mirror of
https://gitee.com/element-plus/element-plus.git
synced 2024-12-16 02:11:48 +08:00
31 lines
844 B
TypeScript
31 lines
844 B
TypeScript
import { shallowReactive } from 'vue'
|
|
import type { ComponentInternalInstance, VNode } from 'vue'
|
|
import type { Mutable } from '@element-plus/utils'
|
|
import type { MessageHandler, MessageProps } from './message'
|
|
|
|
export type MessageContext = {
|
|
id: string
|
|
vnode: VNode
|
|
handler: MessageHandler
|
|
vm: ComponentInternalInstance
|
|
props: Mutable<MessageProps>
|
|
}
|
|
|
|
export const instances: MessageContext[] = shallowReactive([])
|
|
|
|
export const getInstance = (id: string) => {
|
|
const idx = instances.findIndex((instance) => instance.id === id)
|
|
const current = instances[idx]
|
|
let prev: MessageContext | undefined
|
|
if (idx > 0) {
|
|
prev = instances[idx - 1]
|
|
}
|
|
return { current, prev }
|
|
}
|
|
|
|
export const getLastOffset = (id: string): number => {
|
|
const { prev } = getInstance(id)
|
|
if (!prev) return 0
|
|
return prev.vm.exposeProxy!.bottom
|
|
}
|