index.mjs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import { ref, nextTick } from 'vue';
  2. import { isKorean } from '../../utils/i18n.mjs';
  3. function useComposition({
  4. afterComposition,
  5. emit
  6. }) {
  7. const isComposing = ref(false);
  8. const handleCompositionStart = (event) => {
  9. emit == null ? void 0 : emit("compositionstart", event);
  10. isComposing.value = true;
  11. };
  12. const handleCompositionUpdate = (event) => {
  13. var _a;
  14. emit == null ? void 0 : emit("compositionupdate", event);
  15. const text = (_a = event.target) == null ? void 0 : _a.value;
  16. const lastCharacter = text[text.length - 1] || "";
  17. isComposing.value = !isKorean(lastCharacter);
  18. };
  19. const handleCompositionEnd = (event) => {
  20. emit == null ? void 0 : emit("compositionend", event);
  21. if (isComposing.value) {
  22. isComposing.value = false;
  23. nextTick(() => afterComposition(event));
  24. }
  25. };
  26. const handleComposition = (event) => {
  27. event.type === "compositionend" ? handleCompositionEnd(event) : handleCompositionUpdate(event);
  28. };
  29. return {
  30. isComposing,
  31. handleComposition,
  32. handleCompositionStart,
  33. handleCompositionUpdate,
  34. handleCompositionEnd
  35. };
  36. }
  37. export { useComposition };
  38. //# sourceMappingURL=index.mjs.map