y-design-ssr 0.2.5 → 0.2.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/libs/button/index.css +579 -1
- package/libs/button/index.mjs +111 -66
- package/libs/button/index.umd.js +203 -2
- package/libs/button/package.json +1 -1
- package/libs/{types/components/button → button}/src/button.d.ts +1 -1
- package/libs/cell/index.css +1077 -1
- package/libs/{types/components/cell → cell}/index.d.ts +1 -0
- package/libs/cell/index.mjs +168 -104
- package/libs/cell/index.umd.js +301 -2
- package/libs/cell/package.json +1 -1
- package/libs/{types/components/cell → cell}/src/cell.d.ts +1 -1
- package/libs/checkbox/index.css +1053 -1
- package/libs/{types/components/checkbox → checkbox}/index.d.ts +1 -0
- package/libs/checkbox/index.mjs +243 -127
- package/libs/checkbox/index.umd.js +370 -2
- package/libs/checkbox/package.json +1 -1
- package/libs/checkboxGroup/index.css +422 -1
- package/libs/{types/components/checkboxGroup → checkboxGroup}/index.d.ts +1 -0
- package/libs/checkboxGroup/index.mjs +174 -87
- package/libs/checkboxGroup/index.umd.js +266 -2
- package/libs/checkboxGroup/package.json +1 -1
- package/libs/col/index.css +615 -1
- package/libs/{types/components/col → col}/index.d.ts +1 -0
- package/libs/col/index.mjs +247 -81
- package/libs/col/index.umd.js +306 -2
- package/libs/col/package.json +1 -1
- package/libs/countdown/index.css +417 -1
- package/libs/{types/components/countdown → countdown}/index.d.ts +1 -0
- package/libs/countdown/index.mjs +180 -71
- package/libs/countdown/index.umd.js +232 -2
- package/libs/countdown/package.json +1 -1
- package/libs/dialog/index.css +1405 -1
- package/libs/{types/components/dialog → dialog}/index.d.ts +1 -0
- package/libs/dialog/index.mjs +647 -476
- package/libs/dialog/index.umd.js +1129 -2
- package/libs/dialog/package.json +1 -1
- package/libs/{types/components/dialog → dialog}/src/dialog.d.ts +1 -1
- package/libs/empty/index.css +457 -1
- package/libs/{types/components/empty → empty}/index.d.ts +1 -0
- package/libs/empty/index.mjs +92 -44
- package/libs/empty/index.umd.js +140 -2
- package/libs/empty/package.json +1 -1
- package/libs/form/index.css +477 -1
- package/libs/{types/components/form → form}/index.d.ts +1 -0
- package/libs/form/index.mjs +227 -126
- package/libs/form/index.umd.js +320 -2
- package/libs/form/package.json +1 -1
- package/libs/formItem/index.css +477 -1
- package/libs/{types/components/formItem → formItem}/index.d.ts +1 -0
- package/libs/formItem/index.mjs +277 -126
- package/libs/formItem/index.umd.js +373 -2
- package/libs/formItem/package.json +1 -1
- package/libs/icon/index.css +982 -1
- package/libs/{types/components/icon → icon}/index.d.ts +1 -0
- package/libs/icon/index.mjs +108 -58
- package/libs/icon/index.umd.js +187 -2
- package/libs/icon/package.json +1 -1
- package/libs/index.css +2902 -1
- package/libs/index.d.ts +86 -3
- package/libs/index.mjs +3785 -2344
- package/libs/index.umd.js +5509 -2
- package/libs/input/index.css +483 -1
- package/libs/{types/components/input → input}/index.d.ts +1 -0
- package/libs/input/index.mjs +184 -92
- package/libs/input/index.umd.js +275 -2
- package/libs/input/package.json +1 -1
- package/libs/layout/index.css +684 -1
- package/libs/layout/index.mjs +230 -130
- package/libs/layout/index.umd.js +318 -2
- package/libs/layout/package.json +1 -1
- package/libs/list/index.css +440 -1
- package/libs/{types/components/list → list}/index.d.ts +1 -0
- package/libs/list/index.mjs +389 -207
- package/libs/list/index.umd.js +572 -2
- package/libs/list/package.json +1 -1
- package/libs/loading/index.css +548 -1
- package/libs/{types/components/loading → loading}/index.d.ts +1 -0
- package/libs/loading/index.mjs +197 -118
- package/libs/loading/index.umd.js +322 -2
- package/libs/loading/package.json +1 -1
- package/libs/{types/components/loading → loading}/src/loading.d.ts +1 -1
- package/libs/mask/index.css +426 -1
- package/libs/{types/components/mask → mask}/index.d.ts +1 -0
- package/libs/mask/index.mjs +132 -70
- package/libs/mask/index.umd.js +202 -2
- package/libs/mask/package.json +1 -1
- package/libs/popup/index.css +465 -1
- package/libs/{types/components/popup → popup}/index.d.ts +1 -0
- package/libs/popup/index.mjs +211 -134
- package/libs/popup/index.umd.js +359 -2
- package/libs/popup/package.json +1 -1
- package/libs/{types/components/popup → popup}/src/popup.d.ts +1 -1
- package/libs/progress/index.css +488 -1
- package/libs/{types/components/progress → progress}/index.d.ts +1 -0
- package/libs/progress/index.mjs +201 -128
- package/libs/progress/index.umd.js +323 -2
- package/libs/progress/package.json +1 -1
- package/libs/pullrefresh/index.css +441 -1
- package/libs/{types/components/pullrefresh → pullrefresh}/index.d.ts +1 -0
- package/libs/pullrefresh/index.mjs +242 -111
- package/libs/pullrefresh/index.umd.js +303 -2
- package/libs/pullrefresh/package.json +1 -1
- package/libs/row/index.css +485 -1
- package/libs/{types/components/row → row}/index.d.ts +1 -0
- package/libs/row/index.mjs +182 -89
- package/libs/row/index.umd.js +238 -2
- package/libs/row/package.json +1 -1
- package/libs/{types/components/row → row}/src/row.d.ts +1 -1
- package/libs/slider/index.css +558 -1
- package/libs/{types/components/slider → slider}/index.d.ts +1 -0
- package/libs/slider/index.mjs +357 -160
- package/libs/slider/index.umd.js +454 -2
- package/libs/slider/package.json +1 -1
- package/libs/stepper/index.css +489 -1
- package/libs/{types/components/stepper → stepper}/index.d.ts +1 -0
- package/libs/stepper/index.mjs +182 -101
- package/libs/stepper/index.umd.js +270 -2
- package/libs/stepper/package.json +1 -1
- package/libs/swipe/index.css +506 -1
- package/libs/{types/components/swipe → swipe}/index.d.ts +1 -0
- package/libs/swipe/index.mjs +543 -259
- package/libs/swipe/index.umd.js +704 -2
- package/libs/swipe/package.json +1 -1
- package/libs/swipeItem/index.css +424 -1
- package/libs/{types/components/swipeItem → swipeItem}/index.d.ts +1 -0
- package/libs/swipeItem/index.mjs +112 -52
- package/libs/swipeItem/index.umd.js +155 -2
- package/libs/swipeItem/package.json +1 -1
- package/libs/switch/index.css +472 -1
- package/libs/{types/components/switch → switch}/index.d.ts +1 -0
- package/libs/switch/index.mjs +122 -62
- package/libs/switch/index.umd.js +201 -2
- package/libs/switch/package.json +1 -1
- package/libs/{types/components/switch → switch}/src/switch.d.ts +1 -1
- package/libs/{types/components/tab → tab}/index.d.ts +1 -0
- package/libs/tab/index.mjs +132 -68
- package/libs/tab/index.umd.js +191 -1
- package/libs/tab/package.json +1 -1
- package/libs/tabs/index.css +514 -1
- package/libs/{types/components/tabs → tabs}/index.d.ts +1 -0
- package/libs/tabs/index.mjs +752 -410
- package/libs/tabs/index.umd.js +1021 -2
- package/libs/tabs/package.json +1 -1
- package/libs/toast/index.css +1050 -1
- package/libs/{types/components/toast → toast}/index.d.ts +1 -0
- package/libs/toast/index.mjs +184 -114
- package/libs/toast/index.umd.js +307 -2
- package/libs/toast/package.json +1 -1
- package/libs/{types/components/toast → toast}/src/toast.d.ts +1 -1
- package/libs/tooltip/index.css +514 -1
- package/libs/{types/components/tooltip → tooltip}/index.d.ts +1 -0
- package/libs/tooltip/index.mjs +294 -155
- package/libs/tooltip/index.umd.js +417 -2
- package/libs/tooltip/package.json +1 -1
- package/libs/vue-sfc.d.ts +12 -0
- package/libs/vue-tsx.d.ts +42 -0
- package/package.json +2 -2
- package/libs/types/index.d.ts +0 -86
- /package/libs/{types/components/button → button}/index.d.ts +0 -0
- /package/libs/{types/components/checkbox → checkbox}/src/checkbox.d.ts +0 -0
- /package/libs/{types/components/checkboxGroup → checkboxGroup}/src/checkboxGroup.d.ts +0 -0
- /package/libs/{types/components/checkboxGroup → checkboxGroup}/src/constants.d.ts +0 -0
- /package/libs/{types/components/col → col}/src/col.d.ts +0 -0
- /package/libs/{types/context → context}/filed/constants.d.ts +0 -0
- /package/libs/{types/context → context}/filed/index.d.ts +0 -0
- /package/libs/{types/context → context}/filed/inject.d.ts +0 -0
- /package/libs/{types/context → context}/filed/provide.d.ts +0 -0
- /package/libs/{types/context → context}/relation/index.d.ts +0 -0
- /package/libs/{types/context → context}/relation/inject.d.ts +0 -0
- /package/libs/{types/context → context}/relation/provide.d.ts +0 -0
- /package/libs/{types/components/countdown → countdown}/src/count-down.d.ts +0 -0
- /package/libs/{types/components/dialog → dialog}/src/create.d.ts +0 -0
- /package/libs/{types/components/empty → empty}/src/empty.d.ts +0 -0
- /package/libs/{types/components/empty → empty}/src/utils.d.ts +0 -0
- /package/libs/{types/components/form → form}/src/constants.d.ts +0 -0
- /package/libs/{types/components/form → form}/src/form.d.ts +0 -0
- /package/libs/{types/components/formItem → formItem}/src/formItem.d.ts +0 -0
- /package/libs/{types/hooks → hooks}/touch/index.d.ts +0 -0
- /package/libs/{types/components/icon → icon}/src/icon.d.ts +0 -0
- /package/libs/{types/components/input → input}/src/input.d.ts +0 -0
- /package/libs/{types/components/list → list}/src/list.d.ts +0 -0
- /package/libs/{types/components/loading → loading}/src/create.d.ts +0 -0
- /package/libs/{types/components/loading → loading}/src/directive.d.ts +0 -0
- /package/libs/{types/locale → locale}/index.d.ts +0 -0
- /package/libs/{types/locale → locale}/lang/zh-CN.d.ts +0 -0
- /package/libs/{types/components/mask → mask}/src/mask.d.ts +0 -0
- /package/libs/{types/components/progress → progress}/src/progress.d.ts +0 -0
- /package/libs/{types/components/pullrefresh → pullrefresh}/src/pullrefresh.d.ts +0 -0
- /package/libs/{types/components/pullrefresh → pullrefresh}/src/utils.d.ts +0 -0
- /package/libs/{types/components/row → row}/src/constants.d.ts +0 -0
- /package/libs/{types/components/slider → slider}/src/slider.d.ts +0 -0
- /package/libs/{types/components/stepper → stepper}/src/stepper.d.ts +0 -0
- /package/libs/{types/style → style}/index.d.ts +0 -0
- /package/libs/{types/components/swipe → swipe}/src/constants.d.ts +0 -0
- /package/libs/{types/components/swipe → swipe}/src/swipe.d.ts +0 -0
- /package/libs/{types/components/swipeItem → swipeItem}/src/swipeItem.d.ts +0 -0
- /package/libs/{types/components/tab → tab}/src/tab.d.ts +0 -0
- /package/libs/{types/components/tabs → tabs}/src/constants.d.ts +0 -0
- /package/libs/{types/components/tabs → tabs}/src/tabs.d.ts +0 -0
- /package/libs/{types/components/tabs → tabs}/src/title.d.ts +0 -0
- /package/libs/{types/components/toast → toast}/src/create.d.ts +0 -0
- /package/libs/{types/components/tooltip → tooltip}/src/constants.d.ts +0 -0
- /package/libs/{types/components/tooltip → tooltip}/src/direactive.d.ts +0 -0
- /package/libs/{types/components/tooltip → tooltip}/src/popper.d.ts +0 -0
- /package/libs/{types/components/tooltip → tooltip}/src/tooltip.d.ts +0 -0
- /package/libs/{types/utils → utils}/create/bem.d.ts +0 -0
- /package/libs/{types/utils → utils}/create/index.d.ts +0 -0
- /package/libs/{types/utils → utils}/index.d.ts +0 -0
- /package/libs/{types/utils → utils}/is.d.ts +0 -0
- /package/libs/{types/utils → utils}/parseFlexDirection.d.ts +0 -0
- /package/libs/{types/utils → utils}/parseUnit.d.ts +0 -0
- /package/libs/{types/utils → utils}/types.d.ts +0 -0
package/libs/formItem/index.mjs
CHANGED
|
@@ -1,11 +1,48 @@
|
|
|
1
|
-
import { ref
|
|
2
|
-
const
|
|
3
|
-
(
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import { ref, reactive, inject, getCurrentInstance, onUnmounted, computed, provide, defineComponent, createVNode } from "vue";
|
|
2
|
+
const tagTester = (name2) => {
|
|
3
|
+
return (obj) => {
|
|
4
|
+
return Object.prototype.toString.call(obj) === `[object ${name2}]`;
|
|
5
|
+
};
|
|
6
|
+
};
|
|
7
|
+
const isFunction = tagTester("Function");
|
|
8
|
+
const isString = tagTester("String");
|
|
9
|
+
const isObject = tagTester("Object");
|
|
10
|
+
const getMods = (el, mods) => {
|
|
11
|
+
if (!mods) {
|
|
12
|
+
return "";
|
|
13
|
+
}
|
|
14
|
+
if (typeof mods === "string") {
|
|
15
|
+
return ` ${el}--${mods}`;
|
|
16
|
+
}
|
|
17
|
+
if (Array.isArray(mods)) {
|
|
18
|
+
return mods.reduce((acc, cur) => acc + getMods(el, cur), "");
|
|
19
|
+
}
|
|
20
|
+
return Object.keys(mods).reduce(
|
|
21
|
+
(acc, cur) => acc + (mods[cur] ? getMods(el, cur) : ""),
|
|
22
|
+
""
|
|
23
|
+
);
|
|
24
|
+
};
|
|
25
|
+
const createBEM = (block) => {
|
|
26
|
+
return (el, mods) => {
|
|
27
|
+
let _el = el;
|
|
28
|
+
let _mods = mods;
|
|
29
|
+
if (_el && typeof _el !== "string") {
|
|
30
|
+
_mods = _el;
|
|
31
|
+
_el = "";
|
|
32
|
+
}
|
|
33
|
+
_el = _el ? `${block}__${_el}` : block;
|
|
34
|
+
return `${_el}${getMods(_el, _mods)}`;
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
const createGlobalBem = () => {
|
|
38
|
+
return (el, mods) => {
|
|
39
|
+
if (!mods) {
|
|
40
|
+
return `y-${el}`;
|
|
41
|
+
}
|
|
42
|
+
return `${getMods(`y-${el}`, mods)}`;
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
const defaultLang = {
|
|
9
46
|
"pull-refresh": {
|
|
10
47
|
pulling: "下拉刷新...",
|
|
11
48
|
loosing: "释放刷新...",
|
|
@@ -16,56 +53,77 @@ const O = (t) => (e) => Object.prototype.toString.call(e) === `[object ${t}]`, L
|
|
|
16
53
|
"form-item": {
|
|
17
54
|
validateMessage: "请输入正确内容"
|
|
18
55
|
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
|
|
56
|
+
};
|
|
57
|
+
const lang = ref("zh-CN");
|
|
58
|
+
const langs = reactive({
|
|
59
|
+
"zh-CN": defaultLang
|
|
60
|
+
});
|
|
61
|
+
const locale$1 = {
|
|
22
62
|
text() {
|
|
23
|
-
return
|
|
63
|
+
return langs[lang.value];
|
|
24
64
|
},
|
|
25
|
-
use(
|
|
26
|
-
|
|
65
|
+
use(newLang, newConfigs) {
|
|
66
|
+
lang.value = newLang;
|
|
67
|
+
this.add({ [newLang]: newConfigs });
|
|
27
68
|
},
|
|
28
|
-
add(
|
|
29
|
-
Object.assign(
|
|
69
|
+
add(newConfigs = {}) {
|
|
70
|
+
Object.assign(langs, newConfigs);
|
|
30
71
|
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
72
|
+
};
|
|
73
|
+
const createNamespace = (name2) => {
|
|
74
|
+
const prefixedName = `y-${name2}`;
|
|
75
|
+
return [prefixedName, createBEM(prefixedName), createGlobalBem()];
|
|
76
|
+
};
|
|
77
|
+
const createLocale = (name2) => {
|
|
78
|
+
return locale$1.text()[name2];
|
|
79
|
+
};
|
|
80
|
+
const useRelation = (key) => {
|
|
81
|
+
const parent = inject(key, null);
|
|
82
|
+
const currentInstance = getCurrentInstance();
|
|
83
|
+
if (parent && currentInstance) {
|
|
84
|
+
const { childrens, addChild, removeChild } = parent;
|
|
85
|
+
addChild(currentInstance);
|
|
86
|
+
onUnmounted(() => removeChild(currentInstance));
|
|
87
|
+
const index = computed(() => childrens.indexOf(currentInstance));
|
|
88
|
+
return {
|
|
89
|
+
index,
|
|
90
|
+
parent
|
|
41
91
|
};
|
|
42
92
|
}
|
|
43
93
|
return {
|
|
44
94
|
parent: null,
|
|
45
|
-
index:
|
|
95
|
+
index: ref(-1)
|
|
96
|
+
};
|
|
97
|
+
};
|
|
98
|
+
const FORM_ITEM_PROVIDE = "y-form-item";
|
|
99
|
+
const setFormItem = () => {
|
|
100
|
+
const instance = getCurrentInstance();
|
|
101
|
+
const filed = ref();
|
|
102
|
+
const initProvide = (value) => {
|
|
103
|
+
const setField = (obj) => {
|
|
104
|
+
if (obj == null ? void 0 : obj.proxy) {
|
|
105
|
+
filed.value = obj;
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
provide(FORM_ITEM_PROVIDE, {
|
|
109
|
+
setField,
|
|
110
|
+
instance,
|
|
111
|
+
...value
|
|
112
|
+
});
|
|
46
113
|
};
|
|
47
|
-
}, Y = "y-form-item", Z = () => {
|
|
48
|
-
const t = R(), e = y();
|
|
49
114
|
return {
|
|
50
|
-
filed
|
|
51
|
-
initProvide
|
|
52
|
-
W(Y, {
|
|
53
|
-
setField: (o) => {
|
|
54
|
-
o != null && o.proxy && (e.value = o);
|
|
55
|
-
},
|
|
56
|
-
instance: t,
|
|
57
|
-
...r
|
|
58
|
-
});
|
|
59
|
-
}
|
|
115
|
+
filed,
|
|
116
|
+
initProvide
|
|
60
117
|
};
|
|
61
|
-
}
|
|
118
|
+
};
|
|
119
|
+
const commonProps = {
|
|
62
120
|
size: {
|
|
63
121
|
type: String,
|
|
64
122
|
default: null
|
|
65
123
|
},
|
|
66
124
|
border: {
|
|
67
125
|
type: Boolean,
|
|
68
|
-
default:
|
|
126
|
+
default: true
|
|
69
127
|
},
|
|
70
128
|
labelWidth: {
|
|
71
129
|
type: [Number, String],
|
|
@@ -74,7 +132,7 @@ const O = (t) => (e) => Object.prototype.toString.call(e) === `[object ${t}]`, L
|
|
|
74
132
|
colon: {
|
|
75
133
|
// 是否有 ":"
|
|
76
134
|
type: Boolean,
|
|
77
|
-
default:
|
|
135
|
+
default: false
|
|
78
136
|
},
|
|
79
137
|
labelAlign: {
|
|
80
138
|
type: String,
|
|
@@ -82,11 +140,11 @@ const O = (t) => (e) => Object.prototype.toString.call(e) === `[object ${t}]`, L
|
|
|
82
140
|
},
|
|
83
141
|
showError: {
|
|
84
142
|
type: Boolean,
|
|
85
|
-
default:
|
|
143
|
+
default: true
|
|
86
144
|
},
|
|
87
145
|
showErrorMessage: {
|
|
88
146
|
type: Boolean,
|
|
89
|
-
default:
|
|
147
|
+
default: true
|
|
90
148
|
},
|
|
91
149
|
errorMessageAlign: {
|
|
92
150
|
type: String,
|
|
@@ -96,10 +154,16 @@ const O = (t) => (e) => Object.prototype.toString.call(e) === `[object ${t}]`, L
|
|
|
96
154
|
type: [Object, Array],
|
|
97
155
|
default: null
|
|
98
156
|
}
|
|
99
|
-
}
|
|
100
|
-
|
|
157
|
+
};
|
|
158
|
+
const [name$1, bem$1] = createNamespace("form");
|
|
159
|
+
const FORM_PROVIDE = name$1;
|
|
160
|
+
const COMPONENT_NAME = "form-item";
|
|
161
|
+
const [name, bem, gbem] = createNamespace(COMPONENT_NAME);
|
|
162
|
+
const locale = createLocale(COMPONENT_NAME);
|
|
163
|
+
const FormItem = /* @__PURE__ */ defineComponent({
|
|
164
|
+
name,
|
|
101
165
|
props: {
|
|
102
|
-
...
|
|
166
|
+
...commonProps,
|
|
103
167
|
label: {
|
|
104
168
|
type: [Number, String],
|
|
105
169
|
default: ""
|
|
@@ -114,103 +178,190 @@ const O = (t) => (e) => Object.prototype.toString.call(e) === `[object ${t}]`, L
|
|
|
114
178
|
default: ""
|
|
115
179
|
}
|
|
116
180
|
},
|
|
117
|
-
setup(
|
|
118
|
-
slots
|
|
119
|
-
expose
|
|
181
|
+
setup(props, {
|
|
182
|
+
slots,
|
|
183
|
+
expose
|
|
120
184
|
}) {
|
|
121
185
|
const {
|
|
122
|
-
parent
|
|
123
|
-
} =
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
186
|
+
parent
|
|
187
|
+
} = useRelation(FORM_PROVIDE);
|
|
188
|
+
const {
|
|
189
|
+
initProvide: initFormItemProvide,
|
|
190
|
+
filed
|
|
191
|
+
} = setFormItem();
|
|
192
|
+
const validateFailed = ref(false);
|
|
193
|
+
const validateMessage = ref(locale.validateMessage);
|
|
194
|
+
const getProp = (propName) => {
|
|
195
|
+
if (props[propName] && props[propName] !== null)
|
|
196
|
+
return props[propName];
|
|
197
|
+
const parentProps = parent && parent.props;
|
|
198
|
+
return parentProps && parentProps[propName] || null;
|
|
199
|
+
};
|
|
200
|
+
const rules = computed(() => {
|
|
201
|
+
const parentRules = parent && parent.props.rules;
|
|
202
|
+
const curRules = props.rules || (parentRules == null ? void 0 : parentRules[props.prop]);
|
|
203
|
+
return isObject(curRules) ? [curRules] : curRules;
|
|
204
|
+
});
|
|
205
|
+
const required = computed(() => rules.value && rules.value.some((item) => item.required));
|
|
206
|
+
const formValue = computed(() => {
|
|
207
|
+
if (filed.value) {
|
|
208
|
+
const filedInstance = filed.value.proxy;
|
|
209
|
+
return filedInstance.modelValue;
|
|
210
|
+
}
|
|
211
|
+
return null;
|
|
212
|
+
});
|
|
213
|
+
const errorStatus = computed(() => {
|
|
214
|
+
return getProp("showError") && validateFailed.value;
|
|
215
|
+
});
|
|
216
|
+
const runSyncRule = (value, rule) => {
|
|
217
|
+
if (rule.required) {
|
|
218
|
+
if (filed.value && filed.value.exposed && typeof filed.value.exposed.isRequired !== "undefined" && !filed.value.exposed.isRequired) {
|
|
219
|
+
return false;
|
|
220
|
+
}
|
|
221
|
+
if (!(Array.isArray(value) ? value.length : value)) {
|
|
222
|
+
return false;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
if (rule.pattern && isString(value) && !rule.pattern.test(value)) {
|
|
226
|
+
return false;
|
|
227
|
+
}
|
|
228
|
+
return true;
|
|
229
|
+
};
|
|
230
|
+
const getRuleMessage = (value, rule) => {
|
|
135
231
|
const {
|
|
136
|
-
message
|
|
137
|
-
} =
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
232
|
+
message
|
|
233
|
+
} = rule;
|
|
234
|
+
if (isFunction(message)) {
|
|
235
|
+
return message(value, rule);
|
|
236
|
+
}
|
|
237
|
+
return message;
|
|
238
|
+
};
|
|
239
|
+
const runRules = (ruleList) => {
|
|
240
|
+
return ruleList.reduce((promise, rule) => promise.then(() => {
|
|
241
|
+
if (validateFailed.value)
|
|
242
|
+
return null;
|
|
243
|
+
const value = rule.formatter ? rule.formatter(formValue.value, rule) : formValue.value;
|
|
244
|
+
if (!runSyncRule(value, rule)) {
|
|
245
|
+
validateFailed.value = true;
|
|
246
|
+
validateMessage.value = getRuleMessage(value, rule);
|
|
247
|
+
return null;
|
|
248
|
+
}
|
|
249
|
+
if (rule.validator) {
|
|
250
|
+
const cb = rule.validator(value, rule);
|
|
251
|
+
if (typeof cb === "boolean") {
|
|
252
|
+
if (!cb) {
|
|
253
|
+
validateFailed.value = true;
|
|
254
|
+
validateMessage.value = getRuleMessage(value, rule);
|
|
255
|
+
}
|
|
256
|
+
return Promise.resolve(cb);
|
|
257
|
+
}
|
|
258
|
+
return cb.then((result) => {
|
|
259
|
+
if (!result) {
|
|
260
|
+
validateFailed.value = true;
|
|
261
|
+
validateMessage.value = getRuleMessage(value, rule);
|
|
262
|
+
}
|
|
263
|
+
return result;
|
|
264
|
+
});
|
|
265
|
+
}
|
|
141
266
|
return null;
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
return
|
|
267
|
+
}), Promise.resolve());
|
|
268
|
+
};
|
|
269
|
+
const validate = async (ruleList) => {
|
|
270
|
+
const ruleArr = ruleList || rules.value;
|
|
271
|
+
if (!ruleArr) {
|
|
272
|
+
return Promise.resolve();
|
|
273
|
+
}
|
|
274
|
+
await runRules(ruleArr);
|
|
275
|
+
if (validateFailed.value) {
|
|
276
|
+
return {
|
|
277
|
+
name: props.prop,
|
|
278
|
+
message: validateMessage.value
|
|
279
|
+
};
|
|
148
280
|
}
|
|
149
281
|
return null;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
282
|
+
};
|
|
283
|
+
const validateWithTrigger = (trigger) => {
|
|
284
|
+
var _a;
|
|
285
|
+
if (parent && rules.value) {
|
|
286
|
+
const defaultTrigger = ((_a = parent.props) == null ? void 0 : _a.validateTrigger) === trigger;
|
|
287
|
+
const ruleList = rules.value.filter((rule) => {
|
|
288
|
+
if (rule.trigger) {
|
|
289
|
+
return rule.trigger === trigger;
|
|
290
|
+
}
|
|
291
|
+
return defaultTrigger;
|
|
292
|
+
});
|
|
293
|
+
return validate(ruleList);
|
|
161
294
|
}
|
|
162
295
|
return Promise.resolve(null);
|
|
163
|
-
}, E = () => {
|
|
164
|
-
c.value && (c.value = !1, v.value = "");
|
|
165
296
|
};
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
change: r == null ? void 0 : r.change
|
|
171
|
-
}), i({
|
|
172
|
-
resetValidation: E,
|
|
173
|
-
formValue: M,
|
|
174
|
-
validate: S
|
|
175
|
-
});
|
|
176
|
-
const V = () => A.value ? e.error ? e.error() : f("showErrorMessage") ? h("p", {
|
|
177
|
-
class: b("error"),
|
|
178
|
-
style: {
|
|
179
|
-
textAlign: "left"
|
|
297
|
+
const resetValidation = () => {
|
|
298
|
+
if (validateFailed.value) {
|
|
299
|
+
validateFailed.value = false;
|
|
300
|
+
validateMessage.value = "";
|
|
180
301
|
}
|
|
181
|
-
}
|
|
302
|
+
};
|
|
303
|
+
initFormItemProvide({
|
|
304
|
+
getProp,
|
|
305
|
+
validateWithTrigger,
|
|
306
|
+
resetValidation,
|
|
307
|
+
change: parent == null ? void 0 : parent.change
|
|
308
|
+
});
|
|
309
|
+
expose({
|
|
310
|
+
resetValidation,
|
|
311
|
+
formValue,
|
|
312
|
+
validate
|
|
313
|
+
});
|
|
314
|
+
const _renderError = () => {
|
|
315
|
+
if (!errorStatus.value)
|
|
316
|
+
return null;
|
|
317
|
+
if (slots.error)
|
|
318
|
+
return slots.error();
|
|
319
|
+
return getProp("showErrorMessage") ? createVNode("p", {
|
|
320
|
+
"class": bem("error"),
|
|
321
|
+
"style": {
|
|
322
|
+
textAlign: "left"
|
|
323
|
+
}
|
|
324
|
+
}, [validateMessage.value]) : null;
|
|
325
|
+
};
|
|
182
326
|
return () => {
|
|
183
|
-
var
|
|
327
|
+
var _a, _b, _c;
|
|
184
328
|
const {
|
|
185
|
-
label
|
|
186
|
-
border
|
|
187
|
-
colon
|
|
188
|
-
} =
|
|
189
|
-
return
|
|
190
|
-
class: [
|
|
191
|
-
"is-error":
|
|
192
|
-
[
|
|
193
|
-
hairline:
|
|
194
|
-
}),
|
|
195
|
-
"hairline-bottom":
|
|
329
|
+
label,
|
|
330
|
+
border,
|
|
331
|
+
colon
|
|
332
|
+
} = props;
|
|
333
|
+
return createVNode("div", {
|
|
334
|
+
"class": [bem({
|
|
335
|
+
"is-error": errorStatus.value,
|
|
336
|
+
[getProp("size")]: getProp("size"),
|
|
337
|
+
hairline: border
|
|
338
|
+
}), gbem("el", {
|
|
339
|
+
"hairline-bottom": border
|
|
196
340
|
})]
|
|
197
|
-
}, [
|
|
198
|
-
class:
|
|
199
|
-
"is-required":
|
|
341
|
+
}, [createVNode("label", {
|
|
342
|
+
"class": bem("label", {
|
|
343
|
+
"is-required": required.value
|
|
200
344
|
}),
|
|
201
|
-
style: {
|
|
202
|
-
width:
|
|
203
|
-
textAlign:
|
|
345
|
+
"style": {
|
|
346
|
+
width: getProp("labelWidth"),
|
|
347
|
+
textAlign: getProp("labelAlign") || "left"
|
|
204
348
|
}
|
|
205
|
-
}, [(
|
|
206
|
-
class:
|
|
207
|
-
}, [(
|
|
349
|
+
}, [(_a = slots.labelIcon) == null ? void 0 : _a.call(slots), label, colon ? " :" : ""]), createVNode("div", {
|
|
350
|
+
"class": bem("content")
|
|
351
|
+
}, [(_b = slots.default) == null ? void 0 : _b.call(slots), _renderError()]), (_c = slots.extra) == null ? void 0 : _c.call(slots)]);
|
|
208
352
|
};
|
|
209
353
|
}
|
|
210
354
|
});
|
|
211
|
-
|
|
212
|
-
|
|
355
|
+
const reset = "";
|
|
356
|
+
const libs = "";
|
|
357
|
+
const font = "";
|
|
358
|
+
const animation = "";
|
|
359
|
+
const theme = "";
|
|
360
|
+
const style = "";
|
|
361
|
+
FormItem.install = (Vue) => {
|
|
362
|
+
Vue.component(FormItem.name, FormItem);
|
|
213
363
|
};
|
|
214
364
|
export {
|
|
215
|
-
|
|
365
|
+
FormItem,
|
|
366
|
+
FormItem as default
|
|
216
367
|
};
|