1
0
mirror of https://github.com/misskey-dev/misskey.git synced 2026-05-20 09:25:33 +02:00
Files
misskey/packages/frontend/src/directives/follow-append.ts
かっこかり d98bf012b5 refactor(frontend): カスタムディレクティブの型付け (#16659)
* refactor(frontend): カスタムディレクティブの型付け

* fix
2025-10-19 11:36:00 +09:00

45 lines
1.1 KiB
TypeScript

/*
* SPDX-FileCopyrightText: syuilo and misskey-project
* SPDX-License-Identifier: AGPL-3.0-only
*/
import type { Directive } from 'vue';
import { getScrollContainer, getScrollPosition } from '@@/js/scroll.js';
interface HTMLElementWithRO extends HTMLElement {
_ro_?: ResizeObserver;
}
export const followAppendDirective = {
mounted(src, binding) {
if (binding.value === false) return;
let isBottom = true;
const container = getScrollContainer(src)!;
container.addEventListener('scroll', () => {
const pos = getScrollPosition(container);
const viewHeight = container.clientHeight;
const height = container.scrollHeight;
isBottom = (pos + viewHeight > height - 32);
}, { passive: true });
container.scrollTop = container.scrollHeight;
const ro = new ResizeObserver((entries, observer) => {
if (isBottom) {
const height = container.scrollHeight;
container.scrollTop = height;
}
});
ro.observe(src);
// TODO: 新たにプロパティを作るのをやめMapを使う
src._ro_ = ro;
},
unmounted(src) {
if (src._ro_) src._ro_.unobserve(src);
},
} as Directive<HTMLElementWithRO, boolean>;