UNPKG

radfile

Version:

A modern, unstyled, and customizable file upload component library for Vue 3, built with [Radix Vue](https://www.radix-vue.com/) primitives.

599 lines (499 loc) 19 kB
import { AllowedComponentProps } from 'vue'; import { AsTag } from 'radix-vue'; import { Component } from 'vue'; import { ComponentCustomProps } from 'vue'; import { ComponentOptionsMixin } from 'vue'; import { ComponentProvideOptions } from 'vue'; import { ComputedRef } from 'vue'; import { CreateComponentPublicInstanceWithMixins } from 'vue'; import { DefineComponent } from 'vue'; import { ExtractPropTypes } from 'vue'; import { GlobalComponents } from 'vue'; import { GlobalDirectives } from 'vue'; import { InjectionKey } from 'vue'; import { PrimitiveProps } from 'radix-vue'; import { PropType } from 'vue'; import { PublicProps } from 'vue'; import { Ref } from 'vue'; import { RendererElement } from 'vue'; import { RendererNode } from 'vue'; import { ShallowUnwrapRef } from 'vue'; import { VNode } from 'vue'; import { VNodeProps } from 'vue'; declare const __VLS_component: DefineComponent<__VLS_Props, {}, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {}, string, PublicProps, Readonly<__VLS_Props> & Readonly<{}>, { as: AsTag | Component; class: string; }, {}, {}, {}, string, ComponentProvideOptions, false, { zone: CreateComponentPublicInstanceWithMixins<Readonly<ExtractPropTypes< { asChild: { type: BooleanConstructor; default: boolean; }; as: { type: PropType<AsTag | Component>; default: string; }; }>>, () => VNode<RendererNode, RendererElement, { [key: string]: any; }>, unknown, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {}, PublicProps, { asChild: boolean; as: AsTag | Component; }, true, {}, {}, GlobalComponents, GlobalDirectives, string, {}, any, ComponentProvideOptions, { P: {}; B: {}; D: {}; C: {}; M: {}; Defaults: {}; }, Readonly<ExtractPropTypes< { asChild: { type: BooleanConstructor; default: boolean; }; as: { type: PropType<AsTag | Component>; default: string; }; }>>, () => VNode<RendererNode, RendererElement, { [key: string]: any; }>, {}, {}, {}, { asChild: boolean; as: AsTag | Component; }> | null; }, any>; declare const __VLS_component_10: DefineComponent<__VLS_Props_5, {}, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {}, string, PublicProps, Readonly<__VLS_Props_5> & Readonly<{}>, { as: AsTag | Component; class: string; }, {}, {}, {}, string, ComponentProvideOptions, false, {}, any>; declare const __VLS_component_11: DefineComponent<Props_5, {}, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {}, string, PublicProps, Readonly<Props_5> & Readonly<{}>, { as: AsTag | Component; class: string; }, {}, {}, {}, string, ComponentProvideOptions, false, {}, any>; declare const __VLS_component_12: DefineComponent<__VLS_Props_6, {}, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {}, string, PublicProps, Readonly<__VLS_Props_6> & Readonly<{}>, { as: AsTag | Component; class: string; }, {}, {}, {}, string, ComponentProvideOptions, false, {}, any>; declare const __VLS_component_2: DefineComponent<PrimitiveProps, {}, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {}, string, PublicProps, Readonly<PrimitiveProps> & Readonly<{}>, { as: AsTag | Component; }, {}, {}, {}, string, ComponentProvideOptions, false, { fileInput: HTMLInputElement; }, any>; declare const __VLS_component_3: DefineComponent<__VLS_Props_2, {}, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {}, string, PublicProps, Readonly<__VLS_Props_2> & Readonly<{}>, { as: AsTag | Component; class: string; }, {}, {}, {}, string, ComponentProvideOptions, false, {}, any>; declare const __VLS_component_4: DefineComponent<__VLS_Props_3, {}, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {}, string, PublicProps, Readonly<__VLS_Props_3> & Readonly<{}>, { as: AsTag | Component; }, {}, {}, {}, string, ComponentProvideOptions, false, {}, any>; declare const __VLS_component_5: DefineComponent<Props, {}, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {}, string, PublicProps, Readonly<Props> & Readonly<{}>, { as: AsTag | Component; class: string; }, {}, {}, {}, string, ComponentProvideOptions, false, {}, any>; declare const __VLS_component_6: DefineComponent<Props_2, {}, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {}, string, PublicProps, Readonly<Props_2> & Readonly<{}>, { as: AsTag | Component; class: string; }, {}, {}, {}, string, ComponentProvideOptions, false, {}, any>; declare const __VLS_component_7: DefineComponent<Props_3, {}, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {}, string, PublicProps, Readonly<Props_3> & Readonly<{}>, { as: AsTag | Component; class: string; }, {}, {}, {}, string, ComponentProvideOptions, false, {}, any>; declare const __VLS_component_8: DefineComponent<Props_4, {}, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {}, string, PublicProps, Readonly<Props_4> & Readonly<{}>, { as: AsTag | Component; class: string; }, {}, {}, {}, string, ComponentProvideOptions, false, {}, any>; declare const __VLS_component_9: DefineComponent<PrimitiveProps, {}, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {}, string, PublicProps, Readonly<PrimitiveProps> & Readonly<{}>, { as: AsTag | Component; }, {}, {}, {}, string, ComponentProvideOptions, false, {}, any>; declare type __VLS_PrettifyLocal<T> = { [K in keyof T]: T[K]; } & {}; declare type __VLS_Props = PrimitiveProps & { class?: string; }; declare type __VLS_Props_2 = PrimitiveProps & { class?: string; }; declare type __VLS_Props_3 = PrimitiveProps & { item: UploadFile; }; declare type __VLS_Props_4 = PrimitiveProps & { class?: string; }; declare type __VLS_Props_5 = PrimitiveProps & { class?: string; }; declare type __VLS_Props_6 = PrimitiveProps & { class?: string; }; declare function __VLS_template(): { attrs: Partial<{}>; slots: { default?(_: {}): any; }; refs: { zone: CreateComponentPublicInstanceWithMixins<Readonly<ExtractPropTypes< { asChild: { type: BooleanConstructor; default: boolean; }; as: { type: PropType<AsTag | Component>; default: string; }; }>>, () => VNode<RendererNode, RendererElement, { [key: string]: any; }>, unknown, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {}, PublicProps, { asChild: boolean; as: AsTag | Component; }, true, {}, {}, GlobalComponents, GlobalDirectives, string, {}, any, ComponentProvideOptions, { P: {}; B: {}; D: {}; C: {}; M: {}; Defaults: {}; }, Readonly<ExtractPropTypes< { asChild: { type: BooleanConstructor; default: boolean; }; as: { type: PropType<AsTag | Component>; default: string; }; }>>, () => VNode<RendererNode, RendererElement, { [key: string]: any; }>, {}, {}, {}, { asChild: boolean; as: AsTag | Component; }> | null; }; rootEl: any; }; declare function __VLS_template_10(): { attrs: Partial<{}>; slots: { default?(_: {}): any; }; refs: {}; rootEl: any; }; declare function __VLS_template_11(): { attrs: Partial<{}>; slots: { default?(_: { progress: number; totalFiles: number; pendingCount: number; successCount: number; errorCount: number; }): any; }; refs: {}; rootEl: any; }; declare function __VLS_template_12(): { attrs: Partial<{}>; slots: { default?(_: {}): any; }; refs: {}; rootEl: any; }; declare function __VLS_template_2(): { attrs: Partial<{}>; slots: { default?(_: {}): any; }; refs: { fileInput: HTMLInputElement; }; rootEl: any; }; declare function __VLS_template_3(): { attrs: Partial<{}>; slots: { default?(_: { files: UploadFile<any, UploadFileStatus>[]; }): any; }; refs: {}; rootEl: any; }; declare function __VLS_template_4(): { attrs: Partial<{}>; slots: { default?(_: { status: "pending" | "error" | "success" | "idle"; }): any; }; refs: {}; rootEl: any; }; declare function __VLS_template_5(): { attrs: Partial<{}>; slots: { default?(_: { error: string; }): any; }; refs: {}; rootEl: any; }; declare function __VLS_template_6(): { attrs: Partial<{}>; slots: { default?(_: { preview: Preview; }): any; }; refs: {}; rootEl: any; }; declare function __VLS_template_7(): { attrs: Partial<{}>; slots: { default?(_: { progress: number; }): any; }; refs: {}; rootEl: any; }; declare function __VLS_template_8(): { attrs: Partial<{}>; slots: { default?(_: {}): any; }; refs: {}; rootEl: any; }; declare function __VLS_template_9(): { attrs: Partial<{}>; slots: { default?(_: { size: string; bytes: number; }): any; }; refs: {}; rootEl: any; }; declare type __VLS_TemplateResult = ReturnType<typeof __VLS_template>; declare type __VLS_TemplateResult_10 = ReturnType<typeof __VLS_template_10>; declare type __VLS_TemplateResult_11 = ReturnType<typeof __VLS_template_11>; declare type __VLS_TemplateResult_12 = ReturnType<typeof __VLS_template_12>; declare type __VLS_TemplateResult_2 = ReturnType<typeof __VLS_template_2>; declare type __VLS_TemplateResult_3 = ReturnType<typeof __VLS_template_3>; declare type __VLS_TemplateResult_4 = ReturnType<typeof __VLS_template_4>; declare type __VLS_TemplateResult_5 = ReturnType<typeof __VLS_template_5>; declare type __VLS_TemplateResult_6 = ReturnType<typeof __VLS_template_6>; declare type __VLS_TemplateResult_7 = ReturnType<typeof __VLS_template_7>; declare type __VLS_TemplateResult_8 = ReturnType<typeof __VLS_template_8>; declare type __VLS_TemplateResult_9 = ReturnType<typeof __VLS_template_9>; declare type __VLS_WithTemplateSlots<T, S> = T & { new (): { $slots: S; }; }; declare type __VLS_WithTemplateSlots_10<T, S> = T & { new (): { $slots: S; }; }; declare type __VLS_WithTemplateSlots_11<T, S> = T & { new (): { $slots: S; }; }; declare type __VLS_WithTemplateSlots_12<T, S> = T & { new (): { $slots: S; }; }; declare type __VLS_WithTemplateSlots_2<T, S> = T & { new (): { $slots: S; }; }; declare type __VLS_WithTemplateSlots_3<T, S> = T & { new (): { $slots: S; }; }; declare type __VLS_WithTemplateSlots_4<T, S> = T & { new (): { $slots: S; }; }; declare type __VLS_WithTemplateSlots_5<T, S> = T & { new (): { $slots: S; }; }; declare type __VLS_WithTemplateSlots_6<T, S> = T & { new (): { $slots: S; }; }; declare type __VLS_WithTemplateSlots_7<T, S> = T & { new (): { $slots: S; }; }; declare type __VLS_WithTemplateSlots_8<T, S> = T & { new (): { $slots: S; }; }; declare type __VLS_WithTemplateSlots_9<T, S> = T & { new (): { $slots: S; }; }; export declare type CreateUploadHandler<MetadataT extends UploadMetadata> = (callbacks: UploadCallbacks) => UploadHandler<MetadataT>; export declare type FileType = { description: string; accept: Record<string, string[]>; }; declare type GenericPreview = { type: "generic"; fileType: string; }; declare type ImagePreview = { type: "image"; url: string; alt: string; }; export declare const injectState: () => UploadState<any>; export declare const injectUploadFile: () => Ref<UploadFile<any, UploadFileStatus>, UploadFile<any, UploadFileStatus>>; export declare const injectUploadOptions: () => UploadOptions<any>; declare type Preview = ImagePreview | GenericPreview; declare interface Props extends PrimitiveProps { class?: string; } declare interface Props_2 extends PrimitiveProps { class?: string; } declare interface Props_3 extends PrimitiveProps { class?: string; } declare interface Props_4 extends PrimitiveProps { class?: string; } declare interface Props_5 extends PrimitiveProps { class?: string; } export declare type UploadCallbacks = { onProgress: (file: File, byteSent: number) => void; onError: (file: File, error: Error) => void; onDone: (file: File) => void; }; export declare const UploadDropZone: __VLS_WithTemplateSlots<typeof __VLS_component, __VLS_TemplateResult["slots"]>; export declare const UploadEmptyState: __VLS_WithTemplateSlots_10<typeof __VLS_component_10, __VLS_TemplateResult_10["slots"]>; export declare type UploadFile<TMetadata extends UploadMetadata = any, TStatus extends UploadFileStatus = UploadFileStatus> = { id: string; metadata: TMetadata; file: File; status: TStatus; }; export declare const UploadFileButton: __VLS_WithTemplateSlots_2<typeof __VLS_component_2, __VLS_TemplateResult_2["slots"]>; export declare const uploadFileKey: InjectionKey<Ref<UploadFile<any>>>; export declare type UploadFileProgressStatus = { status: "pending"; uploaded: number; }; export declare const UploadFiles: __VLS_WithTemplateSlots_3<typeof __VLS_component_3, __VLS_TemplateResult_3["slots"]>; export declare type UploadFileStatus = UploadFileProgressStatus | { status: "error"; error: unknown; } | { status: "success"; } | { status: "idle"; }; export declare type UploadHandler<MetadataT extends UploadMetadata> = { onUpload: (files: UploadFile<MetadataT>[]) => void; onCleanup: () => void; onRemove: (file: File) => void; }; export declare const UploadItem: __VLS_WithTemplateSlots_4<typeof __VLS_component_4, __VLS_TemplateResult_4["slots"]>; export declare const UploadItemErrorMessage: __VLS_WithTemplateSlots_5<typeof __VLS_component_5, __VLS_TemplateResult_5["slots"]>; export declare const UploadItemName: DefineComponent<__VLS_Props_4, {}, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {}, string, PublicProps, Readonly<__VLS_Props_4> & Readonly<{}>, { as: AsTag | Component; class: string; }, {}, {}, {}, string, ComponentProvideOptions, false, {}, any>; export declare const UploadItemPreview: __VLS_WithTemplateSlots_6<typeof __VLS_component_6, __VLS_TemplateResult_6["slots"]>; export declare const UploadItemProgress: __VLS_WithTemplateSlots_7<typeof __VLS_component_7, __VLS_TemplateResult_7["slots"]>; export declare const UploadItemRemove: __VLS_WithTemplateSlots_8<typeof __VLS_component_8, __VLS_TemplateResult_8["slots"]>; export declare const UploadItemSize: __VLS_WithTemplateSlots_9<typeof __VLS_component_9, __VLS_TemplateResult_9["slots"]>; export declare type UploadMetadata = object; export declare interface UploadOptions<MetadataT extends UploadMetadata> { readonly createUploadHandler: CreateUploadHandler<MetadataT>; readonly autoUpload: boolean; readonly getMetadata: (file: File) => MetadataT; readonly onPickError?: (err: unknown) => void; readonly onUploadError?: (err: unknown) => void; readonly onSuccess?: (upload: MetadataT) => void; readonly restrictions: { readonly allowMultiple: boolean; readonly allowedFileTypes?: FileType[]; }; } export declare const uploadOptionsKey: InjectionKey<UploadOptions<any>>; export declare const UploadProgress: __VLS_WithTemplateSlots_11<typeof __VLS_component_11, __VLS_TemplateResult_11["slots"]>; export declare const UploadRoot: <MetadataT extends UploadMetadata>(__VLS_props: NonNullable<Awaited<typeof __VLS_setup>>["props"], __VLS_ctx?: __VLS_PrettifyLocal<Pick<NonNullable<Awaited<typeof __VLS_setup>>, "attrs" | "emit" | "slots">>, __VLS_expose?: NonNullable<Awaited<typeof __VLS_setup>>["expose"], __VLS_setup?: Promise<{ props: __VLS_PrettifyLocal<Pick<Partial<{}> & Omit<{ readonly "onUpdate:modelValue"?: ((value: readonly UploadFile<MetadataT>[]) => any) | undefined; } & VNodeProps & AllowedComponentProps & ComponentCustomProps, never>, "onUpdate:modelValue"> & (PrimitiveProps & { class?: string; options: UploadOptions<MetadataT>; modelValue?: UploadFile<MetadataT>[]; }) & Partial<{}>> & PublicProps; expose(exposed: ShallowUnwrapRef< {}>): void; attrs: any; slots: { default?(_: { hasIdle: boolean; hasFiles: boolean; isUploading: boolean; }): any; }; emit: (evt: "update:modelValue", value: readonly UploadFile<MetadataT>[]) => void; }>) => VNode & { __ctx?: Awaited<typeof __VLS_setup>; }; export declare const UploadStartUploadButton: __VLS_WithTemplateSlots_12<typeof __VLS_component_12, __VLS_TemplateResult_12["slots"]>; export declare type UploadState<TMetadata extends UploadMetadata> = { files: Readonly<Ref<UploadFile<TMetadata>[]>>; isUploading: Readonly<Ref<boolean>>; hasIdle: Readonly<Ref<boolean>>; hasFiles: Readonly<Ref<boolean>>; addFile: (file: File | File[]) => void; removeFile: (file: UploadFile<TMetadata>) => void; upload: () => void; }; export declare const uploadStateKey: InjectionKey<UploadState<any>>; export declare function useFileManagement<MetadataT extends UploadMetadata>(options: UploadOptions<MetadataT>, emitValue: (files: ReadonlyArray<UploadFile<MetadataT>>) => void): { files: Readonly<Ref<UploadFile<MetadataT>[]>>; addFile: (append: File | File[]) => void; removeFile: (file: UploadFile<MetadataT>) => void; setStatus: (file: UploadFile<MetadataT>, status: UploadFileStatus) => void; emitUpdatedModelValue: () => void; }; export declare function useUploadHandler<MetadataT extends UploadMetadata>(options: UploadOptions<MetadataT>, files: Readonly<Ref<UploadFile<MetadataT>[]>>, emitUpdatedModelValue: () => void, setStatus: (file: UploadFile<MetadataT>, status: UploadFileStatus) => void): { upload: () => void; handler: UploadHandler<MetadataT>; }; export declare function useUploadState<MetadataT extends UploadMetadata>(files: Readonly<Ref<UploadFile<MetadataT>[]>>): { hasIdle: ComputedRef<boolean>; hasFiles: ComputedRef<boolean>; isUploading: ComputedRef<boolean>; }; export { } declare global { interface WindowEventMap { "story:setProgress": StoryProgressEvent; "story:onDone": CustomEvent; } }