I added support to load thumbnails when uploading AVIF images, by adding 'avif' to the regex. I also updated the unit test.
Note that support for this is dependant on browser support, and currently only Chrome 85+ and Firefox 77+ support it (Firefox requires flag to be set to allow it)
* Move @uppy/utils/lib/prettyBytes -> @transloadit/prettier-bytes so we can more easily re-use it across projects
* Switch to MIT licensed @transloadit/prettier-bytes
* lockfile fun
* build: add dep for website/inject.js
Co-authored-by: Renée Kooi <renee@kooi.me>
* Add NetworkError error type and isNetworkError utility check
* Detect network errors in tus and xhr-upload
Co-Authored-By: Ifedapo .A. Olarewaju <ifedapoolarewaju@gmail.com>
* add NetworkError check to RequestClient in companion-client
* return false if !xhr 🙈
* move catch so that only errors from _checkMinNumberOfFiles are caught — errors from uploads are logged in `upload-error` already
//cc @goto-bus-stop
* Add NetworkError to MiniXHRUpload in aws-s3
//cc @goto-bus-stop
* Add tests
//cc @ifedapoolarewaju
* pass xhr to NetworkError
* add logging in catch of uppy.upload()
* start error message with “This looks like a network error”
* originalRequest --> request, return NetworkError right away
* check for NetworkError in `delete` as well
do we need it in preflight too, @ifedapoolarewaju?
* remove redundant error message re-declaration
* _showOrLogErrorAndThrow, but don’t showInformer
Co-authored-by: Ifedapo .A. Olarewaju <ifedapoolarewaju@gmail.com>
* aws-s3: handle actual upload internally instead of deferring to XHRUpload
* aws-s3: add a comment explaining the mess
* aws-s3: move XHRUpload code into a separate class
* utils: support prioritization in rate limiting queue
* aws-s3: remove old implementation
* core,status-bar: account for pre/postprocessing files in progress calculations
* changelog: add entry for this PR
* utils: Support cancellation in `RateLimitedQueue#wrapPromiseFunction`
* s3: remove preprocessing stage, only use upload-* events
* utils: remove console.log
* aws-s3: comment out duplicate `upload-started`
* xhr-upload: reorder `ProgressTimeout` creation for readability
* aws-s3: apply 7d972e0 to MiniXHRUpload
* aws-s3: apply 4ed7508 to MiniXHRUpload
* webcam: request a video mime type listed in `allowedFileTypes`
* webcam: stop recording when we are about to reach the max file size
* webcam: request an image mime type listed in `allowedFileTypes`
* docs: add Webcam#preferredImageMimeType
* locale: add `recordingStoppedMaxSize` string
* changelog: check webcam restrictions
Co-authored-by: Artur Paikin <artur@arturpaikin.com>
* ProviderViews: Improve Instagram’s “video thumbnail”
* Update all provider icons to nicer round ones
* Change “drop files” copy depending on number of acquirers and Dashboard width
* Translator: support multiple components in options
When the source contains multiple placeholders for interpolation, we should ignore chunks that are not strings, because those can be JSX objects and will be otherwise incorrectly turned into strings.
Without this condition we’d get this: [object Object] hello [object Object] my <button>
* Remove unused locale strings
* Rever renderSingleInlineProvider, use Browse button instead of link, tweak styles
* Try “Browse My Device” button
* Introduce “Dark Mode“: new Dashboard option 'theme': 'light', 'dark' or 'auto'
* Refactor to also add uninstall/removeListener for the darkModeMediaQuery; remove all bindings in favor of class properties
* More dark mode styles: Providers, FileCard, tweaking focus, inputs, etc
* My Device: mobile and desktop icons
* add isMobileDevice capability, very simple detection
* More dark mode styles
* refactor
* switch back to single simple my device icon
* chrome 78 for android doesn’t support document.querySelector 👌
* nobr --> span white-space: nowrap
* Major style tweaks for mobile provider list, show dashed borders only when DnD is supported
* Add color after “import from”
just for Russian for now, because I’m thinking if this should be a part of the language string or html? @goto-bus-stop @kvz, what do you think?
* improve isMobileDevice, add tests
* don’t set the isMobileDevice capability in core for now
* add checks for typeof window !== 'undefined', otherwise fails in Node/RN
* update locales
* refactor renderDropFilesSubtitle
* Fix translations that did not respect word order
Fixes#2069
We were still using raw string concatenation in these two places. To
maintain backwards compatibility, this commit adds _new_ translations
that are substitution-based instead of concatenation-based. The old
translation is passed in as a possible substitution parameter
`backwardsCompat`, and the default (English) translations use this
parameter.
With this, if you are using a custom locale that overrides eg. the
`exceedsSize` string, Uppy will first get your `exceedsSize`
translation, and then use the default `exceedsSize2` translation which
concatenates that result and the file size. So it works the same as it
did in the past.
If a translation requires a different word order, it can override the
`exceedsSize2` translation instead.
```js
new Uppy({
locale: {
strings: {
exceedsSize2: 'Maximum file size of %{size} exceeded',
poweredBy2: '%{uppy} made this!'
}
}
})
```
In 2.0, we can remove all the old strings and only use `poweredBy2` (and
probably rename them to `poweredBy` too, heh)
* website: add missing dashboard strings to docs
* locales: remove unused second plural form from EN and NL
* build: allow different numbers of plural forms
* utils: add test for new throwing behaviour
* docs: insert PR url
* locales: revert ko_KR changes
* changelog: add 2.0 backlog entry
* locales: var → const
* docs: add brief note that translators should supply a pluralize function
* locales: update en_US with new template
* fix HEIGHT_MD = 400
Co-authored-by: Artur Paikin <artur@arturpaikin.com>
* types: stronger typings
* Remove remaining `declare module` things for uppy.use
* Format types standard-style-like
* Add `target` properties to plugin typings
* Add type for `replaceTargetContent` option
* xhr-upload: allow lowercase method
* opt in to stricter typechecks
* use the strictly typed version in all typings tests
* endtoend: use strict types in typescript test
* Add some comments to the typings file so IDEs will warn about untyped use()
* informer: remove obsolete option from typings
* react: generate prop types based on actual options types
* react: update types
* react: fix import in typings test
* companion-client: add `pluginId` property to ProviderOptions type
Co-Authored-By: Ifedapo .A. Olarewaju <ifedapoolarewaju@gmail.com>
* core: remove some `any` types
* *: add locale string types
* *: generate locale typings
* core: fix LocaleStrings<> type
* dashboard: add locale string type tests
* tus: inherit options typings from tus-js-client
* transloadit: add missing options types
* ci: do the required build steps before testing typings
* Support TokenStorage in types, add `title?: string` options
* form: update typings
* types: put TokenStorage type in dependents
* Document Uppy.StrictTypes
* if we pin at least we should use the latest
* Allow document.querySelector
I think it's a eslint-plugin-compat bug that it's marking querySelector
as not available in Android Chrome 78.
Co-authored-by: Ifedapo .A. Olarewaju <ifedapoolarewaju@gmail.com>
* core: add an addFiles() method that only updates state once
Previously, adding 1300-ish files took around 260ms, and looked like
this in Firefox's performance tab:

All of the downward peaks are `setState()` calls and GC.
Now it takes around 60ms, and looks like this:

Here, most of the time is spent generating file IDs and guessing file
types. Those would be areas to look at next.
* dashboard: prevent frequent state update if nothing changed
After the last commit, `addFiles()` still spends a lot of time in
`emit()` and `hideAllPanels()`. The reason is that `addFiles()` still
emits all the hundreds of file-added events, and the Dashboard responds
to each with `hideAllPanels()`, which does a state update. But this all
happens synchronously, and the state almost certainly did not change
since the last `file-added` event that fired a millisecond ago.
This adds a check to avoid the state update if it is not necessary.

Adding 1300 files takes about 40ms now.
With this change, the `addFiles()` call is no longer the slowest
part—now preact rendering all the items is!
* utils: optimize generateFileID and getFileNameAndExtension
Replaces some clever things with more mundane and faster things!
Now, generateFileID is a bunch of string concatenations.
Now, getFileNameAndExtension uses `lastIndexOf()` instead of a regex.

Adding 1300 files takes about 25ms.
* dashboard: use preact-virtual-list
* thumbnail-generator: add `lazy` option
* dashboard: request thumbnails once file item renders the first time
* dashboard: fork preact-virtual-list
* core: add removeFiles() to remove files in bulk
* Implement removeFile() in terms of removeFiles()
* thumbnail-generator: only queue files that can be previewed
* rename size constants to accommodate WIDTH/HEIGHT
* Use new uppy.addFiles in DragDrop and FileInput
* utils: fix getFileNameAndExtension() type
* Rip out the lazy thumbnail generation
* Rip out virtualization.
* Remove virtualization leftovers
* tell future people that this is intentionally verbose
* Update package-lock.json
* henlo i am spell
* Make `addFiles()` respect maxNumberOfFiles
* core: show an informer error if some files fail in bulk add
* locales: fix quotes to make build:locale-pack happy
Co-authored-by: Artur Paikin <artur@arturpaikin.com>
* aws-s3-multipart: prevent deadlock in rate limit queue
* utils: fix RateLimitedQueue thrashing when aborting all items
* aws-s3-multipart: only send abort request if upload was already created, fixes#1146
* xhr-upload: redo limit option using different strategy
* xhr-upload: fix marking requests as done
* Move duplicate createEventTracker definitions to @uppy/utils
* tus: new cancellation for local uploads
* tus: fix cancelling queued uploads
* tus: fix wrong name
* aws-s3-multipart: smol refactor
* aws-s3-multipart: new cancellation style
* aws-s3: new cancellation
* utils: port limitPromises test to RateLimitedQueue
* timing fix?
* tus: new cancellation on websocket
* xhr-upload: implement cancellation for remote uploads
* aws-s3-multipart: port to new cancellation
* utils: remove limitPromises
* xhr-upload: remove pause/resume code
* xhr-upload: clean up event listeners
* xhr-upload: extract progress timer to separate class
* Move ProgressTimeout class to utils
* utils: update typings
* Fix lint
* tus: make pause/resume respect the rate limiting queue
* tus: try to explain some of the tricky things at play in the Tus#upload method
* aws-s3-multipart: add missing { abort: true }
* aws-s3-multipart: make pause/resume respect the rate limiting queue
* eslintrc.json - fixed eslint warnings for jsdoc
* Revert "eslintrc.json - fixed eslint warnings for jsdoc"
This reverts commit 50b24773ce.
* eslintrc.json - allow indentation in jsdoc comments
* xhr-upload: fix promise return value
* tus: fix promise return value
* tus: add missing `return () => {}`
* utils: typing export type fixes
* tus: add more jsdoc
* companion-client: add missing SocketOptions type
* utils: fix more export typings
* core,companion-client,tus: more typings tweaking
* companion-client: test fix 😩
* companion-client: add type for Socket#open
* tus: fix emit() call
* add local cancellation fuzz....ish? test
* Add file.data.relativePath to the file.id
* Don’t add/overwrite a file if a file with the same id already exsists, issue a warning
* override @uppy/tus fingerprint to uppy’s file.id
* combine cordove/react native handling, don’t log twice
* always use onError for errors in addFile
* use file.meta.relativePath instead of file.data.relativePath
what do you think, @lakesare?
* update tests to include allowing/diallowing duplicates and file.id generation with relativePath
* update tus-js-client
* refactor error handling for addFile and upload into a mutual _showOrLogErrorAndThrow method
* explain duplicate files and relativePath
* throw TypeError vs Error when allowedFileTypes is not an array
* fix tests
* tweak docs
* Emit restriction-failed for all restriction errors, move it to _showOrLogErrorAndThrow
* @utils/getDroppedFiles.js - mild refactoring
* @utils/getDroppedFiles.js - added .info and .log on drop error
* @utils/getDroppedFiles.js - one more refactor
* @utils/getDroppedFiles.js - log error objects instead of strings
* Update eslint
* Do eslint --fix
* Do not access Object.prototype method 'hasOwnProperty' from target object
* utils: add hasProperty
* eslint --fix
* Disable quote-props for locale files
* add back quotes in locale files
* revert locale files to state on master
* Update react-scripts
* core: add test for ID generation with non-latin names
* core: adjust ID generation to keep non-latin characters
This shouldn't be bc-breaking!
Now, non-latin characters are encoded as their charcode in base 32, so
files that only differ by name in a non-latin language will generate
different IDs.
* Replace prettier-bytes with its copy, only use 1024 instead of 1000 to justify KB vs kB
* Add tests
* added License
* pretty-bytes to @uppy/utils/lib/prettyBytes everywhere