@wfrog/vc-ui 1.3.0 → 1.4.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/es/chunk/{CCmEeM7D.mjs → B3GxuXVE.mjs} +6 -6
- package/dist/es/chunk/BL8WhaLp.mjs +427 -0
- package/dist/es/chunk/{BiHWk71g.mjs → BPqrpkTb.mjs} +4 -4
- package/dist/es/chunk/{C_7t9blX.mjs → BZ1uhZQF.mjs} +1 -1
- package/dist/es/chunk/{-ga82G_B.mjs → BdVq9mV6.mjs} +1 -1
- package/dist/es/chunk/{DGGhWn1A.mjs → BfjuZmry.mjs} +6 -5
- package/dist/es/chunk/{BLLKi_0v.mjs → Bu3XHP55.mjs} +1 -1
- package/dist/es/chunk/{DEiqPcuO.mjs → BvNFaD5d.mjs} +3 -3
- package/dist/es/chunk/BxibBO68.mjs +5741 -0
- package/dist/es/chunk/{DO-mBaf5.mjs → By7FMB3I.mjs} +1 -43
- package/dist/es/chunk/{DATKTbFj.mjs → CGhekNBa.mjs} +5 -5
- package/dist/es/chunk/{plK2vnjp.mjs → CJ0afvkJ.mjs} +1 -1
- package/dist/es/chunk/{CtYp4FB7.mjs → CK5Bluh4.mjs} +2 -2
- package/dist/es/chunk/{Vv8g5_A1.mjs → CKZGL4_3.mjs} +9 -8
- package/dist/es/chunk/CNEMJL35.mjs +69 -0
- package/dist/es/chunk/{C9ldJ8Hh.mjs → CPCieLBG.mjs} +1 -1
- package/dist/es/chunk/{C50_dziC.mjs → CQz3lhyS.mjs} +2 -1
- package/dist/es/chunk/{Cekqdlxf.mjs → CbYM6R_O.mjs} +12 -77
- package/dist/es/chunk/{CQbpo0im.mjs → CboHfRXN.mjs} +5 -6
- package/dist/es/chunk/{BambM7zX.mjs → Cdh3HNZa.mjs} +2 -2
- package/dist/es/chunk/{aX4SRHmD.mjs → Cg-Krnly.mjs} +2 -1
- package/dist/es/chunk/{9qQNa4bM.mjs → Cjp0Czyu.mjs} +1 -1
- package/dist/es/chunk/Cmb_E8Ip.mjs +184 -0
- package/dist/es/chunk/{BIK5Djc_.mjs → Co77DVCw.mjs} +2 -2
- package/dist/es/chunk/CqTa_Vd-.mjs +375 -0
- package/dist/es/{components/dual-pane/dual-pane.mjs → chunk/CsjEhAYY.mjs} +11 -91
- package/dist/es/chunk/{BQyZW57B.mjs → CwXV7M2F.mjs} +3 -3
- package/dist/es/chunk/{b9dx0jdT.mjs → D1MHFKtN.mjs} +3 -3
- package/dist/es/chunk/{DskGUrkJ.mjs → D6m3vWpc.mjs} +2 -1
- package/dist/es/chunk/{4F1xxyju.mjs → D6nWUATi.mjs} +48 -2117
- package/dist/es/chunk/{C6bIuBQg.mjs → D7CQDxqy.mjs} +3 -3
- package/dist/es/chunk/{Dqk3gyUk.mjs → D9Lr0Bzb.mjs} +1 -374
- package/dist/es/chunk/{Xk5kfdyT.mjs → DAIuzoFs.mjs} +2 -1
- package/dist/es/chunk/{OVbHCQoq.mjs → DCS0eqqM.mjs} +3 -101
- package/dist/es/chunk/{BJTCqgn1.mjs → DDR6UjaC.mjs} +1 -1
- package/dist/es/chunk/{BKmk2ptO.mjs → DNsAO9iB.mjs} +2 -2
- package/dist/es/chunk/{-_x5oKYF.mjs → DQK0ezHm.mjs} +5 -4
- package/dist/es/chunk/{BQHHM_Gw.mjs → DQi1QPak.mjs} +30 -70
- package/dist/es/chunk/{BaqDgAvL.mjs → DSt2uDNE.mjs} +22 -434
- package/dist/es/chunk/DSw4GnC6.mjs +44 -0
- package/dist/es/chunk/DTbnchOm.mjs +94 -0
- package/dist/es/chunk/DViraU6I.mjs +45 -0
- package/dist/es/chunk/{C540ZOUa.mjs → DX84QR5M.mjs} +10 -9
- package/dist/es/chunk/DYKOYbzT.mjs +2003 -0
- package/dist/es/chunk/{D1PKXAql.mjs → D_F7nIja.mjs} +3 -4
- package/dist/es/chunk/{DcTh6n4x.mjs → D_Mvdscy.mjs} +5 -4
- package/dist/es/chunk/DhGOsWxx.mjs +6 -0
- package/dist/es/chunk/{DFxeI_lP.mjs → DhGcJR5p.mjs} +6 -6
- package/dist/es/chunk/DxxbB5jY.mjs +34 -0
- package/dist/es/chunk/EMeQxUfH.mjs +49 -0
- package/dist/es/chunk/{eN6VJ63C.mjs → F2ph6lWu.mjs} +9 -8
- package/dist/es/chunk/{Dn-BFXcJ.mjs → dN0VcQc2.mjs} +1 -1
- package/dist/es/chunk/{DTpr71Gd.mjs → e5i7OJY-.mjs} +4 -4
- package/dist/es/chunk/fueZ9sVu.mjs +890 -0
- package/dist/es/chunk/{CV2NA_2e.mjs → ipA7n6-J.mjs} +1 -1
- package/dist/es/chunk/{Dw-yyl2m.mjs → q2jRgbir.mjs} +2 -2
- package/dist/es/chunk/{C72pWnuz.mjs → w7VqVeWU.mjs} +5 -4
- package/dist/es/chunk/{DWcIzeMM.mjs → ytiKcA3H.mjs} +108 -10
- package/dist/es/chunk/{DFHjl3eL.mjs → yuIXvUxc.mjs} +1 -1
- package/dist/es/components/backbottom/backbottom.mjs +2 -2
- package/dist/es/components/button/button.d.ts +2 -1
- package/dist/es/components/button/button.mjs +68 -17
- package/dist/es/components/button/button.vue.d.ts +4 -1
- package/dist/es/components/choice/choice.mjs +3 -2
- package/dist/es/components/color-switcher/color-switcher.d.ts +15 -0
- package/dist/es/components/color-switcher/color-switcher.mjs +1215 -0
- package/dist/es/components/color-switcher/color-switcher.vue.d.ts +122 -0
- package/dist/es/components/color-switcher/index.css +5 -0
- package/dist/es/components/color-switcher/index.d.ts +4 -0
- package/dist/es/components/color-switcher/index.mjs +6 -0
- package/dist/es/components/cropper/cropper.mjs +12 -11
- package/dist/es/components/cropper/cropper.vue.d.ts +2 -2
- package/dist/es/components/currency/currency.mjs +7 -7
- package/dist/es/components/dark-switcher/dark-switcher.d.ts +10 -0
- package/dist/es/components/dark-switcher/dark-switcher.mjs +87 -0
- package/dist/es/components/dark-switcher/dark-switcher.vue.d.ts +12 -0
- package/dist/es/components/dark-switcher/index.css +11 -0
- package/dist/es/components/dark-switcher/index.d.ts +4 -0
- package/dist/es/components/dark-switcher/index.mjs +6 -0
- package/dist/es/components/daterange-picker/daterange-picker.mjs +21 -20
- package/dist/es/components/dialog/dialog.d.ts +1 -1
- package/dist/es/components/dialog/dialog.mjs +46 -61
- package/dist/es/components/dialog/dialog.vue.d.ts +1 -3
- package/dist/es/components/dialog/index.css +31 -32
- package/dist/es/components/dialog-camera-upload/dialog-camera-upload.mjs +12 -12
- package/dist/es/components/dialog-map-point/dialog-map-point.mjs +5 -5
- package/dist/es/components/dialog-upload-images/dialog-upload-images.mjs +14 -13
- package/dist/es/components/document.vue.d.ts +14 -0
- package/dist/es/components/drag-verify/drag-verify.mjs +14 -14
- package/dist/es/components/drag-verify/index.css +11 -11
- package/dist/es/components/drawer/drawer.mjs +14 -14
- package/dist/es/components/drawer/index.css +16 -15
- package/dist/es/components/easy-pagination/easy-pagination.mjs +4 -4
- package/dist/es/components/el-icon/el-icon.mjs +2 -2
- package/dist/es/components/example-wrapper.vue.d.ts +19 -0
- package/dist/es/components/explorer/docs/data.d.ts +13 -0
- package/dist/es/components/explorer/explorer.d.ts +12 -0
- package/dist/es/components/explorer/explorer.mjs +64 -0
- package/dist/es/components/explorer/explorer.vue.d.ts +183 -0
- package/dist/es/components/explorer/explorer2.mjs +6 -0
- package/dist/es/components/explorer/index.css +14 -0
- package/dist/es/components/explorer/index.d.ts +4 -0
- package/dist/es/components/explorer/index.mjs +6 -0
- package/dist/es/components/explorer-column-table/explorer-column-table.d.ts +23 -0
- package/dist/es/components/explorer-column-table/explorer-column-table.mjs +2948 -0
- package/dist/es/components/explorer-column-table/explorer-column-table.vue.d.ts +1486 -0
- package/dist/es/components/explorer-column-table/index.css +49 -0
- package/dist/es/components/explorer-column-table/index.d.ts +4 -0
- package/dist/es/components/explorer-column-table/index.mjs +6 -0
- package/dist/es/components/explorer-filter/explorer-filter.d.ts +12 -0
- package/dist/es/components/explorer-filter/explorer-filter.mjs +81 -0
- package/dist/es/components/explorer-filter/explorer-filter.vue.d.ts +14 -0
- package/dist/es/components/explorer-filter/index.css +7 -0
- package/dist/es/components/explorer-filter/index.d.ts +4 -0
- package/dist/es/components/explorer-filter/index.mjs +6 -0
- package/dist/es/components/explorer-footer/explorer-footer.d.ts +5 -0
- package/dist/es/components/explorer-footer/explorer-footer.mjs +92 -0
- package/dist/es/components/explorer-footer/explorer-footer.vue.d.ts +21 -0
- package/dist/es/components/explorer-footer/index.css +7 -0
- package/dist/es/components/explorer-footer/index.d.ts +4 -0
- package/dist/es/components/explorer-footer/index.mjs +6 -0
- package/dist/es/components/explorer-list/explorer-list.d.ts +23 -0
- package/dist/es/components/explorer-list/explorer-list.mjs +157 -0
- package/dist/es/components/explorer-list/explorer-list.vue.d.ts +38 -0
- package/dist/es/components/explorer-list/index.css +47 -0
- package/dist/es/components/explorer-list/index.d.ts +4 -0
- package/dist/es/components/explorer-list/index.mjs +6 -0
- package/dist/es/components/explorer-panel/explorer-panel.d.ts +14 -0
- package/dist/es/components/explorer-panel/explorer-panel.mjs +77 -0
- package/dist/es/components/explorer-panel/explorer-panel.vue.d.ts +253 -0
- package/dist/es/components/explorer-panel/explorer-panel2.mjs +6 -0
- package/dist/es/components/explorer-panel/index.css +12 -0
- package/dist/es/components/explorer-panel/index.d.ts +4 -0
- package/dist/es/components/explorer-panel/index.mjs +6 -0
- package/dist/es/components/explorer-query/explorer-query.d.ts +11 -0
- package/dist/es/components/explorer-query/explorer-query.mjs +2376 -0
- package/dist/es/components/explorer-query/explorer-query.vue.d.ts +396 -0
- package/dist/es/components/explorer-query/index.css +36 -0
- package/dist/es/components/explorer-query/index.d.ts +4 -0
- package/dist/es/components/explorer-query/index.mjs +6 -0
- package/dist/es/components/explorer-table/explorer-table.d.ts +11 -0
- package/dist/es/components/explorer-table/explorer-table.mjs +116 -0
- package/dist/es/components/explorer-table/explorer-table.vue.d.ts +25 -0
- package/dist/es/components/explorer-table/index.css +18 -0
- package/dist/es/components/explorer-table/index.d.ts +4 -0
- package/dist/es/components/explorer-table/index.mjs +6 -0
- package/dist/es/components/explorer-tools/components/column-setter.vue.d.ts +3028 -0
- package/dist/es/components/explorer-tools/explorer-tools.d.ts +35 -0
- package/dist/es/components/explorer-tools/explorer-tools.mjs +585 -0
- package/dist/es/components/explorer-tools/explorer-tools.vue.d.ts +43 -0
- package/dist/es/components/explorer-tools/index.css +60 -0
- package/dist/es/components/explorer-tools/index.d.ts +4 -0
- package/dist/es/components/explorer-tools/index.mjs +6 -0
- package/dist/es/components/explorer-tree/explorer-tree.d.ts +22 -0
- package/dist/es/components/explorer-tree/explorer-tree.mjs +174 -0
- package/dist/es/components/explorer-tree/explorer-tree.vue.d.ts +2055 -0
- package/dist/es/components/explorer-tree/index.css +55 -0
- package/dist/es/components/explorer-tree/index.d.ts +4 -0
- package/dist/es/components/explorer-tree/index.mjs +6 -0
- package/dist/es/components/icon/icon2.mjs +2 -2
- package/dist/es/components/icon-picker/components/collections.vue.d.ts +242 -196
- package/dist/es/components/icon-picker/icon-picker.mjs +38 -921
- package/dist/es/components/icon-picker/index.css +31 -29
- package/dist/es/components/iconify-icon/iconify-icon.mjs +2 -2
- package/dist/es/components/image/image.mjs +5 -5
- package/dist/es/components/image/image.vue.d.ts +7 -7
- package/dist/es/components/input/index.css +4 -5
- package/dist/es/components/input/input.mjs +7 -7
- package/dist/es/components/input/input.vue.d.ts +3 -3
- package/dist/es/components/input-number/input-number.mjs +5 -5
- package/dist/es/components/pca-picker/components/c.vue.d.ts +3 -3
- package/dist/es/components/pca-picker/index.css +4 -4
- package/dist/es/components/pca-picker/pca-picker.mjs +21 -209
- package/dist/es/components/pca-picker/pca-picker.vue.d.ts +10 -10
- package/dist/es/components/screenfull/screenfull.mjs +4 -4
- package/dist/es/components/scrollbar/index.css +6 -5
- package/dist/es/components/scrollbar/scrollbar.d.ts +2 -0
- package/dist/es/components/scrollbar/scrollbar.mjs +17 -12
- package/dist/es/components/scrollbar/scrollbar.vue.d.ts +156 -134
- package/dist/es/components/select/select.mjs +7 -7
- package/dist/es/components/single-player/index.css +11 -11
- package/dist/es/components/single-player/single-player.mjs +20 -19
- package/dist/es/components/splitter/index.d.ts +4 -0
- package/dist/es/components/splitter/index.mjs +6 -0
- package/dist/es/components/splitter/splitter.d.ts +4 -0
- package/dist/es/components/splitter/splitter.mjs +28 -0
- package/dist/es/components/{dual-pane/dual-pane.vue.d.ts → splitter/splitter.vue.d.ts} +3 -5
- package/dist/es/components/splitter-panel/index.css +5 -0
- package/dist/es/components/splitter-panel/index.d.ts +4 -0
- package/dist/es/components/splitter-panel/index.mjs +6 -0
- package/dist/es/components/splitter-panel/splitter-panel.d.ts +3 -0
- package/dist/es/components/splitter-panel/splitter-panel.mjs +49 -0
- package/dist/es/components/splitter-panel/splitter-panel.vue.d.ts +20 -0
- package/dist/es/components/svg-icon/svg-icon.mjs +2 -2
- package/dist/es/components/switch/switch.mjs +2 -2
- package/dist/es/components/sync-scroll-container/sync-scroll-container.mjs +2 -2
- package/dist/es/components/tags/tags.mjs +12 -11
- package/dist/es/components/text-ellipsis/text-ellipsis.mjs +4 -4
- package/dist/es/components/text-ellipsis/text-ellipsis.vue.d.ts +1 -1
- package/dist/es/components/thousand-input/thousand-input.mjs +3 -3
- package/dist/es/components/thousand-input/thousand-input.vue.d.ts +8 -8
- package/dist/es/components/tinymce/index.css +1 -1
- package/dist/es/components/tinymce/tinymce.d.ts +1 -0
- package/dist/es/components/tinymce/tinymce.mjs +20 -11
- package/dist/es/components/tinymce/tinymce.vue.d.ts +1 -0
- package/dist/es/components/tree-picker/popover-cascader.css +1 -1
- package/dist/es/components/tree-picker/tree-picker.mjs +11 -10
- package/dist/es/components/tree-picker/tree-picker.vue.d.ts +10 -10
- package/dist/es/components/upload-file/upload-file.mjs +2 -2
- package/dist/es/index.d.ts +14 -1
- package/dist/es/index.mjs +69 -39
- package/dist/es/use/usePersistentModel/index.d.ts +4 -0
- package/dist/es/use/usePersistentModel/index.mjs +19 -0
- package/dist/global.d.ts +14 -1
- package/dist/index.css +450 -123
- package/package.json +4 -1
- package/dist/es/chunk/DVNTpOBR.mjs +0 -4
- package/dist/es/components/dual-pane/dual-pane.d.ts +0 -8
- package/dist/es/components/dual-pane/index.css +0 -8
- package/dist/es/components/dual-pane/index.d.ts +0 -4
- package/dist/es/components/dual-pane/index.mjs +0 -6
|
@@ -0,0 +1,2376 @@
|
|
|
1
|
+
import './index.css'
|
|
2
|
+
import { c as isArray, i as isString, b as buildProps, d as definePropType, a as debugWarn, u as useNamespace, f as isFunction, t as throwError } from '../../chunk/By7FMB3I.mjs';
|
|
3
|
+
import { ref, computed, defineComponent, reactive, watch, provide, toRefs, createElementBlock, openBlock, normalizeClass, renderSlot, inject, onMounted, onBeforeUnmount, onUpdated, createVNode, Fragment, nextTick, useSlots, unref, createElementVNode, withCtx, createBlock, createCommentVNode, resolveDynamicComponent, normalizeStyle, createTextVNode, toDisplayString, TransitionGroup, useCssVars, useTemplateRef } from 'vue';
|
|
4
|
+
import { useResizeObserver, refDebounced, useStorage, useToggle, useElementSize, promiseTimeout } from '@vueuse/core';
|
|
5
|
+
import { C as Component$1 } from '../button/button.mjs';
|
|
6
|
+
import { i as injectExplorerState } from '../explorer/explorer2.mjs';
|
|
7
|
+
import { f as formContextKey, a as formItemContextKey, u as useId } from '../../chunk/Co77DVCw.mjs';
|
|
8
|
+
import { c as componentSizes } from '../../chunk/CPCieLBG.mjs';
|
|
9
|
+
import { d as isBoolean } from '../../chunk/DViraU6I.mjs';
|
|
10
|
+
import { c as castArray } from '../../chunk/DSw4GnC6.mjs';
|
|
11
|
+
import { _ as _export_sfc, w as withInstall, a as withNoopInstall } from '../../chunk/dN0VcQc2.mjs';
|
|
12
|
+
import { c as useFormSize } from '../../chunk/BvNFaD5d.mjs';
|
|
13
|
+
import { g as getProp } from '../../chunk/EMeQxUfH.mjs';
|
|
14
|
+
import { h as hasPath } from '../../chunk/DCS0eqqM.mjs';
|
|
15
|
+
import { a as addUnit } from '../../chunk/CQz3lhyS.mjs';
|
|
16
|
+
import { b as baseClone } from '../../chunk/D_F7nIja.mjs';
|
|
17
|
+
import { _ as _export_sfc$1 } from '../../chunk/pcqpp-6-.mjs';
|
|
18
|
+
|
|
19
|
+
/** Used to compose bitmasks for cloning. */
|
|
20
|
+
var CLONE_SYMBOLS_FLAG = 4;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Creates a shallow clone of `value`.
|
|
24
|
+
*
|
|
25
|
+
* **Note:** This method is loosely based on the
|
|
26
|
+
* [structured clone algorithm](https://mdn.io/Structured_clone_algorithm)
|
|
27
|
+
* and supports cloning arrays, array buffers, booleans, date objects, maps,
|
|
28
|
+
* numbers, `Object` objects, regexes, sets, strings, symbols, and typed
|
|
29
|
+
* arrays. The own enumerable properties of `arguments` objects are cloned
|
|
30
|
+
* as plain objects. An empty object is returned for uncloneable values such
|
|
31
|
+
* as error objects, functions, DOM nodes, and WeakMaps.
|
|
32
|
+
*
|
|
33
|
+
* @static
|
|
34
|
+
* @memberOf _
|
|
35
|
+
* @since 0.1.0
|
|
36
|
+
* @category Lang
|
|
37
|
+
* @param {*} value The value to clone.
|
|
38
|
+
* @returns {*} Returns the cloned value.
|
|
39
|
+
* @see _.cloneDeep
|
|
40
|
+
* @example
|
|
41
|
+
*
|
|
42
|
+
* var objects = [{ 'a': 1 }, { 'b': 2 }];
|
|
43
|
+
*
|
|
44
|
+
* var shallow = _.clone(objects);
|
|
45
|
+
* console.log(shallow[0] === objects[0]);
|
|
46
|
+
* // => true
|
|
47
|
+
*/
|
|
48
|
+
function clone(value) {
|
|
49
|
+
return baseClone(value, CLONE_SYMBOLS_FLAG);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** Used for built-in method references. */
|
|
53
|
+
var objectProto = Object.prototype;
|
|
54
|
+
|
|
55
|
+
/** Used to check objects for own properties. */
|
|
56
|
+
var hasOwnProperty = objectProto.hasOwnProperty;
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* The base implementation of `_.has` without support for deep paths.
|
|
60
|
+
*
|
|
61
|
+
* @private
|
|
62
|
+
* @param {Object} [object] The object to query.
|
|
63
|
+
* @param {Array|string} key The key to check.
|
|
64
|
+
* @returns {boolean} Returns `true` if `key` exists, else `false`.
|
|
65
|
+
*/
|
|
66
|
+
function baseHas(object, key) {
|
|
67
|
+
return object != null && hasOwnProperty.call(object, key);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Checks if `path` is a direct property of `object`.
|
|
72
|
+
*
|
|
73
|
+
* @static
|
|
74
|
+
* @since 0.1.0
|
|
75
|
+
* @memberOf _
|
|
76
|
+
* @category Object
|
|
77
|
+
* @param {Object} object The object to query.
|
|
78
|
+
* @param {Array|string} path The path to check.
|
|
79
|
+
* @returns {boolean} Returns `true` if `path` exists, else `false`.
|
|
80
|
+
* @example
|
|
81
|
+
*
|
|
82
|
+
* var object = { 'a': { 'b': 2 } };
|
|
83
|
+
* var other = _.create({ 'a': _.create({ 'b': 2 }) });
|
|
84
|
+
*
|
|
85
|
+
* _.has(object, 'a');
|
|
86
|
+
* // => true
|
|
87
|
+
*
|
|
88
|
+
* _.has(object, 'a.b');
|
|
89
|
+
* // => true
|
|
90
|
+
*
|
|
91
|
+
* _.has(object, ['a', 'b']);
|
|
92
|
+
* // => true
|
|
93
|
+
*
|
|
94
|
+
* _.has(other, 'a');
|
|
95
|
+
* // => false
|
|
96
|
+
*/
|
|
97
|
+
function has(object, path) {
|
|
98
|
+
return object != null && hasPath(object, path, baseHas);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const formMetaProps = buildProps({
|
|
102
|
+
size: {
|
|
103
|
+
type: String,
|
|
104
|
+
values: componentSizes
|
|
105
|
+
},
|
|
106
|
+
disabled: Boolean
|
|
107
|
+
});
|
|
108
|
+
const formProps = buildProps({
|
|
109
|
+
...formMetaProps,
|
|
110
|
+
model: Object,
|
|
111
|
+
rules: {
|
|
112
|
+
type: definePropType(Object)
|
|
113
|
+
},
|
|
114
|
+
labelPosition: {
|
|
115
|
+
type: String,
|
|
116
|
+
values: ["left", "right", "top"],
|
|
117
|
+
default: "right"
|
|
118
|
+
},
|
|
119
|
+
requireAsteriskPosition: {
|
|
120
|
+
type: String,
|
|
121
|
+
values: ["left", "right"],
|
|
122
|
+
default: "left"
|
|
123
|
+
},
|
|
124
|
+
labelWidth: {
|
|
125
|
+
type: [String, Number],
|
|
126
|
+
default: ""
|
|
127
|
+
},
|
|
128
|
+
labelSuffix: {
|
|
129
|
+
type: String,
|
|
130
|
+
default: ""
|
|
131
|
+
},
|
|
132
|
+
inline: Boolean,
|
|
133
|
+
inlineMessage: Boolean,
|
|
134
|
+
statusIcon: Boolean,
|
|
135
|
+
showMessage: {
|
|
136
|
+
type: Boolean,
|
|
137
|
+
default: true
|
|
138
|
+
},
|
|
139
|
+
validateOnRuleChange: {
|
|
140
|
+
type: Boolean,
|
|
141
|
+
default: true
|
|
142
|
+
},
|
|
143
|
+
hideRequiredAsterisk: Boolean,
|
|
144
|
+
scrollToError: Boolean,
|
|
145
|
+
scrollIntoViewOptions: {
|
|
146
|
+
type: definePropType([Object, Boolean]),
|
|
147
|
+
default: true
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
const formEmits = {
|
|
151
|
+
validate: (prop, isValid, message) => (isArray(prop) || isString(prop)) && isBoolean(isValid) && isString(message)
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
const SCOPE = "ElForm";
|
|
155
|
+
function useFormLabelWidth() {
|
|
156
|
+
const potentialLabelWidthArr = ref([]);
|
|
157
|
+
const autoLabelWidth = computed(() => {
|
|
158
|
+
if (!potentialLabelWidthArr.value.length)
|
|
159
|
+
return "0";
|
|
160
|
+
const max = Math.max(...potentialLabelWidthArr.value);
|
|
161
|
+
return max ? `${max}px` : "";
|
|
162
|
+
});
|
|
163
|
+
function getLabelWidthIndex(width) {
|
|
164
|
+
const index = potentialLabelWidthArr.value.indexOf(width);
|
|
165
|
+
if (index === -1 && autoLabelWidth.value === "0") {
|
|
166
|
+
debugWarn(SCOPE, `unexpected width ${width}`);
|
|
167
|
+
}
|
|
168
|
+
return index;
|
|
169
|
+
}
|
|
170
|
+
function registerLabelWidth(val, oldVal) {
|
|
171
|
+
if (val && oldVal) {
|
|
172
|
+
const index = getLabelWidthIndex(oldVal);
|
|
173
|
+
potentialLabelWidthArr.value.splice(index, 1, val);
|
|
174
|
+
} else if (val) {
|
|
175
|
+
potentialLabelWidthArr.value.push(val);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
function deregisterLabelWidth(val) {
|
|
179
|
+
const index = getLabelWidthIndex(val);
|
|
180
|
+
if (index > -1) {
|
|
181
|
+
potentialLabelWidthArr.value.splice(index, 1);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
return {
|
|
185
|
+
autoLabelWidth,
|
|
186
|
+
registerLabelWidth,
|
|
187
|
+
deregisterLabelWidth
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
const filterFields = (fields, props) => {
|
|
191
|
+
const normalized = castArray(props).map(
|
|
192
|
+
(prop) => isArray(prop) ? prop.join(".") : prop
|
|
193
|
+
);
|
|
194
|
+
return normalized.length > 0 ? fields.filter(
|
|
195
|
+
(field) => field.propString && normalized.includes(field.propString)
|
|
196
|
+
) : fields;
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
const COMPONENT_NAME$1 = "ElForm";
|
|
200
|
+
const _sfc_main$2 = defineComponent({
|
|
201
|
+
...{
|
|
202
|
+
name: COMPONENT_NAME$1
|
|
203
|
+
},
|
|
204
|
+
__name: "form",
|
|
205
|
+
props: formProps,
|
|
206
|
+
emits: formEmits,
|
|
207
|
+
setup(__props, { expose: __expose, emit: __emit }) {
|
|
208
|
+
const props = __props;
|
|
209
|
+
const emit = __emit;
|
|
210
|
+
const formRef = ref();
|
|
211
|
+
const fields = reactive([]);
|
|
212
|
+
const formSize = useFormSize();
|
|
213
|
+
const ns = useNamespace("form");
|
|
214
|
+
const formClasses = computed(() => {
|
|
215
|
+
const { labelPosition, inline } = props;
|
|
216
|
+
return [
|
|
217
|
+
ns.b(),
|
|
218
|
+
ns.m(formSize.value || "default"),
|
|
219
|
+
{
|
|
220
|
+
[ns.m(`label-${labelPosition}`)]: labelPosition,
|
|
221
|
+
[ns.m("inline")]: inline
|
|
222
|
+
}
|
|
223
|
+
];
|
|
224
|
+
});
|
|
225
|
+
const getField = (prop) => {
|
|
226
|
+
return filterFields(fields, [prop])[0];
|
|
227
|
+
};
|
|
228
|
+
const addField = (field) => {
|
|
229
|
+
fields.push(field);
|
|
230
|
+
};
|
|
231
|
+
const removeField = (field) => {
|
|
232
|
+
if (field.prop) {
|
|
233
|
+
fields.splice(fields.indexOf(field), 1);
|
|
234
|
+
}
|
|
235
|
+
};
|
|
236
|
+
const setInitialValues = (initModel) => {
|
|
237
|
+
if (!props.model) {
|
|
238
|
+
debugWarn(COMPONENT_NAME$1, "model is required for setInitialValues to work.");
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
if (!initModel) {
|
|
242
|
+
debugWarn(
|
|
243
|
+
COMPONENT_NAME$1,
|
|
244
|
+
"initModel is required for setInitialValues to work."
|
|
245
|
+
);
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
248
|
+
fields.forEach((field) => {
|
|
249
|
+
if (field.prop) {
|
|
250
|
+
if (has(initModel, field.prop)) {
|
|
251
|
+
const initValue = getProp(initModel, field.prop).value;
|
|
252
|
+
field.setInitialValue(initValue);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
});
|
|
256
|
+
};
|
|
257
|
+
const resetFields = (properties = []) => {
|
|
258
|
+
if (!props.model) {
|
|
259
|
+
debugWarn(COMPONENT_NAME$1, "model is required for resetFields to work.");
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
262
|
+
filterFields(fields, properties).forEach((field) => field.resetField());
|
|
263
|
+
};
|
|
264
|
+
const clearValidate = (props2 = []) => {
|
|
265
|
+
filterFields(fields, props2).forEach((field) => field.clearValidate());
|
|
266
|
+
};
|
|
267
|
+
const isValidatable = computed(() => {
|
|
268
|
+
const hasModel = !!props.model;
|
|
269
|
+
if (!hasModel) {
|
|
270
|
+
debugWarn(COMPONENT_NAME$1, "model is required for validate to work.");
|
|
271
|
+
}
|
|
272
|
+
return hasModel;
|
|
273
|
+
});
|
|
274
|
+
const obtainValidateFields = (props2) => {
|
|
275
|
+
if (fields.length === 0)
|
|
276
|
+
return [];
|
|
277
|
+
const filteredFields = filterFields(fields, props2);
|
|
278
|
+
if (!filteredFields.length) {
|
|
279
|
+
debugWarn(COMPONENT_NAME$1, "please pass correct props!");
|
|
280
|
+
return [];
|
|
281
|
+
}
|
|
282
|
+
return filteredFields;
|
|
283
|
+
};
|
|
284
|
+
const validate = async (callback) => validateField(void 0, callback);
|
|
285
|
+
const doValidateField = async (props2 = []) => {
|
|
286
|
+
if (!isValidatable.value)
|
|
287
|
+
return false;
|
|
288
|
+
const fields2 = obtainValidateFields(props2);
|
|
289
|
+
if (fields2.length === 0)
|
|
290
|
+
return true;
|
|
291
|
+
let validationErrors = {};
|
|
292
|
+
for (const field of fields2) {
|
|
293
|
+
try {
|
|
294
|
+
await field.validate("");
|
|
295
|
+
if (field.validateState === "error" && !field.error)
|
|
296
|
+
field.resetField();
|
|
297
|
+
} catch (fields3) {
|
|
298
|
+
validationErrors = {
|
|
299
|
+
...validationErrors,
|
|
300
|
+
...fields3
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
if (Object.keys(validationErrors).length === 0)
|
|
305
|
+
return true;
|
|
306
|
+
return Promise.reject(validationErrors);
|
|
307
|
+
};
|
|
308
|
+
const validateField = async (modelProps = [], callback) => {
|
|
309
|
+
let result = false;
|
|
310
|
+
const shouldThrow = !isFunction(callback);
|
|
311
|
+
try {
|
|
312
|
+
result = await doValidateField(modelProps);
|
|
313
|
+
if (result === true) {
|
|
314
|
+
await (callback == null ? void 0 : callback(result));
|
|
315
|
+
}
|
|
316
|
+
return result;
|
|
317
|
+
} catch (e) {
|
|
318
|
+
if (e instanceof Error)
|
|
319
|
+
throw e;
|
|
320
|
+
const invalidFields = e;
|
|
321
|
+
if (props.scrollToError) {
|
|
322
|
+
if (formRef.value) {
|
|
323
|
+
const formItem = formRef.value.querySelector(`.${ns.b()}-item.is-error`);
|
|
324
|
+
formItem == null ? void 0 : formItem.scrollIntoView(props.scrollIntoViewOptions);
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
!result && await (callback == null ? void 0 : callback(false, invalidFields));
|
|
328
|
+
return shouldThrow && Promise.reject(invalidFields);
|
|
329
|
+
}
|
|
330
|
+
};
|
|
331
|
+
const scrollToField = (prop) => {
|
|
332
|
+
var _a;
|
|
333
|
+
const field = getField(prop);
|
|
334
|
+
if (field) {
|
|
335
|
+
(_a = field.$el) == null ? void 0 : _a.scrollIntoView(props.scrollIntoViewOptions);
|
|
336
|
+
}
|
|
337
|
+
};
|
|
338
|
+
watch(
|
|
339
|
+
() => props.rules,
|
|
340
|
+
() => {
|
|
341
|
+
if (props.validateOnRuleChange) {
|
|
342
|
+
validate().catch((err) => debugWarn(err));
|
|
343
|
+
}
|
|
344
|
+
},
|
|
345
|
+
{ deep: true, flush: "post" }
|
|
346
|
+
);
|
|
347
|
+
provide(
|
|
348
|
+
formContextKey,
|
|
349
|
+
reactive({
|
|
350
|
+
...toRefs(props),
|
|
351
|
+
emit,
|
|
352
|
+
resetFields,
|
|
353
|
+
clearValidate,
|
|
354
|
+
validateField,
|
|
355
|
+
getField,
|
|
356
|
+
addField,
|
|
357
|
+
removeField,
|
|
358
|
+
setInitialValues,
|
|
359
|
+
...useFormLabelWidth()
|
|
360
|
+
})
|
|
361
|
+
);
|
|
362
|
+
__expose({
|
|
363
|
+
validate,
|
|
364
|
+
validateField,
|
|
365
|
+
resetFields,
|
|
366
|
+
clearValidate,
|
|
367
|
+
scrollToField,
|
|
368
|
+
getField,
|
|
369
|
+
fields,
|
|
370
|
+
setInitialValues
|
|
371
|
+
});
|
|
372
|
+
return (_ctx, _cache) => {
|
|
373
|
+
return openBlock(), createElementBlock(
|
|
374
|
+
"form",
|
|
375
|
+
{
|
|
376
|
+
ref_key: "formRef",
|
|
377
|
+
ref: formRef,
|
|
378
|
+
class: normalizeClass(formClasses.value)
|
|
379
|
+
},
|
|
380
|
+
[
|
|
381
|
+
renderSlot(_ctx.$slots, "default")
|
|
382
|
+
],
|
|
383
|
+
2
|
|
384
|
+
);
|
|
385
|
+
};
|
|
386
|
+
}
|
|
387
|
+
});
|
|
388
|
+
var Form = /* @__PURE__ */ _export_sfc(_sfc_main$2, [["__file", "/home/runner/work/element-plus/element-plus/packages/components/form/src/form.vue"]]);
|
|
389
|
+
|
|
390
|
+
function _extends() {
|
|
391
|
+
_extends = Object.assign ? Object.assign.bind() : function (target) {
|
|
392
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
393
|
+
var source = arguments[i];
|
|
394
|
+
|
|
395
|
+
for (var key in source) {
|
|
396
|
+
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
397
|
+
target[key] = source[key];
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
return target;
|
|
403
|
+
};
|
|
404
|
+
return _extends.apply(this, arguments);
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
function _inheritsLoose(subClass, superClass) {
|
|
408
|
+
subClass.prototype = Object.create(superClass.prototype);
|
|
409
|
+
subClass.prototype.constructor = subClass;
|
|
410
|
+
|
|
411
|
+
_setPrototypeOf(subClass, superClass);
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
function _getPrototypeOf(o) {
|
|
415
|
+
_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) {
|
|
416
|
+
return o.__proto__ || Object.getPrototypeOf(o);
|
|
417
|
+
};
|
|
418
|
+
return _getPrototypeOf(o);
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
function _setPrototypeOf(o, p) {
|
|
422
|
+
_setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
|
|
423
|
+
o.__proto__ = p;
|
|
424
|
+
return o;
|
|
425
|
+
};
|
|
426
|
+
return _setPrototypeOf(o, p);
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
function _isNativeReflectConstruct() {
|
|
430
|
+
if (typeof Reflect === "undefined" || !Reflect.construct) return false;
|
|
431
|
+
if (Reflect.construct.sham) return false;
|
|
432
|
+
if (typeof Proxy === "function") return true;
|
|
433
|
+
|
|
434
|
+
try {
|
|
435
|
+
Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
|
|
436
|
+
return true;
|
|
437
|
+
} catch (e) {
|
|
438
|
+
return false;
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
function _construct(Parent, args, Class) {
|
|
443
|
+
if (_isNativeReflectConstruct()) {
|
|
444
|
+
_construct = Reflect.construct.bind();
|
|
445
|
+
} else {
|
|
446
|
+
_construct = function _construct(Parent, args, Class) {
|
|
447
|
+
var a = [null];
|
|
448
|
+
a.push.apply(a, args);
|
|
449
|
+
var Constructor = Function.bind.apply(Parent, a);
|
|
450
|
+
var instance = new Constructor();
|
|
451
|
+
if (Class) _setPrototypeOf(instance, Class.prototype);
|
|
452
|
+
return instance;
|
|
453
|
+
};
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
return _construct.apply(null, arguments);
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
function _isNativeFunction(fn) {
|
|
460
|
+
return Function.toString.call(fn).indexOf("[native code]") !== -1;
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
function _wrapNativeSuper(Class) {
|
|
464
|
+
var _cache = typeof Map === "function" ? new Map() : undefined;
|
|
465
|
+
|
|
466
|
+
_wrapNativeSuper = function _wrapNativeSuper(Class) {
|
|
467
|
+
if (Class === null || !_isNativeFunction(Class)) return Class;
|
|
468
|
+
|
|
469
|
+
if (typeof Class !== "function") {
|
|
470
|
+
throw new TypeError("Super expression must either be null or a function");
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
if (typeof _cache !== "undefined") {
|
|
474
|
+
if (_cache.has(Class)) return _cache.get(Class);
|
|
475
|
+
|
|
476
|
+
_cache.set(Class, Wrapper);
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
function Wrapper() {
|
|
480
|
+
return _construct(Class, arguments, _getPrototypeOf(this).constructor);
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
Wrapper.prototype = Object.create(Class.prototype, {
|
|
484
|
+
constructor: {
|
|
485
|
+
value: Wrapper,
|
|
486
|
+
enumerable: false,
|
|
487
|
+
writable: true,
|
|
488
|
+
configurable: true
|
|
489
|
+
}
|
|
490
|
+
});
|
|
491
|
+
return _setPrototypeOf(Wrapper, Class);
|
|
492
|
+
};
|
|
493
|
+
|
|
494
|
+
return _wrapNativeSuper(Class);
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
/* eslint no-console:0 */
|
|
498
|
+
var formatRegExp = /%[sdj%]/g;
|
|
499
|
+
var warning = function warning() {}; // don't print warning message when in production env or node runtime
|
|
500
|
+
|
|
501
|
+
if (typeof process !== 'undefined' && process.env && process.env.NODE_ENV !== 'production' && typeof window !== 'undefined' && typeof document !== 'undefined') {
|
|
502
|
+
warning = function warning(type, errors) {
|
|
503
|
+
if (typeof console !== 'undefined' && console.warn && typeof ASYNC_VALIDATOR_NO_WARNING === 'undefined') {
|
|
504
|
+
if (errors.every(function (e) {
|
|
505
|
+
return typeof e === 'string';
|
|
506
|
+
})) {
|
|
507
|
+
console.warn(type, errors);
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
};
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
function convertFieldsError(errors) {
|
|
514
|
+
if (!errors || !errors.length) return null;
|
|
515
|
+
var fields = {};
|
|
516
|
+
errors.forEach(function (error) {
|
|
517
|
+
var field = error.field;
|
|
518
|
+
fields[field] = fields[field] || [];
|
|
519
|
+
fields[field].push(error);
|
|
520
|
+
});
|
|
521
|
+
return fields;
|
|
522
|
+
}
|
|
523
|
+
function format(template) {
|
|
524
|
+
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
525
|
+
args[_key - 1] = arguments[_key];
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
var i = 0;
|
|
529
|
+
var len = args.length;
|
|
530
|
+
|
|
531
|
+
if (typeof template === 'function') {
|
|
532
|
+
return template.apply(null, args);
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
if (typeof template === 'string') {
|
|
536
|
+
var str = template.replace(formatRegExp, function (x) {
|
|
537
|
+
if (x === '%%') {
|
|
538
|
+
return '%';
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
if (i >= len) {
|
|
542
|
+
return x;
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
switch (x) {
|
|
546
|
+
case '%s':
|
|
547
|
+
return String(args[i++]);
|
|
548
|
+
|
|
549
|
+
case '%d':
|
|
550
|
+
return Number(args[i++]);
|
|
551
|
+
|
|
552
|
+
case '%j':
|
|
553
|
+
try {
|
|
554
|
+
return JSON.stringify(args[i++]);
|
|
555
|
+
} catch (_) {
|
|
556
|
+
return '[Circular]';
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
break;
|
|
560
|
+
|
|
561
|
+
default:
|
|
562
|
+
return x;
|
|
563
|
+
}
|
|
564
|
+
});
|
|
565
|
+
return str;
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
return template;
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
function isNativeStringType(type) {
|
|
572
|
+
return type === 'string' || type === 'url' || type === 'hex' || type === 'email' || type === 'date' || type === 'pattern';
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
function isEmptyValue(value, type) {
|
|
576
|
+
if (value === undefined || value === null) {
|
|
577
|
+
return true;
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
if (type === 'array' && Array.isArray(value) && !value.length) {
|
|
581
|
+
return true;
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
if (isNativeStringType(type) && typeof value === 'string' && !value) {
|
|
585
|
+
return true;
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
return false;
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
function asyncParallelArray(arr, func, callback) {
|
|
592
|
+
var results = [];
|
|
593
|
+
var total = 0;
|
|
594
|
+
var arrLength = arr.length;
|
|
595
|
+
|
|
596
|
+
function count(errors) {
|
|
597
|
+
results.push.apply(results, errors || []);
|
|
598
|
+
total++;
|
|
599
|
+
|
|
600
|
+
if (total === arrLength) {
|
|
601
|
+
callback(results);
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
arr.forEach(function (a) {
|
|
606
|
+
func(a, count);
|
|
607
|
+
});
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
function asyncSerialArray(arr, func, callback) {
|
|
611
|
+
var index = 0;
|
|
612
|
+
var arrLength = arr.length;
|
|
613
|
+
|
|
614
|
+
function next(errors) {
|
|
615
|
+
if (errors && errors.length) {
|
|
616
|
+
callback(errors);
|
|
617
|
+
return;
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
var original = index;
|
|
621
|
+
index = index + 1;
|
|
622
|
+
|
|
623
|
+
if (original < arrLength) {
|
|
624
|
+
func(arr[original], next);
|
|
625
|
+
} else {
|
|
626
|
+
callback([]);
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
next([]);
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
function flattenObjArr(objArr) {
|
|
634
|
+
var ret = [];
|
|
635
|
+
Object.keys(objArr).forEach(function (k) {
|
|
636
|
+
ret.push.apply(ret, objArr[k] || []);
|
|
637
|
+
});
|
|
638
|
+
return ret;
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
var AsyncValidationError = /*#__PURE__*/function (_Error) {
|
|
642
|
+
_inheritsLoose(AsyncValidationError, _Error);
|
|
643
|
+
|
|
644
|
+
function AsyncValidationError(errors, fields) {
|
|
645
|
+
var _this;
|
|
646
|
+
|
|
647
|
+
_this = _Error.call(this, 'Async Validation Error') || this;
|
|
648
|
+
_this.errors = errors;
|
|
649
|
+
_this.fields = fields;
|
|
650
|
+
return _this;
|
|
651
|
+
}
|
|
652
|
+
|
|
653
|
+
return AsyncValidationError;
|
|
654
|
+
}( /*#__PURE__*/_wrapNativeSuper(Error));
|
|
655
|
+
function asyncMap(objArr, option, func, callback, source) {
|
|
656
|
+
if (option.first) {
|
|
657
|
+
var _pending = new Promise(function (resolve, reject) {
|
|
658
|
+
var next = function next(errors) {
|
|
659
|
+
callback(errors);
|
|
660
|
+
return errors.length ? reject(new AsyncValidationError(errors, convertFieldsError(errors))) : resolve(source);
|
|
661
|
+
};
|
|
662
|
+
|
|
663
|
+
var flattenArr = flattenObjArr(objArr);
|
|
664
|
+
asyncSerialArray(flattenArr, func, next);
|
|
665
|
+
});
|
|
666
|
+
|
|
667
|
+
_pending["catch"](function (e) {
|
|
668
|
+
return e;
|
|
669
|
+
});
|
|
670
|
+
|
|
671
|
+
return _pending;
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
var firstFields = option.firstFields === true ? Object.keys(objArr) : option.firstFields || [];
|
|
675
|
+
var objArrKeys = Object.keys(objArr);
|
|
676
|
+
var objArrLength = objArrKeys.length;
|
|
677
|
+
var total = 0;
|
|
678
|
+
var results = [];
|
|
679
|
+
var pending = new Promise(function (resolve, reject) {
|
|
680
|
+
var next = function next(errors) {
|
|
681
|
+
results.push.apply(results, errors);
|
|
682
|
+
total++;
|
|
683
|
+
|
|
684
|
+
if (total === objArrLength) {
|
|
685
|
+
callback(results);
|
|
686
|
+
return results.length ? reject(new AsyncValidationError(results, convertFieldsError(results))) : resolve(source);
|
|
687
|
+
}
|
|
688
|
+
};
|
|
689
|
+
|
|
690
|
+
if (!objArrKeys.length) {
|
|
691
|
+
callback(results);
|
|
692
|
+
resolve(source);
|
|
693
|
+
}
|
|
694
|
+
|
|
695
|
+
objArrKeys.forEach(function (key) {
|
|
696
|
+
var arr = objArr[key];
|
|
697
|
+
|
|
698
|
+
if (firstFields.indexOf(key) !== -1) {
|
|
699
|
+
asyncSerialArray(arr, func, next);
|
|
700
|
+
} else {
|
|
701
|
+
asyncParallelArray(arr, func, next);
|
|
702
|
+
}
|
|
703
|
+
});
|
|
704
|
+
});
|
|
705
|
+
pending["catch"](function (e) {
|
|
706
|
+
return e;
|
|
707
|
+
});
|
|
708
|
+
return pending;
|
|
709
|
+
}
|
|
710
|
+
|
|
711
|
+
function isErrorObj(obj) {
|
|
712
|
+
return !!(obj && obj.message !== undefined);
|
|
713
|
+
}
|
|
714
|
+
|
|
715
|
+
function getValue(value, path) {
|
|
716
|
+
var v = value;
|
|
717
|
+
|
|
718
|
+
for (var i = 0; i < path.length; i++) {
|
|
719
|
+
if (v == undefined) {
|
|
720
|
+
return v;
|
|
721
|
+
}
|
|
722
|
+
|
|
723
|
+
v = v[path[i]];
|
|
724
|
+
}
|
|
725
|
+
|
|
726
|
+
return v;
|
|
727
|
+
}
|
|
728
|
+
|
|
729
|
+
function complementError(rule, source) {
|
|
730
|
+
return function (oe) {
|
|
731
|
+
var fieldValue;
|
|
732
|
+
|
|
733
|
+
if (rule.fullFields) {
|
|
734
|
+
fieldValue = getValue(source, rule.fullFields);
|
|
735
|
+
} else {
|
|
736
|
+
fieldValue = source[oe.field || rule.fullField];
|
|
737
|
+
}
|
|
738
|
+
|
|
739
|
+
if (isErrorObj(oe)) {
|
|
740
|
+
oe.field = oe.field || rule.fullField;
|
|
741
|
+
oe.fieldValue = fieldValue;
|
|
742
|
+
return oe;
|
|
743
|
+
}
|
|
744
|
+
|
|
745
|
+
return {
|
|
746
|
+
message: typeof oe === 'function' ? oe() : oe,
|
|
747
|
+
fieldValue: fieldValue,
|
|
748
|
+
field: oe.field || rule.fullField
|
|
749
|
+
};
|
|
750
|
+
};
|
|
751
|
+
}
|
|
752
|
+
function deepMerge(target, source) {
|
|
753
|
+
if (source) {
|
|
754
|
+
for (var s in source) {
|
|
755
|
+
if (source.hasOwnProperty(s)) {
|
|
756
|
+
var value = source[s];
|
|
757
|
+
|
|
758
|
+
if (typeof value === 'object' && typeof target[s] === 'object') {
|
|
759
|
+
target[s] = _extends({}, target[s], value);
|
|
760
|
+
} else {
|
|
761
|
+
target[s] = value;
|
|
762
|
+
}
|
|
763
|
+
}
|
|
764
|
+
}
|
|
765
|
+
}
|
|
766
|
+
|
|
767
|
+
return target;
|
|
768
|
+
}
|
|
769
|
+
|
|
770
|
+
var required$1 = function required(rule, value, source, errors, options, type) {
|
|
771
|
+
if (rule.required && (!source.hasOwnProperty(rule.field) || isEmptyValue(value, type || rule.type))) {
|
|
772
|
+
errors.push(format(options.messages.required, rule.fullField));
|
|
773
|
+
}
|
|
774
|
+
};
|
|
775
|
+
|
|
776
|
+
/**
|
|
777
|
+
* Rule for validating whitespace.
|
|
778
|
+
*
|
|
779
|
+
* @param rule The validation rule.
|
|
780
|
+
* @param value The value of the field on the source object.
|
|
781
|
+
* @param source The source object being validated.
|
|
782
|
+
* @param errors An array of errors that this rule may add
|
|
783
|
+
* validation errors to.
|
|
784
|
+
* @param options The validation options.
|
|
785
|
+
* @param options.messages The validation messages.
|
|
786
|
+
*/
|
|
787
|
+
|
|
788
|
+
var whitespace = function whitespace(rule, value, source, errors, options) {
|
|
789
|
+
if (/^\s+$/.test(value) || value === '') {
|
|
790
|
+
errors.push(format(options.messages.whitespace, rule.fullField));
|
|
791
|
+
}
|
|
792
|
+
};
|
|
793
|
+
|
|
794
|
+
// https://github.com/kevva/url-regex/blob/master/index.js
|
|
795
|
+
var urlReg;
|
|
796
|
+
var getUrlRegex = (function () {
|
|
797
|
+
if (urlReg) {
|
|
798
|
+
return urlReg;
|
|
799
|
+
}
|
|
800
|
+
|
|
801
|
+
var word = '[a-fA-F\\d:]';
|
|
802
|
+
|
|
803
|
+
var b = function b(options) {
|
|
804
|
+
return options && options.includeBoundaries ? "(?:(?<=\\s|^)(?=" + word + ")|(?<=" + word + ")(?=\\s|$))" : '';
|
|
805
|
+
};
|
|
806
|
+
|
|
807
|
+
var v4 = '(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)(?:\\.(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)){3}';
|
|
808
|
+
var v6seg = '[a-fA-F\\d]{1,4}';
|
|
809
|
+
var v6 = ("\n(?:\n(?:" + v6seg + ":){7}(?:" + v6seg + "|:)| // 1:2:3:4:5:6:7:: 1:2:3:4:5:6:7:8\n(?:" + v6seg + ":){6}(?:" + v4 + "|:" + v6seg + "|:)| // 1:2:3:4:5:6:: 1:2:3:4:5:6::8 1:2:3:4:5:6::8 1:2:3:4:5:6::1.2.3.4\n(?:" + v6seg + ":){5}(?::" + v4 + "|(?::" + v6seg + "){1,2}|:)| // 1:2:3:4:5:: 1:2:3:4:5::7:8 1:2:3:4:5::8 1:2:3:4:5::7:1.2.3.4\n(?:" + v6seg + ":){4}(?:(?::" + v6seg + "){0,1}:" + v4 + "|(?::" + v6seg + "){1,3}|:)| // 1:2:3:4:: 1:2:3:4::6:7:8 1:2:3:4::8 1:2:3:4::6:7:1.2.3.4\n(?:" + v6seg + ":){3}(?:(?::" + v6seg + "){0,2}:" + v4 + "|(?::" + v6seg + "){1,4}|:)| // 1:2:3:: 1:2:3::5:6:7:8 1:2:3::8 1:2:3::5:6:7:1.2.3.4\n(?:" + v6seg + ":){2}(?:(?::" + v6seg + "){0,3}:" + v4 + "|(?::" + v6seg + "){1,5}|:)| // 1:2:: 1:2::4:5:6:7:8 1:2::8 1:2::4:5:6:7:1.2.3.4\n(?:" + v6seg + ":){1}(?:(?::" + v6seg + "){0,4}:" + v4 + "|(?::" + v6seg + "){1,6}|:)| // 1:: 1::3:4:5:6:7:8 1::8 1::3:4:5:6:7:1.2.3.4\n(?::(?:(?::" + v6seg + "){0,5}:" + v4 + "|(?::" + v6seg + "){1,7}|:)) // ::2:3:4:5:6:7:8 ::2:3:4:5:6:7:8 ::8 ::1.2.3.4\n)(?:%[0-9a-zA-Z]{1,})? // %eth0 %1\n").replace(/\s*\/\/.*$/gm, '').replace(/\n/g, '').trim(); // Pre-compile only the exact regexes because adding a global flag make regexes stateful
|
|
810
|
+
|
|
811
|
+
var v46Exact = new RegExp("(?:^" + v4 + "$)|(?:^" + v6 + "$)");
|
|
812
|
+
var v4exact = new RegExp("^" + v4 + "$");
|
|
813
|
+
var v6exact = new RegExp("^" + v6 + "$");
|
|
814
|
+
|
|
815
|
+
var ip = function ip(options) {
|
|
816
|
+
return options && options.exact ? v46Exact : new RegExp("(?:" + b(options) + v4 + b(options) + ")|(?:" + b(options) + v6 + b(options) + ")", 'g');
|
|
817
|
+
};
|
|
818
|
+
|
|
819
|
+
ip.v4 = function (options) {
|
|
820
|
+
return options && options.exact ? v4exact : new RegExp("" + b(options) + v4 + b(options), 'g');
|
|
821
|
+
};
|
|
822
|
+
|
|
823
|
+
ip.v6 = function (options) {
|
|
824
|
+
return options && options.exact ? v6exact : new RegExp("" + b(options) + v6 + b(options), 'g');
|
|
825
|
+
};
|
|
826
|
+
|
|
827
|
+
var protocol = "(?:(?:[a-z]+:)?//)";
|
|
828
|
+
var auth = '(?:\\S+(?::\\S*)?@)?';
|
|
829
|
+
var ipv4 = ip.v4().source;
|
|
830
|
+
var ipv6 = ip.v6().source;
|
|
831
|
+
var host = "(?:(?:[a-z\\u00a1-\\uffff0-9][-_]*)*[a-z\\u00a1-\\uffff0-9]+)";
|
|
832
|
+
var domain = "(?:\\.(?:[a-z\\u00a1-\\uffff0-9]-*)*[a-z\\u00a1-\\uffff0-9]+)*";
|
|
833
|
+
var tld = "(?:\\.(?:[a-z\\u00a1-\\uffff]{2,}))";
|
|
834
|
+
var port = '(?::\\d{2,5})?';
|
|
835
|
+
var path = '(?:[/?#][^\\s"]*)?';
|
|
836
|
+
var regex = "(?:" + protocol + "|www\\.)" + auth + "(?:localhost|" + ipv4 + "|" + ipv6 + "|" + host + domain + tld + ")" + port + path;
|
|
837
|
+
urlReg = new RegExp("(?:^" + regex + "$)", 'i');
|
|
838
|
+
return urlReg;
|
|
839
|
+
});
|
|
840
|
+
|
|
841
|
+
/* eslint max-len:0 */
|
|
842
|
+
|
|
843
|
+
var pattern$2 = {
|
|
844
|
+
// http://emailregex.com/
|
|
845
|
+
email: /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+\.)+[a-zA-Z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]{2,}))$/,
|
|
846
|
+
// url: new RegExp(
|
|
847
|
+
// '^(?!mailto:)(?:(?:http|https|ftp)://|//)(?:\\S+(?::\\S*)?@)?(?:(?:(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}(?:\\.(?:[0-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))|(?:(?:[a-z\\u00a1-\\uffff0-9]+-*)*[a-z\\u00a1-\\uffff0-9]+)(?:\\.(?:[a-z\\u00a1-\\uffff0-9]+-*)*[a-z\\u00a1-\\uffff0-9]+)*(?:\\.(?:[a-z\\u00a1-\\uffff]{2,})))|localhost)(?::\\d{2,5})?(?:(/|\\?|#)[^\\s]*)?$',
|
|
848
|
+
// 'i',
|
|
849
|
+
// ),
|
|
850
|
+
hex: /^#?([a-f0-9]{6}|[a-f0-9]{3})$/i
|
|
851
|
+
};
|
|
852
|
+
var types = {
|
|
853
|
+
integer: function integer(value) {
|
|
854
|
+
return types.number(value) && parseInt(value, 10) === value;
|
|
855
|
+
},
|
|
856
|
+
"float": function float(value) {
|
|
857
|
+
return types.number(value) && !types.integer(value);
|
|
858
|
+
},
|
|
859
|
+
array: function array(value) {
|
|
860
|
+
return Array.isArray(value);
|
|
861
|
+
},
|
|
862
|
+
regexp: function regexp(value) {
|
|
863
|
+
if (value instanceof RegExp) {
|
|
864
|
+
return true;
|
|
865
|
+
}
|
|
866
|
+
|
|
867
|
+
try {
|
|
868
|
+
return !!new RegExp(value);
|
|
869
|
+
} catch (e) {
|
|
870
|
+
return false;
|
|
871
|
+
}
|
|
872
|
+
},
|
|
873
|
+
date: function date(value) {
|
|
874
|
+
return typeof value.getTime === 'function' && typeof value.getMonth === 'function' && typeof value.getYear === 'function' && !isNaN(value.getTime());
|
|
875
|
+
},
|
|
876
|
+
number: function number(value) {
|
|
877
|
+
if (isNaN(value)) {
|
|
878
|
+
return false;
|
|
879
|
+
}
|
|
880
|
+
|
|
881
|
+
return typeof value === 'number';
|
|
882
|
+
},
|
|
883
|
+
object: function object(value) {
|
|
884
|
+
return typeof value === 'object' && !types.array(value);
|
|
885
|
+
},
|
|
886
|
+
method: function method(value) {
|
|
887
|
+
return typeof value === 'function';
|
|
888
|
+
},
|
|
889
|
+
email: function email(value) {
|
|
890
|
+
return typeof value === 'string' && value.length <= 320 && !!value.match(pattern$2.email);
|
|
891
|
+
},
|
|
892
|
+
url: function url(value) {
|
|
893
|
+
return typeof value === 'string' && value.length <= 2048 && !!value.match(getUrlRegex());
|
|
894
|
+
},
|
|
895
|
+
hex: function hex(value) {
|
|
896
|
+
return typeof value === 'string' && !!value.match(pattern$2.hex);
|
|
897
|
+
}
|
|
898
|
+
};
|
|
899
|
+
|
|
900
|
+
var type$1 = function type(rule, value, source, errors, options) {
|
|
901
|
+
if (rule.required && value === undefined) {
|
|
902
|
+
required$1(rule, value, source, errors, options);
|
|
903
|
+
return;
|
|
904
|
+
}
|
|
905
|
+
|
|
906
|
+
var custom = ['integer', 'float', 'array', 'regexp', 'object', 'method', 'email', 'number', 'date', 'url', 'hex'];
|
|
907
|
+
var ruleType = rule.type;
|
|
908
|
+
|
|
909
|
+
if (custom.indexOf(ruleType) > -1) {
|
|
910
|
+
if (!types[ruleType](value)) {
|
|
911
|
+
errors.push(format(options.messages.types[ruleType], rule.fullField, rule.type));
|
|
912
|
+
} // straight typeof check
|
|
913
|
+
|
|
914
|
+
} else if (ruleType && typeof value !== rule.type) {
|
|
915
|
+
errors.push(format(options.messages.types[ruleType], rule.fullField, rule.type));
|
|
916
|
+
}
|
|
917
|
+
};
|
|
918
|
+
|
|
919
|
+
var range = function range(rule, value, source, errors, options) {
|
|
920
|
+
var len = typeof rule.len === 'number';
|
|
921
|
+
var min = typeof rule.min === 'number';
|
|
922
|
+
var max = typeof rule.max === 'number'; // 正则匹配码点范围从U+010000一直到U+10FFFF的文字(补充平面Supplementary Plane)
|
|
923
|
+
|
|
924
|
+
var spRegexp = /[\uD800-\uDBFF][\uDC00-\uDFFF]/g;
|
|
925
|
+
var val = value;
|
|
926
|
+
var key = null;
|
|
927
|
+
var num = typeof value === 'number';
|
|
928
|
+
var str = typeof value === 'string';
|
|
929
|
+
var arr = Array.isArray(value);
|
|
930
|
+
|
|
931
|
+
if (num) {
|
|
932
|
+
key = 'number';
|
|
933
|
+
} else if (str) {
|
|
934
|
+
key = 'string';
|
|
935
|
+
} else if (arr) {
|
|
936
|
+
key = 'array';
|
|
937
|
+
} // if the value is not of a supported type for range validation
|
|
938
|
+
// the validation rule rule should use the
|
|
939
|
+
// type property to also test for a particular type
|
|
940
|
+
|
|
941
|
+
|
|
942
|
+
if (!key) {
|
|
943
|
+
return false;
|
|
944
|
+
}
|
|
945
|
+
|
|
946
|
+
if (arr) {
|
|
947
|
+
val = value.length;
|
|
948
|
+
}
|
|
949
|
+
|
|
950
|
+
if (str) {
|
|
951
|
+
// 处理码点大于U+010000的文字length属性不准确的bug,如"𠮷𠮷𠮷".lenght !== 3
|
|
952
|
+
val = value.replace(spRegexp, '_').length;
|
|
953
|
+
}
|
|
954
|
+
|
|
955
|
+
if (len) {
|
|
956
|
+
if (val !== rule.len) {
|
|
957
|
+
errors.push(format(options.messages[key].len, rule.fullField, rule.len));
|
|
958
|
+
}
|
|
959
|
+
} else if (min && !max && val < rule.min) {
|
|
960
|
+
errors.push(format(options.messages[key].min, rule.fullField, rule.min));
|
|
961
|
+
} else if (max && !min && val > rule.max) {
|
|
962
|
+
errors.push(format(options.messages[key].max, rule.fullField, rule.max));
|
|
963
|
+
} else if (min && max && (val < rule.min || val > rule.max)) {
|
|
964
|
+
errors.push(format(options.messages[key].range, rule.fullField, rule.min, rule.max));
|
|
965
|
+
}
|
|
966
|
+
};
|
|
967
|
+
|
|
968
|
+
var ENUM$1 = 'enum';
|
|
969
|
+
|
|
970
|
+
var enumerable$1 = function enumerable(rule, value, source, errors, options) {
|
|
971
|
+
rule[ENUM$1] = Array.isArray(rule[ENUM$1]) ? rule[ENUM$1] : [];
|
|
972
|
+
|
|
973
|
+
if (rule[ENUM$1].indexOf(value) === -1) {
|
|
974
|
+
errors.push(format(options.messages[ENUM$1], rule.fullField, rule[ENUM$1].join(', ')));
|
|
975
|
+
}
|
|
976
|
+
};
|
|
977
|
+
|
|
978
|
+
var pattern$1 = function pattern(rule, value, source, errors, options) {
|
|
979
|
+
if (rule.pattern) {
|
|
980
|
+
if (rule.pattern instanceof RegExp) {
|
|
981
|
+
// if a RegExp instance is passed, reset `lastIndex` in case its `global`
|
|
982
|
+
// flag is accidentally set to `true`, which in a validation scenario
|
|
983
|
+
// is not necessary and the result might be misleading
|
|
984
|
+
rule.pattern.lastIndex = 0;
|
|
985
|
+
|
|
986
|
+
if (!rule.pattern.test(value)) {
|
|
987
|
+
errors.push(format(options.messages.pattern.mismatch, rule.fullField, value, rule.pattern));
|
|
988
|
+
}
|
|
989
|
+
} else if (typeof rule.pattern === 'string') {
|
|
990
|
+
var _pattern = new RegExp(rule.pattern);
|
|
991
|
+
|
|
992
|
+
if (!_pattern.test(value)) {
|
|
993
|
+
errors.push(format(options.messages.pattern.mismatch, rule.fullField, value, rule.pattern));
|
|
994
|
+
}
|
|
995
|
+
}
|
|
996
|
+
}
|
|
997
|
+
};
|
|
998
|
+
|
|
999
|
+
var rules = {
|
|
1000
|
+
required: required$1,
|
|
1001
|
+
whitespace: whitespace,
|
|
1002
|
+
type: type$1,
|
|
1003
|
+
range: range,
|
|
1004
|
+
"enum": enumerable$1,
|
|
1005
|
+
pattern: pattern$1
|
|
1006
|
+
};
|
|
1007
|
+
|
|
1008
|
+
var string = function string(rule, value, callback, source, options) {
|
|
1009
|
+
var errors = [];
|
|
1010
|
+
var validate = rule.required || !rule.required && source.hasOwnProperty(rule.field);
|
|
1011
|
+
|
|
1012
|
+
if (validate) {
|
|
1013
|
+
if (isEmptyValue(value, 'string') && !rule.required) {
|
|
1014
|
+
return callback();
|
|
1015
|
+
}
|
|
1016
|
+
|
|
1017
|
+
rules.required(rule, value, source, errors, options, 'string');
|
|
1018
|
+
|
|
1019
|
+
if (!isEmptyValue(value, 'string')) {
|
|
1020
|
+
rules.type(rule, value, source, errors, options);
|
|
1021
|
+
rules.range(rule, value, source, errors, options);
|
|
1022
|
+
rules.pattern(rule, value, source, errors, options);
|
|
1023
|
+
|
|
1024
|
+
if (rule.whitespace === true) {
|
|
1025
|
+
rules.whitespace(rule, value, source, errors, options);
|
|
1026
|
+
}
|
|
1027
|
+
}
|
|
1028
|
+
}
|
|
1029
|
+
|
|
1030
|
+
callback(errors);
|
|
1031
|
+
};
|
|
1032
|
+
|
|
1033
|
+
var method = function method(rule, value, callback, source, options) {
|
|
1034
|
+
var errors = [];
|
|
1035
|
+
var validate = rule.required || !rule.required && source.hasOwnProperty(rule.field);
|
|
1036
|
+
|
|
1037
|
+
if (validate) {
|
|
1038
|
+
if (isEmptyValue(value) && !rule.required) {
|
|
1039
|
+
return callback();
|
|
1040
|
+
}
|
|
1041
|
+
|
|
1042
|
+
rules.required(rule, value, source, errors, options);
|
|
1043
|
+
|
|
1044
|
+
if (value !== undefined) {
|
|
1045
|
+
rules.type(rule, value, source, errors, options);
|
|
1046
|
+
}
|
|
1047
|
+
}
|
|
1048
|
+
|
|
1049
|
+
callback(errors);
|
|
1050
|
+
};
|
|
1051
|
+
|
|
1052
|
+
var number = function number(rule, value, callback, source, options) {
|
|
1053
|
+
var errors = [];
|
|
1054
|
+
var validate = rule.required || !rule.required && source.hasOwnProperty(rule.field);
|
|
1055
|
+
|
|
1056
|
+
if (validate) {
|
|
1057
|
+
if (value === '') {
|
|
1058
|
+
value = undefined;
|
|
1059
|
+
}
|
|
1060
|
+
|
|
1061
|
+
if (isEmptyValue(value) && !rule.required) {
|
|
1062
|
+
return callback();
|
|
1063
|
+
}
|
|
1064
|
+
|
|
1065
|
+
rules.required(rule, value, source, errors, options);
|
|
1066
|
+
|
|
1067
|
+
if (value !== undefined) {
|
|
1068
|
+
rules.type(rule, value, source, errors, options);
|
|
1069
|
+
rules.range(rule, value, source, errors, options);
|
|
1070
|
+
}
|
|
1071
|
+
}
|
|
1072
|
+
|
|
1073
|
+
callback(errors);
|
|
1074
|
+
};
|
|
1075
|
+
|
|
1076
|
+
var _boolean = function _boolean(rule, value, callback, source, options) {
|
|
1077
|
+
var errors = [];
|
|
1078
|
+
var validate = rule.required || !rule.required && source.hasOwnProperty(rule.field);
|
|
1079
|
+
|
|
1080
|
+
if (validate) {
|
|
1081
|
+
if (isEmptyValue(value) && !rule.required) {
|
|
1082
|
+
return callback();
|
|
1083
|
+
}
|
|
1084
|
+
|
|
1085
|
+
rules.required(rule, value, source, errors, options);
|
|
1086
|
+
|
|
1087
|
+
if (value !== undefined) {
|
|
1088
|
+
rules.type(rule, value, source, errors, options);
|
|
1089
|
+
}
|
|
1090
|
+
}
|
|
1091
|
+
|
|
1092
|
+
callback(errors);
|
|
1093
|
+
};
|
|
1094
|
+
|
|
1095
|
+
var regexp = function regexp(rule, value, callback, source, options) {
|
|
1096
|
+
var errors = [];
|
|
1097
|
+
var validate = rule.required || !rule.required && source.hasOwnProperty(rule.field);
|
|
1098
|
+
|
|
1099
|
+
if (validate) {
|
|
1100
|
+
if (isEmptyValue(value) && !rule.required) {
|
|
1101
|
+
return callback();
|
|
1102
|
+
}
|
|
1103
|
+
|
|
1104
|
+
rules.required(rule, value, source, errors, options);
|
|
1105
|
+
|
|
1106
|
+
if (!isEmptyValue(value)) {
|
|
1107
|
+
rules.type(rule, value, source, errors, options);
|
|
1108
|
+
}
|
|
1109
|
+
}
|
|
1110
|
+
|
|
1111
|
+
callback(errors);
|
|
1112
|
+
};
|
|
1113
|
+
|
|
1114
|
+
var integer = function integer(rule, value, callback, source, options) {
|
|
1115
|
+
var errors = [];
|
|
1116
|
+
var validate = rule.required || !rule.required && source.hasOwnProperty(rule.field);
|
|
1117
|
+
|
|
1118
|
+
if (validate) {
|
|
1119
|
+
if (isEmptyValue(value) && !rule.required) {
|
|
1120
|
+
return callback();
|
|
1121
|
+
}
|
|
1122
|
+
|
|
1123
|
+
rules.required(rule, value, source, errors, options);
|
|
1124
|
+
|
|
1125
|
+
if (value !== undefined) {
|
|
1126
|
+
rules.type(rule, value, source, errors, options);
|
|
1127
|
+
rules.range(rule, value, source, errors, options);
|
|
1128
|
+
}
|
|
1129
|
+
}
|
|
1130
|
+
|
|
1131
|
+
callback(errors);
|
|
1132
|
+
};
|
|
1133
|
+
|
|
1134
|
+
var floatFn = function floatFn(rule, value, callback, source, options) {
|
|
1135
|
+
var errors = [];
|
|
1136
|
+
var validate = rule.required || !rule.required && source.hasOwnProperty(rule.field);
|
|
1137
|
+
|
|
1138
|
+
if (validate) {
|
|
1139
|
+
if (isEmptyValue(value) && !rule.required) {
|
|
1140
|
+
return callback();
|
|
1141
|
+
}
|
|
1142
|
+
|
|
1143
|
+
rules.required(rule, value, source, errors, options);
|
|
1144
|
+
|
|
1145
|
+
if (value !== undefined) {
|
|
1146
|
+
rules.type(rule, value, source, errors, options);
|
|
1147
|
+
rules.range(rule, value, source, errors, options);
|
|
1148
|
+
}
|
|
1149
|
+
}
|
|
1150
|
+
|
|
1151
|
+
callback(errors);
|
|
1152
|
+
};
|
|
1153
|
+
|
|
1154
|
+
var array = function array(rule, value, callback, source, options) {
|
|
1155
|
+
var errors = [];
|
|
1156
|
+
var validate = rule.required || !rule.required && source.hasOwnProperty(rule.field);
|
|
1157
|
+
|
|
1158
|
+
if (validate) {
|
|
1159
|
+
if ((value === undefined || value === null) && !rule.required) {
|
|
1160
|
+
return callback();
|
|
1161
|
+
}
|
|
1162
|
+
|
|
1163
|
+
rules.required(rule, value, source, errors, options, 'array');
|
|
1164
|
+
|
|
1165
|
+
if (value !== undefined && value !== null) {
|
|
1166
|
+
rules.type(rule, value, source, errors, options);
|
|
1167
|
+
rules.range(rule, value, source, errors, options);
|
|
1168
|
+
}
|
|
1169
|
+
}
|
|
1170
|
+
|
|
1171
|
+
callback(errors);
|
|
1172
|
+
};
|
|
1173
|
+
|
|
1174
|
+
var object = function object(rule, value, callback, source, options) {
|
|
1175
|
+
var errors = [];
|
|
1176
|
+
var validate = rule.required || !rule.required && source.hasOwnProperty(rule.field);
|
|
1177
|
+
|
|
1178
|
+
if (validate) {
|
|
1179
|
+
if (isEmptyValue(value) && !rule.required) {
|
|
1180
|
+
return callback();
|
|
1181
|
+
}
|
|
1182
|
+
|
|
1183
|
+
rules.required(rule, value, source, errors, options);
|
|
1184
|
+
|
|
1185
|
+
if (value !== undefined) {
|
|
1186
|
+
rules.type(rule, value, source, errors, options);
|
|
1187
|
+
}
|
|
1188
|
+
}
|
|
1189
|
+
|
|
1190
|
+
callback(errors);
|
|
1191
|
+
};
|
|
1192
|
+
|
|
1193
|
+
var ENUM = 'enum';
|
|
1194
|
+
|
|
1195
|
+
var enumerable = function enumerable(rule, value, callback, source, options) {
|
|
1196
|
+
var errors = [];
|
|
1197
|
+
var validate = rule.required || !rule.required && source.hasOwnProperty(rule.field);
|
|
1198
|
+
|
|
1199
|
+
if (validate) {
|
|
1200
|
+
if (isEmptyValue(value) && !rule.required) {
|
|
1201
|
+
return callback();
|
|
1202
|
+
}
|
|
1203
|
+
|
|
1204
|
+
rules.required(rule, value, source, errors, options);
|
|
1205
|
+
|
|
1206
|
+
if (value !== undefined) {
|
|
1207
|
+
rules[ENUM](rule, value, source, errors, options);
|
|
1208
|
+
}
|
|
1209
|
+
}
|
|
1210
|
+
|
|
1211
|
+
callback(errors);
|
|
1212
|
+
};
|
|
1213
|
+
|
|
1214
|
+
var pattern = function pattern(rule, value, callback, source, options) {
|
|
1215
|
+
var errors = [];
|
|
1216
|
+
var validate = rule.required || !rule.required && source.hasOwnProperty(rule.field);
|
|
1217
|
+
|
|
1218
|
+
if (validate) {
|
|
1219
|
+
if (isEmptyValue(value, 'string') && !rule.required) {
|
|
1220
|
+
return callback();
|
|
1221
|
+
}
|
|
1222
|
+
|
|
1223
|
+
rules.required(rule, value, source, errors, options);
|
|
1224
|
+
|
|
1225
|
+
if (!isEmptyValue(value, 'string')) {
|
|
1226
|
+
rules.pattern(rule, value, source, errors, options);
|
|
1227
|
+
}
|
|
1228
|
+
}
|
|
1229
|
+
|
|
1230
|
+
callback(errors);
|
|
1231
|
+
};
|
|
1232
|
+
|
|
1233
|
+
var date = function date(rule, value, callback, source, options) {
|
|
1234
|
+
// console.log('integer rule called %j', rule);
|
|
1235
|
+
var errors = [];
|
|
1236
|
+
var validate = rule.required || !rule.required && source.hasOwnProperty(rule.field); // console.log('validate on %s value', value);
|
|
1237
|
+
|
|
1238
|
+
if (validate) {
|
|
1239
|
+
if (isEmptyValue(value, 'date') && !rule.required) {
|
|
1240
|
+
return callback();
|
|
1241
|
+
}
|
|
1242
|
+
|
|
1243
|
+
rules.required(rule, value, source, errors, options);
|
|
1244
|
+
|
|
1245
|
+
if (!isEmptyValue(value, 'date')) {
|
|
1246
|
+
var dateObject;
|
|
1247
|
+
|
|
1248
|
+
if (value instanceof Date) {
|
|
1249
|
+
dateObject = value;
|
|
1250
|
+
} else {
|
|
1251
|
+
dateObject = new Date(value);
|
|
1252
|
+
}
|
|
1253
|
+
|
|
1254
|
+
rules.type(rule, dateObject, source, errors, options);
|
|
1255
|
+
|
|
1256
|
+
if (dateObject) {
|
|
1257
|
+
rules.range(rule, dateObject.getTime(), source, errors, options);
|
|
1258
|
+
}
|
|
1259
|
+
}
|
|
1260
|
+
}
|
|
1261
|
+
|
|
1262
|
+
callback(errors);
|
|
1263
|
+
};
|
|
1264
|
+
|
|
1265
|
+
var required = function required(rule, value, callback, source, options) {
|
|
1266
|
+
var errors = [];
|
|
1267
|
+
var type = Array.isArray(value) ? 'array' : typeof value;
|
|
1268
|
+
rules.required(rule, value, source, errors, options, type);
|
|
1269
|
+
callback(errors);
|
|
1270
|
+
};
|
|
1271
|
+
|
|
1272
|
+
var type = function type(rule, value, callback, source, options) {
|
|
1273
|
+
var ruleType = rule.type;
|
|
1274
|
+
var errors = [];
|
|
1275
|
+
var validate = rule.required || !rule.required && source.hasOwnProperty(rule.field);
|
|
1276
|
+
|
|
1277
|
+
if (validate) {
|
|
1278
|
+
if (isEmptyValue(value, ruleType) && !rule.required) {
|
|
1279
|
+
return callback();
|
|
1280
|
+
}
|
|
1281
|
+
|
|
1282
|
+
rules.required(rule, value, source, errors, options, ruleType);
|
|
1283
|
+
|
|
1284
|
+
if (!isEmptyValue(value, ruleType)) {
|
|
1285
|
+
rules.type(rule, value, source, errors, options);
|
|
1286
|
+
}
|
|
1287
|
+
}
|
|
1288
|
+
|
|
1289
|
+
callback(errors);
|
|
1290
|
+
};
|
|
1291
|
+
|
|
1292
|
+
var any = function any(rule, value, callback, source, options) {
|
|
1293
|
+
var errors = [];
|
|
1294
|
+
var validate = rule.required || !rule.required && source.hasOwnProperty(rule.field);
|
|
1295
|
+
|
|
1296
|
+
if (validate) {
|
|
1297
|
+
if (isEmptyValue(value) && !rule.required) {
|
|
1298
|
+
return callback();
|
|
1299
|
+
}
|
|
1300
|
+
|
|
1301
|
+
rules.required(rule, value, source, errors, options);
|
|
1302
|
+
}
|
|
1303
|
+
|
|
1304
|
+
callback(errors);
|
|
1305
|
+
};
|
|
1306
|
+
|
|
1307
|
+
var validators = {
|
|
1308
|
+
string: string,
|
|
1309
|
+
method: method,
|
|
1310
|
+
number: number,
|
|
1311
|
+
"boolean": _boolean,
|
|
1312
|
+
regexp: regexp,
|
|
1313
|
+
integer: integer,
|
|
1314
|
+
"float": floatFn,
|
|
1315
|
+
array: array,
|
|
1316
|
+
object: object,
|
|
1317
|
+
"enum": enumerable,
|
|
1318
|
+
pattern: pattern,
|
|
1319
|
+
date: date,
|
|
1320
|
+
url: type,
|
|
1321
|
+
hex: type,
|
|
1322
|
+
email: type,
|
|
1323
|
+
required: required,
|
|
1324
|
+
any: any
|
|
1325
|
+
};
|
|
1326
|
+
|
|
1327
|
+
function newMessages() {
|
|
1328
|
+
return {
|
|
1329
|
+
"default": 'Validation error on field %s',
|
|
1330
|
+
required: '%s is required',
|
|
1331
|
+
"enum": '%s must be one of %s',
|
|
1332
|
+
whitespace: '%s cannot be empty',
|
|
1333
|
+
date: {
|
|
1334
|
+
format: '%s date %s is invalid for format %s',
|
|
1335
|
+
parse: '%s date could not be parsed, %s is invalid ',
|
|
1336
|
+
invalid: '%s date %s is invalid'
|
|
1337
|
+
},
|
|
1338
|
+
types: {
|
|
1339
|
+
string: '%s is not a %s',
|
|
1340
|
+
method: '%s is not a %s (function)',
|
|
1341
|
+
array: '%s is not an %s',
|
|
1342
|
+
object: '%s is not an %s',
|
|
1343
|
+
number: '%s is not a %s',
|
|
1344
|
+
date: '%s is not a %s',
|
|
1345
|
+
"boolean": '%s is not a %s',
|
|
1346
|
+
integer: '%s is not an %s',
|
|
1347
|
+
"float": '%s is not a %s',
|
|
1348
|
+
regexp: '%s is not a valid %s',
|
|
1349
|
+
email: '%s is not a valid %s',
|
|
1350
|
+
url: '%s is not a valid %s',
|
|
1351
|
+
hex: '%s is not a valid %s'
|
|
1352
|
+
},
|
|
1353
|
+
string: {
|
|
1354
|
+
len: '%s must be exactly %s characters',
|
|
1355
|
+
min: '%s must be at least %s characters',
|
|
1356
|
+
max: '%s cannot be longer than %s characters',
|
|
1357
|
+
range: '%s must be between %s and %s characters'
|
|
1358
|
+
},
|
|
1359
|
+
number: {
|
|
1360
|
+
len: '%s must equal %s',
|
|
1361
|
+
min: '%s cannot be less than %s',
|
|
1362
|
+
max: '%s cannot be greater than %s',
|
|
1363
|
+
range: '%s must be between %s and %s'
|
|
1364
|
+
},
|
|
1365
|
+
array: {
|
|
1366
|
+
len: '%s must be exactly %s in length',
|
|
1367
|
+
min: '%s cannot be less than %s in length',
|
|
1368
|
+
max: '%s cannot be greater than %s in length',
|
|
1369
|
+
range: '%s must be between %s and %s in length'
|
|
1370
|
+
},
|
|
1371
|
+
pattern: {
|
|
1372
|
+
mismatch: '%s value %s does not match pattern %s'
|
|
1373
|
+
},
|
|
1374
|
+
clone: function clone() {
|
|
1375
|
+
var cloned = JSON.parse(JSON.stringify(this));
|
|
1376
|
+
cloned.clone = this.clone;
|
|
1377
|
+
return cloned;
|
|
1378
|
+
}
|
|
1379
|
+
};
|
|
1380
|
+
}
|
|
1381
|
+
var messages = newMessages();
|
|
1382
|
+
|
|
1383
|
+
/**
|
|
1384
|
+
* Encapsulates a validation schema.
|
|
1385
|
+
*
|
|
1386
|
+
* @param descriptor An object declaring validation rules
|
|
1387
|
+
* for this schema.
|
|
1388
|
+
*/
|
|
1389
|
+
|
|
1390
|
+
var Schema = /*#__PURE__*/function () {
|
|
1391
|
+
// ========================= Static =========================
|
|
1392
|
+
// ======================== Instance ========================
|
|
1393
|
+
function Schema(descriptor) {
|
|
1394
|
+
this.rules = null;
|
|
1395
|
+
this._messages = messages;
|
|
1396
|
+
this.define(descriptor);
|
|
1397
|
+
}
|
|
1398
|
+
|
|
1399
|
+
var _proto = Schema.prototype;
|
|
1400
|
+
|
|
1401
|
+
_proto.define = function define(rules) {
|
|
1402
|
+
var _this = this;
|
|
1403
|
+
|
|
1404
|
+
if (!rules) {
|
|
1405
|
+
throw new Error('Cannot configure a schema with no rules');
|
|
1406
|
+
}
|
|
1407
|
+
|
|
1408
|
+
if (typeof rules !== 'object' || Array.isArray(rules)) {
|
|
1409
|
+
throw new Error('Rules must be an object');
|
|
1410
|
+
}
|
|
1411
|
+
|
|
1412
|
+
this.rules = {};
|
|
1413
|
+
Object.keys(rules).forEach(function (name) {
|
|
1414
|
+
var item = rules[name];
|
|
1415
|
+
_this.rules[name] = Array.isArray(item) ? item : [item];
|
|
1416
|
+
});
|
|
1417
|
+
};
|
|
1418
|
+
|
|
1419
|
+
_proto.messages = function messages(_messages) {
|
|
1420
|
+
if (_messages) {
|
|
1421
|
+
this._messages = deepMerge(newMessages(), _messages);
|
|
1422
|
+
}
|
|
1423
|
+
|
|
1424
|
+
return this._messages;
|
|
1425
|
+
};
|
|
1426
|
+
|
|
1427
|
+
_proto.validate = function validate(source_, o, oc) {
|
|
1428
|
+
var _this2 = this;
|
|
1429
|
+
|
|
1430
|
+
if (o === void 0) {
|
|
1431
|
+
o = {};
|
|
1432
|
+
}
|
|
1433
|
+
|
|
1434
|
+
if (oc === void 0) {
|
|
1435
|
+
oc = function oc() {};
|
|
1436
|
+
}
|
|
1437
|
+
|
|
1438
|
+
var source = source_;
|
|
1439
|
+
var options = o;
|
|
1440
|
+
var callback = oc;
|
|
1441
|
+
|
|
1442
|
+
if (typeof options === 'function') {
|
|
1443
|
+
callback = options;
|
|
1444
|
+
options = {};
|
|
1445
|
+
}
|
|
1446
|
+
|
|
1447
|
+
if (!this.rules || Object.keys(this.rules).length === 0) {
|
|
1448
|
+
if (callback) {
|
|
1449
|
+
callback(null, source);
|
|
1450
|
+
}
|
|
1451
|
+
|
|
1452
|
+
return Promise.resolve(source);
|
|
1453
|
+
}
|
|
1454
|
+
|
|
1455
|
+
function complete(results) {
|
|
1456
|
+
var errors = [];
|
|
1457
|
+
var fields = {};
|
|
1458
|
+
|
|
1459
|
+
function add(e) {
|
|
1460
|
+
if (Array.isArray(e)) {
|
|
1461
|
+
var _errors;
|
|
1462
|
+
|
|
1463
|
+
errors = (_errors = errors).concat.apply(_errors, e);
|
|
1464
|
+
} else {
|
|
1465
|
+
errors.push(e);
|
|
1466
|
+
}
|
|
1467
|
+
}
|
|
1468
|
+
|
|
1469
|
+
for (var i = 0; i < results.length; i++) {
|
|
1470
|
+
add(results[i]);
|
|
1471
|
+
}
|
|
1472
|
+
|
|
1473
|
+
if (!errors.length) {
|
|
1474
|
+
callback(null, source);
|
|
1475
|
+
} else {
|
|
1476
|
+
fields = convertFieldsError(errors);
|
|
1477
|
+
callback(errors, fields);
|
|
1478
|
+
}
|
|
1479
|
+
}
|
|
1480
|
+
|
|
1481
|
+
if (options.messages) {
|
|
1482
|
+
var messages$1 = this.messages();
|
|
1483
|
+
|
|
1484
|
+
if (messages$1 === messages) {
|
|
1485
|
+
messages$1 = newMessages();
|
|
1486
|
+
}
|
|
1487
|
+
|
|
1488
|
+
deepMerge(messages$1, options.messages);
|
|
1489
|
+
options.messages = messages$1;
|
|
1490
|
+
} else {
|
|
1491
|
+
options.messages = this.messages();
|
|
1492
|
+
}
|
|
1493
|
+
|
|
1494
|
+
var series = {};
|
|
1495
|
+
var keys = options.keys || Object.keys(this.rules);
|
|
1496
|
+
keys.forEach(function (z) {
|
|
1497
|
+
var arr = _this2.rules[z];
|
|
1498
|
+
var value = source[z];
|
|
1499
|
+
arr.forEach(function (r) {
|
|
1500
|
+
var rule = r;
|
|
1501
|
+
|
|
1502
|
+
if (typeof rule.transform === 'function') {
|
|
1503
|
+
if (source === source_) {
|
|
1504
|
+
source = _extends({}, source);
|
|
1505
|
+
}
|
|
1506
|
+
|
|
1507
|
+
value = source[z] = rule.transform(value);
|
|
1508
|
+
}
|
|
1509
|
+
|
|
1510
|
+
if (typeof rule === 'function') {
|
|
1511
|
+
rule = {
|
|
1512
|
+
validator: rule
|
|
1513
|
+
};
|
|
1514
|
+
} else {
|
|
1515
|
+
rule = _extends({}, rule);
|
|
1516
|
+
} // Fill validator. Skip if nothing need to validate
|
|
1517
|
+
|
|
1518
|
+
|
|
1519
|
+
rule.validator = _this2.getValidationMethod(rule);
|
|
1520
|
+
|
|
1521
|
+
if (!rule.validator) {
|
|
1522
|
+
return;
|
|
1523
|
+
}
|
|
1524
|
+
|
|
1525
|
+
rule.field = z;
|
|
1526
|
+
rule.fullField = rule.fullField || z;
|
|
1527
|
+
rule.type = _this2.getType(rule);
|
|
1528
|
+
series[z] = series[z] || [];
|
|
1529
|
+
series[z].push({
|
|
1530
|
+
rule: rule,
|
|
1531
|
+
value: value,
|
|
1532
|
+
source: source,
|
|
1533
|
+
field: z
|
|
1534
|
+
});
|
|
1535
|
+
});
|
|
1536
|
+
});
|
|
1537
|
+
var errorFields = {};
|
|
1538
|
+
return asyncMap(series, options, function (data, doIt) {
|
|
1539
|
+
var rule = data.rule;
|
|
1540
|
+
var deep = (rule.type === 'object' || rule.type === 'array') && (typeof rule.fields === 'object' || typeof rule.defaultField === 'object');
|
|
1541
|
+
deep = deep && (rule.required || !rule.required && data.value);
|
|
1542
|
+
rule.field = data.field;
|
|
1543
|
+
|
|
1544
|
+
function addFullField(key, schema) {
|
|
1545
|
+
return _extends({}, schema, {
|
|
1546
|
+
fullField: rule.fullField + "." + key,
|
|
1547
|
+
fullFields: rule.fullFields ? [].concat(rule.fullFields, [key]) : [key]
|
|
1548
|
+
});
|
|
1549
|
+
}
|
|
1550
|
+
|
|
1551
|
+
function cb(e) {
|
|
1552
|
+
if (e === void 0) {
|
|
1553
|
+
e = [];
|
|
1554
|
+
}
|
|
1555
|
+
|
|
1556
|
+
var errorList = Array.isArray(e) ? e : [e];
|
|
1557
|
+
|
|
1558
|
+
if (!options.suppressWarning && errorList.length) {
|
|
1559
|
+
Schema.warning('async-validator:', errorList);
|
|
1560
|
+
}
|
|
1561
|
+
|
|
1562
|
+
if (errorList.length && rule.message !== undefined) {
|
|
1563
|
+
errorList = [].concat(rule.message);
|
|
1564
|
+
} // Fill error info
|
|
1565
|
+
|
|
1566
|
+
|
|
1567
|
+
var filledErrors = errorList.map(complementError(rule, source));
|
|
1568
|
+
|
|
1569
|
+
if (options.first && filledErrors.length) {
|
|
1570
|
+
errorFields[rule.field] = 1;
|
|
1571
|
+
return doIt(filledErrors);
|
|
1572
|
+
}
|
|
1573
|
+
|
|
1574
|
+
if (!deep) {
|
|
1575
|
+
doIt(filledErrors);
|
|
1576
|
+
} else {
|
|
1577
|
+
// if rule is required but the target object
|
|
1578
|
+
// does not exist fail at the rule level and don't
|
|
1579
|
+
// go deeper
|
|
1580
|
+
if (rule.required && !data.value) {
|
|
1581
|
+
if (rule.message !== undefined) {
|
|
1582
|
+
filledErrors = [].concat(rule.message).map(complementError(rule, source));
|
|
1583
|
+
} else if (options.error) {
|
|
1584
|
+
filledErrors = [options.error(rule, format(options.messages.required, rule.field))];
|
|
1585
|
+
}
|
|
1586
|
+
|
|
1587
|
+
return doIt(filledErrors);
|
|
1588
|
+
}
|
|
1589
|
+
|
|
1590
|
+
var fieldsSchema = {};
|
|
1591
|
+
|
|
1592
|
+
if (rule.defaultField) {
|
|
1593
|
+
Object.keys(data.value).map(function (key) {
|
|
1594
|
+
fieldsSchema[key] = rule.defaultField;
|
|
1595
|
+
});
|
|
1596
|
+
}
|
|
1597
|
+
|
|
1598
|
+
fieldsSchema = _extends({}, fieldsSchema, data.rule.fields);
|
|
1599
|
+
var paredFieldsSchema = {};
|
|
1600
|
+
Object.keys(fieldsSchema).forEach(function (field) {
|
|
1601
|
+
var fieldSchema = fieldsSchema[field];
|
|
1602
|
+
var fieldSchemaList = Array.isArray(fieldSchema) ? fieldSchema : [fieldSchema];
|
|
1603
|
+
paredFieldsSchema[field] = fieldSchemaList.map(addFullField.bind(null, field));
|
|
1604
|
+
});
|
|
1605
|
+
var schema = new Schema(paredFieldsSchema);
|
|
1606
|
+
schema.messages(options.messages);
|
|
1607
|
+
|
|
1608
|
+
if (data.rule.options) {
|
|
1609
|
+
data.rule.options.messages = options.messages;
|
|
1610
|
+
data.rule.options.error = options.error;
|
|
1611
|
+
}
|
|
1612
|
+
|
|
1613
|
+
schema.validate(data.value, data.rule.options || options, function (errs) {
|
|
1614
|
+
var finalErrors = [];
|
|
1615
|
+
|
|
1616
|
+
if (filledErrors && filledErrors.length) {
|
|
1617
|
+
finalErrors.push.apply(finalErrors, filledErrors);
|
|
1618
|
+
}
|
|
1619
|
+
|
|
1620
|
+
if (errs && errs.length) {
|
|
1621
|
+
finalErrors.push.apply(finalErrors, errs);
|
|
1622
|
+
}
|
|
1623
|
+
|
|
1624
|
+
doIt(finalErrors.length ? finalErrors : null);
|
|
1625
|
+
});
|
|
1626
|
+
}
|
|
1627
|
+
}
|
|
1628
|
+
|
|
1629
|
+
var res;
|
|
1630
|
+
|
|
1631
|
+
if (rule.asyncValidator) {
|
|
1632
|
+
res = rule.asyncValidator(rule, data.value, cb, data.source, options);
|
|
1633
|
+
} else if (rule.validator) {
|
|
1634
|
+
try {
|
|
1635
|
+
res = rule.validator(rule, data.value, cb, data.source, options);
|
|
1636
|
+
} catch (error) {
|
|
1637
|
+
console.error == null ? void 0 : console.error(error); // rethrow to report error
|
|
1638
|
+
|
|
1639
|
+
if (!options.suppressValidatorError) {
|
|
1640
|
+
setTimeout(function () {
|
|
1641
|
+
throw error;
|
|
1642
|
+
}, 0);
|
|
1643
|
+
}
|
|
1644
|
+
|
|
1645
|
+
cb(error.message);
|
|
1646
|
+
}
|
|
1647
|
+
|
|
1648
|
+
if (res === true) {
|
|
1649
|
+
cb();
|
|
1650
|
+
} else if (res === false) {
|
|
1651
|
+
cb(typeof rule.message === 'function' ? rule.message(rule.fullField || rule.field) : rule.message || (rule.fullField || rule.field) + " fails");
|
|
1652
|
+
} else if (res instanceof Array) {
|
|
1653
|
+
cb(res);
|
|
1654
|
+
} else if (res instanceof Error) {
|
|
1655
|
+
cb(res.message);
|
|
1656
|
+
}
|
|
1657
|
+
}
|
|
1658
|
+
|
|
1659
|
+
if (res && res.then) {
|
|
1660
|
+
res.then(function () {
|
|
1661
|
+
return cb();
|
|
1662
|
+
}, function (e) {
|
|
1663
|
+
return cb(e);
|
|
1664
|
+
});
|
|
1665
|
+
}
|
|
1666
|
+
}, function (results) {
|
|
1667
|
+
complete(results);
|
|
1668
|
+
}, source);
|
|
1669
|
+
};
|
|
1670
|
+
|
|
1671
|
+
_proto.getType = function getType(rule) {
|
|
1672
|
+
if (rule.type === undefined && rule.pattern instanceof RegExp) {
|
|
1673
|
+
rule.type = 'pattern';
|
|
1674
|
+
}
|
|
1675
|
+
|
|
1676
|
+
if (typeof rule.validator !== 'function' && rule.type && !validators.hasOwnProperty(rule.type)) {
|
|
1677
|
+
throw new Error(format('Unknown rule type %s', rule.type));
|
|
1678
|
+
}
|
|
1679
|
+
|
|
1680
|
+
return rule.type || 'string';
|
|
1681
|
+
};
|
|
1682
|
+
|
|
1683
|
+
_proto.getValidationMethod = function getValidationMethod(rule) {
|
|
1684
|
+
if (typeof rule.validator === 'function') {
|
|
1685
|
+
return rule.validator;
|
|
1686
|
+
}
|
|
1687
|
+
|
|
1688
|
+
var keys = Object.keys(rule);
|
|
1689
|
+
var messageIndex = keys.indexOf('message');
|
|
1690
|
+
|
|
1691
|
+
if (messageIndex !== -1) {
|
|
1692
|
+
keys.splice(messageIndex, 1);
|
|
1693
|
+
}
|
|
1694
|
+
|
|
1695
|
+
if (keys.length === 1 && keys[0] === 'required') {
|
|
1696
|
+
return validators.required;
|
|
1697
|
+
}
|
|
1698
|
+
|
|
1699
|
+
return validators[this.getType(rule)] || undefined;
|
|
1700
|
+
};
|
|
1701
|
+
|
|
1702
|
+
return Schema;
|
|
1703
|
+
}();
|
|
1704
|
+
|
|
1705
|
+
Schema.register = function register(type, validator) {
|
|
1706
|
+
if (typeof validator !== 'function') {
|
|
1707
|
+
throw new Error('Cannot register a validator by type, validator is not a function');
|
|
1708
|
+
}
|
|
1709
|
+
|
|
1710
|
+
validators[type] = validator;
|
|
1711
|
+
};
|
|
1712
|
+
|
|
1713
|
+
Schema.warning = warning;
|
|
1714
|
+
Schema.messages = messages;
|
|
1715
|
+
Schema.validators = validators;
|
|
1716
|
+
|
|
1717
|
+
const formItemValidateStates = [
|
|
1718
|
+
"",
|
|
1719
|
+
"error",
|
|
1720
|
+
"validating",
|
|
1721
|
+
"success"
|
|
1722
|
+
];
|
|
1723
|
+
const formItemProps = buildProps({
|
|
1724
|
+
label: String,
|
|
1725
|
+
labelWidth: {
|
|
1726
|
+
type: [String, Number]
|
|
1727
|
+
},
|
|
1728
|
+
labelPosition: {
|
|
1729
|
+
type: String,
|
|
1730
|
+
values: ["left", "right", "top", ""],
|
|
1731
|
+
default: ""
|
|
1732
|
+
},
|
|
1733
|
+
prop: {
|
|
1734
|
+
type: definePropType([String, Array])
|
|
1735
|
+
},
|
|
1736
|
+
required: {
|
|
1737
|
+
type: Boolean,
|
|
1738
|
+
default: void 0
|
|
1739
|
+
},
|
|
1740
|
+
rules: {
|
|
1741
|
+
type: definePropType([Object, Array])
|
|
1742
|
+
},
|
|
1743
|
+
error: String,
|
|
1744
|
+
validateStatus: {
|
|
1745
|
+
type: String,
|
|
1746
|
+
values: formItemValidateStates
|
|
1747
|
+
},
|
|
1748
|
+
for: String,
|
|
1749
|
+
inlineMessage: {
|
|
1750
|
+
type: Boolean,
|
|
1751
|
+
default: void 0
|
|
1752
|
+
},
|
|
1753
|
+
showMessage: {
|
|
1754
|
+
type: Boolean,
|
|
1755
|
+
default: true
|
|
1756
|
+
},
|
|
1757
|
+
size: {
|
|
1758
|
+
type: String,
|
|
1759
|
+
values: componentSizes
|
|
1760
|
+
}
|
|
1761
|
+
});
|
|
1762
|
+
|
|
1763
|
+
const COMPONENT_NAME = "ElLabelWrap";
|
|
1764
|
+
var FormLabelWrap = defineComponent({
|
|
1765
|
+
name: COMPONENT_NAME,
|
|
1766
|
+
props: {
|
|
1767
|
+
isAutoWidth: Boolean,
|
|
1768
|
+
updateAll: Boolean
|
|
1769
|
+
},
|
|
1770
|
+
setup(props, {
|
|
1771
|
+
slots
|
|
1772
|
+
}) {
|
|
1773
|
+
const formContext = inject(formContextKey, void 0);
|
|
1774
|
+
const formItemContext = inject(formItemContextKey);
|
|
1775
|
+
if (!formItemContext)
|
|
1776
|
+
throwError(COMPONENT_NAME, "usage: <el-form-item><label-wrap /></el-form-item>");
|
|
1777
|
+
const ns = useNamespace("form");
|
|
1778
|
+
const el = ref();
|
|
1779
|
+
const computedWidth = ref(0);
|
|
1780
|
+
const getLabelWidth = () => {
|
|
1781
|
+
var _a;
|
|
1782
|
+
if ((_a = el.value) == null ? void 0 : _a.firstElementChild) {
|
|
1783
|
+
const width = window.getComputedStyle(el.value.firstElementChild).width;
|
|
1784
|
+
return Math.ceil(Number.parseFloat(width));
|
|
1785
|
+
} else {
|
|
1786
|
+
return 0;
|
|
1787
|
+
}
|
|
1788
|
+
};
|
|
1789
|
+
const updateLabelWidth = (action = "update") => {
|
|
1790
|
+
nextTick(() => {
|
|
1791
|
+
if (slots.default && props.isAutoWidth) {
|
|
1792
|
+
if (action === "update") {
|
|
1793
|
+
computedWidth.value = getLabelWidth();
|
|
1794
|
+
} else if (action === "remove") {
|
|
1795
|
+
formContext == null ? void 0 : formContext.deregisterLabelWidth(computedWidth.value);
|
|
1796
|
+
}
|
|
1797
|
+
}
|
|
1798
|
+
});
|
|
1799
|
+
};
|
|
1800
|
+
const updateLabelWidthFn = () => updateLabelWidth("update");
|
|
1801
|
+
onMounted(() => {
|
|
1802
|
+
updateLabelWidthFn();
|
|
1803
|
+
});
|
|
1804
|
+
onBeforeUnmount(() => {
|
|
1805
|
+
updateLabelWidth("remove");
|
|
1806
|
+
});
|
|
1807
|
+
onUpdated(() => updateLabelWidthFn());
|
|
1808
|
+
watch(computedWidth, (val, oldVal) => {
|
|
1809
|
+
if (props.updateAll) {
|
|
1810
|
+
formContext == null ? void 0 : formContext.registerLabelWidth(val, oldVal);
|
|
1811
|
+
}
|
|
1812
|
+
});
|
|
1813
|
+
useResizeObserver(computed(() => {
|
|
1814
|
+
var _a, _b;
|
|
1815
|
+
return (_b = (_a = el.value) == null ? void 0 : _a.firstElementChild) != null ? _b : null;
|
|
1816
|
+
}), updateLabelWidthFn);
|
|
1817
|
+
return () => {
|
|
1818
|
+
var _a, _b;
|
|
1819
|
+
if (!slots)
|
|
1820
|
+
return null;
|
|
1821
|
+
const {
|
|
1822
|
+
isAutoWidth
|
|
1823
|
+
} = props;
|
|
1824
|
+
if (isAutoWidth) {
|
|
1825
|
+
const autoLabelWidth = formContext == null ? void 0 : formContext.autoLabelWidth;
|
|
1826
|
+
const hasLabel = formItemContext == null ? void 0 : formItemContext.hasLabel;
|
|
1827
|
+
const style = {};
|
|
1828
|
+
if (hasLabel && autoLabelWidth && autoLabelWidth !== "auto") {
|
|
1829
|
+
const marginWidth = Math.max(0, Number.parseInt(autoLabelWidth, 10) - computedWidth.value);
|
|
1830
|
+
const labelPosition = formItemContext.labelPosition || formContext.labelPosition;
|
|
1831
|
+
const marginPosition = labelPosition === "left" ? "marginRight" : "marginLeft";
|
|
1832
|
+
if (marginWidth) {
|
|
1833
|
+
style[marginPosition] = `${marginWidth}px`;
|
|
1834
|
+
}
|
|
1835
|
+
}
|
|
1836
|
+
return createVNode("div", {
|
|
1837
|
+
"ref": el,
|
|
1838
|
+
"class": [ns.be("item", "label-wrap")],
|
|
1839
|
+
"style": style
|
|
1840
|
+
}, [(_a = slots.default) == null ? void 0 : _a.call(slots)]);
|
|
1841
|
+
} else {
|
|
1842
|
+
return createVNode(Fragment, {
|
|
1843
|
+
"ref": el
|
|
1844
|
+
}, [(_b = slots.default) == null ? void 0 : _b.call(slots)]);
|
|
1845
|
+
}
|
|
1846
|
+
};
|
|
1847
|
+
}
|
|
1848
|
+
});
|
|
1849
|
+
|
|
1850
|
+
const _hoisted_1 = ["role", "aria-labelledby"];
|
|
1851
|
+
const _sfc_main$1 = defineComponent({
|
|
1852
|
+
...{
|
|
1853
|
+
name: "ElFormItem"
|
|
1854
|
+
},
|
|
1855
|
+
__name: "form-item",
|
|
1856
|
+
props: formItemProps,
|
|
1857
|
+
setup(__props, { expose: __expose }) {
|
|
1858
|
+
const props = __props;
|
|
1859
|
+
const slots = useSlots();
|
|
1860
|
+
const formContext = inject(formContextKey, void 0);
|
|
1861
|
+
const parentFormItemContext = inject(formItemContextKey, void 0);
|
|
1862
|
+
const _size = useFormSize(void 0, { formItem: false });
|
|
1863
|
+
const ns = useNamespace("form-item");
|
|
1864
|
+
const labelId = useId().value;
|
|
1865
|
+
const inputIds = ref([]);
|
|
1866
|
+
const validateState = ref("");
|
|
1867
|
+
const validateStateDebounced = refDebounced(validateState, 100);
|
|
1868
|
+
const validateMessage = ref("");
|
|
1869
|
+
const formItemRef = ref();
|
|
1870
|
+
let initialValue = void 0;
|
|
1871
|
+
let isResettingField = false;
|
|
1872
|
+
const labelPosition = computed(
|
|
1873
|
+
() => props.labelPosition || (formContext == null ? void 0 : formContext.labelPosition)
|
|
1874
|
+
);
|
|
1875
|
+
const labelStyle = computed(() => {
|
|
1876
|
+
var _a;
|
|
1877
|
+
if (labelPosition.value === "top") {
|
|
1878
|
+
return {};
|
|
1879
|
+
}
|
|
1880
|
+
const labelWidth = addUnit((_a = props.labelWidth) != null ? _a : formContext == null ? void 0 : formContext.labelWidth);
|
|
1881
|
+
return { width: labelWidth };
|
|
1882
|
+
});
|
|
1883
|
+
const contentStyle = computed(() => {
|
|
1884
|
+
var _a;
|
|
1885
|
+
if (labelPosition.value === "top" || (formContext == null ? void 0 : formContext.inline)) {
|
|
1886
|
+
return {};
|
|
1887
|
+
}
|
|
1888
|
+
if (!props.label && !props.labelWidth && isNested) {
|
|
1889
|
+
return {};
|
|
1890
|
+
}
|
|
1891
|
+
const labelWidth = addUnit((_a = props.labelWidth) != null ? _a : formContext == null ? void 0 : formContext.labelWidth);
|
|
1892
|
+
if (!props.label && !slots.label) {
|
|
1893
|
+
return { marginLeft: labelWidth };
|
|
1894
|
+
}
|
|
1895
|
+
return {};
|
|
1896
|
+
});
|
|
1897
|
+
const formItemClasses = computed(() => [
|
|
1898
|
+
ns.b(),
|
|
1899
|
+
ns.m(_size.value),
|
|
1900
|
+
ns.is("error", validateState.value === "error"),
|
|
1901
|
+
ns.is("validating", validateState.value === "validating"),
|
|
1902
|
+
ns.is("success", validateState.value === "success"),
|
|
1903
|
+
ns.is("required", isRequired.value || props.required),
|
|
1904
|
+
ns.is("no-asterisk", formContext == null ? void 0 : formContext.hideRequiredAsterisk),
|
|
1905
|
+
(formContext == null ? void 0 : formContext.requireAsteriskPosition) === "right" ? "asterisk-right" : "asterisk-left",
|
|
1906
|
+
{
|
|
1907
|
+
[ns.m("feedback")]: formContext == null ? void 0 : formContext.statusIcon,
|
|
1908
|
+
[ns.m(`label-${labelPosition.value}`)]: labelPosition.value
|
|
1909
|
+
}
|
|
1910
|
+
]);
|
|
1911
|
+
const _inlineMessage = computed(
|
|
1912
|
+
() => isBoolean(props.inlineMessage) ? props.inlineMessage : (formContext == null ? void 0 : formContext.inlineMessage) || false
|
|
1913
|
+
);
|
|
1914
|
+
const validateClasses = computed(() => [
|
|
1915
|
+
ns.e("error"),
|
|
1916
|
+
{ [ns.em("error", "inline")]: _inlineMessage.value }
|
|
1917
|
+
]);
|
|
1918
|
+
const propString = computed(() => {
|
|
1919
|
+
if (!props.prop)
|
|
1920
|
+
return "";
|
|
1921
|
+
return isArray(props.prop) ? props.prop.join(".") : props.prop;
|
|
1922
|
+
});
|
|
1923
|
+
const hasLabel = computed(() => {
|
|
1924
|
+
return !!(props.label || slots.label);
|
|
1925
|
+
});
|
|
1926
|
+
const labelFor = computed(() => {
|
|
1927
|
+
var _a;
|
|
1928
|
+
return (_a = props.for) != null ? _a : inputIds.value.length === 1 ? inputIds.value[0] : void 0;
|
|
1929
|
+
});
|
|
1930
|
+
const isGroup = computed(() => {
|
|
1931
|
+
return !labelFor.value && hasLabel.value;
|
|
1932
|
+
});
|
|
1933
|
+
const isNested = !!parentFormItemContext;
|
|
1934
|
+
const fieldValue = computed(() => {
|
|
1935
|
+
const model = formContext == null ? void 0 : formContext.model;
|
|
1936
|
+
if (!model || !props.prop) {
|
|
1937
|
+
return;
|
|
1938
|
+
}
|
|
1939
|
+
return getProp(model, props.prop).value;
|
|
1940
|
+
});
|
|
1941
|
+
const normalizedRules = computed(() => {
|
|
1942
|
+
const { required } = props;
|
|
1943
|
+
const rules = [];
|
|
1944
|
+
if (props.rules) {
|
|
1945
|
+
rules.push(...castArray(props.rules));
|
|
1946
|
+
}
|
|
1947
|
+
const formRules = formContext == null ? void 0 : formContext.rules;
|
|
1948
|
+
if (formRules && props.prop) {
|
|
1949
|
+
const _rules = getProp(
|
|
1950
|
+
formRules,
|
|
1951
|
+
props.prop
|
|
1952
|
+
).value;
|
|
1953
|
+
if (_rules) {
|
|
1954
|
+
rules.push(...castArray(_rules));
|
|
1955
|
+
}
|
|
1956
|
+
}
|
|
1957
|
+
if (required !== void 0) {
|
|
1958
|
+
const requiredRules = rules.map((rule, i) => [rule, i]).filter(([rule]) => "required" in rule);
|
|
1959
|
+
if (requiredRules.length > 0) {
|
|
1960
|
+
for (const [rule, i] of requiredRules) {
|
|
1961
|
+
if (rule.required === required)
|
|
1962
|
+
continue;
|
|
1963
|
+
rules[i] = { ...rule, required };
|
|
1964
|
+
}
|
|
1965
|
+
} else {
|
|
1966
|
+
rules.push({ required });
|
|
1967
|
+
}
|
|
1968
|
+
}
|
|
1969
|
+
return rules;
|
|
1970
|
+
});
|
|
1971
|
+
const validateEnabled = computed(() => normalizedRules.value.length > 0);
|
|
1972
|
+
const getFilteredRule = (trigger) => {
|
|
1973
|
+
const rules = normalizedRules.value;
|
|
1974
|
+
return rules.filter((rule) => {
|
|
1975
|
+
if (!rule.trigger || !trigger)
|
|
1976
|
+
return true;
|
|
1977
|
+
if (isArray(rule.trigger)) {
|
|
1978
|
+
return rule.trigger.includes(trigger);
|
|
1979
|
+
} else {
|
|
1980
|
+
return rule.trigger === trigger;
|
|
1981
|
+
}
|
|
1982
|
+
}).map(({ trigger: trigger2, ...rule }) => rule);
|
|
1983
|
+
};
|
|
1984
|
+
const isRequired = computed(
|
|
1985
|
+
() => normalizedRules.value.some((rule) => rule.required)
|
|
1986
|
+
);
|
|
1987
|
+
const shouldShowError = computed(
|
|
1988
|
+
() => {
|
|
1989
|
+
var _a;
|
|
1990
|
+
return validateStateDebounced.value === "error" && props.showMessage && ((_a = formContext == null ? void 0 : formContext.showMessage) != null ? _a : true);
|
|
1991
|
+
}
|
|
1992
|
+
);
|
|
1993
|
+
const currentLabel = computed(
|
|
1994
|
+
() => `${props.label || ""}${(formContext == null ? void 0 : formContext.labelSuffix) || ""}`
|
|
1995
|
+
);
|
|
1996
|
+
const setValidationState = (state) => {
|
|
1997
|
+
validateState.value = state;
|
|
1998
|
+
};
|
|
1999
|
+
const onValidationFailed = (error) => {
|
|
2000
|
+
var _a, _b;
|
|
2001
|
+
const { errors, fields } = error;
|
|
2002
|
+
if (!errors || !fields) {
|
|
2003
|
+
console.error(error);
|
|
2004
|
+
}
|
|
2005
|
+
setValidationState("error");
|
|
2006
|
+
validateMessage.value = errors ? (_b = (_a = errors == null ? void 0 : errors[0]) == null ? void 0 : _a.message) != null ? _b : `${props.prop} is required` : "";
|
|
2007
|
+
formContext == null ? void 0 : formContext.emit("validate", props.prop, false, validateMessage.value);
|
|
2008
|
+
};
|
|
2009
|
+
const onValidationSucceeded = () => {
|
|
2010
|
+
setValidationState("success");
|
|
2011
|
+
formContext == null ? void 0 : formContext.emit("validate", props.prop, true, "");
|
|
2012
|
+
};
|
|
2013
|
+
const doValidate = async (rules) => {
|
|
2014
|
+
const modelName = propString.value;
|
|
2015
|
+
const validator = new Schema({
|
|
2016
|
+
[modelName]: rules
|
|
2017
|
+
});
|
|
2018
|
+
return validator.validate({ [modelName]: fieldValue.value }, { firstFields: true }).then(() => {
|
|
2019
|
+
onValidationSucceeded();
|
|
2020
|
+
return true;
|
|
2021
|
+
}).catch((err) => {
|
|
2022
|
+
onValidationFailed(err);
|
|
2023
|
+
return Promise.reject(err);
|
|
2024
|
+
});
|
|
2025
|
+
};
|
|
2026
|
+
const validate = async (trigger, callback) => {
|
|
2027
|
+
if (isResettingField || !props.prop) {
|
|
2028
|
+
return false;
|
|
2029
|
+
}
|
|
2030
|
+
const hasCallback = isFunction(callback);
|
|
2031
|
+
if (!validateEnabled.value) {
|
|
2032
|
+
callback == null ? void 0 : callback(false);
|
|
2033
|
+
return false;
|
|
2034
|
+
}
|
|
2035
|
+
const rules = getFilteredRule(trigger);
|
|
2036
|
+
if (rules.length === 0) {
|
|
2037
|
+
callback == null ? void 0 : callback(true);
|
|
2038
|
+
return true;
|
|
2039
|
+
}
|
|
2040
|
+
setValidationState("validating");
|
|
2041
|
+
return doValidate(rules).then(() => {
|
|
2042
|
+
callback == null ? void 0 : callback(true);
|
|
2043
|
+
return true;
|
|
2044
|
+
}).catch((err) => {
|
|
2045
|
+
const { fields } = err;
|
|
2046
|
+
callback == null ? void 0 : callback(false, fields);
|
|
2047
|
+
return hasCallback ? false : Promise.reject(fields);
|
|
2048
|
+
});
|
|
2049
|
+
};
|
|
2050
|
+
const clearValidate = () => {
|
|
2051
|
+
setValidationState("");
|
|
2052
|
+
validateMessage.value = "";
|
|
2053
|
+
isResettingField = false;
|
|
2054
|
+
};
|
|
2055
|
+
const resetField = async () => {
|
|
2056
|
+
const model = formContext == null ? void 0 : formContext.model;
|
|
2057
|
+
if (!model || !props.prop)
|
|
2058
|
+
return;
|
|
2059
|
+
const computedValue = getProp(model, props.prop);
|
|
2060
|
+
isResettingField = true;
|
|
2061
|
+
computedValue.value = clone(initialValue);
|
|
2062
|
+
await nextTick();
|
|
2063
|
+
clearValidate();
|
|
2064
|
+
isResettingField = false;
|
|
2065
|
+
};
|
|
2066
|
+
const addInputId = (id) => {
|
|
2067
|
+
if (!inputIds.value.includes(id)) {
|
|
2068
|
+
inputIds.value.push(id);
|
|
2069
|
+
}
|
|
2070
|
+
};
|
|
2071
|
+
const removeInputId = (id) => {
|
|
2072
|
+
inputIds.value = inputIds.value.filter((listId) => listId !== id);
|
|
2073
|
+
};
|
|
2074
|
+
const setInitialValue = (value) => {
|
|
2075
|
+
initialValue = clone(value);
|
|
2076
|
+
};
|
|
2077
|
+
watch(
|
|
2078
|
+
() => props.error,
|
|
2079
|
+
(val) => {
|
|
2080
|
+
validateMessage.value = val || "";
|
|
2081
|
+
setValidationState(val ? "error" : "");
|
|
2082
|
+
},
|
|
2083
|
+
{ immediate: true }
|
|
2084
|
+
);
|
|
2085
|
+
watch(
|
|
2086
|
+
() => props.validateStatus,
|
|
2087
|
+
(val) => setValidationState(val || "")
|
|
2088
|
+
);
|
|
2089
|
+
const context = reactive({
|
|
2090
|
+
...toRefs(props),
|
|
2091
|
+
$el: formItemRef,
|
|
2092
|
+
size: _size,
|
|
2093
|
+
validateMessage,
|
|
2094
|
+
validateState,
|
|
2095
|
+
labelId,
|
|
2096
|
+
inputIds,
|
|
2097
|
+
isGroup,
|
|
2098
|
+
hasLabel,
|
|
2099
|
+
fieldValue,
|
|
2100
|
+
addInputId,
|
|
2101
|
+
removeInputId,
|
|
2102
|
+
resetField,
|
|
2103
|
+
clearValidate,
|
|
2104
|
+
validate,
|
|
2105
|
+
propString,
|
|
2106
|
+
setInitialValue
|
|
2107
|
+
});
|
|
2108
|
+
provide(formItemContextKey, context);
|
|
2109
|
+
onMounted(() => {
|
|
2110
|
+
if (props.prop) {
|
|
2111
|
+
formContext == null ? void 0 : formContext.addField(context);
|
|
2112
|
+
initialValue = clone(fieldValue.value);
|
|
2113
|
+
}
|
|
2114
|
+
});
|
|
2115
|
+
onBeforeUnmount(() => {
|
|
2116
|
+
formContext == null ? void 0 : formContext.removeField(context);
|
|
2117
|
+
});
|
|
2118
|
+
__expose({
|
|
2119
|
+
size: _size,
|
|
2120
|
+
validateMessage,
|
|
2121
|
+
validateState,
|
|
2122
|
+
validate,
|
|
2123
|
+
clearValidate,
|
|
2124
|
+
resetField,
|
|
2125
|
+
setInitialValue
|
|
2126
|
+
});
|
|
2127
|
+
return (_ctx, _cache) => {
|
|
2128
|
+
var _a;
|
|
2129
|
+
return openBlock(), createElementBlock("div", {
|
|
2130
|
+
ref_key: "formItemRef",
|
|
2131
|
+
ref: formItemRef,
|
|
2132
|
+
class: normalizeClass(formItemClasses.value),
|
|
2133
|
+
role: isGroup.value ? "group" : void 0,
|
|
2134
|
+
"aria-labelledby": isGroup.value ? unref(labelId) : void 0
|
|
2135
|
+
}, [
|
|
2136
|
+
createVNode(unref(FormLabelWrap), {
|
|
2137
|
+
"is-auto-width": labelStyle.value.width === "auto",
|
|
2138
|
+
"update-all": ((_a = unref(formContext)) == null ? void 0 : _a.labelWidth) === "auto"
|
|
2139
|
+
}, {
|
|
2140
|
+
default: withCtx(() => [
|
|
2141
|
+
!!(_ctx.label || _ctx.$slots.label) ? (openBlock(), createBlock(resolveDynamicComponent(labelFor.value ? "label" : "div"), {
|
|
2142
|
+
key: 0,
|
|
2143
|
+
id: unref(labelId),
|
|
2144
|
+
for: labelFor.value,
|
|
2145
|
+
class: normalizeClass(unref(ns).e("label")),
|
|
2146
|
+
style: normalizeStyle(labelStyle.value)
|
|
2147
|
+
}, {
|
|
2148
|
+
default: withCtx(() => [
|
|
2149
|
+
renderSlot(_ctx.$slots, "label", { label: currentLabel.value }, () => [
|
|
2150
|
+
createTextVNode(
|
|
2151
|
+
toDisplayString(currentLabel.value),
|
|
2152
|
+
1
|
|
2153
|
+
)
|
|
2154
|
+
])
|
|
2155
|
+
]),
|
|
2156
|
+
_: 3
|
|
2157
|
+
}, 8, ["id", "for", "class", "style"])) : createCommentVNode("v-if", true)
|
|
2158
|
+
]),
|
|
2159
|
+
_: 3
|
|
2160
|
+
}, 8, ["is-auto-width", "update-all"]),
|
|
2161
|
+
createElementVNode(
|
|
2162
|
+
"div",
|
|
2163
|
+
{
|
|
2164
|
+
class: normalizeClass(unref(ns).e("content")),
|
|
2165
|
+
style: normalizeStyle(contentStyle.value)
|
|
2166
|
+
},
|
|
2167
|
+
[
|
|
2168
|
+
renderSlot(_ctx.$slots, "default"),
|
|
2169
|
+
createVNode(TransitionGroup, {
|
|
2170
|
+
name: `${unref(ns).namespace.value}-zoom-in-top`
|
|
2171
|
+
}, {
|
|
2172
|
+
default: withCtx(() => [
|
|
2173
|
+
shouldShowError.value ? renderSlot(_ctx.$slots, "error", {
|
|
2174
|
+
key: 0,
|
|
2175
|
+
error: validateMessage.value
|
|
2176
|
+
}, () => [
|
|
2177
|
+
createElementVNode(
|
|
2178
|
+
"div",
|
|
2179
|
+
{
|
|
2180
|
+
class: normalizeClass(validateClasses.value)
|
|
2181
|
+
},
|
|
2182
|
+
toDisplayString(validateMessage.value),
|
|
2183
|
+
3
|
|
2184
|
+
)
|
|
2185
|
+
]) : createCommentVNode("v-if", true)
|
|
2186
|
+
]),
|
|
2187
|
+
_: 3
|
|
2188
|
+
}, 8, ["name"])
|
|
2189
|
+
],
|
|
2190
|
+
6
|
|
2191
|
+
)
|
|
2192
|
+
], 10, _hoisted_1);
|
|
2193
|
+
};
|
|
2194
|
+
}
|
|
2195
|
+
});
|
|
2196
|
+
var FormItem = /* @__PURE__ */ _export_sfc(_sfc_main$1, [["__file", "/home/runner/work/element-plus/element-plus/packages/components/form/src/form-item.vue"]]);
|
|
2197
|
+
|
|
2198
|
+
const ElForm = withInstall(Form, {
|
|
2199
|
+
FormItem
|
|
2200
|
+
});
|
|
2201
|
+
withNoopInstall(FormItem);
|
|
2202
|
+
|
|
2203
|
+
function calculateLayout(containerEl, actionsEl, formContainerEl) {
|
|
2204
|
+
const rowGap = 8;
|
|
2205
|
+
const colGap = 16;
|
|
2206
|
+
const rowWidth = Math.floor(containerEl.getBoundingClientRect().width);
|
|
2207
|
+
const actionsWidth = Math.ceil(actionsEl.getBoundingClientRect().width);
|
|
2208
|
+
const baseHeight = actionsEl.offsetHeight;
|
|
2209
|
+
const firstRowWidth = rowWidth - actionsWidth - colGap;
|
|
2210
|
+
const formEl = formContainerEl.querySelector(".el-form");
|
|
2211
|
+
const formItems = formContainerEl.querySelectorAll(".el-form-item");
|
|
2212
|
+
formContainerEl.style.position = "relative";
|
|
2213
|
+
formContainerEl.style.width = `${rowWidth}px`;
|
|
2214
|
+
containerEl.style.position = "relative";
|
|
2215
|
+
actionsEl.style.position = "absolute";
|
|
2216
|
+
actionsEl.style.right = "0";
|
|
2217
|
+
actionsEl.style.top = "0";
|
|
2218
|
+
let currentX = 0;
|
|
2219
|
+
let currentY = 0;
|
|
2220
|
+
let rowIndex = 1;
|
|
2221
|
+
formItems.forEach((item) => {
|
|
2222
|
+
const itemWidth = Math.ceil(item.getBoundingClientRect().width);
|
|
2223
|
+
const safeWidth = rowIndex === 1 ? firstRowWidth : rowWidth;
|
|
2224
|
+
if (currentX + itemWidth >= safeWidth) {
|
|
2225
|
+
rowIndex++;
|
|
2226
|
+
currentX = 0;
|
|
2227
|
+
currentY += baseHeight + rowGap;
|
|
2228
|
+
}
|
|
2229
|
+
item.style.position = "absolute";
|
|
2230
|
+
item.style.left = `${currentX}px`;
|
|
2231
|
+
item.style.top = `${currentY}px`;
|
|
2232
|
+
currentX += itemWidth + colGap;
|
|
2233
|
+
});
|
|
2234
|
+
formEl.style.height = `${currentY + baseHeight}px`;
|
|
2235
|
+
}
|
|
2236
|
+
|
|
2237
|
+
const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
2238
|
+
__name: "explorer-query",
|
|
2239
|
+
props: {
|
|
2240
|
+
paddingBottom: { default: 8 },
|
|
2241
|
+
height: { default: 32 },
|
|
2242
|
+
model: {},
|
|
2243
|
+
autoSpace: { type: Boolean, default: true },
|
|
2244
|
+
queryKey: {}
|
|
2245
|
+
},
|
|
2246
|
+
emits: ["search"],
|
|
2247
|
+
setup(__props, { emit: __emit }) {
|
|
2248
|
+
useCssVars((_ctx) => ({
|
|
2249
|
+
"v7132dbec": `${_ctx.paddingBottom}px`,
|
|
2250
|
+
"v264493e2": `${_ctx.height}px`
|
|
2251
|
+
}));
|
|
2252
|
+
const props = __props;
|
|
2253
|
+
const emits = __emit;
|
|
2254
|
+
const queryRef = useTemplateRef("queryRef");
|
|
2255
|
+
const formContainerRef = useTemplateRef("formContainerRef");
|
|
2256
|
+
const formRef = useTemplateRef("formRef");
|
|
2257
|
+
const formElRef = computed(() => formRef.value?.$el);
|
|
2258
|
+
const actionsRef = useTemplateRef("actionsRef");
|
|
2259
|
+
const { key } = injectExplorerState();
|
|
2260
|
+
const expandStorageKey = props.queryKey ? `${key}-${props.queryKey}-expand` : `${key}-expand`;
|
|
2261
|
+
const defaultExpand = useStorage(expandStorageKey, false);
|
|
2262
|
+
const [isExpanded, toggle] = useToggle(defaultExpand.value);
|
|
2263
|
+
const expandText = computed(() => isExpanded.value ? "收起搜索" : "展开搜索");
|
|
2264
|
+
const expnadWatch = watch(isExpanded, (val) => {
|
|
2265
|
+
defaultExpand.value = val;
|
|
2266
|
+
});
|
|
2267
|
+
const { height: formHeight } = useElementSize(formElRef);
|
|
2268
|
+
const hasMore = computed(() => formHeight.value > props.height + 8);
|
|
2269
|
+
function handleReset() {
|
|
2270
|
+
formRef.value?.resetFields();
|
|
2271
|
+
emits("search", props.model);
|
|
2272
|
+
}
|
|
2273
|
+
function handleSearch() {
|
|
2274
|
+
emits("search", props.model);
|
|
2275
|
+
}
|
|
2276
|
+
function refreshLayout() {
|
|
2277
|
+
if (!props.autoSpace) {
|
|
2278
|
+
return;
|
|
2279
|
+
}
|
|
2280
|
+
calculateLayout(queryRef.value, actionsRef.value, formContainerRef.value);
|
|
2281
|
+
}
|
|
2282
|
+
useResizeObserver(queryRef, () => refreshLayout());
|
|
2283
|
+
onMounted(async () => {
|
|
2284
|
+
await promiseTimeout(0);
|
|
2285
|
+
refreshLayout();
|
|
2286
|
+
});
|
|
2287
|
+
onBeforeUnmount(() => expnadWatch.stop());
|
|
2288
|
+
return (_ctx, _cache) => {
|
|
2289
|
+
const _component_ElForm = ElForm;
|
|
2290
|
+
return openBlock(), createElementBlock("div", {
|
|
2291
|
+
ref_key: "queryRef",
|
|
2292
|
+
ref: queryRef,
|
|
2293
|
+
class: normalizeClass(_ctx.$style["explorer-query"])
|
|
2294
|
+
}, [
|
|
2295
|
+
createElementVNode("div", {
|
|
2296
|
+
ref_key: "formContainerRef",
|
|
2297
|
+
ref: formContainerRef,
|
|
2298
|
+
class: normalizeClass([_ctx.$style["form-container"], { [_ctx.$style.expand]: unref(isExpanded) }])
|
|
2299
|
+
}, [
|
|
2300
|
+
createVNode(_component_ElForm, {
|
|
2301
|
+
ref_key: "formRef",
|
|
2302
|
+
ref: formRef,
|
|
2303
|
+
inline: true,
|
|
2304
|
+
model: __props.model,
|
|
2305
|
+
class: normalizeClass(_ctx.$style.form)
|
|
2306
|
+
}, {
|
|
2307
|
+
default: withCtx(() => [
|
|
2308
|
+
renderSlot(_ctx.$slots, "default")
|
|
2309
|
+
]),
|
|
2310
|
+
_: 3
|
|
2311
|
+
}, 8, ["model", "class"])
|
|
2312
|
+
], 2),
|
|
2313
|
+
createElementVNode("div", {
|
|
2314
|
+
ref_key: "actionsRef",
|
|
2315
|
+
ref: actionsRef,
|
|
2316
|
+
class: normalizeClass(_ctx.$style.actions)
|
|
2317
|
+
}, [
|
|
2318
|
+
unref(hasMore) ? (openBlock(), createBlock(Component$1, {
|
|
2319
|
+
key: 0,
|
|
2320
|
+
link: "",
|
|
2321
|
+
type: "primary",
|
|
2322
|
+
icon: { name: "ArrowDown", position: "right" },
|
|
2323
|
+
class: normalizeClass([{ [_ctx.$style.expand]: unref(isExpanded) }, _ctx.$style.more]),
|
|
2324
|
+
throttle: 0,
|
|
2325
|
+
onClick: _cache[0] || (_cache[0] = () => unref(toggle)())
|
|
2326
|
+
}, {
|
|
2327
|
+
default: withCtx(() => [
|
|
2328
|
+
createTextVNode(toDisplayString(unref(expandText)), 1)
|
|
2329
|
+
]),
|
|
2330
|
+
_: 1
|
|
2331
|
+
}, 8, ["class"])) : createCommentVNode("", true),
|
|
2332
|
+
createVNode(Component$1, { onClick: handleReset }, {
|
|
2333
|
+
default: withCtx(() => [..._cache[1] || (_cache[1] = [
|
|
2334
|
+
createTextVNode("重置", -1)
|
|
2335
|
+
])]),
|
|
2336
|
+
_: 1
|
|
2337
|
+
}),
|
|
2338
|
+
createVNode(Component$1, {
|
|
2339
|
+
type: "primary",
|
|
2340
|
+
onClick: handleSearch
|
|
2341
|
+
}, {
|
|
2342
|
+
default: withCtx(() => [..._cache[2] || (_cache[2] = [
|
|
2343
|
+
createTextVNode("搜索", -1)
|
|
2344
|
+
])]),
|
|
2345
|
+
_: 1
|
|
2346
|
+
})
|
|
2347
|
+
], 2)
|
|
2348
|
+
], 2);
|
|
2349
|
+
};
|
|
2350
|
+
}
|
|
2351
|
+
});
|
|
2352
|
+
|
|
2353
|
+
/* unplugin-vue-components disabled */const expand = "_expand_1k7s1_14";
|
|
2354
|
+
const form = "_form_1k7s1_10";
|
|
2355
|
+
const more = "_more_1k7s1_29";
|
|
2356
|
+
const actions = "_actions_1k7s1_36";
|
|
2357
|
+
const style0 = {
|
|
2358
|
+
"explorer-query": "_explorer-query_1k7s1_1",
|
|
2359
|
+
"form-container": "_form-container_1k7s1_10",
|
|
2360
|
+
expand: expand,
|
|
2361
|
+
form: form,
|
|
2362
|
+
more: more,
|
|
2363
|
+
actions: actions
|
|
2364
|
+
};
|
|
2365
|
+
|
|
2366
|
+
const cssModules = {
|
|
2367
|
+
"$style": style0
|
|
2368
|
+
};
|
|
2369
|
+
const Component = /* @__PURE__ */ _export_sfc$1(_sfc_main, [["__cssModules", cssModules]]);
|
|
2370
|
+
|
|
2371
|
+
const __vite_glob_0_25 = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.defineProperty({
|
|
2372
|
+
__proto__: null,
|
|
2373
|
+
default: Component
|
|
2374
|
+
}, Symbol.toStringTag, { value: 'Module' }));
|
|
2375
|
+
|
|
2376
|
+
export { Component as C, __vite_glob_0_25 as _ };
|