index.js 1.3 KB

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