@veltra/utils 1.0.0
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/dom/class-name.d.ts +10 -0
- package/dist/dom/class-name.js +16 -0
- package/dist/dom/class-name.js.map +1 -0
- package/dist/dom/highlight.d.ts +14 -0
- package/dist/dom/highlight.js +19 -0
- package/dist/dom/highlight.js.map +1 -0
- package/dist/dom/position.d.ts +28 -0
- package/dist/dom/position.js +59 -0
- package/dist/dom/position.js.map +1 -0
- package/dist/dom/style.d.ts +25 -0
- package/dist/dom/style.js +38 -0
- package/dist/dom/style.js.map +1 -0
- package/dist/dom/z-index.d.ts +9 -0
- package/dist/dom/z-index.js +11 -0
- package/dist/dom/z-index.js.map +1 -0
- package/dist/form/validate.d.ts +33 -0
- package/dist/form/validate.js +197 -0
- package/dist/form/validate.js.map +1 -0
- package/dist/helper/create-increase.d.ts +10 -0
- package/dist/helper/create-increase.js +17 -0
- package/dist/helper/create-increase.js.map +1 -0
- package/dist/helper/create-toggle.d.ts +15 -0
- package/dist/helper/create-toggle.js +24 -0
- package/dist/helper/create-toggle.js.map +1 -0
- package/dist/helper/frame.d.ts +9 -0
- package/dist/helper/frame.js +14 -0
- package/dist/helper/frame.js.map +1 -0
- package/dist/helper/make-bem.d.ts +52 -0
- package/dist/helper/make-bem.js +39 -0
- package/dist/helper/make-bem.js.map +1 -0
- package/dist/helper/tween.d.ts +43 -0
- package/dist/helper/tween.js +89 -0
- package/dist/helper/tween.js.map +1 -0
- package/dist/helper/vue.d.ts +44 -0
- package/dist/helper/vue.js +62 -0
- package/dist/helper/vue.js.map +1 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.js +15 -0
- package/dist/reactive/proxy.d.ts +19 -0
- package/dist/reactive/proxy.js +57 -0
- package/dist/reactive/proxy.js.map +1 -0
- package/dist/shared/constants.d.ts +10 -0
- package/dist/shared/constants.js +11 -0
- package/dist/shared/constants.js.map +1 -0
- package/dist/types/component-common.d.ts +37 -0
- package/dist/types/form-context.d.ts +6 -0
- package/dist/types/helper.d.ts +22 -0
- package/dist/types/index.d.ts +5 -0
- package/dist/types/index.js +0 -0
- package/dist/types/utils/form/validate.d.ts +34 -0
- package/package.json +47 -0
- package/src/dom/class-name.ts +20 -0
- package/src/dom/highlight.ts +23 -0
- package/src/dom/position.ts +96 -0
- package/src/dom/style.ts +60 -0
- package/src/dom/z-index.ts +7 -0
- package/src/env.d.ts +1 -0
- package/src/form/validate.ts +278 -0
- package/src/helper/create-increase.ts +14 -0
- package/src/helper/create-toggle.ts +29 -0
- package/src/helper/frame.ts +9 -0
- package/src/helper/make-bem.ts +109 -0
- package/src/helper/tween.ts +123 -0
- package/src/helper/vue.ts +88 -0
- package/src/index.ts +28 -0
- package/src/reactive/proxy.ts +90 -0
- package/src/shared/constants.ts +8 -0
- package/src/shared/index.ts +1 -0
- package/src/types/component-common.ts +41 -0
- package/src/types/form-context.ts +2 -0
- package/src/types/helper.ts +31 -0
- package/src/types/index.ts +4 -0
- package/src/types/utils/form/validate.ts +33 -0
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
//#region src/helper/make-bem.d.ts
|
|
2
|
+
/** BEM实例 */
|
|
3
|
+
type BEM<N extends string, P extends string = 'u-', B extends string = `${P}${N}`> = {
|
|
4
|
+
/** BEM中的块 */b: B;
|
|
5
|
+
/**
|
|
6
|
+
* BEM中的元素(E)
|
|
7
|
+
* @param name 元素名称
|
|
8
|
+
* @returns
|
|
9
|
+
*/
|
|
10
|
+
e<const E extends string>(name: E): `${B}__${E}`;
|
|
11
|
+
/**
|
|
12
|
+
* 基于当前bem创建一个新的bem
|
|
13
|
+
* @param block 块名称
|
|
14
|
+
*/
|
|
15
|
+
create<const Block extends string>(block: Block): BEM<`${N}-${Block}`, P>;
|
|
16
|
+
/**
|
|
17
|
+
* BEM中的修饰符(M)
|
|
18
|
+
* @param m 修饰符名
|
|
19
|
+
* @returns 修饰符
|
|
20
|
+
*/
|
|
21
|
+
m<const M extends string>(m: M): `${B}--${M}`;
|
|
22
|
+
/**
|
|
23
|
+
* BEM中的元素与修饰符(E--M)
|
|
24
|
+
* @param e 元素名
|
|
25
|
+
* @param m 修饰符名
|
|
26
|
+
* @returns
|
|
27
|
+
*/
|
|
28
|
+
em<const E extends string, const M extends string>(e: E, m: M): `${B}__${E}--${M}`;
|
|
29
|
+
};
|
|
30
|
+
/** BEM工厂 */
|
|
31
|
+
interface BEMFactory<Prefix extends string> {
|
|
32
|
+
<N extends string>(name: N): BEM<N, Prefix>;
|
|
33
|
+
/**
|
|
34
|
+
* 生成is辅助类
|
|
35
|
+
* @param name 辅助类名称
|
|
36
|
+
*/
|
|
37
|
+
is<const N extends string>(name: N): `is-${N}`;
|
|
38
|
+
/**
|
|
39
|
+
* 生成is辅助类
|
|
40
|
+
* @param name 辅助类名称
|
|
41
|
+
* @param condition 辅助类显示条件
|
|
42
|
+
*/
|
|
43
|
+
is<const N extends string, C extends boolean | undefined>(name: N, condition: C): C extends true ? `is-${N}` : '';
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* 创建一个bem函数
|
|
47
|
+
* @param prefix 前缀
|
|
48
|
+
*/
|
|
49
|
+
declare function makeBEM<Prefix extends '' | `${string}-`>(prefix: Prefix): BEMFactory<Prefix>;
|
|
50
|
+
//#endregion
|
|
51
|
+
export { BEM, BEMFactory, makeBEM };
|
|
52
|
+
//# sourceMappingURL=make-bem.d.ts.map
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
//#region src/helper/make-bem.ts
|
|
2
|
+
/**
|
|
3
|
+
* 创建一个bem函数
|
|
4
|
+
* @param prefix 前缀
|
|
5
|
+
*/
|
|
6
|
+
function makeBEM(prefix) {
|
|
7
|
+
/**
|
|
8
|
+
* css类命名辅助
|
|
9
|
+
* @param name 类block名称
|
|
10
|
+
*/
|
|
11
|
+
function bem(name) {
|
|
12
|
+
const b = `${prefix}${name}`;
|
|
13
|
+
return {
|
|
14
|
+
b,
|
|
15
|
+
e(name) {
|
|
16
|
+
return `${b}__${name}`;
|
|
17
|
+
},
|
|
18
|
+
create(block) {
|
|
19
|
+
return bem(`${name}-${block}`);
|
|
20
|
+
},
|
|
21
|
+
m(m) {
|
|
22
|
+
return `${b}--${m}`;
|
|
23
|
+
},
|
|
24
|
+
em(e, m) {
|
|
25
|
+
return `${b}__${e}--${m}`;
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
function is(name, condition) {
|
|
30
|
+
if (arguments.length < 2) return `is-${name}`;
|
|
31
|
+
return condition !== true ? "" : `is-${name}`;
|
|
32
|
+
}
|
|
33
|
+
bem.is = is;
|
|
34
|
+
return bem;
|
|
35
|
+
}
|
|
36
|
+
//#endregion
|
|
37
|
+
export { makeBEM };
|
|
38
|
+
|
|
39
|
+
//# sourceMappingURL=make-bem.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"make-bem.js","names":[],"sources":["../../src/helper/make-bem.ts"],"sourcesContent":["/** BEM实例 */\nexport type BEM<N extends string, P extends string = 'u-', B extends string = `${P}${N}`> = {\n /** BEM中的块 */\n b: B\n\n /**\n * BEM中的元素(E)\n * @param name 元素名称\n * @returns\n */\n e<const E extends string>(name: E): `${B}__${E}`\n\n /**\n * 基于当前bem创建一个新的bem\n * @param block 块名称\n */\n create<const Block extends string>(block: Block): BEM<`${N}-${Block}`, P>\n\n /**\n * BEM中的修饰符(M)\n * @param m 修饰符名\n * @returns 修饰符\n */\n m<const M extends string>(m: M): `${B}--${M}`\n\n /**\n * BEM中的元素与修饰符(E--M)\n * @param e 元素名\n * @param m 修饰符名\n * @returns\n */\n em<const E extends string, const M extends string>(e: E, m: M): `${B}__${E}--${M}`\n}\n\n/** BEM工厂 */\nexport interface BEMFactory<Prefix extends string> {\n <N extends string>(name: N): BEM<N, Prefix>\n /**\n * 生成is辅助类\n * @param name 辅助类名称\n */\n is<const N extends string>(name: N): `is-${N}`\n /**\n * 生成is辅助类\n * @param name 辅助类名称\n * @param condition 辅助类显示条件\n */\n is<const N extends string, C extends boolean | undefined>(\n name: N,\n condition: C\n ): C extends true ? `is-${N}` : ''\n}\n\n/**\n * 创建一个bem函数\n * @param prefix 前缀\n */\nexport function makeBEM<Prefix extends '' | `${string}-`>(prefix: Prefix): BEMFactory<Prefix> {\n /**\n * css类命名辅助\n * @param name 类block名称\n */\n function bem<N extends string>(name: N): BEM<N, Prefix> {\n const b = `${prefix}${name}` as BEM<N, Prefix>['b']\n return {\n b,\n\n e(name) {\n return `${b}__${name}`\n },\n\n create(block) {\n return bem(`${name}-${block}`)\n },\n\n m(m) {\n return `${b}--${m}`\n },\n\n em(e, m) {\n return `${b}__${e}--${m}`\n }\n }\n }\n\n /**\n * 生成is辅助类\n * @param name 辅助类名称\n */\n function is<const N extends string>(name: N): `is-${N}`\n /**\n * 生成is辅助类\n * @param name 辅助类名称\n * @param condition 辅助类显示条件\n */\n function is<const N extends string, C extends boolean | undefined>(\n name: N,\n condition: C\n ): C extends true ? `is-${N}` : ''\n\n function is<N extends string>(name: N, condition?: boolean) {\n if (arguments.length < 2) return `is-${name}`\n return condition !== true ? '' : (`is-${name}` as const)\n }\n\n bem.is = is\n\n return bem\n}\n"],"mappings":";;;;;AAyDA,SAAgB,QAA0C,QAAoC;;;;;CAK5F,SAAS,IAAsB,MAAyB;EACtD,MAAM,IAAI,GAAG,SAAS;AACtB,SAAO;GACL;GAEA,EAAE,MAAM;AACN,WAAO,GAAG,EAAE,IAAI;;GAGlB,OAAO,OAAO;AACZ,WAAO,IAAI,GAAG,KAAK,GAAG,QAAQ;;GAGhC,EAAE,GAAG;AACH,WAAO,GAAG,EAAE,IAAI;;GAGlB,GAAG,GAAG,GAAG;AACP,WAAO,GAAG,EAAE,IAAI,EAAE,IAAI;;GAEzB;;CAkBH,SAAS,GAAqB,MAAS,WAAqB;AAC1D,MAAI,UAAU,SAAS,EAAG,QAAO,MAAM;AACvC,SAAO,cAAc,OAAO,KAAM,MAAM;;AAG1C,KAAI,KAAK;AAET,QAAO"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
//#region src/helper/tween.d.ts
|
|
2
|
+
/** 自 cat-kit 3.x Tween 行为对齐的轻量动画(原 `cat-kit/fe` 导出) */
|
|
3
|
+
interface AnimeConfig<State extends Record<string, number>> {
|
|
4
|
+
duration?: number;
|
|
5
|
+
easingFunction?: (progress: number) => number;
|
|
6
|
+
onComplete?(state: State): void;
|
|
7
|
+
}
|
|
8
|
+
interface TweenConfig<State extends Record<string, number>> {
|
|
9
|
+
duration?: number;
|
|
10
|
+
onUpdate?(state: State): void;
|
|
11
|
+
onComplete?(state: State): void;
|
|
12
|
+
easingFunction?: (progress: number) => number;
|
|
13
|
+
}
|
|
14
|
+
declare class Tween<State extends Record<string, number> = Record<string, number>> {
|
|
15
|
+
readonly state: State;
|
|
16
|
+
protected duration: number;
|
|
17
|
+
protected onUpdate?: (state: State) => void;
|
|
18
|
+
protected onComplete?: (state: State) => void;
|
|
19
|
+
protected frameId?: number;
|
|
20
|
+
protected easingFunction: (progress: number) => number;
|
|
21
|
+
private defaultState;
|
|
22
|
+
constructor(state: State, config?: TweenConfig<State>);
|
|
23
|
+
protected raf(options: {
|
|
24
|
+
onComplete: () => void;
|
|
25
|
+
duration: number;
|
|
26
|
+
tick: (p: number) => void;
|
|
27
|
+
}): void;
|
|
28
|
+
to(state: Partial<State>, config?: AnimeConfig<State>): void;
|
|
29
|
+
back(config?: AnimeConfig<State>): void;
|
|
30
|
+
private stop;
|
|
31
|
+
static readonly easing: {
|
|
32
|
+
linear: (p: number) => number;
|
|
33
|
+
easeInQuad: (p: number) => number;
|
|
34
|
+
easeOutQuad: (p: number) => number;
|
|
35
|
+
easeInOutQuad: (p: number) => number;
|
|
36
|
+
easeInBack: (p: number) => number;
|
|
37
|
+
easeOutBack: (p: number) => number;
|
|
38
|
+
easeInOutBack: (p: number) => number;
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
//#endregion
|
|
42
|
+
export { AnimeConfig, Tween, TweenConfig };
|
|
43
|
+
//# sourceMappingURL=tween.d.ts.map
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
//#region src/helper/tween.ts
|
|
2
|
+
var Tween = class Tween {
|
|
3
|
+
state;
|
|
4
|
+
duration = 300;
|
|
5
|
+
onUpdate;
|
|
6
|
+
onComplete;
|
|
7
|
+
frameId;
|
|
8
|
+
easingFunction;
|
|
9
|
+
defaultState;
|
|
10
|
+
constructor(state, config) {
|
|
11
|
+
this.state = state;
|
|
12
|
+
this.defaultState = { ...state };
|
|
13
|
+
const { duration, onUpdate, onComplete, easingFunction } = config || {};
|
|
14
|
+
if (duration !== void 0) this.duration = duration;
|
|
15
|
+
if (onUpdate !== void 0) this.onUpdate = onUpdate;
|
|
16
|
+
if (onComplete !== void 0) this.onComplete = onComplete;
|
|
17
|
+
this.easingFunction = easingFunction ?? Tween.easing.linear;
|
|
18
|
+
}
|
|
19
|
+
raf(options) {
|
|
20
|
+
const start = performance.now();
|
|
21
|
+
const { onComplete, tick, duration } = options;
|
|
22
|
+
const update = (timestamp) => {
|
|
23
|
+
const elapsed = timestamp - start;
|
|
24
|
+
const progress = Math.min(elapsed / duration, 1);
|
|
25
|
+
tick(progress);
|
|
26
|
+
if (progress < 1) this.frameId = requestAnimationFrame(update);
|
|
27
|
+
else {
|
|
28
|
+
tick(progress);
|
|
29
|
+
this.stop();
|
|
30
|
+
onComplete();
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
this.frameId = requestAnimationFrame(update);
|
|
34
|
+
}
|
|
35
|
+
to(state, config) {
|
|
36
|
+
this.stop();
|
|
37
|
+
const prevState = { ...this.state };
|
|
38
|
+
const stateDistance = Object.keys(state).reduce((acc, key) => {
|
|
39
|
+
const k = key;
|
|
40
|
+
const sv = state[k];
|
|
41
|
+
const pv = prevState[k];
|
|
42
|
+
if ((sv || sv === 0) && (pv || pv === 0)) acc[key] = sv - pv;
|
|
43
|
+
return acc;
|
|
44
|
+
}, {});
|
|
45
|
+
const duration = config?.duration || this.duration;
|
|
46
|
+
const easingFunction = config?.easingFunction || this.easingFunction;
|
|
47
|
+
const onComplete = config?.onComplete || this.onComplete;
|
|
48
|
+
this.raf({
|
|
49
|
+
duration,
|
|
50
|
+
onComplete: () => {
|
|
51
|
+
for (const key in state) if (key in this.state) this.state[key] = state[key];
|
|
52
|
+
this.onUpdate?.(this.state);
|
|
53
|
+
onComplete?.(this.state);
|
|
54
|
+
},
|
|
55
|
+
tick: (progress) => {
|
|
56
|
+
for (const key in stateDistance) {
|
|
57
|
+
const target = prevState[key] + easingFunction(progress) * stateDistance[key];
|
|
58
|
+
this.state[key] = target;
|
|
59
|
+
}
|
|
60
|
+
this.onUpdate?.(this.state);
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
back(config) {
|
|
65
|
+
this.to(this.defaultState, config);
|
|
66
|
+
}
|
|
67
|
+
stop() {
|
|
68
|
+
if (!this.frameId) return false;
|
|
69
|
+
cancelAnimationFrame(this.frameId);
|
|
70
|
+
this.frameId = void 0;
|
|
71
|
+
return true;
|
|
72
|
+
}
|
|
73
|
+
static easing = {
|
|
74
|
+
linear: (p) => p,
|
|
75
|
+
easeInQuad: (p) => p * p,
|
|
76
|
+
easeOutQuad: (p) => p * (2 - p),
|
|
77
|
+
easeInOutQuad: (p) => p < .5 ? 2 * p * p : -1 + (4 - 2 * p) * p,
|
|
78
|
+
easeInBack: (p) => p * p * (3.70158 * p - 1),
|
|
79
|
+
easeOutBack: (p) => 1 + 2.70158 * Math.pow(p - 1, 3) + 1.70158 * Math.pow(p - 1, 2),
|
|
80
|
+
easeInOutBack: (p) => {
|
|
81
|
+
const c2 = 1.70158 * 1.525;
|
|
82
|
+
return p < .5 ? Math.pow(2 * p, 2) * ((c2 + 1) * 2 * p - c2) / 2 : (Math.pow(2 * p - 2, 2) * ((c2 + 1) * (p * 2 - 2) + c2) + 2) / 2;
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
};
|
|
86
|
+
//#endregion
|
|
87
|
+
export { Tween };
|
|
88
|
+
|
|
89
|
+
//# sourceMappingURL=tween.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tween.js","names":[],"sources":["../../src/helper/tween.ts"],"sourcesContent":["/** 自 cat-kit 3.x Tween 行为对齐的轻量动画(原 `cat-kit/fe` 导出) */\n\nexport interface AnimeConfig<State extends Record<string, number>> {\n duration?: number\n easingFunction?: (progress: number) => number\n onComplete?(state: State): void\n}\n\nexport interface TweenConfig<State extends Record<string, number>> {\n duration?: number\n onUpdate?(state: State): void\n onComplete?(state: State): void\n easingFunction?: (progress: number) => number\n}\n\nexport class Tween<State extends Record<string, number> = Record<string, number>> {\n readonly state: State\n protected duration = 300\n protected onUpdate?: (state: State) => void\n protected onComplete?: (state: State) => void\n protected frameId?: number\n protected easingFunction: (progress: number) => number\n private defaultState: State\n\n constructor(state: State, config?: TweenConfig<State>) {\n this.state = state\n this.defaultState = { ...state }\n const { duration, onUpdate, onComplete, easingFunction } = config || {}\n if (duration !== undefined) this.duration = duration\n if (onUpdate !== undefined) this.onUpdate = onUpdate\n if (onComplete !== undefined) this.onComplete = onComplete\n this.easingFunction = easingFunction ?? Tween.easing.linear\n }\n\n protected raf(options: {\n onComplete: () => void\n duration: number\n tick: (p: number) => void\n }): void {\n const start = performance.now()\n const { onComplete, tick, duration } = options\n const update = (timestamp: number) => {\n const elapsed = timestamp - start\n const progress = Math.min(elapsed / duration, 1)\n tick(progress)\n if (progress < 1) {\n this.frameId = requestAnimationFrame(update)\n } else {\n tick(progress)\n this.stop()\n onComplete()\n }\n }\n this.frameId = requestAnimationFrame(update)\n }\n\n to(state: Partial<State>, config?: AnimeConfig<State>): void {\n this.stop()\n const prevState = { ...this.state }\n const stateDistance = Object.keys(state).reduce(\n (acc, key) => {\n const k = key as keyof State\n const sv = state[k] as number\n const pv = prevState[k] as number\n if ((sv || sv === 0) && (pv || pv === 0)) {\n acc[key] = sv - pv\n }\n return acc\n },\n {} as Record<string, number>\n )\n const duration = config?.duration || this.duration\n const easingFunction = config?.easingFunction || this.easingFunction\n const onComplete = config?.onComplete || this.onComplete\n this.raf({\n duration,\n onComplete: () => {\n for (const key in state) {\n if (key in this.state) {\n ;(this.state as Record<string, number>)[key] = state[key as keyof State] as number\n }\n }\n this.onUpdate?.(this.state)\n onComplete?.(this.state)\n },\n tick: (progress) => {\n for (const key in stateDistance) {\n const pk = key as keyof State\n const target = (prevState[pk] as number) + easingFunction(progress) * stateDistance[key]!\n ;(this.state as Record<string, number>)[key] = target\n }\n this.onUpdate?.(this.state)\n }\n })\n }\n\n back(config?: AnimeConfig<State>): void {\n this.to(this.defaultState as Partial<State>, config)\n }\n\n private stop(): boolean {\n if (!this.frameId) return false\n cancelAnimationFrame(this.frameId)\n this.frameId = undefined\n return true\n }\n\n static readonly easing = {\n linear: (p: number) => p,\n easeInQuad: (p: number) => p * p,\n easeOutQuad: (p: number) => p * (2 - p),\n easeInOutQuad: (p: number) => (p < 0.5 ? 2 * p * p : -1 + (4 - 2 * p) * p),\n easeInBack: (p: number) => p * p * ((2.70158 + 1) * p - 1),\n easeOutBack: (p: number) => 1 + 2.70158 * Math.pow(p - 1, 3) + 1.70158 * Math.pow(p - 1, 2),\n easeInOutBack: (p: number) => {\n const c1 = 1.70158\n const c2 = c1 * 1.525\n return p < 0.5\n ? (Math.pow(2 * p, 2) * ((c2 + 1) * 2 * p - c2)) / 2\n : (Math.pow(2 * p - 2, 2) * ((c2 + 1) * (p * 2 - 2) + c2) + 2) / 2\n }\n }\n}\n"],"mappings":";AAeA,IAAa,QAAb,MAAa,MAAqE;CAChF;CACA,WAAqB;CACrB;CACA;CACA;CACA;CACA;CAEA,YAAY,OAAc,QAA6B;AACrD,OAAK,QAAQ;AACb,OAAK,eAAe,EAAE,GAAG,OAAO;EAChC,MAAM,EAAE,UAAU,UAAU,YAAY,mBAAmB,UAAU,EAAE;AACvE,MAAI,aAAa,KAAA,EAAW,MAAK,WAAW;AAC5C,MAAI,aAAa,KAAA,EAAW,MAAK,WAAW;AAC5C,MAAI,eAAe,KAAA,EAAW,MAAK,aAAa;AAChD,OAAK,iBAAiB,kBAAkB,MAAM,OAAO;;CAGvD,IAAc,SAIL;EACP,MAAM,QAAQ,YAAY,KAAK;EAC/B,MAAM,EAAE,YAAY,MAAM,aAAa;EACvC,MAAM,UAAU,cAAsB;GACpC,MAAM,UAAU,YAAY;GAC5B,MAAM,WAAW,KAAK,IAAI,UAAU,UAAU,EAAE;AAChD,QAAK,SAAS;AACd,OAAI,WAAW,EACb,MAAK,UAAU,sBAAsB,OAAO;QACvC;AACL,SAAK,SAAS;AACd,SAAK,MAAM;AACX,gBAAY;;;AAGhB,OAAK,UAAU,sBAAsB,OAAO;;CAG9C,GAAG,OAAuB,QAAmC;AAC3D,OAAK,MAAM;EACX,MAAM,YAAY,EAAE,GAAG,KAAK,OAAO;EACnC,MAAM,gBAAgB,OAAO,KAAK,MAAM,CAAC,QACtC,KAAK,QAAQ;GACZ,MAAM,IAAI;GACV,MAAM,KAAK,MAAM;GACjB,MAAM,KAAK,UAAU;AACrB,QAAK,MAAM,OAAO,OAAO,MAAM,OAAO,GACpC,KAAI,OAAO,KAAK;AAElB,UAAO;KAET,EAAE,CACH;EACD,MAAM,WAAW,QAAQ,YAAY,KAAK;EAC1C,MAAM,iBAAiB,QAAQ,kBAAkB,KAAK;EACtD,MAAM,aAAa,QAAQ,cAAc,KAAK;AAC9C,OAAK,IAAI;GACP;GACA,kBAAkB;AAChB,SAAK,MAAM,OAAO,MAChB,KAAI,OAAO,KAAK,MACZ,MAAK,MAAiC,OAAO,MAAM;AAGzD,SAAK,WAAW,KAAK,MAAM;AAC3B,iBAAa,KAAK,MAAM;;GAE1B,OAAO,aAAa;AAClB,SAAK,MAAM,OAAO,eAAe;KAE/B,MAAM,SAAU,UADL,OACgC,eAAe,SAAS,GAAG,cAAc;AAClF,UAAK,MAAiC,OAAO;;AAEjD,SAAK,WAAW,KAAK,MAAM;;GAE9B,CAAC;;CAGJ,KAAK,QAAmC;AACtC,OAAK,GAAG,KAAK,cAAgC,OAAO;;CAGtD,OAAwB;AACtB,MAAI,CAAC,KAAK,QAAS,QAAO;AAC1B,uBAAqB,KAAK,QAAQ;AAClC,OAAK,UAAU,KAAA;AACf,SAAO;;CAGT,OAAgB,SAAS;EACvB,SAAS,MAAc;EACvB,aAAa,MAAc,IAAI;EAC/B,cAAc,MAAc,KAAK,IAAI;EACrC,gBAAgB,MAAe,IAAI,KAAM,IAAI,IAAI,IAAI,MAAM,IAAI,IAAI,KAAK;EACxE,aAAa,MAAc,IAAI,KAAM,UAAe,IAAI;EACxD,cAAc,MAAc,IAAI,UAAU,KAAK,IAAI,IAAI,GAAG,EAAE,GAAG,UAAU,KAAK,IAAI,IAAI,GAAG,EAAE;EAC3F,gBAAgB,MAAc;GAE5B,MAAM,KADK,UACK;AAChB,UAAO,IAAI,KACN,KAAK,IAAI,IAAI,GAAG,EAAE,KAAK,KAAK,KAAK,IAAI,IAAI,MAAO,KAChD,KAAK,IAAI,IAAI,IAAI,GAAG,EAAE,KAAK,KAAK,MAAM,IAAI,IAAI,KAAK,MAAM,KAAK;;EAEtE"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { ShallowRef, VNode, VNodeArrayChildren } from "vue";
|
|
2
|
+
|
|
3
|
+
//#region src/helper/vue.d.ts
|
|
4
|
+
interface TextVNode extends VNode {
|
|
5
|
+
children: string;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* 是否为文本
|
|
9
|
+
* @param node
|
|
10
|
+
* @returns
|
|
11
|
+
*/
|
|
12
|
+
declare function isTextNode(node: VNode): node is TextVNode;
|
|
13
|
+
/**
|
|
14
|
+
* 是否为片段
|
|
15
|
+
* @param node
|
|
16
|
+
* @returns
|
|
17
|
+
*/
|
|
18
|
+
declare function isFragment(node: any): node is VNode;
|
|
19
|
+
interface CommentVNode extends VNode {
|
|
20
|
+
children: string;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* 是否为注释
|
|
24
|
+
* @param node
|
|
25
|
+
* @returns
|
|
26
|
+
*/
|
|
27
|
+
declare function isComment(node: VNode): node is CommentVNode;
|
|
28
|
+
/**
|
|
29
|
+
* 是否为模板
|
|
30
|
+
* @param node
|
|
31
|
+
* @returns
|
|
32
|
+
*/
|
|
33
|
+
declare function isTemplate(node: unknown): node is VNode;
|
|
34
|
+
/**
|
|
35
|
+
* 提取常规虚拟节点(移除type为fragment、template的节点)
|
|
36
|
+
* @param nodes VNodeArrayChildren
|
|
37
|
+
* @param results 虚拟节点
|
|
38
|
+
* @returns
|
|
39
|
+
*/
|
|
40
|
+
declare function extractNormalVNodes(nodes: VNodeArrayChildren, results?: VNode[]): VNode[];
|
|
41
|
+
declare function shallowComputed<T>(getter: () => T): ShallowRef<T>;
|
|
42
|
+
//#endregion
|
|
43
|
+
export { extractNormalVNodes, isComment, isFragment, isTemplate, isTextNode, shallowComputed };
|
|
44
|
+
//# sourceMappingURL=vue.d.ts.map
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { Comment, Fragment, Text, createTextVNode, isVNode, shallowRef, watch } from "vue";
|
|
2
|
+
//#region src/helper/vue.ts
|
|
3
|
+
/**
|
|
4
|
+
* 是否为文本
|
|
5
|
+
* @param node
|
|
6
|
+
* @returns
|
|
7
|
+
*/
|
|
8
|
+
function isTextNode(node) {
|
|
9
|
+
return node.type === Text;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* 是否为片段
|
|
13
|
+
* @param node
|
|
14
|
+
* @returns
|
|
15
|
+
*/
|
|
16
|
+
function isFragment(node) {
|
|
17
|
+
return node && node.type === Fragment;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* 是否为注释
|
|
21
|
+
* @param node
|
|
22
|
+
* @returns
|
|
23
|
+
*/
|
|
24
|
+
function isComment(node) {
|
|
25
|
+
return node.type === Comment;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* 是否为模板
|
|
29
|
+
* @param node
|
|
30
|
+
* @returns
|
|
31
|
+
*/
|
|
32
|
+
function isTemplate(node) {
|
|
33
|
+
return isVNode(node) && node.type === "template";
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* 提取常规虚拟节点(移除type为fragment、template的节点)
|
|
37
|
+
* @param nodes VNodeArrayChildren
|
|
38
|
+
* @param results 虚拟节点
|
|
39
|
+
* @returns
|
|
40
|
+
*/
|
|
41
|
+
function extractNormalVNodes(nodes, results = []) {
|
|
42
|
+
nodes.forEach((node) => {
|
|
43
|
+
if (!isVNode(node)) {
|
|
44
|
+
if (typeof node === "string" || typeof node === "number") results.push(createTextVNode(String(node)));
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
if ((isFragment(node) || isTemplate(node)) && Array.isArray(node.children)) extractNormalVNodes(node.children, results);
|
|
48
|
+
else results.push(node);
|
|
49
|
+
});
|
|
50
|
+
return results;
|
|
51
|
+
}
|
|
52
|
+
function shallowComputed(getter) {
|
|
53
|
+
const result = shallowRef(getter());
|
|
54
|
+
watch(getter, (value) => {
|
|
55
|
+
result.value = value;
|
|
56
|
+
});
|
|
57
|
+
return result;
|
|
58
|
+
}
|
|
59
|
+
//#endregion
|
|
60
|
+
export { extractNormalVNodes, isComment, isFragment, isTemplate, isTextNode, shallowComputed };
|
|
61
|
+
|
|
62
|
+
//# sourceMappingURL=vue.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vue.js","names":[],"sources":["../../src/helper/vue.ts"],"sourcesContent":["import {\n Text,\n Fragment,\n Comment,\n type VNode,\n isVNode,\n createTextVNode,\n type VNodeArrayChildren,\n shallowRef,\n watch,\n type ShallowRef\n} from 'vue'\n\ninterface TextVNode extends VNode {\n children: string\n}\n\n/**\n * 是否为文本\n * @param node\n * @returns\n */\nexport function isTextNode(node: VNode): node is TextVNode {\n return node.type === Text\n}\n\n/**\n * 是否为片段\n * @param node\n * @returns\n */\nexport function isFragment(node: any): node is VNode {\n return node && node.type === Fragment\n}\n\ninterface CommentVNode extends VNode {\n children: string\n}\n\n/**\n * 是否为注释\n * @param node\n * @returns\n */\nexport function isComment(node: VNode): node is CommentVNode {\n return node.type === Comment\n}\n\n/**\n * 是否为模板\n * @param node\n * @returns\n */\nexport function isTemplate(node: unknown): node is VNode {\n return isVNode(node) && node.type === 'template'\n}\n\n/**\n * 提取常规虚拟节点(移除type为fragment、template的节点)\n * @param nodes VNodeArrayChildren\n * @param results 虚拟节点\n * @returns\n */\nexport function extractNormalVNodes(nodes: VNodeArrayChildren, results: VNode[] = []): VNode[] {\n nodes.forEach((node) => {\n if (!isVNode(node)) {\n if (typeof node === 'string' || typeof node === 'number') {\n results.push(createTextVNode(String(node)))\n }\n return\n }\n if ((isFragment(node) || isTemplate(node)) && Array.isArray(node.children)) {\n extractNormalVNodes(node.children, results)\n } else {\n results.push(node)\n }\n })\n return results\n}\n\nexport function shallowComputed<T>(getter: () => T): ShallowRef<T> {\n const result = shallowRef<T>(getter())\n watch(getter, (value) => {\n result.value = value\n })\n\n return result\n}\n"],"mappings":";;;;;;;AAsBA,SAAgB,WAAW,MAAgC;AACzD,QAAO,KAAK,SAAS;;;;;;;AAQvB,SAAgB,WAAW,MAA0B;AACnD,QAAO,QAAQ,KAAK,SAAS;;;;;;;AAY/B,SAAgB,UAAU,MAAmC;AAC3D,QAAO,KAAK,SAAS;;;;;;;AAQvB,SAAgB,WAAW,MAA8B;AACvD,QAAO,QAAQ,KAAK,IAAI,KAAK,SAAS;;;;;;;;AASxC,SAAgB,oBAAoB,OAA2B,UAAmB,EAAE,EAAW;AAC7F,OAAM,SAAS,SAAS;AACtB,MAAI,CAAC,QAAQ,KAAK,EAAE;AAClB,OAAI,OAAO,SAAS,YAAY,OAAO,SAAS,SAC9C,SAAQ,KAAK,gBAAgB,OAAO,KAAK,CAAC,CAAC;AAE7C;;AAEF,OAAK,WAAW,KAAK,IAAI,WAAW,KAAK,KAAK,MAAM,QAAQ,KAAK,SAAS,CACxE,qBAAoB,KAAK,UAAU,QAAQ;MAE3C,SAAQ,KAAK,KAAK;GAEpB;AACF,QAAO;;AAGT,SAAgB,gBAAmB,QAAgC;CACjE,MAAM,SAAS,WAAc,QAAQ,CAAC;AACtC,OAAM,SAAS,UAAU;AACvB,SAAO,QAAQ;GACf;AAEF,QAAO"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { BEM, BEMFactory, makeBEM } from "./helper/make-bem.js";
|
|
2
|
+
import { CLS_PREFIX, FORM_EMPTY_CONTENT, NAME_SPACE } from "./shared/constants.js";
|
|
3
|
+
import { addClass, bem, removeClass } from "./dom/class-name.js";
|
|
4
|
+
import { getHighlightChunks } from "./dom/highlight.js";
|
|
5
|
+
import { getNearestScrollParent, getScrollParents, scrollIntoContainerView } from "./dom/position.js";
|
|
6
|
+
import { removeStyles, setStyles, withUnit } from "./dom/style.js";
|
|
7
|
+
import { zIndex } from "./dom/z-index.js";
|
|
8
|
+
import { Data, PresetRule, ValidateRule, ValidatorConfig } from "./types/utils/form/validate.js";
|
|
9
|
+
import { Validator } from "./form/validate.js";
|
|
10
|
+
import { createIncrease } from "./helper/create-increase.js";
|
|
11
|
+
import { createToggle } from "./helper/create-toggle.js";
|
|
12
|
+
import { AnimeConfig, Tween, TweenConfig } from "./helper/tween.js";
|
|
13
|
+
import { nextFrame } from "./helper/frame.js";
|
|
14
|
+
import { extractNormalVNodes, isComment, isFragment, isTemplate, isTextNode, shallowComputed } from "./helper/vue.js";
|
|
15
|
+
import { middleProxy } from "./reactive/proxy.js";
|
|
16
|
+
import { DeconstructValue, DefineEvent, Index, Null, RenderReturn, Undef } from "./types/helper.js";
|
|
17
|
+
import { BreakpointName, ColorType, ComponentProps, ComponentSize, FormComponentProps, PropsWithServerQuery } from "./types/component-common.js";
|
|
18
|
+
import { FormContextInjectProps } from "./types/form-context.js";
|
|
19
|
+
export { AnimeConfig, BEM, BEMFactory, BreakpointName, CLS_PREFIX, ColorType, ComponentProps, ComponentSize, Data, DeconstructValue, DefineEvent, FORM_EMPTY_CONTENT, FormComponentProps, FormContextInjectProps, Index, NAME_SPACE, Null, PresetRule, PropsWithServerQuery, RenderReturn, Tween, TweenConfig, Undef, ValidateRule, Validator, ValidatorConfig, addClass, bem, createIncrease, createToggle, extractNormalVNodes, getHighlightChunks, getNearestScrollParent, getScrollParents, isComment, isFragment, isTemplate, isTextNode, makeBEM, middleProxy, nextFrame, removeClass, removeStyles, scrollIntoContainerView, setStyles, shallowComputed, withUnit, zIndex };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { makeBEM } from "./helper/make-bem.js";
|
|
2
|
+
import { CLS_PREFIX, FORM_EMPTY_CONTENT, NAME_SPACE } from "./shared/constants.js";
|
|
3
|
+
import { addClass, bem, removeClass } from "./dom/class-name.js";
|
|
4
|
+
import { getHighlightChunks } from "./dom/highlight.js";
|
|
5
|
+
import { getNearestScrollParent, getScrollParents, scrollIntoContainerView } from "./dom/position.js";
|
|
6
|
+
import { removeStyles, setStyles, withUnit } from "./dom/style.js";
|
|
7
|
+
import { createIncrease } from "./helper/create-increase.js";
|
|
8
|
+
import { zIndex } from "./dom/z-index.js";
|
|
9
|
+
import { Validator } from "./form/validate.js";
|
|
10
|
+
import { createToggle } from "./helper/create-toggle.js";
|
|
11
|
+
import { Tween } from "./helper/tween.js";
|
|
12
|
+
import { nextFrame } from "./helper/frame.js";
|
|
13
|
+
import { extractNormalVNodes, isComment, isFragment, isTemplate, isTextNode, shallowComputed } from "./helper/vue.js";
|
|
14
|
+
import { middleProxy } from "./reactive/proxy.js";
|
|
15
|
+
export { CLS_PREFIX, FORM_EMPTY_CONTENT, NAME_SPACE, Tween, Validator, addClass, bem, createIncrease, createToggle, extractNormalVNodes, getHighlightChunks, getNearestScrollParent, getScrollParents, isComment, isFragment, isTemplate, isTextNode, makeBEM, middleProxy, nextFrame, removeClass, removeStyles, scrollIntoContainerView, setStyles, shallowComputed, withUnit, zIndex };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
//#region src/reactive/proxy.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* 中间代理, 用于vue的reactive和shallowReactive方法的中间层
|
|
4
|
+
* @param o 代理对象
|
|
5
|
+
* @param config 代理配置
|
|
6
|
+
* @returns
|
|
7
|
+
*/
|
|
8
|
+
declare function middleProxy<O extends Record<string, any>>(o: O, handler?: {
|
|
9
|
+
set?: (field: string, val: any) => void;
|
|
10
|
+
get?: (field: string) => any;
|
|
11
|
+
/**
|
|
12
|
+
* 数值变更回调,传入的参数是本次模型值变更的所有字段
|
|
13
|
+
* @param fields 变更的字段
|
|
14
|
+
*/
|
|
15
|
+
changed?: (fields: string[]) => void;
|
|
16
|
+
}): O;
|
|
17
|
+
//#endregion
|
|
18
|
+
export { middleProxy };
|
|
19
|
+
//# sourceMappingURL=proxy.d.ts.map
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
//#region src/reactive/proxy.ts
|
|
2
|
+
/**
|
|
3
|
+
* 创建一个介于vue的reactive和shallowReactive对象的中间层
|
|
4
|
+
* @description
|
|
5
|
+
* 如果对象含有嵌套对象,则**递归**进行中间代理
|
|
6
|
+
*
|
|
7
|
+
* @param o 代理对象
|
|
8
|
+
* @param handler 处理函数
|
|
9
|
+
* @param options 代理配置
|
|
10
|
+
* @returns 中间代理对象
|
|
11
|
+
*/
|
|
12
|
+
function createMiddleProxy(o, handler, options) {
|
|
13
|
+
let { weakMap, parentsField, changedFields = [] } = options || {};
|
|
14
|
+
if (!weakMap) weakMap = /* @__PURE__ */ new WeakMap();
|
|
15
|
+
return new Proxy(o, {
|
|
16
|
+
set(target, field, val) {
|
|
17
|
+
const changedField = parentsField ? `${parentsField}.${field}` : field;
|
|
18
|
+
handler?.set?.(changedField, val);
|
|
19
|
+
target[field] = val;
|
|
20
|
+
changedFields.push(changedField);
|
|
21
|
+
Promise.resolve().then(() => {
|
|
22
|
+
if (!changedFields.length) return;
|
|
23
|
+
handler?.changed?.([...changedFields]);
|
|
24
|
+
changedFields.splice(0);
|
|
25
|
+
});
|
|
26
|
+
return true;
|
|
27
|
+
},
|
|
28
|
+
get(target, field) {
|
|
29
|
+
handler?.get?.(field);
|
|
30
|
+
const val = target[field];
|
|
31
|
+
if (val !== null && typeof val === "object" && !(val instanceof Date) && !(val instanceof RegExp)) {
|
|
32
|
+
if (weakMap.has(val)) return weakMap.get(val);
|
|
33
|
+
const valProxy = createMiddleProxy(val, handler, {
|
|
34
|
+
weakMap,
|
|
35
|
+
parentsField: parentsField ? `${parentsField}.${field}` : field,
|
|
36
|
+
changedFields
|
|
37
|
+
});
|
|
38
|
+
weakMap.set(val, valProxy);
|
|
39
|
+
return valProxy;
|
|
40
|
+
}
|
|
41
|
+
return val;
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* 中间代理, 用于vue的reactive和shallowReactive方法的中间层
|
|
47
|
+
* @param o 代理对象
|
|
48
|
+
* @param config 代理配置
|
|
49
|
+
* @returns
|
|
50
|
+
*/
|
|
51
|
+
function middleProxy(o, handler) {
|
|
52
|
+
return createMiddleProxy(o, handler);
|
|
53
|
+
}
|
|
54
|
+
//#endregion
|
|
55
|
+
export { middleProxy };
|
|
56
|
+
|
|
57
|
+
//# sourceMappingURL=proxy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"proxy.js","names":[],"sources":["../../src/reactive/proxy.ts"],"sourcesContent":["/**\n * 创建一个介于vue的reactive和shallowReactive对象的中间层\n * @description\n * 如果对象含有嵌套对象,则**递归**进行中间代理\n *\n * @param o 代理对象\n * @param handler 处理函数\n * @param options 代理配置\n * @returns 中间代理对象\n */\nfunction createMiddleProxy(\n o: Record<string, any>,\n handler?: {\n set?: (field: string, val: any) => void\n get?: (field: string) => any\n changed?: (fields: string[]) => void\n },\n options?: {\n weakMap?: WeakMap<Record<string, any>, any>\n parentsField?: string\n changedFields?: string[]\n }\n) {\n let { weakMap, parentsField, changedFields = [] } = options || {}\n if (!weakMap) {\n weakMap = new WeakMap()\n }\n\n return new Proxy(o, {\n set(target, field: string, val) {\n const changedField = parentsField ? `${parentsField}.${field}` : field\n handler?.set?.(changedField, val)\n target[field] = val\n\n changedFields.push(changedField)\n Promise.resolve().then(() => {\n if (!changedFields.length) return\n handler?.changed?.([...changedFields])\n changedFields.splice(0)\n })\n\n return true\n },\n\n get(target, field: string) {\n handler?.get?.(field)\n\n const val = target[field]\n if (\n val !== null &&\n typeof val === 'object' &&\n !(val instanceof Date) &&\n !(val instanceof RegExp)\n ) {\n if (weakMap.has(val)) return weakMap.get(val)\n const valProxy = createMiddleProxy(val, handler, {\n weakMap,\n parentsField: parentsField ? `${parentsField}.${field}` : field,\n changedFields\n })\n weakMap.set(val, valProxy)\n\n return valProxy\n }\n\n return val\n }\n })\n}\n\n/**\n * 中间代理, 用于vue的reactive和shallowReactive方法的中间层\n * @param o 代理对象\n * @param config 代理配置\n * @returns\n */\nexport function middleProxy<O extends Record<string, any>>(\n o: O,\n handler?: {\n set?: (field: string, val: any) => void\n get?: (field: string) => any\n /**\n * 数值变更回调,传入的参数是本次模型值变更的所有字段\n * @param fields 变更的字段\n */\n changed?: (fields: string[]) => void\n }\n): O {\n return createMiddleProxy(o, handler) as O\n}\n"],"mappings":";;;;;;;;;;;AAUA,SAAS,kBACP,GACA,SAKA,SAKA;CACA,IAAI,EAAE,SAAS,cAAc,gBAAgB,EAAE,KAAK,WAAW,EAAE;AACjE,KAAI,CAAC,QACH,2BAAU,IAAI,SAAS;AAGzB,QAAO,IAAI,MAAM,GAAG;EAClB,IAAI,QAAQ,OAAe,KAAK;GAC9B,MAAM,eAAe,eAAe,GAAG,aAAa,GAAG,UAAU;AACjE,YAAS,MAAM,cAAc,IAAI;AACjC,UAAO,SAAS;AAEhB,iBAAc,KAAK,aAAa;AAChC,WAAQ,SAAS,CAAC,WAAW;AAC3B,QAAI,CAAC,cAAc,OAAQ;AAC3B,aAAS,UAAU,CAAC,GAAG,cAAc,CAAC;AACtC,kBAAc,OAAO,EAAE;KACvB;AAEF,UAAO;;EAGT,IAAI,QAAQ,OAAe;AACzB,YAAS,MAAM,MAAM;GAErB,MAAM,MAAM,OAAO;AACnB,OACE,QAAQ,QACR,OAAO,QAAQ,YACf,EAAE,eAAe,SACjB,EAAE,eAAe,SACjB;AACA,QAAI,QAAQ,IAAI,IAAI,CAAE,QAAO,QAAQ,IAAI,IAAI;IAC7C,MAAM,WAAW,kBAAkB,KAAK,SAAS;KAC/C;KACA,cAAc,eAAe,GAAG,aAAa,GAAG,UAAU;KAC1D;KACD,CAAC;AACF,YAAQ,IAAI,KAAK,SAAS;AAE1B,WAAO;;AAGT,UAAO;;EAEV,CAAC;;;;;;;;AASJ,SAAgB,YACd,GACA,SASG;AACH,QAAO,kBAAkB,GAAG,QAAQ"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
//#region src/shared/constants.d.ts
|
|
2
|
+
/** 命名前缀 */
|
|
3
|
+
declare const NAME_SPACE = "U";
|
|
4
|
+
/** 类前缀 */
|
|
5
|
+
declare const CLS_PREFIX: "u-";
|
|
6
|
+
/** 表单空内容 */
|
|
7
|
+
declare const FORM_EMPTY_CONTENT = "-";
|
|
8
|
+
//#endregion
|
|
9
|
+
export { CLS_PREFIX, FORM_EMPTY_CONTENT, NAME_SPACE };
|
|
10
|
+
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
//#region src/shared/constants.ts
|
|
2
|
+
/** 命名前缀 */
|
|
3
|
+
const NAME_SPACE = "U";
|
|
4
|
+
/** 类前缀 */
|
|
5
|
+
const CLS_PREFIX = `${"U".toLowerCase()}-`;
|
|
6
|
+
/** 表单空内容 */
|
|
7
|
+
const FORM_EMPTY_CONTENT = "-";
|
|
8
|
+
//#endregion
|
|
9
|
+
export { CLS_PREFIX, FORM_EMPTY_CONTENT, NAME_SPACE };
|
|
10
|
+
|
|
11
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","names":[],"sources":["../../src/shared/constants.ts"],"sourcesContent":["/** 命名前缀 */\nexport const NAME_SPACE = 'U'\n\n/** 类前缀 */\nexport const CLS_PREFIX = `${NAME_SPACE.toLowerCase()}-` as 'u-'\n\n/** 表单空内容 */\nexport const FORM_EMPTY_CONTENT = '-'\n"],"mappings":";;AACA,MAAa,aAAa;;AAG1B,MAAa,aAAa,GAAA,IAAc,aAAa,CAAC;;AAGtD,MAAa,qBAAqB"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
//#region src/types/component-common.d.ts
|
|
2
|
+
type ComponentSize = 'small' | 'default' | 'large';
|
|
3
|
+
type ColorType = 'primary' | 'info' | 'success' | 'warning' | 'danger';
|
|
4
|
+
/** 断点名称 */
|
|
5
|
+
type BreakpointName = 'xs' | 'sm' | 'md' | 'lg' | 'xl';
|
|
6
|
+
/** 组件通用属性 */
|
|
7
|
+
interface ComponentProps {
|
|
8
|
+
/** 组件尺寸 */
|
|
9
|
+
size?: ComponentSize;
|
|
10
|
+
}
|
|
11
|
+
/** 表单组件通用属性 */
|
|
12
|
+
interface FormComponentProps extends ComponentProps {
|
|
13
|
+
/** 在表单控件内时的提示 */
|
|
14
|
+
tips?: string;
|
|
15
|
+
/** 所占列的大小 */
|
|
16
|
+
span?: number | 'full' | ({ [key in BreakpointName]?: 'full' | number } & {
|
|
17
|
+
default: number | 'full';
|
|
18
|
+
});
|
|
19
|
+
/** 表单标签文字 */
|
|
20
|
+
label?: string;
|
|
21
|
+
/** 表单项字段 */
|
|
22
|
+
field?: string;
|
|
23
|
+
/** 是否禁用 */
|
|
24
|
+
disabled?: boolean;
|
|
25
|
+
/** 是否只读 */
|
|
26
|
+
readonly?: boolean;
|
|
27
|
+
}
|
|
28
|
+
/** 带有服务端交互功能的组件属性 */
|
|
29
|
+
interface PropsWithServerQuery {
|
|
30
|
+
/** 请求接口地址 */
|
|
31
|
+
api?: string;
|
|
32
|
+
/** 请求查询参数 */
|
|
33
|
+
query?: Record<string, any>;
|
|
34
|
+
}
|
|
35
|
+
//#endregion
|
|
36
|
+
export { BreakpointName, ColorType, ComponentProps, ComponentSize, FormComponentProps, PropsWithServerQuery };
|
|
37
|
+
//# sourceMappingURL=component-common.d.ts.map
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { VNode } from "vue";
|
|
2
|
+
|
|
3
|
+
//#region src/types/helper.d.ts
|
|
4
|
+
type Null<T> = null | T;
|
|
5
|
+
type Undef<T> = undefined | T;
|
|
6
|
+
/** 自定义事件, 可以指定target类型 */
|
|
7
|
+
interface DefineEvent<T = HTMLElement> extends Omit<Event, 'target'> {
|
|
8
|
+
target: T;
|
|
9
|
+
}
|
|
10
|
+
/** 解构VueExpose中被引用的实例 */
|
|
11
|
+
type DeconstructValue<E extends Record<string, any>> = { [K in keyof E]: E[K] extends {
|
|
12
|
+
value: infer V;
|
|
13
|
+
} ? V : E[K] };
|
|
14
|
+
/** 索引类型 */
|
|
15
|
+
type Index<Keys extends string, Val> = { [key in Keys]?: Val };
|
|
16
|
+
/**
|
|
17
|
+
* 渲染函数返回内容
|
|
18
|
+
*/
|
|
19
|
+
type RenderReturn = (undefined | VNode | string | null | number)[] | undefined | VNode | string | null | number;
|
|
20
|
+
//#endregion
|
|
21
|
+
export { DeconstructValue, DefineEvent, Index, Null, RenderReturn, Undef };
|
|
22
|
+
//# sourceMappingURL=helper.d.ts.map
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { Data, PresetRule, ValidateRule, ValidatorConfig } from "./utils/form/validate.js";
|
|
2
|
+
import { DeconstructValue, DefineEvent, Index, Null, RenderReturn, Undef } from "./helper.js";
|
|
3
|
+
import { BreakpointName, ColorType, ComponentProps, ComponentSize, FormComponentProps, PropsWithServerQuery } from "./component-common.js";
|
|
4
|
+
import { FormContextInjectProps } from "./form-context.js";
|
|
5
|
+
export { BreakpointName, ColorType, ComponentProps, ComponentSize, Data, DeconstructValue, DefineEvent, FormComponentProps, FormContextInjectProps, Index, Null, PresetRule, PropsWithServerQuery, RenderReturn, Undef, ValidateRule, ValidatorConfig };
|
|
File without changes
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
//#region src/types/utils/form/validate.d.ts
|
|
2
|
+
type Data = Record<string, any>;
|
|
3
|
+
type PresetRule = 'email' | 'phone' | 'num' | 'url' | 'idCard';
|
|
4
|
+
/** 字段校验规则 */
|
|
5
|
+
interface ValidateRule {
|
|
6
|
+
/** 是否必填 */
|
|
7
|
+
required?: boolean | string;
|
|
8
|
+
/** 长度单位 */
|
|
9
|
+
length?: number | [number, string];
|
|
10
|
+
/** 最小值 */
|
|
11
|
+
min?: number | [number, string];
|
|
12
|
+
/** 最大值 */
|
|
13
|
+
max?: number | [number, string];
|
|
14
|
+
/** 最小长度 */
|
|
15
|
+
minLen?: number | [number, string];
|
|
16
|
+
/** 最大长度 */
|
|
17
|
+
maxLen?: number | [number, string];
|
|
18
|
+
/** 匹配 */
|
|
19
|
+
match?: RegExp | [RegExp, string] | string;
|
|
20
|
+
/** 预设 */
|
|
21
|
+
preset?: PresetRule;
|
|
22
|
+
/** 自定义校验 */
|
|
23
|
+
validator?: (value: any, data: Data) => Promise<string> | string;
|
|
24
|
+
}
|
|
25
|
+
interface ValidatorConfig {
|
|
26
|
+
/**
|
|
27
|
+
* 是否懒校验,为true时在任意一个字段的的任意规则校验不通过时立马结束校验,性能稍微高一点,但是不能得出所有的错误
|
|
28
|
+
* @default true
|
|
29
|
+
*/
|
|
30
|
+
lazy?: boolean;
|
|
31
|
+
}
|
|
32
|
+
//#endregion
|
|
33
|
+
export { Data, PresetRule, ValidateRule, ValidatorConfig };
|
|
34
|
+
//# sourceMappingURL=validate.d.ts.map
|