|
| 1 | +<script setup lang="ts"> |
| 2 | +import { useLocalStorage } from '@vueuse/core' |
| 3 | +import { allFeaturesMarkdown } from '~/constants' |
| 4 | +
|
| 5 | +definePageMeta({ footer: false }) |
| 6 | +
|
| 7 | +useSeoMeta({ |
| 8 | + title: 'Compare - Comark', |
| 9 | + description: 'Compare multiple Comark documents side by side.', |
| 10 | +}) |
| 11 | +
|
| 12 | +interface Col { |
| 13 | + id: string |
| 14 | + content: string |
| 15 | +} |
| 16 | +
|
| 17 | +const defaultCols: Col[] = [ |
| 18 | + { id: '1', content: allFeaturesMarkdown }, |
| 19 | + { id: '2', content: allFeaturesMarkdown }, |
| 20 | +] |
| 21 | +
|
| 22 | +const cols = useLocalStorage<Col[]>('comark:compare-cols', defaultCols, { |
| 23 | + serializer: { |
| 24 | + read: (v) => { |
| 25 | + try { |
| 26 | + const parsed = JSON.parse(v) |
| 27 | + return Array.isArray(parsed) && parsed.length >= 2 ? parsed : defaultCols |
| 28 | + } catch { |
| 29 | + return defaultCols |
| 30 | + } |
| 31 | + }, |
| 32 | + write: (v) => JSON.stringify(v), |
| 33 | + }, |
| 34 | +}) |
| 35 | +
|
| 36 | +// nextId must be higher than any existing id to avoid collisions after reload |
| 37 | +let nextId = cols.value.reduce((max, c) => Math.max(max, Number(c.id) || 0), 0) + 1 |
| 38 | +
|
| 39 | +function addCol() { |
| 40 | + cols.value = [...cols.value, { id: String(nextId++), content: '' }] |
| 41 | +} |
| 42 | +
|
| 43 | +function removeCol(id: string) { |
| 44 | + if (cols.value.length <= 2) return |
| 45 | + cols.value = cols.value.filter((c) => c.id !== id) |
| 46 | +} |
| 47 | +</script> |
| 48 | + |
| 49 | +<template> |
| 50 | + <ClientOnly> |
| 51 | + <div class="flex h-[calc(100vh-64px)] overflow-hidden"> |
| 52 | + <!-- Editor columns --> |
| 53 | + <div |
| 54 | + v-for="(col, i) in cols" |
| 55 | + :key="col.id" |
| 56 | + class="flex min-w-0 flex-1 flex-col border-l border-default first:border-l-0" |
| 57 | + > |
| 58 | + <div class="flex h-9 shrink-0 items-center gap-2 border-b border-default bg-elevated px-3"> |
| 59 | + <span class="text-xs text-muted">Editor {{ i + 1 }}</span> |
| 60 | + <UButton |
| 61 | + v-if="cols.length > 2" |
| 62 | + icon="i-lucide-x" |
| 63 | + variant="ghost" |
| 64 | + color="neutral" |
| 65 | + size="xs" |
| 66 | + class="ml-auto -mr-1" |
| 67 | + @click="removeCol(col.id)" |
| 68 | + /> |
| 69 | + </div> |
| 70 | + <div class="min-h-0 flex-1"> |
| 71 | + <Editor v-model="col.content" /> |
| 72 | + </div> |
| 73 | + </div> |
| 74 | + |
| 75 | + <!-- Add column --> |
| 76 | + <div class="flex w-10 shrink-0 items-center justify-center border-l border-default bg-elevated"> |
| 77 | + <UTooltip text="Add editor"> |
| 78 | + <UButton |
| 79 | + icon="i-lucide-plus" |
| 80 | + variant="ghost" |
| 81 | + color="neutral" |
| 82 | + size="sm" |
| 83 | + @click="addCol" |
| 84 | + /> |
| 85 | + </UTooltip> |
| 86 | + </div> |
| 87 | + </div> |
| 88 | + |
| 89 | + <template #fallback> |
| 90 | + <div class="flex h-[calc(100vh-64px)] overflow-hidden"> |
| 91 | + <div |
| 92 | + v-for="i in 2" |
| 93 | + :key="i" |
| 94 | + class="flex flex-1 flex-col border-l border-default first:border-l-0" |
| 95 | + > |
| 96 | + <div class="h-9 border-b border-default bg-elevated" /> |
| 97 | + <div class="flex-1 p-4"> |
| 98 | + <USkeleton class="h-full w-full" /> |
| 99 | + </div> |
| 100 | + </div> |
| 101 | + <div class="w-10 shrink-0 border-l border-default bg-elevated" /> |
| 102 | + </div> |
| 103 | + </template> |
| 104 | + </ClientOnly> |
| 105 | +</template> |
0 commit comments