{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "global-upload",
  "title": "Global Upload",
  "description": "An app-wide upload provider with a drop-anywhere overlay, a background queue panel and IndexedDB persistence.",
  "dependencies": [
    "@uploadcn/core@^0.1.0",
    "@uploadcn/react@^0.1.0",
    "cn"
  ],
  "registryDependencies": [
    "@uploadcn/upload"
  ],
  "files": [
    {
      "path": "registry/default/blocks/global-upload.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport {\n  type UploadAdapter,\n  type UploadPersistence,\n  createIndexedDBPersistence,\n} from \"@uploadcn/core\"\nimport {\n  Upload as UploadPrimitive,\n  type UseUploaderOptions,\n  useNetworkStatus,\n  useUploadContext,\n  useUploadGuard,\n  useUploadProgress,\n  useUploader,\n  useWindowDrop,\n} from \"@uploadcn/react\"\nimport { cn } from \"cn\"\n\nimport { IconPlaceholder } from \"@/components/icon-placeholder\"\nimport {\n  NativeButton,\n  UploadProgress,\n  UploadQueue,\n} from \"@/registry/default/ui/upload\"\n\ninterface UploadProviderProps<TResult> extends Partial<\n  UseUploaderOptions<TResult>\n> {\n  adapter?: UploadAdapter<TResult>\n  /**\n   * Keep uploads across reloads in IndexedDB and resume them. `true` uses the\n   * default store; pass your own `UploadPersistence` to customize.\n   */\n  persist?: boolean | UploadPersistence\n  /** Warn before leaving the page while uploads run. Default `true`. */\n  guard?: boolean\n  children: React.ReactNode\n}\n\n/**\n * One uploader for the whole app. Any component inside can add files with\n * `useUploadContext().addFiles`, and `GlobalDropzone` / `UploadQueuePanel`\n * render app-wide UI for it, uploads keep running across client-side\n * navigation because the provider stays mounted.\n */\nfunction UploadProvider<TResult = unknown>({\n  adapter,\n  persist = false,\n  guard = true,\n  children,\n  ...options\n}: UploadProviderProps<TResult>) {\n  const [persistence] = React.useState(() =>\n    persist === true\n      ? createIndexedDBPersistence()\n      : persist === false\n        ? undefined\n        : persist\n  )\n  const uploader = useUploader<TResult>({\n    adapter,\n    persistence,\n    restore: !!persistence,\n    ...options,\n  })\n  useUploadGuard(uploader, { enabled: guard })\n  return (\n    <UploadPrimitive.Root uploader={uploader} className=\"contents\">\n      {children}\n    </UploadPrimitive.Root>\n  )\n}\n\ninterface GlobalDropzoneProps {\n  title?: React.ReactNode\n  description?: React.ReactNode\n  disabled?: boolean\n  className?: string\n}\n\n/** A full-window overlay that appears when files are dragged over the page. */\nfunction GlobalDropzone({\n  title = \"Drop files anywhere to upload\",\n  description = \"They'll keep uploading while you work\",\n  disabled = false,\n  className,\n}: GlobalDropzoneProps) {\n  const { addFiles, disabled: uploadDisabled } = useUploadContext()\n  const { isDragging } = useWindowDrop({\n    onDrop: addFiles,\n    enabled: !disabled && !uploadDisabled,\n  })\n  if (!isDragging) return null\n  return (\n    <div\n      data-slot=\"global-dropzone\"\n      aria-hidden\n      className={cn(\n        \"pointer-events-none fixed inset-0 z-50 flex animate-in items-center justify-center bg-background/80 p-6 backdrop-blur-sm duration-150 fade-in-0 motion-reduce:animate-none\",\n        className\n      )}\n    >\n      <div className=\"flex size-full max-h-128 max-w-3xl animate-in flex-col items-center justify-center gap-3 rounded-2xl border-2 border-dashed border-primary/60 text-center duration-200 zoom-in-95 motion-reduce:animate-none\">\n        <div className=\"flex size-12 items-center justify-center rounded-full border bg-background shadow-sm\">\n          <IconPlaceholder\n            lucide=\"CloudUploadIcon\"\n            tabler=\"IconCloudUpload\"\n            hugeicons=\"CloudUploadIcon\"\n            phosphor=\"CloudArrowUpIcon\"\n            remixicon=\"RiUploadCloud2Line\"\n            className=\"size-5\"\n          />\n        </div>\n        <p className=\"text-lg font-medium\">{title}</p>\n        <p className=\"text-sm text-muted-foreground\">{description}</p>\n      </div>\n    </div>\n  )\n}\n\n/** A collapsible panel showing every upload in the app, like a cloud drive. */\nfunction UploadQueuePanel({ className }: { className?: string }) {\n  const { uploader } = useUploadContext()\n  const summary = useUploadProgress(uploader)\n  const online = useNetworkStatus()\n  const [collapsed, setCollapsed] = React.useState(false)\n  const [dismissed, setDismissed] = React.useState(false)\n  const panelId = React.useId()\n\n  // A new upload brings the panel back.\n  const [lastTotal, setLastTotal] = React.useState(summary.total)\n  if (summary.total !== lastTotal) {\n    setLastTotal(summary.total)\n    if (summary.total > lastTotal) setDismissed(false)\n  }\n\n  if (summary.total === 0 || dismissed) return null\n\n  const title = summary.isUploading\n    ? `Uploading ${summary.counts.uploading + summary.counts.queued} file${summary.counts.uploading + summary.counts.queued === 1 ? \"\" : \"s\"}`\n    : summary.counts.paused > 0\n      ? `${summary.counts.paused} paused`\n      : `${summary.counts.success} upload${summary.counts.success === 1 ? \"\" : \"s\"} complete`\n\n  return (\n    <section\n      aria-label=\"Uploads\"\n      data-slot=\"upload-queue-panel\"\n      className={cn(\n        \"fixed inset-x-4 bottom-4 z-40 flex animate-in flex-col overflow-hidden rounded-xl border bg-popover text-popover-foreground shadow-lg duration-200 fade-in-0 slide-in-from-bottom-4 motion-reduce:animate-none sm:inset-x-auto sm:right-4 sm:w-96\",\n        className\n      )}\n    >\n      <header className=\"flex items-center gap-2 border-b px-3 py-2\">\n        <div className=\"flex min-w-0 flex-1 flex-col gap-1.5\">\n          <div className=\"flex items-center gap-2 text-sm font-medium\">\n            {!online ? (\n              <IconPlaceholder\n                lucide=\"WifiOffIcon\"\n                tabler=\"IconWifiOff\"\n                hugeicons=\"WifiOff01Icon\"\n                phosphor=\"WifiSlashIcon\"\n                remixicon=\"RiWifiOffLine\"\n                className=\"size-3.5 text-muted-foreground\"\n                aria-label=\"Offline\"\n              />\n            ) : null}\n            <span className=\"truncate\">{title}</span>\n            {summary.isUploading ? (\n              <span className=\"ms-auto text-xs font-normal text-muted-foreground tabular-nums\">\n                {Math.round(summary.percent)}%\n              </span>\n            ) : null}\n          </div>\n          {summary.isUploading ? <UploadProgress /> : null}\n        </div>\n        <NativeButton\n          variant=\"ghost\"\n          size=\"icon-xs\"\n          aria-label={collapsed ? \"Expand uploads\" : \"Collapse uploads\"}\n          aria-expanded={!collapsed}\n          aria-controls={panelId}\n          onClick={() => setCollapsed((value) => !value)}\n        >\n          <IconPlaceholder\n            lucide=\"ChevronDownIcon\"\n            tabler=\"IconChevronDown\"\n            hugeicons=\"ArrowDown01Icon\"\n            phosphor=\"CaretDownIcon\"\n            remixicon=\"RiArrowDownSLine\"\n            className={cn(\"transition-transform\", collapsed && \"rotate-180\")}\n          />\n        </NativeButton>\n        {summary.isUploading ? null : (\n          <NativeButton\n            variant=\"ghost\"\n            size=\"icon-xs\"\n            aria-label=\"Close uploads\"\n            onClick={() => setDismissed(true)}\n          >\n            <IconPlaceholder\n              lucide=\"XIcon\"\n              tabler=\"IconX\"\n              hugeicons=\"Cancel01Icon\"\n              phosphor=\"XIcon\"\n              remixicon=\"RiCloseLine\"\n            />\n          </NativeButton>\n        )}\n      </header>\n      <div\n        id={panelId}\n        hidden={collapsed}\n        className=\"max-h-80 overflow-y-auto p-2\"\n      >\n        <UploadQueue variant=\"default\" size=\"sm\" />\n      </div>\n    </section>\n  )\n}\n\nexport {\n  GlobalDropzone,\n  UploadProvider,\n  UploadQueuePanel,\n  type UploadProviderProps,\n}\n",
      "type": "registry:component"
    }
  ],
  "categories": [
    "upload"
  ],
  "type": "registry:block"
}