cosmic-ai-input 1.0.7 → 1.0.8
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.d.ts +5 -5
- package/dist/index.es.js +274 -166
- package/package.json +1 -1
package/dist/index.cjs.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
// Generated at: 2026-01-
|
|
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"),
|
|
3
|
-
`&&(e=""),e},de=()=>{var
|
|
4
|
-
`)return[{type:"text",content:"",id:`text-${h++}-${f}`}];const $=new Set((p||[]).map(
|
|
5
|
-
`);A.forEach((q,
|
|
6
|
-
`);t.forEach((A,q)=>{A&&
|
|
1
|
+
// Generated at: 2026-01-16T03:24:55.032Z
|
|
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"),ze=require("react-dom"),we=i.forwardRef(({value:c,position:r,id:s,onChange:p},S)=>{const[w,C]=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 w?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 P(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:w},C)=>{const[k,R]=i.useState(r||""),m=i.useRef(null);i.useEffect(()=>{typeof C=="function"?C(m.current):C&&(C.current=m.current)},[C]);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),w==null||w(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:w},C)=>{const[k,R]=i.useState(r||""),m=i.useRef(null);i.useEffect(()=>{typeof C=="function"?C(m.current):C&&(C.current=m.current)},[C]);const T=g=>{R(g),w==null||w(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 ve(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 j(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 Ue(){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 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>0?s:s.previousSibling:s.nodeType===Node.ELEMENT_NODE?p>0?s.childNodes[p-1]:s.previousSibling:null}function Ge(){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 Je(c){return c&&!c.getAttribute("data-set-type")}const Re=i.forwardRef((c,r)=>{const{value:s="",varList:p,placeholder:S="",maxLength:w,defaultRows:C=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,[Qe,Ye]=i.useState(s||""),[W,_]=i.useState(""),[Ze,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,oe]=i.useState(null),[le,se]=i.useState(120),[ce,re]=i.useState(R),Se=240,Ae=240,ie=240,ae=276,x=i.useRef(null),E=i.useRef(null),N=i.useRef(null),B=()=>{var o,n;let e=((n=(o=x.current)==null?void 0:o.innerText)==null?void 0:n.replace(/\u200B/g,""))||"";return e===`
|
|
3
|
+
`&&(e=""),e},de=()=>{var o;let e=((o=x.current)==null?void 0:o.innerHTML)||"";return e==="<br>"&&(e=""),e},ke=e=>{const o=[];let n=0;const l=/\[([^\]]+)\]/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(b=>b.name));for(;(a=l.exec(e))!==null;){if(a.index>n){const A=e.substring(n,a.index).split(`
|
|
5
|
+
`);A.forEach((q,_e)=>{q&&o.push({type:"text",content:q,id:`text-${h++}-${f}`}),_e<A.length-1&&o.push({type:"newline",id:`newline-${h++}-${f}`})})}const b=a[1];if($.has(b)){const t=p.find(A=>A.name===b);(t==null?void 0:t.type)==="input"?o.push({type:"input",name:t==null?void 0:t.name,content:(t==null?void 0:t.content)||"",placeholder:(t==null?void 0:t.placeholder)||b,id:`input-${h++}-${f}`}):(t==null?void 0:t.type)==="select"?o.push({type:"select",name:t==null?void 0:t.name,content:(t==null?void 0:t.content)||"",placeholder:(t==null?void 0:t.placeholder)||b,options:(t==null?void 0:t.options)||[],id:`select-${h++}-${f}`}):(t==null?void 0:t.type)==="multiple-select"?o.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)||b,options:(t==null?void 0:t.options)||[],id:`multiple-select-${h++}-${f}`}):(t==null?void 0:t.type)==="date-picker"&&o.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)||b,id:`date-picker-${h++}-${f}`})}else o.push({type:"text",content:`[${b}]`,id:`text-${h++}-${f}`});n=l.lastIndex}if(n<e.length){const t=e.substring(n).split(`
|
|
6
|
+
`);t.forEach((A,q)=>{A&&o.push({type:"text",content:A,id:`text-${h++}`}),q<t.length-1&&o.push({type:"newline",id:`newline-${h++}`})})}return o},G=()=>{var e;(e=x.current)==null||e.setAttribute("contenteditable","true"),E.current&&(P(E.current)&&E.current.children[0].setAttribute("contenteditable","false"),E.current=null),j(x.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 o,n;if(e.code==="Enter"&&!e.shiftKey){e.preventDefault();const l=B();if(console.log("onSend",l,"maxLength:",w,"length:",l.length),l.length===0||(console.log("containerRef.current?.innerHTML",(o=x.current)==null?void 0:o.innerHTML),(n=x.current)!=null&&n.innerHTML.match(/^<span>[\s\u200B]*(<br\s*\/?>[\s\u200B]*)+<\/span>$/)))return;w?l.length<=w?y==null||y(l):(console.log("maxLength exceeded",l,w),K==null||K(l,w)):y==null||y(l)}},Le=e=>{var n;console.log("handleEditorKeyDown",e),D==null||D(e);const o=Ue();if(o&&Je(o)){if(e.code==="ArrowLeft"){const l=o==null?void 0:o.previousElementSibling,a=Z(o);l&&a===0&&P(l)&&l.children[0]&&(E.current=l,M(l),requestAnimationFrame(()=>{j(l.children[0])}))}if(e.code==="ArrowRight"){const l=o==null?void 0:o.nextElementSibling,a=Z(o);l&&a===((n=o.textContent)==null?void 0:n.length)&&P(l)&&l.children[0]&&(E.current=l,M(l),requestAnimationFrame(()=>{V(l.children[0])}))}e.code==="Backspace"&&(o.innerHTML===""&&e.preventDefault(),o.innerHTML==="<br>"&&(e.preventDefault(),o.innerHTML=""))}if(o&&o.getAttribute("data-set-type")==="container"){if(e.code==="ArrowLeft"){const l=Xe();P(l)&&l.children[0]&&(E.current=l,M(l),requestAnimationFrame(()=>{j(l.children[0])}))}if(e.code==="ArrowRight"){const l=Ge();P(l)&&l.children[0]&&(E.current=l,M(l),requestAnimationFrame(()=>{V(l.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 l=n,a=n;e.clipboardData.setData("text/plain",l),e.clipboardData.setData("text/html",a)},je=e=>{m==null||m(e)},Pe=(e,o)=>{o.stopPropagation(),console.log("handleInputClick",e)},Fe=(e,o)=>{var l;o.stopPropagation(),console.log("handleInputMouseDown",e,o),E.current&&Ee(E.current),(l=x.current)==null||l.setAttribute("contenteditable","false");const n=document.getElementById(e.id);E.current=n,requestAnimationFrame(()=>{M(n)})},Oe=(e,o)=>{var a,f,h,$,b;console.log("handleInputKeyDown",e,o),D==null||D(o),o.stopPropagation();const n=o.target,l=Z(n);if(o.code==="Backspace"&&l===0){const t=(a=n.parentElement)==null?void 0:a.previousElementSibling;console.log("previousElement",t),t&&(P(t)&&t.children[0]&&((f=t.children[0].textContent)!=null&&f.length)?(E.current=t,M(t),j(t.children[0]),requestAnimationFrame(()=>{Y(t.children[0])})):(G(),j(t)))}if(o.code==="ArrowRight"&&l===((h=n.textContent)==null?void 0:h.length)){const t=($=n.parentElement)==null?void 0:$.nextElementSibling;console.log("nextElement",t),t&&(P(t)&&t.children[0]&&((b=t.children[0].textContent)!=null&&b.length)?(E.current=t,M(t),V(t.children[0]),requestAnimationFrame(()=>{Y(t.children[0])})):(G(),V(t)))}},He=(e,o)=>{console.log("handleInputKeyUp",e,o),O==null||O(o);const n=o.target;Y(n)},Be=(e,o)=>{var l;o.stopPropagation(),console.log("handlePlaceholderMouseDown",e),E.current&&Ee(E.current),(l=x.current)==null||l.setAttribute("contenteditable","false");const n=document.getElementById(e.id);E.current=n,requestAnimationFrame(()=>{M(n)})},qe=(e,o)=>{console.log("handleInputChange",e,o),_(B()),I(de()),g==null||g(B())},Ve=(e,o)=>{console.log("handleTextSpanKeyDown 不生效",e,o)};i.useEffect(()=>{if(!z)return;const e=l=>{N.current&&!N.current.contains(l.target)&&H(!1)},o=l=>{N.current&&!N.current.contains(l.target)&&H(!1)},n=()=>{H(!1)};return document.addEventListener("mousedown",e),document.addEventListener("scroll",o,!0),window.addEventListener("resize",n),()=>{document.removeEventListener("mousedown",e),document.removeEventListener("scroll",o,!0),window.removeEventListener("resize",n)}},[z]);const J=(e,o)=>{if(console.log("handleFloatChange",e,o),L&&ve(L.id,e),o==="select"&&H(!1),o==="multiple-select"||o==="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,o)=>{console.log("handleSelectClick",e,o);const l=o.target.getBoundingClientRect();te(e.options),ne(e.value||be(e.id)),U({top:-999999,left:-999999999}),oe(e),se(Ae),H(!0),requestAnimationFrame(()=>{if(N.current){console.log("currentFloatElementRef.current",N.current);const a=N.current.getBoundingClientRect();let f=l.left,h=l.top+l.height;window.innerWidth-l.right<Se&&l.width<a.width&&(f=l.right-a.width),l.top<a.height&&(h=l.top+l.height),U({top:h,left:f}),se(a.height)}})},Ke=(e,o)=>{console.log("handleDatePickerClick",e,o);const l=o.target.getBoundingClientRect();let a=l.left,f=l.top-ae;window.innerWidth-l.right<ie&&(a=a-ie+l.width),l.top<ae&&(f=l.top+l.height),te(e.options),ne(e.value||be(e.id)),U({top:f,left:a}),oe(e),H(!0)},[fe,he]=i.useState([]),[Q,ge]=i.useState(!0),ye=i.useCallback(()=>{ge(!1);const e=ke(s),o=[];return e.forEach(n=>{var l,a,f,h,$,b;if(n.type==="text")o.push(u.jsx("span",{onKeyDown:t=>Ve(n,t),children:n.content},n.id));else if(n.type==="newline")o.push(u.jsx("br",{},n.id));else if(n.type==="input")o.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:(l=n.content)!=null&&l.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;o.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]);o.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"&&o.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:(b=n.content)!=null&&b.length?"none":"inline"},className:"cosmic-ai-input-datePickerPlaceholder",contentEditable:!1,children:n.placeholder})]},n.id))}),setTimeout(()=>{ge(!0)},0),console.log("重新渲染 ============================>","elements",o,"parsed",e,s),o},[s]);i.useEffect(()=>{Q&&setTimeout(()=>{j(x.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(()=>{x.current&&document.contains(x.current)&&(requestAnimationFrame(()=>{j(x.current),re(!1)}),e.disconnect())});return x.current&&e.observe(document.body,{childList:!0,subtree:!0}),()=>e.disconnect()},[R,ce]);const We=()=>{x.current&&requestAnimationFrame(()=>{j(x.current)})};return i.useImperativeHandle(r,()=>({getCurrentValue:B,focus:We})),console.log("renderElements",fe),u.jsxs("div",{className:xe(`cosmic-ai-input-rows${C}`),children:[Q&&u.jsx("div",{"data-set-type":"container","data-cosmic-ai-input-placeholder":S,className:xe("cosmic-ai-input",`cosmic-ai-input-rows${C}`,{"is-disabled":k},{"is-empty":W.length===0}),ref:x,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&&ze.createPortal((L==null?void 0:L.type)==="multiple-select"?u.jsx(Ce,{ref:N,options:ee,value:X,position:v,height:le,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:le,onChange:J},"select"),document.body)]})});Re.displayName="AiInput";exports.default=Re;
|
package/dist/index.d.ts
CHANGED
|
@@ -27,25 +27,25 @@ export declare interface AiInputRef {
|
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
declare interface DatePickerItem {
|
|
30
|
-
type:
|
|
30
|
+
type: "date-picker";
|
|
31
31
|
name: string;
|
|
32
32
|
content: string;
|
|
33
33
|
placeholder: string;
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
declare interface InputItem {
|
|
37
|
-
type:
|
|
37
|
+
type: "input";
|
|
38
38
|
name: string;
|
|
39
39
|
content: string;
|
|
40
40
|
placeholder: string;
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
declare interface MultipleSelectItem extends Omit<SelectItem,
|
|
44
|
-
type:
|
|
43
|
+
declare interface MultipleSelectItem extends Omit<SelectItem, "type"> {
|
|
44
|
+
type: "multiple-select";
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
declare interface SelectItem {
|
|
48
|
-
type:
|
|
48
|
+
type: "select";
|
|
49
49
|
name: string;
|
|
50
50
|
content: string;
|
|
51
51
|
placeholder: string;
|
package/dist/index.es.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
// Generated at: 2026-01-
|
|
1
|
+
// Generated at: 2026-01-16T03:24:54.633Z
|
|
2
2
|
import { jsx as f, jsxs as _ } from "react/jsx-runtime";
|
|
3
|
-
import { forwardRef as j, useState as
|
|
3
|
+
import { forwardRef as j, useState as C, useRef as H, useEffect as P, useCallback as ve, useImperativeHandle as Ge } from "react";
|
|
4
4
|
import Ce from "classnames";
|
|
5
|
-
import { createPortal as
|
|
5
|
+
import { createPortal as Je } from "react-dom";
|
|
6
6
|
const ke = j(
|
|
7
7
|
({ value: s, position: r, id: c, onChange: d }, k) => {
|
|
8
|
-
const [
|
|
8
|
+
const [x, w] = C(!0), D = H(null), A = H(null);
|
|
9
9
|
P(() => {
|
|
10
10
|
typeof k == "function" ? k(D.current) : k && (k.current = D.current);
|
|
11
11
|
}, [k]);
|
|
@@ -34,7 +34,7 @@ const ke = j(
|
|
|
34
34
|
}, h = (a) => {
|
|
35
35
|
a.stopPropagation(), console.log("DatePicker handleClick", a);
|
|
36
36
|
};
|
|
37
|
-
return
|
|
37
|
+
return x ? /* @__PURE__ */ f(
|
|
38
38
|
"div",
|
|
39
39
|
{
|
|
40
40
|
ref: D,
|
|
@@ -75,7 +75,7 @@ function M(s) {
|
|
|
75
75
|
function me(s) {
|
|
76
76
|
s && s.getAttribute("data-set-type") === "input" && s.children[0].setAttribute("contenteditable", "false");
|
|
77
77
|
}
|
|
78
|
-
function
|
|
78
|
+
function O(s) {
|
|
79
79
|
return s && s.getAttribute("data-set-type") === "input";
|
|
80
80
|
}
|
|
81
81
|
const Re = j(({
|
|
@@ -84,16 +84,16 @@ const Re = j(({
|
|
|
84
84
|
position: c,
|
|
85
85
|
id: d,
|
|
86
86
|
height: k = 37,
|
|
87
|
-
onChange:
|
|
88
|
-
},
|
|
89
|
-
const [D, A] =
|
|
87
|
+
onChange: x
|
|
88
|
+
}, w) => {
|
|
89
|
+
const [D, A] = C(r || ""), m = H(null);
|
|
90
90
|
P(() => {
|
|
91
|
-
typeof
|
|
92
|
-
}, [
|
|
91
|
+
typeof w == "function" ? w(m.current) : w && (w.current = m.current);
|
|
92
|
+
}, [w]);
|
|
93
93
|
const S = (a) => {
|
|
94
94
|
const g = D.split(",").filter((N) => N) || [];
|
|
95
95
|
let B = "";
|
|
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),
|
|
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), x == null || x(B, "multiple-select");
|
|
97
97
|
}, h = D.split(",") || [];
|
|
98
98
|
return /* @__PURE__ */ f(
|
|
99
99
|
"div",
|
|
@@ -127,14 +127,14 @@ const De = j(({
|
|
|
127
127
|
position: c,
|
|
128
128
|
id: d,
|
|
129
129
|
height: k = 120,
|
|
130
|
-
onChange:
|
|
131
|
-
},
|
|
132
|
-
const [D, A] =
|
|
130
|
+
onChange: x
|
|
131
|
+
}, w) => {
|
|
132
|
+
const [D, A] = C(r || ""), m = H(null);
|
|
133
133
|
P(() => {
|
|
134
|
-
typeof
|
|
135
|
-
}, [
|
|
134
|
+
typeof w == "function" ? w(m.current) : w && (w.current = m.current);
|
|
135
|
+
}, [w]);
|
|
136
136
|
const S = (h) => {
|
|
137
|
-
A(h),
|
|
137
|
+
A(h), x == null || x(h, "select");
|
|
138
138
|
};
|
|
139
139
|
return /* @__PURE__ */ f(
|
|
140
140
|
"div",
|
|
@@ -166,7 +166,7 @@ function Ae(s) {
|
|
|
166
166
|
const r = s instanceof Element ? s : document.getElementById(s);
|
|
167
167
|
return r && r.children[0].textContent || "";
|
|
168
168
|
}
|
|
169
|
-
function
|
|
169
|
+
function Qe(s, r) {
|
|
170
170
|
const c = s instanceof Element ? s : document.getElementById(s);
|
|
171
171
|
c && (c.children[0].textContent = r);
|
|
172
172
|
}
|
|
@@ -182,7 +182,7 @@ function z(s) {
|
|
|
182
182
|
}
|
|
183
183
|
r.selectNodeContents(s), r.collapse(!0), c.removeAllRanges(), c.addRange(r);
|
|
184
184
|
}
|
|
185
|
-
function
|
|
185
|
+
function F(s) {
|
|
186
186
|
const r = document.createRange(), c = window.getSelection();
|
|
187
187
|
if (!c) {
|
|
188
188
|
console.error("无法获取selection对象");
|
|
@@ -205,273 +205,311 @@ function ne(s) {
|
|
|
205
205
|
const c = r.getRangeAt(0), d = c.cloneRange();
|
|
206
206
|
return d.selectNodeContents(s), d.setEnd(c.startContainer, c.startOffset), d.toString().length;
|
|
207
207
|
}
|
|
208
|
-
function
|
|
208
|
+
function Ye() {
|
|
209
209
|
const s = window.getSelection();
|
|
210
210
|
if (!s || s.rangeCount === 0)
|
|
211
211
|
return null;
|
|
212
212
|
const c = s.getRangeAt(0).startContainer;
|
|
213
213
|
return c.nodeType === Node.TEXT_NODE ? c.parentElement : c.nodeType === Node.ELEMENT_NODE ? c : null;
|
|
214
214
|
}
|
|
215
|
-
function
|
|
215
|
+
function Ze() {
|
|
216
216
|
const s = window.getSelection();
|
|
217
217
|
if (!s || s.rangeCount === 0) return null;
|
|
218
218
|
const r = s.getRangeAt(0), c = r.startContainer, d = r.startOffset;
|
|
219
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;
|
|
220
220
|
}
|
|
221
|
-
function
|
|
221
|
+
function Ie() {
|
|
222
222
|
const s = window.getSelection();
|
|
223
223
|
if (!s || s.rangeCount === 0) return null;
|
|
224
224
|
const r = s.getRangeAt(0), c = r.startContainer, d = r.startOffset;
|
|
225
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;
|
|
226
226
|
}
|
|
227
|
-
function
|
|
227
|
+
function et(s) {
|
|
228
228
|
return s && !s.getAttribute("data-set-type");
|
|
229
229
|
}
|
|
230
|
-
const
|
|
231
|
-
const {
|
|
232
|
-
|
|
233
|
-
|
|
230
|
+
const tt = j((s, r) => {
|
|
231
|
+
const {
|
|
232
|
+
value: c = "",
|
|
233
|
+
varList: d,
|
|
234
|
+
placeholder: k = "",
|
|
235
|
+
maxLength: x,
|
|
236
|
+
defaultRows: w = 3,
|
|
237
|
+
disabled: D = !1,
|
|
238
|
+
defaultFocus: A = !1,
|
|
239
|
+
onFocus: m,
|
|
240
|
+
onBlur: S,
|
|
241
|
+
onChange: h,
|
|
242
|
+
onClick: a,
|
|
243
|
+
onSend: g,
|
|
244
|
+
onParse: B,
|
|
245
|
+
onKeyDown: N,
|
|
246
|
+
onKeyUp: V,
|
|
247
|
+
onMaxLengthExceeded: U
|
|
248
|
+
} = s, [nt, ot] = C(c || ""), [X, v] = C(""), [lt, oe] = C(""), [G, q] = C(!1), [J, Q] = C({ top: 0, left: 0 }), [le, ce] = C([]), [Y, se] = C(""), [L, re] = C(null), [ie, ae] = C(120), [de, ue] = C(A), Ne = 240, Te = 240, pe = 240, fe = 276, y = H(null), E = H(null), T = H(null), K = () => {
|
|
249
|
+
var o, n;
|
|
250
|
+
let e = ((n = (o = y.current) == null ? void 0 : o.innerText) == null ? void 0 : n.replace(/\u200B/g, "")) || "";
|
|
234
251
|
return e === `
|
|
235
252
|
` && (e = ""), e;
|
|
236
253
|
}, he = () => {
|
|
237
|
-
var
|
|
238
|
-
let e = ((
|
|
254
|
+
var o;
|
|
255
|
+
let e = ((o = y.current) == null ? void 0 : o.innerHTML) || "";
|
|
239
256
|
return e === "<br>" && (e = ""), e;
|
|
240
257
|
}, Se = (e) => {
|
|
241
|
-
const
|
|
258
|
+
const o = [];
|
|
242
259
|
let n = 0;
|
|
243
|
-
const
|
|
260
|
+
const l = /\[([^\]]+)\]/g;
|
|
244
261
|
let i;
|
|
245
262
|
const u = `${Date.now()}-${Math.random().toString(36).slice(2, 9)}`;
|
|
246
263
|
let p = 0;
|
|
247
264
|
if (e === "" || !e || e === `
|
|
248
265
|
`)
|
|
249
|
-
return [
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
266
|
+
return [
|
|
267
|
+
{
|
|
268
|
+
type: "text",
|
|
269
|
+
content: "",
|
|
270
|
+
id: `text-${p++}-${u}`
|
|
271
|
+
}
|
|
272
|
+
];
|
|
273
|
+
const $ = new Set((d || []).map((b) => b.name));
|
|
274
|
+
for (; (i = l.exec(e)) !== null; ) {
|
|
256
275
|
if (i.index > n) {
|
|
257
276
|
const R = e.substring(n, i.index).split(`
|
|
258
277
|
`);
|
|
259
|
-
R.forEach((W,
|
|
260
|
-
W &&
|
|
278
|
+
R.forEach((W, Xe) => {
|
|
279
|
+
W && o.push({
|
|
261
280
|
type: "text",
|
|
262
281
|
content: W,
|
|
263
282
|
id: `text-${p++}-${u}`
|
|
264
|
-
}),
|
|
283
|
+
}), Xe < R.length - 1 && o.push({
|
|
265
284
|
type: "newline",
|
|
266
285
|
id: `newline-${p++}-${u}`
|
|
267
286
|
});
|
|
268
287
|
});
|
|
269
288
|
}
|
|
270
|
-
const
|
|
271
|
-
if ($.has(
|
|
272
|
-
const t = d.find((R) => R.name ===
|
|
273
|
-
(t == null ? void 0 : t.type) === "input" ?
|
|
289
|
+
const b = i[1];
|
|
290
|
+
if ($.has(b)) {
|
|
291
|
+
const t = d.find((R) => R.name === b);
|
|
292
|
+
(t == null ? void 0 : t.type) === "input" ? o.push({
|
|
274
293
|
type: "input",
|
|
275
294
|
name: t == null ? void 0 : t.name,
|
|
276
295
|
content: (t == null ? void 0 : t.content) || "",
|
|
277
|
-
placeholder: (t == null ? void 0 : t.placeholder) ||
|
|
296
|
+
placeholder: (t == null ? void 0 : t.placeholder) || b,
|
|
278
297
|
id: `input-${p++}-${u}`
|
|
279
|
-
}) : (t == null ? void 0 : t.type) === "select" ?
|
|
298
|
+
}) : (t == null ? void 0 : t.type) === "select" ? o.push({
|
|
280
299
|
type: "select",
|
|
281
300
|
name: t == null ? void 0 : t.name,
|
|
282
301
|
content: (t == null ? void 0 : t.content) || "",
|
|
283
|
-
placeholder: (t == null ? void 0 : t.placeholder) ||
|
|
302
|
+
placeholder: (t == null ? void 0 : t.placeholder) || b,
|
|
284
303
|
options: (t == null ? void 0 : t.options) || [],
|
|
285
304
|
id: `select-${p++}-${u}`
|
|
286
|
-
}) : (t == null ? void 0 : t.type) === "multiple-select" ?
|
|
305
|
+
}) : (t == null ? void 0 : t.type) === "multiple-select" ? o.push({
|
|
287
306
|
type: "multiple-select",
|
|
288
307
|
name: t == null ? void 0 : t.name,
|
|
289
308
|
content: (t == null ? void 0 : t.content) || "",
|
|
290
|
-
placeholder: (t == null ? void 0 : t.placeholder) ||
|
|
309
|
+
placeholder: (t == null ? void 0 : t.placeholder) || b,
|
|
291
310
|
options: (t == null ? void 0 : t.options) || [],
|
|
292
311
|
id: `multiple-select-${p++}-${u}`
|
|
293
|
-
}) : (t == null ? void 0 : t.type) === "date-picker" &&
|
|
312
|
+
}) : (t == null ? void 0 : t.type) === "date-picker" && o.push({
|
|
294
313
|
type: "date-picker",
|
|
295
314
|
name: t == null ? void 0 : t.name,
|
|
296
315
|
content: (t == null ? void 0 : t.content) || "",
|
|
297
|
-
placeholder: (t == null ? void 0 : t.placeholder) ||
|
|
316
|
+
placeholder: (t == null ? void 0 : t.placeholder) || b,
|
|
298
317
|
id: `date-picker-${p++}-${u}`
|
|
299
318
|
});
|
|
300
319
|
} else
|
|
301
|
-
|
|
320
|
+
o.push({
|
|
302
321
|
type: "text",
|
|
303
|
-
content: `[${
|
|
322
|
+
content: `[${b}]`,
|
|
304
323
|
id: `text-${p++}-${u}`
|
|
305
324
|
});
|
|
306
|
-
n =
|
|
325
|
+
n = l.lastIndex;
|
|
307
326
|
}
|
|
308
327
|
if (n < e.length) {
|
|
309
328
|
const t = e.substring(n).split(`
|
|
310
329
|
`);
|
|
311
330
|
t.forEach((R, W) => {
|
|
312
|
-
R &&
|
|
331
|
+
R && o.push({
|
|
313
332
|
type: "text",
|
|
314
333
|
content: R,
|
|
315
334
|
id: `text-${p++}`
|
|
316
|
-
}), W < t.length - 1 &&
|
|
335
|
+
}), W < t.length - 1 && o.push({
|
|
317
336
|
type: "newline",
|
|
318
337
|
id: `newline-${p++}`
|
|
319
338
|
});
|
|
320
339
|
});
|
|
321
340
|
}
|
|
322
|
-
return
|
|
341
|
+
return o;
|
|
323
342
|
}, Z = () => {
|
|
324
343
|
var e;
|
|
325
|
-
(e =
|
|
344
|
+
(e = y.current) == null || e.setAttribute("contenteditable", "true"), E.current && (O(E.current) && E.current.children[0].setAttribute(
|
|
345
|
+
"contenteditable",
|
|
346
|
+
"false"
|
|
347
|
+
), E.current = null), F(y.current);
|
|
326
348
|
}, Le = (e) => {
|
|
327
349
|
console.log("handleEditorClick", e), a == null || a(e);
|
|
328
350
|
}, $e = (e) => {
|
|
329
351
|
console.log("handleEditorMouseDown", e), Z();
|
|
330
352
|
}, ge = (e) => {
|
|
331
|
-
console.log("handleEditorInput", e), v(K()),
|
|
353
|
+
console.log("handleEditorInput", e), v(K()), oe(he()), h == null || h(K());
|
|
332
354
|
}, Me = (e) => {
|
|
333
|
-
var
|
|
355
|
+
var o, n;
|
|
334
356
|
if (e.code === "Enter" && !e.shiftKey) {
|
|
335
357
|
e.preventDefault();
|
|
336
|
-
const
|
|
337
|
-
if (console.log(
|
|
358
|
+
const l = K();
|
|
359
|
+
if (console.log(
|
|
360
|
+
"onSend",
|
|
361
|
+
l,
|
|
362
|
+
"maxLength:",
|
|
363
|
+
x,
|
|
364
|
+
"length:",
|
|
365
|
+
l.length
|
|
366
|
+
), l.length === 0 || (console.log(
|
|
367
|
+
"containerRef.current?.innerHTML",
|
|
368
|
+
(o = y.current) == null ? void 0 : o.innerHTML
|
|
369
|
+
), (n = y.current) != null && n.innerHTML.match(
|
|
370
|
+
/^<span>[\s\u200B]*(<br\s*\/?>[\s\u200B]*)+<\/span>$/
|
|
371
|
+
)))
|
|
338
372
|
return;
|
|
339
|
-
|
|
373
|
+
x ? l.length <= x ? g == null || g(l) : (console.log("maxLength exceeded", l, x), U == null || U(l, x)) : g == null || g(l);
|
|
340
374
|
}
|
|
341
|
-
},
|
|
375
|
+
}, Fe = (e) => {
|
|
342
376
|
var n;
|
|
343
377
|
console.log("handleEditorKeyDown", e), N == null || N(e);
|
|
344
|
-
const
|
|
345
|
-
if (
|
|
378
|
+
const o = Ye();
|
|
379
|
+
if (o && et(o)) {
|
|
346
380
|
if (e.code === "ArrowLeft") {
|
|
347
|
-
const
|
|
348
|
-
|
|
349
|
-
|
|
381
|
+
const l = o == null ? void 0 : o.previousElementSibling, i = ne(o);
|
|
382
|
+
l && i === 0 && O(l) && l.children[0] && (E.current = l, M(l), requestAnimationFrame(() => {
|
|
383
|
+
F(l.children[0]);
|
|
350
384
|
}));
|
|
351
385
|
}
|
|
352
386
|
if (e.code === "ArrowRight") {
|
|
353
|
-
const
|
|
354
|
-
|
|
355
|
-
z(
|
|
387
|
+
const l = o == null ? void 0 : o.nextElementSibling, i = ne(o);
|
|
388
|
+
l && i === ((n = o.textContent) == null ? void 0 : n.length) && O(l) && l.children[0] && (E.current = l, M(l), requestAnimationFrame(() => {
|
|
389
|
+
z(l.children[0]);
|
|
356
390
|
}));
|
|
357
391
|
}
|
|
358
|
-
e.code === "Backspace" && (
|
|
392
|
+
e.code === "Backspace" && (o.innerHTML === "" && e.preventDefault(), o.innerHTML === "<br>" && (e.preventDefault(), o.innerHTML = ""));
|
|
359
393
|
}
|
|
360
|
-
if (
|
|
394
|
+
if (o && o.getAttribute("data-set-type") === "container") {
|
|
361
395
|
if (e.code === "ArrowLeft") {
|
|
362
|
-
const
|
|
363
|
-
|
|
364
|
-
|
|
396
|
+
const l = Ze();
|
|
397
|
+
O(l) && l.children[0] && (E.current = l, M(l), requestAnimationFrame(() => {
|
|
398
|
+
F(l.children[0]);
|
|
365
399
|
}));
|
|
366
400
|
}
|
|
367
401
|
if (e.code === "ArrowRight") {
|
|
368
|
-
const
|
|
369
|
-
|
|
370
|
-
z(
|
|
402
|
+
const l = Ie();
|
|
403
|
+
O(l) && l.children[0] && (E.current = l, M(l), requestAnimationFrame(() => {
|
|
404
|
+
z(l.children[0]);
|
|
371
405
|
}));
|
|
372
406
|
}
|
|
373
407
|
}
|
|
374
408
|
Me(e);
|
|
375
|
-
},
|
|
409
|
+
}, Pe = (e) => {
|
|
376
410
|
console.log("handleEditorKeyUp", e), V == null || V(e);
|
|
377
411
|
}, Oe = (e) => {
|
|
378
412
|
e.preventDefault();
|
|
379
413
|
const n = window.getSelection().toString();
|
|
380
414
|
if (!n) return;
|
|
381
|
-
const
|
|
382
|
-
e.clipboardData.setData("text/plain",
|
|
415
|
+
const l = n, i = n;
|
|
416
|
+
e.clipboardData.setData("text/plain", l), e.clipboardData.setData("text/html", i);
|
|
383
417
|
}, He = (e) => {
|
|
384
418
|
m == null || m(e);
|
|
385
|
-
}, Be = (e,
|
|
386
|
-
|
|
387
|
-
}, Ve = (e,
|
|
388
|
-
var
|
|
389
|
-
|
|
419
|
+
}, Be = (e, o) => {
|
|
420
|
+
o.stopPropagation(), console.log("handleInputClick", e);
|
|
421
|
+
}, Ve = (e, o) => {
|
|
422
|
+
var l;
|
|
423
|
+
o.stopPropagation(), console.log("handleInputMouseDown", e, o), E.current && me(E.current), (l = y.current) == null || l.setAttribute("contenteditable", "false");
|
|
390
424
|
const n = document.getElementById(e.id);
|
|
391
|
-
|
|
425
|
+
E.current = n, requestAnimationFrame(() => {
|
|
392
426
|
M(n);
|
|
393
427
|
});
|
|
394
|
-
}, qe = (e,
|
|
395
|
-
var i, u, p, $,
|
|
396
|
-
console.log("handleInputKeyDown", e,
|
|
397
|
-
const n =
|
|
398
|
-
if (
|
|
428
|
+
}, qe = (e, o) => {
|
|
429
|
+
var i, u, p, $, b;
|
|
430
|
+
console.log("handleInputKeyDown", e, o), N == null || N(o), o.stopPropagation();
|
|
431
|
+
const n = o.target, l = ne(n);
|
|
432
|
+
if (o.code === "Backspace" && l === 0) {
|
|
399
433
|
const t = (i = n.parentElement) == null ? void 0 : i.previousElementSibling;
|
|
400
|
-
console.log("previousElement", t), t && (
|
|
434
|
+
console.log("previousElement", t), t && (O(t) && t.children[0] && ((u = t.children[0].textContent) != null && u.length) ? (E.current = t, M(t), F(t.children[0]), requestAnimationFrame(() => {
|
|
401
435
|
te(t.children[0]);
|
|
402
|
-
})) : (Z(),
|
|
436
|
+
})) : (Z(), F(t)));
|
|
403
437
|
}
|
|
404
|
-
if (
|
|
438
|
+
if (o.code === "ArrowRight" && l === ((p = n.textContent) == null ? void 0 : p.length)) {
|
|
405
439
|
const t = ($ = n.parentElement) == null ? void 0 : $.nextElementSibling;
|
|
406
|
-
console.log("nextElement", t), t && (
|
|
440
|
+
console.log("nextElement", t), t && (O(t) && t.children[0] && ((b = t.children[0].textContent) != null && b.length) ? (E.current = t, M(t), z(t.children[0]), requestAnimationFrame(() => {
|
|
407
441
|
te(t.children[0]);
|
|
408
442
|
})) : (Z(), z(t)));
|
|
409
443
|
}
|
|
410
|
-
}, Ke = (e,
|
|
411
|
-
console.log("handleInputKeyUp", e,
|
|
412
|
-
const n =
|
|
444
|
+
}, Ke = (e, o) => {
|
|
445
|
+
console.log("handleInputKeyUp", e, o), V == null || V(o);
|
|
446
|
+
const n = o.target;
|
|
413
447
|
te(n);
|
|
414
|
-
}, We = (e,
|
|
415
|
-
var
|
|
416
|
-
|
|
448
|
+
}, We = (e, o) => {
|
|
449
|
+
var l;
|
|
450
|
+
o.stopPropagation(), console.log("handlePlaceholderMouseDown", e), E.current && me(E.current), (l = y.current) == null || l.setAttribute("contenteditable", "false");
|
|
417
451
|
const n = document.getElementById(e.id);
|
|
418
|
-
|
|
452
|
+
E.current = n, requestAnimationFrame(() => {
|
|
419
453
|
M(n);
|
|
420
454
|
});
|
|
421
|
-
}, _e = (e,
|
|
422
|
-
console.log("handleInputChange", e,
|
|
423
|
-
}, ze = (e,
|
|
424
|
-
console.log("handleTextSpanKeyDown 不生效", e,
|
|
455
|
+
}, _e = (e, o) => {
|
|
456
|
+
console.log("handleInputChange", e, o), v(K()), oe(he()), h == null || h(K());
|
|
457
|
+
}, ze = (e, o) => {
|
|
458
|
+
console.log("handleTextSpanKeyDown 不生效", e, o);
|
|
425
459
|
};
|
|
426
460
|
P(() => {
|
|
427
|
-
if (!G)
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
T.current && !T.current.contains(o.target) && q(!1);
|
|
461
|
+
if (!G) return;
|
|
462
|
+
const e = (l) => {
|
|
463
|
+
T.current && !T.current.contains(l.target) && q(!1);
|
|
464
|
+
}, o = (l) => {
|
|
465
|
+
T.current && !T.current.contains(l.target) && q(!1);
|
|
433
466
|
}, n = () => {
|
|
434
467
|
q(!1);
|
|
435
468
|
};
|
|
436
|
-
return document.addEventListener("mousedown", e), document.addEventListener("scroll",
|
|
437
|
-
document.removeEventListener("mousedown", e), document.removeEventListener("scroll",
|
|
469
|
+
return document.addEventListener("mousedown", e), document.addEventListener("scroll", o, !0), window.addEventListener("resize", n), () => {
|
|
470
|
+
document.removeEventListener("mousedown", e), document.removeEventListener("scroll", o, !0), window.removeEventListener("resize", n);
|
|
438
471
|
};
|
|
439
472
|
}, [G]);
|
|
440
|
-
const I = (e,
|
|
441
|
-
if (console.log("handleFloatChange", e,
|
|
442
|
-
const n = document.getElementById(
|
|
473
|
+
const I = (e, o) => {
|
|
474
|
+
if (console.log("handleFloatChange", e, o), L && Qe(L.id, e), o === "select" && q(!1), o === "multiple-select" || o === "date-picker") {
|
|
475
|
+
const n = document.getElementById(
|
|
476
|
+
L.id
|
|
477
|
+
);
|
|
443
478
|
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")));
|
|
444
479
|
}
|
|
445
480
|
ge({});
|
|
446
|
-
}, ye = (e,
|
|
447
|
-
console.log("handleSelectClick", e,
|
|
448
|
-
const
|
|
481
|
+
}, ye = (e, o) => {
|
|
482
|
+
console.log("handleSelectClick", e, o);
|
|
483
|
+
const l = o.target.getBoundingClientRect();
|
|
449
484
|
ce(e.options), se(e.value || Ae(e.id)), Q({ top: -999999, left: -999999999 }), re(e), ae(Te), q(!0), requestAnimationFrame(() => {
|
|
450
485
|
if (T.current) {
|
|
451
|
-
console.log(
|
|
486
|
+
console.log(
|
|
487
|
+
"currentFloatElementRef.current",
|
|
488
|
+
T.current
|
|
489
|
+
);
|
|
452
490
|
const i = T.current.getBoundingClientRect();
|
|
453
|
-
let u =
|
|
454
|
-
window.innerWidth -
|
|
491
|
+
let u = l.left, p = l.top + l.height;
|
|
492
|
+
window.innerWidth - l.right < Ne && l.width < i.width && (u = l.right - i.width), l.top < i.height && (p = l.top + l.height), Q({ top: p, left: u }), ae(i.height);
|
|
455
493
|
}
|
|
456
494
|
});
|
|
457
|
-
}, je = (e,
|
|
458
|
-
console.log("handleDatePickerClick", e,
|
|
459
|
-
const
|
|
460
|
-
let i =
|
|
461
|
-
window.innerWidth -
|
|
462
|
-
}, [Ee, be] =
|
|
495
|
+
}, je = (e, o) => {
|
|
496
|
+
console.log("handleDatePickerClick", e, o);
|
|
497
|
+
const l = o.target.getBoundingClientRect();
|
|
498
|
+
let i = l.left, u = l.top - fe;
|
|
499
|
+
window.innerWidth - l.right < pe && (i = i - pe + l.width), l.top < fe && (u = l.top + l.height), ce(e.options), se(e.value || Ae(e.id)), Q({ top: u, left: i }), re(e), q(!0);
|
|
500
|
+
}, [Ee, be] = C([]), [ee, xe] = C(!0), we = ve(() => {
|
|
463
501
|
xe(!1);
|
|
464
|
-
const e = Se(c),
|
|
502
|
+
const e = Se(c), o = [];
|
|
465
503
|
return e.forEach((n) => {
|
|
466
|
-
var
|
|
504
|
+
var l, i, u, p, $, b;
|
|
467
505
|
if (n.type === "text")
|
|
468
|
-
|
|
506
|
+
o.push(
|
|
469
507
|
/* @__PURE__ */ f("span", { onKeyDown: (t) => ze(n, t), children: n.content }, n.id)
|
|
470
508
|
);
|
|
471
509
|
else if (n.type === "newline")
|
|
472
|
-
|
|
510
|
+
o.push(/* @__PURE__ */ f("br", {}, n.id));
|
|
473
511
|
else if (n.type === "input")
|
|
474
|
-
|
|
512
|
+
o.push(
|
|
475
513
|
/* @__PURE__ */ _(
|
|
476
514
|
"span",
|
|
477
515
|
{
|
|
@@ -484,8 +522,29 @@ const et = j((s, r) => {
|
|
|
484
522
|
onMouseDown: (t) => Ve(n, t),
|
|
485
523
|
"data-cosmic-ai-input-placeholder": n.placeholder,
|
|
486
524
|
children: [
|
|
487
|
-
/* @__PURE__ */ f(
|
|
488
|
-
|
|
525
|
+
/* @__PURE__ */ f(
|
|
526
|
+
"span",
|
|
527
|
+
{
|
|
528
|
+
className: "cosmic-ai-input-inputContent",
|
|
529
|
+
style: {
|
|
530
|
+
padding: (l = n.content) != null && l.length ? "2px 4px" : "2px 0 2px 4px"
|
|
531
|
+
},
|
|
532
|
+
contentEditable: !1,
|
|
533
|
+
onKeyDown: (t) => qe(n, t),
|
|
534
|
+
onKeyUp: (t) => Ke(n, t),
|
|
535
|
+
children: n.content
|
|
536
|
+
}
|
|
537
|
+
),
|
|
538
|
+
/* @__PURE__ */ f(
|
|
539
|
+
"span",
|
|
540
|
+
{
|
|
541
|
+
contentEditable: !1,
|
|
542
|
+
style: { display: (i = n.content) != null && i.length ? "none" : "inline" },
|
|
543
|
+
className: "cosmic-ai-input-placeholder",
|
|
544
|
+
onMouseDown: (t) => We(n, t),
|
|
545
|
+
children: n.placeholder
|
|
546
|
+
}
|
|
547
|
+
)
|
|
489
548
|
]
|
|
490
549
|
},
|
|
491
550
|
n.id
|
|
@@ -493,7 +552,7 @@ const et = j((s, r) => {
|
|
|
493
552
|
);
|
|
494
553
|
else if (n.type === "select") {
|
|
495
554
|
const t = n.content || ((u = n.options) == null ? void 0 : u[0]) || n.placeholder;
|
|
496
|
-
|
|
555
|
+
o.push(
|
|
497
556
|
/* @__PURE__ */ f(
|
|
498
557
|
"span",
|
|
499
558
|
{
|
|
@@ -510,7 +569,7 @@ const et = j((s, r) => {
|
|
|
510
569
|
);
|
|
511
570
|
} else if (n.type === "multiple-select") {
|
|
512
571
|
const t = n.content || ((p = n.options) == null ? void 0 : p[0]);
|
|
513
|
-
|
|
572
|
+
o.push(
|
|
514
573
|
/* @__PURE__ */ _(
|
|
515
574
|
"span",
|
|
516
575
|
{
|
|
@@ -521,14 +580,29 @@ const et = j((s, r) => {
|
|
|
521
580
|
onClick: (R) => ye(n, R),
|
|
522
581
|
"data-cosmic-ai-input-placeholder": n.placeholder,
|
|
523
582
|
children: [
|
|
524
|
-
/* @__PURE__ */ f(
|
|
525
|
-
|
|
583
|
+
/* @__PURE__ */ f(
|
|
584
|
+
"span",
|
|
585
|
+
{
|
|
586
|
+
style: { display: t != null && t.length ? "inline" : "none" },
|
|
587
|
+
contentEditable: !1,
|
|
588
|
+
children: t
|
|
589
|
+
}
|
|
590
|
+
),
|
|
591
|
+
/* @__PURE__ */ f(
|
|
592
|
+
"span",
|
|
593
|
+
{
|
|
594
|
+
style: { display: t != null && t.length ? "none" : "inline" },
|
|
595
|
+
className: "cosmic-ai-input-selectPlaceholder",
|
|
596
|
+
contentEditable: !1,
|
|
597
|
+
children: n.placeholder
|
|
598
|
+
}
|
|
599
|
+
)
|
|
526
600
|
]
|
|
527
601
|
},
|
|
528
602
|
n.id
|
|
529
603
|
)
|
|
530
604
|
);
|
|
531
|
-
} else n.type === "date-picker" &&
|
|
605
|
+
} else n.type === "date-picker" && o.push(
|
|
532
606
|
/* @__PURE__ */ _(
|
|
533
607
|
"span",
|
|
534
608
|
{
|
|
@@ -539,8 +613,23 @@ const et = j((s, r) => {
|
|
|
539
613
|
onClick: (t) => je(n, t),
|
|
540
614
|
"data-cosmic-ai-input-placeholder": n.placeholder,
|
|
541
615
|
children: [
|
|
542
|
-
/* @__PURE__ */ f(
|
|
543
|
-
|
|
616
|
+
/* @__PURE__ */ f(
|
|
617
|
+
"span",
|
|
618
|
+
{
|
|
619
|
+
style: { display: ($ = n.content) != null && $.length ? "inline" : "none" },
|
|
620
|
+
contentEditable: !1,
|
|
621
|
+
children: n.content
|
|
622
|
+
}
|
|
623
|
+
),
|
|
624
|
+
/* @__PURE__ */ f(
|
|
625
|
+
"span",
|
|
626
|
+
{
|
|
627
|
+
style: { display: (b = n.content) != null && b.length ? "none" : "inline" },
|
|
628
|
+
className: "cosmic-ai-input-datePickerPlaceholder",
|
|
629
|
+
contentEditable: !1,
|
|
630
|
+
children: n.placeholder
|
|
631
|
+
}
|
|
632
|
+
)
|
|
544
633
|
]
|
|
545
634
|
},
|
|
546
635
|
n.id
|
|
@@ -548,33 +637,52 @@ const et = j((s, r) => {
|
|
|
548
637
|
);
|
|
549
638
|
}), setTimeout(() => {
|
|
550
639
|
xe(!0);
|
|
551
|
-
}, 0), console.log(
|
|
640
|
+
}, 0), console.log(
|
|
641
|
+
"重新渲染 ============================>",
|
|
642
|
+
"elements",
|
|
643
|
+
o,
|
|
644
|
+
"parsed",
|
|
645
|
+
e,
|
|
646
|
+
c
|
|
647
|
+
), o;
|
|
552
648
|
}, [c]);
|
|
553
|
-
|
|
649
|
+
P(() => {
|
|
554
650
|
ee && setTimeout(() => {
|
|
555
|
-
|
|
651
|
+
F(y.current);
|
|
556
652
|
}, 0);
|
|
557
653
|
}, [ee]), P(() => {
|
|
558
654
|
c !== X ? (be(we()), v(c), ue(!0)) : (c === "" || !c) && be(we());
|
|
559
655
|
}, [c, X]), P(() => {
|
|
560
656
|
if (!A && !de) return;
|
|
561
657
|
const e = new MutationObserver(() => {
|
|
562
|
-
|
|
563
|
-
|
|
658
|
+
y.current && document.contains(y.current) && (requestAnimationFrame(() => {
|
|
659
|
+
F(y.current), ue(!1);
|
|
564
660
|
}), e.disconnect());
|
|
565
661
|
});
|
|
566
|
-
return
|
|
567
|
-
}, [A, de])
|
|
568
|
-
|
|
662
|
+
return y.current && e.observe(document.body, { childList: !0, subtree: !0 }), () => e.disconnect();
|
|
663
|
+
}, [A, de]);
|
|
664
|
+
const Ue = () => {
|
|
665
|
+
y.current && requestAnimationFrame(() => {
|
|
666
|
+
F(y.current);
|
|
667
|
+
});
|
|
668
|
+
};
|
|
669
|
+
return Ge(r, () => ({
|
|
670
|
+
getCurrentValue: K,
|
|
671
|
+
focus: Ue
|
|
569
672
|
})), console.log("renderElements", Ee), // 最外层的防止renderContainer为false的时候样式坍塌
|
|
570
|
-
/* @__PURE__ */ _("div", { className: Ce(`cosmic-ai-input-rows${
|
|
673
|
+
/* @__PURE__ */ _("div", { className: Ce(`cosmic-ai-input-rows${w}`), children: [
|
|
571
674
|
ee && /* @__PURE__ */ f(
|
|
572
675
|
"div",
|
|
573
676
|
{
|
|
574
677
|
"data-set-type": "container",
|
|
575
678
|
"data-cosmic-ai-input-placeholder": k,
|
|
576
|
-
className: Ce(
|
|
577
|
-
|
|
679
|
+
className: Ce(
|
|
680
|
+
"cosmic-ai-input",
|
|
681
|
+
`cosmic-ai-input-rows${w}`,
|
|
682
|
+
{ "is-disabled": D },
|
|
683
|
+
{ "is-empty": X.length === 0 }
|
|
684
|
+
),
|
|
685
|
+
ref: y,
|
|
578
686
|
contentEditable: !0,
|
|
579
687
|
suppressContentEditableWarning: !0,
|
|
580
688
|
onClick: (e) => Le(e),
|
|
@@ -585,19 +693,19 @@ const et = j((s, r) => {
|
|
|
585
693
|
S == null || S(e);
|
|
586
694
|
},
|
|
587
695
|
onMouseDown: (e) => $e(e),
|
|
588
|
-
onKeyDown: (e) =>
|
|
589
|
-
onKeyUp: (e) =>
|
|
696
|
+
onKeyDown: (e) => Fe(e),
|
|
697
|
+
onKeyUp: (e) => Pe(e),
|
|
590
698
|
onInput: (e) => ge(e),
|
|
591
699
|
onCopy: (e) => Oe(e),
|
|
592
700
|
children: Ee
|
|
593
701
|
}
|
|
594
702
|
),
|
|
595
|
-
G &&
|
|
703
|
+
G && Je(
|
|
596
704
|
(L == null ? void 0 : L.type) === "multiple-select" ? /* @__PURE__ */ f(
|
|
597
705
|
Re,
|
|
598
706
|
{
|
|
599
707
|
ref: T,
|
|
600
|
-
options:
|
|
708
|
+
options: le,
|
|
601
709
|
value: Y,
|
|
602
710
|
position: J,
|
|
603
711
|
height: ie,
|
|
@@ -617,7 +725,7 @@ const et = j((s, r) => {
|
|
|
617
725
|
De,
|
|
618
726
|
{
|
|
619
727
|
ref: T,
|
|
620
|
-
options:
|
|
728
|
+
options: le,
|
|
621
729
|
value: Y,
|
|
622
730
|
position: J,
|
|
623
731
|
height: ie,
|
|
@@ -629,7 +737,7 @@ const et = j((s, r) => {
|
|
|
629
737
|
)
|
|
630
738
|
] });
|
|
631
739
|
});
|
|
632
|
-
|
|
740
|
+
tt.displayName = "AiInput";
|
|
633
741
|
export {
|
|
634
|
-
|
|
742
|
+
tt as default
|
|
635
743
|
};
|