use-tus 0.4.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/README.md +2 -3
  2. package/dist/TusClientProvider/TusClientProvider.d.ts +4 -4
  3. package/dist/TusClientProvider/TusController.d.ts +4 -4
  4. package/dist/TusClientProvider/index.d.ts +2 -2
  5. package/dist/__stories__/Basic.stories.d.ts +5 -0
  6. package/dist/__stories__/CacheKey.stories.d.ts +5 -0
  7. package/dist/__stories__/DefaultOptions.stories.d.ts +5 -0
  8. package/dist/__stories__/components/BasicButton/BasicButton.d.ts +9 -0
  9. package/dist/__stories__/components/BasicButton/index.d.ts +1 -0
  10. package/dist/__stories__/components/LoadingCircle/LoadingCircle.d.ts +2 -0
  11. package/dist/__stories__/components/LoadingCircle/index.d.ts +1 -0
  12. package/dist/__stories__/components/ProgressBar/ProgressBar.d.ts +7 -0
  13. package/dist/__stories__/components/ProgressBar/index.d.ts +1 -0
  14. package/dist/__stories__/components/UploadIcon/UploadIcon.d.ts +2 -0
  15. package/dist/__stories__/components/UploadIcon/index.d.ts +1 -0
  16. package/dist/__stories__/constants.d.ts +1 -0
  17. package/dist/__tests__/TusClientProvider.test.d.ts +1 -0
  18. package/dist/__tests__/useTus.test.d.ts +1 -0
  19. package/dist/__tests__/utils/getBlob.d.ts +1 -0
  20. package/dist/__tests__/utils/mock.d.ts +5 -0
  21. package/dist/core/constants.d.ts +4 -4
  22. package/dist/core/contexts.d.ts +7 -7
  23. package/dist/core/tucClientActions.d.ts +50 -50
  24. package/dist/core/tusClientReducer.d.ts +18 -18
  25. package/dist/core/tusHandler.d.ts +17 -17
  26. package/dist/core/types.d.ts +8 -8
  27. package/dist/index.cjs.js +46 -1428
  28. package/dist/index.d.ts +4 -4
  29. package/dist/index.esm.js +33 -1412
  30. package/dist/index.js +385 -0
  31. package/dist/useTus/index.d.ts +2 -2
  32. package/dist/useTus/types.d.ts +15 -15
  33. package/dist/useTus/useTus.d.ts +2 -2
  34. package/dist/useTus/utils.d.ts +16 -16
  35. package/dist/useTusClient/index.d.ts +1 -1
  36. package/dist/useTusClient/useTusClient.d.ts +7 -7
  37. package/dist/utils/uid.d.ts +1 -1
  38. package/package.json +7 -7
package/README.md CHANGED
@@ -15,7 +15,6 @@
15
15
  ## Features
16
16
  - Resumable file uploads on react.
17
17
  - Managing the [Upload](https://github.com/tus/tus-js-client/blob/master/docs/api.md#tusuploadfile-options) by using context.
18
- - One dependency ([tus-js-client](https://github.com/tus/tus-js-client)).
19
18
  - TypeScript support.
20
19
 
21
20
  ## Demo
@@ -25,12 +24,12 @@ You can try the [use-tus demo](https://kqito.github.io/use-tus/?path=/story/uset
25
24
  ## Installation
26
25
  You can install the package from npm.
27
26
  ```sh
28
- npm install use-tus
27
+ npm install use-tus tus-js-client
29
28
  ```
30
29
 
31
30
  or
32
31
  ```sh
33
- yarn add use-tus
32
+ yarn add use-tus tus-js-client
34
33
  ```
35
34
 
36
35
  ## Usage
@@ -1,4 +1,4 @@
1
- import type { FC } from 'react';
2
- import { TusConfigs } from '../core/tusHandler';
3
- export declare type TusClientProviderProps = Readonly<TusConfigs>;
4
- export declare const TusClientProvider: FC<TusClientProviderProps>;
1
+ import { FC } from 'react';
2
+ import { TusConfigs } from '../core/tusHandler';
3
+ export declare type TusClientProviderProps = Readonly<TusConfigs>;
4
+ export declare const TusClientProvider: FC<TusClientProviderProps>;
@@ -1,4 +1,4 @@
1
- import { FC } from 'react';
2
- import { TusConfigs } from '../core/tusHandler';
3
- export declare type TusControllerProps = Readonly<TusConfigs>;
4
- export declare const TusController: FC<TusControllerProps>;
1
+ import { FC } from 'react';
2
+ import { TusConfigs } from '../core/tusHandler';
3
+ export declare type TusControllerProps = Readonly<TusConfigs>;
4
+ export declare const TusController: FC<TusControllerProps>;
@@ -1,2 +1,2 @@
1
- export { TusClientProvider } from './TusClientProvider';
2
- export type { TusClientProviderProps } from './TusClientProvider';
1
+ export { TusClientProvider } from './TusClientProvider';
2
+ export type { TusClientProviderProps } from './TusClientProvider';
@@ -0,0 +1,5 @@
1
+ /// <reference types="react" />
2
+ import { Meta } from '@storybook/react';
3
+ declare const _default: Meta<import("@storybook/react").Args>;
4
+ export default _default;
5
+ export declare const Basic: () => JSX.Element;
@@ -0,0 +1,5 @@
1
+ /// <reference types="react" />
2
+ import { Meta } from '@storybook/react';
3
+ declare const _default: Meta<import("@storybook/react").Args>;
4
+ export default _default;
5
+ export declare const CacheKey: () => JSX.Element;
@@ -0,0 +1,5 @@
1
+ /// <reference types="react" />
2
+ import { Meta } from '@storybook/react';
3
+ declare const _default: Meta<import("@storybook/react").Args>;
4
+ export default _default;
5
+ export declare const WithDefaultOptions: () => JSX.Element;
@@ -0,0 +1,9 @@
1
+ import { ComponentProps } from 'react';
2
+ declare type BasicButtonProps = {
3
+ onClick: ComponentProps<'button'>['onClick'];
4
+ title: string;
5
+ disabled?: ComponentProps<'button'>['disabled'];
6
+ styleColor?: 'primary' | 'basic' | 'error';
7
+ };
8
+ export declare const BasicButton: import("react").ForwardRefExoticComponent<BasicButtonProps & import("react").RefAttributes<HTMLButtonElement>>;
9
+ export {};
@@ -0,0 +1 @@
1
+ export { BasicButton } from './BasicButton';
@@ -0,0 +1,2 @@
1
+ import type { VFC } from 'react';
2
+ export declare const LoadingCircle: VFC;
@@ -0,0 +1 @@
1
+ export { LoadingCircle } from './LoadingCircle';
@@ -0,0 +1,7 @@
1
+ import { VFC } from 'react';
2
+ declare type ProgressBarProps = {
3
+ title?: string;
4
+ value?: number;
5
+ };
6
+ export declare const ProgressBar: VFC<ProgressBarProps>;
7
+ export {};
@@ -0,0 +1 @@
1
+ export { ProgressBar } from './ProgressBar';
@@ -0,0 +1,2 @@
1
+ import { VFC } from 'react';
2
+ export declare const UploadIcon: VFC;
@@ -0,0 +1 @@
1
+ export { UploadIcon } from './UploadIcon';
@@ -0,0 +1 @@
1
+ export declare const TUS_DEMO_ENDPOINT: "https://tusd.tusdemo.net/files/";
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export declare const getBlob: (str: string) => Blob;
@@ -0,0 +1,5 @@
1
+ /// <reference types="jest" />
2
+ /// <reference types="webpack-env" />
3
+ /// <reference types="node" />
4
+ export declare const createConsoleErrorMock: () => jest.SpyInstance<void, [message?: any, ...optionalParams: any[]]>;
5
+ export declare const insertEnvValue: (value: NodeJS.Process['env']) => void;
@@ -1,4 +1,4 @@
1
- export declare const ERROR_MESSAGES: {
2
- tusClientHasNotFounded: string;
3
- tusIsNotSupported: string;
4
- };
1
+ export declare const ERROR_MESSAGES: {
2
+ tusClientHasNotFounded: string;
3
+ tusIsNotSupported: string;
4
+ };
@@ -1,7 +1,7 @@
1
- import type { Dispatch } from 'react';
2
- import { TusClientActions } from './tucClientActions';
3
- import { TusClientState } from './tusClientReducer';
4
- export declare const TusClientStateContext: import("react").Context<TusClientState | undefined>;
5
- export declare const TusClientDispatchContext: import("react").Context<Dispatch<TusClientActions> | undefined>;
6
- export declare const useTusClientState: () => TusClientState;
7
- export declare const useTusClientDispatch: () => Dispatch<TusClientActions>;
1
+ import type { Dispatch } from 'react';
2
+ import { TusClientActions } from './tucClientActions';
3
+ import { TusClientState } from './tusClientReducer';
4
+ export declare const TusClientStateContext: import("react").Context<TusClientState | undefined>;
5
+ export declare const TusClientDispatchContext: import("react").Context<Dispatch<TusClientActions> | undefined>;
6
+ export declare const useTusClientState: () => TusClientState;
7
+ export declare const useTusClientDispatch: () => Dispatch<TusClientActions>;
@@ -1,50 +1,50 @@
1
- import type { Upload } from 'tus-js-client';
2
- import { TusConfigs } from './tusHandler';
3
- export declare type TusClientActions = ReturnType<typeof insertUploadInstance | typeof removeUploadInstance | typeof resetClient | typeof updateSuccessUpload | typeof updateErrorUpload | typeof updateIsAbortedUpload | typeof updateTusHandlerOptions>;
4
- export declare const insertUploadInstance: (cacheKey: string, upload: Upload) => {
5
- readonly type: "INSERT_UPLOAD_INSTANCE";
6
- readonly payload: {
7
- readonly cacheKey: string;
8
- readonly uploadState: {
9
- readonly upload: Upload;
10
- readonly isSuccess: false;
11
- readonly isAborted: false;
12
- };
13
- };
14
- };
15
- export declare const updateSuccessUpload: (cacheKey: string) => {
16
- readonly type: "UPDATE_SUCCESS_UPLOAD";
17
- readonly payload: {
18
- readonly cacheKey: string;
19
- };
20
- };
21
- export declare const updateErrorUpload: (cacheKey: string, error?: Error | undefined) => {
22
- readonly type: "UPDATE_ERROR_UPLOAD";
23
- readonly payload: {
24
- readonly cacheKey: string;
25
- readonly error: Error | undefined;
26
- };
27
- };
28
- export declare const updateIsAbortedUpload: (cacheKey: string, isAborted: boolean) => {
29
- readonly type: "UPDATE_IS_ABORTED_UPLOAD";
30
- readonly payload: {
31
- readonly cacheKey: string;
32
- readonly isAborted: boolean;
33
- };
34
- };
35
- export declare const removeUploadInstance: (cacheKey: string) => {
36
- readonly type: "REMOVE_UPLOAD_INSTANCE";
37
- readonly payload: {
38
- readonly cacheKey: string;
39
- };
40
- };
41
- export declare const resetClient: () => {
42
- readonly type: "RESET_CLIENT";
43
- };
44
- export declare const updateTusHandlerOptions: (payload: TusConfigs) => {
45
- readonly type: "UPDATE_TUS_HANDLER_OPTIONS";
46
- readonly payload: Partial<{
47
- canStoreURLs: boolean;
48
- defaultOptions: import("./tusHandler").DefaultOptions;
49
- }>;
50
- };
1
+ import type { Upload } from 'tus-js-client';
2
+ import { TusConfigs } from './tusHandler';
3
+ export declare type TusClientActions = ReturnType<typeof insertUploadInstance | typeof removeUploadInstance | typeof resetClient | typeof updateSuccessUpload | typeof updateErrorUpload | typeof updateIsAbortedUpload | typeof updateTusHandlerOptions>;
4
+ export declare const insertUploadInstance: (cacheKey: string, upload: Upload) => {
5
+ readonly type: "INSERT_UPLOAD_INSTANCE";
6
+ readonly payload: {
7
+ readonly cacheKey: string;
8
+ readonly uploadState: {
9
+ readonly upload: Upload;
10
+ readonly isSuccess: false;
11
+ readonly isAborted: false;
12
+ };
13
+ };
14
+ };
15
+ export declare const updateSuccessUpload: (cacheKey: string) => {
16
+ readonly type: "UPDATE_SUCCESS_UPLOAD";
17
+ readonly payload: {
18
+ readonly cacheKey: string;
19
+ };
20
+ };
21
+ export declare const updateErrorUpload: (cacheKey: string, error?: Error | undefined) => {
22
+ readonly type: "UPDATE_ERROR_UPLOAD";
23
+ readonly payload: {
24
+ readonly cacheKey: string;
25
+ readonly error: Error | undefined;
26
+ };
27
+ };
28
+ export declare const updateIsAbortedUpload: (cacheKey: string, isAborted: boolean) => {
29
+ readonly type: "UPDATE_IS_ABORTED_UPLOAD";
30
+ readonly payload: {
31
+ readonly cacheKey: string;
32
+ readonly isAborted: boolean;
33
+ };
34
+ };
35
+ export declare const removeUploadInstance: (cacheKey: string) => {
36
+ readonly type: "REMOVE_UPLOAD_INSTANCE";
37
+ readonly payload: {
38
+ readonly cacheKey: string;
39
+ };
40
+ };
41
+ export declare const resetClient: () => {
42
+ readonly type: "RESET_CLIENT";
43
+ };
44
+ export declare const updateTusHandlerOptions: (payload: TusConfigs) => {
45
+ readonly type: "UPDATE_TUS_HANDLER_OPTIONS";
46
+ readonly payload: Partial<{
47
+ canStoreURLs: boolean;
48
+ defaultOptions: import("./tusHandler").DefaultOptions;
49
+ }>;
50
+ };
@@ -1,18 +1,18 @@
1
- import type { Reducer } from 'react';
2
- import type { Upload } from 'tus-js-client';
3
- import { TusClientActions } from './tucClientActions';
4
- import { TusHandler } from './tusHandler';
5
- export declare type UploadState = {
6
- upload: Upload | undefined;
7
- isSuccess: boolean;
8
- isAborted: boolean;
9
- error?: Error;
10
- };
11
- export declare type TusClientState = {
12
- uploads: {
13
- [cacheKey: string]: UploadState | undefined;
14
- };
15
- tusHandler: TusHandler;
16
- };
17
- export declare const tusClientReducer: Reducer<TusClientState, TusClientActions>;
18
- export declare const tusClientInitialState: TusClientState;
1
+ import type { Reducer } from 'react';
2
+ import type { Upload } from 'tus-js-client';
3
+ import { TusClientActions } from './tucClientActions';
4
+ import { TusHandler } from './tusHandler';
5
+ export declare type UploadState = {
6
+ upload: Upload | undefined;
7
+ isSuccess: boolean;
8
+ isAborted: boolean;
9
+ error?: Error;
10
+ };
11
+ export declare type TusClientState = {
12
+ uploads: {
13
+ [cacheKey: string]: UploadState | undefined;
14
+ };
15
+ tusHandler: TusHandler;
16
+ };
17
+ export declare const tusClientReducer: Reducer<TusClientState, TusClientActions>;
18
+ export declare const tusClientInitialState: TusClientState;
@@ -1,17 +1,17 @@
1
- import * as tus from 'tus-js-client';
2
- import { Upload } from 'tus-js-client';
3
- export declare type DefaultOptions = (file: Upload['file']) => tus.UploadOptions;
4
- export declare type TusConfigs = Partial<{
5
- canStoreURLs: boolean;
6
- defaultOptions: DefaultOptions;
7
- }>;
8
- export declare type Tus = Readonly<Omit<typeof tus, 'defaultOptions'> & Required<TusConfigs>>;
9
- export declare const initialDefaultOptions: DefaultOptions;
10
- export declare class TusHandler {
11
- private tus;
12
- constructor(tusConfigs?: TusConfigs);
13
- get getTus(): Readonly<Omit<typeof tus, "defaultOptions"> & Required<Partial<{
14
- canStoreURLs: boolean;
15
- defaultOptions: DefaultOptions;
16
- }>>>;
17
- }
1
+ import * as tus from 'tus-js-client';
2
+ import { Upload } from 'tus-js-client';
3
+ export declare type DefaultOptions = (file: Upload['file']) => tus.UploadOptions;
4
+ export declare type TusConfigs = Partial<{
5
+ canStoreURLs: boolean;
6
+ defaultOptions: DefaultOptions;
7
+ }>;
8
+ export declare type Tus = Readonly<Omit<typeof tus, 'defaultOptions'> & Required<TusConfigs>>;
9
+ export declare const initialDefaultOptions: DefaultOptions;
10
+ export declare class TusHandler {
11
+ private tus;
12
+ constructor(tusConfigs?: TusConfigs);
13
+ get getTus(): Readonly<Omit<typeof tus, "defaultOptions"> & Required<Partial<{
14
+ canStoreURLs: boolean;
15
+ defaultOptions: DefaultOptions;
16
+ }>>>;
17
+ }
@@ -1,8 +1,8 @@
1
- import { Upload } from 'tus-js-client';
2
- export declare type BaseUseTusResult = {
3
- upload?: Upload;
4
- setUpload: (file: Upload['file'], options?: Upload['options']) => void;
5
- isSuccess: boolean;
6
- error?: Error;
7
- };
8
- export declare type BaseUseTusOptions = {};
1
+ import { Upload } from 'tus-js-client';
2
+ export declare type BaseUseTusResult = {
3
+ upload?: Upload;
4
+ setUpload: (file: Upload['file'], options?: Upload['options']) => void;
5
+ isSuccess: boolean;
6
+ error?: Error;
7
+ };
8
+ export declare type BaseUseTusOptions = {};