UNPKG

chatarea

Version:

纯JS封装的聊天框,交互功能对标钉钉微信聊天框,适用于JQuery/React/Vue等各大框架,兼容PC与H5的使用

1 lines 127 kB
var __defProp=Object.defineProperty,__defNormalProp=(t,e,i)=>e in t?__defProp(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,__publicField=(t,e,i)=>__defNormalProp(t,"symbol"!=typeof e?e+"":e,i);function os(){const t=navigator.userAgent,e=/(?:Windows Phone)/.test(t),i=/(?:SymbianOS)/.test(t)||e,n=/(?:Android)/.test(t),s=/(?:Firefox)/.test(t),a=/(?:iPad|PlayBook)/.test(t)||n&&!/(?:Mobile)/.test(t)||s&&/(?:Tablet)/.test(t),l=/(?:iPhone)/.test(t)&&!a;return{isTablet:a,isPhone:l,isAndroid:n,isPc:!l&&!n&&!i}}function domItVisible(t,e=!1,i="block"){t&&(t.className=t.className.replace(/ chat-view-show| chat-view-hidden/g,""),e?(t.style.display=i,t.className+=" chat-view-show"):(t.className+=" chat-view-hidden",t.style.display="none"))}function hasElmShow(t){return t&&t.classList.contains("chat-view-show")}function updateElmClass(t,e,i){t.classList[i?"add":"remove"](e)}const ELEMENT_EMPTY_KEY="data-set-empty",ELEMENT_RICH_TYPE_KEY="data-set-richType",RICH_WRAP="richWrap",RICH_GRID="richGrid",RICH_MARK="richMark",RICH_INPUT="richInput",RICH_TAG="richTag",ELEMENT_COMPONENT_KEY="data-set-component",sleep=(t=50)=>new Promise(e=>{setTimeout(e,t)}),getBoolean=t=>"false"!==String(t)&&"null"!==String(t)&&"0"!==String(t),debounce=(t,e,i=!1)=>{let n;return function(...s){const a=this,l=i&&!n;clearTimeout(n),n=setTimeout(()=>{n=null,i||t.apply(a,s)},e),l&&t.apply(a,s)}},throttle=(t,e)=>{let i;return function(...n){const s=this;i||(t.apply(s,n),i=!0,setTimeout(function(){i=!1},e))}},upFindElm=(t,e)=>{const i=t.getAttribute("data-set-richType");return i===RICH_GRID?null:i===RICH_MARK||i===RICH_TAG?t:t.parentElement&&e>0?upFindElm(t.parentElement,e-1):null},getObjValue=(t,e,i)=>t&&t[e]?t[e]:i,strictMinifyHtml=t=>t.replace(/\n+/g,"").replace(/\s+/g," ").replace(/>\s+</g,"><").trim(),convertBlocksToSpans=(t,e)=>{const i=document.createElement("div");i.innerHTML=t;i.querySelectorAll("div, p, h1, h2, h3, h4, h5, h6, section, article, header, footer, aside, nav").forEach(t=>{const e=document.createElement("span");for(e.style.display="block",Array.from(t.attributes).forEach(t=>{e.setAttribute(t.name,t.value)});t.firstChild;)e.appendChild(t.firstChild);t.parentNode.replaceChild(e,t)});const n=i.children[0];if(n&&"block"===n.style.display&&(n.style.display="inline-block"),n){for(const t in e)n.dataset[t]="{{"+t+"}}";n.setAttribute("data-set-component","{{data-set-component}}")}return i.innerHTML};function replaceTemplateVariables(t,e){let i=t;for(const[t,n]of Object.entries(e)){const e=`{{${t}}}`;i=i.replace(new RegExp(e,"g"),String(n))}return i}function escapeHtml(t){return t.replace(/[&<>"']/g,t=>{switch(t){case"&":return"&amp;";case"<":return"&lt;";case">":return"&gt;";case'"':return"&quot;";case"'":return"&#039;";default:return t}}).replace(/\s/g,"&nbsp;")}function isKeyType(t,e){switch(e){case"text-delete":return"Backspace"===t.key||"Backspace"===t.code||8===t.keyCode;case"text-move":return"ArrowLeft"===t.key||"ArrowRight"===t.key||"ArrowLeft"===t.code||"ArrowRight"===t.code||37===t.keyCode||39===t.keyCode;case"text-select-all":return(t.ctrlKey||t.metaKey)&&("A"===t.key||"a"===t.key||"KeyA"===t.code||65===t.keyCode);case"text-undo":return(t.ctrlKey||t.metaKey)&&("Z"===t.key||"z"===t.key||"KeyZ"===t.code||90===t.keyCode);case"text-redo":return(t.ctrlKey||t.metaKey)&&("Y"===t.key||"y"===t.key||"KeyY"===t.code||89===t.keyCode);case"text-write":return t.isComposing||!t.ctrlKey&&!t.altKey&&!["Backspace","Shift","Tab","CapsLock","Control","Meta","Alt","ContextMenu","Enter","NumpadEnter","Escape","ArrowLeft","ArrowUp","ArrowRight","ArrowDown","Home","End","PageUp","PageDown","Insert","Delete","NumLock"].includes(t.key);case"dialog-options":return"ArrowUp"===t.key||"ArrowDown"===t.key||"Enter"===t.key||"ArrowUp"===t.code||"ArrowDown"===t.code||"Enter"===t.code||"NumpadEnter"===t.code||38===t.keyCode||40===t.keyCode||13===t.keyCode;case"IME":return"Unidentified"===t.key||229===t.keyCode;default:return!1}}function pinyinMatch(t,e,i){const n=e.split(/\s+/),s=t.split("").map((t,i)=>{let s=n[i]||"";return""===e&&""===s&&(s=t),{char:t,pinyin:s.toLowerCase(),initial:s?s[0].toLowerCase():""}}),a=(t=>{const e=[];let i="";for(const n of t)/[a-zA-Z]/.test(n)?i+=n.toLowerCase():(i&&(e.push({type:"pinyin",value:i}),i=""),e.push({type:"char",value:n}));return i&&e.push({type:"pinyin",value:i}),e})(i),l=s.length,o=a.length,r=Array.from({length:l+1},()=>Array(o+1).fill(!1));r[0][0]=!0;for(let t=0;t<=l;t++)for(let e=0;e<=o;e++)if(r[t][e]&&e<o){const i=a[e];for(let n=t;n<l;n++){const t=s[n];if("char"===i.type)t.char===i.value&&(r[n+1][e+1]=!0);else{const a=t.pinyin.toLowerCase(),o=t.initial,c=i.value;if(c===o)r[n+1][e+1]=!0;else if(c===a)r[n+1][e+1]=!0;else if(isSubsequence(c,a))r[n+1][e+1]=!0;else for(let t=2;t<=l-n;t++){const i=s.slice(n,n+t),a=i.map(t=>t.pinyin.toLowerCase()).join(""),l=i.map(t=>t.initial).join("");if(c===a||c===l||isSubsequence(c,a)){r[n+t][e+1]=!0;break}}}}}for(let t=0;t<=l;t++)if(r[t][o])return!0;return!1}function isSubsequence(t,e){let i=0,n=0;for(;i<t.length&&n<e.length;)t[i]===e[n]&&i++,n++;return i===t.length}const checkEmptySvg='<svg class="check-empty-svg" viewBox="0 0 64 41" xmlns="http://www.w3.org/2000/svg"><g transform="translate(0 1)" fill="none" fill-rule="evenodd"><ellipse fill="#f5f5f5" cx="32" cy="33" rx="32" ry="7"></ellipse><g fill-rule="nonzero" stroke="#d9d9d9"><path d="M55 12.76L44.854 1.258C44.367.474 43.656 0 42.907 0H21.093c-.749 0-1.46.474-1.947 1.257L9 12.761V22h46v-9.24z"></path><path d="M41.613 15.931c0-1.605.994-2.93 2.227-2.931H55v18.137C55 33.26 53.68 35 52.05 35h-40.1C10.32 35 9 33.259 9 31.137V13h11.16c1.233 0 2.227 1.323 2.227 2.928v.022c0 1.605 1.005 2.901 2.237 2.901h14.752c1.232 0 2.237-1.308 2.237-2.913v-.007z" fill="#fafafa"></path></g></g></svg>',searchEmptySvg='<svg class="empty-svg" viewBox="0 0 64 41" xmlns="http://www.w3.org/2000/svg"><g transform="translate(0 1)" fill="none" fill-rule="evenodd"><ellipse fill="#f5f5f5" cx="32" cy="33" rx="32" ry="7"></ellipse><g fill-rule="nonzero" stroke="#d9d9d9"><path d="M55 12.76L44.854 1.258C44.367.474 43.656 0 42.907 0H21.093c-.749 0-1.46.474-1.947 1.257L9 12.761V22h46v-9.24z"></path><path d="M41.613 15.931c0-1.605.994-2.93 2.227-2.931H55v18.137C55 33.26 53.68 35 52.05 35h-40.1C10.32 35 9 33.259 9 31.137V13h11.16c1.233 0 2.227 1.323 2.227 2.928v.022c0 1.605 1.005 2.901 2.237 2.901h14.752c1.232 0 2.237-1.308 2.237-2.913v-.007z" fill="#fafafa"></path></g></g></svg>',searchSvg='<svg class="icon-search" style="vertical-align: middle;fill: currentColor;overflow: hidden;" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg"><path d="M684.8 223.530667a326.272 326.272 0 0 1 24.96 433.621333c2.645333 2.133333 5.290667 4.48 7.850667 7.04L870.4 817.066667c24.789333 24.746667 32.896 56.832 18.133333 71.594666-14.762667 14.805333-46.848 6.656-71.637333-18.090666l-152.789333-152.832a106.282667 106.282667 0 0 1-7.210667-7.936 326.101333 326.101333 0 0 1-433.109333-25.173334c-127.445333-127.445333-127.573333-333.952-0.256-461.269333 127.36-127.36 333.866667-127.232 461.269333 0.213333zM275.328 275.114667a252.885333 252.885333 0 0 0 0.256 357.632 252.885333 252.885333 0 0 0 357.632 0.256 252.885333 252.885333 0 0 0-0.256-357.632 252.885333 252.885333 0 0 0-357.632-0.256z" fill="#9B9B9B"></path></svg>',antdLoading='<div class="ant-spin ant-spin-spinning" aria-live="polite" aria-busy="true"><span class="ant-spin-dot ant-spin-dot-spin"><i class="ant-spin-dot-item"></i><i class="ant-spin-dot-item"></i><i class="ant-spin-dot-item"></i><i class="ant-spin-dot-item"></i></span></div>',matchEmptySvg='<svg class="match-empty-svg" viewBox="0 0 64 41" xmlns="http://www.w3.org/2000/svg"><g transform="translate(0 1)" fill="none" fill-rule="evenodd"><ellipse fill="#f5f5f5" cx="32" cy="33" rx="32" ry="7"></ellipse><g fill-rule="nonzero" stroke="#d9d9d9"><path d="M55 12.76L44.854 1.258C44.367.474 43.656 0 42.907 0H21.093c-.749 0-1.46.474-1.947 1.257L9 12.761V22h46v-9.24z"></path><path d="M41.613 15.931c0-1.605.994-2.93 2.227-2.931H55v18.137C55 33.26 53.68 35 52.05 35h-40.1C10.32 35 9 33.259 9 31.137V13h11.16c1.233 0 2.227 1.323 2.227 2.928v.022c0 1.605 1.005 2.901 2.237 2.901h14.752c1.232 0 2.237-1.308 2.237-2.913v-.007z" fill="#fafafa"></path></g></g></svg>',checkSvg='<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" fill="none" viewBox="0 0 24 24"><path fill="currentColor" d="M9.218 17.41 19.83 6.796a.99.99 0 1 1 1.389 1.415c-3.545 3.425-4.251 4.105-11.419 11.074a.997.997 0 0 1-1.375.018c-1.924-1.801-3.709-3.568-5.573-5.43a.999.999 0 0 1 1.414-1.413z"></path></svg>',arrowSvg='<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" fill="none" viewBox="0 0 24 24"><path fill="currentColor" d="m20.23 8.653-7.795 9.685a1.2 1.2 0 0 1-1.87 0L2.771 8.652C2.14 7.867 2.698 6.7 3.706 6.7h15.588c1.008 0 1.567 1.167.935 1.952"></path></svg>',closeSvg='<svg focusable="false" data-icon="close-circle" width="1em" height="1em" fill="currentColor" aria-hidden="true" fill-rule="evenodd" viewBox="64 64 896 896"><path d="M512 64c247.4 0 448 200.6 448 448S759.4 960 512 960 64 759.4 64 512 264.6 64 512 64zm127.98 274.82h-.04l-.08.06L512 466.75 384.14 338.88c-.04-.05-.06-.06-.08-.06a.12.12 0 00-.07 0c-.03 0-.05.01-.09.05l-45.02 45.02a.2.2 0 00-.05.09.12.12 0 000 .07v.02a.27.27 0 00.06.06L466.75 512 338.88 639.86c-.05.04-.06.06-.06.08a.12.12 0 000 .07c0 .03.01.05.05.09l45.02 45.02a.2.2 0 00.09.05.12.12 0 00.07 0c.02 0 .04-.01.08-.05L512 557.25l127.86 127.87c.04.04.06.05.08.05a.12.12 0 00.07 0c.03 0 .05-.01.09-.05l45.02-45.02a.2.2 0 00.05-.09.12.12 0 000-.07v-.02a.27.27 0 00-.05-.06L557.25 512l127.87-127.86c.04-.04.05-.06.05-.08a.12.12 0 000-.07c0-.03-.01-.05-.05-.09l-45.02-45.02a.2.2 0 00-.09-.05.12.12 0 00-.07 0z"></path></svg>';class ChatElement{constructor(t){__publicField(this,"target"),__publicField(this,"richText",document.createElement("div")),__publicField(this,"placeholderElm",document.createElement("div")),__publicField(this,"tipElm",null),__publicField(this,"isExternalCallPopup",!1),__publicField(this,"isPointSearchMode",!1),__publicField(this,"checkboxRows",[]),__publicField(this,"customTags",{}),__publicField(this,"selectTags",{}),__publicField(this,"rects",{}),__publicField(this,"pcElms",{containerDialogElm:null,pointDialogElm:null,pointDialogCheckElm:null,pointDialogMainElm:null,pointDialogUsersElm:[],pointDialogActiveElm:null,pointDialogLoadingElm:null,pointDialogEmptyElm:null,checkDialogElm:null,checkDialogSearchResultElm:null,checkDialogUsersElm:null,checkDialogSearchInputElm:null,checkDialogTagsElm:null,customTagDialogElms:{},customTagDialogTagKey:"",customTagDialogActiveElm:null,selectDialogElms:{},selectDialogKey:"",selectDialogAim:null,tipContainerPopoverElm:null,tipPopoverElm:null}),__publicField(this,"h5Elms",{dialogElm:null,dialogMainElm:null,dialogCheckElm:null,dialogShowElm:null,dialogSearchElm:null,dialogEmptyElm:null,dialogLoadingElm:null}),this.target=t,this.createRichText(),this.createPlaceholder(),t.deviceInfo.isPc?this.createPCDialog():this.createH5Dialog()}createRichText(){const{options:t,deviceInfo:e}=this.target,{elm:i}=t;updateElmClass(i,"chat-area-"+(e.isPc?"pc":"h5"),!0),updateElmClass(this.richText,"chat-rich-text",!0),this.richText.setAttribute("data-set-richType",RICH_WRAP),this.richText.setAttribute("contenteditable","true"),i.appendChild(this.richText)}createPlaceholder(){const{options:t}=this.target,{elm:e}=t;updateElmClass(this.placeholderElm,"chat-placeholder-wrap",!0),domItVisible(this.placeholderElm,!0),e.appendChild(this.placeholderElm),this.rects.plaRect=this.placeholderElm.getBoundingClientRect()}createPCDialog(){const{options:t}=this.target,{needDialog:e,elm:i,asyncMatch:n}=t;if(!e)return;const{pcElms:s}=this;s.containerDialogElm=document.createElement("div"),updateElmClass(this.pcElms.containerDialogElm,"chat-dialog",!0),i.nextElementSibling?i.parentElement.insertBefore(s.containerDialogElm,i.nextElementSibling):i.parentElement.appendChild(s.containerDialogElm),n||this.createPCCheckDialog(),this.createPCPointDialog()}createPCCheckDialog(){const{options:t}=this.target,e=this.target.options.dialogLabels.pcPCheckDialog,{pcElms:i}=this;i.checkDialogElm=document.createElement("div"),updateElmClass(i.checkDialogElm,"checkbox-dialog",!0),domItVisible(i.checkDialogElm),i.checkDialogElm.innerHTML=`\n <div class="checkbox-dialog-container">\n <div class="checkbox-dialog-container-header">\n <span>${e.title}</span>\n <span class="checkbox-dialog-container-header-close">⛌</span>\n </div>\n <div class="checkbox-dialog-container-body">\n <div class="checkbox-dialog-left-box">\n <div class="checkbox-dialog-search">\n <input class="checkbox-dialog-search-input" placeholder="${e.searchPlaceholder}" type="text">\n <div class="checkbox-dialog-search-group"></div>\n </div>\n <div class="checkbox-dialog-tags"></div>\n <div class="checkbox-dialog-option">\n <button class="checkbox-dialog-option-btn btn-submit disabled">${e.confirmLabel}</button>\n <button class="checkbox-dialog-option-btn btn-close">${e.cancelLabel}</button>\n </div>\n </div>\n <div class="checkbox-dialog-right-box">\n <div class="checkbox-dialog-right-box-title">${e.userTagTitle}</div>\n <div class="checkbox-dialog-check-group"></div>\n </div>\n </div>\n </div>\n `,i.containerDialogElm.appendChild(i.checkDialogElm),i.checkDialogUsersElm=i.checkDialogElm.querySelector(".checkbox-dialog-check-group"),i.checkDialogSearchResultElm=i.checkDialogElm.querySelector(".checkbox-dialog-search-group"),i.checkDialogSearchInputElm=i.checkDialogElm.querySelector(".checkbox-dialog-search-input"),i.checkDialogTagsElm=i.checkDialogElm.querySelector(".checkbox-dialog-tags");const n=()=>{domItVisible(i.checkDialogElm),updateElmClass(document.body,"disable-scroll")};i.checkDialogElm.querySelector(".checkbox-dialog-container-header-close").onclick=n,i.checkDialogElm.querySelector(".btn-close").onclick=n;const s=i.checkDialogElm.querySelector(".btn-submit");s.onclick=async()=>{if(s.classList.contains("disabled"))return;const e=this.checkboxRows.map(e=>{const i=Object.create(null);return i[t.userProps.id]=e.id,i[t.userProps.name]=e.name,i});await this.target.batchSetTag(e),n()},domItVisible(i.checkDialogSearchResultElm),i.checkDialogSearchResultElm.onclick=t=>{t.stopPropagation()},i.checkDialogSearchInputElm.onclick=t=>{t.stopPropagation()};const a=debounce(t=>{const e=String(t.target.value||"").replace(/'/g,"").trim();if(!e)return void domItVisible(i.checkDialogSearchResultElm);const n=this.target.searchUserList(e).map(t=>t.id);Array.from(i.checkDialogSearchResultElm.children,(t,e)=>{if(e===i.checkDialogSearchResultElm.children.length-1)domItVisible(t,0===n.length);else{const e=t.getAttribute("data-set-id");domItVisible(t,-1!==n.indexOf(e),"flex")}}),domItVisible(i.checkDialogSearchResultElm,!0)},200);i.checkDialogSearchInputElm.oninput=a,i.checkDialogSearchInputElm.onfocus=a}createPCPointDialog(){const{pcElms:t,target:e}=this;t.pointDialogElm=document.createElement("div"),updateElmClass(t.pointDialogElm,"call-user-dialog",!0),domItVisible(t.pointDialogElm);const i=document.createElement("div");updateElmClass(i,"call-user-dialog-header",!0),i.innerHTML=`<span class="call-user-dialog-header-title">${e.options.dialogLabels.pcPointDialog.title}</span>`,t.pointDialogCheckElm=document.createElement("span"),updateElmClass(t.pointDialogCheckElm,"call-user-dialog-header-check",!0),t.pointDialogCheckElm.innerText=e.options.dialogLabels.pcPointDialog.checkLabel,t.pointDialogCheckElm.onclick=()=>{this.target.showPCCheckDialog(),this.isExternalCallPopup=!1},i.appendChild(t.pointDialogCheckElm),t.pointDialogElm.appendChild(i),t.pointDialogMainElm=document.createElement("div"),updateElmClass(t.pointDialogMainElm,"call-user-dialog-main",!0),t.pointDialogElm.appendChild(t.pointDialogMainElm),e.options.asyncMatch&&(t.pointDialogLoadingElm=document.createElement("div"),updateElmClass(t.pointDialogLoadingElm,"call-user-dialog-loading",!0),t.pointDialogLoadingElm.innerHTML=antdLoading,t.pointDialogElm.appendChild(t.pointDialogLoadingElm),domItVisible(t.pointDialogLoadingElm),t.pointDialogEmptyElm=document.createElement("div"),updateElmClass(t.pointDialogEmptyElm,"call-user-dialog-empty",!0),t.pointDialogEmptyElm.innerHTML=`\n ${matchEmptySvg}\n <span class="empty-label">${e.options.dialogLabels.pcPointDialog.emptyLabel}</span>\n `,t.pointDialogElm.appendChild(t.pointDialogEmptyElm),domItVisible(t.pointDialogEmptyElm)),t.containerDialogElm.appendChild(t.pointDialogElm)}createH5Dialog(){const{options:t,chatEvent:e}=this.target,{needDialog:i,dialogLabels:n}=t;if(!i)return;const{h5Elms:s}=this;s.dialogElm=document.createElement("div"),updateElmClass(s.dialogElm,"call-user-popup",!0),s.dialogElm.innerHTML=`\n <div class="call-user-popup-main">\n <div class="call-user-popup-header">\n <span class="popup-show">${n.h5Dialog.cancelLabel}</span>\n <span class="popup-title">${n.h5Dialog.title}</span>\n <span class="popup-check">${n.h5Dialog.confirmLabel}</span>\n </div>\n <div class="call-user-popup-search">\n ${searchSvg}\n <input class="call-user-popup-search-input"\n placeholder="${n.h5Dialog.searchPlaceholder}"\n type="text">\n </div>\n <div class="call-user-popup-body"></div>\n </div>\n `;const a=async()=>{s.dialogElm.className=s.dialogElm.className.replace(/ chat-view-show/g," chat-view-hidden"),s.dialogSearchElm.value="",await sleep(260),domItVisible(s.dialogElm),updateElmClass(document.body,"disable-scroll"),t.asyncMatch&&this.target.updateUserList([]),this.target.chatInput.restCursorPos(this.target.chatInput.vnode,this.target.chatInput.cursorIndex),this.target.chatInput.viewIntoPoint()};s.dialogElm.onclick=a;const l=s.dialogElm.querySelector(".call-user-popup-main");l.onclick=t=>{t.stopPropagation()},s.dialogShowElm=s.dialogElm.querySelector(".popup-show"),s.dialogShowElm.onclick=a,s.dialogCheckElm=s.dialogElm.querySelector(".popup-check"),s.dialogCheckElm.onclick=async()=>{if(s.dialogCheckElm.classList.contains("disabled"))return;const e=s.dialogElm.querySelectorAll(".user-popup-check-item-check")||[];if(0===e.length)return void await a();if(Array.prototype.some.call(e,t=>"isALL"===t.getAttribute("data-set-id")))return await this.target.onceSetTag({[t.userProps.id]:"isALL",[t.userProps.name]:t.dialogLabels.h5Dialog.callEveryLabel}),void await a();const i=Array.from(e,t=>t.getAttribute("data-set-id")),n=t.userList.filter(e=>-1!==i.indexOf(String(e[t.userProps.id])));await this.target.batchSetTag(n),await a()},s.dialogMainElm=s.dialogElm.querySelector(".call-user-popup-body"),s.dialogEmptyElm=document.createElement("div"),updateElmClass(s.dialogEmptyElm,"call-user-popup-empty",!0),this.h5Elms.dialogEmptyElm.innerHTML=`\n ${searchEmptySvg}\n <span class="empty-label">${t.dialogLabels.h5Dialog.searchEmptyLabel}</span>\n `,domItVisible(s.dialogEmptyElm),l.appendChild(s.dialogEmptyElm),t.asyncMatch&&(s.dialogLoadingElm=document.createElement("div"),updateElmClass(s.dialogLoadingElm,"call-user-popup-loading",!0),s.dialogLoadingElm.innerHTML=antdLoading,domItVisible(s.dialogLoadingElm),l.appendChild(s.dialogLoadingElm)),s.dialogSearchElm=s.dialogElm.querySelector(".call-user-popup-search-input"),s.dialogSearchElm.oninput=debounce(i=>{const n=String(i.target.value||"").replace(/'/g,"").trim();if(t.asyncMatch){e.matchKey++;const t=e.matchKey;this.target.updateUserList([]),domItVisible(s.dialogLoadingElm,!0),domItVisible(s.dialogEmptyElm);const i=e.triggerChatEvent("atMatch",n).find(t=>t&&t instanceof Promise);return void(i&&i.then(i=>{t===e.matchKey&&(domItVisible(s.dialogLoadingElm),!i||i.length<=0?domItVisible(s.dialogEmptyElm,!0,"flex"):this.target.updateUserList(i))}))}const a=[];Array.from(this.h5Elms.dialogMainElm.children,t=>{if(!n)return domItVisible(t,!0,"flex"),void a.push(t);pinyinMatch(t.getAttribute("data-set-name")||"",t.getAttribute("data-set-pinyin")||"",n)?(domItVisible(t,!0,"flex"),a.push(t)):domItVisible(t)}),domItVisible(this.h5Elms.dialogEmptyElm,!a.length,"flex")},200),domItVisible(s.dialogElm),document.body.appendChild(s.dialogElm)}updatePCUser(){const{pcElms:t,target:e}=this;t.pointDialogMainElm.innerHTML="",t.pointDialogActiveElm=void 0;const i=document.createDocumentFragment();if(this.target.options.needCallEvery){const t=document.createElement("div");updateElmClass(t,"call-user-dialog-item",!0),t.setAttribute("data-set-id","isALL"),this.userSelectStyleAndEvent(t,{id:"isALL",name:e.options.dialogLabels.pcPointDialog.callEveryLabel}),t.innerHTML=`\n <span class="call-user-dialog-item-sculpture">\n <span style="transform: scale(0.75)">@</span>\n </span>\n <span class="call-user-dialog-item-name">${e.options.dialogLabels.pcPointDialog.callEveryLabel}(${e.options.reformList.length})</span>\n `,i.appendChild(t)}if(e.options.reformList.forEach(t=>{const e=document.createElement("div");updateElmClass(e,"call-user-dialog-item",!0),e.setAttribute("data-set-id",t.id),this.userSelectStyleAndEvent(e,t),this.getUserHtmlTemplate(e,t),i.appendChild(e)}),t.pointDialogMainElm.appendChild(i),t.pointDialogUsersElm=[],Array.from(t.pointDialogMainElm.children||[],(e,i)=>{t.pointDialogUsersElm.push({index:i,elm:e})}),e.options.asyncMatch)return;t.checkDialogUsersElm.innerHTML=`\n <div class="checkbox-dialog-check-item" data-set-value="ALL">\n <input type="checkbox" value>\n <span class="checkbox-dialog-check-item-inner"></span>\n <div class="checkbox-dialog-check-item-label">${e.options.dialogLabels.pcPCheckDialog.checkAllLabel}</div>\n </div>\n `;const n=document.createDocumentFragment();e.options.reformList.forEach(t=>{const e=document.createElement("div");updateElmClass(e,"checkbox-dialog-check-item",!0),e.setAttribute("data-set-value",t.id),e.innerHTML='\n <input type="checkbox" value>\n <span class="checkbox-dialog-check-item-inner"></span>\n ',this.getUserHtmlTemplate(e,t),n.appendChild(e)}),t.checkDialogUsersElm.appendChild(n),t.checkDialogUsersElm&&t.checkDialogUsersElm.children.length&&Array.from(t.checkDialogUsersElm.children,t=>{t.onclick=()=>{const i=t.getAttribute("data-set-value")||"",n=e.options.reformList.find(t=>t.id===i),s=-1===t.className.indexOf("checkbox-dialog-check-item-check");"ALL"===i?this.checkboxRows=s?e.options.reformList.map(t=>t):[]:s?this.checkboxRows.push(n):this.checkboxRows=this.checkboxRows.filter(t=>t.id!==i),this.updateCheckDialogTags()}}),t.checkDialogSearchResultElm.innerHTML="";const s=document.createDocumentFragment();e.options.reformList.forEach(t=>{const i=document.createElement("div");updateElmClass(i,"checkbox-dialog-check-item",!0),i.setAttribute("data-set-id",t.id);const n=document.createElement("div");updateElmClass(n,"checkbox-dialog-check-item-label",!0),this.getUserHtmlTemplate(n,t),i.appendChild(n),i.onclick=()=>{domItVisible(this.pcElms.checkDialogSearchResultElm);const t=i.getAttribute("data-set-id")||"";if(this.pcElms.checkDialogSearchInputElm.value="",this.pcElms.checkDialogSearchInputElm.focus(),this.checkboxRows.some(e=>e.id===t))return;const n=e.options.reformList.find(e=>e.id===t);n&&this.checkboxRows.push(n),this.updateCheckDialogTags()},s.appendChild(i)});const a=document.createElement("div");updateElmClass(a,"checkbox-dialog-search-empty",!0),a.innerText=e.options.dialogLabels.pcPCheckDialog.searchEmptyLabel,s.appendChild(a),t.checkDialogSearchResultElm.appendChild(s)}updateH5User(){const{h5Elms:t,target:e}=this;t.dialogMainElm.innerHTML="";const i=e.options.reformList&&e.options.reformList.length>0,n=document.createDocumentFragment(),s=document.createElement("span");if(s.innerHTML='\n <input type="checkbox" value>\n <span class="user-popup-check-item-inner"></span>\n ',i){const t=document.createElement("div");e.options.needCallEvery&&(updateElmClass(t,"call-user-popup-item",!0),t.setAttribute("data-set-id","isALL"),t.innerHTML=`\n <span class="call-user-dialog-item-sculpture">\n <span style="transform: scale(0.75)">@</span>\n </span>\n <span class="call-user-dialog-item-name">${e.options.dialogLabels.h5Dialog.callEveryLabel}(${e.options.reformList.length})</span>\n `,t.appendChild(s.cloneNode(!0)),t.onclick=()=>{const e=!t.classList.contains("user-popup-check-item-check");Array.from(this.h5Elms.dialogMainElm.children,t=>{updateElmClass(t,"user-popup-check-item-check",e)}),updateElmClass(this.h5Elms.dialogCheckElm,"disabled",!e)},n.appendChild(t)),e.options.reformList.forEach((e,i)=>{const a=document.createElement("div");updateElmClass(a,"call-user-popup-item",!0),a.setAttribute("data-set-id",e.id),a.setAttribute("data-set-name",e.name),a.setAttribute("data-set-pinyin",e.pinyin||""),this.getUserHtmlTemplate(a,e),a.appendChild(s.cloneNode(!0)),n.appendChild(a),a.onclick=e=>{const i=!a.classList.contains("user-popup-check-item-check");updateElmClass(a,"user-popup-check-item-check",i);const n=Array.prototype.every.call(this.h5Elms.dialogMainElm.children,t=>t.classList.contains("user-popup-check-item-check")||"isALL"===t.getAttribute("data-set-id"));updateElmClass(t,"user-popup-check-item-check",n);const s=Array.prototype.some.call(this.h5Elms.dialogMainElm.children,t=>t.classList.contains("user-popup-check-item-check"));updateElmClass(this.h5Elms.dialogCheckElm,"disabled",!s)}})}t.dialogMainElm.appendChild(n)}updateCheckDialogTags(){const t=this.checkboxRows.map(t=>t.id),e=[],i=[],n=document.createElement("div");n.className="check-empty",n.innerHTML=`\n ${checkEmptySvg}\n <span class="check-empty-label">${this.target.options.dialogLabels.pcPCheckDialog.checkEmptyLabel}</span>\n `,Array.from(this.pcElms.checkDialogTagsElm.children,n=>{const s=n.getAttribute("data-set-value");-1===t.indexOf(s)?i.push(n):e.push(s)}),Array.from(this.pcElms.checkDialogUsersElm.children,(e,i)=>{if(0===i)return void updateElmClass(e,"checkbox-dialog-check-item-check",t.length===this.target.options.reformList.length);const n=e.getAttribute("data-set-value");updateElmClass(e,"checkbox-dialog-check-item-check",-1!==t.indexOf(n))}),i.forEach(t=>{this.pcElms.checkDialogTagsElm.removeChild(t)});updateElmClass(this.pcElms.checkDialogElm.querySelector(".btn-submit"),"disabled",t.length<=0),t.length||this.pcElms.checkDialogTagsElm.appendChild(n);const s=this.checkboxRows.filter(t=>-1===e.indexOf(t.id));if(!s.length)return;const a=document.createDocumentFragment();s.forEach(t=>{const e=document.createElement("div");e.setAttribute("class","checkbox-dialog-tag-item"),e.setAttribute("data-set-value",t.id),e.innerHTML=`\n <span>${t.name}</span>\n `;const i=document.createElement("span");i.setAttribute("class","checkbox-dialog-tag-item-close"),i.innerHTML="⛌",i.onclick=()=>{const t=e.getAttribute("data-set-value");this.checkboxRows=this.checkboxRows.filter(e=>e.id!==t),this.updateCheckDialogTags()},e.appendChild(i),a.appendChild(e)}),this.pcElms.checkDialogTagsElm.appendChild(a)}userSelectStyleAndEvent(t,e){t.addEventListener("click",async i=>{const{options:n}=this.target;if(i.stopPropagation(),this.updatePointActiveUserElm(t),this.isPointSearchMode||n.asyncMatch)await this.target.matchSetTag(e);else{const t=n.userList.find(t=>String(t[n.userProps.id])===e.id);await this.target.onceSetTag(t)}this.exitPointDialog()})}bindCustomTrigger(){Object.values(this.pcElms.customTagDialogElms).forEach(t=>{this.pcElms.containerDialogElm.removeChild(t)}),this.pcElms.customTagDialogElms={},this.customTags={},this.target.options.customTrigger.forEach(t=>{t.tagList&&t.tagList.length>0&&(this.customTags[t.prefix]=t.tagList.map(t=>({id:String(t.id),name:String(t.name),pinyin:String(t.pinyin||"")})),this.createCustomTagDialog(t))})}createCustomTagDialog(t){const e=document.createElement("div");e.setAttribute("class","call-tag-dialog"),domItVisible(e);const i=document.createElement("div");i.setAttribute("class","call-tag-dialog-header"),i.innerHTML=`<span class="call-tag-dialog-header-title">${t.dialogTitle||t.prefix}</span>`,e.appendChild(i);const n=document.createElement("div");n.setAttribute("class","call-tag-dialog-main"),t.tagList.forEach(t=>{const e=document.createElement("div");e.setAttribute("class","call-tag-dialog-item"),e.setAttribute("data-set-id",t.id);const i=document.createElement("span");i.setAttribute("class","call-tag-dialog-item-name"),i.innerHTML=t.name,e.appendChild(i),e.addEventListener("click",async i=>{i.stopPropagation(),this.updateActiveCustomTagElm(e),this.isPointSearchMode?await this.target.matchSetCustomTag(t):await this.target.onceSetCustomTag(t),this.exitCustomTagDialog()}),n.appendChild(e)}),e.appendChild(n),this.pcElms.containerDialogElm.appendChild(e),this.pcElms.customTagDialogElms[t.prefix]=e}getUserHtmlTemplate(t,e){const i=document.createElement("span");if(i.setAttribute("class","call-user-dialog-item-sculpture "+(e.avatar?"is-avatar":"")),e.avatar){const t=new Image;t.alt="",t.src=String(e.avatar),i.appendChild(t)}else i.innerHTML=`<span style="transform: scale(0.75)">${e.name.slice(-2)}</span>`;t.appendChild(i);const n=document.createElement("span");n.setAttribute("class","call-user-dialog-item-name"),n.innerHTML=e.name,t.appendChild(n)}updatePointActiveUserElm(t,e=!1){if(this.pcElms.pointDialogActiveElm&&updateElmClass(this.pcElms.pointDialogActiveElm,"call-user-dialog-item-active"),this.pcElms.pointDialogActiveElm=t,t&&(updateElmClass(t,"call-user-dialog-item-active",!0),e)){const e=Array.prototype.filter.call(this.pcElms.pointDialogMainElm.children,t=>-1===t.className.indexOf("user-no-match")),i=t.clientHeight,n=Array.prototype.indexOf.call(e,t)+1-Math.ceil(Math.floor(this.pcElms.pointDialogMainElm.clientHeight/i)/2);this.pcElms.pointDialogMainElm.scrollTop=n>0?n*i:0}}updateActiveCustomTagElm(t,e=!1){if(this.pcElms.customTagDialogActiveElm&&updateElmClass(this.pcElms.customTagDialogActiveElm,"call-tag-dialog-item-active"),this.pcElms.customTagDialogActiveElm=t,t&&(updateElmClass(t,"call-tag-dialog-item-active",!0),e)){const e=this.pcElms.customTagDialogElms[this.pcElms.customTagDialogTagKey].children[1],i=Array.prototype.filter.call(e.children,t=>-1===t.className.indexOf("tag-no-match")),n=t.clientHeight,s=Array.prototype.indexOf.call(i,t)+1-Math.ceil(Math.floor(e.clientHeight/n)/2);e.scrollTop=s>0?s*n:0}}showPointDialog(t){this.exitSelectDialog(),this.exitCustomTagDialog(),this.exitPointDialog(),this.isPointSearchMode=!!t;let e=null;this.pcElms.pointDialogUsersElm.forEach(i=>{const n=i.elm,s=n.getAttribute("data-set-id"),a=t&&t.every(t=>t.id!==s);e||a||(e=n),updateElmClass(n,"user-no-match",a)}),null!==e&&this.updatePointActiveUserElm(e),domItVisible(this.pcElms.pointDialogCheckElm,!this.target.options.asyncMatch&&!this.isPointSearchMode),domItVisible(this.pcElms.pointDialogElm,!0),this.target.chatEvent.debounceEvents.dialogMoveToRange(this.pcElms.pointDialogElm),this.pcElms.pointDialogMainElm.scrollTop=0}showCustomTagDialog(t,e){this.exitSelectDialog(),this.exitCustomTagDialog(),this.exitPointDialog(),this.isPointSearchMode=!!e,this.pcElms.customTagDialogTagKey=t;const i=this.pcElms.customTagDialogElms[t],n=i.children[1];let s=null;Array.from(n.children,t=>{const i=t.getAttribute("data-set-id"),n=e&&e.every(t=>t.id!==i);s||n||(s=t),updateElmClass(t,"tag-no-match",n)}),null!==s&&this.updateActiveCustomTagElm(s),domItVisible(i,!0),this.target.chatEvent.debounceEvents.dialogMoveToRange(i),i.children[1].scrollTop=0}exitPointDialog(){this.updatePointActiveUserElm(),this.target.options.asyncMatch&&this.target.updateUserList([]),domItVisible(this.pcElms.pointDialogElm)}exitCustomTagDialog(){this.updateActiveCustomTagElm();for(const t in this.pcElms.customTagDialogElms)domItVisible(this.pcElms.customTagDialogElms[t])}ruleShowPointDialog(){const{options:t}=this.target;t.needDialog&&t.reformList.length>0&&(this.isExternalCallPopup=!1,this.showPointDialog())}showPlaceholder(){domItVisible(this.placeholderElm,this.target.isEmpty()),this.offsetTipElm()}bindSelectList(){Object.values(this.pcElms.selectDialogElms).forEach(t=>{this.pcElms.containerDialogElm.removeChild(t)}),this.pcElms.selectDialogElms={},this.selectTags={},this.target.options.selectList.forEach(t=>{t.options&&t.options.length>0&&(this.selectTags[t.key]=t.options.map(t=>({id:String(t.id),name:String(t.name),preview:String(t.preview||"")})),this.createSelectDialog(t))})}createSelectDialog(t){const e=document.createElement("div");e.setAttribute("class","chat-select-dialog"),domItVisible(e);const i=document.createElement("div");i.setAttribute("class","chat-select-dialog-header"),i.innerHTML=`<span class="chat-select-dialog-header-title">${t.dialogTitle||t.key}</span>`,e.appendChild(i);const n=document.createElement("div");n.setAttribute("class","chat-select-dialog-main"),t.options.forEach(t=>{const e=document.createElement("div");if(e.setAttribute("class","chat-select-dialog-item"),e.setAttribute("data-set-id",t.id),t.preview){const i=document.createElement("img");i.setAttribute("class","chat-select-dialog-preview"),i.src=String(t.preview),e.appendChild(i)}const i=document.createElement("span");i.setAttribute("class","chat-select-dialog-name"),i.textContent=t.name;const s=document.createElement("span");s.setAttribute("class","chat-select-dialog-check"),s.innerHTML=checkSvg,domItVisible(s),i.appendChild(s),e.appendChild(i),e.onclick=async()=>{await this.target.setSelectTag(t)},n.appendChild(e)}),e.appendChild(n);const s=document.createElement("div");s.setAttribute("class","chat-select-arrow"),e.appendChild(s),this.pcElms.containerDialogElm.appendChild(e),this.pcElms.selectDialogElms[t.key]=e}exitSelectDialog(){for(const t in this.pcElms.selectDialogElms)domItVisible(this.pcElms.selectDialogElms[t]);this.pcElms.selectDialogKey="",this.pcElms.selectDialogAim&&(updateElmClass(this.pcElms.selectDialogAim,"aim"),this.pcElms.selectDialogAim=null)}createTipElm(t){this.tipElm||(this.tipElm=document.createElement("div")),updateElmClass(this.tipElm,"chat-tip-wrap",!0),this.tipElm.innerHTML=`\n <div class="chat-tip-tag">\n <span class="chat-tip-tag-txt">${t.tagLabel||"--"}</span>\n <span class="chat-tip-tag-close">\n ${this.target.deviceInfo.isPc?closeSvg:""}\n </span>\n </div>\n `,this.target.options.elm.appendChild(this.tipElm);const e=this.tipElm.children[0],i=(e.clientHeight-this.target.chatInput.NODE_HEIGHT)/2;this.tipElm.style.top=`-${i}px`,e.onclick=()=>{this.target.deviceInfo.isPc&&this.target.closeTipTag()},e.onmouseenter=()=>{if(this.pcElms.tipContainerPopoverElm&&this.pcElms.tipPopoverElm){domItVisible(this.pcElms.tipPopoverElm,!0);const t=this.pcElms.tipContainerPopoverElm.getBoundingClientRect();this.rects.tipRect=this.tipElm.getBoundingClientRect();const i=(this.pcElms.tipPopoverElm.clientWidth-(this.tipElm.clientWidth+(this.tipElm.clientWidth-e.clientWidth)))/2;this.pcElms.tipPopoverElm.style.left=-i+"px",this.pcElms.tipPopoverElm.style.bottom=t.y-this.rects.tipRect.y+"px",this.pcElms.tipPopoverElm.style.transform=e.style.transform}},e.onmouseleave=()=>{this.pcElms.tipPopoverElm&&domItVisible(this.pcElms.tipPopoverElm)};const n=this.richText.children[0].children[0];this.rects.tipRect=this.tipElm.getBoundingClientRect();const s=this.rects.tipRect;if(this.placeholderElm.style.paddingLeft=s.width+"px",n.style.paddingLeft=s.width-n.offsetLeft+"px",this.offsetTipElm(),this.target.deviceInfo.isPc){this.pcElms.tipContainerPopoverElm||(this.pcElms.tipContainerPopoverElm=document.createElement("div"),updateElmClass(this.pcElms.tipContainerPopoverElm,"chat-tip-dialog",!0)),this.pcElms.tipPopoverElm||(this.pcElms.tipPopoverElm=document.createElement("div")),updateElmClass(this.pcElms.tipPopoverElm,"chat-tip-popover",!0),this.pcElms.tipPopoverElm.innerHTML=`\n <div class="chat-tip-popover-main">\n <span class="chat-tip-popover-txt">${t.popoverLabel||"--"}</span>\n <span class="chat-tip-popover-code ${t.codeLabel?"":"chat-view-show"}">${t.codeLabel||"--"}</span>\n </div>\n <div class="chat-tip-popover-arrow"></div>\n `,this.pcElms.tipContainerPopoverElm.appendChild(this.pcElms.tipPopoverElm),domItVisible(this.pcElms.tipPopoverElm);const{elm:e}=this.target.options;e.parentElement&&(e.nextElementSibling?e.parentElement.insertBefore(this.pcElms.tipContainerPopoverElm,e.nextElementSibling):e.parentElement.appendChild(this.pcElms.tipContainerPopoverElm))}this.target.chatEvent.triggerChatEvent("tipTagState",!0)}offsetTipElm(){if(this.tipElm){const t=this.richText.children[0].children[0];t.style.paddingLeft=this.rects.tipRect.width-t.offsetLeft+"px",this.target.nextTick(()=>{if(this.tipElm){const t=this.tipElm.children[0],e=this.richText.children[0].children[0];t.style.transform=`translateY(${e.offsetTop-this.target.chatInput.NODE_PADDING_DIFF}px)`}})}}removeTipElm(){this.tipElm&&(this.target.options.elm.removeChild(this.tipElm),this.tipElm=null),this.pcElms.tipContainerPopoverElm&&(this.pcElms.tipContainerPopoverElm.removeChild(this.pcElms.tipPopoverElm),this.target.options.elm.parentElement.removeChild(this.pcElms.tipContainerPopoverElm),this.pcElms.tipContainerPopoverElm=null,this.pcElms.tipPopoverElm=null);const t=this.richText.children[0].children[0];this.placeholderElm.style.removeProperty("padding-left"),t.style.removeProperty("padding-left"),this.target.chatInput.setRangeLastText(),this.target.chatEvent.triggerChatEvent("tipTagState",!1)}}class ChatInput{constructor(t){__publicField(this,"target"),__publicField(this,"richText"),__publicField(this,"vnode"),__publicField(this,"cursorIndex"),__publicField(this,"cursorLeft"),__publicField(this,"needCallSpace",!1),__publicField(this,"VOID_KEY","\ufeff"),__publicField(this,"ZERO_WIDTH_KEY","​"),__publicField(this,"INPUT_TAG_WRAP_KEY","​\n​"),__publicField(this,"NODE_HEIGHT",24),__publicField(this,"NODE_PADDING_DIFF",10),__publicField(this,"IME_RECORD",{MARK:void 0,GRID:void 0,TAG:void 0,NODE:void 0,INDEX:void 0}),this.target=t,this.richText=t.chatElement.richText,this.initEditor()}initEditor(t=!1,e){if(t||this.getNodeEmpty(this.richText)){this.richText.innerHTML="";const i=this.getGridElm();this.richText.appendChild(i);const n=i.children[0].children[0];e&&(n.textContent=e,n.setAttribute("data-set-empty","false"));const s=n.childNodes[0];t||this.target.options.autoFocus?this.restCursorPos(s,s.textContent===this.VOID_KEY?1:s.textContent.length):(this.vnode=s,this.cursorIndex=s.textContent===this.VOID_KEY?1:s.textContent.length),this.target.nextTick(()=>{const t=i.getBoundingClientRect();this.NODE_HEIGHT=t.height,this.NODE_PADDING_DIFF=t.top-this.target.options.elm.getBoundingClientRect().top})}}onceCall(t){return new Promise(e=>{const i=this.createChatTagElm(t,"@","at-user","user-id");this.replaceRegContent(i),e()})}onceSearchCall(t,e){return new Promise(i=>{const n=this.createChatTagElm(t,"@","at-user","user-id");this.replaceRegContent(n,e),i()})}onceCustomCall(t,e,i){return new Promise(n=>{const s=this.createChatTagElm(t,i,"at-tag","tag-id");s.children[0].setAttribute("data-set-prefix",i),this.replaceRegContent(s,e),n()})}upDataNodeOrIndex(){var t,e,i;const{focusNode:n,focusOffset:s,anchorOffset:a}=window.getSelection(),l=(null==n?void 0:n.parentNode)||void 0;if(!l||!l.getAttribute||l.getAttribute("data-set-richType")!==RICH_INPUT)return;(null==(i=null==(e=null==(t=null==n?void 0:n.parentNode)?void 0:t.parentNode)?void 0:e.parentNode)?void 0:i.parentNode)===this.richText&&(this.vnode=n,this.cursorIndex=s,this.cursorLeft=a<s?a:s)}keyUpAsKey(t){if(this.upDataNodeOrIndex(),!this.vnode||this.vnode.nodeType!==Node.TEXT_NODE)return!1;const e=this.vnode.textContent||"",i=new RegExp(`${t}([^${t}\\s]*)$`),n=e.slice(0,this.cursorIndex),s=i.exec(n);return s&&2===s.length&&n[n.length-1]===t}getRangeRect(){let t=0,e=0;const i=window.getSelection();if(i.focusNode.nodeType!==Node.TEXT_NODE)return null;const n=i.getRangeAt(0).getClientRects()[0];return n&&(t=n.x,e=n.y),{x:t,y:e}}createChatTagElm(t,e,i,n){const s=document.createElement("span");return s.className=i,s.setAttribute(`data-${n}`,String(t.id)),s.textContent=`${e}${t.name}${this.needCallSpace?" ":""}`,this.createNewDom(s)}createNewDom(t){const e=document.createElement("span");return e.className="chat-tag",e.setAttribute("contenteditable","false"),e.setAttribute("data-set-richType",RICH_TAG),e.appendChild(t),e}restCursorPos(t,e){null==e?e=t.textContent===this.VOID_KEY?1:0:e>t.textContent.length&&(e=t.textContent.length);const i=new Range;i.setStart(t,e),i.setEnd(t,e);const n=window.getSelection();n&&(this.vnode=t,this.cursorIndex=e,this.cursorLeft=e,n.removeAllRanges(),n.addRange(i))}replaceRegContent(t,e=!0){const i=this.vnode.textContent;let n;n="boolean"==typeof e?i.slice(0,e?this.cursorIndex-1:this.cursorIndex):i.slice(0,e-1),0===n.length?(this.vnode.parentElement.setAttribute("data-set-empty","true"),this.vnode.textContent=this.VOID_KEY):this.vnode.textContent=n;let s=i.slice(this.cursorIndex);const a=this.vnode.parentNode.parentNode,l=a.nextSibling;l?a.parentNode.insertBefore(t,l):a.parentNode.appendChild(t);const o=t.previousSibling.childNodes[0],r=o.childNodes[1];r&&o.removeChild(r);const c=this.getGridElm(!0),h=c.childNodes[0];s&&s!==this.VOID_KEY&&(h.setAttribute("data-set-empty","false"),h.innerHTML=s);const d=h.childNodes[1];t.nextSibling?(d&&h.removeChild(d),a.parentNode.insertBefore(c,t.nextSibling)):a.parentNode.appendChild(c),this.restCursorPos(h.childNodes[0])}batchReplaceRegContent(t=[],e=!0){return new Promise(i=>{let n=`<span data-set-richType="${RICH_MARK}"><span class="chat-grid-input" data-set-richType="${RICH_INPUT}" data-set-empty="true">${this.VOID_KEY}</span></span>`;t.forEach(t=>{n+=`<span class="chat-tag" contenteditable="false" data-set-richType="${RICH_TAG}"><span class="at-user" data-user-id="${t.id}" contentEditable="false">@${t.name}${this.needCallSpace?" ":""}</span></span><span data-set-richType="${RICH_MARK}"><span class="chat-grid-input" data-set-richType="${RICH_INPUT}" data-set-empty="true">${this.VOID_KEY}</span></span>`});const s=document.createElement("div");s.innerHTML=n,this.insetRangeGrid(s,e?1:0),i()})}switchRange(t){var e,i;let{focusNode:n,focusOffset:s}=window.getSelection();n.getAttribute&&n.getAttribute("data-set-richType")===RICH_INPUT&&(n=n.childNodes[0]);let a,l,o=!1;if(n.nodeType===Node.TEXT_NODE){const r=n.textContent.length,c=n.parentNode.parentNode;switch(t){case"ArrowLeft":if(s>0&&n.textContent!==this.VOID_KEY){l=s-1,a=n;break}const t=c.previousSibling;if(t&&t.children[0].classList.contains("at-input")){a=t.children[0].children[0].childNodes[0],l=a.textContent===this.VOID_KEY?1:a.textContent.length,o=!0;break}const h=null==(e=null==c?void 0:c.previousSibling)?void 0:e.previousSibling;if(h)a=h.childNodes[0].childNodes[0],l=a.textContent.length;else{const t=c.parentNode.previousSibling;if(t){a=t.lastChild.childNodes[0].childNodes[0],l=a.textContent.length}}break;case"ArrowRight":if(s<r&&n.textContent!==this.VOID_KEY){l=s+1,a=n;break}const d=c.nextSibling;if(d&&d.children[0].classList.contains("at-input")){a=d.children[0].children[0].childNodes[0],l=a.textContent===this.VOID_KEY?1:0,o=!0;break}const p=null==(i=null==c?void 0:c.nextSibling)?void 0:i.nextSibling;if(p)a=p.childNodes[0].childNodes[0],l=a.textContent===this.VOID_KEY?1:0;else{const t=c.parentNode.nextSibling;t&&(a=t.childNodes[0].childNodes[0].childNodes[0],l=a.textContent===this.VOID_KEY?1:0)}}}(l||0===l)&&(o?this.setInputTagRange(a,l):this.restCursorPos(a,l))}getGridElm(t=!1){const e=document.createElement("span");if(e.setAttribute("data-set-richType",RICH_MARK),e.innerHTML=`<span class="chat-grid-input" data-set-richType="${RICH_INPUT}" data-set-empty="true">${this.VOID_KEY}<br></span>`,t)return e;const i=document.createElement("p");return i.className="chat-grid-wrap",i.setAttribute("data-set-richType",RICH_GRID),i.appendChild(e),i}updateGrid(){const t=window.getSelection(),e=t.focusNode;if(!e)return;const i=e.parentNode;let n,s,a,l;switch(i.getAttribute("data-set-richType")){case RICH_WRAP:if(!e.getAttribute||e.getAttribute("data-set-richType")!==RICH_GRID)break;if(n=e.childNodes[t.focusOffset],!n||n.getAttribute("data-set-richType")===RICH_TAG){const t=this.getGridElm(!0),i=t.children[0];n?(i.removeChild(i.childNodes[1]),e.insertBefore(t,n)):e.appendChild(t),this.restCursorPos(i.childNodes[0]);break}if(n.tagName&&"BR"===n.tagName.toLocaleUpperCase()){const t=this.getGridElm(!0),i=t.children[0];e.insertBefore(t,n),e.removeChild(n),t.nextElementSibling&&t.children[0].removeChild(t.children[0].childNodes[1]),this.restCursorPos(i.childNodes[0],i.childNodes[0].textContent.length)}break;case RICH_MARK:const o=i.parentNode,r=Array.prototype.indexOf.call(o.childNodes,i);if(-1===r)break;if(0===r){const e=t.focusNode;e.setAttribute("data-set-empty","true"),e.innerHTML=`${this.VOID_KEY}<br>`,n=e.childNodes[0],this.restCursorPos(n,n.textContent.length);break}let c,h=i.previousSibling;h.getAttribute("data-set-richType")===RICH_TAG?(c=h.previousSibling,o.removeChild(h),o.removeChild(i)):(c=i.previousSibling,o.removeChild(i));n=c.childNodes[0].childNodes[0],n.textContent===this.VOID_KEY&&n.parentNode.appendChild(document.createElement("br")),this.restCursorPos(n,n.textContent.length);break;case RICH_INPUT:if(l=i.parentNode,a=l.parentNode,this.getNodeEmpty(i)){i.setAttribute("data-set-empty","true"),a.childNodes[a.childNodes.length-1]===l&&(i.innerHTML=`${this.VOID_KEY}<br>`),n=i.childNodes[0],this.restCursorPos(n,n.textContent.length);break}if("true"===String(i.getAttribute("data-set-empty"))){i.setAttribute("data-set-empty","false"),n=i.childNodes[0],this.target.chatEvent.isIMEModel?(i.childNodes[1]&&i.removeChild(i.childNodes[1]),n.textContent===this.VOID_KEY&&i.setAttribute("data-set-empty","true")):i.textContent=n.textContent.replace(new RegExp(this.VOID_KEY,"g"),"");const t=i.childNodes[0];this.restCursorPos(t,t.textContent.length)}if(s=i.parentNode.nextSibling,s&&s.nodeType===Node.TEXT_NODE){let t=s.textContent,e=this.getGridElm(!0);e.childNodes[0].textContent=t,e.childNodes[0].setAttribute("data-set-empty","false"),s.parentNode.insertBefore(e,s),s.parentNode.removeChild(s),s=e}s&&s.getAttribute("data-set-richType")===RICH_MARK&&this.markMerge(i.parentNode,s)}}getNodeEmpty(t){const e=new RegExp(`^(${this.ZERO_WIDTH_KEY}|<br>|${this.VOID_KEY})+$`);return!t.innerHTML||e.test(t.innerHTML)}setWrap(t=!0){const e=window.getSelection();let{focusNode:i,focusOffset:n}=e;if(i.nodeType!==Node.TEXT_NODE){if(!i.getAttribute||i.getAttribute("data-set-richType")!==RICH_INPUT)return;i=i.childNodes[0]}const s=i.textContent.slice(n),a=i.parentNode.parentNode,l=a.parentNode,o=Array.prototype.indexOf.call(l.childNodes,a),r=Array.prototype.slice.call(l.childNodes,o+1),c=this.getGridElm();let h=c.children[0].children[0].childNodes[0];(s||r.length>0)&&h.parentNode.removeChild(h.parentNode.childNodes[1]),s&&s!==this.VOID_KEY&&(i.textContent=i.textContent.slice(0,n),h.textContent=s,h.parentElement.setAttribute("data-set-empty","false")),r.forEach(t=>{l.removeChild(t),c.appendChild(t)});const d=l.lastChild.childNodes[0],p=c.lastChild.childNodes[0];if(d.childNodes.length<=1){const t=d.childNodes[0];t.textContent&&t.textContent!==this.VOID_KEY||(d.innerHTML=`${this.VOID_KEY}<br>`,d.setAttribute("data-set-empty","true"))}if(p.parentElement.getAttribute("data-set-richType")!==RICH_MARK)c.appendChild(this.getGridElm(!0));else if(p.childNodes.length<=1){const t=p.childNodes[0];t.textContent&&t.textContent!==this.VOID_KEY||(p.innerHTML=`${this.VOID_KEY}<br>`,p.setAttribute("data-set-empty","true"),h=c.children[0].children[0].childNodes[0])}l.nextSibling?this.richText.insertBefore(c,l.nextSibling):this.richText.appendChild(c),t&&this.restCursorPos(h,h.textContent===this.VOID_KEY?1:0)}selectAll(){const t=document.createRange(),e=this.richText.children[0].children[0].childNodes[0].childNodes[0],i=this.richText.lastElementChild.lastElementChild.childNodes[0].childNodes[0];t.setStart(e,0),t.setEnd(i,i.textContent.length);const n=window.getSelection();n.removeAllRanges(),n.addRange(t)}selectRegionMerge(){const t=window.getSelection();if(t.isCollapsed||t.rangeCount<=0)return;const e=t.getRangeAt(0);if(e.startContainer.nodeType===Node.TEXT_NODE&&e.startContainer===e.endContainer){const t=e.startContainer;if(t.length===e.endOffset-e.startOffset){const e=t.parentNode,i=e.parentNode===e.parentNode.parentNode.lastChild;e.setAttribute("data-set-empty","true"),e.innerHTML="\ufeff"+(i?"<br>":""),this.restCursorPos(e.childNodes[0])}else e.deleteContents()}else if(e.commonAncestorContainer&&e.commonAncestorContainer.getAttribute("data-set-richType")===RICH_GRID){const t=e.startContainer.nodeType===Node.TEXT_NODE?e.startContainer.parentNode.parentNode:e.startContainer,i=e.endContainer.nodeType===Node.TEXT_NODE?e.endContainer.parentNode.parentNode:e.endContainer;e.deleteContents(),t.getAttribute("data-set-richType")===i.getAttribute("data-set-richType")&&this.markMerge(t,i)}else if(e.commonAncestorContainer===e.startContainer&&e.startContainer===e.endContainer)this.initEditor(!0);else{const t=t=>{if(t.nodeType===Node.TEXT_NODE)return t.parentNode.parentNode.parentNode;switch(t.getAttribute("data-set-richType")){cas