|
@@ -1,5 +1,24 @@
|
|
|
const Uppy = require('@uppy/core')
|
|
|
|
|
|
+const eventNames = {
|
|
|
+ onFileAdded: 'file-added',
|
|
|
+ onFileRemoved: 'file-removed',
|
|
|
+
|
|
|
+ onAssemblyCreated: 'transloadit:assembly-created',
|
|
|
+ onAssemblyExecuting: 'transloadit:assembly-executing',
|
|
|
+ onAssemblyComplete: 'transloadit:complete',
|
|
|
+
|
|
|
+ onStart: 'upload',
|
|
|
+ onPause: 'pause-all',
|
|
|
+ onFilePause: 'upload-pause',
|
|
|
+ onCancel: 'cancel-all',
|
|
|
+ onFileCancel: 'upload-cancel',
|
|
|
+ onFileProgress: 'upload-progress',
|
|
|
+ onUploaded: 'transloadit:upload',
|
|
|
+ onResult: 'transloadit:result',
|
|
|
+ onComplete: 'complete'
|
|
|
+}
|
|
|
+
|
|
|
const uppyOptionNames = [
|
|
|
'autoProceed',
|
|
|
'restrictions',
|
|
@@ -14,7 +33,25 @@ function createUppy (opts, overrides = {}) {
|
|
|
})
|
|
|
Object.assign(uppyOptions, overrides)
|
|
|
|
|
|
- return Uppy(uppyOptions)
|
|
|
+ const uppy = Uppy(uppyOptions)
|
|
|
+
|
|
|
+ // Builtin event aliases
|
|
|
+ Object.keys(eventNames).forEach((optionName) => {
|
|
|
+ const eventName = eventNames[optionName]
|
|
|
+ if (typeof opts[optionName] === 'function') {
|
|
|
+ uppy.on(eventName, opts[optionName])
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+ // Custom events (these should probably be added to core)
|
|
|
+ if (typeof opts.onProgress === 'function') {
|
|
|
+ uppy.on('upload-progress', () => {
|
|
|
+ const { totalProgress } = uppy.getState()
|
|
|
+ opts.onProgress.call(uppy, totalProgress)
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ return uppy
|
|
|
}
|
|
|
|
|
|
module.exports = createUppy
|