yanzhen-design-vue
Version:
56 lines (55 loc) • 1.78 kB
JavaScript
;
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const vue = require("vue");
const utilsVue = require("@yanzhen-libs/utils-vue");
const utils = require("@yanzhen-libs/utils");
const core = require("@yanzhen-lowcode/core");
const lodashEs = require("lodash-es");
function useWrapper(props, emit) {
const valueRef = utilsVue.useModelValue(props, null, emit);
const tag = vue.computed(() => props.tag);
const model = vue.computed(() => props.model ?? {});
const propsRef = vue.computed(() => lodashEs.omit(props, "tag", "model"));
const attrs = vue.useAttrs();
const _props = vue.computed(() => {
const schema = vue.unref(propsRef);
return vue.mergeProps(vue.unref(attrs), {
class: [schema == null ? void 0 : schema.class],
style: schema == null ? void 0 : schema.style
});
});
function handleEmit(type, key, value) {
let flag = true;
switch (true) {
case (props.prop && type === "update:model" && key === props.prop):
valueRef.value = value;
flag = false;
break;
}
if (flag && emit && !type.startsWith("update:")) {
emit(type, {
model: vue.unref(model),
type,
key,
value
});
}
}
core.providePageConfigure(model, {
listener: handleEmit
});
const Wrapper = vue.computed(() => {
const type = vue.unref(tag);
const props2 = vue.unref(propsRef);
const comp = type && core.getComponentsInstance(type);
if (core.isComponent(comp)) {
const typeProps = utils.mergeWith({ type }, props2);
return core.createSchemaElement(typeProps, vue.unref(_props));
}
return vue.createCommentVNode("v-if", true);
});
return {
Wrapper
};
}
exports.useWrapper = useWrapper;