{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "document-picker",
  "title": "Document Picker",
  "type": "registry:ui",
  "files": [
    {
      "path": "packages/registry-native/components/document-picker/DocumentPicker.tsx",
      "content": "import * as React from 'react'\nimport { Platform, type GestureResponderEvent } from 'react-native'\nimport { getDocumentAsync, type DocumentPickerOptions, type DocumentPickerResult } from 'expo-document-picker'\nimport { Button, type ButtonProps } from '@/components/ui/button'\n\nfunction revokeUnclaimedWebBlobUrls(result: DocumentPickerResult | undefined) {\n  if (Platform.OS !== 'web' || !result || result.canceled || !Array.isArray(result.assets)) return\n  if (typeof URL === 'undefined' || typeof URL.revokeObjectURL !== 'function') return\n  for (const asset of result.assets) {\n    if (typeof asset?.uri === 'string' && asset.uri.startsWith('blob:')) {\n      try {\n        URL.revokeObjectURL(asset.uri)\n      } catch {\n        // Ignore errors when revoking unclaimed web blob URLs.\n      }\n    }\n  }\n}\n\nexport interface DocumentPickerProps extends ButtonProps {\n  /** Allowed MIME types (e.g. `'application/pdf'`, `['image/*', 'application/pdf']`). Defaults to all types. */\n  type?: string | string[]\n  /** Allow selecting multiple documents when supported by the platform. */\n  multiple?: boolean\n  /** Copy selected documents into the app cache directory so they can be read immediately. Defaults to `true`. */\n  copyToCacheDirectory?: boolean\n  /** Receives the complete `DocumentPickerResult` returned by `expo-document-picker`, including canceled results (`result.canceled === true`). */\n  onResult?: (result: DocumentPickerResult) => void\n  /** Called when the user cancels the document picker (`result.canceled === true`). */\n  onCancel?: () => void\n  /** Called when `getDocumentAsync` rejects. */\n  onError?: (error: Error) => void\n}\n\n/**\n * Triggers the system document picker via `expo-document-picker` (`getDocumentAsync`).\n *\n * Bare React Native apps require `expo-modules` (Expo Modules autolinking) to use `expo-document-picker`.\n * On web, cancelling the browser file dialog may not reliably resolve with a canceled result or fire `onCancel`\n * across browsers. Callers own any delivered web blob URLs (`URL.createObjectURL` assets) and should revoke\n * them when finished; unclaimed web `blob:` URLs (if the trigger unmounts before resolution or no `onResult`\n * callback is provided) are revoked automatically.\n */\nconst DocumentPicker = React.forwardRef<React.ComponentRef<typeof Button>, DocumentPickerProps>(\n  (\n    {\n      type,\n      multiple,\n      copyToCacheDirectory = true,\n      onResult,\n      onCancel,\n      onError,\n      onPress,\n      disabled,\n      loading = false,\n      children = 'Choose file',\n      ...props\n    },\n    ref,\n  ) => {\n    const [pending, setPending] = React.useState(false)\n    const mountedRef = React.useRef(true)\n    const pendingRef = React.useRef(false)\n    const onResultRef = React.useRef(onResult)\n    onResultRef.current = onResult\n\n    React.useEffect(() => {\n      mountedRef.current = true\n      return () => {\n        mountedRef.current = false\n      }\n    }, [])\n\n    async function handlePress(event: GestureResponderEvent) {\n      if (disabled || loading || pendingRef.current) return\n      onPress?.(event)\n      if (event?.defaultPrevented) return\n\n      const options: DocumentPickerOptions = { copyToCacheDirectory, base64: false }\n      if (type !== undefined) options.type = type\n      if (multiple !== undefined) options.multiple = multiple\n\n      pendingRef.current = true\n      setPending(true)\n      let result: DocumentPickerResult | undefined\n      let nativeError: Error | undefined\n      try {\n        result = await getDocumentAsync(options)\n      } catch (error) {\n        nativeError = error instanceof Error ? error : new Error(String(error))\n      }\n\n      pendingRef.current = false\n      if (!mountedRef.current) {\n        revokeUnclaimedWebBlobUrls(result)\n        return\n      }\n      setPending(false)\n\n      if (nativeError) {\n        onError?.(nativeError)\n        return\n      }\n      if (!result) return\n      const deliverResult = onResultRef.current\n      if (deliverResult) {\n        deliverResult(result)\n      } else {\n        revokeUnclaimedWebBlobUrls(result)\n      }\n      if (result.canceled) {\n        onCancel?.()\n      }\n    }\n\n    return (\n      <Button ref={ref} disabled={disabled} loading={loading || pending} onPress={handlePress} {...props}>\n        {children}\n      </Button>\n    )\n  },\n)\nDocumentPicker.displayName = 'DocumentPicker'\n\nexport { DocumentPicker }\n",
      "type": "registry:ui",
      "target": "~/components/ui/document-picker/DocumentPicker.tsx"
    },
    {
      "path": "packages/registry-native/components/document-picker/index.ts",
      "content": "export { DocumentPicker, type DocumentPickerProps } from './DocumentPicker'\n",
      "type": "registry:ui",
      "target": "~/components/ui/document-picker/index.ts"
    }
  ],
  "dependencies": [
    "expo-document-picker"
  ],
  "devDependencies": [],
  "registryDependencies": [
    "https://native.uipkge.dev/r/native/button.json"
  ],
  "description": "Action button wrapping expo-document-picker with rapid-press guards, error isolation, and typed result/cancel callbacks.",
  "categories": [
    "control"
  ]
}