UNPKG

tdesign-mobile-vue

Version:
1,041 lines (992 loc) 40.6 kB
/** * tdesign v1.7.0 * (c) 2024 TDesign Group * @license MIT */ import { _ as _toConsumableArray } from '../_chunks/dep-f0f403be.mjs'; import { _ as _asyncToGenerator, r as regenerator } from '../_chunks/dep-80e4de18.mjs'; import { _ as _defineProperty } from '../_chunks/dep-219bb5a7.mjs'; import { defineComponent, toRefs, inject, computed, ref, nextTick, reactive, onMounted, onBeforeUnmount, watch, provide, createVNode } from 'vue'; import { i as isArray_1 } from '../_chunks/dep-019e292f.mjs'; import { i as isNumber_1 } from '../_chunks/dep-52fdc8e1.mjs'; import { i as isString_1 } from '../_chunks/dep-6303c50c.mjs'; import { i as isBoolean_1 } from '../_chunks/dep-ea9a17dc.mjs'; import { c as cloneDeep_1 } from '../_chunks/dep-b9b8ead5.mjs'; import { g as get_1 } from '../_chunks/dep-4f59c35d.mjs'; import { s as set_1 } from '../_chunks/dep-45fbc10d.mjs'; import { i as isNil_1 } from '../_chunks/dep-864c806a.mjs'; import '../_chunks/dep-8bf3054e.mjs'; import { _ as _copyObject, k as keysIn_1, i as isPlainObject_1 } from '../_chunks/dep-d2161895.mjs'; import { _ as _createAssigner } from '../_chunks/dep-ac139980.mjs'; import { _ as _apply } from '../_chunks/dep-ba131d9c.mjs'; import { _ as _baseRest } from '../_chunks/dep-154c1925.mjs'; import { _ as _baseGetTag } from '../_chunks/dep-3d249f65.mjs'; import { i as isObjectLike_1 } from '../_chunks/dep-9b2de386.mjs'; import { _ as _arrayMap } from '../_chunks/dep-0d52e58f.mjs'; import { e as eq_1 } from '../_chunks/dep-4931819d.mjs'; import { _ as _isIterateeCall } from '../_chunks/dep-007f294e.mjs'; import { k as keys_1 } from '../_chunks/dep-6c53a3e4.mjs'; import { _ as _basePropertyOf } from '../_chunks/dep-b437ef0b.mjs'; import { t as toString_1 } from '../_chunks/dep-8140c29b.mjs'; import { ChevronRightIcon } from 'tdesign-icons-vue-next'; import { validate } from './form-model.mjs'; import props from './form-item-props.mjs'; import { FormInjectionKey, ValidateStatus, FormItemInjectionKey } from './const.mjs'; import config from '../config.mjs'; import { useTNodeJSX } from '../hooks/tnode.mjs'; import { usePrefixClass } from '../hooks/useClass.mjs'; import '../_chunks/dep-8d37dbf8.mjs'; import '../_chunks/dep-620d73f7.mjs'; import '../_chunks/dep-32364550.mjs'; import '../_chunks/dep-91d696ea.mjs'; import '../_chunks/dep-e6c129ab.mjs'; import '../config-provider/type.mjs'; import '../_chunks/dep-c51d4905.mjs'; import '../_chunks/dep-a836a38c.mjs'; import '../_chunks/dep-89951f45.mjs'; import '../_chunks/dep-08bc7a4c.mjs'; import '../_chunks/dep-6bc862af.mjs'; import '../_chunks/dep-df48d24d.mjs'; import '../_chunks/dep-10f4d030.mjs'; import '../_chunks/dep-8ee6f5cd.mjs'; import '../_chunks/dep-933f3a85.mjs'; import '../_chunks/dep-e57d46f3.mjs'; import '../_chunks/dep-4f44985d.mjs'; import '../_chunks/dep-b84be35c.mjs'; import '../_common/js/global-config/mobile/default-config.mjs'; import '../_common/js/global-config/mobile/locale/zh_CN.mjs'; import '../_chunks/dep-161f0c44.mjs'; import '../_chunks/dep-5fd0eaa4.mjs'; import '../_chunks/dep-3c59bf72.mjs'; import '../_chunks/dep-2bce42ea.mjs'; import '../_chunks/dep-40507aac.mjs'; import '../_chunks/dep-60cadef8.mjs'; import '../_chunks/dep-0ea7bbde.mjs'; import '../_chunks/dep-6917b9bc.mjs'; import '../hooks/render-tnode.mjs'; var copyObject = _copyObject, createAssigner = _createAssigner, keysIn = keysIn_1; /** * This method is like `_.assignIn` except that it accepts `customizer` * which is invoked to produce the assigned values. If `customizer` returns * `undefined`, assignment is handled by the method instead. The `customizer` * is invoked with five arguments: (objValue, srcValue, key, object, source). * * **Note:** This method mutates `object`. * * @static * @memberOf _ * @since 4.0.0 * @alias extendWith * @category Object * @param {Object} object The destination object. * @param {...Object} sources The source objects. * @param {Function} [customizer] The function to customize assigned values. * @returns {Object} Returns `object`. * @see _.assignWith * @example * * function customizer(objValue, srcValue) { * return _.isUndefined(objValue) ? srcValue : objValue; * } * * var defaults = _.partialRight(_.assignInWith, customizer); * * defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 }); * // => { 'a': 1, 'b': 2 } */ var assignInWith$1 = createAssigner(function (object, source, srcIndex, customizer) { copyObject(source, keysIn(source), object, customizer); }); var assignInWith_1 = assignInWith$1; var baseGetTag = _baseGetTag, isObjectLike = isObjectLike_1, isPlainObject = isPlainObject_1; /** `Object#toString` result references. */ var domExcTag = '[object DOMException]', errorTag = '[object Error]'; /** * Checks if `value` is an `Error`, `EvalError`, `RangeError`, `ReferenceError`, * `SyntaxError`, `TypeError`, or `URIError` object. * * @static * @memberOf _ * @since 3.0.0 * @category Lang * @param {*} value The value to check. * @returns {boolean} Returns `true` if `value` is an error object, else `false`. * @example * * _.isError(new Error); * // => true * * _.isError(Error); * // => false */ function isError$2(value) { if (!isObjectLike(value)) { return false; } var tag = baseGetTag(value); return tag == errorTag || tag == domExcTag || typeof value.message == 'string' && typeof value.name == 'string' && !isPlainObject(value); } var isError_1 = isError$2; var apply = _apply, baseRest = _baseRest, isError$1 = isError_1; /** * Attempts to invoke `func`, returning either the result or the caught error * object. Any additional arguments are provided to `func` when it's invoked. * * @static * @memberOf _ * @since 3.0.0 * @category Util * @param {Function} func The function to attempt. * @param {...*} [args] The arguments to invoke `func` with. * @returns {*} Returns the `func` result or error object. * @example * * // Avoid throwing errors for invalid selectors. * var elements = _.attempt(function(selector) { * return document.querySelectorAll(selector); * }, '>_>'); * * if (_.isError(elements)) { * elements = []; * } */ var attempt$1 = baseRest(function (func, args) { try { return apply(func, undefined, args); } catch (e) { return isError$1(e) ? e : new Error(e); } }); var attempt_1 = attempt$1; var arrayMap = _arrayMap; /** * The base implementation of `_.values` and `_.valuesIn` which creates an * array of `object` property values corresponding to the property names * of `props`. * * @private * @param {Object} object The object to query. * @param {Array} props The property names to get values for. * @returns {Object} Returns the array of property values. */ function baseValues$1(object, props) { return arrayMap(props, function (key) { return object[key]; }); } var _baseValues = baseValues$1; var eq = eq_1; /** Used for built-in method references. */ var objectProto$1 = Object.prototype; /** Used to check objects for own properties. */ var hasOwnProperty$1 = objectProto$1.hasOwnProperty; /** * Used by `_.defaults` to customize its `_.assignIn` use to assign properties * of source objects to the destination object for all destination properties * that resolve to `undefined`. * * @private * @param {*} objValue The destination value. * @param {*} srcValue The source value. * @param {string} key The key of the property to assign. * @param {Object} object The parent object of `objValue`. * @returns {*} Returns the value to assign. */ function customDefaultsAssignIn$1(objValue, srcValue, key, object) { if (objValue === undefined || eq(objValue, objectProto$1[key]) && !hasOwnProperty$1.call(object, key)) { return srcValue; } return objValue; } var _customDefaultsAssignIn = customDefaultsAssignIn$1; /** Used to escape characters for inclusion in compiled string literals. */ var stringEscapes = { '\\': '\\', "'": "'", '\n': 'n', '\r': 'r', "\u2028": 'u2028', "\u2029": 'u2029' }; /** * Used by `_.template` to escape characters for inclusion in compiled string literals. * * @private * @param {string} chr The matched character to escape. * @returns {string} Returns the escaped character. */ function escapeStringChar$1(chr) { return '\\' + stringEscapes[chr]; } var _escapeStringChar = escapeStringChar$1; /** Used to match template delimiters. */ var reInterpolate$2 = /<%=([\s\S]+?)%>/g; var _reInterpolate = reInterpolate$2; var basePropertyOf = _basePropertyOf; /** Used to map characters to HTML entities. */ var htmlEscapes = { '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' }; /** * Used by `_.escape` to convert characters to HTML entities. * * @private * @param {string} chr The matched character to escape. * @returns {string} Returns the escaped character. */ var escapeHtmlChar$1 = basePropertyOf(htmlEscapes); var _escapeHtmlChar = escapeHtmlChar$1; var escapeHtmlChar = _escapeHtmlChar, toString$1 = toString_1; /** Used to match HTML entities and HTML characters. */ var reUnescapedHtml = /[&<>"']/g, reHasUnescapedHtml = RegExp(reUnescapedHtml.source); /** * Converts the characters "&", "<", ">", '"', and "'" in `string` to their * corresponding HTML entities. * * **Note:** No other characters are escaped. To escape additional * characters use a third-party library like [_he_](https://mths.be/he). * * Though the ">" character is escaped for symmetry, characters like * ">" and "/" don't need escaping in HTML and have no special meaning * unless they're part of a tag or unquoted attribute value. See * [Mathias Bynens's article](https://mathiasbynens.be/notes/ambiguous-ampersands) * (under "semi-related fun fact") for more details. * * When working with HTML you should always * [quote attribute values](http://wonko.com/post/html-escaping) to reduce * XSS vectors. * * @static * @since 0.1.0 * @memberOf _ * @category String * @param {string} [string=''] The string to escape. * @returns {string} Returns the escaped string. * @example * * _.escape('fred, barney, & pebbles'); * // => 'fred, barney, &amp; pebbles' */ function escape$1(string) { string = toString$1(string); return string && reHasUnescapedHtml.test(string) ? string.replace(reUnescapedHtml, escapeHtmlChar) : string; } var _escape = escape$1; /** Used to match template delimiters. */ var reEscape$1 = /<%-([\s\S]+?)%>/g; var _reEscape = reEscape$1; /** Used to match template delimiters. */ var reEvaluate$1 = /<%([\s\S]+?)%>/g; var _reEvaluate = reEvaluate$1; var escape = _escape, reEscape = _reEscape, reEvaluate = _reEvaluate, reInterpolate$1 = _reInterpolate; /** * By default, the template delimiters used by lodash are like those in * embedded Ruby (ERB) as well as ES2015 template strings. Change the * following template settings to use alternative delimiters. * * @static * @memberOf _ * @type {Object} */ var templateSettings$1 = { /** * Used to detect `data` property values to be HTML-escaped. * * @memberOf _.templateSettings * @type {RegExp} */ 'escape': reEscape, /** * Used to detect code to be evaluated. * * @memberOf _.templateSettings * @type {RegExp} */ 'evaluate': reEvaluate, /** * Used to detect `data` property values to inject. * * @memberOf _.templateSettings * @type {RegExp} */ 'interpolate': reInterpolate$1, /** * Used to reference the data object in the template text. * * @memberOf _.templateSettings * @type {string} */ 'variable': '', /** * Used to import variables into the compiled template. * * @memberOf _.templateSettings * @type {Object} */ 'imports': { /** * A reference to the `lodash` function. * * @memberOf _.templateSettings.imports * @type {Function} */ '_': { 'escape': escape } } }; var templateSettings_1 = templateSettings$1; var assignInWith = assignInWith_1, attempt = attempt_1, baseValues = _baseValues, customDefaultsAssignIn = _customDefaultsAssignIn, escapeStringChar = _escapeStringChar, isError = isError_1, isIterateeCall = _isIterateeCall, keys = keys_1, reInterpolate = _reInterpolate, templateSettings = templateSettings_1, toString = toString_1; /** Error message constants. */ var INVALID_TEMPL_VAR_ERROR_TEXT = 'Invalid `variable` option passed into `_.template`'; /** Used to match empty string literals in compiled template source. */ var reEmptyStringLeading = /\b__p \+= '';/g, reEmptyStringMiddle = /\b(__p \+=) '' \+/g, reEmptyStringTrailing = /(__e\(.*?\)|\b__t\)) \+\n'';/g; /** * Used to validate the `validate` option in `_.template` variable. * * Forbids characters which could potentially change the meaning of the function argument definition: * - "()," (modification of function parameters) * - "=" (default value) * - "[]{}" (destructuring of function parameters) * - "/" (beginning of a comment) * - whitespace */ var reForbiddenIdentifierChars = /[()=,{}\[\]\/\s]/; /** * Used to match * [ES template delimiters](http://ecma-international.org/ecma-262/7.0/#sec-template-literal-lexical-components). */ var reEsTemplate = /\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g; /** Used to ensure capturing order of template delimiters. */ var reNoMatch = /($^)/; /** Used to match unescaped characters in compiled string literals. */ var reUnescapedString = /['\n\r\u2028\u2029\\]/g; /** Used for built-in method references. */ var objectProto = Object.prototype; /** Used to check objects for own properties. */ var hasOwnProperty = objectProto.hasOwnProperty; /** * Creates a compiled template function that can interpolate data properties * in "interpolate" delimiters, HTML-escape interpolated data properties in * "escape" delimiters, and execute JavaScript in "evaluate" delimiters. Data * properties may be accessed as free variables in the template. If a setting * object is given, it takes precedence over `_.templateSettings` values. * * **Note:** In the development build `_.template` utilizes * [sourceURLs](http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/#toc-sourceurl) * for easier debugging. * * For more information on precompiling templates see * [lodash's custom builds documentation](https://lodash.com/custom-builds). * * For more information on Chrome extension sandboxes see * [Chrome's extensions documentation](https://developer.chrome.com/extensions/sandboxingEval). * * @static * @since 0.1.0 * @memberOf _ * @category String * @param {string} [string=''] The template string. * @param {Object} [options={}] The options object. * @param {RegExp} [options.escape=_.templateSettings.escape] * The HTML "escape" delimiter. * @param {RegExp} [options.evaluate=_.templateSettings.evaluate] * The "evaluate" delimiter. * @param {Object} [options.imports=_.templateSettings.imports] * An object to import into the template as free variables. * @param {RegExp} [options.interpolate=_.templateSettings.interpolate] * The "interpolate" delimiter. * @param {string} [options.sourceURL='templateSources[n]'] * The sourceURL of the compiled template. * @param {string} [options.variable='obj'] * The data object variable name. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`. * @returns {Function} Returns the compiled template function. * @example * * // Use the "interpolate" delimiter to create a compiled template. * var compiled = _.template('hello <%= user %>!'); * compiled({ 'user': 'fred' }); * // => 'hello fred!' * * // Use the HTML "escape" delimiter to escape data property values. * var compiled = _.template('<b><%- value %></b>'); * compiled({ 'value': '<script>' }); * // => '<b>&lt;script&gt;</b>' * * // Use the "evaluate" delimiter to execute JavaScript and generate HTML. * var compiled = _.template('<% _.forEach(users, function(user) { %><li><%- user %></li><% }); %>'); * compiled({ 'users': ['fred', 'barney'] }); * // => '<li>fred</li><li>barney</li>' * * // Use the internal `print` function in "evaluate" delimiters. * var compiled = _.template('<% print("hello " + user); %>!'); * compiled({ 'user': 'barney' }); * // => 'hello barney!' * * // Use the ES template literal delimiter as an "interpolate" delimiter. * // Disable support by replacing the "interpolate" delimiter. * var compiled = _.template('hello ${ user }!'); * compiled({ 'user': 'pebbles' }); * // => 'hello pebbles!' * * // Use backslashes to treat delimiters as plain text. * var compiled = _.template('<%= "\\<%- value %\\>" %>'); * compiled({ 'value': 'ignored' }); * // => '<%- value %>' * * // Use the `imports` option to import `jQuery` as `jq`. * var text = '<% jq.each(users, function(user) { %><li><%- user %></li><% }); %>'; * var compiled = _.template(text, { 'imports': { 'jq': jQuery } }); * compiled({ 'users': ['fred', 'barney'] }); * // => '<li>fred</li><li>barney</li>' * * // Use the `sourceURL` option to specify a custom sourceURL for the template. * var compiled = _.template('hello <%= user %>!', { 'sourceURL': '/basic/greeting.jst' }); * compiled(data); * // => Find the source of "greeting.jst" under the Sources tab or Resources panel of the web inspector. * * // Use the `variable` option to ensure a with-statement isn't used in the compiled template. * var compiled = _.template('hi <%= data.user %>!', { 'variable': 'data' }); * compiled.source; * // => function(data) { * // var __t, __p = ''; * // __p += 'hi ' + ((__t = ( data.user )) == null ? '' : __t) + '!'; * // return __p; * // } * * // Use custom template delimiters. * _.templateSettings.interpolate = /{{([\s\S]+?)}}/g; * var compiled = _.template('hello {{ user }}!'); * compiled({ 'user': 'mustache' }); * // => 'hello mustache!' * * // Use the `source` property to inline compiled templates for meaningful * // line numbers in error messages and stack traces. * fs.writeFileSync(path.join(process.cwd(), 'jst.js'), '\ * var JST = {\ * "main": ' + _.template(mainText).source + '\ * };\ * '); */ function template(string, options, guard) { // Based on John Resig's `tmpl` implementation // (http://ejohn.org/blog/javascript-micro-templating/) // and Laura Doktorova's doT.js (https://github.com/olado/doT). var settings = templateSettings.imports._.templateSettings || templateSettings; if (guard && isIterateeCall(string, options, guard)) { options = undefined; } string = toString(string); options = assignInWith({}, options, settings, customDefaultsAssignIn); var imports = assignInWith({}, options.imports, settings.imports, customDefaultsAssignIn), importsKeys = keys(imports), importsValues = baseValues(imports, importsKeys); var isEscaping, isEvaluating, index = 0, interpolate = options.interpolate || reNoMatch, source = "__p += '"; // Compile the regexp to match each delimiter. var reDelimiters = RegExp((options.escape || reNoMatch).source + '|' + interpolate.source + '|' + (interpolate === reInterpolate ? reEsTemplate : reNoMatch).source + '|' + (options.evaluate || reNoMatch).source + '|$', 'g'); // Use a sourceURL for easier debugging. // The sourceURL gets injected into the source that's eval-ed, so be careful // to normalize all kinds of whitespace, so e.g. newlines (and unicode versions of it) can't sneak in // and escape the comment, thus injecting code that gets evaled. var sourceURL = hasOwnProperty.call(options, 'sourceURL') ? '//# sourceURL=' + (options.sourceURL + '').replace(/\s/g, ' ') + '\n' : ''; string.replace(reDelimiters, function (match, escapeValue, interpolateValue, esTemplateValue, evaluateValue, offset) { interpolateValue || (interpolateValue = esTemplateValue); // Escape characters that can't be included in string literals. source += string.slice(index, offset).replace(reUnescapedString, escapeStringChar); // Replace delimiters with snippets. if (escapeValue) { isEscaping = true; source += "' +\n__e(" + escapeValue + ") +\n'"; } if (evaluateValue) { isEvaluating = true; source += "';\n" + evaluateValue + ";\n__p += '"; } if (interpolateValue) { source += "' +\n((__t = (" + interpolateValue + ")) == null ? '' : __t) +\n'"; } index = offset + match.length; // The JS engine embedded in Adobe products needs `match` returned in // order to produce the correct `offset` value. return match; }); source += "';\n"; // If `variable` is not specified wrap a with-statement around the generated // code to add the data object to the top of the scope chain. var variable = hasOwnProperty.call(options, 'variable') && options.variable; if (!variable) { source = 'with (obj) {\n' + source + '\n}\n'; } // Throw an error if a forbidden character was found in `variable`, to prevent // potential command injection attacks. else if (reForbiddenIdentifierChars.test(variable)) { throw new Error(INVALID_TEMPL_VAR_ERROR_TEXT); } // Cleanup code by stripping empty strings. source = (isEvaluating ? source.replace(reEmptyStringLeading, '') : source).replace(reEmptyStringMiddle, '$1').replace(reEmptyStringTrailing, '$1;'); // Frame code as the function body. source = 'function(' + (variable || 'obj') + ') {\n' + (variable ? '' : 'obj || (obj = {});\n') + "var __t, __p = ''" + (isEscaping ? ', __e = _.escape' : '') + (isEvaluating ? ', __j = Array.prototype.join;\n' + "function print() { __p += __j.call(arguments, '') }\n" : ';\n') + source + 'return __p\n}'; var result = attempt(function () { return Function(importsKeys, sourceURL + 'return ' + source).apply(undefined, importsValues); }); // Provide the compiled function's source by its `toString` method or // the `source` property as a convenience for inlining compiled templates. result.source = source; if (isError(result)) { throw result; } return result; } var template_1 = template; function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; } function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } var prefix = config.prefix; var _FormItem = defineComponent({ name: "".concat(prefix, "-form-item"), props: props, setup: function setup(props2, _ref) { var slots = _ref.slots; var renderTNodeJSX = useTNodeJSX(); var formClass = usePrefixClass("form"); var formItemClass = usePrefixClass("form__item"); var _toRefs = toRefs(props2), name = _toRefs.name; var form = inject(FormInjectionKey, void 0); var extraNode = computed(function () { var _list$; var list = errorList.value; if (showErrorMessage.value && (_list$ = list[0]) !== null && _list$ !== void 0 && _list$.message) { var _list$2; return (_list$2 = list[0]) === null || _list$2 === void 0 ? void 0 : _list$2.message; } if (successList.value.length) { return successList.value[0].message; } return null; }); var formItemClasses = computed(function () { return [formItemClass.value, "".concat(formItemClass.value, "--bordered"), "".concat(formClass.value, "--").concat(labelAlign.value), "".concat(formClass.value, "-item__").concat(props2.name)]; }); var needRequiredMark = computed(function () { var _props2$requiredMark; var requiredMark = (_props2$requiredMark = props2.requiredMark) !== null && _props2$requiredMark !== void 0 ? _props2$requiredMark : form === null || form === void 0 ? void 0 : form.requiredMark; var isRequired = innerRules.value.filter(function (rule) { return rule.required; }).length > 0; return requiredMark !== null && requiredMark !== void 0 ? requiredMark : isRequired; }); var hasLabel = computed(function () { return slots.label || props2.label; }); var hasColon = computed(function () { return !!(form !== null && form !== void 0 && form.colon && hasLabel.value); }); var labelClass = "".concat(formClass.value, "__label"); var labelAlign = computed(function () { return isNil_1(props2.labelAlign) ? form === null || form === void 0 ? void 0 : form.labelAlign : props2.labelAlign; }); var labelWidth = computed(function () { return isNil_1(props2.labelWidth) ? form === null || form === void 0 ? void 0 : form.labelWidth : props2.labelWidth; }); var contentAlign = computed(function () { return isNil_1(props2.contentAlign) ? form === null || form === void 0 ? void 0 : form.contentAlign : props2.contentAlign; }); var labelClasses = computed(function () { return [labelClass, _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty({}, "".concat(labelClass, "--required"), needRequiredMark.value), "".concat(labelClass, "--colon"), hasColon.value), "".concat(labelClass, "--top"), hasLabel.value && (labelAlign.value === "top" || !labelWidth.value)), "".concat(labelClass, "--left"), labelAlign.value === "left" && labelWidth.value), "".concat(labelClass, "--right"), labelAlign.value === "right" && labelWidth.value)]; }); var labelStyle = computed(function () { if (labelWidth.value && labelAlign.value !== "top") { return isNumber_1(labelWidth.value) ? { width: "".concat(labelWidth.value, "px") } : { width: labelWidth.value }; } return {}; }); var freeShowErrorMessage = ref(false); var showErrorMessage = computed(function () { if (isBoolean_1(freeShowErrorMessage.value)) return freeShowErrorMessage.value; if (isBoolean_1(props2.showErrorMessage)) return props2.showErrorMessage; return form === null || form === void 0 ? void 0 : form.showErrorMessage; }); var errorClasses = computed(function () { if (!showErrorMessage.value) return ""; if (!errorList.value.length) return ""; var type = errorList.value[0].type || "error"; return type === "error" ? "".concat(formItemClass.value, "--error") : "".concat(formItemClass.value, "--warning"); }); var contentClasses = computed(function () { return ["".concat(formClass.value, "__controls"), errorClasses.value]; }); var contentSlotClasses = computed(function () { return ["".concat(formClass.value, "__controls-content"), "".concat(formClass.value, "__controls--").concat(contentAlign.value)]; }); var contentStyle = computed(function () { var contentStyle2 = {}; if (labelWidth.value && labelAlign.value !== "top") { if (isNumber_1(labelWidth.value)) { contentStyle2 = { marginLeft: "".concat(labelWidth.value, "px") }; } else { contentStyle2 = { marginLeft: labelWidth.value }; } } return contentStyle2; }); var errorList = ref([]); var successList = ref([]); var verifyStatus = ref(ValidateStatus.TO_BE_VALIDATED); var resetValidating = ref(false); var needResetField = ref(false); var resetHandler = function resetHandler() { needResetField.value = false; errorList.value = []; successList.value = []; verifyStatus.value = ValidateStatus.TO_BE_VALIDATED; }; var getEmptyValue = function getEmptyValue() { var type = Object.prototype.toString.call(get_1(form === null || form === void 0 ? void 0 : form.data, "".concat(props2.name))); var emptyValue; if (type === "[object String]") { emptyValue = ""; } if (type === "[object Array]") { emptyValue = []; } if (type === "[object Object]") { emptyValue = {}; } return emptyValue; }; var resetField = /*#__PURE__*/function () { var _ref3 = _asyncToGenerator(/*#__PURE__*/regenerator.mark(function _callee() { var resetType, _args = arguments; return regenerator.wrap(function _callee$(_context) { while (1) switch (_context.prev = _context.next) { case 0: resetType = _args.length > 0 && _args[0] !== undefined ? _args[0] : form === null || form === void 0 ? void 0 : form.resetType; if (props2.name) { _context.next = 3; break; } return _context.abrupt("return", null); case 3: if (resetType === "empty") { set_1(form === null || form === void 0 ? void 0 : form.data, props2.name, getEmptyValue()); } else if (resetType === "initial") { set_1(form === null || form === void 0 ? void 0 : form.data, props2.name, initialValue.value); } _context.next = 6; return nextTick(); case 6: if (resetValidating.value) { needResetField.value = true; } else { resetHandler(); } case 7: case "end": return _context.stop(); } }, _callee); })); return function resetField() { return _ref3.apply(this, arguments); }; }(); var errorMessages = computed(function () { return (form === null || form === void 0 ? void 0 : form.errorMessage) || {}; }); var innerRules = computed(function () { var _props2$rules; if ((_props2$rules = props2.rules) !== null && _props2$rules !== void 0 && _props2$rules.length) return props2.rules; if (!props2.name) return []; var index = "".concat(props2.name).lastIndexOf(".") || -1; var pRuleName = "".concat(props2.name).slice(index + 1); return get_1(form === null || form === void 0 ? void 0 : form.rules, props2.name) || get_1(form === null || form === void 0 ? void 0 : form.rules, pRuleName) || []; }); var analysisValidateResult = /*#__PURE__*/function () { var _ref4 = _asyncToGenerator(/*#__PURE__*/regenerator.mark(function _callee2(trigger) { var _result$rules; var result; return regenerator.wrap(function _callee2$(_context2) { while (1) switch (_context2.prev = _context2.next) { case 0: result = { successList: [], errorList: [], rules: [], resultList: [], allowSetValue: false }; result.rules = trigger === "all" ? innerRules.value : innerRules.value.filter(function (item) { return (item.trigger || "change") === trigger; }); if (!(innerRules.value.length && !((_result$rules = result.rules) !== null && _result$rules !== void 0 && _result$rules.length))) { _context2.next = 4; break; } return _context2.abrupt("return", result); case 4: result.allowSetValue = true; _context2.next = 7; return validate(value.value, result.rules); case 7: result.resultList = _context2.sent; result.errorList = result.resultList.filter(function (item) { return item.result !== true; }).map(function (item) { Object.keys(item).forEach(function (key) { if (!item.message && errorMessages.value[key]) { var compiled = template_1(errorMessages.value[key]); var name2 = isString_1(props2.label) ? props2.label : props2.name; item.message = compiled({ name: name2, validate: item[key] }); } }); return item; }); result.successList = result.resultList.filter(function (item) { return item.result === true && item.message && item.type === "success"; }); return _context2.abrupt("return", result); case 11: case "end": return _context2.stop(); } }, _callee2); })); return function analysisValidateResult(_x) { return _ref4.apply(this, arguments); }; }(); var validateHandler = /*#__PURE__*/function () { var _ref5 = _asyncToGenerator(/*#__PURE__*/regenerator.mark(function _callee3(trigger, showErrorMessage2) { var _yield$analysisValida, innerSuccessList, innerErrorList, rules, resultList, allowSetValue; return regenerator.wrap(function _callee3$(_context3) { while (1) switch (_context3.prev = _context3.next) { case 0: resetValidating.value = true; freeShowErrorMessage.value = showErrorMessage2; _context3.next = 4; return analysisValidateResult(trigger); case 4: _yield$analysisValida = _context3.sent; innerSuccessList = _yield$analysisValida.successList; innerErrorList = _yield$analysisValida.errorList; rules = _yield$analysisValida.rules; resultList = _yield$analysisValida.resultList; allowSetValue = _yield$analysisValida.allowSetValue; if (allowSetValue) { successList.value = innerSuccessList || []; errorList.value = innerErrorList || []; } if (rules.length) { verifyStatus.value = innerErrorList !== null && innerErrorList !== void 0 && innerErrorList.length ? ValidateStatus.FAIL : ValidateStatus.SUCCESS; } if (needResetField.value) { resetHandler(); } resetValidating.value = false; return _context3.abrupt("return", _defineProperty({}, "".concat(name.value), (innerErrorList === null || innerErrorList === void 0 ? void 0 : innerErrorList.length) === 0 ? true : resultList)); case 15: case "end": return _context3.stop(); } }, _callee3); })); return function validateHandler(_x2, _x3) { return _ref5.apply(this, arguments); }; }(); var validateOnly = /*#__PURE__*/function () { var _ref7 = _asyncToGenerator(/*#__PURE__*/regenerator.mark(function _callee4(trigger) { var _yield$analysisValida2, innerErrorList, resultList; return regenerator.wrap(function _callee4$(_context4) { while (1) switch (_context4.prev = _context4.next) { case 0: _context4.next = 2; return analysisValidateResult(trigger); case 2: _yield$analysisValida2 = _context4.sent; innerErrorList = _yield$analysisValida2.errorList; resultList = _yield$analysisValida2.resultList; return _context4.abrupt("return", _defineProperty({}, props2.name, innerErrorList.length === 0 ? true : resultList)); case 6: case "end": return _context4.stop(); } }, _callee4); })); return function validateOnly(_x4) { return _ref7.apply(this, arguments); }; }(); var setValidateMessage = function setValidateMessage(validateMessage) { if (!validateMessage && !isArray_1(validateMessage)) return; if (validateMessage.length === 0) { errorList.value = []; verifyStatus.value = ValidateStatus.SUCCESS; } errorList.value = validateMessage.map(function (item) { return _objectSpread(_objectSpread({}, item), {}, { result: false }); }); verifyStatus.value = ValidateStatus.FAIL; }; var value = computed(function () { return (form === null || form === void 0 ? void 0 : form.data) && get_1(form === null || form === void 0 ? void 0 : form.data, "".concat(name.value)); }); var initialValue = ref(void 0); var context = reactive({ name: name, resetHandler: resetHandler, resetField: resetField, validate: validateHandler, validateOnly: validateOnly, setValidateMessage: setValidateMessage }); onMounted(function () { initialValue.value = cloneDeep_1(value.value); form === null || form === void 0 || form.children.push(context); }); onBeforeUnmount(function () { if (form) form.children = form === null || form === void 0 ? void 0 : form.children.filter(function (ctx) { return ctx !== context; }); }); watch(value, /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/regenerator.mark(function _callee5() { return regenerator.wrap(function _callee5$(_context5) { while (1) switch (_context5.prev = _context5.next) { case 0: _context5.next = 2; return validateHandler("change"); case 2: case "end": return _context5.stop(); } }, _callee5); })), { deep: true }); watch(function () { return [props2.name, JSON.stringify(props2.rules)].join(","); }, function () { validateHandler("change"); }); var handleBlur = /*#__PURE__*/function () { var _ref10 = _asyncToGenerator(/*#__PURE__*/regenerator.mark(function _callee6() { return regenerator.wrap(function _callee6$(_context6) { while (1) switch (_context6.prev = _context6.next) { case 0: _context6.next = 2; return validateHandler("blur"); case 2: case "end": return _context6.stop(); } }, _callee6); })); return function handleBlur() { return _ref10.apply(this, arguments); }; }(); provide(FormItemInjectionKey, { handleBlur: handleBlur }); return function () { var renderRightIconContent = function renderRightIconContent() { if (!props2.arrow) { return null; } return createVNode(ChevronRightIcon, { "size": "24px", "style": { color: "rgba(0, 0, 0, .4)" } }, null); }; var renderLabelContent = function renderLabelContent() { if (Number(labelWidth.value) === 0) { return null; } return renderTNodeJSX("label"); }; var renderHelpNode = function renderHelpNode() { var helpNode = renderTNodeJSX("help"); if (!helpNode) { return null; } return createVNode("div", { "class": ["".concat(formItemClass.value, "-help"), "".concat(formClass.value, "__controls--").concat(contentAlign.value)] }, [helpNode]); }; var renderExtraNode = function renderExtraNode() { if (!extraNode.value) { return null; } return createVNode("div", { "class": ["".concat(formItemClass.value, "-extra"), "".concat(formClass.value, "__controls--").concat(contentAlign.value)] }, [extraNode.value]); }; return createVNode("div", { "class": [].concat(_toConsumableArray(formItemClasses.value), [renderHelpNode() ? "".concat(formClass.value, "__item-with-help") : ""]) }, [createVNode("div", { "class": ["".concat(formItemClass.value, "-wrap"), "".concat(formItemClass.value, "--").concat(labelAlign.value)] }, [createVNode("div", { "class": labelClasses.value, "style": labelStyle.value }, [createVNode("label", { "for": props2.for }, [renderLabelContent()])]), createVNode("div", { "class": contentClasses.value, "style": contentStyle.value }, [createVNode("div", { "class": contentSlotClasses.value }, [renderTNodeJSX("default")]), renderHelpNode(), renderExtraNode()])]), renderRightIconContent()]); }; } }); export { _FormItem as default }; //# sourceMappingURL=form-item.mjs.map