@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.
- package/dist/props-util/index.cjs +1 -1
- package/dist/props-util/index.d.ts +2 -3
- package/dist/props-util/index.js +18 -20
- package/package.json +5 -1
- package/dist/props-util/initDefaultProps.cjs +0 -1
- package/dist/props-util/initDefaultProps.d.ts +0 -8
- package/dist/props-util/initDefaultProps.js +0 -13
- package/src/Children/isFragment.ts +0 -6
- package/src/Children/tests/isFragment.test.tsx +0 -15
- package/src/Children/tests/toArray.test.tsx +0 -101
- package/src/Children/toArray.ts +0 -27
- package/src/Dom/addEventListener.ts +0 -20
- package/src/Dom/canUseDom.ts +0 -7
- package/src/Dom/class.ts +0 -29
- package/src/Dom/contains.ts +0 -19
- package/src/Dom/css.ts +0 -113
- package/src/Dom/dynamicCSS.ts +0 -173
- package/src/Dom/findDOMNode.ts +0 -23
- package/src/Dom/focus.ts +0 -96
- package/src/Dom/isVisible.ts +0 -23
- package/src/Dom/scrollLocker.ts +0 -144
- package/src/Dom/shadow.ts +0 -17
- package/src/Dom/styleChecker.ts +0 -31
- package/src/Dom/support.ts +0 -27
- package/src/EventInterface.ts +0 -19
- package/src/KeyCode.ts +0 -517
- package/src/Portal.tsx +0 -50
- package/src/PortalWrapper.tsx +0 -217
- package/src/composeProps.ts +0 -23
- package/src/createRef.ts +0 -32
- package/src/debug/diff.ts +0 -66
- package/src/deprecated.ts +0 -8
- package/src/getScrollBarSize.tsx +0 -57
- package/src/guid.ts +0 -4
- package/src/hooks/useEvent.ts +0 -3
- package/src/hooks/useId.ts +0 -20
- package/src/hooks/useLayoutEffect.ts +0 -61
- package/src/hooks/useMemo.ts +0 -21
- package/src/hooks/useMergedState.ts +0 -44
- package/src/hooks/useMobile.ts +0 -16
- package/src/hooks/useState.ts +0 -17
- package/src/index.ts +0 -3
- package/src/isEqual.ts +0 -50
- package/src/isMobile.ts +0 -15
- package/src/isValid.ts +0 -4
- package/src/omit.ts +0 -14
- package/src/pickAttrs.ts +0 -79
- package/src/props-util/index.ts +0 -57
- package/src/props-util/initDefaultProps.ts +0 -34
- package/src/raf.ts +0 -55
- package/src/setStyle.ts +0 -38
- package/src/switchScrollingEffect.ts +0 -48
- package/src/test/domHook.ts +0 -66
- package/src/type.ts +0 -94
- package/src/utils/checkSlotProp.ts +0 -10
- package/src/utils/get.ts +0 -15
- package/src/utils/omit.ts +0 -9
- package/src/utils/set.ts +0 -110
- package/src/utils/transition.ts +0 -128
- package/src/vnode.ts +0 -86
- package/src/vueuse/unref-element.ts +0 -13
- package/src/warning.ts +0 -79
- package/tests/Portal.spec.tsx +0 -199
- package/tsconfig.json +0 -8
- package/vite.config.ts +0 -18
- package/vitest.config.ts +0 -11
package/src/PortalWrapper.tsx
DELETED
|
@@ -1,217 +0,0 @@
|
|
|
1
|
-
import type { SlotsType } from 'vue'
|
|
2
|
-
import type { PortalRef } from './Portal'
|
|
3
|
-
import { defineComponent, onBeforeUnmount, onMounted, onUpdated, shallowRef } from 'vue'
|
|
4
|
-
import canUseDom from './Dom/canUseDom'
|
|
5
|
-
import ScrollLocker from './Dom/scrollLocker'
|
|
6
|
-
import Portal from './Portal'
|
|
7
|
-
import raf from './raf'
|
|
8
|
-
import setStyle from './setStyle'
|
|
9
|
-
|
|
10
|
-
// import raf from './raf';
|
|
11
|
-
|
|
12
|
-
let openCount = 0
|
|
13
|
-
const supportDom = canUseDom()
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* @private
|
|
17
|
-
*/
|
|
18
|
-
export function getOpenCount() {
|
|
19
|
-
return process.env.NODE_ENV === 'test' ? openCount : 0
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
// https://github.com/ant-design/ant-design/issues/19340
|
|
23
|
-
// https://github.com/ant-design/ant-design/issues/19332
|
|
24
|
-
let cacheOverflow = {}
|
|
25
|
-
|
|
26
|
-
function getParent(getContainer: GetContainer) {
|
|
27
|
-
if (!supportDom)
|
|
28
|
-
return null
|
|
29
|
-
|
|
30
|
-
if (getContainer) {
|
|
31
|
-
if (typeof getContainer === 'string')
|
|
32
|
-
return document.querySelectorAll(getContainer)[0]
|
|
33
|
-
|
|
34
|
-
if (typeof getContainer === 'function')
|
|
35
|
-
return getContainer()
|
|
36
|
-
|
|
37
|
-
if (
|
|
38
|
-
typeof getContainer === 'object'
|
|
39
|
-
&& getContainer instanceof window.HTMLElement
|
|
40
|
-
) {
|
|
41
|
-
return getContainer
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
return document.body
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export type GetContainer = string | HTMLElement | (() => HTMLElement)
|
|
48
|
-
|
|
49
|
-
export type DefaultSlotInfo = SlotsType<{
|
|
50
|
-
default: {
|
|
51
|
-
getOpenCount: () => number
|
|
52
|
-
getContainer: () => HTMLElement
|
|
53
|
-
switchScrollingEffect: () => void
|
|
54
|
-
scrollLocker: ScrollLocker
|
|
55
|
-
}
|
|
56
|
-
}>
|
|
57
|
-
|
|
58
|
-
export interface PortalWrapperProps {
|
|
59
|
-
visible?: boolean
|
|
60
|
-
getContainer?: GetContainer
|
|
61
|
-
wrapperClassName?: string
|
|
62
|
-
forceRender?: boolean
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
const PortalWrapper = defineComponent<PortalWrapperProps, any, string, DefaultSlotInfo>((props, ctx) => {
|
|
66
|
-
const container = shallowRef<HTMLElement>()
|
|
67
|
-
const componentRef = shallowRef<PortalRef>()
|
|
68
|
-
const rafId = shallowRef<number>()
|
|
69
|
-
const scrollLocker = shallowRef<ScrollLocker>()
|
|
70
|
-
|
|
71
|
-
const removeCurrentContainer = () => {
|
|
72
|
-
// Portal will remove from `parentNode`.
|
|
73
|
-
// Let's handle this again to avoid refactor issue.
|
|
74
|
-
container.value?.parentNode?.removeChild(container.value)
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
const updateOpenCount = (prevProps?: Partial<PortalWrapperProps>) => {
|
|
78
|
-
const { visible: prevVisible, getContainer: prevGetContainer }
|
|
79
|
-
= prevProps || {}
|
|
80
|
-
const { visible, getContainer } = props
|
|
81
|
-
|
|
82
|
-
// Update count
|
|
83
|
-
if (
|
|
84
|
-
visible !== prevVisible
|
|
85
|
-
&& supportDom
|
|
86
|
-
&& getParent(getContainer!) === document.body
|
|
87
|
-
) {
|
|
88
|
-
if (visible && !prevVisible)
|
|
89
|
-
openCount += 1
|
|
90
|
-
else if (prevProps)
|
|
91
|
-
openCount -= 1
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
// Clean up container if needed
|
|
95
|
-
const getContainerIsFunc
|
|
96
|
-
= typeof getContainer === 'function'
|
|
97
|
-
&& typeof prevGetContainer === 'function'
|
|
98
|
-
if (
|
|
99
|
-
getContainerIsFunc
|
|
100
|
-
? getContainer.toString() !== prevGetContainer.toString()
|
|
101
|
-
: getContainer !== prevGetContainer
|
|
102
|
-
) {
|
|
103
|
-
removeCurrentContainer()
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
const attachToParent = (force = false) => {
|
|
108
|
-
if (force || (container.value && !container.value.parentNode)) {
|
|
109
|
-
const parent = getParent(props.getContainer!)
|
|
110
|
-
if (parent) {
|
|
111
|
-
parent.appendChild(container.value!)
|
|
112
|
-
return true
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
return false
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
return true
|
|
119
|
-
}
|
|
120
|
-
const setWrapperClassName = () => {
|
|
121
|
-
const { wrapperClassName } = props
|
|
122
|
-
if (
|
|
123
|
-
container.value
|
|
124
|
-
&& wrapperClassName
|
|
125
|
-
&& wrapperClassName !== container.value.className
|
|
126
|
-
) {
|
|
127
|
-
container.value.className = wrapperClassName
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
const getContainer = () => {
|
|
132
|
-
if (!supportDom)
|
|
133
|
-
return null
|
|
134
|
-
|
|
135
|
-
if (!container.value) {
|
|
136
|
-
container.value = document.createElement('div')
|
|
137
|
-
attachToParent(true)
|
|
138
|
-
}
|
|
139
|
-
setWrapperClassName()
|
|
140
|
-
return container.value
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
onMounted(() => {
|
|
144
|
-
scrollLocker.value = new ScrollLocker({
|
|
145
|
-
container: getParent(props.getContainer!) as HTMLElement,
|
|
146
|
-
})
|
|
147
|
-
updateOpenCount()
|
|
148
|
-
if (!attachToParent()) {
|
|
149
|
-
rafId.value = raf(() => {
|
|
150
|
-
// 对组件执行强制更新 forceUpdate,准备采用改变key的方式来实现
|
|
151
|
-
})
|
|
152
|
-
}
|
|
153
|
-
})
|
|
154
|
-
|
|
155
|
-
onUpdated(() => {
|
|
156
|
-
updateOpenCount(props)
|
|
157
|
-
updateOpenCount(props)
|
|
158
|
-
setWrapperClassName()
|
|
159
|
-
attachToParent()
|
|
160
|
-
})
|
|
161
|
-
|
|
162
|
-
onBeforeUnmount(() => {
|
|
163
|
-
const { visible, getContainer } = props
|
|
164
|
-
if (supportDom && getParent(getContainer!) === document.body) {
|
|
165
|
-
// 离开时不会 render, 导到离开时数值不变,改用 func 。。
|
|
166
|
-
openCount = visible && openCount ? openCount - 1 : openCount
|
|
167
|
-
}
|
|
168
|
-
removeCurrentContainer()
|
|
169
|
-
raf.cancel(rafId.value!)
|
|
170
|
-
})
|
|
171
|
-
|
|
172
|
-
/**
|
|
173
|
-
* Enhance ./switchScrollingEffect
|
|
174
|
-
* 1. Simulate document body scroll bar with
|
|
175
|
-
* 2. Record body has overflow style and recover when all of PortalWrapper invisible
|
|
176
|
-
* 3. Disable body scroll when PortalWrapper has open
|
|
177
|
-
*
|
|
178
|
-
* @memberof PortalWrapper
|
|
179
|
-
*/
|
|
180
|
-
const switchScrollingEffect = () => {
|
|
181
|
-
if (openCount === 1 && !Object.keys(cacheOverflow).length) {
|
|
182
|
-
switchScrollingEffect()
|
|
183
|
-
// Must be set after switchScrollingEffect
|
|
184
|
-
cacheOverflow = setStyle({
|
|
185
|
-
overflow: 'hidden',
|
|
186
|
-
overflowX: 'hidden',
|
|
187
|
-
overflowY: 'hidden',
|
|
188
|
-
})
|
|
189
|
-
}
|
|
190
|
-
else if (!openCount) {
|
|
191
|
-
setStyle(cacheOverflow)
|
|
192
|
-
cacheOverflow = {}
|
|
193
|
-
switchScrollingEffect()
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
return () => {
|
|
197
|
-
const { forceRender, visible } = props
|
|
198
|
-
let portal = null
|
|
199
|
-
const childProps = {
|
|
200
|
-
getOpenCount,
|
|
201
|
-
getContainer,
|
|
202
|
-
switchScrollingEffect,
|
|
203
|
-
scrollLocker: scrollLocker.value,
|
|
204
|
-
}
|
|
205
|
-
if (forceRender || visible || componentRef.value) {
|
|
206
|
-
portal = (
|
|
207
|
-
<Portal getContainer={getContainer as any} ref={componentRef}>
|
|
208
|
-
{ctx?.slots?.default(childProps as any)}
|
|
209
|
-
</Portal>
|
|
210
|
-
)
|
|
211
|
-
}
|
|
212
|
-
return portal
|
|
213
|
-
}
|
|
214
|
-
// TODO
|
|
215
|
-
})
|
|
216
|
-
|
|
217
|
-
export default PortalWrapper
|
package/src/composeProps.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
function composeProps<T extends Record<string, any>>(
|
|
2
|
-
originProps: T,
|
|
3
|
-
patchProps: Partial<T>,
|
|
4
|
-
isAll?: boolean,
|
|
5
|
-
) {
|
|
6
|
-
const composedProps: Record<string, any> = {
|
|
7
|
-
...originProps,
|
|
8
|
-
...(isAll ? patchProps : {}),
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
Object.keys(patchProps).forEach((key) => {
|
|
12
|
-
const func = patchProps[key]
|
|
13
|
-
if (typeof func === 'function') {
|
|
14
|
-
composedProps[key] = (...args: any[]) => {
|
|
15
|
-
func(...args)
|
|
16
|
-
return originProps[key]?.(...args)
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
})
|
|
20
|
-
return composedProps
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export default composeProps
|
package/src/createRef.ts
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import type { Ref } from 'vue'
|
|
2
|
-
|
|
3
|
-
export interface RefObject extends Function {
|
|
4
|
-
current?: any
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
function createRef(): any {
|
|
8
|
-
const func: RefObject = (node: any) => {
|
|
9
|
-
func.current = node
|
|
10
|
-
}
|
|
11
|
-
return func
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export function fillRef<T>(ref: Ref, node: T) {
|
|
15
|
-
if (typeof ref === 'function')
|
|
16
|
-
(ref as any)(node)
|
|
17
|
-
else if (typeof ref === 'object' && ref && 'current' in ref)
|
|
18
|
-
(ref as any).current = node
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Merge refs into one ref function to support ref passing.
|
|
23
|
-
*/
|
|
24
|
-
export function composeRef<T>(...refs: any[]) {
|
|
25
|
-
return (node: T) => {
|
|
26
|
-
refs.forEach((ref) => {
|
|
27
|
-
fillRef(ref, node)
|
|
28
|
-
})
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export default createRef
|
package/src/debug/diff.ts
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
// eslint-disable-next-line ts/ban-ts-comment
|
|
2
|
-
// @ts-nocheck
|
|
3
|
-
function createArray() {
|
|
4
|
-
const arr: any[] = []
|
|
5
|
-
// eslint-disable-next-line no-proto,no-restricted-properties
|
|
6
|
-
arr.__proto__ = []
|
|
7
|
-
// eslint-disable-next-line no-proto,no-restricted-properties
|
|
8
|
-
arr.__proto__.format = function toString() {
|
|
9
|
-
return this.map(obj => ({
|
|
10
|
-
...obj,
|
|
11
|
-
path: obj.path.join(' > '),
|
|
12
|
-
}))
|
|
13
|
-
}
|
|
14
|
-
// eslint-disable-next-line no-proto,no-restricted-properties
|
|
15
|
-
arr.__proto__.toString = function toString() {
|
|
16
|
-
return JSON.stringify(this.format(), null, 2)
|
|
17
|
-
}
|
|
18
|
-
return arr
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export default function diff(obj1, obj2, depth = 10, path = [], diffList = createArray()) {
|
|
22
|
-
if (depth <= 0)
|
|
23
|
-
return diffList
|
|
24
|
-
|
|
25
|
-
const keys = new Set([...Object.keys(obj1), ...Object.keys(obj2)])
|
|
26
|
-
keys.forEach((key) => {
|
|
27
|
-
const value1 = obj1[key]
|
|
28
|
-
const value2 = obj2[key]
|
|
29
|
-
|
|
30
|
-
// Same value
|
|
31
|
-
if (value1 === value2)
|
|
32
|
-
return
|
|
33
|
-
|
|
34
|
-
const type1 = typeof value1
|
|
35
|
-
const type2 = typeof value2
|
|
36
|
-
|
|
37
|
-
// Diff type
|
|
38
|
-
if (type1 !== type2) {
|
|
39
|
-
diffList.push({
|
|
40
|
-
path: path.concat(key),
|
|
41
|
-
value1,
|
|
42
|
-
value2,
|
|
43
|
-
})
|
|
44
|
-
return
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
// NaN
|
|
48
|
-
if (Number.isNaN(value1) && Number.isNaN(value2))
|
|
49
|
-
return
|
|
50
|
-
|
|
51
|
-
// Object & Array
|
|
52
|
-
if (type1 === 'object' && value1 !== null && value2 !== null) {
|
|
53
|
-
diff(value1, value2, depth - 1, path.concat(key), diffList)
|
|
54
|
-
return
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
// Rest
|
|
58
|
-
diffList.push({
|
|
59
|
-
path: path.concat(key),
|
|
60
|
-
value1,
|
|
61
|
-
value2,
|
|
62
|
-
})
|
|
63
|
-
})
|
|
64
|
-
|
|
65
|
-
return diffList
|
|
66
|
-
}
|
package/src/deprecated.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
export default function deprecated(props: any, instead: any, component: any) {
|
|
2
|
-
if (typeof window !== 'undefined' && window.console && window.console.error) {
|
|
3
|
-
window.console.error(
|
|
4
|
-
`Warning: ${props} is deprecated at [ ${component} ], `
|
|
5
|
-
+ `use [ ${instead} ] instead of it.`,
|
|
6
|
-
)
|
|
7
|
-
}
|
|
8
|
-
}
|
package/src/getScrollBarSize.tsx
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
let cached: number
|
|
2
|
-
|
|
3
|
-
export default function getScrollBarSize(fresh?: boolean) {
|
|
4
|
-
if (typeof document === 'undefined')
|
|
5
|
-
return 0
|
|
6
|
-
|
|
7
|
-
if (fresh || cached === undefined) {
|
|
8
|
-
const inner = document.createElement('div')
|
|
9
|
-
inner.style.width = '100%'
|
|
10
|
-
inner.style.height = '200px'
|
|
11
|
-
|
|
12
|
-
const outer = document.createElement('div')
|
|
13
|
-
const outerStyle = outer.style
|
|
14
|
-
|
|
15
|
-
outerStyle.position = 'absolute'
|
|
16
|
-
outerStyle.top = '0'
|
|
17
|
-
outerStyle.left = '0'
|
|
18
|
-
outerStyle.pointerEvents = 'none'
|
|
19
|
-
outerStyle.visibility = 'hidden'
|
|
20
|
-
outerStyle.width = '200px'
|
|
21
|
-
outerStyle.height = '150px'
|
|
22
|
-
outerStyle.overflow = 'hidden'
|
|
23
|
-
|
|
24
|
-
outer.appendChild(inner)
|
|
25
|
-
|
|
26
|
-
document.body.appendChild(outer)
|
|
27
|
-
|
|
28
|
-
const widthContained = inner.offsetWidth
|
|
29
|
-
outer.style.overflow = 'scroll'
|
|
30
|
-
let widthScroll = inner.offsetWidth
|
|
31
|
-
|
|
32
|
-
if (widthContained === widthScroll)
|
|
33
|
-
widthScroll = outer.clientWidth
|
|
34
|
-
|
|
35
|
-
document.body.removeChild(outer)
|
|
36
|
-
|
|
37
|
-
cached = widthContained - widthScroll
|
|
38
|
-
}
|
|
39
|
-
return cached
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
function ensureSize(str: string) {
|
|
43
|
-
const match = str.match(/^(.*)px$/)
|
|
44
|
-
const value = Number(match?.[1])
|
|
45
|
-
return Number.isNaN(value) ? getScrollBarSize() : value
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export function getTargetScrollBarSize(target: HTMLElement) {
|
|
49
|
-
if (typeof document === 'undefined' || !target || !(target instanceof Element))
|
|
50
|
-
return { width: 0, height: 0 }
|
|
51
|
-
|
|
52
|
-
const { width, height } = getComputedStyle(target, '::-webkit-scrollbar')
|
|
53
|
-
return {
|
|
54
|
-
width: ensureSize(width),
|
|
55
|
-
height: ensureSize(height),
|
|
56
|
-
}
|
|
57
|
-
}
|
package/src/guid.ts
DELETED
package/src/hooks/useEvent.ts
DELETED
package/src/hooks/useId.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { useId } from 'vue'
|
|
2
|
-
|
|
3
|
-
function getUseId() {
|
|
4
|
-
return useId
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
const useOriginalId = getUseId()
|
|
8
|
-
|
|
9
|
-
export default function (id?: string) {
|
|
10
|
-
const vueId = useOriginalId()
|
|
11
|
-
if (id) {
|
|
12
|
-
return id
|
|
13
|
-
}
|
|
14
|
-
// Test env always return mock id
|
|
15
|
-
if (process.env.NODE_ENV === 'test') {
|
|
16
|
-
return 'test-id'
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
return vueId
|
|
20
|
-
}
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import type { WatchSource } from 'vue'
|
|
2
|
-
import { nextTick, onMounted, onUnmounted, onUpdated, watch } from 'vue'
|
|
3
|
-
|
|
4
|
-
export function useLayoutEffect(callback: Function, deps: WatchSource<unknown>[] = []) {
|
|
5
|
-
let close: Function | null = null
|
|
6
|
-
if (deps && deps.length) {
|
|
7
|
-
watch(deps, async () => {
|
|
8
|
-
if (close) {
|
|
9
|
-
close?.()
|
|
10
|
-
}
|
|
11
|
-
await nextTick()
|
|
12
|
-
if (typeof callback === 'function') {
|
|
13
|
-
close = callback()
|
|
14
|
-
}
|
|
15
|
-
}, {
|
|
16
|
-
immediate: true,
|
|
17
|
-
flush: 'post',
|
|
18
|
-
})
|
|
19
|
-
}
|
|
20
|
-
else {
|
|
21
|
-
onMounted(() => {
|
|
22
|
-
if (close) {
|
|
23
|
-
close?.()
|
|
24
|
-
}
|
|
25
|
-
if (typeof callback === 'function') {
|
|
26
|
-
close = callback()
|
|
27
|
-
}
|
|
28
|
-
})
|
|
29
|
-
|
|
30
|
-
onUpdated(() => {
|
|
31
|
-
if (close) {
|
|
32
|
-
close?.()
|
|
33
|
-
}
|
|
34
|
-
if (typeof callback === 'function') {
|
|
35
|
-
close = callback()
|
|
36
|
-
}
|
|
37
|
-
})
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
onUnmounted(() => {
|
|
41
|
-
if (close) {
|
|
42
|
-
close?.()
|
|
43
|
-
}
|
|
44
|
-
})
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export function useLayoutUpdateEffect(callback: Function, deps: WatchSource<unknown>[]) {
|
|
48
|
-
let close: Function | null = null
|
|
49
|
-
|
|
50
|
-
watch(deps, async () => {
|
|
51
|
-
if (close) {
|
|
52
|
-
close?.()
|
|
53
|
-
}
|
|
54
|
-
await nextTick()
|
|
55
|
-
if (typeof callback === 'function') {
|
|
56
|
-
close = callback()
|
|
57
|
-
}
|
|
58
|
-
}, {
|
|
59
|
-
flush: 'post',
|
|
60
|
-
})
|
|
61
|
-
}
|
package/src/hooks/useMemo.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import type { Ref, WatchSource } from 'vue'
|
|
2
|
-
import { ref, watch } from 'vue'
|
|
3
|
-
|
|
4
|
-
export default function useMemo<T>(
|
|
5
|
-
getValue: () => T,
|
|
6
|
-
condition: (WatchSource<unknown> | object)[],
|
|
7
|
-
shouldUpdate?: (prev: any[], next: any[]) => boolean,
|
|
8
|
-
) {
|
|
9
|
-
const cacheRef: Ref<T> = ref(getValue() as any)
|
|
10
|
-
watch(condition, (next, pre) => {
|
|
11
|
-
if (shouldUpdate) {
|
|
12
|
-
if (shouldUpdate(next, pre))
|
|
13
|
-
cacheRef.value = getValue()
|
|
14
|
-
}
|
|
15
|
-
else {
|
|
16
|
-
cacheRef.value = getValue()
|
|
17
|
-
}
|
|
18
|
-
})
|
|
19
|
-
|
|
20
|
-
return cacheRef
|
|
21
|
-
}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import type { ComputedRef, Ref, UnwrapRef } from 'vue'
|
|
2
|
-
import { ref, toRaw, unref, watch, watchEffect } from 'vue'
|
|
3
|
-
|
|
4
|
-
export default function useMergedState<T, R = Ref<T>>(
|
|
5
|
-
defaultStateValue: T | (() => T),
|
|
6
|
-
option?: {
|
|
7
|
-
defaultValue?: T | (() => T)
|
|
8
|
-
value?: Ref<T> | Ref<UnwrapRef<T>> | ComputedRef<T>
|
|
9
|
-
onChange?: (val: T, prevValue: T) => void
|
|
10
|
-
postState?: (val: T) => T
|
|
11
|
-
},
|
|
12
|
-
): [R, (val: T) => void] {
|
|
13
|
-
const { defaultValue, value = ref() } = option || {}
|
|
14
|
-
let initValue: T
|
|
15
|
-
= typeof defaultStateValue === 'function' ? (defaultStateValue as any)() : defaultStateValue
|
|
16
|
-
if (value.value !== undefined)
|
|
17
|
-
initValue = unref(value as any) as T
|
|
18
|
-
|
|
19
|
-
if (defaultValue !== undefined)
|
|
20
|
-
initValue = typeof defaultValue === 'function' ? (defaultValue as any)() : defaultValue
|
|
21
|
-
|
|
22
|
-
const innerValue = ref(initValue) as Ref<T>
|
|
23
|
-
const mergedValue = ref(initValue) as Ref<T>
|
|
24
|
-
watchEffect(() => {
|
|
25
|
-
let val = value.value !== undefined ? value.value : innerValue.value
|
|
26
|
-
if (option?.postState)
|
|
27
|
-
val = option.postState(val as T)
|
|
28
|
-
mergedValue.value = val as T
|
|
29
|
-
})
|
|
30
|
-
|
|
31
|
-
function triggerChange(newValue: T) {
|
|
32
|
-
const preVal = mergedValue.value
|
|
33
|
-
innerValue.value = newValue
|
|
34
|
-
if (toRaw(mergedValue.value) !== newValue && option?.onChange)
|
|
35
|
-
option.onChange(newValue, preVal)
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
// Effect of reset value to `undefined`
|
|
39
|
-
watch(value, () => {
|
|
40
|
-
innerValue.value = value.value as T
|
|
41
|
-
})
|
|
42
|
-
|
|
43
|
-
return [mergedValue as unknown as R, triggerChange]
|
|
44
|
-
}
|
package/src/hooks/useMobile.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { onMounted, onUpdated, shallowRef } from 'vue'
|
|
2
|
-
import isMobile from '../isMobile'
|
|
3
|
-
|
|
4
|
-
export function useMobile() {
|
|
5
|
-
const mobile = shallowRef(false)
|
|
6
|
-
onMounted(() => {
|
|
7
|
-
mobile.value = isMobile()
|
|
8
|
-
})
|
|
9
|
-
|
|
10
|
-
onUpdated(() => {
|
|
11
|
-
mobile.value = isMobile()
|
|
12
|
-
})
|
|
13
|
-
return mobile
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export default useMobile
|
package/src/hooks/useState.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { Ref } from 'vue'
|
|
2
|
-
import { ref } from 'vue'
|
|
3
|
-
|
|
4
|
-
export default function useState<T, R = Ref<T>>(
|
|
5
|
-
defaultStateValue?: T | (() => T),
|
|
6
|
-
): [R, (val: T) => void] {
|
|
7
|
-
const initValue: T
|
|
8
|
-
= typeof defaultStateValue === 'function' ? (defaultStateValue as any)() : defaultStateValue
|
|
9
|
-
|
|
10
|
-
const innerValue = ref(initValue) as Ref<T>
|
|
11
|
-
|
|
12
|
-
function triggerChange(newValue: T) {
|
|
13
|
-
innerValue.value = newValue
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
return [innerValue as unknown as R, triggerChange]
|
|
17
|
-
}
|
package/src/index.ts
DELETED
package/src/isEqual.ts
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import warning from './warning'
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Deeply compares two object literals.
|
|
5
|
-
* @param obj1 object 1
|
|
6
|
-
* @param obj2 object 2
|
|
7
|
-
* @param shallow shallow compare
|
|
8
|
-
*/
|
|
9
|
-
function isEqual(obj1: any, obj2: any, shallow = false): boolean {
|
|
10
|
-
// https://github.com/mapbox/mapbox-gl-js/pull/5979/files#diff-fde7145050c47cc3a306856efd5f9c3016e86e859de9afbd02c879be5067e58f
|
|
11
|
-
const refSet = new Set<any>()
|
|
12
|
-
function deepEqual(a: any, b: any, level = 1): boolean {
|
|
13
|
-
const circular = refSet.has(a)
|
|
14
|
-
warning(!circular, 'Warning: There may be circular references')
|
|
15
|
-
if (circular)
|
|
16
|
-
return false
|
|
17
|
-
|
|
18
|
-
if (a === b)
|
|
19
|
-
return true
|
|
20
|
-
|
|
21
|
-
if (shallow && level > 1)
|
|
22
|
-
return false
|
|
23
|
-
|
|
24
|
-
refSet.add(a)
|
|
25
|
-
const newLevel = level + 1
|
|
26
|
-
if (Array.isArray(a)) {
|
|
27
|
-
if (!Array.isArray(b) || a.length !== b.length)
|
|
28
|
-
return false
|
|
29
|
-
|
|
30
|
-
for (let i = 0; i < a.length; i++) {
|
|
31
|
-
if (!deepEqual(a[i], b[i], newLevel))
|
|
32
|
-
return false
|
|
33
|
-
}
|
|
34
|
-
return true
|
|
35
|
-
}
|
|
36
|
-
if (a && b && typeof a === 'object' && typeof b === 'object') {
|
|
37
|
-
const keys = Object.keys(a)
|
|
38
|
-
if (keys.length !== Object.keys(b).length)
|
|
39
|
-
return false
|
|
40
|
-
|
|
41
|
-
return keys.every(key => deepEqual(a[key], b[key], newLevel))
|
|
42
|
-
}
|
|
43
|
-
// other
|
|
44
|
-
return false
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
return deepEqual(obj1, obj2)
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export default isEqual
|
package/src/isMobile.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
export default () => {
|
|
2
|
-
if (typeof navigator === 'undefined' || typeof window === 'undefined')
|
|
3
|
-
return false
|
|
4
|
-
|
|
5
|
-
const agent
|
|
6
|
-
= navigator.userAgent || navigator.vendor || (window as any).opera
|
|
7
|
-
return (
|
|
8
|
-
/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino|android|ipad|playbook|silk/i.test(
|
|
9
|
-
agent,
|
|
10
|
-
)
|
|
11
|
-
|| /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw-(n|u)|c55\/|capi|ccwa|cdm-|cell|chtm|cldc|cmd-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc-s|devi|dica|dmob|do(c|p)o|ds(12|-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(-|_)|g1 u|g560|gene|gf-5|g-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd-([mpt])|hei-|hi(pt|ta)|hp( i|ip)|hs-c|ht(c([\- _agpst])|tp)|hu(aw|tc)|i-(20|go|ma)|i230|iac([ \-/])|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc-|kyo(c|k)|le(no|xi)|lg( g|\/([klu])|50|54|-[a-w])|libw|lynx|m1-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t([\- ov])|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[23]|n30(0|2)|n50([025])|n7(0(0|1)|10)|ne((c|m)-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan([adt])|pdxg|pg(13|-([1-8c]))|phil|pire|pl(ay|uc)|pn-2|po(ck|rt|se)|prox|psio|pt-g|qa-a|qc(07|12|21|32|60|-[2-7]|i-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h-|oo|p-)|sdk\/|se(c([\-01])|47|mc|nd|ri)|sgh-|shar|sie(-|m)|sk-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h-|v-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl-|tdg-|tel(i|m)|tim-|t-mo|to(pl|sh)|ts(70|m-|m3|m5)|tx-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas-|your|zeto|zte-/i.test(
|
|
12
|
-
agent?.substr(0, 4),
|
|
13
|
-
)
|
|
14
|
-
)
|
|
15
|
-
}
|
package/src/isValid.ts
DELETED