feat(ui): code blocks and chat messages from shadcn-vue's code-block, message and bubble

This commit is contained in:
sam committed 2026-10-19 02:22:42 +11:00
1 parent d876c150eb
commit 63adbc71ef
67 files changed
+1770 -310

No files matched your search

+38
View File
@@ -0,0 +1,38 @@
<script setup lang="ts">
import { cn } from "@/lib/utils";
import {
CodeBlock,
CodeBlockActions,
CodeBlockContent,
CodeBlockCopyButton,
CodeBlockLine,
CodeBlockToken,
useHighlightedCode,
} from "@/components/ui/code-block";
/**
* Code or a payload with a copy button that appears on hover or focus. The
* text is shown verbatim and wrapped: stored payloads are mostly long unbroken
* tokens (URLs, hashes, base64), which must not push the panel past its edge.
* A language the highlighter does not know renders plain.
*/
const props = defineProps<{ code: string; lang?: string; class?: string }>();
const lines = useHighlightedCode(
() => props.code,
() => props.lang || "text",
);
</script>
<template>
<CodeBlock :class="cn('bg-muted', props.class)">
<CodeBlockActions>
<CodeBlockCopyButton :value="code" />
</CodeBlockActions>
<CodeBlockContent wrap class="max-h-[60vh] pe-10 text-xs">
<CodeBlockLine v-for="(line, index) in lines" :key="index">
<CodeBlockToken v-for="(token, i) in line" :key="i" :token="token" />
</CodeBlockLine>
</CodeBlockContent>
</CodeBlock>
</template>
-28
View File
@@ -1,28 +0,0 @@
<script setup lang="ts">
/**
* Inline JSON content with syntax highlighting, or the text verbatim when it
* is not JSON. Every source character survives either way: highlighting adds
* colour spans, never removes or rewrites text. Callers own the surrounding
* <pre> and its classes (borders, max height, wrap behaviour differ per
* surface); this renders only the content.
*/
import { computed } from "vue";
import { tokenClass, tokenizeJson } from "@/lib/json-tokens";
const props = defineProps<{ text: string }>();
const tokens = computed(() => tokenizeJson(props.text));
</script>
<template>
<template v-if="tokens">
<span
v-for="(token, i) in tokens"
:key="i"
:class="tokenClass(token.kind)"
>{{ token.text }}</span
>
</template>
<template v-else>{{ props.text }}</template>
</template>