Skip to content

Commit c0cf29d

Browse files
committed
refactor: VueUse を導入
1 parent f3566e9 commit c0cf29d

24 files changed

Lines changed: 109 additions & 240 deletions

package-lock.json

Lines changed: 45 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
"@shiguredo/virtual-background": "^2023.2.0",
3434
"@traptitech/traq": "^3.26.1-1",
3535
"@traptitech/traq-markdown-it": "^7.0.2",
36+
"@vueuse/core": "^14.1.0",
3637
"autosize": "^6.0.1",
3738
"browser-image-compression": "^2.0.2",
3839
"cropperjs": "^1.6.2",

src/components/Main/MainView/ChannelView/ChannelHeader/ChannelHeaderRelationButton.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@
2727
<script setup lang="ts">
2828
import { computed, onMounted, reactive, ref } from 'vue'
2929
30+
import { useEventListener } from '@vueuse/core'
31+
3032
import AIcon from '/@/components/UI/AIcon.vue'
31-
import useEventListener from '/@/composables/dom/useEventListener'
3233
import type { Point } from '/@/lib/basic/point'
3334
import { randomString } from '/@/lib/basic/randomString'
3435

src/components/Main/MainView/MessageElement/MessageEditor.vue

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ import useAttachments from '/@/components/Main/MainView/MessageInput/composables
5353
import useModifierKey from '/@/components/Main/MainView/MessageInput/composables/useModifierKey'
5454
import apis, { buildFilePathForPost, formatResizeError } from '/@/lib/apis'
5555
import { countLength } from '/@/lib/basic/string'
56-
import { unrefElement } from '/@/lib/dom/unrefElement'
5756
import { getResizedFile } from '/@/lib/resize'
5857
import { MESSAGE_MAX_LENGTH } from '/@/lib/validate'
5958
import { useToastStore } from '/@/store/ui/toast'
@@ -166,14 +165,12 @@ const { isModifierKeyPressed, onModifierKeyDown, onModifierKeyUp } =
166165
const textareaComponentRef =
167166
shallowRef<InstanceType<typeof MessageInputTextArea>>()
168167
169-
const textareaElement = computed(() =>
170-
unrefElement(textareaComponentRef.value?.textareaAutosizeRef)
171-
)
168+
const textareaRef = computed(() => textareaComponentRef.value?.textareaRef)
172169
173170
const containerEle = ref<HTMLDivElement>()
174171
const { toggleStampPicker } = useTextStampPickerInvoker(
175172
text,
176-
textareaElement,
173+
textareaRef,
177174
containerEle
178175
)
179176
@@ -185,7 +182,7 @@ const {
185182
} = useAttachmentsEditor(props, text)
186183
187184
onMounted(() => {
188-
textareaElement.value?.focus()
185+
textareaRef.value?.focus()
189186
})
190187
</script>
191188

src/components/Main/MainView/MessageInput/MessageInput.vue

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ import useFocus from '/@/composables/dom/useFocus'
7474
import useMessageInputState from '/@/composables/messageInputState/useMessageInputState'
7575
import useMessageInputStateAttachment from '/@/composables/messageInputState/useMessageInputStateAttachment'
7676
import useResponsive from '/@/composables/useResponsive'
77-
import { unrefElement } from '/@/lib/dom/unrefElement'
7877
import { useBrowserSettings } from '/@/store/app/browserSettings'
7978
import { useViewStateSenderStore } from '/@/store/domain/viewStateSenderStore'
8079
import { useChannelsStore } from '/@/store/entities/channels'
@@ -164,7 +163,7 @@ const textareaComponentRef = ref<InstanceType<typeof MessageInputTextArea>>()
164163
const containerEle = ref<HTMLDivElement>()
165164
const { toggleStampPicker } = useTextStampPickerInvoker(
166165
toRef(state, 'text'),
167-
computed(() => unrefElement(textareaComponentRef.value?.textareaAutosizeRef)),
166+
computed(() => textareaComponentRef.value?.textareaRef),
168167
containerEle
169168
)
170169

src/components/Main/MainView/MessageInput/MessageInputTextArea.vue

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,13 @@
3737
</template>
3838

3939
<script lang="ts" setup>
40-
import { computed, nextTick, ref, watch } from 'vue'
40+
import { computed, nextTick, shallowRef, watch } from 'vue'
4141
4242
import TextareaAutosize from '/@/components/UI/TextareaAutosize.vue'
4343
import useInsertText from '/@/composables/dom/useInsertText'
4444
import useResponsive from '/@/composables/useResponsive'
4545
import { isFirefox } from '/@/lib/dom/browser'
4646
import { getScrollbarWidth } from '/@/lib/dom/scrollbar'
47-
import { unrefElement } from '/@/lib/dom/unrefElement'
4847
import type { ChannelId } from '/@/types/entity-ids'
4948
5049
import DropdownSuggester from './DropdownSuggester/DropdownSuggester.vue'
@@ -93,10 +92,12 @@ const firefoxFlag = isFirefox()
9392
9493
const { isMobile } = useResponsive()
9594
96-
const textareaAutosizeRef = ref<InstanceType<typeof TextareaAutosize>>()
97-
const textareaRef = computed(() => unrefElement(textareaAutosizeRef))
95+
const textareaAutosizeRef = shallowRef<InstanceType<typeof TextareaAutosize>>()
96+
const textareaRef = computed(
97+
() => textareaAutosizeRef.value?.textareaEle ?? undefined
98+
)
9899
99-
defineExpose({ textareaAutosizeRef })
100+
defineExpose({ textareaRef, textareaAutosizeRef })
100101
101102
const { insertText } = useInsertText(textareaRef)
102103
const { onPaste } = usePaste(emit, insertText)

src/components/Main/MainView/MessagesScroller/MessagesScroller.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ import type { ComponentPublicInstance, Ref } from 'vue'
3737
import { nextTick, onMounted, reactive, shallowRef, watch } from 'vue'
3838
import { useRoute, useRouter } from 'vue-router'
3939
40+
import { useEventListener } from '@vueuse/core'
4041
import { throttle } from 'throttle-debounce'
4142
42-
import useEventListener from '/@/composables/dom/useEventListener'
4343
import { useOpenLink } from '/@/composables/useOpenLink'
4444
import { embeddingOrigin } from '/@/lib/apis'
4545
import { toggleSpoiler } from '/@/lib/markdown/spoiler'

src/components/Main/NavigationBar/composables/useNavigationResizer.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { computed, onUnmounted, ref } from 'vue'
22

3-
import useInnerWindowSize from '/@/composables/dom/useInnerWindowSize'
3+
import { useWindowSize } from '@vueuse/core'
4+
45
import { createAnimationFrameController } from '/@/lib/dom/animationFrame'
56
import {
67
MAX_NAVIGATION_WIDTH_RATIO,
@@ -12,9 +13,7 @@ import {
1213
const useNavigationResizer = () => {
1314
const animationFrame = createAnimationFrameController()
1415

15-
const { width: windowWidth } = useInnerWindowSize({
16-
fallback: { width: Infinity }
17-
})
16+
const { width: windowWidth } = useWindowSize({ initialWidth: Infinity })
1817

1918
const {
2019
resizerRef,

src/components/Main/PopupNavigatior/PopupNavigator.vue

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828
import { computed, reactive, readonly, shallowRef, watch } from 'vue'
2929
import { useRouter } from 'vue-router'
3030
31-
import useEventListener from '/@/composables/dom/useEventListener'
31+
import { useEventListener } from '@vueuse/core'
32+
3233
import useToggle from '/@/composables/utils/useToggle'
3334
3435
const popupNavigatorButtonId = 'popup-navigation-button'
@@ -48,8 +49,8 @@ const useWindowPointer = (
4849
},
4950
options?: boolean | AddEventListenerOptions | undefined
5051
) => {
51-
useEventListener(window, 'pointerdown', onPointerDown, options)
52-
useEventListener(window, 'pointerup', onPointerUp, options)
52+
useEventListener('pointerdown', onPointerDown, options)
53+
useEventListener('pointerup', onPointerUp, options)
5354
}
5455
5556
/**

src/components/UI/ClickOutside.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ import {
99
shallowRef
1010
} from 'vue'
1111

12-
import useEventListener from '/@/composables/dom/useEventListener'
12+
import { useEventListener } from '@vueuse/core'
13+
1314
import { unrefElement } from '/@/lib/dom/unrefElement'
1415
import { useModalStore } from '/@/store/ui/modal'
1516

@@ -54,7 +55,7 @@ export default defineComponent({
5455
clickOutside: (_e: PointerEvent) => true
5556
},
5657
setup(props, { slots, emit }) {
57-
const element = shallowRef<Element | ComponentPublicInstance>()
58+
const element = shallowRef<HTMLElement | ComponentPublicInstance>()
5859

5960
const { shouldShowModal } = useModalStore()
6061
const isMouseDown = ref(false)

0 commit comments

Comments
 (0)