Ver Fonte

Merge branch 'master' of github.com:transloadit/uppy

Kevin van Zonneveld há 4 anos atrás
pai
commit
b50c494027

+ 9 - 2
packages/@uppy/aws-s3/src/index.js

@@ -134,14 +134,21 @@ module.exports = class AwsS3 extends Plugin {
   validateParameters (file, params) {
     const valid = typeof params === 'object' && params &&
       typeof params.url === 'string' &&
-      (typeof params.fields === 'object' || params.fields == null) &&
-      (params.method == null || /^(put|post)$/i.test(params.method))
+      (typeof params.fields === 'object' || params.fields == null)
 
     if (!valid) {
       const err = new TypeError(`AwsS3: got incorrect result from 'getUploadParameters()' for file '${file.name}', expected an object '{ url, method, fields, headers }' but got '${JSON.stringify(params)}' instead.\nSee https://uppy.io/docs/aws-s3/#getUploadParameters-file for more on the expected format.`)
       console.error(err)
       throw err
     }
+
+    const methodIsValid = params.method == null || /^(put|post)$/i.test(params.method)
+
+    if (!methodIsValid) {
+      const err = new TypeError(`AwsS3: got incorrect method from 'getUploadParameters()' for file '${file.name}', expected  'put' or 'post' but got '${params.method}' instead.\nSee https://uppy.io/docs/aws-s3/#getUploadParameters-file for more on the expected format.`)
+      console.error(err)
+      throw err
+    }
   }
 
   handleUpload (fileIDs) {

+ 2 - 2
packages/@uppy/companion/src/server/helpers/jwt.js

@@ -28,7 +28,7 @@ module.exports.verifyToken = (token, secret) => {
  *
  * @param {object} res
  * @param {string} token
- * @param {object=} companionOptions
+ * @param {object} companionOptions
  * @param {string} providerName
  */
 module.exports.addToCookies = (res, token, companionOptions, providerName) => {
@@ -47,7 +47,7 @@ module.exports.addToCookies = (res, token, companionOptions, providerName) => {
 /**
  *
  * @param {object} res
- * @param {object=} companionOptions
+ * @param {object} companionOptions
  * @param {string} providerName
  */
 module.exports.removeFromCookies = (res, companionOptions, providerName) => {

+ 4 - 3
packages/@uppy/dashboard/src/components/FileItem/Buttons/index.js

@@ -9,9 +9,10 @@ function EditButton ({
   i18n,
   onClick
 }) {
-  if ((!uploadInProgressOrComplete &&
-      metaFields &&
-      metaFields.length > 0) || canEditFile(file)) {
+  if (
+    (!uploadInProgressOrComplete && metaFields && metaFields.length > 0) ||
+    (!uploadInProgressOrComplete && canEditFile(file))
+  ) {
     return (
       <button
         class="uppy-u-reset uppy-Dashboard-Item-action uppy-Dashboard-Item-action--edit"

+ 2 - 0
packages/@uppy/xhr-upload/types/index.d.ts

@@ -14,6 +14,8 @@ declare module XHRUpload {
     endpoint: string
     method?: 'GET' | 'POST' | 'PUT' | 'HEAD' | 'get' | 'post' | 'put' | 'head'
     locale?: XHRUploadLocale
+    responseType?: string
+    withCredentials?: boolean    
   }
 }
 

+ 11 - 0
website/src/docs/fileinput.md

@@ -128,4 +128,15 @@ fileInput.addEventListener('change', (event) => {
     }
   })
 })
+
+// it’s probably a good idea to clear the `<input>`
+// after the upload or when the file was removed
+// (see https://github.com/transloadit/uppy/issues/2640#issuecomment-731034781)
+uppy.on('file-removed', () => {
+  fileInput.value = null
+})
+
+uppy.on('complete', () => {
+  fileInput.value = null
+})
 ```

+ 1 - 1
website/src/docs/image-editor.md

@@ -80,7 +80,7 @@ uppy.use(ImageEditor, {
 
 ### `id: 'ImageEditor'`
 
-A unique identifier for this plugin. It defaults to `'ThumbnailGenerator'`.
+A unique identifier for this plugin. It defaults to `'ImageEditor'`.
 
 ### `quality: 0.8`
 

+ 2 - 2
website/src/docs/react-dashboard.md

@@ -43,13 +43,13 @@ Styles for Provider plugins, like Google Drive and Instagram, are also bundled w
 
 The `<Dashboard />` component supports all [`@uppy/dashboard`][] options as props. Additionally, an Uppy instance must be provided in the `uppy={}` prop: see [Initializing Uppy](/docs/react/initializing) for details.
 
-The `<Dashboard />` cannot be passed to a `target:` option of a remote provider or plugins such as [`@uppy/webcam`][]. To use other plugins like [`@uppy/webcam`][] with the `<Dashboard />` component, first add them to the Uppy instance, and then specify their `id` in the [`plugins`](/docs/dashboard/#plugins) prop:
+> The `<Dashboard />` cannot be passed to a `target:` option of a remote provider or plugins such as [`@uppy/webcam`][]. To use other plugins like [`@uppy/webcam`][] (Image Editor, Google Drive, etc) with the `<Dashboard />` component, first add them to the Uppy instance, and then specify their `id` in the [`plugins`](/docs/dashboard/#plugins) prop:
 
 ```js
 function Uploader () {
   const uppy = React.useMemo(() => {
     return Uppy()
-      .use(Webcam) // `id` defaults to "Webcam"
+      .use(Webcam) // `id` defaults to "Webcam". Note: no `target` option!
       // or
       .use(Webcam, { id: 'MyWebcam' }) // `id` is… "MyWebcam"
   }, [])

+ 27 - 15
website/src/docs/react-initializing.md

@@ -12,44 +12,56 @@ When using Uppy's React components, an Uppy instance must be passed in to the `u
 
 ## Functional Components
 
-With React Hooks, the `useMemo` hook can be used to create an instance once and remember it for all rerenders. The `useEffect` hook can close the Uppy instance when the component unmounts.
+With React Hooks, the `useRef` hook can be used to create an instance once and remember it for all rerenders. The `useEffect` hook can close the Uppy instance when the component unmounts.
 
 ```js
-const MyComponent = () => {
-  const uppy = React.useMemo(() => {
-    // Do all the configuration here
-    return new Uppy()
+function MyComponent () {
+  const uppy = useRef(undefined);
+  // Make sure we only initialize it the first time:
+  if (uppy.current === undefined) {
+    uppy.current = new Uppy()
       .use(Transloadit, {})
-  }, []);
+  }
 
   React.useEffect(() => {
-    return () => uppy.close()
+    // Return a cleanup function:
+    return () => uppy.current.close()
   }, [])
 
   return <DashboardModal uppy={uppy} />
 }
 ```
 
-Both hooks must receive the `[]` dependency array parameter, or the Uppy instance will be recreated and/or destroyed every time the component rerenders. To make sure you never forget that, a custom hook could be used:
+With `useRef`, the Uppy instance and its functions are stored on the `.current` property.
+`useEffect()` must receive the `[]` dependency array parameter, or the Uppy instance will be destroyed every time the component rerenders.
+To make sure you never forget these requirements, you could wrap it up in a custom hook:
+
 ```js
 function useUppy (factory) {
-  const uppy = React.useMemo(factory, [])
+  const uppy = React.useRef(undefined)
+  // Make sure we only initialize it the first time:
+  if (uppy.current === undefined) {
+    uppy.current = factory()
+  }
+
   React.useEffect(() => {
-    return () => uppy.close()
+    return () => uppy.current.close()
   }, [])
-  return new uppy
+  return uppy.current
 }
 
 // Then use it as:
-const uppy = useUppy(() => {
-  return new Uppy()
+const uppy = useUppy(() =>
+  new Uppy()
     .use(Tus, {})
-})
+)
 ```
 
+(The function wrapper is required here so you don't create an unused Uppy instance on each rerender.)
+
 ## Class Components
 
-A simple approach is to initialize it in your React component's `constructor()` and destroy it in `componentWillUnmount()`.
+A simple approach is to create an Uppy instance in your React component's `constructor()` and destroy it in `componentWillUnmount()`.
 
 > ⚠ Uppy instances are stateful, so the same instance must be used across different renders.
 > Do **NOT** initialize Uppy in a `render()` method!

+ 18 - 2
website/src/docs/uppy.md

@@ -164,7 +164,7 @@ Optionally, provide rules and conditions to limit the type and/or number of file
 
 **Parameters**
 
-- `maxFileSize` *null | number* — maximum file size in bytes for each individual file (total max size [has been requested, and is planned](https://github.com/transloadit/uppy/issues/514))
+- `maxFileSize` *null | number* — maximum file size in bytes for each individual file
 - `minFileSize` *null | number* — minimum file size in bytes for each individual file
 - `maxTotalFileSize` *null | number* — maximum file size in bytes for all the files that can be selected for upload
 - `maxNumberOfFiles` *null | number* — total number of files that can be selected
@@ -767,9 +767,25 @@ uppy.on('upload', (data) => {
 })
 ```
 
+### `progress`
+
+Fired each time the total upload progress is updated:
+
+**Parameters**
+- `progress` - An integer (0-100) representing the total upload progress.
+
+**Example**
+
+```javascript
+uppy.on('progress', (progress) => {
+  // progress: integer (total progress percentage)
+  console.log(progress)
+})
+```
+
 ### `upload-progress`
 
-Fired each time file upload progress is available:
+Fired each time an individual file upload progress is available:
 
 **Parameters**
 - `file` - The [File Object][File Objects] for the file whose upload has progressed.