@opentiny/vue-renderless 3.21.2 → 3.23.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.
Files changed (331) hide show
  1. package/amount/index.js +4 -4
  2. package/anchor/index.js +1 -1
  3. package/async-flowchart/index.js +1 -1
  4. package/autocomplete/index.js +4 -1
  5. package/autocomplete/vue.js +3 -3
  6. package/base-select/index.js +20 -21
  7. package/base-select/vue.js +2 -2
  8. package/calendar/index.js +2 -2
  9. package/calendar-bar/index.js +2 -2
  10. package/calendar-bar/vue.js +1 -1
  11. package/calendar-view/index.js +91 -25
  12. package/calendar-view/vue.js +6 -4
  13. package/card/index.js +1 -1
  14. package/card-template/index.js +1 -1
  15. package/carousel/index.js +4 -4
  16. package/carousel/vue.js +1 -1
  17. package/cascader/index.js +21 -11
  18. package/cascader/vue.js +6 -5
  19. package/cascader-menu/vue.js +2 -2
  20. package/cascader-mobile/index.js +1 -1
  21. package/cascader-node/vue.js +11 -1
  22. package/cascader-panel/index.js +4 -4
  23. package/cascader-panel/node.js +3 -4
  24. package/cascader-panel/vue.js +1 -1
  25. package/cascader-select/column-index.js +2 -2
  26. package/cascader-view/index.js +1 -1
  27. package/chart-bar/index.js +1 -1
  28. package/chart-candle/index.js +1 -1
  29. package/chart-core/deps/utils.js +6 -6
  30. package/chart-core/index.js +1 -1
  31. package/chart-funnel/index.js +1 -1
  32. package/chart-gauge/index.js +1 -1
  33. package/chart-line/index.js +1 -1
  34. package/chart-map/index.js +1 -1
  35. package/chart-pie/index.js +1 -1
  36. package/chart-radar/index.js +1 -1
  37. package/chart-sankey/index.js +1 -1
  38. package/chart-scatter/index.js +1 -1
  39. package/chart-waterfall/index.js +1 -1
  40. package/chart-wordcloud/index.js +1 -1
  41. package/checkbox/index.js +1 -1
  42. package/collapse-item/vue.js +1 -1
  43. package/column-list-item/index.js +1 -1
  44. package/common/deps/dom.js +20 -196
  45. package/common/deps/infinite-scroll.js +4 -43
  46. package/common/deps/popup-manager.js +1 -200
  47. package/container/index.js +2 -2
  48. package/crop/index.js +3 -3
  49. package/currency/index.js +2 -2
  50. package/date-panel/index.js +82 -26
  51. package/date-panel/vue.js +53 -21
  52. package/date-picker/vue.js +1 -1
  53. package/date-picker-mobile/index.js +1 -1
  54. package/date-range/index.js +74 -37
  55. package/date-range/vue.js +27 -23
  56. package/date-table/index.js +8 -5
  57. package/date-table/vue.js +1 -1
  58. package/dialog-box/index.js +3 -3
  59. package/dialog-box/vue.js +1 -1
  60. package/dialog-select/index.js +15 -4
  61. package/dialog-select/vue.js +7 -4
  62. package/drawer/index.js +2 -2
  63. package/drop-times/index.js +1 -1
  64. package/dropdown/index.js +11 -3
  65. package/dropdown/vue.js +2 -2
  66. package/dropdown-item/index.js +1 -1
  67. package/dropdown-item/mf.js +1 -1
  68. package/dropdown-menu/index.js +1 -1
  69. package/espace/vue.js +2 -2
  70. package/fall-menu/index.js +3 -3
  71. package/file-upload/index.js +16 -13
  72. package/file-upload/vue.js +2 -2
  73. package/filter/vue.js +1 -1
  74. package/filter-panel/vue.js +1 -2
  75. package/floating-button/index.js +1 -1
  76. package/flowchart/index.js +3 -3
  77. package/flowchart/vue.js +1 -1
  78. package/fluent-editor/index.js +5 -7
  79. package/fluent-editor/options.js +2 -2
  80. package/form/index.js +20 -2
  81. package/form-item/index.js +6 -6
  82. package/fullscreen/index.js +1 -1
  83. package/fullscreen/vue.js +1 -1
  84. package/grid/plugins/export.js +8 -2
  85. package/grid/plugins/exportExcel.js +3 -3
  86. package/grid/plugins/resize.js +2 -2
  87. package/grid/static/base/helperEqualCompare.js +1 -1
  88. package/grid/static/base/isPlainObject.js +1 -1
  89. package/grid/utils/common.js +2 -2
  90. package/grid/utils/dom.js +12 -7
  91. package/grid/utils/event.js +4 -4
  92. package/hrapprover/index.js +1 -1
  93. package/image/index.js +3 -3
  94. package/image-viewer/index.js +4 -6
  95. package/image-viewer/vue.js +1 -1
  96. package/input/index.js +2 -2
  97. package/input/vue.js +1 -1
  98. package/ip-address/index.js +17 -21
  99. package/ip-address/vue.js +1 -1
  100. package/link-menu/index.js +1 -1
  101. package/link-menu/vue.js +1 -1
  102. package/load-list/index.js +1 -1
  103. package/load-list/vue.js +4 -4
  104. package/loading/index.js +2 -2
  105. package/menu/vue.js +1 -1
  106. package/milestone/index.js +6 -45
  107. package/modal/index.js +5 -5
  108. package/month-range/index.js +48 -5
  109. package/month-range/vue.js +19 -15
  110. package/month-table/index.js +5 -5
  111. package/month-table/vue.js +1 -1
  112. package/nav-menu/index.js +7 -7
  113. package/notify/index.js +3 -3
  114. package/number-animation/index.js +53 -0
  115. package/number-animation/vue.js +27 -0
  116. package/numeric/index.js +5 -5
  117. package/option/index.js +1 -1
  118. package/option/vue.js +2 -1
  119. package/package.json +3 -2
  120. package/pager/index.js +28 -16
  121. package/pager/vue.js +27 -16
  122. package/panel/index.js +1 -1
  123. package/picker/index.js +28 -23
  124. package/picker/vue.js +6 -6
  125. package/picker-column/index.js +1 -1
  126. package/pop-upload/vue.js +1 -1
  127. package/popconfirm/vue.js +1 -1
  128. package/popeditor/index.js +6 -6
  129. package/popeditor/vue.js +2 -2
  130. package/popover/index.js +3 -3
  131. package/popover/vue.js +1 -1
  132. package/popup/index.js +3 -3
  133. package/pull-refresh/index.js +1 -1
  134. package/pull-refresh-mobile-first/index.js +1 -1
  135. package/pull-refresh-mobile-first/vue.js +4 -4
  136. package/quarter-panel/index.js +2 -2
  137. package/quarter-panel/vue.js +1 -1
  138. package/radio-group/index.js +1 -1
  139. package/rate/index.js +1 -1
  140. package/rate/vue.js +1 -1
  141. package/recycle-scroller/index.js +2 -2
  142. package/recycle-scroller/vue.js +1 -1
  143. package/rich-text/index.js +1 -1
  144. package/rich-text/table-module.js +2 -2
  145. package/river/river.js +1 -1
  146. package/river/vue.js +1 -1
  147. package/scrollbar/vue-bar.js +1 -1
  148. package/scrollbar/vue.js +1 -1
  149. package/search/index.js +3 -3
  150. package/select/index.js +26 -22
  151. package/select/vue.js +8 -7
  152. package/select-dropdown/vue.js +5 -5
  153. package/selected-box/index.js +1 -1
  154. package/signature/index.js +1 -1
  155. package/signature/vue.js +2 -2
  156. package/skeleton/index.js +1 -1
  157. package/slider/index.js +4 -4
  158. package/slider-button-group/slide-button.js +2 -2
  159. package/split/index.js +2 -2
  160. package/split/vue.js +1 -1
  161. package/statistic/index.js +1 -1
  162. package/steps/index.js +2 -3
  163. package/steps/slide-bar.js +2 -2
  164. package/sticky/vue.js +4 -4
  165. package/tab-bar/index.js +2 -2
  166. package/tab-item-mf/vue.js +1 -1
  167. package/tab-nav/index.js +4 -4
  168. package/tabbar/index.js +1 -1
  169. package/tabbar/vue.js +1 -1
  170. package/tabbar-item/index.js +1 -1
  171. package/tabs-mf/index.js +9 -5
  172. package/tabs-mf/vue-bar.js +5 -4
  173. package/tabs-mf/vue-swipe.js +1 -1
  174. package/tabs-mf/vue.js +2 -2
  175. package/tabs-mf/wheel.js +3 -3
  176. package/tag-group/vue.js +2 -2
  177. package/tall-storage/index.js +1 -1
  178. package/tall-storage/vue.js +1 -1
  179. package/time/index.js +1 -1
  180. package/time/vue.js +1 -1
  181. package/time-line/index.js +1 -1
  182. package/time-line-new/index.js +1 -1
  183. package/time-panel/index.js +2 -2
  184. package/time-panel/vue.js +1 -1
  185. package/time-range/index.js +1 -1
  186. package/time-range/vue.js +1 -1
  187. package/time-spinner/index.js +4 -4
  188. package/time-spinner/vue.js +1 -1
  189. package/timeline-item/index.js +1 -1
  190. package/toggle-menu/index.js +1 -1
  191. package/tooltip/index.js +2 -2
  192. package/tooltip/vue.js +2 -2
  193. package/top-box/index.js +3 -3
  194. package/transfer/index.js +42 -1
  195. package/transfer/vue.js +64 -24
  196. package/transfer-panel/index.js +6 -1
  197. package/tree/index.js +9 -9
  198. package/tree/vue.js +2 -2
  199. package/tree-node/index.js +1 -1
  200. package/tree-node/vue.js +1 -1
  201. package/tree-select/index.js +68 -22
  202. package/tree-select/vue.js +27 -3
  203. package/types/async-flowchart.type.d.ts +2 -14
  204. package/types/breadcrumb-item.type.d.ts +5 -1
  205. package/types/breadcrumb.type.d.ts +5 -1
  206. package/types/button-group.type.d.ts +5 -1
  207. package/types/button.type.d.ts +2 -2
  208. package/types/cascader.type.d.ts +6 -1
  209. package/types/date-table.type.d.ts +1 -120
  210. package/types/dropdown.type.d.ts +1 -1
  211. package/types/label.type.d.ts +1 -53
  212. package/types/loading.type.d.ts +12 -0
  213. package/types/numeric.type.d.ts +3 -22
  214. package/types/pager.type.d.ts +12 -7
  215. package/types/popconfirm.type.d.ts +2 -0
  216. package/types/steps.type.d.ts +1 -0
  217. package/types/tag-group.type.d.ts +2 -14
  218. package/types/tag.type.d.ts +4 -4
  219. package/types/tooltip.type.d.ts +3 -13
  220. package/types/transfer.type.d.ts +3 -0
  221. package/types/user-head.type.d.ts +0 -4
  222. package/upload/index.js +1 -1
  223. package/upload-list/index.js +1 -1
  224. package/upload-list/vue.js +4 -4
  225. package/user/index.js +7 -7
  226. package/user/vue.js +15 -2
  227. package/user-contact/vue.js +2 -2
  228. package/virtual-scroll-box/index.js +2 -2
  229. package/wizard/index.js +3 -3
  230. package/year-range/index.js +61 -11
  231. package/year-range/vue.js +33 -20
  232. package/year-table/index.js +10 -5
  233. package/avatar/index.js +0 -30
  234. package/avatar/vue.js +0 -22
  235. package/common/array.js +0 -115
  236. package/common/bigInt.js +0 -315
  237. package/common/browser.js +0 -81
  238. package/common/calendar/calendar.js +0 -97
  239. package/common/dataset/index.js +0 -99
  240. package/common/date.js +0 -354
  241. package/common/decimal.js +0 -155
  242. package/common/deps/ResizeObserver.js +0 -456
  243. package/common/deps/after-leave.js +0 -27
  244. package/common/deps/clickoutside.js +0 -75
  245. package/common/deps/date-util.js +0 -255
  246. package/common/deps/date.js +0 -286
  247. package/common/deps/debounce.js +0 -8
  248. package/common/deps/eSpaceCtrl.js +0 -304
  249. package/common/deps/fastdom/async.js +0 -41
  250. package/common/deps/fastdom/index.js +0 -9
  251. package/common/deps/fastdom/sandbox.js +0 -53
  252. package/common/deps/fastdom/singleton.js +0 -88
  253. package/common/deps/fullscreen/apis.js +0 -143
  254. package/common/deps/fullscreen/screenfull.js +0 -165
  255. package/common/deps/memorize.js +0 -124
  256. package/common/deps/observe-visibility.js +0 -106
  257. package/common/deps/popper.js +0 -616
  258. package/common/deps/repeat-click.js +0 -29
  259. package/common/deps/resize-event.js +0 -39
  260. package/common/deps/scroll-into-view.js +0 -29
  261. package/common/deps/scrollbar-width.js +0 -33
  262. package/common/deps/throttle.js +0 -45
  263. package/common/deps/touch-emulator.js +0 -103
  264. package/common/deps/touch.js +0 -37
  265. package/common/deps/tree-model/node.js +0 -475
  266. package/common/deps/tree-model/tree-store.js +0 -312
  267. package/common/deps/tree-model/util.js +0 -24
  268. package/common/deps/upload-ajax.js +0 -81
  269. package/common/deps/useEventListener.js +0 -54
  270. package/common/deps/useInstanceSlots.js +0 -22
  271. package/common/deps/useRect.js +0 -25
  272. package/common/deps/useRelation.js +0 -89
  273. package/common/deps/useTouch.js +0 -68
  274. package/common/deps/useUserAgent.js +0 -16
  275. package/common/deps/useWindowSize.js +0 -23
  276. package/common/deps/vue-emitter.js +0 -34
  277. package/common/deps/vue-popper.js +0 -180
  278. package/common/deps/vue-popup.js +0 -138
  279. package/common/event.js +0 -46
  280. package/common/form/const.js +0 -10
  281. package/common/function.js +0 -28
  282. package/common/global.js +0 -11
  283. package/common/index.js +0 -259
  284. package/common/object.js +0 -227
  285. package/common/prop-util.js +0 -43
  286. package/common/runtime.js +0 -79
  287. package/common/string.js +0 -417
  288. package/common/type.js +0 -66
  289. package/common/validate/index.js +0 -10
  290. package/common/validate/messages.js +0 -65
  291. package/common/validate/rules/enum.js +0 -12
  292. package/common/validate/rules/index.js +0 -18
  293. package/common/validate/rules/pattern.js +0 -20
  294. package/common/validate/rules/range.js +0 -52
  295. package/common/validate/rules/required.js +0 -11
  296. package/common/validate/rules/type.js +0 -100
  297. package/common/validate/rules/whitespace.js +0 -10
  298. package/common/validate/schema.js +0 -290
  299. package/common/validate/util.js +0 -211
  300. package/common/validate/validations/array.js +0 -22
  301. package/common/validate/validations/date.js +0 -31
  302. package/common/validate/validations/enum.js +0 -22
  303. package/common/validate/validations/float.js +0 -22
  304. package/common/validate/validations/index.js +0 -46
  305. package/common/validate/validations/integer.js +0 -22
  306. package/common/validate/validations/method.js +0 -21
  307. package/common/validate/validations/number.js +0 -25
  308. package/common/validate/validations/pattern.js +0 -21
  309. package/common/validate/validations/required.js +0 -11
  310. package/common/validate/validations/string.js +0 -33
  311. package/common/validate/validations/type.js +0 -29
  312. package/index-bar/index.js +0 -66
  313. package/index-bar/vue.js +0 -73
  314. package/index-bar-anchor/vue.js +0 -16
  315. package/label/index.js +0 -56
  316. package/label/vue.js +0 -26
  317. package/list/index.js +0 -13
  318. package/list/vue.js +0 -17
  319. package/mask/index.js +0 -13
  320. package/mask/vue.js +0 -18
  321. package/mini-picker/index.js +0 -165
  322. package/mini-picker/vue.js +0 -122
  323. package/multi-select/index.js +0 -394
  324. package/multi-select/vue.js +0 -113
  325. package/multi-select-item/index.js +0 -23
  326. package/multi-select-item/vue.js +0 -31
  327. package/toast/index.js +0 -7
  328. package/toast/vue.js +0 -19
  329. package/types/toast.type.d.ts +0 -63
  330. package/wheel/index.js +0 -165
  331. package/wheel/vue.js +0 -79
@@ -1,100 +0,0 @@
1
- import "../../../chunk-G2ADBYYC.js";
2
- import * as util from "../util";
3
- import required from "./required";
4
- import { format } from "../../date";
5
- import { isNullOrEmpty } from "../../string";
6
- import { isNumber, isObject, isDate, typeOf } from "../../type";
7
- const emailReg1 = '^(([^<>()\\[\\]\\\\.,;:\\s@"]+(\\.[^<>()\\[\\]\\\\.,;:\\s@"]+)*)|(".+"))';
8
- const emailReg = new RegExp(
9
- emailReg1 + "@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}])|(([a-zA-Z\\-0-9]+\\.)+[a-zA-Z]{2,6}))$"
10
- );
11
- const pattern = {
12
- acceptImg: /\.(png|jpe?g|gif)$/,
13
- acceptFile: /\.(doc?x|xls?x|ppt?x|txt)$/,
14
- email: emailReg,
15
- fileSize: /^\d+(\.\d+)?[KMGTPEZY]?B$/i,
16
- hex: /^#?([a-f0-9]{6}|[a-f0-9]{3})$/i,
17
- speczh: /^[0-9a-zA-Z_\u4E00-\u9FA5]+$/,
18
- specialch: /^[0-9a-zA-Z_\-.]+$/,
19
- specialch2: /^[0-9a-zA-Z_-]+$/,
20
- url: /^(([a-zA-Z]{3,}):)?\/\/([\w-]+\.)+[\w]+(\/[a-zA-Z- ./?%&=]*)?/i,
21
- version: /^\d+\.\d+(\.\d+)*$/
22
- };
23
- const types = {
24
- integer: (value) => types.number(value) && /^[-]?[\d]+$/.test(value),
25
- float: (value) => types.number(value) && !types.integer(value),
26
- array: Array.isArray,
27
- regexp(value) {
28
- if (value instanceof RegExp) {
29
- return true;
30
- }
31
- try {
32
- return !!new RegExp(value);
33
- } catch (e) {
34
- return false;
35
- }
36
- },
37
- date: isDate,
38
- number: (value) => isNumber(Number(value)),
39
- object: (value) => isObject(value) && !types.array(value),
40
- method: (value) => typeOf(value) === "function",
41
- email: (value) => isNullOrEmpty(value) || !!value.match(pattern.email) && value.length < 255,
42
- url: (value) => isNullOrEmpty(value) || !!value.match(pattern.url),
43
- hex: (value) => isNullOrEmpty(value) || !!value.match(pattern.hex),
44
- digits: (value) => isNullOrEmpty(value) || /^\d+$/.test(value),
45
- time: (value) => isNullOrEmpty(value) || /^((0)[0-9]|1[0-9]|20|21|22|23):([0-5][0-9])$/.test(value),
46
- dateYM: (value) => isNullOrEmpty(value) || format(value, "yyyy-MM") === value,
47
- dateYMD: (value) => isNullOrEmpty(value) || format(value, "yyyy-MM-dd") === value,
48
- dateTime: (value) => isNullOrEmpty(value) || format(value, "yyyy-MM-dd hh:mm") === value,
49
- longDateTime: (value) => isNullOrEmpty(value) || format(value, "yyyy-MM-dd hh:mm:ss") === value,
50
- version: (value) => isNullOrEmpty(value) || !!value.match(pattern.version),
51
- speczh: (value) => isNullOrEmpty(value) || !!value.match(pattern.speczh),
52
- specialch: (value) => isNullOrEmpty(value) || !!value.match(pattern.specialch),
53
- specialch2: (value) => isNullOrEmpty(value) || !!value.match(pattern.specialch2),
54
- acceptImg: (value) => isNullOrEmpty(value) || !!value.match(pattern.acceptImg),
55
- acceptFile: (value) => isNullOrEmpty(value) || !!value.match(pattern.acceptFile),
56
- fileSize: (value) => isNullOrEmpty(value) || !!value.match(pattern.fileSize)
57
- };
58
- function type_default(rule, value, source, errors, options) {
59
- if (rule.required && value === void 0) {
60
- required(rule, value, source, errors, options);
61
- return;
62
- }
63
- const custom = [
64
- "array",
65
- "acceptImg",
66
- "acceptFile",
67
- "date",
68
- "digits",
69
- "dateTime",
70
- "dateYM",
71
- "dateYMD",
72
- "email",
73
- "float",
74
- "fileSize",
75
- "hex",
76
- "integer",
77
- "longDateTime",
78
- "method",
79
- "number",
80
- "object",
81
- "regexp",
82
- "speczh",
83
- "specialch",
84
- "specialch2",
85
- "time",
86
- "version",
87
- "url"
88
- ];
89
- const ruleType = rule.type;
90
- if (custom.includes(ruleType)) {
91
- if (!types[ruleType](value)) {
92
- errors.push(util.format(options.messages.types[ruleType], "", rule.type));
93
- }
94
- } else if (ruleType && typeof value !== rule.type) {
95
- errors.push(util.format(options.messages.types[ruleType], "", rule.type));
96
- }
97
- }
98
- export {
99
- type_default as default
100
- };
@@ -1,10 +0,0 @@
1
- import "../../../chunk-G2ADBYYC.js";
2
- import * as util from "../util";
3
- function whitespace_default(rule, checkValue, source, errors, options) {
4
- if (/^\s+$/.test(checkValue) || checkValue === "") {
5
- errors.push(util.format(options.messages.whitespace, ""));
6
- }
7
- }
8
- export {
9
- whitespace_default as default
10
- };
@@ -1,290 +0,0 @@
1
- import {
2
- __spreadProps,
3
- __spreadValues
4
- } from "../../chunk-G2ADBYYC.js";
5
- import { format, complementError, asyncMap, warning, deepMerge, convertFieldsError } from "./util";
6
- import { hasOwn, isFunction } from "../type";
7
- function Schema(descriptor, translate) {
8
- Schema.getSystemMessage = () => Schema.getDefaultMessage(translate);
9
- Schema.messages = Schema.getSystemMessage(translate);
10
- Schema.systemMessages = Schema.messages;
11
- this.rules = null;
12
- this._messages = Schema.systemMessages;
13
- this.define(descriptor);
14
- }
15
- const getCompleteFn = (validCallback) => (results) => {
16
- let idx;
17
- let errors = [];
18
- let fields = {};
19
- function addValid(eror) {
20
- if (Array.isArray(eror)) {
21
- errors = errors.concat(...eror);
22
- } else {
23
- errors.push(eror);
24
- }
25
- }
26
- for (idx = 0; idx < results.length; idx++) {
27
- addValid(results[idx]);
28
- }
29
- if (errors.length) {
30
- fields = convertFieldsError(errors);
31
- } else {
32
- errors = null;
33
- fields = null;
34
- }
35
- validCallback(errors, fields);
36
- };
37
- const isDeep = (rule, data) => {
38
- let deep = (rule.type === "object" || rule.type === "array") && (typeof rule.fields === "object" || typeof rule.defaultField === "object");
39
- deep = deep && (rule.required || !rule.required && data.value);
40
- return deep;
41
- };
42
- const getFieldsSchema = (rule, data) => {
43
- let schema = {};
44
- function addFullfield(key, item) {
45
- return __spreadProps(__spreadValues({}, item), {
46
- fullField: `${rule.fullField}.${key}`
47
- });
48
- }
49
- if (rule.defaultField) {
50
- for (const k in data.value) {
51
- if (hasOwn.call(data.value, k)) {
52
- schema[k] = rule.defaultField;
53
- }
54
- }
55
- }
56
- schema = __spreadValues(__spreadValues({}, schema), data.rule.fields);
57
- for (const f in schema) {
58
- if (hasOwn.call(schema, f)) {
59
- const fieldSchema = Array.isArray(schema[f]) ? schema[f] : [schema[f]];
60
- schema[f] = fieldSchema.map(addFullfield.bind(null, f));
61
- }
62
- }
63
- return schema;
64
- };
65
- const arrayed = (failds) => {
66
- if (!Array.isArray(failds)) {
67
- failds = [failds];
68
- }
69
- return failds;
70
- };
71
- const getRequiredErrorFeilds = ({ rule, failds, options }) => {
72
- if (rule.message) {
73
- failds = [].concat(rule.message).map(complementError(rule));
74
- } else if (options.error) {
75
- failds = [options.error(rule, format(options.messages.required, rule.field))];
76
- } else {
77
- failds = [];
78
- }
79
- return failds;
80
- };
81
- const setDataRuleOptions = ({ data, options }) => {
82
- if (data.rule.options) {
83
- let { messages, error } = options;
84
- Object.assign(data.rule.options, { messages, error });
85
- }
86
- };
87
- const getValidateCallback = ({ failds, doIt }) => (errs) => {
88
- const finalErrors = [];
89
- if (failds && failds.length) {
90
- finalErrors.push(...failds);
91
- }
92
- if (errs && errs.length) {
93
- finalErrors.push(...errs);
94
- }
95
- doIt(finalErrors.length ? finalErrors : null);
96
- };
97
- const asyncCallback = (options, rule, errorFields, doIt, data) => (e = []) => {
98
- let failds = e;
99
- const deep = isDeep(rule, data);
100
- failds = arrayed(failds);
101
- if (!options.suppressWarning && failds.length) {
102
- Schema.warning("async-validator:", failds);
103
- }
104
- if (failds.length && rule.message) {
105
- failds = [].concat(rule.message);
106
- }
107
- failds = failds.map(complementError(rule));
108
- if (options.first && failds.length) {
109
- errorFields[rule.field] = 1;
110
- return doIt(failds);
111
- }
112
- if (deep) {
113
- if (rule.required && !data.value) {
114
- failds = getRequiredErrorFeilds({ rule, failds, options });
115
- return doIt(failds);
116
- }
117
- const schema = new Schema(getFieldsSchema(rule, data));
118
- schema.messages(options.messages);
119
- setDataRuleOptions({ data, options });
120
- schema.validate(data.value, data.rule.options || options, getValidateCallback({ failds, doIt }));
121
- } else {
122
- doIt(failds);
123
- }
124
- };
125
- Schema.prototype = {
126
- messages(messages) {
127
- if (messages) {
128
- this._messages = deepMerge(Schema.getSystemMessage(), messages);
129
- }
130
- return this._messages;
131
- },
132
- /** 格式化检验规则并添加到实例上。
133
- * rules格式化后的数据结构: { key: [ { type: 'xx', ...others } ] }
134
- */
135
- define(rules) {
136
- if (!rules) {
137
- throw new Error("Cannot configure a schema with no rules");
138
- }
139
- if (Array.isArray(rules) || typeof rules !== "object") {
140
- throw new TypeError("Rules must be an object");
141
- }
142
- this.rules = {};
143
- let rule;
144
- Object.keys(rules).forEach((key) => {
145
- if (hasOwn.call(rules, key)) {
146
- rule = rules[key];
147
- this.rules[key] = Array.isArray(rule) ? rule : [rule];
148
- }
149
- });
150
- },
151
- /** 将检验规则和源数据合并转化成新数据
152
- * rules: { key: [rule1, rule2] }, source: { key: sourceData, key2: sourceData2 }
153
- * series { key: [{ rule: rule1, value: sourceData, source, field: key }, ...] }
154
- */
155
- getSeries(options, source, source_) {
156
- let arr;
157
- let value;
158
- const series = {};
159
- const keys = options.keys || Object.keys(this.rules);
160
- keys.forEach((key) => {
161
- arr = this.rules[key];
162
- value = source[key];
163
- arr.forEach((r) => {
164
- let rule = r;
165
- if (typeof rule.transform === "function") {
166
- if (source === source_) {
167
- source = __spreadValues({}, source);
168
- }
169
- source[key] = rule.transform(value);
170
- value = source[key];
171
- }
172
- if (typeof rule === "function") {
173
- rule = { validator: rule };
174
- } else {
175
- rule = __spreadValues({}, rule);
176
- }
177
- rule.validator = this.getValidationMethod(rule);
178
- rule.field = key;
179
- rule.fullField = rule.fullField || key;
180
- rule.type = this.getType(rule);
181
- options.custom && Object.assign(rule, options.custom);
182
- if (!rule.validator) {
183
- return;
184
- }
185
- series[key] = series[key] || [];
186
- series[key].push({ rule, value, source, field: key });
187
- });
188
- });
189
- return series;
190
- },
191
- mergeMessage(options) {
192
- if (options.messages) {
193
- let messages = this.messages();
194
- if (messages === Schema.systemMessages) {
195
- messages = Schema.getSystemMessage();
196
- }
197
- deepMerge(messages, options.messages);
198
- options.messages = messages;
199
- } else {
200
- options.messages = this.messages();
201
- }
202
- },
203
- validate(source_, o = {}, oc = () => void 0) {
204
- let source = source_;
205
- let options = o;
206
- let validCallback = oc;
207
- if (typeof options === "function") {
208
- validCallback = options;
209
- options = {};
210
- }
211
- if (!this.rules || Object.keys(this.rules).length === 0) {
212
- validCallback && validCallback();
213
- return Promise.resolve();
214
- }
215
- const complete = getCompleteFn(validCallback);
216
- this.mergeMessage(options);
217
- const seriesData = this.getSeries(options, source, source_);
218
- const errorFields = {};
219
- return asyncMap(
220
- seriesData,
221
- options,
222
- (data, doIt) => {
223
- const rule = data.rule;
224
- const validHandler = asyncCallback(options, rule, errorFields, doIt, data);
225
- let validResult;
226
- if (rule.asyncValidator) {
227
- validResult = rule.asyncValidator(rule, data.value, validHandler, data.source, options);
228
- } else if (rule.validator) {
229
- validResult = rule.validator(rule, data.value, validHandler, data.source, options);
230
- if (validResult === true) {
231
- validHandler();
232
- } else if (validResult === false) {
233
- validHandler(rule.message || `${rule.field} fails`);
234
- } else if (Array.isArray(validResult)) {
235
- validHandler(validResult);
236
- } else if (validResult instanceof Error) {
237
- validHandler(validResult.message);
238
- }
239
- }
240
- if (validResult && validResult.then) {
241
- validResult.then(
242
- () => validHandler(),
243
- (e) => validHandler(e)
244
- );
245
- }
246
- },
247
- (results) => {
248
- complete(results);
249
- }
250
- );
251
- },
252
- getValidationMethod(rule) {
253
- if (isFunction(rule.validator)) {
254
- return rule.validator;
255
- }
256
- const ruleKeys = Object.keys(rule);
257
- const messageIndex = ruleKeys.indexOf("message");
258
- if (messageIndex > -1) {
259
- ruleKeys.splice(messageIndex, 1);
260
- }
261
- if (ruleKeys.length === 1 && ruleKeys[0] === "required") {
262
- return Schema.validators.required;
263
- }
264
- return Schema.validators[this.getType(rule)] || false;
265
- },
266
- getType(rule) {
267
- if (rule.type === void 0 && rule.pattern instanceof RegExp) {
268
- rule.type = "pattern";
269
- }
270
- if (typeof rule.validator !== "function" && rule.type && !hasOwn.call(Schema.validators, rule.type)) {
271
- throw new Error(format("Unknown rule type %s", rule.type));
272
- }
273
- return rule.type || "string";
274
- }
275
- };
276
- Schema.register = (type, validator) => {
277
- if (typeof validator !== "function") {
278
- throw new TypeError("Cannot register a validator by type, validator is not a function");
279
- }
280
- Schema.validators[type] = validator;
281
- };
282
- Schema.validators = {};
283
- Schema.warning = warning;
284
- Schema.messages = {};
285
- Schema.systemMessages = {};
286
- Schema.getDefaultMessage = () => void 0;
287
- var schema_default = Schema;
288
- export {
289
- schema_default as default
290
- };
@@ -1,211 +0,0 @@
1
- import {
2
- __spreadValues
3
- } from "../../chunk-G2ADBYYC.js";
4
- import { hasOwn, isNull } from "../type";
5
- import { log } from "@opentiny/utils";
6
- const formatRegExp = /%[sdj%]/g;
7
- const warning = () => void 0;
8
- function convertFieldsError(errors) {
9
- if (!errors || !errors.length) {
10
- return null;
11
- }
12
- const fields = {};
13
- errors.forEach((error) => {
14
- const field = error.field;
15
- fields[field] = fields[field] || [];
16
- fields[field].push(error);
17
- });
18
- return fields;
19
- }
20
- function format(i18nTemplate, ...rest) {
21
- if (typeof i18nTemplate === "function") {
22
- return i18nTemplate(...rest);
23
- }
24
- if (typeof i18nTemplate === "string") {
25
- let i = 0;
26
- const len = rest.length;
27
- let str = String(i18nTemplate).replace(formatRegExp, (matchChar) => {
28
- if (matchChar === "%%") {
29
- return "%";
30
- }
31
- if (i >= len) {
32
- return matchChar;
33
- }
34
- switch (matchChar) {
35
- case "%j":
36
- try {
37
- return JSON.stringify(rest[i++]);
38
- } catch (e) {
39
- return "[Circular]";
40
- }
41
- case "%d":
42
- return Number(rest[i++]);
43
- case "%s":
44
- return String(rest[i++]);
45
- default:
46
- return matchChar;
47
- }
48
- });
49
- return str;
50
- }
51
- return i18nTemplate;
52
- }
53
- function isNativeStringType(type) {
54
- return [
55
- "string",
56
- "url",
57
- "hex",
58
- "email",
59
- "pattern",
60
- "digits",
61
- "time",
62
- "dateYMD",
63
- "longDateTime",
64
- "dateTime",
65
- "dateYM",
66
- "version",
67
- "speczh",
68
- "specialch",
69
- "specialch2",
70
- "acceptImg",
71
- "acceptFile",
72
- "fileSize"
73
- ].includes(type);
74
- }
75
- function isEmptyValue(data, dataType) {
76
- if (isNull(data)) {
77
- return true;
78
- }
79
- if (dataType === "array" && Array.isArray(data) && !data.length) {
80
- return true;
81
- }
82
- if (isNativeStringType(dataType) && typeof data === "string" && !data) {
83
- return true;
84
- }
85
- return false;
86
- }
87
- function isEmptyObject(data) {
88
- return Object.keys(data).length === 0;
89
- }
90
- function asyncParallelArray(arrData, func, callback) {
91
- let count = 0;
92
- const results = [];
93
- const arrLength = arrData.length;
94
- function checkCount(errors) {
95
- results.push(...errors);
96
- count++;
97
- if (count === arrLength) {
98
- callback(results);
99
- }
100
- }
101
- arrData.forEach((rule) => {
102
- func(rule, checkCount);
103
- });
104
- }
105
- function asyncSerialArray(arr, fn, cb) {
106
- let idx = 0;
107
- const arrLength = arr.length;
108
- function checkNext(errorList) {
109
- if (errorList && errorList.length) {
110
- cb(errorList);
111
- return;
112
- }
113
- const original = idx;
114
- idx = idx + 1;
115
- if (original < arrLength) {
116
- fn(arr[original], checkNext);
117
- } else {
118
- cb([]);
119
- }
120
- }
121
- checkNext([]);
122
- }
123
- function flattenObjArr(objArr) {
124
- const result = [];
125
- Object.keys(objArr).forEach((item) => {
126
- result.push(...objArr[item]);
127
- });
128
- return result;
129
- }
130
- function asyncMap(objArray, option, func, callback) {
131
- if (option.first) {
132
- const pending2 = new Promise((resolve, reject) => {
133
- const errorFn = reject;
134
- const next = (errors) => {
135
- callback(errors);
136
- return errors.length ? errorFn({ errors, fields: convertFieldsError(errors) }) : resolve();
137
- };
138
- const flattenArr = flattenObjArr(objArray);
139
- asyncSerialArray(flattenArr, func, next);
140
- });
141
- pending2.catch((error) => error.errors && error.fields || log.logger.error(error));
142
- return pending2;
143
- }
144
- let firstFields = option.firstFields || [];
145
- if (firstFields === true) {
146
- firstFields = Object.keys(objArray);
147
- }
148
- let total = 0;
149
- const objArrayKeys = Object.keys(objArray);
150
- const objArrLength = objArrayKeys.length;
151
- const results = [];
152
- const pending = new Promise((resolve, reject) => {
153
- const errorFn = reject;
154
- const next = (errors) => {
155
- results.push(...errors);
156
- total++;
157
- if (total === objArrLength) {
158
- callback(results);
159
- return results.length ? errorFn({ errors: results, fields: convertFieldsError(results) }) : resolve();
160
- }
161
- };
162
- objArrayKeys.forEach((key) => {
163
- const arr = objArray[key];
164
- if (firstFields.includes(key)) {
165
- asyncSerialArray(arr, func, next);
166
- } else {
167
- asyncParallelArray(arr, func, next);
168
- }
169
- });
170
- });
171
- pending.catch((error) => error.errors && error.fields || log.logger.error(error));
172
- return pending;
173
- }
174
- function complementError(rule) {
175
- return (onError) => {
176
- if (onError && onError.message) {
177
- onError.field = onError.field || rule.fullField;
178
- return onError;
179
- }
180
- return {
181
- message: typeof onError === "function" ? onError() : onError,
182
- field: onError.field || rule.fullField
183
- };
184
- };
185
- }
186
- function deepMerge(target, sources) {
187
- if (!sources) {
188
- return target;
189
- }
190
- for (const source in sources) {
191
- if (hasOwn.call(sources, source)) {
192
- const value = sources[source];
193
- if (typeof value === "object" && typeof target[source] === "object") {
194
- target[source] = __spreadValues(__spreadValues({}, target[source]), value);
195
- } else {
196
- target[source] = value;
197
- }
198
- }
199
- }
200
- return target;
201
- }
202
- export {
203
- asyncMap,
204
- complementError,
205
- convertFieldsError,
206
- deepMerge,
207
- format,
208
- isEmptyObject,
209
- isEmptyValue,
210
- warning
211
- };
@@ -1,22 +0,0 @@
1
- import "../../../chunk-G2ADBYYC.js";
2
- import rules from "../rules/index";
3
- import { isEmptyValue } from "../util";
4
- import { hasOwn } from "../../type";
5
- function array_default(rule, checkValue, callback, source, options) {
6
- const errors = [];
7
- const validate = rule.required || !rule.required && hasOwn.call(source, rule.field);
8
- if (validate) {
9
- if (isEmptyValue(checkValue, "array") && !rule.required) {
10
- return callback();
11
- }
12
- rules.required({ rule, checkValue, source, errors, options, type: "array" });
13
- if (!isEmptyValue(checkValue, "array")) {
14
- rules.type(rule, checkValue, source, errors, options);
15
- rules.range(rule, checkValue, source, errors, options);
16
- }
17
- }
18
- callback(errors);
19
- }
20
- export {
21
- array_default as default
22
- };
@@ -1,31 +0,0 @@
1
- import "../../../chunk-G2ADBYYC.js";
2
- import rules from "../rules/index";
3
- import { isEmptyValue } from "../util";
4
- import { hasOwn } from "../../type";
5
- function date_default(rule, checkValue, callback, source, options) {
6
- const errors = [];
7
- const validate = rule.required || !rule.required && hasOwn.call(source, rule.field);
8
- const isValidDateStr = (value) => value && typeof value === "string" && new Date(value).toString() !== "Invalid Date";
9
- if (validate) {
10
- if (isEmptyValue(checkValue) && !rule.required) {
11
- return callback();
12
- }
13
- rules.required({ rule, checkValue, source, errors, options });
14
- if (!isEmptyValue(checkValue)) {
15
- let dateObject;
16
- if (typeof checkValue === "number" || isValidDateStr(checkValue)) {
17
- dateObject = new Date(checkValue);
18
- } else {
19
- dateObject = checkValue;
20
- }
21
- rules.type(rule, dateObject, source, errors, options);
22
- if (dateObject && typeof dateObject.getTime === "function") {
23
- rules.range(rule, dateObject.getTime(), source, errors, options);
24
- }
25
- }
26
- }
27
- callback(errors);
28
- }
29
- export {
30
- date_default as default
31
- };
@@ -1,22 +0,0 @@
1
- import "../../../chunk-G2ADBYYC.js";
2
- import rules from "../rules/index";
3
- import { isEmptyValue } from "../util";
4
- import { hasOwn } from "../../type";
5
- const ENUM = "enum";
6
- function enum_default(rule, checkValue, callback, source, options) {
7
- const errors = [];
8
- const validate = rule.required || !rule.required && hasOwn.call(source, rule.field);
9
- if (validate) {
10
- if (isEmptyValue(checkValue) && !rule.required) {
11
- return callback();
12
- }
13
- rules.required({ rule, checkValue, source, errors, options });
14
- if (checkValue !== void 0) {
15
- rules[ENUM](rule, checkValue, source, errors, options);
16
- }
17
- }
18
- callback(errors);
19
- }
20
- export {
21
- enum_default as default
22
- };