@scaleflex/widget-core 4.0.7 → 4.3.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.
- package/CHANGELOG.md +7519 -7491
- package/LICENSE +21 -21
- package/README.md +1201 -1211
- package/dist/style.css +94 -58
- package/dist/style.min.css +1 -1
- package/lib/Client.js +5 -5
- package/lib/Plugin.js +40 -40
- package/lib/SassKeyRenewer.js +12 -12
- package/lib/_common.scss +243 -243
- package/lib/_utils.scss +38 -38
- package/lib/_variables.scss +63 -63
- package/lib/index.js +196 -196
- package/lib/slices/common.slice.js +9 -9
- package/lib/slices/info.slice.js +10 -10
- package/lib/slices/uploads.slice.js +9 -9
- package/lib/slices/user.slice.js +9 -9
- package/lib/style.scss +3 -3
- package/package.json +3 -3
- package/types/index.d.ts +301 -301
package/types/index.d.ts
CHANGED
|
@@ -1,301 +1,301 @@
|
|
|
1
|
-
const FilerobotUtils = require("@scaleflex/widget-utils");
|
|
2
|
-
|
|
3
|
-
declare module Filerobot {
|
|
4
|
-
// Utility types
|
|
5
|
-
type OmitKey<T, Key> = Pick<T, Exclude<keyof T, Key>>;
|
|
6
|
-
|
|
7
|
-
// These are defined in @scaleflex/widget-utils instead of core so it can be used there without creating import cycles
|
|
8
|
-
export type FilerobotFile<
|
|
9
|
-
TMeta extends IndexedObject<any> = {},
|
|
10
|
-
TBody extends IndexedObject<any> = {}
|
|
11
|
-
> = FilerobotUtils.FilerobotFile<TMeta, TBody>;
|
|
12
|
-
export type Store = FilerobotUtils.Store;
|
|
13
|
-
export type InternalMetadata = FilerobotUtils.InternalMetadata;
|
|
14
|
-
|
|
15
|
-
interface IndexedObject<T> {
|
|
16
|
-
[key: string]: T;
|
|
17
|
-
[key: number]: T;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
interface UploadedFilerobotFile<TMeta, TBody>
|
|
21
|
-
extends FilerobotFile<TMeta, TBody> {
|
|
22
|
-
uploadURL: string;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
interface FailedFilerobotFile<TMeta, TBody>
|
|
26
|
-
extends FilerobotFile<TMeta, TBody> {
|
|
27
|
-
error: string;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
// Replace the `meta` property type with one that allows omitting internal metadata; addFile() will add that
|
|
31
|
-
type FilerobotFileWithoutMeta<TMeta, TBody> = OmitKey<
|
|
32
|
-
FilerobotFile<TMeta, TBody>,
|
|
33
|
-
"meta"
|
|
34
|
-
>;
|
|
35
|
-
interface AddFileOptions<
|
|
36
|
-
TMeta = IndexedObject<any>,
|
|
37
|
-
TBody = IndexedObject<any>
|
|
38
|
-
> extends Partial<FilerobotFileWithoutMeta<TMeta, TBody>> {
|
|
39
|
-
// `.data` is the only required property here.
|
|
40
|
-
data: Blob | File;
|
|
41
|
-
meta?: Partial<InternalMetadata> & TMeta;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
interface PluginOptions {
|
|
45
|
-
id?: string;
|
|
46
|
-
}
|
|
47
|
-
interface DefaultPluginOptions extends PluginOptions {
|
|
48
|
-
[prop: string]: any;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
type PluginTarget = string | Element | typeof Plugin;
|
|
52
|
-
|
|
53
|
-
class Plugin<TOptions extends PluginOptions = DefaultPluginOptions> {
|
|
54
|
-
id: string;
|
|
55
|
-
filerobot: Filerobot;
|
|
56
|
-
type: string;
|
|
57
|
-
constructor(filerobot: Filerobot, opts?: TOptions);
|
|
58
|
-
setOptions(update: Partial<TOptions>): void;
|
|
59
|
-
getPluginState(): object;
|
|
60
|
-
setPluginState(update: IndexedObject<any>): object;
|
|
61
|
-
update(state?: object): void;
|
|
62
|
-
mount(target: PluginTarget, plugin: typeof Plugin): void;
|
|
63
|
-
render(state: object): void;
|
|
64
|
-
addTarget<TPlugin extends Plugin>(plugin: TPlugin): void;
|
|
65
|
-
unmount(): void;
|
|
66
|
-
install(): void;
|
|
67
|
-
uninstall(): void;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
type LocaleStrings<TNames extends string> = {
|
|
71
|
-
[K in TNames]?: string | { [n: number]: string };
|
|
72
|
-
};
|
|
73
|
-
interface Locale<TNames extends string = string> {
|
|
74
|
-
strings: LocaleStrings<TNames>;
|
|
75
|
-
pluralize?: (n: number) => number;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
interface Restrictions {
|
|
79
|
-
maxFileSize?: number | null;
|
|
80
|
-
maxNumberOfFiles?: number | null;
|
|
81
|
-
minNumberOfFiles?: number | null;
|
|
82
|
-
allowedFileTypes?: string[] | null;
|
|
83
|
-
maxItemsSizeForCompression: number | null;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
interface FilerobotOptions<TMeta extends IndexedObject<any> = {}> {
|
|
87
|
-
container: string;
|
|
88
|
-
securityTemplateId?: string;
|
|
89
|
-
sassKey?: string;
|
|
90
|
-
dev?: boolean;
|
|
91
|
-
userInfo?: {
|
|
92
|
-
email: string;
|
|
93
|
-
name: string;
|
|
94
|
-
photo_uri: string;
|
|
95
|
-
uuid: string;
|
|
96
|
-
};
|
|
97
|
-
autoProceed?: boolean;
|
|
98
|
-
allowMultipleUploads?: boolean;
|
|
99
|
-
debug?: boolean;
|
|
100
|
-
restrictions?: Restrictions;
|
|
101
|
-
meta?: TMeta;
|
|
102
|
-
onBeforeFileAdded?: (
|
|
103
|
-
currentFile: FilerobotFile<TMeta>,
|
|
104
|
-
files: { [key: string]: FilerobotFile<TMeta> }
|
|
105
|
-
) => FilerobotFile<TMeta> | boolean | undefined;
|
|
106
|
-
onBeforeUpload?: (files: {
|
|
107
|
-
[key: string]: FilerobotFile<TMeta>;
|
|
108
|
-
}) => { [key: string]: FilerobotFile<TMeta> } | boolean;
|
|
109
|
-
locale?: Locale;
|
|
110
|
-
store?: Store;
|
|
111
|
-
userPermissions?: string[];
|
|
112
|
-
userFoldersScope?: string[];
|
|
113
|
-
apiEndpoint?: string;
|
|
114
|
-
skipApiEndpointToken?: boolean;
|
|
115
|
-
adminApiEndpoint?: string;
|
|
116
|
-
shareApiEndpoint?: string;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
interface UploadResult<
|
|
120
|
-
TMeta extends IndexedObject<any> = {},
|
|
121
|
-
TBody extends IndexedObject<any> = {}
|
|
122
|
-
> {
|
|
123
|
-
successful: UploadedFilerobotFile<TMeta, TBody>[];
|
|
124
|
-
failed: FailedFilerobotFile<TMeta, TBody>[];
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
interface State<
|
|
128
|
-
TMeta extends IndexedObject<any> = {},
|
|
129
|
-
TBody extends IndexedObject<any> = {}
|
|
130
|
-
> extends IndexedObject<any> {
|
|
131
|
-
capabilities?: { resumableUploads?: boolean };
|
|
132
|
-
currentUploads: {};
|
|
133
|
-
error?: string;
|
|
134
|
-
files: {
|
|
135
|
-
[key: string]:
|
|
136
|
-
| UploadedFilerobotFile<TMeta, TBody>
|
|
137
|
-
| FailedFilerobotFile<TMeta, TBody>;
|
|
138
|
-
};
|
|
139
|
-
info?: {
|
|
140
|
-
isHidden: boolean;
|
|
141
|
-
type: string;
|
|
142
|
-
message: string;
|
|
143
|
-
details: string;
|
|
144
|
-
};
|
|
145
|
-
plugins?: IndexedObject<any>;
|
|
146
|
-
totalProgress: number;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
type LogLevel = "info" | "warning" | "error";
|
|
150
|
-
|
|
151
|
-
/** Enable the old, untyped `filerobot.use()` signature. */
|
|
152
|
-
type LooseTypes = "loose";
|
|
153
|
-
/** Disable the old, untyped `filerobot.use()` signature. */
|
|
154
|
-
type StrictTypes = "strict";
|
|
155
|
-
type TypeChecking = LooseTypes | StrictTypes;
|
|
156
|
-
|
|
157
|
-
// This hack accepts _any_ string for `Event`, but also tricks VSCode and friends into providing autocompletions
|
|
158
|
-
// for the names listed. https://github.com/microsoft/TypeScript/issues/29729#issuecomment-505826972
|
|
159
|
-
type LiteralUnion<T extends U, U = string> = T | (U & {});
|
|
160
|
-
type Event = LiteralUnion<
|
|
161
|
-
| "file-added"
|
|
162
|
-
| "file-removed"
|
|
163
|
-
| "upload"
|
|
164
|
-
| "upload-progress"
|
|
165
|
-
| "upload-success"
|
|
166
|
-
| "complete"
|
|
167
|
-
| "error"
|
|
168
|
-
| "upload-error"
|
|
169
|
-
| "upload-retry"
|
|
170
|
-
| "info-visible"
|
|
171
|
-
| "info-hidden"
|
|
172
|
-
| "cancel-uploads"
|
|
173
|
-
| "restriction-failed"
|
|
174
|
-
| "reset-progress"
|
|
175
|
-
>;
|
|
176
|
-
|
|
177
|
-
type UploadHandler = (fileIDs: string[]) => Promise<void>;
|
|
178
|
-
|
|
179
|
-
class Filerobot<TUseStrictTypes extends TypeChecking = TypeChecking> {
|
|
180
|
-
constructor(opts?: FilerobotOptions);
|
|
181
|
-
on<TMeta extends IndexedObject<any> = {}>(
|
|
182
|
-
event: "upload-success",
|
|
183
|
-
callback: (
|
|
184
|
-
file: FilerobotFile<TMeta>,
|
|
185
|
-
body: any,
|
|
186
|
-
uploadURL: string
|
|
187
|
-
) => void
|
|
188
|
-
): this;
|
|
189
|
-
on<TMeta extends IndexedObject<any> = {}>(
|
|
190
|
-
event: "complete",
|
|
191
|
-
callback: (result: UploadResult<TMeta>) => void
|
|
192
|
-
): this;
|
|
193
|
-
on(event: Event, callback: (...args: any[]) => void): this;
|
|
194
|
-
off(event: Event, callback: (...args: any[]) => void): this;
|
|
195
|
-
/**
|
|
196
|
-
* For use by plugins only.
|
|
197
|
-
*/
|
|
198
|
-
emit(event: Event, ...args: any[]): void;
|
|
199
|
-
updateAll(state: object): void;
|
|
200
|
-
setOptions(update: Partial<FilerobotOptions>): void;
|
|
201
|
-
setState(patch: object): void;
|
|
202
|
-
getState<TMeta extends IndexedObject<any> = {}>(): State<TMeta>;
|
|
203
|
-
readonly state: State;
|
|
204
|
-
addPreProcessor(fn: UploadHandler): void;
|
|
205
|
-
removePreProcessor(fn: UploadHandler): void;
|
|
206
|
-
addPostProcessor(fn: UploadHandler): void;
|
|
207
|
-
removePostProcessor(fn: UploadHandler): void;
|
|
208
|
-
addFilerobot(fn: UploadHandler): void;
|
|
209
|
-
removeFilerobot(fn: UploadHandler): void;
|
|
210
|
-
setMeta<TMeta extends IndexedObject<any> = {}>(data: TMeta): void;
|
|
211
|
-
setFileMeta<TMeta extends IndexedObject<any> = {}>(
|
|
212
|
-
fileID: string,
|
|
213
|
-
data: TMeta
|
|
214
|
-
): void;
|
|
215
|
-
getFile<
|
|
216
|
-
TMeta extends IndexedObject<any> = {},
|
|
217
|
-
TBody extends IndexedObject<any> = {}
|
|
218
|
-
>(fileID: string): FilerobotFile<TMeta, TBody>;
|
|
219
|
-
getFiles<
|
|
220
|
-
TMeta extends IndexedObject<any> = {},
|
|
221
|
-
TBody extends IndexedObject<any> = {}
|
|
222
|
-
>(): Array<FilerobotFile<TMeta, TBody>>;
|
|
223
|
-
addFile<TMeta extends IndexedObject<any> = {}>(
|
|
224
|
-
file: AddFileOptions<TMeta>
|
|
225
|
-
): void;
|
|
226
|
-
removeFile(fileID: string): void;
|
|
227
|
-
pauseResume(fileID: string): void;
|
|
228
|
-
cancelUploads(): void;
|
|
229
|
-
retryUpload<TMeta extends IndexedObject<any> = {}>(
|
|
230
|
-
fileID: string
|
|
231
|
-
): Promise<UploadResult<TMeta>>;
|
|
232
|
-
pauseAll(): void;
|
|
233
|
-
resumeAll(): void;
|
|
234
|
-
retryAll<TMeta extends IndexedObject<any> = {}>(): Promise<
|
|
235
|
-
UploadResult<TMeta>
|
|
236
|
-
>;
|
|
237
|
-
cancelAll(): void;
|
|
238
|
-
getId(): string;
|
|
239
|
-
/**
|
|
240
|
-
* Add a plugin to this Filerobot instance.
|
|
241
|
-
*/
|
|
242
|
-
use<TOptions, TInstance extends Plugin<TOptions>>(
|
|
243
|
-
pluginClass: new (filerobot: this, opts: TOptions) => TInstance,
|
|
244
|
-
opts?: TOptions
|
|
245
|
-
): this;
|
|
246
|
-
/**
|
|
247
|
-
* Fallback `.use()` overload with unchecked plugin options.
|
|
248
|
-
*
|
|
249
|
-
* This does not validate that the options you pass in are correct.
|
|
250
|
-
* We recommend disabling this overload by using the `Filerobot<Filerobot.StrictTypes>` type, instead of the plain `Filerobot` type, to enforce strict typechecking.
|
|
251
|
-
* This overload will be removed in Filerobot 2.0.
|
|
252
|
-
*/
|
|
253
|
-
use(
|
|
254
|
-
pluginClass: TUseStrictTypes extends StrictTypes
|
|
255
|
-
? never
|
|
256
|
-
: new (filerobot: this, opts: any) => Plugin<any>,
|
|
257
|
-
opts?: object
|
|
258
|
-
): this;
|
|
259
|
-
getPlugin(name: string): Plugin;
|
|
260
|
-
iteratePlugins(callback: (plugin: Plugin) => void): void;
|
|
261
|
-
removePlugin(instance: Plugin): void;
|
|
262
|
-
close(): void;
|
|
263
|
-
info(
|
|
264
|
-
message: string | { message: string; details: string },
|
|
265
|
-
type?: LogLevel,
|
|
266
|
-
duration?: number
|
|
267
|
-
): void;
|
|
268
|
-
hideInfo(): void;
|
|
269
|
-
log(msg: string, type?: LogLevel): void;
|
|
270
|
-
/**
|
|
271
|
-
* Obsolete: do not use. This method does nothing and will be removed in a future release.
|
|
272
|
-
*/
|
|
273
|
-
run(): this;
|
|
274
|
-
restore<TMeta extends IndexedObject<any> = {}>(
|
|
275
|
-
uploadID: string
|
|
276
|
-
): Promise<UploadResult<TMeta>>;
|
|
277
|
-
addResultData(uploadID: string, data: object): void;
|
|
278
|
-
upload<TMeta extends IndexedObject<any> = {}>(): Promise<
|
|
279
|
-
UploadResult<TMeta>
|
|
280
|
-
>;
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
/**
|
|
285
|
-
* Create a filerobot instance.
|
|
286
|
-
*
|
|
287
|
-
* By default, Filerobot's `.use(Plugin, options)` method uses loose type checking.
|
|
288
|
-
* In Filerobot 2.0, the `.use()` method will get a stricter type signature. You can enable strict type checking of plugin classes and their options today by using:
|
|
289
|
-
* ```ts
|
|
290
|
-
* const filerobot = Filerobot<Filerobot.StrictTypes>()
|
|
291
|
-
* ```
|
|
292
|
-
* Make sure to also declare any variables and class properties with the `StrictTypes` parameter:
|
|
293
|
-
* ```ts
|
|
294
|
-
* private filerobot: Filerobot<Filerobot.StrictTypes>;
|
|
295
|
-
* ```
|
|
296
|
-
*/
|
|
297
|
-
declare function Filerobot<
|
|
298
|
-
TUseStrictTypes extends Filerobot.TypeChecking = Filerobot.TypeChecking
|
|
299
|
-
>(opts?: Filerobot.FilerobotOptions): Filerobot.Filerobot<TUseStrictTypes>;
|
|
300
|
-
|
|
301
|
-
export = Filerobot;
|
|
1
|
+
const FilerobotUtils = require("@scaleflex/widget-utils");
|
|
2
|
+
|
|
3
|
+
declare module Filerobot {
|
|
4
|
+
// Utility types
|
|
5
|
+
type OmitKey<T, Key> = Pick<T, Exclude<keyof T, Key>>;
|
|
6
|
+
|
|
7
|
+
// These are defined in @scaleflex/widget-utils instead of core so it can be used there without creating import cycles
|
|
8
|
+
export type FilerobotFile<
|
|
9
|
+
TMeta extends IndexedObject<any> = {},
|
|
10
|
+
TBody extends IndexedObject<any> = {}
|
|
11
|
+
> = FilerobotUtils.FilerobotFile<TMeta, TBody>;
|
|
12
|
+
export type Store = FilerobotUtils.Store;
|
|
13
|
+
export type InternalMetadata = FilerobotUtils.InternalMetadata;
|
|
14
|
+
|
|
15
|
+
interface IndexedObject<T> {
|
|
16
|
+
[key: string]: T;
|
|
17
|
+
[key: number]: T;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
interface UploadedFilerobotFile<TMeta, TBody>
|
|
21
|
+
extends FilerobotFile<TMeta, TBody> {
|
|
22
|
+
uploadURL: string;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
interface FailedFilerobotFile<TMeta, TBody>
|
|
26
|
+
extends FilerobotFile<TMeta, TBody> {
|
|
27
|
+
error: string;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// Replace the `meta` property type with one that allows omitting internal metadata; addFile() will add that
|
|
31
|
+
type FilerobotFileWithoutMeta<TMeta, TBody> = OmitKey<
|
|
32
|
+
FilerobotFile<TMeta, TBody>,
|
|
33
|
+
"meta"
|
|
34
|
+
>;
|
|
35
|
+
interface AddFileOptions<
|
|
36
|
+
TMeta = IndexedObject<any>,
|
|
37
|
+
TBody = IndexedObject<any>
|
|
38
|
+
> extends Partial<FilerobotFileWithoutMeta<TMeta, TBody>> {
|
|
39
|
+
// `.data` is the only required property here.
|
|
40
|
+
data: Blob | File;
|
|
41
|
+
meta?: Partial<InternalMetadata> & TMeta;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
interface PluginOptions {
|
|
45
|
+
id?: string;
|
|
46
|
+
}
|
|
47
|
+
interface DefaultPluginOptions extends PluginOptions {
|
|
48
|
+
[prop: string]: any;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
type PluginTarget = string | Element | typeof Plugin;
|
|
52
|
+
|
|
53
|
+
class Plugin<TOptions extends PluginOptions = DefaultPluginOptions> {
|
|
54
|
+
id: string;
|
|
55
|
+
filerobot: Filerobot;
|
|
56
|
+
type: string;
|
|
57
|
+
constructor(filerobot: Filerobot, opts?: TOptions);
|
|
58
|
+
setOptions(update: Partial<TOptions>): void;
|
|
59
|
+
getPluginState(): object;
|
|
60
|
+
setPluginState(update: IndexedObject<any>): object;
|
|
61
|
+
update(state?: object): void;
|
|
62
|
+
mount(target: PluginTarget, plugin: typeof Plugin): void;
|
|
63
|
+
render(state: object): void;
|
|
64
|
+
addTarget<TPlugin extends Plugin>(plugin: TPlugin): void;
|
|
65
|
+
unmount(): void;
|
|
66
|
+
install(): void;
|
|
67
|
+
uninstall(): void;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
type LocaleStrings<TNames extends string> = {
|
|
71
|
+
[K in TNames]?: string | { [n: number]: string };
|
|
72
|
+
};
|
|
73
|
+
interface Locale<TNames extends string = string> {
|
|
74
|
+
strings: LocaleStrings<TNames>;
|
|
75
|
+
pluralize?: (n: number) => number;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
interface Restrictions {
|
|
79
|
+
maxFileSize?: number | null;
|
|
80
|
+
maxNumberOfFiles?: number | null;
|
|
81
|
+
minNumberOfFiles?: number | null;
|
|
82
|
+
allowedFileTypes?: string[] | null;
|
|
83
|
+
maxItemsSizeForCompression: number | null;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
interface FilerobotOptions<TMeta extends IndexedObject<any> = {}> {
|
|
87
|
+
container: string;
|
|
88
|
+
securityTemplateId?: string;
|
|
89
|
+
sassKey?: string;
|
|
90
|
+
dev?: boolean;
|
|
91
|
+
userInfo?: {
|
|
92
|
+
email: string;
|
|
93
|
+
name: string;
|
|
94
|
+
photo_uri: string;
|
|
95
|
+
uuid: string;
|
|
96
|
+
};
|
|
97
|
+
autoProceed?: boolean;
|
|
98
|
+
allowMultipleUploads?: boolean;
|
|
99
|
+
debug?: boolean;
|
|
100
|
+
restrictions?: Restrictions;
|
|
101
|
+
meta?: TMeta;
|
|
102
|
+
onBeforeFileAdded?: (
|
|
103
|
+
currentFile: FilerobotFile<TMeta>,
|
|
104
|
+
files: { [key: string]: FilerobotFile<TMeta> }
|
|
105
|
+
) => FilerobotFile<TMeta> | boolean | undefined;
|
|
106
|
+
onBeforeUpload?: (files: {
|
|
107
|
+
[key: string]: FilerobotFile<TMeta>;
|
|
108
|
+
}) => { [key: string]: FilerobotFile<TMeta> } | boolean;
|
|
109
|
+
locale?: Locale;
|
|
110
|
+
store?: Store;
|
|
111
|
+
userPermissions?: string[];
|
|
112
|
+
userFoldersScope?: string[];
|
|
113
|
+
apiEndpoint?: string;
|
|
114
|
+
skipApiEndpointToken?: boolean;
|
|
115
|
+
adminApiEndpoint?: string;
|
|
116
|
+
shareApiEndpoint?: string;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
interface UploadResult<
|
|
120
|
+
TMeta extends IndexedObject<any> = {},
|
|
121
|
+
TBody extends IndexedObject<any> = {}
|
|
122
|
+
> {
|
|
123
|
+
successful: UploadedFilerobotFile<TMeta, TBody>[];
|
|
124
|
+
failed: FailedFilerobotFile<TMeta, TBody>[];
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
interface State<
|
|
128
|
+
TMeta extends IndexedObject<any> = {},
|
|
129
|
+
TBody extends IndexedObject<any> = {}
|
|
130
|
+
> extends IndexedObject<any> {
|
|
131
|
+
capabilities?: { resumableUploads?: boolean };
|
|
132
|
+
currentUploads: {};
|
|
133
|
+
error?: string;
|
|
134
|
+
files: {
|
|
135
|
+
[key: string]:
|
|
136
|
+
| UploadedFilerobotFile<TMeta, TBody>
|
|
137
|
+
| FailedFilerobotFile<TMeta, TBody>;
|
|
138
|
+
};
|
|
139
|
+
info?: {
|
|
140
|
+
isHidden: boolean;
|
|
141
|
+
type: string;
|
|
142
|
+
message: string;
|
|
143
|
+
details: string;
|
|
144
|
+
};
|
|
145
|
+
plugins?: IndexedObject<any>;
|
|
146
|
+
totalProgress: number;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
type LogLevel = "info" | "warning" | "error";
|
|
150
|
+
|
|
151
|
+
/** Enable the old, untyped `filerobot.use()` signature. */
|
|
152
|
+
type LooseTypes = "loose";
|
|
153
|
+
/** Disable the old, untyped `filerobot.use()` signature. */
|
|
154
|
+
type StrictTypes = "strict";
|
|
155
|
+
type TypeChecking = LooseTypes | StrictTypes;
|
|
156
|
+
|
|
157
|
+
// This hack accepts _any_ string for `Event`, but also tricks VSCode and friends into providing autocompletions
|
|
158
|
+
// for the names listed. https://github.com/microsoft/TypeScript/issues/29729#issuecomment-505826972
|
|
159
|
+
type LiteralUnion<T extends U, U = string> = T | (U & {});
|
|
160
|
+
type Event = LiteralUnion<
|
|
161
|
+
| "file-added"
|
|
162
|
+
| "file-removed"
|
|
163
|
+
| "upload"
|
|
164
|
+
| "upload-progress"
|
|
165
|
+
| "upload-success"
|
|
166
|
+
| "complete"
|
|
167
|
+
| "error"
|
|
168
|
+
| "upload-error"
|
|
169
|
+
| "upload-retry"
|
|
170
|
+
| "info-visible"
|
|
171
|
+
| "info-hidden"
|
|
172
|
+
| "cancel-uploads"
|
|
173
|
+
| "restriction-failed"
|
|
174
|
+
| "reset-progress"
|
|
175
|
+
>;
|
|
176
|
+
|
|
177
|
+
type UploadHandler = (fileIDs: string[]) => Promise<void>;
|
|
178
|
+
|
|
179
|
+
class Filerobot<TUseStrictTypes extends TypeChecking = TypeChecking> {
|
|
180
|
+
constructor(opts?: FilerobotOptions);
|
|
181
|
+
on<TMeta extends IndexedObject<any> = {}>(
|
|
182
|
+
event: "upload-success",
|
|
183
|
+
callback: (
|
|
184
|
+
file: FilerobotFile<TMeta>,
|
|
185
|
+
body: any,
|
|
186
|
+
uploadURL: string
|
|
187
|
+
) => void
|
|
188
|
+
): this;
|
|
189
|
+
on<TMeta extends IndexedObject<any> = {}>(
|
|
190
|
+
event: "complete",
|
|
191
|
+
callback: (result: UploadResult<TMeta>) => void
|
|
192
|
+
): this;
|
|
193
|
+
on(event: Event, callback: (...args: any[]) => void): this;
|
|
194
|
+
off(event: Event, callback: (...args: any[]) => void): this;
|
|
195
|
+
/**
|
|
196
|
+
* For use by plugins only.
|
|
197
|
+
*/
|
|
198
|
+
emit(event: Event, ...args: any[]): void;
|
|
199
|
+
updateAll(state: object): void;
|
|
200
|
+
setOptions(update: Partial<FilerobotOptions>): void;
|
|
201
|
+
setState(patch: object): void;
|
|
202
|
+
getState<TMeta extends IndexedObject<any> = {}>(): State<TMeta>;
|
|
203
|
+
readonly state: State;
|
|
204
|
+
addPreProcessor(fn: UploadHandler): void;
|
|
205
|
+
removePreProcessor(fn: UploadHandler): void;
|
|
206
|
+
addPostProcessor(fn: UploadHandler): void;
|
|
207
|
+
removePostProcessor(fn: UploadHandler): void;
|
|
208
|
+
addFilerobot(fn: UploadHandler): void;
|
|
209
|
+
removeFilerobot(fn: UploadHandler): void;
|
|
210
|
+
setMeta<TMeta extends IndexedObject<any> = {}>(data: TMeta): void;
|
|
211
|
+
setFileMeta<TMeta extends IndexedObject<any> = {}>(
|
|
212
|
+
fileID: string,
|
|
213
|
+
data: TMeta
|
|
214
|
+
): void;
|
|
215
|
+
getFile<
|
|
216
|
+
TMeta extends IndexedObject<any> = {},
|
|
217
|
+
TBody extends IndexedObject<any> = {}
|
|
218
|
+
>(fileID: string): FilerobotFile<TMeta, TBody>;
|
|
219
|
+
getFiles<
|
|
220
|
+
TMeta extends IndexedObject<any> = {},
|
|
221
|
+
TBody extends IndexedObject<any> = {}
|
|
222
|
+
>(): Array<FilerobotFile<TMeta, TBody>>;
|
|
223
|
+
addFile<TMeta extends IndexedObject<any> = {}>(
|
|
224
|
+
file: AddFileOptions<TMeta>
|
|
225
|
+
): void;
|
|
226
|
+
removeFile(fileID: string): void;
|
|
227
|
+
pauseResume(fileID: string): void;
|
|
228
|
+
cancelUploads(): void;
|
|
229
|
+
retryUpload<TMeta extends IndexedObject<any> = {}>(
|
|
230
|
+
fileID: string
|
|
231
|
+
): Promise<UploadResult<TMeta>>;
|
|
232
|
+
pauseAll(): void;
|
|
233
|
+
resumeAll(): void;
|
|
234
|
+
retryAll<TMeta extends IndexedObject<any> = {}>(): Promise<
|
|
235
|
+
UploadResult<TMeta>
|
|
236
|
+
>;
|
|
237
|
+
cancelAll(): void;
|
|
238
|
+
getId(): string;
|
|
239
|
+
/**
|
|
240
|
+
* Add a plugin to this Filerobot instance.
|
|
241
|
+
*/
|
|
242
|
+
use<TOptions, TInstance extends Plugin<TOptions>>(
|
|
243
|
+
pluginClass: new (filerobot: this, opts: TOptions) => TInstance,
|
|
244
|
+
opts?: TOptions
|
|
245
|
+
): this;
|
|
246
|
+
/**
|
|
247
|
+
* Fallback `.use()` overload with unchecked plugin options.
|
|
248
|
+
*
|
|
249
|
+
* This does not validate that the options you pass in are correct.
|
|
250
|
+
* We recommend disabling this overload by using the `Filerobot<Filerobot.StrictTypes>` type, instead of the plain `Filerobot` type, to enforce strict typechecking.
|
|
251
|
+
* This overload will be removed in Filerobot 2.0.
|
|
252
|
+
*/
|
|
253
|
+
use(
|
|
254
|
+
pluginClass: TUseStrictTypes extends StrictTypes
|
|
255
|
+
? never
|
|
256
|
+
: new (filerobot: this, opts: any) => Plugin<any>,
|
|
257
|
+
opts?: object
|
|
258
|
+
): this;
|
|
259
|
+
getPlugin(name: string): Plugin;
|
|
260
|
+
iteratePlugins(callback: (plugin: Plugin) => void): void;
|
|
261
|
+
removePlugin(instance: Plugin): void;
|
|
262
|
+
close(): void;
|
|
263
|
+
info(
|
|
264
|
+
message: string | { message: string; details: string },
|
|
265
|
+
type?: LogLevel,
|
|
266
|
+
duration?: number
|
|
267
|
+
): void;
|
|
268
|
+
hideInfo(): void;
|
|
269
|
+
log(msg: string, type?: LogLevel): void;
|
|
270
|
+
/**
|
|
271
|
+
* Obsolete: do not use. This method does nothing and will be removed in a future release.
|
|
272
|
+
*/
|
|
273
|
+
run(): this;
|
|
274
|
+
restore<TMeta extends IndexedObject<any> = {}>(
|
|
275
|
+
uploadID: string
|
|
276
|
+
): Promise<UploadResult<TMeta>>;
|
|
277
|
+
addResultData(uploadID: string, data: object): void;
|
|
278
|
+
upload<TMeta extends IndexedObject<any> = {}>(): Promise<
|
|
279
|
+
UploadResult<TMeta>
|
|
280
|
+
>;
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
/**
|
|
285
|
+
* Create a filerobot instance.
|
|
286
|
+
*
|
|
287
|
+
* By default, Filerobot's `.use(Plugin, options)` method uses loose type checking.
|
|
288
|
+
* In Filerobot 2.0, the `.use()` method will get a stricter type signature. You can enable strict type checking of plugin classes and their options today by using:
|
|
289
|
+
* ```ts
|
|
290
|
+
* const filerobot = Filerobot<Filerobot.StrictTypes>()
|
|
291
|
+
* ```
|
|
292
|
+
* Make sure to also declare any variables and class properties with the `StrictTypes` parameter:
|
|
293
|
+
* ```ts
|
|
294
|
+
* private filerobot: Filerobot<Filerobot.StrictTypes>;
|
|
295
|
+
* ```
|
|
296
|
+
*/
|
|
297
|
+
declare function Filerobot<
|
|
298
|
+
TUseStrictTypes extends Filerobot.TypeChecking = Filerobot.TypeChecking
|
|
299
|
+
>(opts?: Filerobot.FilerobotOptions): Filerobot.Filerobot<TUseStrictTypes>;
|
|
300
|
+
|
|
301
|
+
export = Filerobot;
|