const exitBlock = context.enterBlock(branch)
context.reference()
// generate key for branch result when it's in transition
- // the key will be used to cache node at runtime
+ // the key will be used to track node leaving at runtime
branch.dynamic.needsKey = isInTransition(context)
return [branch, exitBlock]
}
): [SlotBlockIRNode, () => void] {
const block: SlotBlockIRNode = newBlock(slotNode)
block.props = dir && dir.exp
- block.key = key
- if (key) block.dynamic.needsKey = true
+ if (key) {
+ block.key = key
+ block.dynamic.needsKey = true
+ }
const exitBlock = context.enterBlock(block)
return [block, exitBlock]
}
context: TransformContext<ElementNode>,
): boolean {
const parentNode = context.parent && context.parent.node
- return !!(
- parentNode &&
- (isTransitionNode(parentNode as ElementNode) ||
- isTransitionGroupNode(parentNode as ElementNode))
- )
+ return !!(parentNode && isTransitionNode(parentNode as ElementNode))
}
export function isTransitionNode(node: ElementNode): boolean {
return baseResolveTransitionHooks(context, props, state, instance)
}
+// shared between vdom and vapor
export function baseResolveTransitionHooks(
context: TransitionHooksContext,
props: BaseTransitionProps<any>,
}
}
+// shared between vdom and vapor
export function performTransitionEnter(
el: RendererElement,
transition: TransitionHooks,
}
}
+// shared between vdom and vapor
export function performTransitionLeave(
el: RendererElement,
transition: TransitionHooks,
}
}
+// shared between vdom and vapor
export function baseApplyTranslation(
oldPos: DOMRect,
newPos: DOMRect,
return false
}
+// shared between vdom and vapor
export function hasCSSTransform(
el: ElementWithTransition,
root: Node,
return hasTransform
}
+// shared between vdom and vapor
export const handleMovedChildren = (
el: ElementWithTransition,
moveClass: string,
getKey && getKey(item, key, index),
))
+ // apply transition for new nodes
if (frag.$transition) {
applyTransitionEnterHooks(block.nodes, frag.$transition)
}
anchor = anchor === 0 ? parent.firstChild : anchor
if (block instanceof Node) {
if (!isHydrating) {
- // don't apply transition on text or comment nodes
+ // only apply transition on Element nodes
if (
block instanceof Element &&
(block as TransitionBlock).$transition &&
// inserted into the correct position immediately. this prevents
// `recordPosition` from getting incorrect positions in `onUpdated`
hook.disabledOnMoving = true
- positionMap.set(child, getEl(child).getBoundingClientRect())
+ positionMap.set(
+ child,
+ getTransitionElement(child).getBoundingClientRect(),
+ )
}
}
}
const moveClass = props.moveClass || `${props.name || 'v'}-move`
- const firstChild = findFirstChild(prevChildren)
+ const firstChild = getFirstConnectedChild(prevChildren)
if (
!firstChild ||
!hasCSSTransform(
forceReflow()
movedChildren.forEach(c =>
- handleMovedChildren(getEl(c) as ElementWithTransition, moveClass),
+ handleMovedChildren(
+ getTransitionElement(c) as ElementWithTransition,
+ moveClass,
+ ),
)
})
return !!(block instanceof Element || (isFragment(block) && block.insert))
}
-function getEl(c: TransitionBlock): Element {
- return (isFragment(c) ? c.nodes : c) as Element
+function getTransitionElement(c: TransitionBlock): Element {
+ return (isFragment(c) ? (c.nodes as Element[])[0] : c) as Element
}
function recordPosition(c: TransitionBlock) {
- newPositionMap.set(c, getEl(c).getBoundingClientRect())
+ newPositionMap.set(c, getTransitionElement(c).getBoundingClientRect())
}
function applyTranslation(c: TransitionBlock): TransitionBlock | undefined {
baseApplyTranslation(
positionMap.get(c)!,
newPositionMap.get(c)!,
- getEl(c) as ElementWithTransition,
+ getTransitionElement(c) as ElementWithTransition,
)
) {
return c
}
}
-function findFirstChild(children: TransitionBlock[]): Element | undefined {
+function getFirstConnectedChild(
+ children: TransitionBlock[],
+): Element | undefined {
for (let i = 0; i < children.length; i++) {
const child = children[i]
- const el = getEl(child)
+ const el = getTransitionElement(child)
if (el.isConnected) return el
}
}
parentInstance as any,
)
}
- frag.nodes = vnode.el as Node
+
+ frag.nodes = [vnode.el as Node]
simpleSetCurrentInstance(prev)
}