yanzhen-design-vue
Version:
28 lines (27 loc) • 877 B
JavaScript
import { ref, useAttrs, getCurrentInstance, computed, normalizeProps, mergeProps, unref } from "vue";
import { isEmptyValue } from "@yanzhen-libs/utils";
import { isFunction } from "lodash-es";
function useTextPreview(props, emit) {
const _ref = ref();
const attrs = useAttrs();
const instance = getCurrentInstance();
const propsRef = computed(() => normalizeProps(mergeProps(attrs, props)));
const previewTextRef = computed(() => {
const props2 = unref(propsRef) ?? {};
const keys = Object.keys(props2);
const txt = props2.value;
const nativeTagFormatter = props2.nativeTagFormatter;
if (keys.includes("value") && isEmptyValue(txt)) return "";
if (isFunction(nativeTagFormatter)) {
return nativeTagFormatter(txt, props2, instance);
}
return txt;
});
return {
_ref,
previewTextRef
};
}
export {
useTextPreview
};