{
  "$schema": "https://shadcn-vue.com/schema/registry-item.json",
  "name": "your-data",
  "type": "registry:block",
  "title": "Your data",
  "description": "Download everything kept about the user, or delete it after a confirmation.",
  "author": "spotstrap (https://kodentuzo.com/spotstrap)",
  "dependencies": [
    "@kodentuzo/spotstrap@^0.3.1",
    "@kodentuzo/spotkit@^0.3.0"
  ],
  "registryDependencies": [
    "button",
    "card",
    "alert-dialog"
  ],
  "files": [
    {
      "path": "components/YourData.vue",
      "type": "registry:component",
      "content": "<script setup lang=\"ts\">\n// Download everything kept about the user, or delete it after a confirmation. Talks to the user\n// pool on the app's domain (@kodentuzo/spotkit/client); `exportApp` adds the app's own rows.\nimport { deleteMe, exportMe } from '@kodentuzo/spotkit/client'\nimport { createYourData, en, type Messages, type YourDataState } from '@kodentuzo/spotstrap/blocks'\nimport { computed, onBeforeUnmount, ref } from 'vue'\nimport {\n  AlertDialog,\n  AlertDialogAction,\n  AlertDialogCancel,\n  AlertDialogContent,\n  AlertDialogDescription,\n  AlertDialogFooter,\n  AlertDialogHeader,\n  AlertDialogTitle,\n} from '@/components/ui/alert-dialog'\nimport { Button } from '@/components/ui/button'\nimport { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'\n\nconst props = defineProps<{\n  appName: string\n  /** The app's own rows about the user, from its server. */\n  exportApp?: () => Promise<unknown>\n  messages?: Messages\n}>()\nconst emit = defineEmits<{ deleted: [] }>()\n\nconst t = computed(() => (props.messages ?? en).yourData)\nconst data = createYourData({ exportMe, deleteMe }, { appName: props.appName, exportApp: props.exportApp })\nconst state = ref<YourDataState>(data.state)\nconst stop = data.subscribe((next) => {\n  state.value = next\n  if (next.status === 'deleted') emit('deleted')\n})\nonBeforeUnmount(stop)\n\nconst confirming = computed({\n  get: () => state.value.status === 'confirming',\n  set: (open) => {\n    // The dialog closes before its Delete button's click handler runs; cancel only if that\n    // handler didn't start deleting.\n    if (!open) queueMicrotask(() => data.cancel())\n  },\n})\nconst busy = computed(() => state.value.status === 'exporting' || state.value.status === 'deleting')\n\nasync function download() {\n  const file = await data.exportData()\n  if (!file) return\n  const url = URL.createObjectURL(new Blob([file.json], { type: 'application/json' }))\n  const link = Object.assign(document.createElement('a'), { href: url, download: file.filename })\n  link.click()\n  // Some browsers cancel a download whose URL goes at once.\n  setTimeout(() => URL.revokeObjectURL(url), 60_000)\n}\n</script>\n\n<template>\n  <Card>\n    <CardHeader>\n      <CardTitle>{{ t.title }}</CardTitle>\n    </CardHeader>\n    <CardContent class=\"space-y-6\">\n      <p v-if=\"state.status === 'deleted'\" role=\"status\">{{ t.deleted }}</p>\n      <p v-else-if=\"state.status === 'empty'\" role=\"status\">{{ t.nothing }}</p>\n      <template v-else>\n        <div class=\"flex flex-wrap items-center justify-between gap-3\">\n          <CardDescription class=\"max-w-prose\">{{ t.exportHelp }}</CardDescription>\n          <Button variant=\"outline\" :disabled=\"busy\" @click=\"download\">\n            {{ state.status === 'exporting' ? t.exporting : t.exportLabel }}\n          </Button>\n        </div>\n        <div class=\"flex flex-wrap items-center justify-between gap-3\">\n          <CardDescription class=\"max-w-prose\">{{ t.deleteHelp }}</CardDescription>\n          <Button variant=\"destructive\" :disabled=\"busy\" @click=\"data.askDelete()\">\n            {{ state.status === 'deleting' ? t.deleting : t.deleteLabel }}\n          </Button>\n        </div>\n        <p v-if=\"state.status === 'failed'\" role=\"alert\" class=\"text-destructive\">\n          {{ state.action === 'export' ? t.failedExport : t.failedDelete }}\n        </p>\n      </template>\n      <slot />\n    </CardContent>\n  </Card>\n\n  <AlertDialog v-model:open=\"confirming\">\n    <AlertDialogContent>\n      <AlertDialogHeader>\n        <AlertDialogTitle>{{ t.confirmTitle }}</AlertDialogTitle>\n        <AlertDialogDescription>{{ t.confirmBody }}</AlertDialogDescription>\n      </AlertDialogHeader>\n      <AlertDialogFooter>\n        <AlertDialogCancel>{{ t.cancel }}</AlertDialogCancel>\n        <AlertDialogAction class=\"bg-destructive text-destructive-foreground\" @click=\"data.confirmDelete()\">\n          {{ t.confirm }}\n        </AlertDialogAction>\n      </AlertDialogFooter>\n    </AlertDialogContent>\n  </AlertDialog>\n</template>\n"
    }
  ]
}
