frontend/components/notes/content.vue

141 lines
5 KiB
Vue
Raw Normal View History

2024-11-30 02:19:32 +01:00
<template>
2024-12-07 15:16:45 +01:00
<Alert variant="warning" v-if="sensitive || contentWarning"
class="mb-4 py-2 px-4 grid grid-cols-[auto,1fr,auto] gap-2 items-center [&>svg~*]:pl-0 [&>svg+div]:translate-y-0 [&>svg]:static">
<AlertTitle class="sr-only">Sensitive content</AlertTitle>
<div>
<TriangleAlert class="size-4" />
</div>
2024-12-07 15:16:45 +01:00
<AlertDescription>
{{ contentWarning || "This content is sensitive" }}
</AlertDescription>
<Button @click="blurred = !blurred" variant="outline" size="sm">{{ blurred ? "Show" : "Hide" }}</Button>
</Alert>
<div ref="container" :class="cn('overflow-y-hidden relative duration-200', blurred && 'blur-md')" :style="{
maxHeight: collapsed ? '18rem' : `${container?.scrollHeight}px`,
}">
<div :class="[
'prose prose-sm block relative dark:prose-invert duration-200 !max-w-full break-words prose-a:no-underline prose-a:hover:underline',
$style.content,
]" v-html="content" v-render-emojis="emojis"></div>
<div v-if="isOverflowing && collapsed"
2024-12-07 15:16:45 +01:00
class="absolute inset-x-0 bottom-0 h-36 bg-gradient-to-t from-black/5 to-transparent rounded-b"></div>
<Button v-if="isOverflowing" @click="collapsed = !collapsed"
class="absolute bottom-2 right-1/2 translate-x-1/2">{{
2024-12-07 15:16:45 +01:00
collapsed
? `Show more${plainContent ? `${formattedCharacterCount} characters` : ""
}`
: "Show less"
}}</Button>
2024-11-30 02:19:32 +01:00
</div>
2024-11-30 16:39:02 +01:00
2024-12-07 15:16:45 +01:00
<Attachments v-if="attachments.length > 0" :attachments="attachments" :class="blurred && 'blur-xl'" />
2024-11-30 19:15:23 +01:00
<div v-if="quote" class="mt-4 rounded border overflow-hidden">
2024-11-30 16:39:02 +01:00
<Note :note="quote" :hide-actions="true" :small-layout="true" />
</div>
2024-11-30 02:19:32 +01:00
</template>
<script lang="ts" setup>
2024-12-07 15:16:45 +01:00
import { cn } from "@/lib/utils";
import type { Attachment, Emoji, Status } from "@versia/client/types";
2024-12-07 15:16:45 +01:00
import { TriangleAlert } from "lucide-vue-next";
import { Button, buttonVariants } from "~/components/ui/button";
import { Alert, AlertDescription, AlertTitle } from "../ui/alert";
import { Card, CardHeader } from "../ui/card";
import Attachments from "./attachments.vue";
2024-11-30 16:39:02 +01:00
import Note from "./note.vue";
2024-12-07 15:16:45 +01:00
const { content, plainContent, sensitive, contentWarning } = defineProps<{
plainContent?: string;
2024-11-30 02:19:32 +01:00
content: string;
2024-11-30 16:39:02 +01:00
quote?: NonNullable<Status["quote"]>;
emojis: Emoji[];
attachments: Attachment[];
2024-12-07 15:16:45 +01:00
sensitive: boolean;
contentWarning?: string;
2024-11-30 02:19:32 +01:00
}>();
const container = ref<HTMLDivElement | null>(null);
const collapsed = ref(true);
2024-12-07 15:16:45 +01:00
const blurred = ref(sensitive || !!contentWarning);
// max-h-72 is 18rem
const remToPx = (rem: number) =>
rem *
Number.parseFloat(
getComputedStyle(document.documentElement).fontSize || "16px",
);
const isOverflowing = computed(() => {
if (!container.value) {
return false;
}
return container.value.scrollHeight > remToPx(18);
});
const characterCount = plainContent?.length;
const formattedCharacterCount = characterCount
? new Intl.NumberFormat("en-us").format(characterCount)
: undefined;
2024-11-30 02:19:32 +01:00
</script>
<style module>
.content pre:has(code) {
word-wrap: normal;
background: transparent;
background-color: #ffffff0d;
2024-12-07 15:16:45 +01:00
border-radius: 0.25rem;
2024-11-30 02:19:32 +01:00
hyphens: none;
margin-top: 1rem;
overflow-x: auto;
2024-12-07 15:16:45 +01:00
padding: 0.75rem 1rem;
2024-11-30 02:19:32 +01:00
tab-size: 4;
white-space: pre;
word-break: normal;
word-spacing: normal;
--tw-ring-offset-shadow: var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color);
--tw-ring-shadow: var(--tw-ring-inset) 0 0 0 calc(1px + var(--tw-ring-offset-width)) var(--tw-ring-color);
box-shadow: var(--tw-ring-offset-shadow), var(--tw-ring-shadow), 0 0 #0000;
2024-12-07 15:16:45 +01:00
box-shadow: var(--tw-ring-offset-shadow), var(--tw-ring-shadow),
var(--tw-shadow, 0 0 #0000);
--tw-ring-color: hsla(0, 0%, 100%, 0.1);
2024-11-30 02:19:32 +01:00
}
.content pre code {
display: block;
2024-12-07 15:16:45 +01:00
padding: 0;
2024-11-30 02:19:32 +01:00
}
.content code:not(pre code)::after,
.content code:not(pre code)::before {
2024-12-07 15:16:45 +01:00
content: "";
2024-11-30 02:19:32 +01:00
}
2024-12-07 15:16:45 +01:00
.content ol li input[type="checkbox"],
.content ul li input[type="checkbox"] {
border-radius: 0.25rem;
margin-bottom: 0.2rem;
2024-12-07 15:16:45 +01:00
margin-right: 0.5rem;
margin-top: 0;
vertical-align: middle;
--tw-text-opacity: 1;
color: var(--theme-primary-400);
2024-11-30 02:19:32 +01:00
}
.content code:not(pre code) {
2024-12-07 15:16:45 +01:00
border-radius: 0.25rem;
padding: 0.25rem 0.5rem;
2024-11-30 02:19:32 +01:00
word-wrap: break-word;
background: transparent;
background-color: #ffffff0d;
hyphens: none;
margin-top: 1rem;
tab-size: 4;
--tw-ring-offset-shadow: var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color);
--tw-ring-shadow: var(--tw-ring-inset) 0 0 0 calc(1px + var(--tw-ring-offset-width)) var(--tw-ring-color);
box-shadow: var(--tw-ring-offset-shadow), var(--tw-ring-shadow), 0 0 #0000;
2024-12-07 15:16:45 +01:00
box-shadow: var(--tw-ring-offset-shadow), var(--tw-ring-shadow),
var(--tw-shadow, 0 0 #0000);
--tw-ring-color: hsla(0, 0%, 100%, 0.1);
2024-11-30 02:19:32 +01:00
}
2024-12-07 15:16:45 +01:00
</style>