From bc55af91654e15da574bc4c0b736aa585b94030f Mon Sep 17 00:00:00 2001 From: kakkokari-gtyih <67428053+kakkokari-gtyih@users.noreply.github.com> Date: Sat, 2 Nov 2024 16:49:48 +0900 Subject: [PATCH] refactor --- packages/frontend/src/directives/appear.ts | 2 ++ packages/frontend/src/directives/get-size.ts | 3 +++ packages/frontend/src/directives/hotkey.ts | 8 ++++++++ packages/frontend/src/directives/tooltip.ts | 11 +++++++---- packages/frontend/src/directives/user-preview.ts | 1 + 5 files changed, 21 insertions(+), 4 deletions(-) diff --git a/packages/frontend/src/directives/appear.ts b/packages/frontend/src/directives/appear.ts index af1af491e5..243d54a41e 100644 --- a/packages/frontend/src/directives/appear.ts +++ b/packages/frontend/src/directives/appear.ts @@ -20,10 +20,12 @@ export const vAppear = { observer.observe(src); + //@ts-expect-error HTMLElementにプロパティを追加している src._observer_ = observer; }, async unmounted(src) { + //@ts-expect-error HTMLElementにプロパティを追加している src._observer_?.disconnect(); }, } satisfies VAppear as VAppear; diff --git a/packages/frontend/src/directives/get-size.ts b/packages/frontend/src/directives/get-size.ts index f25e4cfeed..b6d298cf2c 100644 --- a/packages/frontend/src/directives/get-size.ts +++ b/packages/frontend/src/directives/get-size.ts @@ -15,6 +15,8 @@ type VGetSize = ObjectDirective unknown) export const vGetSize = { async mounted(src, binding) { + if (!binding.value) return; + const resize = new ResizeObserver(() => { calc(src); }); @@ -25,6 +27,7 @@ export const vGetSize = { }, async unmounted(src, binding) { + if (!binding.value) return; binding.value(0, 0); const info = mountings.get(src); if (!info) return; diff --git a/packages/frontend/src/directives/hotkey.ts b/packages/frontend/src/directives/hotkey.ts index 16314742fd..4cb16ad0f7 100644 --- a/packages/frontend/src/directives/hotkey.ts +++ b/packages/frontend/src/directives/hotkey.ts @@ -16,21 +16,29 @@ export const vHotkey = { import('@/scripts/hotkey.js'), ]); + //@ts-expect-error HTMLElementにプロパティを追加している src._hotkey_global = binding.modifiers.global === true; + //@ts-expect-error HTMLElementにプロパティを追加している src._keyHandler = makeHotkey(binding.value); + //@ts-expect-error HTMLElementにプロパティを追加している if (src._hotkey_global) { + //@ts-expect-error HTMLElementにプロパティを追加している document.addEventListener('keydown', src._keyHandler, { passive: false }); } else { + //@ts-expect-error HTMLElementにプロパティを追加している src.addEventListener('keydown', src._keyHandler, { passive: false }); } }, async unmounted(src) { + //@ts-expect-error HTMLElementにプロパティを追加している if (src._hotkey_global) { + //@ts-expect-error HTMLElementにプロパティを追加している document.removeEventListener('keydown', src._keyHandler); } else { + //@ts-expect-error HTMLElementにプロパティを追加している src.removeEventListener('keydown', src._keyHandler); } }, diff --git a/packages/frontend/src/directives/tooltip.ts b/packages/frontend/src/directives/tooltip.ts index 6957533e5e..bcc3e25f05 100644 --- a/packages/frontend/src/directives/tooltip.ts +++ b/packages/frontend/src/directives/tooltip.ts @@ -25,7 +25,8 @@ export const vTooltip = { const delay = binding.modifiers.noDelay ? 0 : 100; - const self = (src as any)._tooltipDirective_ = {} as any; + //@ts-expect-error HTMLElementにプロパティを追加している + const self = src._tooltipDirective_ = {} as any; self.text = binding.value as string; self._close = null; @@ -47,7 +48,7 @@ export const vTooltip = { ev.stopPropagation(); alert({ type: 'info', - text: binding.value, + text: binding.value ?? '', }); return false; }); @@ -105,12 +106,14 @@ export const vTooltip = { }, async updated(src, binding) { - const self = (src as any)._tooltipDirective_; + //@ts-expect-error HTMLElementにプロパティを追加している + const self = src._tooltipDirective_; self.text = binding.value as string; }, async unmounted(src) { - const self = (src as any)._tooltipDirective_; + //@ts-expect-error HTMLElementにプロパティを追加している + const self = src._tooltipDirective_; window.clearInterval(self.checkTimer); }, } satisfies VTooltip as VTooltip; diff --git a/packages/frontend/src/directives/user-preview.ts b/packages/frontend/src/directives/user-preview.ts index 5f3baa4aef..b2006b178f 100644 --- a/packages/frontend/src/directives/user-preview.ts +++ b/packages/frontend/src/directives/user-preview.ts @@ -22,6 +22,7 @@ export const vUserPreview = { async unmounted(src, binding) { if (binding.value == null) return; + //@ts-expect-error HTMLElementにプロパティを追加している const self = src._userPreviewDirective_; self.preview.detach(); },