@v-c/util 0.0.4 → 0.0.6

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 (66) hide show
  1. package/dist/props-util/index.cjs +1 -1
  2. package/dist/props-util/index.d.ts +2 -3
  3. package/dist/props-util/index.js +18 -20
  4. package/package.json +5 -1
  5. package/dist/props-util/initDefaultProps.cjs +0 -1
  6. package/dist/props-util/initDefaultProps.d.ts +0 -8
  7. package/dist/props-util/initDefaultProps.js +0 -13
  8. package/src/Children/isFragment.ts +0 -6
  9. package/src/Children/tests/isFragment.test.tsx +0 -15
  10. package/src/Children/tests/toArray.test.tsx +0 -101
  11. package/src/Children/toArray.ts +0 -27
  12. package/src/Dom/addEventListener.ts +0 -20
  13. package/src/Dom/canUseDom.ts +0 -7
  14. package/src/Dom/class.ts +0 -29
  15. package/src/Dom/contains.ts +0 -19
  16. package/src/Dom/css.ts +0 -113
  17. package/src/Dom/dynamicCSS.ts +0 -173
  18. package/src/Dom/findDOMNode.ts +0 -23
  19. package/src/Dom/focus.ts +0 -96
  20. package/src/Dom/isVisible.ts +0 -23
  21. package/src/Dom/scrollLocker.ts +0 -144
  22. package/src/Dom/shadow.ts +0 -17
  23. package/src/Dom/styleChecker.ts +0 -31
  24. package/src/Dom/support.ts +0 -27
  25. package/src/EventInterface.ts +0 -19
  26. package/src/KeyCode.ts +0 -517
  27. package/src/Portal.tsx +0 -50
  28. package/src/PortalWrapper.tsx +0 -217
  29. package/src/composeProps.ts +0 -23
  30. package/src/createRef.ts +0 -32
  31. package/src/debug/diff.ts +0 -66
  32. package/src/deprecated.ts +0 -8
  33. package/src/getScrollBarSize.tsx +0 -57
  34. package/src/guid.ts +0 -4
  35. package/src/hooks/useEvent.ts +0 -3
  36. package/src/hooks/useId.ts +0 -20
  37. package/src/hooks/useLayoutEffect.ts +0 -61
  38. package/src/hooks/useMemo.ts +0 -21
  39. package/src/hooks/useMergedState.ts +0 -44
  40. package/src/hooks/useMobile.ts +0 -16
  41. package/src/hooks/useState.ts +0 -17
  42. package/src/index.ts +0 -3
  43. package/src/isEqual.ts +0 -50
  44. package/src/isMobile.ts +0 -15
  45. package/src/isValid.ts +0 -4
  46. package/src/omit.ts +0 -14
  47. package/src/pickAttrs.ts +0 -79
  48. package/src/props-util/index.ts +0 -57
  49. package/src/props-util/initDefaultProps.ts +0 -34
  50. package/src/raf.ts +0 -55
  51. package/src/setStyle.ts +0 -38
  52. package/src/switchScrollingEffect.ts +0 -48
  53. package/src/test/domHook.ts +0 -66
  54. package/src/type.ts +0 -94
  55. package/src/utils/checkSlotProp.ts +0 -10
  56. package/src/utils/get.ts +0 -15
  57. package/src/utils/omit.ts +0 -9
  58. package/src/utils/set.ts +0 -110
  59. package/src/utils/transition.ts +0 -128
  60. package/src/vnode.ts +0 -86
  61. package/src/vueuse/unref-element.ts +0 -13
  62. package/src/warning.ts +0 -79
  63. package/tests/Portal.spec.tsx +0 -199
  64. package/tsconfig.json +0 -8
  65. package/vite.config.ts +0 -18
  66. package/vitest.config.ts +0 -11
@@ -1,128 +0,0 @@
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 DELETED
@@ -1,86 +0,0 @@
1
- import type { Slots, VNode, VNodeArrayChildren, VNodeProps } from 'vue'
2
- import type { RefObject } from './createRef'
3
- import { cloneVNode, Comment, Fragment, isVNode, render as VueRender } from 'vue'
4
- import { filterEmpty } from './props-util'
5
- import warning from './warning'
6
-
7
- type NodeProps = Record<string, any> &
8
- Omit<VNodeProps, 'ref'> & { ref?: VNodeProps['ref'] | RefObject }
9
-
10
- export function cloneElement<T, U>(
11
- vnode: VNode<T, U> | VNode<T, U>[],
12
- nodeProps: NodeProps = {},
13
- override = true,
14
- mergeRef = false,
15
- ): VNode<T, U> | null {
16
- let ele = vnode
17
- if (Array.isArray(vnode))
18
- ele = filterEmpty(vnode)[0]
19
-
20
- if (!ele)
21
- return null
22
-
23
- const node: any = cloneVNode(ele as VNode<T, U>, nodeProps as any, mergeRef)
24
-
25
- // cloneVNode内部是合并属性,这里改成覆盖属性
26
- node.props = (override ? { ...node.props, ...nodeProps } : node.props) as any
27
- warning(typeof node.props.class !== 'object', 'class must be string')
28
- return node
29
- }
30
-
31
- export function cloneVNodes(vnodes: any, nodeProps = {}, override = true) {
32
- return vnodes.map((vnode: any) => cloneElement(vnode, nodeProps, override))
33
- }
34
-
35
- export function deepCloneElement<T, U>(
36
- vnode: VNode<T, U> | VNode<T, U>[],
37
- nodeProps: NodeProps = {},
38
- override = true,
39
- mergeRef = false,
40
- ): any {
41
- if (Array.isArray(vnode)) {
42
- return vnode.map((item: any) => deepCloneElement(item, nodeProps, override, mergeRef))
43
- }
44
- else {
45
- // 需要判断是否为vnode方可进行clone操作
46
- if (!isVNode(vnode))
47
- return vnode
48
-
49
- const cloned: any = cloneElement(vnode, nodeProps, override, mergeRef)
50
- if (Array.isArray(cloned.children))
51
- cloned.children = deepCloneElement(cloned.children as VNode<T, U>[])
52
-
53
- return cloned
54
- }
55
- }
56
-
57
- export function triggerVNodeUpdate(vm: VNode, attrs: Record<string, any>, dom: any) {
58
- VueRender(cloneVNode(vm, { ...attrs }), dom)
59
- }
60
-
61
- function ensureValidVNode(slot: VNodeArrayChildren | null) {
62
- return (slot || []).some((child) => {
63
- if (!isVNode(child))
64
- return true
65
- if (child.type === Comment)
66
- return false
67
- if (child.type === Fragment && !ensureValidVNode(child.children as VNodeArrayChildren))
68
- return false
69
- return true
70
- })
71
- ? slot
72
- : null
73
- }
74
-
75
- export function customRenderSlot(
76
- slots: Slots,
77
- name: string,
78
- props: Record<string, unknown>,
79
- fallback?: () => VNodeArrayChildren,
80
- ) {
81
- const slot = slots[name]?.(props)
82
- if (ensureValidVNode(slot as any))
83
- return slot
84
-
85
- return fallback?.()
86
- }
@@ -1,13 +0,0 @@
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/src/warning.ts DELETED
@@ -1,79 +0,0 @@
1
- let warned: Record<string, boolean> = {}
2
-
3
- export type preMessageFn = (
4
- message: string,
5
- type: 'warning' | 'note',
6
- ) => string | null | undefined | number
7
-
8
- const preWarningFns: preMessageFn[] = []
9
-
10
- /**
11
- * Pre warning enable you to parse content before console.error.
12
- * Modify to null will prevent warning.
13
- */
14
- export function preMessage(fn: preMessageFn) {
15
- preWarningFns.push(fn)
16
- }
17
-
18
- export function warning(valid: boolean, message: string) {
19
- // Support uglify
20
- if (
21
- process.env.NODE_ENV !== 'production'
22
- && !valid
23
- && console !== undefined
24
- ) {
25
- const finalMessage = preWarningFns.reduce(
26
- (msg, preMessageFn) => (preMessageFn as any)(msg ?? '', 'warning'),
27
- message,
28
- )
29
-
30
- if (finalMessage)
31
- console.error(`Warning: ${finalMessage}`)
32
- }
33
- }
34
-
35
- export function note(valid: boolean, message: string) {
36
- // Support uglify
37
- if (
38
- process.env.NODE_ENV !== 'production'
39
- && !valid
40
- && console !== undefined
41
- ) {
42
- const finalMessage = preWarningFns.reduce(
43
- (msg, preMessageFn) => (preMessageFn as any)(msg ?? '', 'note'),
44
- message,
45
- )
46
-
47
- if (finalMessage)
48
- console.warn(`Note: ${finalMessage}`)
49
- }
50
- }
51
-
52
- export function resetWarned() {
53
- warned = {}
54
- }
55
-
56
- export function call(
57
- method: (valid: boolean, message: string) => void,
58
- valid: boolean,
59
- message: string,
60
- ) {
61
- if (!valid && !warned[message]) {
62
- method(false, message)
63
- warned[message] = true
64
- }
65
- }
66
-
67
- export function warningOnce(valid: boolean, message: string) {
68
- call(warning, valid, message)
69
- }
70
-
71
- export function noteOnce(valid: boolean, message: string) {
72
- call(note, valid, message)
73
- }
74
-
75
- warningOnce.preMessage = preMessage
76
- warningOnce.resetWarned = resetWarned
77
- warningOnce.noteOnce = noteOnce
78
-
79
- export default warningOnce
@@ -1,199 +0,0 @@
1
- import { mount } from '@vue/test-utils'
2
- import { afterEach, beforeEach, describe, expect, it } from 'vitest'
3
- import { defineComponent, onMounted, ref } from 'vue'
4
- import Portal from '../src/Portal'
5
- import PortalWrapper, { getOpenCount } from '../src/PortalWrapper'
6
-
7
- describe('portal', () => {
8
- let domContainer: HTMLDivElement
9
-
10
- window.requestAnimationFrame = callback => window.setTimeout(callback)
11
- window.cancelAnimationFrame = id => window.clearTimeout(id)
12
-
13
- beforeEach(() => {
14
- domContainer = document.createElement('div')
15
- document.body.appendChild(domContainer)
16
- })
17
-
18
- afterEach(() => {
19
- document.body.removeChild(domContainer)
20
- })
21
- it('forceRender', () => {
22
- const divRef = ref<HTMLDivElement>()
23
-
24
- const wrapper = mount(
25
- <PortalWrapper forceRender>
26
- {{
27
- default: () => <div ref={divRef as any}>2333</div>,
28
- }}
29
- </PortalWrapper>,
30
- )
31
-
32
- expect(divRef.value).toBeTruthy()
33
- wrapper.unmount()
34
- })
35
-
36
- it('didUpdate', () => {
37
- let times = 0
38
- const didUpdate = () => {
39
- ++times
40
- }
41
-
42
- let wrapper = mount(
43
- <Portal
44
- didUpdate={didUpdate}
45
- getContainer={() => document.createElement('div')}
46
- >
47
- light
48
- </Portal>,
49
- )
50
- expect(times).toEqual(0)
51
- wrapper.unmount()
52
- wrapper = mount(
53
- <Portal
54
- didUpdate={didUpdate}
55
- getContainer={() => document.createElement('div')}
56
- {...{ justForceUpdate: true }}
57
- >
58
- light
59
- </Portal>,
60
- )
61
- expect(times).toEqual(1)
62
- wrapper.unmount()
63
- })
64
-
65
- describe('getContainer', () => {
66
- it('string', () => {
67
- const div = document.createElement('div')
68
- div.id = 'bamboo-light'
69
- document.body.appendChild(div)
70
-
71
- const wrapper = mount(
72
- <PortalWrapper visible getContainer="#bamboo-light">
73
- {() => <div>2333</div>}
74
- </PortalWrapper>,
75
- )
76
-
77
- expect((document as any).querySelector?.('#bamboo-light').childElementCount)
78
- .toEqual(1)
79
-
80
- document.body.removeChild(div)
81
- wrapper.unmount()
82
- })
83
-
84
- it('function', () => {
85
- const div = document.createElement('div')
86
-
87
- const wrapper = mount(
88
- <PortalWrapper visible getContainer={() => div}>
89
- {() => <div>2333</div>}
90
- </PortalWrapper>,
91
- )
92
-
93
- expect(div.childElementCount).toEqual(1)
94
-
95
- wrapper.unmount()
96
- })
97
-
98
- it('htmlElement', () => {
99
- const div = document.createElement('div')
100
-
101
- const wrapper = mount(
102
- <PortalWrapper visible getContainer={div}>
103
- {() => <div>2333</div>}
104
- </PortalWrapper>,
105
- )
106
-
107
- expect(div.childElementCount).toEqual(1)
108
- wrapper.unmount()
109
- })
110
-
111
- it('delay', () => {
112
- let dom: any
113
- const wrapper = mount(defineComponent({
114
- setup() {
115
- const divRef = ref<HTMLDivElement>()
116
- onMounted(() => {
117
- dom = divRef.value as any
118
- })
119
- return () => {
120
- return (
121
- <div>
122
- <PortalWrapper visible getContainer={() => divRef.value!}>
123
- {() => <div />}
124
- </PortalWrapper>
125
- <div ref={divRef as any} />
126
- </div>
127
- )
128
- }
129
- },
130
- }))
131
-
132
- expect(dom?.childElementCount).toEqual(1)
133
- wrapper.unmount()
134
- })
135
- })
136
-
137
- describe('openCount', () => {
138
- it('start as 0', () => {
139
- expect(getOpenCount()).toEqual(0)
140
-
141
- const wrapper = mount(
142
- <PortalWrapper visible={false}>{() => <div>2333</div>}</PortalWrapper>,
143
- )
144
- expect(getOpenCount()).toEqual(0)
145
-
146
- const wrapper1 = mount(<PortalWrapper visible>{() => <div>2333</div>}</PortalWrapper>)
147
- expect(getOpenCount()).toEqual(1)
148
-
149
- wrapper.unmount()
150
- wrapper1.unmount()
151
- })
152
-
153
- it('correct count', () => {
154
- const Demo = defineComponent({
155
- props: {
156
- count: Number,
157
- visible: Boolean,
158
- },
159
- setup(props) {
160
- return () => {
161
- const { count, visible } = props
162
- const getItem = (index: number) => {
163
- return (
164
- <>
165
- <PortalWrapper key={index} visible={visible}>
166
- {() => <div>2333</div>}
167
- </PortalWrapper>
168
- </>
169
- )
170
- }
171
- return (
172
- <>
173
- {Array.from({ length: count as any }).fill(null).map((_, index) => getItem(index))}
174
- </>
175
- )
176
- }
177
- },
178
- })
179
-
180
- expect(getOpenCount()).toEqual(0)
181
-
182
- let wrapper = mount(<Demo count={1} visible />)
183
- expect(getOpenCount()).toEqual(1)
184
- wrapper.unmount()
185
-
186
- wrapper = mount(<Demo count={2} visible />)
187
- expect(getOpenCount()).toEqual(2)
188
- wrapper.unmount()
189
-
190
- wrapper = mount(<Demo count={1} visible />)
191
- expect(getOpenCount()).toEqual(1)
192
- wrapper.unmount()
193
-
194
- wrapper = mount(<Demo count={1} visible={false} />)
195
- expect(getOpenCount()).toEqual(0)
196
- wrapper.unmount()
197
- })
198
- })
199
- })
package/tsconfig.json DELETED
@@ -1,8 +0,0 @@
1
- {
2
- "extends": ["../../tsconfig.json"],
3
- "compilerOptions": {
4
- "strictNullChecks": false,
5
- "noImplicitAny": false
6
- },
7
- "include": ["src/**/*.ts", "src/**/*.tsx", "src/**/*.js", "src/**/*.jsx"]
8
- }
package/vite.config.ts DELETED
@@ -1,18 +0,0 @@
1
- import type { UserConfig } from 'vite'
2
- import fg from 'fast-glob'
3
- import { defineConfig, mergeConfig } from 'vite'
4
- import { buildCommon } from '../../scripts/build.common'
5
-
6
- const entry = fg.sync(['src/**/*.ts', 'src/**/*.tsx', '!src/**/*.test.ts', '!src/**/*.test.tsx', '!src/**/tests'])
7
-
8
- export default defineConfig({
9
- ...mergeConfig(buildCommon({
10
- external: ['vue'],
11
- }), {
12
- build: {
13
- lib: {
14
- entry,
15
- },
16
- },
17
- } as UserConfig),
18
- })
package/vitest.config.ts DELETED
@@ -1,11 +0,0 @@
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
- )