vue-admin-core
Version:
A Component Library for Vue 3
116 lines (113 loc) • 3.31 kB
JavaScript
import { defineComponent, h, createVNode } from 'vue';
import '../../__builtins__/index.mjs';
import { useField, connect, mapProps, mapReadPretty, useFieldSchema, RecursionField, Field, Schema } from '@formily/vue';
import '../../preview-text/index.mjs';
import { ElInput, ElIcon } from 'element-plus';
import { map, find } from 'lodash-es';
import { Loading } from '@element-plus/icons-vue';
import { transformComponent } from '../../__builtins__/shared/transform-component.mjs';
import { PreviewText } from '../../preview-text/src/index.mjs';
import { stylePrefix } from '../../__builtins__/configs/index.mjs';
import { composeExport } from '../../__builtins__/shared/utils.mjs';
const RefElInput = defineComponent({
name: "RefElInput",
props: ElInput.props,
setup(props, {
attrs,
slots
}) {
const field = useField();
return () => h(ElInput, {
...attrs,
...props,
ref: (inst) => {
field.value.inject({
getRef: () => inst
});
}
}, slots);
}
});
const TransformElInput = transformComponent(RefElInput, {
change: "update:modelValue"
});
const InnerInput = connect(TransformElInput, mapProps({
value: "modelValue",
readOnly: "readonly"
}, (props, field) => {
return {
...props,
ref: (inst) => {
field.inject({
getInstance: () => inst
});
},
suffixIcon: (
// @ts-ignore
(field == null ? void 0 : field["loading"]) || (field == null ? void 0 : field["validating"]) ? createVNode(ElIcon, {
"class": "is-loading"
}, {
default: () => [createVNode(Loading, null, null)]
}) : props.suffixIcon
)
};
}), mapReadPretty(PreviewText.Input));
const TextArea = connect(InnerInput, mapProps((props) => {
return {
...props,
type: "textarea"
};
}), mapReadPretty(PreviewText.Input));
const Password = connect(InnerInput, mapProps((props) => ({
...props,
showPassword: true
})));
const Item = defineComponent({
name: "FInputItem",
inheritAttrs: false,
setup(_, {
attrs
}) {
const field = useField();
const schema = useFieldSchema();
const schemas = schema.value.schema;
map(schemas, (value, key) => {
value["name"] = key;
});
const prepend = find(schemas, ["x-slot", "prepend"]);
const append = find(schemas, ["x-slot", "append"]);
const input = find(schemas, (item) => !item["x-slot"] || item["x-slot"] === "default");
const slots = {};
if (prepend) {
slots["prepend"] = () => {
return h(RecursionField, {
name: prepend.name,
schema: prepend,
basePath: field.value.address
});
};
}
if (append) {
slots["append"] = () => h(RecursionField, {
name: append.name,
schema: append,
basePath: field.value.address
});
}
return () => {
return h(Field, {
...new Schema(input).toFieldProps(),
class: [`${stylePrefix}-select-input`, attrs == null ? void 0 : attrs.class],
style: attrs == null ? void 0 : attrs.style,
basePath: field.value.address
}, slots);
};
}
});
const Input = composeExport(InnerInput, {
TextArea,
Password,
Item
});
export { Input, Item, Password, Input as default };
//# sourceMappingURL=index.mjs.map