UNPKG

@opensig/opendesign

Version:

38 lines (37 loc) 972 B
import { ref, onMounted, onUnmounted } from "vue"; import { trigger } from "../_utils/event.mjs"; function useComposition({ el } = {}) { const isComposing = ref(false); const onCompositionStart = () => { isComposing.value = true; }; const onCompositionEnd = (e) => { if (!isComposing.value) { return; } isComposing.value = false; trigger(e.target, "input"); }; onMounted(() => { if (!(el == null ? void 0 : el.value)) { return; } el.value.addEventListener("compositionstart", onCompositionStart); el.value.addEventListener("compositionend", onCompositionEnd); }); onUnmounted(() => { if (!(el == null ? void 0 : el.value)) { return; } el.value.removeEventListener("compositionstart", onCompositionStart); el.value.removeEventListener("compositionend", onCompositionEnd); }); return { isComposing, onCompositionStart, onCompositionEnd }; } export { useComposition };