misskey/packages/frontend/src/components/MkNoteMediaGrid.vue
Kissa Ruokanen 23bb992121
enhance(frontend): scroll position restoration in the drive page and "Files" tab on the user page (#17497)
* fix: ユーザーページのFilesタブでスクロール位置が正しく復元されない問題を修正

* fix: ドライブページでスクロール位置が保持されない問題を修正

* fix: 変更履歴の文言を調整

* fix: 同じファイルを複数ノートに添付した場合にスクロール位置が先頭要素へ戻る問題を修正

* fix: viewPosition の計算誤りと KeepAlive によるスクロール位置消失を修正

* fix: スクロール位置復元が下端要素の見切れを引き起こす問題を修正

* fix: スクロール位置復元がコンテナ高さ変化時にオーバーシュートする問題を修正

* Update CHANGELOG.md

Co-authored-by: かっこかり <67428053+kakkokari-gtyih@users.noreply.github.com>

* fix: 最下部スクロール時にスクロール位置のキャプチャが失敗する問題を修正

min-height による空白領域にビューポート中央が入るケースで anchorId が更新
されず、復元が古い位置に飛んでしまう問題を修正した。
アンカー選択条件を「中央を跨ぐ要素のみ」から「上端が中央以下の最も下の要素」
に変更することで、空白領域スクロール時も最後のアイテムを正しくキャプチャできる。

* Update CHANGELOG.md

* fix: MkNoteMediaGrid のスクロールアンカーをノートIDとファイルIDの複合キーに変更

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* refactor: anchorIndex による重複アンカー対応を削除

* refactor: unused になった onUnmounted の import を削除

* refactor: querySelectorAll/querySelector にジェネリクスを渡し型キャストを削除

---------

Co-authored-by: かっこかり <67428053+kakkokari-gtyih@users.noreply.github.com>
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-03 09:07:17 +09:00

125 lines
2.8 KiB
Vue

<!--
SPDX-FileCopyrightText: syuilo and misskey-project
SPDX-License-Identifier: AGPL-3.0-only
-->
<template>
<template v-for="file in note.files">
<div
v-if="isHiding(file)"
:class="[$style.filePreview, { [$style.square]: square }]"
:data-scroll-anchor="`${note.id}:${file.id}`"
@click="reveal(file)"
>
<MkDriveFileThumbnail
:file="file"
fit="cover"
:highlightWhenSensitive="prefer.s.highlightSensitiveMedia"
:forceBlurhash="true"
:large="true"
:class="$style.file"
/>
<div :class="$style.sensitive">
<div>
<div v-if="file.isSensitive"><i class="ti ti-eye-exclamation"></i> {{ i18n.ts.sensitive }}{{ prefer.s.dataSaver.media && file.size ? ` (${bytes(file.size)})` : '' }}</div>
<div v-else><i class="ti ti-photo"></i> {{ prefer.s.dataSaver.media && file.size ? bytes(file.size) : i18n.ts.image }}</div>
<div>{{ i18n.ts.clickToShow }}</div>
</div>
</div>
</div>
<MkA v-else :class="[$style.filePreview, { [$style.square]: square }]" :data-scroll-anchor="`${note.id}:${file.id}`" :to="notePage(note)">
<MkDriveFileThumbnail
:file="file"
fit="cover"
:highlightWhenSensitive="prefer.s.highlightSensitiveMedia"
:large="true"
:class="$style.file"
/>
</MkA>
</template>
</template>
<script lang="ts" setup>
import { ref } from 'vue';
import * as Misskey from 'misskey-js';
import { notePage } from '@/filters/note.js';
import { i18n } from '@/i18n.js';
import { prefer } from '@/preferences.js';
import { shouldHideFileByDefault, canRevealFile } from '@/utility/sensitive-file.js';
import bytes from '@/filters/bytes.js';
import MkDriveFileThumbnail from '@/components/MkDriveFileThumbnail.vue';
defineProps<{
note: Misskey.entities.Note;
square?: boolean;
}>();
const showingFiles = ref<Set<string>>(new Set());
function isHiding(file: Misskey.entities.DriveFile) {
if (shouldHideFileByDefault(file) && !showingFiles.value.has(file.id)) {
if (!file.isSensitive && !file.type.startsWith('image/')) {
return false;
}
return true;
}
return false;
}
async function reveal(file: Misskey.entities.DriveFile) {
if (!(await canRevealFile(file))) {
return;
}
showingFiles.value.add(file.id);
}
</script>
<style lang="scss" module>
.square {
width: 100%;
height: auto;
aspect-ratio: 1;
}
.filePreview {
position: relative;
height: 128px;
border-radius: calc(var(--MI-radius) / 2);
overflow: clip;
&:hover {
text-decoration: none;
}
&.square {
height: 100%;
}
}
.file {
width: 100%;
height: 100%;
border-radius: calc(var(--MI-radius) / 2);
}
.sensitive {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
display: grid;
place-items: center;
font-size: 0.8em;
text-align: center;
padding: 8px;
border-radius: calc(var(--MI-radius) / 2);
box-sizing: border-box;
color: #fff;
background: rgba(0, 0, 0, 0.5);
backdrop-filter: blur(5px);
cursor: pointer;
}
</style>