You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
129 lines
3.5 KiB
129 lines
3.5 KiB
11 months ago
|
'use strict';
|
||
|
|
||
|
Object.defineProperty(exports, '__esModule', { value: true });
|
||
|
|
||
|
var vue = require('vue');
|
||
|
var shared = require('@vue/shared');
|
||
|
var core = require('@vueuse/core');
|
||
|
var util = require('../../utils/util.js');
|
||
|
var props = require('../../utils/props.js');
|
||
|
|
||
|
const createModelToggleComposable = (name) => {
|
||
|
const useModelToggleProps2 = {
|
||
|
[name]: props.buildProp({
|
||
|
type: props.definePropType(Boolean),
|
||
|
default: null
|
||
|
}),
|
||
|
[`onUpdate:${name}`]: props.buildProp({
|
||
|
type: props.definePropType(Function)
|
||
|
})
|
||
|
};
|
||
|
const useModelToggleEmits2 = [`update:${name}`];
|
||
|
const useModelToggle2 = ({
|
||
|
indicator,
|
||
|
shouldHideWhenRouteChanges,
|
||
|
shouldProceed,
|
||
|
onShow,
|
||
|
onHide
|
||
|
}) => {
|
||
|
const instance = vue.getCurrentInstance();
|
||
|
const props = instance.props;
|
||
|
const { emit } = instance;
|
||
|
const updateEventKey = `update:${name}`;
|
||
|
const hasUpdateHandler = vue.computed(() => shared.isFunction(props[`onUpdate:${name}`]));
|
||
|
const isModelBindingAbsent = vue.computed(() => props[name] === null);
|
||
|
const doShow = () => {
|
||
|
if (indicator.value === true) {
|
||
|
return;
|
||
|
}
|
||
|
indicator.value = true;
|
||
|
if (shared.isFunction(onShow)) {
|
||
|
onShow();
|
||
|
}
|
||
|
};
|
||
|
const doHide = () => {
|
||
|
if (indicator.value === false) {
|
||
|
return;
|
||
|
}
|
||
|
indicator.value = false;
|
||
|
if (shared.isFunction(onHide)) {
|
||
|
onHide();
|
||
|
}
|
||
|
};
|
||
|
const show = () => {
|
||
|
if (props.disabled === true || shared.isFunction(shouldProceed) && !shouldProceed())
|
||
|
return;
|
||
|
const shouldEmit = hasUpdateHandler.value && core.isClient;
|
||
|
if (shouldEmit) {
|
||
|
emit(updateEventKey, true);
|
||
|
}
|
||
|
if (isModelBindingAbsent.value || !shouldEmit) {
|
||
|
doShow();
|
||
|
}
|
||
|
};
|
||
|
const hide = () => {
|
||
|
if (props.disabled === true || !core.isClient)
|
||
|
return;
|
||
|
const shouldEmit = hasUpdateHandler.value && core.isClient;
|
||
|
if (shouldEmit) {
|
||
|
emit(updateEventKey, false);
|
||
|
}
|
||
|
if (isModelBindingAbsent.value || !shouldEmit) {
|
||
|
doHide();
|
||
|
}
|
||
|
};
|
||
|
const onChange = (val) => {
|
||
|
if (!util.isBool(val))
|
||
|
return;
|
||
|
if (props.disabled && val) {
|
||
|
if (hasUpdateHandler.value) {
|
||
|
emit(updateEventKey, false);
|
||
|
}
|
||
|
} else if (indicator.value !== val) {
|
||
|
if (val) {
|
||
|
doShow();
|
||
|
} else {
|
||
|
doHide();
|
||
|
}
|
||
|
}
|
||
|
};
|
||
|
const toggle = () => {
|
||
|
if (indicator.value) {
|
||
|
hide();
|
||
|
} else {
|
||
|
show();
|
||
|
}
|
||
|
};
|
||
|
vue.watch(() => props[name], onChange);
|
||
|
if (shouldHideWhenRouteChanges && instance.appContext.config.globalProperties.$route !== void 0) {
|
||
|
vue.watch(() => ({
|
||
|
...instance.proxy.$route
|
||
|
}), () => {
|
||
|
if (shouldHideWhenRouteChanges.value && indicator.value) {
|
||
|
hide();
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
vue.onMounted(() => {
|
||
|
onChange(props[name]);
|
||
|
});
|
||
|
return {
|
||
|
hide,
|
||
|
show,
|
||
|
toggle
|
||
|
};
|
||
|
};
|
||
|
return {
|
||
|
useModelToggle: useModelToggle2,
|
||
|
useModelToggleProps: useModelToggleProps2,
|
||
|
useModelToggleEmits: useModelToggleEmits2
|
||
|
};
|
||
|
};
|
||
|
const { useModelToggle, useModelToggleProps, useModelToggleEmits } = createModelToggleComposable("modelValue");
|
||
|
|
||
|
exports.createModelToggleComposable = createModelToggleComposable;
|
||
|
exports.useModelToggle = useModelToggle;
|
||
|
exports.useModelToggleEmits = useModelToggleEmits;
|
||
|
exports.useModelToggleProps = useModelToggleProps;
|
||
|
//# sourceMappingURL=index.js.map
|