active_storage_drag_and_drop 0.3.0 → 0.3.1

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: 0ebcab98ea53affc1a17f933dfac48d5ca1d944c0688fa525bbbca086f0739cc
4
- data.tar.gz: 4811dbc8de9aa33a4af730494f642fb4806ec6f47b5b4f1287034307320d972f
3
+ metadata.gz: 77831f698945cda19e6fcfe3a3dac981cb187c8132828626e2b3885f9b9f26ab
4
+ data.tar.gz: e1e23d401dff7989da878494ddc812d41911a0da8598e5f56ecc708ceaebfb53
5
5
  SHA512:
6
- metadata.gz: c103992d6ef02780e08da15c8b1e0482dd32e0d392cb9560b311571877c3060b94db21a2e6a0243f885a5692aeffd8a171666ee1027d67469a9ad86ca94c38ec
7
- data.tar.gz: e1d48cc0161ba91ecd7b8937d13a14dcc5e8a3b5905b55f9edfc2a1116c64195364c320f360524124de312c0544589ccdb32fc183ecdec2829bcd4180d1984e9
6
+ metadata.gz: 10f40a62e0dcefe74574a63bb204b76c4ae769f2f001599b508fa33949c05e653ed53cc5efc93eaf071d3b2d30ed5a15f40ebca2c12435522a0476c60dc919a4
7
+ data.tar.gz: b528ac93389424f60d5862b2c33986ee940c464e1d8e2c9ffd29630dc34da8d7d3d5fefe0ccd7183b71b25c96e782a19a50201762b5292be96dc7336bc7c2f9f
@@ -0,0 +1,19 @@
1
+ AllCops:
2
+ Exclude:
3
+ - 'app/assets/havascripts/active_storage_drag_and_drop.js'
4
+ - 'lib/active_storage_drag_and_drop/version.rb'
5
+
6
+ Rails:
7
+ Enabled: true
8
+
9
+ Style/Documentation:
10
+ Enabled: false
11
+
12
+ Style/ClassAndModuleChildren:
13
+ Enabled: false
14
+
15
+ Style/BracesAroundHashParameters:
16
+ EnforcedStyle: context_dependent
17
+
18
+ Metrics/LineLength:
19
+ Max: 99
data/Gemfile CHANGED
@@ -1,6 +1,6 @@
1
- source "https://rubygems.org"
1
+ source 'https://rubygems.org'
2
2
 
3
- git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
3
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
4
4
 
5
5
  # Specify your gem's dependencies in active_storage_drag_and_drop.gemspec
6
6
  gemspec
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- active_storage_drag_and_drop (0.3.0)
4
+ active_storage_drag_and_drop (0.3.1)
5
5
  rails (~> 5.2)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -46,6 +46,10 @@ Call the method `drag_and_drop_file_field` on your model's form:
46
46
  = form.submit
47
47
  ```
48
48
  The first parameter is a symbol representing the method of the ActiveStorage attachment and an optional second parameter sets the the text on the drag and drop zone.
49
+ Options for the nested file field can be passed as key value pairs:
50
+ ```ruby
51
+ form.drag_and_drop_file_field :images, accept: 'image/png, image/jpeg, image/gif, image/tiff'
52
+ ```
49
53
  In your controller you can permit the params like so:
50
54
  ```ruby
51
55
  params.permit(:message).require(images: [])
@@ -64,7 +68,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
64
68
 
65
69
  ## Contributing
66
70
 
67
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/active_storage_drag_and_drop. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
71
+ Bug reports and pull requests are welcome on GitHub at https://github.com/marinosoftware/active_storage_drag_and_drop. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
68
72
 
69
73
  ## License
70
74
 
@@ -72,4 +76,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
72
76
 
73
77
  ## Code of Conduct
74
78
 
75
- Everyone interacting in the ActiveStorageDragAndDrop project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/active_storage_drag_and_drop/blob/master/CODE_OF_CONDUCT.md).
79
+ Everyone interacting in the ActiveStorageDragAndDrop project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/marinosoftware/active_storage_drag_and_drop/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile CHANGED
@@ -1,10 +1,10 @@
1
- require "bundler/gem_tasks"
2
- require "rake/testtask"
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
3
 
4
4
  Rake::TestTask.new(:test) do |t|
5
- t.libs << "test"
6
- t.libs << "lib"
7
- t.test_files = FileList["test/**/*_test.rb"]
5
+ t.libs << 'test'
6
+ t.libs << 'lib'
7
+ t.test_files = FileList['test/**/*_test.rb']
8
8
  end
9
9
 
10
- task :default => :test
10
+ task default: :test
@@ -1,37 +1,36 @@
1
-
2
- lib = File.expand_path("../lib", __FILE__)
1
+ lib = File.expand_path('lib', __dir__)
3
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require "active_storage_drag_and_drop/version"
3
+ require 'active_storage_drag_and_drop/version'
5
4
 
6
5
  Gem::Specification.new do |spec|
7
- spec.name = "active_storage_drag_and_drop"
6
+ spec.name = 'active_storage_drag_and_drop'
8
7
  spec.version = ActiveStorageDragAndDrop::VERSION
9
- spec.authors = ["Dave O'Keeffe", "Ian Grant"]
10
- spec.email = ["ian.grant@marinosoftware.com"]
8
+ spec.authors = ["Dave O'Keeffe", 'Ian Grant']
9
+ spec.email = ['ian.grant@marinosoftware.com']
11
10
 
12
- spec.summary = %q{Provides js drag and drop file upload functionality for active storage.}
13
- spec.description = %q{Provides a form helper to make it easy to make drag and drop file upload fields that work with Rails' Active Storage.}
14
- spec.homepage = "https://github.com/marinosoftware/active_storage_drag_and_drop"
15
- spec.license = "MIT"
11
+ spec.summary = 'Provides js drag and drop file upload functionality for active storage.'
12
+ spec.description = 'Provides a form helper to make it easy to make drag and drop file upload'\
13
+ "fields that work with Rails' Active Storage."
14
+ spec.homepage = 'https://github.com/marinosoftware/active_storage_drag_and_drop'
15
+ spec.license = 'MIT'
16
16
 
17
17
  # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
18
  # to allow pushing to a single host or delete this section to allow pushing to any host.
19
- if spec.respond_to?(:metadata)
20
- spec.metadata["source_code_uri"] = "https://github.com/marinosoftware/active_storage_drag_and_drop"
21
- else
22
- raise "RubyGems 2.0 or newer is required to protect against " \
23
- "public gem pushes."
19
+ unless spec.respond_to?(:metadata)
20
+ raise 'RubyGems 2.0 or newer is required to protect against public gem pushes.'
24
21
  end
25
22
 
26
- spec.files = `git ls-files -z`.split("\x0").reject do |f|
23
+ spec.metadata['source_code_uri'] = 'https://github.com/marinosoftware/active_storage_drag_and_drop'
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
27
26
  f.match(%r{^(test|spec|features)/})
28
27
  end
29
- spec.bindir = "exe"
28
+ spec.bindir = 'exe'
30
29
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
31
- spec.require_paths = ["lib"]
30
+ spec.require_paths = ['lib']
32
31
 
33
- spec.add_development_dependency "bundler", "~> 1.16"
34
- spec.add_development_dependency "rake", "~> 10.0"
35
- spec.add_development_dependency "minitest", "~> 5.0"
36
- spec.add_dependency "rails", '~> 5.2'
32
+ spec.add_development_dependency 'bundler', '~> 1.16'
33
+ spec.add_development_dependency 'minitest', '~> 5.0'
34
+ spec.add_development_dependency 'rake', '~> 10.0'
35
+ spec.add_dependency 'rails', '~> 5.2'
37
36
  end
@@ -1 +1,171 @@
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
+ (function webpackUniversalModuleDefinition(root, factory) {
2
+ if(typeof exports === 'object' && typeof module === 'object')
3
+ module.exports = factory();
4
+ else if(typeof define === 'function' && define.amd)
5
+ define([], factory);
6
+ else if(typeof exports === 'object')
7
+ exports["ActiveStorage"] = factory();
8
+ else
9
+ root["ActiveStorage"] = factory();
10
+ })(window, function() {
11
+ return /******/ (function(modules) { // webpackBootstrap
12
+ /******/ // The module cache
13
+ /******/ var installedModules = {};
14
+ /******/
15
+ /******/ // The require function
16
+ /******/ function __webpack_require__(moduleId) {
17
+ /******/
18
+ /******/ // Check if module is in cache
19
+ /******/ if(installedModules[moduleId]) {
20
+ /******/ return installedModules[moduleId].exports;
21
+ /******/ }
22
+ /******/ // Create a new module (and put it into the cache)
23
+ /******/ var module = installedModules[moduleId] = {
24
+ /******/ i: moduleId,
25
+ /******/ l: false,
26
+ /******/ exports: {}
27
+ /******/ };
28
+ /******/
29
+ /******/ // Execute the module function
30
+ /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
31
+ /******/
32
+ /******/ // Flag the module as loaded
33
+ /******/ module.l = true;
34
+ /******/
35
+ /******/ // Return the exports of the module
36
+ /******/ return module.exports;
37
+ /******/ }
38
+ /******/
39
+ /******/
40
+ /******/ // expose the modules object (__webpack_modules__)
41
+ /******/ __webpack_require__.m = modules;
42
+ /******/
43
+ /******/ // expose the module cache
44
+ /******/ __webpack_require__.c = installedModules;
45
+ /******/
46
+ /******/ // define getter function for harmony exports
47
+ /******/ __webpack_require__.d = function(exports, name, getter) {
48
+ /******/ if(!__webpack_require__.o(exports, name)) {
49
+ /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
50
+ /******/ }
51
+ /******/ };
52
+ /******/
53
+ /******/ // define __esModule on exports
54
+ /******/ __webpack_require__.r = function(exports) {
55
+ /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
56
+ /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
57
+ /******/ }
58
+ /******/ Object.defineProperty(exports, '__esModule', { value: true });
59
+ /******/ };
60
+ /******/
61
+ /******/ // create a fake namespace object
62
+ /******/ // mode & 1: value is a module id, require it
63
+ /******/ // mode & 2: merge all properties of value into the ns
64
+ /******/ // mode & 4: return value when already ns object
65
+ /******/ // mode & 8|1: behave like require
66
+ /******/ __webpack_require__.t = function(value, mode) {
67
+ /******/ if(mode & 1) value = __webpack_require__(value);
68
+ /******/ if(mode & 8) return value;
69
+ /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
70
+ /******/ var ns = Object.create(null);
71
+ /******/ __webpack_require__.r(ns);
72
+ /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
73
+ /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
74
+ /******/ return ns;
75
+ /******/ };
76
+ /******/
77
+ /******/ // getDefaultExport function for compatibility with non-harmony modules
78
+ /******/ __webpack_require__.n = function(module) {
79
+ /******/ var getter = module && module.__esModule ?
80
+ /******/ function getDefault() { return module['default']; } :
81
+ /******/ function getModuleExports() { return module; };
82
+ /******/ __webpack_require__.d(getter, 'a', getter);
83
+ /******/ return getter;
84
+ /******/ };
85
+ /******/
86
+ /******/ // Object.prototype.hasOwnProperty.call
87
+ /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
88
+ /******/
89
+ /******/ // __webpack_public_path__
90
+ /******/ __webpack_require__.p = "";
91
+ /******/
92
+ /******/
93
+ /******/ // Load entry module and return exports
94
+ /******/ return __webpack_require__(__webpack_require__.s = "./app/javascript/active_storage_drag_and_drop/index.js");
95
+ /******/ })
96
+ /************************************************************************/
97
+ /******/ ({
98
+
99
+ /***/ "./app/javascript/active_storage_drag_and_drop/direct_upload_controller.js":
100
+ /*!*********************************************************************************!*\
101
+ !*** ./app/javascript/active_storage_drag_and_drop/direct_upload_controller.js ***!
102
+ \*********************************************************************************/
103
+ /*! exports provided: DragAndDropUploadController */
104
+ /***/ (function(module, __webpack_exports__, __webpack_require__) {
105
+
106
+ "use strict";
107
+ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"DragAndDropUploadController\", function() { return DragAndDropUploadController; });\n/* harmony import */ var _helpers__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./helpers */ \"./app/javascript/active_storage_drag_and_drop/helpers.js\");\n/* harmony import */ var activestorage__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! activestorage */ \"./node_modules/activestorage/app/assets/javascripts/activestorage.js\");\n/* harmony import */ var activestorage__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(activestorage__WEBPACK_IMPORTED_MODULE_1__);\n\n\nconst eventFamily = 'dnd-upload';\n\nclass DragAndDropUploadController {\n constructor(input, file) {\n this.input = input;\n this.form = input.closest('form');\n this.url = this.input.dataset.directUploadUrl;\n this.iconContainer = document.getElementById(this.input.dataset.iconContainerId);\n this.file = file;\n this.upload = new activestorage__WEBPACK_IMPORTED_MODULE_1__[\"DirectUpload\"](this.file, this.url, this);\n this.dispatch(\"initialize\");\n }\n\n start(callback) {\n this.upload.create((error, blob) => {\n if (error) {\n // Handle the error\n console.log(\"Upload Error:\");\n console.log(error);\n this.dispatchError(error);\n callback(error);\n } else {\n console.log(\"Upload SUCCESS!!\");\n // // Add an appropriately-named hidden input to the form with a\n // // value of blob.signed_id so that the blob ids will be\n // // transmitted in the normal upload flow\n const hiddenField = document.createElement('input');\n hiddenField.setAttribute(\"type\", \"hidden\");\n hiddenField.setAttribute(\"value\", blob.signed_id);\n hiddenField.name = this.input.name;\n hiddenField.setAttribute('data-direct-upload-id', this.upload.id);\n this.form.appendChild(hiddenField);\n this.dispatch(\"end\");\n callback(error);\n }\n });\n }\n\n dispatch(name, detail = {}) {\n detail.file = this.file;\n detail.id = this.upload.id;\n detail.iconContainer = this.iconContainer;\n return Object(_helpers__WEBPACK_IMPORTED_MODULE_0__[\"dispatchEvent\"])(this.input, `${eventFamily}:${name}`, { detail });\n }\n\n dispatchError(error) {\n const event = this.dispatch(\"error\", { error });\n if (!event.defaultPrevented) {\n alert(error);\n }\n }\n\n directUploadWillCreateBlobWithXHR(xhr) {\n this.dispatch(\"before-blob-request\", { xhr });\n }\n // directUploadWillStoreFileWithXHR\n directUploadWillStoreFileWithXHR(xhr) {\n this.dispatch(\"before-storage-request\", { xhr });\n xhr.upload.addEventListener(\"progress\", event => this.uploadRequestDidProgress(event));\n }\n\n uploadRequestDidProgress(event) {\n const progress = event.loaded / event.total * 100;\n if (progress) {\n this.dispatch(\"progress\", { progress });\n }\n }\n\n}\n\n//# sourceURL=webpack://ActiveStorage/./app/javascript/active_storage_drag_and_drop/direct_upload_controller.js?");
108
+
109
+ /***/ }),
110
+
111
+ /***/ "./app/javascript/active_storage_drag_and_drop/helpers.js":
112
+ /*!****************************************************************!*\
113
+ !*** ./app/javascript/active_storage_drag_and_drop/helpers.js ***!
114
+ \****************************************************************/
115
+ /*! exports provided: dispatchEvent, hasClassnameInHeirarchy, getClassnameFromHeirarchy */
116
+ /***/ (function(module, __webpack_exports__, __webpack_require__) {
117
+
118
+ "use strict";
119
+ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"dispatchEvent\", function() { return dispatchEvent; });\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"hasClassnameInHeirarchy\", function() { return hasClassnameInHeirarchy; });\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"getClassnameFromHeirarchy\", function() { return getClassnameFromHeirarchy; });\n\nfunction dispatchEvent(element, type, eventInit = {}) {\n const { bubbles, cancelable, detail } = eventInit;\n const event = document.createEvent(\"Event\");\n event.initEvent(type, bubbles || true, cancelable || true);\n event.detail = detail || {};\n element.dispatchEvent(event);\n return event;\n}\n\nfunction hasClassnameInHeirarchy(element, classname) {\n if (element && element.classList) {\n if (element.classList.contains(classname)) {\n return true;\n } else {\n return hasClassnameInHeirarchy(element.parentNode, classname);\n }\n } else {\n return false;\n }\n}\n\nfunction getClassnameFromHeirarchy(element, classname) {\n if (element && element.classList) {\n if (element.classList.contains(classname)) {\n return element;\n } else {\n return getClassnameFromHeirarchy(element.parentNode, classname);\n }\n } else {\n return null;\n }\n}\n\n//export function disable(input) {\n// input.disabled = true\n//}\n\n//export function enable(input) {\n// input.disabled = false\n//}\n\n//export function toArray(value) {\n// if (Array.isArray(value)) {\n// return value\n// } else if (Array.from) {\n// return Array.from(value)\n// } else {\n// return [].slice.call(value)\n// }\n//}\n\n//export function findElements(root, selector) {\n// if (typeof root == \"string\") {\n// selector = root\n// root = document\n// }\n// const elements = root.querySelectorAll(selector)\n// return toArray(elements)\n//}\n\n//export function findElement(root, selector) {\n// if (typeof root == \"string\") {\n// selector = root\n// root = document\n// }\n// return root.querySelector(selector)\n//}\n\n//# sourceURL=webpack://ActiveStorage/./app/javascript/active_storage_drag_and_drop/helpers.js?");
120
+
121
+ /***/ }),
122
+
123
+ /***/ "./app/javascript/active_storage_drag_and_drop/index.js":
124
+ /*!**************************************************************!*\
125
+ !*** ./app/javascript/active_storage_drag_and_drop/index.js ***!
126
+ \**************************************************************/
127
+ /*! exports provided: start */
128
+ /***/ (function(module, __webpack_exports__, __webpack_require__) {
129
+
130
+ "use strict";
131
+ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony import */ var _ujs__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./ujs */ \"./app/javascript/active_storage_drag_and_drop/ujs.js\");\n/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, \"start\", function() { return _ujs__WEBPACK_IMPORTED_MODULE_0__[\"start\"]; });\n\n\n\n\n\nfunction autostart() {\n Object(_ujs__WEBPACK_IMPORTED_MODULE_0__[\"start\"])();\n}\n\nsetTimeout(autostart, 1);\n\n//----------------------------------------------------------------------------------------------------\n// UI Events - this code is completely outside the draganddrop lib - it's just reacting to events\n//----------------------------------------------------------------------------------------------------\nvar fileUploadUIPainter = function (iconContainer, id, filename, complete) {\n // the only rule here is that all root level elements must have the data: { direct_upload_id: [id] } attribute ala: 'data-direct-upload-id=\"${id}\"'\n var cname = complete ? 'complete' : 'pending';\n var progress = complete ? 100 : 0;\n iconContainer.insertAdjacentHTML(\"beforeend\", `\n <div id=\"direct-upload-${id}\" class=\"direct-upload direct-upload--${cname}\" data-direct-upload-id=\"${id}\">\n <div id=\"direct-upload-progress-${id}\" class=\"direct-upload__progress\" style=\"width: ${progress}%\"></div>\n <span class=\"direct-upload__filename\">${filename}</span>\n </div>\n <a href='remove' class='direct-upload__remove' data-dnd-delete='true' data-direct-upload-id=\"${id}\">x</a>\n `);\n};\n\naddEventListener(\"dnd-uploads:start\", event => {\n console.log(\"dnd-uploads:start\");\n});\naddEventListener(\"dnd-uploads:end\", event => {\n console.log(\"dnd-uploads:end\");\n});\n\naddEventListener(\"dnd-upload:initialize\", event => {\n console.log(\"dnd-upload:initialize\");\n const { target, detail } = event;\n const { id, file, iconContainer } = detail;\n fileUploadUIPainter(iconContainer, id, file.name, false);\n});\n\naddEventListener(\"dnd-upload:placeholder\", event => {\n console.log(\"dnd-upload:placeholder\");\n const { target, detail } = event;\n const { id, fileName, iconContainer } = detail;\n fileUploadUIPainter(iconContainer, id, fileName, true);\n});\n\naddEventListener(\"dnd-upload:start\", event => {\n console.log(\"dnd-upload:start\");\n const { id } = event.detail;\n const element = document.getElementById(`direct-upload-${id}`);\n element.classList.remove(\"direct-upload--pending\");\n});\n\naddEventListener(\"dnd-upload:progress\", event => {\n console.log(\"dnd-upload:progress\");\n const { id, progress } = event.detail;\n const progressElement = document.getElementById(`direct-upload-progress-${id}`);\n progressElement.style.width = `${progress}%`;\n});\n\naddEventListener(\"dnd-upload:error\", event => {\n console.log(\"dnd-upload:error\");\n event.preventDefault();\n const { id, error } = event.detail;\n const element = document.getElementById(`direct-upload-${id}`);\n element.classList.add(\"direct-upload--error\");\n element.setAttribute(\"title\", error);\n});\n\naddEventListener(\"dnd-upload:end\", event => {\n console.log(\"dnd-upload:end\");\n const { id } = event.detail;\n const element = document.getElementById(`direct-upload-${id}`);\n element.classList.remove(\"direct-upload--pending\");\n element.classList.add(\"direct-upload--complete\");\n});\n\n//# sourceURL=webpack://ActiveStorage/./app/javascript/active_storage_drag_and_drop/index.js?");
132
+
133
+ /***/ }),
134
+
135
+ /***/ "./app/javascript/active_storage_drag_and_drop/ujs.js":
136
+ /*!************************************************************!*\
137
+ !*** ./app/javascript/active_storage_drag_and_drop/ujs.js ***!
138
+ \************************************************************/
139
+ /*! exports provided: start */
140
+ /***/ (function(module, __webpack_exports__, __webpack_require__) {
141
+
142
+ "use strict";
143
+ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"start\", function() { return start; });\n/* harmony import */ var _upload_queue_processor__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./upload_queue_processor */ \"./app/javascript/active_storage_drag_and_drop/upload_queue_processor.js\");\n/* harmony import */ var _helpers__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./helpers */ \"./app/javascript/active_storage_drag_and_drop/helpers.js\");\n\n\n\nlet started = false;\nlet formSubmitted = false;\n\nfunction didSubmitForm(event) {\n handleFormSubmissionEvent(event);\n}\n\nfunction didSubmitRemoteElement(event) {\n if (event.target.tagName == \"FORM\") {\n handleFormSubmissionEvent(event);\n }\n}\n\nfunction handleFormSubmissionEvent(event) {\n if (formSubmitted) {\n return;\n }\n formSubmitted = true;\n const form = event.target;\n const next_upload = new _upload_queue_processor__WEBPACK_IMPORTED_MODULE_0__[\"UploadQueueProcessor\"](form);\n // if the upload processor has no dnd file inputs, then we let the event happen naturally\n // if it DOES have dnd file inputs, then we have to process our queue first and then submit the form\n if (next_upload.current_uploaders.length > 0) {\n event.preventDefault();\n // inputs.forEach(disable)\n next_upload.start(error => {\n if (error) {\n // inputs.forEach(enable)\n } else {\n form.submit();\n // The original ActiveStorage DirectUpload system did this action using\n // input.click(), but doing that either makes the form submission event\n // happen multiple times, or the browser seems to block the input.click()\n // event completely, because it's not a trusted 'as a result of a mouse\n // click' event.\n // HOWEVER\n // form.submit() doesn't trigger to any UJS submission events. This\n // results in remote forms being submitted locally whenever there's a\n // dnd file to upload. Instead we use Rails.fire(element, 'submit')\n // Rails.fire(form, 'submit')\n }\n });\n }\n}\n\nfunction addAttachedFileIcons() {\n console.log('checking for already attached files');\n document.querySelectorAll(\"input[type='hidden'][data-direct-upload-id][data-uploaded-file-name]\").forEach(uploadedFile => {\n console.log('addAttachedFileIcon!');\n const dataset = uploadedFile.dataset;\n let iconContainer = document.getElementById(dataset.iconContainerId);\n let detail = {\n id: dataset.directUploadId,\n fileName: dataset.uploadedFileName,\n iconContainer: iconContainer\n };\n _helpers__WEBPACK_IMPORTED_MODULE_1__[\"dispatchEvent\"](uploadedFile, `dnd-upload:placeholder`, { detail });\n });\n}\n\nfunction start() {\n if (started) {\n return;\n }\n started = true;\n document.addEventListener(\"submit\", didSubmitForm);\n document.addEventListener(\"ajax:before\", didSubmitRemoteElement);\n\n // input[type=file][data-dnd=true]\n document.addEventListener(\"change\", event => {\n console.log('document:change');\n if (event.target.type == 'file' && event.target.dataset.dnd == 'true') {\n const input = event.target;\n console.log(\"input[type=file][data-dnd=true]:change\");\n Array.from(input.files).forEach(file => Object(_upload_queue_processor__WEBPACK_IMPORTED_MODULE_0__[\"createUploader\"])(input, file));\n input.value = null;\n }\n });\n document.addEventListener(\"dragover\", event => {\n console.log('document:dragover');\n if (_helpers__WEBPACK_IMPORTED_MODULE_1__[\"hasClassnameInHeirarchy\"](event.target, 'asdndzone')) {\n event.preventDefault();\n }\n });\n document.addEventListener(\"drop\", event => {\n console.log('document:drop');\n let asdndz = _helpers__WEBPACK_IMPORTED_MODULE_1__[\"getClassnameFromHeirarchy\"](event.target, 'asdndzone');\n if (asdndz) {\n event.preventDefault();\n console.log(\".asdndzone:drop\");\n // get the input associated with this dndz\n const input = document.getElementById(asdndz.dataset.dndInputId);\n Array.from(event.dataTransfer.files).forEach(file => Object(_upload_queue_processor__WEBPACK_IMPORTED_MODULE_0__[\"createUploader\"])(input, file));\n }\n });\n document.addEventListener(\"click\", event => {\n if (event.target.dataset.dndDelete == 'true' && event.target.hasAttribute('data-direct-upload-id')) {\n event.preventDefault();\n console.log(\"[data-dnd-delete=true][data-direct-upload-id]:click\");\n document.querySelectorAll('[data-direct-upload-id=\"' + event.target.dataset.directUploadId + '\"]').forEach(element => {\n element.remove();\n });\n for (var i = 0; i < _upload_queue_processor__WEBPACK_IMPORTED_MODULE_0__[\"uploaders\"].length; i++) {\n if (_upload_queue_processor__WEBPACK_IMPORTED_MODULE_0__[\"uploaders\"][i].upload.id == event.target.dataset.directUploadId) {\n _upload_queue_processor__WEBPACK_IMPORTED_MODULE_0__[\"uploaders\"].splice(i, 1);\n break;\n }\n }\n }\n });\n addEventListener(\"turbolinks:load\", addAttachedFileIcons);\n addEventListener(\"load\", addAttachedFileIcons);\n}\n\n//# sourceURL=webpack://ActiveStorage/./app/javascript/active_storage_drag_and_drop/ujs.js?");
144
+
145
+ /***/ }),
146
+
147
+ /***/ "./app/javascript/active_storage_drag_and_drop/upload_queue_processor.js":
148
+ /*!*******************************************************************************!*\
149
+ !*** ./app/javascript/active_storage_drag_and_drop/upload_queue_processor.js ***!
150
+ \*******************************************************************************/
151
+ /*! exports provided: uploaders, UploadQueueProcessor, createUploader */
152
+ /***/ (function(module, __webpack_exports__, __webpack_require__) {
153
+
154
+ "use strict";
155
+ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"uploaders\", function() { return uploaders; });\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"UploadQueueProcessor\", function() { return UploadQueueProcessor; });\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"createUploader\", function() { return createUploader; });\n/* harmony import */ var _helpers__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./helpers */ \"./app/javascript/active_storage_drag_and_drop/helpers.js\");\n/* harmony import */ var _direct_upload_controller__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./direct_upload_controller */ \"./app/javascript/active_storage_drag_and_drop/direct_upload_controller.js\");\n\n\nconst uploaders = [];\n\nconst eventFamily = 'dnd-uploads';\n\nclass UploadQueueProcessor {\n constructor(form) {\n this.form = form;\n this.current_uploaders = [];\n uploaders.forEach(uploader => {\n if (form == uploader.form) {\n this.current_uploaders.push(uploader);\n }\n });\n }\n\n start(callback) {\n const startNextUploader = () => {\n const nextUploader = this.current_uploaders.shift();\n if (nextUploader) {\n nextUploader.start(error => {\n if (error) {\n callback(error);\n this.dispatch(\"end\");\n } else {\n startNextUploader();\n }\n });\n } else {\n callback();\n this.dispatch(\"end\");\n }\n };\n\n this.dispatch(\"start\");\n startNextUploader();\n }\n\n dispatch(name, detail = {}) {\n return Object(_helpers__WEBPACK_IMPORTED_MODULE_0__[\"dispatchEvent\"])(this.form, `${eventFamily}:${name}`, { detail });\n }\n}\n\nfunction createUploader(input, file) {\n // your form needs the file_field direct_upload: true, which\n // provides data-direct-upload-url\n console.log(input.accept === '');\n if (input.accept === '' || input.accept.split(', ').includes(file.type)) {\n uploaders.push(new _direct_upload_controller__WEBPACK_IMPORTED_MODULE_1__[\"DragAndDropUploadController\"](input, file));\n } else {\n const error = Error('Invalid filetype');\n const event = Object(_helpers__WEBPACK_IMPORTED_MODULE_0__[\"dispatchEvent\"])(input, `${eventFamily}:error`, { error });\n if (!event.defaultPrevented) {\n alert(error);\n }\n return event;\n }\n}\n\n//# sourceURL=webpack://ActiveStorage/./app/javascript/active_storage_drag_and_drop/upload_queue_processor.js?");
156
+
157
+ /***/ }),
158
+
159
+ /***/ "./node_modules/activestorage/app/assets/javascripts/activestorage.js":
160
+ /*!****************************************************************************!*\
161
+ !*** ./node_modules/activestorage/app/assets/javascripts/activestorage.js ***!
162
+ \****************************************************************************/
163
+ /*! no static exports found */
164
+ /***/ (function(module, exports, __webpack_require__) {
165
+
166
+ eval("!function(t,e){ true?module.exports=e():undefined}(this,function(){return 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){var e=a(document.head,'meta[name=\"'+t+'\"]');if(e)return e.getAttribute(\"content\")}function i(t,e){return\"string\"==typeof t&&(e=t,t=document),o(t.querySelectorAll(e))}function a(t,e){return\"string\"==typeof t&&(e=t,t=document),t.querySelector(e)}function u(t,e){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},n=t.disabled,i=r.bubbles,a=r.cancelable,u=r.detail,o=document.createEvent(\"Event\");o.initEvent(e,i||!0,a||!0),o.detail=u||{};try{t.disabled=!1,t.dispatchEvent(o)}finally{t.disabled=n}return o}function o(t){return Array.isArray(t)?t:Array.from?Array.from(t):[].slice.call(t)}e.d=n,e.c=i,e.b=a,e.a=u,e.e=o},function(t,e,r){\"use strict\";function n(t,e){if(!(t instanceof e))throw new TypeError(\"Cannot call a class as a function\")}function i(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 c});var a=r(6),u=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}}(),f=0,c=function(){function t(e,r,i){n(this,t),this.id=++f,this.file=e,this.url=r,this.delegate=i}return s(t,[{key:\"create\",value:function(t){var e=this;a.a.create(this.file,function(r,n){if(r)return void t(r);var a=new u.a(e.file,n,e.url);i(e.delegate,\"directUploadWillCreateBlobWithXHR\",a.xhr),a.create(function(r){if(r)t(r);else{var n=new o.a(a);i(e.delegate,\"directUploadWillStoreFileWithXHR\",n.xhr),n.create(function(e){e?t(e):t(null,a.toJSON())})}})})}}]),t}()},function(t,e,r){\"use strict\";function n(){window.ActiveStorage&&Object(i.a)()}Object.defineProperty(e,\"__esModule\",{value:!0});var i=r(3),a=r(1);r.d(e,\"start\",function(){return i.a}),r.d(e,\"DirectUpload\",function(){return a.a}),setTimeout(n,1)},function(t,e,r){\"use strict\";function n(){d||(d=!0,document.addEventListener(\"submit\",i),document.addEventListener(\"ajax:before\",a))}function i(t){u(t)}function a(t){\"FORM\"==t.target.tagName&&u(t)}function u(t){var e=t.target;if(e.hasAttribute(l))return void t.preventDefault();var r=new c.a(e),n=r.inputs;n.length&&(t.preventDefault(),e.setAttribute(l,\"\"),n.forEach(s),r.start(function(t){e.removeAttribute(l),t?n.forEach(f):o(e)}))}function o(t){var e=Object(h.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\"),e.type=\"submit\",e.style.display=\"none\",t.appendChild(e),e.click(),t.removeChild(e)}function s(t){t.disabled=!0}function f(t){t.disabled=!1}e.a=n;var c=r(4),h=r(0),l=\"data-direct-uploads-processing\",d=!1},function(t,e,r){\"use strict\";function n(t,e){if(!(t instanceof e))throw new TypeError(\"Cannot call a class as a function\")}r.d(e,\"a\",function(){return s});var i=r(5),a=r(0),u=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){n(this,t),this.form=e,this.inputs=Object(a.c)(e,o).filter(function(t){return t.files.length})}return u(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(a.e)(e.files).forEach(function(r){var n=new i.a(e,r);t.push(n)})}),t}},{key:\"dispatch\",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return Object(a.a)(this.form,\"direct-uploads:\"+t,{detail:e})}}]),t}()},function(t,e,r){\"use strict\";function n(t,e){if(!(t instanceof e))throw new TypeError(\"Cannot call a class as a function\")}r.d(e,\"a\",function(){return o});var i=r(1),a=r(0),u=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){n(this,t),this.input=e,this.file=r,this.directUpload=new i.a(this.file,this.url,this),this.dispatch(\"initialize\")}return u(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(a.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\";function n(t,e){if(!(t instanceof e))throw new TypeError(\"Cannot call a class as a function\")}r.d(e,\"a\",function(){return s});var i=r(7),a=r.n(i),u=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){n(this,t),this.file=e,this.chunkSize=2097152,this.chunkCount=Math.ceil(this.file.size/this.chunkSize),this.chunkIndex=0}return u(t,null,[{key:\"create\",value:function(e,r){new t(e).create(r)}}]),u(t,[{key:\"create\",value:function(t){var e=this;this.callback=t,this.md5Buffer=new a.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){!function(e){t.exports=e()}(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,r=(r<<7|r>>>25)+n|0,a+=(r&n|~r&i)+e[1]-389564586|0,a=(a<<12|a>>>20)+r|0,i+=(a&r|~a&n)+e[2]+606105819|0,i=(i<<17|i>>>15)+a|0,n+=(i&a|~i&r)+e[3]-1044525330|0,n=(n<<22|n>>>10)+i|0,r+=(n&i|~n&a)+e[4]-176418897|0,r=(r<<7|r>>>25)+n|0,a+=(r&n|~r&i)+e[5]+1200080426|0,a=(a<<12|a>>>20)+r|0,i+=(a&r|~a&n)+e[6]-1473231341|0,i=(i<<17|i>>>15)+a|0,n+=(i&a|~i&r)+e[7]-45705983|0,n=(n<<22|n>>>10)+i|0,r+=(n&i|~n&a)+e[8]+1770035416|0,r=(r<<7|r>>>25)+n|0,a+=(r&n|~r&i)+e[9]-1958414417|0,a=(a<<12|a>>>20)+r|0,i+=(a&r|~a&n)+e[10]-42063|0,i=(i<<17|i>>>15)+a|0,n+=(i&a|~i&r)+e[11]-1990404162|0,n=(n<<22|n>>>10)+i|0,r+=(n&i|~n&a)+e[12]+1804603682|0,r=(r<<7|r>>>25)+n|0,a+=(r&n|~r&i)+e[13]-40341101|0,a=(a<<12|a>>>20)+r|0,i+=(a&r|~a&n)+e[14]-1502002290|0,i=(i<<17|i>>>15)+a|0,n+=(i&a|~i&r)+e[15]+1236535329|0,n=(n<<22|n>>>10)+i|0,r+=(n&a|i&~a)+e[1]-165796510|0,r=(r<<5|r>>>27)+n|0,a+=(r&i|n&~i)+e[6]-1069501632|0,a=(a<<9|a>>>23)+r|0,i+=(a&n|r&~n)+e[11]+643717713|0,i=(i<<14|i>>>18)+a|0,n+=(i&r|a&~r)+e[0]-373897302|0,n=(n<<20|n>>>12)+i|0,r+=(n&a|i&~a)+e[5]-701558691|0,r=(r<<5|r>>>27)+n|0,a+=(r&i|n&~i)+e[10]+38016083|0,a=(a<<9|a>>>23)+r|0,i+=(a&n|r&~n)+e[15]-660478335|0,i=(i<<14|i>>>18)+a|0,n+=(i&r|a&~r)+e[4]-405537848|0,n=(n<<20|n>>>12)+i|0,r+=(n&a|i&~a)+e[9]+568446438|0,r=(r<<5|r>>>27)+n|0,a+=(r&i|n&~i)+e[14]-1019803690|0,a=(a<<9|a>>>23)+r|0,i+=(a&n|r&~n)+e[3]-187363961|0,i=(i<<14|i>>>18)+a|0,n+=(i&r|a&~r)+e[8]+1163531501|0,n=(n<<20|n>>>12)+i|0,r+=(n&a|i&~a)+e[13]-1444681467|0,r=(r<<5|r>>>27)+n|0,a+=(r&i|n&~i)+e[2]-51403784|0,a=(a<<9|a>>>23)+r|0,i+=(a&n|r&~n)+e[7]+1735328473|0,i=(i<<14|i>>>18)+a|0,n+=(i&r|a&~r)+e[12]-1926607734|0,n=(n<<20|n>>>12)+i|0,r+=(n^i^a)+e[5]-378558|0,r=(r<<4|r>>>28)+n|0,a+=(r^n^i)+e[8]-2022574463|0,a=(a<<11|a>>>21)+r|0,i+=(a^r^n)+e[11]+1839030562|0,i=(i<<16|i>>>16)+a|0,n+=(i^a^r)+e[14]-35309556|0,n=(n<<23|n>>>9)+i|0,r+=(n^i^a)+e[1]-1530992060|0,r=(r<<4|r>>>28)+n|0,a+=(r^n^i)+e[4]+1272893353|0,a=(a<<11|a>>>21)+r|0,i+=(a^r^n)+e[7]-155497632|0,i=(i<<16|i>>>16)+a|0,n+=(i^a^r)+e[10]-1094730640|0,n=(n<<23|n>>>9)+i|0,r+=(n^i^a)+e[13]+681279174|0,r=(r<<4|r>>>28)+n|0,a+=(r^n^i)+e[0]-358537222|0,a=(a<<11|a>>>21)+r|0,i+=(a^r^n)+e[3]-722521979|0,i=(i<<16|i>>>16)+a|0,n+=(i^a^r)+e[6]+76029189|0,n=(n<<23|n>>>9)+i|0,r+=(n^i^a)+e[9]-640364487|0,r=(r<<4|r>>>28)+n|0,a+=(r^n^i)+e[12]-421815835|0,a=(a<<11|a>>>21)+r|0,i+=(a^r^n)+e[15]+530742520|0,i=(i<<16|i>>>16)+a|0,n+=(i^a^r)+e[2]-995338651|0,n=(n<<23|n>>>9)+i|0,r+=(i^(n|~a))+e[0]-198630844|0,r=(r<<6|r>>>26)+n|0,a+=(n^(r|~i))+e[7]+1126891415|0,a=(a<<10|a>>>22)+r|0,i+=(r^(a|~n))+e[14]-1416354905|0,i=(i<<15|i>>>17)+a|0,n+=(a^(i|~r))+e[5]-57434055|0,n=(n<<21|n>>>11)+i|0,r+=(i^(n|~a))+e[12]+1700485571|0,r=(r<<6|r>>>26)+n|0,a+=(n^(r|~i))+e[3]-1894986606|0,a=(a<<10|a>>>22)+r|0,i+=(r^(a|~n))+e[10]-1051523|0,i=(i<<15|i>>>17)+a|0,n+=(a^(i|~r))+e[1]-2054922799|0,n=(n<<21|n>>>11)+i|0,r+=(i^(n|~a))+e[8]+1873313359|0,r=(r<<6|r>>>26)+n|0,a+=(n^(r|~i))+e[15]-30611744|0,a=(a<<10|a>>>22)+r|0,i+=(r^(a|~n))+e[6]-1560198380|0,i=(i<<15|i>>>17)+a|0,n+=(a^(i|~r))+e[13]+1309151649|0,n=(n<<21|n>>>11)+i|0,r+=(i^(n|~a))+e[4]-145523070|0,r=(r<<6|r>>>26)+n|0,a+=(n^(r|~i))+e[11]-1120210379|0,a=(a<<10|a>>>22)+r|0,i+=(r^(a|~n))+e[2]+718787259|0,i=(i<<15|i>>>17)+a|0,n+=(a^(i|~r))+e[9]-343485551|0,n=(n<<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,u,o,s,f=t.length,c=[1732584193,-271733879,-1732584194,271733878];for(n=64;n<=f;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 u=8*f,u=u.toString(16).match(/(.*?)(.{0,8})$/),o=parseInt(u[2],16),s=parseInt(u[1],16)||0,a[14]=o,a[15]=s,e(c,a),c}function a(t){var r,i,a,u,o,s,f=t.length,c=[1732584193,-271733879,-1732584194,271733878];for(r=64;r<=f;r+=64)e(c,n(t.subarray(r-64,r)));for(t=r-64<f?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 u=8*f,u=u.toString(16).match(/(.*?)(.{0,8})$/),o=parseInt(u[2],16),s=parseInt(u[1],16)||0,a[14]=o,a[15]=s,e(c,a),c}function u(t){var e,r=\"\";for(e=0;e<4;e+=1)r+=p[t>>8*e+4&15]+p[t>>8*e&15];return r}function o(t){var e;for(e=0;e<t.length;e+=1)t[e]=u(t[e]);return t.join(\"\")}function s(t){return/[\\u0080-\\uFFFF]/.test(t)&&(t=unescape(encodeURIComponent(t))),t}function f(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}function c(t){return String.fromCharCode.apply(null,new Uint8Array(t))}function h(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}function l(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 d(){this.reset()}var p=[\"0\",\"1\",\"2\",\"3\",\"4\",\"5\",\"6\",\"7\",\"8\",\"9\",\"a\",\"b\",\"c\",\"d\",\"e\",\"f\"];return\"5d41402abc4b2a76b9719d911017c592\"!==o(i(\"hello\"))&&function(t,e){var r=(65535&t)+(65535&e);return(t>>16)+(e>>16)+(r>>16)<<16|65535&r},\"undefined\"==typeof ArrayBuffer||ArrayBuffer.prototype.slice||function(){function e(t,e){return t=0|t||0,t<0?Math.max(t+e,0):Math.min(t,e)}ArrayBuffer.prototype.slice=function(r,n){var i,a,u,o,s=this.byteLength,f=e(r,s),c=s;return n!==t&&(c=e(n,s)),f>c?new ArrayBuffer(0):(i=c-f,a=new ArrayBuffer(i),u=new Uint8Array(a),o=new Uint8Array(this,f,i),u.set(o),a)}}(),d.prototype.append=function(t){return this.appendBinary(s(t)),this},d.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},d.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=o(this._hash),t&&(r=l(r)),this.reset(),r},d.prototype.reset=function(){return this._buff=\"\",this._length=0,this._hash=[1732584193,-271733879,-1732584194,271733878],this},d.prototype.getState=function(){return{buff:this._buff,length:this._length,hash:this._hash}},d.prototype.setState=function(t){return this._buff=t.buff,this._length=t.length,this._hash=t.hash,this},d.prototype.destroy=function(){delete this._hash,delete this._buff,delete this._length},d.prototype._finish=function(t,r){var n,i,a,u=r;if(t[u>>2]|=128<<(u%4<<3),u>55)for(e(this._hash,t),u=0;u<16;u+=1)t[u]=0;n=8*this._length,n=n.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)},d.hash=function(t,e){return d.hashBinary(s(t),e)},d.hashBinary=function(t,e){var r=i(t),n=o(r);return e?l(n):n},d.ArrayBuffer=function(){this.reset()},d.ArrayBuffer.prototype.append=function(t){var r,i=h(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},d.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=o(this._hash),t&&(r=l(r)),this.reset(),r},d.ArrayBuffer.prototype.reset=function(){return this._buff=new Uint8Array(0),this._length=0,this._hash=[1732584193,-271733879,-1732584194,271733878],this},d.ArrayBuffer.prototype.getState=function(){var t=d.prototype.getState.call(this);return t.buff=c(t.buff),t},d.ArrayBuffer.prototype.setState=function(t){return t.buff=f(t.buff,!0),d.prototype.setState.call(this,t)},d.ArrayBuffer.prototype.destroy=d.prototype.destroy,d.ArrayBuffer.prototype._finish=d.prototype._finish,d.ArrayBuffer.hash=function(t,e){var r=a(new Uint8Array(t)),n=o(r);return e?l(n):n},d})},function(t,e,r){\"use strict\";function n(t,e){if(!(t instanceof e))throw new TypeError(\"Cannot call a class as a function\")}r.d(e,\"a\",function(){return u});var 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}}(),u=function(){function t(e,r,a){var u=this;n(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\",a,!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(i.d)(\"csrf-token\")),this.xhr.addEventListener(\"load\",function(t){return u.requestDidLoad(t)}),this.xhr.addEventListener(\"error\",function(t){return u.requestDidError(t)})}return a(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\";function n(t,e){if(!(t instanceof e))throw new TypeError(\"Cannot call a class as a function\")}r.d(e,\"a\",function(){return a});var 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){var r=this;n(this,t),this.blob=e,this.file=e.file;var i=e.directUploadData,a=i.url,u=i.headers;this.xhr=new XMLHttpRequest,this.xhr.open(\"PUT\",a,!0),this.xhr.responseType=\"text\";for(var o in u)this.xhr.setRequestHeader(o,u[o]);this.xhr.addEventListener(\"load\",function(t){return r.requestDidLoad(t)}),this.xhr.addEventListener(\"error\",function(t){return r.requestDidError(t)})}return i(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}()}])});\n\n\n//# sourceURL=webpack://ActiveStorage/./node_modules/activestorage/app/assets/javascripts/activestorage.js?");
167
+
168
+ /***/ })
169
+
170
+ /******/ });
171
+ });
@@ -45,5 +45,15 @@ export class UploadQueueProcessor {
45
45
  export function createUploader(input, file) {
46
46
  // your form needs the file_field direct_upload: true, which
47
47
  // provides data-direct-upload-url
48
- uploaders.push( new DragAndDropUploadController(input, file) )
48
+ console.log(input.accept === '')
49
+ if (input.accept === '' || input.accept.split(', ').includes(file.type)) {
50
+ uploaders.push(new DragAndDropUploadController(input, file))
51
+ } else {
52
+ const error = Error('Invalid filetype')
53
+ const event = dispatchEvent(input, `${eventFamily}:error`, { error })
54
+ if (!event.defaultPrevented) {
55
+ alert(error)
56
+ }
57
+ return event
58
+ }
49
59
  }
@@ -1,16 +1,8 @@
1
1
  <label class="asdndzone" id="asdndz-<%= form.object_name %>_<%= method %>" data-dnd-input-id="<%= form.object_name %>_<%= method %>">
2
2
  <%= tag_value %>
3
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
- } %>
13
- <% attachments.each_with_index do |blob,idx| %>
4
+ <%= form.file_field method, options %>
5
+ <% attachments.reject(&:persisted?).each_with_index do |blob,idx| %>
14
6
  <%= form.hidden_field method,
15
7
  value: blob.signed_id,
16
8
  :multiple => true,
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require "bundler/setup"
4
- require "active_storage_drag_and_drop"
3
+ require 'bundler/setup'
4
+ require 'active_storage_drag_and_drop'
5
5
 
6
6
  # You can add fixtures and/or initialization code here to make experimenting
7
7
  # with your gem easier. You can also use a different console, if you like.
@@ -10,5 +10,5 @@ require "active_storage_drag_and_drop"
10
10
  # require "pry"
11
11
  # Pry.start
12
12
 
13
- require "irb"
13
+ require 'irb'
14
14
  IRB.start(__FILE__)
@@ -1,5 +1,5 @@
1
- require "active_storage_drag_and_drop/version"
2
- require "active_storage_drag_and_drop/rails" if defined?(Rails)
1
+ require 'active_storage_drag_and_drop/version'
2
+ require 'active_storage_drag_and_drop/rails' if defined?(Rails)
3
3
 
4
4
  module ActiveStorageDragAndDrop
5
5
  end
@@ -2,7 +2,9 @@ module ActiveStorageDragAndDrop
2
2
  module Rails
3
3
  class Engine < ::Rails::Engine
4
4
  initializer 'active_storage_drag_and_drop.form_helpers' do |_app|
5
- ActiveSupport.on_load(:action_view) { require 'active_storage_drag_and_drop/rails/form_helper'}
5
+ ActiveSupport.on_load(:action_view) do
6
+ require 'active_storage_drag_and_drop/rails/form_helper'
7
+ end
6
8
  end
7
9
  end
8
10
  end
@@ -3,9 +3,38 @@ module ActiveStorageDragAndDrop
3
3
  module FormBuilder
4
4
  include ActionView::Helpers::TagHelper
5
5
 
6
- def drag_and_drop_file_field method, tag_value=nil, **options
7
- tag_value ||= tag.strong('Drag and drop') + ' files here or ' + tag.strong('click to browse')
8
- @template.render partial: 'active_storage_drag_and_drop', locals: { tag_value: tag_value, form: self, attachments: @object.send(method), method: method }
6
+ def drag_and_drop_file_field(method, tag_value = nil, **options)
7
+ tag_value ||= tag.strong('Drag and drop') + ' files here or ' +
8
+ tag.strong('click to browse')
9
+ @template.render partial: 'active_storage_drag_and_drop',
10
+ locals: {
11
+ tag_value: tag_value,
12
+ form: self,
13
+ attachments: @object.send(method),
14
+ method: method,
15
+ options: file_field_options(options, method)
16
+ }
17
+ end
18
+
19
+ private
20
+
21
+ def default_file_field_options(method)
22
+ {
23
+ multiple: true,
24
+ direct_upload: true,
25
+ style: 'display:none;',
26
+ data: {
27
+ dnd: true,
28
+ dnd_zone_id: "asdndz-#{object_name}_#{method}",
29
+ icon_container_id: "asdndz-#{object_name}_#{method}__icon-container"
30
+ }
31
+ }
32
+ end
33
+
34
+ def file_field_options(custom_options, method)
35
+ default_file_field_options(method).merge(custom_options) do |_key, default, custom|
36
+ default.is_a?(Hash) && custom.is_a?(Hash) ? default.merge(custom) : custom
37
+ end
9
38
  end
10
39
  end
11
40
  end
@@ -1,3 +1,3 @@
1
1
  module ActiveStorageDragAndDrop
2
- VERSION = "0.3.0"
2
+ VERSION = '0.3.1'
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.3.0
4
+ version: 0.3.1
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-08-09 00:00:00.000000000 Z
12
+ date: 2018-10-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -26,33 +26,33 @@ dependencies:
26
26
  - !ruby/object:Gem::Version
27
27
  version: '1.16'
28
28
  - !ruby/object:Gem::Dependency
29
- name: rake
29
+ name: minitest
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
32
  - - "~>"
33
33
  - !ruby/object:Gem::Version
34
- version: '10.0'
34
+ version: '5.0'
35
35
  type: :development
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
39
  - - "~>"
40
40
  - !ruby/object:Gem::Version
41
- version: '10.0'
41
+ version: '5.0'
42
42
  - !ruby/object:Gem::Dependency
43
- name: minitest
43
+ name: rake
44
44
  requirement: !ruby/object:Gem::Requirement
45
45
  requirements:
46
46
  - - "~>"
47
47
  - !ruby/object:Gem::Version
48
- version: '5.0'
48
+ version: '10.0'
49
49
  type: :development
50
50
  prerelease: false
51
51
  version_requirements: !ruby/object:Gem::Requirement
52
52
  requirements:
53
53
  - - "~>"
54
54
  - !ruby/object:Gem::Version
55
- version: '5.0'
55
+ version: '10.0'
56
56
  - !ruby/object:Gem::Dependency
57
57
  name: rails
58
58
  requirement: !ruby/object:Gem::Requirement
@@ -67,8 +67,8 @@ dependencies:
67
67
  - - "~>"
68
68
  - !ruby/object:Gem::Version
69
69
  version: '5.2'
70
- description: Provides a form helper to make it easy to make drag and drop file upload
71
- fields that work with Rails' Active Storage.
70
+ description: Provides a form helper to make it easy to make drag and drop file uploadfields
71
+ that work with Rails' Active Storage.
72
72
  email:
73
73
  - ian.grant@marinosoftware.com
74
74
  executables: []
@@ -76,6 +76,7 @@ extensions: []
76
76
  extra_rdoc_files: []
77
77
  files:
78
78
  - ".gitignore"
79
+ - ".rubocop.yml"
79
80
  - ".travis.yml"
80
81
  - CODE_OF_CONDUCT.md
81
82
  - Gemfile