This commit is contained in:
kakkokari-gtyih 2024-11-02 16:49:48 +09:00
parent 1c34a03b7a
commit bc55af9165
5 changed files with 21 additions and 4 deletions

View file

@ -20,10 +20,12 @@ export const vAppear = {
observer.observe(src); observer.observe(src);
//@ts-expect-error HTMLElementにプロパティを追加している
src._observer_ = observer; src._observer_ = observer;
}, },
async unmounted(src) { async unmounted(src) {
//@ts-expect-error HTMLElementにプロパティを追加している
src._observer_?.disconnect(); src._observer_?.disconnect();
}, },
} satisfies VAppear as VAppear; } satisfies VAppear as VAppear;

View file

@ -15,6 +15,8 @@ type VGetSize = ObjectDirective<HTMLElement, ((w: number, h: number) => unknown)
export const vGetSize = { export const vGetSize = {
async mounted(src, binding) { async mounted(src, binding) {
if (!binding.value) return;
const resize = new ResizeObserver(() => { const resize = new ResizeObserver(() => {
calc(src); calc(src);
}); });
@ -25,6 +27,7 @@ export const vGetSize = {
}, },
async unmounted(src, binding) { async unmounted(src, binding) {
if (!binding.value) return;
binding.value(0, 0); binding.value(0, 0);
const info = mountings.get(src); const info = mountings.get(src);
if (!info) return; if (!info) return;

View file

@ -16,21 +16,29 @@ export const vHotkey = {
import('@/scripts/hotkey.js'), import('@/scripts/hotkey.js'),
]); ]);
//@ts-expect-error HTMLElementにプロパティを追加している
src._hotkey_global = binding.modifiers.global === true; src._hotkey_global = binding.modifiers.global === true;
//@ts-expect-error HTMLElementにプロパティを追加している
src._keyHandler = makeHotkey(binding.value); src._keyHandler = makeHotkey(binding.value);
//@ts-expect-error HTMLElementにプロパティを追加している
if (src._hotkey_global) { if (src._hotkey_global) {
//@ts-expect-error HTMLElementにプロパティを追加している
document.addEventListener('keydown', src._keyHandler, { passive: false }); document.addEventListener('keydown', src._keyHandler, { passive: false });
} else { } else {
//@ts-expect-error HTMLElementにプロパティを追加している
src.addEventListener('keydown', src._keyHandler, { passive: false }); src.addEventListener('keydown', src._keyHandler, { passive: false });
} }
}, },
async unmounted(src) { async unmounted(src) {
//@ts-expect-error HTMLElementにプロパティを追加している
if (src._hotkey_global) { if (src._hotkey_global) {
//@ts-expect-error HTMLElementにプロパティを追加している
document.removeEventListener('keydown', src._keyHandler); document.removeEventListener('keydown', src._keyHandler);
} else { } else {
//@ts-expect-error HTMLElementにプロパティを追加している
src.removeEventListener('keydown', src._keyHandler); src.removeEventListener('keydown', src._keyHandler);
} }
}, },

View file

@ -25,7 +25,8 @@ export const vTooltip = {
const delay = binding.modifiers.noDelay ? 0 : 100; 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.text = binding.value as string;
self._close = null; self._close = null;
@ -47,7 +48,7 @@ export const vTooltip = {
ev.stopPropagation(); ev.stopPropagation();
alert({ alert({
type: 'info', type: 'info',
text: binding.value, text: binding.value ?? '',
}); });
return false; return false;
}); });
@ -105,12 +106,14 @@ export const vTooltip = {
}, },
async updated(src, binding) { async updated(src, binding) {
const self = (src as any)._tooltipDirective_; //@ts-expect-error HTMLElementにプロパティを追加している
const self = src._tooltipDirective_;
self.text = binding.value as string; self.text = binding.value as string;
}, },
async unmounted(src) { async unmounted(src) {
const self = (src as any)._tooltipDirective_; //@ts-expect-error HTMLElementにプロパティを追加している
const self = src._tooltipDirective_;
window.clearInterval(self.checkTimer); window.clearInterval(self.checkTimer);
}, },
} satisfies VTooltip as VTooltip; } satisfies VTooltip as VTooltip;

View file

@ -22,6 +22,7 @@ export const vUserPreview = {
async unmounted(src, binding) { async unmounted(src, binding) {
if (binding.value == null) return; if (binding.value == null) return;
//@ts-expect-error HTMLElementにプロパティを追加している
const self = src._userPreviewDirective_; const self = src._userPreviewDirective_;
self.preview.detach(); self.preview.detach();
}, },