yc-design-vue 1.7.8 → 1.8.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/es/Calendar/Calendar.vue.js +15 -14
- package/es/Calendar/CalendarMonth.vue.js +11 -1
- package/es/Calendar/CalendarYear.vue.js +20 -16
- package/es/ColorPicker/ColorList.vue.js +4 -2
- package/es/ColorPicker/ColorPanel.vue.js +6 -4
- package/es/ColorPicker/index.css +1 -1
- package/es/ConfigProvider/index.d.ts +3 -0
- package/es/ConfigProvider/index.vue.d.ts +1 -0
- package/es/ConfigProvider/index.vue.js +13 -2
- package/es/ConfigProvider/type.d.ts +1 -0
- package/es/Drawer/Drawer.vue.js +6 -4
- package/es/Drawer/DrawerService.vue.js +2 -2
- package/es/Drawer/index.css +1 -1
- package/es/Dropdown/index.css +1 -1
- package/es/Empty/index.vue.js +11 -4
- package/es/Image/Image.vue.js +4 -2
- package/es/Image/ImagePreviewToolbar.vue.js +13 -29
- package/es/Layout/hooks/useTheme.js +0 -1
- package/es/Modal/Modal.vue.js +6 -4
- package/es/Modal/ModalService.vue.js +2 -2
- package/es/Pagination/Pagination.vue.js +5 -3
- package/es/Pagination/hooks/useContext.d.ts +5 -0
- package/es/Pagination/hooks/useContext.js +5 -2
- package/es/Popconfirm/index.css +1 -1
- package/es/Popconfirm/index.vue.js +6 -4
- package/es/Popover/index.css +1 -1
- package/es/Tooltip/index.css +1 -1
- package/es/Typography/TypographyBase.vue.js +5 -4
- package/es/_shared/locale/i18n.d.ts +256 -0
- package/es/_shared/locale/i18n.js +35 -0
- package/es/_shared/locale/lang/ar-eg.d.ts +205 -0
- package/es/_shared/locale/lang/ar-eg.js +153 -0
- package/es/_shared/locale/lang/de-de.d.ts +205 -0
- package/es/_shared/locale/lang/de-de.js +153 -0
- package/es/_shared/locale/lang/en-us.d.ts +253 -0
- package/es/_shared/locale/lang/en-us.js +158 -0
- package/es/_shared/locale/lang/es-es.d.ts +205 -0
- package/es/_shared/locale/lang/es-es.js +153 -0
- package/es/_shared/locale/lang/fr-fr.d.ts +205 -0
- package/es/_shared/locale/lang/fr-fr.js +153 -0
- package/es/_shared/locale/lang/id-id.d.ts +205 -0
- package/es/_shared/locale/lang/id-id.js +153 -0
- package/es/_shared/locale/lang/it-it.d.ts +205 -0
- package/es/_shared/locale/lang/it-it.js +153 -0
- package/es/_shared/locale/lang/ja-jp.d.ts +253 -0
- package/es/_shared/locale/lang/ja-jp.js +201 -0
- package/es/_shared/locale/lang/km-kh.d.ts +205 -0
- package/es/_shared/locale/lang/km-kh.js +153 -0
- package/es/_shared/locale/lang/ko-kr.d.ts +205 -0
- package/es/_shared/locale/lang/ko-kr.js +153 -0
- package/es/_shared/locale/lang/ms-my.d.ts +205 -0
- package/es/_shared/locale/lang/ms-my.js +153 -0
- package/es/_shared/locale/lang/nl-nl.d.ts +253 -0
- package/es/_shared/locale/lang/nl-nl.js +201 -0
- package/es/_shared/locale/lang/pt-pt.d.ts +205 -0
- package/es/_shared/locale/lang/pt-pt.js +153 -0
- package/es/_shared/locale/lang/ru-ru.d.ts +253 -0
- package/es/_shared/locale/lang/ru-ru.js +201 -0
- package/es/_shared/locale/lang/th-th.d.ts +205 -0
- package/es/_shared/locale/lang/th-th.js +153 -0
- package/es/_shared/locale/lang/vi-vn.d.ts +205 -0
- package/es/_shared/locale/lang/vi-vn.js +153 -0
- package/es/_shared/locale/lang/zh-cn.d.ts +253 -0
- package/es/_shared/locale/lang/zh-cn.js +201 -0
- package/es/_shared/locale/lang/zh-tw.d.ts +253 -0
- package/es/_shared/locale/lang/zh-tw.js +201 -0
- package/es/_shared/utils/time.js +1 -1
- package/es/_virtual/dynamic-import-helper.js +19 -0
- package/es/index.js +2 -0
- package/es/node_modules/@intlify/core-base/dist/core-base.js +1129 -0
- package/es/node_modules/@intlify/message-compiler/dist/message-compiler.js +65 -0
- package/es/node_modules/@intlify/shared/dist/shared.js +199 -0
- package/es/node_modules/@intlify/vue-i18n-core/dist/vue-i18n-core.js +1381 -0
- package/es/node_modules/@vue/devtools-api/lib/esm/const.js +6 -0
- package/es/node_modules/@vue/devtools-api/lib/esm/env.js +12 -0
- package/es/node_modules/@vue/devtools-api/lib/esm/index.js +26 -0
- package/es/node_modules/@vue/devtools-api/lib/esm/proxy.js +103 -0
- package/es/node_modules/@vue/devtools-api/lib/esm/time.js +25 -0
- package/es/node_modules/b-validate/es/is.js +27 -0
- package/es/node_modules/b-validate/es/locale/en-US.js +50 -0
- package/es/node_modules/b-validate/es/rules/base.js +86 -0
- package/es/node_modules/b-validate/es/util.js +25 -0
- package/es/style.css +1 -1
- package/lib/Calendar/Calendar.vue.js +1 -1
- package/lib/Calendar/CalendarMonth.vue.js +1 -1
- package/lib/Calendar/CalendarYear.vue.js +1 -1
- package/lib/ColorPicker/ColorList.vue.js +1 -1
- package/lib/ColorPicker/ColorPanel.vue.js +1 -1
- package/lib/ColorPicker/index.css +1 -1
- package/lib/ConfigProvider/index.d.ts +3 -0
- package/lib/ConfigProvider/index.vue.d.ts +1 -0
- package/lib/ConfigProvider/index.vue.js +1 -1
- package/lib/ConfigProvider/type.d.ts +1 -0
- package/lib/Drawer/Drawer.vue.js +1 -1
- package/lib/Drawer/DrawerService.vue.js +1 -1
- package/lib/Drawer/index.css +1 -1
- package/lib/Dropdown/index.css +1 -1
- package/lib/Empty/index.vue.js +1 -1
- package/lib/Image/Image.vue.js +1 -1
- package/lib/Image/ImagePreviewToolbar.vue.js +1 -1
- package/lib/Modal/Modal.vue.js +1 -1
- package/lib/Modal/ModalService.vue.js +1 -1
- package/lib/Pagination/Pagination.vue.js +1 -1
- package/lib/Pagination/hooks/useContext.d.ts +5 -0
- package/lib/Pagination/hooks/useContext.js +1 -1
- package/lib/Popconfirm/index.css +1 -1
- package/lib/Popconfirm/index.vue.js +1 -1
- package/lib/Popover/index.css +1 -1
- package/lib/Tooltip/index.css +1 -1
- package/lib/Typography/TypographyBase.vue.js +1 -1
- package/lib/_shared/locale/i18n.d.ts +256 -0
- package/lib/_shared/locale/i18n.js +1 -0
- package/lib/_shared/locale/lang/ar-eg.d.ts +205 -0
- package/lib/_shared/locale/lang/ar-eg.js +1 -0
- package/lib/_shared/locale/lang/de-de.d.ts +205 -0
- package/lib/_shared/locale/lang/de-de.js +1 -0
- package/lib/_shared/locale/lang/en-us.d.ts +253 -0
- package/lib/_shared/locale/lang/en-us.js +1 -0
- package/lib/_shared/locale/lang/es-es.d.ts +205 -0
- package/lib/_shared/locale/lang/es-es.js +1 -0
- package/lib/_shared/locale/lang/fr-fr.d.ts +205 -0
- package/lib/_shared/locale/lang/fr-fr.js +1 -0
- package/lib/_shared/locale/lang/id-id.d.ts +205 -0
- package/lib/_shared/locale/lang/id-id.js +1 -0
- package/lib/_shared/locale/lang/it-it.d.ts +205 -0
- package/lib/_shared/locale/lang/it-it.js +1 -0
- package/lib/_shared/locale/lang/ja-jp.d.ts +253 -0
- package/lib/_shared/locale/lang/ja-jp.js +1 -0
- package/lib/_shared/locale/lang/km-kh.d.ts +205 -0
- package/lib/_shared/locale/lang/km-kh.js +1 -0
- package/lib/_shared/locale/lang/ko-kr.d.ts +205 -0
- package/lib/_shared/locale/lang/ko-kr.js +1 -0
- package/lib/_shared/locale/lang/ms-my.d.ts +205 -0
- package/lib/_shared/locale/lang/ms-my.js +1 -0
- package/lib/_shared/locale/lang/nl-nl.d.ts +253 -0
- package/lib/_shared/locale/lang/nl-nl.js +1 -0
- package/lib/_shared/locale/lang/pt-pt.d.ts +205 -0
- package/lib/_shared/locale/lang/pt-pt.js +1 -0
- package/lib/_shared/locale/lang/ru-ru.d.ts +253 -0
- package/lib/_shared/locale/lang/ru-ru.js +1 -0
- package/lib/_shared/locale/lang/th-th.d.ts +205 -0
- package/lib/_shared/locale/lang/th-th.js +1 -0
- package/lib/_shared/locale/lang/vi-vn.d.ts +205 -0
- package/lib/_shared/locale/lang/vi-vn.js +1 -0
- package/lib/_shared/locale/lang/zh-cn.d.ts +253 -0
- package/lib/_shared/locale/lang/zh-cn.js +1 -0
- package/lib/_shared/locale/lang/zh-tw.d.ts +253 -0
- package/lib/_shared/locale/lang/zh-tw.js +1 -0
- package/lib/_shared/utils/time.js +1 -1
- package/lib/_virtual/dynamic-import-helper.js +1 -0
- package/lib/index.js +1 -1
- package/lib/node_modules/@intlify/core-base/dist/core-base.js +1 -0
- package/lib/node_modules/@intlify/message-compiler/dist/message-compiler.js +6 -0
- package/lib/node_modules/@intlify/shared/dist/shared.js +7 -0
- package/lib/node_modules/@intlify/vue-i18n-core/dist/vue-i18n-core.js +1 -0
- package/lib/node_modules/@vue/devtools-api/lib/esm/const.js +1 -0
- package/lib/node_modules/@vue/devtools-api/lib/esm/env.js +1 -0
- package/lib/node_modules/@vue/devtools-api/lib/esm/index.js +1 -0
- package/lib/node_modules/@vue/devtools-api/lib/esm/proxy.js +1 -0
- package/lib/node_modules/@vue/devtools-api/lib/esm/time.js +1 -0
- package/lib/node_modules/b-validate/es/is.js +1 -0
- package/lib/node_modules/b-validate/es/locale/en-US.js +1 -0
- package/lib/node_modules/b-validate/es/rules/base.js +1 -0
- package/lib/node_modules/b-validate/es/util.js +1 -0
- package/lib/style.css +1 -1
- package/package.json +3 -2
@@ -0,0 +1,12 @@
|
|
1
|
+
function getDevtoolsGlobalHook() {
|
2
|
+
return getTarget().__VUE_DEVTOOLS_GLOBAL_HOOK__;
|
3
|
+
}
|
4
|
+
function getTarget() {
|
5
|
+
return typeof navigator !== "undefined" && typeof window !== "undefined" ? window : typeof globalThis !== "undefined" ? globalThis : {};
|
6
|
+
}
|
7
|
+
const isProxyAvailable = typeof Proxy === "function";
|
8
|
+
export {
|
9
|
+
getDevtoolsGlobalHook,
|
10
|
+
getTarget,
|
11
|
+
isProxyAvailable
|
12
|
+
};
|
@@ -0,0 +1,26 @@
|
|
1
|
+
import { getTarget, getDevtoolsGlobalHook, isProxyAvailable } from "./env.js";
|
2
|
+
import { HOOK_SETUP } from "./const.js";
|
3
|
+
import { ApiProxy } from "./proxy.js";
|
4
|
+
function setupDevtoolsPlugin(pluginDescriptor, setupFn) {
|
5
|
+
const descriptor = pluginDescriptor;
|
6
|
+
const target = getTarget();
|
7
|
+
const hook = getDevtoolsGlobalHook();
|
8
|
+
const enableProxy = isProxyAvailable && descriptor.enableEarlyProxy;
|
9
|
+
if (hook && (target.__VUE_DEVTOOLS_PLUGIN_API_AVAILABLE__ || !enableProxy)) {
|
10
|
+
hook.emit(HOOK_SETUP, pluginDescriptor, setupFn);
|
11
|
+
} else {
|
12
|
+
const proxy = enableProxy ? new ApiProxy(descriptor, hook) : null;
|
13
|
+
const list = target.__VUE_DEVTOOLS_PLUGINS__ = target.__VUE_DEVTOOLS_PLUGINS__ || [];
|
14
|
+
list.push({
|
15
|
+
pluginDescriptor: descriptor,
|
16
|
+
setupFn,
|
17
|
+
proxy
|
18
|
+
});
|
19
|
+
if (proxy) {
|
20
|
+
setupFn(proxy.proxiedTarget);
|
21
|
+
}
|
22
|
+
}
|
23
|
+
}
|
24
|
+
export {
|
25
|
+
setupDevtoolsPlugin
|
26
|
+
};
|
@@ -0,0 +1,103 @@
|
|
1
|
+
import { HOOK_PLUGIN_SETTINGS_SET } from "./const.js";
|
2
|
+
import { now } from "./time.js";
|
3
|
+
class ApiProxy {
|
4
|
+
constructor(plugin, hook) {
|
5
|
+
this.target = null;
|
6
|
+
this.targetQueue = [];
|
7
|
+
this.onQueue = [];
|
8
|
+
this.plugin = plugin;
|
9
|
+
this.hook = hook;
|
10
|
+
const defaultSettings = {};
|
11
|
+
if (plugin.settings) {
|
12
|
+
for (const id in plugin.settings) {
|
13
|
+
const item = plugin.settings[id];
|
14
|
+
defaultSettings[id] = item.defaultValue;
|
15
|
+
}
|
16
|
+
}
|
17
|
+
const localSettingsSaveId = `__vue-devtools-plugin-settings__${plugin.id}`;
|
18
|
+
let currentSettings = Object.assign({}, defaultSettings);
|
19
|
+
try {
|
20
|
+
const raw = localStorage.getItem(localSettingsSaveId);
|
21
|
+
const data = JSON.parse(raw);
|
22
|
+
Object.assign(currentSettings, data);
|
23
|
+
} catch (e) {
|
24
|
+
}
|
25
|
+
this.fallbacks = {
|
26
|
+
getSettings() {
|
27
|
+
return currentSettings;
|
28
|
+
},
|
29
|
+
setSettings(value) {
|
30
|
+
try {
|
31
|
+
localStorage.setItem(localSettingsSaveId, JSON.stringify(value));
|
32
|
+
} catch (e) {
|
33
|
+
}
|
34
|
+
currentSettings = value;
|
35
|
+
},
|
36
|
+
now() {
|
37
|
+
return now();
|
38
|
+
}
|
39
|
+
};
|
40
|
+
if (hook) {
|
41
|
+
hook.on(HOOK_PLUGIN_SETTINGS_SET, (pluginId, value) => {
|
42
|
+
if (pluginId === this.plugin.id) {
|
43
|
+
this.fallbacks.setSettings(value);
|
44
|
+
}
|
45
|
+
});
|
46
|
+
}
|
47
|
+
this.proxiedOn = new Proxy({}, {
|
48
|
+
get: (_target, prop) => {
|
49
|
+
if (this.target) {
|
50
|
+
return this.target.on[prop];
|
51
|
+
} else {
|
52
|
+
return (...args) => {
|
53
|
+
this.onQueue.push({
|
54
|
+
method: prop,
|
55
|
+
args
|
56
|
+
});
|
57
|
+
};
|
58
|
+
}
|
59
|
+
}
|
60
|
+
});
|
61
|
+
this.proxiedTarget = new Proxy({}, {
|
62
|
+
get: (_target, prop) => {
|
63
|
+
if (this.target) {
|
64
|
+
return this.target[prop];
|
65
|
+
} else if (prop === "on") {
|
66
|
+
return this.proxiedOn;
|
67
|
+
} else if (Object.keys(this.fallbacks).includes(prop)) {
|
68
|
+
return (...args) => {
|
69
|
+
this.targetQueue.push({
|
70
|
+
method: prop,
|
71
|
+
args,
|
72
|
+
resolve: () => {
|
73
|
+
}
|
74
|
+
});
|
75
|
+
return this.fallbacks[prop](...args);
|
76
|
+
};
|
77
|
+
} else {
|
78
|
+
return (...args) => {
|
79
|
+
return new Promise((resolve) => {
|
80
|
+
this.targetQueue.push({
|
81
|
+
method: prop,
|
82
|
+
args,
|
83
|
+
resolve
|
84
|
+
});
|
85
|
+
});
|
86
|
+
};
|
87
|
+
}
|
88
|
+
}
|
89
|
+
});
|
90
|
+
}
|
91
|
+
async setRealTarget(target) {
|
92
|
+
this.target = target;
|
93
|
+
for (const item of this.onQueue) {
|
94
|
+
this.target.on[item.method](...item.args);
|
95
|
+
}
|
96
|
+
for (const item of this.targetQueue) {
|
97
|
+
item.resolve(await this.target[item.method](...item.args));
|
98
|
+
}
|
99
|
+
}
|
100
|
+
}
|
101
|
+
export {
|
102
|
+
ApiProxy
|
103
|
+
};
|
@@ -0,0 +1,25 @@
|
|
1
|
+
let supported;
|
2
|
+
let perf;
|
3
|
+
function isPerformanceSupported() {
|
4
|
+
var _a;
|
5
|
+
if (supported !== void 0) {
|
6
|
+
return supported;
|
7
|
+
}
|
8
|
+
if (typeof window !== "undefined" && window.performance) {
|
9
|
+
supported = true;
|
10
|
+
perf = window.performance;
|
11
|
+
} else if (typeof globalThis !== "undefined" && ((_a = globalThis.perf_hooks) === null || _a === void 0 ? void 0 : _a.performance)) {
|
12
|
+
supported = true;
|
13
|
+
perf = globalThis.perf_hooks.performance;
|
14
|
+
} else {
|
15
|
+
supported = false;
|
16
|
+
}
|
17
|
+
return supported;
|
18
|
+
}
|
19
|
+
function now() {
|
20
|
+
return isPerformanceSupported() ? perf.now() : Date.now();
|
21
|
+
}
|
22
|
+
export {
|
23
|
+
isPerformanceSupported,
|
24
|
+
now
|
25
|
+
};
|
@@ -0,0 +1,27 @@
|
|
1
|
+
var opt = Object.prototype.toString;
|
2
|
+
function isArray(obj) {
|
3
|
+
return opt.call(obj) === "[object Array]";
|
4
|
+
}
|
5
|
+
function isObject(obj) {
|
6
|
+
return opt.call(obj) === "[object Object]";
|
7
|
+
}
|
8
|
+
function isString(obj) {
|
9
|
+
return opt.call(obj) === "[object String]";
|
10
|
+
}
|
11
|
+
function isFunction(obj) {
|
12
|
+
return opt.call(obj) === "[object Function]";
|
13
|
+
}
|
14
|
+
function isEmptyValue(obj) {
|
15
|
+
return obj === void 0 || obj === null || obj === "";
|
16
|
+
}
|
17
|
+
function isEmptyArray(obj) {
|
18
|
+
return isArray(obj) && !obj.length;
|
19
|
+
}
|
20
|
+
export {
|
21
|
+
isArray,
|
22
|
+
isEmptyArray,
|
23
|
+
isEmptyValue,
|
24
|
+
isFunction,
|
25
|
+
isObject,
|
26
|
+
isString
|
27
|
+
};
|
@@ -0,0 +1,50 @@
|
|
1
|
+
var defaultTypeTemplate = "#{field} is not a #{type} type";
|
2
|
+
var defaultValidateLocale = {
|
3
|
+
required: "#{field} is required",
|
4
|
+
type: {
|
5
|
+
ip: defaultTypeTemplate,
|
6
|
+
email: defaultTypeTemplate,
|
7
|
+
url: defaultTypeTemplate,
|
8
|
+
string: defaultTypeTemplate,
|
9
|
+
number: defaultTypeTemplate,
|
10
|
+
array: defaultTypeTemplate,
|
11
|
+
object: defaultTypeTemplate,
|
12
|
+
boolean: defaultTypeTemplate
|
13
|
+
},
|
14
|
+
number: {
|
15
|
+
min: "`#{value}` is not greater than `#{min}`",
|
16
|
+
max: "`#{value}` is not less than `#{max}`",
|
17
|
+
equal: "`#{value}` is not equal to `#{equal}`",
|
18
|
+
range: "`#{value}` is not in range `#{min} ~ #{max}`",
|
19
|
+
positive: "`#{value}` is not a positive number",
|
20
|
+
negative: "`#{value}` is not a negative number"
|
21
|
+
},
|
22
|
+
string: {
|
23
|
+
maxLength: "#{field} cannot be longer than #{maxLength} characters",
|
24
|
+
minLength: "#{field} must be at least #{minLength} characters",
|
25
|
+
length: "#{field} must be exactly #{length} characters",
|
26
|
+
match: "`#{value}` does not match pattern #{pattern}",
|
27
|
+
uppercase: "`#{value}` must be all uppercase",
|
28
|
+
lowercase: "`#{value}` must be all lowercased"
|
29
|
+
},
|
30
|
+
array: {
|
31
|
+
length: "#{field} must be exactly #{length} in length",
|
32
|
+
minLength: "#{field} cannot be less than #{minLength} in length",
|
33
|
+
maxLength: "#{field} cannot be greater than #{maxLength} in length",
|
34
|
+
includes: "#{field} is not includes #{includes}",
|
35
|
+
deepEqual: "#{field} is not deep equal with #{deepEqual}",
|
36
|
+
empty: "#{field} is not an empty array"
|
37
|
+
},
|
38
|
+
object: {
|
39
|
+
deepEqual: "#{field} is not deep equal to expected value",
|
40
|
+
hasKeys: "#{field} does not contain required fields",
|
41
|
+
empty: "#{field} is not an empty object"
|
42
|
+
},
|
43
|
+
boolean: {
|
44
|
+
true: "Expect true but got `#{value}`",
|
45
|
+
false: "Expect false but got `#{value}`"
|
46
|
+
}
|
47
|
+
};
|
48
|
+
export {
|
49
|
+
defaultValidateLocale as default
|
50
|
+
};
|
@@ -0,0 +1,86 @@
|
|
1
|
+
import { isObject, isFunction, isString, isArray, isEmptyValue, isEmptyArray } from "../is.js";
|
2
|
+
import { getTemplate, mergeTemplate } from "../util.js";
|
3
|
+
import defaultValidateLocale from "../locale/en-US.js";
|
4
|
+
var Base = function Base2(obj, options) {
|
5
|
+
var this$1$1 = this;
|
6
|
+
this.getValidateMsg = function(keyPath, info) {
|
7
|
+
if (info === void 0) info = {};
|
8
|
+
var data = Object.assign(Object.assign({}, info), { value: this$1$1.obj, field: this$1$1.field, type: this$1$1.type });
|
9
|
+
var template = getTemplate(this$1$1.validateMessages, keyPath);
|
10
|
+
if (isFunction(template)) {
|
11
|
+
return template(data);
|
12
|
+
}
|
13
|
+
if (isString(template)) {
|
14
|
+
return template.replace(/\#\{.+?\}/g, function(variable) {
|
15
|
+
var key = variable.slice(2, -1);
|
16
|
+
if (key in data) {
|
17
|
+
if (isObject(data[key]) || isArray(data[key])) {
|
18
|
+
try {
|
19
|
+
return JSON.stringify(data[key]);
|
20
|
+
} catch (_) {
|
21
|
+
return data[key];
|
22
|
+
}
|
23
|
+
}
|
24
|
+
return String(data[key]);
|
25
|
+
}
|
26
|
+
return variable;
|
27
|
+
});
|
28
|
+
}
|
29
|
+
return template;
|
30
|
+
};
|
31
|
+
if (isObject(options) && isString(obj) && options.trim) {
|
32
|
+
this.obj = obj.trim();
|
33
|
+
} else if (isObject(options) && options.ignoreEmptyString && obj === "") {
|
34
|
+
this.obj = void 0;
|
35
|
+
} else {
|
36
|
+
this.obj = obj;
|
37
|
+
}
|
38
|
+
this.message = options.message;
|
39
|
+
this.type = options.type;
|
40
|
+
this.error = null;
|
41
|
+
this.field = options.field || options.type;
|
42
|
+
this.validateMessages = mergeTemplate(defaultValidateLocale, options.validateMessages);
|
43
|
+
};
|
44
|
+
var prototypeAccessors = { not: { configurable: true }, isRequired: { configurable: true }, end: { configurable: true } };
|
45
|
+
prototypeAccessors.not.get = function() {
|
46
|
+
this._not = !this._not;
|
47
|
+
return this;
|
48
|
+
};
|
49
|
+
prototypeAccessors.isRequired.get = function() {
|
50
|
+
if (isEmptyValue(this.obj) || isEmptyArray(this.obj)) {
|
51
|
+
var message = this.getValidateMsg("required");
|
52
|
+
this.error = {
|
53
|
+
value: this.obj,
|
54
|
+
type: this.type,
|
55
|
+
requiredError: true,
|
56
|
+
message: this.message || (isObject(message) ? message : (this._not ? "[NOT MODE]:" : "") + message)
|
57
|
+
};
|
58
|
+
}
|
59
|
+
return this;
|
60
|
+
};
|
61
|
+
prototypeAccessors.end.get = function() {
|
62
|
+
return this.error;
|
63
|
+
};
|
64
|
+
Base.prototype.addError = function addError(message) {
|
65
|
+
if (!this.error && message) {
|
66
|
+
this.error = {
|
67
|
+
value: this.obj,
|
68
|
+
type: this.type,
|
69
|
+
message: this.message || (isObject(message) ? message : (this._not ? "[NOT MODE]:" : "") + message)
|
70
|
+
};
|
71
|
+
}
|
72
|
+
};
|
73
|
+
Base.prototype.validate = function validate(expression, errorMessage) {
|
74
|
+
var _expression = this._not ? expression : !expression;
|
75
|
+
if (_expression) {
|
76
|
+
this.addError(errorMessage);
|
77
|
+
}
|
78
|
+
return this;
|
79
|
+
};
|
80
|
+
Base.prototype.collect = function collect(callback) {
|
81
|
+
callback && callback(this.error);
|
82
|
+
};
|
83
|
+
Object.defineProperties(Base.prototype, prototypeAccessors);
|
84
|
+
export {
|
85
|
+
Base as default
|
86
|
+
};
|
@@ -0,0 +1,25 @@
|
|
1
|
+
import { isObject } from "./is.js";
|
2
|
+
var mergeTemplate = function(defaultValidateMessages, validateMessages) {
|
3
|
+
var result = Object.assign({}, defaultValidateMessages);
|
4
|
+
Object.keys(validateMessages || {}).forEach(function(key) {
|
5
|
+
var defaultValue = result[key];
|
6
|
+
var newValue = validateMessages === null || validateMessages === void 0 ? void 0 : validateMessages[key];
|
7
|
+
result[key] = isObject(defaultValue) ? Object.assign(Object.assign({}, defaultValue), newValue) : newValue || defaultValue;
|
8
|
+
});
|
9
|
+
return result;
|
10
|
+
};
|
11
|
+
var getTemplate = function(validateMessages, keyPath) {
|
12
|
+
var keys = keyPath.split(".");
|
13
|
+
var result = validateMessages;
|
14
|
+
for (var i = 0; i < keys.length; i++) {
|
15
|
+
result = result && result[keys[i]];
|
16
|
+
if (result === void 0) {
|
17
|
+
return result;
|
18
|
+
}
|
19
|
+
}
|
20
|
+
return result;
|
21
|
+
};
|
22
|
+
export {
|
23
|
+
getTemplate,
|
24
|
+
mergeTemplate
|
25
|
+
};
|