index.mjs 1.0 KB

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