active_storage_drag_and_drop 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 729988913922129efcd90cea954872a29abafaabdcff487834381b9c021caf6c
4
- data.tar.gz: aa125c1870b11d8a64b8215b4760f0a74cfe1b9cbf0bdfddcc6b296a1190c3ce
3
+ metadata.gz: 0ebcab98ea53affc1a17f933dfac48d5ca1d944c0688fa525bbbca086f0739cc
4
+ data.tar.gz: 4811dbc8de9aa33a4af730494f642fb4806ec6f47b5b4f1287034307320d972f
5
5
  SHA512:
6
- metadata.gz: c2f91030868199631e753f64cfa23ccb6e24a8b87ab68d3a453f8ea563189b23c2957d2680fa0f90af129b011f398618d69c2485fc7bd07e9f2abe8b25c6a0ff
7
- data.tar.gz: 282219794f60412fd0bfab09091074d6ae8ce15fb09eeef290c646b3437bdbe0bcc133e9e48b1dc4d021102bd13a9af918cd946d9dc450d77ae415b4d7f73516
6
+ metadata.gz: c103992d6ef02780e08da15c8b1e0482dd32e0d392cb9560b311571877c3060b94db21a2e6a0243f885a5692aeffd8a171666ee1027d67469a9ad86ca94c38ec
7
+ data.tar.gz: e1d48cc0161ba91ecd7b8937d13a14dcc5e8a3b5905b55f9edfc2a1116c64195364c320f360524124de312c0544589ccdb32fc183ecdec2829bcd4180d1984e9
data/.gitignore CHANGED
@@ -7,3 +7,4 @@
7
7
  /spec/reports/
8
8
  /node_modules/
9
9
  /tmp/
10
+ active_storage_drag_and_drop-*.gem
@@ -1,8 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- active_storage_drag_and_drop (0.1.0)
5
- rails (>= 5.2.0)
4
+ active_storage_drag_and_drop (0.3.0)
5
+ rails (~> 5.2)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
@@ -70,10 +70,10 @@ GEM
70
70
  mini_portile2 (2.3.0)
71
71
  minitest (5.11.3)
72
72
  nio4r (2.3.1)
73
- nokogiri (1.8.3)
73
+ nokogiri (1.8.4)
74
74
  mini_portile2 (~> 2.3.0)
75
75
  rack (2.0.5)
76
- rack-test (1.0.0)
76
+ rack-test (1.1.0)
77
77
  rack (>= 1.0, < 3)
78
78
  rails (5.2.0)
79
79
  actioncable (= 5.2.0)
data/README.md CHANGED
@@ -56,7 +56,9 @@ params.permit(:message).require(images: [])
56
56
  Install yarn to manage js dependencies.
57
57
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
58
58
 
59
- After making a change to the javascript in `app/javascript` compile it to `app/assets/javascripts/active_storage_drag_and_drop.js` by running `node_modules/webpack`.
59
+ After making a change to the javascript in `app/javascript` compile it to `app/assets/javascripts/active_storage_drag_and_drop.js` by running `node_modules/webpack-command/lib/cli.js`.
60
+
61
+ Use `node_modules/webpack-command/lib/cli.js --mode=development --watch` to build files automatically on change. Use with `gem 'active_storage_drag_and_drop', path: [local-gem-repo]` to develop and debug the gem in place in a rails app.
60
62
 
61
63
  To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
62
64
 
@@ -1 +1 @@
1
- !function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.ActiveStorage=e():t.ActiveStorage=e()}(window,function(){return function(t){var e={};function r(n){if(e[n])return e[n].exports;var i=e[n]={i:n,l:!1,exports:{}};return t[n].call(i.exports,i,i.exports,r),i.l=!0,i.exports}return r.m=t,r.c=e,r.d=function(t,e,n){r.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},r.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(t,e){if(1&e&&(t=r(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var i in t)r.d(n,i,function(e){return t[e]}.bind(null,i));return n},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="",r(r.s=1)}([function(t,e,r){t.exports=function(t){function e(n){if(r[n])return r[n].exports;var i=r[n]={i:n,l:!1,exports:{}};return t[n].call(i.exports,i,i.exports,e),i.l=!0,i.exports}var r={};return e.m=t,e.c=r,e.d=function(t,r,n){e.o(t,r)||Object.defineProperty(t,r,{configurable:!1,enumerable:!0,get:n})},e.n=function(t){var r=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(r,"a",r),r},e.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},e.p="",e(e.s=2)}([function(t,e,r){"use strict";function n(t,e){return"string"==typeof t&&(e=t,t=document),t.querySelector(e)}function i(t){return Array.isArray(t)?t:Array.from?Array.from(t):[].slice.call(t)}e.d=function(t){var e=n(document.head,'meta[name="'+t+'"]');if(e)return e.getAttribute("content")},e.c=function(t,e){return"string"==typeof t&&(e=t,t=document),i(t.querySelectorAll(e))},e.b=n,e.a=function(t,e){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},n=t.disabled,i=r.bubbles,a=r.cancelable,o=r.detail,s=document.createEvent("Event");s.initEvent(e,i||!0,a||!0),s.detail=o||{};try{t.disabled=!1,t.dispatchEvent(s)}finally{t.disabled=n}return s},e.e=i},function(t,e,r){"use strict";function n(t,e){if(t&&"function"==typeof t[e]){for(var r=arguments.length,n=Array(r>2?r-2:0),i=2;i<r;i++)n[i-2]=arguments[i];return t[e].apply(t,n)}}r.d(e,"a",function(){return d});var i=r(6),a=r(8),o=r(9),s=function(){function t(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}return function(e,r,n){return r&&t(e.prototype,r),n&&t(e,n),e}}(),u=0,d=function(){function t(e,r,n){(function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")})(this,t),this.id=++u,this.file=e,this.url=r,this.delegate=n}return s(t,[{key:"create",value:function(t){var e=this;i.a.create(this.file,function(r,i){if(r)t(r);else{var s=new a.a(e.file,i,e.url);n(e.delegate,"directUploadWillCreateBlobWithXHR",s.xhr),s.create(function(r){if(r)t(r);else{var i=new o.a(s);n(e.delegate,"directUploadWillStoreFileWithXHR",i.xhr),i.create(function(e){e?t(e):t(null,s.toJSON())})}})}})}}]),t}()},function(t,e,r){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var n=r(3),i=r(1);r.d(e,"start",function(){return n.a}),r.d(e,"DirectUpload",function(){return i.a}),setTimeout(function(){window.ActiveStorage&&Object(n.a)()},1)},function(t,e,r){"use strict";function n(t){a(t)}function i(t){"FORM"==t.target.tagName&&a(t)}function a(t){var e=t.target;if(e.hasAttribute(c))t.preventDefault();else{var r=new u.a(e),n=r.inputs;n.length&&(t.preventDefault(),e.setAttribute(c,""),n.forEach(o),r.start(function(t){e.removeAttribute(c),t?n.forEach(s):function(t){var e=Object(d.b)(t,"input[type=submit]");if(e){var r=e,n=r.disabled;e.disabled=!1,e.focus(),e.click(),e.disabled=n}else(e=document.createElement("input")).type="submit",e.style.display="none",t.appendChild(e),e.click(),t.removeChild(e)}(e)}))}}function o(t){t.disabled=!0}function s(t){t.disabled=!1}e.a=function(){l||(l=!0,document.addEventListener("submit",n),document.addEventListener("ajax:before",i))};var u=r(4),d=r(0),c="data-direct-uploads-processing",l=!1},function(t,e,r){"use strict";r.d(e,"a",function(){return s});var n=r(5),i=r(0),a=function(){function t(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}return function(e,r,n){return r&&t(e.prototype,r),n&&t(e,n),e}}(),o="input[type=file][data-direct-upload-url]:not([disabled])",s=function(){function t(e){(function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")})(this,t),this.form=e,this.inputs=Object(i.c)(e,o).filter(function(t){return t.files.length})}return a(t,[{key:"start",value:function(t){var e=this,r=this.createDirectUploadControllers();this.dispatch("start"),function n(){var i=r.shift();i?i.start(function(r){r?(t(r),e.dispatch("end")):n()}):(t(),e.dispatch("end"))}()}},{key:"createDirectUploadControllers",value:function(){var t=[];return this.inputs.forEach(function(e){Object(i.e)(e.files).forEach(function(r){var i=new n.a(e,r);t.push(i)})}),t}},{key:"dispatch",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return Object(i.a)(this.form,"direct-uploads:"+t,{detail:e})}}]),t}()},function(t,e,r){"use strict";r.d(e,"a",function(){return o});var n=r(1),i=r(0),a=function(){function t(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}return function(e,r,n){return r&&t(e.prototype,r),n&&t(e,n),e}}(),o=function(){function t(e,r){(function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")})(this,t),this.input=e,this.file=r,this.directUpload=new n.a(this.file,this.url,this),this.dispatch("initialize")}return a(t,[{key:"start",value:function(t){var e=this,r=document.createElement("input");r.type="hidden",r.name=this.input.name,this.input.insertAdjacentElement("beforebegin",r),this.dispatch("start"),this.directUpload.create(function(n,i){n?(r.parentNode.removeChild(r),e.dispatchError(n)):r.value=i.signed_id,e.dispatch("end"),t(n)})}},{key:"uploadRequestDidProgress",value:function(t){var e=t.loaded/t.total*100;e&&this.dispatch("progress",{progress:e})}},{key:"dispatch",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return e.file=this.file,e.id=this.directUpload.id,Object(i.a)(this.input,"direct-upload:"+t,{detail:e})}},{key:"dispatchError",value:function(t){this.dispatch("error",{error:t}).defaultPrevented||alert(t)}},{key:"directUploadWillCreateBlobWithXHR",value:function(t){this.dispatch("before-blob-request",{xhr:t})}},{key:"directUploadWillStoreFileWithXHR",value:function(t){var e=this;this.dispatch("before-storage-request",{xhr:t}),t.upload.addEventListener("progress",function(t){return e.uploadRequestDidProgress(t)})}},{key:"url",get:function(){return this.input.getAttribute("data-direct-upload-url")}}]),t}()},function(t,e,r){"use strict";r.d(e,"a",function(){return s});var n=r(7),i=r.n(n),a=function(){function t(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}return function(e,r,n){return r&&t(e.prototype,r),n&&t(e,n),e}}(),o=File.prototype.slice||File.prototype.mozSlice||File.prototype.webkitSlice,s=function(){function t(e){(function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")})(this,t),this.file=e,this.chunkSize=2097152,this.chunkCount=Math.ceil(this.file.size/this.chunkSize),this.chunkIndex=0}return a(t,null,[{key:"create",value:function(e,r){new t(e).create(r)}}]),a(t,[{key:"create",value:function(t){var e=this;this.callback=t,this.md5Buffer=new i.a.ArrayBuffer,this.fileReader=new FileReader,this.fileReader.addEventListener("load",function(t){return e.fileReaderDidLoad(t)}),this.fileReader.addEventListener("error",function(t){return e.fileReaderDidError(t)}),this.readNextChunk()}},{key:"fileReaderDidLoad",value:function(t){if(this.md5Buffer.append(t.target.result),!this.readNextChunk()){var e=this.md5Buffer.end(!0),r=btoa(e);this.callback(null,r)}}},{key:"fileReaderDidError",value:function(t){this.callback("Error reading "+this.file.name)}},{key:"readNextChunk",value:function(){if(this.chunkIndex<this.chunkCount){var t=this.chunkIndex*this.chunkSize,e=Math.min(t+this.chunkSize,this.file.size),r=o.call(this.file,t,e);return this.fileReader.readAsArrayBuffer(r),this.chunkIndex++,!0}return!1}}]),t}()},function(t,e,r){t.exports=function(t){"use strict";function e(t,e){var r=t[0],n=t[1],i=t[2],a=t[3];r+=(n&i|~n&a)+e[0]-680876936|0,a+=((r=(r<<7|r>>>25)+n|0)&n|~r&i)+e[1]-389564586|0,i+=((a=(a<<12|a>>>20)+r|0)&r|~a&n)+e[2]+606105819|0,n+=((i=(i<<17|i>>>15)+a|0)&a|~i&r)+e[3]-1044525330|0,r+=((n=(n<<22|n>>>10)+i|0)&i|~n&a)+e[4]-176418897|0,a+=((r=(r<<7|r>>>25)+n|0)&n|~r&i)+e[5]+1200080426|0,i+=((a=(a<<12|a>>>20)+r|0)&r|~a&n)+e[6]-1473231341|0,n+=((i=(i<<17|i>>>15)+a|0)&a|~i&r)+e[7]-45705983|0,r+=((n=(n<<22|n>>>10)+i|0)&i|~n&a)+e[8]+1770035416|0,a+=((r=(r<<7|r>>>25)+n|0)&n|~r&i)+e[9]-1958414417|0,i+=((a=(a<<12|a>>>20)+r|0)&r|~a&n)+e[10]-42063|0,n+=((i=(i<<17|i>>>15)+a|0)&a|~i&r)+e[11]-1990404162|0,r+=((n=(n<<22|n>>>10)+i|0)&i|~n&a)+e[12]+1804603682|0,a+=((r=(r<<7|r>>>25)+n|0)&n|~r&i)+e[13]-40341101|0,i+=((a=(a<<12|a>>>20)+r|0)&r|~a&n)+e[14]-1502002290|0,n+=((i=(i<<17|i>>>15)+a|0)&a|~i&r)+e[15]+1236535329|0,r+=((n=(n<<22|n>>>10)+i|0)&a|i&~a)+e[1]-165796510|0,a+=((r=(r<<5|r>>>27)+n|0)&i|n&~i)+e[6]-1069501632|0,i+=((a=(a<<9|a>>>23)+r|0)&n|r&~n)+e[11]+643717713|0,n+=((i=(i<<14|i>>>18)+a|0)&r|a&~r)+e[0]-373897302|0,r+=((n=(n<<20|n>>>12)+i|0)&a|i&~a)+e[5]-701558691|0,a+=((r=(r<<5|r>>>27)+n|0)&i|n&~i)+e[10]+38016083|0,i+=((a=(a<<9|a>>>23)+r|0)&n|r&~n)+e[15]-660478335|0,n+=((i=(i<<14|i>>>18)+a|0)&r|a&~r)+e[4]-405537848|0,r+=((n=(n<<20|n>>>12)+i|0)&a|i&~a)+e[9]+568446438|0,a+=((r=(r<<5|r>>>27)+n|0)&i|n&~i)+e[14]-1019803690|0,i+=((a=(a<<9|a>>>23)+r|0)&n|r&~n)+e[3]-187363961|0,n+=((i=(i<<14|i>>>18)+a|0)&r|a&~r)+e[8]+1163531501|0,r+=((n=(n<<20|n>>>12)+i|0)&a|i&~a)+e[13]-1444681467|0,a+=((r=(r<<5|r>>>27)+n|0)&i|n&~i)+e[2]-51403784|0,i+=((a=(a<<9|a>>>23)+r|0)&n|r&~n)+e[7]+1735328473|0,n+=((i=(i<<14|i>>>18)+a|0)&r|a&~r)+e[12]-1926607734|0,r+=((n=(n<<20|n>>>12)+i|0)^i^a)+e[5]-378558|0,a+=((r=(r<<4|r>>>28)+n|0)^n^i)+e[8]-2022574463|0,i+=((a=(a<<11|a>>>21)+r|0)^r^n)+e[11]+1839030562|0,n+=((i=(i<<16|i>>>16)+a|0)^a^r)+e[14]-35309556|0,r+=((n=(n<<23|n>>>9)+i|0)^i^a)+e[1]-1530992060|0,a+=((r=(r<<4|r>>>28)+n|0)^n^i)+e[4]+1272893353|0,i+=((a=(a<<11|a>>>21)+r|0)^r^n)+e[7]-155497632|0,n+=((i=(i<<16|i>>>16)+a|0)^a^r)+e[10]-1094730640|0,r+=((n=(n<<23|n>>>9)+i|0)^i^a)+e[13]+681279174|0,a+=((r=(r<<4|r>>>28)+n|0)^n^i)+e[0]-358537222|0,i+=((a=(a<<11|a>>>21)+r|0)^r^n)+e[3]-722521979|0,n+=((i=(i<<16|i>>>16)+a|0)^a^r)+e[6]+76029189|0,r+=((n=(n<<23|n>>>9)+i|0)^i^a)+e[9]-640364487|0,a+=((r=(r<<4|r>>>28)+n|0)^n^i)+e[12]-421815835|0,i+=((a=(a<<11|a>>>21)+r|0)^r^n)+e[15]+530742520|0,n+=((i=(i<<16|i>>>16)+a|0)^a^r)+e[2]-995338651|0,r+=(i^((n=(n<<23|n>>>9)+i|0)|~a))+e[0]-198630844|0,a+=(n^((r=(r<<6|r>>>26)+n|0)|~i))+e[7]+1126891415|0,i+=(r^((a=(a<<10|a>>>22)+r|0)|~n))+e[14]-1416354905|0,n+=(a^((i=(i<<15|i>>>17)+a|0)|~r))+e[5]-57434055|0,r+=(i^((n=(n<<21|n>>>11)+i|0)|~a))+e[12]+1700485571|0,a+=(n^((r=(r<<6|r>>>26)+n|0)|~i))+e[3]-1894986606|0,i+=(r^((a=(a<<10|a>>>22)+r|0)|~n))+e[10]-1051523|0,n+=(a^((i=(i<<15|i>>>17)+a|0)|~r))+e[1]-2054922799|0,r+=(i^((n=(n<<21|n>>>11)+i|0)|~a))+e[8]+1873313359|0,a+=(n^((r=(r<<6|r>>>26)+n|0)|~i))+e[15]-30611744|0,i+=(r^((a=(a<<10|a>>>22)+r|0)|~n))+e[6]-1560198380|0,n+=(a^((i=(i<<15|i>>>17)+a|0)|~r))+e[13]+1309151649|0,r+=(i^((n=(n<<21|n>>>11)+i|0)|~a))+e[4]-145523070|0,a+=(n^((r=(r<<6|r>>>26)+n|0)|~i))+e[11]-1120210379|0,i+=(r^((a=(a<<10|a>>>22)+r|0)|~n))+e[2]+718787259|0,n=((n+=(a^((i=(i<<15|i>>>17)+a|0)|~r))+e[9]-343485551|0)<<21|n>>>11)+i|0,t[0]=r+t[0]|0,t[1]=n+t[1]|0,t[2]=i+t[2]|0,t[3]=a+t[3]|0}function r(t){var e,r=[];for(e=0;e<64;e+=4)r[e>>2]=t.charCodeAt(e)+(t.charCodeAt(e+1)<<8)+(t.charCodeAt(e+2)<<16)+(t.charCodeAt(e+3)<<24);return r}function n(t){var e,r=[];for(e=0;e<64;e+=4)r[e>>2]=t[e]+(t[e+1]<<8)+(t[e+2]<<16)+(t[e+3]<<24);return r}function i(t){var n,i,a,o,s,u,d=t.length,c=[1732584193,-271733879,-1732584194,271733878];for(n=64;n<=d;n+=64)e(c,r(t.substring(n-64,n)));for(t=t.substring(n-64),i=t.length,a=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],n=0;n<i;n+=1)a[n>>2]|=t.charCodeAt(n)<<(n%4<<3);if(a[n>>2]|=128<<(n%4<<3),n>55)for(e(c,a),n=0;n<16;n+=1)a[n]=0;return o=(o=8*d).toString(16).match(/(.*?)(.{0,8})$/),s=parseInt(o[2],16),u=parseInt(o[1],16)||0,a[14]=s,a[15]=u,e(c,a),c}function a(t){var r,i,a,o,s,u,d=t.length,c=[1732584193,-271733879,-1732584194,271733878];for(r=64;r<=d;r+=64)e(c,n(t.subarray(r-64,r)));for(t=r-64<d?t.subarray(r-64):new Uint8Array(0),i=t.length,a=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],r=0;r<i;r+=1)a[r>>2]|=t[r]<<(r%4<<3);if(a[r>>2]|=128<<(r%4<<3),r>55)for(e(c,a),r=0;r<16;r+=1)a[r]=0;return o=(o=8*d).toString(16).match(/(.*?)(.{0,8})$/),s=parseInt(o[2],16),u=parseInt(o[1],16)||0,a[14]=s,a[15]=u,e(c,a),c}function o(t){var e,r="";for(e=0;e<4;e+=1)r+=l[t>>8*e+4&15]+l[t>>8*e&15];return r}function s(t){var e;for(e=0;e<t.length;e+=1)t[e]=o(t[e]);return t.join("")}function u(t){return/[\u0080-\uFFFF]/.test(t)&&(t=unescape(encodeURIComponent(t))),t}function d(t){var e,r=[],n=t.length;for(e=0;e<n-1;e+=2)r.push(parseInt(t.substr(e,2),16));return String.fromCharCode.apply(String,r)}function c(){this.reset()}var l=["0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f"];return s(i("hello")),"undefined"==typeof ArrayBuffer||ArrayBuffer.prototype.slice||function(){function e(t,e){return(t=0|t||0)<0?Math.max(t+e,0):Math.min(t,e)}ArrayBuffer.prototype.slice=function(r,n){var i,a,o,s,u=this.byteLength,d=e(r,u),c=u;return n!==t&&(c=e(n,u)),d>c?new ArrayBuffer(0):(i=c-d,a=new ArrayBuffer(i),o=new Uint8Array(a),s=new Uint8Array(this,d,i),o.set(s),a)}}(),c.prototype.append=function(t){return this.appendBinary(u(t)),this},c.prototype.appendBinary=function(t){this._buff+=t,this._length+=t.length;var n,i=this._buff.length;for(n=64;n<=i;n+=64)e(this._hash,r(this._buff.substring(n-64,n)));return this._buff=this._buff.substring(n-64),this},c.prototype.end=function(t){var e,r,n=this._buff,i=n.length,a=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];for(e=0;e<i;e+=1)a[e>>2]|=n.charCodeAt(e)<<(e%4<<3);return this._finish(a,i),r=s(this._hash),t&&(r=d(r)),this.reset(),r},c.prototype.reset=function(){return this._buff="",this._length=0,this._hash=[1732584193,-271733879,-1732584194,271733878],this},c.prototype.getState=function(){return{buff:this._buff,length:this._length,hash:this._hash}},c.prototype.setState=function(t){return this._buff=t.buff,this._length=t.length,this._hash=t.hash,this},c.prototype.destroy=function(){delete this._hash,delete this._buff,delete this._length},c.prototype._finish=function(t,r){var n,i,a,o=r;if(t[o>>2]|=128<<(o%4<<3),o>55)for(e(this._hash,t),o=0;o<16;o+=1)t[o]=0;n=(n=8*this._length).toString(16).match(/(.*?)(.{0,8})$/),i=parseInt(n[2],16),a=parseInt(n[1],16)||0,t[14]=i,t[15]=a,e(this._hash,t)},c.hash=function(t,e){return c.hashBinary(u(t),e)},c.hashBinary=function(t,e){var r=i(t),n=s(r);return e?d(n):n},c.ArrayBuffer=function(){this.reset()},c.ArrayBuffer.prototype.append=function(t){var r,i=function(t,e,r){var n=new Uint8Array(t.byteLength+e.byteLength);return n.set(new Uint8Array(t)),n.set(new Uint8Array(e),t.byteLength),r?n:n.buffer}(this._buff.buffer,t,!0),a=i.length;for(this._length+=t.byteLength,r=64;r<=a;r+=64)e(this._hash,n(i.subarray(r-64,r)));return this._buff=r-64<a?new Uint8Array(i.buffer.slice(r-64)):new Uint8Array(0),this},c.ArrayBuffer.prototype.end=function(t){var e,r,n=this._buff,i=n.length,a=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];for(e=0;e<i;e+=1)a[e>>2]|=n[e]<<(e%4<<3);return this._finish(a,i),r=s(this._hash),t&&(r=d(r)),this.reset(),r},c.ArrayBuffer.prototype.reset=function(){return this._buff=new Uint8Array(0),this._length=0,this._hash=[1732584193,-271733879,-1732584194,271733878],this},c.ArrayBuffer.prototype.getState=function(){var t=c.prototype.getState.call(this);return t.buff=function(t){return String.fromCharCode.apply(null,new Uint8Array(t))}(t.buff),t},c.ArrayBuffer.prototype.setState=function(t){return t.buff=function(t,e){var r,n=t.length,i=new ArrayBuffer(n),a=new Uint8Array(i);for(r=0;r<n;r+=1)a[r]=t.charCodeAt(r);return e?a:i}(t.buff,!0),c.prototype.setState.call(this,t)},c.ArrayBuffer.prototype.destroy=c.prototype.destroy,c.ArrayBuffer.prototype._finish=c.prototype._finish,c.ArrayBuffer.hash=function(t,e){var r=a(new Uint8Array(t)),n=s(r);return e?d(n):n},c}()},function(t,e,r){"use strict";r.d(e,"a",function(){return a});var n=r(0),i=function(){function t(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}return function(e,r,n){return r&&t(e.prototype,r),n&&t(e,n),e}}(),a=function(){function t(e,r,i){var a=this;(function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")})(this,t),this.file=e,this.attributes={filename:e.name,content_type:e.type,byte_size:e.size,checksum:r},this.xhr=new XMLHttpRequest,this.xhr.open("POST",i,!0),this.xhr.responseType="json",this.xhr.setRequestHeader("Content-Type","application/json"),this.xhr.setRequestHeader("Accept","application/json"),this.xhr.setRequestHeader("X-Requested-With","XMLHttpRequest"),this.xhr.setRequestHeader("X-CSRF-Token",Object(n.d)("csrf-token")),this.xhr.addEventListener("load",function(t){return a.requestDidLoad(t)}),this.xhr.addEventListener("error",function(t){return a.requestDidError(t)})}return i(t,[{key:"create",value:function(t){this.callback=t,this.xhr.send(JSON.stringify({blob:this.attributes}))}},{key:"requestDidLoad",value:function(t){if(this.status>=200&&this.status<300){var e=this.response,r=e.direct_upload;delete e.direct_upload,this.attributes=e,this.directUploadData=r,this.callback(null,this.toJSON())}else this.requestDidError(t)}},{key:"requestDidError",value:function(t){this.callback('Error creating Blob for "'+this.file.name+'". Status: '+this.status)}},{key:"toJSON",value:function(){var t={};for(var e in this.attributes)t[e]=this.attributes[e];return t}},{key:"status",get:function(){return this.xhr.status}},{key:"response",get:function(){var t=this.xhr,e=t.responseType,r=t.response;return"json"==e?r:JSON.parse(r)}}]),t}()},function(t,e,r){"use strict";r.d(e,"a",function(){return i});var n=function(){function t(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}return function(e,r,n){return r&&t(e.prototype,r),n&&t(e,n),e}}(),i=function(){function t(e){var r=this;(function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")})(this,t),this.blob=e,this.file=e.file;var n=e.directUploadData,i=n.url,a=n.headers;for(var o in this.xhr=new XMLHttpRequest,this.xhr.open("PUT",i,!0),this.xhr.responseType="text",a)this.xhr.setRequestHeader(o,a[o]);this.xhr.addEventListener("load",function(t){return r.requestDidLoad(t)}),this.xhr.addEventListener("error",function(t){return r.requestDidError(t)})}return n(t,[{key:"create",value:function(t){this.callback=t,this.xhr.send(this.file.slice())}},{key:"requestDidLoad",value:function(t){var e=this.xhr,r=e.status,n=e.response;r>=200&&r<300?this.callback(null,n):this.requestDidError(t)}},{key:"requestDidError",value:function(t){this.callback('Error storing "'+this.file.name+'". Status: '+this.xhr.status)}}]),t}()}])},function(t,e,r){"use strict";function n(t,e,r={}){const{bubbles:n,cancelable:i,detail:a}=r,o=document.createEvent("Event");return o.initEvent(e,n||!0,i||!0),o.detail=a||{},t.dispatchEvent(o),o}r.r(e);var i=r(0);const a="dnd-upload",o=[];class s{constructor(t,e){this.input=t,this.form=t.closest("form"),this.url=this.input.dataset.directUploadUrl,this.iconContainer=document.getElementById(this.input.dataset.iconContainerId),this.file=e,this.upload=new i.DirectUpload(this.file,this.url,this),this.dispatch("initialize")}start(t){this.upload.create((e,r)=>{if(e)console.log("Upload Error:"),console.log(e),this.dispatchError(e),t(e);else{console.log("Upload SUCCESS!!");const n=document.createElement("input");n.setAttribute("type","hidden"),n.setAttribute("value",r.signed_id),n.name=this.input.name,n.setAttribute("data-direct-upload-id",this.upload.id),this.form.appendChild(n),this.dispatch("end"),t(e)}})}dispatch(t,e={}){return e.file=this.file,e.id=this.upload.id,e.iconContainer=this.iconContainer,n(this.input,`${a}:${t}`,{detail:e})}dispatchError(t){this.dispatch("error",{error:t}).defaultPrevented||alert(t)}directUploadWillCreateBlobWithXHR(t){this.dispatch("before-blob-request",{xhr:t})}directUploadWillStoreFileWithXHR(t){this.dispatch("before-storage-request",{xhr:t}),t.upload.addEventListener("progress",t=>this.uploadRequestDidProgress(t))}uploadRequestDidProgress(t){const e=t.loaded/t.total*100;e&&this.dispatch("progress",{progress:e})}}function u(t,e){o.push(new s(t,e))}const d="dnd-uploads";class c{constructor(t){this.form=t,this.current_uploaders=[],o.forEach(e=>{t==e.form&&this.current_uploaders.push(e)})}start(t){const e=()=>{const r=this.current_uploaders.shift();r?r.start(r=>{r?(t(r),this.dispatch("end")):e()}):(t(),this.dispatch("end"))};this.dispatch("start"),e()}dispatch(t,e={}){return n(this.form,`${d}:${t}`,{detail:e})}}const l="dnd-upload";class f{constructor(t){this.input=t,this.start(t)}start(t){console.log("Binding input:change to createUploader");const e=t.closest("form"),r=t.dataset.dndZoneId,i=document.getElementById(r),a=(t.dataset.iconContainerId,document.getElementById(t.dataset.iconContainerId));t.addEventListener("change",e=>{console.log("input:change"),Array.from(t.files).forEach(e=>u(t,e)),t.value=null}),i.addEventListener("dragover",function(t){t.preventDefault()}),i.addEventListener("drop",function(e){e.preventDefault();const r=e.dataTransfer.files;Array.from(r).forEach(e=>u(t,e))});i.addEventListener("click",t=>{var e=t.target;if("true"==e.dataset.dndDelete&&e.hasAttribute("data-direct-upload-id")){t.preventDefault(),console.log("Delete Uploaded File: "+e.dataset.directUploadId),document.querySelectorAll('[data-direct-upload-id="'+e.dataset.directUploadId+'"]').forEach(t=>{t.remove()});for(var r=0;r<o.length;r++)if(o[r].upload.id==e.dataset.directUploadId){o.splice(r,1);break}}}),e.querySelectorAll("input[name='"+t.name+"'][type='hidden'][data-direct-upload-id][data-uploaded-file-name]").forEach(t=>{const e=t.dataset;let r={id:e.directUploadId,fileName:e.uploadedFileName,iconContainer:a};n(t,`${l}:placeholder`,{detail:r})})}}let h=!1;function p(t){v(t)}function y(t){"FORM"==t.target.tagName&&v(t)}function v(t){const e=t.target,r=new c(e);r.current_uploaders.length>0&&(t.preventDefault(),r.start(t=>{t||e.submit()}))}function b(){document.querySelectorAll("input[type=file][data-dnd=true]").forEach(t=>{new f(t)})}function g(){h||(h=!0,document.addEventListener("submit",p),document.addEventListener("ajax:before",y),addEventListener("turbolinks:load",b),addEventListener("load",b))}r.d(e,"start",function(){return g}),setTimeout(function(){g()},1);var m=function(t,e,r,n){var i=n?"complete":"pending",a=n?100:0;t.insertAdjacentHTML("beforeend",`\n <div id="direct-upload-${e}" class="direct-upload direct-upload--${i}" data-direct-upload-id="${e}">\n <div id="direct-upload-progress-${e}" class="direct-upload__progress" style="width: ${a}%"></div>\n <span class="direct-upload__filename">${r}</span>\n </div>\n <a href='remove' class='direct-upload__remove' data-dnd-delete='true' data-direct-upload-id="${e}">x</a>\n `)};addEventListener("dnd-uploads:start",t=>{console.log("dnd-uploads:start")}),addEventListener("dnd-uploads:end",t=>{console.log("dnd-uploads:end")}),addEventListener("dnd-upload:initialize",t=>{console.log("dnd-upload:initialize");const{target:e,detail:r}=t,{id:n,file:i,iconContainer:a}=r;m(a,n,i.name,!1)}),addEventListener("dnd-upload:placeholder",t=>{console.log("dnd-upload:placeholder");const{target:e,detail:r}=t,{id:n,fileName:i,iconContainer:a}=r;m(a,n,i,!0)}),addEventListener("dnd-upload:start",t=>{console.log("dnd-upload:start");const{id:e}=t.detail;document.getElementById(`direct-upload-${e}`).classList.remove("direct-upload--pending")}),addEventListener("dnd-upload:progress",t=>{console.log("dnd-upload:progress");const{id:e,progress:r}=t.detail;document.getElementById(`direct-upload-progress-${e}`).style.width=`${r}%`}),addEventListener("dnd-upload:error",t=>{console.log("dnd-upload:error"),t.preventDefault();const{id:e,error:r}=t.detail,n=document.getElementById(`direct-upload-${e}`);n.classList.add("direct-upload--error"),n.setAttribute("title",r)}),addEventListener("dnd-upload:end",t=>{console.log("dnd-upload:end");const{id:e}=t.detail,r=document.getElementById(`direct-upload-${e}`);r.classList.remove("direct-upload--pending"),r.classList.add("direct-upload--complete")})}])});
1
+ !function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.ActiveStorage=e():t.ActiveStorage=e()}(window,function(){return function(t){var e={};function r(n){if(e[n])return e[n].exports;var i=e[n]={i:n,l:!1,exports:{}};return t[n].call(i.exports,i,i.exports,r),i.l=!0,i.exports}return r.m=t,r.c=e,r.d=function(t,e,n){r.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},r.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(t,e){if(1&e&&(t=r(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var i in t)r.d(n,i,function(e){return t[e]}.bind(null,i));return n},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="",r(r.s=1)}([function(t,e,r){t.exports=function(t){function e(n){if(r[n])return r[n].exports;var i=r[n]={i:n,l:!1,exports:{}};return t[n].call(i.exports,i,i.exports,e),i.l=!0,i.exports}var r={};return e.m=t,e.c=r,e.d=function(t,r,n){e.o(t,r)||Object.defineProperty(t,r,{configurable:!1,enumerable:!0,get:n})},e.n=function(t){var r=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(r,"a",r),r},e.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},e.p="",e(e.s=2)}([function(t,e,r){"use strict";function n(t,e){return"string"==typeof t&&(e=t,t=document),t.querySelector(e)}function i(t){return Array.isArray(t)?t:Array.from?Array.from(t):[].slice.call(t)}e.d=function(t){var e=n(document.head,'meta[name="'+t+'"]');if(e)return e.getAttribute("content")},e.c=function(t,e){return"string"==typeof t&&(e=t,t=document),i(t.querySelectorAll(e))},e.b=n,e.a=function(t,e){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},n=t.disabled,i=r.bubbles,a=r.cancelable,o=r.detail,s=document.createEvent("Event");s.initEvent(e,i||!0,a||!0),s.detail=o||{};try{t.disabled=!1,t.dispatchEvent(s)}finally{t.disabled=n}return s},e.e=i},function(t,e,r){"use strict";function n(t,e){if(t&&"function"==typeof t[e]){for(var r=arguments.length,n=Array(r>2?r-2:0),i=2;i<r;i++)n[i-2]=arguments[i];return t[e].apply(t,n)}}r.d(e,"a",function(){return d});var i=r(6),a=r(8),o=r(9),s=function(){function t(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}return function(e,r,n){return r&&t(e.prototype,r),n&&t(e,n),e}}(),u=0,d=function(){function t(e,r,n){(function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")})(this,t),this.id=++u,this.file=e,this.url=r,this.delegate=n}return s(t,[{key:"create",value:function(t){var e=this;i.a.create(this.file,function(r,i){if(r)t(r);else{var s=new a.a(e.file,i,e.url);n(e.delegate,"directUploadWillCreateBlobWithXHR",s.xhr),s.create(function(r){if(r)t(r);else{var i=new o.a(s);n(e.delegate,"directUploadWillStoreFileWithXHR",i.xhr),i.create(function(e){e?t(e):t(null,s.toJSON())})}})}})}}]),t}()},function(t,e,r){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var n=r(3),i=r(1);r.d(e,"start",function(){return n.a}),r.d(e,"DirectUpload",function(){return i.a}),setTimeout(function(){window.ActiveStorage&&Object(n.a)()},1)},function(t,e,r){"use strict";function n(t){a(t)}function i(t){"FORM"==t.target.tagName&&a(t)}function a(t){var e=t.target;if(e.hasAttribute(c))t.preventDefault();else{var r=new u.a(e),n=r.inputs;n.length&&(t.preventDefault(),e.setAttribute(c,""),n.forEach(o),r.start(function(t){e.removeAttribute(c),t?n.forEach(s):function(t){var e=Object(d.b)(t,"input[type=submit]");if(e){var r=e,n=r.disabled;e.disabled=!1,e.focus(),e.click(),e.disabled=n}else(e=document.createElement("input")).type="submit",e.style.display="none",t.appendChild(e),e.click(),t.removeChild(e)}(e)}))}}function o(t){t.disabled=!0}function s(t){t.disabled=!1}e.a=function(){l||(l=!0,document.addEventListener("submit",n),document.addEventListener("ajax:before",i))};var u=r(4),d=r(0),c="data-direct-uploads-processing",l=!1},function(t,e,r){"use strict";r.d(e,"a",function(){return s});var n=r(5),i=r(0),a=function(){function t(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}return function(e,r,n){return r&&t(e.prototype,r),n&&t(e,n),e}}(),o="input[type=file][data-direct-upload-url]:not([disabled])",s=function(){function t(e){(function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")})(this,t),this.form=e,this.inputs=Object(i.c)(e,o).filter(function(t){return t.files.length})}return a(t,[{key:"start",value:function(t){var e=this,r=this.createDirectUploadControllers();this.dispatch("start"),function n(){var i=r.shift();i?i.start(function(r){r?(t(r),e.dispatch("end")):n()}):(t(),e.dispatch("end"))}()}},{key:"createDirectUploadControllers",value:function(){var t=[];return this.inputs.forEach(function(e){Object(i.e)(e.files).forEach(function(r){var i=new n.a(e,r);t.push(i)})}),t}},{key:"dispatch",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return Object(i.a)(this.form,"direct-uploads:"+t,{detail:e})}}]),t}()},function(t,e,r){"use strict";r.d(e,"a",function(){return o});var n=r(1),i=r(0),a=function(){function t(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}return function(e,r,n){return r&&t(e.prototype,r),n&&t(e,n),e}}(),o=function(){function t(e,r){(function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")})(this,t),this.input=e,this.file=r,this.directUpload=new n.a(this.file,this.url,this),this.dispatch("initialize")}return a(t,[{key:"start",value:function(t){var e=this,r=document.createElement("input");r.type="hidden",r.name=this.input.name,this.input.insertAdjacentElement("beforebegin",r),this.dispatch("start"),this.directUpload.create(function(n,i){n?(r.parentNode.removeChild(r),e.dispatchError(n)):r.value=i.signed_id,e.dispatch("end"),t(n)})}},{key:"uploadRequestDidProgress",value:function(t){var e=t.loaded/t.total*100;e&&this.dispatch("progress",{progress:e})}},{key:"dispatch",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return e.file=this.file,e.id=this.directUpload.id,Object(i.a)(this.input,"direct-upload:"+t,{detail:e})}},{key:"dispatchError",value:function(t){this.dispatch("error",{error:t}).defaultPrevented||alert(t)}},{key:"directUploadWillCreateBlobWithXHR",value:function(t){this.dispatch("before-blob-request",{xhr:t})}},{key:"directUploadWillStoreFileWithXHR",value:function(t){var e=this;this.dispatch("before-storage-request",{xhr:t}),t.upload.addEventListener("progress",function(t){return e.uploadRequestDidProgress(t)})}},{key:"url",get:function(){return this.input.getAttribute("data-direct-upload-url")}}]),t}()},function(t,e,r){"use strict";r.d(e,"a",function(){return s});var n=r(7),i=r.n(n),a=function(){function t(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}return function(e,r,n){return r&&t(e.prototype,r),n&&t(e,n),e}}(),o=File.prototype.slice||File.prototype.mozSlice||File.prototype.webkitSlice,s=function(){function t(e){(function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")})(this,t),this.file=e,this.chunkSize=2097152,this.chunkCount=Math.ceil(this.file.size/this.chunkSize),this.chunkIndex=0}return a(t,null,[{key:"create",value:function(e,r){new t(e).create(r)}}]),a(t,[{key:"create",value:function(t){var e=this;this.callback=t,this.md5Buffer=new i.a.ArrayBuffer,this.fileReader=new FileReader,this.fileReader.addEventListener("load",function(t){return e.fileReaderDidLoad(t)}),this.fileReader.addEventListener("error",function(t){return e.fileReaderDidError(t)}),this.readNextChunk()}},{key:"fileReaderDidLoad",value:function(t){if(this.md5Buffer.append(t.target.result),!this.readNextChunk()){var e=this.md5Buffer.end(!0),r=btoa(e);this.callback(null,r)}}},{key:"fileReaderDidError",value:function(t){this.callback("Error reading "+this.file.name)}},{key:"readNextChunk",value:function(){if(this.chunkIndex<this.chunkCount){var t=this.chunkIndex*this.chunkSize,e=Math.min(t+this.chunkSize,this.file.size),r=o.call(this.file,t,e);return this.fileReader.readAsArrayBuffer(r),this.chunkIndex++,!0}return!1}}]),t}()},function(t,e,r){t.exports=function(t){"use strict";function e(t,e){var r=t[0],n=t[1],i=t[2],a=t[3];r+=(n&i|~n&a)+e[0]-680876936|0,a+=((r=(r<<7|r>>>25)+n|0)&n|~r&i)+e[1]-389564586|0,i+=((a=(a<<12|a>>>20)+r|0)&r|~a&n)+e[2]+606105819|0,n+=((i=(i<<17|i>>>15)+a|0)&a|~i&r)+e[3]-1044525330|0,r+=((n=(n<<22|n>>>10)+i|0)&i|~n&a)+e[4]-176418897|0,a+=((r=(r<<7|r>>>25)+n|0)&n|~r&i)+e[5]+1200080426|0,i+=((a=(a<<12|a>>>20)+r|0)&r|~a&n)+e[6]-1473231341|0,n+=((i=(i<<17|i>>>15)+a|0)&a|~i&r)+e[7]-45705983|0,r+=((n=(n<<22|n>>>10)+i|0)&i|~n&a)+e[8]+1770035416|0,a+=((r=(r<<7|r>>>25)+n|0)&n|~r&i)+e[9]-1958414417|0,i+=((a=(a<<12|a>>>20)+r|0)&r|~a&n)+e[10]-42063|0,n+=((i=(i<<17|i>>>15)+a|0)&a|~i&r)+e[11]-1990404162|0,r+=((n=(n<<22|n>>>10)+i|0)&i|~n&a)+e[12]+1804603682|0,a+=((r=(r<<7|r>>>25)+n|0)&n|~r&i)+e[13]-40341101|0,i+=((a=(a<<12|a>>>20)+r|0)&r|~a&n)+e[14]-1502002290|0,n+=((i=(i<<17|i>>>15)+a|0)&a|~i&r)+e[15]+1236535329|0,r+=((n=(n<<22|n>>>10)+i|0)&a|i&~a)+e[1]-165796510|0,a+=((r=(r<<5|r>>>27)+n|0)&i|n&~i)+e[6]-1069501632|0,i+=((a=(a<<9|a>>>23)+r|0)&n|r&~n)+e[11]+643717713|0,n+=((i=(i<<14|i>>>18)+a|0)&r|a&~r)+e[0]-373897302|0,r+=((n=(n<<20|n>>>12)+i|0)&a|i&~a)+e[5]-701558691|0,a+=((r=(r<<5|r>>>27)+n|0)&i|n&~i)+e[10]+38016083|0,i+=((a=(a<<9|a>>>23)+r|0)&n|r&~n)+e[15]-660478335|0,n+=((i=(i<<14|i>>>18)+a|0)&r|a&~r)+e[4]-405537848|0,r+=((n=(n<<20|n>>>12)+i|0)&a|i&~a)+e[9]+568446438|0,a+=((r=(r<<5|r>>>27)+n|0)&i|n&~i)+e[14]-1019803690|0,i+=((a=(a<<9|a>>>23)+r|0)&n|r&~n)+e[3]-187363961|0,n+=((i=(i<<14|i>>>18)+a|0)&r|a&~r)+e[8]+1163531501|0,r+=((n=(n<<20|n>>>12)+i|0)&a|i&~a)+e[13]-1444681467|0,a+=((r=(r<<5|r>>>27)+n|0)&i|n&~i)+e[2]-51403784|0,i+=((a=(a<<9|a>>>23)+r|0)&n|r&~n)+e[7]+1735328473|0,n+=((i=(i<<14|i>>>18)+a|0)&r|a&~r)+e[12]-1926607734|0,r+=((n=(n<<20|n>>>12)+i|0)^i^a)+e[5]-378558|0,a+=((r=(r<<4|r>>>28)+n|0)^n^i)+e[8]-2022574463|0,i+=((a=(a<<11|a>>>21)+r|0)^r^n)+e[11]+1839030562|0,n+=((i=(i<<16|i>>>16)+a|0)^a^r)+e[14]-35309556|0,r+=((n=(n<<23|n>>>9)+i|0)^i^a)+e[1]-1530992060|0,a+=((r=(r<<4|r>>>28)+n|0)^n^i)+e[4]+1272893353|0,i+=((a=(a<<11|a>>>21)+r|0)^r^n)+e[7]-155497632|0,n+=((i=(i<<16|i>>>16)+a|0)^a^r)+e[10]-1094730640|0,r+=((n=(n<<23|n>>>9)+i|0)^i^a)+e[13]+681279174|0,a+=((r=(r<<4|r>>>28)+n|0)^n^i)+e[0]-358537222|0,i+=((a=(a<<11|a>>>21)+r|0)^r^n)+e[3]-722521979|0,n+=((i=(i<<16|i>>>16)+a|0)^a^r)+e[6]+76029189|0,r+=((n=(n<<23|n>>>9)+i|0)^i^a)+e[9]-640364487|0,a+=((r=(r<<4|r>>>28)+n|0)^n^i)+e[12]-421815835|0,i+=((a=(a<<11|a>>>21)+r|0)^r^n)+e[15]+530742520|0,n+=((i=(i<<16|i>>>16)+a|0)^a^r)+e[2]-995338651|0,r+=(i^((n=(n<<23|n>>>9)+i|0)|~a))+e[0]-198630844|0,a+=(n^((r=(r<<6|r>>>26)+n|0)|~i))+e[7]+1126891415|0,i+=(r^((a=(a<<10|a>>>22)+r|0)|~n))+e[14]-1416354905|0,n+=(a^((i=(i<<15|i>>>17)+a|0)|~r))+e[5]-57434055|0,r+=(i^((n=(n<<21|n>>>11)+i|0)|~a))+e[12]+1700485571|0,a+=(n^((r=(r<<6|r>>>26)+n|0)|~i))+e[3]-1894986606|0,i+=(r^((a=(a<<10|a>>>22)+r|0)|~n))+e[10]-1051523|0,n+=(a^((i=(i<<15|i>>>17)+a|0)|~r))+e[1]-2054922799|0,r+=(i^((n=(n<<21|n>>>11)+i|0)|~a))+e[8]+1873313359|0,a+=(n^((r=(r<<6|r>>>26)+n|0)|~i))+e[15]-30611744|0,i+=(r^((a=(a<<10|a>>>22)+r|0)|~n))+e[6]-1560198380|0,n+=(a^((i=(i<<15|i>>>17)+a|0)|~r))+e[13]+1309151649|0,r+=(i^((n=(n<<21|n>>>11)+i|0)|~a))+e[4]-145523070|0,a+=(n^((r=(r<<6|r>>>26)+n|0)|~i))+e[11]-1120210379|0,i+=(r^((a=(a<<10|a>>>22)+r|0)|~n))+e[2]+718787259|0,n=((n+=(a^((i=(i<<15|i>>>17)+a|0)|~r))+e[9]-343485551|0)<<21|n>>>11)+i|0,t[0]=r+t[0]|0,t[1]=n+t[1]|0,t[2]=i+t[2]|0,t[3]=a+t[3]|0}function r(t){var e,r=[];for(e=0;e<64;e+=4)r[e>>2]=t.charCodeAt(e)+(t.charCodeAt(e+1)<<8)+(t.charCodeAt(e+2)<<16)+(t.charCodeAt(e+3)<<24);return r}function n(t){var e,r=[];for(e=0;e<64;e+=4)r[e>>2]=t[e]+(t[e+1]<<8)+(t[e+2]<<16)+(t[e+3]<<24);return r}function i(t){var n,i,a,o,s,u,d=t.length,c=[1732584193,-271733879,-1732584194,271733878];for(n=64;n<=d;n+=64)e(c,r(t.substring(n-64,n)));for(t=t.substring(n-64),i=t.length,a=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],n=0;n<i;n+=1)a[n>>2]|=t.charCodeAt(n)<<(n%4<<3);if(a[n>>2]|=128<<(n%4<<3),n>55)for(e(c,a),n=0;n<16;n+=1)a[n]=0;return o=(o=8*d).toString(16).match(/(.*?)(.{0,8})$/),s=parseInt(o[2],16),u=parseInt(o[1],16)||0,a[14]=s,a[15]=u,e(c,a),c}function a(t){var r,i,a,o,s,u,d=t.length,c=[1732584193,-271733879,-1732584194,271733878];for(r=64;r<=d;r+=64)e(c,n(t.subarray(r-64,r)));for(t=r-64<d?t.subarray(r-64):new Uint8Array(0),i=t.length,a=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],r=0;r<i;r+=1)a[r>>2]|=t[r]<<(r%4<<3);if(a[r>>2]|=128<<(r%4<<3),r>55)for(e(c,a),r=0;r<16;r+=1)a[r]=0;return o=(o=8*d).toString(16).match(/(.*?)(.{0,8})$/),s=parseInt(o[2],16),u=parseInt(o[1],16)||0,a[14]=s,a[15]=u,e(c,a),c}function o(t){var e,r="";for(e=0;e<4;e+=1)r+=l[t>>8*e+4&15]+l[t>>8*e&15];return r}function s(t){var e;for(e=0;e<t.length;e+=1)t[e]=o(t[e]);return t.join("")}function u(t){return/[\u0080-\uFFFF]/.test(t)&&(t=unescape(encodeURIComponent(t))),t}function d(t){var e,r=[],n=t.length;for(e=0;e<n-1;e+=2)r.push(parseInt(t.substr(e,2),16));return String.fromCharCode.apply(String,r)}function c(){this.reset()}var l=["0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f"];return s(i("hello")),"undefined"==typeof ArrayBuffer||ArrayBuffer.prototype.slice||function(){function e(t,e){return(t=0|t||0)<0?Math.max(t+e,0):Math.min(t,e)}ArrayBuffer.prototype.slice=function(r,n){var i,a,o,s,u=this.byteLength,d=e(r,u),c=u;return n!==t&&(c=e(n,u)),d>c?new ArrayBuffer(0):(i=c-d,a=new ArrayBuffer(i),o=new Uint8Array(a),s=new Uint8Array(this,d,i),o.set(s),a)}}(),c.prototype.append=function(t){return this.appendBinary(u(t)),this},c.prototype.appendBinary=function(t){this._buff+=t,this._length+=t.length;var n,i=this._buff.length;for(n=64;n<=i;n+=64)e(this._hash,r(this._buff.substring(n-64,n)));return this._buff=this._buff.substring(n-64),this},c.prototype.end=function(t){var e,r,n=this._buff,i=n.length,a=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];for(e=0;e<i;e+=1)a[e>>2]|=n.charCodeAt(e)<<(e%4<<3);return this._finish(a,i),r=s(this._hash),t&&(r=d(r)),this.reset(),r},c.prototype.reset=function(){return this._buff="",this._length=0,this._hash=[1732584193,-271733879,-1732584194,271733878],this},c.prototype.getState=function(){return{buff:this._buff,length:this._length,hash:this._hash}},c.prototype.setState=function(t){return this._buff=t.buff,this._length=t.length,this._hash=t.hash,this},c.prototype.destroy=function(){delete this._hash,delete this._buff,delete this._length},c.prototype._finish=function(t,r){var n,i,a,o=r;if(t[o>>2]|=128<<(o%4<<3),o>55)for(e(this._hash,t),o=0;o<16;o+=1)t[o]=0;n=(n=8*this._length).toString(16).match(/(.*?)(.{0,8})$/),i=parseInt(n[2],16),a=parseInt(n[1],16)||0,t[14]=i,t[15]=a,e(this._hash,t)},c.hash=function(t,e){return c.hashBinary(u(t),e)},c.hashBinary=function(t,e){var r=i(t),n=s(r);return e?d(n):n},c.ArrayBuffer=function(){this.reset()},c.ArrayBuffer.prototype.append=function(t){var r,i=function(t,e,r){var n=new Uint8Array(t.byteLength+e.byteLength);return n.set(new Uint8Array(t)),n.set(new Uint8Array(e),t.byteLength),r?n:n.buffer}(this._buff.buffer,t,!0),a=i.length;for(this._length+=t.byteLength,r=64;r<=a;r+=64)e(this._hash,n(i.subarray(r-64,r)));return this._buff=r-64<a?new Uint8Array(i.buffer.slice(r-64)):new Uint8Array(0),this},c.ArrayBuffer.prototype.end=function(t){var e,r,n=this._buff,i=n.length,a=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];for(e=0;e<i;e+=1)a[e>>2]|=n[e]<<(e%4<<3);return this._finish(a,i),r=s(this._hash),t&&(r=d(r)),this.reset(),r},c.ArrayBuffer.prototype.reset=function(){return this._buff=new Uint8Array(0),this._length=0,this._hash=[1732584193,-271733879,-1732584194,271733878],this},c.ArrayBuffer.prototype.getState=function(){var t=c.prototype.getState.call(this);return t.buff=function(t){return String.fromCharCode.apply(null,new Uint8Array(t))}(t.buff),t},c.ArrayBuffer.prototype.setState=function(t){return t.buff=function(t,e){var r,n=t.length,i=new ArrayBuffer(n),a=new Uint8Array(i);for(r=0;r<n;r+=1)a[r]=t.charCodeAt(r);return e?a:i}(t.buff,!0),c.prototype.setState.call(this,t)},c.ArrayBuffer.prototype.destroy=c.prototype.destroy,c.ArrayBuffer.prototype._finish=c.prototype._finish,c.ArrayBuffer.hash=function(t,e){var r=a(new Uint8Array(t)),n=s(r);return e?d(n):n},c}()},function(t,e,r){"use strict";r.d(e,"a",function(){return a});var n=r(0),i=function(){function t(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}return function(e,r,n){return r&&t(e.prototype,r),n&&t(e,n),e}}(),a=function(){function t(e,r,i){var a=this;(function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")})(this,t),this.file=e,this.attributes={filename:e.name,content_type:e.type,byte_size:e.size,checksum:r},this.xhr=new XMLHttpRequest,this.xhr.open("POST",i,!0),this.xhr.responseType="json",this.xhr.setRequestHeader("Content-Type","application/json"),this.xhr.setRequestHeader("Accept","application/json"),this.xhr.setRequestHeader("X-Requested-With","XMLHttpRequest"),this.xhr.setRequestHeader("X-CSRF-Token",Object(n.d)("csrf-token")),this.xhr.addEventListener("load",function(t){return a.requestDidLoad(t)}),this.xhr.addEventListener("error",function(t){return a.requestDidError(t)})}return i(t,[{key:"create",value:function(t){this.callback=t,this.xhr.send(JSON.stringify({blob:this.attributes}))}},{key:"requestDidLoad",value:function(t){if(this.status>=200&&this.status<300){var e=this.response,r=e.direct_upload;delete e.direct_upload,this.attributes=e,this.directUploadData=r,this.callback(null,this.toJSON())}else this.requestDidError(t)}},{key:"requestDidError",value:function(t){this.callback('Error creating Blob for "'+this.file.name+'". Status: '+this.status)}},{key:"toJSON",value:function(){var t={};for(var e in this.attributes)t[e]=this.attributes[e];return t}},{key:"status",get:function(){return this.xhr.status}},{key:"response",get:function(){var t=this.xhr,e=t.responseType,r=t.response;return"json"==e?r:JSON.parse(r)}}]),t}()},function(t,e,r){"use strict";r.d(e,"a",function(){return i});var n=function(){function t(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}return function(e,r,n){return r&&t(e.prototype,r),n&&t(e,n),e}}(),i=function(){function t(e){var r=this;(function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")})(this,t),this.blob=e,this.file=e.file;var n=e.directUploadData,i=n.url,a=n.headers;for(var o in this.xhr=new XMLHttpRequest,this.xhr.open("PUT",i,!0),this.xhr.responseType="text",a)this.xhr.setRequestHeader(o,a[o]);this.xhr.addEventListener("load",function(t){return r.requestDidLoad(t)}),this.xhr.addEventListener("error",function(t){return r.requestDidError(t)})}return n(t,[{key:"create",value:function(t){this.callback=t,this.xhr.send(this.file.slice())}},{key:"requestDidLoad",value:function(t){var e=this.xhr,r=e.status,n=e.response;r>=200&&r<300?this.callback(null,n):this.requestDidError(t)}},{key:"requestDidError",value:function(t){this.callback('Error storing "'+this.file.name+'". Status: '+this.xhr.status)}}]),t}()}])},function(t,e,r){"use strict";function n(t,e,r={}){const{bubbles:n,cancelable:i,detail:a}=r,o=document.createEvent("Event");return o.initEvent(e,n||!0,i||!0),o.detail=a||{},t.dispatchEvent(o),o}r.r(e);var i=r(0);const a="dnd-upload";class o{constructor(t,e){this.input=t,this.form=t.closest("form"),this.url=this.input.dataset.directUploadUrl,this.iconContainer=document.getElementById(this.input.dataset.iconContainerId),this.file=e,this.upload=new i.DirectUpload(this.file,this.url,this),this.dispatch("initialize")}start(t){this.upload.create((e,r)=>{if(e)console.log("Upload Error:"),console.log(e),this.dispatchError(e),t(e);else{console.log("Upload SUCCESS!!");const n=document.createElement("input");n.setAttribute("type","hidden"),n.setAttribute("value",r.signed_id),n.name=this.input.name,n.setAttribute("data-direct-upload-id",this.upload.id),this.form.appendChild(n),this.dispatch("end"),t(e)}})}dispatch(t,e={}){return e.file=this.file,e.id=this.upload.id,e.iconContainer=this.iconContainer,n(this.input,`${a}:${t}`,{detail:e})}dispatchError(t){this.dispatch("error",{error:t}).defaultPrevented||alert(t)}directUploadWillCreateBlobWithXHR(t){this.dispatch("before-blob-request",{xhr:t})}directUploadWillStoreFileWithXHR(t){this.dispatch("before-storage-request",{xhr:t}),t.upload.addEventListener("progress",t=>this.uploadRequestDidProgress(t))}uploadRequestDidProgress(t){const e=t.loaded/t.total*100;e&&this.dispatch("progress",{progress:e})}}const s=[],u="dnd-uploads";class d{constructor(t){this.form=t,this.current_uploaders=[],s.forEach(e=>{t==e.form&&this.current_uploaders.push(e)})}start(t){const e=()=>{const r=this.current_uploaders.shift();r?r.start(r=>{r?(t(r),this.dispatch("end")):e()}):(t(),this.dispatch("end"))};this.dispatch("start"),e()}dispatch(t,e={}){return n(this.form,`${u}:${t}`,{detail:e})}}function c(t,e){s.push(new o(t,e))}let l=!1,f=!1;function h(t){y(t)}function p(t){"FORM"==t.target.tagName&&y(t)}function y(t){if(f)return;f=!0;const e=t.target,r=new d(e);r.current_uploaders.length>0&&(t.preventDefault(),r.start(t=>{t||e.submit()}))}function v(){console.log("checking for already attached files"),document.querySelectorAll("input[type='hidden'][data-direct-upload-id][data-uploaded-file-name]").forEach(t=>{console.log("addAttachedFileIcon!");const e=t.dataset;let r=document.getElementById(e.iconContainerId);n(t,"dnd-upload:placeholder",{detail:{id:e.directUploadId,fileName:e.uploadedFileName,iconContainer:r}})})}function b(){l||(l=!0,document.addEventListener("submit",h),document.addEventListener("ajax:before",p),document.addEventListener("change",t=>{if(console.log("document:change"),"file"==t.target.type&&"true"==t.target.dataset.dnd){const e=t.target;console.log("input[type=file][data-dnd=true]:change"),Array.from(e.files).forEach(t=>c(e,t)),e.value=null}}),document.addEventListener("dragover",t=>{console.log("document:dragover"),function t(e,r){return!(!e||!e.classList)&&(!!e.classList.contains(r)||t(e.parentNode,r))}(t.target,"asdndzone")&&t.preventDefault()}),document.addEventListener("drop",t=>{console.log("document:drop");let e=function t(e,r){return e&&e.classList?e.classList.contains(r)?e:t(e.parentNode,r):null}(t.target,"asdndzone");if(e){t.preventDefault(),console.log(".asdndzone:drop");const r=document.getElementById(e.dataset.dndInputId);Array.from(t.dataTransfer.files).forEach(t=>c(r,t))}}),document.addEventListener("click",t=>{if("true"==t.target.dataset.dndDelete&&t.target.hasAttribute("data-direct-upload-id")){t.preventDefault(),console.log("[data-dnd-delete=true][data-direct-upload-id]:click"),document.querySelectorAll('[data-direct-upload-id="'+t.target.dataset.directUploadId+'"]').forEach(t=>{t.remove()});for(var e=0;e<s.length;e++)if(s[e].upload.id==t.target.dataset.directUploadId){s.splice(e,1);break}}}),addEventListener("turbolinks:load",v),addEventListener("load",v))}r.d(e,"start",function(){return b}),setTimeout(function(){b()},1);var g=function(t,e,r,n){var i=n?"complete":"pending",a=n?100:0;t.insertAdjacentHTML("beforeend",`\n <div id="direct-upload-${e}" class="direct-upload direct-upload--${i}" data-direct-upload-id="${e}">\n <div id="direct-upload-progress-${e}" class="direct-upload__progress" style="width: ${a}%"></div>\n <span class="direct-upload__filename">${r}</span>\n </div>\n <a href='remove' class='direct-upload__remove' data-dnd-delete='true' data-direct-upload-id="${e}">x</a>\n `)};addEventListener("dnd-uploads:start",t=>{console.log("dnd-uploads:start")}),addEventListener("dnd-uploads:end",t=>{console.log("dnd-uploads:end")}),addEventListener("dnd-upload:initialize",t=>{console.log("dnd-upload:initialize");const{target:e,detail:r}=t,{id:n,file:i,iconContainer:a}=r;g(a,n,i.name,!1)}),addEventListener("dnd-upload:placeholder",t=>{console.log("dnd-upload:placeholder");const{target:e,detail:r}=t,{id:n,fileName:i,iconContainer:a}=r;g(a,n,i,!0)}),addEventListener("dnd-upload:start",t=>{console.log("dnd-upload:start");const{id:e}=t.detail;document.getElementById(`direct-upload-${e}`).classList.remove("direct-upload--pending")}),addEventListener("dnd-upload:progress",t=>{console.log("dnd-upload:progress");const{id:e,progress:r}=t.detail;document.getElementById(`direct-upload-progress-${e}`).style.width=`${r}%`}),addEventListener("dnd-upload:error",t=>{console.log("dnd-upload:error"),t.preventDefault();const{id:e,error:r}=t.detail,n=document.getElementById(`direct-upload-${e}`);n.classList.add("direct-upload--error"),n.setAttribute("title",r)}),addEventListener("dnd-upload:end",t=>{console.log("dnd-upload:end");const{id:e}=t.detail,r=document.getElementById(`direct-upload-${e}`);r.classList.remove("direct-upload--pending"),r.classList.add("direct-upload--complete")})}])});
@@ -1,4 +1,4 @@
1
- #active-storage-drag-zone {
1
+ .asdndzone {
2
2
  min-height: 100px;
3
3
  border: 2px solid rgba(0, 0, 0, 0.3);
4
4
  background: rgba(0,0,0,0.1);
@@ -1,7 +1,6 @@
1
1
  import { dispatchEvent } from './helpers'
2
2
  import { DirectUpload } from 'activestorage'
3
3
  const eventFamily = 'dnd-upload'
4
- export const uploaders = []
5
4
 
6
5
  export class DragAndDropUploadController {
7
6
  constructor(input, file) {
@@ -70,9 +69,3 @@ export class DragAndDropUploadController {
70
69
  }
71
70
 
72
71
  }
73
-
74
- export function createUploader(input, file) {
75
- // your form needs the file_field direct_upload: true, which
76
- // provides data-direct-upload-url
77
- uploaders.push( new DragAndDropUploadController(input, file) )
78
- }
@@ -8,6 +8,30 @@ export function dispatchEvent(element, type, eventInit = {}) {
8
8
  return event
9
9
  }
10
10
 
11
+ export function hasClassnameInHeirarchy(element, classname) {
12
+ if(element && element.classList) {
13
+ if (element.classList.contains(classname)) {
14
+ return true
15
+ } else {
16
+ return hasClassnameInHeirarchy(element.parentNode, classname)
17
+ }
18
+ } else {
19
+ return false
20
+ }
21
+ }
22
+
23
+ export function getClassnameFromHeirarchy(element, classname) {
24
+ if(element && element.classList) {
25
+ if (element.classList.contains(classname)) {
26
+ return element
27
+ } else {
28
+ return getClassnameFromHeirarchy(element.parentNode, classname)
29
+ }
30
+ } else {
31
+ return null
32
+ }
33
+ }
34
+
11
35
  //export function disable(input) {
12
36
  // input.disabled = true
13
37
  //}
@@ -1,7 +1,8 @@
1
- import { UploadQueueProcessor } from "./upload_queue_processor"
2
- import { UploaderInput } from "./uploader_input"
1
+ import { UploadQueueProcessor, uploaders, createUploader } from "./upload_queue_processor"
2
+ import * as helpers from './helpers'
3
3
 
4
4
  let started = false
5
+ let formSubmitted = false
5
6
 
6
7
  function didSubmitForm(event) {
7
8
  handleFormSubmissionEvent(event)
@@ -14,6 +15,8 @@ function didSubmitRemoteElement(event) {
14
15
  }
15
16
 
16
17
  function handleFormSubmissionEvent(event) {
18
+ if(formSubmitted) { return }
19
+ formSubmitted = true
17
20
  const form = event.target
18
21
  const next_upload = new UploadQueueProcessor(form)
19
22
  // if the upload processor has no dnd file inputs, then we let the event happen naturally
@@ -25,29 +28,85 @@ function handleFormSubmissionEvent(event) {
25
28
  if (error) {
26
29
  // inputs.forEach(enable)
27
30
  } else {
28
- // The original ActiveStorage DirectUpload system did this action using
29
- // input.click(), but doing that either makes the form submission event
30
- // happen multiple times, or the browser seems to block the input.click()
31
- // event completely, because it's not a trusted 'as a result of a mouse
32
- // click' event.
33
- form.submit()
31
+ form.submit()
32
+ // The original ActiveStorage DirectUpload system did this action using
33
+ // input.click(), but doing that either makes the form submission event
34
+ // happen multiple times, or the browser seems to block the input.click()
35
+ // event completely, because it's not a trusted 'as a result of a mouse
36
+ // click' event.
37
+ // HOWEVER
38
+ // form.submit() doesn't trigger to any UJS submission events. This
39
+ // results in remote forms being submitted locally whenever there's a
40
+ // dnd file to upload. Instead we use Rails.fire(element, 'submit')
41
+ // Rails.fire(form, 'submit')
34
42
  }
35
43
  })
36
44
  }
37
45
  }
38
46
 
39
- function initializeDragAndDropUploader() {
40
- document.querySelectorAll('input[type=file][data-dnd=true]').forEach(input => {
41
- new UploaderInput(input)
47
+ function addAttachedFileIcons() {
48
+ console.log('checking for already attached files')
49
+ document.querySelectorAll("input[type='hidden'][data-direct-upload-id][data-uploaded-file-name]").forEach( uploadedFile => {
50
+ console.log('addAttachedFileIcon!')
51
+ const dataset = uploadedFile.dataset
52
+ let iconContainer = document.getElementById(dataset.iconContainerId);
53
+ let detail = {
54
+ id: dataset.directUploadId,
55
+ fileName: dataset.uploadedFileName,
56
+ iconContainer: iconContainer
57
+ }
58
+ helpers.dispatchEvent(uploadedFile, `dnd-upload:placeholder`, { detail })
42
59
  })
43
60
  }
44
61
 
45
62
  export function start() {
46
- if (!started) {
47
- started = true
48
- document.addEventListener("submit", didSubmitForm)
49
- document.addEventListener("ajax:before", didSubmitRemoteElement)
50
- addEventListener("turbolinks:load", initializeDragAndDropUploader)
51
- addEventListener("load", initializeDragAndDropUploader)
52
- }
63
+ if (started) { return }
64
+ started = true
65
+ document.addEventListener("submit", didSubmitForm)
66
+ document.addEventListener("ajax:before", didSubmitRemoteElement)
67
+
68
+ // input[type=file][data-dnd=true]
69
+ document.addEventListener("change", event => {
70
+ console.log('document:change')
71
+ if(event.target.type == 'file' && event.target.dataset.dnd == 'true') {
72
+ const input = event.target;
73
+ console.log("input[type=file][data-dnd=true]:change")
74
+ Array.from(input.files).forEach(file => createUploader(input, file))
75
+ input.value = null
76
+ }
77
+ })
78
+ document.addEventListener("dragover", event => {
79
+ console.log('document:dragover');
80
+ if(helpers.hasClassnameInHeirarchy(event.target, 'asdndzone')) {
81
+ event.preventDefault();
82
+ }
83
+ })
84
+ document.addEventListener("drop", event => {
85
+ console.log('document:drop');
86
+ let asdndz = helpers.getClassnameFromHeirarchy(event.target, 'asdndzone')
87
+ if(asdndz) {
88
+ event.preventDefault()
89
+ console.log(".asdndzone:drop")
90
+ // get the input associated with this dndz
91
+ const input = document.getElementById(asdndz.dataset.dndInputId)
92
+ Array.from(event.dataTransfer.files).forEach(file => createUploader(input, file))
93
+ }
94
+ })
95
+ document.addEventListener("click", event => {
96
+ if( event.target.dataset.dndDelete == 'true' && event.target.hasAttribute('data-direct-upload-id') ) {
97
+ event.preventDefault();
98
+ console.log("[data-dnd-delete=true][data-direct-upload-id]:click")
99
+ document.querySelectorAll('[data-direct-upload-id="'+event.target.dataset.directUploadId+'"]').forEach(element => {
100
+ element.remove()
101
+ })
102
+ for(var i=0;i<uploaders.length;i++) {
103
+ if(uploaders[i].upload.id == event.target.dataset.directUploadId) {
104
+ uploaders.splice( i, 1 )
105
+ break
106
+ }
107
+ }
108
+ }
109
+ })
110
+ addEventListener("turbolinks:load", addAttachedFileIcons);
111
+ addEventListener("load", addAttachedFileIcons);
53
112
  }
@@ -1,5 +1,6 @@
1
1
  import { dispatchEvent } from "./helpers"
2
- import { uploaders } from "./direct_upload_controller"
2
+ import { DragAndDropUploadController } from "./direct_upload_controller"
3
+ export const uploaders = []
3
4
 
4
5
  const eventFamily = 'dnd-uploads'
5
6
 
@@ -40,3 +41,9 @@ export class UploadQueueProcessor {
40
41
  return dispatchEvent(this.form, `${eventFamily}:${name}`, { detail })
41
42
  }
42
43
  }
44
+
45
+ export function createUploader(input, file) {
46
+ // your form needs the file_field direct_upload: true, which
47
+ // provides data-direct-upload-url
48
+ uploaders.push( new DragAndDropUploadController(input, file) )
49
+ }
@@ -1,8 +1,23 @@
1
- <label id="active-storage-drag-zone">
1
+ <label class="asdndzone" id="asdndz-<%= form.object_name %>_<%= method %>" data-dnd-input-id="<%= form.object_name %>_<%= method %>">
2
2
  <%= tag_value %>
3
- <div id="active-storage-drag-zone__icon-container"></div>
4
- <%= form.file_field method, multiple: true, direct_upload: true, style: 'display:none;', data: { dnd: true, dnd_zone_id: 'active-storage-drag-zone', icon_container_id: 'active-storage-drag-zone__icon-container' } %>
3
+ <div id="asdndz-<%= form.object_name %>_<%= method %>__icon-container"></div>
4
+ <%= form.file_field method,
5
+ multiple: true,
6
+ direct_upload: true,
7
+ style: 'display:none;',
8
+ data: {
9
+ dnd: true,
10
+ dnd_zone_id: "asdndz-#{form.object_name}_#{method}",
11
+ icon_container_id: "asdndz-#{form.object_name}_#{method}__icon-container"
12
+ } %>
5
13
  <% attachments.each_with_index do |blob,idx| %>
6
- <%= form.hidden_field method, value: blob.signed_id, :multiple => true, data: { direct_upload_id: idx, uploaded_file_name: blob.filename } %>
14
+ <%= form.hidden_field method,
15
+ value: blob.signed_id,
16
+ :multiple => true,
17
+ data: {
18
+ direct_upload_id: idx,
19
+ uploaded_file_name: blob.filename,
20
+ icon_container_id: "asdndz-#{form.object_name}_#{method}__icon-container"
21
+ } %>
7
22
  <% end %>
8
23
  </label>
@@ -1,3 +1,3 @@
1
1
  module ActiveStorageDragAndDrop
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_storage_drag_and_drop
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dave O'Keeffe
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2018-07-17 00:00:00.000000000 Z
12
+ date: 2018-08-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -92,7 +92,6 @@ files:
92
92
  - app/javascript/active_storage_drag_and_drop/index.js
93
93
  - app/javascript/active_storage_drag_and_drop/ujs.js
94
94
  - app/javascript/active_storage_drag_and_drop/upload_queue_processor.js
95
- - app/javascript/active_storage_drag_and_drop/uploader_input.js
96
95
  - app/views/application/_active_storage_drag_and_drop.html.erb
97
96
  - bin/console
98
97
  - bin/setup
@@ -1,66 +0,0 @@
1
- import { dispatchEvent } from './helpers'
2
- import { uploaders, createUploader } from "./direct_upload_controller"
3
- const eventFamily = 'dnd-upload'
4
-
5
- export class UploaderInput {
6
- constructor(input) {
7
- this.input = input
8
- this.start(input)
9
- }
10
-
11
- start(input) {
12
- console.log('Binding input:change to createUploader')
13
- const form = input.closest('form')
14
- const dropZoneId = input.dataset.dndZoneId
15
- const dropZone = document.getElementById(dropZoneId)
16
- const iconContainerId = input.dataset.iconContainerId
17
- const iconContainer = document.getElementById(input.dataset.iconContainerId)
18
-
19
- // bind Change events on original file input
20
- input.addEventListener('change', (event) => {
21
- console.log('input:change')
22
- Array.from(input.files).forEach(file => createUploader(input, file))
23
- input.value = null
24
- })
25
-
26
- // bind DND events to onDrop
27
- dropZone.addEventListener('dragover', function(e){e.preventDefault()})
28
- dropZone.addEventListener('drop', function(e){
29
- e.preventDefault()
30
- const files = e.dataTransfer.files
31
- Array.from(files).forEach(file => createUploader(input, file))
32
- })
33
-
34
- // add delete-file support for all data-dnd-delete elements in our dropZone
35
- // add 'click here to upload' support for all inputs/dnd-zone groupings
36
- const clickable_input = input
37
- dropZone.addEventListener('click', event => {
38
- var target = event.target;
39
- if( target.dataset.dndDelete == 'true' && target.hasAttribute('data-direct-upload-id') ) {
40
- event.preventDefault();
41
- console.log("Delete Uploaded File: " + target.dataset.directUploadId)
42
- document.querySelectorAll('[data-direct-upload-id="'+target.dataset.directUploadId+'"]').forEach(element => {
43
- element.remove()
44
- })
45
- for(var i=0;i<uploaders.length;i++) {
46
- if(uploaders[i].upload.id == target.dataset.directUploadId) {
47
- uploaders.splice( i, 1 )
48
- break
49
- }
50
- }
51
- }
52
- })
53
-
54
- // Handle pre-existing uploaded files with the same input name
55
- form.querySelectorAll("input[name='" + input.name + "'][type='hidden'][data-direct-upload-id][data-uploaded-file-name]").forEach( uploadedFile => {
56
- const dataset = uploadedFile.dataset
57
- let detail = {
58
- id: dataset.directUploadId,
59
- fileName: dataset.uploadedFileName,
60
- iconContainer: iconContainer
61
- }
62
- dispatchEvent(uploadedFile, `${eventFamily}:placeholder`, { detail })
63
- })
64
-
65
- }
66
- }