@llamaindex/ui
Version:
A comprehensive UI component library built with React, TypeScript, and Tailwind CSS for LlamaIndex applications
133 lines (128 loc) • 4.34 kB
TypeScript
import * as react_jsx_runtime from 'react/jsx-runtime';
import * as React from 'react';
/**
* Supported file types for document parsing and extraction
*/
declare enum FileType {
JPEG = "jpeg",
JPG = "jpg",
PNG = "png",
WEBP = "webp",
PDF = "pdf",
DOC = "doc",
DOCX = "docx",
XLS = "xls",
XLSX = "xlsx",
PPT = "ppt",
PPTX = "pptx",
TXT = "txt",
CSV = "csv",
JSON = "json",
XML = "xml",
HTML = "html",
CSS = "css",
JS = "js",
TS = "ts",
MD = "md"
}
/**
* Predefined file type groups for common use cases
*/
declare const FILE_TYPE_GROUPS: {
IMAGES: FileType[];
DOCUMENTS: FileType[];
TEXT: FileType[];
SPREADSHEETS: FileType[];
PRESENTATIONS: FileType[];
COMMON_IMAGES: FileType[];
OFFICE_DOCS: FileType[];
};
/**
* Gets file type definition by FileType enum
*/
declare const getFileTypeDefinition: (fileType: FileType) => {
extensions: string[];
mimeTypes: string[];
displayName: string;
category: string;
};
/**
* Gets all supported extensions for a FileType
*/
declare const getFileExtensions: (fileType: FileType) => string[];
/**
* Gets all supported MIME types for a FileType
*/
declare const getFileMimeTypes: (fileType: FileType) => string[];
/**
* Checks if a file matches the given FileType
*/
declare const isFileTypeMatch: (file: File, fileType: FileType) => boolean;
/**
* File validation with FileType enum system
*/
declare const validateFile: (file: File, allowedFileTypes?: FileType[], maxFileSizeBytes?: number) => string | null;
/**
* Gets all file types by category
*/
declare const getFileTypesByCategory: (category: string) => FileType[];
/**
* Creates a validation function for a specific file type group
*/
declare const createFileTypeValidator: (allowedTypes: FileType[], maxSizeBytes?: number) => (file: File) => string | null;
/**
* Formats file size in human-readable format using decimal (SI) units
* Uses powers of 1000 for true KB, MB, GB calculations
*/
declare const formatFileSize: (bytes: number) => string;
/**
* Checks if the current environment supports the File API
*/
declare const isFileApiSupported: () => boolean;
/**
* Checks if the current environment supports the Web Crypto API
*/
declare const isCryptoSupported: () => boolean;
interface FileUploadData {
file: File;
fileId: string;
url?: string;
}
interface UploadResult {
success: boolean;
data: FileUploadData | null;
error: Error | null;
}
interface UseFileUploadOptions {
onProgress?: (file: File, progress: number) => void;
onUploadStart?: (file: File) => void;
onUploadComplete?: (file: File) => void;
onUploadError?: (file: File, error: string) => void;
}
interface UseFileUploadReturn {
isUploading: boolean;
uploadAndReturn: (file: File) => Promise<UploadResult>;
}
declare function useFileUpload({ onProgress, onUploadStart, onUploadComplete, onUploadError, }?: UseFileUploadOptions): UseFileUploadReturn;
interface InputField {
key: string;
label: string;
placeholder?: string;
required?: boolean;
validation?: (value: string) => string | null;
}
interface FileUploaderProps {
title?: string;
description?: string;
inputFields?: InputField[];
allowedFileTypes?: FileType[];
maxFileSizeBytes?: number;
multiple?: boolean;
onSuccess: (data: FileUploadData[], fieldValues: Record<string, string>) => Promise<void>;
trigger?: React.ReactNode;
/** Set to true while processing the file after a callback, in order to show a spinner */
isProcessing?: boolean;
}
declare function FileUploader({ title, description, inputFields, allowedFileTypes, maxFileSizeBytes, // 100MB default
multiple, onSuccess, trigger, isProcessing, }: FileUploaderProps): react_jsx_runtime.JSX.Element;
export { type FileUploaderProps as F, type InputField as I, type UploadResult as U, FileUploader as a, FileType as b, FILE_TYPE_GROUPS as c, getFileExtensions as d, getFileMimeTypes as e, getFileTypesByCategory as f, getFileTypeDefinition as g, createFileTypeValidator as h, isFileTypeMatch as i, formatFileSize as j, isFileApiSupported as k, isCryptoSupported as l, type FileUploadData as m, type UseFileUploadOptions as n, type UseFileUploadReturn as o, useFileUpload as u, validateFile as v };