x-sender 1.2.6 → 1.3.1
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/README.md +3 -0
- package/index.d.ts +19 -4
- package/lib/XSender.mjs +1 -1
- package/lib/XSender.umd.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -30,6 +30,9 @@ npm i --save x-sender
|
|
|
30
30
|
|
|
31
31
|
### 版本更新日志
|
|
32
32
|
```
|
|
33
|
+
v1.3.1 => bus优化:所有内置事件的事件名都改为由Symbol函数创建
|
|
34
|
+
新增静态属性:EventSet => 暴露出去可开放的bus事件
|
|
35
|
+
交互优化:优化方向键上下时输入框内的光标移动行为
|
|
33
36
|
v1.2.6 => 新增交互:支持Select下拉选择标签弹窗开启搜索查询功能
|
|
34
37
|
新增配置项:SelectConfig.showSearch => 是否开启搜索查询功能
|
|
35
38
|
新增配置项:SelectConfig.placeholder => 搜索输入框占位提示语
|
package/index.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
export type BusEventKey = string | symbol;
|
|
2
|
+
|
|
1
3
|
export interface MentionItem {
|
|
2
4
|
id: string;
|
|
3
5
|
name: string;
|
|
@@ -207,10 +209,10 @@ export class ChatEditor {
|
|
|
207
209
|
}
|
|
208
210
|
|
|
209
211
|
export class Bus {
|
|
210
|
-
on(key:
|
|
211
|
-
emit(eventName:
|
|
212
|
-
off(key:
|
|
213
|
-
offKeyEvent(key:
|
|
212
|
+
on(key: BusEventKey, eventName: BusEventKey, callback: Function | Promise<any>)
|
|
213
|
+
emit(eventName: BusEventKey, ...args: any[])
|
|
214
|
+
off(key: BusEventKey, eventName: BusEventKey)
|
|
215
|
+
offKeyEvent(key: BusEventKey)
|
|
214
216
|
}
|
|
215
217
|
|
|
216
218
|
export class Component {
|
|
@@ -222,6 +224,19 @@ export class Component {
|
|
|
222
224
|
|
|
223
225
|
declare class XSender {
|
|
224
226
|
static version: string;
|
|
227
|
+
static EventSet: {
|
|
228
|
+
EVENT_COMMON_SEND: symbol;
|
|
229
|
+
EVENT_COMMON_CHANGE: symbol;
|
|
230
|
+
EVENT_COMMON_DESTROY: symbol;
|
|
231
|
+
EVENT_COMMON_TIP_STATE: symbol;
|
|
232
|
+
EVENT_COMMON_DIALOG_CLOSE: symbol;
|
|
233
|
+
EVENT_COMMON_SELECT_ACTIVE: symbol;
|
|
234
|
+
EVENT_EDITOR_INSERT_MENTION: symbol;
|
|
235
|
+
EVENT_EDITOR_INSERT_TRIGGER: symbol;
|
|
236
|
+
EVENT_EDITOR_INSERT_SELECT: symbol;
|
|
237
|
+
EVENT_EDITOR_INSERT_INPUT: symbol;
|
|
238
|
+
EVENT_EDITOR_INSERT_CUSTOM: symbol;
|
|
239
|
+
};
|
|
225
240
|
static Component = Component;
|
|
226
241
|
options: Options;
|
|
227
242
|
deviceInfo: DeviceInfo;
|
package/lib/XSender.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var _Events,_MentionDialog_instances,registerBus_fn,registerEvent_fn,createDialog_fn,_Events2,_TriggerDialog_instances,registerBus_fn2,registerEvent_fn2,createDialog_fn2,_Events3,_SelectDialog_instances,registerBus_fn3,registerEvent_fn3,createDialog_fn3,_Events4,_BeforeTip_instances,registerBus_fn4,registerEvent_fn4,createTip_fn,update_fn,_ChatElement_instances,registerBus_fn5,createRichText_fn,createPlaceholder_fn,createDialogRoot_fn,switchPlaceholder_fn,_Write_instances,emit_fn,_Select_instances,emit_fn2,_Input_instances,emit_fn3,_disabledEvent,_Events5,_ChatEditor_instances,registerBus_fn6,registerEvent_fn5,richTextDelete_fn,richTextWrap_fn,richTextCopy_fn,richTextPaste_fn,recordHistory_fn,richTextUndo_fn,richTextRedo_fn,renderHistory_fn,richTextChange_fn,cursorChange_fn,ruleMaxLength_fn,_handles,_eventMapKey,_syncElms,_Component_instances,emit_fn4,findEventNodes_fn,syncNode_fn,getChainElm_fn,__defProp=Object.defineProperty,__typeError=t=>{throw TypeError(t)},__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),__accessCheck=(t,e,i)=>e.has(t)||__typeError("Cannot "+i),__privateGet=(t,e,i)=>(__accessCheck(t,e,"read from private field"),i?i.call(t):e.get(t)),__privateAdd=(t,e,i)=>e.has(t)?__typeError("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(t):e.set(t,i),__privateSet=(t,e,i,s)=>(__accessCheck(t,e,"write to private field"),s?s.call(t,i):e.set(t,i),i),__privateMethod=(t,e,i)=>(__accessCheck(t,e,"access private method"),i);const 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>',DEFAULT_OPTIONS={device:"auto",autoFocus:!0,placeholder:"",maxLength:-1,keyboardWrapFun:t=>t.ctrlKey&&["Enter"].includes(t.key),keyboardSendFun:t=>!t.ctrlKey&&["Enter"].includes(t.key)},DEFAULT_MENTION_OPTIONS={dialogTitle:"群成员",callEvery:!0,everyText:"所有人",asyncMatch:void 0,emptyText:"暂无数据",options:[]},KEY_CODE_MAP={"`":["`","~"],"~":["`","~"],1:["1","!"],"!":["1","!"],3:["3","#"],"#":["3","#"],4:["4","$"],$:["4","$"],5:["5","%"],"%":["5","%"],6:["6","^"],"^":["6","^"],7:["7","&"],"&":["7","&"],8:["8","*"],"*":["8","*"],";":[";",":"],":":[";",":"],"/":["/","?"],"?":["/","?"],"\\":["\\","|"],"|":["\\","|"]},DEFAULT_TIP_OPTIONS={tipTemplate:'<div class="chat-before-tip-box">{{text}}</div><div class="chat-before-tip-close">'+closeSvg+"</div>",dialogTemplate:'<div class="chat-tip-dialog-main"><span>{{dialogText}}</span><span class="chat-tip-dialog-code">ESC</span></div><div class="chat-tip-dialog-arrow"></div>',closeNames:["chat-before-tip-box","chat-before-tip-close"],offsetTop:0},ELEMENT_EMPTY_KEY="data-set-empty",ELEMENT_RICH_TYPE_KEY="data-set-richType",RICH_WRAP="richWrap",RICH_GRID="richGrid",RICH_MARK="richMark",RICH_WRITE="richWrite",RICH_MENTION="richMention",RICH_TRIGGER="richTrigger",RICH_SELECT="richSelect",RICH_INPUT="richInput",RICH_CUSTOM="richCustom",RICH_COMPONENT="richComponent",CHAT_COPY_KEY="application/chat-nodes",VOID_KEY="\ufeff",WRAP_KEY="\n",debounce=(t,e,i=!1)=>{let s;return function(...n){const a=this,o=i&&!s;clearTimeout(s),s=setTimeout(()=>{s=null,i||t.apply(a,n)},e),o&&t.apply(a,n)}},throttle=(t,e)=>{let i;return function(...s){const n=this;i||(t.apply(n,s),i=!0,setTimeout(function(){i=!1},e))}},unEmpty=t=>null!=t,replaceTemplate=(t,e)=>t.replace(/{{(\w+)}}/g,(t,i)=>void 0!==e[i]?e[i]:t);function escapeHtml(t){return t.replace(/[&<>"']/g,t=>{switch(t){case"&":return"&";case"<":return"<";case">":return">";case'"':return""";case"'":return"'";default:return t}})}const replaceBlockTagsWithSpan=t=>{const e=["address","article","aside","blockquote","canvas","dd","div","dl","dt","fieldset","figcaption","figure","footer","form","h1","h2","h3","h4","h5","h6","header","hgroup","hr","li","main","nav","noscript","ol","output","p","pre","section","table","tfoot","ul"],i=new RegExp(`<(${e.join("|")})([^>]*?)>`,"gi"),s=new RegExp(`</(${e.join("|")})>`,"gi");let n=t.replace(i,(t,e,i)=>{let s="",n="";if(i){const t=i.match(/style\s*=\s*["']([^"']*)["']/i);if(t){const e=t[1];s=e.match(/display\s*:/i)?`style="${e.replace(/display\s*:.*?;/gi,"display:block;")}"`:`style="display:block;${e}"`,n=i.replace(/style\s*=\s*["']([^"']*)["']/i,"").trim()}else s='style="display:block"',n=i.trim()}else s='style="display:block"';return`<span ${[n,s].filter(Boolean).join(" ")}>`.replace(/\s+/g," ").replace(/ >/,">")});return n=n.replace(s,"</span>"),n};function isKeyType(t,e){switch(e){case"text-jump":return"Tab"===t.key||"Tab"===t.code;case"text-backspace":return"Backspace"===t.key||"Backspace"===t.code;case"text-delete":return"Delete"===t.code||"Delete"===t.key;case"text-move":return"ArrowLeft"===t.key||"ArrowRight"===t.key||"ArrowLeft"===t.code||"ArrowRight"===t.code;case"text-select-all":return(t.ctrlKey||t.metaKey)&&("A"===t.key||"a"===t.key||"KeyA"===t.code);case"text-undo":return(t.ctrlKey||t.metaKey)&&("Z"===t.key||"z"===t.key||"KeyZ"===t.code);case"text-redo":return(t.ctrlKey||t.metaKey)&&("Y"===t.key||"y"===t.key||"KeyY"===t.code);case"text-write":return t.isComposing||!t.ctrlKey&&!t.altKey&&!t.metaKey&&!["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;case"IME":return"Unidentified"===t.key||229===t.keyCode;default:return!1}}function pinyinMatch(t,e,i){const s=e.split(/\s+/),n=t.split("").map((t,i)=>{let n=s[i]||"";return""===e&&""===n&&(n=t),{char:t,pinyin:n.toLowerCase(),initial:n?n[0].toLowerCase():""}}),a=(t=>{const e=[];let i="";for(const s of t)/[a-zA-Z]/.test(s)?i+=s.toLowerCase():(i&&(e.push({type:"pinyin",value:i}),i=""),e.push({type:"char",value:s}));return i&&e.push({type:"pinyin",value:i}),e})(i),o=n.length,c=a.length,h=Array.from({length:o+1},()=>Array(c+1).fill(!1));h[0][0]=!0;for(let t=0;t<=o;t++)for(let e=0;e<=c;e++)if(h[t][e]&&e<c){const i=a[e];for(let s=t;s<o;s++){const t=n[s];if("char"===i.type)t.char===i.value&&(h[s+1][e+1]=!0);else{const a=t.pinyin.toLowerCase(),c=t.initial,l=i.value;if(l===c)h[s+1][e+1]=!0;else if(l===a)h[s+1][e+1]=!0;else if(isSubsequence(l,a))h[s+1][e+1]=!0;else for(let t=2;t<=o-s;t++){const i=n.slice(s,s+t),a=i.map(t=>t.pinyin.toLowerCase()).join(""),o=i.map(t=>t.initial).join("");if(l===a||l===o||isSubsequence(l,a)){h[s+t][e+1]=!0;break}}}}}for(let t=0;t<=o;t++)if(h[t][c])return!0;return!1}function isSubsequence(t,e){let i=0,s=0;for(;i<t.length&&s<e.length;)t[i]===e[s]&&i++,s++;return i===t.length}function os(){if("undefined"==typeof navigator)return{isTablet:!1,isPhone:!1,isAndroid:!1,isIOS:!1,isPc:!0,isIPhone:!1,isIPad:!1,isWindows:!1,isMacOS:!1,isLinux:!1,isWechat:!1,isMobile:!1};const t=navigator.userAgent.toLowerCase(),e=t.includes("windows"),i=t.includes("macintosh"),s=t.includes("linux")&&!t.includes("android"),n=t.includes("android"),a=/iphone|ipad|ipod/.test(t),o=t.includes("iphone"),c=t.includes("ipad")||t.includes("macintosh")&&navigator.maxTouchPoints>1,h=t.includes("micromessenger"),l=c||n&&!/mobile/.test(t)||t.includes("firefox")&&t.includes("tablet")||t.includes("playbook"),r=o&&!l||n&&/mobile/.test(t)||t.includes("windows phone");return{isTablet:l,isPhone:r,isAndroid:n,isIOS:a,isPc:!r&&!l&&(e||i||s),isIPhone:o,isIPad:c,isWindows:e,isMacOS:i,isLinux:s,isWechat:h,isMobile:r||l}}function switchDisplay(t,e=!0,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 isShow(t){return t&&t.classList.contains("chat-view-show")}class MentionDialog{constructor(t,e){__privateAdd(this,_MentionDialog_instances),__publicField(this,"chatElement"),__publicField(this,"bus"),__publicField(this,"dialog"),__publicField(this,"activeMention",null),__publicField(this,"title",""),__publicField(this,"callEvery",!0),__publicField(this,"everyText",""),__publicField(this,"emptyText",""),__publicField(this,"options",[]),__publicField(this,"asyncMatch"),__publicField(this,"matchKey",0),__privateAdd(this,_Events,[]),this.dialog=document.createElement("div"),this.chatElement=t,this.bus=this.chatElement.chat.bus,__privateMethod(this,_MentionDialog_instances,registerBus_fn).call(this),__privateMethod(this,_MentionDialog_instances,registerEvent_fn).call(this),__privateMethod(this,_MentionDialog_instances,createDialog_fn).call(this),this.updateConfig(e)}updateConfig(t){this.asyncMatch=t.asyncMatch,this.title=t.dialogTitle,this.emptyText=t.emptyText,this.everyText=t.everyText,this.callEvery=!this.asyncMatch&&t.callEvery,this.options=this.asyncMatch?[]:t.options,this.updateRender()}updateRender(){this.dialog.children[0].textContent=this.title,this.dialog.children[2].innerHTML=`${matchEmptySvg}<span class="empty-label">${this.emptyText}</span>`;const t=this.dialog.children[1];t.innerHTML="";const e=document.createDocumentFragment();this.callEvery&&e.appendChild(this.getRenderMention({id:"ALL",name:this.everyText})),this.options.forEach(t=>{e.appendChild(this.getRenderMention(t))}),t.appendChild(e)}getRenderMention(t){const e=document.createElement("div");e.setAttribute("data-id",t.id),e.setAttribute("data-name",t.name),e.classList.add("chat-mention-dialog-item"),switchDisplay(e,!0,"flex");const i=document.createElement("div");if(i.classList.add("chat-mention-dialog-item-avatar"),t.avatar){i.classList.add("have-avatar");const e=document.createElement("div");e.classList.add("chat-mention-dialog-item-avatar-loading"),e.innerHTML=antdLoading,i.appendChild(e);const s=new Image;s.alt="",s.src=t.avatar,s.onload=()=>{i.removeChild(e),i.appendChild(s)}}else{const e=document.createElement("span");e.textContent="ALL"===t.id?"@":t.name.slice(-2),e.classList.add("chat-mention-dialog-item-avatar-text"),i.appendChild(e)}e.appendChild(i);const s=document.createElement("div");return s.classList.add("chat-mention-dialog-item-name"),s.textContent=t.name,e.appendChild(s),e.addEventListener("click",t=>{t.stopPropagation();const i=this.chatElement.chat.chatEditor.markCursorWrite,s=i.node.textContent.slice(0,i.offset).lastIndexOf("@"),n=i.offset-s;this.bus.emit("insertMention",{id:e.getAttribute("data-id"),name:e.getAttribute("data-name"),del:n>0?n:0}),this.closeDialog()}),e}openDialog(t){if(isShow(this.dialog)||this.bus.emit("closeDialog"),this.asyncMatch){this.options=[],this.updateRender();const t=this.dialog.children[2],e=this.dialog.children[3];switchDisplay(t,!1),switchDisplay(e,!0,"flex"),switchDisplay(this.dialog),this.moveDialog(),this.bus.emit("switchDisabledState",!0)}else if(this.options.length>0){const e=this.dialog.children[1];let i;e.scrollTop=0;const s=(t||this.pinyinMatchDialog()).map(t=>t.id);Array.from(e.children,t=>{const e=t.getAttribute("data-id");s.includes(e)?(switchDisplay(t,!0,"flex"),i||(i=t)):switchDisplay(t,!1)}),this.switchActiveMention(i||e.children[0]),switchDisplay(this.dialog),this.moveDialog(),this.bus.emit("switchDisabledState",!0)}}closeDialog(){isShow(this.dialog)&&(switchDisplay(this.dialog,!1),this.switchActiveMention(),this.bus.emit("switchDisabledState",!1))}moveDialog(){const t=this.chatElement.chat.getSelection().getRangeAt(0).getBoundingClientRect(),e=this.chatElement.dialogRoot.getBoundingClientRect();let i="0",s="100%",n=t.x-e.x,a=e.y-t.y;const{clientWidth:o,clientHeight:c}=this.dialog;t.x>window.innerWidth-o-30&&(n=t.x-o-e.x-16,i="100%"),t.y<c&&(a-=c,s="0"),this.dialog.style.transform="translate(0, 0)",this.dialog.style.transformOrigin=`${i} ${s}`,this.dialog.style.left=n+6+"px",this.dialog.style.bottom=`${a}px`,this.dialog.style.opacity="1"}moveActiveMention(t){const e=this.dialog.children[1],i=Array.prototype.filter.call(e.children,t=>t.classList.contains("chat-view-show")),s=Array.prototype.indexOf.call(i,this.activeMention);"up"===t?s>0?this.switchActiveMention(i[s-1],!0):this.switchActiveMention(i[i.length-1],!0):"down"===t&&(s<i.length-1?this.switchActiveMention(i[s+1],!0):this.switchActiveMention(i[0],!0))}switchActiveMention(t,e=!1){if(this.activeMention&&this.activeMention.classList.remove("active"),t){if(this.activeMention=t,this.activeMention.classList.add("active"),e){const t=this.dialog.children[1],e=Array.prototype.filter.call(t.children,t=>t.classList.contains("chat-view-show")),i=this.activeMention.clientHeight,s=Array.prototype.indexOf.call(e,this.activeMention)+1-Math.ceil(Math.floor(t.clientHeight/i)/2);t.scrollTop=s>0?s*i:0}}else this.activeMention=null}matchDialog(){const t=this.chatElement.chat.chatEditor.markCursorWrite,e=t.node.textContent.slice(0,t.offset),i=e.lastIndexOf("@");if(-1===i)return void this.closeDialog();const s=e.slice(i+1);if(this.asyncMatch)return void this.asyncMatchDialog(s);const n=this.pinyinMatchDialog(s);n.length>0?this.openDialog(n):this.closeDialog()}pinyinMatchDialog(t){return t?this.options.filter(e=>pinyinMatch(e.name,e.pinyin||"",t)):this.callEvery?[{id:"ALL",name:this.everyText},...this.options]:this.options}async asyncMatchDialog(t=""){this.matchKey++;const e=this.matchKey;if(/\s/gi.test(t))return void this.closeDialog();this.openDialog();const i=await this.asyncMatch(t);if(e===this.matchKey){this.options=i,this.updateRender();const t=this.dialog.children[1],e=this.dialog.children[2],s=this.dialog.children[3];switchDisplay(s,!0,"flex"),t.scrollTop=0,switchDisplay(e,0===this.options.length,"flex"),switchDisplay(s,!1),this.switchActiveMention(t.children[0]),this.moveDialog()}}destroy(){this.bus.offKeyEvent("MentionDialog"),this.dialog.parentElement&&this.dialog.parentElement.removeChild(this.dialog),__privateGet(this,_Events).forEach(t=>{const e=t[0],i=t[1];for(const t in i)e.removeEventListener(t,i[t])})}}_Events=new WeakMap,_MentionDialog_instances=new WeakSet,registerBus_fn=function(){const t="MentionDialog";this.bus.on(t,"closeDialog",()=>{this.closeDialog()}),this.bus.on(t,"moveActiveMention",throttle(this.moveActiveMention,120).bind(this)),this.bus.on(t,"matchDialog",debounce(this.matchDialog,200).bind(this)),this.bus.on(t,"updateDialogReact",debounce(()=>{isShow(this.dialog)&&this.moveDialog()},200)),this.bus.on(t,"destroy",()=>{this.destroy()})},registerEvent_fn=function(){__privateSet(this,_Events,[[this.chatElement.richText,{keydown:t=>{isShow(this.dialog)&&(isKeyType(t,"dialog-options")?t.preventDefault():isKeyType(t,"text-move")&&this.closeDialog())},keyup:t=>{if(t.stopPropagation(),"@"===t.key||"2"===String(t.key)||isKeyType(t,"IME")){const t=this.chatElement.chat.getSelection(),e=t.focusNode,i=this.chatElement.chat.chatEditor.findNode(e);if(i&&"Write"===i.type){const e=t.focusOffset;"@"===i.text[e-1]&&!this.chatElement.chat.deviceInfo.isPc&&this.openDialog()}}}}],[window,{mousedown:()=>{this.closeDialog()},keydown:t=>{!this.chatElement.chat.chatEditor.isComposition&&isShow(this.dialog)&&isKeyType(t,"dialog-options")&&(t.preventDefault(),"ArrowUp"===t.key||"ArrowUp"===t.code?this.bus.emit("moveActiveMention","up"):"ArrowDown"===t.key||"ArrowDown"===t.code?this.bus.emit("moveActiveMention","down"):"Enter"!==t.key&&"Enter"!==t.code&&"NumpadEnter"!==t.code||this.activeMention&&this.activeMention.click())}}]]),__privateGet(this,_Events).forEach(t=>{const e=t[0],i=t[1];for(const t in i)e.addEventListener(t,i[t])})},createDialog_fn=function(){this.dialog.classList.add("chat-mention-dialog-wrap"),this.dialog.addEventListener("mousedown",t=>{t.stopPropagation()}),switchDisplay(this.dialog,!1);const t=document.createDocumentFragment(),e=document.createElement("div");e.classList.add("chat-mention-dialog-header"),t.appendChild(e);const i=document.createElement("div");i.classList.add("chat-mention-dialog-main"),i.classList.add("chat-scroll"),t.appendChild(i);const s=document.createElement("div");s.classList.add("chat-mention-dialog-empty"),switchDisplay(s,!1),t.appendChild(s);const n=document.createElement("div");n.classList.add("chat-mention-dialog-loading"),n.innerHTML=antdLoading,switchDisplay(n,!1),t.appendChild(n),this.dialog.appendChild(t),this.chatElement.dialogRoot.appendChild(this.dialog)};class TriggerDialog{constructor(t,e){__privateAdd(this,_TriggerDialog_instances),__publicField(this,"bus"),__publicField(this,"chatElement"),__publicField(this,"dialog"),__publicField(this,"activeTrigger",null),__publicField(this,"title"),__publicField(this,"key"),__publicField(this,"options"),__publicField(this,"keyMap"),__privateAdd(this,_Events2,[]),this.title=e.dialogTitle,this.key=e.key,this.options=e.options,this.keyMap=e.keyMap,this.dialog=document.createElement("div"),this.chatElement=t,this.bus=this.chatElement.chat.bus,__privateMethod(this,_TriggerDialog_instances,registerBus_fn2).call(this),__privateMethod(this,_TriggerDialog_instances,registerEvent_fn2).call(this),__privateMethod(this,_TriggerDialog_instances,createDialog_fn2).call(this)}openDialog(t){if(isShow(this.dialog)||this.bus.emit("closeDialog"),this.options.length>0){const e=this.dialog.children[1];let i;e.scrollTop=0;const s=(t||this.pinyinMatchDialog()).map(t=>t.id);Array.from(e.children,t=>{const e=t.getAttribute("data-id");s.includes(e)?(switchDisplay(t,!0,"flex"),i||(i=t)):switchDisplay(t,!1)}),this.switchActiveTrigger(i||e.children[0]),switchDisplay(this.dialog),this.moveDialog(),this.bus.emit("switchDisabledState",!0)}}closeDialog(){isShow(this.dialog)&&(switchDisplay(this.dialog,!1),this.switchActiveTrigger(),this.bus.emit("switchDisabledState",!1))}moveDialog(){const t=this.chatElement.chat.getSelection().getRangeAt(0).getBoundingClientRect(),e=this.chatElement.dialogRoot.getBoundingClientRect();let i="0",s="100%",n=t.x-e.x,a=e.y-t.y;const{clientWidth:o,clientHeight:c}=this.dialog;t.x>window.innerWidth-o-30&&(n=t.x-o-e.x-16,i="100%"),t.y<c&&(a-=c,s="0"),this.dialog.style.transform="translate(0, 0)",this.dialog.style.transformOrigin=`${i} ${s}`,this.dialog.style.left=n+6+"px",this.dialog.style.bottom=`${a}px`,this.dialog.style.opacity="1"}moveActiveTrigger(t){const e=this.dialog.children[1],i=Array.prototype.filter.call(e.children,t=>t.classList.contains("chat-view-show")),s=Array.prototype.indexOf.call(i,this.activeTrigger);"up"===t?s>0?this.switchActiveTrigger(i[s-1],!0):this.switchActiveTrigger(i[i.length-1],!0):"down"===t&&(s<i.length-1?this.switchActiveTrigger(i[s+1],!0):this.switchActiveTrigger(i[0],!0))}switchActiveTrigger(t,e=!1){if(this.activeTrigger&&this.activeTrigger.classList.remove("active"),t){if(this.activeTrigger=t,this.activeTrigger.classList.add("active"),e){const t=this.dialog.children[1],e=Array.prototype.filter.call(t.children,t=>t.classList.contains("chat-view-show")),i=this.activeTrigger.clientHeight,s=Array.prototype.indexOf.call(e,this.activeTrigger)+1-Math.ceil(Math.floor(t.clientHeight/i)/2);t.scrollTop=s>0?s*i:0}}else this.activeTrigger=null}matchDialog(){const t=this.chatElement.chat.chatEditor.markCursorWrite,e=t.node.textContent.slice(0,t.offset),i=e.lastIndexOf(this.key);if(-1===i)return void this.closeDialog();const s=e.slice(i+1),n=this.pinyinMatchDialog(s);n.length>0?this.openDialog(n):this.closeDialog()}pinyinMatchDialog(t){return t?this.options.filter(e=>pinyinMatch(e.name,e.pinyin||"",t)):this.options}destroy(){const t="TriggerDialog-"+this.key;this.bus.offKeyEvent(t),this.dialog.parentElement&&this.dialog.parentElement.removeChild(this.dialog),__privateGet(this,_Events2).forEach(t=>{const e=t[0],i=t[1];for(const t in i)e.removeEventListener(t,i[t])})}}_Events2=new WeakMap,_TriggerDialog_instances=new WeakSet,registerBus_fn2=function(){const t="TriggerDialog-"+this.key;this.bus.on(t,"closeDialog",()=>{this.closeDialog()}),this.bus.on(t,"moveActiveTrigger",throttle(this.moveActiveTrigger,120).bind(this)),this.bus.on(t,"matchDialog",debounce(this.matchDialog,200).bind(this)),this.bus.on(t,"updateDialogReact",debounce(()=>{isShow(this.dialog)&&this.moveDialog()},200)),this.bus.on(t,"destroy",()=>{this.destroy()})},registerEvent_fn2=function(){__privateSet(this,_Events2,[[this.chatElement.richText,{keydown:t=>{isShow(this.dialog)&&(isKeyType(t,"dialog-options")?t.preventDefault():isKeyType(t,"text-move")&&this.closeDialog())},keyup:t=>{if(t.stopPropagation(),this.keyMap.includes(String(t.key))||isKeyType(t,"IME")){const t=this.chatElement.chat.getSelection(),e=t.focusNode,i=this.chatElement.chat.chatEditor.findNode(e);if(i&&"Write"===i.type){const e=t.focusOffset;i.text[e-1]===this.key&&!this.chatElement.chat.deviceInfo.isPc&&this.openDialog()}}}}],[window,{mousedown:()=>{this.closeDialog()},keydown:t=>{!this.chatElement.chat.chatEditor.isComposition&&isShow(this.dialog)&&isKeyType(t,"dialog-options")&&(t.preventDefault(),"ArrowUp"===t.key||"ArrowUp"===t.code?this.bus.emit("moveActiveTrigger","up"):"ArrowDown"===t.key||"ArrowDown"===t.code?this.bus.emit("moveActiveTrigger","down"):"Enter"!==t.key&&"Enter"!==t.code&&"NumpadEnter"!==t.code||this.activeTrigger&&this.activeTrigger.click())}}]]),__privateGet(this,_Events2).forEach(t=>{const e=t[0],i=t[1];for(const t in i)e.addEventListener(t,i[t])})},createDialog_fn2=function(){this.dialog.classList.add("chat-trigger-dialog-wrap"),this.dialog.addEventListener("mousedown",t=>{t.stopPropagation()}),switchDisplay(this.dialog,!1);const t=document.createDocumentFragment(),e=document.createElement("div");e.classList.add("chat-trigger-dialog-header"),e.textContent=this.title,t.appendChild(e);const i=document.createElement("div");i.classList.add("chat-trigger-dialog-main"),i.classList.add("chat-scroll"),t.appendChild(i);const s=document.createDocumentFragment();this.options.forEach(t=>{const e=document.createElement("div");e.setAttribute("data-id",t.id),e.setAttribute("data-name",t.name),e.classList.add("chat-trigger-dialog-item"),switchDisplay(e,!0,"flex");const i=document.createElement("div");i.classList.add("chat-trigger-dialog-item-name"),i.textContent=t.name,e.appendChild(i),e.addEventListener("click",t=>{t.stopPropagation();const i=this.chatElement.chat.chatEditor.markCursorWrite,s=i.node.textContent.slice(0,i.offset).lastIndexOf(this.key),n=i.offset-s;this.bus.emit("insertTrigger",{id:e.getAttribute("data-id"),name:e.getAttribute("data-name"),key:this.key,del:n>0?n:0}),this.closeDialog()}),s.appendChild(e)}),i.appendChild(s),this.dialog.appendChild(t),this.chatElement.dialogRoot.appendChild(this.dialog)};class SelectDialog{constructor(t,e){__privateAdd(this,_SelectDialog_instances),__publicField(this,"chatElement"),__publicField(this,"bus"),__publicField(this,"dialog"),__publicField(this,"title",""),__publicField(this,"key",""),__publicField(this,"multiple",!1),__publicField(this,"emptyText",""),__publicField(this,"showSearch",!1),__publicField(this,"placeholder",""),__publicField(this,"searchEmptyText",""),__publicField(this,"options",[]),__publicField(this,"selectNode",null),__privateAdd(this,_Events3,[]),this.dialog=document.createElement("div"),this.chatElement=t,this.bus=this.chatElement.chat.bus,this.title=e.dialogTitle,this.key=e.key,this.multiple=e.multiple||!1,this.emptyText=e.emptyText||"请选择标签选项",this.placeholder=e.placeholder||"请输入关键字查询",this.searchEmptyText=e.searchEmptyText||"暂无查询结果",this.showSearch=e.showSearch||!1,this.options=e.options,__privateMethod(this,_SelectDialog_instances,registerBus_fn3).call(this),__privateMethod(this,_SelectDialog_instances,registerEvent_fn3).call(this),__privateMethod(this,_SelectDialog_instances,createDialog_fn3).call(this)}openDialog(t){if(isShow(this.dialog)||this.bus.emit("closeDialog"),this.selectNode=t,!this.selectNode)return;if(this.showSearch){const t=this.dialog.children[1];t.children[0].value="",switchDisplay(t.children[1],!1)}switchDisplay(this.dialog);const e=this.dialog.children[this.showSearch?2:1],i=e.children;let s=0,n=!1,a=0;if("Select"===this.selectNode.type){const t=this.selectNode.id,o=(t||"").split(",");this.selectNode.$el.children[0].classList.add("active"),Array.from(i,e=>{switchDisplay(e,!0,"flex");const i=e.lastChild,c=o.length>0?o.some(t=>String(t)===e.getAttribute("data-id")):String(t)===String(e.getAttribute("data-id"));c&&(a=e.clientHeight,n=!0),c||n||(s+=e.clientHeight),switchDisplay(i,c)});const c=s-e.clientHeight/2+a/2;e.scrollTop=n&&c>0?c:0}else e.scrollTop=0,Array.from(i,t=>{switchDisplay(t,!0,"flex");switchDisplay(t.lastChild,!1)});this.bus.emit("switchDisabledState",!0),this.moveDialog()}closeDialog(){if(isShow(this.dialog)){if(switchDisplay(this.dialog,!1),this.selectNode&&"Select"===this.selectNode.type){this.selectNode.$el.children[0].classList.remove("active")}this.bus.emit("switchDisabledState",!1),this.selectNode=null}}moveDialog(){if(!this.selectNode)return;const t=this.selectNode.$el.getClientRects()[0],e=this.dialog.children[this.showSearch?3:2];let i=this.dialog.clientHeight+16;if(i>t.y?(i=-(t.height+16),e.style.top="-16px",e.style.bottom="auto",e.style.transform="rotate(0deg)"):(e.style.transform="rotate(180deg)",e.style.bottom="-16px",e.style.top="auto"),window.innerWidth-t.x<this.dialog.clientWidth){const i=this.dialog.clientWidth-(window.innerWidth-t.x)-10;this.dialog.style.left="auto",this.dialog.style.right="10px",e.style.left="auto",e.style.right=i-16+"px"}else this.dialog.style.left=t.x+"px",this.dialog.style.right="auto",e.style.left="16px",e.style.right="auto";this.dialog.style.top=t.y+"px",this.dialog.style.transform=`translateY(${-i}px)`}destroy(){const t="SelectDialog-"+this.key;this.bus.offKeyEvent(t),this.dialog.parentElement&&this.dialog.parentElement.removeChild(this.dialog),__privateGet(this,_Events3).forEach(t=>{const e=t[0],i=t[1];for(const t in i)e.removeEventListener(t,i[t])})}}_Events3=new WeakMap,_SelectDialog_instances=new WeakSet,registerBus_fn3=function(){const t="SelectDialog-"+this.key;this.bus.on(t,"activeSelect",t=>{t.key===this.key&&this.chatElement.chat.nextTick(()=>{this.openDialog(t)})}),this.bus.on(t,"closeDialog",()=>{this.closeDialog()})},registerEvent_fn3=function(){__privateSet(this,_Events3,[[window,{mousedown:()=>{this.closeDialog()}}]]),__privateGet(this,_Events3).forEach(t=>{const e=t[0],i=t[1];for(const t in i)e.addEventListener(t,i[t])})},createDialog_fn3=function(){this.dialog.classList.add("chat-select-dialog-wrap"),this.dialog.addEventListener("mousedown",t=>{t.stopPropagation()}),switchDisplay(this.dialog,!1);const t=document.createDocumentFragment(),e=document.createElement("div");e.classList.add("chat-select-dialog-header");const i=document.createElement("span");if(i.textContent=this.title,e.appendChild(i),t.appendChild(e),this.showSearch){const e=document.createElement("div");e.classList.add("chat-select-dialog-search");const i=document.createElement("input");i.classList.add("chat-select-dialog-search-input"),i.setAttribute("placeholder",this.placeholder),i.addEventListener("input",debounce(t=>{t.stopPropagation();const e=t.target.value||"",i=this.dialog.children[1].children[1],s=this.dialog.children[2].children;let n=!0;Array.from(s,t=>{const i=t.getAttribute("data-name")||"";""===e||-1!==i.indexOf(e)?(n=!1,switchDisplay(t,!0,"flex")):switchDisplay(t,!1)}),switchDisplay(i,n,"flex"),this.moveDialog()},200).bind(this)),e.appendChild(i);const s=document.createElement("div");s.classList.add("chat-select-dialog-search-empty"),s.innerHTML=`${matchEmptySvg}<span class="empty-label">${this.searchEmptyText}</span>`,switchDisplay(s,!1),e.appendChild(s),t.appendChild(e)}const s=document.createElement("div");s.classList.add("chat-select-dialog-main"),s.classList.add("chat-scroll");const n=document.createDocumentFragment();this.options.forEach(t=>{const e=document.createElement("div");if(e.classList.add("chat-select-dialog-item"),e.setAttribute("data-id",t.id),e.setAttribute("data-name",t.name),t.preview){const i=document.createElement("div");i.classList.add("chat-select-dialog-preview"),i.classList.add("loading"),i.innerHTML=antdLoading,e.appendChild(i);const s=new Image;s.classList.add("chat-select-dialog-preview"),s.src=String(t.preview),s.onload=()=>{e.insertBefore(s,i),e.removeChild(i)}}const i=document.createElement("span");i.classList.add("chat-select-dialog-name"),i.textContent=t.name,e.appendChild(i);const s=document.createElement("span");s.classList.add("chat-select-dialog-check"),s.innerHTML=checkSvg,switchDisplay(s,!1),e.appendChild(s),e.addEventListener("click",t=>{if(t.stopPropagation(),this.selectNode&&"Select"===this.selectNode.type)if(this.multiple){switchDisplay(e.lastChild,!isShow(e.lastChild));const t=e.parentElement.querySelectorAll(".chat-select-dialog-check.chat-view-show");if(0===t.length)this.selectNode.updateTag({id:null,name:this.emptyText});else{let e="",i="";Array.from(t,t=>{const s=t.parentElement;e+=`${s.getAttribute("data-id")},`,i+=`${s.getAttribute("data-name")}、`}),this.selectNode.updateTag({id:e.slice(0,-1),name:i.slice(0,-1)})}}else{const t=e.getAttribute("data-id"),i=e.getAttribute("data-name");this.selectNode.updateTag({id:t,name:i}),this.closeDialog()}else{const t=e.getAttribute("data-id"),i=e.getAttribute("data-name");this.bus.emit("insertSelect",{...this.selectNode||{},id:t,name:i}),this.closeDialog()}}),n.appendChild(e)}),s.appendChild(n),t.appendChild(s);const a=document.createElement("div");a.classList.add("chat-select-dialog-arrow"),t.appendChild(a),this.dialog.appendChild(t),this.chatElement.dialogRoot.appendChild(this.dialog)};class BeforeTip{constructor(t,e){__privateAdd(this,_BeforeTip_instances),__publicField(this,"chatElement"),__publicField(this,"bus"),__publicField(this,"tip"),__publicField(this,"dialog"),__publicField(this,"config",{}),__privateAdd(this,_Events4,[]),this.chatElement=t,this.bus=this.chatElement.chat.bus,this.tip=document.createElement("div"),this.dialog=document.createElement("div"),__privateMethod(this,_BeforeTip_instances,registerBus_fn4).call(this),__privateMethod(this,_BeforeTip_instances,registerEvent_fn4).call(this),__privateMethod(this,_BeforeTip_instances,createTip_fn).call(this),this.updateConfig(e)}updateConfig(t){this.config=t,this.tip.innerHTML=t.tipTemplate||"",this.dialog.innerHTML=t.dialogTemplate||""}openTip(t){this.tip.innerHTML=replaceTemplate(this.tip.innerHTML,t),this.dialog.innerHTML=replaceTemplate(this.dialog.innerHTML,t),switchDisplay(this.tip);(this.config.closeNames||[]).forEach(t=>{const e=this.tip.querySelector(`.${t}`);e&&e.addEventListener("click",()=>{this.closeTip()})}),this.tip.onmouseenter=()=>{switchDisplay(this.dialog),this.tip.classList.add("tip-hover");const t=this.tip.children[0],e=t.offsetWidth/2+t.offsetLeft,i=this.dialog.children[0].clientWidth/2;this.chatElement.container.style.setProperty("--chat-tip-dialog-left",e-i+"px");const s=Number(this.chatElement.container.style.getPropertyValue("--chat-before-tip-top").replace("px",""));this.chatElement.container.style.setProperty("--chat-tip-dialog-top",s-this.chatElement.rollBox.scrollTop+"px")},this.tip.onmouseleave=()=>{switchDisplay(this.dialog,!1),this.tip.classList.remove("tip-hover")};const e=this.tip.children[0].clientWidth;this.chatElement.container.style.setProperty("--chat-before-tip-width",`${e+Number(t.offset||4)}px`),this.bus.emit("focus","mark"),__privateMethod(this,_BeforeTip_instances,update_fn).call(this),this.bus.emit("tipState",!0)}closeTip(){isShow(this.tip)&&(this.chatElement.container.style.setProperty("--chat-before-tip-width","0px"),this.chatElement.container.style.setProperty("--chat-before-tip-top","0px"),this.chatElement.container.style.setProperty("--chat-tip-dialog-left","0px"),switchDisplay(this.tip,!1),switchDisplay(this.dialog,!1),this.tip.classList.remove("tip-hover"),this.bus.emit("focus","mark"),this.tip.innerHTML=this.config.tipTemplate||"",this.dialog.innerHTML=this.config.dialogTemplate||"",this.bus.emit("tipState",!1))}destroy(){this.bus.offKeyEvent("BeforeTip"),__privateGet(this,_Events4).forEach(t=>{const e=t[0],i=t[1];for(const t in i)e.removeEventListener(t,i[t])})}}_Events4=new WeakMap,_BeforeTip_instances=new WeakSet,registerBus_fn4=function(){const t="BeforeTip";this.bus.on(t,"destroy",()=>{this.destroy()}),this.bus.on(t,"openTip",t=>{this.openTip(t)}),this.bus.on(t,"closeTip",()=>{this.closeTip()}),this.bus.on(t,"editorChange",()=>{__privateMethod(this,_BeforeTip_instances,update_fn).call(this)})},registerEvent_fn4=function(){__privateSet(this,_Events4,[[window,{resize:()=>{__privateMethod(this,_BeforeTip_instances,update_fn).call(this)},keydown:t=>{"Escape"===t.key&&this.closeTip()}}]]),__privateGet(this,_Events4).forEach(t=>{const e=t[0],i=t[1];for(const t in i)e.addEventListener(t,i[t])})},createTip_fn=function(){this.tip.classList.add("chat-before-tip-wrap"),this.dialog.classList.add("chat-tip-dialog-wrap"),this.chatElement.rollBox.appendChild(this.tip),this.chatElement.dialogRoot.appendChild(this.dialog),switchDisplay(this.tip,!1),switchDisplay(this.dialog,!1)},update_fn=function(){if(!isShow(this.tip))return;const t=this.chatElement.chat.chatEditor.NODES[0].children[0],e=this.tip.children[0],i=t.$el.getBoundingClientRect(),s=e.getBoundingClientRect(),n=Number(this.chatElement.container.style.getPropertyValue("--chat-before-tip-top").replace("px","")),a=i.y+this.chatElement.chat.chatEditor.NODE_HEIGHT/2-(s.y+s.height/2)+n;this.chatElement.container.style.setProperty("--chat-before-tip-top",`${a+(this.config.offsetTop||0)}px`)};class ChatElement{constructor(t,e){__privateAdd(this,_ChatElement_instances),__publicField(this,"chat"),__publicField(this,"container"),__publicField(this,"rollBox"),__publicField(this,"richText"),__publicField(this,"placeholder"),__publicField(this,"dialogRoot"),__publicField(this,"mentionDialog"),__publicField(this,"triggerDialogs"),__publicField(this,"selectDialogs"),__publicField(this,"beforeTip"),this.chat=e,this.container=t,this.rollBox=document.createElement("div"),this.richText=document.createElement("div"),this.placeholder=document.createElement("div"),this.dialogRoot=document.createElement("div"),__privateMethod(this,_ChatElement_instances,registerBus_fn5).call(this),__privateMethod(this,_ChatElement_instances,createRichText_fn).call(this),__privateMethod(this,_ChatElement_instances,createPlaceholder_fn).call(this),__privateMethod(this,_ChatElement_instances,createDialogRoot_fn).call(this)}updatePlaceholder(t){this.placeholder.textContent=t}updateChatStyle(t){Object.assign(this.rollBox.style,t)}createMentionDialog(){this.mentionDialog?this.mentionDialog.updateConfig(this.chat.options.mentionConfig):this.mentionDialog=new MentionDialog(this,this.chat.options.mentionConfig)}createTriggerDialog(){this.triggerDialogs?(this.triggerDialogs.forEach(t=>{t.destroy()}),this.triggerDialogs=[]):this.triggerDialogs=[],this.chat.options.triggerConfig.forEach(t=>{this.triggerDialogs.push(new TriggerDialog(this,t))})}createSelectDialog(){this.selectDialogs?(this.selectDialogs.forEach(t=>{t.destroy()}),this.selectDialogs=[]):this.selectDialogs=[],this.chat.options.selectConfig.forEach(t=>{this.selectDialogs.push(new SelectDialog(this,t))})}createBeforeTip(){this.beforeTip?this.beforeTip.updateConfig(this.chat.options.tipConfig):this.beforeTip=new BeforeTip(this,this.chat.options.tipConfig)}destroy(){this.chat.bus.offKeyEvent("ChatElement"),this.rollBox.parentElement&&this.rollBox.parentElement.removeChild(this.rollBox),this.placeholder.parentElement&&this.placeholder.parentElement.removeChild(this.placeholder),this.dialogRoot.parentElement&&this.dialogRoot.parentElement.removeChild(this.dialogRoot)}}_ChatElement_instances=new WeakSet,registerBus_fn5=function(){const t="ChatElement";this.chat.bus.on(t,"editorChange",()=>{__privateMethod(this,_ChatElement_instances,switchPlaceholder_fn).call(this)}),this.chat.bus.on(t,"destroy",()=>{this.destroy()})},createRichText_fn=function(){this.container.classList.add("chat-area-wrap"),this.rollBox.classList.add("chat-rich-text"),this.rollBox.classList.add("chat-scroll"),this.richText.setAttribute("data-set-richType",RICH_WRAP),this.richText.setAttribute("contenteditable","true"),this.rollBox.appendChild(this.richText),this.container.appendChild(this.rollBox)},createPlaceholder_fn=function(){this.placeholder.classList.add("chat-placeholder-wrap"),switchDisplay(this.placeholder),this.container.appendChild(this.placeholder)},createDialogRoot_fn=function(){this.dialogRoot.classList.add("chat-dialog-wrap"),this.container.appendChild(this.dialogRoot)},switchPlaceholder_fn=function(){if(this.chat.chatEditor.isComposition)return switchDisplay(this.placeholder,!1);const t=this.chat.chatEditor.NODES;return t.length>1||t[0].children.length>1||t[0].children[0].text.length>0?switchDisplay(this.placeholder,!1):void switchDisplay(this.placeholder,!0)};class Render{constructor(t){__publicField(this,"$el",null),__publicField(this,"type",""),this.type=t}mount({parentElm:t,beforeElm:e,afterElm:i,targetElm:s}){s&&(i?i.nextElementSibling?t.insertBefore(s,i.nextElementSibling):t.appendChild(s):e?t.insertBefore(s,e):t.appendChild(s))}}const _Write=class t extends Render{constructor(t,e){super(e.type),__privateAdd(this,_Write_instances),__publicField(this,"context"),__publicField(this,"text",""),__publicField(this,"VOID_KEY","\ufeff"),this.context=t,this.text=String(e.text||""),this.render(e)}ruleBRTag(){const t=this.$el.children[0];if(t.childNodes.length>1){const e=[];for(let i=1;i<t.childNodes.length;i++)e.push(t.childNodes[i]);e.forEach(e=>{t.removeChild(e)})}if(!Boolean(this.text)&&this.$el===this.$el.parentElement.lastElementChild){const t=document.createElement("br");this.$el.children[0].appendChild(t)}}focus(t){const e=this.$el.children[0].childNodes[0];t||0===t?-1===t&&(t=e.textContent===this.VOID_KEY?1:e.textContent.length):t=e.textContent===this.VOID_KEY?1:0;const i=new Range,s=this.context.context.chat.getSelection();i.setStart(e,t),i.setEnd(e,t),s.removeAllRanges(),s.addRange(i),__privateMethod(this,_Write_instances,emit_fn).call(this,"cursorChange",{node:e,offset:t,type:"Write",instance:this})}updateNode(){const t=this.$el.children[0],e=t.childNodes[0],i=e.textContent||"";if(this.text=i.replace(new RegExp(this.VOID_KEY,"ig"),"")||"",t.setAttribute("data-set-empty",String(!Boolean(this.text))),Boolean(this.text)){if(-1!==i.indexOf(this.VOID_KEY)&&(e.textContent=this.text,this.focus(-1)),t.childNodes.length>1)for(let e=t.childNodes.length-1;e>0;e--)t.removeChild(t.childNodes[e])}else e.textContent=this.VOID_KEY,this.ruleBRTag()}deleteNode(){const t=this.context.children.indexOf(this);this.context.children.splice(t,1),this.context.$el.removeChild(this.$el)}deleteRelevanceNode(){this.deleteNode()}deleteRangeNode(t){const e=t.anchorOffset,i=t.focusOffset,s=e>i,n=s?i:e,a=s?e:i,o=this.text.slice(0,n),c=this.text.slice(a);this.text=o+c,this.syncNode(),this.focus(n)}updateContext(t){this.context=t}syncNode(){const t=this.$el.children[0].childNodes[0];Boolean(this.text)?t.textContent=this.text:t.textContent=this.VOID_KEY,this.ruleBRTag()}splitNode(e,i,s="",n=""){const a=!Boolean(this.text),o=a?"":this.text.slice(0,e),c=a?"":this.text.slice(e);this.text=i?o.slice(0,-i):o,this.text=this.text+s;const h=this.context.children.indexOf(this),l=new t(this.context,{type:"Write",text:n+c,afterElm:this.$el});this.context.children.splice(h+1,0,l),this.syncNode(),this.updateNode(),l.updateNode(),l.focus(n.length>0?n.length:void 0)}backspace(t){const e=t.anchorOffset;if(t.isCollapsed){if(0===e||1===e&&!Boolean(this.text)){const t=this.context.children.indexOf(this),e=this.context.context.NODES.indexOf(this.context);if(0===t){if(0===e)return void __privateMethod(this,_Write_instances,emit_fn).call(this,"closeTip");return void this.context.context.NODES[e].mergeNode(!1)}return void this.context.context.NODES[e].children[t-1].deleteRelevanceNode()}this.text=this.text.slice(0,e-1)+this.text.slice(e),this.syncNode(),this.focus(e-1)}else this.deleteRangeNode({anchorInstance:this,anchorOffset:e,focusInstance:this,focusOffset:t.focusOffset})}delete(t){const e=t.anchorOffset;if(t.isCollapsed)if(e===this.text.length||1===e&&!Boolean(this.text)){const t=this.context.children.indexOf(this),e=this.context.context.NODES.indexOf(this.context);if(t===this.context.children.length-1){if(e===this.context.context.NODES.length-1)return;return void this.context.context.NODES[e].mergeNode(!0)}this.context.context.NODES[e].children[t+1].deleteRelevanceNode(!0)}else this.text=this.text.slice(0,e)+this.text.slice(e+1),this.syncNode(),this.focus(e);else{const i=t.focusOffset,s=e>i,n=s?i:e,a=s?e:i,o=this.text.slice(0,n),c=this.text.slice(a);this.text=o+c,this.syncNode(),this.focus(n)}}render(t){const e=document.createElement("span");this.$el=e,e.setAttribute("data-set-richType",RICH_MARK),e.classList.add("chat-write-wrap");const i=document.createElement("span");i.classList.add("chat-write-input"),i.setAttribute("data-set-richType",RICH_WRITE),i.setAttribute("data-set-empty",String(!Boolean(this.text))),i.appendChild(document.createTextNode(Boolean(this.text)?this.text:this.VOID_KEY)),e.appendChild(i),this.mount({parentElm:(null==t?void 0:t.parentElm)||this.context.$el,targetElm:this.$el,...t||{}})}};_Write_instances=new WeakSet,emit_fn=function(t,...e){this.context.context.bus.emit(t,...e)};let Write=_Write;class Tag extends Render{constructor(t,e){super(t),__publicField(this,"context"),this.context=e}deleteNode(){const t=this.context.children.indexOf(this);this.context.children.splice(t,1),this.context.$el.removeChild(this.$el)}deleteRelevanceNode(t=!1){const e=this.context.children.indexOf(this),i=this.context.children[e-1],s=this.context.children[e+1];this.context.children.splice(e,1),this.context.$el.removeChild(this.$el),t?this.context.mergeWriteNode(s,i,!0,!0):this.context.mergeWriteNode(i,s)}deleteRangeNode(){this.deleteRelevanceNode()}updateContext(t){this.context=t}focus(t=!1){const e=this.context.children.indexOf(this),i=this.context.children[t?e-1:e+1];if(i){const e=!Boolean(i.text);i.focus(t?e?1:i.text.length:e?1:0)}}backspace(){this.context.backspace()}updateNode(){this.context.updateNode()}delete(){this.context.delete()}}class Mention extends Tag{constructor(t,e){super(e.type,t),__publicField(this,"id",""),__publicField(this,"name",""),this.id=e.id,this.name=e.name,this.render(e)}render(t){const e=document.createElement("span");this.$el=e,e.setAttribute("data-set-richType",RICH_MENTION),e.setAttribute("contenteditable","false"),e.classList.add("chat-tag-wrap");const i=document.createElement("span");i.classList.add("chat-tag-mention"),i.textContent="@"+this.name,e.appendChild(i),this.mount({parentElm:(null==t?void 0:t.parentElm)||this.context.$el,targetElm:this.$el,...t||{}})}}class Trigger extends Tag{constructor(t,e){super(e.type,t),__publicField(this,"id",""),__publicField(this,"name",""),__publicField(this,"key",""),this.id=e.id,this.name=e.name,this.key=e.key,this.render(e)}render(t){const e=document.createElement("span");this.$el=e,e.setAttribute("data-set-richType",RICH_TRIGGER),e.setAttribute("contenteditable","false"),e.classList.add("chat-tag-wrap");const i=document.createElement("span");i.classList.add("chat-tag-trigger"),i.textContent=this.key+this.name,e.appendChild(i),this.mount({parentElm:(null==t?void 0:t.parentElm)||this.context.$el,targetElm:this.$el,...t||{}})}}class Select extends Tag{constructor(t,e){super(e.type,t),__privateAdd(this,_Select_instances),__publicField(this,"id",""),__publicField(this,"name",""),__publicField(this,"key",""),this.id=e.id,this.name=e.name,this.key=e.key,this.render(e)}updateTag({id:t,name:e}){this.id=t,this.name=e;this.$el.children[0].children[0].textContent=e,this.focus(),__privateMethod(this,_Select_instances,emit_fn2).call(this,"richTextChange")}render(t){const e=document.createElement("span");this.$el=e,e.setAttribute("data-set-richType",RICH_SELECT),e.setAttribute("contenteditable","false"),e.classList.add("chat-tag-wrap");const i=document.createElement("span");i.classList.add("chat-tag-select"),i.innerHTML=`<span></span>${arrowSvg}`;i.children[0].textContent=this.name,e.appendChild(i),e.addEventListener("click",t=>{t.stopPropagation(),this.context.context.bus.emit("activeSelect",this)}),this.mount({parentElm:(null==t?void 0:t.parentElm)||this.context.$el,targetElm:this.$el,...t||{}})}}_Select_instances=new WeakSet,emit_fn2=function(t,...e){this.context.context.bus.emit(t,...e)};class Input extends Render{constructor(t,e){super(e.type),__privateAdd(this,_Input_instances),__publicField(this,"context"),__publicField(this,"text",""),__publicField(this,"placeholder",""),__publicField(this,"key",""),__publicField(this,"VOID_KEY","\ufeff"),__publicField(this,"WRAP_KEY","\n"),this.context=t,this.text=(e.text||"").replace(new RegExp(`${this.WRAP_KEY[0]}|${this.VOID_KEY}`,"ig"),""),this.placeholder=String(e.placeholder||"placeholder"),this.key=e.key,this.render(e)}updateContext(t){this.context=t}syncNode(){const t=this.$el.children[0].children[0].childNodes[0];Boolean(this.text)?t.textContent=this.fixWrapKey(this.text):t.textContent=this.VOID_KEY,this.updateNode()}updateNode(){const t=this.$el.children[0].children[0],e=this.$el.children[0].children[1],i=t.childNodes[0],s=i.textContent||"";if(this.text=s.replace(new RegExp(`${this.WRAP_KEY[0]}|${this.VOID_KEY}`,"ig"),""),switchDisplay(e,!Boolean(this.text),"inline-block"),Boolean(this.text)){if(-1!==s.indexOf(this.VOID_KEY))i.textContent=this.fixWrapKey(this.text),this.focus(-1);else if(-1!==this.text.indexOf(this.WRAP_KEY[1])){const t=this.fixWrapKey(this.text);if(t!==i.textContent){let e=0;for(let s=0;s<i.textContent.length;s++){if(i.textContent[s]!==t[s]){e=s;break}}i.textContent=t,this.focus(e+2)}}}else i.textContent=this.VOID_KEY}deleteNode(){const t=this.context.children.indexOf(this);this.context.children.splice(t,1),this.context.$el.removeChild(this.$el)}backspace(t){const e=t.anchorOffset;if(t.isCollapsed)if(0===e||1===e&&!Boolean(this.text))if(Boolean(this.text)){const t=this.context.children.indexOf(this);this.context.children[t-1].focus(-1)}else this.deleteRelevanceTag();else{const t=this.$el.children[0].children[0].childNodes[0],i=this.getWrapOffset(t,e,"left"),s=t.textContent||"";let n;switch(i){case 1:n=e-i-2;break;case 2:n=e-i-1;break;case 3:n=e-i;break;default:n=e-1}const a=s.slice(0,n),o=s.slice(e);this.text=(a+o).replace(new RegExp(`${this.WRAP_KEY[0]}|${this.VOID_KEY}`,"ig"),""),this.syncNode(),this.focus(n)}else this.deleteRangeNode({anchorInstance:this,anchorOffset:e,focusInstance:this,focusOffset:t.focusOffset})}delete(t){const e=t.anchorOffset,i=this.$el.children[0].children[0].childNodes[0],s=this.getWrapOffset(i,e,"right");if(t.isCollapsed)if(e+s===this.fixWrapKey(this.text).length||1===e&&!Boolean(this.text))if(Boolean(this.text)){const t=this.context.children.indexOf(this);this.context.children[t+1].focus()}else this.deleteRelevanceTag(!0);else{const t=i.textContent||"";let n,a,o;switch(s){case 1:n=2,a=1,o=e+1;break;case 2:n=1,a=2,o=e-1;break;case 3:n=0,a=3,o=e;break;default:n=0,a=1,o=e}const c=t.slice(0,e-n),h=t.slice(e+a);this.text=(c+h).replace(new RegExp(`${this.WRAP_KEY[0]}|${this.VOID_KEY}`,"ig"),""),this.syncNode(),this.focus(o)}else this.deleteRangeNode({anchorInstance:this,anchorOffset:e,focusInstance:this,focusOffset:t.focusOffset})}deleteRangeNode(t){const e=t.anchorOffset,i=t.focusOffset,s=e>i;let n=s?i:e,a=s?e:i;const o=this.$el.children[0].children[0].childNodes[0],c=o.textContent||"",h=this.getWrapOffset(o,n,"right"),l=this.getWrapOffset(o,a-1,"left"),r=c.slice(0,n+h),d=c.slice(a+l);this.text=(r+d).replace(new RegExp(`${this.WRAP_KEY[0]}|${this.VOID_KEY}`,"ig"),""),this.syncNode(),this.focus(n)}focus(t){const e=this.$el.children[0].children[0].childNodes[0];t||0===t?-1===t&&(t=e.textContent===this.VOID_KEY?1:e.textContent.length):t=e.textContent===this.VOID_KEY?1:0;const i=new Range,s=this.context.context.chat.getSelection();i.setStart(e,t),i.setEnd(e,t),s.removeAllRanges(),s.addRange(i),__privateMethod(this,_Input_instances,emit_fn3).call(this,"cursorChange",{node:e,offset:t,type:"Input",instance:this})}deleteRelevanceNode(t=!1){this.focus(t?void 0:-1)}deleteRelevanceTag(t=!1){const e=this.context.children.indexOf(this),i=this.context.children[e-1],s=this.context.children[e+1];this.context.children.splice(e,1),this.context.$el.removeChild(this.$el),t?this.context.mergeWriteNode(s,i,!0,!0):this.context.mergeWriteNode(i,s)}setText(t,e){if(e=this.fixWrapKey(e),Boolean(this.text)){const i=this.$el.children[0].children[0].textContent||"",s=i.slice(0,t),n=i.slice(t);this.text=s+e+n,this.syncNode(),this.focus(s.length+e.length)}else this.text=e,this.syncNode(),this.focus(e.length)}fixWrapKey(t){return t.replace(new RegExp(this.WRAP_KEY[0],"ig"),"").replace(new RegExp(this.WRAP_KEY[1],"ig"),this.WRAP_KEY)}getWrapOffset(t,e,i="left"){const s="left"===i?t.textContent[e-1]:t.textContent[e];if(s===this.WRAP_KEY[0]){return("left"===i?t.textContent[e-2]:t.textContent[e+1])===this.WRAP_KEY[1]?3:1}return s===this.WRAP_KEY[1]?2:0}render(t){const e=document.createElement("span");this.$el=e,e.setAttribute("data-set-richType",RICH_INPUT),e.setAttribute("contenteditable","false"),e.classList.add("chat-tag-wrap");const i=document.createElement("span");i.classList.add("chat-tag-input");const s=document.createElement("span");s.classList.add("input-write"),s.setAttribute("contenteditable","true"),s.textContent=Boolean(this.text)?this.fixWrapKey(this.text):this.VOID_KEY,i.appendChild(s);const n=document.createElement("span");n.classList.add("input-tip"),n.textContent=`[${this.placeholder}]`,i.appendChild(n),Boolean(this.text)&&switchDisplay(n,!1),e.addEventListener("click",()=>{Boolean(this.text)||this.focus()}),e.appendChild(i),this.mount({parentElm:(null==t?void 0:t.parentElm)||this.context.$el,targetElm:this.$el,...t||{}})}}_Input_instances=new WeakSet,emit_fn3=function(t,...e){this.context.context.bus.emit(t,...e)};class Custom extends Tag{constructor(t,e){super(e.type,t),__publicField(this,"html",""),this.html=e.html,this.render(e)}render(t){const e=document.createElement("span");this.$el=e,e.setAttribute("data-set-richType",RICH_CUSTOM),e.setAttribute("contenteditable","false"),e.classList.add("chat-tag-wrap"),e.innerHTML=this.html,this.mount({parentElm:(null==t?void 0:t.parentElm)||this.context.$el,targetElm:this.$el,...t||{}})}}class Grid extends Render{constructor(t,e,i){super("Grid"),__publicField(this,"children",[]),__publicField(this,"context"),this.context=t,this.render(e,i)}getAnalyzeChildren(t){if(!t||0===t.length)return[{type:"Write",text:""}];const e=[];t.forEach((i,s)=>{if(s===t.length-1)return;const n=s+1;if("Write"===i.type&&"Write"===t[n].type){let t=n-e.length;e.push(t)}}),e.forEach(e=>{const i=t[e];t[e-1].text+=i.text,t.splice(e,1)});const i=[];return t.forEach((e,s)=>{if(s===t.length-1)return;const n=s+1;if("Write"!==e.type&&"Write"!==t[n].type){let t=n+i.length;i.push(t)}}),i.forEach(e=>{t.splice(e,0,{type:"Write",text:""})}),"Write"!==t[0].type&&t.unshift({type:"Write",text:""}),"Write"!==t[t.length-1].type&&t.push({type:"Write",text:""}),t}emit(t,...e){this.context.bus.emit(t,...e)}mergeNode(t=!1){const e=this.context.NODES.indexOf(this);if(t){const t=this.context.NODES[e+1];if(t){const e=this.children[this.children.length-1],i=t.children[0];this.mergeWriteNode(e,i),this.children.push(...t.children);const s=document.createDocumentFragment();t.children.forEach(t=>{t.updateContext(this),s.appendChild(t.$el)}),this.$el.appendChild(s),e.ruleBRTag(),t.deleteNode()}}else{const t=this.context.NODES[e-1];if(t){const e=t.children[t.children.length-1],i=this.children[0];this.mergeWriteNode(e,i),t.children.push(...this.children);const s=document.createDocumentFragment();this.children.forEach(e=>{e.updateContext(t),s.appendChild(e.$el)}),t.$el.appendChild(s),e.ruleBRTag(),this.deleteNode()}}}splitNode(t,e=0){const i=this.context.NODES.indexOf(this),s=this.children.indexOf(t),n=Boolean(t.text)?t.text.slice(0,e):"",a=Boolean(t.text)?t.text.slice(e):"";t.text=n;const o=this.children.slice(0,s+1),c=this.children.slice(s+1);this.children=o;const h=new Grid(this.context,[],{afterElm:this.$el});this.context.NODES.splice(i+1,0,h);const l=h.children[0];l.text=a,h.children.push(...c);const r=document.createDocumentFragment();c.forEach(t=>{t.updateContext(h),r.appendChild(t.$el)}),h.$el.appendChild(r),t.syncNode(),l.syncNode(),l.focus()}deleteNode(){this.children=[];const t=this.context.NODES.indexOf(this);this.context.NODES.splice(t,1),this.context.$el.removeChild(this.$el)}mergeWriteNode(t,e,i=!0,s=!1){const n=t.text||"",a=e.text||"",o=s?a.length:n.length;t.text=s?a+n:n+a,t.syncNode(),e.deleteNode(),i&&t.focus(Boolean(t.text)?o:1)}splitWriteNode(t,e){const i=this.children.indexOf(t),s=Boolean(t.text)?t.text.slice(0,e):"",n=Boolean(t.text)?t.text.slice(e):"";t.text=s,t.syncNode();const a=new Write(this,{type:"Write",text:n,afterElm:t.$el});this.children.splice(i+1,0,a)}deleteRangeNode(t){const e=t.anchorInstance,i=t.focusInstance;if(e===i)return void e.deleteRangeNode(t);const s=this.children.indexOf(e)>this.children.indexOf(i);"Write"===e.type&&this.splitWriteNode(e,t.anchorOffset),"Write"===i.type&&this.splitWriteNode(i,t.focusOffset);const n=this.children.indexOf(e),a=this.children.indexOf(i);let o=(s?a:n)+1;const c=s?n:a;s&&"Write"!==i.type&&(o-=1);const h=this.children.slice(o,c+1),l=this.children[o-1],r=this.children[c+1];h.forEach(t=>{t.deleteNode()}),this.mergeWriteNode(l,r)}updateNode(){this.context.fixEditor()}backspace(){this.context.fixEditor()}delete(){this.context.fixEditor()}render(t,e){const i=document.createElement("p");this.$el=i,i.className="chat-grid-wrap",i.setAttribute("data-set-richType",RICH_GRID),this.renderChildren(t,!1),this.mount({parentElm:this.context.$el,targetElm:this.$el,...e||{}})}renderChildren(t,e=!0){if(!this.$el)return;this.children=[],this.$el.innerHTML="";const i=this.getAnalyzeChildren(t),s=document.createDocumentFragment();i.forEach(t=>{let e;switch(t.type){case"Write":e=new Write(this,{...t,parentElm:s}),this.children.push(e);break;case"Mention":e=new Mention(this,{...t,parentElm:s}),this.children.push(e);break;case"Trigger":e=new Trigger(this,{...t,parentElm:s}),this.children.push(e);break;case"Select":e=new Select(this,{...t,parentElm:s}),this.children.push(e);break;case"Input":e=new Input(this,{...t,parentElm:s}),this.children.push(e);break;case"Custom":e=new Custom(this,{...t,parentElm:s}),this.children.push(e);break;default:const i=this.context.components[t.type];i&&(e=new i({type:t.type,data:t.data,context:this,config:{parentElm:s}}),this.children.push(e))}}),this.$el.appendChild(s);const n=this.children[this.children.length-1];n.ruleBRTag(),e&&(n.focus(-1),this.emit("richTextChange"))}}class ChatEditor{constructor(t){__privateAdd(this,_ChatEditor_instances),__publicField(this,"$el"),__publicField(this,"bus"),__publicField(this,"chat"),__publicField(this,"isComposition",!1),__publicField(this,"textLength",0),__privateAdd(this,_disabledEvent,!1),__publicField(this,"NODES",[]),__publicField(this,"NODE_HEIGHT",24),__publicField(this,"IME_MODEL",!1),__publicField(this,"FIX_MODEL",!1),__privateAdd(this,_Events5,[]),__publicField(this,"components",{}),__publicField(this,"markCursorWrite",{node:null,offset:0,instance:null}),__publicField(this,"markCursorInput",{node:null,offset:0,instance:null}),__publicField(this,"markLastType","Write"),__publicField(this,"undoHistory",[]),__publicField(this,"redoHistory",[]),__publicField(this,"historyLoading",!1),this.chat=t,this.bus=t.bus,this.$el=t.chatElement.richText,__privateMethod(this,_ChatEditor_instances,registerBus_fn6).call(this),__privateMethod(this,_ChatEditor_instances,registerEvent_fn5).call(this),this.initEditor()}initEditor(){this.$el.innerHTML="",this.NODES=[new Grid(this)],this.markLastType="Write",this.NODE_HEIGHT=this.NODES[0].$el.getBoundingClientRect().height,this.undoHistory=[{nodes:this.compileNodes(this.NODES),gridIndex:this.NODES.length-1,childIndex:0,offset:1,type:"Write"}],this.redoHistory=[],this.chat.options.autoFocus&&this.chat.nextTick(()=>{this.focusLast()});const t=this.NODES[this.NODES.length-1],e=t.children[t.children.length-1];__privateMethod(this,_ChatEditor_instances,cursorChange_fn).call(this,{node:e.$el.children[0].childNodes[0],offset:Boolean(e.text)?e.text.length:1,type:"Write",instance:e})}async fixEditor(t){this.$el.innerHTML="",t||(t=this.compileNodes(this.NODES)),this.NODES=t.map(t=>new Grid(this,t)),this.focusLast(),await __privateMethod(this,_ChatEditor_instances,richTextChange_fn).call(this)}deleteRangeNode(t){let e=t.anchorInstance,i=t.focusInstance;"Grid"===e.type&&(e=e.children[0],t.anchorOffset=Boolean(e.text)?0:1),"Grid"===i.type&&(i=i.children[0],t.focusInstance=Boolean(i.text)?0:1);const s=e.context,n=i.context,a=this.NODES.indexOf(s),o=this.NODES.indexOf(n),c=a>o,h=c?o:a,l=c?a:o;this.NODES.slice(h+1,l).forEach(t=>{t.deleteNode()});const r=c?n:s,d=c?s:n,p=r.children[r.children.length-1],u=d.children[0];c?(r.deleteRangeNode({anchorInstance:p,anchorOffset:Boolean(p.text)?p.text.length:1,focusInstance:i,focusOffset:t.focusOffset}),d.deleteRangeNode({anchorInstance:u,anchorOffset:Boolean(u.text)?0:1,focusInstance:e,focusOffset:t.anchorOffset})):(r.deleteRangeNode({anchorInstance:e,anchorOffset:t.anchorOffset,focusInstance:p,focusOffset:Boolean(p.text)?p.text.length:1}),d.deleteRangeNode({anchorInstance:i,anchorOffset:t.focusOffset,focusInstance:u,focusOffset:Boolean(u.text)?0:1})),r.mergeNode(!0)}findNode(t,e=5,i=!0){if(!t)return null;if(i&&!this.$el.contains(t))return null;if(e<=0)return null;if(t.nodeType===Node.TEXT_NODE)return this.findNode(t.parentElement,e-1);const s=t,n=s.getAttribute?s.getAttribute("data-set-richType"):"";if(n===RICH_WRITE){const t=s.parentElement,e=t.parentElement,i=Array.prototype.indexOf.call(e.children,t),n=Array.prototype.indexOf.call(this.$el.children,e);return this.NODES[n].children[i]}if(n===RICH_MARK){const t=s,e=t.parentElement,i=Array.prototype.indexOf.call(e.children,t),n=Array.prototype.indexOf.call(this.$el.children,e);return this.NODES[n].children[i]}if(n===RICH_MENTION||n===RICH_TRIGGER||n===RICH_SELECT||n===RICH_INPUT||n===RICH_CUSTOM||n===RICH_COMPONENT){const t=s,e=t.parentElement,i=Array.prototype.indexOf.call(e.children,t),n=Array.prototype.indexOf.call(this.$el.children,e);return this.NODES[n].children[i]}if(n===RICH_GRID){const t=Array.prototype.indexOf.call(this.$el.children,s);return this.NODES[t]}return this.findNode(s.parentElement,e-1,!1)}focusFirst(){this.NODES[0].children[0].focus(),this.cursorView()}focusMark(){const t=this.chat.getSelection(),e=new Range;switch(this.markLastType){case"Write":e.setStart(this.markCursorWrite.node,this.markCursorWrite.offset),e.setEnd(this.markCursorWrite.node,this.markCursorWrite.offset);break;case"Input":e.setStart(this.markCursorInput.node,this.markCursorInput.offset),e.setEnd(this.markCursorInput.node,this.markCursorInput.offset)}t.removeAllRanges(),t.addRange(e),this.cursorView()}focusLast(){const t=this.NODES[this.NODES.length-1];t.children[t.children.length-1].focus(-1),this.cursorView()}selectAll(){const t=this.chat.getSelection(),e=new Range,i=this.NODES[0].children[0],s=this.NODES[this.NODES.length-1].children[this.NODES[this.NODES.length-1].children.length-1],n=i.$el.children[0].childNodes[0],a=s.$el.children[0].childNodes[0];e.setStart(n,Boolean(i.text)?0:1),e.setEnd(a,Boolean(s.text)?s.text.length:1),t.removeAllRanges(),t.addRange(e)}cursorMove(t,e){const i=e||this.chat.getSelection(),s=t<0;if(!i.isCollapsed){const t=this.findNode(i.anchorNode),e=this.findNode(i.focusNode);if(!t||!e)return;let n,a,o=!1;if(t===e)o=i.anchorOffset>i.focusOffset;else if(t.context===e.context){o=t.context.children.indexOf(t)>e.context.children.indexOf(e)}else{o=this.NODES.indexOf(t.context)>this.NODES.indexOf(e.context)}return s?(n=o?i.focusOffset:i.anchorOffset,a=o?e:t):(n=o?i.anchorOffset:i.focusOffset,a=o?t:e),"Write"===a.type||"Input"===a.type?a.focus(n):a.focus(o),void this.cursorView()}const n=i.focusNode,a=this.findNode(n);let o=0;if(!a)return;if("Write"===a.type){const e=i.focusOffset,n=s?a.text.slice(0,e):a.text.slice(e);if(n.length>=Math.abs(t))return a.focus(e+t),void this.cursorView();o+=n.length}else if("Input"===a.type){const e=i.focusOffset,n=a.$el.children[0].children[0].childNodes[0],c=(s?n.textContent.slice(0,e):n.textContent.slice(e)).replace(new RegExp(`${a.VOID_KEY}|${a.WRAP_KEY[0]}`,"ig"),"");if(c.length>=Math.abs(t)){const i=a.getWrapOffset(n,s?e+t+1:e+t-1,s?"left":"right");return i?s?a.focus(e+t-i+1):a.focus(e+t+i-1):a.focus(e+t),void this.cursorView()}o+=c.length}const c=a.context.children.indexOf(a);if(s){if(0===c){const e=this.NODES.indexOf(a.context);if(0===e)return void a.focus();const i=this.NODES[e-1],s=i.children[i.children.length-1],n=s.$el.children[0].childNodes[0];return o+=1,void this.cursorMove(-(Math.abs(t)-o),{focusNode:n,focusOffset:Boolean(s.text)?s.text.length:1,isCollapsed:!0})}const e=a.context.children[c-1];let i,s;o+=1,"Input"===e.type?(i=e,s=i.$el.children[0].children[0].childNodes[0]):"Write"===e.type?(i=e,s=i.$el.children[0].childNodes[0]):(i=a.context.children[c-2],s=i.$el.children[0].childNodes[0]);const n="Input"===e.type?i.fixWrapKey(i.text):i.text;this.cursorMove(-(Math.abs(t)-o),{focusNode:s,focusOffset:Boolean(n)?n.length:1,isCollapsed:!0})}else{if(c===a.context.children.length-1){const e=this.NODES.indexOf(a.context);if(e===this.NODES.length-1)return void a.focus(-1);const i=this.NODES[e+1].children[0],s=i.$el.children[0].childNodes[0];return o+=1,void this.cursorMove(t-o,{focusNode:s,focusOffset:Boolean(i.text)?0:1,isCollapsed:!0})}const e=a.context.children[c+1];let i,s;o+=1,"Input"===e.type?(i=e,s=i.$el.children[0].children[0].childNodes[0]):"Write"===e.type?(i=e,s=i.$el.children[0].childNodes[0]):(i=a.context.children[c+2],s=i.$el.children[0].childNodes[0]),this.cursorMove(t-o,{focusNode:s,focusOffset:Boolean(i.text)?0:1,isCollapsed:!0})}}cursorView(){const t=this.$el.parentElement;if(t.scrollHeight<=t.clientHeight)return;const e=this.chat.getSelection().getRangeAt(0).getClientRects()[0],i=t.getClientRects()[0],s=e.y-i.y;s<0?t.scrollTop=t.scrollTop-Math.abs(s):s+e.height>i.height&&(t.scrollTop=t.scrollTop+(s+e.height-i.height))}compileNodes(t){const e=[];return t.forEach(t=>{const i=[];t.children.forEach(t=>{switch(t.type){case"Write":i.push({type:"Write",text:t.text});break;case"Mention":i.push({type:"Mention",id:t.id,name:t.name});break;case"Trigger":i.push({type:"Trigger",id:t.id,name:t.name,key:t.key});break;case"Select":i.push({type:"Select",id:t.id,name:t.name,key:t.key});break;case"Input":i.push({type:"Input",placeholder:t.placeholder,text:t.text,key:t.key});break;case"Custom":i.push({type:"Custom",html:t.html});break;default:this.components[t.type]&&i.push({type:t.type,data:t.data})}}),e.push(i)}),e}async insertText(t){const e=t.replace(new RegExp("\ufeff","ig"),"").replace(/\r\n/g,"\n").replace(/\r/g,"\n").split("\n").map(t=>[{type:"Write",text:t}]);await this.insertNodes(e)}async insertNodes(t){const{instance:e,offset:i}=this.markCursorWrite;if(!e)return;const s=e,n=s.context,a=this.NODES.indexOf(n);n.splitNode(s,i);let o=n.$el,c=null,h=null;t.forEach((e,i)=>{const s=new Grid(this,e,{afterElm:o});o=s.$el,0===i?c=s:i===t.length-1&&(h=s),this.NODES.splice(a+i+1,0,s)}),c&&c.mergeNode(),h?h.mergeNode(!0):n.mergeNode(!0),await __privateMethod(this,_ChatEditor_instances,richTextChange_fn).call(this)}async insertInputText(t){const{instance:e,offset:i}=this.markCursorInput;if(!e)return;const s=e,n=t.replace(new RegExp("\ufeff","ig"),"").replace(/\r\n/g,"\n").replace(/\r/g,"\n");s.setText(i,n),await __privateMethod(this,_ChatEditor_instances,richTextChange_fn).call(this)}splitWrite(t){const{instance:e,offset:i}=this.markCursorWrite;if(!e)return null;const s=e,n=s.context,a=n.children.indexOf(s);return s.splitNode(i,t.del,t.beforeText,t.afterText),{index:a,write:s,grid:n}}async insertMention(t){const e=this.splitWrite(t);if(!e)return;const{index:i,write:s,grid:n}=e,a=new Mention(n,{type:"Mention",id:t.id,name:t.name,afterElm:s.$el});n.children.splice(i+1,0,a),await __privateMethod(this,_ChatEditor_instances,richTextChange_fn).call(this)}async insertTrigger(t){const e=this.splitWrite(t);if(!e)return;const{index:i,write:s,grid:n}=e,a=new Trigger(n,{type:"Trigger",id:t.id,name:t.name,key:t.key,afterElm:s.$el});n.children.splice(i+1,0,a),await __privateMethod(this,_ChatEditor_instances,richTextChange_fn).call(this)}async insertSelect(t){const e=this.splitWrite(t);if(!e)return;const{index:i,write:s,grid:n}=e,a=new Select(n,{type:"Select",id:t.id,name:t.name,key:t.key,afterElm:s.$el});n.children.splice(i+1,0,a),await __privateMethod(this,_ChatEditor_instances,richTextChange_fn).call(this)}async insertInput(t){const e=this.splitWrite(t);if(!e)return;const{index:i,write:s,grid:n}=e,a=new Input(n,{type:"Input",text:t.text,placeholder:t.placeholder,key:t.key,afterElm:s.$el});n.children.splice(i+1,0,a),a.focus(-1),await __privateMethod(this,_ChatEditor_instances,richTextChange_fn).call(this)}async insertCustom(t){const e=this.splitWrite(t);if(!e)return;const{index:i,write:s,grid:n}=e,a=new Custom(n,{type:"Custom",html:t.html,afterElm:s.$el});n.children.splice(i+1,0,a),await __privateMethod(this,_ChatEditor_instances,richTextChange_fn).call(this)}async reset(t){if(this.$el.innerHTML="",this.NODES=t.chatNode.map(t=>new Grid(this,t)),t.clearHistory){const t=this.NODES[this.NODES.length-1],e=t.children[t.children.length-1];this.undoHistory=[{nodes:this.compileNodes(this.NODES),gridIndex:this.NODES.length-1,childIndex:t.children.length-1,offset:Boolean(e.text)?e.text.length:1,type:"Write"}],this.redoHistory=[]}this.markLastType="Write",await this.chat.nextTick(),this.focusLast(),await __privateMethod(this,_ChatEditor_instances,richTextChange_fn).call(this,!t.clearHistory)}destroy(){this.bus.offKeyEvent("ChatEditor"),__privateGet(this,_Events5).forEach(t=>{const e=t[0],i=t[1];for(const t in i)e.removeEventListener(t,i[t])})}useComponent(t,e){this.components[t]=e}async insertComponent(t,e){const i=this.components[t];if(!i)return;const s=this.splitWrite({type:t,data:e,del:0});if(!s)return;const{index:n,write:a,grid:o}=s,c=new i({type:t,data:e,context:o,config:{afterElm:a.$el}});o.children.splice(n+1,0,c),await __privateMethod(this,_ChatEditor_instances,richTextChange_fn).call(this)}}_disabledEvent=new WeakMap,_Events5=new WeakMap,_ChatEditor_instances=new WeakSet,registerBus_fn6=function(){const t="ChatEditor";this.bus.on(t,"richTextChange",async t=>{await __privateMethod(this,_ChatEditor_instances,richTextChange_fn).call(this),t&&t()}),this.bus.on(t,"richTextDelete",async(t,e)=>{await __privateMethod(this,_ChatEditor_instances,richTextDelete_fn).call(this,t),e&&e()}),this.bus.on(t,"cursorChange",t=>{__privateMethod(this,_ChatEditor_instances,cursorChange_fn).call(this,t)}),this.bus.on(t,"lineBreak",async t=>{await __privateMethod(this,_ChatEditor_instances,richTextWrap_fn).call(this),t&&t()}),this.bus.on(t,"undo",async t=>{await __privateMethod(this,_ChatEditor_instances,richTextUndo_fn).call(this),t&&t()}),this.bus.on(t,"redo",async t=>{await __privateMethod(this,_ChatEditor_instances,richTextRedo_fn).call(this),t&&t()}),this.bus.on(t,"recordHistory",debounce(__privateMethod(this,_ChatEditor_instances,recordHistory_fn),200).bind(this)),this.bus.on(t,"ruleMaxLength",()=>{__privateMethod(this,_ChatEditor_instances,ruleMaxLength_fn).call(this)}),this.bus.on(t,"switchDisabledState",t=>{__privateSet(this,_disabledEvent,t)}),this.bus.on(t,"insertMention",async(t,e)=>{await this.insertMention(t),e&&e()}),this.bus.on(t,"insertTrigger",async(t,e)=>{await this.insertTrigger(t),e&&e()}),this.bus.on(t,"insertSelect",async(t,e)=>{await this.insertSelect(t),e&&e()}),this.bus.on(t,"insertInput",async(t,e)=>{await this.insertInput(t),e&&e()}),this.bus.on(t,"insertCustom",async(t,e)=>{await this.insertCustom(t),e&&e()}),this.bus.on(t,"focus",t=>{switch(t){case"first":this.focusFirst();break;case"last":this.focusLast();break;case"mark":this.focusMark()}}),this.bus.on(t,"destroy",()=>{this.destroy()})},registerEvent_fn5=function(){__privateSet(this,_Events5,[[this.$el,{keydown:t=>{if(this.isComposition=t.isComposing,this.chat.deviceInfo.isPc||!isKeyType(t,"IME")){if(!this.IME_MODEL)if(this.isComposition||!isKeyType(t,"text-backspace")&&!isKeyType(t,"text-delete"))this.chat.options.keyboardWrapFun(t)||!this.chat.deviceInfo.isPc&&"Enter"===t.key?(t.preventDefault(),t.stopPropagation(),__privateMethod(this,_ChatEditor_instances,richTextWrap_fn).call(this)):!__privateGet(this,_disabledEvent)&&this.chat.options.keyboardSendFun(t)?(t.preventDefault(),t.stopPropagation(),this.isComposition||this.bus.emit("send")):isKeyType(t,"text-select-all")?(t.preventDefault(),t.stopPropagation(),this.selectAll()):isKeyType(t,"text-move")?(t.preventDefault(),t.stopPropagation(),this.isComposition||this.cursorMove("ArrowLeft"===t.key||"ArrowLeft"===t.code?-1:1)):isKeyType(t,"text-undo")?(t.preventDefault(),t.stopPropagation(),__privateMethod(this,_ChatEditor_instances,richTextUndo_fn).call(this)):isKeyType(t,"text-redo")?(t.preventDefault(),t.stopPropagation(),__privateMethod(this,_ChatEditor_instances,richTextRedo_fn).call(this)):isKeyType(t,"text-jump")&&(t.preventDefault(),t.stopPropagation(),t.shiftKey?this.chat.jumpPrev():this.chat.jumpNext());else{t.preventDefault(),t.stopPropagation();const e=isKeyType(t,"text-delete");__privateMethod(this,_ChatEditor_instances,richTextDelete_fn).call(this,e)}}else this.IME_MODEL=!0},beforeinput:async t=>{if(!this.IME_MODEL||!["insertParagraph","deleteContentBackward"].includes(t.inputType))return;t.preventDefault(),t.stopPropagation();const e=this.chat.getSelection();let i=this.findNode(e.focusNode),s=e.focusOffset;if(i||(i=this.findNode(this.markCursorWrite.node),s=this.markCursorWrite.offset),!i)return;"Grid"===i.type&&(i=i.children[0]),this.FIX_MODEL=!0;const n=i,a=this.NODES.indexOf(n.context),o=n.context.children.indexOf(n),c=this.compileNodes(this.NODES);this.chat.nextTick(async()=>{this.$el.innerHTML="",this.NODES=c.map(t=>new Grid(this,t));this.NODES[a].children[o].focus(s),"insertParagraph"===t.inputType?await __privateMethod(this,_ChatEditor_instances,richTextWrap_fn).call(this):"deleteContentBackward"===t.inputType&&await __privateMethod(this,_ChatEditor_instances,richTextDelete_fn).call(this),this.IME_MODEL=!1,this.FIX_MODEL=!1})},input:()=>{this.FIX_MODEL||(this.IME_MODEL=!1,__privateMethod(this,_ChatEditor_instances,richTextChange_fn).call(this))},copy:t=>{t.stopPropagation(),t.preventDefault(),__privateMethod(this,_ChatEditor_instances,richTextCopy_fn).call(this,t)},cut:t=>{t.stopPropagation(),t.preventDefault(),__privateMethod(this,_ChatEditor_instances,richTextCopy_fn).call(this,t),__privateMethod(this,_ChatEditor_instances,richTextDelete_fn).call(this)},paste:t=>{t.stopPropagation(),t.preventDefault(),__privateMethod(this,_ChatEditor_instances,richTextPaste_fn).call(this,t)},blur:()=>{__privateMethod(this,_ChatEditor_instances,cursorChange_fn).call(this)},focus:()=>{__privateMethod(this,_ChatEditor_instances,cursorChange_fn).call(this)},click:()=>{this.chat.nextTick(()=>{__privateMethod(this,_ChatEditor_instances,cursorChange_fn).call(this)})},compositionstart:()=>{this.isComposition=!0},compositionend:()=>{this.isComposition=!1},dragstart:t=>{t.stopPropagation(),t.preventDefault()},dragover:t=>{t.stopPropagation(),t.preventDefault()},drop:t=>{t.stopPropagation(),t.preventDefault()}}],[window,{keydown:t=>{(isKeyType(t,"text-undo")||isKeyType(t,"text-redo"))&&(t.preventDefault(),t.stopPropagation())}}]]);const t=["blur"];__privateGet(this,_Events5).forEach(e=>{const i=e[0],s=e[1];for(const e in s)i.addEventListener(e,s[e],-1!==t.indexOf(e))})},richTextDelete_fn=async function(t=!1){const e=this.chat.getSelection(),i=e.anchorNode,s=e.focusNode;let n=this.findNode(i),a=this.findNode(s);if(n&&a){if(n===a)t?n.delete(e):n.backspace(e);else if(n.context===a.context){n.context.deleteRangeNode({anchorInstance:n,anchorOffset:e.anchorOffset,focusInstance:a,focusOffset:e.focusOffset})}else this.deleteRangeNode({anchorInstance:n,anchorOffset:e.anchorOffset,focusInstance:a,focusOffset:e.focusOffset});await __privateMethod(this,_ChatEditor_instances,richTextChange_fn).call(this)}},richTextWrap_fn=async function(){if(this.isComposition)return;let t=this.chat.getSelection();t.isCollapsed||await __privateMethod(this,_ChatEditor_instances,richTextDelete_fn).call(this),t=this.chat.getSelection();const e=t.focusNode,i=this.findNode(e);if(i){if("Write"===i.type){i.context.splitNode(i,t.focusOffset)}else"Input"===i.type&&i.setText(t.focusOffset,"\n");await __privateMethod(this,_ChatEditor_instances,richTextChange_fn).call(this)}},richTextCopy_fn=function(t){const e=this.chat.getSelection(),i=t.clipboardData;if(e.isCollapsed||e.rangeCount<=0)return;const s=e.toString().replace(/\n\n/g,"\n")||"";i.setData("text/plain",s);let n=this.findNode(e.anchorNode),a=this.findNode(e.focusNode),o=e.anchorOffset,c=e.focusOffset;if(!n||!a)return;if("Grid"===n.type&&(n=n.children[0],o=Boolean(n.text)?0:1),"Grid"===a.type&&(a=a.children[0],c=Boolean(a.text)?0:1),n===a)return;const h=n.context,l=a.context;if(h===l){const t=h.children.indexOf(n),e=l.children.indexOf(a),s=t>e,r=s?e:t,d=s?t:e,p=h.children.slice(r+1,d),u={...s?a:n},f={...s?n:a},g=s?c:o,_=s?o:c;"Write"===u.type&&(u.text=u.text.slice(g)),"Write"===f.type&&(f.text=f.text.slice(0,_)),p.unshift(u),p.push(f);const m={type:"Grid",children:p},y=this.compileNodes([m]);return void i.setData(CHAT_COPY_KEY,JSON.stringify(y))}const r=n.context,d=a.context,p=this.NODES.indexOf(r),u=this.NODES.indexOf(d);let f,g,_,m,y,E,x,v;p>u?(f=d,g=r,_=a,m=n,y=u,E=p,x=c,v=o):(f=r,g=d,_=n,m=a,y=p,E=u,x=o,v=c);const C=f.children.indexOf(_),b=this.compileNodes([{type:"Gird",children:f.children.filter((t,e)=>e>C)}]);"Write"===_.type?b[0].unshift({type:"Write",text:Boolean(_.text)?_.text.slice(x):""}):b[0].unshift({...this.compileNodes([{type:"Gird",children:[_]}])[0][0]});const w=g.children.indexOf(m),T=this.compileNodes([{type:"Gird",children:g.children.filter((t,e)=>e<w)}]);"Write"===m.type?T[0].push({type:"Write",text:Boolean(m.text)?m.text.slice(0,v):""}):T[0].push({...this.compileNodes([{type:"Gird",children:[m]}])[0][0]});const D=this.compileNodes(this.NODES.slice(y+1,E));D.unshift(b[0]),D.push(T[0]),i.setData(CHAT_COPY_KEY,JSON.stringify(D))},richTextPaste_fn=async function(t){const e=t.clipboardData,i=e.getData("text/plain");if(!i)return;if("Input"===this.markLastType)return void this.insertInputText(i);const s=e.getData(CHAT_COPY_KEY)||"";let n=[];try{n=JSON.parse(s)}catch(t){}this.chat.getSelection().isCollapsed||await __privateMethod(this,_ChatEditor_instances,richTextDelete_fn).call(this),n&&n.length>0?this.insertNodes(n):this.insertText(i)},recordHistory_fn=function(){if("Input"===this.markLastType){const{instance:t,offset:e}=this.markCursorInput;if(!t)return;const i=t,s=i.context;this.undoHistory.push({nodes:this.compileNodes(this.NODES),gridIndex:this.NODES.indexOf(s),childIndex:s.children.indexOf(i),offset:e,type:"Input"})}else{const{instance:t,offset:e}=this.markCursorWrite;if(!t)return;const i=t,s=i.context;this.undoHistory.push({nodes:this.compileNodes(this.NODES),gridIndex:this.NODES.indexOf(s),childIndex:s.children.indexOf(i),offset:e,type:"Write"})}this.undoHistory.length>50&&this.undoHistory.shift()},richTextUndo_fn=async function(){if(this.historyLoading||this.undoHistory.length<=1)return;const t=this.undoHistory[this.undoHistory.length-1],e=this.undoHistory[this.undoHistory.length-2];this.redoHistory.push(t),this.undoHistory.pop(),await __privateMethod(this,_ChatEditor_instances,renderHistory_fn).call(this,e)},richTextRedo_fn=async function(){if(this.historyLoading||this.redoHistory.length<=0)return;const t=this.redoHistory[this.redoHistory.length-1];this.redoHistory.pop(),this.undoHistory.push(t),await __privateMethod(this,_ChatEditor_instances,renderHistory_fn).call(this,t)},renderHistory_fn=async function(t){this.historyLoading=!0,this.$el.innerHTML="",this.NODES=t.nodes.map(t=>new Grid(this,t));this.NODES[t.gridIndex].children[t.childIndex].focus(t.offset),await __privateMethod(this,_ChatEditor_instances,richTextChange_fn).call(this,!1),this.historyLoading=!1},richTextChange_fn=async function(t=!0){const e=this.chat.getSelection(),i=e.focusNode,s=this.findNode(i);return s&&__privateMethod(this,_ChatEditor_instances,cursorChange_fn).call(this,{type:s.type,node:s.$el.children[0].childNodes[0],offset:e.focusOffset,instance:s}),await this.chat.nextTick(),this.isComposition||(null==s||s.updateNode(),__privateMethod(this,_ChatEditor_instances,ruleMaxLength_fn).call(this),this.chat.deviceInfo.isPc&&t&&!this.historyLoading&&this.bus.emit("recordHistory")),s&&this.cursorView(),this.bus.emit("editorChange"),s&&"Write"===s.type&&this.bus.emit(this.isComposition?"updateDialogReact":"matchDialog"),!0},cursorChange_fn=function(t){if(!t){const e=this.chat.getSelection(),i=e.focusNode,s=this.findNode(i);if(!s)return;"Write"===s.type?t={type:s.type,node:s.$el.children[0].childNodes[0],offset:e.focusOffset,instance:s}:"Input"===s.type&&(t={type:s.type,node:s.$el.children[0].children[0].childNodes[0],offset:e.focusOffset,instance:s})}if(t)switch(t.type){case"Write":this.markCursorWrite.node=t.node,this.markCursorWrite.offset=t.offset,this.markCursorWrite.instance=t.instance,this.markLastType="Write";break;case"Input":this.markCursorInput.node=t.node,this.markCursorInput.offset=t.offset,this.markCursorInput.instance=t.instance,this.markLastType="Input"}},ruleMaxLength_fn=function(){const t=this.chat.options.maxLength;if(-1===t)return;let e=0;const i=[];if(this.NODES.forEach((t,s)=>{let n=0;n=s>0&&1===t.children.length&&0===t.children[0].text.length?1:t.$el.textContent.replace(new RegExp("\ufeff","ig"),"").length,i.push(n),e+=n}),e>t){const s=e-t;let n=0,a=0;for(let t=i.length-1;t>=0;t--)if(n+=i[t],n>=s){a=t;break}this.NODES.slice(a+1).forEach(t=>{t.deleteNode()});let o=n-s;const c=this.NODES[a];if(0===o&&a>0){c.deleteNode();const e=this.NODES[a-1];return e.children[e.children.length-1].focus(-1),void(this.textLength=t)}let h=null,l=0;for(let t=0;t<c.children.length;t++){const e=c.children[t];if("Write"===e.type?o-=e.text.length:o-=e.$el.textContent.length,o<=0){h=e,l=t;break}}if(c.children.slice(l+1).forEach(t=>{t.deleteNode()}),"Write"===h.type){const e=h;e.text=e.text.slice(0,e.text.length-Math.abs(o)),e.syncNode(),e.updateNode(),e.focus(-1),this.textLength=t}else{const e=c.children[l-1];h.deleteNode(),e.ruleBRTag(),e.focus(-1),this.textLength=t-Math.abs(o)}}else this.textLength=e};class Bus{constructor(){__privateAdd(this,_handles),__privateAdd(this,_eventMapKey),__privateSet(this,_handles,Object.create(null)),__privateSet(this,_eventMapKey,Object.create(null))}on(t,e,i){__privateGet(this,_handles)[e]||(__privateGet(this,_handles)[e]=Object.create(null)),__privateGet(this,_eventMapKey)[t]||(__privateGet(this,_eventMapKey)[t]=[]),__privateGet(this,_eventMapKey)[t].push(e),__privateGet(this,_handles)[e][t]=i}emit(...t){const e=t[0],i=t.slice(1),s=__privateGet(this,_handles)[e];if(s)for(const t in s)s[t](...i)}off(t,e){for(const i in __privateGet(this,_handles)[e])i+""==t+""&&delete __privateGet(this,_handles)[e][t];0===Object.keys(__privateGet(this,_handles)[e]).length&&delete __privateGet(this,_handles)[e]}offKeyEvent(t){(__privateGet(this,_eventMapKey)[t]||[]).forEach(e=>{this.off(t,e)}),delete __privateGet(this,_eventMapKey)[t]}}_handles=new WeakMap,_eventMapKey=new WeakMap;class Component extends Tag{constructor(t){var e;super(t.type,t.context),__privateAdd(this,_Component_instances),__publicField(this,"data",{}),__privateAdd(this,_syncElms,{}),this.data=t.data||{},this.$el=document.createElement("span"),this.$el.setAttribute("data-set-richType",RICH_COMPONENT),this.$el.setAttribute("contenteditable","false"),this.$el.classList.add("chat-tag-wrap"),this.$el.innerHTML=this.render(),__privateMethod(this,_Component_instances,findEventNodes_fn).call(this,this.$el),this.mount({parentElm:(null==(e=t.config)?void 0:e.parentElm)||this.context.$el,targetElm:this.$el,...t.config||{}})}remove(){this.deleteRelevanceNode(),__privateMethod(this,_Component_instances,emit_fn4).call(this,"richTextChange")}render(){return"undefined"}}_syncElms=new WeakMap,_Component_instances=new WeakSet,emit_fn4=function(t,...e){this.context.context.bus.emit(t,...e)},findEventNodes_fn=function(t,e=""){Array.from(t.children,(t,i)=>{const s=String(""===e?i:e+"-"+i);t.children&&t.children.length>0&&__privateMethod(this,_Component_instances,findEventNodes_fn).call(this,t,s);const n=t,a=n.dataset||{};if(a){a.update&&(__privateGet(this,_syncElms)[s]=n,n.removeAttribute("data-update"),delete a.update);for(const t in a){const e=a[t];n.addEventListener(t,t=>{const i=this[e](t);i instanceof Promise?i.then(()=>{__privateMethod(this,_Component_instances,syncNode_fn).call(this)}):__privateMethod(this,_Component_instances,syncNode_fn).call(this)}),n.removeAttribute("data-"+t)}}})},syncNode_fn=function(){const t=document.createElement("span");t.innerHTML=this.render();for(let e in __privateGet(this,_syncElms)){const i=e.split("-");__privateGet(this,_syncElms)[e].innerHTML=__privateMethod(this,_Component_instances,getChainElm_fn).call(this,t,i)}},getChainElm_fn=function(t,e){return 1===e.length?t.children[Number(e[0])].innerHTML:__privateMethod(this,_Component_instances,getChainElm_fn).call(this,t.children[Number(e[0])],e.slice(1))};class XSender{constructor(t,e){switch(__publicField(this,"options"),__publicField(this,"deviceInfo",os()),__publicField(this,"chatElement"),__publicField(this,"chatEditor"),__publicField(this,"bus"),this.options=Object.assign({},DEFAULT_OPTIONS,e||{},{mentionConfig:void 0}),this.deviceInfo.isTablet&&(this.deviceInfo.isPc=!1),this.options.device){case"pc":this.deviceInfo.isPc=!0;break;case"h5":this.deviceInfo.isPc=!1}this.bus=new Bus,this.chatElement=new ChatElement(t,this),this.chatEditor=new ChatEditor(this),this.updateConfig(e)}updateConfig(t){unEmpty(t.placeholder)&&this.chatElement.updatePlaceholder(t.placeholder),unEmpty(t.chatStyle)&&this.chatElement.updateChatStyle(t.chatStyle),unEmpty(t.maxLength)&&(this.options.maxLength=t.maxLength<=0?-1:t.maxLength,this.bus.emit("ruleMaxLength")),unEmpty(t.keyboardWrapFun)&&(this.options.keyboardWrapFun=t.keyboardWrapFun),unEmpty(t.keyboardSendFun)&&(this.options.keyboardSendFun=t.keyboardSendFun),unEmpty(t.mentionConfig)&&(this.options.mentionConfig=Object.assign({},this.options.mentionConfig||DEFAULT_MENTION_OPTIONS,t.mentionConfig),this.chatElement.createMentionDialog()),unEmpty(t.triggerConfig)&&(this.options.triggerConfig=t.triggerConfig.map(t=>(t.keyMap||(t.keyMap=KEY_CODE_MAP[t.key]||[]),t)),this.chatElement.createTriggerDialog()),unEmpty(t.selectConfig)&&(this.options.selectConfig=t.selectConfig,this.chatElement.createSelectDialog()),unEmpty(t.tipConfig)&&(this.options.tipConfig=Object.assign({},DEFAULT_TIP_OPTIONS,t.tipConfig),this.chatElement.createBeforeTip())}async nextTick(t){return new Promise(e=>{requestAnimationFrame(()=>{if(!t)return void e();const i=t();i instanceof Promise?i.then(()=>{e()}):e()})})}getSelection(){return window.getSelection()}getModel(){return this.chatEditor.compileNodes(this.chatEditor.NODES)}getHtml(t){const e=Object.assign({},{saveTagData:!1,identifyLink:!1},t||{}),i=/(https?|http|ftp|file):\/\/[-A-Za-z0-9+&@#/%?=~_|!:,.;]+[-A-Za-z0-9+&@#/%=~_|]/g,s=this.getModel();let n="",a="";return s.forEach((t,s)=>{let o='<p class="chat-tag-grid">';t.forEach((t,n)=>{let c="<span ";switch(t.type){case"Mention":c+='class="chat-tag-mention"',e.saveTagData&&(c+=` data-id="${t.id}"`),c+=`>@${escapeHtml(t.name)}`;break;case"Trigger":c+='class="chat-tag-trigger"',e.saveTagData&&(c+=` data-id="${t.id}" data-key=${t.key}`),c+=`>${t.key}${escapeHtml(t.name)}`;break;case"Select":c+='class="chat-tag-select"',e.saveTagData&&(c+=` data-id="${t.id}" data-key=${t.key}`),c+=`>${escapeHtml(t.name)}`;break;case"Input":c+='class="chat-tag-input"',e.saveTagData&&(c+=` data-placeholder="${t.placeholder}" data-key=${t.key}`),c+=`>${escapeHtml(t.text||t.placeholder)}`;break;case"Custom":c+='class="chat-tag-custom"',c+=`>${t.html}`;break;case"Write":c+='class="chat-tag-write"',a=escapeHtml(t.text),e.identifyLink?c+=`>${a.replace(i,t=>`<a class="chat-tag-link" href="${t}" target="_blank">${t}</a>`)}`:c+=`>${a}`;break;default:const o=this.chatEditor.NODES[s].children[n];if(c+='class="chat-tag-component"',e.saveTagData){for(const t in o.data)c+=` data-${t}="${o.data[t]}"`;c+=` data-type="${o.type}"`}c+=`>${o.$el.innerHTML}`}c+="</span>",o+=c}),o+="</p>",n+=o}),n}getText(){let t="";return this.getModel().forEach((e,i)=>{0!==i&&(t+="\n"),e.forEach((e,s)=>{switch(e.type){case"Write":t+=e.text;break;case"Input":t+=e.text||`[${e.placeholder}]`;break;default:t+=this.chatEditor.NODES[i].children[s].$el.textContent||""}})}),t.replace(new RegExp(`\ufeff|${"\n"[0]}`,"ig"),"")}getTagData(){const t={mention:[],trigger:{},select:{},input:{}},e={mention:new Map,trigger:{},select:{}};return this.getModel().forEach(i=>{i.forEach(i=>{switch(i.type){case"Mention":e.mention.set(i.id,{id:i.id,name:i.name});break;case"Trigger":e.trigger[i.key]||(e.trigger[i.key]=new Map),e.trigger[i.key].set(i.id,{id:i.id,name:i.name});break;case"Select":e.select[i.key]||(e.select[i.key]=new Map),i.id&&i.id.split(",").length>0?i.id.split(",").forEach((t,s)=>{e.select[i.key].set(t,{id:t,name:i.name.split("、")[s]})}):e.select[i.key].set(i.id,{id:i.id,name:i.name});break;case"Input":t.input[i.key]||(t.input[i.key]=[]),t.input[i.key].push({text:i.text||"",placeholder:i.placeholder||""})}})}),t.mention=Array.from(e.mention.values()),Object.keys(e.trigger).forEach(i=>{t.trigger[i]=Array.from(e.trigger[i].values())}),Object.keys(e.select).forEach(i=>{t.select[i]=Array.from(e.select[i].values())}),t}setLineBreak(){return new Promise(t=>{this.bus.emit("lineBreak",t)})}async setHtml(t){await this.chatEditor.insertCustom({html:`<span style="display: inline-block;">${replaceBlockTagsWithSpan(t)}</span>`})}async setText(t){switch(this.chatEditor.markLastType){case"Write":await this.chatEditor.insertText(t);break;case"Input":await this.chatEditor.insertInputText(t)}}async setMention(t){await this.chatEditor.insertMention(t)}async setTrigger(t){await this.chatEditor.insertTrigger(t)}async setSelect(t){await this.chatEditor.insertSelect(t)}async setInput(t){await this.chatEditor.insertInput(t)}async setChatNode(t){await this.chatEditor.insertNodes(t)}removeMention(t){return new Promise(e=>{const i=[];this.chatEditor.NODES.forEach(e=>{e.children.forEach(e=>{const s=e;"Mention"!==s.type||t&&!t.includes(s.id)||i.push(s)})}),i.forEach(t=>{t.deleteRelevanceNode()}),this.bus.emit("richTextChange",e)})}removeTrigger(t,e){return new Promise(i=>{const s=[];this.chatEditor.NODES.forEach(i=>{i.children.forEach(i=>{const n=i;"Trigger"!==n.type||n.key!==t||e&&!e.includes(n.id)||s.push(n)})}),s.forEach(t=>{t.deleteRelevanceNode()}),this.bus.emit("richTextChange",i)})}removeSelect(t,e){return new Promise(i=>{const s=[];this.chatEditor.NODES.forEach(i=>{i.children.forEach(i=>{const n=i;"Select"!==n.type||n.key!==t||e&&!e.includes(n.id)||s.push(n)})}),s.forEach(t=>{t.deleteRelevanceNode()}),this.bus.emit("richTextChange",i)})}removeInput(t){return new Promise(e=>{const i=[];this.chatEditor.NODES.forEach(e=>{e.children.forEach(e=>{const s=e;"Input"===s.type&&s.key===t&&i.push(s)})}),i.forEach(t=>{t.deleteRelevanceTag()}),this.bus.emit("richTextChange",e)})}async reverseHtml(t,e=!1){let i=document.createElement("div");i.innerHTML=t;const s=[];Array.from(i.children,t=>{const e=[];Array.from(t.children,t=>{const i=t;switch(i.className){case"chat-tag-write":e.push({type:"Write",text:i.textContent});break;case"chat-tag-mention":e.push({type:"Mention",id:i.dataset.id||"",name:(i.textContent||"").slice(1)});break;case"chat-tag-trigger":e.push({type:"Trigger",key:i.dataset.key||"",id:i.dataset.id||"",name:(i.textContent||"").slice(1)});break;case"chat-tag-select":e.push({type:"Select",key:i.dataset.key||"",id:i.dataset.id||"",name:i.textContent});break;case"chat-tag-input":e.push({type:"Input",key:i.dataset.key||"",text:i.textContent,placeholder:i.dataset.placeholder||""});break;case"chat-tag-custom":e.push({type:"Custom",html:i.innerHTML});break;case"chat-tag-component":const t=i.dataset.type,s=i.dataset;"type"in s&&delete s.type,e.push({type:t,data:s})}}),s.push(e)}),e?(this.chatEditor.focusLast(),await this.chatEditor.insertNodes(s)):await this.chatEditor.fixEditor(s)}undo(){return new Promise(t=>{this.bus.emit("undo",t)})}redo(){return new Promise(t=>{this.bus.emit("redo",t)})}jumpPrev(t="end"){this.bus.emit("cursorChange");const e="Write"===this.chatEditor.markLastType?this.chatEditor.markCursorWrite.instance:this.chatEditor.markCursorInput.instance,i=e.context,s=i.children.indexOf(e),n=[...i.children.slice(0,s)].reverse().find(t=>"Write"===t.type||"Input"===t.type);if(n)return void n.focus("start"===t?0:-1);const a=i.context.NODES.indexOf(i);let o;[...this.chatEditor.NODES.slice(0,a)].reverse().some(t=>[...t.children].reverse().some(t=>{if("Write"===t.type||"Input"===t.type)return o=t,!0})),o?o.focus("start"===t?0:-1):this.focus("first")}jumpNext(t="end"){this.bus.emit("cursorChange");const e="Write"===this.chatEditor.markLastType?this.chatEditor.markCursorWrite.instance:this.chatEditor.markCursorInput.instance,i=e.context,s=i.children.indexOf(e),n=i.children.slice(s+1).find(t=>"Write"===t.type||"Input"===t.type);if(n)return void n.focus("start"===t?0:-1);const a=i.context.NODES.indexOf(i);let o;this.chatEditor.NODES.slice(a+1).some(t=>t.children.some(t=>{if("Write"===t.type||"Input"===t.type)return o=t,!0})),o?o.focus("start"===t?0:-1):this.focus("last")}move(t){this.chatEditor.focusMark(),0!==t&&this.chatEditor.cursorMove(t)}backspace(t){return new Promise(e=>{if(this.chatEditor.focusMark(),0===t)return e();if(-1===t||1===t)return void this.bus.emit("richTextDelete",t>0,e);const i=this.getSelection(),s=i.focusNode,n=i.focusOffset;this.chatEditor.cursorMove(t);const a=this.getSelection(),o=a.focusNode,c=a.focusOffset,h=new Range,l=t<0;l?(h.setStart(o,c),h.setEnd(s,n)):(h.setStart(s,n),h.setEnd(o,c)),a.removeAllRanges(),a.addRange(h),this.bus.emit("richTextDelete",!l,e)})}focus(t="last"){this.bus.emit("focus",t)}disable(){this.chatElement.richText.setAttribute("contenteditable","false"),this.chatElement.rollBox.classList.add("disabled")}enable(){this.chatElement.richText.setAttribute("contenteditable","true"),this.chatElement.rollBox.classList.remove("disabled"),this.focus()}async reset(t){const e=Object.assign({},{clearHistory:!0,chatNode:[[{type:"Write",text:""}]]},t||{});await this.chatEditor.reset(e)}isEmpty(t=!0){if(t)return 0===this.getText().trim().length;const e=this.chatEditor.NODES;return!(e.length>1)&&(!(e[0].children.length>1)&&e[0].children[0].text.length<=0)}destroy(){this.bus.emit("destroy");for(const t in this)delete this[t];Object.setPrototypeOf(this,Object.create(null))}showSelectPopup(t,e){this.bus.emit("activeSelect",{key:t,$el:e})}showTip(t){this.bus.emit("openTip",t)}closeTip(){this.bus.emit("closeTip")}getCurrentNode(){switch(this.chatEditor.markLastType){case"Input":return this.chatEditor.markCursorInput;case"Write":return this.chatEditor.markCursorWrite}}useComponent(t,e){this.chatEditor.useComponent(t,e)}async setComponent(t,e){await this.chatEditor.insertComponent(t,e)}}__publicField(XSender,"version","1.2.6"),__publicField(XSender,"Component",Component);export{XSender as default};
|
|
1
|
+
var _Events,_MentionDialog_instances,registerBus_fn,registerEvent_fn,createDialog_fn,_Events2,_TriggerDialog_instances,registerBus_fn2,registerEvent_fn2,createDialog_fn2,_Events3,_SelectDialog_instances,registerBus_fn3,registerEvent_fn3,createDialog_fn3,_Events4,_BeforeTip_instances,registerBus_fn4,registerEvent_fn4,createTip_fn,update_fn,_ChatElement_instances,registerBus_fn5,createRichText_fn,createPlaceholder_fn,createDialogRoot_fn,switchPlaceholder_fn,_Write_instances,emit_fn,_Select_instances,emit_fn2,_Input_instances,emit_fn3,_disabledEvent,_Events5,_ChatEditor_instances,registerBus_fn6,registerEvent_fn5,richTextDelete_fn,richTextWrap_fn,richTextCopy_fn,richTextPaste_fn,recordHistory_fn,richTextUndo_fn,richTextRedo_fn,renderHistory_fn,richTextChange_fn,cursorChange_fn,ruleMaxLength_fn,_handles,_eventMapKey,_syncElms,_Component_instances,emit_fn4,findEventNodes_fn,syncNode_fn,getChainElm_fn,__defProp=Object.defineProperty,__typeError=t=>{throw TypeError(t)},__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),__accessCheck=(t,e,i)=>e.has(t)||__typeError("Cannot "+i),__privateGet=(t,e,i)=>(__accessCheck(t,e,"read from private field"),i?i.call(t):e.get(t)),__privateAdd=(t,e,i)=>e.has(t)?__typeError("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(t):e.set(t,i),__privateSet=(t,e,i,s)=>(__accessCheck(t,e,"write to private field"),s?s.call(t,i):e.set(t,i),i),__privateMethod=(t,e,i)=>(__accessCheck(t,e,"access private method"),i);const 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>',DEFAULT_OPTIONS={device:"auto",autoFocus:!0,placeholder:"",maxLength:-1,keyboardWrapFun:t=>t.ctrlKey&&["Enter"].includes(t.key),keyboardSendFun:t=>!t.ctrlKey&&["Enter"].includes(t.key)},DEFAULT_MENTION_OPTIONS={dialogTitle:"群成员",callEvery:!0,everyText:"所有人",asyncMatch:void 0,emptyText:"暂无数据",options:[]},KEY_CODE_MAP={"`":["`","~"],"~":["`","~"],1:["1","!"],"!":["1","!"],3:["3","#"],"#":["3","#"],4:["4","$"],$:["4","$"],5:["5","%"],"%":["5","%"],6:["6","^"],"^":["6","^"],7:["7","&"],"&":["7","&"],8:["8","*"],"*":["8","*"],";":[";",":"],":":[";",":"],"/":["/","?"],"?":["/","?"],"\\":["\\","|"],"|":["\\","|"]},DEFAULT_TIP_OPTIONS={tipTemplate:'<div class="chat-before-tip-box">{{text}}</div><div class="chat-before-tip-close">'+closeSvg+"</div>",dialogTemplate:'<div class="chat-tip-dialog-main"><span>{{dialogText}}</span><span class="chat-tip-dialog-code">ESC</span></div><div class="chat-tip-dialog-arrow"></div>',closeNames:["chat-before-tip-box","chat-before-tip-close"],offsetTop:0},EVENT_COMMON_SEND=Symbol("EVENT_COMMON_SEND"),EVENT_COMMON_CHANGE=Symbol("EVENT_COMMON_CHANGE"),EVENT_COMMON_DESTROY=Symbol("EVENT_COMMON_DESTROY"),EVENT_COMMON_TIP_STATE=Symbol("EVENT_COMMON_TIP_STATE"),EVENT_COMMON_DIALOG_CLOSE=Symbol("EVENT_COMMON_DIALOG_CLOSE"),EVENT_COMMON_SELECT_ACTIVE=Symbol("EVENT_COMMON_SELECT_ACTIVE"),EVENT_EDITOR_CHANGE=Symbol("EVENT_EDITOR_CHANGE"),EVENT_EDITOR_DELETE=Symbol("EVENT_EDITOR_DELETE"),EVENT_EDITOR_CURSOR_CHANGE=Symbol("EVENT_EDITOR_CURSOR_CHANGE"),EVENT_EDITOR_LINE_BREAK=Symbol("EVENT_EDITOR_LINE_BREAK"),EVENT_EDITOR_UNDO=Symbol("EVENT_EDITOR_UNDO"),EVENT_EDITOR_REDO=Symbol("EVENT_EDITOR_REDO"),EVENT_EDITOR_HISTORY=Symbol("EVENT_EDITOR_HISTORY"),EVENT_EDITOR_MAXLENGTH=Symbol("EVENT_EDITOR_MAXLENGTH"),EVENT_EDITOR_SWITCH_DISABLED=Symbol("EVENT_EDITOR_SWITCH_DISABLED"),EVENT_EDITOR_INSERT_MENTION=Symbol("EVENT_EDITOR_INSERT_MENTION"),EVENT_EDITOR_INSERT_TRIGGER=Symbol("EVENT_EDITOR_INSERT_TRIGGER"),EVENT_EDITOR_INSERT_SELECT=Symbol("EVENT_EDITOR_INSERT_SELECT"),EVENT_EDITOR_INSERT_INPUT=Symbol("EVENT_EDITOR_INSERT_INPUT"),EVENT_EDITOR_INSERT_CUSTOM=Symbol("EVENT_EDITOR_INSERT_CUSTOM"),EVENT_EDITOR_FOCUS=Symbol("EVENT_EDITOR_FOCUS"),EVENT_TIP_OPEN=Symbol("EVENT_TIP_OPEN"),EVENT_TIP_CLOSE=Symbol("EVENT_TIP_CLOSE"),EVENT_DIALOG_MATCH=Symbol("EVENT_DIALOG_MATCH"),EVENT_DIALOG_UPDATE_REACT=Symbol("EVENT_DIALOG_UPDATE_REACT"),EVENT_DIALOG_KEYBOARD_MOVE=Symbol("EVENT_DIALOG_KEYBOARD_MOVE"),ELEMENT_EMPTY_KEY="data-set-empty",ELEMENT_RICH_TYPE_KEY="data-set-richType",RICH_WRAP="richWrap",RICH_GRID="richGrid",RICH_MARK="richMark",RICH_WRITE="richWrite",RICH_MENTION="richMention",RICH_TRIGGER="richTrigger",RICH_SELECT="richSelect",RICH_INPUT="richInput",RICH_CUSTOM="richCustom",RICH_COMPONENT="richComponent",CHAT_COPY_KEY="application/chat-nodes",VOID_KEY="\ufeff",WRAP_KEY="\n",debounce=(t,e,i=!1)=>{let s;return function(...n){const o=this,a=i&&!s;clearTimeout(s),s=setTimeout(()=>{s=null,i||t.apply(o,n)},e),a&&t.apply(o,n)}},throttle=(t,e)=>{let i;return function(...s){const n=this;i||(t.apply(n,s),i=!0,setTimeout(function(){i=!1},e))}},unEmpty=t=>null!=t,replaceTemplate=(t,e)=>t.replace(/{{(\w+)}}/g,(t,i)=>void 0!==e[i]?e[i]:t);function escapeHtml(t){return t.replace(/[&<>"']/g,t=>{switch(t){case"&":return"&";case"<":return"<";case">":return">";case'"':return""";case"'":return"'";default:return t}})}const replaceBlockTagsWithSpan=t=>{const e=["address","article","aside","blockquote","canvas","dd","div","dl","dt","fieldset","figcaption","figure","footer","form","h1","h2","h3","h4","h5","h6","header","hgroup","hr","li","main","nav","noscript","ol","output","p","pre","section","table","tfoot","ul"],i=new RegExp(`<(${e.join("|")})([^>]*?)>`,"gi"),s=new RegExp(`</(${e.join("|")})>`,"gi");let n=t.replace(i,(t,e,i)=>{let s="",n="";if(i){const t=i.match(/style\s*=\s*["']([^"']*)["']/i);if(t){const e=t[1];s=e.match(/display\s*:/i)?`style="${e.replace(/display\s*:.*?;/gi,"display:block;")}"`:`style="display:block;${e}"`,n=i.replace(/style\s*=\s*["']([^"']*)["']/i,"").trim()}else s='style="display:block"',n=i.trim()}else s='style="display:block"';return`<span ${[n,s].filter(Boolean).join(" ")}>`.replace(/\s+/g," ").replace(/ >/,">")});return n=n.replace(s,"</span>"),n};function isKeyType(t,e){switch(e){case"text-jump":return"Tab"===t.key||"Tab"===t.code;case"text-backspace":return"Backspace"===t.key||"Backspace"===t.code;case"text-delete":return"Delete"===t.code||"Delete"===t.key;case"text-move":return"ArrowLeft"===t.key||"ArrowRight"===t.key||"ArrowLeft"===t.code||"ArrowRight"===t.code;case"text-updown":return"ArrowUp"===t.key||"ArrowDown"===t.key||"ArrowUp"===t.code||"ArrowDown"===t.code;case"text-select-all":return(t.ctrlKey||t.metaKey)&&("A"===t.key||"a"===t.key||"KeyA"===t.code);case"text-undo":return(t.ctrlKey||t.metaKey)&&("Z"===t.key||"z"===t.key||"KeyZ"===t.code);case"text-redo":return(t.ctrlKey||t.metaKey)&&("Y"===t.key||"y"===t.key||"KeyY"===t.code);case"text-write":return t.isComposing||!t.ctrlKey&&!t.altKey&&!t.metaKey&&!["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;case"IME":return"Unidentified"===t.key||229===t.keyCode;default:return!1}}function pinyinMatch(t,e,i){const s=e.split(/\s+/),n=t.split("").map((t,i)=>{let n=s[i]||"";return""===e&&""===n&&(n=t),{char:t,pinyin:n.toLowerCase(),initial:n?n[0].toLowerCase():""}}),o=(t=>{const e=[];let i="";for(const s of t)/[a-zA-Z]/.test(s)?i+=s.toLowerCase():(i&&(e.push({type:"pinyin",value:i}),i=""),e.push({type:"char",value:s}));return i&&e.push({type:"pinyin",value:i}),e})(i),a=n.length,c=o.length,h=Array.from({length:a+1},()=>Array(c+1).fill(!1));h[0][0]=!0;for(let t=0;t<=a;t++)for(let e=0;e<=c;e++)if(h[t][e]&&e<c){const i=o[e];for(let s=t;s<a;s++){const t=n[s];if("char"===i.type)t.char===i.value&&(h[s+1][e+1]=!0);else{const o=t.pinyin.toLowerCase(),c=t.initial,l=i.value;if(l===c)h[s+1][e+1]=!0;else if(l===o)h[s+1][e+1]=!0;else if(isSubsequence(l,o))h[s+1][e+1]=!0;else for(let t=2;t<=a-s;t++){const i=n.slice(s,s+t),o=i.map(t=>t.pinyin.toLowerCase()).join(""),a=i.map(t=>t.initial).join("");if(l===o||l===a||isSubsequence(l,o)){h[s+t][e+1]=!0;break}}}}}for(let t=0;t<=a;t++)if(h[t][c])return!0;return!1}function isSubsequence(t,e){let i=0,s=0;for(;i<t.length&&s<e.length;)t[i]===e[s]&&i++,s++;return i===t.length}function os(){if("undefined"==typeof navigator)return{isTablet:!1,isPhone:!1,isAndroid:!1,isIOS:!1,isPc:!0,isIPhone:!1,isIPad:!1,isWindows:!1,isMacOS:!1,isLinux:!1,isWechat:!1,isMobile:!1};const t=navigator.userAgent.toLowerCase(),e=t.includes("windows"),i=t.includes("macintosh"),s=t.includes("linux")&&!t.includes("android"),n=t.includes("android"),o=/iphone|ipad|ipod/.test(t),a=t.includes("iphone"),c=t.includes("ipad")||t.includes("macintosh")&&navigator.maxTouchPoints>1,h=t.includes("micromessenger"),l=c||n&&!/mobile/.test(t)||t.includes("firefox")&&t.includes("tablet")||t.includes("playbook"),r=a&&!l||n&&/mobile/.test(t)||t.includes("windows phone");return{isTablet:l,isPhone:r,isAndroid:n,isIOS:o,isPc:!r&&!l&&(e||i||s),isIPhone:a,isIPad:c,isWindows:e,isMacOS:i,isLinux:s,isWechat:h,isMobile:r||l}}function switchDisplay(t,e=!0,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 isShow(t){return t&&t.classList.contains("chat-view-show")}class MentionDialog{constructor(t,e){__privateAdd(this,_MentionDialog_instances),__publicField(this,"eventKey",Symbol("MentionDialog")),__publicField(this,"chatElement"),__publicField(this,"bus"),__publicField(this,"dialog"),__publicField(this,"activeMention",null),__publicField(this,"title",""),__publicField(this,"callEvery",!0),__publicField(this,"everyText",""),__publicField(this,"emptyText",""),__publicField(this,"options",[]),__publicField(this,"asyncMatch"),__publicField(this,"matchKey",0),__privateAdd(this,_Events,[]),this.dialog=document.createElement("div"),this.chatElement=t,this.bus=this.chatElement.chat.bus,__privateMethod(this,_MentionDialog_instances,registerBus_fn).call(this),__privateMethod(this,_MentionDialog_instances,registerEvent_fn).call(this),__privateMethod(this,_MentionDialog_instances,createDialog_fn).call(this),this.updateConfig(e)}updateConfig(t){this.asyncMatch=t.asyncMatch,this.title=t.dialogTitle,this.emptyText=t.emptyText,this.everyText=t.everyText,this.callEvery=!this.asyncMatch&&t.callEvery,this.options=this.asyncMatch?[]:t.options,this.updateRender()}updateRender(){this.dialog.children[0].textContent=this.title,this.dialog.children[2].innerHTML=`${matchEmptySvg}<span class="empty-label">${this.emptyText}</span>`;const t=this.dialog.children[1];t.innerHTML="";const e=document.createDocumentFragment();this.callEvery&&e.appendChild(this.getRenderMention({id:"ALL",name:this.everyText})),this.options.forEach(t=>{e.appendChild(this.getRenderMention(t))}),t.appendChild(e)}getRenderMention(t){const e=document.createElement("div");e.setAttribute("data-id",t.id),e.setAttribute("data-name",t.name),e.classList.add("chat-mention-dialog-item"),switchDisplay(e,!0,"flex");const i=document.createElement("div");if(i.classList.add("chat-mention-dialog-item-avatar"),t.avatar){i.classList.add("have-avatar");const e=document.createElement("div");e.classList.add("chat-mention-dialog-item-avatar-loading"),e.innerHTML=antdLoading,i.appendChild(e);const s=new Image;s.alt="",s.src=t.avatar,s.onload=()=>{i.removeChild(e),i.appendChild(s)}}else{const e=document.createElement("span");e.textContent="ALL"===t.id?"@":t.name.slice(-2),e.classList.add("chat-mention-dialog-item-avatar-text"),i.appendChild(e)}e.appendChild(i);const s=document.createElement("div");return s.classList.add("chat-mention-dialog-item-name"),s.textContent=t.name,e.appendChild(s),e.addEventListener("click",t=>{t.stopPropagation();const i=this.chatElement.chat.chatEditor.markCursorWrite,s=i.node.textContent.slice(0,i.offset).lastIndexOf("@"),n=i.offset-s;this.bus.emit(EVENT_EDITOR_INSERT_MENTION,{id:e.getAttribute("data-id"),name:e.getAttribute("data-name"),del:n>0?n:0}),this.closeDialog()}),e}openDialog(t){if(isShow(this.dialog)||this.bus.emit(EVENT_COMMON_DIALOG_CLOSE),this.asyncMatch){this.options=[],this.updateRender();const t=this.dialog.children[2],e=this.dialog.children[3];switchDisplay(t,!1),switchDisplay(e,!0,"flex"),switchDisplay(this.dialog),this.moveDialog(),this.bus.emit(EVENT_EDITOR_SWITCH_DISABLED,!0)}else if(this.options.length>0){const e=this.dialog.children[1];let i;e.scrollTop=0;const s=(t||this.pinyinMatchDialog()).map(t=>t.id);Array.from(e.children,t=>{const e=t.getAttribute("data-id");s.includes(e)?(switchDisplay(t,!0,"flex"),i||(i=t)):switchDisplay(t,!1)}),this.switchActiveMention(i||e.children[0]),switchDisplay(this.dialog),this.moveDialog(),this.bus.emit(EVENT_EDITOR_SWITCH_DISABLED,!0)}}closeDialog(){isShow(this.dialog)&&(switchDisplay(this.dialog,!1),this.switchActiveMention(),this.bus.emit(EVENT_EDITOR_SWITCH_DISABLED,!1))}moveDialog(){const t=this.chatElement.chat.getSelection().getRangeAt(0).getBoundingClientRect(),e=this.chatElement.dialogRoot.getBoundingClientRect();let i="0",s="100%",n=t.x-e.x,o=e.y-t.y;const{clientWidth:a,clientHeight:c}=this.dialog;t.x>window.innerWidth-a-30&&(n=t.x-a-e.x-16,i="100%"),t.y<c&&(o-=c,s="0"),this.dialog.style.transform="translate(0, 0)",this.dialog.style.transformOrigin=`${i} ${s}`,this.dialog.style.left=n+6+"px",this.dialog.style.bottom=`${o}px`,this.dialog.style.opacity="1"}moveActiveMention(t){const e=this.dialog.children[1],i=Array.prototype.filter.call(e.children,t=>t.classList.contains("chat-view-show")),s=Array.prototype.indexOf.call(i,this.activeMention);"up"===t?s>0?this.switchActiveMention(i[s-1],!0):this.switchActiveMention(i[i.length-1],!0):"down"===t&&(s<i.length-1?this.switchActiveMention(i[s+1],!0):this.switchActiveMention(i[0],!0))}switchActiveMention(t,e=!1){if(this.activeMention&&this.activeMention.classList.remove("active"),t){if(this.activeMention=t,this.activeMention.classList.add("active"),e){const t=this.dialog.children[1],e=Array.prototype.filter.call(t.children,t=>t.classList.contains("chat-view-show")),i=this.activeMention.clientHeight,s=Array.prototype.indexOf.call(e,this.activeMention)+1-Math.ceil(Math.floor(t.clientHeight/i)/2);t.scrollTop=s>0?s*i:0}}else this.activeMention=null}matchDialog(){const t=this.chatElement.chat.chatEditor.markCursorWrite,e=t.node.textContent.slice(0,t.offset),i=e.lastIndexOf("@");if(-1===i)return void this.closeDialog();const s=e.slice(i+1);if(this.asyncMatch)return void this.asyncMatchDialog(s);const n=this.pinyinMatchDialog(s);n.length>0?this.openDialog(n):this.closeDialog()}pinyinMatchDialog(t){return t?this.options.filter(e=>pinyinMatch(e.name,e.pinyin||"",t)):this.callEvery?[{id:"ALL",name:this.everyText},...this.options]:this.options}async asyncMatchDialog(t=""){this.matchKey++;const e=this.matchKey;if(/\s/gi.test(t))return void this.closeDialog();this.openDialog();const i=await this.asyncMatch(t);if(e===this.matchKey){this.options=i,this.updateRender();const t=this.dialog.children[1],e=this.dialog.children[2],s=this.dialog.children[3];switchDisplay(s,!0,"flex"),t.scrollTop=0,switchDisplay(e,0===this.options.length,"flex"),switchDisplay(s,!1),this.switchActiveMention(t.children[0]),this.moveDialog()}}destroy(){this.bus.offKeyEvent(this.eventKey),this.dialog.parentElement&&this.dialog.parentElement.removeChild(this.dialog),__privateGet(this,_Events).forEach(t=>{const e=t[0],i=t[1];for(const t in i)e.removeEventListener(t,i[t])})}}_Events=new WeakMap,_MentionDialog_instances=new WeakSet,registerBus_fn=function(){this.bus.on(this.eventKey,EVENT_COMMON_DIALOG_CLOSE,()=>{this.closeDialog()}),this.bus.on(this.eventKey,EVENT_DIALOG_KEYBOARD_MOVE,throttle(this.moveActiveMention,120).bind(this)),this.bus.on(this.eventKey,EVENT_DIALOG_MATCH,debounce(this.matchDialog,200).bind(this)),this.bus.on(this.eventKey,EVENT_DIALOG_UPDATE_REACT,debounce(()=>{isShow(this.dialog)&&this.moveDialog()},200)),this.bus.on(this.eventKey,EVENT_COMMON_DESTROY,()=>{this.destroy()})},registerEvent_fn=function(){__privateSet(this,_Events,[[this.chatElement.richText,{keydown:t=>{isShow(this.dialog)&&(isKeyType(t,"dialog-options")?t.preventDefault():isKeyType(t,"text-move")&&this.closeDialog())},keyup:t=>{if(t.stopPropagation(),"@"===t.key||"2"===String(t.key)||isKeyType(t,"IME")){const t=this.chatElement.chat.getSelection(),e=t.focusNode,i=this.chatElement.chat.chatEditor.findNode(e);if(i&&"Write"===i.type){const e=t.focusOffset;"@"===i.text[e-1]&&!this.chatElement.chat.deviceInfo.isPc&&this.openDialog()}}}}],[window,{mousedown:()=>{this.closeDialog()},keydown:t=>{!this.chatElement.chat.chatEditor.isComposition&&isShow(this.dialog)&&isKeyType(t,"dialog-options")&&(t.preventDefault(),"ArrowUp"===t.key||"ArrowUp"===t.code?this.bus.emit(EVENT_DIALOG_KEYBOARD_MOVE,"up"):"ArrowDown"===t.key||"ArrowDown"===t.code?this.bus.emit(EVENT_DIALOG_KEYBOARD_MOVE,"down"):"Enter"!==t.key&&"Enter"!==t.code&&"NumpadEnter"!==t.code||this.activeMention&&this.activeMention.click())}}]]),__privateGet(this,_Events).forEach(t=>{const e=t[0],i=t[1];for(const t in i)e.addEventListener(t,i[t])})},createDialog_fn=function(){this.dialog.classList.add("chat-mention-dialog-wrap"),this.dialog.addEventListener("mousedown",t=>{t.stopPropagation()}),switchDisplay(this.dialog,!1);const t=document.createDocumentFragment(),e=document.createElement("div");e.classList.add("chat-mention-dialog-header"),t.appendChild(e);const i=document.createElement("div");i.classList.add("chat-mention-dialog-main"),i.classList.add("chat-scroll"),t.appendChild(i);const s=document.createElement("div");s.classList.add("chat-mention-dialog-empty"),switchDisplay(s,!1),t.appendChild(s);const n=document.createElement("div");n.classList.add("chat-mention-dialog-loading"),n.innerHTML=antdLoading,switchDisplay(n,!1),t.appendChild(n),this.dialog.appendChild(t),this.chatElement.dialogRoot.appendChild(this.dialog)};class TriggerDialog{constructor(t,e){__privateAdd(this,_TriggerDialog_instances),__publicField(this,"eventKey",""),__publicField(this,"bus"),__publicField(this,"chatElement"),__publicField(this,"dialog"),__publicField(this,"activeTrigger",null),__publicField(this,"title"),__publicField(this,"key"),__publicField(this,"options"),__publicField(this,"keyMap"),__privateAdd(this,_Events2,[]),this.title=e.dialogTitle,this.key=e.key,this.options=e.options,this.keyMap=e.keyMap,this.dialog=document.createElement("div"),this.chatElement=t,this.bus=this.chatElement.chat.bus,__privateMethod(this,_TriggerDialog_instances,registerBus_fn2).call(this),__privateMethod(this,_TriggerDialog_instances,registerEvent_fn2).call(this),__privateMethod(this,_TriggerDialog_instances,createDialog_fn2).call(this)}openDialog(t){if(isShow(this.dialog)||this.bus.emit(EVENT_COMMON_DIALOG_CLOSE),this.options.length>0){const e=this.dialog.children[1];let i;e.scrollTop=0;const s=(t||this.pinyinMatchDialog()).map(t=>t.id);Array.from(e.children,t=>{const e=t.getAttribute("data-id");s.includes(e)?(switchDisplay(t,!0,"flex"),i||(i=t)):switchDisplay(t,!1)}),this.switchActiveTrigger(i||e.children[0]),switchDisplay(this.dialog),this.moveDialog(),this.bus.emit(EVENT_EDITOR_SWITCH_DISABLED,!0)}}closeDialog(){isShow(this.dialog)&&(switchDisplay(this.dialog,!1),this.switchActiveTrigger(),this.bus.emit(EVENT_EDITOR_SWITCH_DISABLED,!1))}moveDialog(){const t=this.chatElement.chat.getSelection().getRangeAt(0).getBoundingClientRect(),e=this.chatElement.dialogRoot.getBoundingClientRect();let i="0",s="100%",n=t.x-e.x,o=e.y-t.y;const{clientWidth:a,clientHeight:c}=this.dialog;t.x>window.innerWidth-a-30&&(n=t.x-a-e.x-16,i="100%"),t.y<c&&(o-=c,s="0"),this.dialog.style.transform="translate(0, 0)",this.dialog.style.transformOrigin=`${i} ${s}`,this.dialog.style.left=n+6+"px",this.dialog.style.bottom=`${o}px`,this.dialog.style.opacity="1"}moveActiveTrigger(t){const e=this.dialog.children[1],i=Array.prototype.filter.call(e.children,t=>t.classList.contains("chat-view-show")),s=Array.prototype.indexOf.call(i,this.activeTrigger);"up"===t?s>0?this.switchActiveTrigger(i[s-1],!0):this.switchActiveTrigger(i[i.length-1],!0):"down"===t&&(s<i.length-1?this.switchActiveTrigger(i[s+1],!0):this.switchActiveTrigger(i[0],!0))}switchActiveTrigger(t,e=!1){if(this.activeTrigger&&this.activeTrigger.classList.remove("active"),t){if(this.activeTrigger=t,this.activeTrigger.classList.add("active"),e){const t=this.dialog.children[1],e=Array.prototype.filter.call(t.children,t=>t.classList.contains("chat-view-show")),i=this.activeTrigger.clientHeight,s=Array.prototype.indexOf.call(e,this.activeTrigger)+1-Math.ceil(Math.floor(t.clientHeight/i)/2);t.scrollTop=s>0?s*i:0}}else this.activeTrigger=null}matchDialog(){const t=this.chatElement.chat.chatEditor.markCursorWrite,e=t.node.textContent.slice(0,t.offset),i=e.lastIndexOf(this.key);if(-1===i)return void this.closeDialog();const s=e.slice(i+1),n=this.pinyinMatchDialog(s);n.length>0?this.openDialog(n):this.closeDialog()}pinyinMatchDialog(t){return t?this.options.filter(e=>pinyinMatch(e.name,e.pinyin||"",t)):this.options}destroy(){this.bus.offKeyEvent(this.eventKey),this.dialog.parentElement&&this.dialog.parentElement.removeChild(this.dialog),__privateGet(this,_Events2).forEach(t=>{const e=t[0],i=t[1];for(const t in i)e.removeEventListener(t,i[t])})}}_Events2=new WeakMap,_TriggerDialog_instances=new WeakSet,registerBus_fn2=function(){this.eventKey=Symbol("TriggerDialog-"+this.key),this.bus.on(this.eventKey,EVENT_COMMON_DIALOG_CLOSE,()=>{this.closeDialog()}),this.bus.on(this.eventKey,EVENT_DIALOG_KEYBOARD_MOVE,throttle(this.moveActiveTrigger,120).bind(this)),this.bus.on(this.eventKey,EVENT_DIALOG_MATCH,debounce(this.matchDialog,200).bind(this)),this.bus.on(this.eventKey,EVENT_DIALOG_UPDATE_REACT,debounce(()=>{isShow(this.dialog)&&this.moveDialog()},200)),this.bus.on(this.eventKey,EVENT_COMMON_DESTROY,()=>{this.destroy()})},registerEvent_fn2=function(){__privateSet(this,_Events2,[[this.chatElement.richText,{keydown:t=>{isShow(this.dialog)&&(isKeyType(t,"dialog-options")?t.preventDefault():isKeyType(t,"text-move")&&this.closeDialog())},keyup:t=>{if(t.stopPropagation(),this.keyMap.includes(String(t.key))||isKeyType(t,"IME")){const t=this.chatElement.chat.getSelection(),e=t.focusNode,i=this.chatElement.chat.chatEditor.findNode(e);if(i&&"Write"===i.type){const e=t.focusOffset;i.text[e-1]===this.key&&!this.chatElement.chat.deviceInfo.isPc&&this.openDialog()}}}}],[window,{mousedown:()=>{this.closeDialog()},keydown:t=>{!this.chatElement.chat.chatEditor.isComposition&&isShow(this.dialog)&&isKeyType(t,"dialog-options")&&(t.preventDefault(),"ArrowUp"===t.key||"ArrowUp"===t.code?this.bus.emit(EVENT_DIALOG_KEYBOARD_MOVE,"up"):"ArrowDown"===t.key||"ArrowDown"===t.code?this.bus.emit(EVENT_DIALOG_KEYBOARD_MOVE,"down"):"Enter"!==t.key&&"Enter"!==t.code&&"NumpadEnter"!==t.code||this.activeTrigger&&this.activeTrigger.click())}}]]),__privateGet(this,_Events2).forEach(t=>{const e=t[0],i=t[1];for(const t in i)e.addEventListener(t,i[t])})},createDialog_fn2=function(){this.dialog.classList.add("chat-trigger-dialog-wrap"),this.dialog.addEventListener("mousedown",t=>{t.stopPropagation()}),switchDisplay(this.dialog,!1);const t=document.createDocumentFragment(),e=document.createElement("div");e.classList.add("chat-trigger-dialog-header"),e.textContent=this.title,t.appendChild(e);const i=document.createElement("div");i.classList.add("chat-trigger-dialog-main"),i.classList.add("chat-scroll"),t.appendChild(i);const s=document.createDocumentFragment();this.options.forEach(t=>{const e=document.createElement("div");e.setAttribute("data-id",t.id),e.setAttribute("data-name",t.name),e.classList.add("chat-trigger-dialog-item"),switchDisplay(e,!0,"flex");const i=document.createElement("div");i.classList.add("chat-trigger-dialog-item-name"),i.textContent=t.name,e.appendChild(i),e.addEventListener("click",t=>{t.stopPropagation();const i=this.chatElement.chat.chatEditor.markCursorWrite,s=i.node.textContent.slice(0,i.offset).lastIndexOf(this.key),n=i.offset-s;this.bus.emit(EVENT_EDITOR_INSERT_TRIGGER,{id:e.getAttribute("data-id"),name:e.getAttribute("data-name"),key:this.key,del:n>0?n:0}),this.closeDialog()}),s.appendChild(e)}),i.appendChild(s),this.dialog.appendChild(t),this.chatElement.dialogRoot.appendChild(this.dialog)};class SelectDialog{constructor(t,e){__privateAdd(this,_SelectDialog_instances),__publicField(this,"eventKey",""),__publicField(this,"chatElement"),__publicField(this,"bus"),__publicField(this,"dialog"),__publicField(this,"title",""),__publicField(this,"key",""),__publicField(this,"multiple",!1),__publicField(this,"emptyText",""),__publicField(this,"showSearch",!1),__publicField(this,"placeholder",""),__publicField(this,"searchEmptyText",""),__publicField(this,"options",[]),__publicField(this,"selectNode",null),__privateAdd(this,_Events3,[]),this.dialog=document.createElement("div"),this.chatElement=t,this.bus=this.chatElement.chat.bus,this.title=e.dialogTitle,this.key=e.key,this.multiple=e.multiple||!1,this.emptyText=e.emptyText||"请选择标签选项",this.placeholder=e.placeholder||"请输入关键字查询",this.searchEmptyText=e.searchEmptyText||"暂无查询结果",this.showSearch=e.showSearch||!1,this.options=e.options,__privateMethod(this,_SelectDialog_instances,registerBus_fn3).call(this),__privateMethod(this,_SelectDialog_instances,registerEvent_fn3).call(this),__privateMethod(this,_SelectDialog_instances,createDialog_fn3).call(this)}openDialog(t){if(isShow(this.dialog)||this.bus.emit(EVENT_COMMON_DIALOG_CLOSE),this.selectNode=t,!this.selectNode)return;if(this.showSearch){const t=this.dialog.children[1];t.children[0].value="",switchDisplay(t.children[1],!1)}switchDisplay(this.dialog);const e=this.dialog.children[this.showSearch?2:1],i=e.children;let s=0,n=!1,o=0;if("Select"===this.selectNode.type){const t=this.selectNode.id,a=(t||"").split(",");this.selectNode.$el.children[0].classList.add("active"),Array.from(i,e=>{switchDisplay(e,!0,"flex");const i=e.lastChild,c=a.length>0?a.some(t=>String(t)===e.getAttribute("data-id")):String(t)===String(e.getAttribute("data-id"));c&&(o=e.clientHeight,n=!0),c||n||(s+=e.clientHeight),switchDisplay(i,c)});const c=s-e.clientHeight/2+o/2;e.scrollTop=n&&c>0?c:0}else e.scrollTop=0,Array.from(i,t=>{switchDisplay(t,!0,"flex");switchDisplay(t.lastChild,!1)});this.bus.emit(EVENT_EDITOR_SWITCH_DISABLED,!0),this.moveDialog()}closeDialog(){if(isShow(this.dialog)){if(switchDisplay(this.dialog,!1),this.selectNode&&"Select"===this.selectNode.type){this.selectNode.$el.children[0].classList.remove("active")}this.bus.emit(EVENT_EDITOR_SWITCH_DISABLED,!1),this.selectNode=null}}moveDialog(){if(!this.selectNode)return;const t=this.selectNode.$el.getClientRects()[0],e=this.dialog.children[this.showSearch?3:2];let i=this.dialog.clientHeight+16;if(i>t.y?(i=-(t.height+16),e.style.top="-16px",e.style.bottom="auto",e.style.transform="rotate(0deg)"):(e.style.transform="rotate(180deg)",e.style.bottom="-16px",e.style.top="auto"),window.innerWidth-t.x<this.dialog.clientWidth){const i=this.dialog.clientWidth-(window.innerWidth-t.x)-10;this.dialog.style.left="auto",this.dialog.style.right="10px",e.style.left="auto",e.style.right=i-16+"px"}else this.dialog.style.left=t.x+"px",this.dialog.style.right="auto",e.style.left="16px",e.style.right="auto";this.dialog.style.top=t.y+"px",this.dialog.style.transform=`translateY(${-i}px)`}destroy(){this.bus.offKeyEvent(this.eventKey),this.dialog.parentElement&&this.dialog.parentElement.removeChild(this.dialog),__privateGet(this,_Events3).forEach(t=>{const e=t[0],i=t[1];for(const t in i)e.removeEventListener(t,i[t])})}}_Events3=new WeakMap,_SelectDialog_instances=new WeakSet,registerBus_fn3=function(){this.eventKey=Symbol("SelectDialog-"+this.key),this.bus.on(this.eventKey,EVENT_COMMON_SELECT_ACTIVE,t=>{t.key===this.key&&this.chatElement.chat.nextTick(()=>{this.openDialog(t)})}),this.bus.on(this.eventKey,EVENT_COMMON_DIALOG_CLOSE,()=>{this.closeDialog()}),this.bus.on(this.eventKey,EVENT_COMMON_DESTROY,()=>{this.destroy()})},registerEvent_fn3=function(){__privateSet(this,_Events3,[[window,{mousedown:()=>{this.closeDialog()}}]]),__privateGet(this,_Events3).forEach(t=>{const e=t[0],i=t[1];for(const t in i)e.addEventListener(t,i[t])})},createDialog_fn3=function(){this.dialog.classList.add("chat-select-dialog-wrap"),this.dialog.addEventListener("mousedown",t=>{t.stopPropagation()}),switchDisplay(this.dialog,!1);const t=document.createDocumentFragment(),e=document.createElement("div");e.classList.add("chat-select-dialog-header");const i=document.createElement("span");if(i.textContent=this.title,e.appendChild(i),t.appendChild(e),this.showSearch){const e=document.createElement("div");e.classList.add("chat-select-dialog-search");const i=document.createElement("input");i.classList.add("chat-select-dialog-search-input"),i.setAttribute("placeholder",this.placeholder),i.addEventListener("input",debounce(t=>{t.stopPropagation();const e=t.target.value||"",i=this.dialog.children[1].children[1],s=this.dialog.children[2].children;let n=!0;Array.from(s,t=>{const i=t.getAttribute("data-name")||"";""===e||-1!==i.indexOf(e)?(n=!1,switchDisplay(t,!0,"flex")):switchDisplay(t,!1)}),switchDisplay(i,n,"flex"),this.moveDialog()},200).bind(this)),e.appendChild(i);const s=document.createElement("div");s.classList.add("chat-select-dialog-search-empty"),s.innerHTML=`${matchEmptySvg}<span class="empty-label">${this.searchEmptyText}</span>`,switchDisplay(s,!1),e.appendChild(s),t.appendChild(e)}const s=document.createElement("div");s.classList.add("chat-select-dialog-main"),s.classList.add("chat-scroll");const n=document.createDocumentFragment();this.options.forEach(t=>{const e=document.createElement("div");if(e.classList.add("chat-select-dialog-item"),e.setAttribute("data-id",t.id),e.setAttribute("data-name",t.name),t.preview){const i=document.createElement("div");i.classList.add("chat-select-dialog-preview"),i.classList.add("loading"),i.innerHTML=antdLoading,e.appendChild(i);const s=new Image;s.classList.add("chat-select-dialog-preview"),s.src=String(t.preview),s.onload=()=>{e.insertBefore(s,i),e.removeChild(i)}}const i=document.createElement("span");i.classList.add("chat-select-dialog-name"),i.textContent=t.name,e.appendChild(i);const s=document.createElement("span");s.classList.add("chat-select-dialog-check"),s.innerHTML=checkSvg,switchDisplay(s,!1),e.appendChild(s),e.addEventListener("click",t=>{if(t.stopPropagation(),this.selectNode&&"Select"===this.selectNode.type)if(this.multiple){switchDisplay(e.lastChild,!isShow(e.lastChild));const t=e.parentElement.querySelectorAll(".chat-select-dialog-check.chat-view-show");if(0===t.length)this.selectNode.updateTag({id:null,name:this.emptyText});else{let e="",i="";Array.from(t,t=>{const s=t.parentElement;e+=`${s.getAttribute("data-id")},`,i+=`${s.getAttribute("data-name")}、`}),this.selectNode.updateTag({id:e.slice(0,-1),name:i.slice(0,-1)})}}else{const t=e.getAttribute("data-id"),i=e.getAttribute("data-name");this.selectNode.updateTag({id:t,name:i}),this.closeDialog()}else{const t=e.getAttribute("data-id"),i=e.getAttribute("data-name");this.bus.emit(EVENT_EDITOR_INSERT_SELECT,{...this.selectNode||{},id:t,name:i}),this.closeDialog()}}),n.appendChild(e)}),s.appendChild(n),t.appendChild(s);const o=document.createElement("div");o.classList.add("chat-select-dialog-arrow"),t.appendChild(o),this.dialog.appendChild(t),this.chatElement.dialogRoot.appendChild(this.dialog)};class BeforeTip{constructor(t,e){__privateAdd(this,_BeforeTip_instances),__publicField(this,"eventKey",Symbol("BeforeTip")),__publicField(this,"chatElement"),__publicField(this,"bus"),__publicField(this,"tip"),__publicField(this,"dialog"),__publicField(this,"config",{}),__privateAdd(this,_Events4,[]),this.chatElement=t,this.bus=this.chatElement.chat.bus,this.tip=document.createElement("div"),this.dialog=document.createElement("div"),__privateMethod(this,_BeforeTip_instances,registerBus_fn4).call(this),__privateMethod(this,_BeforeTip_instances,registerEvent_fn4).call(this),__privateMethod(this,_BeforeTip_instances,createTip_fn).call(this),this.updateConfig(e)}updateConfig(t){this.config=t,this.tip.innerHTML=t.tipTemplate||"",this.dialog.innerHTML=t.dialogTemplate||""}openTip(t){this.tip.innerHTML=replaceTemplate(this.tip.innerHTML,t),this.dialog.innerHTML=replaceTemplate(this.dialog.innerHTML,t),switchDisplay(this.tip);(this.config.closeNames||[]).forEach(t=>{const e=this.tip.querySelector(`.${t}`);e&&e.addEventListener("click",()=>{this.closeTip()})}),this.tip.onmouseenter=()=>{switchDisplay(this.dialog),this.tip.classList.add("tip-hover");const t=this.tip.children[0],e=t.offsetWidth/2+t.offsetLeft,i=this.dialog.children[0].clientWidth/2;this.chatElement.container.style.setProperty("--chat-tip-dialog-left",e-i+"px");const s=Number(this.chatElement.container.style.getPropertyValue("--chat-before-tip-top").replace("px",""));this.chatElement.container.style.setProperty("--chat-tip-dialog-top",s-this.chatElement.rollBox.scrollTop+"px")},this.tip.onmouseleave=()=>{switchDisplay(this.dialog,!1),this.tip.classList.remove("tip-hover")};const e=this.tip.children[0].clientWidth;this.chatElement.container.style.setProperty("--chat-before-tip-width",`${e+Number(t.offset||4)}px`),this.bus.emit(EVENT_EDITOR_FOCUS,"mark"),__privateMethod(this,_BeforeTip_instances,update_fn).call(this),this.bus.emit(EVENT_COMMON_TIP_STATE,!0)}closeTip(){isShow(this.tip)&&(this.chatElement.container.style.setProperty("--chat-before-tip-width","0px"),this.chatElement.container.style.setProperty("--chat-before-tip-top","0px"),this.chatElement.container.style.setProperty("--chat-tip-dialog-left","0px"),switchDisplay(this.tip,!1),switchDisplay(this.dialog,!1),this.tip.classList.remove("tip-hover"),this.bus.emit(EVENT_EDITOR_FOCUS,"mark"),this.tip.innerHTML=this.config.tipTemplate||"",this.dialog.innerHTML=this.config.dialogTemplate||"",this.bus.emit(EVENT_COMMON_TIP_STATE,!1))}destroy(){this.bus.offKeyEvent(this.eventKey),__privateGet(this,_Events4).forEach(t=>{const e=t[0],i=t[1];for(const t in i)e.removeEventListener(t,i[t])})}}_Events4=new WeakMap,_BeforeTip_instances=new WeakSet,registerBus_fn4=function(){this.bus.on(this.eventKey,EVENT_COMMON_DESTROY,()=>{this.destroy()}),this.bus.on(this.eventKey,EVENT_TIP_OPEN,t=>{this.openTip(t)}),this.bus.on(this.eventKey,EVENT_TIP_CLOSE,()=>{this.closeTip()}),this.bus.on(this.eventKey,EVENT_COMMON_CHANGE,()=>{__privateMethod(this,_BeforeTip_instances,update_fn).call(this)})},registerEvent_fn4=function(){__privateSet(this,_Events4,[[window,{resize:()=>{__privateMethod(this,_BeforeTip_instances,update_fn).call(this)},keydown:t=>{"Escape"===t.key&&this.closeTip()}}]]),__privateGet(this,_Events4).forEach(t=>{const e=t[0],i=t[1];for(const t in i)e.addEventListener(t,i[t])})},createTip_fn=function(){this.tip.classList.add("chat-before-tip-wrap"),this.dialog.classList.add("chat-tip-dialog-wrap"),this.chatElement.rollBox.appendChild(this.tip),this.chatElement.dialogRoot.appendChild(this.dialog),switchDisplay(this.tip,!1),switchDisplay(this.dialog,!1)},update_fn=function(){if(!isShow(this.tip))return;const t=this.chatElement.chat.chatEditor.NODES[0].children[0],e=this.tip.children[0],i=t.$el.getBoundingClientRect(),s=e.getBoundingClientRect(),n=Number(this.chatElement.container.style.getPropertyValue("--chat-before-tip-top").replace("px","")),o=i.y+this.chatElement.chat.chatEditor.NODE_HEIGHT/2-(s.y+s.height/2)+n;this.chatElement.container.style.setProperty("--chat-before-tip-top",`${o+(this.config.offsetTop||0)}px`)};class ChatElement{constructor(t,e){__privateAdd(this,_ChatElement_instances),__publicField(this,"eventKey",Symbol("ChatElement")),__publicField(this,"chat"),__publicField(this,"container"),__publicField(this,"rollBox"),__publicField(this,"richText"),__publicField(this,"placeholder"),__publicField(this,"dialogRoot"),__publicField(this,"mentionDialog"),__publicField(this,"triggerDialogs"),__publicField(this,"selectDialogs"),__publicField(this,"beforeTip"),this.chat=e,this.container=t,this.rollBox=document.createElement("div"),this.richText=document.createElement("div"),this.placeholder=document.createElement("div"),this.dialogRoot=document.createElement("div"),__privateMethod(this,_ChatElement_instances,registerBus_fn5).call(this),__privateMethod(this,_ChatElement_instances,createRichText_fn).call(this),__privateMethod(this,_ChatElement_instances,createPlaceholder_fn).call(this),__privateMethod(this,_ChatElement_instances,createDialogRoot_fn).call(this)}updatePlaceholder(t){this.placeholder.textContent=t}updateChatStyle(t){Object.assign(this.rollBox.style,t)}createMentionDialog(){this.mentionDialog?this.mentionDialog.updateConfig(this.chat.options.mentionConfig):this.mentionDialog=new MentionDialog(this,this.chat.options.mentionConfig)}createTriggerDialog(){this.triggerDialogs?(this.triggerDialogs.forEach(t=>{t.destroy()}),this.triggerDialogs=[]):this.triggerDialogs=[],this.chat.options.triggerConfig.forEach(t=>{this.triggerDialogs.push(new TriggerDialog(this,t))})}createSelectDialog(){this.selectDialogs?(this.selectDialogs.forEach(t=>{t.destroy()}),this.selectDialogs=[]):this.selectDialogs=[],this.chat.options.selectConfig.forEach(t=>{this.selectDialogs.push(new SelectDialog(this,t))})}createBeforeTip(){this.beforeTip?this.beforeTip.updateConfig(this.chat.options.tipConfig):this.beforeTip=new BeforeTip(this,this.chat.options.tipConfig)}destroy(){this.chat.bus.offKeyEvent(this.eventKey),this.rollBox.parentElement&&this.rollBox.parentElement.removeChild(this.rollBox),this.placeholder.parentElement&&this.placeholder.parentElement.removeChild(this.placeholder),this.dialogRoot.parentElement&&this.dialogRoot.parentElement.removeChild(this.dialogRoot)}}_ChatElement_instances=new WeakSet,registerBus_fn5=function(){this.chat.bus.on(this.eventKey,EVENT_COMMON_CHANGE,()=>{__privateMethod(this,_ChatElement_instances,switchPlaceholder_fn).call(this)}),this.chat.bus.on(this.eventKey,EVENT_COMMON_DESTROY,()=>{this.destroy()})},createRichText_fn=function(){this.container.classList.add("chat-area-wrap"),this.rollBox.classList.add("chat-rich-text"),this.rollBox.classList.add("chat-scroll"),this.richText.setAttribute("data-set-richType",RICH_WRAP),this.richText.setAttribute("contenteditable","true"),this.rollBox.appendChild(this.richText),this.container.appendChild(this.rollBox)},createPlaceholder_fn=function(){this.placeholder.classList.add("chat-placeholder-wrap"),switchDisplay(this.placeholder),this.container.appendChild(this.placeholder)},createDialogRoot_fn=function(){this.dialogRoot.classList.add("chat-dialog-wrap"),this.container.appendChild(this.dialogRoot)},switchPlaceholder_fn=function(){if(this.chat.chatEditor.isComposition)return switchDisplay(this.placeholder,!1);const t=this.chat.chatEditor.NODES;return t.length>1||t[0].children.length>1||t[0].children[0].text.length>0?switchDisplay(this.placeholder,!1):void switchDisplay(this.placeholder,!0)};class Render{constructor(t){__publicField(this,"$el",null),__publicField(this,"type",""),this.type=t}mount({parentElm:t,beforeElm:e,afterElm:i,targetElm:s}){s&&(i?i.nextElementSibling?t.insertBefore(s,i.nextElementSibling):t.appendChild(s):e?t.insertBefore(s,e):t.appendChild(s))}}const _Write=class t extends Render{constructor(t,e){super(e.type),__privateAdd(this,_Write_instances),__publicField(this,"context"),__publicField(this,"text",""),__publicField(this,"VOID_KEY","\ufeff"),this.context=t,this.text=String(e.text||""),this.render(e)}ruleBRTag(){const t=this.$el.children[0];if(t.childNodes.length>1){const e=[];for(let i=1;i<t.childNodes.length;i++)e.push(t.childNodes[i]);e.forEach(e=>{t.removeChild(e)})}if(!Boolean(this.text)&&this.$el===this.$el.parentElement.lastElementChild){const t=document.createElement("br");this.$el.children[0].appendChild(t)}}focus(t){const e=this.$el.children[0].childNodes[0];t||0===t?-1===t&&(t=e.textContent===this.VOID_KEY?1:e.textContent.length):t=e.textContent===this.VOID_KEY?1:0;const i=new Range,s=this.context.context.chat.getSelection();i.setStart(e,t),i.setEnd(e,t),s.removeAllRanges(),s.addRange(i),__privateMethod(this,_Write_instances,emit_fn).call(this,EVENT_EDITOR_CURSOR_CHANGE,{node:e,offset:t,type:"Write",instance:this})}updateNode(){const t=this.$el.children[0],e=t.childNodes[0],i=e.textContent||"";if(this.text=i.replace(new RegExp(this.VOID_KEY,"ig"),"")||"",t.setAttribute("data-set-empty",String(!Boolean(this.text))),Boolean(this.text)){if(-1!==i.indexOf(this.VOID_KEY)&&(e.textContent=this.text,this.focus(-1)),t.childNodes.length>1)for(let e=t.childNodes.length-1;e>0;e--)t.removeChild(t.childNodes[e])}else e.textContent=this.VOID_KEY,this.ruleBRTag()}deleteNode(){const t=this.context.children.indexOf(this);this.context.children.splice(t,1),this.context.$el.removeChild(this.$el)}deleteRelevanceNode(){this.deleteNode()}deleteRangeNode(t){const e=t.anchorOffset,i=t.focusOffset,s=e>i,n=s?i:e,o=s?e:i,a=this.text.slice(0,n),c=this.text.slice(o);this.text=a+c,this.syncNode(),this.focus(n)}updateContext(t){this.context=t}syncNode(){const t=this.$el.children[0].childNodes[0];Boolean(this.text)?t.textContent=this.text:t.textContent=this.VOID_KEY,this.ruleBRTag()}splitNode(e,i,s="",n=""){const o=!Boolean(this.text),a=o?"":this.text.slice(0,e),c=o?"":this.text.slice(e);this.text=i?a.slice(0,-i):a,this.text=this.text+s;const h=this.context.children.indexOf(this),l=new t(this.context,{type:"Write",text:n+c,afterElm:this.$el});this.context.children.splice(h+1,0,l),this.syncNode(),this.updateNode(),l.updateNode(),l.focus(n.length>0?n.length:void 0)}backspace(t){const e=t.anchorOffset;if(t.isCollapsed){if(0===e||1===e&&!Boolean(this.text)){const t=this.context.children.indexOf(this),e=this.context.context.NODES.indexOf(this.context);if(0===t){if(0===e)return void __privateMethod(this,_Write_instances,emit_fn).call(this,EVENT_TIP_CLOSE);return void this.context.context.NODES[e].mergeNode(!1)}return void this.context.context.NODES[e].children[t-1].deleteRelevanceNode()}this.text=this.text.slice(0,e-1)+this.text.slice(e),this.syncNode(),this.focus(e-1)}else this.deleteRangeNode({anchorInstance:this,anchorOffset:e,focusInstance:this,focusOffset:t.focusOffset})}delete(t){const e=t.anchorOffset;if(t.isCollapsed)if(e===this.text.length||1===e&&!Boolean(this.text)){const t=this.context.children.indexOf(this),e=this.context.context.NODES.indexOf(this.context);if(t===this.context.children.length-1){if(e===this.context.context.NODES.length-1)return;return void this.context.context.NODES[e].mergeNode(!0)}this.context.context.NODES[e].children[t+1].deleteRelevanceNode(!0)}else this.text=this.text.slice(0,e)+this.text.slice(e+1),this.syncNode(),this.focus(e);else{const i=t.focusOffset,s=e>i,n=s?i:e,o=s?e:i,a=this.text.slice(0,n),c=this.text.slice(o);this.text=a+c,this.syncNode(),this.focus(n)}}render(t){const e=document.createElement("span");this.$el=e,e.setAttribute("data-set-richType",RICH_MARK),e.classList.add("chat-write-wrap");const i=document.createElement("span");i.classList.add("chat-write-input"),i.setAttribute("data-set-richType",RICH_WRITE),i.setAttribute("data-set-empty",String(!Boolean(this.text))),i.appendChild(document.createTextNode(Boolean(this.text)?this.text:this.VOID_KEY)),e.appendChild(i),this.mount({parentElm:(null==t?void 0:t.parentElm)||this.context.$el,targetElm:this.$el,...t||{}})}};_Write_instances=new WeakSet,emit_fn=function(t,...e){this.context.context.bus.emit(t,...e)};let Write=_Write;class Tag extends Render{constructor(t,e){super(t),__publicField(this,"context"),this.context=e}deleteNode(){const t=this.context.children.indexOf(this);this.context.children.splice(t,1),this.context.$el.removeChild(this.$el)}deleteRelevanceNode(t=!1){const e=this.context.children.indexOf(this),i=this.context.children[e-1],s=this.context.children[e+1];this.context.children.splice(e,1),this.context.$el.removeChild(this.$el),t?this.context.mergeWriteNode(s,i,!0,!0):this.context.mergeWriteNode(i,s)}deleteRangeNode(){this.deleteRelevanceNode()}updateContext(t){this.context=t}focus(t=!1){const e=this.context.children.indexOf(this),i=this.context.children[t?e-1:e+1];if(i){const e=!Boolean(i.text);i.focus(t?e?1:i.text.length:e?1:0)}}backspace(){this.context.backspace()}updateNode(){this.context.updateNode()}delete(){this.context.delete()}}class Mention extends Tag{constructor(t,e){super(e.type,t),__publicField(this,"id",""),__publicField(this,"name",""),this.id=e.id,this.name=e.name,this.render(e)}render(t){const e=document.createElement("span");this.$el=e,e.setAttribute("data-set-richType",RICH_MENTION),e.setAttribute("contenteditable","false"),e.classList.add("chat-tag-wrap");const i=document.createElement("span");i.classList.add("chat-tag-mention"),i.textContent="@"+this.name,e.appendChild(i),this.mount({parentElm:(null==t?void 0:t.parentElm)||this.context.$el,targetElm:this.$el,...t||{}})}}class Trigger extends Tag{constructor(t,e){super(e.type,t),__publicField(this,"id",""),__publicField(this,"name",""),__publicField(this,"key",""),this.id=e.id,this.name=e.name,this.key=e.key,this.render(e)}render(t){const e=document.createElement("span");this.$el=e,e.setAttribute("data-set-richType",RICH_TRIGGER),e.setAttribute("contenteditable","false"),e.classList.add("chat-tag-wrap");const i=document.createElement("span");i.classList.add("chat-tag-trigger"),i.textContent=this.key+this.name,e.appendChild(i),this.mount({parentElm:(null==t?void 0:t.parentElm)||this.context.$el,targetElm:this.$el,...t||{}})}}class Select extends Tag{constructor(t,e){super(e.type,t),__privateAdd(this,_Select_instances),__publicField(this,"id",""),__publicField(this,"name",""),__publicField(this,"key",""),this.id=e.id,this.name=e.name,this.key=e.key,this.render(e)}updateTag({id:t,name:e}){this.id=t,this.name=e;this.$el.children[0].children[0].textContent=e,this.focus(),__privateMethod(this,_Select_instances,emit_fn2).call(this,EVENT_EDITOR_CHANGE)}render(t){const e=document.createElement("span");this.$el=e,e.setAttribute("data-set-richType",RICH_SELECT),e.setAttribute("contenteditable","false"),e.classList.add("chat-tag-wrap");const i=document.createElement("span");i.classList.add("chat-tag-select"),i.innerHTML=`<span></span>${arrowSvg}`;i.children[0].textContent=this.name,e.appendChild(i),e.addEventListener("click",t=>{t.stopPropagation(),this.context.context.bus.emit(EVENT_COMMON_SELECT_ACTIVE,this)}),this.mount({parentElm:(null==t?void 0:t.parentElm)||this.context.$el,targetElm:this.$el,...t||{}})}}_Select_instances=new WeakSet,emit_fn2=function(t,...e){this.context.context.bus.emit(t,...e)};class Input extends Render{constructor(t,e){super(e.type),__privateAdd(this,_Input_instances),__publicField(this,"context"),__publicField(this,"text",""),__publicField(this,"placeholder",""),__publicField(this,"key",""),__publicField(this,"VOID_KEY","\ufeff"),__publicField(this,"WRAP_KEY","\n"),this.context=t,this.text=(e.text||"").replace(new RegExp(`${this.WRAP_KEY[0]}|${this.VOID_KEY}`,"ig"),""),this.placeholder=String(e.placeholder||"placeholder"),this.key=e.key,this.render(e)}updateContext(t){this.context=t}syncNode(){const t=this.$el.children[0].children[0].childNodes[0];Boolean(this.text)?t.textContent=this.fixWrapKey(this.text):t.textContent=this.VOID_KEY,this.updateNode()}updateNode(){const t=this.$el.children[0].children[0],e=this.$el.children[0].children[1],i=t.childNodes[0],s=i.textContent||"";if(this.text=s.replace(new RegExp(`${this.WRAP_KEY[0]}|${this.VOID_KEY}`,"ig"),""),switchDisplay(e,!Boolean(this.text),"inline-block"),Boolean(this.text)){if(-1!==s.indexOf(this.VOID_KEY))i.textContent=this.fixWrapKey(this.text),this.focus(-1);else if(-1!==this.text.indexOf(this.WRAP_KEY[1])){const t=this.fixWrapKey(this.text);if(t!==i.textContent){let e=0;for(let s=0;s<i.textContent.length;s++){if(i.textContent[s]!==t[s]){e=s;break}}i.textContent=t,this.focus(e+2)}}}else i.textContent=this.VOID_KEY}deleteNode(){const t=this.context.children.indexOf(this);this.context.children.splice(t,1),this.context.$el.removeChild(this.$el)}backspace(t){const e=t.anchorOffset;if(t.isCollapsed)if(0===e||1===e&&!Boolean(this.text))if(Boolean(this.text)){const t=this.context.children.indexOf(this);this.context.children[t-1].focus(-1)}else this.deleteRelevanceTag();else{const t=this.$el.children[0].children[0].childNodes[0],i=this.getWrapOffset(t,e,"left"),s=t.textContent||"";let n;switch(i){case 1:n=e-i-2;break;case 2:n=e-i-1;break;case 3:n=e-i;break;default:n=e-1}const o=s.slice(0,n),a=s.slice(e);this.text=(o+a).replace(new RegExp(`${this.WRAP_KEY[0]}|${this.VOID_KEY}`,"ig"),""),this.syncNode(),this.focus(n)}else this.deleteRangeNode({anchorInstance:this,anchorOffset:e,focusInstance:this,focusOffset:t.focusOffset})}delete(t){const e=t.anchorOffset,i=this.$el.children[0].children[0].childNodes[0],s=this.getWrapOffset(i,e,"right");if(t.isCollapsed)if(e+s===this.fixWrapKey(this.text).length||1===e&&!Boolean(this.text))if(Boolean(this.text)){const t=this.context.children.indexOf(this);this.context.children[t+1].focus()}else this.deleteRelevanceTag(!0);else{const t=i.textContent||"";let n,o,a;switch(s){case 1:n=2,o=1,a=e+1;break;case 2:n=1,o=2,a=e-1;break;case 3:n=0,o=3,a=e;break;default:n=0,o=1,a=e}const c=t.slice(0,e-n),h=t.slice(e+o);this.text=(c+h).replace(new RegExp(`${this.WRAP_KEY[0]}|${this.VOID_KEY}`,"ig"),""),this.syncNode(),this.focus(a)}else this.deleteRangeNode({anchorInstance:this,anchorOffset:e,focusInstance:this,focusOffset:t.focusOffset})}deleteRangeNode(t){const e=t.anchorOffset,i=t.focusOffset,s=e>i;let n=s?i:e,o=s?e:i;const a=this.$el.children[0].children[0].childNodes[0],c=a.textContent||"",h=this.getWrapOffset(a,n,"right"),l=this.getWrapOffset(a,o-1,"left"),r=c.slice(0,n+h),d=c.slice(o+l);this.text=(r+d).replace(new RegExp(`${this.WRAP_KEY[0]}|${this.VOID_KEY}`,"ig"),""),this.syncNode(),this.focus(n)}focus(t){const e=this.$el.children[0].children[0].childNodes[0];t||0===t?-1===t&&(t=e.textContent===this.VOID_KEY?1:e.textContent.length):t=e.textContent===this.VOID_KEY?1:0;const i=new Range,s=this.context.context.chat.getSelection();i.setStart(e,t),i.setEnd(e,t),s.removeAllRanges(),s.addRange(i),__privateMethod(this,_Input_instances,emit_fn3).call(this,EVENT_EDITOR_CURSOR_CHANGE,{node:e,offset:t,type:"Input",instance:this})}deleteRelevanceNode(t=!1){this.focus(t?void 0:-1)}deleteRelevanceTag(t=!1){const e=this.context.children.indexOf(this),i=this.context.children[e-1],s=this.context.children[e+1];this.context.children.splice(e,1),this.context.$el.removeChild(this.$el),t?this.context.mergeWriteNode(s,i,!0,!0):this.context.mergeWriteNode(i,s)}setText(t,e){if(e=this.fixWrapKey(e),Boolean(this.text)){const i=this.$el.children[0].children[0].textContent||"",s=i.slice(0,t),n=i.slice(t);this.text=s+e+n,this.syncNode(),this.focus(s.length+e.length)}else this.text=e,this.syncNode(),this.focus(e.length)}fixWrapKey(t){return t.replace(new RegExp(this.WRAP_KEY[0],"ig"),"").replace(new RegExp(this.WRAP_KEY[1],"ig"),this.WRAP_KEY)}getWrapOffset(t,e,i="left"){const s="left"===i?t.textContent[e-1]:t.textContent[e];if(s===this.WRAP_KEY[0]){return("left"===i?t.textContent[e-2]:t.textContent[e+1])===this.WRAP_KEY[1]?3:1}return s===this.WRAP_KEY[1]?2:0}render(t){const e=document.createElement("span");this.$el=e,e.setAttribute("data-set-richType",RICH_INPUT),e.setAttribute("contenteditable","false"),e.classList.add("chat-tag-wrap");const i=document.createElement("span");i.classList.add("chat-tag-input");const s=document.createElement("span");s.classList.add("input-write"),s.setAttribute("contenteditable","true"),s.textContent=Boolean(this.text)?this.fixWrapKey(this.text):this.VOID_KEY,i.appendChild(s);const n=document.createElement("span");n.classList.add("input-tip"),n.textContent=`[${this.placeholder}]`,i.appendChild(n),Boolean(this.text)&&switchDisplay(n,!1),e.addEventListener("click",()=>{Boolean(this.text)||this.focus()}),e.appendChild(i),this.mount({parentElm:(null==t?void 0:t.parentElm)||this.context.$el,targetElm:this.$el,...t||{}})}}_Input_instances=new WeakSet,emit_fn3=function(t,...e){this.context.context.bus.emit(t,...e)};class Custom extends Tag{constructor(t,e){super(e.type,t),__publicField(this,"html",""),this.html=e.html,this.render(e)}render(t){const e=document.createElement("span");this.$el=e,e.setAttribute("data-set-richType",RICH_CUSTOM),e.setAttribute("contenteditable","false"),e.classList.add("chat-tag-wrap"),e.innerHTML=this.html,this.mount({parentElm:(null==t?void 0:t.parentElm)||this.context.$el,targetElm:this.$el,...t||{}})}}class Grid extends Render{constructor(t,e,i){super("Grid"),__publicField(this,"children",[]),__publicField(this,"context"),this.context=t,this.render(e,i)}getAnalyzeChildren(t){if(!t||0===t.length)return[{type:"Write",text:""}];const e=[];t.forEach((i,s)=>{if(s===t.length-1)return;const n=s+1;if("Write"===i.type&&"Write"===t[n].type){let t=n-e.length;e.push(t)}}),e.forEach(e=>{const i=t[e];t[e-1].text+=i.text,t.splice(e,1)});const i=[];return t.forEach((e,s)=>{if(s===t.length-1)return;const n=s+1;if("Write"!==e.type&&"Write"!==t[n].type){let t=n+i.length;i.push(t)}}),i.forEach(e=>{t.splice(e,0,{type:"Write",text:""})}),"Write"!==t[0].type&&t.unshift({type:"Write",text:""}),"Write"!==t[t.length-1].type&&t.push({type:"Write",text:""}),t}emit(t,...e){this.context.bus.emit(t,...e)}mergeNode(t=!1){const e=this.context.NODES.indexOf(this);if(t){const t=this.context.NODES[e+1];if(t){const e=this.children[this.children.length-1],i=t.children[0];this.mergeWriteNode(e,i),this.children.push(...t.children);const s=document.createDocumentFragment();t.children.forEach(t=>{t.updateContext(this),s.appendChild(t.$el)}),this.$el.appendChild(s),e.ruleBRTag(),t.deleteNode()}}else{const t=this.context.NODES[e-1];if(t){const e=t.children[t.children.length-1],i=this.children[0];this.mergeWriteNode(e,i),t.children.push(...this.children);const s=document.createDocumentFragment();this.children.forEach(e=>{e.updateContext(t),s.appendChild(e.$el)}),t.$el.appendChild(s),e.ruleBRTag(),this.deleteNode()}}}splitNode(t,e=0){const i=this.context.NODES.indexOf(this),s=this.children.indexOf(t),n=Boolean(t.text)?t.text.slice(0,e):"",o=Boolean(t.text)?t.text.slice(e):"";t.text=n;const a=this.children.slice(0,s+1),c=this.children.slice(s+1);this.children=a;const h=new Grid(this.context,[],{afterElm:this.$el});this.context.NODES.splice(i+1,0,h);const l=h.children[0];l.text=o,h.children.push(...c);const r=document.createDocumentFragment();c.forEach(t=>{t.updateContext(h),r.appendChild(t.$el)}),h.$el.appendChild(r),t.syncNode(),l.syncNode(),l.focus()}deleteNode(){this.children=[];const t=this.context.NODES.indexOf(this);this.context.NODES.splice(t,1),this.context.$el.removeChild(this.$el)}mergeWriteNode(t,e,i=!0,s=!1){const n=t.text||"",o=e.text||"",a=s?o.length:n.length;t.text=s?o+n:n+o,t.syncNode(),e.deleteNode(),i&&t.focus(Boolean(t.text)?a:1)}splitWriteNode(t,e){const i=this.children.indexOf(t),s=Boolean(t.text)?t.text.slice(0,e):"",n=Boolean(t.text)?t.text.slice(e):"";t.text=s,t.syncNode();const o=new Write(this,{type:"Write",text:n,afterElm:t.$el});this.children.splice(i+1,0,o)}deleteRangeNode(t){const e=t.anchorInstance,i=t.focusInstance;if(e===i)return void e.deleteRangeNode(t);const s=this.children.indexOf(e)>this.children.indexOf(i);"Write"===e.type&&this.splitWriteNode(e,t.anchorOffset),"Write"===i.type&&this.splitWriteNode(i,t.focusOffset);const n=this.children.indexOf(e),o=this.children.indexOf(i);let a=(s?o:n)+1;const c=s?n:o;s&&"Write"!==i.type&&(a-=1);const h=this.children.slice(a,c+1),l=this.children[a-1],r=this.children[c+1];h.forEach(t=>{t.deleteNode()}),this.mergeWriteNode(l,r)}updateNode(){this.context.fixEditor()}backspace(){this.context.fixEditor()}delete(){this.context.fixEditor()}render(t,e){const i=document.createElement("p");this.$el=i,i.className="chat-grid-wrap",i.setAttribute("data-set-richType",RICH_GRID),this.renderChildren(t,!1),this.mount({parentElm:this.context.$el,targetElm:this.$el,...e||{}})}renderChildren(t,e=!0){if(!this.$el)return;this.children=[],this.$el.innerHTML="";const i=this.getAnalyzeChildren(t),s=document.createDocumentFragment();i.forEach(t=>{let e;switch(t.type){case"Write":e=new Write(this,{...t,parentElm:s}),this.children.push(e);break;case"Mention":e=new Mention(this,{...t,parentElm:s}),this.children.push(e);break;case"Trigger":e=new Trigger(this,{...t,parentElm:s}),this.children.push(e);break;case"Select":e=new Select(this,{...t,parentElm:s}),this.children.push(e);break;case"Input":e=new Input(this,{...t,parentElm:s}),this.children.push(e);break;case"Custom":e=new Custom(this,{...t,parentElm:s}),this.children.push(e);break;default:const i=this.context.components[t.type];i&&(e=new i({type:t.type,data:t.data,context:this,config:{parentElm:s}}),this.children.push(e))}}),this.$el.appendChild(s);const n=this.children[this.children.length-1];n.ruleBRTag(),e&&(n.focus(-1),this.emit(EVENT_EDITOR_CHANGE))}}class ChatEditor{constructor(t){__privateAdd(this,_ChatEditor_instances),__publicField(this,"$el"),__publicField(this,"bus"),__publicField(this,"chat"),__publicField(this,"eventKey",Symbol("ChatEditor")),__publicField(this,"isComposition",!1),__publicField(this,"textLength",0),__privateAdd(this,_disabledEvent,!1),__publicField(this,"NODES",[]),__publicField(this,"NODE_HEIGHT",24),__publicField(this,"IME_MODEL",!1),__publicField(this,"FIX_MODEL",!1),__privateAdd(this,_Events5,[]),__publicField(this,"components",{}),__publicField(this,"markCursorWrite",{node:null,offset:0,instance:null}),__publicField(this,"markCursorInput",{node:null,offset:0,instance:null}),__publicField(this,"markLastType","Write"),__publicField(this,"undoHistory",[]),__publicField(this,"redoHistory",[]),__publicField(this,"historyLoading",!1),this.chat=t,this.bus=t.bus,this.$el=t.chatElement.richText,__privateMethod(this,_ChatEditor_instances,registerBus_fn6).call(this),__privateMethod(this,_ChatEditor_instances,registerEvent_fn5).call(this),this.initEditor()}initEditor(){this.$el.innerHTML="",this.NODES=[new Grid(this)],this.markLastType="Write",this.NODE_HEIGHT=this.NODES[0].$el.getBoundingClientRect().height,this.undoHistory=[{nodes:this.compileNodes(this.NODES),gridIndex:this.NODES.length-1,childIndex:0,offset:1,type:"Write"}],this.redoHistory=[],this.chat.options.autoFocus&&this.chat.nextTick(()=>{this.focusLast()});const t=this.NODES[this.NODES.length-1],e=t.children[t.children.length-1];__privateMethod(this,_ChatEditor_instances,cursorChange_fn).call(this,{node:e.$el.children[0].childNodes[0],offset:Boolean(e.text)?e.text.length:1,type:"Write",instance:e})}async fixEditor(t){this.$el.innerHTML="",t||(t=this.compileNodes(this.NODES)),this.NODES=t.map(t=>new Grid(this,t)),this.focusLast(),await __privateMethod(this,_ChatEditor_instances,richTextChange_fn).call(this)}deleteRangeNode(t){let e=t.anchorInstance,i=t.focusInstance;"Grid"===e.type&&(e=e.children[0],t.anchorOffset=Boolean(e.text)?0:1),"Grid"===i.type&&(i=i.children[0],t.focusInstance=Boolean(i.text)?0:1);const s=e.context,n=i.context,o=this.NODES.indexOf(s),a=this.NODES.indexOf(n),c=o>a,h=c?a:o,l=c?o:a;this.NODES.slice(h+1,l).forEach(t=>{t.deleteNode()});const r=c?n:s,d=c?s:n,p=r.children[r.children.length-1],_=d.children[0];c?(r.deleteRangeNode({anchorInstance:p,anchorOffset:Boolean(p.text)?p.text.length:1,focusInstance:i,focusOffset:t.focusOffset}),d.deleteRangeNode({anchorInstance:_,anchorOffset:Boolean(_.text)?0:1,focusInstance:e,focusOffset:t.anchorOffset})):(r.deleteRangeNode({anchorInstance:e,anchorOffset:t.anchorOffset,focusInstance:p,focusOffset:Boolean(p.text)?p.text.length:1}),d.deleteRangeNode({anchorInstance:i,anchorOffset:t.focusOffset,focusInstance:_,focusOffset:Boolean(_.text)?0:1})),r.mergeNode(!0)}findNode(t,e=5,i=!0){if(!t)return null;if(i&&!this.$el.contains(t))return null;if(e<=0)return null;if(t.nodeType===Node.TEXT_NODE)return this.findNode(t.parentElement,e-1);const s=t,n=s.getAttribute?s.getAttribute("data-set-richType"):"";if(n===RICH_WRITE){const t=s.parentElement,e=t.parentElement,i=Array.prototype.indexOf.call(e.children,t),n=Array.prototype.indexOf.call(this.$el.children,e);return this.NODES[n].children[i]}if(n===RICH_MARK){const t=s,e=t.parentElement,i=Array.prototype.indexOf.call(e.children,t),n=Array.prototype.indexOf.call(this.$el.children,e);return this.NODES[n].children[i]}if(n===RICH_MENTION||n===RICH_TRIGGER||n===RICH_SELECT||n===RICH_INPUT||n===RICH_CUSTOM||n===RICH_COMPONENT){const t=s,e=t.parentElement,i=Array.prototype.indexOf.call(e.children,t),n=Array.prototype.indexOf.call(this.$el.children,e);return this.NODES[n].children[i]}if(n===RICH_GRID){const t=Array.prototype.indexOf.call(this.$el.children,s);return this.NODES[t]}return this.findNode(s.parentElement,e-1,!1)}focusFirst(){this.NODES[0].children[0].focus(),this.cursorView()}focusMark(){const t=this.chat.getSelection(),e=new Range;switch(this.markLastType){case"Write":e.setStart(this.markCursorWrite.node,this.markCursorWrite.offset),e.setEnd(this.markCursorWrite.node,this.markCursorWrite.offset);break;case"Input":e.setStart(this.markCursorInput.node,this.markCursorInput.offset),e.setEnd(this.markCursorInput.node,this.markCursorInput.offset)}t.removeAllRanges(),t.addRange(e),this.cursorView()}focusLast(){const t=this.NODES[this.NODES.length-1];t.children[t.children.length-1].focus(-1),this.cursorView()}selectAll(){const t=this.chat.getSelection(),e=new Range,i=this.NODES[0].children[0],s=this.NODES[this.NODES.length-1].children[this.NODES[this.NODES.length-1].children.length-1],n=i.$el.children[0].childNodes[0],o=s.$el.children[0].childNodes[0];e.setStart(n,Boolean(i.text)?0:1),e.setEnd(o,Boolean(s.text)?s.text.length:1),t.removeAllRanges(),t.addRange(e)}cursorMove(t,e){const i=e||this.chat.getSelection(),s=t<0;if(!i.isCollapsed){const t=this.findNode(i.anchorNode),e=this.findNode(i.focusNode);if(!t||!e)return;let n,o,a=!1;if(t===e)a=i.anchorOffset>i.focusOffset;else if(t.context===e.context){a=t.context.children.indexOf(t)>e.context.children.indexOf(e)}else{a=this.NODES.indexOf(t.context)>this.NODES.indexOf(e.context)}return s?(n=a?i.focusOffset:i.anchorOffset,o=a?e:t):(n=a?i.anchorOffset:i.focusOffset,o=a?t:e),"Write"===o.type||"Input"===o.type?o.focus(n):o.focus(a),void this.cursorView()}const n=i.focusNode,o=this.findNode(n);let a=0;if(!o)return;if("Write"===o.type){const e=i.focusOffset,n=s?o.text.slice(0,e):o.text.slice(e);if(n.length>=Math.abs(t))return o.focus(e+t),void this.cursorView();a+=n.length}else if("Input"===o.type){const e=i.focusOffset,n=o.$el.children[0].children[0].childNodes[0],c=(s?n.textContent.slice(0,e):n.textContent.slice(e)).replace(new RegExp(`${o.VOID_KEY}|${o.WRAP_KEY[0]}`,"ig"),"");if(c.length>=Math.abs(t)){const i=o.getWrapOffset(n,s?e+t+1:e+t-1,s?"left":"right");return i?s?o.focus(e+t-i+1):o.focus(e+t+i-1):o.focus(e+t),void this.cursorView()}a+=c.length}const c=o.context.children.indexOf(o);if(s){if(0===c){const e=this.NODES.indexOf(o.context);if(0===e)return void o.focus();const i=this.NODES[e-1],s=i.children[i.children.length-1],n=s.$el.children[0].childNodes[0];return a+=1,void this.cursorMove(-(Math.abs(t)-a),{focusNode:n,focusOffset:Boolean(s.text)?s.text.length:1,isCollapsed:!0})}const e=o.context.children[c-1];let i,s;a+=1,"Input"===e.type?(i=e,s=i.$el.children[0].children[0].childNodes[0]):"Write"===e.type?(i=e,s=i.$el.children[0].childNodes[0]):(i=o.context.children[c-2],s=i.$el.children[0].childNodes[0]);const n="Input"===e.type?i.fixWrapKey(i.text):i.text;this.cursorMove(-(Math.abs(t)-a),{focusNode:s,focusOffset:Boolean(n)?n.length:1,isCollapsed:!0})}else{if(c===o.context.children.length-1){const e=this.NODES.indexOf(o.context);if(e===this.NODES.length-1)return void o.focus(-1);const i=this.NODES[e+1].children[0],s=i.$el.children[0].childNodes[0];return a+=1,void this.cursorMove(t-a,{focusNode:s,focusOffset:Boolean(i.text)?0:1,isCollapsed:!0})}const e=o.context.children[c+1];let i,s;a+=1,"Input"===e.type?(i=e,s=i.$el.children[0].children[0].childNodes[0]):"Write"===e.type?(i=e,s=i.$el.children[0].childNodes[0]):(i=o.context.children[c+2],s=i.$el.children[0].childNodes[0]),this.cursorMove(t-a,{focusNode:s,focusOffset:Boolean(i.text)?0:1,isCollapsed:!0})}}cursorView(){const t=this.$el.parentElement;if(t.scrollHeight<=t.clientHeight)return;const e=this.chat.getSelection().getRangeAt(0).getClientRects()[0],i=t.getClientRects()[0],s=e.y-i.y;s<0?t.scrollTop=t.scrollTop-Math.abs(s):s+e.height>i.height&&(t.scrollTop=t.scrollTop+(s+e.height-i.height))}compileNodes(t){const e=[];return t.forEach(t=>{const i=[];t.children.forEach(t=>{switch(t.type){case"Write":i.push({type:"Write",text:t.text});break;case"Mention":i.push({type:"Mention",id:t.id,name:t.name});break;case"Trigger":i.push({type:"Trigger",id:t.id,name:t.name,key:t.key});break;case"Select":i.push({type:"Select",id:t.id,name:t.name,key:t.key});break;case"Input":i.push({type:"Input",placeholder:t.placeholder,text:t.text,key:t.key});break;case"Custom":i.push({type:"Custom",html:t.html});break;default:this.components[t.type]&&i.push({type:t.type,data:t.data})}}),e.push(i)}),e}async insertText(t){const e=t.replace(new RegExp("\ufeff","ig"),"").replace(/\r\n/g,"\n").replace(/\r/g,"\n").split("\n").map(t=>[{type:"Write",text:t}]);await this.insertNodes(e)}async insertNodes(t){const{instance:e,offset:i}=this.markCursorWrite;if(!e)return;const s=e,n=s.context,o=this.NODES.indexOf(n);n.splitNode(s,i);let a=n.$el,c=null,h=null;t.forEach((e,i)=>{const s=new Grid(this,e,{afterElm:a});a=s.$el,0===i?c=s:i===t.length-1&&(h=s),this.NODES.splice(o+i+1,0,s)}),c&&c.mergeNode(),h?h.mergeNode(!0):n.mergeNode(!0),await __privateMethod(this,_ChatEditor_instances,richTextChange_fn).call(this)}async insertInputText(t){const{instance:e,offset:i}=this.markCursorInput;if(!e)return;const s=e,n=t.replace(new RegExp("\ufeff","ig"),"").replace(/\r\n/g,"\n").replace(/\r/g,"\n");s.setText(i,n),await __privateMethod(this,_ChatEditor_instances,richTextChange_fn).call(this)}splitWrite(t){const{instance:e,offset:i}=this.markCursorWrite;if(!e)return null;const s=e,n=s.context,o=n.children.indexOf(s);return s.splitNode(i,t.del,t.beforeText,t.afterText),{index:o,write:s,grid:n}}async insertMention(t){const e=this.splitWrite(t);if(!e)return;const{index:i,write:s,grid:n}=e,o=new Mention(n,{type:"Mention",id:t.id,name:t.name,afterElm:s.$el});n.children.splice(i+1,0,o),await __privateMethod(this,_ChatEditor_instances,richTextChange_fn).call(this)}async insertTrigger(t){const e=this.splitWrite(t);if(!e)return;const{index:i,write:s,grid:n}=e,o=new Trigger(n,{type:"Trigger",id:t.id,name:t.name,key:t.key,afterElm:s.$el});n.children.splice(i+1,0,o),await __privateMethod(this,_ChatEditor_instances,richTextChange_fn).call(this)}async insertSelect(t){const e=this.splitWrite(t);if(!e)return;const{index:i,write:s,grid:n}=e,o=new Select(n,{type:"Select",id:t.id,name:t.name,key:t.key,afterElm:s.$el});n.children.splice(i+1,0,o),await __privateMethod(this,_ChatEditor_instances,richTextChange_fn).call(this)}async insertInput(t){const e=this.splitWrite(t);if(!e)return;const{index:i,write:s,grid:n}=e,o=new Input(n,{type:"Input",text:t.text,placeholder:t.placeholder,key:t.key,afterElm:s.$el});n.children.splice(i+1,0,o),o.focus(-1),await __privateMethod(this,_ChatEditor_instances,richTextChange_fn).call(this)}async insertCustom(t){const e=this.splitWrite(t);if(!e)return;const{index:i,write:s,grid:n}=e,o=new Custom(n,{type:"Custom",html:t.html,afterElm:s.$el});n.children.splice(i+1,0,o),await __privateMethod(this,_ChatEditor_instances,richTextChange_fn).call(this)}async reset(t){if(this.$el.innerHTML="",this.NODES=t.chatNode.map(t=>new Grid(this,t)),t.clearHistory){const t=this.NODES[this.NODES.length-1],e=t.children[t.children.length-1];this.undoHistory=[{nodes:this.compileNodes(this.NODES),gridIndex:this.NODES.length-1,childIndex:t.children.length-1,offset:Boolean(e.text)?e.text.length:1,type:"Write"}],this.redoHistory=[]}this.markLastType="Write",await this.chat.nextTick(),this.focusLast(),await __privateMethod(this,_ChatEditor_instances,richTextChange_fn).call(this,!t.clearHistory)}destroy(){this.bus.offKeyEvent(this.eventKey),__privateGet(this,_Events5).forEach(t=>{const e=t[0],i=t[1];for(const t in i)e.removeEventListener(t,i[t])})}useComponent(t,e){this.components[t]=e}async insertComponent(t,e){const i=this.components[t];if(!i)return;const s=this.splitWrite({type:t,data:e,del:0});if(!s)return;const{index:n,write:o,grid:a}=s,c=new i({type:t,data:e,context:a,config:{afterElm:o.$el}});a.children.splice(n+1,0,c),await __privateMethod(this,_ChatEditor_instances,richTextChange_fn).call(this)}}_disabledEvent=new WeakMap,_Events5=new WeakMap,_ChatEditor_instances=new WeakSet,registerBus_fn6=function(){this.bus.on(this.eventKey,EVENT_EDITOR_CHANGE,async t=>{await __privateMethod(this,_ChatEditor_instances,richTextChange_fn).call(this),t&&t()}),this.bus.on(this.eventKey,EVENT_EDITOR_DELETE,async(t,e)=>{await __privateMethod(this,_ChatEditor_instances,richTextDelete_fn).call(this,t),e&&e()}),this.bus.on(this.eventKey,EVENT_EDITOR_CURSOR_CHANGE,t=>{__privateMethod(this,_ChatEditor_instances,cursorChange_fn).call(this,t)}),this.bus.on(this.eventKey,EVENT_EDITOR_LINE_BREAK,async t=>{await __privateMethod(this,_ChatEditor_instances,richTextWrap_fn).call(this),t&&t()}),this.bus.on(this.eventKey,EVENT_EDITOR_UNDO,async t=>{await __privateMethod(this,_ChatEditor_instances,richTextUndo_fn).call(this),t&&t()}),this.bus.on(this.eventKey,EVENT_EDITOR_REDO,async t=>{await __privateMethod(this,_ChatEditor_instances,richTextRedo_fn).call(this),t&&t()}),this.bus.on(this.eventKey,EVENT_EDITOR_HISTORY,debounce(__privateMethod(this,_ChatEditor_instances,recordHistory_fn),200).bind(this)),this.bus.on(this.eventKey,EVENT_EDITOR_MAXLENGTH,()=>{__privateMethod(this,_ChatEditor_instances,ruleMaxLength_fn).call(this)}),this.bus.on(this.eventKey,EVENT_EDITOR_SWITCH_DISABLED,t=>{__privateSet(this,_disabledEvent,t)}),this.bus.on(this.eventKey,EVENT_EDITOR_INSERT_MENTION,async(t,e)=>{await this.insertMention(t),e&&e()}),this.bus.on(this.eventKey,EVENT_EDITOR_INSERT_TRIGGER,async(t,e)=>{await this.insertTrigger(t),e&&e()}),this.bus.on(this.eventKey,EVENT_EDITOR_INSERT_SELECT,async(t,e)=>{await this.insertSelect(t),e&&e()}),this.bus.on(this.eventKey,EVENT_EDITOR_INSERT_INPUT,async(t,e)=>{await this.insertInput(t),e&&e()}),this.bus.on(this.eventKey,EVENT_EDITOR_INSERT_CUSTOM,async(t,e)=>{await this.insertCustom(t),e&&e()}),this.bus.on(this.eventKey,EVENT_EDITOR_FOCUS,t=>{switch(t){case"first":this.focusFirst();break;case"last":this.focusLast();break;case"mark":this.focusMark()}}),this.bus.on(this.eventKey,EVENT_COMMON_DESTROY,()=>{this.destroy()})},registerEvent_fn5=function(){__privateSet(this,_Events5,[[this.$el,{keydown:t=>{if(this.isComposition=t.isComposing,this.chat.deviceInfo.isPc||!isKeyType(t,"IME")){if(!this.IME_MODEL)if(this.isComposition||!isKeyType(t,"text-backspace")&&!isKeyType(t,"text-delete"))if(this.chat.options.keyboardWrapFun(t)||!this.chat.deviceInfo.isPc&&"Enter"===t.key)t.preventDefault(),t.stopPropagation(),__privateMethod(this,_ChatEditor_instances,richTextWrap_fn).call(this);else if(!__privateGet(this,_disabledEvent)&&this.chat.options.keyboardSendFun(t))t.preventDefault(),t.stopPropagation(),this.isComposition||this.bus.emit(EVENT_COMMON_SEND);else if(isKeyType(t,"text-select-all"))t.preventDefault(),t.stopPropagation(),this.selectAll();else if(isKeyType(t,"text-move"))t.preventDefault(),t.stopPropagation(),this.isComposition||this.cursorMove("ArrowLeft"===t.key||"ArrowLeft"===t.code?-1:1);else if(isKeyType(t,"text-updown")){if(!this.isComposition){t.preventDefault(),t.stopPropagation();const e="ArrowUp"===t.key||"ArrowUp"===t.code,{instance:i,offset:s}=this.chat.getCurrentNode();if("Write"===i.type){const t=0===s||""===i.text&&1===s,n=s===i.text.length||""===i.text&&1===s;e?t?this.chat.jumpPrev("end"):i.focus(0):n?this.chat.jumpNext("start"):i.focus(-1)}else e?this.chat.jumpPrev("end"):this.chat.jumpNext("start")}}else isKeyType(t,"text-undo")?(t.preventDefault(),t.stopPropagation(),__privateMethod(this,_ChatEditor_instances,richTextUndo_fn).call(this)):isKeyType(t,"text-redo")?(t.preventDefault(),t.stopPropagation(),__privateMethod(this,_ChatEditor_instances,richTextRedo_fn).call(this)):isKeyType(t,"text-jump")&&(t.preventDefault(),t.stopPropagation(),t.shiftKey?this.chat.jumpPrev():this.chat.jumpNext());else{t.preventDefault(),t.stopPropagation();const e=isKeyType(t,"text-delete");__privateMethod(this,_ChatEditor_instances,richTextDelete_fn).call(this,e)}}else this.IME_MODEL=!0},beforeinput:async t=>{if(!this.IME_MODEL||!["insertParagraph","deleteContentBackward"].includes(t.inputType))return;t.preventDefault(),t.stopPropagation();const e=this.chat.getSelection();let i=this.findNode(e.focusNode),s=e.focusOffset;if(i||(i=this.findNode(this.markCursorWrite.node),s=this.markCursorWrite.offset),!i)return;"Grid"===i.type&&(i=i.children[0]),this.FIX_MODEL=!0;const n=i,o=this.NODES.indexOf(n.context),a=n.context.children.indexOf(n),c=this.compileNodes(this.NODES);this.chat.nextTick(async()=>{this.$el.innerHTML="",this.NODES=c.map(t=>new Grid(this,t));this.NODES[o].children[a].focus(s),"insertParagraph"===t.inputType?await __privateMethod(this,_ChatEditor_instances,richTextWrap_fn).call(this):"deleteContentBackward"===t.inputType&&await __privateMethod(this,_ChatEditor_instances,richTextDelete_fn).call(this),this.IME_MODEL=!1,this.FIX_MODEL=!1})},input:()=>{this.FIX_MODEL||(this.IME_MODEL=!1,__privateMethod(this,_ChatEditor_instances,richTextChange_fn).call(this))},copy:t=>{t.stopPropagation(),t.preventDefault(),__privateMethod(this,_ChatEditor_instances,richTextCopy_fn).call(this,t)},cut:t=>{t.stopPropagation(),t.preventDefault(),__privateMethod(this,_ChatEditor_instances,richTextCopy_fn).call(this,t),__privateMethod(this,_ChatEditor_instances,richTextDelete_fn).call(this)},paste:t=>{t.stopPropagation(),t.preventDefault(),__privateMethod(this,_ChatEditor_instances,richTextPaste_fn).call(this,t)},blur:()=>{__privateMethod(this,_ChatEditor_instances,cursorChange_fn).call(this)},focus:()=>{__privateMethod(this,_ChatEditor_instances,cursorChange_fn).call(this)},click:()=>{this.chat.nextTick(()=>{__privateMethod(this,_ChatEditor_instances,cursorChange_fn).call(this)})},compositionstart:()=>{this.isComposition=!0},compositionend:()=>{this.isComposition=!1},dragstart:t=>{t.stopPropagation(),t.preventDefault()},dragover:t=>{t.stopPropagation(),t.preventDefault()},drop:t=>{t.stopPropagation(),t.preventDefault()}}],[window,{keydown:t=>{(isKeyType(t,"text-undo")||isKeyType(t,"text-redo"))&&(t.preventDefault(),t.stopPropagation())}}]]);const t=["blur"];__privateGet(this,_Events5).forEach(e=>{const i=e[0],s=e[1];for(const e in s)i.addEventListener(e,s[e],-1!==t.indexOf(e))})},richTextDelete_fn=async function(t=!1){const e=this.chat.getSelection(),i=e.anchorNode,s=e.focusNode;let n=this.findNode(i),o=this.findNode(s);if(n&&o){if(n===o)t?n.delete(e):n.backspace(e);else if(n.context===o.context){n.context.deleteRangeNode({anchorInstance:n,anchorOffset:e.anchorOffset,focusInstance:o,focusOffset:e.focusOffset})}else this.deleteRangeNode({anchorInstance:n,anchorOffset:e.anchorOffset,focusInstance:o,focusOffset:e.focusOffset});await __privateMethod(this,_ChatEditor_instances,richTextChange_fn).call(this)}},richTextWrap_fn=async function(){if(this.isComposition)return;let t=this.chat.getSelection();t.isCollapsed||await __privateMethod(this,_ChatEditor_instances,richTextDelete_fn).call(this),t=this.chat.getSelection();const e=t.focusNode,i=this.findNode(e);if(i){if("Write"===i.type){i.context.splitNode(i,t.focusOffset)}else"Input"===i.type&&i.setText(t.focusOffset,"\n");await __privateMethod(this,_ChatEditor_instances,richTextChange_fn).call(this)}},richTextCopy_fn=function(t){const e=this.chat.getSelection(),i=t.clipboardData;if(e.isCollapsed||e.rangeCount<=0)return;const s=e.toString().replace(/\n\n/g,"\n")||"";i.setData("text/plain",s);let n=this.findNode(e.anchorNode),o=this.findNode(e.focusNode),a=e.anchorOffset,c=e.focusOffset;if(!n||!o)return;if("Grid"===n.type&&(n=n.children[0],a=Boolean(n.text)?0:1),"Grid"===o.type&&(o=o.children[0],c=Boolean(o.text)?0:1),n===o)return;const h=n.context,l=o.context;if(h===l){const t=h.children.indexOf(n),e=l.children.indexOf(o),s=t>e,r=s?e:t,d=s?t:e,p=h.children.slice(r+1,d),_={...s?o:n},E={...s?n:o},u=s?c:a,f=s?a:c;"Write"===_.type&&(_.text=_.text.slice(u)),"Write"===E.type&&(E.text=E.text.slice(0,f)),p.unshift(_),p.push(E);const g={type:"Grid",children:p},m=this.compileNodes([g]);return void i.setData(CHAT_COPY_KEY,JSON.stringify(m))}const r=n.context,d=o.context,p=this.NODES.indexOf(r),_=this.NODES.indexOf(d);let E,u,f,g,m,y,T,x;p>_?(E=d,u=r,f=o,g=n,m=_,y=p,T=c,x=a):(E=r,u=d,f=n,g=o,m=p,y=_,T=a,x=c);const N=E.children.indexOf(f),v=this.compileNodes([{type:"Gird",children:E.children.filter((t,e)=>e>N)}]);"Write"===f.type?v[0].unshift({type:"Write",text:Boolean(f.text)?f.text.slice(T):""}):v[0].unshift({...this.compileNodes([{type:"Gird",children:[f]}])[0][0]});const O=u.children.indexOf(g),C=this.compileNodes([{type:"Gird",children:u.children.filter((t,e)=>e<O)}]);"Write"===g.type?C[0].push({type:"Write",text:Boolean(g.text)?g.text.slice(0,x):""}):C[0].push({...this.compileNodes([{type:"Gird",children:[g]}])[0][0]});const D=this.compileNodes(this.NODES.slice(m+1,y));D.unshift(v[0]),D.push(C[0]),i.setData(CHAT_COPY_KEY,JSON.stringify(D))},richTextPaste_fn=async function(t){const e=t.clipboardData,i=e.getData("text/plain");if(!i)return;if("Input"===this.markLastType)return void this.insertInputText(i);const s=e.getData(CHAT_COPY_KEY)||"";let n=[];try{n=JSON.parse(s)}catch(t){}this.chat.getSelection().isCollapsed||await __privateMethod(this,_ChatEditor_instances,richTextDelete_fn).call(this),n&&n.length>0?this.insertNodes(n):this.insertText(i)},recordHistory_fn=function(){if("Input"===this.markLastType){const{instance:t,offset:e}=this.markCursorInput;if(!t)return;const i=t,s=i.context;this.undoHistory.push({nodes:this.compileNodes(this.NODES),gridIndex:this.NODES.indexOf(s),childIndex:s.children.indexOf(i),offset:e,type:"Input"})}else{const{instance:t,offset:e}=this.markCursorWrite;if(!t)return;const i=t,s=i.context;this.undoHistory.push({nodes:this.compileNodes(this.NODES),gridIndex:this.NODES.indexOf(s),childIndex:s.children.indexOf(i),offset:e,type:"Write"})}this.undoHistory.length>50&&this.undoHistory.shift()},richTextUndo_fn=async function(){if(this.historyLoading||this.undoHistory.length<=1)return;const t=this.undoHistory[this.undoHistory.length-1],e=this.undoHistory[this.undoHistory.length-2];this.redoHistory.push(t),this.undoHistory.pop(),await __privateMethod(this,_ChatEditor_instances,renderHistory_fn).call(this,e)},richTextRedo_fn=async function(){if(this.historyLoading||this.redoHistory.length<=0)return;const t=this.redoHistory[this.redoHistory.length-1];this.redoHistory.pop(),this.undoHistory.push(t),await __privateMethod(this,_ChatEditor_instances,renderHistory_fn).call(this,t)},renderHistory_fn=async function(t){this.historyLoading=!0,this.$el.innerHTML="",this.NODES=t.nodes.map(t=>new Grid(this,t));this.NODES[t.gridIndex].children[t.childIndex].focus(t.offset),await __privateMethod(this,_ChatEditor_instances,richTextChange_fn).call(this,!1),this.historyLoading=!1},richTextChange_fn=async function(t=!0){const e=this.chat.getSelection(),i=e.focusNode,s=this.findNode(i);return s&&__privateMethod(this,_ChatEditor_instances,cursorChange_fn).call(this,{type:s.type,node:s.$el.children[0].childNodes[0],offset:e.focusOffset,instance:s}),await this.chat.nextTick(),this.isComposition||(null==s||s.updateNode(),__privateMethod(this,_ChatEditor_instances,ruleMaxLength_fn).call(this),this.chat.deviceInfo.isPc&&t&&!this.historyLoading&&this.bus.emit(EVENT_EDITOR_HISTORY)),s&&this.cursorView(),this.bus.emit(EVENT_COMMON_CHANGE),s&&"Write"===s.type&&this.bus.emit(this.isComposition?EVENT_DIALOG_UPDATE_REACT:EVENT_DIALOG_MATCH),!0},cursorChange_fn=function(t){if(!t){const e=this.chat.getSelection(),i=e.focusNode,s=this.findNode(i);if(!s)return;"Write"===s.type?t={type:s.type,node:s.$el.children[0].childNodes[0],offset:e.focusOffset,instance:s}:"Input"===s.type&&(t={type:s.type,node:s.$el.children[0].children[0].childNodes[0],offset:e.focusOffset,instance:s})}if(t)switch(t.type){case"Write":this.markCursorWrite.node=t.node,this.markCursorWrite.offset=t.offset,this.markCursorWrite.instance=t.instance,this.markLastType="Write";break;case"Input":this.markCursorInput.node=t.node,this.markCursorInput.offset=t.offset,this.markCursorInput.instance=t.instance,this.markLastType="Input"}},ruleMaxLength_fn=function(){const t=this.chat.options.maxLength;if(-1===t)return;let e=0;const i=[];if(this.NODES.forEach((t,s)=>{let n=0;n=s>0&&1===t.children.length&&0===t.children[0].text.length?1:t.$el.textContent.replace(new RegExp("\ufeff","ig"),"").length,i.push(n),e+=n}),e>t){const s=e-t;let n=0,o=0;for(let t=i.length-1;t>=0;t--)if(n+=i[t],n>=s){o=t;break}this.NODES.slice(o+1).forEach(t=>{t.deleteNode()});let a=n-s;const c=this.NODES[o];if(0===a&&o>0){c.deleteNode();const e=this.NODES[o-1];return e.children[e.children.length-1].focus(-1),void(this.textLength=t)}let h=null,l=0;for(let t=0;t<c.children.length;t++){const e=c.children[t];if("Write"===e.type?a-=e.text.length:a-=e.$el.textContent.length,a<=0){h=e,l=t;break}}if(c.children.slice(l+1).forEach(t=>{t.deleteNode()}),"Write"===h.type){const e=h;e.text=e.text.slice(0,e.text.length-Math.abs(a)),e.syncNode(),e.updateNode(),e.focus(-1),this.textLength=t}else{const e=c.children[l-1];h.deleteNode(),e.ruleBRTag(),e.focus(-1),this.textLength=t-Math.abs(a)}}else this.textLength=e};class Bus{constructor(){__privateAdd(this,_handles),__privateAdd(this,_eventMapKey),__privateSet(this,_handles,Object.create(null)),__privateSet(this,_eventMapKey,Object.create(null))}on(t,e,i){Reflect.get(__privateGet(this,_handles),e)||Reflect.set(__privateGet(this,_handles),e,Object.create(null)),Reflect.get(__privateGet(this,_eventMapKey),t)||Reflect.set(__privateGet(this,_eventMapKey),t,[]),Reflect.get(__privateGet(this,_eventMapKey),t).push(e),Reflect.set(Reflect.get(__privateGet(this,_handles),e),t,i)}emit(...t){const e=t[0],i=t.slice(1),s=Reflect.get(__privateGet(this,_handles),e);s&&Reflect.ownKeys(s).forEach(t=>{Reflect.get(s,t)(...i)})}off(t,e){const i=Reflect.get(__privateGet(this,_handles),e);Reflect.ownKeys(i).forEach(e=>{t===e&&Reflect.deleteProperty(i,e)}),0===Reflect.ownKeys(i).length&&Reflect.deleteProperty(__privateGet(this,_handles),e)}offKeyEvent(t){(Reflect.get(__privateGet(this,_eventMapKey),t)||[]).forEach(e=>{this.off(t,e)}),Reflect.deleteProperty(__privateGet(this,_eventMapKey),t)}}_handles=new WeakMap,_eventMapKey=new WeakMap;class Component extends Tag{constructor(t){var e;super(t.type,t.context),__privateAdd(this,_Component_instances),__publicField(this,"data",{}),__privateAdd(this,_syncElms,{}),this.data=t.data||{},this.$el=document.createElement("span"),this.$el.setAttribute("data-set-richType",RICH_COMPONENT),this.$el.setAttribute("contenteditable","false"),this.$el.classList.add("chat-tag-wrap"),this.$el.innerHTML=this.render(),__privateMethod(this,_Component_instances,findEventNodes_fn).call(this,this.$el),this.mount({parentElm:(null==(e=t.config)?void 0:e.parentElm)||this.context.$el,targetElm:this.$el,...t.config||{}})}remove(){this.deleteRelevanceNode(),__privateMethod(this,_Component_instances,emit_fn4).call(this,EVENT_EDITOR_CHANGE)}render(){return"undefined"}}_syncElms=new WeakMap,_Component_instances=new WeakSet,emit_fn4=function(t,...e){this.context.context.bus.emit(t,...e)},findEventNodes_fn=function(t,e=""){Array.from(t.children,(t,i)=>{const s=String(""===e?i:e+"-"+i);t.children&&t.children.length>0&&__privateMethod(this,_Component_instances,findEventNodes_fn).call(this,t,s);const n=t,o=n.dataset||{};if(o){o.update&&(__privateGet(this,_syncElms)[s]=n,n.removeAttribute("data-update"),delete o.update);for(const t in o){const e=o[t];n.addEventListener(t,t=>{const i=this[e](t);i instanceof Promise?i.then(()=>{__privateMethod(this,_Component_instances,syncNode_fn).call(this)}):__privateMethod(this,_Component_instances,syncNode_fn).call(this)}),n.removeAttribute("data-"+t)}}})},syncNode_fn=function(){const t=document.createElement("span");t.innerHTML=this.render();for(let e in __privateGet(this,_syncElms)){const i=e.split("-");__privateGet(this,_syncElms)[e].innerHTML=__privateMethod(this,_Component_instances,getChainElm_fn).call(this,t,i)}},getChainElm_fn=function(t,e){return 1===e.length?t.children[Number(e[0])].innerHTML:__privateMethod(this,_Component_instances,getChainElm_fn).call(this,t.children[Number(e[0])],e.slice(1))};class XSender{constructor(t,e){switch(__publicField(this,"options"),__publicField(this,"deviceInfo",os()),__publicField(this,"chatElement"),__publicField(this,"chatEditor"),__publicField(this,"bus"),this.options=Object.assign({},DEFAULT_OPTIONS,e||{},{mentionConfig:void 0}),this.deviceInfo.isTablet&&(this.deviceInfo.isPc=!1),this.options.device){case"pc":this.deviceInfo.isPc=!0;break;case"h5":this.deviceInfo.isPc=!1}this.bus=new Bus,this.chatElement=new ChatElement(t,this),this.chatEditor=new ChatEditor(this),this.updateConfig(e)}updateConfig(t){unEmpty(t.placeholder)&&this.chatElement.updatePlaceholder(t.placeholder),unEmpty(t.chatStyle)&&this.chatElement.updateChatStyle(t.chatStyle),unEmpty(t.maxLength)&&(this.options.maxLength=t.maxLength<=0?-1:t.maxLength,this.bus.emit(EVENT_EDITOR_MAXLENGTH)),unEmpty(t.keyboardWrapFun)&&(this.options.keyboardWrapFun=t.keyboardWrapFun),unEmpty(t.keyboardSendFun)&&(this.options.keyboardSendFun=t.keyboardSendFun),unEmpty(t.mentionConfig)&&(this.options.mentionConfig=Object.assign({},this.options.mentionConfig||DEFAULT_MENTION_OPTIONS,t.mentionConfig),this.chatElement.createMentionDialog()),unEmpty(t.triggerConfig)&&(this.options.triggerConfig=t.triggerConfig.map(t=>(t.keyMap||(t.keyMap=KEY_CODE_MAP[t.key]||[]),t)),this.chatElement.createTriggerDialog()),unEmpty(t.selectConfig)&&(this.options.selectConfig=t.selectConfig,this.chatElement.createSelectDialog()),unEmpty(t.tipConfig)&&(this.options.tipConfig=Object.assign({},DEFAULT_TIP_OPTIONS,t.tipConfig),this.chatElement.createBeforeTip())}async nextTick(t){return new Promise(e=>{requestAnimationFrame(()=>{if(!t)return void e();const i=t();i instanceof Promise?i.then(()=>{e()}):e()})})}getSelection(){return window.getSelection()}getModel(){return this.chatEditor.compileNodes(this.chatEditor.NODES)}getHtml(t){const e=Object.assign({},{saveTagData:!1,identifyLink:!1},t||{}),i=/(https?|http|ftp|file):\/\/[-A-Za-z0-9+&@#/%?=~_|!:,.;]+[-A-Za-z0-9+&@#/%=~_|]/g,s=this.getModel();let n="",o="";return s.forEach((t,s)=>{let a='<p class="chat-tag-grid">';t.forEach((t,n)=>{let c="<span ";switch(t.type){case"Mention":c+='class="chat-tag-mention"',e.saveTagData&&(c+=` data-id="${t.id}"`),c+=`>@${escapeHtml(t.name)}`;break;case"Trigger":c+='class="chat-tag-trigger"',e.saveTagData&&(c+=` data-id="${t.id}" data-key=${t.key}`),c+=`>${t.key}${escapeHtml(t.name)}`;break;case"Select":c+='class="chat-tag-select"',e.saveTagData&&(c+=` data-id="${t.id}" data-key=${t.key}`),c+=`>${escapeHtml(t.name)}`;break;case"Input":c+='class="chat-tag-input"',e.saveTagData&&(c+=` data-placeholder="${t.placeholder}" data-key=${t.key}`),c+=`>${escapeHtml(t.text||t.placeholder)}`;break;case"Custom":c+='class="chat-tag-custom"',c+=`>${t.html}`;break;case"Write":c+='class="chat-tag-write"',o=escapeHtml(t.text),e.identifyLink?c+=`>${o.replace(i,t=>`<a class="chat-tag-link" href="${t}" target="_blank">${t}</a>`)}`:c+=`>${o}`;break;default:const a=this.chatEditor.NODES[s].children[n];if(c+='class="chat-tag-component"',e.saveTagData){for(const t in a.data)c+=` data-${t}="${a.data[t]}"`;c+=` data-type="${a.type}"`}c+=`>${a.$el.innerHTML}`}c+="</span>",a+=c}),a+="</p>",n+=a}),n}getText(){let t="";return this.getModel().forEach((e,i)=>{0!==i&&(t+="\n"),e.forEach((e,s)=>{switch(e.type){case"Write":t+=e.text;break;case"Input":t+=e.text||`[${e.placeholder}]`;break;default:t+=this.chatEditor.NODES[i].children[s].$el.textContent||""}})}),t.replace(new RegExp(`\ufeff|${"\n"[0]}`,"ig"),"")}getTagData(){const t={mention:[],trigger:{},select:{},input:{}},e={mention:new Map,trigger:{},select:{}};return this.getModel().forEach(i=>{i.forEach(i=>{switch(i.type){case"Mention":e.mention.set(i.id,{id:i.id,name:i.name});break;case"Trigger":e.trigger[i.key]||(e.trigger[i.key]=new Map),e.trigger[i.key].set(i.id,{id:i.id,name:i.name});break;case"Select":e.select[i.key]||(e.select[i.key]=new Map),i.id&&i.id.split(",").length>0?i.id.split(",").forEach((t,s)=>{e.select[i.key].set(t,{id:t,name:i.name.split("、")[s]})}):e.select[i.key].set(i.id,{id:i.id,name:i.name});break;case"Input":t.input[i.key]||(t.input[i.key]=[]),t.input[i.key].push({text:i.text||"",placeholder:i.placeholder||""})}})}),t.mention=Array.from(e.mention.values()),Object.keys(e.trigger).forEach(i=>{t.trigger[i]=Array.from(e.trigger[i].values())}),Object.keys(e.select).forEach(i=>{t.select[i]=Array.from(e.select[i].values())}),t}setLineBreak(){return new Promise(t=>{this.bus.emit(EVENT_EDITOR_LINE_BREAK,t)})}async setHtml(t){return new Promise(e=>{this.bus.emit(EVENT_EDITOR_INSERT_CUSTOM,{html:`<span style="display: inline-block;">${replaceBlockTagsWithSpan(t)}</span>`},e)})}async setText(t){switch(this.chatEditor.markLastType){case"Write":await this.chatEditor.insertText(t);break;case"Input":await this.chatEditor.insertInputText(t)}}async setMention(t){return new Promise(e=>{this.bus.emit(EVENT_EDITOR_INSERT_MENTION,t,e)})}async setTrigger(t){return new Promise(e=>{this.bus.emit(EVENT_EDITOR_INSERT_TRIGGER,t,e)})}async setSelect(t){return new Promise(e=>{this.bus.emit(EVENT_EDITOR_INSERT_SELECT,t,e)})}async setInput(t){return new Promise(e=>{this.bus.emit(EVENT_EDITOR_INSERT_INPUT,t,e)})}async setChatNode(t){await this.chatEditor.insertNodes(t)}removeMention(t){return new Promise(e=>{const i=[];this.chatEditor.NODES.forEach(e=>{e.children.forEach(e=>{const s=e;"Mention"!==s.type||t&&!t.includes(s.id)||i.push(s)})}),i.forEach(t=>{t.deleteRelevanceNode()}),this.bus.emit(EVENT_EDITOR_CHANGE,e)})}removeTrigger(t,e){return new Promise(i=>{const s=[];this.chatEditor.NODES.forEach(i=>{i.children.forEach(i=>{const n=i;"Trigger"!==n.type||n.key!==t||e&&!e.includes(n.id)||s.push(n)})}),s.forEach(t=>{t.deleteRelevanceNode()}),this.bus.emit(EVENT_EDITOR_CHANGE,i)})}removeSelect(t,e){return new Promise(i=>{const s=[];this.chatEditor.NODES.forEach(i=>{i.children.forEach(i=>{const n=i;"Select"!==n.type||n.key!==t||e&&!e.includes(n.id)||s.push(n)})}),s.forEach(t=>{t.deleteRelevanceNode()}),this.bus.emit(EVENT_EDITOR_CHANGE,i)})}removeInput(t){return new Promise(e=>{const i=[];this.chatEditor.NODES.forEach(e=>{e.children.forEach(e=>{const s=e;"Input"===s.type&&s.key===t&&i.push(s)})}),i.forEach(t=>{t.deleteRelevanceTag()}),this.bus.emit(EVENT_EDITOR_CHANGE,e)})}async reverseHtml(t,e=!1){let i=document.createElement("div");i.innerHTML=t;const s=[];Array.from(i.children,t=>{const e=[];Array.from(t.children,t=>{const i=t;switch(i.className){case"chat-tag-write":e.push({type:"Write",text:i.textContent});break;case"chat-tag-mention":e.push({type:"Mention",id:i.dataset.id||"",name:(i.textContent||"").slice(1)});break;case"chat-tag-trigger":e.push({type:"Trigger",key:i.dataset.key||"",id:i.dataset.id||"",name:(i.textContent||"").slice(1)});break;case"chat-tag-select":e.push({type:"Select",key:i.dataset.key||"",id:i.dataset.id||"",name:i.textContent});break;case"chat-tag-input":e.push({type:"Input",key:i.dataset.key||"",text:i.textContent,placeholder:i.dataset.placeholder||""});break;case"chat-tag-custom":e.push({type:"Custom",html:i.innerHTML});break;case"chat-tag-component":const t=i.dataset.type,s=i.dataset;"type"in s&&delete s.type,e.push({type:t,data:s})}}),s.push(e)}),e?(this.chatEditor.focusLast(),await this.chatEditor.insertNodes(s)):await this.chatEditor.fixEditor(s)}undo(){return new Promise(t=>{this.bus.emit(EVENT_EDITOR_UNDO,t)})}redo(){return new Promise(t=>{this.bus.emit(EVENT_EDITOR_REDO,t)})}jumpPrev(t="end"){this.bus.emit(EVENT_EDITOR_CURSOR_CHANGE);const e=this.getCurrentNode().instance,i=e.context,s=i.children.indexOf(e),n=[...i.children.slice(0,s)].reverse().find(t=>"Write"===t.type||"Input"===t.type);if(n)return void n.focus("start"===t?0:-1);const o=i.context.NODES.indexOf(i);let a;[...this.chatEditor.NODES.slice(0,o)].reverse().some(t=>[...t.children].reverse().some(t=>{if("Write"===t.type||"Input"===t.type)return a=t,!0})),a?a.focus("start"===t?0:-1):this.focus("first")}jumpNext(t="end"){this.bus.emit(EVENT_EDITOR_CURSOR_CHANGE);const e=this.getCurrentNode().instance,i=e.context,s=i.children.indexOf(e),n=i.children.slice(s+1).find(t=>"Write"===t.type||"Input"===t.type);if(n)return void n.focus("start"===t?0:-1);const o=i.context.NODES.indexOf(i);let a;this.chatEditor.NODES.slice(o+1).some(t=>t.children.some(t=>{if("Write"===t.type||"Input"===t.type)return a=t,!0})),a?a.focus("start"===t?0:-1):this.focus("last")}move(t){this.chatEditor.focusMark(),0!==t&&this.chatEditor.cursorMove(t)}backspace(t){return new Promise(e=>{if(this.chatEditor.focusMark(),0===t)return e();if(-1===t||1===t)return void this.bus.emit(EVENT_EDITOR_DELETE,t>0,e);const i=this.getSelection(),s=i.focusNode,n=i.focusOffset;this.chatEditor.cursorMove(t);const o=this.getSelection(),a=o.focusNode,c=o.focusOffset,h=new Range,l=t<0;l?(h.setStart(a,c),h.setEnd(s,n)):(h.setStart(s,n),h.setEnd(a,c)),o.removeAllRanges(),o.addRange(h),this.bus.emit(EVENT_EDITOR_DELETE,!l,e)})}focus(t="last"){this.bus.emit(EVENT_EDITOR_FOCUS,t)}disable(){this.chatElement.richText.setAttribute("contenteditable","false"),this.chatElement.rollBox.classList.add("disabled")}enable(){this.chatElement.richText.setAttribute("contenteditable","true"),this.chatElement.rollBox.classList.remove("disabled"),this.focus()}async reset(t){const e=Object.assign({},{clearHistory:!0,chatNode:[[{type:"Write",text:""}]]},t||{});await this.chatEditor.reset(e)}isEmpty(t=!0){if(t)return 0===this.getText().trim().length;const e=this.chatEditor.NODES;return!(e.length>1)&&(!(e[0].children.length>1)&&e[0].children[0].text.length<=0)}destroy(){this.bus.emit(EVENT_COMMON_DESTROY);for(const t in this)delete this[t];Object.setPrototypeOf(this,Object.create(null))}showSelectPopup(t,e){this.bus.emit(EVENT_COMMON_SELECT_ACTIVE,{key:t,$el:e})}showTip(t){this.bus.emit(EVENT_TIP_OPEN,t)}closeTip(){this.bus.emit(EVENT_TIP_CLOSE)}getCurrentNode(){switch(this.chatEditor.markLastType){case"Input":return this.chatEditor.markCursorInput;case"Write":return this.chatEditor.markCursorWrite}}useComponent(t,e){this.chatEditor.useComponent(t,e)}async setComponent(t,e){await this.chatEditor.insertComponent(t,e)}}__publicField(XSender,"version","1.3.1"),__publicField(XSender,"EventSet",{EVENT_COMMON_SEND:EVENT_COMMON_SEND,EVENT_COMMON_CHANGE:EVENT_COMMON_CHANGE,EVENT_COMMON_DESTROY:EVENT_COMMON_DESTROY,EVENT_COMMON_TIP_STATE:EVENT_COMMON_TIP_STATE,EVENT_COMMON_DIALOG_CLOSE:EVENT_COMMON_DIALOG_CLOSE,EVENT_COMMON_SELECT_ACTIVE:EVENT_COMMON_SELECT_ACTIVE,EVENT_EDITOR_INSERT_MENTION:EVENT_EDITOR_INSERT_MENTION,EVENT_EDITOR_INSERT_TRIGGER:EVENT_EDITOR_INSERT_TRIGGER,EVENT_EDITOR_INSERT_SELECT:EVENT_EDITOR_INSERT_SELECT,EVENT_EDITOR_INSERT_INPUT:EVENT_EDITOR_INSERT_INPUT,EVENT_EDITOR_INSERT_CUSTOM:EVENT_EDITOR_INSERT_CUSTOM}),__publicField(XSender,"Component",Component);export{XSender as default};
|
package/lib/XSender.umd.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).XSender=e()}(this,function(){"use strict";var t,e,i,s,a,n,o,c,h,r,l,d,p,g,u,f,m,x,y,w,v,b,E,k,C,N,O,D,T,S,L,$,M,A,W,I,R,B,P,H,K,z,_,F,Y,j,V,G,U,Z,q,X,J,Q,tt,et,it,st=Object.defineProperty,at=t=>{throw TypeError(t)},nt=(t,e,i)=>((t,e,i)=>e in t?st(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i)(t,"symbol"!=typeof e?e+"":e,i),ot=(t,e,i)=>e.has(t)||at("Cannot "+i),ct=(t,e,i)=>(ot(t,e,"read from private field"),i?i.call(t):e.get(t)),ht=(t,e,i)=>e.has(t)?at("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(t):e.set(t,i),rt=(t,e,i,s)=>(ot(t,e,"write to private field"),s?s.call(t,i):e.set(t,i),i),lt=(t,e,i)=>(ot(t,e,"access private method"),i),dt=document.createElement("style");dt.textContent=':root{--chat-primary: #1890ff;--chat-disabled: #e8e8e8;--chat-highlight: #40A9FF;--chat-text: #333;--chat-text-assistant: #666;--chat-text-secondary: #ccc;--chat-text-placeholder: #bfbfbf;--chat-box: #fff;--chat-box-shadow: 1px 3px 10px 2px rgba(6, 21, 50, .2);--chat-box-mark: rgba(0, 0, 0, .5);--chat-input: #FFFFFF;--chat-input-border: #D9D9D9;--chat-input-shadow-color: rgba(24, 144, 255, .2);--chat-card: #F2F6FC;--chat-highlight-card: #E6F7FF;--chat-popover: #000;--chat-popover-text: #fff;--chat-rect-padding: 10px;--chat-before-tip-width: 0px;--chat-before-tip-top: 0px;--chat-tip-dialog-top: 0px;--chat-tip-dialog-left: 0px}@-webkit-keyframes antSpinMove{to{opacity:1}}@keyframes antSpinMove{to{opacity:1}}@-webkit-keyframes antRotate{to{transform:rotate(405deg)}}@keyframes antRotate{to{transform:rotate(405deg)}}.ant-spin{font-size:14px;line-height:1.5;list-style:none;font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica Neue,Arial,Noto Sans,sans-serif,"Apple Color Emoji","Segoe UI Emoji",Segoe UI Symbol,"Noto Color Emoji";position:absolute;display:none;text-align:center;vertical-align:middle;opacity:0;transition:transform .3s cubic-bezier(.78,.14,.15,.86)}.ant-spin .ant-spin-dot{position:relative;display:inline-block;font-size:20px;width:1em;height:1em}.ant-spin .ant-spin-dot-spin{transform:rotate(45deg);animation-name:antRotate;animation-duration:1.2s;animation-iteration-count:infinite;animation-timing-function:linear}.ant-spin .ant-spin-dot-item{position:absolute;display:block;width:9px;height:9px;background-color:var(--chat-primary);border-radius:100%;transform:scale(.75);transform-origin:50% 50%;opacity:.3;animation-name:antSpinMove;animation-duration:1s;animation-iteration-count:infinite;animation-timing-function:linear;animation-direction:alternate}.ant-spin .ant-spin-dot-item:nth-child(1){top:0;inset-inline-start:0}.ant-spin .ant-spin-dot-item:nth-child(2){top:0;inset-inline-end:0;animation-delay:.4s}.ant-spin .ant-spin-dot-item:nth-child(3){inset-inline-end:0;bottom:0;animation-delay:.8s}.ant-spin .ant-spin-dot-item:nth-child(4){bottom:0;inset-inline-start:0;animation-delay:1.2s}.ant-spin-spinning{position:static;display:inline-block;opacity:1}.chat-area-wrap{position:relative;z-index:10;font-size:16px}.chat-area-wrap *{margin:0;padding:0;box-sizing:border-box;outline:none;text-indent:0;-moz-osx-font-smoothing:grayscale;-webkit-font-smoothing:antialiased;text-rendering:optimizeLegibility}.chat-rich-text{position:relative;width:100%;padding:var(--chat-rect-padding);margin:0;background:transparent;box-sizing:border-box;overflow-x:hidden;overflow-y:auto;font-size:16px;color:var(--chat-text);vertical-align:text-bottom;white-space:pre-wrap;word-break:break-all}.chat-rich-text.disabled{cursor:not-allowed}.chat-rich-text.disabled *{pointer-events:none}.chat-rich-text .chat-grid-wrap:first-child>*:first-child{padding-left:var(--chat-before-tip-width)}.chat-dialog-wrap{position:absolute;top:0;left:0;z-index:21;width:100%;height:0;pointer-events:none}@keyframes chat-dialog-show{0%{transform:scale(.6);opacity:.4}to{opacity:1;transform:scale(1)}}.chat-dialog-wrap .chat-mention-dialog-wrap{position:absolute;z-index:11;border-radius:4px;padding:4px;overflow:hidden;background:var(--chat-box);box-shadow:var(--chat-box-shadow);pointer-events:visible}.chat-dialog-wrap .chat-mention-dialog-wrap.chat-view-show{animation:chat-dialog-show .2s ease}.chat-dialog-wrap .chat-mention-dialog-wrap .chat-mention-dialog-header{padding:6px 4px;width:100%;color:var(--chat-text);font-weight:700;font-size:14px}.chat-dialog-wrap .chat-mention-dialog-wrap .chat-mention-dialog-main{min-width:180px;max-height:240px;overflow-y:auto}.chat-dialog-wrap .chat-mention-dialog-wrap .chat-mention-dialog-main .chat-mention-dialog-item{display:flex;align-items:center;color:var(--chat-text-secondary);background:transparent;cursor:pointer;padding:4px;transition:all .3s ease;font-weight:700;font-size:14px;border-radius:4px}.chat-dialog-wrap .chat-mention-dialog-wrap .chat-mention-dialog-main .chat-mention-dialog-item .chat-mention-dialog-item-avatar{flex-shrink:0;display:flex;align-items:center;justify-content:center;width:24px;height:24px;margin-right:8px;border-radius:4px;overflow:hidden;background:var(--chat-primary);color:var(--chat-box);white-space:nowrap;font-size:12px}.chat-dialog-wrap .chat-mention-dialog-wrap .chat-mention-dialog-main .chat-mention-dialog-item .chat-mention-dialog-item-avatar.have-avatar{background:var(--chat-box)}.chat-dialog-wrap .chat-mention-dialog-wrap .chat-mention-dialog-main .chat-mention-dialog-item .chat-mention-dialog-item-avatar.have-avatar img{width:100%;height:100%;object-fit:cover}.chat-dialog-wrap .chat-mention-dialog-wrap .chat-mention-dialog-main .chat-mention-dialog-item .chat-mention-dialog-item-avatar .chat-mention-dialog-item-avatar-loading{position:relative;top:2px;transform:scale(.75)}.chat-dialog-wrap .chat-mention-dialog-wrap .chat-mention-dialog-main .chat-mention-dialog-item .chat-mention-dialog-item-avatar .chat-mention-dialog-item-avatar-text{position:relative;top:-1px;transform:scale(.75);font-size:12px}.chat-dialog-wrap .chat-mention-dialog-wrap .chat-mention-dialog-main .chat-mention-dialog-item .chat-mention-dialog-item-name{flex:1;white-space:nowrap;line-height:24px;overflow:hidden;text-overflow:ellipsis;padding-right:10px;font-size:14px;transition:all .3s ease;color:var(--chat-text-secondary)}.chat-dialog-wrap .chat-mention-dialog-wrap .chat-mention-dialog-main .chat-mention-dialog-item:hover{background:var(--chat-card);opacity:.7}.chat-dialog-wrap .chat-mention-dialog-wrap .chat-mention-dialog-main .chat-mention-dialog-item:hover .chat-mention-dialog-item-name{color:var(--chat-primary)}.chat-dialog-wrap .chat-mention-dialog-wrap .chat-mention-dialog-main .chat-mention-dialog-item.active{background:var(--chat-card);opacity:1}.chat-dialog-wrap .chat-mention-dialog-wrap .chat-mention-dialog-main .chat-mention-dialog-item.active .chat-mention-dialog-item-name{color:var(--chat-primary)}.chat-dialog-wrap .chat-mention-dialog-wrap .chat-mention-dialog-empty{display:flex;align-items:center;flex-direction:column;justify-content:center;padding:10px 0}.chat-dialog-wrap .chat-mention-dialog-wrap .chat-mention-dialog-empty .match-empty-svg{width:auto;height:40px;margin-bottom:2px}.chat-dialog-wrap .chat-mention-dialog-wrap .chat-mention-dialog-empty .empty-label{font-size:12px;color:var(--chat-text-secondary)}.chat-dialog-wrap .chat-mention-dialog-wrap .chat-mention-dialog-loading{display:flex;align-items:center;flex-direction:column;justify-content:center;padding:16px}.chat-dialog-wrap .chat-trigger-dialog-wrap{position:absolute;z-index:10;border-radius:4px;padding:4px;overflow:hidden;background:var(--chat-box);box-shadow:var(--chat-box-shadow);pointer-events:visible}.chat-dialog-wrap .chat-trigger-dialog-wrap.chat-view-show{animation:chat-dialog-show .2s ease}.chat-dialog-wrap .chat-trigger-dialog-wrap .chat-trigger-dialog-header{padding:6px 4px;width:100%;color:var(--chat-text);font-weight:700;font-size:14px}.chat-dialog-wrap .chat-trigger-dialog-wrap .chat-trigger-dialog-main{min-width:180px;max-height:240px;overflow-y:auto}.chat-dialog-wrap .chat-trigger-dialog-wrap .chat-trigger-dialog-main .chat-trigger-dialog-item{display:flex;align-items:center;color:var(--chat-text-secondary);background:transparent;cursor:pointer;padding:4px;transition:all .3s ease;font-weight:700;font-size:14px;border-radius:4px}.chat-dialog-wrap .chat-trigger-dialog-wrap .chat-trigger-dialog-main .chat-trigger-dialog-item .chat-trigger-dialog-item-name{flex:1;white-space:nowrap;line-height:24px;overflow:hidden;text-overflow:ellipsis;padding-right:10px;font-size:14px;transition:all .3s ease;color:var(--chat-text-secondary)}.chat-dialog-wrap .chat-trigger-dialog-wrap .chat-trigger-dialog-main .chat-trigger-dialog-item:hover{background:var(--chat-card);opacity:.7}.chat-dialog-wrap .chat-trigger-dialog-wrap .chat-trigger-dialog-main .chat-trigger-dialog-item:hover .chat-trigger-dialog-item-name{color:var(--chat-primary)}.chat-dialog-wrap .chat-trigger-dialog-wrap .chat-trigger-dialog-main .chat-trigger-dialog-item.active{background:var(--chat-card);opacity:1}.chat-dialog-wrap .chat-trigger-dialog-wrap .chat-trigger-dialog-main .chat-trigger-dialog-item.active .chat-trigger-dialog-item-name{color:var(--chat-primary)}.chat-dialog-wrap .chat-select-dialog-wrap{position:fixed;z-index:21;padding:4px;border-radius:4px;box-sizing:border-box;background:var(--chat-box);box-shadow:var(--chat-box-shadow);pointer-events:visible}.chat-dialog-wrap .chat-select-dialog-wrap .chat-select-dialog-header{display:flex;align-items:center;justify-content:space-between;background:var(--chat-box);padding:6px;color:var(--chat-text);font-weight:700;font-size:14px}.chat-dialog-wrap .chat-select-dialog-wrap .chat-select-dialog-search{margin-bottom:6px;display:flex;flex-direction:column;align-items:center;justify-content:center}.chat-dialog-wrap .chat-select-dialog-wrap .chat-select-dialog-search .chat-select-dialog-search-input{width:calc(100% - 12px);padding:4px 10px;height:32px;font-size:14px;color:var(--chat-text);line-height:1.5;border-width:1px;border-style:solid;border-color:var(--chat-input-border);border-radius:6px;outline:none;transition:border-color .3s cubic-bezier(.645,.045,.355,1),box-shadow .3s cubic-bezier(.645,.045,.355,1);background:var(--chat-input)}.chat-dialog-wrap .chat-select-dialog-wrap .chat-select-dialog-search .chat-select-dialog-search-input::-moz-placeholder{color:var(--chat-text-placeholder);opacity:1}.chat-dialog-wrap .chat-select-dialog-wrap .chat-select-dialog-search .chat-select-dialog-search-input:-ms-input-placeholder{color:var(--chat-text-placeholder)}.chat-dialog-wrap .chat-select-dialog-wrap .chat-select-dialog-search .chat-select-dialog-search-input::-webkit-input-placeholder{color:var(--chat-text-placeholder)}.chat-dialog-wrap .chat-select-dialog-wrap .chat-select-dialog-search .chat-select-dialog-search-input:hover{border-color:var(--chat-highlight)}.chat-dialog-wrap .chat-select-dialog-wrap .chat-select-dialog-search .chat-select-dialog-search-input:focus,.chat-dialog-wrap .chat-select-dialog-wrap .chat-select-dialog-search .chat-select-dialog-search-input:active{border-color:var(--chat-primary);box-shadow:0 0 0 2px var(--chat-input-shadow-color)}.chat-dialog-wrap .chat-select-dialog-wrap .chat-select-dialog-search .chat-select-dialog-search-empty{display:flex;align-items:center;flex-direction:column;justify-content:center;padding:10px 0}.chat-dialog-wrap .chat-select-dialog-wrap .chat-select-dialog-search .chat-select-dialog-search-empty .match-empty-svg{width:auto;height:40px;margin-bottom:2px}.chat-dialog-wrap .chat-select-dialog-wrap .chat-select-dialog-search .chat-select-dialog-search-empty .empty-label{font-size:12px;color:var(--chat-text-secondary)}.chat-dialog-wrap .chat-select-dialog-wrap .chat-select-dialog-main{position:relative;z-index:3;max-height:280px;overflow-y:auto}.chat-dialog-wrap .chat-select-dialog-wrap .chat-select-dialog-main .chat-select-dialog-item{display:flex;align-items:center;min-width:180px;color:var(--chat-text-secondary);background:transparent;cursor:pointer;padding:8px;transition:all .3s ease;font-weight:700;font-size:14px;border-radius:6px;min-height:42px}.chat-dialog-wrap .chat-select-dialog-wrap .chat-select-dialog-main .chat-select-dialog-item .chat-select-dialog-preview{flex-shrink:0;width:42px;height:42px;border-radius:6px;margin-right:12px}.chat-dialog-wrap .chat-select-dialog-wrap .chat-select-dialog-main .chat-select-dialog-item .chat-select-dialog-preview.loading{display:flex;align-items:center;justify-content:center}.chat-dialog-wrap .chat-select-dialog-wrap .chat-select-dialog-main .chat-select-dialog-item .chat-select-dialog-preview.loading .ant-spin{position:relative;top:2px;transform:scale(.75)}.chat-dialog-wrap .chat-select-dialog-wrap .chat-select-dialog-main .chat-select-dialog-item .chat-select-dialog-name{flex:1;transition:all .3s ease;color:var(--chat-text-secondary)}.chat-dialog-wrap .chat-select-dialog-wrap .chat-select-dialog-main .chat-select-dialog-item .chat-select-dialog-check{flex-shrink:0;display:inline-block;margin-left:6px;font-size:18px;color:var(--chat-primary)}.chat-dialog-wrap .chat-select-dialog-wrap .chat-select-dialog-main .chat-select-dialog-item:hover{background:var(--chat-card);opacity:.8}.chat-dialog-wrap .chat-select-dialog-wrap .chat-select-dialog-main .chat-select-dialog-item:hover .chat-select-dialog-name{color:var(--chat-primary)}.chat-dialog-wrap .chat-select-dialog-wrap .chat-select-dialog-arrow{position:absolute;z-index:2;pointer-events:none;width:16px;height:16px;overflow:hidden}.chat-dialog-wrap .chat-select-dialog-wrap .chat-select-dialog-arrow:before{box-sizing:border-box;background:var(--chat-box);position:absolute;bottom:0;inset-inline-start:0;width:16px;height:8px;-webkit-clip-path:path("M 0 8 A 4 4 0 0 0 2.828 6.828 L 6.586 3.071 A 2 2 0 0 1 9.414 3.071 L 13.172 6.828 A 4 4 0 0 0 16 8 Z");clip-path:path("M 0 8 A 4 4 0 0 0 2.828 6.828 L 6.586 3.071 A 2 2 0 0 1 9.414 3.071 L 13.172 6.828 A 4 4 0 0 0 16 8 Z");content:""}.chat-dialog-wrap .chat-select-dialog-wrap .chat-select-dialog-arrow:after{box-sizing:border-box;content:"";position:absolute;width:9px;height:9px;bottom:0;inset-inline:0;margin:auto;border-radius:0 0 2px;transform:translateY(50%) rotate(-135deg);box-shadow:var(--chat-box-shadow);z-index:0;background:transparent;opacity:.25}.chat-scroll{overflow-y:auto;overflow-x:hidden}.chat-scroll::-webkit-scrollbar{width:6px;height:6px}.chat-scroll::-webkit-scrollbar-thumb{border-radius:10px;box-shadow:inset 0 0 5px #61b8b31a;background-color:#0003}.chat-scroll::-webkit-scrollbar-track{box-shadow:inset 0 0 5px #57afbb1a;border-radius:10px;background:#ededed}.chat-placeholder-wrap{position:absolute;top:0;left:0;width:100%;margin:0;padding:var(--chat-rect-padding) var(--chat-rect-padding) var(--chat-rect-padding) calc(var(--chat-rect-padding) + var(--chat-before-tip-width));box-sizing:border-box;color:var(--chat-text-placeholder);pointer-events:none;font-style:oblique;word-break:break-all;z-index:11}.chat-write-wrap,.chat-write-input{word-break:break-all}.chat-tag-grid{word-break:break-all;white-space:pre-wrap}.chat-tag-wrap{margin:0 1px;white-space:normal}.chat-tag-mention,.chat-tag-trigger{color:var(--chat-primary)}.chat-tag-select{display:inline-block;cursor:pointer;background:var(--chat-card);color:var(--chat-primary);padding:2px 6px;border-radius:10px;margin:2px;transition:all .3s ease}.chat-tag-select svg{margin-left:4px;font-size:12px;transition:all .3s ease}.chat-tag-select:hover{color:var(--chat-highlight);background:var(--chat-highlight-card)}.chat-tag-select.active svg{transform:rotate(-180deg)}.chat-tag-input{padding:2px 6px;border-radius:4px;margin:0 2px;color:var(--chat-primary);cursor:text;background:var(--chat-card);line-height:1.8}.chat-tag-input .input-write{white-space:pre-wrap;word-break:break-all;word-wrap:break-word;padding-left:.1px}.chat-tag-input .input-tip{pointer-events:none;-webkit-user-select:none;user-select:none;opacity:.35;word-break:break-all}.chat-tag-component{white-space:normal}.chat-before-tip-wrap{position:absolute;top:0;left:0;height:0;transform:translateY(var(--chat-before-tip-top));z-index:11;padding:var(--chat-rect-padding);pointer-events:none}.chat-before-tip-wrap>*{pointer-events:visible}.chat-before-tip-wrap.tip-hover .chat-before-tip-box{background:var(--chat-card)}.chat-before-tip-wrap.tip-hover .chat-before-tip-close{opacity:1}.chat-before-tip-wrap .chat-before-tip-box{cursor:pointer;padding:2px 6px;color:var(--chat-primary);border-radius:8px;transition:background .3s ease;font-size:18px;font-weight:700}.chat-before-tip-wrap .chat-before-tip-close{position:absolute;top:4px;right:4px;width:16px;height:16px;cursor:pointer;color:#999;transition:opacity .3s ease;opacity:0}.chat-tip-dialog-wrap{position:absolute;bottom:100%;transform:translate(var(--chat-tip-dialog-left),var(--chat-tip-dialog-top));pointer-events:none}.chat-tip-dialog-wrap>*{pointer-events:visible}.chat-tip-dialog-wrap .chat-tip-dialog-main{display:flex;align-items:center;color:var(--chat-popover-text);font-size:13px;padding:8px 10px;background:var(--chat-popover);border-radius:8px}.chat-tip-dialog-wrap .chat-tip-dialog-main .chat-tip-dialog-code{margin-left:4px;opacity:.7;font-size:12px}.chat-tip-dialog-wrap .chat-tip-dialog-arrow{position:absolute;width:10px;height:10px;bottom:-5px;left:50%;transform:translate(-50%) rotate(-45deg);overflow:hidden;background:var(--chat-popover);z-index:2}\n/*$vite$:1*/',document.head.appendChild(dt);const pt='<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>',gt='<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>',ut={device:"auto",autoFocus:!0,placeholder:"",maxLength:-1,keyboardWrapFun:t=>t.ctrlKey&&["Enter"].includes(t.key),keyboardSendFun:t=>!t.ctrlKey&&["Enter"].includes(t.key)},ft={dialogTitle:"群成员",callEvery:!0,everyText:"所有人",asyncMatch:void 0,emptyText:"暂无数据",options:[]},mt={"`":["`","~"],"~":["`","~"],1:["1","!"],"!":["1","!"],3:["3","#"],"#":["3","#"],4:["4","$"],$:["4","$"],5:["5","%"],"%":["5","%"],6:["6","^"],"^":["6","^"],7:["7","&"],"&":["7","&"],8:["8","*"],"*":["8","*"],";":[";",":"],":":[";",":"],"/":["/","?"],"?":["/","?"],"\\":["\\","|"],"|":["\\","|"]},xt={tipTemplate:'<div class="chat-before-tip-box">{{text}}</div><div class="chat-before-tip-close"><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></div>',dialogTemplate:'<div class="chat-tip-dialog-main"><span>{{dialogText}}</span><span class="chat-tip-dialog-code">ESC</span></div><div class="chat-tip-dialog-arrow"></div>',closeNames:["chat-before-tip-box","chat-before-tip-close"],offsetTop:0},yt="data-set-empty",wt="data-set-richType",vt="richGrid",bt="richMark",Et="richWrite",kt="richMention",Ct="richTrigger",Nt="richSelect",Ot="richInput",Dt="richCustom",Tt="richComponent",St="application/chat-nodes",Lt="\ufeff",$t=(t,e,i=!1)=>{let s;return function(...a){const n=this,o=i&&!s;clearTimeout(s),s=setTimeout(()=>{s=null,i||t.apply(n,a)},e),o&&t.apply(n,a)}},Mt=(t,e)=>{let i;return function(...s){const a=this;i||(t.apply(a,s),i=!0,setTimeout(function(){i=!1},e))}},At=t=>null!=t,Wt=(t,e)=>t.replace(/{{(\w+)}}/g,(t,i)=>void 0!==e[i]?e[i]:t);function It(t){return t.replace(/[&<>"']/g,t=>{switch(t){case"&":return"&";case"<":return"<";case">":return">";case'"':return""";case"'":return"'";default:return t}})}const Rt=t=>{const e=["address","article","aside","blockquote","canvas","dd","div","dl","dt","fieldset","figcaption","figure","footer","form","h1","h2","h3","h4","h5","h6","header","hgroup","hr","li","main","nav","noscript","ol","output","p","pre","section","table","tfoot","ul"],i=new RegExp(`<(${e.join("|")})([^>]*?)>`,"gi"),s=new RegExp(`</(${e.join("|")})>`,"gi");let a=t.replace(i,(t,e,i)=>{let s="",a="";if(i){const t=i.match(/style\s*=\s*["']([^"']*)["']/i);if(t){const e=t[1];s=e.match(/display\s*:/i)?`style="${e.replace(/display\s*:.*?;/gi,"display:block;")}"`:`style="display:block;${e}"`,a=i.replace(/style\s*=\s*["']([^"']*)["']/i,"").trim()}else s='style="display:block"',a=i.trim()}else s='style="display:block"';return`<span ${[a,s].filter(Boolean).join(" ")}>`.replace(/\s+/g," ").replace(/ >/,">")});return a=a.replace(s,"</span>"),a};function Bt(t,e){switch(e){case"text-jump":return"Tab"===t.key||"Tab"===t.code;case"text-backspace":return"Backspace"===t.key||"Backspace"===t.code;case"text-delete":return"Delete"===t.code||"Delete"===t.key;case"text-move":return"ArrowLeft"===t.key||"ArrowRight"===t.key||"ArrowLeft"===t.code||"ArrowRight"===t.code;case"text-select-all":return(t.ctrlKey||t.metaKey)&&("A"===t.key||"a"===t.key||"KeyA"===t.code);case"text-undo":return(t.ctrlKey||t.metaKey)&&("Z"===t.key||"z"===t.key||"KeyZ"===t.code);case"text-redo":return(t.ctrlKey||t.metaKey)&&("Y"===t.key||"y"===t.key||"KeyY"===t.code);case"text-write":return t.isComposing||!t.ctrlKey&&!t.altKey&&!t.metaKey&&!["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;case"IME":return"Unidentified"===t.key||229===t.keyCode;default:return!1}}function Pt(t,e,i){const s=e.split(/\s+/),a=t.split("").map((t,i)=>{let a=s[i]||"";return""===e&&""===a&&(a=t),{char:t,pinyin:a.toLowerCase(),initial:a?a[0].toLowerCase():""}}),n=(t=>{const e=[];let i="";for(const s of t)/[a-zA-Z]/.test(s)?i+=s.toLowerCase():(i&&(e.push({type:"pinyin",value:i}),i=""),e.push({type:"char",value:s}));return i&&e.push({type:"pinyin",value:i}),e})(i),o=a.length,c=n.length,h=Array.from({length:o+1},()=>Array(c+1).fill(!1));h[0][0]=!0;for(let r=0;r<=o;r++)for(let t=0;t<=c;t++)if(h[r][t]&&t<c){const e=n[t];for(let i=r;i<o;i++){const s=a[i];if("char"===e.type)s.char===e.value&&(h[i+1][t+1]=!0);else{const n=s.pinyin.toLowerCase(),c=s.initial,r=e.value;if(r===c)h[i+1][t+1]=!0;else if(r===n)h[i+1][t+1]=!0;else if(Ht(r,n))h[i+1][t+1]=!0;else for(let e=2;e<=o-i;e++){const s=a.slice(i,i+e),n=s.map(t=>t.pinyin.toLowerCase()).join(""),o=s.map(t=>t.initial).join("");if(r===n||r===o||Ht(r,n)){h[i+e][t+1]=!0;break}}}}}for(let r=0;r<=o;r++)if(h[r][c])return!0;return!1}function Ht(t,e){let i=0,s=0;for(;i<t.length&&s<e.length;)t[i]===e[s]&&i++,s++;return i===t.length}function Kt(t,e=!0,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 zt(t){return t&&t.classList.contains("chat-view-show")}class _t{constructor(n,o){ht(this,e),nt(this,"chatElement"),nt(this,"bus"),nt(this,"dialog"),nt(this,"activeMention",null),nt(this,"title",""),nt(this,"callEvery",!0),nt(this,"everyText",""),nt(this,"emptyText",""),nt(this,"options",[]),nt(this,"asyncMatch"),nt(this,"matchKey",0),ht(this,t,[]),this.dialog=document.createElement("div"),this.chatElement=n,this.bus=this.chatElement.chat.bus,lt(this,e,i).call(this),lt(this,e,s).call(this),lt(this,e,a).call(this),this.updateConfig(o)}updateConfig(t){this.asyncMatch=t.asyncMatch,this.title=t.dialogTitle,this.emptyText=t.emptyText,this.everyText=t.everyText,this.callEvery=!this.asyncMatch&&t.callEvery,this.options=this.asyncMatch?[]:t.options,this.updateRender()}updateRender(){this.dialog.children[0].textContent=this.title,this.dialog.children[2].innerHTML=`${gt}<span class="empty-label">${this.emptyText}</span>`;const t=this.dialog.children[1];t.innerHTML="";const e=document.createDocumentFragment();this.callEvery&&e.appendChild(this.getRenderMention({id:"ALL",name:this.everyText})),this.options.forEach(t=>{e.appendChild(this.getRenderMention(t))}),t.appendChild(e)}getRenderMention(t){const e=document.createElement("div");e.setAttribute("data-id",t.id),e.setAttribute("data-name",t.name),e.classList.add("chat-mention-dialog-item"),Kt(e,!0,"flex");const i=document.createElement("div");if(i.classList.add("chat-mention-dialog-item-avatar"),t.avatar){i.classList.add("have-avatar");const e=document.createElement("div");e.classList.add("chat-mention-dialog-item-avatar-loading"),e.innerHTML=pt,i.appendChild(e);const s=new Image;s.alt="",s.src=t.avatar,s.onload=()=>{i.removeChild(e),i.appendChild(s)}}else{const e=document.createElement("span");e.textContent="ALL"===t.id?"@":t.name.slice(-2),e.classList.add("chat-mention-dialog-item-avatar-text"),i.appendChild(e)}e.appendChild(i);const s=document.createElement("div");return s.classList.add("chat-mention-dialog-item-name"),s.textContent=t.name,e.appendChild(s),e.addEventListener("click",t=>{t.stopPropagation();const i=this.chatElement.chat.chatEditor.markCursorWrite,s=i.node.textContent.slice(0,i.offset).lastIndexOf("@"),a=i.offset-s;this.bus.emit("insertMention",{id:e.getAttribute("data-id"),name:e.getAttribute("data-name"),del:a>0?a:0}),this.closeDialog()}),e}openDialog(t){if(zt(this.dialog)||this.bus.emit("closeDialog"),this.asyncMatch){this.options=[],this.updateRender();const t=this.dialog.children[2],e=this.dialog.children[3];Kt(t,!1),Kt(e,!0,"flex"),Kt(this.dialog),this.moveDialog(),this.bus.emit("switchDisabledState",!0)}else if(this.options.length>0){const e=this.dialog.children[1];let i;e.scrollTop=0;const s=(t||this.pinyinMatchDialog()).map(t=>t.id);Array.from(e.children,t=>{const e=t.getAttribute("data-id");s.includes(e)?(Kt(t,!0,"flex"),i||(i=t)):Kt(t,!1)}),this.switchActiveMention(i||e.children[0]),Kt(this.dialog),this.moveDialog(),this.bus.emit("switchDisabledState",!0)}}closeDialog(){zt(this.dialog)&&(Kt(this.dialog,!1),this.switchActiveMention(),this.bus.emit("switchDisabledState",!1))}moveDialog(){const t=this.chatElement.chat.getSelection().getRangeAt(0).getBoundingClientRect(),e=this.chatElement.dialogRoot.getBoundingClientRect();let i="0",s="100%",a=t.x-e.x,n=e.y-t.y;const{clientWidth:o,clientHeight:c}=this.dialog;t.x>window.innerWidth-o-30&&(a=t.x-o-e.x-16,i="100%"),t.y<c&&(n-=c,s="0"),this.dialog.style.transform="translate(0, 0)",this.dialog.style.transformOrigin=`${i} ${s}`,this.dialog.style.left=a+6+"px",this.dialog.style.bottom=`${n}px`,this.dialog.style.opacity="1"}moveActiveMention(t){const e=this.dialog.children[1],i=Array.prototype.filter.call(e.children,t=>t.classList.contains("chat-view-show")),s=Array.prototype.indexOf.call(i,this.activeMention);"up"===t?s>0?this.switchActiveMention(i[s-1],!0):this.switchActiveMention(i[i.length-1],!0):"down"===t&&(s<i.length-1?this.switchActiveMention(i[s+1],!0):this.switchActiveMention(i[0],!0))}switchActiveMention(t,e=!1){if(this.activeMention&&this.activeMention.classList.remove("active"),t){if(this.activeMention=t,this.activeMention.classList.add("active"),e){const t=this.dialog.children[1],e=Array.prototype.filter.call(t.children,t=>t.classList.contains("chat-view-show")),i=this.activeMention.clientHeight,s=Array.prototype.indexOf.call(e,this.activeMention)+1-Math.ceil(Math.floor(t.clientHeight/i)/2);t.scrollTop=s>0?s*i:0}}else this.activeMention=null}matchDialog(){const t=this.chatElement.chat.chatEditor.markCursorWrite,e=t.node.textContent.slice(0,t.offset),i=e.lastIndexOf("@");if(-1===i)return void this.closeDialog();const s=e.slice(i+1);if(this.asyncMatch)return void this.asyncMatchDialog(s);const a=this.pinyinMatchDialog(s);a.length>0?this.openDialog(a):this.closeDialog()}pinyinMatchDialog(t){return t?this.options.filter(e=>Pt(e.name,e.pinyin||"",t)):this.callEvery?[{id:"ALL",name:this.everyText},...this.options]:this.options}async asyncMatchDialog(t=""){this.matchKey++;const e=this.matchKey;if(/\s/gi.test(t))return void this.closeDialog();this.openDialog();const i=await this.asyncMatch(t);if(e===this.matchKey){this.options=i,this.updateRender();const t=this.dialog.children[1],e=this.dialog.children[2],s=this.dialog.children[3];Kt(s,!0,"flex"),t.scrollTop=0,Kt(e,0===this.options.length,"flex"),Kt(s,!1),this.switchActiveMention(t.children[0]),this.moveDialog()}}destroy(){this.bus.offKeyEvent("MentionDialog"),this.dialog.parentElement&&this.dialog.parentElement.removeChild(this.dialog),ct(this,t).forEach(t=>{const e=t[0],i=t[1];for(const s in i)e.removeEventListener(s,i[s])})}}t=new WeakMap,e=new WeakSet,i=function(){const t="MentionDialog";this.bus.on(t,"closeDialog",()=>{this.closeDialog()}),this.bus.on(t,"moveActiveMention",Mt(this.moveActiveMention,120).bind(this)),this.bus.on(t,"matchDialog",$t(this.matchDialog,200).bind(this)),this.bus.on(t,"updateDialogReact",$t(()=>{zt(this.dialog)&&this.moveDialog()},200)),this.bus.on(t,"destroy",()=>{this.destroy()})},s=function(){rt(this,t,[[this.chatElement.richText,{keydown:t=>{zt(this.dialog)&&(Bt(t,"dialog-options")?t.preventDefault():Bt(t,"text-move")&&this.closeDialog())},keyup:t=>{if(t.stopPropagation(),"@"===t.key||"2"===String(t.key)||Bt(t,"IME")){const t=this.chatElement.chat.getSelection(),e=t.focusNode,i=this.chatElement.chat.chatEditor.findNode(e);if(i&&"Write"===i.type){const e=t.focusOffset;"@"===i.text[e-1]&&!this.chatElement.chat.deviceInfo.isPc&&this.openDialog()}}}}],[window,{mousedown:()=>{this.closeDialog()},keydown:t=>{!this.chatElement.chat.chatEditor.isComposition&&zt(this.dialog)&&Bt(t,"dialog-options")&&(t.preventDefault(),"ArrowUp"===t.key||"ArrowUp"===t.code?this.bus.emit("moveActiveMention","up"):"ArrowDown"===t.key||"ArrowDown"===t.code?this.bus.emit("moveActiveMention","down"):"Enter"!==t.key&&"Enter"!==t.code&&"NumpadEnter"!==t.code||this.activeMention&&this.activeMention.click())}}]]),ct(this,t).forEach(t=>{const e=t[0],i=t[1];for(const s in i)e.addEventListener(s,i[s])})},a=function(){this.dialog.classList.add("chat-mention-dialog-wrap"),this.dialog.addEventListener("mousedown",t=>{t.stopPropagation()}),Kt(this.dialog,!1);const t=document.createDocumentFragment(),e=document.createElement("div");e.classList.add("chat-mention-dialog-header"),t.appendChild(e);const i=document.createElement("div");i.classList.add("chat-mention-dialog-main"),i.classList.add("chat-scroll"),t.appendChild(i);const s=document.createElement("div");s.classList.add("chat-mention-dialog-empty"),Kt(s,!1),t.appendChild(s);const a=document.createElement("div");a.classList.add("chat-mention-dialog-loading"),a.innerHTML=pt,Kt(a,!1),t.appendChild(a),this.dialog.appendChild(t),this.chatElement.dialogRoot.appendChild(this.dialog)};class Ft{constructor(t,e){ht(this,o),nt(this,"bus"),nt(this,"chatElement"),nt(this,"dialog"),nt(this,"activeTrigger",null),nt(this,"title"),nt(this,"key"),nt(this,"options"),nt(this,"keyMap"),ht(this,n,[]),this.title=e.dialogTitle,this.key=e.key,this.options=e.options,this.keyMap=e.keyMap,this.dialog=document.createElement("div"),this.chatElement=t,this.bus=this.chatElement.chat.bus,lt(this,o,c).call(this),lt(this,o,h).call(this),lt(this,o,r).call(this)}openDialog(t){if(zt(this.dialog)||this.bus.emit("closeDialog"),this.options.length>0){const e=this.dialog.children[1];let i;e.scrollTop=0;const s=(t||this.pinyinMatchDialog()).map(t=>t.id);Array.from(e.children,t=>{const e=t.getAttribute("data-id");s.includes(e)?(Kt(t,!0,"flex"),i||(i=t)):Kt(t,!1)}),this.switchActiveTrigger(i||e.children[0]),Kt(this.dialog),this.moveDialog(),this.bus.emit("switchDisabledState",!0)}}closeDialog(){zt(this.dialog)&&(Kt(this.dialog,!1),this.switchActiveTrigger(),this.bus.emit("switchDisabledState",!1))}moveDialog(){const t=this.chatElement.chat.getSelection().getRangeAt(0).getBoundingClientRect(),e=this.chatElement.dialogRoot.getBoundingClientRect();let i="0",s="100%",a=t.x-e.x,n=e.y-t.y;const{clientWidth:o,clientHeight:c}=this.dialog;t.x>window.innerWidth-o-30&&(a=t.x-o-e.x-16,i="100%"),t.y<c&&(n-=c,s="0"),this.dialog.style.transform="translate(0, 0)",this.dialog.style.transformOrigin=`${i} ${s}`,this.dialog.style.left=a+6+"px",this.dialog.style.bottom=`${n}px`,this.dialog.style.opacity="1"}moveActiveTrigger(t){const e=this.dialog.children[1],i=Array.prototype.filter.call(e.children,t=>t.classList.contains("chat-view-show")),s=Array.prototype.indexOf.call(i,this.activeTrigger);"up"===t?s>0?this.switchActiveTrigger(i[s-1],!0):this.switchActiveTrigger(i[i.length-1],!0):"down"===t&&(s<i.length-1?this.switchActiveTrigger(i[s+1],!0):this.switchActiveTrigger(i[0],!0))}switchActiveTrigger(t,e=!1){if(this.activeTrigger&&this.activeTrigger.classList.remove("active"),t){if(this.activeTrigger=t,this.activeTrigger.classList.add("active"),e){const t=this.dialog.children[1],e=Array.prototype.filter.call(t.children,t=>t.classList.contains("chat-view-show")),i=this.activeTrigger.clientHeight,s=Array.prototype.indexOf.call(e,this.activeTrigger)+1-Math.ceil(Math.floor(t.clientHeight/i)/2);t.scrollTop=s>0?s*i:0}}else this.activeTrigger=null}matchDialog(){const t=this.chatElement.chat.chatEditor.markCursorWrite,e=t.node.textContent.slice(0,t.offset),i=e.lastIndexOf(this.key);if(-1===i)return void this.closeDialog();const s=e.slice(i+1),a=this.pinyinMatchDialog(s);a.length>0?this.openDialog(a):this.closeDialog()}pinyinMatchDialog(t){return t?this.options.filter(e=>Pt(e.name,e.pinyin||"",t)):this.options}destroy(){const t="TriggerDialog-"+this.key;this.bus.offKeyEvent(t),this.dialog.parentElement&&this.dialog.parentElement.removeChild(this.dialog),ct(this,n).forEach(t=>{const e=t[0],i=t[1];for(const s in i)e.removeEventListener(s,i[s])})}}n=new WeakMap,o=new WeakSet,c=function(){const t="TriggerDialog-"+this.key;this.bus.on(t,"closeDialog",()=>{this.closeDialog()}),this.bus.on(t,"moveActiveTrigger",Mt(this.moveActiveTrigger,120).bind(this)),this.bus.on(t,"matchDialog",$t(this.matchDialog,200).bind(this)),this.bus.on(t,"updateDialogReact",$t(()=>{zt(this.dialog)&&this.moveDialog()},200)),this.bus.on(t,"destroy",()=>{this.destroy()})},h=function(){rt(this,n,[[this.chatElement.richText,{keydown:t=>{zt(this.dialog)&&(Bt(t,"dialog-options")?t.preventDefault():Bt(t,"text-move")&&this.closeDialog())},keyup:t=>{if(t.stopPropagation(),this.keyMap.includes(String(t.key))||Bt(t,"IME")){const t=this.chatElement.chat.getSelection(),e=t.focusNode,i=this.chatElement.chat.chatEditor.findNode(e);if(i&&"Write"===i.type){const e=t.focusOffset;i.text[e-1]===this.key&&!this.chatElement.chat.deviceInfo.isPc&&this.openDialog()}}}}],[window,{mousedown:()=>{this.closeDialog()},keydown:t=>{!this.chatElement.chat.chatEditor.isComposition&&zt(this.dialog)&&Bt(t,"dialog-options")&&(t.preventDefault(),"ArrowUp"===t.key||"ArrowUp"===t.code?this.bus.emit("moveActiveTrigger","up"):"ArrowDown"===t.key||"ArrowDown"===t.code?this.bus.emit("moveActiveTrigger","down"):"Enter"!==t.key&&"Enter"!==t.code&&"NumpadEnter"!==t.code||this.activeTrigger&&this.activeTrigger.click())}}]]),ct(this,n).forEach(t=>{const e=t[0],i=t[1];for(const s in i)e.addEventListener(s,i[s])})},r=function(){this.dialog.classList.add("chat-trigger-dialog-wrap"),this.dialog.addEventListener("mousedown",t=>{t.stopPropagation()}),Kt(this.dialog,!1);const t=document.createDocumentFragment(),e=document.createElement("div");e.classList.add("chat-trigger-dialog-header"),e.textContent=this.title,t.appendChild(e);const i=document.createElement("div");i.classList.add("chat-trigger-dialog-main"),i.classList.add("chat-scroll"),t.appendChild(i);const s=document.createDocumentFragment();this.options.forEach(t=>{const e=document.createElement("div");e.setAttribute("data-id",t.id),e.setAttribute("data-name",t.name),e.classList.add("chat-trigger-dialog-item"),Kt(e,!0,"flex");const i=document.createElement("div");i.classList.add("chat-trigger-dialog-item-name"),i.textContent=t.name,e.appendChild(i),e.addEventListener("click",t=>{t.stopPropagation();const i=this.chatElement.chat.chatEditor.markCursorWrite,s=i.node.textContent.slice(0,i.offset).lastIndexOf(this.key),a=i.offset-s;this.bus.emit("insertTrigger",{id:e.getAttribute("data-id"),name:e.getAttribute("data-name"),key:this.key,del:a>0?a:0}),this.closeDialog()}),s.appendChild(e)}),i.appendChild(s),this.dialog.appendChild(t),this.chatElement.dialogRoot.appendChild(this.dialog)};class Yt{constructor(t,e){ht(this,d),nt(this,"chatElement"),nt(this,"bus"),nt(this,"dialog"),nt(this,"title",""),nt(this,"key",""),nt(this,"multiple",!1),nt(this,"emptyText",""),nt(this,"showSearch",!1),nt(this,"placeholder",""),nt(this,"searchEmptyText",""),nt(this,"options",[]),nt(this,"selectNode",null),ht(this,l,[]),this.dialog=document.createElement("div"),this.chatElement=t,this.bus=this.chatElement.chat.bus,this.title=e.dialogTitle,this.key=e.key,this.multiple=e.multiple||!1,this.emptyText=e.emptyText||"请选择标签选项",this.placeholder=e.placeholder||"请输入关键字查询",this.searchEmptyText=e.searchEmptyText||"暂无查询结果",this.showSearch=e.showSearch||!1,this.options=e.options,lt(this,d,p).call(this),lt(this,d,g).call(this),lt(this,d,u).call(this)}openDialog(t){if(zt(this.dialog)||this.bus.emit("closeDialog"),this.selectNode=t,!this.selectNode)return;if(this.showSearch){const t=this.dialog.children[1];t.children[0].value="",Kt(t.children[1],!1)}Kt(this.dialog);const e=this.dialog.children[this.showSearch?2:1],i=e.children;let s=0,a=!1,n=0;if("Select"===this.selectNode.type){const t=this.selectNode.id,o=(t||"").split(",");this.selectNode.$el.children[0].classList.add("active"),Array.from(i,e=>{Kt(e,!0,"flex");const i=e.lastChild,c=o.length>0?o.some(t=>String(t)===e.getAttribute("data-id")):String(t)===String(e.getAttribute("data-id"));c&&(n=e.clientHeight,a=!0),c||a||(s+=e.clientHeight),Kt(i,c)});const c=s-e.clientHeight/2+n/2;e.scrollTop=a&&c>0?c:0}else e.scrollTop=0,Array.from(i,t=>{Kt(t,!0,"flex");Kt(t.lastChild,!1)});this.bus.emit("switchDisabledState",!0),this.moveDialog()}closeDialog(){if(zt(this.dialog)){if(Kt(this.dialog,!1),this.selectNode&&"Select"===this.selectNode.type){this.selectNode.$el.children[0].classList.remove("active")}this.bus.emit("switchDisabledState",!1),this.selectNode=null}}moveDialog(){if(!this.selectNode)return;const t=this.selectNode.$el.getClientRects()[0],e=this.dialog.children[this.showSearch?3:2];let i=this.dialog.clientHeight+16;if(i>t.y?(i=-(t.height+16),e.style.top="-16px",e.style.bottom="auto",e.style.transform="rotate(0deg)"):(e.style.transform="rotate(180deg)",e.style.bottom="-16px",e.style.top="auto"),window.innerWidth-t.x<this.dialog.clientWidth){const i=this.dialog.clientWidth-(window.innerWidth-t.x)-10;this.dialog.style.left="auto",this.dialog.style.right="10px",e.style.left="auto",e.style.right=i-16+"px"}else this.dialog.style.left=t.x+"px",this.dialog.style.right="auto",e.style.left="16px",e.style.right="auto";this.dialog.style.top=t.y+"px",this.dialog.style.transform=`translateY(${-i}px)`}destroy(){const t="SelectDialog-"+this.key;this.bus.offKeyEvent(t),this.dialog.parentElement&&this.dialog.parentElement.removeChild(this.dialog),ct(this,l).forEach(t=>{const e=t[0],i=t[1];for(const s in i)e.removeEventListener(s,i[s])})}}l=new WeakMap,d=new WeakSet,p=function(){const t="SelectDialog-"+this.key;this.bus.on(t,"activeSelect",t=>{t.key===this.key&&this.chatElement.chat.nextTick(()=>{this.openDialog(t)})}),this.bus.on(t,"closeDialog",()=>{this.closeDialog()})},g=function(){rt(this,l,[[window,{mousedown:()=>{this.closeDialog()}}]]),ct(this,l).forEach(t=>{const e=t[0],i=t[1];for(const s in i)e.addEventListener(s,i[s])})},u=function(){this.dialog.classList.add("chat-select-dialog-wrap"),this.dialog.addEventListener("mousedown",t=>{t.stopPropagation()}),Kt(this.dialog,!1);const t=document.createDocumentFragment(),e=document.createElement("div");e.classList.add("chat-select-dialog-header");const i=document.createElement("span");if(i.textContent=this.title,e.appendChild(i),t.appendChild(e),this.showSearch){const e=document.createElement("div");e.classList.add("chat-select-dialog-search");const i=document.createElement("input");i.classList.add("chat-select-dialog-search-input"),i.setAttribute("placeholder",this.placeholder),i.addEventListener("input",$t(t=>{t.stopPropagation();const e=t.target.value||"",i=this.dialog.children[1].children[1],s=this.dialog.children[2].children;let a=!0;Array.from(s,t=>{const i=t.getAttribute("data-name")||"";""===e||-1!==i.indexOf(e)?(a=!1,Kt(t,!0,"flex")):Kt(t,!1)}),Kt(i,a,"flex"),this.moveDialog()},200).bind(this)),e.appendChild(i);const s=document.createElement("div");s.classList.add("chat-select-dialog-search-empty"),s.innerHTML=`${gt}<span class="empty-label">${this.searchEmptyText}</span>`,Kt(s,!1),e.appendChild(s),t.appendChild(e)}const s=document.createElement("div");s.classList.add("chat-select-dialog-main"),s.classList.add("chat-scroll");const a=document.createDocumentFragment();this.options.forEach(t=>{const e=document.createElement("div");if(e.classList.add("chat-select-dialog-item"),e.setAttribute("data-id",t.id),e.setAttribute("data-name",t.name),t.preview){const i=document.createElement("div");i.classList.add("chat-select-dialog-preview"),i.classList.add("loading"),i.innerHTML=pt,e.appendChild(i);const s=new Image;s.classList.add("chat-select-dialog-preview"),s.src=String(t.preview),s.onload=()=>{e.insertBefore(s,i),e.removeChild(i)}}const i=document.createElement("span");i.classList.add("chat-select-dialog-name"),i.textContent=t.name,e.appendChild(i);const s=document.createElement("span");s.classList.add("chat-select-dialog-check"),s.innerHTML='<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>',Kt(s,!1),e.appendChild(s),e.addEventListener("click",t=>{if(t.stopPropagation(),this.selectNode&&"Select"===this.selectNode.type)if(this.multiple){Kt(e.lastChild,!zt(e.lastChild));const t=e.parentElement.querySelectorAll(".chat-select-dialog-check.chat-view-show");if(0===t.length)this.selectNode.updateTag({id:null,name:this.emptyText});else{let e="",i="";Array.from(t,t=>{const s=t.parentElement;e+=`${s.getAttribute("data-id")},`,i+=`${s.getAttribute("data-name")}、`}),this.selectNode.updateTag({id:e.slice(0,-1),name:i.slice(0,-1)})}}else{const t=e.getAttribute("data-id"),i=e.getAttribute("data-name");this.selectNode.updateTag({id:t,name:i}),this.closeDialog()}else{const t=e.getAttribute("data-id"),i=e.getAttribute("data-name");this.bus.emit("insertSelect",{...this.selectNode||{},id:t,name:i}),this.closeDialog()}}),a.appendChild(e)}),s.appendChild(a),t.appendChild(s);const n=document.createElement("div");n.classList.add("chat-select-dialog-arrow"),t.appendChild(n),this.dialog.appendChild(t),this.chatElement.dialogRoot.appendChild(this.dialog)};class jt{constructor(t,e){ht(this,m),nt(this,"chatElement"),nt(this,"bus"),nt(this,"tip"),nt(this,"dialog"),nt(this,"config",{}),ht(this,f,[]),this.chatElement=t,this.bus=this.chatElement.chat.bus,this.tip=document.createElement("div"),this.dialog=document.createElement("div"),lt(this,m,x).call(this),lt(this,m,y).call(this),lt(this,m,w).call(this),this.updateConfig(e)}updateConfig(t){this.config=t,this.tip.innerHTML=t.tipTemplate||"",this.dialog.innerHTML=t.dialogTemplate||""}openTip(t){this.tip.innerHTML=Wt(this.tip.innerHTML,t),this.dialog.innerHTML=Wt(this.dialog.innerHTML,t),Kt(this.tip);(this.config.closeNames||[]).forEach(t=>{const e=this.tip.querySelector(`.${t}`);e&&e.addEventListener("click",()=>{this.closeTip()})}),this.tip.onmouseenter=()=>{Kt(this.dialog),this.tip.classList.add("tip-hover");const t=this.tip.children[0],e=t.offsetWidth/2+t.offsetLeft,i=this.dialog.children[0].clientWidth/2;this.chatElement.container.style.setProperty("--chat-tip-dialog-left",e-i+"px");const s=Number(this.chatElement.container.style.getPropertyValue("--chat-before-tip-top").replace("px",""));this.chatElement.container.style.setProperty("--chat-tip-dialog-top",s-this.chatElement.rollBox.scrollTop+"px")},this.tip.onmouseleave=()=>{Kt(this.dialog,!1),this.tip.classList.remove("tip-hover")};const e=this.tip.children[0].clientWidth;this.chatElement.container.style.setProperty("--chat-before-tip-width",`${e+Number(t.offset||4)}px`),this.bus.emit("focus","mark"),lt(this,m,v).call(this),this.bus.emit("tipState",!0)}closeTip(){zt(this.tip)&&(this.chatElement.container.style.setProperty("--chat-before-tip-width","0px"),this.chatElement.container.style.setProperty("--chat-before-tip-top","0px"),this.chatElement.container.style.setProperty("--chat-tip-dialog-left","0px"),Kt(this.tip,!1),Kt(this.dialog,!1),this.tip.classList.remove("tip-hover"),this.bus.emit("focus","mark"),this.tip.innerHTML=this.config.tipTemplate||"",this.dialog.innerHTML=this.config.dialogTemplate||"",this.bus.emit("tipState",!1))}destroy(){this.bus.offKeyEvent("BeforeTip"),ct(this,f).forEach(t=>{const e=t[0],i=t[1];for(const s in i)e.removeEventListener(s,i[s])})}}f=new WeakMap,m=new WeakSet,x=function(){const t="BeforeTip";this.bus.on(t,"destroy",()=>{this.destroy()}),this.bus.on(t,"openTip",t=>{this.openTip(t)}),this.bus.on(t,"closeTip",()=>{this.closeTip()}),this.bus.on(t,"editorChange",()=>{lt(this,m,v).call(this)})},y=function(){rt(this,f,[[window,{resize:()=>{lt(this,m,v).call(this)},keydown:t=>{"Escape"===t.key&&this.closeTip()}}]]),ct(this,f).forEach(t=>{const e=t[0],i=t[1];for(const s in i)e.addEventListener(s,i[s])})},w=function(){this.tip.classList.add("chat-before-tip-wrap"),this.dialog.classList.add("chat-tip-dialog-wrap"),this.chatElement.rollBox.appendChild(this.tip),this.chatElement.dialogRoot.appendChild(this.dialog),Kt(this.tip,!1),Kt(this.dialog,!1)},v=function(){if(!zt(this.tip))return;const t=this.chatElement.chat.chatEditor.NODES[0].children[0],e=this.tip.children[0],i=t.$el.getBoundingClientRect(),s=e.getBoundingClientRect(),a=Number(this.chatElement.container.style.getPropertyValue("--chat-before-tip-top").replace("px","")),n=i.y+this.chatElement.chat.chatEditor.NODE_HEIGHT/2-(s.y+s.height/2)+a;this.chatElement.container.style.setProperty("--chat-before-tip-top",`${n+(this.config.offsetTop||0)}px`)};class Vt{constructor(t,e){ht(this,b),nt(this,"chat"),nt(this,"container"),nt(this,"rollBox"),nt(this,"richText"),nt(this,"placeholder"),nt(this,"dialogRoot"),nt(this,"mentionDialog"),nt(this,"triggerDialogs"),nt(this,"selectDialogs"),nt(this,"beforeTip"),this.chat=e,this.container=t,this.rollBox=document.createElement("div"),this.richText=document.createElement("div"),this.placeholder=document.createElement("div"),this.dialogRoot=document.createElement("div"),lt(this,b,E).call(this),lt(this,b,k).call(this),lt(this,b,C).call(this),lt(this,b,N).call(this)}updatePlaceholder(t){this.placeholder.textContent=t}updateChatStyle(t){Object.assign(this.rollBox.style,t)}createMentionDialog(){this.mentionDialog?this.mentionDialog.updateConfig(this.chat.options.mentionConfig):this.mentionDialog=new _t(this,this.chat.options.mentionConfig)}createTriggerDialog(){this.triggerDialogs?(this.triggerDialogs.forEach(t=>{t.destroy()}),this.triggerDialogs=[]):this.triggerDialogs=[],this.chat.options.triggerConfig.forEach(t=>{this.triggerDialogs.push(new Ft(this,t))})}createSelectDialog(){this.selectDialogs?(this.selectDialogs.forEach(t=>{t.destroy()}),this.selectDialogs=[]):this.selectDialogs=[],this.chat.options.selectConfig.forEach(t=>{this.selectDialogs.push(new Yt(this,t))})}createBeforeTip(){this.beforeTip?this.beforeTip.updateConfig(this.chat.options.tipConfig):this.beforeTip=new jt(this,this.chat.options.tipConfig)}destroy(){this.chat.bus.offKeyEvent("ChatElement"),this.rollBox.parentElement&&this.rollBox.parentElement.removeChild(this.rollBox),this.placeholder.parentElement&&this.placeholder.parentElement.removeChild(this.placeholder),this.dialogRoot.parentElement&&this.dialogRoot.parentElement.removeChild(this.dialogRoot)}}b=new WeakSet,E=function(){const t="ChatElement";this.chat.bus.on(t,"editorChange",()=>{lt(this,b,O).call(this)}),this.chat.bus.on(t,"destroy",()=>{this.destroy()})},k=function(){this.container.classList.add("chat-area-wrap"),this.rollBox.classList.add("chat-rich-text"),this.rollBox.classList.add("chat-scroll"),this.richText.setAttribute(wt,"richWrap"),this.richText.setAttribute("contenteditable","true"),this.rollBox.appendChild(this.richText),this.container.appendChild(this.rollBox)},C=function(){this.placeholder.classList.add("chat-placeholder-wrap"),Kt(this.placeholder),this.container.appendChild(this.placeholder)},N=function(){this.dialogRoot.classList.add("chat-dialog-wrap"),this.container.appendChild(this.dialogRoot)},O=function(){if(this.chat.chatEditor.isComposition)return Kt(this.placeholder,!1);const t=this.chat.chatEditor.NODES;return t.length>1||t[0].children.length>1||t[0].children[0].text.length>0?Kt(this.placeholder,!1):void Kt(this.placeholder,!0)};class Gt{constructor(t){nt(this,"$el",null),nt(this,"type",""),this.type=t}mount({parentElm:t,beforeElm:e,afterElm:i,targetElm:s}){s&&(i?i.nextElementSibling?t.insertBefore(s,i.nextElementSibling):t.appendChild(s):e?t.insertBefore(s,e):t.appendChild(s))}}D=new WeakSet,T=function(t,...e){this.context.context.bus.emit(t,...e)};let Ut=class t extends Gt{constructor(t,e){super(e.type),ht(this,D),nt(this,"context"),nt(this,"text",""),nt(this,"VOID_KEY",Lt),this.context=t,this.text=String(e.text||""),this.render(e)}ruleBRTag(){const t=this.$el.children[0];if(t.childNodes.length>1){const e=[];for(let i=1;i<t.childNodes.length;i++)e.push(t.childNodes[i]);e.forEach(e=>{t.removeChild(e)})}if(!Boolean(this.text)&&this.$el===this.$el.parentElement.lastElementChild){const t=document.createElement("br");this.$el.children[0].appendChild(t)}}focus(t){const e=this.$el.children[0].childNodes[0];t||0===t?-1===t&&(t=e.textContent===this.VOID_KEY?1:e.textContent.length):t=e.textContent===this.VOID_KEY?1:0;const i=new Range,s=this.context.context.chat.getSelection();i.setStart(e,t),i.setEnd(e,t),s.removeAllRanges(),s.addRange(i),lt(this,D,T).call(this,"cursorChange",{node:e,offset:t,type:"Write",instance:this})}updateNode(){const t=this.$el.children[0],e=t.childNodes[0],i=e.textContent||"";if(this.text=i.replace(new RegExp(this.VOID_KEY,"ig"),"")||"",t.setAttribute(yt,String(!Boolean(this.text))),Boolean(this.text)){if(-1!==i.indexOf(this.VOID_KEY)&&(e.textContent=this.text,this.focus(-1)),t.childNodes.length>1)for(let s=t.childNodes.length-1;s>0;s--)t.removeChild(t.childNodes[s])}else e.textContent=this.VOID_KEY,this.ruleBRTag()}deleteNode(){const t=this.context.children.indexOf(this);this.context.children.splice(t,1),this.context.$el.removeChild(this.$el)}deleteRelevanceNode(){this.deleteNode()}deleteRangeNode(t){const e=t.anchorOffset,i=t.focusOffset,s=e>i,a=s?i:e,n=s?e:i,o=this.text.slice(0,a),c=this.text.slice(n);this.text=o+c,this.syncNode(),this.focus(a)}updateContext(t){this.context=t}syncNode(){const t=this.$el.children[0].childNodes[0];Boolean(this.text)?t.textContent=this.text:t.textContent=this.VOID_KEY,this.ruleBRTag()}splitNode(e,i,s="",a=""){const n=!Boolean(this.text),o=n?"":this.text.slice(0,e),c=n?"":this.text.slice(e);this.text=i?o.slice(0,-i):o,this.text=this.text+s;const h=this.context.children.indexOf(this),r=new t(this.context,{type:"Write",text:a+c,afterElm:this.$el});this.context.children.splice(h+1,0,r),this.syncNode(),this.updateNode(),r.updateNode(),r.focus(a.length>0?a.length:void 0)}backspace(t){const e=t.anchorOffset;if(t.isCollapsed){if(0===e||1===e&&!Boolean(this.text)){const t=this.context.children.indexOf(this),e=this.context.context.NODES.indexOf(this.context);if(0===t){if(0===e)return void lt(this,D,T).call(this,"closeTip");return void this.context.context.NODES[e].mergeNode(!1)}return void this.context.context.NODES[e].children[t-1].deleteRelevanceNode()}this.text=this.text.slice(0,e-1)+this.text.slice(e),this.syncNode(),this.focus(e-1)}else this.deleteRangeNode({anchorInstance:this,anchorOffset:e,focusInstance:this,focusOffset:t.focusOffset})}delete(t){const e=t.anchorOffset;if(t.isCollapsed)if(e===this.text.length||1===e&&!Boolean(this.text)){const t=this.context.children.indexOf(this),e=this.context.context.NODES.indexOf(this.context);if(t===this.context.children.length-1){if(e===this.context.context.NODES.length-1)return;return void this.context.context.NODES[e].mergeNode(!0)}this.context.context.NODES[e].children[t+1].deleteRelevanceNode(!0)}else this.text=this.text.slice(0,e)+this.text.slice(e+1),this.syncNode(),this.focus(e);else{const i=t.focusOffset,s=e>i,a=s?i:e,n=s?e:i,o=this.text.slice(0,a),c=this.text.slice(n);this.text=o+c,this.syncNode(),this.focus(a)}}render(t){const e=document.createElement("span");this.$el=e,e.setAttribute(wt,bt),e.classList.add("chat-write-wrap");const i=document.createElement("span");i.classList.add("chat-write-input"),i.setAttribute(wt,Et),i.setAttribute(yt,String(!Boolean(this.text))),i.appendChild(document.createTextNode(Boolean(this.text)?this.text:this.VOID_KEY)),e.appendChild(i),this.mount({parentElm:(null==t?void 0:t.parentElm)||this.context.$el,targetElm:this.$el,...t||{}})}};class Zt extends Gt{constructor(t,e){super(t),nt(this,"context"),this.context=e}deleteNode(){const t=this.context.children.indexOf(this);this.context.children.splice(t,1),this.context.$el.removeChild(this.$el)}deleteRelevanceNode(t=!1){const e=this.context.children.indexOf(this),i=this.context.children[e-1],s=this.context.children[e+1];this.context.children.splice(e,1),this.context.$el.removeChild(this.$el),t?this.context.mergeWriteNode(s,i,!0,!0):this.context.mergeWriteNode(i,s)}deleteRangeNode(){this.deleteRelevanceNode()}updateContext(t){this.context=t}focus(t=!1){const e=this.context.children.indexOf(this),i=this.context.children[t?e-1:e+1];if(i){const e=!Boolean(i.text);i.focus(t?e?1:i.text.length:e?1:0)}}backspace(){this.context.backspace()}updateNode(){this.context.updateNode()}delete(){this.context.delete()}}class qt extends Zt{constructor(t,e){super(e.type,t),nt(this,"id",""),nt(this,"name",""),this.id=e.id,this.name=e.name,this.render(e)}render(t){const e=document.createElement("span");this.$el=e,e.setAttribute(wt,kt),e.setAttribute("contenteditable","false"),e.classList.add("chat-tag-wrap");const i=document.createElement("span");i.classList.add("chat-tag-mention"),i.textContent="@"+this.name,e.appendChild(i),this.mount({parentElm:(null==t?void 0:t.parentElm)||this.context.$el,targetElm:this.$el,...t||{}})}}class Xt extends Zt{constructor(t,e){super(e.type,t),nt(this,"id",""),nt(this,"name",""),nt(this,"key",""),this.id=e.id,this.name=e.name,this.key=e.key,this.render(e)}render(t){const e=document.createElement("span");this.$el=e,e.setAttribute(wt,Ct),e.setAttribute("contenteditable","false"),e.classList.add("chat-tag-wrap");const i=document.createElement("span");i.classList.add("chat-tag-trigger"),i.textContent=this.key+this.name,e.appendChild(i),this.mount({parentElm:(null==t?void 0:t.parentElm)||this.context.$el,targetElm:this.$el,...t||{}})}}class Jt extends Zt{constructor(t,e){super(e.type,t),ht(this,S),nt(this,"id",""),nt(this,"name",""),nt(this,"key",""),this.id=e.id,this.name=e.name,this.key=e.key,this.render(e)}updateTag({id:t,name:e}){this.id=t,this.name=e;this.$el.children[0].children[0].textContent=e,this.focus(),lt(this,S,L).call(this,"richTextChange")}render(t){const e=document.createElement("span");this.$el=e,e.setAttribute(wt,Nt),e.setAttribute("contenteditable","false"),e.classList.add("chat-tag-wrap");const i=document.createElement("span");i.classList.add("chat-tag-select"),i.innerHTML='<span></span><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>';i.children[0].textContent=this.name,e.appendChild(i),e.addEventListener("click",t=>{t.stopPropagation(),this.context.context.bus.emit("activeSelect",this)}),this.mount({parentElm:(null==t?void 0:t.parentElm)||this.context.$el,targetElm:this.$el,...t||{}})}}S=new WeakSet,L=function(t,...e){this.context.context.bus.emit(t,...e)};class Qt extends Gt{constructor(t,e){super(e.type),ht(this,$),nt(this,"context"),nt(this,"text",""),nt(this,"placeholder",""),nt(this,"key",""),nt(this,"VOID_KEY",Lt),nt(this,"WRAP_KEY","\n"),this.context=t,this.text=(e.text||"").replace(new RegExp(`${this.WRAP_KEY[0]}|${this.VOID_KEY}`,"ig"),""),this.placeholder=String(e.placeholder||"placeholder"),this.key=e.key,this.render(e)}updateContext(t){this.context=t}syncNode(){const t=this.$el.children[0].children[0].childNodes[0];Boolean(this.text)?t.textContent=this.fixWrapKey(this.text):t.textContent=this.VOID_KEY,this.updateNode()}updateNode(){const t=this.$el.children[0].children[0],e=this.$el.children[0].children[1],i=t.childNodes[0],s=i.textContent||"";if(this.text=s.replace(new RegExp(`${this.WRAP_KEY[0]}|${this.VOID_KEY}`,"ig"),""),Kt(e,!Boolean(this.text),"inline-block"),Boolean(this.text)){if(-1!==s.indexOf(this.VOID_KEY))i.textContent=this.fixWrapKey(this.text),this.focus(-1);else if(-1!==this.text.indexOf(this.WRAP_KEY[1])){const t=this.fixWrapKey(this.text);if(t!==i.textContent){let e=0;for(let s=0;s<i.textContent.length;s++){if(i.textContent[s]!==t[s]){e=s;break}}i.textContent=t,this.focus(e+2)}}}else i.textContent=this.VOID_KEY}deleteNode(){const t=this.context.children.indexOf(this);this.context.children.splice(t,1),this.context.$el.removeChild(this.$el)}backspace(t){const e=t.anchorOffset;if(t.isCollapsed)if(0===e||1===e&&!Boolean(this.text))if(Boolean(this.text)){const t=this.context.children.indexOf(this);this.context.children[t-1].focus(-1)}else this.deleteRelevanceTag();else{const t=this.$el.children[0].children[0].childNodes[0],i=this.getWrapOffset(t,e,"left"),s=t.textContent||"";let a;switch(i){case 1:a=e-i-2;break;case 2:a=e-i-1;break;case 3:a=e-i;break;default:a=e-1}const n=s.slice(0,a),o=s.slice(e);this.text=(n+o).replace(new RegExp(`${this.WRAP_KEY[0]}|${this.VOID_KEY}`,"ig"),""),this.syncNode(),this.focus(a)}else this.deleteRangeNode({anchorInstance:this,anchorOffset:e,focusInstance:this,focusOffset:t.focusOffset})}delete(t){const e=t.anchorOffset,i=this.$el.children[0].children[0].childNodes[0],s=this.getWrapOffset(i,e,"right");if(t.isCollapsed)if(e+s===this.fixWrapKey(this.text).length||1===e&&!Boolean(this.text))if(Boolean(this.text)){const t=this.context.children.indexOf(this);this.context.children[t+1].focus()}else this.deleteRelevanceTag(!0);else{const t=i.textContent||"";let a,n,o;switch(s){case 1:a=2,n=1,o=e+1;break;case 2:a=1,n=2,o=e-1;break;case 3:a=0,n=3,o=e;break;default:a=0,n=1,o=e}const c=t.slice(0,e-a),h=t.slice(e+n);this.text=(c+h).replace(new RegExp(`${this.WRAP_KEY[0]}|${this.VOID_KEY}`,"ig"),""),this.syncNode(),this.focus(o)}else this.deleteRangeNode({anchorInstance:this,anchorOffset:e,focusInstance:this,focusOffset:t.focusOffset})}deleteRangeNode(t){const e=t.anchorOffset,i=t.focusOffset,s=e>i;let a=s?i:e,n=s?e:i;const o=this.$el.children[0].children[0].childNodes[0],c=o.textContent||"",h=this.getWrapOffset(o,a,"right"),r=this.getWrapOffset(o,n-1,"left"),l=c.slice(0,a+h),d=c.slice(n+r);this.text=(l+d).replace(new RegExp(`${this.WRAP_KEY[0]}|${this.VOID_KEY}`,"ig"),""),this.syncNode(),this.focus(a)}focus(t){const e=this.$el.children[0].children[0].childNodes[0];t||0===t?-1===t&&(t=e.textContent===this.VOID_KEY?1:e.textContent.length):t=e.textContent===this.VOID_KEY?1:0;const i=new Range,s=this.context.context.chat.getSelection();i.setStart(e,t),i.setEnd(e,t),s.removeAllRanges(),s.addRange(i),lt(this,$,M).call(this,"cursorChange",{node:e,offset:t,type:"Input",instance:this})}deleteRelevanceNode(t=!1){this.focus(t?void 0:-1)}deleteRelevanceTag(t=!1){const e=this.context.children.indexOf(this),i=this.context.children[e-1],s=this.context.children[e+1];this.context.children.splice(e,1),this.context.$el.removeChild(this.$el),t?this.context.mergeWriteNode(s,i,!0,!0):this.context.mergeWriteNode(i,s)}setText(t,e){if(e=this.fixWrapKey(e),Boolean(this.text)){const i=this.$el.children[0].children[0].textContent||"",s=i.slice(0,t),a=i.slice(t);this.text=s+e+a,this.syncNode(),this.focus(s.length+e.length)}else this.text=e,this.syncNode(),this.focus(e.length)}fixWrapKey(t){return t.replace(new RegExp(this.WRAP_KEY[0],"ig"),"").replace(new RegExp(this.WRAP_KEY[1],"ig"),this.WRAP_KEY)}getWrapOffset(t,e,i="left"){const s="left"===i?t.textContent[e-1]:t.textContent[e];if(s===this.WRAP_KEY[0]){return("left"===i?t.textContent[e-2]:t.textContent[e+1])===this.WRAP_KEY[1]?3:1}return s===this.WRAP_KEY[1]?2:0}render(t){const e=document.createElement("span");this.$el=e,e.setAttribute(wt,Ot),e.setAttribute("contenteditable","false"),e.classList.add("chat-tag-wrap");const i=document.createElement("span");i.classList.add("chat-tag-input");const s=document.createElement("span");s.classList.add("input-write"),s.setAttribute("contenteditable","true"),s.textContent=Boolean(this.text)?this.fixWrapKey(this.text):this.VOID_KEY,i.appendChild(s);const a=document.createElement("span");a.classList.add("input-tip"),a.textContent=`[${this.placeholder}]`,i.appendChild(a),Boolean(this.text)&&Kt(a,!1),e.addEventListener("click",()=>{Boolean(this.text)||this.focus()}),e.appendChild(i),this.mount({parentElm:(null==t?void 0:t.parentElm)||this.context.$el,targetElm:this.$el,...t||{}})}}$=new WeakSet,M=function(t,...e){this.context.context.bus.emit(t,...e)};class te extends Zt{constructor(t,e){super(e.type,t),nt(this,"html",""),this.html=e.html,this.render(e)}render(t){const e=document.createElement("span");this.$el=e,e.setAttribute(wt,Dt),e.setAttribute("contenteditable","false"),e.classList.add("chat-tag-wrap"),e.innerHTML=this.html,this.mount({parentElm:(null==t?void 0:t.parentElm)||this.context.$el,targetElm:this.$el,...t||{}})}}class ee extends Gt{constructor(t,e,i){super("Grid"),nt(this,"children",[]),nt(this,"context"),this.context=t,this.render(e,i)}getAnalyzeChildren(t){if(!t||0===t.length)return[{type:"Write",text:""}];const e=[];t.forEach((i,s)=>{if(s===t.length-1)return;const a=s+1;if("Write"===i.type&&"Write"===t[a].type){let t=a-e.length;e.push(t)}}),e.forEach(e=>{const i=t[e];t[e-1].text+=i.text,t.splice(e,1)});const i=[];return t.forEach((e,s)=>{if(s===t.length-1)return;const a=s+1;if("Write"!==e.type&&"Write"!==t[a].type){let t=a+i.length;i.push(t)}}),i.forEach(e=>{t.splice(e,0,{type:"Write",text:""})}),"Write"!==t[0].type&&t.unshift({type:"Write",text:""}),"Write"!==t[t.length-1].type&&t.push({type:"Write",text:""}),t}emit(t,...e){this.context.bus.emit(t,...e)}mergeNode(t=!1){const e=this.context.NODES.indexOf(this);if(t){const t=this.context.NODES[e+1];if(t){const e=this.children[this.children.length-1],i=t.children[0];this.mergeWriteNode(e,i),this.children.push(...t.children);const s=document.createDocumentFragment();t.children.forEach(t=>{t.updateContext(this),s.appendChild(t.$el)}),this.$el.appendChild(s),e.ruleBRTag(),t.deleteNode()}}else{const t=this.context.NODES[e-1];if(t){const e=t.children[t.children.length-1],i=this.children[0];this.mergeWriteNode(e,i),t.children.push(...this.children);const s=document.createDocumentFragment();this.children.forEach(e=>{e.updateContext(t),s.appendChild(e.$el)}),t.$el.appendChild(s),e.ruleBRTag(),this.deleteNode()}}}splitNode(t,e=0){const i=this.context.NODES.indexOf(this),s=this.children.indexOf(t),a=Boolean(t.text)?t.text.slice(0,e):"",n=Boolean(t.text)?t.text.slice(e):"";t.text=a;const o=this.children.slice(0,s+1),c=this.children.slice(s+1);this.children=o;const h=new ee(this.context,[],{afterElm:this.$el});this.context.NODES.splice(i+1,0,h);const r=h.children[0];r.text=n,h.children.push(...c);const l=document.createDocumentFragment();c.forEach(t=>{t.updateContext(h),l.appendChild(t.$el)}),h.$el.appendChild(l),t.syncNode(),r.syncNode(),r.focus()}deleteNode(){this.children=[];const t=this.context.NODES.indexOf(this);this.context.NODES.splice(t,1),this.context.$el.removeChild(this.$el)}mergeWriteNode(t,e,i=!0,s=!1){const a=t.text||"",n=e.text||"",o=s?n.length:a.length;t.text=s?n+a:a+n,t.syncNode(),e.deleteNode(),i&&t.focus(Boolean(t.text)?o:1)}splitWriteNode(t,e){const i=this.children.indexOf(t),s=Boolean(t.text)?t.text.slice(0,e):"",a=Boolean(t.text)?t.text.slice(e):"";t.text=s,t.syncNode();const n=new Ut(this,{type:"Write",text:a,afterElm:t.$el});this.children.splice(i+1,0,n)}deleteRangeNode(t){const e=t.anchorInstance,i=t.focusInstance;if(e===i)return void e.deleteRangeNode(t);const s=this.children.indexOf(e)>this.children.indexOf(i);"Write"===e.type&&this.splitWriteNode(e,t.anchorOffset),"Write"===i.type&&this.splitWriteNode(i,t.focusOffset);const a=this.children.indexOf(e),n=this.children.indexOf(i);let o=(s?n:a)+1;const c=s?a:n;s&&"Write"!==i.type&&(o-=1);const h=this.children.slice(o,c+1),r=this.children[o-1],l=this.children[c+1];h.forEach(t=>{t.deleteNode()}),this.mergeWriteNode(r,l)}updateNode(){this.context.fixEditor()}backspace(){this.context.fixEditor()}delete(){this.context.fixEditor()}render(t,e){const i=document.createElement("p");this.$el=i,i.className="chat-grid-wrap",i.setAttribute(wt,vt),this.renderChildren(t,!1),this.mount({parentElm:this.context.$el,targetElm:this.$el,...e||{}})}renderChildren(t,e=!0){if(!this.$el)return;this.children=[],this.$el.innerHTML="";const i=this.getAnalyzeChildren(t),s=document.createDocumentFragment();i.forEach(t=>{let e;switch(t.type){case"Write":e=new Ut(this,{...t,parentElm:s}),this.children.push(e);break;case"Mention":e=new qt(this,{...t,parentElm:s}),this.children.push(e);break;case"Trigger":e=new Xt(this,{...t,parentElm:s}),this.children.push(e);break;case"Select":e=new Jt(this,{...t,parentElm:s}),this.children.push(e);break;case"Input":e=new Qt(this,{...t,parentElm:s}),this.children.push(e);break;case"Custom":e=new te(this,{...t,parentElm:s}),this.children.push(e);break;default:const i=this.context.components[t.type];i&&(e=new i({type:t.type,data:t.data,context:this,config:{parentElm:s}}),this.children.push(e))}}),this.$el.appendChild(s);const a=this.children[this.children.length-1];a.ruleBRTag(),e&&(a.focus(-1),this.emit("richTextChange"))}}class ie{constructor(t){ht(this,I),nt(this,"$el"),nt(this,"bus"),nt(this,"chat"),nt(this,"isComposition",!1),nt(this,"textLength",0),ht(this,A,!1),nt(this,"NODES",[]),nt(this,"NODE_HEIGHT",24),nt(this,"IME_MODEL",!1),nt(this,"FIX_MODEL",!1),ht(this,W,[]),nt(this,"components",{}),nt(this,"markCursorWrite",{node:null,offset:0,instance:null}),nt(this,"markCursorInput",{node:null,offset:0,instance:null}),nt(this,"markLastType","Write"),nt(this,"undoHistory",[]),nt(this,"redoHistory",[]),nt(this,"historyLoading",!1),this.chat=t,this.bus=t.bus,this.$el=t.chatElement.richText,lt(this,I,R).call(this),lt(this,I,B).call(this),this.initEditor()}initEditor(){this.$el.innerHTML="",this.NODES=[new ee(this)],this.markLastType="Write",this.NODE_HEIGHT=this.NODES[0].$el.getBoundingClientRect().height,this.undoHistory=[{nodes:this.compileNodes(this.NODES),gridIndex:this.NODES.length-1,childIndex:0,offset:1,type:"Write"}],this.redoHistory=[],this.chat.options.autoFocus&&this.chat.nextTick(()=>{this.focusLast()});const t=this.NODES[this.NODES.length-1],e=t.children[t.children.length-1];lt(this,I,G).call(this,{node:e.$el.children[0].childNodes[0],offset:Boolean(e.text)?e.text.length:1,type:"Write",instance:e})}async fixEditor(t){this.$el.innerHTML="",t||(t=this.compileNodes(this.NODES)),this.NODES=t.map(t=>new ee(this,t)),this.focusLast(),await lt(this,I,V).call(this)}deleteRangeNode(t){let e=t.anchorInstance,i=t.focusInstance;"Grid"===e.type&&(e=e.children[0],t.anchorOffset=Boolean(e.text)?0:1),"Grid"===i.type&&(i=i.children[0],t.focusInstance=Boolean(i.text)?0:1);const s=e.context,a=i.context,n=this.NODES.indexOf(s),o=this.NODES.indexOf(a),c=n>o,h=c?o:n,r=c?n:o;this.NODES.slice(h+1,r).forEach(t=>{t.deleteNode()});const l=c?a:s,d=c?s:a,p=l.children[l.children.length-1],g=d.children[0];c?(l.deleteRangeNode({anchorInstance:p,anchorOffset:Boolean(p.text)?p.text.length:1,focusInstance:i,focusOffset:t.focusOffset}),d.deleteRangeNode({anchorInstance:g,anchorOffset:Boolean(g.text)?0:1,focusInstance:e,focusOffset:t.anchorOffset})):(l.deleteRangeNode({anchorInstance:e,anchorOffset:t.anchorOffset,focusInstance:p,focusOffset:Boolean(p.text)?p.text.length:1}),d.deleteRangeNode({anchorInstance:i,anchorOffset:t.focusOffset,focusInstance:g,focusOffset:Boolean(g.text)?0:1})),l.mergeNode(!0)}findNode(t,e=5,i=!0){if(!t)return null;if(i&&!this.$el.contains(t))return null;if(e<=0)return null;if(t.nodeType===Node.TEXT_NODE)return this.findNode(t.parentElement,e-1);const s=t,a=s.getAttribute?s.getAttribute(wt):"";if(a===Et){const t=s.parentElement,e=t.parentElement,i=Array.prototype.indexOf.call(e.children,t),a=Array.prototype.indexOf.call(this.$el.children,e);return this.NODES[a].children[i]}if(a===bt){const t=s,e=t.parentElement,i=Array.prototype.indexOf.call(e.children,t),a=Array.prototype.indexOf.call(this.$el.children,e);return this.NODES[a].children[i]}if(a===kt||a===Ct||a===Nt||a===Ot||a===Dt||a===Tt){const t=s,e=t.parentElement,i=Array.prototype.indexOf.call(e.children,t),a=Array.prototype.indexOf.call(this.$el.children,e);return this.NODES[a].children[i]}if(a===vt){const t=Array.prototype.indexOf.call(this.$el.children,s);return this.NODES[t]}return this.findNode(s.parentElement,e-1,!1)}focusFirst(){this.NODES[0].children[0].focus(),this.cursorView()}focusMark(){const t=this.chat.getSelection(),e=new Range;switch(this.markLastType){case"Write":e.setStart(this.markCursorWrite.node,this.markCursorWrite.offset),e.setEnd(this.markCursorWrite.node,this.markCursorWrite.offset);break;case"Input":e.setStart(this.markCursorInput.node,this.markCursorInput.offset),e.setEnd(this.markCursorInput.node,this.markCursorInput.offset)}t.removeAllRanges(),t.addRange(e),this.cursorView()}focusLast(){const t=this.NODES[this.NODES.length-1];t.children[t.children.length-1].focus(-1),this.cursorView()}selectAll(){const t=this.chat.getSelection(),e=new Range,i=this.NODES[0].children[0],s=this.NODES[this.NODES.length-1].children[this.NODES[this.NODES.length-1].children.length-1],a=i.$el.children[0].childNodes[0],n=s.$el.children[0].childNodes[0];e.setStart(a,Boolean(i.text)?0:1),e.setEnd(n,Boolean(s.text)?s.text.length:1),t.removeAllRanges(),t.addRange(e)}cursorMove(t,e){const i=e||this.chat.getSelection(),s=t<0;if(!i.isCollapsed){const t=this.findNode(i.anchorNode),e=this.findNode(i.focusNode);if(!t||!e)return;let a,n,o=!1;if(t===e)o=i.anchorOffset>i.focusOffset;else if(t.context===e.context){o=t.context.children.indexOf(t)>e.context.children.indexOf(e)}else{o=this.NODES.indexOf(t.context)>this.NODES.indexOf(e.context)}return s?(a=o?i.focusOffset:i.anchorOffset,n=o?e:t):(a=o?i.anchorOffset:i.focusOffset,n=o?t:e),"Write"===n.type||"Input"===n.type?n.focus(a):n.focus(o),void this.cursorView()}const a=i.focusNode,n=this.findNode(a);let o=0;if(!n)return;if("Write"===n.type){const e=i.focusOffset,a=s?n.text.slice(0,e):n.text.slice(e);if(a.length>=Math.abs(t))return n.focus(e+t),void this.cursorView();o+=a.length}else if("Input"===n.type){const e=i.focusOffset,a=n.$el.children[0].children[0].childNodes[0],c=(s?a.textContent.slice(0,e):a.textContent.slice(e)).replace(new RegExp(`${n.VOID_KEY}|${n.WRAP_KEY[0]}`,"ig"),"");if(c.length>=Math.abs(t)){const i=n.getWrapOffset(a,s?e+t+1:e+t-1,s?"left":"right");return i?s?n.focus(e+t-i+1):n.focus(e+t+i-1):n.focus(e+t),void this.cursorView()}o+=c.length}const c=n.context.children.indexOf(n);if(s){if(0===c){const e=this.NODES.indexOf(n.context);if(0===e)return void n.focus();const i=this.NODES[e-1],s=i.children[i.children.length-1],a=s.$el.children[0].childNodes[0];return o+=1,void this.cursorMove(-(Math.abs(t)-o),{focusNode:a,focusOffset:Boolean(s.text)?s.text.length:1,isCollapsed:!0})}const e=n.context.children[c-1];let i,s;o+=1,"Input"===e.type?(i=e,s=i.$el.children[0].children[0].childNodes[0]):"Write"===e.type?(i=e,s=i.$el.children[0].childNodes[0]):(i=n.context.children[c-2],s=i.$el.children[0].childNodes[0]);const a="Input"===e.type?i.fixWrapKey(i.text):i.text;this.cursorMove(-(Math.abs(t)-o),{focusNode:s,focusOffset:Boolean(a)?a.length:1,isCollapsed:!0})}else{if(c===n.context.children.length-1){const e=this.NODES.indexOf(n.context);if(e===this.NODES.length-1)return void n.focus(-1);const i=this.NODES[e+1].children[0],s=i.$el.children[0].childNodes[0];return o+=1,void this.cursorMove(t-o,{focusNode:s,focusOffset:Boolean(i.text)?0:1,isCollapsed:!0})}const e=n.context.children[c+1];let i,s;o+=1,"Input"===e.type?(i=e,s=i.$el.children[0].children[0].childNodes[0]):"Write"===e.type?(i=e,s=i.$el.children[0].childNodes[0]):(i=n.context.children[c+2],s=i.$el.children[0].childNodes[0]),this.cursorMove(t-o,{focusNode:s,focusOffset:Boolean(i.text)?0:1,isCollapsed:!0})}}cursorView(){const t=this.$el.parentElement;if(t.scrollHeight<=t.clientHeight)return;const e=this.chat.getSelection().getRangeAt(0).getClientRects()[0],i=t.getClientRects()[0],s=e.y-i.y;s<0?t.scrollTop=t.scrollTop-Math.abs(s):s+e.height>i.height&&(t.scrollTop=t.scrollTop+(s+e.height-i.height))}compileNodes(t){const e=[];return t.forEach(t=>{const i=[];t.children.forEach(t=>{switch(t.type){case"Write":i.push({type:"Write",text:t.text});break;case"Mention":i.push({type:"Mention",id:t.id,name:t.name});break;case"Trigger":i.push({type:"Trigger",id:t.id,name:t.name,key:t.key});break;case"Select":i.push({type:"Select",id:t.id,name:t.name,key:t.key});break;case"Input":i.push({type:"Input",placeholder:t.placeholder,text:t.text,key:t.key});break;case"Custom":i.push({type:"Custom",html:t.html});break;default:this.components[t.type]&&i.push({type:t.type,data:t.data})}}),e.push(i)}),e}async insertText(t){const e=t.replace(new RegExp(`${Lt}`,"ig"),"").replace(/\r\n/g,"\n").replace(/\r/g,"\n").split("\n").map(t=>[{type:"Write",text:t}]);await this.insertNodes(e)}async insertNodes(t){const{instance:e,offset:i}=this.markCursorWrite;if(!e)return;const s=e,a=s.context,n=this.NODES.indexOf(a);a.splitNode(s,i);let o=a.$el,c=null,h=null;t.forEach((e,i)=>{const s=new ee(this,e,{afterElm:o});o=s.$el,0===i?c=s:i===t.length-1&&(h=s),this.NODES.splice(n+i+1,0,s)}),c&&c.mergeNode(),h?h.mergeNode(!0):a.mergeNode(!0),await lt(this,I,V).call(this)}async insertInputText(t){const{instance:e,offset:i}=this.markCursorInput;if(!e)return;const s=e,a=t.replace(new RegExp(`${Lt}`,"ig"),"").replace(/\r\n/g,"\n").replace(/\r/g,"\n");s.setText(i,a),await lt(this,I,V).call(this)}splitWrite(t){const{instance:e,offset:i}=this.markCursorWrite;if(!e)return null;const s=e,a=s.context,n=a.children.indexOf(s);return s.splitNode(i,t.del,t.beforeText,t.afterText),{index:n,write:s,grid:a}}async insertMention(t){const e=this.splitWrite(t);if(!e)return;const{index:i,write:s,grid:a}=e,n=new qt(a,{type:"Mention",id:t.id,name:t.name,afterElm:s.$el});a.children.splice(i+1,0,n),await lt(this,I,V).call(this)}async insertTrigger(t){const e=this.splitWrite(t);if(!e)return;const{index:i,write:s,grid:a}=e,n=new Xt(a,{type:"Trigger",id:t.id,name:t.name,key:t.key,afterElm:s.$el});a.children.splice(i+1,0,n),await lt(this,I,V).call(this)}async insertSelect(t){const e=this.splitWrite(t);if(!e)return;const{index:i,write:s,grid:a}=e,n=new Jt(a,{type:"Select",id:t.id,name:t.name,key:t.key,afterElm:s.$el});a.children.splice(i+1,0,n),await lt(this,I,V).call(this)}async insertInput(t){const e=this.splitWrite(t);if(!e)return;const{index:i,write:s,grid:a}=e,n=new Qt(a,{type:"Input",text:t.text,placeholder:t.placeholder,key:t.key,afterElm:s.$el});a.children.splice(i+1,0,n),n.focus(-1),await lt(this,I,V).call(this)}async insertCustom(t){const e=this.splitWrite(t);if(!e)return;const{index:i,write:s,grid:a}=e,n=new te(a,{type:"Custom",html:t.html,afterElm:s.$el});a.children.splice(i+1,0,n),await lt(this,I,V).call(this)}async reset(t){if(this.$el.innerHTML="",this.NODES=t.chatNode.map(t=>new ee(this,t)),t.clearHistory){const t=this.NODES[this.NODES.length-1],e=t.children[t.children.length-1];this.undoHistory=[{nodes:this.compileNodes(this.NODES),gridIndex:this.NODES.length-1,childIndex:t.children.length-1,offset:Boolean(e.text)?e.text.length:1,type:"Write"}],this.redoHistory=[]}this.markLastType="Write",await this.chat.nextTick(),this.focusLast(),await lt(this,I,V).call(this,!t.clearHistory)}destroy(){this.bus.offKeyEvent("ChatEditor"),ct(this,W).forEach(t=>{const e=t[0],i=t[1];for(const s in i)e.removeEventListener(s,i[s])})}useComponent(t,e){this.components[t]=e}async insertComponent(t,e){const i=this.components[t];if(!i)return;const s=this.splitWrite({type:t,data:e,del:0});if(!s)return;const{index:a,write:n,grid:o}=s,c=new i({type:t,data:e,context:o,config:{afterElm:n.$el}});o.children.splice(a+1,0,c),await lt(this,I,V).call(this)}}A=new WeakMap,W=new WeakMap,I=new WeakSet,R=function(){const t="ChatEditor";this.bus.on(t,"richTextChange",async t=>{await lt(this,I,V).call(this),t&&t()}),this.bus.on(t,"richTextDelete",async(t,e)=>{await lt(this,I,P).call(this,t),e&&e()}),this.bus.on(t,"cursorChange",t=>{lt(this,I,G).call(this,t)}),this.bus.on(t,"lineBreak",async t=>{await lt(this,I,H).call(this),t&&t()}),this.bus.on(t,"undo",async t=>{await lt(this,I,F).call(this),t&&t()}),this.bus.on(t,"redo",async t=>{await lt(this,I,Y).call(this),t&&t()}),this.bus.on(t,"recordHistory",$t(lt(this,I,_),200).bind(this)),this.bus.on(t,"ruleMaxLength",()=>{lt(this,I,U).call(this)}),this.bus.on(t,"switchDisabledState",t=>{rt(this,A,t)}),this.bus.on(t,"insertMention",async(t,e)=>{await this.insertMention(t),e&&e()}),this.bus.on(t,"insertTrigger",async(t,e)=>{await this.insertTrigger(t),e&&e()}),this.bus.on(t,"insertSelect",async(t,e)=>{await this.insertSelect(t),e&&e()}),this.bus.on(t,"insertInput",async(t,e)=>{await this.insertInput(t),e&&e()}),this.bus.on(t,"insertCustom",async(t,e)=>{await this.insertCustom(t),e&&e()}),this.bus.on(t,"focus",t=>{switch(t){case"first":this.focusFirst();break;case"last":this.focusLast();break;case"mark":this.focusMark()}}),this.bus.on(t,"destroy",()=>{this.destroy()})},B=function(){rt(this,W,[[this.$el,{keydown:t=>{if(this.isComposition=t.isComposing,this.chat.deviceInfo.isPc||!Bt(t,"IME")){if(!this.IME_MODEL)if(this.isComposition||!Bt(t,"text-backspace")&&!Bt(t,"text-delete"))this.chat.options.keyboardWrapFun(t)||!this.chat.deviceInfo.isPc&&"Enter"===t.key?(t.preventDefault(),t.stopPropagation(),lt(this,I,H).call(this)):!ct(this,A)&&this.chat.options.keyboardSendFun(t)?(t.preventDefault(),t.stopPropagation(),this.isComposition||this.bus.emit("send")):Bt(t,"text-select-all")?(t.preventDefault(),t.stopPropagation(),this.selectAll()):Bt(t,"text-move")?(t.preventDefault(),t.stopPropagation(),this.isComposition||this.cursorMove("ArrowLeft"===t.key||"ArrowLeft"===t.code?-1:1)):Bt(t,"text-undo")?(t.preventDefault(),t.stopPropagation(),lt(this,I,F).call(this)):Bt(t,"text-redo")?(t.preventDefault(),t.stopPropagation(),lt(this,I,Y).call(this)):Bt(t,"text-jump")&&(t.preventDefault(),t.stopPropagation(),t.shiftKey?this.chat.jumpPrev():this.chat.jumpNext());else{t.preventDefault(),t.stopPropagation();const e=Bt(t,"text-delete");lt(this,I,P).call(this,e)}}else this.IME_MODEL=!0},beforeinput:async t=>{if(!this.IME_MODEL||!["insertParagraph","deleteContentBackward"].includes(t.inputType))return;t.preventDefault(),t.stopPropagation();const e=this.chat.getSelection();let i=this.findNode(e.focusNode),s=e.focusOffset;if(i||(i=this.findNode(this.markCursorWrite.node),s=this.markCursorWrite.offset),!i)return;"Grid"===i.type&&(i=i.children[0]),this.FIX_MODEL=!0;const a=i,n=this.NODES.indexOf(a.context),o=a.context.children.indexOf(a),c=this.compileNodes(this.NODES);this.chat.nextTick(async()=>{this.$el.innerHTML="",this.NODES=c.map(t=>new ee(this,t));this.NODES[n].children[o].focus(s),"insertParagraph"===t.inputType?await lt(this,I,H).call(this):"deleteContentBackward"===t.inputType&&await lt(this,I,P).call(this),this.IME_MODEL=!1,this.FIX_MODEL=!1})},input:()=>{this.FIX_MODEL||(this.IME_MODEL=!1,lt(this,I,V).call(this))},copy:t=>{t.stopPropagation(),t.preventDefault(),lt(this,I,K).call(this,t)},cut:t=>{t.stopPropagation(),t.preventDefault(),lt(this,I,K).call(this,t),lt(this,I,P).call(this)},paste:t=>{t.stopPropagation(),t.preventDefault(),lt(this,I,z).call(this,t)},blur:()=>{lt(this,I,G).call(this)},focus:()=>{lt(this,I,G).call(this)},click:()=>{this.chat.nextTick(()=>{lt(this,I,G).call(this)})},compositionstart:()=>{this.isComposition=!0},compositionend:()=>{this.isComposition=!1},dragstart:t=>{t.stopPropagation(),t.preventDefault()},dragover:t=>{t.stopPropagation(),t.preventDefault()},drop:t=>{t.stopPropagation(),t.preventDefault()}}],[window,{keydown:t=>{(Bt(t,"text-undo")||Bt(t,"text-redo"))&&(t.preventDefault(),t.stopPropagation())}}]]);const t=["blur"];ct(this,W).forEach(e=>{const i=e[0],s=e[1];for(const a in s)i.addEventListener(a,s[a],-1!==t.indexOf(a))})},P=async function(t=!1){const e=this.chat.getSelection(),i=e.anchorNode,s=e.focusNode;let a=this.findNode(i),n=this.findNode(s);if(a&&n){if(a===n)t?a.delete(e):a.backspace(e);else if(a.context===n.context){a.context.deleteRangeNode({anchorInstance:a,anchorOffset:e.anchorOffset,focusInstance:n,focusOffset:e.focusOffset})}else this.deleteRangeNode({anchorInstance:a,anchorOffset:e.anchorOffset,focusInstance:n,focusOffset:e.focusOffset});await lt(this,I,V).call(this)}},H=async function(){if(this.isComposition)return;let t=this.chat.getSelection();t.isCollapsed||await lt(this,I,P).call(this),t=this.chat.getSelection();const e=t.focusNode,i=this.findNode(e);if(i){if("Write"===i.type){i.context.splitNode(i,t.focusOffset)}else"Input"===i.type&&i.setText(t.focusOffset,"\n");await lt(this,I,V).call(this)}},K=function(t){const e=this.chat.getSelection(),i=t.clipboardData;if(e.isCollapsed||e.rangeCount<=0)return;const s=e.toString().replace(/\n\n/g,"\n")||"";i.setData("text/plain",s);let a=this.findNode(e.anchorNode),n=this.findNode(e.focusNode),o=e.anchorOffset,c=e.focusOffset;if(!a||!n)return;if("Grid"===a.type&&(a=a.children[0],o=Boolean(a.text)?0:1),"Grid"===n.type&&(n=n.children[0],c=Boolean(n.text)?0:1),a===n)return;const h=a.context,r=n.context;if(h===r){const t=h.children.indexOf(a),e=r.children.indexOf(n),s=t>e,l=s?e:t,d=s?t:e,p=h.children.slice(l+1,d),g={...s?n:a},u={...s?a:n},f=s?c:o,m=s?o:c;"Write"===g.type&&(g.text=g.text.slice(f)),"Write"===u.type&&(u.text=u.text.slice(0,m)),p.unshift(g),p.push(u);const x={type:"Grid",children:p},y=this.compileNodes([x]);return void i.setData(St,JSON.stringify(y))}const l=a.context,d=n.context,p=this.NODES.indexOf(l),g=this.NODES.indexOf(d);let u,f,m,x,y,w,v,b;p>g?(u=d,f=l,m=n,x=a,y=g,w=p,v=c,b=o):(u=l,f=d,m=a,x=n,y=p,w=g,v=o,b=c);const E=u.children.indexOf(m),k=this.compileNodes([{type:"Gird",children:u.children.filter((t,e)=>e>E)}]);"Write"===m.type?k[0].unshift({type:"Write",text:Boolean(m.text)?m.text.slice(v):""}):k[0].unshift({...this.compileNodes([{type:"Gird",children:[m]}])[0][0]});const C=f.children.indexOf(x),N=this.compileNodes([{type:"Gird",children:f.children.filter((t,e)=>e<C)}]);"Write"===x.type?N[0].push({type:"Write",text:Boolean(x.text)?x.text.slice(0,b):""}):N[0].push({...this.compileNodes([{type:"Gird",children:[x]}])[0][0]});const O=this.compileNodes(this.NODES.slice(y+1,w));O.unshift(k[0]),O.push(N[0]),i.setData(St,JSON.stringify(O))},z=async function(t){const e=t.clipboardData,i=e.getData("text/plain");if(!i)return;if("Input"===this.markLastType)return void this.insertInputText(i);const s=e.getData(St)||"";let a=[];try{a=JSON.parse(s)}catch(n){}this.chat.getSelection().isCollapsed||await lt(this,I,P).call(this),a&&a.length>0?this.insertNodes(a):this.insertText(i)},_=function(){if("Input"===this.markLastType){const{instance:t,offset:e}=this.markCursorInput;if(!t)return;const i=t,s=i.context;this.undoHistory.push({nodes:this.compileNodes(this.NODES),gridIndex:this.NODES.indexOf(s),childIndex:s.children.indexOf(i),offset:e,type:"Input"})}else{const{instance:t,offset:e}=this.markCursorWrite;if(!t)return;const i=t,s=i.context;this.undoHistory.push({nodes:this.compileNodes(this.NODES),gridIndex:this.NODES.indexOf(s),childIndex:s.children.indexOf(i),offset:e,type:"Write"})}this.undoHistory.length>50&&this.undoHistory.shift()},F=async function(){if(this.historyLoading||this.undoHistory.length<=1)return;const t=this.undoHistory[this.undoHistory.length-1],e=this.undoHistory[this.undoHistory.length-2];this.redoHistory.push(t),this.undoHistory.pop(),await lt(this,I,j).call(this,e)},Y=async function(){if(this.historyLoading||this.redoHistory.length<=0)return;const t=this.redoHistory[this.redoHistory.length-1];this.redoHistory.pop(),this.undoHistory.push(t),await lt(this,I,j).call(this,t)},j=async function(t){this.historyLoading=!0,this.$el.innerHTML="",this.NODES=t.nodes.map(t=>new ee(this,t));this.NODES[t.gridIndex].children[t.childIndex].focus(t.offset),await lt(this,I,V).call(this,!1),this.historyLoading=!1},V=async function(t=!0){const e=this.chat.getSelection(),i=e.focusNode,s=this.findNode(i);return s&<(this,I,G).call(this,{type:s.type,node:s.$el.children[0].childNodes[0],offset:e.focusOffset,instance:s}),await this.chat.nextTick(),this.isComposition||(null==s||s.updateNode(),lt(this,I,U).call(this),this.chat.deviceInfo.isPc&&t&&!this.historyLoading&&this.bus.emit("recordHistory")),s&&this.cursorView(),this.bus.emit("editorChange"),s&&"Write"===s.type&&this.bus.emit(this.isComposition?"updateDialogReact":"matchDialog"),!0},G=function(t){if(!t){const e=this.chat.getSelection(),i=e.focusNode,s=this.findNode(i);if(!s)return;"Write"===s.type?t={type:s.type,node:s.$el.children[0].childNodes[0],offset:e.focusOffset,instance:s}:"Input"===s.type&&(t={type:s.type,node:s.$el.children[0].children[0].childNodes[0],offset:e.focusOffset,instance:s})}if(t)switch(t.type){case"Write":this.markCursorWrite.node=t.node,this.markCursorWrite.offset=t.offset,this.markCursorWrite.instance=t.instance,this.markLastType="Write";break;case"Input":this.markCursorInput.node=t.node,this.markCursorInput.offset=t.offset,this.markCursorInput.instance=t.instance,this.markLastType="Input"}},U=function(){const t=this.chat.options.maxLength;if(-1===t)return;let e=0;const i=[];if(this.NODES.forEach((t,s)=>{let a=0;a=s>0&&1===t.children.length&&0===t.children[0].text.length?1:t.$el.textContent.replace(new RegExp(Lt,"ig"),"").length,i.push(a),e+=a}),e>t){const s=e-t;let a=0,n=0;for(let t=i.length-1;t>=0;t--)if(a+=i[t],a>=s){n=t;break}this.NODES.slice(n+1).forEach(t=>{t.deleteNode()});let o=a-s;const c=this.NODES[n];if(0===o&&n>0){c.deleteNode();const e=this.NODES[n-1];return e.children[e.children.length-1].focus(-1),void(this.textLength=t)}let h=null,r=0;for(let t=0;t<c.children.length;t++){const e=c.children[t];if("Write"===e.type?o-=e.text.length:o-=e.$el.textContent.length,o<=0){h=e,r=t;break}}if(c.children.slice(r+1).forEach(t=>{t.deleteNode()}),"Write"===h.type){const e=h;e.text=e.text.slice(0,e.text.length-Math.abs(o)),e.syncNode(),e.updateNode(),e.focus(-1),this.textLength=t}else{const e=c.children[r-1];h.deleteNode(),e.ruleBRTag(),e.focus(-1),this.textLength=t-Math.abs(o)}}else this.textLength=e};class se{constructor(){ht(this,Z),ht(this,q),rt(this,Z,Object.create(null)),rt(this,q,Object.create(null))}on(t,e,i){ct(this,Z)[e]||(ct(this,Z)[e]=Object.create(null)),ct(this,q)[t]||(ct(this,q)[t]=[]),ct(this,q)[t].push(e),ct(this,Z)[e][t]=i}emit(...t){const e=t[0],i=t.slice(1),s=ct(this,Z)[e];if(s)for(const a in s)s[a](...i)}off(t,e){for(const i in ct(this,Z)[e])i+""==t+""&&delete ct(this,Z)[e][t];0===Object.keys(ct(this,Z)[e]).length&&delete ct(this,Z)[e]}offKeyEvent(t){(ct(this,q)[t]||[]).forEach(e=>{this.off(t,e)}),delete ct(this,q)[t]}}Z=new WeakMap,q=new WeakMap;X=new WeakMap,J=new WeakSet,Q=function(t,...e){this.context.context.bus.emit(t,...e)},tt=function(t,e=""){Array.from(t.children,(t,i)=>{const s=String(""===e?i:e+"-"+i);t.children&&t.children.length>0&<(this,J,tt).call(this,t,s);const a=t,n=a.dataset||{};if(n){n.update&&(ct(this,X)[s]=a,a.removeAttribute("data-update"),delete n.update);for(const t in n){const e=n[t];a.addEventListener(t,t=>{const i=this[e](t);i instanceof Promise?i.then(()=>{lt(this,J,et).call(this)}):lt(this,J,et).call(this)}),a.removeAttribute("data-"+t)}}})},et=function(){const t=document.createElement("span");t.innerHTML=this.render();for(let e in ct(this,X)){const i=e.split("-");ct(this,X)[e].innerHTML=lt(this,J,it).call(this,t,i)}},it=function(t,e){return 1===e.length?t.children[Number(e[0])].innerHTML:lt(this,J,it).call(this,t.children[Number(e[0])],e.slice(1))};class ae{constructor(t,e){switch(nt(this,"options"),nt(this,"deviceInfo",function(){if("undefined"==typeof navigator)return{isTablet:!1,isPhone:!1,isAndroid:!1,isIOS:!1,isPc:!0,isIPhone:!1,isIPad:!1,isWindows:!1,isMacOS:!1,isLinux:!1,isWechat:!1,isMobile:!1};const t=navigator.userAgent.toLowerCase(),e=t.includes("windows"),i=t.includes("macintosh"),s=t.includes("linux")&&!t.includes("android"),a=t.includes("android"),n=/iphone|ipad|ipod/.test(t),o=t.includes("iphone"),c=t.includes("ipad")||t.includes("macintosh")&&navigator.maxTouchPoints>1,h=t.includes("micromessenger"),r=c||a&&!/mobile/.test(t)||t.includes("firefox")&&t.includes("tablet")||t.includes("playbook"),l=o&&!r||a&&/mobile/.test(t)||t.includes("windows phone");return{isTablet:r,isPhone:l,isAndroid:a,isIOS:n,isPc:!l&&!r&&(e||i||s),isIPhone:o,isIPad:c,isWindows:e,isMacOS:i,isLinux:s,isWechat:h,isMobile:l||r}}()),nt(this,"chatElement"),nt(this,"chatEditor"),nt(this,"bus"),this.options=Object.assign({},ut,e||{},{mentionConfig:void 0}),this.deviceInfo.isTablet&&(this.deviceInfo.isPc=!1),this.options.device){case"pc":this.deviceInfo.isPc=!0;break;case"h5":this.deviceInfo.isPc=!1}this.bus=new se,this.chatElement=new Vt(t,this),this.chatEditor=new ie(this),this.updateConfig(e)}updateConfig(t){At(t.placeholder)&&this.chatElement.updatePlaceholder(t.placeholder),At(t.chatStyle)&&this.chatElement.updateChatStyle(t.chatStyle),At(t.maxLength)&&(this.options.maxLength=t.maxLength<=0?-1:t.maxLength,this.bus.emit("ruleMaxLength")),At(t.keyboardWrapFun)&&(this.options.keyboardWrapFun=t.keyboardWrapFun),At(t.keyboardSendFun)&&(this.options.keyboardSendFun=t.keyboardSendFun),At(t.mentionConfig)&&(this.options.mentionConfig=Object.assign({},this.options.mentionConfig||ft,t.mentionConfig),this.chatElement.createMentionDialog()),At(t.triggerConfig)&&(this.options.triggerConfig=t.triggerConfig.map(t=>(t.keyMap||(t.keyMap=mt[t.key]||[]),t)),this.chatElement.createTriggerDialog()),At(t.selectConfig)&&(this.options.selectConfig=t.selectConfig,this.chatElement.createSelectDialog()),At(t.tipConfig)&&(this.options.tipConfig=Object.assign({},xt,t.tipConfig),this.chatElement.createBeforeTip())}async nextTick(t){return new Promise(e=>{requestAnimationFrame(()=>{if(!t)return void e();const i=t();i instanceof Promise?i.then(()=>{e()}):e()})})}getSelection(){return window.getSelection()}getModel(){return this.chatEditor.compileNodes(this.chatEditor.NODES)}getHtml(t){const e=Object.assign({},{saveTagData:!1,identifyLink:!1},t||{}),i=/(https?|http|ftp|file):\/\/[-A-Za-z0-9+&@#/%?=~_|!:,.;]+[-A-Za-z0-9+&@#/%=~_|]/g,s=this.getModel();let a="",n="";return s.forEach((t,s)=>{let o='<p class="chat-tag-grid">';t.forEach((t,a)=>{let c="<span ";switch(t.type){case"Mention":c+='class="chat-tag-mention"',e.saveTagData&&(c+=` data-id="${t.id}"`),c+=`>@${It(t.name)}`;break;case"Trigger":c+='class="chat-tag-trigger"',e.saveTagData&&(c+=` data-id="${t.id}" data-key=${t.key}`),c+=`>${t.key}${It(t.name)}`;break;case"Select":c+='class="chat-tag-select"',e.saveTagData&&(c+=` data-id="${t.id}" data-key=${t.key}`),c+=`>${It(t.name)}`;break;case"Input":c+='class="chat-tag-input"',e.saveTagData&&(c+=` data-placeholder="${t.placeholder}" data-key=${t.key}`),c+=`>${It(t.text||t.placeholder)}`;break;case"Custom":c+='class="chat-tag-custom"',c+=`>${t.html}`;break;case"Write":c+='class="chat-tag-write"',n=It(t.text),e.identifyLink?c+=`>${n.replace(i,t=>`<a class="chat-tag-link" href="${t}" target="_blank">${t}</a>`)}`:c+=`>${n}`;break;default:const o=this.chatEditor.NODES[s].children[a];if(c+='class="chat-tag-component"',e.saveTagData){for(const t in o.data)c+=` data-${t}="${o.data[t]}"`;c+=` data-type="${o.type}"`}c+=`>${o.$el.innerHTML}`}c+="</span>",o+=c}),o+="</p>",a+=o}),a}getText(){let t="";return this.getModel().forEach((e,i)=>{0!==i&&(t+="\n"),e.forEach((e,s)=>{switch(e.type){case"Write":t+=e.text;break;case"Input":t+=e.text||`[${e.placeholder}]`;break;default:t+=this.chatEditor.NODES[i].children[s].$el.textContent||""}})}),t.replace(new RegExp(`${Lt}|${"\n"[0]}`,"ig"),"")}getTagData(){const t={mention:[],trigger:{},select:{},input:{}},e={mention:new Map,trigger:{},select:{}};return this.getModel().forEach(i=>{i.forEach(i=>{switch(i.type){case"Mention":e.mention.set(i.id,{id:i.id,name:i.name});break;case"Trigger":e.trigger[i.key]||(e.trigger[i.key]=new Map),e.trigger[i.key].set(i.id,{id:i.id,name:i.name});break;case"Select":e.select[i.key]||(e.select[i.key]=new Map),i.id&&i.id.split(",").length>0?i.id.split(",").forEach((t,s)=>{e.select[i.key].set(t,{id:t,name:i.name.split("、")[s]})}):e.select[i.key].set(i.id,{id:i.id,name:i.name});break;case"Input":t.input[i.key]||(t.input[i.key]=[]),t.input[i.key].push({text:i.text||"",placeholder:i.placeholder||""})}})}),t.mention=Array.from(e.mention.values()),Object.keys(e.trigger).forEach(i=>{t.trigger[i]=Array.from(e.trigger[i].values())}),Object.keys(e.select).forEach(i=>{t.select[i]=Array.from(e.select[i].values())}),t}setLineBreak(){return new Promise(t=>{this.bus.emit("lineBreak",t)})}async setHtml(t){await this.chatEditor.insertCustom({html:`<span style="display: inline-block;">${Rt(t)}</span>`})}async setText(t){switch(this.chatEditor.markLastType){case"Write":await this.chatEditor.insertText(t);break;case"Input":await this.chatEditor.insertInputText(t)}}async setMention(t){await this.chatEditor.insertMention(t)}async setTrigger(t){await this.chatEditor.insertTrigger(t)}async setSelect(t){await this.chatEditor.insertSelect(t)}async setInput(t){await this.chatEditor.insertInput(t)}async setChatNode(t){await this.chatEditor.insertNodes(t)}removeMention(t){return new Promise(e=>{const i=[];this.chatEditor.NODES.forEach(e=>{e.children.forEach(e=>{const s=e;"Mention"!==s.type||t&&!t.includes(s.id)||i.push(s)})}),i.forEach(t=>{t.deleteRelevanceNode()}),this.bus.emit("richTextChange",e)})}removeTrigger(t,e){return new Promise(i=>{const s=[];this.chatEditor.NODES.forEach(i=>{i.children.forEach(i=>{const a=i;"Trigger"!==a.type||a.key!==t||e&&!e.includes(a.id)||s.push(a)})}),s.forEach(t=>{t.deleteRelevanceNode()}),this.bus.emit("richTextChange",i)})}removeSelect(t,e){return new Promise(i=>{const s=[];this.chatEditor.NODES.forEach(i=>{i.children.forEach(i=>{const a=i;"Select"!==a.type||a.key!==t||e&&!e.includes(a.id)||s.push(a)})}),s.forEach(t=>{t.deleteRelevanceNode()}),this.bus.emit("richTextChange",i)})}removeInput(t){return new Promise(e=>{const i=[];this.chatEditor.NODES.forEach(e=>{e.children.forEach(e=>{const s=e;"Input"===s.type&&s.key===t&&i.push(s)})}),i.forEach(t=>{t.deleteRelevanceTag()}),this.bus.emit("richTextChange",e)})}async reverseHtml(t,e=!1){let i=document.createElement("div");i.innerHTML=t;const s=[];Array.from(i.children,t=>{const e=[];Array.from(t.children,t=>{const i=t;switch(i.className){case"chat-tag-write":e.push({type:"Write",text:i.textContent});break;case"chat-tag-mention":e.push({type:"Mention",id:i.dataset.id||"",name:(i.textContent||"").slice(1)});break;case"chat-tag-trigger":e.push({type:"Trigger",key:i.dataset.key||"",id:i.dataset.id||"",name:(i.textContent||"").slice(1)});break;case"chat-tag-select":e.push({type:"Select",key:i.dataset.key||"",id:i.dataset.id||"",name:i.textContent});break;case"chat-tag-input":e.push({type:"Input",key:i.dataset.key||"",text:i.textContent,placeholder:i.dataset.placeholder||""});break;case"chat-tag-custom":e.push({type:"Custom",html:i.innerHTML});break;case"chat-tag-component":const t=i.dataset.type,s=i.dataset;"type"in s&&delete s.type,e.push({type:t,data:s})}}),s.push(e)}),e?(this.chatEditor.focusLast(),await this.chatEditor.insertNodes(s)):await this.chatEditor.fixEditor(s)}undo(){return new Promise(t=>{this.bus.emit("undo",t)})}redo(){return new Promise(t=>{this.bus.emit("redo",t)})}jumpPrev(t="end"){this.bus.emit("cursorChange");const e="Write"===this.chatEditor.markLastType?this.chatEditor.markCursorWrite.instance:this.chatEditor.markCursorInput.instance,i=e.context,s=i.children.indexOf(e),a=[...i.children.slice(0,s)].reverse().find(t=>"Write"===t.type||"Input"===t.type);if(a)return void a.focus("start"===t?0:-1);const n=i.context.NODES.indexOf(i);let o;[...this.chatEditor.NODES.slice(0,n)].reverse().some(t=>[...t.children].reverse().some(t=>{if("Write"===t.type||"Input"===t.type)return o=t,!0})),o?o.focus("start"===t?0:-1):this.focus("first")}jumpNext(t="end"){this.bus.emit("cursorChange");const e="Write"===this.chatEditor.markLastType?this.chatEditor.markCursorWrite.instance:this.chatEditor.markCursorInput.instance,i=e.context,s=i.children.indexOf(e),a=i.children.slice(s+1).find(t=>"Write"===t.type||"Input"===t.type);if(a)return void a.focus("start"===t?0:-1);const n=i.context.NODES.indexOf(i);let o;this.chatEditor.NODES.slice(n+1).some(t=>t.children.some(t=>{if("Write"===t.type||"Input"===t.type)return o=t,!0})),o?o.focus("start"===t?0:-1):this.focus("last")}move(t){this.chatEditor.focusMark(),0!==t&&this.chatEditor.cursorMove(t)}backspace(t){return new Promise(e=>{if(this.chatEditor.focusMark(),0===t)return e();if(-1===t||1===t)return void this.bus.emit("richTextDelete",t>0,e);const i=this.getSelection(),s=i.focusNode,a=i.focusOffset;this.chatEditor.cursorMove(t);const n=this.getSelection(),o=n.focusNode,c=n.focusOffset,h=new Range,r=t<0;r?(h.setStart(o,c),h.setEnd(s,a)):(h.setStart(s,a),h.setEnd(o,c)),n.removeAllRanges(),n.addRange(h),this.bus.emit("richTextDelete",!r,e)})}focus(t="last"){this.bus.emit("focus",t)}disable(){this.chatElement.richText.setAttribute("contenteditable","false"),this.chatElement.rollBox.classList.add("disabled")}enable(){this.chatElement.richText.setAttribute("contenteditable","true"),this.chatElement.rollBox.classList.remove("disabled"),this.focus()}async reset(t){const e=Object.assign({},{clearHistory:!0,chatNode:[[{type:"Write",text:""}]]},t||{});await this.chatEditor.reset(e)}isEmpty(t=!0){if(t)return 0===this.getText().trim().length;const e=this.chatEditor.NODES;return!(e.length>1)&&(!(e[0].children.length>1)&&e[0].children[0].text.length<=0)}destroy(){this.bus.emit("destroy");for(const t in this)delete this[t];Object.setPrototypeOf(this,Object.create(null))}showSelectPopup(t,e){this.bus.emit("activeSelect",{key:t,$el:e})}showTip(t){this.bus.emit("openTip",t)}closeTip(){this.bus.emit("closeTip")}getCurrentNode(){switch(this.chatEditor.markLastType){case"Input":return this.chatEditor.markCursorInput;case"Write":return this.chatEditor.markCursorWrite}}useComponent(t,e){this.chatEditor.useComponent(t,e)}async setComponent(t,e){await this.chatEditor.insertComponent(t,e)}}return nt(ae,"version","1.2.6"),nt(ae,"Component",class extends Zt{constructor(t){var e;super(t.type,t.context),ht(this,J),nt(this,"data",{}),ht(this,X,{}),this.data=t.data||{},this.$el=document.createElement("span"),this.$el.setAttribute(wt,Tt),this.$el.setAttribute("contenteditable","false"),this.$el.classList.add("chat-tag-wrap"),this.$el.innerHTML=this.render(),lt(this,J,tt).call(this,this.$el),this.mount({parentElm:(null==(e=t.config)?void 0:e.parentElm)||this.context.$el,targetElm:this.$el,...t.config||{}})}remove(){this.deleteRelevanceNode(),lt(this,J,Q).call(this,"richTextChange")}render(){return"undefined"}}),ae});
|
|
1
|
+
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).XSender=e()}(this,function(){"use strict";var t,e,i,s,n,a,o,c,h,r,l,d,p,g,f,u,m,x,y,E,w,v,b,N,k,O,C,T,D,S,L,M,I,A,$,R,W,_,K,P,B,H,V,z,F,Y,j,G,U,X,Z,q,J,Q,tt,et,it,st=Object.defineProperty,nt=t=>{throw TypeError(t)},at=(t,e,i)=>((t,e,i)=>e in t?st(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i)(t,"symbol"!=typeof e?e+"":e,i),ot=(t,e,i)=>e.has(t)||nt("Cannot "+i),ct=(t,e,i)=>(ot(t,e,"read from private field"),i?i.call(t):e.get(t)),ht=(t,e,i)=>e.has(t)?nt("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(t):e.set(t,i),rt=(t,e,i,s)=>(ot(t,e,"write to private field"),s?s.call(t,i):e.set(t,i),i),lt=(t,e,i)=>(ot(t,e,"access private method"),i),dt=document.createElement("style");dt.textContent=':root{--chat-primary: #1890ff;--chat-disabled: #e8e8e8;--chat-highlight: #40A9FF;--chat-text: #333;--chat-text-assistant: #666;--chat-text-secondary: #ccc;--chat-text-placeholder: #bfbfbf;--chat-box: #fff;--chat-box-shadow: 1px 3px 10px 2px rgba(6, 21, 50, .2);--chat-box-mark: rgba(0, 0, 0, .5);--chat-input: #FFFFFF;--chat-input-border: #D9D9D9;--chat-input-shadow-color: rgba(24, 144, 255, .2);--chat-card: #F2F6FC;--chat-highlight-card: #E6F7FF;--chat-popover: #000;--chat-popover-text: #fff;--chat-rect-padding: 10px;--chat-before-tip-width: 0px;--chat-before-tip-top: 0px;--chat-tip-dialog-top: 0px;--chat-tip-dialog-left: 0px}@-webkit-keyframes antSpinMove{to{opacity:1}}@keyframes antSpinMove{to{opacity:1}}@-webkit-keyframes antRotate{to{transform:rotate(405deg)}}@keyframes antRotate{to{transform:rotate(405deg)}}.ant-spin{font-size:14px;line-height:1.5;list-style:none;font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica Neue,Arial,Noto Sans,sans-serif,"Apple Color Emoji","Segoe UI Emoji",Segoe UI Symbol,"Noto Color Emoji";position:absolute;display:none;text-align:center;vertical-align:middle;opacity:0;transition:transform .3s cubic-bezier(.78,.14,.15,.86)}.ant-spin .ant-spin-dot{position:relative;display:inline-block;font-size:20px;width:1em;height:1em}.ant-spin .ant-spin-dot-spin{transform:rotate(45deg);animation-name:antRotate;animation-duration:1.2s;animation-iteration-count:infinite;animation-timing-function:linear}.ant-spin .ant-spin-dot-item{position:absolute;display:block;width:9px;height:9px;background-color:var(--chat-primary);border-radius:100%;transform:scale(.75);transform-origin:50% 50%;opacity:.3;animation-name:antSpinMove;animation-duration:1s;animation-iteration-count:infinite;animation-timing-function:linear;animation-direction:alternate}.ant-spin .ant-spin-dot-item:nth-child(1){top:0;inset-inline-start:0}.ant-spin .ant-spin-dot-item:nth-child(2){top:0;inset-inline-end:0;animation-delay:.4s}.ant-spin .ant-spin-dot-item:nth-child(3){inset-inline-end:0;bottom:0;animation-delay:.8s}.ant-spin .ant-spin-dot-item:nth-child(4){bottom:0;inset-inline-start:0;animation-delay:1.2s}.ant-spin-spinning{position:static;display:inline-block;opacity:1}.chat-area-wrap{position:relative;z-index:10;font-size:16px}.chat-area-wrap *{margin:0;padding:0;box-sizing:border-box;outline:none;text-indent:0;-moz-osx-font-smoothing:grayscale;-webkit-font-smoothing:antialiased;text-rendering:optimizeLegibility}.chat-rich-text{position:relative;width:100%;padding:var(--chat-rect-padding);margin:0;background:transparent;box-sizing:border-box;overflow-x:hidden;overflow-y:auto;font-size:16px;color:var(--chat-text);vertical-align:text-bottom;white-space:pre-wrap;word-break:break-all}.chat-rich-text.disabled{cursor:not-allowed}.chat-rich-text.disabled *{pointer-events:none}.chat-rich-text .chat-grid-wrap:first-child>*:first-child{padding-left:var(--chat-before-tip-width)}.chat-dialog-wrap{position:absolute;top:0;left:0;z-index:21;width:100%;height:0;pointer-events:none}@keyframes chat-dialog-show{0%{transform:scale(.6);opacity:.4}to{opacity:1;transform:scale(1)}}.chat-dialog-wrap .chat-mention-dialog-wrap{position:absolute;z-index:11;border-radius:4px;padding:4px;overflow:hidden;background:var(--chat-box);box-shadow:var(--chat-box-shadow);pointer-events:visible}.chat-dialog-wrap .chat-mention-dialog-wrap.chat-view-show{animation:chat-dialog-show .2s ease}.chat-dialog-wrap .chat-mention-dialog-wrap .chat-mention-dialog-header{padding:6px 4px;width:100%;color:var(--chat-text);font-weight:700;font-size:14px}.chat-dialog-wrap .chat-mention-dialog-wrap .chat-mention-dialog-main{min-width:180px;max-height:240px;overflow-y:auto}.chat-dialog-wrap .chat-mention-dialog-wrap .chat-mention-dialog-main .chat-mention-dialog-item{display:flex;align-items:center;color:var(--chat-text-secondary);background:transparent;cursor:pointer;padding:4px;transition:all .3s ease;font-weight:700;font-size:14px;border-radius:4px}.chat-dialog-wrap .chat-mention-dialog-wrap .chat-mention-dialog-main .chat-mention-dialog-item .chat-mention-dialog-item-avatar{flex-shrink:0;display:flex;align-items:center;justify-content:center;width:24px;height:24px;margin-right:8px;border-radius:4px;overflow:hidden;background:var(--chat-primary);color:var(--chat-box);white-space:nowrap;font-size:12px}.chat-dialog-wrap .chat-mention-dialog-wrap .chat-mention-dialog-main .chat-mention-dialog-item .chat-mention-dialog-item-avatar.have-avatar{background:var(--chat-box)}.chat-dialog-wrap .chat-mention-dialog-wrap .chat-mention-dialog-main .chat-mention-dialog-item .chat-mention-dialog-item-avatar.have-avatar img{width:100%;height:100%;object-fit:cover}.chat-dialog-wrap .chat-mention-dialog-wrap .chat-mention-dialog-main .chat-mention-dialog-item .chat-mention-dialog-item-avatar .chat-mention-dialog-item-avatar-loading{position:relative;top:2px;transform:scale(.75)}.chat-dialog-wrap .chat-mention-dialog-wrap .chat-mention-dialog-main .chat-mention-dialog-item .chat-mention-dialog-item-avatar .chat-mention-dialog-item-avatar-text{position:relative;top:-1px;transform:scale(.75);font-size:12px}.chat-dialog-wrap .chat-mention-dialog-wrap .chat-mention-dialog-main .chat-mention-dialog-item .chat-mention-dialog-item-name{flex:1;white-space:nowrap;line-height:24px;overflow:hidden;text-overflow:ellipsis;padding-right:10px;font-size:14px;transition:all .3s ease;color:var(--chat-text-secondary)}.chat-dialog-wrap .chat-mention-dialog-wrap .chat-mention-dialog-main .chat-mention-dialog-item:hover{background:var(--chat-card);opacity:.7}.chat-dialog-wrap .chat-mention-dialog-wrap .chat-mention-dialog-main .chat-mention-dialog-item:hover .chat-mention-dialog-item-name{color:var(--chat-primary)}.chat-dialog-wrap .chat-mention-dialog-wrap .chat-mention-dialog-main .chat-mention-dialog-item.active{background:var(--chat-card);opacity:1}.chat-dialog-wrap .chat-mention-dialog-wrap .chat-mention-dialog-main .chat-mention-dialog-item.active .chat-mention-dialog-item-name{color:var(--chat-primary)}.chat-dialog-wrap .chat-mention-dialog-wrap .chat-mention-dialog-empty{display:flex;align-items:center;flex-direction:column;justify-content:center;padding:10px 0}.chat-dialog-wrap .chat-mention-dialog-wrap .chat-mention-dialog-empty .match-empty-svg{width:auto;height:40px;margin-bottom:2px}.chat-dialog-wrap .chat-mention-dialog-wrap .chat-mention-dialog-empty .empty-label{font-size:12px;color:var(--chat-text-secondary)}.chat-dialog-wrap .chat-mention-dialog-wrap .chat-mention-dialog-loading{display:flex;align-items:center;flex-direction:column;justify-content:center;padding:16px}.chat-dialog-wrap .chat-trigger-dialog-wrap{position:absolute;z-index:10;border-radius:4px;padding:4px;overflow:hidden;background:var(--chat-box);box-shadow:var(--chat-box-shadow);pointer-events:visible}.chat-dialog-wrap .chat-trigger-dialog-wrap.chat-view-show{animation:chat-dialog-show .2s ease}.chat-dialog-wrap .chat-trigger-dialog-wrap .chat-trigger-dialog-header{padding:6px 4px;width:100%;color:var(--chat-text);font-weight:700;font-size:14px}.chat-dialog-wrap .chat-trigger-dialog-wrap .chat-trigger-dialog-main{min-width:180px;max-height:240px;overflow-y:auto}.chat-dialog-wrap .chat-trigger-dialog-wrap .chat-trigger-dialog-main .chat-trigger-dialog-item{display:flex;align-items:center;color:var(--chat-text-secondary);background:transparent;cursor:pointer;padding:4px;transition:all .3s ease;font-weight:700;font-size:14px;border-radius:4px}.chat-dialog-wrap .chat-trigger-dialog-wrap .chat-trigger-dialog-main .chat-trigger-dialog-item .chat-trigger-dialog-item-name{flex:1;white-space:nowrap;line-height:24px;overflow:hidden;text-overflow:ellipsis;padding-right:10px;font-size:14px;transition:all .3s ease;color:var(--chat-text-secondary)}.chat-dialog-wrap .chat-trigger-dialog-wrap .chat-trigger-dialog-main .chat-trigger-dialog-item:hover{background:var(--chat-card);opacity:.7}.chat-dialog-wrap .chat-trigger-dialog-wrap .chat-trigger-dialog-main .chat-trigger-dialog-item:hover .chat-trigger-dialog-item-name{color:var(--chat-primary)}.chat-dialog-wrap .chat-trigger-dialog-wrap .chat-trigger-dialog-main .chat-trigger-dialog-item.active{background:var(--chat-card);opacity:1}.chat-dialog-wrap .chat-trigger-dialog-wrap .chat-trigger-dialog-main .chat-trigger-dialog-item.active .chat-trigger-dialog-item-name{color:var(--chat-primary)}.chat-dialog-wrap .chat-select-dialog-wrap{position:fixed;z-index:21;padding:4px;border-radius:4px;box-sizing:border-box;background:var(--chat-box);box-shadow:var(--chat-box-shadow);pointer-events:visible}.chat-dialog-wrap .chat-select-dialog-wrap .chat-select-dialog-header{display:flex;align-items:center;justify-content:space-between;background:var(--chat-box);padding:6px;color:var(--chat-text);font-weight:700;font-size:14px}.chat-dialog-wrap .chat-select-dialog-wrap .chat-select-dialog-search{margin-bottom:6px;display:flex;flex-direction:column;align-items:center;justify-content:center}.chat-dialog-wrap .chat-select-dialog-wrap .chat-select-dialog-search .chat-select-dialog-search-input{width:calc(100% - 12px);padding:4px 10px;height:32px;font-size:14px;color:var(--chat-text);line-height:1.5;border-width:1px;border-style:solid;border-color:var(--chat-input-border);border-radius:6px;outline:none;transition:border-color .3s cubic-bezier(.645,.045,.355,1),box-shadow .3s cubic-bezier(.645,.045,.355,1);background:var(--chat-input)}.chat-dialog-wrap .chat-select-dialog-wrap .chat-select-dialog-search .chat-select-dialog-search-input::-moz-placeholder{color:var(--chat-text-placeholder);opacity:1}.chat-dialog-wrap .chat-select-dialog-wrap .chat-select-dialog-search .chat-select-dialog-search-input:-ms-input-placeholder{color:var(--chat-text-placeholder)}.chat-dialog-wrap .chat-select-dialog-wrap .chat-select-dialog-search .chat-select-dialog-search-input::-webkit-input-placeholder{color:var(--chat-text-placeholder)}.chat-dialog-wrap .chat-select-dialog-wrap .chat-select-dialog-search .chat-select-dialog-search-input:hover{border-color:var(--chat-highlight)}.chat-dialog-wrap .chat-select-dialog-wrap .chat-select-dialog-search .chat-select-dialog-search-input:focus,.chat-dialog-wrap .chat-select-dialog-wrap .chat-select-dialog-search .chat-select-dialog-search-input:active{border-color:var(--chat-primary);box-shadow:0 0 0 2px var(--chat-input-shadow-color)}.chat-dialog-wrap .chat-select-dialog-wrap .chat-select-dialog-search .chat-select-dialog-search-empty{display:flex;align-items:center;flex-direction:column;justify-content:center;padding:10px 0}.chat-dialog-wrap .chat-select-dialog-wrap .chat-select-dialog-search .chat-select-dialog-search-empty .match-empty-svg{width:auto;height:40px;margin-bottom:2px}.chat-dialog-wrap .chat-select-dialog-wrap .chat-select-dialog-search .chat-select-dialog-search-empty .empty-label{font-size:12px;color:var(--chat-text-secondary)}.chat-dialog-wrap .chat-select-dialog-wrap .chat-select-dialog-main{position:relative;z-index:3;max-height:280px;overflow-y:auto}.chat-dialog-wrap .chat-select-dialog-wrap .chat-select-dialog-main .chat-select-dialog-item{display:flex;align-items:center;min-width:180px;color:var(--chat-text-secondary);background:transparent;cursor:pointer;padding:8px;transition:all .3s ease;font-weight:700;font-size:14px;border-radius:6px;min-height:42px}.chat-dialog-wrap .chat-select-dialog-wrap .chat-select-dialog-main .chat-select-dialog-item .chat-select-dialog-preview{flex-shrink:0;width:42px;height:42px;border-radius:6px;margin-right:12px}.chat-dialog-wrap .chat-select-dialog-wrap .chat-select-dialog-main .chat-select-dialog-item .chat-select-dialog-preview.loading{display:flex;align-items:center;justify-content:center}.chat-dialog-wrap .chat-select-dialog-wrap .chat-select-dialog-main .chat-select-dialog-item .chat-select-dialog-preview.loading .ant-spin{position:relative;top:2px;transform:scale(.75)}.chat-dialog-wrap .chat-select-dialog-wrap .chat-select-dialog-main .chat-select-dialog-item .chat-select-dialog-name{flex:1;transition:all .3s ease;color:var(--chat-text-secondary)}.chat-dialog-wrap .chat-select-dialog-wrap .chat-select-dialog-main .chat-select-dialog-item .chat-select-dialog-check{flex-shrink:0;display:inline-block;margin-left:6px;font-size:18px;color:var(--chat-primary)}.chat-dialog-wrap .chat-select-dialog-wrap .chat-select-dialog-main .chat-select-dialog-item:hover{background:var(--chat-card);opacity:.8}.chat-dialog-wrap .chat-select-dialog-wrap .chat-select-dialog-main .chat-select-dialog-item:hover .chat-select-dialog-name{color:var(--chat-primary)}.chat-dialog-wrap .chat-select-dialog-wrap .chat-select-dialog-arrow{position:absolute;z-index:2;pointer-events:none;width:16px;height:16px;overflow:hidden}.chat-dialog-wrap .chat-select-dialog-wrap .chat-select-dialog-arrow:before{box-sizing:border-box;background:var(--chat-box);position:absolute;bottom:0;inset-inline-start:0;width:16px;height:8px;-webkit-clip-path:path("M 0 8 A 4 4 0 0 0 2.828 6.828 L 6.586 3.071 A 2 2 0 0 1 9.414 3.071 L 13.172 6.828 A 4 4 0 0 0 16 8 Z");clip-path:path("M 0 8 A 4 4 0 0 0 2.828 6.828 L 6.586 3.071 A 2 2 0 0 1 9.414 3.071 L 13.172 6.828 A 4 4 0 0 0 16 8 Z");content:""}.chat-dialog-wrap .chat-select-dialog-wrap .chat-select-dialog-arrow:after{box-sizing:border-box;content:"";position:absolute;width:9px;height:9px;bottom:0;inset-inline:0;margin:auto;border-radius:0 0 2px;transform:translateY(50%) rotate(-135deg);box-shadow:var(--chat-box-shadow);z-index:0;background:transparent;opacity:.25}.chat-scroll{overflow-y:auto;overflow-x:hidden}.chat-scroll::-webkit-scrollbar{width:6px;height:6px}.chat-scroll::-webkit-scrollbar-thumb{border-radius:10px;box-shadow:inset 0 0 5px #61b8b31a;background-color:#0003}.chat-scroll::-webkit-scrollbar-track{box-shadow:inset 0 0 5px #57afbb1a;border-radius:10px;background:#ededed}.chat-placeholder-wrap{position:absolute;top:0;left:0;width:100%;margin:0;padding:var(--chat-rect-padding) var(--chat-rect-padding) var(--chat-rect-padding) calc(var(--chat-rect-padding) + var(--chat-before-tip-width));box-sizing:border-box;color:var(--chat-text-placeholder);pointer-events:none;font-style:oblique;word-break:break-all;z-index:11}.chat-write-wrap,.chat-write-input{word-break:break-all}.chat-tag-grid{word-break:break-all;white-space:pre-wrap}.chat-tag-wrap{margin:0 1px;white-space:normal}.chat-tag-mention,.chat-tag-trigger{color:var(--chat-primary)}.chat-tag-select{display:inline-block;cursor:pointer;background:var(--chat-card);color:var(--chat-primary);padding:2px 6px;border-radius:10px;margin:2px;transition:all .3s ease}.chat-tag-select svg{margin-left:4px;font-size:12px;transition:all .3s ease}.chat-tag-select:hover{color:var(--chat-highlight);background:var(--chat-highlight-card)}.chat-tag-select.active svg{transform:rotate(-180deg)}.chat-tag-input{padding:2px 6px;border-radius:4px;margin:0 2px;color:var(--chat-primary);cursor:text;background:var(--chat-card);line-height:1.8}.chat-tag-input .input-write{white-space:pre-wrap;word-break:break-all;word-wrap:break-word;padding-left:.1px}.chat-tag-input .input-tip{pointer-events:none;-webkit-user-select:none;user-select:none;opacity:.35;word-break:break-all}.chat-tag-component{white-space:normal}.chat-before-tip-wrap{position:absolute;top:0;left:0;height:0;transform:translateY(var(--chat-before-tip-top));z-index:11;padding:var(--chat-rect-padding);pointer-events:none}.chat-before-tip-wrap>*{pointer-events:visible}.chat-before-tip-wrap.tip-hover .chat-before-tip-box{background:var(--chat-card)}.chat-before-tip-wrap.tip-hover .chat-before-tip-close{opacity:1}.chat-before-tip-wrap .chat-before-tip-box{cursor:pointer;padding:2px 6px;color:var(--chat-primary);border-radius:8px;transition:background .3s ease;font-size:18px;font-weight:700}.chat-before-tip-wrap .chat-before-tip-close{position:absolute;top:4px;right:4px;width:16px;height:16px;cursor:pointer;color:#999;transition:opacity .3s ease;opacity:0}.chat-tip-dialog-wrap{position:absolute;bottom:100%;transform:translate(var(--chat-tip-dialog-left),var(--chat-tip-dialog-top));pointer-events:none}.chat-tip-dialog-wrap>*{pointer-events:visible}.chat-tip-dialog-wrap .chat-tip-dialog-main{display:flex;align-items:center;color:var(--chat-popover-text);font-size:13px;padding:8px 10px;background:var(--chat-popover);border-radius:8px}.chat-tip-dialog-wrap .chat-tip-dialog-main .chat-tip-dialog-code{margin-left:4px;opacity:.7;font-size:12px}.chat-tip-dialog-wrap .chat-tip-dialog-arrow{position:absolute;width:10px;height:10px;bottom:-5px;left:50%;transform:translate(-50%) rotate(-45deg);overflow:hidden;background:var(--chat-popover);z-index:2}\n/*$vite$:1*/',document.head.appendChild(dt);const pt='<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>',gt='<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>',ft={device:"auto",autoFocus:!0,placeholder:"",maxLength:-1,keyboardWrapFun:t=>t.ctrlKey&&["Enter"].includes(t.key),keyboardSendFun:t=>!t.ctrlKey&&["Enter"].includes(t.key)},ut={dialogTitle:"群成员",callEvery:!0,everyText:"所有人",asyncMatch:void 0,emptyText:"暂无数据",options:[]},mt={"`":["`","~"],"~":["`","~"],1:["1","!"],"!":["1","!"],3:["3","#"],"#":["3","#"],4:["4","$"],$:["4","$"],5:["5","%"],"%":["5","%"],6:["6","^"],"^":["6","^"],7:["7","&"],"&":["7","&"],8:["8","*"],"*":["8","*"],";":[";",":"],":":[";",":"],"/":["/","?"],"?":["/","?"],"\\":["\\","|"],"|":["\\","|"]},xt={tipTemplate:'<div class="chat-before-tip-box">{{text}}</div><div class="chat-before-tip-close"><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></div>',dialogTemplate:'<div class="chat-tip-dialog-main"><span>{{dialogText}}</span><span class="chat-tip-dialog-code">ESC</span></div><div class="chat-tip-dialog-arrow"></div>',closeNames:["chat-before-tip-box","chat-before-tip-close"],offsetTop:0},yt=Symbol("EVENT_COMMON_SEND"),Et=Symbol("EVENT_COMMON_CHANGE"),wt=Symbol("EVENT_COMMON_DESTROY"),vt=Symbol("EVENT_COMMON_TIP_STATE"),bt=Symbol("EVENT_COMMON_DIALOG_CLOSE"),Nt=Symbol("EVENT_COMMON_SELECT_ACTIVE"),kt=Symbol("EVENT_EDITOR_CHANGE"),Ot=Symbol("EVENT_EDITOR_DELETE"),Ct=Symbol("EVENT_EDITOR_CURSOR_CHANGE"),Tt=Symbol("EVENT_EDITOR_LINE_BREAK"),Dt=Symbol("EVENT_EDITOR_UNDO"),St=Symbol("EVENT_EDITOR_REDO"),Lt=Symbol("EVENT_EDITOR_HISTORY"),Mt=Symbol("EVENT_EDITOR_MAXLENGTH"),It=Symbol("EVENT_EDITOR_SWITCH_DISABLED"),At=Symbol("EVENT_EDITOR_INSERT_MENTION"),$t=Symbol("EVENT_EDITOR_INSERT_TRIGGER"),Rt=Symbol("EVENT_EDITOR_INSERT_SELECT"),Wt=Symbol("EVENT_EDITOR_INSERT_INPUT"),_t=Symbol("EVENT_EDITOR_INSERT_CUSTOM"),Kt=Symbol("EVENT_EDITOR_FOCUS"),Pt=Symbol("EVENT_TIP_OPEN"),Bt=Symbol("EVENT_TIP_CLOSE"),Ht=Symbol("EVENT_DIALOG_MATCH"),Vt=Symbol("EVENT_DIALOG_UPDATE_REACT"),zt=Symbol("EVENT_DIALOG_KEYBOARD_MOVE"),Ft="data-set-empty",Yt="data-set-richType",jt="richGrid",Gt="richMark",Ut="richWrite",Xt="richMention",Zt="richTrigger",qt="richSelect",Jt="richInput",Qt="richCustom",te="richComponent",ee="application/chat-nodes",ie="\ufeff",se=(t,e,i=!1)=>{let s;return function(...n){const a=this,o=i&&!s;clearTimeout(s),s=setTimeout(()=>{s=null,i||t.apply(a,n)},e),o&&t.apply(a,n)}},ne=(t,e)=>{let i;return function(...s){const n=this;i||(t.apply(n,s),i=!0,setTimeout(function(){i=!1},e))}},ae=t=>null!=t,oe=(t,e)=>t.replace(/{{(\w+)}}/g,(t,i)=>void 0!==e[i]?e[i]:t);function ce(t){return t.replace(/[&<>"']/g,t=>{switch(t){case"&":return"&";case"<":return"<";case">":return">";case'"':return""";case"'":return"'";default:return t}})}const he=t=>{const e=["address","article","aside","blockquote","canvas","dd","div","dl","dt","fieldset","figcaption","figure","footer","form","h1","h2","h3","h4","h5","h6","header","hgroup","hr","li","main","nav","noscript","ol","output","p","pre","section","table","tfoot","ul"],i=new RegExp(`<(${e.join("|")})([^>]*?)>`,"gi"),s=new RegExp(`</(${e.join("|")})>`,"gi");let n=t.replace(i,(t,e,i)=>{let s="",n="";if(i){const t=i.match(/style\s*=\s*["']([^"']*)["']/i);if(t){const e=t[1];s=e.match(/display\s*:/i)?`style="${e.replace(/display\s*:.*?;/gi,"display:block;")}"`:`style="display:block;${e}"`,n=i.replace(/style\s*=\s*["']([^"']*)["']/i,"").trim()}else s='style="display:block"',n=i.trim()}else s='style="display:block"';return`<span ${[n,s].filter(Boolean).join(" ")}>`.replace(/\s+/g," ").replace(/ >/,">")});return n=n.replace(s,"</span>"),n};function re(t,e){switch(e){case"text-jump":return"Tab"===t.key||"Tab"===t.code;case"text-backspace":return"Backspace"===t.key||"Backspace"===t.code;case"text-delete":return"Delete"===t.code||"Delete"===t.key;case"text-move":return"ArrowLeft"===t.key||"ArrowRight"===t.key||"ArrowLeft"===t.code||"ArrowRight"===t.code;case"text-updown":return"ArrowUp"===t.key||"ArrowDown"===t.key||"ArrowUp"===t.code||"ArrowDown"===t.code;case"text-select-all":return(t.ctrlKey||t.metaKey)&&("A"===t.key||"a"===t.key||"KeyA"===t.code);case"text-undo":return(t.ctrlKey||t.metaKey)&&("Z"===t.key||"z"===t.key||"KeyZ"===t.code);case"text-redo":return(t.ctrlKey||t.metaKey)&&("Y"===t.key||"y"===t.key||"KeyY"===t.code);case"text-write":return t.isComposing||!t.ctrlKey&&!t.altKey&&!t.metaKey&&!["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;case"IME":return"Unidentified"===t.key||229===t.keyCode;default:return!1}}function le(t,e,i){const s=e.split(/\s+/),n=t.split("").map((t,i)=>{let n=s[i]||"";return""===e&&""===n&&(n=t),{char:t,pinyin:n.toLowerCase(),initial:n?n[0].toLowerCase():""}}),a=(t=>{const e=[];let i="";for(const s of t)/[a-zA-Z]/.test(s)?i+=s.toLowerCase():(i&&(e.push({type:"pinyin",value:i}),i=""),e.push({type:"char",value:s}));return i&&e.push({type:"pinyin",value:i}),e})(i),o=n.length,c=a.length,h=Array.from({length:o+1},()=>Array(c+1).fill(!1));h[0][0]=!0;for(let r=0;r<=o;r++)for(let t=0;t<=c;t++)if(h[r][t]&&t<c){const e=a[t];for(let i=r;i<o;i++){const s=n[i];if("char"===e.type)s.char===e.value&&(h[i+1][t+1]=!0);else{const a=s.pinyin.toLowerCase(),c=s.initial,r=e.value;if(r===c)h[i+1][t+1]=!0;else if(r===a)h[i+1][t+1]=!0;else if(de(r,a))h[i+1][t+1]=!0;else for(let e=2;e<=o-i;e++){const s=n.slice(i,i+e),a=s.map(t=>t.pinyin.toLowerCase()).join(""),o=s.map(t=>t.initial).join("");if(r===a||r===o||de(r,a)){h[i+e][t+1]=!0;break}}}}}for(let r=0;r<=o;r++)if(h[r][c])return!0;return!1}function de(t,e){let i=0,s=0;for(;i<t.length&&s<e.length;)t[i]===e[s]&&i++,s++;return i===t.length}function pe(t,e=!0,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 ge(t){return t&&t.classList.contains("chat-view-show")}class fe{constructor(a,o){ht(this,e),at(this,"eventKey",Symbol("MentionDialog")),at(this,"chatElement"),at(this,"bus"),at(this,"dialog"),at(this,"activeMention",null),at(this,"title",""),at(this,"callEvery",!0),at(this,"everyText",""),at(this,"emptyText",""),at(this,"options",[]),at(this,"asyncMatch"),at(this,"matchKey",0),ht(this,t,[]),this.dialog=document.createElement("div"),this.chatElement=a,this.bus=this.chatElement.chat.bus,lt(this,e,i).call(this),lt(this,e,s).call(this),lt(this,e,n).call(this),this.updateConfig(o)}updateConfig(t){this.asyncMatch=t.asyncMatch,this.title=t.dialogTitle,this.emptyText=t.emptyText,this.everyText=t.everyText,this.callEvery=!this.asyncMatch&&t.callEvery,this.options=this.asyncMatch?[]:t.options,this.updateRender()}updateRender(){this.dialog.children[0].textContent=this.title,this.dialog.children[2].innerHTML=`${gt}<span class="empty-label">${this.emptyText}</span>`;const t=this.dialog.children[1];t.innerHTML="";const e=document.createDocumentFragment();this.callEvery&&e.appendChild(this.getRenderMention({id:"ALL",name:this.everyText})),this.options.forEach(t=>{e.appendChild(this.getRenderMention(t))}),t.appendChild(e)}getRenderMention(t){const e=document.createElement("div");e.setAttribute("data-id",t.id),e.setAttribute("data-name",t.name),e.classList.add("chat-mention-dialog-item"),pe(e,!0,"flex");const i=document.createElement("div");if(i.classList.add("chat-mention-dialog-item-avatar"),t.avatar){i.classList.add("have-avatar");const e=document.createElement("div");e.classList.add("chat-mention-dialog-item-avatar-loading"),e.innerHTML=pt,i.appendChild(e);const s=new Image;s.alt="",s.src=t.avatar,s.onload=()=>{i.removeChild(e),i.appendChild(s)}}else{const e=document.createElement("span");e.textContent="ALL"===t.id?"@":t.name.slice(-2),e.classList.add("chat-mention-dialog-item-avatar-text"),i.appendChild(e)}e.appendChild(i);const s=document.createElement("div");return s.classList.add("chat-mention-dialog-item-name"),s.textContent=t.name,e.appendChild(s),e.addEventListener("click",t=>{t.stopPropagation();const i=this.chatElement.chat.chatEditor.markCursorWrite,s=i.node.textContent.slice(0,i.offset).lastIndexOf("@"),n=i.offset-s;this.bus.emit(At,{id:e.getAttribute("data-id"),name:e.getAttribute("data-name"),del:n>0?n:0}),this.closeDialog()}),e}openDialog(t){if(ge(this.dialog)||this.bus.emit(bt),this.asyncMatch){this.options=[],this.updateRender();const t=this.dialog.children[2],e=this.dialog.children[3];pe(t,!1),pe(e,!0,"flex"),pe(this.dialog),this.moveDialog(),this.bus.emit(It,!0)}else if(this.options.length>0){const e=this.dialog.children[1];let i;e.scrollTop=0;const s=(t||this.pinyinMatchDialog()).map(t=>t.id);Array.from(e.children,t=>{const e=t.getAttribute("data-id");s.includes(e)?(pe(t,!0,"flex"),i||(i=t)):pe(t,!1)}),this.switchActiveMention(i||e.children[0]),pe(this.dialog),this.moveDialog(),this.bus.emit(It,!0)}}closeDialog(){ge(this.dialog)&&(pe(this.dialog,!1),this.switchActiveMention(),this.bus.emit(It,!1))}moveDialog(){const t=this.chatElement.chat.getSelection().getRangeAt(0).getBoundingClientRect(),e=this.chatElement.dialogRoot.getBoundingClientRect();let i="0",s="100%",n=t.x-e.x,a=e.y-t.y;const{clientWidth:o,clientHeight:c}=this.dialog;t.x>window.innerWidth-o-30&&(n=t.x-o-e.x-16,i="100%"),t.y<c&&(a-=c,s="0"),this.dialog.style.transform="translate(0, 0)",this.dialog.style.transformOrigin=`${i} ${s}`,this.dialog.style.left=n+6+"px",this.dialog.style.bottom=`${a}px`,this.dialog.style.opacity="1"}moveActiveMention(t){const e=this.dialog.children[1],i=Array.prototype.filter.call(e.children,t=>t.classList.contains("chat-view-show")),s=Array.prototype.indexOf.call(i,this.activeMention);"up"===t?s>0?this.switchActiveMention(i[s-1],!0):this.switchActiveMention(i[i.length-1],!0):"down"===t&&(s<i.length-1?this.switchActiveMention(i[s+1],!0):this.switchActiveMention(i[0],!0))}switchActiveMention(t,e=!1){if(this.activeMention&&this.activeMention.classList.remove("active"),t){if(this.activeMention=t,this.activeMention.classList.add("active"),e){const t=this.dialog.children[1],e=Array.prototype.filter.call(t.children,t=>t.classList.contains("chat-view-show")),i=this.activeMention.clientHeight,s=Array.prototype.indexOf.call(e,this.activeMention)+1-Math.ceil(Math.floor(t.clientHeight/i)/2);t.scrollTop=s>0?s*i:0}}else this.activeMention=null}matchDialog(){const t=this.chatElement.chat.chatEditor.markCursorWrite,e=t.node.textContent.slice(0,t.offset),i=e.lastIndexOf("@");if(-1===i)return void this.closeDialog();const s=e.slice(i+1);if(this.asyncMatch)return void this.asyncMatchDialog(s);const n=this.pinyinMatchDialog(s);n.length>0?this.openDialog(n):this.closeDialog()}pinyinMatchDialog(t){return t?this.options.filter(e=>le(e.name,e.pinyin||"",t)):this.callEvery?[{id:"ALL",name:this.everyText},...this.options]:this.options}async asyncMatchDialog(t=""){this.matchKey++;const e=this.matchKey;if(/\s/gi.test(t))return void this.closeDialog();this.openDialog();const i=await this.asyncMatch(t);if(e===this.matchKey){this.options=i,this.updateRender();const t=this.dialog.children[1],e=this.dialog.children[2],s=this.dialog.children[3];pe(s,!0,"flex"),t.scrollTop=0,pe(e,0===this.options.length,"flex"),pe(s,!1),this.switchActiveMention(t.children[0]),this.moveDialog()}}destroy(){this.bus.offKeyEvent(this.eventKey),this.dialog.parentElement&&this.dialog.parentElement.removeChild(this.dialog),ct(this,t).forEach(t=>{const e=t[0],i=t[1];for(const s in i)e.removeEventListener(s,i[s])})}}t=new WeakMap,e=new WeakSet,i=function(){this.bus.on(this.eventKey,bt,()=>{this.closeDialog()}),this.bus.on(this.eventKey,zt,ne(this.moveActiveMention,120).bind(this)),this.bus.on(this.eventKey,Ht,se(this.matchDialog,200).bind(this)),this.bus.on(this.eventKey,Vt,se(()=>{ge(this.dialog)&&this.moveDialog()},200)),this.bus.on(this.eventKey,wt,()=>{this.destroy()})},s=function(){rt(this,t,[[this.chatElement.richText,{keydown:t=>{ge(this.dialog)&&(re(t,"dialog-options")?t.preventDefault():re(t,"text-move")&&this.closeDialog())},keyup:t=>{if(t.stopPropagation(),"@"===t.key||"2"===String(t.key)||re(t,"IME")){const t=this.chatElement.chat.getSelection(),e=t.focusNode,i=this.chatElement.chat.chatEditor.findNode(e);if(i&&"Write"===i.type){const e=t.focusOffset;"@"===i.text[e-1]&&!this.chatElement.chat.deviceInfo.isPc&&this.openDialog()}}}}],[window,{mousedown:()=>{this.closeDialog()},keydown:t=>{!this.chatElement.chat.chatEditor.isComposition&&ge(this.dialog)&&re(t,"dialog-options")&&(t.preventDefault(),"ArrowUp"===t.key||"ArrowUp"===t.code?this.bus.emit(zt,"up"):"ArrowDown"===t.key||"ArrowDown"===t.code?this.bus.emit(zt,"down"):"Enter"!==t.key&&"Enter"!==t.code&&"NumpadEnter"!==t.code||this.activeMention&&this.activeMention.click())}}]]),ct(this,t).forEach(t=>{const e=t[0],i=t[1];for(const s in i)e.addEventListener(s,i[s])})},n=function(){this.dialog.classList.add("chat-mention-dialog-wrap"),this.dialog.addEventListener("mousedown",t=>{t.stopPropagation()}),pe(this.dialog,!1);const t=document.createDocumentFragment(),e=document.createElement("div");e.classList.add("chat-mention-dialog-header"),t.appendChild(e);const i=document.createElement("div");i.classList.add("chat-mention-dialog-main"),i.classList.add("chat-scroll"),t.appendChild(i);const s=document.createElement("div");s.classList.add("chat-mention-dialog-empty"),pe(s,!1),t.appendChild(s);const n=document.createElement("div");n.classList.add("chat-mention-dialog-loading"),n.innerHTML=pt,pe(n,!1),t.appendChild(n),this.dialog.appendChild(t),this.chatElement.dialogRoot.appendChild(this.dialog)};class ue{constructor(t,e){ht(this,o),at(this,"eventKey",""),at(this,"bus"),at(this,"chatElement"),at(this,"dialog"),at(this,"activeTrigger",null),at(this,"title"),at(this,"key"),at(this,"options"),at(this,"keyMap"),ht(this,a,[]),this.title=e.dialogTitle,this.key=e.key,this.options=e.options,this.keyMap=e.keyMap,this.dialog=document.createElement("div"),this.chatElement=t,this.bus=this.chatElement.chat.bus,lt(this,o,c).call(this),lt(this,o,h).call(this),lt(this,o,r).call(this)}openDialog(t){if(ge(this.dialog)||this.bus.emit(bt),this.options.length>0){const e=this.dialog.children[1];let i;e.scrollTop=0;const s=(t||this.pinyinMatchDialog()).map(t=>t.id);Array.from(e.children,t=>{const e=t.getAttribute("data-id");s.includes(e)?(pe(t,!0,"flex"),i||(i=t)):pe(t,!1)}),this.switchActiveTrigger(i||e.children[0]),pe(this.dialog),this.moveDialog(),this.bus.emit(It,!0)}}closeDialog(){ge(this.dialog)&&(pe(this.dialog,!1),this.switchActiveTrigger(),this.bus.emit(It,!1))}moveDialog(){const t=this.chatElement.chat.getSelection().getRangeAt(0).getBoundingClientRect(),e=this.chatElement.dialogRoot.getBoundingClientRect();let i="0",s="100%",n=t.x-e.x,a=e.y-t.y;const{clientWidth:o,clientHeight:c}=this.dialog;t.x>window.innerWidth-o-30&&(n=t.x-o-e.x-16,i="100%"),t.y<c&&(a-=c,s="0"),this.dialog.style.transform="translate(0, 0)",this.dialog.style.transformOrigin=`${i} ${s}`,this.dialog.style.left=n+6+"px",this.dialog.style.bottom=`${a}px`,this.dialog.style.opacity="1"}moveActiveTrigger(t){const e=this.dialog.children[1],i=Array.prototype.filter.call(e.children,t=>t.classList.contains("chat-view-show")),s=Array.prototype.indexOf.call(i,this.activeTrigger);"up"===t?s>0?this.switchActiveTrigger(i[s-1],!0):this.switchActiveTrigger(i[i.length-1],!0):"down"===t&&(s<i.length-1?this.switchActiveTrigger(i[s+1],!0):this.switchActiveTrigger(i[0],!0))}switchActiveTrigger(t,e=!1){if(this.activeTrigger&&this.activeTrigger.classList.remove("active"),t){if(this.activeTrigger=t,this.activeTrigger.classList.add("active"),e){const t=this.dialog.children[1],e=Array.prototype.filter.call(t.children,t=>t.classList.contains("chat-view-show")),i=this.activeTrigger.clientHeight,s=Array.prototype.indexOf.call(e,this.activeTrigger)+1-Math.ceil(Math.floor(t.clientHeight/i)/2);t.scrollTop=s>0?s*i:0}}else this.activeTrigger=null}matchDialog(){const t=this.chatElement.chat.chatEditor.markCursorWrite,e=t.node.textContent.slice(0,t.offset),i=e.lastIndexOf(this.key);if(-1===i)return void this.closeDialog();const s=e.slice(i+1),n=this.pinyinMatchDialog(s);n.length>0?this.openDialog(n):this.closeDialog()}pinyinMatchDialog(t){return t?this.options.filter(e=>le(e.name,e.pinyin||"",t)):this.options}destroy(){this.bus.offKeyEvent(this.eventKey),this.dialog.parentElement&&this.dialog.parentElement.removeChild(this.dialog),ct(this,a).forEach(t=>{const e=t[0],i=t[1];for(const s in i)e.removeEventListener(s,i[s])})}}a=new WeakMap,o=new WeakSet,c=function(){this.eventKey=Symbol("TriggerDialog-"+this.key),this.bus.on(this.eventKey,bt,()=>{this.closeDialog()}),this.bus.on(this.eventKey,zt,ne(this.moveActiveTrigger,120).bind(this)),this.bus.on(this.eventKey,Ht,se(this.matchDialog,200).bind(this)),this.bus.on(this.eventKey,Vt,se(()=>{ge(this.dialog)&&this.moveDialog()},200)),this.bus.on(this.eventKey,wt,()=>{this.destroy()})},h=function(){rt(this,a,[[this.chatElement.richText,{keydown:t=>{ge(this.dialog)&&(re(t,"dialog-options")?t.preventDefault():re(t,"text-move")&&this.closeDialog())},keyup:t=>{if(t.stopPropagation(),this.keyMap.includes(String(t.key))||re(t,"IME")){const t=this.chatElement.chat.getSelection(),e=t.focusNode,i=this.chatElement.chat.chatEditor.findNode(e);if(i&&"Write"===i.type){const e=t.focusOffset;i.text[e-1]===this.key&&!this.chatElement.chat.deviceInfo.isPc&&this.openDialog()}}}}],[window,{mousedown:()=>{this.closeDialog()},keydown:t=>{!this.chatElement.chat.chatEditor.isComposition&&ge(this.dialog)&&re(t,"dialog-options")&&(t.preventDefault(),"ArrowUp"===t.key||"ArrowUp"===t.code?this.bus.emit(zt,"up"):"ArrowDown"===t.key||"ArrowDown"===t.code?this.bus.emit(zt,"down"):"Enter"!==t.key&&"Enter"!==t.code&&"NumpadEnter"!==t.code||this.activeTrigger&&this.activeTrigger.click())}}]]),ct(this,a).forEach(t=>{const e=t[0],i=t[1];for(const s in i)e.addEventListener(s,i[s])})},r=function(){this.dialog.classList.add("chat-trigger-dialog-wrap"),this.dialog.addEventListener("mousedown",t=>{t.stopPropagation()}),pe(this.dialog,!1);const t=document.createDocumentFragment(),e=document.createElement("div");e.classList.add("chat-trigger-dialog-header"),e.textContent=this.title,t.appendChild(e);const i=document.createElement("div");i.classList.add("chat-trigger-dialog-main"),i.classList.add("chat-scroll"),t.appendChild(i);const s=document.createDocumentFragment();this.options.forEach(t=>{const e=document.createElement("div");e.setAttribute("data-id",t.id),e.setAttribute("data-name",t.name),e.classList.add("chat-trigger-dialog-item"),pe(e,!0,"flex");const i=document.createElement("div");i.classList.add("chat-trigger-dialog-item-name"),i.textContent=t.name,e.appendChild(i),e.addEventListener("click",t=>{t.stopPropagation();const i=this.chatElement.chat.chatEditor.markCursorWrite,s=i.node.textContent.slice(0,i.offset).lastIndexOf(this.key),n=i.offset-s;this.bus.emit($t,{id:e.getAttribute("data-id"),name:e.getAttribute("data-name"),key:this.key,del:n>0?n:0}),this.closeDialog()}),s.appendChild(e)}),i.appendChild(s),this.dialog.appendChild(t),this.chatElement.dialogRoot.appendChild(this.dialog)};class me{constructor(t,e){ht(this,d),at(this,"eventKey",""),at(this,"chatElement"),at(this,"bus"),at(this,"dialog"),at(this,"title",""),at(this,"key",""),at(this,"multiple",!1),at(this,"emptyText",""),at(this,"showSearch",!1),at(this,"placeholder",""),at(this,"searchEmptyText",""),at(this,"options",[]),at(this,"selectNode",null),ht(this,l,[]),this.dialog=document.createElement("div"),this.chatElement=t,this.bus=this.chatElement.chat.bus,this.title=e.dialogTitle,this.key=e.key,this.multiple=e.multiple||!1,this.emptyText=e.emptyText||"请选择标签选项",this.placeholder=e.placeholder||"请输入关键字查询",this.searchEmptyText=e.searchEmptyText||"暂无查询结果",this.showSearch=e.showSearch||!1,this.options=e.options,lt(this,d,p).call(this),lt(this,d,g).call(this),lt(this,d,f).call(this)}openDialog(t){if(ge(this.dialog)||this.bus.emit(bt),this.selectNode=t,!this.selectNode)return;if(this.showSearch){const t=this.dialog.children[1];t.children[0].value="",pe(t.children[1],!1)}pe(this.dialog);const e=this.dialog.children[this.showSearch?2:1],i=e.children;let s=0,n=!1,a=0;if("Select"===this.selectNode.type){const t=this.selectNode.id,o=(t||"").split(",");this.selectNode.$el.children[0].classList.add("active"),Array.from(i,e=>{pe(e,!0,"flex");const i=e.lastChild,c=o.length>0?o.some(t=>String(t)===e.getAttribute("data-id")):String(t)===String(e.getAttribute("data-id"));c&&(a=e.clientHeight,n=!0),c||n||(s+=e.clientHeight),pe(i,c)});const c=s-e.clientHeight/2+a/2;e.scrollTop=n&&c>0?c:0}else e.scrollTop=0,Array.from(i,t=>{pe(t,!0,"flex");pe(t.lastChild,!1)});this.bus.emit(It,!0),this.moveDialog()}closeDialog(){if(ge(this.dialog)){if(pe(this.dialog,!1),this.selectNode&&"Select"===this.selectNode.type){this.selectNode.$el.children[0].classList.remove("active")}this.bus.emit(It,!1),this.selectNode=null}}moveDialog(){if(!this.selectNode)return;const t=this.selectNode.$el.getClientRects()[0],e=this.dialog.children[this.showSearch?3:2];let i=this.dialog.clientHeight+16;if(i>t.y?(i=-(t.height+16),e.style.top="-16px",e.style.bottom="auto",e.style.transform="rotate(0deg)"):(e.style.transform="rotate(180deg)",e.style.bottom="-16px",e.style.top="auto"),window.innerWidth-t.x<this.dialog.clientWidth){const i=this.dialog.clientWidth-(window.innerWidth-t.x)-10;this.dialog.style.left="auto",this.dialog.style.right="10px",e.style.left="auto",e.style.right=i-16+"px"}else this.dialog.style.left=t.x+"px",this.dialog.style.right="auto",e.style.left="16px",e.style.right="auto";this.dialog.style.top=t.y+"px",this.dialog.style.transform=`translateY(${-i}px)`}destroy(){this.bus.offKeyEvent(this.eventKey),this.dialog.parentElement&&this.dialog.parentElement.removeChild(this.dialog),ct(this,l).forEach(t=>{const e=t[0],i=t[1];for(const s in i)e.removeEventListener(s,i[s])})}}l=new WeakMap,d=new WeakSet,p=function(){this.eventKey=Symbol("SelectDialog-"+this.key),this.bus.on(this.eventKey,Nt,t=>{t.key===this.key&&this.chatElement.chat.nextTick(()=>{this.openDialog(t)})}),this.bus.on(this.eventKey,bt,()=>{this.closeDialog()}),this.bus.on(this.eventKey,wt,()=>{this.destroy()})},g=function(){rt(this,l,[[window,{mousedown:()=>{this.closeDialog()}}]]),ct(this,l).forEach(t=>{const e=t[0],i=t[1];for(const s in i)e.addEventListener(s,i[s])})},f=function(){this.dialog.classList.add("chat-select-dialog-wrap"),this.dialog.addEventListener("mousedown",t=>{t.stopPropagation()}),pe(this.dialog,!1);const t=document.createDocumentFragment(),e=document.createElement("div");e.classList.add("chat-select-dialog-header");const i=document.createElement("span");if(i.textContent=this.title,e.appendChild(i),t.appendChild(e),this.showSearch){const e=document.createElement("div");e.classList.add("chat-select-dialog-search");const i=document.createElement("input");i.classList.add("chat-select-dialog-search-input"),i.setAttribute("placeholder",this.placeholder),i.addEventListener("input",se(t=>{t.stopPropagation();const e=t.target.value||"",i=this.dialog.children[1].children[1],s=this.dialog.children[2].children;let n=!0;Array.from(s,t=>{const i=t.getAttribute("data-name")||"";""===e||-1!==i.indexOf(e)?(n=!1,pe(t,!0,"flex")):pe(t,!1)}),pe(i,n,"flex"),this.moveDialog()},200).bind(this)),e.appendChild(i);const s=document.createElement("div");s.classList.add("chat-select-dialog-search-empty"),s.innerHTML=`${gt}<span class="empty-label">${this.searchEmptyText}</span>`,pe(s,!1),e.appendChild(s),t.appendChild(e)}const s=document.createElement("div");s.classList.add("chat-select-dialog-main"),s.classList.add("chat-scroll");const n=document.createDocumentFragment();this.options.forEach(t=>{const e=document.createElement("div");if(e.classList.add("chat-select-dialog-item"),e.setAttribute("data-id",t.id),e.setAttribute("data-name",t.name),t.preview){const i=document.createElement("div");i.classList.add("chat-select-dialog-preview"),i.classList.add("loading"),i.innerHTML=pt,e.appendChild(i);const s=new Image;s.classList.add("chat-select-dialog-preview"),s.src=String(t.preview),s.onload=()=>{e.insertBefore(s,i),e.removeChild(i)}}const i=document.createElement("span");i.classList.add("chat-select-dialog-name"),i.textContent=t.name,e.appendChild(i);const s=document.createElement("span");s.classList.add("chat-select-dialog-check"),s.innerHTML='<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>',pe(s,!1),e.appendChild(s),e.addEventListener("click",t=>{if(t.stopPropagation(),this.selectNode&&"Select"===this.selectNode.type)if(this.multiple){pe(e.lastChild,!ge(e.lastChild));const t=e.parentElement.querySelectorAll(".chat-select-dialog-check.chat-view-show");if(0===t.length)this.selectNode.updateTag({id:null,name:this.emptyText});else{let e="",i="";Array.from(t,t=>{const s=t.parentElement;e+=`${s.getAttribute("data-id")},`,i+=`${s.getAttribute("data-name")}、`}),this.selectNode.updateTag({id:e.slice(0,-1),name:i.slice(0,-1)})}}else{const t=e.getAttribute("data-id"),i=e.getAttribute("data-name");this.selectNode.updateTag({id:t,name:i}),this.closeDialog()}else{const t=e.getAttribute("data-id"),i=e.getAttribute("data-name");this.bus.emit(Rt,{...this.selectNode||{},id:t,name:i}),this.closeDialog()}}),n.appendChild(e)}),s.appendChild(n),t.appendChild(s);const a=document.createElement("div");a.classList.add("chat-select-dialog-arrow"),t.appendChild(a),this.dialog.appendChild(t),this.chatElement.dialogRoot.appendChild(this.dialog)};class xe{constructor(t,e){ht(this,m),at(this,"eventKey",Symbol("BeforeTip")),at(this,"chatElement"),at(this,"bus"),at(this,"tip"),at(this,"dialog"),at(this,"config",{}),ht(this,u,[]),this.chatElement=t,this.bus=this.chatElement.chat.bus,this.tip=document.createElement("div"),this.dialog=document.createElement("div"),lt(this,m,x).call(this),lt(this,m,y).call(this),lt(this,m,E).call(this),this.updateConfig(e)}updateConfig(t){this.config=t,this.tip.innerHTML=t.tipTemplate||"",this.dialog.innerHTML=t.dialogTemplate||""}openTip(t){this.tip.innerHTML=oe(this.tip.innerHTML,t),this.dialog.innerHTML=oe(this.dialog.innerHTML,t),pe(this.tip);(this.config.closeNames||[]).forEach(t=>{const e=this.tip.querySelector(`.${t}`);e&&e.addEventListener("click",()=>{this.closeTip()})}),this.tip.onmouseenter=()=>{pe(this.dialog),this.tip.classList.add("tip-hover");const t=this.tip.children[0],e=t.offsetWidth/2+t.offsetLeft,i=this.dialog.children[0].clientWidth/2;this.chatElement.container.style.setProperty("--chat-tip-dialog-left",e-i+"px");const s=Number(this.chatElement.container.style.getPropertyValue("--chat-before-tip-top").replace("px",""));this.chatElement.container.style.setProperty("--chat-tip-dialog-top",s-this.chatElement.rollBox.scrollTop+"px")},this.tip.onmouseleave=()=>{pe(this.dialog,!1),this.tip.classList.remove("tip-hover")};const e=this.tip.children[0].clientWidth;this.chatElement.container.style.setProperty("--chat-before-tip-width",`${e+Number(t.offset||4)}px`),this.bus.emit(Kt,"mark"),lt(this,m,w).call(this),this.bus.emit(vt,!0)}closeTip(){ge(this.tip)&&(this.chatElement.container.style.setProperty("--chat-before-tip-width","0px"),this.chatElement.container.style.setProperty("--chat-before-tip-top","0px"),this.chatElement.container.style.setProperty("--chat-tip-dialog-left","0px"),pe(this.tip,!1),pe(this.dialog,!1),this.tip.classList.remove("tip-hover"),this.bus.emit(Kt,"mark"),this.tip.innerHTML=this.config.tipTemplate||"",this.dialog.innerHTML=this.config.dialogTemplate||"",this.bus.emit(vt,!1))}destroy(){this.bus.offKeyEvent(this.eventKey),ct(this,u).forEach(t=>{const e=t[0],i=t[1];for(const s in i)e.removeEventListener(s,i[s])})}}u=new WeakMap,m=new WeakSet,x=function(){this.bus.on(this.eventKey,wt,()=>{this.destroy()}),this.bus.on(this.eventKey,Pt,t=>{this.openTip(t)}),this.bus.on(this.eventKey,Bt,()=>{this.closeTip()}),this.bus.on(this.eventKey,Et,()=>{lt(this,m,w).call(this)})},y=function(){rt(this,u,[[window,{resize:()=>{lt(this,m,w).call(this)},keydown:t=>{"Escape"===t.key&&this.closeTip()}}]]),ct(this,u).forEach(t=>{const e=t[0],i=t[1];for(const s in i)e.addEventListener(s,i[s])})},E=function(){this.tip.classList.add("chat-before-tip-wrap"),this.dialog.classList.add("chat-tip-dialog-wrap"),this.chatElement.rollBox.appendChild(this.tip),this.chatElement.dialogRoot.appendChild(this.dialog),pe(this.tip,!1),pe(this.dialog,!1)},w=function(){if(!ge(this.tip))return;const t=this.chatElement.chat.chatEditor.NODES[0].children[0],e=this.tip.children[0],i=t.$el.getBoundingClientRect(),s=e.getBoundingClientRect(),n=Number(this.chatElement.container.style.getPropertyValue("--chat-before-tip-top").replace("px","")),a=i.y+this.chatElement.chat.chatEditor.NODE_HEIGHT/2-(s.y+s.height/2)+n;this.chatElement.container.style.setProperty("--chat-before-tip-top",`${a+(this.config.offsetTop||0)}px`)};class ye{constructor(t,e){ht(this,v),at(this,"eventKey",Symbol("ChatElement")),at(this,"chat"),at(this,"container"),at(this,"rollBox"),at(this,"richText"),at(this,"placeholder"),at(this,"dialogRoot"),at(this,"mentionDialog"),at(this,"triggerDialogs"),at(this,"selectDialogs"),at(this,"beforeTip"),this.chat=e,this.container=t,this.rollBox=document.createElement("div"),this.richText=document.createElement("div"),this.placeholder=document.createElement("div"),this.dialogRoot=document.createElement("div"),lt(this,v,b).call(this),lt(this,v,N).call(this),lt(this,v,k).call(this),lt(this,v,O).call(this)}updatePlaceholder(t){this.placeholder.textContent=t}updateChatStyle(t){Object.assign(this.rollBox.style,t)}createMentionDialog(){this.mentionDialog?this.mentionDialog.updateConfig(this.chat.options.mentionConfig):this.mentionDialog=new fe(this,this.chat.options.mentionConfig)}createTriggerDialog(){this.triggerDialogs?(this.triggerDialogs.forEach(t=>{t.destroy()}),this.triggerDialogs=[]):this.triggerDialogs=[],this.chat.options.triggerConfig.forEach(t=>{this.triggerDialogs.push(new ue(this,t))})}createSelectDialog(){this.selectDialogs?(this.selectDialogs.forEach(t=>{t.destroy()}),this.selectDialogs=[]):this.selectDialogs=[],this.chat.options.selectConfig.forEach(t=>{this.selectDialogs.push(new me(this,t))})}createBeforeTip(){this.beforeTip?this.beforeTip.updateConfig(this.chat.options.tipConfig):this.beforeTip=new xe(this,this.chat.options.tipConfig)}destroy(){this.chat.bus.offKeyEvent(this.eventKey),this.rollBox.parentElement&&this.rollBox.parentElement.removeChild(this.rollBox),this.placeholder.parentElement&&this.placeholder.parentElement.removeChild(this.placeholder),this.dialogRoot.parentElement&&this.dialogRoot.parentElement.removeChild(this.dialogRoot)}}v=new WeakSet,b=function(){this.chat.bus.on(this.eventKey,Et,()=>{lt(this,v,C).call(this)}),this.chat.bus.on(this.eventKey,wt,()=>{this.destroy()})},N=function(){this.container.classList.add("chat-area-wrap"),this.rollBox.classList.add("chat-rich-text"),this.rollBox.classList.add("chat-scroll"),this.richText.setAttribute(Yt,"richWrap"),this.richText.setAttribute("contenteditable","true"),this.rollBox.appendChild(this.richText),this.container.appendChild(this.rollBox)},k=function(){this.placeholder.classList.add("chat-placeholder-wrap"),pe(this.placeholder),this.container.appendChild(this.placeholder)},O=function(){this.dialogRoot.classList.add("chat-dialog-wrap"),this.container.appendChild(this.dialogRoot)},C=function(){if(this.chat.chatEditor.isComposition)return pe(this.placeholder,!1);const t=this.chat.chatEditor.NODES;return t.length>1||t[0].children.length>1||t[0].children[0].text.length>0?pe(this.placeholder,!1):void pe(this.placeholder,!0)};class Ee{constructor(t){at(this,"$el",null),at(this,"type",""),this.type=t}mount({parentElm:t,beforeElm:e,afterElm:i,targetElm:s}){s&&(i?i.nextElementSibling?t.insertBefore(s,i.nextElementSibling):t.appendChild(s):e?t.insertBefore(s,e):t.appendChild(s))}}T=new WeakSet,D=function(t,...e){this.context.context.bus.emit(t,...e)};let we=class t extends Ee{constructor(t,e){super(e.type),ht(this,T),at(this,"context"),at(this,"text",""),at(this,"VOID_KEY",ie),this.context=t,this.text=String(e.text||""),this.render(e)}ruleBRTag(){const t=this.$el.children[0];if(t.childNodes.length>1){const e=[];for(let i=1;i<t.childNodes.length;i++)e.push(t.childNodes[i]);e.forEach(e=>{t.removeChild(e)})}if(!Boolean(this.text)&&this.$el===this.$el.parentElement.lastElementChild){const t=document.createElement("br");this.$el.children[0].appendChild(t)}}focus(t){const e=this.$el.children[0].childNodes[0];t||0===t?-1===t&&(t=e.textContent===this.VOID_KEY?1:e.textContent.length):t=e.textContent===this.VOID_KEY?1:0;const i=new Range,s=this.context.context.chat.getSelection();i.setStart(e,t),i.setEnd(e,t),s.removeAllRanges(),s.addRange(i),lt(this,T,D).call(this,Ct,{node:e,offset:t,type:"Write",instance:this})}updateNode(){const t=this.$el.children[0],e=t.childNodes[0],i=e.textContent||"";if(this.text=i.replace(new RegExp(this.VOID_KEY,"ig"),"")||"",t.setAttribute(Ft,String(!Boolean(this.text))),Boolean(this.text)){if(-1!==i.indexOf(this.VOID_KEY)&&(e.textContent=this.text,this.focus(-1)),t.childNodes.length>1)for(let s=t.childNodes.length-1;s>0;s--)t.removeChild(t.childNodes[s])}else e.textContent=this.VOID_KEY,this.ruleBRTag()}deleteNode(){const t=this.context.children.indexOf(this);this.context.children.splice(t,1),this.context.$el.removeChild(this.$el)}deleteRelevanceNode(){this.deleteNode()}deleteRangeNode(t){const e=t.anchorOffset,i=t.focusOffset,s=e>i,n=s?i:e,a=s?e:i,o=this.text.slice(0,n),c=this.text.slice(a);this.text=o+c,this.syncNode(),this.focus(n)}updateContext(t){this.context=t}syncNode(){const t=this.$el.children[0].childNodes[0];Boolean(this.text)?t.textContent=this.text:t.textContent=this.VOID_KEY,this.ruleBRTag()}splitNode(e,i,s="",n=""){const a=!Boolean(this.text),o=a?"":this.text.slice(0,e),c=a?"":this.text.slice(e);this.text=i?o.slice(0,-i):o,this.text=this.text+s;const h=this.context.children.indexOf(this),r=new t(this.context,{type:"Write",text:n+c,afterElm:this.$el});this.context.children.splice(h+1,0,r),this.syncNode(),this.updateNode(),r.updateNode(),r.focus(n.length>0?n.length:void 0)}backspace(t){const e=t.anchorOffset;if(t.isCollapsed){if(0===e||1===e&&!Boolean(this.text)){const t=this.context.children.indexOf(this),e=this.context.context.NODES.indexOf(this.context);if(0===t){if(0===e)return void lt(this,T,D).call(this,Bt);return void this.context.context.NODES[e].mergeNode(!1)}return void this.context.context.NODES[e].children[t-1].deleteRelevanceNode()}this.text=this.text.slice(0,e-1)+this.text.slice(e),this.syncNode(),this.focus(e-1)}else this.deleteRangeNode({anchorInstance:this,anchorOffset:e,focusInstance:this,focusOffset:t.focusOffset})}delete(t){const e=t.anchorOffset;if(t.isCollapsed)if(e===this.text.length||1===e&&!Boolean(this.text)){const t=this.context.children.indexOf(this),e=this.context.context.NODES.indexOf(this.context);if(t===this.context.children.length-1){if(e===this.context.context.NODES.length-1)return;return void this.context.context.NODES[e].mergeNode(!0)}this.context.context.NODES[e].children[t+1].deleteRelevanceNode(!0)}else this.text=this.text.slice(0,e)+this.text.slice(e+1),this.syncNode(),this.focus(e);else{const i=t.focusOffset,s=e>i,n=s?i:e,a=s?e:i,o=this.text.slice(0,n),c=this.text.slice(a);this.text=o+c,this.syncNode(),this.focus(n)}}render(t){const e=document.createElement("span");this.$el=e,e.setAttribute(Yt,Gt),e.classList.add("chat-write-wrap");const i=document.createElement("span");i.classList.add("chat-write-input"),i.setAttribute(Yt,Ut),i.setAttribute(Ft,String(!Boolean(this.text))),i.appendChild(document.createTextNode(Boolean(this.text)?this.text:this.VOID_KEY)),e.appendChild(i),this.mount({parentElm:(null==t?void 0:t.parentElm)||this.context.$el,targetElm:this.$el,...t||{}})}};class ve extends Ee{constructor(t,e){super(t),at(this,"context"),this.context=e}deleteNode(){const t=this.context.children.indexOf(this);this.context.children.splice(t,1),this.context.$el.removeChild(this.$el)}deleteRelevanceNode(t=!1){const e=this.context.children.indexOf(this),i=this.context.children[e-1],s=this.context.children[e+1];this.context.children.splice(e,1),this.context.$el.removeChild(this.$el),t?this.context.mergeWriteNode(s,i,!0,!0):this.context.mergeWriteNode(i,s)}deleteRangeNode(){this.deleteRelevanceNode()}updateContext(t){this.context=t}focus(t=!1){const e=this.context.children.indexOf(this),i=this.context.children[t?e-1:e+1];if(i){const e=!Boolean(i.text);i.focus(t?e?1:i.text.length:e?1:0)}}backspace(){this.context.backspace()}updateNode(){this.context.updateNode()}delete(){this.context.delete()}}class be extends ve{constructor(t,e){super(e.type,t),at(this,"id",""),at(this,"name",""),this.id=e.id,this.name=e.name,this.render(e)}render(t){const e=document.createElement("span");this.$el=e,e.setAttribute(Yt,Xt),e.setAttribute("contenteditable","false"),e.classList.add("chat-tag-wrap");const i=document.createElement("span");i.classList.add("chat-tag-mention"),i.textContent="@"+this.name,e.appendChild(i),this.mount({parentElm:(null==t?void 0:t.parentElm)||this.context.$el,targetElm:this.$el,...t||{}})}}class Ne extends ve{constructor(t,e){super(e.type,t),at(this,"id",""),at(this,"name",""),at(this,"key",""),this.id=e.id,this.name=e.name,this.key=e.key,this.render(e)}render(t){const e=document.createElement("span");this.$el=e,e.setAttribute(Yt,Zt),e.setAttribute("contenteditable","false"),e.classList.add("chat-tag-wrap");const i=document.createElement("span");i.classList.add("chat-tag-trigger"),i.textContent=this.key+this.name,e.appendChild(i),this.mount({parentElm:(null==t?void 0:t.parentElm)||this.context.$el,targetElm:this.$el,...t||{}})}}class ke extends ve{constructor(t,e){super(e.type,t),ht(this,S),at(this,"id",""),at(this,"name",""),at(this,"key",""),this.id=e.id,this.name=e.name,this.key=e.key,this.render(e)}updateTag({id:t,name:e}){this.id=t,this.name=e;this.$el.children[0].children[0].textContent=e,this.focus(),lt(this,S,L).call(this,kt)}render(t){const e=document.createElement("span");this.$el=e,e.setAttribute(Yt,qt),e.setAttribute("contenteditable","false"),e.classList.add("chat-tag-wrap");const i=document.createElement("span");i.classList.add("chat-tag-select"),i.innerHTML='<span></span><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>';i.children[0].textContent=this.name,e.appendChild(i),e.addEventListener("click",t=>{t.stopPropagation(),this.context.context.bus.emit(Nt,this)}),this.mount({parentElm:(null==t?void 0:t.parentElm)||this.context.$el,targetElm:this.$el,...t||{}})}}S=new WeakSet,L=function(t,...e){this.context.context.bus.emit(t,...e)};class Oe extends Ee{constructor(t,e){super(e.type),ht(this,M),at(this,"context"),at(this,"text",""),at(this,"placeholder",""),at(this,"key",""),at(this,"VOID_KEY",ie),at(this,"WRAP_KEY","\n"),this.context=t,this.text=(e.text||"").replace(new RegExp(`${this.WRAP_KEY[0]}|${this.VOID_KEY}`,"ig"),""),this.placeholder=String(e.placeholder||"placeholder"),this.key=e.key,this.render(e)}updateContext(t){this.context=t}syncNode(){const t=this.$el.children[0].children[0].childNodes[0];Boolean(this.text)?t.textContent=this.fixWrapKey(this.text):t.textContent=this.VOID_KEY,this.updateNode()}updateNode(){const t=this.$el.children[0].children[0],e=this.$el.children[0].children[1],i=t.childNodes[0],s=i.textContent||"";if(this.text=s.replace(new RegExp(`${this.WRAP_KEY[0]}|${this.VOID_KEY}`,"ig"),""),pe(e,!Boolean(this.text),"inline-block"),Boolean(this.text)){if(-1!==s.indexOf(this.VOID_KEY))i.textContent=this.fixWrapKey(this.text),this.focus(-1);else if(-1!==this.text.indexOf(this.WRAP_KEY[1])){const t=this.fixWrapKey(this.text);if(t!==i.textContent){let e=0;for(let s=0;s<i.textContent.length;s++){if(i.textContent[s]!==t[s]){e=s;break}}i.textContent=t,this.focus(e+2)}}}else i.textContent=this.VOID_KEY}deleteNode(){const t=this.context.children.indexOf(this);this.context.children.splice(t,1),this.context.$el.removeChild(this.$el)}backspace(t){const e=t.anchorOffset;if(t.isCollapsed)if(0===e||1===e&&!Boolean(this.text))if(Boolean(this.text)){const t=this.context.children.indexOf(this);this.context.children[t-1].focus(-1)}else this.deleteRelevanceTag();else{const t=this.$el.children[0].children[0].childNodes[0],i=this.getWrapOffset(t,e,"left"),s=t.textContent||"";let n;switch(i){case 1:n=e-i-2;break;case 2:n=e-i-1;break;case 3:n=e-i;break;default:n=e-1}const a=s.slice(0,n),o=s.slice(e);this.text=(a+o).replace(new RegExp(`${this.WRAP_KEY[0]}|${this.VOID_KEY}`,"ig"),""),this.syncNode(),this.focus(n)}else this.deleteRangeNode({anchorInstance:this,anchorOffset:e,focusInstance:this,focusOffset:t.focusOffset})}delete(t){const e=t.anchorOffset,i=this.$el.children[0].children[0].childNodes[0],s=this.getWrapOffset(i,e,"right");if(t.isCollapsed)if(e+s===this.fixWrapKey(this.text).length||1===e&&!Boolean(this.text))if(Boolean(this.text)){const t=this.context.children.indexOf(this);this.context.children[t+1].focus()}else this.deleteRelevanceTag(!0);else{const t=i.textContent||"";let n,a,o;switch(s){case 1:n=2,a=1,o=e+1;break;case 2:n=1,a=2,o=e-1;break;case 3:n=0,a=3,o=e;break;default:n=0,a=1,o=e}const c=t.slice(0,e-n),h=t.slice(e+a);this.text=(c+h).replace(new RegExp(`${this.WRAP_KEY[0]}|${this.VOID_KEY}`,"ig"),""),this.syncNode(),this.focus(o)}else this.deleteRangeNode({anchorInstance:this,anchorOffset:e,focusInstance:this,focusOffset:t.focusOffset})}deleteRangeNode(t){const e=t.anchorOffset,i=t.focusOffset,s=e>i;let n=s?i:e,a=s?e:i;const o=this.$el.children[0].children[0].childNodes[0],c=o.textContent||"",h=this.getWrapOffset(o,n,"right"),r=this.getWrapOffset(o,a-1,"left"),l=c.slice(0,n+h),d=c.slice(a+r);this.text=(l+d).replace(new RegExp(`${this.WRAP_KEY[0]}|${this.VOID_KEY}`,"ig"),""),this.syncNode(),this.focus(n)}focus(t){const e=this.$el.children[0].children[0].childNodes[0];t||0===t?-1===t&&(t=e.textContent===this.VOID_KEY?1:e.textContent.length):t=e.textContent===this.VOID_KEY?1:0;const i=new Range,s=this.context.context.chat.getSelection();i.setStart(e,t),i.setEnd(e,t),s.removeAllRanges(),s.addRange(i),lt(this,M,I).call(this,Ct,{node:e,offset:t,type:"Input",instance:this})}deleteRelevanceNode(t=!1){this.focus(t?void 0:-1)}deleteRelevanceTag(t=!1){const e=this.context.children.indexOf(this),i=this.context.children[e-1],s=this.context.children[e+1];this.context.children.splice(e,1),this.context.$el.removeChild(this.$el),t?this.context.mergeWriteNode(s,i,!0,!0):this.context.mergeWriteNode(i,s)}setText(t,e){if(e=this.fixWrapKey(e),Boolean(this.text)){const i=this.$el.children[0].children[0].textContent||"",s=i.slice(0,t),n=i.slice(t);this.text=s+e+n,this.syncNode(),this.focus(s.length+e.length)}else this.text=e,this.syncNode(),this.focus(e.length)}fixWrapKey(t){return t.replace(new RegExp(this.WRAP_KEY[0],"ig"),"").replace(new RegExp(this.WRAP_KEY[1],"ig"),this.WRAP_KEY)}getWrapOffset(t,e,i="left"){const s="left"===i?t.textContent[e-1]:t.textContent[e];if(s===this.WRAP_KEY[0]){return("left"===i?t.textContent[e-2]:t.textContent[e+1])===this.WRAP_KEY[1]?3:1}return s===this.WRAP_KEY[1]?2:0}render(t){const e=document.createElement("span");this.$el=e,e.setAttribute(Yt,Jt),e.setAttribute("contenteditable","false"),e.classList.add("chat-tag-wrap");const i=document.createElement("span");i.classList.add("chat-tag-input");const s=document.createElement("span");s.classList.add("input-write"),s.setAttribute("contenteditable","true"),s.textContent=Boolean(this.text)?this.fixWrapKey(this.text):this.VOID_KEY,i.appendChild(s);const n=document.createElement("span");n.classList.add("input-tip"),n.textContent=`[${this.placeholder}]`,i.appendChild(n),Boolean(this.text)&&pe(n,!1),e.addEventListener("click",()=>{Boolean(this.text)||this.focus()}),e.appendChild(i),this.mount({parentElm:(null==t?void 0:t.parentElm)||this.context.$el,targetElm:this.$el,...t||{}})}}M=new WeakSet,I=function(t,...e){this.context.context.bus.emit(t,...e)};class Ce extends ve{constructor(t,e){super(e.type,t),at(this,"html",""),this.html=e.html,this.render(e)}render(t){const e=document.createElement("span");this.$el=e,e.setAttribute(Yt,Qt),e.setAttribute("contenteditable","false"),e.classList.add("chat-tag-wrap"),e.innerHTML=this.html,this.mount({parentElm:(null==t?void 0:t.parentElm)||this.context.$el,targetElm:this.$el,...t||{}})}}class Te extends Ee{constructor(t,e,i){super("Grid"),at(this,"children",[]),at(this,"context"),this.context=t,this.render(e,i)}getAnalyzeChildren(t){if(!t||0===t.length)return[{type:"Write",text:""}];const e=[];t.forEach((i,s)=>{if(s===t.length-1)return;const n=s+1;if("Write"===i.type&&"Write"===t[n].type){let t=n-e.length;e.push(t)}}),e.forEach(e=>{const i=t[e];t[e-1].text+=i.text,t.splice(e,1)});const i=[];return t.forEach((e,s)=>{if(s===t.length-1)return;const n=s+1;if("Write"!==e.type&&"Write"!==t[n].type){let t=n+i.length;i.push(t)}}),i.forEach(e=>{t.splice(e,0,{type:"Write",text:""})}),"Write"!==t[0].type&&t.unshift({type:"Write",text:""}),"Write"!==t[t.length-1].type&&t.push({type:"Write",text:""}),t}emit(t,...e){this.context.bus.emit(t,...e)}mergeNode(t=!1){const e=this.context.NODES.indexOf(this);if(t){const t=this.context.NODES[e+1];if(t){const e=this.children[this.children.length-1],i=t.children[0];this.mergeWriteNode(e,i),this.children.push(...t.children);const s=document.createDocumentFragment();t.children.forEach(t=>{t.updateContext(this),s.appendChild(t.$el)}),this.$el.appendChild(s),e.ruleBRTag(),t.deleteNode()}}else{const t=this.context.NODES[e-1];if(t){const e=t.children[t.children.length-1],i=this.children[0];this.mergeWriteNode(e,i),t.children.push(...this.children);const s=document.createDocumentFragment();this.children.forEach(e=>{e.updateContext(t),s.appendChild(e.$el)}),t.$el.appendChild(s),e.ruleBRTag(),this.deleteNode()}}}splitNode(t,e=0){const i=this.context.NODES.indexOf(this),s=this.children.indexOf(t),n=Boolean(t.text)?t.text.slice(0,e):"",a=Boolean(t.text)?t.text.slice(e):"";t.text=n;const o=this.children.slice(0,s+1),c=this.children.slice(s+1);this.children=o;const h=new Te(this.context,[],{afterElm:this.$el});this.context.NODES.splice(i+1,0,h);const r=h.children[0];r.text=a,h.children.push(...c);const l=document.createDocumentFragment();c.forEach(t=>{t.updateContext(h),l.appendChild(t.$el)}),h.$el.appendChild(l),t.syncNode(),r.syncNode(),r.focus()}deleteNode(){this.children=[];const t=this.context.NODES.indexOf(this);this.context.NODES.splice(t,1),this.context.$el.removeChild(this.$el)}mergeWriteNode(t,e,i=!0,s=!1){const n=t.text||"",a=e.text||"",o=s?a.length:n.length;t.text=s?a+n:n+a,t.syncNode(),e.deleteNode(),i&&t.focus(Boolean(t.text)?o:1)}splitWriteNode(t,e){const i=this.children.indexOf(t),s=Boolean(t.text)?t.text.slice(0,e):"",n=Boolean(t.text)?t.text.slice(e):"";t.text=s,t.syncNode();const a=new we(this,{type:"Write",text:n,afterElm:t.$el});this.children.splice(i+1,0,a)}deleteRangeNode(t){const e=t.anchorInstance,i=t.focusInstance;if(e===i)return void e.deleteRangeNode(t);const s=this.children.indexOf(e)>this.children.indexOf(i);"Write"===e.type&&this.splitWriteNode(e,t.anchorOffset),"Write"===i.type&&this.splitWriteNode(i,t.focusOffset);const n=this.children.indexOf(e),a=this.children.indexOf(i);let o=(s?a:n)+1;const c=s?n:a;s&&"Write"!==i.type&&(o-=1);const h=this.children.slice(o,c+1),r=this.children[o-1],l=this.children[c+1];h.forEach(t=>{t.deleteNode()}),this.mergeWriteNode(r,l)}updateNode(){this.context.fixEditor()}backspace(){this.context.fixEditor()}delete(){this.context.fixEditor()}render(t,e){const i=document.createElement("p");this.$el=i,i.className="chat-grid-wrap",i.setAttribute(Yt,jt),this.renderChildren(t,!1),this.mount({parentElm:this.context.$el,targetElm:this.$el,...e||{}})}renderChildren(t,e=!0){if(!this.$el)return;this.children=[],this.$el.innerHTML="";const i=this.getAnalyzeChildren(t),s=document.createDocumentFragment();i.forEach(t=>{let e;switch(t.type){case"Write":e=new we(this,{...t,parentElm:s}),this.children.push(e);break;case"Mention":e=new be(this,{...t,parentElm:s}),this.children.push(e);break;case"Trigger":e=new Ne(this,{...t,parentElm:s}),this.children.push(e);break;case"Select":e=new ke(this,{...t,parentElm:s}),this.children.push(e);break;case"Input":e=new Oe(this,{...t,parentElm:s}),this.children.push(e);break;case"Custom":e=new Ce(this,{...t,parentElm:s}),this.children.push(e);break;default:const i=this.context.components[t.type];i&&(e=new i({type:t.type,data:t.data,context:this,config:{parentElm:s}}),this.children.push(e))}}),this.$el.appendChild(s);const n=this.children[this.children.length-1];n.ruleBRTag(),e&&(n.focus(-1),this.emit(kt))}}class De{constructor(t){ht(this,R),at(this,"$el"),at(this,"bus"),at(this,"chat"),at(this,"eventKey",Symbol("ChatEditor")),at(this,"isComposition",!1),at(this,"textLength",0),ht(this,A,!1),at(this,"NODES",[]),at(this,"NODE_HEIGHT",24),at(this,"IME_MODEL",!1),at(this,"FIX_MODEL",!1),ht(this,$,[]),at(this,"components",{}),at(this,"markCursorWrite",{node:null,offset:0,instance:null}),at(this,"markCursorInput",{node:null,offset:0,instance:null}),at(this,"markLastType","Write"),at(this,"undoHistory",[]),at(this,"redoHistory",[]),at(this,"historyLoading",!1),this.chat=t,this.bus=t.bus,this.$el=t.chatElement.richText,lt(this,R,W).call(this),lt(this,R,_).call(this),this.initEditor()}initEditor(){this.$el.innerHTML="",this.NODES=[new Te(this)],this.markLastType="Write",this.NODE_HEIGHT=this.NODES[0].$el.getBoundingClientRect().height,this.undoHistory=[{nodes:this.compileNodes(this.NODES),gridIndex:this.NODES.length-1,childIndex:0,offset:1,type:"Write"}],this.redoHistory=[],this.chat.options.autoFocus&&this.chat.nextTick(()=>{this.focusLast()});const t=this.NODES[this.NODES.length-1],e=t.children[t.children.length-1];lt(this,R,G).call(this,{node:e.$el.children[0].childNodes[0],offset:Boolean(e.text)?e.text.length:1,type:"Write",instance:e})}async fixEditor(t){this.$el.innerHTML="",t||(t=this.compileNodes(this.NODES)),this.NODES=t.map(t=>new Te(this,t)),this.focusLast(),await lt(this,R,j).call(this)}deleteRangeNode(t){let e=t.anchorInstance,i=t.focusInstance;"Grid"===e.type&&(e=e.children[0],t.anchorOffset=Boolean(e.text)?0:1),"Grid"===i.type&&(i=i.children[0],t.focusInstance=Boolean(i.text)?0:1);const s=e.context,n=i.context,a=this.NODES.indexOf(s),o=this.NODES.indexOf(n),c=a>o,h=c?o:a,r=c?a:o;this.NODES.slice(h+1,r).forEach(t=>{t.deleteNode()});const l=c?n:s,d=c?s:n,p=l.children[l.children.length-1],g=d.children[0];c?(l.deleteRangeNode({anchorInstance:p,anchorOffset:Boolean(p.text)?p.text.length:1,focusInstance:i,focusOffset:t.focusOffset}),d.deleteRangeNode({anchorInstance:g,anchorOffset:Boolean(g.text)?0:1,focusInstance:e,focusOffset:t.anchorOffset})):(l.deleteRangeNode({anchorInstance:e,anchorOffset:t.anchorOffset,focusInstance:p,focusOffset:Boolean(p.text)?p.text.length:1}),d.deleteRangeNode({anchorInstance:i,anchorOffset:t.focusOffset,focusInstance:g,focusOffset:Boolean(g.text)?0:1})),l.mergeNode(!0)}findNode(t,e=5,i=!0){if(!t)return null;if(i&&!this.$el.contains(t))return null;if(e<=0)return null;if(t.nodeType===Node.TEXT_NODE)return this.findNode(t.parentElement,e-1);const s=t,n=s.getAttribute?s.getAttribute(Yt):"";if(n===Ut){const t=s.parentElement,e=t.parentElement,i=Array.prototype.indexOf.call(e.children,t),n=Array.prototype.indexOf.call(this.$el.children,e);return this.NODES[n].children[i]}if(n===Gt){const t=s,e=t.parentElement,i=Array.prototype.indexOf.call(e.children,t),n=Array.prototype.indexOf.call(this.$el.children,e);return this.NODES[n].children[i]}if(n===Xt||n===Zt||n===qt||n===Jt||n===Qt||n===te){const t=s,e=t.parentElement,i=Array.prototype.indexOf.call(e.children,t),n=Array.prototype.indexOf.call(this.$el.children,e);return this.NODES[n].children[i]}if(n===jt){const t=Array.prototype.indexOf.call(this.$el.children,s);return this.NODES[t]}return this.findNode(s.parentElement,e-1,!1)}focusFirst(){this.NODES[0].children[0].focus(),this.cursorView()}focusMark(){const t=this.chat.getSelection(),e=new Range;switch(this.markLastType){case"Write":e.setStart(this.markCursorWrite.node,this.markCursorWrite.offset),e.setEnd(this.markCursorWrite.node,this.markCursorWrite.offset);break;case"Input":e.setStart(this.markCursorInput.node,this.markCursorInput.offset),e.setEnd(this.markCursorInput.node,this.markCursorInput.offset)}t.removeAllRanges(),t.addRange(e),this.cursorView()}focusLast(){const t=this.NODES[this.NODES.length-1];t.children[t.children.length-1].focus(-1),this.cursorView()}selectAll(){const t=this.chat.getSelection(),e=new Range,i=this.NODES[0].children[0],s=this.NODES[this.NODES.length-1].children[this.NODES[this.NODES.length-1].children.length-1],n=i.$el.children[0].childNodes[0],a=s.$el.children[0].childNodes[0];e.setStart(n,Boolean(i.text)?0:1),e.setEnd(a,Boolean(s.text)?s.text.length:1),t.removeAllRanges(),t.addRange(e)}cursorMove(t,e){const i=e||this.chat.getSelection(),s=t<0;if(!i.isCollapsed){const t=this.findNode(i.anchorNode),e=this.findNode(i.focusNode);if(!t||!e)return;let n,a,o=!1;if(t===e)o=i.anchorOffset>i.focusOffset;else if(t.context===e.context){o=t.context.children.indexOf(t)>e.context.children.indexOf(e)}else{o=this.NODES.indexOf(t.context)>this.NODES.indexOf(e.context)}return s?(n=o?i.focusOffset:i.anchorOffset,a=o?e:t):(n=o?i.anchorOffset:i.focusOffset,a=o?t:e),"Write"===a.type||"Input"===a.type?a.focus(n):a.focus(o),void this.cursorView()}const n=i.focusNode,a=this.findNode(n);let o=0;if(!a)return;if("Write"===a.type){const e=i.focusOffset,n=s?a.text.slice(0,e):a.text.slice(e);if(n.length>=Math.abs(t))return a.focus(e+t),void this.cursorView();o+=n.length}else if("Input"===a.type){const e=i.focusOffset,n=a.$el.children[0].children[0].childNodes[0],c=(s?n.textContent.slice(0,e):n.textContent.slice(e)).replace(new RegExp(`${a.VOID_KEY}|${a.WRAP_KEY[0]}`,"ig"),"");if(c.length>=Math.abs(t)){const i=a.getWrapOffset(n,s?e+t+1:e+t-1,s?"left":"right");return i?s?a.focus(e+t-i+1):a.focus(e+t+i-1):a.focus(e+t),void this.cursorView()}o+=c.length}const c=a.context.children.indexOf(a);if(s){if(0===c){const e=this.NODES.indexOf(a.context);if(0===e)return void a.focus();const i=this.NODES[e-1],s=i.children[i.children.length-1],n=s.$el.children[0].childNodes[0];return o+=1,void this.cursorMove(-(Math.abs(t)-o),{focusNode:n,focusOffset:Boolean(s.text)?s.text.length:1,isCollapsed:!0})}const e=a.context.children[c-1];let i,s;o+=1,"Input"===e.type?(i=e,s=i.$el.children[0].children[0].childNodes[0]):"Write"===e.type?(i=e,s=i.$el.children[0].childNodes[0]):(i=a.context.children[c-2],s=i.$el.children[0].childNodes[0]);const n="Input"===e.type?i.fixWrapKey(i.text):i.text;this.cursorMove(-(Math.abs(t)-o),{focusNode:s,focusOffset:Boolean(n)?n.length:1,isCollapsed:!0})}else{if(c===a.context.children.length-1){const e=this.NODES.indexOf(a.context);if(e===this.NODES.length-1)return void a.focus(-1);const i=this.NODES[e+1].children[0],s=i.$el.children[0].childNodes[0];return o+=1,void this.cursorMove(t-o,{focusNode:s,focusOffset:Boolean(i.text)?0:1,isCollapsed:!0})}const e=a.context.children[c+1];let i,s;o+=1,"Input"===e.type?(i=e,s=i.$el.children[0].children[0].childNodes[0]):"Write"===e.type?(i=e,s=i.$el.children[0].childNodes[0]):(i=a.context.children[c+2],s=i.$el.children[0].childNodes[0]),this.cursorMove(t-o,{focusNode:s,focusOffset:Boolean(i.text)?0:1,isCollapsed:!0})}}cursorView(){const t=this.$el.parentElement;if(t.scrollHeight<=t.clientHeight)return;const e=this.chat.getSelection().getRangeAt(0).getClientRects()[0],i=t.getClientRects()[0],s=e.y-i.y;s<0?t.scrollTop=t.scrollTop-Math.abs(s):s+e.height>i.height&&(t.scrollTop=t.scrollTop+(s+e.height-i.height))}compileNodes(t){const e=[];return t.forEach(t=>{const i=[];t.children.forEach(t=>{switch(t.type){case"Write":i.push({type:"Write",text:t.text});break;case"Mention":i.push({type:"Mention",id:t.id,name:t.name});break;case"Trigger":i.push({type:"Trigger",id:t.id,name:t.name,key:t.key});break;case"Select":i.push({type:"Select",id:t.id,name:t.name,key:t.key});break;case"Input":i.push({type:"Input",placeholder:t.placeholder,text:t.text,key:t.key});break;case"Custom":i.push({type:"Custom",html:t.html});break;default:this.components[t.type]&&i.push({type:t.type,data:t.data})}}),e.push(i)}),e}async insertText(t){const e=t.replace(new RegExp(`${ie}`,"ig"),"").replace(/\r\n/g,"\n").replace(/\r/g,"\n").split("\n").map(t=>[{type:"Write",text:t}]);await this.insertNodes(e)}async insertNodes(t){const{instance:e,offset:i}=this.markCursorWrite;if(!e)return;const s=e,n=s.context,a=this.NODES.indexOf(n);n.splitNode(s,i);let o=n.$el,c=null,h=null;t.forEach((e,i)=>{const s=new Te(this,e,{afterElm:o});o=s.$el,0===i?c=s:i===t.length-1&&(h=s),this.NODES.splice(a+i+1,0,s)}),c&&c.mergeNode(),h?h.mergeNode(!0):n.mergeNode(!0),await lt(this,R,j).call(this)}async insertInputText(t){const{instance:e,offset:i}=this.markCursorInput;if(!e)return;const s=e,n=t.replace(new RegExp(`${ie}`,"ig"),"").replace(/\r\n/g,"\n").replace(/\r/g,"\n");s.setText(i,n),await lt(this,R,j).call(this)}splitWrite(t){const{instance:e,offset:i}=this.markCursorWrite;if(!e)return null;const s=e,n=s.context,a=n.children.indexOf(s);return s.splitNode(i,t.del,t.beforeText,t.afterText),{index:a,write:s,grid:n}}async insertMention(t){const e=this.splitWrite(t);if(!e)return;const{index:i,write:s,grid:n}=e,a=new be(n,{type:"Mention",id:t.id,name:t.name,afterElm:s.$el});n.children.splice(i+1,0,a),await lt(this,R,j).call(this)}async insertTrigger(t){const e=this.splitWrite(t);if(!e)return;const{index:i,write:s,grid:n}=e,a=new Ne(n,{type:"Trigger",id:t.id,name:t.name,key:t.key,afterElm:s.$el});n.children.splice(i+1,0,a),await lt(this,R,j).call(this)}async insertSelect(t){const e=this.splitWrite(t);if(!e)return;const{index:i,write:s,grid:n}=e,a=new ke(n,{type:"Select",id:t.id,name:t.name,key:t.key,afterElm:s.$el});n.children.splice(i+1,0,a),await lt(this,R,j).call(this)}async insertInput(t){const e=this.splitWrite(t);if(!e)return;const{index:i,write:s,grid:n}=e,a=new Oe(n,{type:"Input",text:t.text,placeholder:t.placeholder,key:t.key,afterElm:s.$el});n.children.splice(i+1,0,a),a.focus(-1),await lt(this,R,j).call(this)}async insertCustom(t){const e=this.splitWrite(t);if(!e)return;const{index:i,write:s,grid:n}=e,a=new Ce(n,{type:"Custom",html:t.html,afterElm:s.$el});n.children.splice(i+1,0,a),await lt(this,R,j).call(this)}async reset(t){if(this.$el.innerHTML="",this.NODES=t.chatNode.map(t=>new Te(this,t)),t.clearHistory){const t=this.NODES[this.NODES.length-1],e=t.children[t.children.length-1];this.undoHistory=[{nodes:this.compileNodes(this.NODES),gridIndex:this.NODES.length-1,childIndex:t.children.length-1,offset:Boolean(e.text)?e.text.length:1,type:"Write"}],this.redoHistory=[]}this.markLastType="Write",await this.chat.nextTick(),this.focusLast(),await lt(this,R,j).call(this,!t.clearHistory)}destroy(){this.bus.offKeyEvent(this.eventKey),ct(this,$).forEach(t=>{const e=t[0],i=t[1];for(const s in i)e.removeEventListener(s,i[s])})}useComponent(t,e){this.components[t]=e}async insertComponent(t,e){const i=this.components[t];if(!i)return;const s=this.splitWrite({type:t,data:e,del:0});if(!s)return;const{index:n,write:a,grid:o}=s,c=new i({type:t,data:e,context:o,config:{afterElm:a.$el}});o.children.splice(n+1,0,c),await lt(this,R,j).call(this)}}A=new WeakMap,$=new WeakMap,R=new WeakSet,W=function(){this.bus.on(this.eventKey,kt,async t=>{await lt(this,R,j).call(this),t&&t()}),this.bus.on(this.eventKey,Ot,async(t,e)=>{await lt(this,R,K).call(this,t),e&&e()}),this.bus.on(this.eventKey,Ct,t=>{lt(this,R,G).call(this,t)}),this.bus.on(this.eventKey,Tt,async t=>{await lt(this,R,P).call(this),t&&t()}),this.bus.on(this.eventKey,Dt,async t=>{await lt(this,R,z).call(this),t&&t()}),this.bus.on(this.eventKey,St,async t=>{await lt(this,R,F).call(this),t&&t()}),this.bus.on(this.eventKey,Lt,se(lt(this,R,V),200).bind(this)),this.bus.on(this.eventKey,Mt,()=>{lt(this,R,U).call(this)}),this.bus.on(this.eventKey,It,t=>{rt(this,A,t)}),this.bus.on(this.eventKey,At,async(t,e)=>{await this.insertMention(t),e&&e()}),this.bus.on(this.eventKey,$t,async(t,e)=>{await this.insertTrigger(t),e&&e()}),this.bus.on(this.eventKey,Rt,async(t,e)=>{await this.insertSelect(t),e&&e()}),this.bus.on(this.eventKey,Wt,async(t,e)=>{await this.insertInput(t),e&&e()}),this.bus.on(this.eventKey,_t,async(t,e)=>{await this.insertCustom(t),e&&e()}),this.bus.on(this.eventKey,Kt,t=>{switch(t){case"first":this.focusFirst();break;case"last":this.focusLast();break;case"mark":this.focusMark()}}),this.bus.on(this.eventKey,wt,()=>{this.destroy()})},_=function(){rt(this,$,[[this.$el,{keydown:t=>{if(this.isComposition=t.isComposing,this.chat.deviceInfo.isPc||!re(t,"IME")){if(!this.IME_MODEL)if(this.isComposition||!re(t,"text-backspace")&&!re(t,"text-delete"))if(this.chat.options.keyboardWrapFun(t)||!this.chat.deviceInfo.isPc&&"Enter"===t.key)t.preventDefault(),t.stopPropagation(),lt(this,R,P).call(this);else if(!ct(this,A)&&this.chat.options.keyboardSendFun(t))t.preventDefault(),t.stopPropagation(),this.isComposition||this.bus.emit(yt);else if(re(t,"text-select-all"))t.preventDefault(),t.stopPropagation(),this.selectAll();else if(re(t,"text-move"))t.preventDefault(),t.stopPropagation(),this.isComposition||this.cursorMove("ArrowLeft"===t.key||"ArrowLeft"===t.code?-1:1);else if(re(t,"text-updown")){if(!this.isComposition){t.preventDefault(),t.stopPropagation();const e="ArrowUp"===t.key||"ArrowUp"===t.code,{instance:i,offset:s}=this.chat.getCurrentNode();if("Write"===i.type){const t=0===s||""===i.text&&1===s,n=s===i.text.length||""===i.text&&1===s;e?t?this.chat.jumpPrev("end"):i.focus(0):n?this.chat.jumpNext("start"):i.focus(-1)}else e?this.chat.jumpPrev("end"):this.chat.jumpNext("start")}}else re(t,"text-undo")?(t.preventDefault(),t.stopPropagation(),lt(this,R,z).call(this)):re(t,"text-redo")?(t.preventDefault(),t.stopPropagation(),lt(this,R,F).call(this)):re(t,"text-jump")&&(t.preventDefault(),t.stopPropagation(),t.shiftKey?this.chat.jumpPrev():this.chat.jumpNext());else{t.preventDefault(),t.stopPropagation();const e=re(t,"text-delete");lt(this,R,K).call(this,e)}}else this.IME_MODEL=!0},beforeinput:async t=>{if(!this.IME_MODEL||!["insertParagraph","deleteContentBackward"].includes(t.inputType))return;t.preventDefault(),t.stopPropagation();const e=this.chat.getSelection();let i=this.findNode(e.focusNode),s=e.focusOffset;if(i||(i=this.findNode(this.markCursorWrite.node),s=this.markCursorWrite.offset),!i)return;"Grid"===i.type&&(i=i.children[0]),this.FIX_MODEL=!0;const n=i,a=this.NODES.indexOf(n.context),o=n.context.children.indexOf(n),c=this.compileNodes(this.NODES);this.chat.nextTick(async()=>{this.$el.innerHTML="",this.NODES=c.map(t=>new Te(this,t));this.NODES[a].children[o].focus(s),"insertParagraph"===t.inputType?await lt(this,R,P).call(this):"deleteContentBackward"===t.inputType&&await lt(this,R,K).call(this),this.IME_MODEL=!1,this.FIX_MODEL=!1})},input:()=>{this.FIX_MODEL||(this.IME_MODEL=!1,lt(this,R,j).call(this))},copy:t=>{t.stopPropagation(),t.preventDefault(),lt(this,R,B).call(this,t)},cut:t=>{t.stopPropagation(),t.preventDefault(),lt(this,R,B).call(this,t),lt(this,R,K).call(this)},paste:t=>{t.stopPropagation(),t.preventDefault(),lt(this,R,H).call(this,t)},blur:()=>{lt(this,R,G).call(this)},focus:()=>{lt(this,R,G).call(this)},click:()=>{this.chat.nextTick(()=>{lt(this,R,G).call(this)})},compositionstart:()=>{this.isComposition=!0},compositionend:()=>{this.isComposition=!1},dragstart:t=>{t.stopPropagation(),t.preventDefault()},dragover:t=>{t.stopPropagation(),t.preventDefault()},drop:t=>{t.stopPropagation(),t.preventDefault()}}],[window,{keydown:t=>{(re(t,"text-undo")||re(t,"text-redo"))&&(t.preventDefault(),t.stopPropagation())}}]]);const t=["blur"];ct(this,$).forEach(e=>{const i=e[0],s=e[1];for(const n in s)i.addEventListener(n,s[n],-1!==t.indexOf(n))})},K=async function(t=!1){const e=this.chat.getSelection(),i=e.anchorNode,s=e.focusNode;let n=this.findNode(i),a=this.findNode(s);if(n&&a){if(n===a)t?n.delete(e):n.backspace(e);else if(n.context===a.context){n.context.deleteRangeNode({anchorInstance:n,anchorOffset:e.anchorOffset,focusInstance:a,focusOffset:e.focusOffset})}else this.deleteRangeNode({anchorInstance:n,anchorOffset:e.anchorOffset,focusInstance:a,focusOffset:e.focusOffset});await lt(this,R,j).call(this)}},P=async function(){if(this.isComposition)return;let t=this.chat.getSelection();t.isCollapsed||await lt(this,R,K).call(this),t=this.chat.getSelection();const e=t.focusNode,i=this.findNode(e);if(i){if("Write"===i.type){i.context.splitNode(i,t.focusOffset)}else"Input"===i.type&&i.setText(t.focusOffset,"\n");await lt(this,R,j).call(this)}},B=function(t){const e=this.chat.getSelection(),i=t.clipboardData;if(e.isCollapsed||e.rangeCount<=0)return;const s=e.toString().replace(/\n\n/g,"\n")||"";i.setData("text/plain",s);let n=this.findNode(e.anchorNode),a=this.findNode(e.focusNode),o=e.anchorOffset,c=e.focusOffset;if(!n||!a)return;if("Grid"===n.type&&(n=n.children[0],o=Boolean(n.text)?0:1),"Grid"===a.type&&(a=a.children[0],c=Boolean(a.text)?0:1),n===a)return;const h=n.context,r=a.context;if(h===r){const t=h.children.indexOf(n),e=r.children.indexOf(a),s=t>e,l=s?e:t,d=s?t:e,p=h.children.slice(l+1,d),g={...s?a:n},f={...s?n:a},u=s?c:o,m=s?o:c;"Write"===g.type&&(g.text=g.text.slice(u)),"Write"===f.type&&(f.text=f.text.slice(0,m)),p.unshift(g),p.push(f);const x={type:"Grid",children:p},y=this.compileNodes([x]);return void i.setData(ee,JSON.stringify(y))}const l=n.context,d=a.context,p=this.NODES.indexOf(l),g=this.NODES.indexOf(d);let f,u,m,x,y,E,w,v;p>g?(f=d,u=l,m=a,x=n,y=g,E=p,w=c,v=o):(f=l,u=d,m=n,x=a,y=p,E=g,w=o,v=c);const b=f.children.indexOf(m),N=this.compileNodes([{type:"Gird",children:f.children.filter((t,e)=>e>b)}]);"Write"===m.type?N[0].unshift({type:"Write",text:Boolean(m.text)?m.text.slice(w):""}):N[0].unshift({...this.compileNodes([{type:"Gird",children:[m]}])[0][0]});const k=u.children.indexOf(x),O=this.compileNodes([{type:"Gird",children:u.children.filter((t,e)=>e<k)}]);"Write"===x.type?O[0].push({type:"Write",text:Boolean(x.text)?x.text.slice(0,v):""}):O[0].push({...this.compileNodes([{type:"Gird",children:[x]}])[0][0]});const C=this.compileNodes(this.NODES.slice(y+1,E));C.unshift(N[0]),C.push(O[0]),i.setData(ee,JSON.stringify(C))},H=async function(t){const e=t.clipboardData,i=e.getData("text/plain");if(!i)return;if("Input"===this.markLastType)return void this.insertInputText(i);const s=e.getData(ee)||"";let n=[];try{n=JSON.parse(s)}catch(a){}this.chat.getSelection().isCollapsed||await lt(this,R,K).call(this),n&&n.length>0?this.insertNodes(n):this.insertText(i)},V=function(){if("Input"===this.markLastType){const{instance:t,offset:e}=this.markCursorInput;if(!t)return;const i=t,s=i.context;this.undoHistory.push({nodes:this.compileNodes(this.NODES),gridIndex:this.NODES.indexOf(s),childIndex:s.children.indexOf(i),offset:e,type:"Input"})}else{const{instance:t,offset:e}=this.markCursorWrite;if(!t)return;const i=t,s=i.context;this.undoHistory.push({nodes:this.compileNodes(this.NODES),gridIndex:this.NODES.indexOf(s),childIndex:s.children.indexOf(i),offset:e,type:"Write"})}this.undoHistory.length>50&&this.undoHistory.shift()},z=async function(){if(this.historyLoading||this.undoHistory.length<=1)return;const t=this.undoHistory[this.undoHistory.length-1],e=this.undoHistory[this.undoHistory.length-2];this.redoHistory.push(t),this.undoHistory.pop(),await lt(this,R,Y).call(this,e)},F=async function(){if(this.historyLoading||this.redoHistory.length<=0)return;const t=this.redoHistory[this.redoHistory.length-1];this.redoHistory.pop(),this.undoHistory.push(t),await lt(this,R,Y).call(this,t)},Y=async function(t){this.historyLoading=!0,this.$el.innerHTML="",this.NODES=t.nodes.map(t=>new Te(this,t));this.NODES[t.gridIndex].children[t.childIndex].focus(t.offset),await lt(this,R,j).call(this,!1),this.historyLoading=!1},j=async function(t=!0){const e=this.chat.getSelection(),i=e.focusNode,s=this.findNode(i);return s&<(this,R,G).call(this,{type:s.type,node:s.$el.children[0].childNodes[0],offset:e.focusOffset,instance:s}),await this.chat.nextTick(),this.isComposition||(null==s||s.updateNode(),lt(this,R,U).call(this),this.chat.deviceInfo.isPc&&t&&!this.historyLoading&&this.bus.emit(Lt)),s&&this.cursorView(),this.bus.emit(Et),s&&"Write"===s.type&&this.bus.emit(this.isComposition?Vt:Ht),!0},G=function(t){if(!t){const e=this.chat.getSelection(),i=e.focusNode,s=this.findNode(i);if(!s)return;"Write"===s.type?t={type:s.type,node:s.$el.children[0].childNodes[0],offset:e.focusOffset,instance:s}:"Input"===s.type&&(t={type:s.type,node:s.$el.children[0].children[0].childNodes[0],offset:e.focusOffset,instance:s})}if(t)switch(t.type){case"Write":this.markCursorWrite.node=t.node,this.markCursorWrite.offset=t.offset,this.markCursorWrite.instance=t.instance,this.markLastType="Write";break;case"Input":this.markCursorInput.node=t.node,this.markCursorInput.offset=t.offset,this.markCursorInput.instance=t.instance,this.markLastType="Input"}},U=function(){const t=this.chat.options.maxLength;if(-1===t)return;let e=0;const i=[];if(this.NODES.forEach((t,s)=>{let n=0;n=s>0&&1===t.children.length&&0===t.children[0].text.length?1:t.$el.textContent.replace(new RegExp(ie,"ig"),"").length,i.push(n),e+=n}),e>t){const s=e-t;let n=0,a=0;for(let t=i.length-1;t>=0;t--)if(n+=i[t],n>=s){a=t;break}this.NODES.slice(a+1).forEach(t=>{t.deleteNode()});let o=n-s;const c=this.NODES[a];if(0===o&&a>0){c.deleteNode();const e=this.NODES[a-1];return e.children[e.children.length-1].focus(-1),void(this.textLength=t)}let h=null,r=0;for(let t=0;t<c.children.length;t++){const e=c.children[t];if("Write"===e.type?o-=e.text.length:o-=e.$el.textContent.length,o<=0){h=e,r=t;break}}if(c.children.slice(r+1).forEach(t=>{t.deleteNode()}),"Write"===h.type){const e=h;e.text=e.text.slice(0,e.text.length-Math.abs(o)),e.syncNode(),e.updateNode(),e.focus(-1),this.textLength=t}else{const e=c.children[r-1];h.deleteNode(),e.ruleBRTag(),e.focus(-1),this.textLength=t-Math.abs(o)}}else this.textLength=e};class Se{constructor(){ht(this,X),ht(this,Z),rt(this,X,Object.create(null)),rt(this,Z,Object.create(null))}on(t,e,i){Reflect.get(ct(this,X),e)||Reflect.set(ct(this,X),e,Object.create(null)),Reflect.get(ct(this,Z),t)||Reflect.set(ct(this,Z),t,[]),Reflect.get(ct(this,Z),t).push(e),Reflect.set(Reflect.get(ct(this,X),e),t,i)}emit(...t){const e=t[0],i=t.slice(1),s=Reflect.get(ct(this,X),e);s&&Reflect.ownKeys(s).forEach(t=>{Reflect.get(s,t)(...i)})}off(t,e){const i=Reflect.get(ct(this,X),e);Reflect.ownKeys(i).forEach(e=>{t===e&&Reflect.deleteProperty(i,e)}),0===Reflect.ownKeys(i).length&&Reflect.deleteProperty(ct(this,X),e)}offKeyEvent(t){(Reflect.get(ct(this,Z),t)||[]).forEach(e=>{this.off(t,e)}),Reflect.deleteProperty(ct(this,Z),t)}}X=new WeakMap,Z=new WeakMap;q=new WeakMap,J=new WeakSet,Q=function(t,...e){this.context.context.bus.emit(t,...e)},tt=function(t,e=""){Array.from(t.children,(t,i)=>{const s=String(""===e?i:e+"-"+i);t.children&&t.children.length>0&<(this,J,tt).call(this,t,s);const n=t,a=n.dataset||{};if(a){a.update&&(ct(this,q)[s]=n,n.removeAttribute("data-update"),delete a.update);for(const t in a){const e=a[t];n.addEventListener(t,t=>{const i=this[e](t);i instanceof Promise?i.then(()=>{lt(this,J,et).call(this)}):lt(this,J,et).call(this)}),n.removeAttribute("data-"+t)}}})},et=function(){const t=document.createElement("span");t.innerHTML=this.render();for(let e in ct(this,q)){const i=e.split("-");ct(this,q)[e].innerHTML=lt(this,J,it).call(this,t,i)}},it=function(t,e){return 1===e.length?t.children[Number(e[0])].innerHTML:lt(this,J,it).call(this,t.children[Number(e[0])],e.slice(1))};class Le{constructor(t,e){switch(at(this,"options"),at(this,"deviceInfo",function(){if("undefined"==typeof navigator)return{isTablet:!1,isPhone:!1,isAndroid:!1,isIOS:!1,isPc:!0,isIPhone:!1,isIPad:!1,isWindows:!1,isMacOS:!1,isLinux:!1,isWechat:!1,isMobile:!1};const t=navigator.userAgent.toLowerCase(),e=t.includes("windows"),i=t.includes("macintosh"),s=t.includes("linux")&&!t.includes("android"),n=t.includes("android"),a=/iphone|ipad|ipod/.test(t),o=t.includes("iphone"),c=t.includes("ipad")||t.includes("macintosh")&&navigator.maxTouchPoints>1,h=t.includes("micromessenger"),r=c||n&&!/mobile/.test(t)||t.includes("firefox")&&t.includes("tablet")||t.includes("playbook"),l=o&&!r||n&&/mobile/.test(t)||t.includes("windows phone");return{isTablet:r,isPhone:l,isAndroid:n,isIOS:a,isPc:!l&&!r&&(e||i||s),isIPhone:o,isIPad:c,isWindows:e,isMacOS:i,isLinux:s,isWechat:h,isMobile:l||r}}()),at(this,"chatElement"),at(this,"chatEditor"),at(this,"bus"),this.options=Object.assign({},ft,e||{},{mentionConfig:void 0}),this.deviceInfo.isTablet&&(this.deviceInfo.isPc=!1),this.options.device){case"pc":this.deviceInfo.isPc=!0;break;case"h5":this.deviceInfo.isPc=!1}this.bus=new Se,this.chatElement=new ye(t,this),this.chatEditor=new De(this),this.updateConfig(e)}updateConfig(t){ae(t.placeholder)&&this.chatElement.updatePlaceholder(t.placeholder),ae(t.chatStyle)&&this.chatElement.updateChatStyle(t.chatStyle),ae(t.maxLength)&&(this.options.maxLength=t.maxLength<=0?-1:t.maxLength,this.bus.emit(Mt)),ae(t.keyboardWrapFun)&&(this.options.keyboardWrapFun=t.keyboardWrapFun),ae(t.keyboardSendFun)&&(this.options.keyboardSendFun=t.keyboardSendFun),ae(t.mentionConfig)&&(this.options.mentionConfig=Object.assign({},this.options.mentionConfig||ut,t.mentionConfig),this.chatElement.createMentionDialog()),ae(t.triggerConfig)&&(this.options.triggerConfig=t.triggerConfig.map(t=>(t.keyMap||(t.keyMap=mt[t.key]||[]),t)),this.chatElement.createTriggerDialog()),ae(t.selectConfig)&&(this.options.selectConfig=t.selectConfig,this.chatElement.createSelectDialog()),ae(t.tipConfig)&&(this.options.tipConfig=Object.assign({},xt,t.tipConfig),this.chatElement.createBeforeTip())}async nextTick(t){return new Promise(e=>{requestAnimationFrame(()=>{if(!t)return void e();const i=t();i instanceof Promise?i.then(()=>{e()}):e()})})}getSelection(){return window.getSelection()}getModel(){return this.chatEditor.compileNodes(this.chatEditor.NODES)}getHtml(t){const e=Object.assign({},{saveTagData:!1,identifyLink:!1},t||{}),i=/(https?|http|ftp|file):\/\/[-A-Za-z0-9+&@#/%?=~_|!:,.;]+[-A-Za-z0-9+&@#/%=~_|]/g,s=this.getModel();let n="",a="";return s.forEach((t,s)=>{let o='<p class="chat-tag-grid">';t.forEach((t,n)=>{let c="<span ";switch(t.type){case"Mention":c+='class="chat-tag-mention"',e.saveTagData&&(c+=` data-id="${t.id}"`),c+=`>@${ce(t.name)}`;break;case"Trigger":c+='class="chat-tag-trigger"',e.saveTagData&&(c+=` data-id="${t.id}" data-key=${t.key}`),c+=`>${t.key}${ce(t.name)}`;break;case"Select":c+='class="chat-tag-select"',e.saveTagData&&(c+=` data-id="${t.id}" data-key=${t.key}`),c+=`>${ce(t.name)}`;break;case"Input":c+='class="chat-tag-input"',e.saveTagData&&(c+=` data-placeholder="${t.placeholder}" data-key=${t.key}`),c+=`>${ce(t.text||t.placeholder)}`;break;case"Custom":c+='class="chat-tag-custom"',c+=`>${t.html}`;break;case"Write":c+='class="chat-tag-write"',a=ce(t.text),e.identifyLink?c+=`>${a.replace(i,t=>`<a class="chat-tag-link" href="${t}" target="_blank">${t}</a>`)}`:c+=`>${a}`;break;default:const o=this.chatEditor.NODES[s].children[n];if(c+='class="chat-tag-component"',e.saveTagData){for(const t in o.data)c+=` data-${t}="${o.data[t]}"`;c+=` data-type="${o.type}"`}c+=`>${o.$el.innerHTML}`}c+="</span>",o+=c}),o+="</p>",n+=o}),n}getText(){let t="";return this.getModel().forEach((e,i)=>{0!==i&&(t+="\n"),e.forEach((e,s)=>{switch(e.type){case"Write":t+=e.text;break;case"Input":t+=e.text||`[${e.placeholder}]`;break;default:t+=this.chatEditor.NODES[i].children[s].$el.textContent||""}})}),t.replace(new RegExp(`${ie}|${"\n"[0]}`,"ig"),"")}getTagData(){const t={mention:[],trigger:{},select:{},input:{}},e={mention:new Map,trigger:{},select:{}};return this.getModel().forEach(i=>{i.forEach(i=>{switch(i.type){case"Mention":e.mention.set(i.id,{id:i.id,name:i.name});break;case"Trigger":e.trigger[i.key]||(e.trigger[i.key]=new Map),e.trigger[i.key].set(i.id,{id:i.id,name:i.name});break;case"Select":e.select[i.key]||(e.select[i.key]=new Map),i.id&&i.id.split(",").length>0?i.id.split(",").forEach((t,s)=>{e.select[i.key].set(t,{id:t,name:i.name.split("、")[s]})}):e.select[i.key].set(i.id,{id:i.id,name:i.name});break;case"Input":t.input[i.key]||(t.input[i.key]=[]),t.input[i.key].push({text:i.text||"",placeholder:i.placeholder||""})}})}),t.mention=Array.from(e.mention.values()),Object.keys(e.trigger).forEach(i=>{t.trigger[i]=Array.from(e.trigger[i].values())}),Object.keys(e.select).forEach(i=>{t.select[i]=Array.from(e.select[i].values())}),t}setLineBreak(){return new Promise(t=>{this.bus.emit(Tt,t)})}async setHtml(t){return new Promise(e=>{this.bus.emit(_t,{html:`<span style="display: inline-block;">${he(t)}</span>`},e)})}async setText(t){switch(this.chatEditor.markLastType){case"Write":await this.chatEditor.insertText(t);break;case"Input":await this.chatEditor.insertInputText(t)}}async setMention(t){return new Promise(e=>{this.bus.emit(At,t,e)})}async setTrigger(t){return new Promise(e=>{this.bus.emit($t,t,e)})}async setSelect(t){return new Promise(e=>{this.bus.emit(Rt,t,e)})}async setInput(t){return new Promise(e=>{this.bus.emit(Wt,t,e)})}async setChatNode(t){await this.chatEditor.insertNodes(t)}removeMention(t){return new Promise(e=>{const i=[];this.chatEditor.NODES.forEach(e=>{e.children.forEach(e=>{const s=e;"Mention"!==s.type||t&&!t.includes(s.id)||i.push(s)})}),i.forEach(t=>{t.deleteRelevanceNode()}),this.bus.emit(kt,e)})}removeTrigger(t,e){return new Promise(i=>{const s=[];this.chatEditor.NODES.forEach(i=>{i.children.forEach(i=>{const n=i;"Trigger"!==n.type||n.key!==t||e&&!e.includes(n.id)||s.push(n)})}),s.forEach(t=>{t.deleteRelevanceNode()}),this.bus.emit(kt,i)})}removeSelect(t,e){return new Promise(i=>{const s=[];this.chatEditor.NODES.forEach(i=>{i.children.forEach(i=>{const n=i;"Select"!==n.type||n.key!==t||e&&!e.includes(n.id)||s.push(n)})}),s.forEach(t=>{t.deleteRelevanceNode()}),this.bus.emit(kt,i)})}removeInput(t){return new Promise(e=>{const i=[];this.chatEditor.NODES.forEach(e=>{e.children.forEach(e=>{const s=e;"Input"===s.type&&s.key===t&&i.push(s)})}),i.forEach(t=>{t.deleteRelevanceTag()}),this.bus.emit(kt,e)})}async reverseHtml(t,e=!1){let i=document.createElement("div");i.innerHTML=t;const s=[];Array.from(i.children,t=>{const e=[];Array.from(t.children,t=>{const i=t;switch(i.className){case"chat-tag-write":e.push({type:"Write",text:i.textContent});break;case"chat-tag-mention":e.push({type:"Mention",id:i.dataset.id||"",name:(i.textContent||"").slice(1)});break;case"chat-tag-trigger":e.push({type:"Trigger",key:i.dataset.key||"",id:i.dataset.id||"",name:(i.textContent||"").slice(1)});break;case"chat-tag-select":e.push({type:"Select",key:i.dataset.key||"",id:i.dataset.id||"",name:i.textContent});break;case"chat-tag-input":e.push({type:"Input",key:i.dataset.key||"",text:i.textContent,placeholder:i.dataset.placeholder||""});break;case"chat-tag-custom":e.push({type:"Custom",html:i.innerHTML});break;case"chat-tag-component":const t=i.dataset.type,s=i.dataset;"type"in s&&delete s.type,e.push({type:t,data:s})}}),s.push(e)}),e?(this.chatEditor.focusLast(),await this.chatEditor.insertNodes(s)):await this.chatEditor.fixEditor(s)}undo(){return new Promise(t=>{this.bus.emit(Dt,t)})}redo(){return new Promise(t=>{this.bus.emit(St,t)})}jumpPrev(t="end"){this.bus.emit(Ct);const e=this.getCurrentNode().instance,i=e.context,s=i.children.indexOf(e),n=[...i.children.slice(0,s)].reverse().find(t=>"Write"===t.type||"Input"===t.type);if(n)return void n.focus("start"===t?0:-1);const a=i.context.NODES.indexOf(i);let o;[...this.chatEditor.NODES.slice(0,a)].reverse().some(t=>[...t.children].reverse().some(t=>{if("Write"===t.type||"Input"===t.type)return o=t,!0})),o?o.focus("start"===t?0:-1):this.focus("first")}jumpNext(t="end"){this.bus.emit(Ct);const e=this.getCurrentNode().instance,i=e.context,s=i.children.indexOf(e),n=i.children.slice(s+1).find(t=>"Write"===t.type||"Input"===t.type);if(n)return void n.focus("start"===t?0:-1);const a=i.context.NODES.indexOf(i);let o;this.chatEditor.NODES.slice(a+1).some(t=>t.children.some(t=>{if("Write"===t.type||"Input"===t.type)return o=t,!0})),o?o.focus("start"===t?0:-1):this.focus("last")}move(t){this.chatEditor.focusMark(),0!==t&&this.chatEditor.cursorMove(t)}backspace(t){return new Promise(e=>{if(this.chatEditor.focusMark(),0===t)return e();if(-1===t||1===t)return void this.bus.emit(Ot,t>0,e);const i=this.getSelection(),s=i.focusNode,n=i.focusOffset;this.chatEditor.cursorMove(t);const a=this.getSelection(),o=a.focusNode,c=a.focusOffset,h=new Range,r=t<0;r?(h.setStart(o,c),h.setEnd(s,n)):(h.setStart(s,n),h.setEnd(o,c)),a.removeAllRanges(),a.addRange(h),this.bus.emit(Ot,!r,e)})}focus(t="last"){this.bus.emit(Kt,t)}disable(){this.chatElement.richText.setAttribute("contenteditable","false"),this.chatElement.rollBox.classList.add("disabled")}enable(){this.chatElement.richText.setAttribute("contenteditable","true"),this.chatElement.rollBox.classList.remove("disabled"),this.focus()}async reset(t){const e=Object.assign({},{clearHistory:!0,chatNode:[[{type:"Write",text:""}]]},t||{});await this.chatEditor.reset(e)}isEmpty(t=!0){if(t)return 0===this.getText().trim().length;const e=this.chatEditor.NODES;return!(e.length>1)&&(!(e[0].children.length>1)&&e[0].children[0].text.length<=0)}destroy(){this.bus.emit(wt);for(const t in this)delete this[t];Object.setPrototypeOf(this,Object.create(null))}showSelectPopup(t,e){this.bus.emit(Nt,{key:t,$el:e})}showTip(t){this.bus.emit(Pt,t)}closeTip(){this.bus.emit(Bt)}getCurrentNode(){switch(this.chatEditor.markLastType){case"Input":return this.chatEditor.markCursorInput;case"Write":return this.chatEditor.markCursorWrite}}useComponent(t,e){this.chatEditor.useComponent(t,e)}async setComponent(t,e){await this.chatEditor.insertComponent(t,e)}}return at(Le,"version","1.3.1"),at(Le,"EventSet",{EVENT_COMMON_SEND:yt,EVENT_COMMON_CHANGE:Et,EVENT_COMMON_DESTROY:wt,EVENT_COMMON_TIP_STATE:vt,EVENT_COMMON_DIALOG_CLOSE:bt,EVENT_COMMON_SELECT_ACTIVE:Nt,EVENT_EDITOR_INSERT_MENTION:At,EVENT_EDITOR_INSERT_TRIGGER:$t,EVENT_EDITOR_INSERT_SELECT:Rt,EVENT_EDITOR_INSERT_INPUT:Wt,EVENT_EDITOR_INSERT_CUSTOM:_t}),at(Le,"Component",class extends ve{constructor(t){var e;super(t.type,t.context),ht(this,J),at(this,"data",{}),ht(this,q,{}),this.data=t.data||{},this.$el=document.createElement("span"),this.$el.setAttribute(Yt,te),this.$el.setAttribute("contenteditable","false"),this.$el.classList.add("chat-tag-wrap"),this.$el.innerHTML=this.render(),lt(this,J,tt).call(this,this.$el),this.mount({parentElm:(null==(e=t.config)?void 0:e.parentElm)||this.context.$el,targetElm:this.$el,...t.config||{}})}remove(){this.deleteRelevanceNode(),lt(this,J,Q).call(this,kt)}render(){return"undefined"}}),Le});
|