export type TransitionBlock = {
key?: any
- transition?: VaporTransitionHooks
+ $transition?: VaporTransitionHooks
}
export type BlockFn = (...args: any[]) => Block
anchor?: Node
insert?: (parent: ParentNode, anchor: Node | null) => void
remove?: (parent?: ParentNode) => void
- transitionChild?: TransitionBlock | undefined
+ $transition?: VaporTransitionHooks | undefined
constructor(nodes: Block) {
this.nodes = nodes
scope: EffectScope | undefined
current?: BlockFn
fallback?: BlockFn
- transitionChild?: Block
constructor(anchorLabel?: string) {
super([])
pauseTracking()
const parent = this.anchor.parentNode
- const transition = this.transition
+ const transition = this.$transition
const renderBranch = () => {
if (render) {
this.scope = new EffectScope()
this.nodes = this.scope.run(render) || []
if (transition) {
- this.transitionChild = applyTransitionEnterHooks(
- this.nodes,
- transition,
- )
+ this.$transition = applyTransitionEnterHooks(this.nodes, transition)
}
if (parent) insert(this.nodes, parent, this.anchor)
} else {
resetTracking()
}
-
- get transition(): VaporTransitionHooks | undefined {
- return this.transitionChild && this.transitionChild.transition
- }
}
export function isFragment(val: NonNullable<unknown>): val is VaporFragment {
anchor = anchor === 0 ? parent.firstChild : anchor
if (block instanceof Node) {
// don't apply transition on text or comment nodes
- if (block.transition && block instanceof Element) {
+ if (block.$transition && block instanceof Element) {
performTransitionEnter(
block,
// @ts-expect-error
- block.transition,
+ block.$transition,
() => parent.insertBefore(block, anchor),
parentSuspense,
)
export function remove(block: Block, parent?: ParentNode): void {
if (block instanceof Node) {
- if (block.transition && block instanceof Element) {
+ if (block.$transition && block instanceof Element) {
performTransitionLeave(
block,
// @ts-expect-error
- block.transition,
+ block.$transition,
() => parent && parent.removeChild(block),
)
} else {
function setTransitionHooks(block: Block, hooks: VaporTransitionHooks) {
if (!isFragment(block)) {
- block.transition = hooks
+ block.$transition = hooks
}
}
export function applyTransitionEnterHooks(
block: Block,
hooks: VaporTransitionHooks,
-): Block | undefined {
+): VaporTransitionHooks | undefined {
const child = findElementChild(block)
+ let enterHooks
if (child) {
const { props, state, delayedLeave } = hooks
- let enterHooks = resolveTransitionHooks(
+ enterHooks = resolveTransitionHooks(
child,
props,
state,
enterHooks.delayedLeave = delayedLeave
setTransitionHooks(child, enterHooks)
if (isFragment(block)) {
- block.transitionChild = child
+ block.$transition = enterHooks
}
}
- return child
+ return enterHooks
}
export function applyTransitionLeaveHooks(
leavingHooks.afterLeave = () => {
state.isLeaving = false
afterLeaveCb()
+ leavingBlock.$transition = undefined
delete leavingHooks.afterLeave
}
} else if (mode === 'in-out') {
block[leaveCbKey] = () => {
earlyRemove()
block[leaveCbKey] = undefined
+ leavingBlock.$transition = undefined
delete enterHooks.delayedLeave
}
enterHooks.delayedLeave = () => {
delayedLeave()
+ leavingBlock.$transition = undefined
delete enterHooks.delayedLeave
}
}
}
}
+const transitionChildCache = new WeakMap<Block, Block>()
export function findElementChild(block: Block): Block | undefined {
+ if (transitionChildCache.has(block)) {
+ return transitionChildCache.get(block)
+ }
+
let child: Block | undefined
if (block instanceof Node) {
// transition can only be applied on Element child
if (target instanceof DynamicFragment) {
return setDisplay(target.nodes, value)
}
- const { transition } = target
+ const { $transition } = target
if (target instanceof Element) {
const el = target as VShowElement
if (!(vShowOriginalDisplay in el)) {
el[vShowOriginalDisplay] =
el.style.display === 'none' ? '' : el.style.display
}
- if (transition) {
+ if ($transition) {
if (value) {
- transition.beforeEnter(target)
+ $transition.beforeEnter(target)
el.style.display = el[vShowOriginalDisplay]!
- transition.enter(target)
+ $transition.enter(target)
} else {
- transition.leave(target, () => {
+ $transition.leave(target, () => {
el.style.display = 'none'
})
}
if (isOptimized) return
isOptimized = true
const proto = Element.prototype as any
+ proto.$transition = undefined
proto.$evtclick = undefined
proto.$root = false
proto.$html =