amis-core 1.0.0-beta.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/Root.js +94 -0
- package/dist/RootRenderer.js +288 -0
- package/dist/SchemaRenderer.js +323 -0
- package/dist/Scoped.js +252 -0
- package/dist/WithRootStore.js +44 -0
- package/dist/WithStore.js +179 -0
- package/dist/__tests__/compat.test.d.ts +1 -0
- package/dist/__tests__/factory.test.d.ts +1 -0
- package/dist/__tests__/filter.test.d.ts +1 -0
- package/dist/__tests__/helper.d.ts +13 -0
- package/dist/__tests__/tokenize.test.d.ts +1 -0
- package/dist/actions/Action.js +119 -0
- package/dist/actions/AjaxAction.js +96 -0
- package/dist/actions/BreakAction.js +35 -0
- package/dist/actions/BroadcastAction.js +49 -0
- package/dist/actions/CmptAction.js +60 -0
- package/dist/actions/ContinueAction.js +35 -0
- package/dist/actions/CopyAction.js +43 -0
- package/dist/actions/CustomAction.js +49 -0
- package/dist/actions/DialogAction.js +104 -0
- package/dist/actions/DrawerAction.js +66 -0
- package/dist/actions/EmailAction.js +48 -0
- package/dist/actions/LinkAction.js +52 -0
- package/dist/actions/LoopAction.js +107 -0
- package/dist/actions/PageAction.js +80 -0
- package/dist/actions/ParallelAction.js +40 -0
- package/dist/actions/SwitchAction.js +52 -0
- package/dist/actions/ToastAction.js +35 -0
- package/dist/components/LazyComponent.js +99 -0
- package/dist/env.js +20 -0
- package/dist/envOverwrite.js +43 -0
- package/dist/factory.js +308 -0
- package/dist/index.js +218 -0
- package/dist/index2.js +255 -0
- package/dist/locale.js +114 -0
- package/dist/renderers/Form.js +1162 -0
- package/dist/renderers/Item.js +636 -0
- package/dist/renderers/Options.js +881 -0
- package/dist/renderers/Placeholder.js +31 -0
- package/dist/renderers/builtin.js +27 -0
- package/dist/renderers/wrapControl.js +507 -0
- package/dist/src/Root.d.ts +37 -0
- package/dist/src/RootRenderer.d.ts +27 -0
- package/dist/src/SchemaRenderer.d.ts +37 -0
- package/dist/src/Scoped.d.ts +38 -0
- package/dist/src/WithRootStore.d.ts +737 -0
- package/dist/src/WithStore.d.ts +5 -0
- package/dist/src/actions/Action.d.ts +38 -0
- package/dist/src/actions/AjaxAction.d.ts +25 -0
- package/dist/src/actions/BreakAction.d.ts +15 -0
- package/dist/src/actions/BroadcastAction.d.ts +16 -0
- package/dist/src/actions/CmptAction.d.ts +20 -0
- package/dist/src/actions/ContinueAction.d.ts +15 -0
- package/dist/src/actions/CopyAction.d.ts +20 -0
- package/dist/src/actions/CustomAction.d.ts +17 -0
- package/dist/src/actions/Decorators.d.ts +25 -0
- package/dist/src/actions/DialogAction.d.ts +57 -0
- package/dist/src/actions/DrawerAction.d.ts +30 -0
- package/dist/src/actions/EmailAction.d.ts +23 -0
- package/dist/src/actions/LinkAction.d.ts +24 -0
- package/dist/src/actions/LoopAction.d.ts +19 -0
- package/dist/src/actions/PageAction.d.ts +39 -0
- package/dist/src/actions/ParallelAction.d.ts +8 -0
- package/dist/src/actions/SwitchAction.d.ts +11 -0
- package/dist/src/actions/ToastAction.d.ts +19 -0
- package/dist/src/actions/index.d.ts +21 -0
- package/dist/src/components/LazyComponent.d.ts +32 -0
- package/dist/src/env.d.ts +172 -0
- package/dist/src/envOverwrite.d.ts +4 -0
- package/dist/src/factory.d.ts +78 -0
- package/dist/src/index.d.ts +25 -0
- package/dist/src/locale.d.ts +82 -0
- package/dist/src/renderers/Form.d.ts +352 -0
- package/dist/src/renderers/Item.d.ts +795 -0
- package/dist/src/renderers/Options.d.ts +150 -0
- package/dist/src/renderers/Placeholder.d.ts +6 -0
- package/dist/src/renderers/builtin.d.ts +1 -0
- package/dist/src/renderers/wrapControl.d.ts +446 -0
- package/dist/src/schema.d.ts +369 -0
- package/dist/src/store/app.d.ts +89 -0
- package/dist/src/store/combo.d.ts +8504 -0
- package/dist/src/store/crud.d.ts +124 -0
- package/dist/src/store/form.d.ts +3394 -0
- package/dist/src/store/formItem.d.ts +130 -0
- package/dist/src/store/iRenderer.d.ts +46 -0
- package/dist/src/store/index.d.ts +105 -0
- package/dist/src/store/list.d.ts +270 -0
- package/dist/src/store/manager.d.ts +115 -0
- package/dist/src/store/modal.d.ts +84 -0
- package/dist/src/store/node.d.ts +22 -0
- package/dist/src/store/pagination.d.ts +58 -0
- package/dist/src/store/root.d.ts +79 -0
- package/dist/src/store/service.d.ts +71 -0
- package/dist/src/store/table-v2.d.ts +309 -0
- package/dist/src/store/table.d.ts +8334 -0
- package/dist/src/theme.d.ts +83 -0
- package/dist/src/types.d.ts +217 -0
- package/dist/src/utils/Animation.d.ts +22 -0
- package/dist/src/utils/ColorScale.d.ts +19 -0
- package/dist/src/utils/DataSchema.d.ts +25 -0
- package/dist/src/utils/DataScope.d.ts +23 -0
- package/dist/src/utils/RootClose.d.ts +4 -0
- package/dist/src/utils/SimpleMap.d.ts +8 -0
- package/dist/src/utils/api.d.ts +27 -0
- package/dist/src/utils/attachmentAdpator.d.ts +7 -0
- package/dist/src/utils/autobind.d.ts +7 -0
- package/dist/src/utils/columnsSplit.d.ts +1 -0
- package/dist/src/utils/dataMapping.d.ts +3 -0
- package/dist/src/utils/date.d.ts +4 -0
- package/dist/src/utils/debug.d.ts +26 -0
- package/dist/src/utils/dom.d.ts +13 -0
- package/dist/src/utils/errors.d.ts +6 -0
- package/dist/src/utils/escapeHtml.d.ts +1 -0
- package/dist/src/utils/filter-schema.d.ts +12 -0
- package/dist/src/utils/filter.d.ts +1 -0
- package/dist/src/utils/formatDuration.d.ts +1 -0
- package/dist/src/utils/formula.d.ts +16 -0
- package/dist/src/utils/getVariable.d.ts +3 -0
- package/dist/src/utils/grammar.d.ts +4 -0
- package/dist/src/utils/handleAction.d.ts +6 -0
- package/dist/src/utils/helper.d.ts +286 -0
- package/dist/src/utils/icon.d.ts +12 -0
- package/dist/src/utils/image.d.ts +17 -0
- package/dist/src/utils/index.d.ts +12 -0
- package/dist/src/utils/isPureVariable.d.ts +1 -0
- package/dist/src/utils/json-schema-2-amis-schema.d.ts +6 -0
- package/dist/src/utils/keyToPath.d.ts +6 -0
- package/dist/src/utils/makeSorter.d.ts +1 -0
- package/dist/src/utils/markdown.d.ts +5 -0
- package/dist/src/utils/normalizeLink.d.ts +1 -0
- package/dist/src/utils/normalizeOptions.d.ts +7 -0
- package/dist/src/utils/object.d.ts +15 -0
- package/dist/src/utils/offset.d.ts +14 -0
- package/dist/src/utils/offsetParent.d.ts +4 -0
- package/dist/src/utils/optionValueCompare.d.ts +3 -0
- package/dist/src/utils/position.d.ts +15 -0
- package/dist/src/utils/prettyBytes.d.ts +1 -0
- package/dist/src/utils/renderer-event.d.ts +44 -0
- package/dist/src/utils/replaceText.d.ts +6 -0
- package/dist/src/utils/resize-sensor.d.ts +6 -0
- package/dist/src/utils/resolveVariable.d.ts +1 -0
- package/dist/src/utils/resolveVariableAndFilter.d.ts +1 -0
- package/dist/src/utils/scrollPosition.d.ts +6 -0
- package/dist/src/utils/string2regExp.d.ts +1 -0
- package/dist/src/utils/stripNumber.d.ts +1 -0
- package/dist/src/utils/style.d.ts +10 -0
- package/dist/src/utils/tokenize.d.ts +1 -0
- package/dist/src/utils/tpl-builtin.d.ts +18 -0
- package/dist/src/utils/tpl-lodash.d.ts +4 -0
- package/dist/src/utils/tpl.d.ts +11 -0
- package/dist/src/utils/validations.d.ts +39 -0
- package/dist/store/app.js +190 -0
- package/dist/store/combo.js +154 -0
- package/dist/store/crud.js +413 -0
- package/dist/store/form.js +579 -0
- package/dist/store/formItem.js +846 -0
- package/dist/store/iRenderer.js +189 -0
- package/dist/store/index.js +103 -0
- package/dist/store/list.js +248 -0
- package/dist/store/manager.js +56 -0
- package/dist/store/modal.js +54 -0
- package/dist/store/node.js +93 -0
- package/dist/store/pagination.js +60 -0
- package/dist/store/root.js +45 -0
- package/dist/store/service.js +415 -0
- package/dist/store/table-v2.js +471 -0
- package/dist/store/table.js +1105 -0
- package/dist/theme.js +93 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/utils/Animation.js +290 -0
- package/dist/utils/DataSchema.js +120 -0
- package/dist/utils/DataScope.js +151 -0
- package/dist/utils/SimpleMap.js +46 -0
- package/dist/utils/api.js +555 -0
- package/dist/utils/autobind.js +94 -0
- package/dist/utils/dataMapping.js +136 -0
- package/dist/utils/date.js +90 -0
- package/dist/utils/debug.js +343 -0
- package/dist/utils/errors.js +23 -0
- package/dist/utils/escapeHtml.js +24 -0
- package/dist/utils/filter-schema.js +75 -0
- package/dist/utils/filter.js +481 -0
- package/dist/utils/formatDuration.js +27 -0
- package/dist/utils/formula.js +165 -0
- package/dist/utils/getVariable.js +29 -0
- package/dist/utils/grammar.js +54 -0
- package/dist/utils/helper.js +1283 -0
- package/dist/utils/isPureVariable.js +16 -0
- package/dist/utils/keyToPath.js +34 -0
- package/dist/utils/makeSorter.js +30 -0
- package/dist/utils/normalizeLink.js +47 -0
- package/dist/utils/normalizeOptions.js +92 -0
- package/dist/utils/object.js +156 -0
- package/dist/utils/offset.js +36 -0
- package/dist/utils/offsetParent.js +27 -0
- package/dist/utils/optionValueCompare.js +25 -0
- package/dist/utils/position.js +50 -0
- package/dist/utils/prettyBytes.js +28 -0
- package/dist/utils/renderer-event.js +131 -0
- package/dist/utils/replaceText.js +35 -0
- package/dist/utils/resize-sensor.js +177 -0
- package/dist/utils/resolveVariable.js +39 -0
- package/dist/utils/resolveVariableAndFilter.js +37 -0
- package/dist/utils/string2regExp.js +18 -0
- package/dist/utils/stripNumber.js +20 -0
- package/dist/utils/tokenize.js +33 -0
- package/dist/utils/tpl-builtin.js +71 -0
- package/dist/utils/tpl-lodash.js +71 -0
- package/dist/utils/tpl.js +140 -0
- package/dist/utils/validations.js +377 -0
- package/package.json +121 -0
|
@@ -0,0 +1,377 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* amis-core v1.0.0-beta.0
|
|
3
|
+
* Copyright 2018-2022 fex
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
'use strict';
|
|
7
|
+
|
|
8
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
9
|
+
|
|
10
|
+
var tslib = require('tslib');
|
|
11
|
+
var tpl = require('./tpl.js');
|
|
12
|
+
require('amis-formula');
|
|
13
|
+
require('moment');
|
|
14
|
+
var isPlainObject = require('lodash/isPlainObject');
|
|
15
|
+
var isPureVariable = require('./isPureVariable.js');
|
|
16
|
+
var resolveVariableAndFilter = require('./resolveVariableAndFilter.js');
|
|
17
|
+
require('./filter.js');
|
|
18
|
+
var memoize = require('lodash/memoize');
|
|
19
|
+
|
|
20
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
21
|
+
|
|
22
|
+
var isPlainObject__default = /*#__PURE__*/_interopDefaultLegacy(isPlainObject);
|
|
23
|
+
var memoize__default = /*#__PURE__*/_interopDefaultLegacy(memoize);
|
|
24
|
+
|
|
25
|
+
var isExisty = function (value) { return value !== null && value !== undefined; };
|
|
26
|
+
var isEmpty = function (value) { return value === ''; };
|
|
27
|
+
var makeRegexp = function (reg) {
|
|
28
|
+
if (reg instanceof RegExp) {
|
|
29
|
+
return reg;
|
|
30
|
+
}
|
|
31
|
+
else if (/^(?:matchRegexp\:)?\/(.+)\/([gimuy]*)$/.test(reg)) {
|
|
32
|
+
return new RegExp(RegExp.$1, RegExp.$2 || '');
|
|
33
|
+
}
|
|
34
|
+
else if (typeof reg === 'string') {
|
|
35
|
+
return new RegExp(reg);
|
|
36
|
+
}
|
|
37
|
+
return /^$/;
|
|
38
|
+
};
|
|
39
|
+
var makeUrlRegexp = memoize__default["default"](function (options) {
|
|
40
|
+
options = tslib.__assign({ schemes: ['http', 'https', 'ftp', 'sftp'], allowLocal: true, allowDataUrl: false }, (isPlainObject__default["default"](options) ? options : {}));
|
|
41
|
+
// https://github.com/ansman/validate.js/blob/master/validate.js#L1098-L1164
|
|
42
|
+
var schemes = options.schemes, allowLocal = options.allowLocal, allowDataUrl = options.allowDataUrl;
|
|
43
|
+
if (!Array.isArray(schemes)) {
|
|
44
|
+
schemes = ['http', 'https', 'ftp', 'sftp'];
|
|
45
|
+
}
|
|
46
|
+
var regex = '^' +
|
|
47
|
+
// protocol identifier
|
|
48
|
+
'(?:(?:' +
|
|
49
|
+
schemes.join('|') +
|
|
50
|
+
')://)' +
|
|
51
|
+
// user:pass authentication
|
|
52
|
+
'(?:\\S+(?::\\S*)?@)?' +
|
|
53
|
+
'(?:';
|
|
54
|
+
var tld = '(?:\\.(?:[a-z\\u00a1-\\uffff]{2,}))';
|
|
55
|
+
if (allowLocal) {
|
|
56
|
+
tld += '?';
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
regex +=
|
|
60
|
+
// IP address exclusion
|
|
61
|
+
// private & local networks
|
|
62
|
+
'(?!(?:10|127)(?:\\.\\d{1,3}){3})' +
|
|
63
|
+
'(?!(?:169\\.254|192\\.168)(?:\\.\\d{1,3}){2})' +
|
|
64
|
+
'(?!172\\.(?:1[6-9]|2\\d|3[0-1])(?:\\.\\d{1,3}){2})';
|
|
65
|
+
}
|
|
66
|
+
regex +=
|
|
67
|
+
// IP address dotted notation octets
|
|
68
|
+
// excludes loopback network 0.0.0.0
|
|
69
|
+
// excludes reserved space >= 224.0.0.0
|
|
70
|
+
// excludes network & broacast addresses
|
|
71
|
+
// (first & last IP address of each class)
|
|
72
|
+
'(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])' +
|
|
73
|
+
'(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}' +
|
|
74
|
+
'(?:\\.(?:[1-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))' +
|
|
75
|
+
'|' +
|
|
76
|
+
// host name
|
|
77
|
+
'(?:(?:[a-z\\u00a1-\\uffff0-9]-*)*[a-z\\u00a1-\\uffff0-9]+)' +
|
|
78
|
+
// domain name
|
|
79
|
+
'(?:\\.(?:[a-z\\u00a1-\\uffff0-9]-*)*[a-z\\u00a1-\\uffff0-9]+)*' +
|
|
80
|
+
tld +
|
|
81
|
+
')' +
|
|
82
|
+
// port number
|
|
83
|
+
'(?::\\d{2,5})?' +
|
|
84
|
+
// resource path
|
|
85
|
+
'(?:[/?#]\\S*)?' +
|
|
86
|
+
'$';
|
|
87
|
+
if (allowDataUrl) {
|
|
88
|
+
// RFC 2397
|
|
89
|
+
var mediaType = '\\w+\\/[-+.\\w]+(?:;[\\w=]+)*';
|
|
90
|
+
var urlchar = "[A-Za-z0-9-_.!~\\*'();\\/?:@&=+$,%]*";
|
|
91
|
+
var dataurl = 'data:(?:' + mediaType + ')?(?:;base64)?,' + urlchar;
|
|
92
|
+
regex = '(?:' + regex + ')|(?:^' + dataurl + '$)';
|
|
93
|
+
}
|
|
94
|
+
return new RegExp(regex, 'i');
|
|
95
|
+
});
|
|
96
|
+
var validations = {
|
|
97
|
+
isRequired: function (values, value) {
|
|
98
|
+
return (value !== undefined &&
|
|
99
|
+
value !== '' &&
|
|
100
|
+
value !== null &&
|
|
101
|
+
(!Array.isArray(value) || !!value.length));
|
|
102
|
+
},
|
|
103
|
+
isExisty: function (values, value) {
|
|
104
|
+
return isExisty(value);
|
|
105
|
+
},
|
|
106
|
+
matchRegexp: function (values, value, regexp) {
|
|
107
|
+
return !isExisty(value) || isEmpty(value) || makeRegexp(regexp).test(value);
|
|
108
|
+
},
|
|
109
|
+
isUndefined: function (values, value) {
|
|
110
|
+
return value === undefined;
|
|
111
|
+
},
|
|
112
|
+
isEmptyString: function (values, value) {
|
|
113
|
+
return isEmpty(value);
|
|
114
|
+
},
|
|
115
|
+
isEmail: function (values, value) {
|
|
116
|
+
return validations.matchRegexp(values, value, /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))$/i);
|
|
117
|
+
},
|
|
118
|
+
isUrl: function (values, value, options) {
|
|
119
|
+
return validations.matchRegexp(values, value, makeUrlRegexp(options));
|
|
120
|
+
},
|
|
121
|
+
isTrue: function (values, value) {
|
|
122
|
+
return value === true;
|
|
123
|
+
},
|
|
124
|
+
isFalse: function (values, value) {
|
|
125
|
+
return value === false;
|
|
126
|
+
},
|
|
127
|
+
isNumeric: function (values, value) {
|
|
128
|
+
if (typeof value === 'number') {
|
|
129
|
+
return true;
|
|
130
|
+
}
|
|
131
|
+
return validations.matchRegexp(values, value, /^[-+]?(?:\d*[.])?\d+$/);
|
|
132
|
+
},
|
|
133
|
+
isAlpha: function (values, value) {
|
|
134
|
+
return validations.matchRegexp(values, value, /^[A-Z]+$/i);
|
|
135
|
+
},
|
|
136
|
+
isAlphanumeric: function (values, value) {
|
|
137
|
+
return validations.matchRegexp(values, value, /^[0-9A-Z]+$/i);
|
|
138
|
+
},
|
|
139
|
+
isInt: function (values, value) {
|
|
140
|
+
return validations.matchRegexp(values, value, /^(?:[-+]?(?:0|[1-9]\d*))$/);
|
|
141
|
+
},
|
|
142
|
+
isFloat: function (values, value) {
|
|
143
|
+
return validations.matchRegexp(values, value, /^(?:[-+]?(?:\d+))?(?:\.\d*)?(?:[eE][\+\-]?(?:\d+))?$/);
|
|
144
|
+
},
|
|
145
|
+
isWords: function (values, value) {
|
|
146
|
+
return validations.matchRegexp(values, value, /^[A-Z\s]+$/i);
|
|
147
|
+
},
|
|
148
|
+
isSpecialWords: function (values, value) {
|
|
149
|
+
return validations.matchRegexp(values, value, /^[A-Z\s\u00C0-\u017F]+$/i);
|
|
150
|
+
},
|
|
151
|
+
isLength: function (values, value, length) {
|
|
152
|
+
return !isExisty(value) || isEmpty(value) || value.length === length;
|
|
153
|
+
},
|
|
154
|
+
equals: function (values, value, eql) {
|
|
155
|
+
return !isExisty(value) || isEmpty(value) || value == eql;
|
|
156
|
+
},
|
|
157
|
+
equalsField: function (values, value, field) {
|
|
158
|
+
return value == values[field];
|
|
159
|
+
},
|
|
160
|
+
maxLength: function (values, value, length) {
|
|
161
|
+
// 此方法应该判断文本长度,如果传入数据为number,导致 maxLength 和 maximum 表现一致了,默认转成string
|
|
162
|
+
if (typeof value === 'number') {
|
|
163
|
+
value = String(value);
|
|
164
|
+
}
|
|
165
|
+
return !isExisty(value) || value.length <= length;
|
|
166
|
+
},
|
|
167
|
+
minLength: function (values, value, length) {
|
|
168
|
+
return !isExisty(value) || isEmpty(value) || value.length >= length;
|
|
169
|
+
},
|
|
170
|
+
isUrlPath: function (values, value, regexp) {
|
|
171
|
+
return !isExisty(value) || isEmpty(value) || /^[a-z0-9_\\-]+$/i.test(value);
|
|
172
|
+
},
|
|
173
|
+
maximum: function (values, value, maximum) {
|
|
174
|
+
return (!isExisty(value) ||
|
|
175
|
+
isEmpty(value) ||
|
|
176
|
+
(parseFloat(value) || 0) <= (parseFloat(maximum) || 0));
|
|
177
|
+
},
|
|
178
|
+
lt: function (values, value, maximum) {
|
|
179
|
+
return (!isExisty(value) ||
|
|
180
|
+
isEmpty(value) ||
|
|
181
|
+
(parseFloat(value) || 0) < (parseFloat(maximum) || 0));
|
|
182
|
+
},
|
|
183
|
+
minimum: function (values, value, minimum) {
|
|
184
|
+
return (!isExisty(value) ||
|
|
185
|
+
isEmpty(value) ||
|
|
186
|
+
(parseFloat(value) || 0) >= (parseFloat(minimum) || 0));
|
|
187
|
+
},
|
|
188
|
+
gt: function (values, value, minimum) {
|
|
189
|
+
return (!isExisty(value) ||
|
|
190
|
+
isEmpty(value) ||
|
|
191
|
+
(parseFloat(value) || 0) > (parseFloat(minimum) || 0));
|
|
192
|
+
},
|
|
193
|
+
isJson: function (values, value, minimum) {
|
|
194
|
+
if (isExisty(value) && !isEmpty(value) && typeof value === 'string') {
|
|
195
|
+
try {
|
|
196
|
+
var result = JSON.parse(value);
|
|
197
|
+
if (typeof result === 'object' && result) {
|
|
198
|
+
return true;
|
|
199
|
+
}
|
|
200
|
+
return false;
|
|
201
|
+
}
|
|
202
|
+
catch (e) {
|
|
203
|
+
return false;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
return true;
|
|
207
|
+
},
|
|
208
|
+
isPhoneNumber: function (values, value) {
|
|
209
|
+
return (!isExisty(value) || isEmpty(value) || /^[1]([3-9])[0-9]{9}$/.test(value));
|
|
210
|
+
},
|
|
211
|
+
isTelNumber: function (values, value) {
|
|
212
|
+
return (!isExisty(value) ||
|
|
213
|
+
isEmpty(value) ||
|
|
214
|
+
/^(\(\d{3,4}\)|\d{3,4}-|\s)?\d{7,14}$/.test(value));
|
|
215
|
+
},
|
|
216
|
+
isZipcode: function (values, value) {
|
|
217
|
+
return !isExisty(value) || isEmpty(value) || /^\d{6}$/.test(value);
|
|
218
|
+
},
|
|
219
|
+
isId: function (values, value) {
|
|
220
|
+
return (!isExisty(value) ||
|
|
221
|
+
isEmpty(value) ||
|
|
222
|
+
/(^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$)|(^[1-9]\d{5}\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}$)/.test(value));
|
|
223
|
+
},
|
|
224
|
+
notEmptyString: function (values, value) {
|
|
225
|
+
return !isExisty(value) || !(String(value) && String(value).trim() === '');
|
|
226
|
+
},
|
|
227
|
+
matchRegexp1: function (values, value, regexp) {
|
|
228
|
+
return validations.matchRegexp(values, value, regexp);
|
|
229
|
+
},
|
|
230
|
+
matchRegexp2: function (values, value, regexp) {
|
|
231
|
+
return validations.matchRegexp(values, value, regexp);
|
|
232
|
+
},
|
|
233
|
+
matchRegexp3: function (values, value, regexp) {
|
|
234
|
+
return validations.matchRegexp(values, value, regexp);
|
|
235
|
+
},
|
|
236
|
+
matchRegexp4: function (values, value, regexp) {
|
|
237
|
+
return validations.matchRegexp(values, value, regexp);
|
|
238
|
+
},
|
|
239
|
+
matchRegexp5: function (values, value, regexp) {
|
|
240
|
+
return validations.matchRegexp(values, value, regexp);
|
|
241
|
+
},
|
|
242
|
+
matchRegexp6: function (values, value, regexp) {
|
|
243
|
+
return validations.matchRegexp(values, value, regexp);
|
|
244
|
+
},
|
|
245
|
+
matchRegexp7: function (values, value, regexp) {
|
|
246
|
+
return validations.matchRegexp(values, value, regexp);
|
|
247
|
+
},
|
|
248
|
+
matchRegexp8: function (values, value, regexp) {
|
|
249
|
+
return validations.matchRegexp(values, value, regexp);
|
|
250
|
+
},
|
|
251
|
+
matchRegexp9: function (values, value, regexp) {
|
|
252
|
+
return validations.matchRegexp(values, value, regexp);
|
|
253
|
+
}
|
|
254
|
+
};
|
|
255
|
+
function addRule(ruleName, fn, message) {
|
|
256
|
+
if (message === void 0) { message = ''; }
|
|
257
|
+
validations[ruleName] = fn;
|
|
258
|
+
validateMessages[ruleName] = message;
|
|
259
|
+
}
|
|
260
|
+
var validateMessages = {
|
|
261
|
+
isEmail: 'validate.isEmail',
|
|
262
|
+
isRequired: 'validate.isRequired',
|
|
263
|
+
isUrl: 'validate.isUrl',
|
|
264
|
+
isInt: 'validate.isInt',
|
|
265
|
+
isAlpha: 'validate.isAlpha',
|
|
266
|
+
isNumeric: 'validate.isNumeric',
|
|
267
|
+
isAlphanumeric: 'validate.isAlphanumeric',
|
|
268
|
+
isFloat: 'validate.isFloat',
|
|
269
|
+
isWords: 'validate.isWords',
|
|
270
|
+
isUrlPath: 'validate.isUrlPath',
|
|
271
|
+
matchRegexp: 'validate.matchRegexp',
|
|
272
|
+
minLength: 'validate.minLength',
|
|
273
|
+
maxLength: 'validate.maxLength',
|
|
274
|
+
maximum: 'validate.maximum',
|
|
275
|
+
lt: 'validate.lt',
|
|
276
|
+
minimum: 'validate.minimum',
|
|
277
|
+
gt: 'validate.gt',
|
|
278
|
+
isJson: 'validate.isJson',
|
|
279
|
+
isLength: 'validate.isLength',
|
|
280
|
+
notEmptyString: 'validate.notEmptyString',
|
|
281
|
+
equalsField: 'validate.equalsField',
|
|
282
|
+
equals: 'validate.equals',
|
|
283
|
+
isPhoneNumber: 'validate.isPhoneNumber',
|
|
284
|
+
isTelNumber: 'validate.isTelNumber',
|
|
285
|
+
isZipcode: 'validate.isZipcode',
|
|
286
|
+
isId: 'validate.isId'
|
|
287
|
+
};
|
|
288
|
+
function validate(value, values, rules, messages, __) {
|
|
289
|
+
if (__ === void 0) { __ = function (str) { return str; }; }
|
|
290
|
+
var errors = [];
|
|
291
|
+
rules &&
|
|
292
|
+
Object.keys(rules).forEach(function (ruleName) {
|
|
293
|
+
if (!rules[ruleName] && rules[ruleName] !== 0) {
|
|
294
|
+
return;
|
|
295
|
+
}
|
|
296
|
+
else if (typeof validations[ruleName] !== 'function') {
|
|
297
|
+
throw new Error('Validation `' + ruleName + '` not exists!');
|
|
298
|
+
}
|
|
299
|
+
var fn = validations[ruleName];
|
|
300
|
+
var args = (Array.isArray(rules[ruleName]) ? rules[ruleName] : [rules[ruleName]]).map(function (item) {
|
|
301
|
+
if (typeof item === 'string' && isPureVariable.isPureVariable(item)) {
|
|
302
|
+
return resolveVariableAndFilter.resolveVariableAndFilter(item, values, '|raw');
|
|
303
|
+
}
|
|
304
|
+
return item;
|
|
305
|
+
});
|
|
306
|
+
if (!fn.apply(void 0, tslib.__spreadArray([values, value], args, false))) {
|
|
307
|
+
errors.push({
|
|
308
|
+
rule: ruleName,
|
|
309
|
+
msg: tpl.filter(__((messages && messages[ruleName]) || validateMessages[ruleName]), tslib.__assign({}, [''].concat(args)))
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
});
|
|
313
|
+
return errors;
|
|
314
|
+
}
|
|
315
|
+
function validateObject(values, rules, messages, __) {
|
|
316
|
+
if (__ === void 0) { __ = function (str) { return str; }; }
|
|
317
|
+
var ret = {};
|
|
318
|
+
Object.keys(rules).forEach(function (key) {
|
|
319
|
+
var msgs = validate(values[key], values, rules[key] === true
|
|
320
|
+
? {
|
|
321
|
+
isRequired: true
|
|
322
|
+
}
|
|
323
|
+
: rules[key], messages, __);
|
|
324
|
+
if (msgs.length) {
|
|
325
|
+
ret[key] = msgs;
|
|
326
|
+
}
|
|
327
|
+
});
|
|
328
|
+
return ret;
|
|
329
|
+
}
|
|
330
|
+
var splitValidations = function (str) {
|
|
331
|
+
var i = 0;
|
|
332
|
+
var placeholder = {};
|
|
333
|
+
return str
|
|
334
|
+
.replace(/matchRegexp\d*\s*\:\s*\/.*?\/[igm]*/g, function (raw) {
|
|
335
|
+
placeholder["__".concat(i)] = raw;
|
|
336
|
+
return "__".concat(i++);
|
|
337
|
+
})
|
|
338
|
+
.split(/,(?![^{\[]*[}\]])/g)
|
|
339
|
+
.map(function (str) { return (/^__\d+$/.test(str) ? placeholder[str] : str.trim()); });
|
|
340
|
+
};
|
|
341
|
+
function str2rules(validations) {
|
|
342
|
+
if (typeof validations === 'string') {
|
|
343
|
+
return validations
|
|
344
|
+
? splitValidations(validations).reduce(function (validations, validation) {
|
|
345
|
+
var idx = validation.indexOf(':');
|
|
346
|
+
var validateMethod = validation;
|
|
347
|
+
var args = [];
|
|
348
|
+
if (~idx) {
|
|
349
|
+
validateMethod = validation.substring(0, idx);
|
|
350
|
+
args = /^matchRegexp/.test(validateMethod)
|
|
351
|
+
? [validation.substring(idx + 1).trim()]
|
|
352
|
+
: validation
|
|
353
|
+
.substring(idx + 1)
|
|
354
|
+
.split(',')
|
|
355
|
+
.map(function (arg) {
|
|
356
|
+
try {
|
|
357
|
+
return JSON.parse(arg);
|
|
358
|
+
}
|
|
359
|
+
catch (e) {
|
|
360
|
+
return arg;
|
|
361
|
+
}
|
|
362
|
+
});
|
|
363
|
+
}
|
|
364
|
+
validations[validateMethod] = args.length ? args : true;
|
|
365
|
+
return validations;
|
|
366
|
+
}, {})
|
|
367
|
+
: {};
|
|
368
|
+
}
|
|
369
|
+
return validations || {};
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
exports.addRule = addRule;
|
|
373
|
+
exports.str2rules = str2rules;
|
|
374
|
+
exports.validate = validate;
|
|
375
|
+
exports.validateMessages = validateMessages;
|
|
376
|
+
exports.validateObject = validateObject;
|
|
377
|
+
exports.validations = validations;
|
package/package.json
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "amis-core",
|
|
3
|
+
"version": "1.0.0-beta.0",
|
|
4
|
+
"description": "amis-core",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"module": "./esm-dist/index.js",
|
|
7
|
+
"author": "fex",
|
|
8
|
+
"license": "Apache-2.0",
|
|
9
|
+
"devDependencies": {
|
|
10
|
+
"@rollup/plugin-commonjs": "^22.0.0",
|
|
11
|
+
"@rollup/plugin-json": "^4.1.0",
|
|
12
|
+
"@rollup/plugin-node-resolve": "^13.3.0",
|
|
13
|
+
"@rollup/plugin-typescript": "^8.3.2",
|
|
14
|
+
"@testing-library/jest-dom": "^5.16.4",
|
|
15
|
+
"@types/file-saver": "^2.0.1",
|
|
16
|
+
"@types/hoist-non-react-statics": "^3.3.1",
|
|
17
|
+
"@types/jest": "^27.0.2",
|
|
18
|
+
"@types/react": "^17.0.39",
|
|
19
|
+
"@types/react-dom": "^17.0.11",
|
|
20
|
+
"jest": "^27.2.1",
|
|
21
|
+
"moment-timezone": "^0.5.34",
|
|
22
|
+
"react": "^18.0.0",
|
|
23
|
+
"react-dom": "^18.0.0",
|
|
24
|
+
"rimraf": "^3.0.2",
|
|
25
|
+
"rollup": "^2.73.0",
|
|
26
|
+
"rollup-plugin-auto-external": "^2.0.0",
|
|
27
|
+
"rollup-plugin-license": "^2.7.0",
|
|
28
|
+
"typescript": "^4.6.4"
|
|
29
|
+
},
|
|
30
|
+
"scripts": {
|
|
31
|
+
"build": "npm run clean-dist && NODE_ENV=production rollup -c ",
|
|
32
|
+
"dev": "rollup -c -w",
|
|
33
|
+
"test": "jest",
|
|
34
|
+
"coverage": "jest --coverage",
|
|
35
|
+
"clean-dist": "rimraf dist/* esm-dist/*"
|
|
36
|
+
},
|
|
37
|
+
"files": [
|
|
38
|
+
"dist"
|
|
39
|
+
],
|
|
40
|
+
"dependencies": {
|
|
41
|
+
"amis-formula": "^2.0.0-beta.0",
|
|
42
|
+
"classnames": "2.3.1",
|
|
43
|
+
"file-saver": "^2.0.2",
|
|
44
|
+
"hoist-non-react-statics": "^3.3.2",
|
|
45
|
+
"lodash": "^4.17.15",
|
|
46
|
+
"match-sorter": "^6.3.1",
|
|
47
|
+
"mobx": "^4.5.0",
|
|
48
|
+
"mobx-react": "^6.3.1",
|
|
49
|
+
"mobx-state-tree": "^3.17.3",
|
|
50
|
+
"moment": "^2.19.3",
|
|
51
|
+
"papaparse": "^5.3.0",
|
|
52
|
+
"qs": "6.9.7",
|
|
53
|
+
"react": "^18.0.0",
|
|
54
|
+
"react-dom": "^18.0.0",
|
|
55
|
+
"react-json-view": "1.21.3",
|
|
56
|
+
"react-visibility-sensor": "5.1.1",
|
|
57
|
+
"tslib": "^2.3.1"
|
|
58
|
+
},
|
|
59
|
+
"jest": {
|
|
60
|
+
"testEnvironment": "jsdom",
|
|
61
|
+
"collectCoverageFrom": [
|
|
62
|
+
"src/**/*"
|
|
63
|
+
],
|
|
64
|
+
"moduleFileExtensions": [
|
|
65
|
+
"ts",
|
|
66
|
+
"tsx",
|
|
67
|
+
"js"
|
|
68
|
+
],
|
|
69
|
+
"transform": {
|
|
70
|
+
"\\.(ts|tsx)$": "ts-jest"
|
|
71
|
+
},
|
|
72
|
+
"setupFiles": [
|
|
73
|
+
"jest-canvas-mock"
|
|
74
|
+
],
|
|
75
|
+
"testRegex": "/.*\\.test\\.(ts|tsx|js)$",
|
|
76
|
+
"moduleNameMapper": {
|
|
77
|
+
"\\.(css|less|sass|scss)$": "<rootDir>/../__mocks__/styleMock.js",
|
|
78
|
+
"\\.(svg)$": "<rootDir>/../__mocks__/svgMock.js"
|
|
79
|
+
},
|
|
80
|
+
"setupFilesAfterEnv": [
|
|
81
|
+
"<rootDir>/__tests__/jest.setup.js"
|
|
82
|
+
],
|
|
83
|
+
"testPathIgnorePatterns": [
|
|
84
|
+
"/node_modules/",
|
|
85
|
+
"/.rollup.cache/"
|
|
86
|
+
],
|
|
87
|
+
"globals": {
|
|
88
|
+
"ts-jest": {
|
|
89
|
+
"diagnostics": false,
|
|
90
|
+
"tsconfig": {
|
|
91
|
+
"module": "commonjs",
|
|
92
|
+
"target": "es5",
|
|
93
|
+
"lib": [
|
|
94
|
+
"es6",
|
|
95
|
+
"dom",
|
|
96
|
+
"ES2015"
|
|
97
|
+
],
|
|
98
|
+
"sourceMap": true,
|
|
99
|
+
"jsx": "react",
|
|
100
|
+
"moduleResolution": "node",
|
|
101
|
+
"rootDir": ".",
|
|
102
|
+
"importHelpers": true,
|
|
103
|
+
"esModuleInterop": true,
|
|
104
|
+
"allowSyntheticDefaultImports": true,
|
|
105
|
+
"sourceRoot": ".",
|
|
106
|
+
"noImplicitReturns": true,
|
|
107
|
+
"noImplicitThis": true,
|
|
108
|
+
"noImplicitAny": true,
|
|
109
|
+
"strictNullChecks": true,
|
|
110
|
+
"experimentalDecorators": true,
|
|
111
|
+
"emitDecoratorMetadata": false,
|
|
112
|
+
"typeRoots": [
|
|
113
|
+
"./node_modules/@types",
|
|
114
|
+
"./types"
|
|
115
|
+
],
|
|
116
|
+
"skipLibCheck": true
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|