@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
package/dist/vnode.js
CHANGED
|
@@ -1,41 +1,40 @@
|
|
|
1
|
-
import { cloneVNode as
|
|
1
|
+
import { cloneVNode as l, isVNode as s, render as a, Comment as p, Fragment as m } from "vue";
|
|
2
2
|
import { filterEmpty as y } from "./props-util/index.js";
|
|
3
3
|
import { warningOnce as A } from "./warning.js";
|
|
4
|
-
function
|
|
4
|
+
function f(r, e = {}, n = !0, u = !1) {
|
|
5
5
|
let t = r;
|
|
6
6
|
if (Array.isArray(r) && (t = y(r)[0]), !t)
|
|
7
7
|
return null;
|
|
8
|
-
const i =
|
|
8
|
+
const i = l(t, e, u);
|
|
9
9
|
return i.props = n ? { ...i.props, ...e } : i.props, A(typeof i.props.class != "object", "class must be string"), i;
|
|
10
10
|
}
|
|
11
11
|
function g(r, e = {}, n = !0) {
|
|
12
|
-
return r.map((u) =>
|
|
12
|
+
return r.map((u) => f(u, e, n));
|
|
13
13
|
}
|
|
14
14
|
function o(r, e = {}, n = !0, u = !1) {
|
|
15
15
|
if (Array.isArray(r))
|
|
16
16
|
return r.map((t) => o(t, e, n, u));
|
|
17
17
|
{
|
|
18
|
-
if (!
|
|
18
|
+
if (!s(r))
|
|
19
19
|
return r;
|
|
20
|
-
const t =
|
|
20
|
+
const t = f(r, e, n, u);
|
|
21
21
|
return Array.isArray(t.children) && (t.children = o(t.children)), t;
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
24
|
function E(r, e, n) {
|
|
25
|
-
|
|
25
|
+
a(l(r, { ...e }), n);
|
|
26
26
|
}
|
|
27
|
-
function
|
|
28
|
-
return (r || []).some((e) =>
|
|
27
|
+
function c(r) {
|
|
28
|
+
return (r || []).some((e) => s(e) ? !(e.type === p || e.type === m && !c(e.children)) : !0) ? r : null;
|
|
29
29
|
}
|
|
30
|
-
function
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
return s(t) ? t : u == null ? void 0 : u();
|
|
30
|
+
function b(r, e, n, u) {
|
|
31
|
+
const t = r[e]?.(n);
|
|
32
|
+
return c(t) ? t : u?.();
|
|
34
33
|
}
|
|
35
34
|
export {
|
|
36
|
-
|
|
35
|
+
f as cloneElement,
|
|
37
36
|
g as cloneVNodes,
|
|
38
|
-
|
|
37
|
+
b as customRenderSlot,
|
|
39
38
|
o as deepCloneElement,
|
|
40
39
|
E as triggerVNodeUpdate
|
|
41
40
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("vue");function r(t){const e=n.toValue(t);return e?.$el??e}exports.unrefElement=r;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ComponentPublicInstance, MaybeRef } from 'vue';
|
|
2
|
+
export type VueInstance = ComponentPublicInstance;
|
|
3
|
+
/**
|
|
4
|
+
* Get the dom element of a ref of element or Vue component instance
|
|
5
|
+
*
|
|
6
|
+
* @param elRef
|
|
7
|
+
*/
|
|
8
|
+
export declare function unrefElement<T extends Element>(elRef: MaybeRef<T>): T;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { isFragment } from '@v-c/util/dist/Children/isFragment.ts'
|
|
1
2
|
import { describe, expect, it } from 'vitest'
|
|
2
3
|
import { createVNode } from 'vue'
|
|
3
|
-
import { isFragment } from '@v-c/util/Children/isFragment.ts'
|
|
4
4
|
|
|
5
5
|
describe('isFragment', () => {
|
|
6
6
|
it('should ', () => {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Fragment, defineComponent } from 'vue'
|
|
1
|
+
import { toArray } from '@v-c/util/dist/Children/toArray.ts'
|
|
3
2
|
import { mount } from '@vue/test-utils'
|
|
4
|
-
import {
|
|
3
|
+
import { describe, expect, it } from 'vitest'
|
|
4
|
+
import { defineComponent, Fragment } from 'vue'
|
|
5
5
|
|
|
6
6
|
describe('toArray', () => {
|
|
7
7
|
let children: any
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
export type WindowEventName = keyof WindowEventMap
|
|
2
2
|
export type DocumentEventName = keyof DocumentEventMap
|
|
3
3
|
export function addEventListener<E extends WindowEventName = WindowEventName>(target: Window, eventType: E, cb: WindowEventMap[E], option?: AddEventListenerOptions): {
|
|
4
|
-
remove()
|
|
4
|
+
remove: () => void
|
|
5
5
|
}
|
|
6
6
|
export function addEventListener<E extends DocumentEventName = DocumentEventName>(target: Document, eventType: E, cb: DocumentEventMap[E], option?: AddEventListenerOptions): {
|
|
7
|
-
remove()
|
|
7
|
+
remove: () => void
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
export function addEventListener(...args: any[]) {
|
package/src/Dom/focus.ts
CHANGED
package/src/Dom/scrollLocker.ts
CHANGED
|
@@ -16,8 +16,8 @@ interface Ilocks {
|
|
|
16
16
|
let locks: Ilocks[] = []
|
|
17
17
|
const scrollingEffectClassName = 'ant-scrolling-effect'
|
|
18
18
|
const scrollingEffectClassNameReg = new RegExp(
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
`${scrollingEffectClassName}`,
|
|
20
|
+
'g',
|
|
21
21
|
)
|
|
22
22
|
|
|
23
23
|
// https://github.com/ant-design/ant-design/issues/19340
|
|
@@ -74,7 +74,7 @@ export default class ScrollLocker {
|
|
|
74
74
|
|
|
75
75
|
if (
|
|
76
76
|
(container === document.body
|
|
77
|
-
|
|
77
|
+
&& window.innerWidth - document.documentElement.clientWidth > 0)
|
|
78
78
|
|| container.scrollHeight > container.clientHeight
|
|
79
79
|
) {
|
|
80
80
|
if (getComputedStyle(container).overflow !== 'hidden')
|
|
@@ -124,8 +124,9 @@ export default class ScrollLocker {
|
|
|
124
124
|
|| locks.some(
|
|
125
125
|
({ options }) => options?.container === findLock.options?.container,
|
|
126
126
|
)
|
|
127
|
-
)
|
|
127
|
+
) {
|
|
128
128
|
return
|
|
129
|
+
}
|
|
129
130
|
|
|
130
131
|
// Remove Effect
|
|
131
132
|
const container = this.options?.container || document.body
|
package/src/KeyCode.ts
CHANGED
|
@@ -436,8 +436,9 @@ const KeyCode = {
|
|
|
436
436
|
|| e.metaKey
|
|
437
437
|
// Function keys don't generate text
|
|
438
438
|
|| (keyCode >= KeyCode.F1 && keyCode <= KeyCode.F12)
|
|
439
|
-
)
|
|
439
|
+
) {
|
|
440
440
|
return false
|
|
441
|
+
}
|
|
441
442
|
|
|
442
443
|
// The following keys are quite harmless, even in combination with
|
|
443
444
|
// CTRL, ALT or SHIFT.
|
package/src/Portal.tsx
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { defineComponent, onBeforeUnmount, onMounted, onUnmounted, shallowRef, Teleport } from 'vue'
|
|
2
2
|
import canUseDom from './Dom/canUseDom'
|
|
3
3
|
|
|
4
4
|
export interface PortalProps {
|
package/src/PortalWrapper.tsx
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type { SlotsType } from 'vue'
|
|
2
|
+
import type { PortalRef } from './Portal'
|
|
2
3
|
import { defineComponent, onBeforeUnmount, onMounted, onUpdated, shallowRef } from 'vue'
|
|
3
|
-
import raf from './raf'
|
|
4
4
|
import canUseDom from './Dom/canUseDom'
|
|
5
5
|
import ScrollLocker from './Dom/scrollLocker'
|
|
6
|
-
import setStyle from './setStyle'
|
|
7
|
-
import type { PortalRef } from './Portal'
|
|
8
6
|
import Portal from './Portal'
|
|
7
|
+
import raf from './raf'
|
|
8
|
+
import setStyle from './setStyle'
|
|
9
9
|
|
|
10
10
|
// import raf from './raf';
|
|
11
11
|
|
|
@@ -37,8 +37,9 @@ function getParent(getContainer: GetContainer) {
|
|
|
37
37
|
if (
|
|
38
38
|
typeof getContainer === 'object'
|
|
39
39
|
&& getContainer instanceof window.HTMLElement
|
|
40
|
-
)
|
|
40
|
+
) {
|
|
41
41
|
return getContainer
|
|
42
|
+
}
|
|
42
43
|
}
|
|
43
44
|
return document.body
|
|
44
45
|
}
|
|
@@ -98,8 +99,9 @@ const PortalWrapper = defineComponent<PortalWrapperProps, any, string, DefaultSl
|
|
|
98
99
|
getContainerIsFunc
|
|
99
100
|
? getContainer.toString() !== prevGetContainer.toString()
|
|
100
101
|
: getContainer !== prevGetContainer
|
|
101
|
-
)
|
|
102
|
+
) {
|
|
102
103
|
removeCurrentContainer()
|
|
104
|
+
}
|
|
103
105
|
}
|
|
104
106
|
|
|
105
107
|
const attachToParent = (force = false) => {
|
|
@@ -121,8 +123,9 @@ const PortalWrapper = defineComponent<PortalWrapperProps, any, string, DefaultSl
|
|
|
121
123
|
container.value
|
|
122
124
|
&& wrapperClassName
|
|
123
125
|
&& wrapperClassName !== container.value.className
|
|
124
|
-
)
|
|
126
|
+
) {
|
|
125
127
|
container.value.className = wrapperClassName
|
|
128
|
+
}
|
|
126
129
|
}
|
|
127
130
|
|
|
128
131
|
const getContainer = () => {
|
package/src/createRef.ts
CHANGED
package/src/hooks/useId.ts
CHANGED
|
@@ -1,31 +1,20 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import canUseDom from '../Dom/canUseDom'
|
|
1
|
+
import { useId } from 'vue'
|
|
3
2
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
export const isBrowserClient = process.env.NODE_ENV !== 'test' && canUseDom()
|
|
3
|
+
function getUseId() {
|
|
4
|
+
return useId
|
|
5
|
+
}
|
|
8
6
|
|
|
9
|
-
|
|
10
|
-
export function getUUID(): number | string {
|
|
11
|
-
let retId: string | number
|
|
7
|
+
const useOriginalId = getUseId()
|
|
12
8
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
if (
|
|
16
|
-
|
|
17
|
-
uuid += 1
|
|
9
|
+
export default function (id?: string) {
|
|
10
|
+
const vueId = useOriginalId()
|
|
11
|
+
if (id) {
|
|
12
|
+
return id
|
|
18
13
|
}
|
|
19
|
-
|
|
20
|
-
|
|
14
|
+
// Test env always return mock id
|
|
15
|
+
if (process.env.NODE_ENV === 'test') {
|
|
16
|
+
return 'test-id'
|
|
21
17
|
}
|
|
22
18
|
|
|
23
|
-
return
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export default function useId(id = ref('')) {
|
|
27
|
-
// Inner id for accessibility usage. Only work in client side
|
|
28
|
-
const innerId = `vc_unique_${getUUID()}`
|
|
29
|
-
|
|
30
|
-
return id.value || innerId
|
|
19
|
+
return vueId
|
|
31
20
|
}
|
|
@@ -0,0 +1,61 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
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/isMobile.ts
CHANGED
|
@@ -8,7 +8,7 @@ export default () => {
|
|
|
8
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
9
|
agent,
|
|
10
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-(
|
|
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
12
|
agent?.substr(0, 4),
|
|
13
13
|
)
|
|
14
14
|
)
|
package/src/isValid.ts
ADDED
package/src/pickAttrs.ts
CHANGED
|
@@ -19,7 +19,7 @@ const eventsName = `onCopy onCut onPaste onCompositionEnd onCompositionStart onC
|
|
|
19
19
|
onDurationChange onEmptied onEncrypted onEnded onError onLoadedData onLoadedMetadata
|
|
20
20
|
onLoadStart onPause onPlay onPlaying onProgress onRateChange onSeeked onSeeking onStalled onSuspend onTimeUpdate onVolumeChange onWaiting onLoad onError`
|
|
21
21
|
|
|
22
|
-
const propList = `${attributes} ${eventsName}`.split(
|
|
22
|
+
const propList = `${attributes} ${eventsName}`.split(/\s+/)
|
|
23
23
|
|
|
24
24
|
const ariaPrefix = 'aria-'
|
|
25
25
|
const dataPrefix = 'data-'
|
|
@@ -71,8 +71,9 @@ export default function pickAttrs(
|
|
|
71
71
|
|| (mergedConfig.data && match(key, dataPrefix))
|
|
72
72
|
// Attr
|
|
73
73
|
|| (mergedConfig.attr && propList.includes(key))
|
|
74
|
-
)
|
|
74
|
+
) {
|
|
75
75
|
attrs[key] = (props as any)[key]
|
|
76
|
+
}
|
|
76
77
|
})
|
|
77
78
|
return attrs
|
|
78
79
|
}
|
package/src/props-util/index.ts
CHANGED
|
@@ -1,22 +1,57 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
1
|
+
import type { VNode, VNodeNormalizedChildren } from 'vue'
|
|
2
|
+
import { Comment, Fragment, isVNode, Text } from 'vue'
|
|
3
|
+
import isValid from '../isValid'
|
|
4
|
+
import initDefaultProps from './initDefaultProps'
|
|
5
|
+
|
|
6
|
+
export function isEmptyElement(c: any) {
|
|
7
|
+
return (
|
|
8
|
+
c
|
|
9
|
+
&& (c.type === Comment
|
|
10
|
+
|| (c.type === Fragment && c.children.length === 0)
|
|
11
|
+
|| (c.type === Text && c.children.trim() === ''))
|
|
12
|
+
)
|
|
13
|
+
}
|
|
14
|
+
export function filterEmpty(children: any[] = []) {
|
|
15
|
+
const res: any[] = []
|
|
16
|
+
children.forEach((child: any) => {
|
|
17
|
+
if (Array.isArray(child))
|
|
18
|
+
res.push(...child)
|
|
19
|
+
else if (child?.type === Fragment)
|
|
20
|
+
res.push(...filterEmpty(child.children))
|
|
21
|
+
else res.push(child)
|
|
22
|
+
})
|
|
23
|
+
return res.filter(c => !isEmptyElement(c))
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export const skipFlattenKey = Symbol('skipFlatten')
|
|
27
|
+
function flattenChildren(children?: VNode | VNodeNormalizedChildren, filterEmpty = true) {
|
|
28
|
+
const temp = Array.isArray(children) ? children : [children]
|
|
29
|
+
const res = []
|
|
30
|
+
temp.forEach((child) => {
|
|
31
|
+
if (Array.isArray(child)) {
|
|
32
|
+
res.push(...flattenChildren(child, filterEmpty))
|
|
33
|
+
}
|
|
34
|
+
else if (isValid(child)) {
|
|
35
|
+
res.push(child)
|
|
36
|
+
}
|
|
37
|
+
else if (child && typeof child === 'object' && child.type === Fragment) {
|
|
38
|
+
if (child.key === skipFlattenKey) {
|
|
39
|
+
res.push(child)
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
res.push(...flattenChildren(child.children, filterEmpty))
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
else if (child && isVNode(child)) {
|
|
46
|
+
if (filterEmpty && !isEmptyElement(child)) {
|
|
47
|
+
res.push(child)
|
|
48
|
+
}
|
|
49
|
+
else if (!filterEmpty) {
|
|
50
|
+
res.push(child)
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
})
|
|
54
|
+
return res
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export { flattenChildren, initDefaultProps }
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { PropType } from 'vue'
|
|
2
|
+
import type { VueTypeDef, VueTypeValidableDef } from 'vue-types'
|
|
3
|
+
|
|
4
|
+
function initDefaultProps<T>(types: T, defaultProps: {
|
|
5
|
+
[K in keyof T]?: T[K] extends VueTypeValidableDef<infer U>
|
|
6
|
+
? U
|
|
7
|
+
: T[K] extends VueTypeDef<infer U>
|
|
8
|
+
? U
|
|
9
|
+
: T[K] extends { type: PropType<infer U> }
|
|
10
|
+
? U
|
|
11
|
+
: any;
|
|
12
|
+
}): T {
|
|
13
|
+
const propTypes: T = { ...types }
|
|
14
|
+
Object.keys(defaultProps).forEach((k) => {
|
|
15
|
+
const prop = propTypes[k] as VueTypeValidableDef
|
|
16
|
+
if (prop) {
|
|
17
|
+
if (prop.type || prop.default) {
|
|
18
|
+
prop.default = defaultProps[k]
|
|
19
|
+
}
|
|
20
|
+
else if (prop.def) {
|
|
21
|
+
prop.def(defaultProps[k])
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
propTypes[k] = { type: prop, default: defaultProps[k] }
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
throw new Error(`not have ${k} prop`)
|
|
29
|
+
}
|
|
30
|
+
})
|
|
31
|
+
return propTypes
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export default initDefaultProps
|
package/src/test/domHook.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
const NO_EXIST = { __NOT_EXIST: true }
|
|
2
2
|
|
|
3
|
-
// eslint-disable-next-line ts/no-unsafe-function-type
|
|
4
3
|
export type ElementClass = Function
|
|
5
|
-
|
|
4
|
+
|
|
6
5
|
export type Property = PropertyDescriptor | Function
|
|
7
6
|
|
|
8
7
|
export function spyElementPrototypes<T extends ElementClass>(
|
package/src/type.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { App, Plugin, PropType, Ref, SlotsType, VNode } from 'vue'
|
|
1
|
+
import type { App, Component, Plugin, PropType, Ref, SlotsType, VNode } from 'vue'
|
|
2
2
|
|
|
3
3
|
// https://stackoverflow.com/questions/46176165/ways-to-get-string-literal-type-of-array-values-without-enum-overhead
|
|
4
4
|
export const tuple = <T extends string[]>(...args: T) => args
|
|
@@ -29,7 +29,7 @@ export interface PropOptions<T = any, D = T> {
|
|
|
29
29
|
validator?: (value: unknown) => boolean
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
declare type VNodeChildAtom = VNode | string | number |
|
|
32
|
+
declare type VNodeChildAtom = Component | VNode | string | number | null | undefined | void
|
|
33
33
|
|
|
34
34
|
export type VueNode = VNodeChildAtom | VNodeChildAtom[] | VNode
|
|
35
35
|
|
package/src/utils/set.ts
CHANGED
|
@@ -49,7 +49,7 @@ export default function set<Entity = any, Output = Entity, Value = any>(
|
|
|
49
49
|
return internalSet(entity, paths, value, removeIfUndefined)
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
function isObject(obj: any) {
|
|
52
|
+
export function isObject(obj: any) {
|
|
53
53
|
return (
|
|
54
54
|
typeof obj === 'object'
|
|
55
55
|
&& obj !== null
|