@opentiny/vue-renderless
Version:
An enterprise-class UI component library, support both Vue.js 2 and Vue.js 3, as well as PC and mobile.
103 lines (102 loc) • 3.03 kB
JavaScript
import "../chunk-G2ADBYYC.js";
import { on, off } from "@opentiny/utils";
import { PopupManager } from "@opentiny/utils";
import { isObject, typeOf } from "@opentiny/utils";
const emitInput = ({ emit }) => (...args) => {
emit("update:modelValue", ...args);
emit("input", ...args);
};
const handleChange = ({ emit, state }) => (event) => {
const value = event.target.value;
emit("change", state.searchValue, value);
};
const handleInput = ({ api, props, state }) => (event) => {
const value = event.target ? event.target.value : event;
api.emitInput(value, state.searchValue);
};
const showSelector = ({ vm, state }) => () => {
vm.$refs.selector.style.zIndex = PopupManager.nextZIndex();
state.show = true;
};
const changeKey = ({ emit, state }) => (key) => {
state.searchValue = key;
state.show = false;
emit("select", key);
};
const searchClick = ({ emit, props, state }) => (event) => {
event.preventDefault();
if (props.mini && state.collapse) {
state.collapse = false;
emit("expand");
} else {
emit("search", state.searchValue, state.currentValue);
}
};
const searchEnterKey = ({ api, props, vm, nextTick }) => (event) => {
if (props.isEnterSearch) {
api.searchClick(event);
nextTick(() => vm.$refs.input.blur());
}
};
const clickOutside = ({ parent, props, state, emit }) => (event) => {
const path = (event == null ? void 0 : event.composedPath) && event.composedPath();
if (path ? !path.includes(parent.$el) : !parent.$el.contains(event.target)) {
state.show = false;
if (props.mini && !state.currentValue && !state.collapse) {
state.collapse = true;
emit("collapse");
}
}
};
const setDefaultType = (searchTypes, typeValue) => {
if (typeValue && searchTypes.includes(typeValue)) {
return typeValue;
}
let type = {};
for (let i = 0, len = searchTypes.length; i < len; i++) {
if (isObject(searchTypes[i]) && typeOf(searchTypes[i].value) !== "undefined" && typeOf(searchTypes[i].text) !== "undefined") {
type = searchTypes[i];
break;
}
}
return type;
};
const formatSearchTypes = (searchTypes) => {
const types = [];
for (let i = 0, len = searchTypes.length; i < len; i++) {
if (isObject(searchTypes[i]) && typeOf(searchTypes[i].value) !== "undefined" && typeOf(searchTypes[i].text) !== "undefined") {
types.push(searchTypes[i]);
}
}
return types;
};
const mounted = ({ api }) => () => {
on(document.body, "click", api.clickOutside);
};
const beforeDestroy = ({ api }) => () => {
off(document.body, "click", api.clickOutside);
};
const clear = ({ api, emit, vm, state }) => (event) => {
event.preventDefault();
state.currentValue = "";
vm.$refs.input.focus();
state.focus = true;
api.emitInput("", state.searchValue);
emit("change", [], "");
emit("clear");
};
export {
beforeDestroy,
changeKey,
clear,
clickOutside,
emitInput,
formatSearchTypes,
handleChange,
handleInput,
mounted,
searchClick,
searchEnterKey,
setDefaultType,
showSelector
};