Files

85 lines
2.4 KiB
JavaScript

import {
getCurrentInstance,
toKebabCase
} from "./chunk-LZ5T2ERG.js";
import {
computed,
effectScope,
onScopeDispose,
ref,
toRaw,
watch
} from "./chunk-2MKFL3BX.js";
// node_modules/vuetify/lib/composables/toggleScope.js
function useToggleScope(source, fn) {
let scope;
function start() {
scope = effectScope();
scope.run(() => fn.length ? fn(() => {
scope?.stop();
start();
}) : fn());
}
watch(source, (active) => {
if (active && !scope) {
start();
} else if (!active) {
scope?.stop();
scope = void 0;
}
}, {
immediate: true
});
onScopeDispose(() => {
scope?.stop();
});
}
// node_modules/vuetify/lib/composables/proxiedModel.js
function useProxiedModel(props, prop, defaultValue) {
let transformIn = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : (v) => v;
let transformOut = arguments.length > 4 && arguments[4] !== void 0 ? arguments[4] : (v) => v;
const vm = getCurrentInstance("useProxiedModel");
const internal = ref(props[prop] !== void 0 ? props[prop] : defaultValue);
const kebabProp = toKebabCase(prop);
const checkKebab = kebabProp !== prop;
const isControlled = checkKebab ? computed(() => {
void props[prop];
return !!((vm.vnode.props?.hasOwnProperty(prop) || vm.vnode.props?.hasOwnProperty(kebabProp)) && (vm.vnode.props?.hasOwnProperty(`onUpdate:${prop}`) || vm.vnode.props?.hasOwnProperty(`onUpdate:${kebabProp}`)));
}) : computed(() => {
void props[prop];
return !!(vm.vnode.props?.hasOwnProperty(prop) && vm.vnode.props?.hasOwnProperty(`onUpdate:${prop}`));
});
useToggleScope(() => !isControlled.value, () => {
watch(() => props[prop], (val) => {
internal.value = val;
});
});
const model = computed({
get() {
const externalValue = props[prop];
return transformIn(isControlled.value ? externalValue : internal.value);
},
set(internalValue) {
const newValue = transformOut(internalValue);
const value = toRaw(isControlled.value ? props[prop] : internal.value);
if (value === newValue || transformIn(value) === internalValue) {
return;
}
internal.value = newValue;
vm?.emit(`update:${prop}`, newValue);
}
});
Object.defineProperty(model, "externalValue", {
get: () => isControlled.value ? props[prop] : internal.value
});
return model;
}
export {
useToggleScope,
useProxiedModel
};
//# sourceMappingURL=chunk-KA77II4V.js.map