@v-c/util 0.0.2 → 0.0.3

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.
Files changed (103) hide show
  1. package/dist/Children/isFragment.d.ts +0 -1
  2. package/dist/Children/toArray.d.ts +0 -1
  3. package/dist/Dom/addEventListener.cjs +1 -1
  4. package/dist/Dom/addEventListener.d.ts +2 -2
  5. package/dist/Dom/addEventListener.js +5 -6
  6. package/dist/Dom/dynamicCSS.cjs +1 -1
  7. package/dist/Dom/dynamicCSS.d.ts +1 -1
  8. package/dist/Dom/dynamicCSS.js +33 -34
  9. package/dist/Dom/findDOMNode.d.ts +0 -1
  10. package/dist/Dom/scrollLocker.cjs +1 -1
  11. package/dist/Dom/scrollLocker.js +59 -76
  12. package/dist/Dom/shadow.cjs +1 -1
  13. package/dist/Dom/shadow.js +8 -9
  14. package/dist/Portal.cjs +1 -1
  15. package/dist/Portal.js +14 -21
  16. package/dist/PortalWrapper.cjs +1 -1
  17. package/dist/PortalWrapper.d.ts +2 -3
  18. package/dist/PortalWrapper.js +39 -42
  19. package/dist/composeProps.cjs +1 -1
  20. package/dist/composeProps.js +8 -11
  21. package/dist/createRef.d.ts +0 -1
  22. package/dist/debug/diff.d.ts +1 -1
  23. package/dist/getScrollBarSize.cjs +1 -1
  24. package/dist/getScrollBarSize.js +14 -14
  25. package/dist/hooks/useEvent.cjs +1 -0
  26. package/dist/hooks/useEvent.d.ts +1 -0
  27. package/dist/hooks/useEvent.js +6 -0
  28. package/dist/hooks/useId.cjs +1 -1
  29. package/dist/hooks/useId.d.ts +1 -5
  30. package/dist/hooks/useId.js +8 -13
  31. package/dist/hooks/useLayoutEffect.cjs +1 -0
  32. package/dist/hooks/useLayoutEffect.d.ts +3 -0
  33. package/dist/hooks/useLayoutEffect.js +28 -0
  34. package/dist/hooks/useMemo.d.ts +0 -1
  35. package/dist/hooks/useMergedState.cjs +1 -1
  36. package/dist/hooks/useMergedState.d.ts +0 -1
  37. package/dist/hooks/useMergedState.js +16 -16
  38. package/dist/hooks/useMobile.cjs +1 -0
  39. package/dist/hooks/useMobile.d.ts +2 -0
  40. package/dist/hooks/useMobile.js +14 -0
  41. package/dist/hooks/useState.d.ts +0 -1
  42. package/dist/isMobile.cjs +1 -1
  43. package/dist/isMobile.js +4 -4
  44. package/dist/isValid.cjs +1 -0
  45. package/dist/isValid.d.ts +2 -0
  46. package/dist/isValid.js +6 -0
  47. package/dist/pickAttrs.cjs +1 -1
  48. package/dist/pickAttrs.js +1 -1
  49. package/dist/props-util/index.cjs +1 -1
  50. package/dist/props-util/index.d.ts +6 -1
  51. package/dist/props-util/index.js +21 -9
  52. package/dist/props-util/initDefaultProps.cjs +1 -0
  53. package/dist/props-util/initDefaultProps.d.ts +8 -0
  54. package/dist/props-util/initDefaultProps.js +13 -0
  55. package/dist/setStyle.d.ts +0 -1
  56. package/dist/type.d.ts +2 -3
  57. package/dist/utils/checkSlotProp.cjs +1 -1
  58. package/dist/utils/checkSlotProp.js +3 -4
  59. package/dist/utils/omit.cjs +1 -0
  60. package/dist/utils/omit.d.ts +1 -0
  61. package/dist/utils/omit.js +9 -0
  62. package/dist/utils/set.cjs +1 -1
  63. package/dist/utils/set.d.ts +1 -0
  64. package/dist/utils/set.js +1 -0
  65. package/dist/utils/transition.cjs +1 -0
  66. package/dist/utils/transition.d.ts +18 -0
  67. package/dist/utils/transition.js +79 -0
  68. package/dist/vnode.cjs +1 -1
  69. package/dist/vnode.d.ts +1 -2
  70. package/dist/vnode.js +14 -15
  71. package/dist/vueuse/unref-element.cjs +1 -0
  72. package/dist/vueuse/unref-element.d.ts +8 -0
  73. package/dist/vueuse/unref-element.js +8 -0
  74. package/package.json +1 -1
  75. package/src/Children/tests/isFragment.test.tsx +1 -1
  76. package/src/Children/tests/toArray.test.tsx +3 -3
  77. package/src/Dom/addEventListener.ts +2 -2
  78. package/src/Dom/focus.ts +1 -1
  79. package/src/Dom/scrollLocker.ts +5 -4
  80. package/src/KeyCode.ts +2 -1
  81. package/src/Portal.tsx +1 -1
  82. package/src/PortalWrapper.tsx +9 -6
  83. package/src/createRef.ts +0 -1
  84. package/src/hooks/useEvent.ts +3 -0
  85. package/src/hooks/useId.ts +13 -24
  86. package/src/hooks/useLayoutEffect.ts +61 -0
  87. package/src/hooks/useMobile.ts +16 -0
  88. package/src/isMobile.ts +1 -1
  89. package/src/isValid.ts +4 -0
  90. package/src/pickAttrs.ts +3 -2
  91. package/src/props-util/index.ts +57 -22
  92. package/src/props-util/initDefaultProps.ts +34 -0
  93. package/src/test/domHook.ts +1 -2
  94. package/src/type.ts +2 -2
  95. package/src/utils/omit.ts +9 -0
  96. package/src/utils/set.ts +1 -1
  97. package/src/utils/transition.ts +128 -0
  98. package/src/vnode.ts +2 -2
  99. package/src/vueuse/unref-element.ts +13 -0
  100. package/tsconfig.json +3 -2
  101. package/vite.config.ts +1 -1
  102. package/vitest.config.ts +11 -0
  103. 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 { Comment, Fragment, render as VueRender, cloneVNode, isVNode } from 'vue'
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
@@ -1,7 +1,8 @@
1
1
  {
2
2
  "extends": ["../../tsconfig.json"],
3
3
  "compilerOptions": {
4
-
4
+ "strictNullChecks": false,
5
+ "noImplicitAny": false
5
6
  },
6
7
  "include": ["src/**/*.ts", "src/**/*.tsx", "src/**/*.js", "src/**/*.jsx"]
7
- }
8
+ }
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'])
@@ -0,0 +1,11 @@
1
+ import { defineProject, mergeConfig } from 'vitest/config'
2
+ import configShared from '../../vitest.config.ts'
3
+
4
+ export default mergeConfig(
5
+ configShared,
6
+ defineProject({
7
+ test: {
8
+ environment: 'jsdom',
9
+ },
10
+ }),
11
+ )
@@ -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