@v-c/util 0.0.2 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Children/isFragment.d.ts +0 -1
- package/dist/Children/toArray.d.ts +0 -1
- package/dist/Dom/addEventListener.cjs +1 -1
- package/dist/Dom/addEventListener.d.ts +2 -2
- package/dist/Dom/addEventListener.js +5 -6
- package/dist/Dom/dynamicCSS.cjs +1 -1
- package/dist/Dom/dynamicCSS.d.ts +1 -1
- package/dist/Dom/dynamicCSS.js +33 -34
- package/dist/Dom/findDOMNode.d.ts +0 -1
- package/dist/Dom/scrollLocker.cjs +1 -1
- package/dist/Dom/scrollLocker.js +59 -76
- package/dist/Dom/shadow.cjs +1 -1
- package/dist/Dom/shadow.js +8 -9
- package/dist/Portal.cjs +1 -1
- package/dist/Portal.js +14 -21
- package/dist/PortalWrapper.cjs +1 -1
- package/dist/PortalWrapper.d.ts +2 -3
- package/dist/PortalWrapper.js +39 -42
- package/dist/composeProps.cjs +1 -1
- package/dist/composeProps.js +8 -11
- package/dist/createRef.d.ts +0 -1
- package/dist/debug/diff.d.ts +1 -1
- package/dist/getScrollBarSize.cjs +1 -1
- package/dist/getScrollBarSize.js +14 -14
- package/dist/hooks/useEvent.cjs +1 -0
- package/dist/hooks/useEvent.d.ts +1 -0
- package/dist/hooks/useEvent.js +6 -0
- package/dist/hooks/useId.cjs +1 -1
- package/dist/hooks/useId.d.ts +1 -5
- package/dist/hooks/useId.js +8 -13
- package/dist/hooks/useLayoutEffect.cjs +1 -0
- package/dist/hooks/useLayoutEffect.d.ts +3 -0
- package/dist/hooks/useLayoutEffect.js +28 -0
- package/dist/hooks/useMemo.d.ts +0 -1
- package/dist/hooks/useMergedState.cjs +1 -1
- package/dist/hooks/useMergedState.d.ts +0 -1
- package/dist/hooks/useMergedState.js +16 -16
- package/dist/hooks/useMobile.cjs +1 -0
- package/dist/hooks/useMobile.d.ts +2 -0
- package/dist/hooks/useMobile.js +14 -0
- package/dist/hooks/useState.d.ts +0 -1
- package/dist/isMobile.cjs +1 -1
- package/dist/isMobile.js +4 -4
- package/dist/isValid.cjs +1 -0
- package/dist/isValid.d.ts +2 -0
- package/dist/isValid.js +6 -0
- package/dist/pickAttrs.cjs +1 -1
- package/dist/pickAttrs.js +1 -1
- package/dist/props-util/index.cjs +1 -1
- package/dist/props-util/index.d.ts +6 -1
- package/dist/props-util/index.js +21 -9
- package/dist/props-util/initDefaultProps.cjs +1 -0
- package/dist/props-util/initDefaultProps.d.ts +8 -0
- package/dist/props-util/initDefaultProps.js +13 -0
- package/dist/setStyle.d.ts +0 -1
- package/dist/type.d.ts +2 -3
- package/dist/utils/checkSlotProp.cjs +1 -1
- package/dist/utils/checkSlotProp.js +3 -4
- package/dist/utils/omit.cjs +1 -0
- package/dist/utils/omit.d.ts +1 -0
- package/dist/utils/omit.js +9 -0
- package/dist/utils/set.cjs +1 -1
- package/dist/utils/set.d.ts +1 -0
- package/dist/utils/set.js +1 -0
- package/dist/utils/transition.cjs +1 -0
- package/dist/utils/transition.d.ts +18 -0
- package/dist/utils/transition.js +79 -0
- package/dist/vnode.cjs +1 -1
- package/dist/vnode.d.ts +1 -2
- package/dist/vnode.js +14 -15
- package/dist/vueuse/unref-element.cjs +1 -0
- package/dist/vueuse/unref-element.d.ts +8 -0
- package/dist/vueuse/unref-element.js +8 -0
- package/package.json +1 -1
- package/src/Children/tests/isFragment.test.tsx +1 -1
- package/src/Children/tests/toArray.test.tsx +3 -3
- package/src/Dom/addEventListener.ts +2 -2
- package/src/Dom/focus.ts +1 -1
- package/src/Dom/scrollLocker.ts +5 -4
- package/src/KeyCode.ts +2 -1
- package/src/Portal.tsx +1 -1
- package/src/PortalWrapper.tsx +9 -6
- package/src/createRef.ts +0 -1
- package/src/hooks/useEvent.ts +3 -0
- package/src/hooks/useId.ts +13 -24
- package/src/hooks/useLayoutEffect.ts +61 -0
- package/src/hooks/useMobile.ts +16 -0
- package/src/isMobile.ts +1 -1
- package/src/isValid.ts +4 -0
- package/src/pickAttrs.ts +3 -2
- package/src/props-util/index.ts +57 -22
- package/src/props-util/initDefaultProps.ts +34 -0
- package/src/test/domHook.ts +1 -2
- package/src/type.ts +2 -2
- package/src/utils/omit.ts +9 -0
- package/src/utils/set.ts +1 -1
- package/src/utils/transition.ts +128 -0
- package/src/vnode.ts +2 -2
- package/src/vueuse/unref-element.ts +13 -0
- package/tsconfig.json +3 -2
- package/vite.config.ts +1 -1
- package/vitest.config.ts +11 -0
- package/tests/{Portal.test.tsx → Portal.spec.tsx} +2 -2
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
BaseTransitionProps,
|
|
3
|
+
CSSProperties,
|
|
4
|
+
Ref,
|
|
5
|
+
TransitionGroupProps,
|
|
6
|
+
TransitionProps,
|
|
7
|
+
} from 'vue'
|
|
8
|
+
import { nextTick } from 'vue'
|
|
9
|
+
import { tuple } from '../type'
|
|
10
|
+
|
|
11
|
+
const SelectPlacements = tuple('bottomLeft', 'bottomRight', 'topLeft', 'topRight')
|
|
12
|
+
export type SelectCommonPlacement = (typeof SelectPlacements)[number]
|
|
13
|
+
|
|
14
|
+
function getTransitionDirection(placement: SelectCommonPlacement | undefined) {
|
|
15
|
+
if (placement !== undefined && (placement === 'topLeft' || placement === 'topRight')) {
|
|
16
|
+
return `slide-down`
|
|
17
|
+
}
|
|
18
|
+
return `slide-up`
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function getTransitionProps(transitionName?: string, opt: TransitionProps = {}) {
|
|
22
|
+
if (!transitionName) {
|
|
23
|
+
return {}
|
|
24
|
+
}
|
|
25
|
+
const transitionProps: TransitionProps = transitionName
|
|
26
|
+
? {
|
|
27
|
+
name: transitionName,
|
|
28
|
+
appear: true,
|
|
29
|
+
// type: 'animation',
|
|
30
|
+
// appearFromClass: `${transitionName}-appear ${transitionName}-appear-prepare`,
|
|
31
|
+
// appearActiveClass: `antdv-base-transtion`,
|
|
32
|
+
// appearToClass: `${transitionName}-appear ${transitionName}-appear-active`,
|
|
33
|
+
enterFromClass: `${transitionName}-enter ${transitionName}-enter-prepare ${transitionName}-enter-start`,
|
|
34
|
+
enterActiveClass: `${transitionName}-enter ${transitionName}-enter-prepare`,
|
|
35
|
+
enterToClass: `${transitionName}-enter ${transitionName}-enter-active`,
|
|
36
|
+
leaveFromClass: ` ${transitionName}-leave`,
|
|
37
|
+
leaveActiveClass: `${transitionName}-leave ${transitionName}-leave-active`,
|
|
38
|
+
leaveToClass: `${transitionName}-leave ${transitionName}-leave-active`,
|
|
39
|
+
...opt,
|
|
40
|
+
}
|
|
41
|
+
: { css: false, ...opt }
|
|
42
|
+
return transitionProps
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function getTransitionGroupProps(transitionName: string, opt: TransitionProps = {}) {
|
|
46
|
+
const transitionProps: TransitionGroupProps = transitionName
|
|
47
|
+
? {
|
|
48
|
+
name: transitionName,
|
|
49
|
+
appear: true,
|
|
50
|
+
// appearFromClass: `${transitionName}-appear ${transitionName}-appear-prepare`,
|
|
51
|
+
appearActiveClass: `${transitionName}`,
|
|
52
|
+
appearToClass: `${transitionName}-appear ${transitionName}-appear-active`,
|
|
53
|
+
enterFromClass: `${transitionName}-appear ${transitionName}-enter ${transitionName}-appear-prepare ${transitionName}-enter-prepare`,
|
|
54
|
+
enterActiveClass: `${transitionName}`,
|
|
55
|
+
enterToClass: `${transitionName}-enter ${transitionName}-appear ${transitionName}-appear-active ${transitionName}-enter-active`,
|
|
56
|
+
leaveActiveClass: `${transitionName} ${transitionName}-leave`,
|
|
57
|
+
leaveToClass: `${transitionName}-leave-active`,
|
|
58
|
+
...opt,
|
|
59
|
+
}
|
|
60
|
+
: { css: false, ...opt }
|
|
61
|
+
return transitionProps
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export declare type MotionEvent = (TransitionEvent | AnimationEvent) & {
|
|
65
|
+
deadline?: boolean
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export declare type MotionEventHandler = (element: Element, done?: () => void) => CSSProperties
|
|
69
|
+
|
|
70
|
+
export declare type MotionEndEventHandler = (element: Element, done?: () => void) => boolean | void
|
|
71
|
+
|
|
72
|
+
// ================== Collapse Motion ==================
|
|
73
|
+
const getCollapsedHeight: MotionEventHandler = () => ({ height: 0, opacity: 0 })
|
|
74
|
+
const getRealHeight: MotionEventHandler = node => ({
|
|
75
|
+
height: `${node.scrollHeight}px`,
|
|
76
|
+
opacity: 1,
|
|
77
|
+
})
|
|
78
|
+
const getCurrentHeight: MotionEventHandler = (node: any) => ({ height: `${node.offsetHeight}px` })
|
|
79
|
+
// const skipOpacityTransition: MotionEndEventHandler = (_, event) =>
|
|
80
|
+
// (event as TransitionEvent).propertyName === 'height';
|
|
81
|
+
|
|
82
|
+
export interface CSSMotionProps extends Partial<BaseTransitionProps<Element>> {
|
|
83
|
+
name?: string
|
|
84
|
+
css?: boolean
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function collapseMotion(name = 'ant-motion-collapse', style: Ref<CSSProperties>, className: Ref<string>): CSSMotionProps {
|
|
88
|
+
return {
|
|
89
|
+
name,
|
|
90
|
+
appear: true,
|
|
91
|
+
css: true,
|
|
92
|
+
onBeforeEnter: (node) => {
|
|
93
|
+
className.value = name
|
|
94
|
+
style.value = getCollapsedHeight(node)
|
|
95
|
+
},
|
|
96
|
+
onEnter: (node) => {
|
|
97
|
+
nextTick(() => {
|
|
98
|
+
style.value = getRealHeight(node)
|
|
99
|
+
})
|
|
100
|
+
},
|
|
101
|
+
onAfterEnter: () => {
|
|
102
|
+
className.value = ''
|
|
103
|
+
style.value = {}
|
|
104
|
+
},
|
|
105
|
+
onBeforeLeave: (node) => {
|
|
106
|
+
className.value = name
|
|
107
|
+
style.value = getCurrentHeight(node)
|
|
108
|
+
},
|
|
109
|
+
onLeave: (node) => {
|
|
110
|
+
setTimeout(() => {
|
|
111
|
+
style.value = getCollapsedHeight(node)
|
|
112
|
+
})
|
|
113
|
+
},
|
|
114
|
+
onAfterLeave: () => {
|
|
115
|
+
className.value = ''
|
|
116
|
+
style.value = {}
|
|
117
|
+
},
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function getTransitionName(rootPrefixCls: string, motion: string, transitionName?: string) {
|
|
122
|
+
if (transitionName !== undefined) {
|
|
123
|
+
return transitionName
|
|
124
|
+
}
|
|
125
|
+
return `${rootPrefixCls}-${motion}`
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export { collapseMotion, getTransitionDirection, getTransitionName }
|
package/src/vnode.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { Slots, VNode, VNodeArrayChildren, VNodeProps } from 'vue'
|
|
2
|
-
import {
|
|
2
|
+
import type { RefObject } from './createRef'
|
|
3
|
+
import { cloneVNode, Comment, Fragment, isVNode, render as VueRender } from 'vue'
|
|
3
4
|
import { filterEmpty } from './props-util'
|
|
4
5
|
import warning from './warning'
|
|
5
|
-
import type { RefObject } from './createRef'
|
|
6
6
|
|
|
7
7
|
type NodeProps = Record<string, any> &
|
|
8
8
|
Omit<VNodeProps, 'ref'> & { ref?: VNodeProps['ref'] | RefObject }
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ComponentPublicInstance, MaybeRef } from 'vue'
|
|
2
|
+
import { toValue } from 'vue'
|
|
3
|
+
|
|
4
|
+
export type VueInstance = ComponentPublicInstance
|
|
5
|
+
/**
|
|
6
|
+
* Get the dom element of a ref of element or Vue component instance
|
|
7
|
+
*
|
|
8
|
+
* @param elRef
|
|
9
|
+
*/
|
|
10
|
+
export function unrefElement<T extends Element>(elRef: MaybeRef<T>): T {
|
|
11
|
+
const plain = toValue(elRef)
|
|
12
|
+
return (plain as any)?.$el ?? plain
|
|
13
|
+
}
|
package/tsconfig.json
CHANGED
package/vite.config.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { UserConfig } from 'vite'
|
|
2
|
-
import { defineConfig, mergeConfig } from 'vite'
|
|
3
2
|
import fg from 'fast-glob'
|
|
3
|
+
import { defineConfig, mergeConfig } from 'vite'
|
|
4
4
|
import { buildCommon } from '../../scripts/build.common'
|
|
5
5
|
|
|
6
6
|
const entry = fg.sync(['src/**/*.ts', 'src/**/*.tsx', '!src/**/*.test.ts', '!src/**/*.test.tsx', '!src/**/tests'])
|
package/vitest.config.ts
ADDED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
import { mount } from '@vue/test-utils'
|
|
1
2
|
import { afterEach, beforeEach, describe, expect, it } from 'vitest'
|
|
2
3
|
import { defineComponent, onMounted, ref } from 'vue'
|
|
3
|
-
import { mount } from '@vue/test-utils'
|
|
4
|
-
import PortalWrapper, { getOpenCount } from '../src/PortalWrapper'
|
|
5
4
|
import Portal from '../src/Portal'
|
|
5
|
+
import PortalWrapper, { getOpenCount } from '../src/PortalWrapper'
|
|
6
6
|
|
|
7
7
|
describe('portal', () => {
|
|
8
8
|
let domContainer: HTMLDivElement
|