feat: clip-liste mit schnell-eingabe und kopieren

- Startseite zeigt Clips, angeheftete zuerst, mit 'Weitere laden'
- Schnell-Eingabe mit Text/Code, Spracherkennung und Einfügen aus der Zwischenablage
- Kopieren-Button mit Clipboard API und Ausweichlösung
- Syntax-Highlighting mit highlight.js (nur die 24 unterstützten Sprachen)
- Pinia-Store für Clips als Grundlage für den Live-Sync

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
dbildhauerandClaude Opus 5.5 committed 2026-10-25 11:04:33 +01:00
1 parent 4caab7e657
commit 7b16940b96
13 files changed
+673 -42

No files matched your search

+126
View File
@@ -0,0 +1,126 @@
<script setup lang="ts">
import { computed, ref } from 'vue'
import { RouterLink } from 'vue-router'
import type { Clip } from '@/api/types'
import CopyButton from '@/components/CopyButton.vue'
import { formatDateTime } from '@/utils/format'
import { highlight, languageLabel } from '@/utils/highlight'
const props = defineProps<{ clip: Clip }>()
const emit = defineEmits<{ togglePin: []; remove: [] }>()
const PREVIEW_LINES = 10
const PREVIEW_CHARS = 2000
const expanded = ref(false)
const lines = computed(() => props.clip.content.split('\n'))
const isLong = computed(
() => lines.value.length > PREVIEW_LINES || props.clip.content.length > PREVIEW_CHARS,
)
const visibleText = computed(() =>
expanded.value || !isLong.value
? props.clip.content
: lines.value.slice(0, PREVIEW_LINES).join('\n').slice(0, PREVIEW_CHARS),
)
// Highlight only what is visible; large clips stay cheap until expanded
const html = computed(() =>
props.clip.kind === 'code' ? highlight(visibleText.value, props.clip.language) : null,
)
</script>
<template>
<article class="card clip" :class="{ pinned: clip.pinned }">
<header class="clip-head">
<div class="clip-meta">
<strong v-if="clip.title" class="clip-title">{{ clip.title }}</strong>
<span v-if="clip.pinned" class="badge accent">angeheftet</span>
<span v-if="clip.kind === 'code'" class="badge">{{ languageLabel(clip.language) }}</span>
</div>
<span class="muted small">{{ formatDateTime(clip.updated_at) }}</span>
</header>
<!-- eslint-disable-next-line vue/no-v-html -- highlight.js output is escaped -->
<pre v-if="html !== null" class="content code"><code class="hljs" v-html="html"></code></pre>
<pre v-else class="content text">{{ visibleText }}</pre>
<button v-if="isLong" type="button" class="link" @click="expanded = !expanded">
{{ expanded ? 'weniger' : `mehr (${lines.length} Zeilen)` }}
</button>
<footer class="actions">
<CopyButton :text="clip.content" />
<RouterLink :to="`/clips/${clip.id}`" class="button-link small">Bearbeiten</RouterLink>
<button type="button" class="small" @click="emit('togglePin')">
{{ clip.pinned ? 'Lösen' : 'Anheften' }}
</button>
<button type="button" class="small danger" @click="emit('remove')">Löschen</button>
</footer>
</article>
</template>
<style scoped>
.clip.pinned {
border-color: var(--accent);
}
.clip-head {
display: flex;
flex-wrap: wrap;
align-items: baseline;
justify-content: space-between;
gap: 0.25rem 1rem;
margin-bottom: 0.5rem;
}
.clip-meta {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 0.5rem;
}
.clip-title {
overflow-wrap: anywhere;
}
.small {
font-size: 0.85rem;
}
.content {
margin: 0;
padding: 0.75rem;
border-radius: calc(var(--radius) - 4px);
background: var(--bg);
overflow-x: auto;
font-size: 0.9rem;
line-height: 1.45;
}
.content.text {
white-space: pre-wrap;
overflow-wrap: anywhere;
font-family: inherit;
}
.content code.hljs {
padding: 0;
background: transparent;
}
.link {
min-height: 32px;
padding: 0;
border: none;
color: var(--accent);
}
.actions {
display: flex;
flex-wrap: wrap;
gap: 0.5rem;
margin-top: 0.75rem;
}
</style>
+43
View File
@@ -0,0 +1,43 @@
<script setup lang="ts">
import { ref } from 'vue'
import { copyText } from '@/utils/clipboard'
const props = defineProps<{ text: string }>()
const state = ref<'idle' | 'copied' | 'failed'>('idle')
let timer: ReturnType<typeof setTimeout> | undefined
async function copy(): Promise<void> {
try {
await copyText(props.text)
state.value = 'copied'
} catch {
state.value = 'failed'
}
clearTimeout(timer)
timer = setTimeout(() => (state.value = 'idle'), 1500)
}
</script>
<template>
<button type="button" class="primary small copy" :class="state" @click="copy">
{{ state === 'copied' ? 'Kopiert ✓' : state === 'failed' ? 'Fehlgeschlagen' : 'Kopieren' }}
</button>
</template>
<style scoped>
.copy {
min-width: 7.5rem;
}
.copy.copied {
background: var(--ok);
border-color: var(--ok);
}
.copy.failed {
background: var(--error);
border-color: var(--error);
}
</style>
+133
View File
@@ -0,0 +1,133 @@
<script setup lang="ts">
import { computed, ref, watch } from 'vue'
import type { ClipKind } from '@/api/types'
import { useClipsStore } from '@/stores/clips'
import { readClipboardText } from '@/utils/clipboard'
import { detectLanguage, LANGUAGES } from '@/utils/highlight'
const store = useClipsStore()
const content = ref('')
const kind = ref<ClipKind>('text')
const language = ref<string>('plaintext')
const languageTouched = ref(false)
const busy = ref(false)
const error = ref<string | null>(null)
const canSave = computed(() => content.value.trim().length > 0 && !busy.value)
// Suggest a language while typing until the user picks one
watch([content, kind], () => {
if (kind.value !== 'code' || languageTouched.value) return
language.value = detectLanguage(content.value) ?? 'plaintext'
})
async function paste(): Promise<void> {
error.value = null
try {
const text = await readClipboardText()
content.value = text
if (!languageTouched.value && detectLanguage(text)) kind.value = 'code'
} catch (e) {
error.value = e instanceof Error ? e.message : String(e)
}
}
async function save(): Promise<void> {
if (!canSave.value) return
busy.value = true
error.value = null
try {
await store.create({
content: content.value,
kind: kind.value,
language: kind.value === 'code' ? language.value : null,
})
content.value = ''
kind.value = 'text'
languageTouched.value = false
} catch (e) {
error.value = e instanceof Error ? e.message : String(e)
} finally {
busy.value = false
}
}
</script>
<template>
<form class="card quick-add" @submit.prevent="save">
<textarea
v-model="content"
:class="{ mono: kind === 'code' }"
rows="4"
placeholder="Text oder Code einfügen …"
autocapitalize="off"
spellcheck="false"
@keydown.enter.ctrl.prevent="save"
@keydown.enter.meta.prevent="save"
></textarea>
<div class="row">
<div class="segmented" role="radiogroup" aria-label="Art">
<button
type="button"
role="radio"
:aria-checked="kind === 'text'"
:class="{ active: kind === 'text' }"
@click="kind = 'text'"
>
Text
</button>
<button
type="button"
role="radio"
:aria-checked="kind === 'code'"
:class="{ active: kind === 'code' }"
@click="kind = 'code'"
>
Code
</button>
</div>
<select
v-if="kind === 'code'"
v-model="language"
aria-label="Sprache"
class="language"
@change="languageTouched = true"
>
<option v-for="l in LANGUAGES" :key="l.id" :value="l.id">{{ l.label }}</option>
</select>
<div class="spacer"></div>
<button type="button" @click="paste">Einfügen</button>
<button type="submit" class="primary" :disabled="!canSave">Speichern</button>
</div>
<p v-if="error" class="error" role="alert">{{ error }}</p>
</form>
</template>
<style scoped>
.quick-add {
display: grid;
gap: 0.75rem;
}
.row {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 0.5rem;
}
.spacer {
flex: 1;
}
.language {
width: auto;
min-width: 9rem;
}
.error {
margin: 0;
}
</style>