@aplus-frontend/ui
Version:
32 lines (31 loc) • 754 B
JavaScript
import { ref as v, nextTick as c, watch as m } from "vue";
import { isUndefined as n } from "lodash-unified";
function P(e, f, u) {
const r = u?.defaultValuePropName || "defaultValue", t = u?.valuePropName || "value", a = v(o());
async function i(l) {
u?.beforeUpdateValue && (d(), !await u.beforeUpdateValue(l)) || (e[t] === void 0 && (a.value = l), f(`update:${t}`, l));
}
function d() {
a.value === void 0 && (a.value = "", c(() => {
a.value = void 0;
}));
}
function o() {
return n(e[t]) ? n(e[r]) ? u?.defaultValue : e[r] : e[t];
}
return m(
() => e[t],
(l) => {
a.value = l;
},
{
deep: !0
}
), {
value: a,
updateValue: i
};
}
export {
P as useControllableValue
};