- Safe Areas: Header unter Statusleiste/Notch, Ränder im Querformat
- Touch: alle Buttons mind. 44 px, kein Doppeltipp-Zoom-Verzug
- ab 1024 px Breite zwei Spalten für die Clip-Karten
- relative Zeitangaben ('vor 5 Min.'), genaues Datum als Tooltip
- kurze Einblendungen für Speichern, Löschen, Anheften und Fehler
- nach über 60 s im Hintergrund wird die Liste neu geladen
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
148 lines
3.5 KiB
Vue
148 lines
3.5 KiB
Vue
<script setup lang="ts">
|
|
import { computed, ref, watch } from 'vue'
|
|
|
|
import type { ClipKind } from '@/api/types'
|
|
import { useClipsStore } from '@/stores/clips'
|
|
import { useToastStore } from '@/stores/toast'
|
|
import { readClipboardText } from '@/utils/clipboard'
|
|
import { detectLanguage, LANGUAGES } from '@/utils/highlight'
|
|
|
|
const store = useClipsStore()
|
|
const toast = useToastStore()
|
|
|
|
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'
|
|
})
|
|
|
|
// Content shared from another app (share target) arrives as a draft
|
|
watch(
|
|
() => store.draft,
|
|
(draft) => {
|
|
if (!draft) return
|
|
content.value = draft
|
|
store.draft = null
|
|
},
|
|
{ immediate: true },
|
|
)
|
|
|
|
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
|
|
toast.show('Gespeichert')
|
|
} 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>
|