@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.
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
package/dist/vnode.js CHANGED
@@ -1,41 +1,40 @@
1
- import { cloneVNode as f, isVNode as p, render as c, Comment as l, Fragment as a } from "vue";
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 m(r, e = {}, n = !0, u = !1) {
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 = f(t, e, u);
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) => m(u, e, n));
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 (!p(r))
18
+ if (!s(r))
19
19
  return r;
20
- const t = m(r, e, n, u);
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
- c(f(r, { ...e }), n);
25
+ a(l(r, { ...e }), n);
26
26
  }
27
- function s(r) {
28
- return (r || []).some((e) => p(e) ? !(e.type === l || e.type === a && !s(e.children)) : !0) ? r : null;
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 C(r, e, n, u) {
31
- var i;
32
- const t = (i = r[e]) == null ? void 0 : i.call(r, n);
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
- m as cloneElement,
35
+ f as cloneElement,
37
36
  g as cloneVNodes,
38
- C as customRenderSlot,
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;
@@ -0,0 +1,8 @@
1
+ import { toValue as t } from "vue";
2
+ function r(n) {
3
+ const e = t(n);
4
+ return e?.$el ?? e;
5
+ }
6
+ export {
7
+ r as unrefElement
8
+ };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@v-c/util",
3
3
  "type": "module",
4
- "version": "0.0.2",
4
+ "version": "0.0.4",
5
5
  "description": "Vue3 components utils",
6
6
  "publishConfig": {
7
7
  "access": "public"
@@ -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 { describe, expect, it } from 'vitest'
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 { toArray } from '@v-c/util/Children/toArray.ts'
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(): void
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(): void
7
+ remove: () => void
8
8
  }
9
9
 
10
10
  export function addEventListener(...args: any[]) {
package/src/Dom/focus.ts CHANGED
@@ -73,7 +73,7 @@ export function backLastFocusNode() {
73
73
  // 元素可能已经被移动了
74
74
  lastFocusElement.focus()
75
75
  }
76
- // eslint-disable-next-line unused-imports/no-unused-vars
76
+
77
77
  catch (_e: any) {
78
78
  // empty
79
79
  }
@@ -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
- `${scrollingEffectClassName}`,
20
- 'g',
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
- && window.innerWidth - document.documentElement.clientWidth > 0)
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 { Teleport, defineComponent, onBeforeUnmount, onMounted, onUnmounted, shallowRef } from 'vue'
1
+ import { defineComponent, onBeforeUnmount, onMounted, onUnmounted, shallowRef, Teleport } from 'vue'
2
2
  import canUseDom from './Dom/canUseDom'
3
3
 
4
4
  export interface PortalProps {
@@ -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
@@ -1,6 +1,5 @@
1
1
  import type { Ref } from 'vue'
2
2
 
3
- // eslint-disable-next-line ts/no-unsafe-function-type
4
3
  export interface RefObject extends Function {
5
4
  current?: any
6
5
  }
@@ -0,0 +1,3 @@
1
+ export default function useEvent<T extends Function>(callback: T): T {
2
+ return callback
3
+ }
@@ -1,31 +1,20 @@
1
- import { ref } from 'vue'
2
- import canUseDom from '../Dom/canUseDom'
1
+ import { useId } from 'vue'
3
2
 
4
- let uuid = 0
5
-
6
- /** Is client side and not jsdom */
7
- export const isBrowserClient = process.env.NODE_ENV !== 'test' && canUseDom()
3
+ function getUseId() {
4
+ return useId
5
+ }
8
6
 
9
- /** Get unique id for accessibility usage */
10
- export function getUUID(): number | string {
11
- let retId: string | number
7
+ const useOriginalId = getUseId()
12
8
 
13
- // Test never reach
14
- /* istanbul ignore if */
15
- if (isBrowserClient) {
16
- retId = uuid
17
- uuid += 1
9
+ export default function (id?: string) {
10
+ const vueId = useOriginalId()
11
+ if (id) {
12
+ return id
18
13
  }
19
- else {
20
- retId = 'TEST_OR_SSR'
14
+ // Test env always return mock id
15
+ if (process.env.NODE_ENV === 'test') {
16
+ return 'test-id'
21
17
  }
22
18
 
23
- return retId
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-(m|p|t)|hei-|hi(pt|ta)|hp( i|ip)|hs-c|ht(c(-| |_|a|g|p|s|t)|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|\/(k|l|u)|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(-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|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(a|d|t)|pdxg|pg(13|-([1-8]|c))|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(-|0|1)|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(
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
@@ -0,0 +1,4 @@
1
+ function isValid(value: any): boolean {
2
+ return value !== undefined && value !== null && value !== ''
3
+ }
4
+ export default isValid
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(/[\s\n]+/)
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
  }
@@ -1,22 +1,57 @@
1
- import { Fragment } from 'vue'
2
-
3
- export function isEmptyElement(c: any) {
4
- return (
5
- c
6
- && (c.type === Comment
7
- || (c.type === Fragment && c.children.length === 0)
8
- || (c.type === Text && c.children.trim() === ''))
9
- )
10
- }
11
- export function filterEmpty(children: any[] = []) {
12
- const res: any[] = []
13
- children.forEach((child: any) => {
14
- if (Array.isArray(child))
15
- res.push(...child)
16
- else if (child?.type === Fragment)
17
- res.push(...filterEmpty(child.children))
18
- else
19
- res.push(child)
20
- })
21
- return res.filter(c => !isEmptyElement(c))
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
@@ -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
- // eslint-disable-next-line ts/no-unsafe-function-type
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 | boolean | null | undefined | void
32
+ declare type VNodeChildAtom = Component | VNode | string | number | null | undefined | void
33
33
 
34
34
  export type VueNode = VNodeChildAtom | VNodeChildAtom[] | VNode
35
35
 
@@ -0,0 +1,9 @@
1
+ export function omit<T, K extends keyof T>(obj: T, keys: K[]): Omit<T, K> {
2
+ const result = { ...obj }
3
+
4
+ keys.forEach((key) => {
5
+ delete result[key]
6
+ })
7
+
8
+ return result
9
+ }
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