refactor
This commit is contained in:
parent
af50d7353d
commit
b8243c9448
|
@ -289,11 +289,7 @@ const renoteCollapsed = ref(
|
||||||
|
|
||||||
// oversized note collapsing
|
// oversized note collapsing
|
||||||
const collapsibleArea = ref(null);
|
const collapsibleArea = ref(null);
|
||||||
const collapseSize = ({
|
const collapseSize = defaultStore.state.collapsingNoteSize;
|
||||||
small: 9,
|
|
||||||
medium: 13.5,
|
|
||||||
large: 18,
|
|
||||||
})[defaultStore.state.collapsingNoteSize] ?? 13.5;
|
|
||||||
const isLong = ref(true);
|
const isLong = ref(true);
|
||||||
switch (collapsingNoteCondition) {
|
switch (collapsingNoteCondition) {
|
||||||
case 'detailedCalculation':
|
case 'detailedCalculation':
|
||||||
|
|
|
@ -4,7 +4,8 @@ SPDX-License-Identifier: AGPL-3.0-only
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div :class="[$style.root, { [$style.collapsed]: collapsed }]">
|
<div :class="[$style.root, { [$style.collapsed]: collapsed }]" :style="{ 'max-height': collapsed ? `${collapseSize}em` : undefined }">
|
||||||
|
<div ref="collapsibleArea">
|
||||||
<div>
|
<div>
|
||||||
<span v-if="note.isHidden" style="opacity: 0.5">({{ i18n.ts.private }})</span>
|
<span v-if="note.isHidden" style="opacity: 0.5">({{ i18n.ts.private }})</span>
|
||||||
<span v-if="note.deletedAt" style="opacity: 0.5">({{ i18n.ts.deletedNote }})</span>
|
<span v-if="note.deletedAt" style="opacity: 0.5">({{ i18n.ts.deletedNote }})</span>
|
||||||
|
@ -27,6 +28,7 @@ SPDX-License-Identifier: AGPL-3.0-only
|
||||||
<span :class="$style.showLessLabel">{{ i18n.ts.showLess }}</span>
|
<span :class="$style.showLessLabel">{{ i18n.ts.showLess }}</span>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
|
@ -36,7 +38,8 @@ import * as mfm from 'mfm-js';
|
||||||
import MkMediaList from '@/components/MkMediaList.vue';
|
import MkMediaList from '@/components/MkMediaList.vue';
|
||||||
import MkPoll from '@/components/MkPoll.vue';
|
import MkPoll from '@/components/MkPoll.vue';
|
||||||
import { i18n } from '@/i18n.js';
|
import { i18n } from '@/i18n.js';
|
||||||
import { shouldCollapsed } from '@/scripts/collapsed.js';
|
import { defaultStore } from '@/store.js';
|
||||||
|
import { shouldCollapseLegacy, shouldCollapse } from '@/scripts/collapsed.js';
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
note: Misskey.entities.Note;
|
note: Misskey.entities.Note;
|
||||||
|
@ -44,10 +47,34 @@ const props = defineProps<{
|
||||||
|
|
||||||
const ast = computed(() => props.note.text ? mfm.parse(props.note.text) : []);
|
const ast = computed(() => props.note.text ? mfm.parse(props.note.text) : []);
|
||||||
|
|
||||||
|
// oversized note collapsing
|
||||||
|
const collapsingNoteCondition = defaultStore.state.collapsingNoteCondition;
|
||||||
|
const collapseSize = defaultStore.state.collapsingNoteSize;
|
||||||
|
const collapsibleArea = ref(null);
|
||||||
|
if (collapsingNoteCondition === 'seeRenderedSize') {
|
||||||
|
onMounted(() => {
|
||||||
|
const current = collapsibleArea.value.clientHeight;
|
||||||
|
const limit = collapseSize * parseFloat(getComputedStyle(collapsibleArea.value).fontSize);
|
||||||
|
isLong.value = current > limit;
|
||||||
|
collapsed.value &&= isLong.value;
|
||||||
|
})
|
||||||
|
}
|
||||||
|
const isLong = ref(true);
|
||||||
|
switch (collapsingNoteCondition) {
|
||||||
|
case 'detailedCalculation':
|
||||||
// eslint-disable-next-line vue/no-setup-props-destructure
|
// eslint-disable-next-line vue/no-setup-props-destructure
|
||||||
const isLong = shouldCollapsed(props.note, ast.value);
|
isLong.value = shouldCollapse(props.note, collapseSize, ast.value);
|
||||||
|
break;
|
||||||
const collapsed = ref(isLong);
|
case 'seeRenderedSize':
|
||||||
|
break;
|
||||||
|
// fail safe
|
||||||
|
case 'legacyCalculation':
|
||||||
|
default:
|
||||||
|
// eslint-disable-next-line vue/no-setup-props-destructure
|
||||||
|
isLong.value = shouldCollapseLegacy(props.note, []);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
const collapsed = ref(isLong.value);
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="scss" module>
|
<style lang="scss" module>
|
||||||
|
@ -56,7 +83,6 @@ const collapsed = ref(isLong);
|
||||||
|
|
||||||
&.collapsed {
|
&.collapsed {
|
||||||
position: relative;
|
position: relative;
|
||||||
max-height: 9em;
|
|
||||||
overflow: clip;
|
overflow: clip;
|
||||||
|
|
||||||
> .fade {
|
> .fade {
|
||||||
|
|
|
@ -100,9 +100,9 @@ SPDX-License-Identifier: AGPL-3.0-only
|
||||||
</MkRadios>
|
</MkRadios>
|
||||||
<MkRadios v-model="collapsingNoteSize" v-if="collapsingNoteCondition !== 'legacyCalculation'">
|
<MkRadios v-model="collapsingNoteSize" v-if="collapsingNoteCondition !== 'legacyCalculation'">
|
||||||
<template #label>{{ i18n.ts.collapsingNoteSize }}</template>
|
<template #label>{{ i18n.ts.collapsingNoteSize }}</template>
|
||||||
<option value="large">{{ i18n.ts.large }}</option>
|
<option :value="18">{{ i18n.ts.large }}</option>
|
||||||
<option value="medium">{{ i18n.ts.medium }}</option>
|
<option :value="13.5">{{ i18n.ts.medium }}</option>
|
||||||
<option value="small">{{ i18n.ts.small }}</option>
|
<option :value="9">{{ i18n.ts.small }}</option>
|
||||||
</MkRadios>
|
</MkRadios>
|
||||||
</div>
|
</div>
|
||||||
</FormSection>
|
</FormSection>
|
||||||
|
|
|
@ -384,7 +384,7 @@ export const defaultStore = markRaw(new Storage('base', {
|
||||||
},
|
},
|
||||||
collapsingNoteSize: {
|
collapsingNoteSize: {
|
||||||
where: 'device',
|
where: 'device',
|
||||||
default: 'medium' as 'small' | 'medium' | 'large',
|
default: 13.5,
|
||||||
},
|
},
|
||||||
collapsingNoteCondition: {
|
collapsingNoteCondition: {
|
||||||
where: 'device',
|
where: 'device',
|
||||||
|
|
Loading…
Reference in New Issue