vue-admin-core
Version:
A Component Library for Vue 3
93 lines (90 loc) • 2.49 kB
JavaScript
import { defineComponent } from 'vue';
import { FormProvider as FormProvider$1, useForm, h } from '@formily/vue';
import { buildProps } from 'element-plus/es/utils/vue/props/runtime';
import '../../preview-text/index.mjs';
import '../../form-layout/index.mjs';
import { formLayoutProps, FormLayout } from '../../form-layout/src/index.mjs';
import { PreviewText } from '../../preview-text/src/index.mjs';
const FormProvider = FormProvider$1;
const formProps = {
...formLayoutProps,
...buildProps({
form: {
type: Object
},
component: {
type: Object
},
previewTextPlaceholder: {
type: [String, Function]
},
onAutoSubmit: {
type: Function
},
onAutoSubmitFailed: {
type: Function
}
})
};
const Form = defineComponent({
name: "FForm",
inheritAttrs: false,
props: formProps,
setup(props, { slots }) {
const top = useForm();
return () => {
const {
form,
component = "form",
onAutoSubmit,
onAutoSubmitFailed,
previewTextPlaceholder = slots == null ? void 0 : slots.previewTextPlaceholder,
...other
} = props;
const renderContent = (form2) => {
return h(
PreviewText.Placeholder,
{
value: previewTextPlaceholder
},
{
default: () => [
h(FormLayout, other, {
default: () => [
h(
component,
{
onSubmit: (e) => {
var _a, _b;
(_a = e == null ? void 0 : e.stopPropagation) == null ? void 0 : _a.call(e);
(_b = e == null ? void 0 : e.preventDefault) == null ? void 0 : _b.call(e);
if (onAutoSubmit) {
form2.submit(onAutoSubmit).catch(onAutoSubmitFailed);
}
}
},
slots
)
]
})
]
}
);
};
if (form) {
return h(
FormProvider,
{ form },
{
default: () => renderContent(form)
}
);
}
if (!top.value)
throw new Error("must pass form instance by createForm");
return renderContent(top.value);
};
}
});
export { Form, Form as default, formProps };
//# sourceMappingURL=index.mjs.map