* Instantiate Uppy
(opts?: UppyOptionsWithOptionalRestrictions<M, B>)
| 437 | * Instantiate Uppy |
| 438 | */ |
| 439 | constructor(opts?: UppyOptionsWithOptionalRestrictions<M, B>) { |
| 440 | this.defaultLocale = locale |
| 441 | |
| 442 | const defaultOptions: UppyOptions<Record<string, unknown>, B> = { |
| 443 | id: 'uppy', |
| 444 | autoProceed: false, |
| 445 | allowMultipleUploadBatches: true, |
| 446 | debug: false, |
| 447 | restrictions: defaultRestrictionOptions, |
| 448 | meta: {}, |
| 449 | onBeforeFileAdded: (file, files) => !Object.hasOwn(files, file.id), |
| 450 | onBeforeUpload: (files) => files, |
| 451 | store: new DefaultStore(), |
| 452 | logger: justErrorsLogger, |
| 453 | infoTimeout: 5000, |
| 454 | } |
| 455 | |
| 456 | const merged = { ...defaultOptions, ...opts } as Omit< |
| 457 | NonNullableUppyOptions<M, B>, |
| 458 | 'restrictions' |
| 459 | > |
| 460 | // Merge default options with the ones set by user, |
| 461 | // making sure to merge restrictions too |
| 462 | this.opts = { |
| 463 | ...merged, |
| 464 | restrictions: { |
| 465 | ...(defaultOptions.restrictions as Restrictions), |
| 466 | ...opts?.restrictions, |
| 467 | }, |
| 468 | } |
| 469 | |
| 470 | // Support debug: true for backwards-compatability, unless logger is set in opts |
| 471 | // opts instead of this.opts to avoid comparing objects — we set logger: justErrorsLogger in defaultOptions |
| 472 | if (opts?.logger && opts.debug) { |
| 473 | this.log( |
| 474 | 'You are using a custom `logger`, but also set `debug: true`, which uses built-in logger to output logs to console. Ignoring `debug: true` and using your custom `logger`.', |
| 475 | 'warning', |
| 476 | ) |
| 477 | } else if (opts?.debug) { |
| 478 | this.opts.logger = debugLogger |
| 479 | } |
| 480 | |
| 481 | this.log(`Using Core v${Uppy.VERSION}`) |
| 482 | |
| 483 | this.i18nInit() |
| 484 | |
| 485 | this.store = this.opts.store |
| 486 | this.setState({ |
| 487 | ...defaultUploadState, |
| 488 | plugins: {}, |
| 489 | files: {}, |
| 490 | currentUploads: {}, |
| 491 | capabilities: { |
| 492 | uploadProgress: supportsUploadProgress(), |
| 493 | individualCancellation: true, |
| 494 | resumableUploads: false, |
| 495 | }, |
| 496 | meta: { ...this.opts.meta }, |
nothing calls this directly
no test coverage detected