UNPKG

ant-design-x-vue-next

Version:

Ant Design X for Vue — community continuation aligned with @ant-design/x

2 lines (1 loc) 1.69 kB
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("../use-x-chat/conversationStore.js"),i={_allConversationStores:new Map,set(n,s){i._allConversationStores.set(n,s)},delete(n){i._allConversationStores.delete(n)},getConversation(n){const s=Array.from(i._allConversationStores.values());for(const r of s){const t=r.getConversation(n);if(t)return t}}};class h{constructor(s,r){this.conversations=[],this.listeners=[],this.setActiveConversationKey=t=>(this.activeConversationKey=t,this.emit(),!0),this.setConversations=t=>(this.conversations=[...t],this.emit(),!0),this.getConversation=t=>this.conversations.find(e=>e.key===t),this.addConversation=(t,e)=>this.getConversation(t.key)?!1:(this.setConversations(e==="prepend"?[t,...this.conversations]:[...this.conversations,t]),!0),this.setConversation=(t,e)=>{const o=this.getConversation(t);return o?(Object.assign(o,e),this.setConversations([...this.conversations]),!0):!1},this.removeConversation=t=>{const e=this.conversations.findIndex(o=>o.key===t);return e===-1?!1:(this.conversations.splice(e,1),this.setConversations([...this.conversations]),!0)},this.getMessages=t=>a.getConversationMessages(t),this.getSnapshot=()=>this.conversations,this.getActiveConversationKey=()=>this.activeConversationKey,this.subscribe=t=>(this.listeners.push(t),()=>{this.listeners=this.listeners.filter(e=>e!==t)}),this.destroy=()=>{i.delete(this.storeKey),this.listeners=[]},this.conversations=[...s],this.storeKey=Math.random().toString(36).slice(2),i.set(this.storeKey,this),this.activeConversationKey=r}emit(){this.listeners.forEach(s=>s())}}exports.ConversationStore=h;exports.conversationStoreHelper=i;