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:
1 parent
4caab7e657
commit
7b16940b96
13 files changed
+673
-42
No files matched your search
@@ -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>
|
||||
Reference in new issue
Block a user