Files
element-plus/packages/components/message/src/instance.ts
Noblet Ouways 2f17df1209 style(eslint-config): newline before import type (#21036)
* perf: change to import-x

* feat: add rules

* chore: fix rule

* chore: fix

* chore: fix

* chore: fix

* style: `pnpm lint:fix`

* Revert "style: `pnpm lint:fix`"

This reverts commit db0116a288.

* Revert "chore: fix"

This reverts commit 69c82a90c0.

* chore: fix

* style: `pnpm lint:fix`

* fix: lint

* chore: `pnpm format`
2025-06-16 15:37:12 +08:00

37 lines
1015 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.exposed!.bottom.value
}
export const getOffsetOrSpace = (id: string, offset: number) => {
const idx = instances.findIndex((instance) => instance.id === id)
return idx > 0 ? 16 : offset
}