36 lines
1.2 KiB
JavaScript
Raw Normal View History

2024-01-29 09:26:07 +08:00
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
2024-08-02 18:19:39 +08:00
exports.useIsComposing = useIsComposing;
2024-01-29 09:26:07 +08:00
const vue_1 = require("vue");
const is_browser_1 = require("../env/is-browser");
const isComposingRef = (0, vue_1.ref)(false);
2024-08-02 18:19:39 +08:00
function compositionStartHandler() {
2024-01-29 09:26:07 +08:00
isComposingRef.value = true;
2024-08-02 18:19:39 +08:00
}
function compositionEndHandler() {
2024-01-29 09:26:07 +08:00
isComposingRef.value = false;
2024-08-02 18:19:39 +08:00
}
2024-01-29 09:26:07 +08:00
let mountedCount = 0;
2024-08-02 18:19:39 +08:00
function useIsComposing() {
2024-01-29 09:26:07 +08:00
if (is_browser_1.isBrowser) {
(0, vue_1.onBeforeMount)(() => {
if (!mountedCount) {
window.addEventListener('compositionstart', compositionStartHandler);
window.addEventListener('compositionend', compositionEndHandler);
}
mountedCount++;
});
(0, vue_1.onBeforeUnmount)(() => {
if (mountedCount <= 1) {
window.removeEventListener('compositionstart', compositionStartHandler);
window.removeEventListener('compositionend', compositionEndHandler);
mountedCount = 0;
}
else {
mountedCount--;
}
});
}
return isComposingRef;
2024-08-02 18:19:39 +08:00
}