UNPKG

yanzhen-design-vue

Version:

86 lines (85 loc) 3.21 kB
"use strict"; Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" }); const vue = require("vue"); const lodashEs = require("lodash-es"); const utils = require("@yanzhen-libs/utils"); const utilsVue = require("@yanzhen-libs/utils-vue"); require("../../form/index.cjs"); const formItem = require("./form-item.cjs"); require("./form-item.vue.cjs"); const formItemGroupContext = require("./hooks/form-item-group-context.cjs"); const useForm = require("../../form/src/hooks/use-form.cjs"); const formItem_vue_vue_type_script_setup_true_lang = require("./form-item.vue2.cjs"); function useFormItemGroup(props, emit, expose) { const namesRef = vue.computed(() => { return lodashEs.toArray(utils.isEmptyValue(props.name) ? [] : props.name); }); const injectForm = useForm.useInjectForm("ctx"); const validateInfosRef = vue.computed(() => { var _a; const names = vue.unref(namesRef); return lodashEs.pick(((_a = vue.unref(injectForm)) == null ? void 0 : _a.validateInfos) ?? props.validateInfos, ...names); }); const errorInfos = vue.computed(() => { const names = vue.unref(namesRef); const validateInfos = vue.unref(validateInfosRef); const errors = lodashEs.toArray(lodashEs.pick(validateInfos, ...names)); const errorInfos2 = {}; for (const errorInfo of errors) { lodashEs.mergeWith(errorInfos2, errorInfo, (objValue, srcValue, key) => { switch (key) { case "help": return lodashEs.flattenDeep([objValue].concat(srcValue)).filter((value) => value); } switch (true) { case lodashEs.isBoolean(objValue): case lodashEs.isBoolean(srcValue): return [objValue, srcValue].includes(true); } return [objValue, srcValue].includes("error") ? "error" : srcValue ?? objValue; }); } return errorInfos2; }); formItemGroupContext.useProvideFormItemGroupContext({ id: namesRef, async onFieldChange(name) { var _a; name && ((_a = vue.unref(injectForm)) == null ? void 0 : _a.validate(name)); }, onFieldBlur(name) { var _a; name && ((_a = vue.unref(injectForm)) == null ? void 0 : _a.validate(name)); }, clearValidate(name) { var _a; name && ((_a = vue.unref(injectForm)) == null ? void 0 : _a.clearValidate(name)); } }); const slots = vue.useSlots(); function renderFormItemList() { if (lodashEs.isFunction(slots.default)) { const VNodes = slots.default({ validateInfos: vue.unref(validateInfosRef), errorInfos: vue.unref(errorInfos) }); console.log(VNodes, "VNodes"); return VNodes; } } const config = vue.computed(() => lodashEs.pick(props, ...Object.keys(formItem.AntFormItem.props))); const _props = utilsVue.useProxyProps(config, formItem.AntFormItem.emits, { emit, exclude: ["name", "rules"], filter: true }); return [ { _props }, () => { return vue.createVNode(formItem_vue_vue_type_script_setup_true_lang.default, vue.mergeProps(vue.unref(_props), vue.unref(errorInfos)), { default: vue.withCtx(renderFormItemList) }); } ]; } exports.useFormItemGroup = useFormItemGroup;