@v-c/util 0.0.1
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/LICENSE +21 -0
- package/dist/Children/isFragment.cjs +1 -0
- package/dist/Children/isFragment.d.ts +3 -0
- package/dist/Children/isFragment.js +7 -0
- package/dist/Children/toArray.cjs +1 -0
- package/dist/Children/toArray.d.ts +8 -0
- package/dist/Children/toArray.js +11 -0
- package/dist/Dom/addEventListener.cjs +1 -0
- package/dist/Dom/addEventListener.d.ts +8 -0
- package/dist/Dom/addEventListener.js +12 -0
- package/dist/Dom/canUseDom.cjs +1 -0
- package/dist/Dom/canUseDom.d.ts +1 -0
- package/dist/Dom/canUseDom.js +6 -0
- package/dist/Dom/class.cjs +1 -0
- package/dist/Dom/class.d.ts +3 -0
- package/dist/Dom/class.js +19 -0
- package/dist/Dom/contains.cjs +1 -0
- package/dist/Dom/contains.d.ts +1 -0
- package/dist/Dom/contains.js +16 -0
- package/dist/Dom/css.cjs +1 -0
- package/dist/Dom/css.d.ts +20 -0
- package/dist/Dom/css.js +75 -0
- package/dist/Dom/dynamicCSS.cjs +1 -0
- package/dist/Dom/dynamicCSS.d.ts +24 -0
- package/dist/Dom/dynamicCSS.js +78 -0
- package/dist/Dom/findDOMNode.cjs +1 -0
- package/dist/Dom/findDOMNode.d.ts +7 -0
- package/dist/Dom/findDOMNode.js +12 -0
- package/dist/Dom/focus.cjs +1 -0
- package/dist/Dom/focus.d.ts +8 -0
- package/dist/Dom/focus.js +40 -0
- package/dist/Dom/isVisible.cjs +1 -0
- package/dist/Dom/isVisible.d.ts +2 -0
- package/dist/Dom/isVisible.js +22 -0
- package/dist/Dom/scrollLocker.cjs +1 -0
- package/dist/Dom/scrollLocker.d.ts +12 -0
- package/dist/Dom/scrollLocker.js +81 -0
- package/dist/Dom/shadow.cjs +1 -0
- package/dist/Dom/shadow.d.ts +8 -0
- package/dist/Dom/shadow.js +14 -0
- package/dist/Dom/styleChecker.cjs +1 -0
- package/dist/Dom/styleChecker.d.ts +2 -0
- package/dist/Dom/styleChecker.js +20 -0
- package/dist/Dom/support.cjs +1 -0
- package/dist/Dom/support.d.ts +6 -0
- package/dist/Dom/support.js +24 -0
- package/dist/EventInterface.cjs +1 -0
- package/dist/EventInterface.d.ts +18 -0
- package/dist/EventInterface.js +1 -0
- package/dist/KeyCode.cjs +1 -0
- package/dist/KeyCode.d.ts +435 -0
- package/dist/KeyCode.js +516 -0
- package/dist/Portal.cjs +1 -0
- package/dist/Portal.d.ts +8 -0
- package/dist/Portal.js +38 -0
- package/dist/PortalWrapper.cjs +1 -0
- package/dist/PortalWrapper.d.ts +28 -0
- package/dist/PortalWrapper.js +114 -0
- package/dist/composeProps.cjs +1 -0
- package/dist/composeProps.d.ts +2 -0
- package/dist/composeProps.js +16 -0
- package/dist/createRef.cjs +1 -0
- package/dist/createRef.d.ts +12 -0
- package/dist/createRef.js +21 -0
- package/dist/debug/diff.cjs +1 -0
- package/dist/debug/diff.d.ts +1 -0
- package/dist/debug/diff.js +41 -0
- package/dist/deprecated.cjs +1 -0
- package/dist/deprecated.d.ts +1 -0
- package/dist/deprecated.js +8 -0
- package/dist/getScrollBarSize.cjs +1 -0
- package/dist/getScrollBarSize.d.ts +5 -0
- package/dist/getScrollBarSize.js +37 -0
- package/dist/guid.cjs +1 -0
- package/dist/guid.d.ts +1 -0
- package/dist/guid.js +7 -0
- package/dist/hooks/useId.cjs +1 -0
- package/dist/hooks/useId.d.ts +5 -0
- package/dist/hooks/useId.js +17 -0
- package/dist/hooks/useMemo.cjs +1 -0
- package/dist/hooks/useMemo.d.ts +3 -0
- package/dist/hooks/useMemo.js +10 -0
- package/dist/hooks/useMergedState.cjs +1 -0
- package/dist/hooks/useMergedState.d.ts +8 -0
- package/dist/hooks/useMergedState.js +21 -0
- package/dist/hooks/useState.cjs +1 -0
- package/dist/hooks/useState.d.ts +3 -0
- package/dist/hooks/useState.js +11 -0
- package/dist/index.cjs +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +8 -0
- package/dist/isEqual.cjs +1 -0
- package/dist/isEqual.d.ts +8 -0
- package/dist/isEqual.js +32 -0
- package/dist/isMobile.cjs +1 -0
- package/dist/isMobile.d.ts +2 -0
- package/dist/isMobile.js +13 -0
- package/dist/omit.cjs +1 -0
- package/dist/omit.d.ts +1 -0
- package/dist/omit.js +9 -0
- package/dist/pickAttrs.cjs +18 -0
- package/dist/pickAttrs.d.ts +11 -0
- package/dist/pickAttrs.js +41 -0
- package/dist/props-util/index.cjs +1 -0
- package/dist/props-util/index.d.ts +2 -0
- package/dist/props-util/index.js +14 -0
- package/dist/raf.cjs +1 -0
- package/dist/raf.d.ts +6 -0
- package/dist/raf.js +30 -0
- package/dist/setStyle.cjs +1 -0
- package/dist/setStyle.d.ts +13 -0
- package/dist/setStyle.js +13 -0
- package/dist/switchScrollingEffect.cjs +1 -0
- package/dist/switchScrollingEffect.d.ts +2 -0
- package/dist/switchScrollingEffect.js +31 -0
- package/dist/test/domHook.cjs +1 -0
- package/dist/test/domHook.d.ts +8 -0
- package/dist/test/domHook.js +37 -0
- package/dist/type.cjs +1 -0
- package/dist/type.d.ts +63 -0
- package/dist/type.js +49 -0
- package/dist/utils/checkSlotProp.cjs +1 -0
- package/dist/utils/checkSlotProp.d.ts +1 -0
- package/dist/utils/checkSlotProp.js +7 -0
- package/dist/utils/get.cjs +1 -0
- package/dist/utils/get.d.ts +1 -0
- package/dist/utils/get.js +12 -0
- package/dist/utils/set.cjs +1 -0
- package/dist/utils/set.d.ts +6 -0
- package/dist/utils/set.js +41 -0
- package/dist/vnode.cjs +1 -0
- package/dist/vnode.d.ts +12 -0
- package/dist/vnode.js +41 -0
- package/dist/warning.cjs +1 -0
- package/dist/warning.d.ts +18 -0
- package/dist/warning.js +48 -0
- package/package.json +37 -0
- package/src/Children/isFragment.ts +6 -0
- package/src/Children/tests/isFragment.test.tsx +15 -0
- package/src/Children/tests/toArray.test.tsx +101 -0
- package/src/Children/toArray.ts +27 -0
- package/src/Dom/addEventListener.ts +20 -0
- package/src/Dom/canUseDom.ts +7 -0
- package/src/Dom/class.ts +29 -0
- package/src/Dom/contains.ts +19 -0
- package/src/Dom/css.ts +113 -0
- package/src/Dom/dynamicCSS.ts +173 -0
- package/src/Dom/findDOMNode.ts +23 -0
- package/src/Dom/focus.ts +96 -0
- package/src/Dom/isVisible.ts +23 -0
- package/src/Dom/scrollLocker.ts +143 -0
- package/src/Dom/shadow.ts +17 -0
- package/src/Dom/styleChecker.ts +31 -0
- package/src/Dom/support.ts +27 -0
- package/src/EventInterface.ts +19 -0
- package/src/KeyCode.ts +516 -0
- package/src/Portal.tsx +50 -0
- package/src/PortalWrapper.tsx +214 -0
- package/src/composeProps.ts +23 -0
- package/src/createRef.ts +33 -0
- package/src/debug/diff.ts +66 -0
- package/src/deprecated.ts +8 -0
- package/src/getScrollBarSize.tsx +57 -0
- package/src/guid.ts +4 -0
- package/src/hooks/useId.ts +31 -0
- package/src/hooks/useMemo.ts +21 -0
- package/src/hooks/useMergedState.ts +44 -0
- package/src/hooks/useState.ts +17 -0
- package/src/index.ts +3 -0
- package/src/isEqual.ts +50 -0
- package/src/isMobile.ts +15 -0
- package/src/omit.ts +14 -0
- package/src/pickAttrs.ts +78 -0
- package/src/props-util/index.ts +22 -0
- package/src/raf.ts +55 -0
- package/src/setStyle.ts +38 -0
- package/src/switchScrollingEffect.ts +48 -0
- package/src/test/domHook.ts +67 -0
- package/src/type.ts +94 -0
- package/src/utils/checkSlotProp.ts +10 -0
- package/src/utils/get.ts +15 -0
- package/src/utils/set.ts +110 -0
- package/src/vnode.ts +86 -0
- package/src/warning.ts +79 -0
- package/tests/Portal.test.tsx +199 -0
- package/tsconfig.json +7 -0
- package/vite.config.ts +18 -0
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export type ElementClass = Function;
|
|
2
|
+
export type Property = PropertyDescriptor | Function;
|
|
3
|
+
export declare function spyElementPrototypes<T extends ElementClass>(elementClass: T, properties: Record<string, Property>): {
|
|
4
|
+
mockRestore(): void;
|
|
5
|
+
};
|
|
6
|
+
export declare function spyElementPrototype(Element: ElementClass, propName: string, property: Property): {
|
|
7
|
+
mockRestore(): void;
|
|
8
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
const y = { __NOT_EXIST: !0 };
|
|
2
|
+
function p(r, n) {
|
|
3
|
+
const c = Object.keys(n), s = {};
|
|
4
|
+
return c.forEach((o) => {
|
|
5
|
+
const t = Object.getOwnPropertyDescriptor(r.prototype, o);
|
|
6
|
+
s[o] = t || y;
|
|
7
|
+
const e = n[o];
|
|
8
|
+
typeof e == "function" ? r.prototype[o] = function(...f) {
|
|
9
|
+
return e.call(this, t, ...f);
|
|
10
|
+
} : Object.defineProperty(r.prototype, o, {
|
|
11
|
+
...e,
|
|
12
|
+
set(i) {
|
|
13
|
+
return e.set ? e.set.call(this, t, i) : t.set(i);
|
|
14
|
+
},
|
|
15
|
+
get() {
|
|
16
|
+
return e.get ? e.get.call(this, t) : t.get();
|
|
17
|
+
},
|
|
18
|
+
configurable: !0
|
|
19
|
+
});
|
|
20
|
+
}), {
|
|
21
|
+
mockRestore() {
|
|
22
|
+
c.forEach((o) => {
|
|
23
|
+
const t = s[o];
|
|
24
|
+
t === y ? delete r.prototype[o] : typeof t == "function" ? r.prototype[o] = t : Object.defineProperty(r.prototype, o, t);
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
function u(r, n, c) {
|
|
30
|
+
return p(r, {
|
|
31
|
+
[n]: c
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
export {
|
|
35
|
+
u as spyElementPrototype,
|
|
36
|
+
p as spyElementPrototypes
|
|
37
|
+
};
|
package/dist/type.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=(...e)=>e,o=(...e)=>e;function y(e){const t=e;return t.install=function(n){n.component(t.displayName||t.name,e)},e}function p(){return{type:[Function,Array]}}function a(e){return{type:Object,default:e}}function i(e){return{type:Boolean,default:e}}function c(e){return{type:Function,default:e}}function u(e,t){const n={validator:()=>!0,default:e};return n}function l(){return{validator:()=>!0}}function f(e){return{type:Array,default:e}}function T(e){return{type:String,default:e}}function d(e,t){return e?{type:e,default:t}:u(t)}exports.anyType=u;exports.arrayType=f;exports.booleanType=i;exports.eventType=p;exports.functionType=c;exports.objectType=a;exports.someType=d;exports.stringType=T;exports.tuple=r;exports.tupleNum=o;exports.vNodeType=l;exports.withInstall=y;
|
package/dist/type.d.ts
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { Plugin, PropType, Ref, SlotsType, VNode } from 'vue';
|
|
2
|
+
|
|
3
|
+
export declare const tuple: <T extends string[]>(...args: T) => T;
|
|
4
|
+
export declare const tupleNum: <T extends number[]>(...args: T) => T;
|
|
5
|
+
/**
|
|
6
|
+
* https://stackoverflow.com/a/59187769
|
|
7
|
+
* Extract the type of an element of an array/tuple without performing indexing
|
|
8
|
+
*/
|
|
9
|
+
export type ElementOf<T> = T extends (infer E)[] ? E : T extends readonly (infer F)[] ? F : never;
|
|
10
|
+
/**
|
|
11
|
+
* https://github.com/Microsoft/TypeScript/issues/29729
|
|
12
|
+
*/
|
|
13
|
+
export type LiteralUnion<T extends string> = T | (string & {});
|
|
14
|
+
export type Data = Record<string, unknown>;
|
|
15
|
+
export type Key = string | number;
|
|
16
|
+
type DefaultFactory<T> = (props: Data) => T | null | undefined;
|
|
17
|
+
export interface PropOptions<T = any, D = T> {
|
|
18
|
+
type?: PropType<T> | true | null;
|
|
19
|
+
required?: boolean;
|
|
20
|
+
default?: D | DefaultFactory<D> | null | undefined | object;
|
|
21
|
+
validator?: (value: unknown) => boolean;
|
|
22
|
+
}
|
|
23
|
+
declare type VNodeChildAtom = VNode | string | number | boolean | null | undefined | void;
|
|
24
|
+
export type VueNode = VNodeChildAtom | VNodeChildAtom[] | VNode;
|
|
25
|
+
export declare function withInstall<T>(comp: T): T & Plugin;
|
|
26
|
+
export type MaybeRef<T> = T | Ref<T>;
|
|
27
|
+
export declare function eventType<T>(): {
|
|
28
|
+
type: PropType<T | T[]>;
|
|
29
|
+
};
|
|
30
|
+
export declare function objectType<T = object>(defaultVal?: T): {
|
|
31
|
+
type: PropType<T>;
|
|
32
|
+
default: T;
|
|
33
|
+
};
|
|
34
|
+
export declare function booleanType(defaultVal?: boolean): {
|
|
35
|
+
type: BooleanConstructor;
|
|
36
|
+
default: boolean;
|
|
37
|
+
};
|
|
38
|
+
export declare function functionType<T = () => object>(defaultVal?: T): {
|
|
39
|
+
type: PropType<T>;
|
|
40
|
+
default: T;
|
|
41
|
+
};
|
|
42
|
+
export declare function anyType<T = any>(defaultVal?: T, required?: boolean): {
|
|
43
|
+
default: T;
|
|
44
|
+
type: PropType<T>;
|
|
45
|
+
};
|
|
46
|
+
export declare function vNodeType<T = VueNode>(): {
|
|
47
|
+
type: PropType<T>;
|
|
48
|
+
};
|
|
49
|
+
export declare function arrayType<T extends any[]>(defaultVal?: T): {
|
|
50
|
+
type: PropType<T>;
|
|
51
|
+
default: T;
|
|
52
|
+
};
|
|
53
|
+
export declare function stringType<T extends string = string>(defaultVal?: T): {
|
|
54
|
+
type: PropType<T>;
|
|
55
|
+
default: T;
|
|
56
|
+
};
|
|
57
|
+
export declare function someType<T>(types?: any[], defaultVal?: T): {
|
|
58
|
+
type: PropType<T>;
|
|
59
|
+
default: T;
|
|
60
|
+
};
|
|
61
|
+
export type CustomSlotsType<T extends Record<string, any>> = SlotsType<T>;
|
|
62
|
+
export type AnyObject = Record<PropertyKey, any>;
|
|
63
|
+
export {};
|
package/dist/type.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
const r = (...t) => t, o = (...t) => t;
|
|
2
|
+
function a(t) {
|
|
3
|
+
const n = t;
|
|
4
|
+
return n.install = function(e) {
|
|
5
|
+
e.component(n.displayName || n.name, t);
|
|
6
|
+
}, t;
|
|
7
|
+
}
|
|
8
|
+
function i() {
|
|
9
|
+
return { type: [Function, Array] };
|
|
10
|
+
}
|
|
11
|
+
function y(t) {
|
|
12
|
+
return { type: Object, default: t };
|
|
13
|
+
}
|
|
14
|
+
function c(t) {
|
|
15
|
+
return { type: Boolean, default: t };
|
|
16
|
+
}
|
|
17
|
+
function p(t) {
|
|
18
|
+
return { type: Function, default: t };
|
|
19
|
+
}
|
|
20
|
+
function u(t, n) {
|
|
21
|
+
const e = { validator: () => !0, default: t };
|
|
22
|
+
return e;
|
|
23
|
+
}
|
|
24
|
+
function f() {
|
|
25
|
+
return { validator: () => !0 };
|
|
26
|
+
}
|
|
27
|
+
function l(t) {
|
|
28
|
+
return { type: Array, default: t };
|
|
29
|
+
}
|
|
30
|
+
function d(t) {
|
|
31
|
+
return { type: String, default: t };
|
|
32
|
+
}
|
|
33
|
+
function T(t, n) {
|
|
34
|
+
return t ? { type: t, default: n } : u(n);
|
|
35
|
+
}
|
|
36
|
+
export {
|
|
37
|
+
u as anyType,
|
|
38
|
+
l as arrayType,
|
|
39
|
+
c as booleanType,
|
|
40
|
+
i as eventType,
|
|
41
|
+
p as functionType,
|
|
42
|
+
y as objectType,
|
|
43
|
+
T as someType,
|
|
44
|
+
d as stringType,
|
|
45
|
+
r as tuple,
|
|
46
|
+
o as tupleNum,
|
|
47
|
+
f as vNodeType,
|
|
48
|
+
a as withInstall
|
|
49
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function n(t,e,u,...i){var c,f;return e[u]?(c=e[u])==null?void 0:c.call(e,...i):u in t?typeof t[u]=="function"?(f=t[u])==null?void 0:f.call(t,...i):t[u]:null}exports.checkSlotProp=n;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function checkSlotProp(props: Record<string, any>, slots: Record<string, any>, name: string, ...args: any[]): any;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});function l(u,r){let e=u;for(let t=0;t<r.length;t+=1){if(e==null)return;e=e[r[t]]}return e}exports.default=l;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function get(entity: any, path: (string | number | symbol)[] | readonly (string | number | symbol)[]): any;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const u=require("./get.cjs");function g(e,t,o,l){if(!t.length)return o;const[r,...f]=t;let n;return!e&&typeof r=="number"?n=[]:Array.isArray(e)?n=[...e]:n={...e},l&&o===void 0&&f.length===1?delete n[r][f[0]]:n[r]=g(n[r],f,o,l),n}function i(e,t,o,l=!1){return t.length&&l&&o===void 0&&!u.default(e,t.slice(0,-1))?e:g(e,t,o,l)}function b(e){return typeof e=="object"&&e!==null&&Object.getPrototypeOf(e)===Object.prototype}function y(e){return Array.isArray(e)?[]:{}}const A=typeof Reflect>"u"?Object.keys:Reflect.ownKeys;function O(...e){let t=y(e[0]);return e.forEach(o=>{function l(r,f){const n=new Set(f),c=u.default(o,r),s=Array.isArray(c);if(s||b(c)){if(!n.has(c)){n.add(c);const a=u.default(t,r);s?t=i(t,r,[]):(!a||typeof a!="object")&&(t=i(t,r,y(c))),A(c).forEach(d=>{l([...r,d],n)})}}else t=i(t,r,c)}l([])}),t}exports.default=i;exports.merge=O;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export type Path = (string | number | symbol)[];
|
|
2
|
+
export default function set<Entity = any, Output = Entity, Value = any>(entity: Entity, paths: Path, value: Value, removeIfUndefined?: boolean): Output;
|
|
3
|
+
/**
|
|
4
|
+
* Merge objects which will create
|
|
5
|
+
*/
|
|
6
|
+
export declare function merge<T extends object>(...sources: T[]): T;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import s from "./get.js";
|
|
2
|
+
function g(e, r, o, c) {
|
|
3
|
+
if (!r.length)
|
|
4
|
+
return o;
|
|
5
|
+
const [t, ...i] = r;
|
|
6
|
+
let n;
|
|
7
|
+
return !e && typeof t == "number" ? n = [] : Array.isArray(e) ? n = [...e] : n = { ...e }, c && o === void 0 && i.length === 1 ? delete n[t][i[0]] : n[t] = g(n[t], i, o, c), n;
|
|
8
|
+
}
|
|
9
|
+
function l(e, r, o, c = !1) {
|
|
10
|
+
return r.length && c && o === void 0 && !s(e, r.slice(0, -1)) ? e : g(e, r, o, c);
|
|
11
|
+
}
|
|
12
|
+
function b(e) {
|
|
13
|
+
return typeof e == "object" && e !== null && Object.getPrototypeOf(e) === Object.prototype;
|
|
14
|
+
}
|
|
15
|
+
function a(e) {
|
|
16
|
+
return Array.isArray(e) ? [] : {};
|
|
17
|
+
}
|
|
18
|
+
const O = typeof Reflect > "u" ? Object.keys : Reflect.ownKeys;
|
|
19
|
+
function j(...e) {
|
|
20
|
+
let r = a(e[0]);
|
|
21
|
+
return e.forEach((o) => {
|
|
22
|
+
function c(t, i) {
|
|
23
|
+
const n = new Set(i), f = s(o, t), u = Array.isArray(f);
|
|
24
|
+
if (u || b(f)) {
|
|
25
|
+
if (!n.has(f)) {
|
|
26
|
+
n.add(f);
|
|
27
|
+
const y = s(r, t);
|
|
28
|
+
u ? r = l(r, t, []) : (!y || typeof y != "object") && (r = l(r, t, a(f))), O(f).forEach((A) => {
|
|
29
|
+
c([...t, A], n);
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
} else
|
|
33
|
+
r = l(r, t, f);
|
|
34
|
+
}
|
|
35
|
+
c([]);
|
|
36
|
+
}), r;
|
|
37
|
+
}
|
|
38
|
+
export {
|
|
39
|
+
l as default,
|
|
40
|
+
j as merge
|
|
41
|
+
};
|
package/dist/vnode.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("vue"),f=require("./props-util/index.cjs"),p=require("./warning.cjs");function s(e,r={},t=!0,u=!1){let n=e;if(Array.isArray(e)&&(n=f.filterEmpty(e)[0]),!n)return null;const i=o.cloneVNode(n,r,u);return i.props=t?{...i.props,...r}:i.props,p.warningOnce(typeof i.props.class!="object","class must be string"),i}function a(e,r={},t=!0){return e.map(u=>s(u,r,t))}function c(e,r={},t=!0,u=!1){if(Array.isArray(e))return e.map(n=>c(n,r,t,u));{if(!o.isVNode(e))return e;const n=s(e,r,t,u);return Array.isArray(n.children)&&(n.children=c(n.children)),n}}function d(e,r,t){o.render(o.cloneVNode(e,{...r}),t)}function l(e){return(e||[]).some(r=>o.isVNode(r)?!(r.type===o.Comment||r.type===o.Fragment&&!l(r.children)):!0)?e:null}function m(e,r,t,u){var i;const n=(i=e[r])==null?void 0:i.call(e,t);return l(n)?n:u==null?void 0:u()}exports.cloneElement=s;exports.cloneVNodes=a;exports.customRenderSlot=m;exports.deepCloneElement=c;exports.triggerVNodeUpdate=d;
|
package/dist/vnode.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Slots, VNode, VNodeArrayChildren, VNodeProps } from 'vue';
|
|
2
|
+
import { RefObject } from './createRef';
|
|
3
|
+
|
|
4
|
+
type NodeProps = Record<string, any> & Omit<VNodeProps, 'ref'> & {
|
|
5
|
+
ref?: VNodeProps['ref'] | RefObject;
|
|
6
|
+
};
|
|
7
|
+
export declare function cloneElement<T, U>(vnode: VNode<T, U> | VNode<T, U>[], nodeProps?: NodeProps, override?: boolean, mergeRef?: boolean): VNode<T, U> | null;
|
|
8
|
+
export declare function cloneVNodes(vnodes: any, nodeProps?: {}, override?: boolean): any;
|
|
9
|
+
export declare function deepCloneElement<T, U>(vnode: VNode<T, U> | VNode<T, U>[], nodeProps?: NodeProps, override?: boolean, mergeRef?: boolean): any;
|
|
10
|
+
export declare function triggerVNodeUpdate(vm: VNode, attrs: Record<string, any>, dom: any): void;
|
|
11
|
+
export declare function customRenderSlot(slots: Slots, name: string, props: Record<string, unknown>, fallback?: () => VNodeArrayChildren): VNodeArrayChildren | undefined;
|
|
12
|
+
export {};
|
package/dist/vnode.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { cloneVNode as f, isVNode as p, render as c, Comment as l, Fragment as a } from "vue";
|
|
2
|
+
import { filterEmpty as y } from "./props-util/index.js";
|
|
3
|
+
import { warningOnce as A } from "./warning.js";
|
|
4
|
+
function m(r, e = {}, n = !0, u = !1) {
|
|
5
|
+
let t = r;
|
|
6
|
+
if (Array.isArray(r) && (t = y(r)[0]), !t)
|
|
7
|
+
return null;
|
|
8
|
+
const i = f(t, e, u);
|
|
9
|
+
return i.props = n ? { ...i.props, ...e } : i.props, A(typeof i.props.class != "object", "class must be string"), i;
|
|
10
|
+
}
|
|
11
|
+
function g(r, e = {}, n = !0) {
|
|
12
|
+
return r.map((u) => m(u, e, n));
|
|
13
|
+
}
|
|
14
|
+
function o(r, e = {}, n = !0, u = !1) {
|
|
15
|
+
if (Array.isArray(r))
|
|
16
|
+
return r.map((t) => o(t, e, n, u));
|
|
17
|
+
{
|
|
18
|
+
if (!p(r))
|
|
19
|
+
return r;
|
|
20
|
+
const t = m(r, e, n, u);
|
|
21
|
+
return Array.isArray(t.children) && (t.children = o(t.children)), t;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
function E(r, e, n) {
|
|
25
|
+
c(f(r, { ...e }), n);
|
|
26
|
+
}
|
|
27
|
+
function s(r) {
|
|
28
|
+
return (r || []).some((e) => p(e) ? !(e.type === l || e.type === a && !s(e.children)) : !0) ? r : null;
|
|
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();
|
|
34
|
+
}
|
|
35
|
+
export {
|
|
36
|
+
m as cloneElement,
|
|
37
|
+
g as cloneVNodes,
|
|
38
|
+
C as customRenderSlot,
|
|
39
|
+
o as deepCloneElement,
|
|
40
|
+
E as triggerVNodeUpdate
|
|
41
|
+
};
|
package/dist/warning.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});let i={};const s=[];function u(e){s.push(e)}function l(e,n){if(process.env.NODE_ENV!=="production"&&!e&&console!==void 0){const o=s.reduce((t,c)=>c(t??"","warning"),n);o&&console.error(`Warning: ${o}`)}}function f(e,n){if(process.env.NODE_ENV!=="production"&&!e&&console!==void 0){const o=s.reduce((t,c)=>c(t??"","note"),n);o&&console.warn(`Note: ${o}`)}}function d(){i={}}function a(e,n,o){!n&&!i[o]&&(e(!1,o),i[o]=!0)}function r(e,n){a(l,e,n)}function g(e,n){a(f,e,n)}r.preMessage=u;r.resetWarned=d;r.noteOnce=g;exports.call=a;exports.default=r;exports.note=f;exports.noteOnce=g;exports.preMessage=u;exports.resetWarned=d;exports.warning=l;exports.warningOnce=r;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export type preMessageFn = (message: string, type: 'warning' | 'note') => string | null | undefined | number;
|
|
2
|
+
/**
|
|
3
|
+
* Pre warning enable you to parse content before console.error.
|
|
4
|
+
* Modify to null will prevent warning.
|
|
5
|
+
*/
|
|
6
|
+
export declare function preMessage(fn: preMessageFn): void;
|
|
7
|
+
export declare function warning(valid: boolean, message: string): void;
|
|
8
|
+
export declare function note(valid: boolean, message: string): void;
|
|
9
|
+
export declare function resetWarned(): void;
|
|
10
|
+
export declare function call(method: (valid: boolean, message: string) => void, valid: boolean, message: string): void;
|
|
11
|
+
export declare function warningOnce(valid: boolean, message: string): void;
|
|
12
|
+
export declare namespace warningOnce {
|
|
13
|
+
var preMessage: typeof import("./warning").preMessage;
|
|
14
|
+
var resetWarned: typeof import("./warning").resetWarned;
|
|
15
|
+
var noteOnce: typeof import("./warning").noteOnce;
|
|
16
|
+
}
|
|
17
|
+
export declare function noteOnce(valid: boolean, message: string): void;
|
|
18
|
+
export default warningOnce;
|
package/dist/warning.js
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
let i = {};
|
|
2
|
+
const t = [];
|
|
3
|
+
function f(n) {
|
|
4
|
+
t.push(n);
|
|
5
|
+
}
|
|
6
|
+
function u(n, e) {
|
|
7
|
+
if (process.env.NODE_ENV !== "production" && !n && console !== void 0) {
|
|
8
|
+
const o = t.reduce(
|
|
9
|
+
(r, c) => c(r ?? "", "warning"),
|
|
10
|
+
e
|
|
11
|
+
);
|
|
12
|
+
o && console.error(`Warning: ${o}`);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
function l(n, e) {
|
|
16
|
+
if (process.env.NODE_ENV !== "production" && !n && console !== void 0) {
|
|
17
|
+
const o = t.reduce(
|
|
18
|
+
(r, c) => c(r ?? "", "note"),
|
|
19
|
+
e
|
|
20
|
+
);
|
|
21
|
+
o && console.warn(`Note: ${o}`);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
function d() {
|
|
25
|
+
i = {};
|
|
26
|
+
}
|
|
27
|
+
function a(n, e, o) {
|
|
28
|
+
!e && !i[o] && (n(!1, o), i[o] = !0);
|
|
29
|
+
}
|
|
30
|
+
function s(n, e) {
|
|
31
|
+
a(u, n, e);
|
|
32
|
+
}
|
|
33
|
+
function p(n, e) {
|
|
34
|
+
a(l, n, e);
|
|
35
|
+
}
|
|
36
|
+
s.preMessage = f;
|
|
37
|
+
s.resetWarned = d;
|
|
38
|
+
s.noteOnce = p;
|
|
39
|
+
export {
|
|
40
|
+
a as call,
|
|
41
|
+
s as default,
|
|
42
|
+
l as note,
|
|
43
|
+
p as noteOnce,
|
|
44
|
+
f as preMessage,
|
|
45
|
+
d as resetWarned,
|
|
46
|
+
u as warning,
|
|
47
|
+
s as warningOnce
|
|
48
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@v-c/util",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "0.0.1",
|
|
5
|
+
"description": "Vue3 components utils",
|
|
6
|
+
"publishConfig": {
|
|
7
|
+
"access": "public"
|
|
8
|
+
},
|
|
9
|
+
"author": {
|
|
10
|
+
"name": "aibayanyu20",
|
|
11
|
+
"email": "aibayanyu@qq.com",
|
|
12
|
+
"url": "https://yanyu.me"
|
|
13
|
+
},
|
|
14
|
+
"exports": {
|
|
15
|
+
".": {
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"import": "./dist/index.js",
|
|
18
|
+
"require": "./dist/index.cjs"
|
|
19
|
+
},
|
|
20
|
+
"./dist/*": "./dist/*",
|
|
21
|
+
"./*": {
|
|
22
|
+
"types": "./dist/*",
|
|
23
|
+
"import": "./dist/*",
|
|
24
|
+
"require": "./dist/*",
|
|
25
|
+
"default": "./dist/*"
|
|
26
|
+
},
|
|
27
|
+
"./package.json": "./package.json"
|
|
28
|
+
},
|
|
29
|
+
"main": "dist/index.js",
|
|
30
|
+
"peerDependencies": {
|
|
31
|
+
"vue": "^3.0.0"
|
|
32
|
+
},
|
|
33
|
+
"scripts": {
|
|
34
|
+
"build": "vite build",
|
|
35
|
+
"prepublish": "pnpm build"
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest'
|
|
2
|
+
import { createVNode } from 'vue'
|
|
3
|
+
import { isFragment } from '@vue-components/util/Children/isFragment.ts'
|
|
4
|
+
|
|
5
|
+
describe('isFragment', () => {
|
|
6
|
+
it('should ', () => {
|
|
7
|
+
const Dom = createVNode('div', null, '1')
|
|
8
|
+
|
|
9
|
+
const dom = isFragment(Dom)
|
|
10
|
+
const dom1 = isFragment(<>1</>)
|
|
11
|
+
|
|
12
|
+
expect(dom).toBe(false)
|
|
13
|
+
expect(dom1).toBe(true)
|
|
14
|
+
})
|
|
15
|
+
})
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest'
|
|
2
|
+
import { Fragment, defineComponent } from 'vue'
|
|
3
|
+
import { mount } from '@vue/test-utils'
|
|
4
|
+
import { toArray } from '@vue-components/util/Children/toArray.ts'
|
|
5
|
+
|
|
6
|
+
describe('toArray', () => {
|
|
7
|
+
let children: any
|
|
8
|
+
const UL = defineComponent({
|
|
9
|
+
setup(_, { slots }) {
|
|
10
|
+
return () => {
|
|
11
|
+
children = slots.default?.()
|
|
12
|
+
return <ul>{slots.default?.()}</ul>
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
})
|
|
16
|
+
it('basic', () => {
|
|
17
|
+
const wrapper = mount(
|
|
18
|
+
<UL>
|
|
19
|
+
<li key={1}>1</li>
|
|
20
|
+
<li key={2}>2</li>
|
|
21
|
+
<li key={3}>3</li>
|
|
22
|
+
</UL>,
|
|
23
|
+
)
|
|
24
|
+
const nodes = toArray(children)
|
|
25
|
+
expect(nodes).toHaveLength(3)
|
|
26
|
+
expect(nodes.map(v => v.key)).toEqual([1, 2, 3])
|
|
27
|
+
wrapper.unmount()
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
it('array', () => {
|
|
31
|
+
const wrapper = mount(
|
|
32
|
+
<UL>
|
|
33
|
+
<li key={1}>1</li>
|
|
34
|
+
{[<li key={2}>2</li>, <li key={3}>3</li>]}
|
|
35
|
+
</UL>,
|
|
36
|
+
)
|
|
37
|
+
const nodes = toArray(children)
|
|
38
|
+
expect(nodes).toHaveLength(3)
|
|
39
|
+
expect(nodes.map(v => v.key)).toEqual([1, 2, 3])
|
|
40
|
+
wrapper.unmount()
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
it('fragment', () => {
|
|
44
|
+
const wrapper = mount(
|
|
45
|
+
<UL>
|
|
46
|
+
<li key={1}>1</li>
|
|
47
|
+
<>
|
|
48
|
+
<li key="2">2</li>
|
|
49
|
+
<li key="3">3</li>
|
|
50
|
+
</>
|
|
51
|
+
<Fragment>
|
|
52
|
+
<>
|
|
53
|
+
<li key="4">4</li>
|
|
54
|
+
<li key="5">5</li>
|
|
55
|
+
</>
|
|
56
|
+
</Fragment>
|
|
57
|
+
</UL>,
|
|
58
|
+
)
|
|
59
|
+
const nodes = toArray(children)
|
|
60
|
+
expect(nodes).toHaveLength(5)
|
|
61
|
+
expect(nodes.map(v => v.key)).toEqual([1, '2', '3', '4', '5'])
|
|
62
|
+
wrapper.unmount()
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
it('keep empty', () => {
|
|
66
|
+
const wrapper = mount(
|
|
67
|
+
<UL>
|
|
68
|
+
{null}
|
|
69
|
+
<li key="1">1</li>
|
|
70
|
+
<>
|
|
71
|
+
<li key="2">2</li>
|
|
72
|
+
{null}
|
|
73
|
+
<li key="3">3</li>
|
|
74
|
+
</>
|
|
75
|
+
<Fragment>
|
|
76
|
+
<>
|
|
77
|
+
<li key="4">4</li>
|
|
78
|
+
{undefined}
|
|
79
|
+
<li key="5">5</li>
|
|
80
|
+
</>
|
|
81
|
+
</Fragment>
|
|
82
|
+
{undefined}
|
|
83
|
+
</UL>,
|
|
84
|
+
)
|
|
85
|
+
|
|
86
|
+
const nodes = toArray(children, { keepEmpty: true })
|
|
87
|
+
expect(nodes).toHaveLength(9)
|
|
88
|
+
expect(nodes.map(c => c && c.key)).toEqual([
|
|
89
|
+
null,
|
|
90
|
+
'1',
|
|
91
|
+
'2',
|
|
92
|
+
null,
|
|
93
|
+
'3',
|
|
94
|
+
'4',
|
|
95
|
+
undefined,
|
|
96
|
+
'5',
|
|
97
|
+
null,
|
|
98
|
+
])
|
|
99
|
+
wrapper.unmount()
|
|
100
|
+
})
|
|
101
|
+
})
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { VNode } from 'vue'
|
|
2
|
+
import { isFragment } from './isFragment'
|
|
3
|
+
|
|
4
|
+
export interface Option {
|
|
5
|
+
keepEmpty?: boolean
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export function toArray(children: any, option: Option = {}) {
|
|
9
|
+
// 从slots中获取的必定是数组
|
|
10
|
+
let ret: VNode[] = []
|
|
11
|
+
// 判断children是否是一个数组,如果不是就把它放到一个数组中
|
|
12
|
+
if (!Array.isArray(children))
|
|
13
|
+
children = [children]
|
|
14
|
+
for (const child of children) {
|
|
15
|
+
if ((child === undefined || child === null) && !option.keepEmpty)
|
|
16
|
+
continue
|
|
17
|
+
|
|
18
|
+
if (Array.isArray(child))
|
|
19
|
+
ret = ret.concat(toArray(child, option))
|
|
20
|
+
|
|
21
|
+
else if (isFragment(child) && child.children)
|
|
22
|
+
ret = ret.concat(toArray(child.children, option))
|
|
23
|
+
else
|
|
24
|
+
ret.push(child)
|
|
25
|
+
}
|
|
26
|
+
return ret
|
|
27
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export type WindowEventName = keyof WindowEventMap
|
|
2
|
+
export type DocumentEventName = keyof DocumentEventMap
|
|
3
|
+
export function addEventListener<E extends WindowEventName = WindowEventName>(target: Window, eventType: E, cb: WindowEventMap[E], option?: AddEventListenerOptions): {
|
|
4
|
+
remove(): void
|
|
5
|
+
}
|
|
6
|
+
export function addEventListener<E extends DocumentEventName = DocumentEventName>(target: Document, eventType: E, cb: DocumentEventMap[E], option?: AddEventListenerOptions): {
|
|
7
|
+
remove(): void
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function addEventListener(...args: any[]) {
|
|
11
|
+
const [target, eventType, cb, option] = args
|
|
12
|
+
if (target?.addEventListener)
|
|
13
|
+
target.addEventListener(eventType as any, cb, option)
|
|
14
|
+
|
|
15
|
+
return {
|
|
16
|
+
remove() {
|
|
17
|
+
target?.removeEventListener?.(eventType as any, cb, option)
|
|
18
|
+
},
|
|
19
|
+
}
|
|
20
|
+
}
|
package/src/Dom/class.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export function hasClass(node: Element, className: string) {
|
|
2
|
+
if (node.classList)
|
|
3
|
+
return node.classList.contains(className)
|
|
4
|
+
|
|
5
|
+
const originClass = node.className
|
|
6
|
+
return ` ${originClass} `.includes(` ${className} `)
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function addClass(node: Element, className: string) {
|
|
10
|
+
if (node.classList) {
|
|
11
|
+
node.classList.add(className)
|
|
12
|
+
}
|
|
13
|
+
else {
|
|
14
|
+
if (!hasClass(node, className))
|
|
15
|
+
node.className = `${node.className} ${className}`
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function removeClass(node: Element, className: string) {
|
|
20
|
+
if (node.classList) {
|
|
21
|
+
node.classList.remove(className)
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
if (hasClass(node, className)) {
|
|
25
|
+
const originClass = node.className
|
|
26
|
+
node.className = ` ${originClass} `.replace(` ${className} `, ' ')
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export default function contains(root: Node | null | undefined, n?: Node) {
|
|
2
|
+
if (!root)
|
|
3
|
+
return false
|
|
4
|
+
|
|
5
|
+
// Use native if support
|
|
6
|
+
if (root.contains)
|
|
7
|
+
return root.contains(n as any)
|
|
8
|
+
|
|
9
|
+
// `document.contains` not support with IE11
|
|
10
|
+
let node: any = n
|
|
11
|
+
while (node) {
|
|
12
|
+
if (node === root)
|
|
13
|
+
return true
|
|
14
|
+
|
|
15
|
+
node = node.parentNode
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return false
|
|
19
|
+
}
|