Kaynağa Gözat

fixed autoProceed, refactoring

Artur Paikin 9 yıl önce
ebeveyn
işleme
98fdb813e8
2 değiştirilmiş dosya ile 19 ekleme ve 15 silme
  1. 6 4
      src/core/Core.js
  2. 13 11
      src/plugins/DragDrop.js

+ 6 - 4
src/core/Core.js

@@ -13,7 +13,7 @@ export default class Core {
     const defaultOptions = {
       // load English as the default locale
       locale: require('../locale/en_US.js'),
-      autoProceed: false,
+      autoProceed: true,
       debug: false
     }
 
@@ -72,6 +72,7 @@ export default class Core {
  */
   log (msg) {
     if (this.opts.debug) {
+      msg = JSON.stringify(msg)
       console.log(`DEBUG LOG: ${msg}`)
     }
   }
@@ -97,7 +98,7 @@ export default class Core {
  * All preseters(data) --> All selecters(data) --> All uploaders(data) --> done
  */
   run () {
-    console.log({
+    this.log({
       class: this.constructor.name,
       method: 'run'
     })
@@ -110,7 +111,7 @@ export default class Core {
     // Each Plugin can have `run` and/or `install` methods.
     // `install` adds event listeners and does some non-blocking work, useful for `progress`,
     // `run` waits for the previous step to finish (user selects files) before proceeding
-    return ['install', 'run'].forEach(method => {
+    ['install', 'run'].forEach(method => {
       // First we select only plugins of current type,
       // then create an array of runType methods of this plugins
       const typeMethods = this.types.filter(type => {
@@ -119,8 +120,9 @@ export default class Core {
 
       // Run waterfall of typeMethods
       return Utils.promiseWaterfall(typeMethods)
-        .then(result => result)
+        .then(result => { return result })
         .catch(error => console.error(error))
     })
+
   }
 }

+ 13 - 11
src/plugins/DragDrop.js

@@ -1,6 +1,5 @@
 import Utils from '../core/Utils'
 import Plugin from './Plugin'
-// import componentDragDrop from '../components/dragdrop.js'
 
 /**
  * Drag & Drop plugin
@@ -11,15 +10,15 @@ export default class DragDrop extends Plugin {
     super(core, opts)
     this.type = 'selecter'
 
-    // set default options
+    // Default options
     const defaultOptions = {
       target: '.UppyDragDrop'
     }
 
-    // merge default options with the ones set by user
+    // Merge default options with the ones set by user
     this.opts = Object.assign({}, defaultOptions, opts)
 
-    // check if dragDrop is supported in the browser
+    // Check for browser dragDrop support
     this.isDragDropSupported = this.checkDragDropSupport()
 
     // Initialize dragdrop component, mount it to container DOM node
@@ -49,7 +48,6 @@ export default class DragDrop extends Plugin {
         method="post"
         action="${this.opts.endpoint}"
         enctype="multipart/form-data">
-      <img class="UppyDragDrop-puppy" src="/images/uppy.svg">
       <input class="UppyDragDrop-input"
              id="UppyDragDrop-input"
              type="file"
@@ -62,8 +60,8 @@ export default class DragDrop extends Plugin {
     ${!this.core.opts.autoProceed
       ? `<button class="UppyDragDrop-uploadBtn" type="submit">${this.core.i18n('upload')}</button>`
       : ''}
-    <div class="UppyDragDrop-status"></div>
-    <div class="UppyDragDrop-progress"></div>
+    <!--div class="UppyDragDrop-status"></div-->
+    <!--div class="UppyDragDrop-progress"></div-->
   </form>`
   }
 
@@ -126,18 +124,22 @@ export default class DragDrop extends Plugin {
       this.setProgress(percentage)
     })
 
+    // document.addEventListener('dragover', (e) => {
+    //   console.log('ну пиздец')
+    // })
+
     return Promise.race([onDrop, onInput]).then(handler => handler())
   }
 
   handleDrop (e) {
-    console.log('all right, someone dropped something...')
+    this.core.log('all right, someone dropped something...')
 
     const files = e.dataTransfer.files
     return this.result(files)
   }
 
   handleInputChange () {
-    console.log('all right, something selected through input...')
+    this.core.log('all right, something selected through input...')
 
     const files = this.input.files
     return this.result(files)
@@ -146,7 +148,7 @@ export default class DragDrop extends Plugin {
   result (files) {
     return new Promise((resolve, reject) => {
       const result = {from: 'DragDrop', files}
-      // const result = files
+
       // if autoProceed is false, wait for upload button to be pushed,
       // otherwise just pass files to uploaders right away
       if (this.core.opts.autoProceed) {
@@ -161,7 +163,7 @@ export default class DragDrop extends Plugin {
   }
 
   run (results) {
-    console.log({
+    this.core.log({
       class: this.constructor.name,
       method: 'run',
       results: results