refactor: rename transition components
This commit is contained in:
parent
bdafa1dfc4
commit
a834807942
@ -69,8 +69,8 @@ export type ExtractPropTypes<
|
|||||||
: { [K in string]: any }
|
: { [K in string]: any }
|
||||||
|
|
||||||
const enum BooleanFlags {
|
const enum BooleanFlags {
|
||||||
shouldCast = '1',
|
shouldCast,
|
||||||
shouldCastTrue = '2'
|
shouldCastTrue
|
||||||
}
|
}
|
||||||
|
|
||||||
type NormalizedProp =
|
type NormalizedProp =
|
||||||
|
@ -10,7 +10,7 @@ import { toRaw } from '@vue/reactivity'
|
|||||||
import { callWithAsyncErrorHandling, ErrorCodes } from '../errorHandling'
|
import { callWithAsyncErrorHandling, ErrorCodes } from '../errorHandling'
|
||||||
import { ShapeFlags } from '../shapeFlags'
|
import { ShapeFlags } from '../shapeFlags'
|
||||||
|
|
||||||
export interface TransitionProps {
|
export interface BaseTransitionProps {
|
||||||
mode?: 'in-out' | 'out-in' | 'default'
|
mode?: 'in-out' | 'out-in' | 'default'
|
||||||
appear?: boolean
|
appear?: boolean
|
||||||
|
|
||||||
@ -46,9 +46,9 @@ interface PendingCallbacks {
|
|||||||
leave?: (cancelled?: boolean) => void
|
leave?: (cancelled?: boolean) => void
|
||||||
}
|
}
|
||||||
|
|
||||||
const TransitionImpl = {
|
const BaseTransitionImpl = {
|
||||||
name: `BaseTransition`,
|
name: `BaseTransition`,
|
||||||
setup(props: TransitionProps, { slots }: SetupContext) {
|
setup(props: BaseTransitionProps, { slots }: SetupContext) {
|
||||||
const instance = getCurrentInstance()!
|
const instance = getCurrentInstance()!
|
||||||
const pendingCallbacks: PendingCallbacks = {}
|
const pendingCallbacks: PendingCallbacks = {}
|
||||||
let isLeaving = false
|
let isLeaving = false
|
||||||
@ -138,7 +138,7 @@ const TransitionImpl = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (__DEV__) {
|
if (__DEV__) {
|
||||||
;(TransitionImpl as ComponentOptions).props = {
|
;(BaseTransitionImpl as ComponentOptions).props = {
|
||||||
mode: String,
|
mode: String,
|
||||||
appear: Boolean,
|
appear: Boolean,
|
||||||
persisted: Boolean,
|
persisted: Boolean,
|
||||||
@ -157,9 +157,9 @@ if (__DEV__) {
|
|||||||
|
|
||||||
// export the public type for h/tsx inference
|
// export the public type for h/tsx inference
|
||||||
// also to avoid inline import() in generated d.ts files
|
// also to avoid inline import() in generated d.ts files
|
||||||
export const Transition = (TransitionImpl as any) as {
|
export const BaseTransition = (BaseTransitionImpl as any) as {
|
||||||
new (): {
|
new (): {
|
||||||
$props: TransitionProps
|
$props: BaseTransitionProps
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -186,7 +186,7 @@ function resolveTransitionHooks(
|
|||||||
onLeave,
|
onLeave,
|
||||||
onAfterLeave,
|
onAfterLeave,
|
||||||
onLeaveCancelled
|
onLeaveCancelled
|
||||||
}: TransitionProps,
|
}: BaseTransitionProps,
|
||||||
callHook: TransitionHookCaller,
|
callHook: TransitionHookCaller,
|
||||||
isMounted: boolean,
|
isMounted: boolean,
|
||||||
pendingCallbacks: PendingCallbacks,
|
pendingCallbacks: PendingCallbacks,
|
@ -28,7 +28,10 @@ export { Text, Comment, Fragment, Portal } from './vnode'
|
|||||||
// Internal Components
|
// Internal Components
|
||||||
export { Suspense, SuspenseProps } from './components/Suspense'
|
export { Suspense, SuspenseProps } from './components/Suspense'
|
||||||
export { KeepAlive, KeepAliveProps } from './components/KeepAlive'
|
export { KeepAlive, KeepAliveProps } from './components/KeepAlive'
|
||||||
export { Transition, TransitionProps } from './components/Transition'
|
export {
|
||||||
|
BaseTransition,
|
||||||
|
BaseTransitionProps
|
||||||
|
} from './components/BaseTransition'
|
||||||
// VNode flags
|
// VNode flags
|
||||||
export { PublicShapeFlags as ShapeFlags } from './shapeFlags'
|
export { PublicShapeFlags as ShapeFlags } from './shapeFlags'
|
||||||
import { PublicPatchFlags } from '@vue/shared'
|
import { PublicPatchFlags } from '@vue/shared'
|
||||||
|
@ -19,7 +19,8 @@ import { AppContext } from './apiApp'
|
|||||||
import { SuspenseBoundary } from './components/Suspense'
|
import { SuspenseBoundary } from './components/Suspense'
|
||||||
import { DirectiveBinding } from './directives'
|
import { DirectiveBinding } from './directives'
|
||||||
import { SuspenseImpl } from './components/Suspense'
|
import { SuspenseImpl } from './components/Suspense'
|
||||||
import { TransitionHooks } from './components/Transition'
|
import { TransitionHooks } from './components/BaseTransition'
|
||||||
|
import { warn } from './warning'
|
||||||
|
|
||||||
export const Fragment = (Symbol(__DEV__ ? 'Fragment' : undefined) as any) as {
|
export const Fragment = (Symbol(__DEV__ ? 'Fragment' : undefined) as any) as {
|
||||||
__isFragment: true
|
__isFragment: true
|
||||||
@ -194,6 +195,11 @@ export function createVNode(
|
|||||||
patchFlag: number = 0,
|
patchFlag: number = 0,
|
||||||
dynamicProps: string[] | null = null
|
dynamicProps: string[] | null = null
|
||||||
): VNode {
|
): VNode {
|
||||||
|
if (__DEV__ && !type) {
|
||||||
|
warn(`Invalid vnode type when creating vnode: ${type}.`)
|
||||||
|
type = Comment
|
||||||
|
}
|
||||||
|
|
||||||
// class & style normalization.
|
// class & style normalization.
|
||||||
if (props !== null) {
|
if (props !== null) {
|
||||||
// for reactive or proxy objects, we need to clone it to enable mutation.
|
// for reactive or proxy objects, we need to clone it to enable mutation.
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import {
|
import {
|
||||||
Transition as BaseTransition,
|
BaseTransition,
|
||||||
TransitionProps,
|
BaseTransitionProps,
|
||||||
h,
|
h,
|
||||||
warn,
|
warn,
|
||||||
FunctionalComponent,
|
FunctionalComponent,
|
||||||
@ -13,7 +13,7 @@ import { ErrorCodes } from 'packages/runtime-core/src/errorHandling'
|
|||||||
const TRANSITION = 'transition'
|
const TRANSITION = 'transition'
|
||||||
const ANIMATION = 'animation'
|
const ANIMATION = 'animation'
|
||||||
|
|
||||||
export interface CSSTransitionProps extends TransitionProps {
|
export interface TransitionProps extends BaseTransitionProps {
|
||||||
name?: string
|
name?: string
|
||||||
type?: typeof TRANSITION | typeof ANIMATION
|
type?: typeof TRANSITION | typeof ANIMATION
|
||||||
duration?: number | { enter: number; leave: number }
|
duration?: number | { enter: number; leave: number }
|
||||||
@ -29,15 +29,15 @@ export interface CSSTransitionProps extends TransitionProps {
|
|||||||
leaveToClass?: string
|
leaveToClass?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
// CSSTransition is a higher-order-component based on the platform-agnostic
|
// DOM Transition is a higher-order-component based on the platform-agnostic
|
||||||
// base Transition component, with DOM-specific logic.
|
// base Transition component, with DOM-specific logic.
|
||||||
export const CSSTransition: FunctionalComponent = (
|
export const Transition: FunctionalComponent = (
|
||||||
props: CSSTransitionProps,
|
props: TransitionProps,
|
||||||
{ slots }
|
{ slots }
|
||||||
) => h(BaseTransition, resolveCSSTransitionProps(props), slots)
|
) => h(BaseTransition, resolveTransitionProps(props), slots)
|
||||||
|
|
||||||
if (__DEV__) {
|
if (__DEV__) {
|
||||||
CSSTransition.props = {
|
Transition.props = {
|
||||||
...(BaseTransition as any).props,
|
...(BaseTransition as any).props,
|
||||||
name: String,
|
name: String,
|
||||||
type: String,
|
type: String,
|
||||||
@ -54,7 +54,7 @@ if (__DEV__) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function resolveCSSTransitionProps({
|
function resolveTransitionProps({
|
||||||
name = 'v',
|
name = 'v',
|
||||||
type,
|
type,
|
||||||
duration,
|
duration,
|
||||||
@ -68,7 +68,7 @@ function resolveCSSTransitionProps({
|
|||||||
leaveActiveClass = `${name}-leave-active`,
|
leaveActiveClass = `${name}-leave-active`,
|
||||||
leaveToClass = `${name}-leave-to`,
|
leaveToClass = `${name}-leave-to`,
|
||||||
...baseProps
|
...baseProps
|
||||||
}: CSSTransitionProps): TransitionProps {
|
}: TransitionProps): BaseTransitionProps {
|
||||||
const instance = getCurrentInstance()!
|
const instance = getCurrentInstance()!
|
||||||
const durations = normalizeDuration(duration)
|
const durations = normalizeDuration(duration)
|
||||||
const enterDuration = durations && durations[0]
|
const enterDuration = durations && durations[0]
|
||||||
@ -147,7 +147,7 @@ function resolveCSSTransitionProps({
|
|||||||
}
|
}
|
||||||
|
|
||||||
function normalizeDuration(
|
function normalizeDuration(
|
||||||
duration: CSSTransitionProps['duration']
|
duration: TransitionProps['duration']
|
||||||
): [number, number] | null {
|
): [number, number] | null {
|
||||||
if (duration == null) {
|
if (duration == null) {
|
||||||
return null
|
return null
|
||||||
@ -210,7 +210,7 @@ function nextFrame(cb: () => void) {
|
|||||||
|
|
||||||
function whenTransitionEnds(
|
function whenTransitionEnds(
|
||||||
el: Element,
|
el: Element,
|
||||||
expectedType: CSSTransitionProps['type'] | undefined,
|
expectedType: TransitionProps['type'] | undefined,
|
||||||
cb: () => void
|
cb: () => void
|
||||||
) {
|
) {
|
||||||
const { type, timeout, propCount } = getTransitionInfo(el, expectedType)
|
const { type, timeout, propCount } = getTransitionInfo(el, expectedType)
|
||||||
@ -247,7 +247,7 @@ interface CSSTransitionInfo {
|
|||||||
|
|
||||||
function getTransitionInfo(
|
function getTransitionInfo(
|
||||||
el: Element,
|
el: Element,
|
||||||
expectedType?: CSSTransitionProps['type']
|
expectedType?: TransitionProps['type']
|
||||||
): CSSTransitionInfo {
|
): CSSTransitionInfo {
|
||||||
const styles: any = window.getComputedStyle(el)
|
const styles: any = window.getComputedStyle(el)
|
||||||
// JSDOM may return undefined for transition properties
|
// JSDOM may return undefined for transition properties
|
@ -66,7 +66,7 @@ export {
|
|||||||
export { withModifiers, withKeys } from './directives/vOn'
|
export { withModifiers, withKeys } from './directives/vOn'
|
||||||
|
|
||||||
// DOM-only components
|
// DOM-only components
|
||||||
export { CSSTransition, CSSTransitionProps } from './components/CSSTransition'
|
export { Transition, TransitionProps } from './components/Transition'
|
||||||
|
|
||||||
// re-export everything from core
|
// re-export everything from core
|
||||||
// h, Component, reactivity API, nextTick, flags & types
|
// h, Component, reactivity API, nextTick, flags & types
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { ElementWithTransition } from '../components/CSSTransition'
|
import { ElementWithTransition } from '../components/Transition'
|
||||||
|
|
||||||
// compiler should normalize class + :class bindings on the same element
|
// compiler should normalize class + :class bindings on the same element
|
||||||
// into a single binding ['staticClass', dynamic]
|
// into a single binding ['staticClass', dynamic]
|
||||||
|
Loading…
Reference in New Issue
Block a user