2023-07-27 14:31:52 +09:00
|
|
|
/*
|
2024-02-14 00:59:27 +09:00
|
|
|
* SPDX-FileCopyrightText: syuilo and misskey-project
|
2023-07-27 14:31:52 +09:00
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
*/
|
|
|
|
|
2020-11-01 22:09:16 +09:00
|
|
|
import { Directive } from 'vue';
|
2023-09-19 16:37:43 +09:00
|
|
|
import { getScrollContainer, getScrollPosition } from '@/scripts/scroll.js';
|
2020-11-01 22:09:16 +09:00
|
|
|
|
|
|
|
export default {
|
|
|
|
mounted(src, binding, vn) {
|
2021-02-14 22:26:07 +09:00
|
|
|
if (binding.value === false) return;
|
|
|
|
|
|
|
|
let isBottom = true;
|
|
|
|
|
|
|
|
const container = getScrollContainer(src)!;
|
|
|
|
container.addEventListener('scroll', () => {
|
|
|
|
const pos = getScrollPosition(container);
|
2020-11-01 22:09:16 +09:00
|
|
|
const viewHeight = container.clientHeight;
|
|
|
|
const height = container.scrollHeight;
|
2021-02-14 22:26:07 +09:00
|
|
|
isBottom = (pos + viewHeight > height - 32);
|
|
|
|
}, { passive: true });
|
|
|
|
container.scrollTop = container.scrollHeight;
|
|
|
|
|
|
|
|
const ro = new ResizeObserver((entries, observer) => {
|
|
|
|
if (isBottom) {
|
|
|
|
const height = container.scrollHeight;
|
2020-11-01 22:09:16 +09:00
|
|
|
container.scrollTop = height;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
ro.observe(src);
|
|
|
|
|
|
|
|
// TODO: 新たにプロパティを作るのをやめMapを使う
|
|
|
|
src._ro_ = ro;
|
|
|
|
},
|
|
|
|
|
|
|
|
unmounted(src, binding, vn) {
|
2021-02-14 22:26:07 +09:00
|
|
|
if (src._ro_) src._ro_.unobserve(src);
|
2022-12-22 16:01:59 +09:00
|
|
|
},
|
2020-11-01 22:09:16 +09:00
|
|
|
} as Directive;
|