{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "app-files-dropzone",
  "type": "registry:block",
  "title": "App, upload drop zone",
  "description": "A drop zone that takes a real drop (it highlights while a file is over it, a drop never navigates the page, dropped names are listed and announced) with the file picker inside it, so dragging is never the only way in. Idle, dragging and error states.",
  "categories": [
    "app"
  ],
  "dependencies": [
    "lucide-react@^1.49.0",
    "zod@^4.6.5"
  ],
  "registryDependencies": [
    "https://ui.klarhimmel.com/r/block-kit.json",
    "https://ui.klarhimmel.com/r/editing.json",
    "https://ui.klarhimmel.com/r/file-field.json",
    "https://ui.klarhimmel.com/r/kit-app.json",
    "https://ui.klarhimmel.com/r/utils.json"
  ],
  "files": [
    {
      "path": "src/blocks/app-files-dropzone/spec.ts",
      "type": "registry:file",
      "target": "components/klarhimmel/blocks/app-files-dropzone/spec.ts",
      "content": "import { z } from 'zod';\nimport { defineSpec, t } from '../_shared/schema';\n\nconst schema = z.object({\n  eyebrow: t(60).optional(),\n  title: t(120),\n  description: t(300).optional(),\n  /** The line in the zone. */\n  prompt: t(80),\n  field: z.object({ label: t(40), button: t(30), empty: t(40), hint: t(120) }),\n  /** idle: waiting. dragging: how the zone starts, highlighted, with a line that says so (real drags set it themselves). error: the picker's error text. */\n  state: z.enum(['idle', 'dragging', 'error']),\n  messages: z.object({ dragging: t(60), error: t(120), added: t(40) }),\n});\n\nexport const spec = defineSpec({\n  type: 'app-files-dropzone',\n  aliases: ['app/files-dropzone'],\n  name: 'App, upload drop zone',\n  category: 'app',\n  role: 'body',\n  description: 'A drop zone that takes a real drop (it highlights while a file is over it, a drop never navigates the page, dropped names are listed and announced) with the file picker inside it, so dragging is never the only way in. Idle, dragging and error states.',\n  schema,\n  defaults: {\n    \"eyebrow\": \"Files\",\n    \"title\": \"Upload documents\",\n    \"description\": \"Say which kinds of file are wanted and what they are for.\",\n    \"prompt\": \"Say where to drop files, or how to pick them\",\n    \"field\": {\n      \"label\": \"Files to upload\",\n      \"button\": \"Choose files\",\n      \"empty\": \"No files chosen\",\n      \"hint\": \"Say which types and what size are accepted.\"\n    },\n    \"state\": \"idle\",\n    \"messages\": {\n      \"dragging\": \"Say to drop the files to upload them\",\n      \"error\": \"Say what is wrong with a file and what to do.\",\n      \"added\": \"Files added\"\n    }\n  },\n});\n"
    },
    {
      "path": "src/blocks/app-files-dropzone/index.tsx",
      "type": "registry:file",
      "target": "components/klarhimmel/blocks/app-files-dropzone/index.tsx",
      "content": "import { useId, useRef, useState, type DragEvent } from 'react';\nimport { UploadCloud } from 'lucide-react';\nimport { Text, withHeadingLevel } from '../../editing';\nimport { cn } from '../../lib/utils';\nimport { FileField } from '../../ui/file-field';\nimport { Container, Section, SectionHeader } from '../_shared/kit';\nimport { StateSlot, useSynced } from '../_shared/app-kit';\nimport { spec } from './spec';\nimport type { BlockProps } from '../types';\nimport type { z } from 'zod';\n\nexport { spec };\ntype Props = z.infer<typeof spec.schema>;\n\nfunction AppFilesDropzone({ props }: BlockProps<Props>) {\n  const id = useId();\n  const { state, field } = props;\n  const [over, setOver] = useSynced(state === 'dragging');\n  const [added, setAdded] = useState<string[]>([]);\n  const depth = useRef(0); // dragenter and dragleave fire for every child the pointer crosses\n  const hasFiles = (e: DragEvent) => [...(e.dataTransfer?.types ?? [])].includes('Files');\n  const zone = {\n    onDragEnter: (e: DragEvent) => {\n      if (!hasFiles(e)) return;\n      e.preventDefault();\n      depth.current += 1;\n      setOver(true);\n    },\n    onDragOver: (e: DragEvent) => {\n      if (!hasFiles(e)) return;\n      e.preventDefault(); // without this the browser refuses the drop and opens the file instead\n      e.dataTransfer.dropEffect = 'copy';\n    },\n    onDragLeave: (e: DragEvent) => {\n      if (!hasFiles(e)) return;\n      depth.current = Math.max(0, depth.current - 1);\n      if (depth.current === 0) setOver(false);\n    },\n    onDrop: (e: DragEvent) => {\n      if (!hasFiles(e)) return;\n      e.preventDefault();\n      depth.current = 0;\n      setOver(false);\n      const names = [...e.dataTransfer.files].map((f) => f.name); // read now: the event is gone by the time the updater runs\n      setAdded((a) => [...a, ...names]);\n    },\n  };\n  return (\n    <Section labelledBy={id}>\n      <Container width=\"narrow\">\n        <SectionHeader id={id} eyebrow={props.eyebrow} title={props.title} description={props.description} />\n        <div {...zone} className={cn('mt-10 flex flex-col items-center gap-5 rounded-kh-xl border-2 border-dashed px-6 py-10 text-center @xl:px-12', over ? 'border-kh-accent bg-kh-accent-soft' : 'border-kh-line-strong bg-kh-surface')}>\n          <span aria-hidden className=\"inline-flex size-14 items-center justify-center rounded-kh-lg border border-kh-line bg-kh-surface text-kh-muted shadow-kh-1\">\n            <UploadCloud className=\"size-6\" />\n          </span>\n          <Text path={['prompt']} value={props.prompt} as=\"p\" className=\"text-kh-body font-medium\" />\n          <StateSlot show={over} className=\"text-kh-small font-medium text-kh-accent-ink\">\n            <p role=\"status\">\n              <Text path={['messages', 'dragging']} value={props.messages.dragging} as=\"span\" />\n            </p>\n          </StateSlot>\n          <FileField\n            multiple\n            className=\"items-center\"\n            label={<Text path={['field', 'label']} value={field.label} as=\"span\" />}\n            buttonLabel={<Text path={['field', 'button']} value={field.button} as=\"span\" />}\n            emptyLabel={<Text path={['field', 'empty']} value={field.empty} as=\"span\" />}\n            hint={<Text path={['field', 'hint']} value={field.hint} as=\"span\" />}\n            error={state === 'error' ? <Text path={['messages', 'error']} value={props.messages.error} as=\"span\" /> : undefined}\n          />\n          <StateSlot show={false}>\n            {state !== 'error' && <Text path={['messages', 'error']} value={props.messages.error} as=\"p\" />}\n          </StateSlot>\n          <StateSlot show={added.length > 0} className=\"w-full border-t border-kh-line pt-4 text-left\">\n            <p role=\"status\" className=\"text-kh-small font-medium\">\n              <Text path={['messages', 'added']} value={props.messages.added} as=\"span\" /> ({added.length})\n            </p>\n            <ul className=\"mt-2 flex flex-col gap-1 text-kh-small text-kh-ink-2\">\n              {added.map((n, i) => (\n                <li key={i} className=\"truncate\">\n                  {n}\n                </li>\n              ))}\n            </ul>\n          </StateSlot>\n        </div>\n      </Container>\n    </Section>\n  );\n}\n\nexport default withHeadingLevel(AppFilesDropzone);\n"
    }
  ]
}
