active_storage_drag_and_drop 0.4.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7ba690ed77fde42914d34c270c5fda5cf7746486223b6755093e533366dc0b45
4
- data.tar.gz: 8975e08690e83f5ef6d414c02a06b24c775f3895b68e56b7c154c245f56e6461
3
+ metadata.gz: 780c899a9fde1eddf2c7635968791515dded176e5431cea2d58ba014aa820bf1
4
+ data.tar.gz: fc72e6c77f4c8f854e98a2017d2d9d430237f21835e135d848dfc3cdf4e3a7e5
5
5
  SHA512:
6
- metadata.gz: c9d8bdd77b497ca484f0cf5406776d661003acb83f1a8184b9eb729f2d1182f6de603b17562b9bca57801a69c3f4e2456f67f0601d3fb70f6ea797dd928416f7
7
- data.tar.gz: '090aed49947b5fc99af2618e4c4e4d0daaeca3393e42322b4354124a109494432c26f9a690105755fa3082f4c931eb96b2a998447a97e345e2cfa456b5ebaa00'
6
+ metadata.gz: f6b1bb9f88bd9f04eeaa34f542b43e13a665861b84a5d6ae95f9681bc86364494c5b26a4f090188e702dba3576dc833f0b4c321ebe99340ae8eceb1bf0696f1d
7
+ data.tar.gz: 659df49b6b8b486efe601d05b08438017a5d6e5697f269d6e0a8d866cb4adf463f35b70f97ecf6d4ef8dc4c82183eea8325d38a12462eb9a9547030287c73632
@@ -0,0 +1,3 @@
1
+ {
2
+ 'presets': ['env', 'flow']
3
+ }
@@ -1 +1,16 @@
1
- extends: standard
1
+ ---
2
+ extends:
3
+ - standard
4
+ - plugin:flowtype/recommended
5
+ plugins:
6
+ - flowtype
7
+ env:
8
+ mocha: true
9
+ browser: true
10
+ rules:
11
+ curly: [2, multi]
12
+ arrow-body-style: [2, as-needed]
13
+ arrow-parens: [2, as-needed]
14
+ prefer-arrow-callback: 2
15
+ prefer-const: 2
16
+ no-var: 2
@@ -0,0 +1,11 @@
1
+ [ignore]
2
+
3
+ [include]
4
+
5
+ [libs]
6
+
7
+ [lints]
8
+
9
+ [options]
10
+
11
+ [strict]
data/.gitignore CHANGED
@@ -4,6 +4,7 @@
4
4
  /.yardoc
5
5
  /_yardoc/
6
6
  /coverage/
7
+ /.nyc_output/
7
8
  /doc/
8
9
  /pkg/
9
10
  /spec/reports/
@@ -1,3 +1,4 @@
1
+ ---
1
2
  sudo: false
2
3
  language: ruby
3
4
  cache: bundler
@@ -12,10 +13,15 @@ env:
12
13
  CC_TEST_REPORTER_ID=93b20ad2a94eb5d9feb97dca94b2d1df4243fa3d715d5d6c1c61bc9c6199f105
13
14
 
14
15
  before_install:
16
+ - nvm install node
15
17
  - gem install bundler -v 1.16.1
16
18
  - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
17
19
  - chmod +x ./cc-test-reporter
18
20
  - ./cc-test-reporter before-build
19
21
 
22
+ before_script:
23
+ - yarn install --prod
24
+ - yarn build
25
+
20
26
  after_script:
21
27
  - ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
@@ -1,50 +1,50 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- active_storage_drag_and_drop (0.3.5)
4
+ active_storage_drag_and_drop (1.0.0)
5
5
  rack (~> 2.0.6)
6
- rails (~> 5.2)
6
+ rails (~> 5.2.2.1)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- actioncable (5.2.1)
12
- actionpack (= 5.2.1)
11
+ actioncable (5.2.2.1)
12
+ actionpack (= 5.2.2.1)
13
13
  nio4r (~> 2.0)
14
14
  websocket-driver (>= 0.6.1)
15
- actionmailer (5.2.1)
16
- actionpack (= 5.2.1)
17
- actionview (= 5.2.1)
18
- activejob (= 5.2.1)
15
+ actionmailer (5.2.2.1)
16
+ actionpack (= 5.2.2.1)
17
+ actionview (= 5.2.2.1)
18
+ activejob (= 5.2.2.1)
19
19
  mail (~> 2.5, >= 2.5.4)
20
20
  rails-dom-testing (~> 2.0)
21
- actionpack (5.2.1)
22
- actionview (= 5.2.1)
23
- activesupport (= 5.2.1)
21
+ actionpack (5.2.2.1)
22
+ actionview (= 5.2.2.1)
23
+ activesupport (= 5.2.2.1)
24
24
  rack (~> 2.0)
25
25
  rack-test (>= 0.6.3)
26
26
  rails-dom-testing (~> 2.0)
27
27
  rails-html-sanitizer (~> 1.0, >= 1.0.2)
28
- actionview (5.2.1)
29
- activesupport (= 5.2.1)
28
+ actionview (5.2.2.1)
29
+ activesupport (= 5.2.2.1)
30
30
  builder (~> 3.1)
31
31
  erubi (~> 1.4)
32
32
  rails-dom-testing (~> 2.0)
33
33
  rails-html-sanitizer (~> 1.0, >= 1.0.3)
34
- activejob (5.2.1)
35
- activesupport (= 5.2.1)
34
+ activejob (5.2.2.1)
35
+ activesupport (= 5.2.2.1)
36
36
  globalid (>= 0.3.6)
37
- activemodel (5.2.1)
38
- activesupport (= 5.2.1)
39
- activerecord (5.2.1)
40
- activemodel (= 5.2.1)
41
- activesupport (= 5.2.1)
37
+ activemodel (5.2.2.1)
38
+ activesupport (= 5.2.2.1)
39
+ activerecord (5.2.2.1)
40
+ activemodel (= 5.2.2.1)
41
+ activesupport (= 5.2.2.1)
42
42
  arel (>= 9.0)
43
- activestorage (5.2.1)
44
- actionpack (= 5.2.1)
45
- activerecord (= 5.2.1)
43
+ activestorage (5.2.2.1)
44
+ actionpack (= 5.2.2.1)
45
+ activerecord (= 5.2.2.1)
46
46
  marcel (~> 0.3.1)
47
- activesupport (5.2.1)
47
+ activesupport (5.2.2.1)
48
48
  concurrent-ruby (~> 1.0, >= 1.0.2)
49
49
  i18n (>= 0.7, < 2)
50
50
  minitest (~> 5.1)
@@ -70,20 +70,20 @@ GEM
70
70
  childprocess (0.9.0)
71
71
  ffi (~> 1.0, >= 1.0.11)
72
72
  coderay (1.1.2)
73
- concurrent-ruby (1.1.3)
73
+ concurrent-ruby (1.1.5)
74
74
  crass (1.0.4)
75
75
  docile (1.3.1)
76
- erubi (1.7.1)
76
+ erubi (1.8.0)
77
77
  ffi (1.9.25)
78
78
  geckodriver-helper (0.23.0)
79
79
  archive-zip (~> 0.7)
80
80
  github-markup (3.0.2)
81
- globalid (0.4.1)
81
+ globalid (0.4.2)
82
82
  activesupport (>= 4.2.0)
83
83
  haml (5.0.4)
84
84
  temple (>= 0.8.0)
85
85
  tilt
86
- i18n (1.1.1)
86
+ i18n (1.6.0)
87
87
  concurrent-ruby (~> 1.0)
88
88
  io-like (0.3.0)
89
89
  jaro_winkler (1.5.2)
@@ -100,14 +100,14 @@ GEM
100
100
  marcel (0.3.3)
101
101
  mimemagic (~> 0.3.2)
102
102
  method_source (0.9.2)
103
- mimemagic (0.3.2)
103
+ mimemagic (0.3.3)
104
104
  mini_mime (1.0.1)
105
- mini_portile2 (2.3.0)
105
+ mini_portile2 (2.4.0)
106
106
  minitest (5.11.3)
107
107
  msgpack (1.2.4)
108
108
  nio4r (2.3.1)
109
- nokogiri (1.8.5)
110
- mini_portile2 (~> 2.3.0)
109
+ nokogiri (1.10.3)
110
+ mini_portile2 (~> 2.4.0)
111
111
  parallel (1.13.0)
112
112
  parser (2.6.0.0)
113
113
  ast (~> 2.4.0)
@@ -120,30 +120,30 @@ GEM
120
120
  pry (~> 0.10)
121
121
  public_suffix (3.0.3)
122
122
  puma (3.12.0)
123
- rack (2.0.6)
123
+ rack (2.0.7)
124
124
  rack-test (1.1.0)
125
125
  rack (>= 1.0, < 3)
126
- rails (5.2.1)
127
- actioncable (= 5.2.1)
128
- actionmailer (= 5.2.1)
129
- actionpack (= 5.2.1)
130
- actionview (= 5.2.1)
131
- activejob (= 5.2.1)
132
- activemodel (= 5.2.1)
133
- activerecord (= 5.2.1)
134
- activestorage (= 5.2.1)
135
- activesupport (= 5.2.1)
126
+ rails (5.2.2.1)
127
+ actioncable (= 5.2.2.1)
128
+ actionmailer (= 5.2.2.1)
129
+ actionpack (= 5.2.2.1)
130
+ actionview (= 5.2.2.1)
131
+ activejob (= 5.2.2.1)
132
+ activemodel (= 5.2.2.1)
133
+ activerecord (= 5.2.2.1)
134
+ activestorage (= 5.2.2.1)
135
+ activesupport (= 5.2.2.1)
136
136
  bundler (>= 1.3.0)
137
- railties (= 5.2.1)
137
+ railties (= 5.2.2.1)
138
138
  sprockets-rails (>= 2.0.0)
139
139
  rails-dom-testing (2.0.3)
140
140
  activesupport (>= 4.2.0)
141
141
  nokogiri (>= 1.6)
142
142
  rails-html-sanitizer (1.0.4)
143
143
  loofah (~> 2.2, >= 2.2.2)
144
- railties (5.2.1)
145
- actionpack (= 5.2.1)
146
- activesupport (= 5.2.1)
144
+ railties (5.2.2.1)
145
+ actionpack (= 5.2.2.1)
146
+ activesupport (= 5.2.2.1)
147
147
  method_source
148
148
  rake (>= 0.8.7)
149
149
  thor (>= 0.19.0, < 2.0)
data/README.md CHANGED
@@ -10,10 +10,26 @@
10
10
  Provides a form helper to make it easy to make drag and drop file upload fields that work with
11
11
  Rails' [ActiveStorage](https://github.com/rails/rails/tree/master/activestorage).
12
12
 
13
+ ![Demo](./demo.webp)
14
+
15
+ ## Table of Contents
16
+ - [Installation](#installation)
17
+ - [Usage](#usage)
18
+ - [Strong Parameters](#strong-parameters)
19
+ - [Options]('#options')
20
+ - [Validation](#validation)
21
+ - [JavaScript Events](#javascript-events)
22
+ - [Globally Exported JavaScript](#globally-exported-javascript)
23
+ - [Upload Asynchronously](#upload-acsynchronously)
24
+ - [Custom Upload Icons](#custom-upload-icons)
25
+ - [Development](#development)
26
+ - [Contributing](#contributing)
27
+ - [License](#license)
28
+ - [Code of Conduct](#code-of-conduct)
29
+
13
30
  ## Installation
14
31
 
15
32
  Add this line to your application's Gemfile:
16
-
17
33
  ```ruby
18
34
  gem 'active_storage_drag_and_drop'
19
35
  ```
@@ -31,10 +47,9 @@ Include `active_stroage_drag_and_drop.js` in your application's JavaScript bundl
31
47
  //= require active_storage_drag_and_drop
32
48
  ```
33
49
 
34
- You may also optionally include some basic styles in your application css:
50
+ And include the styles in your application css:
35
51
  ```css
36
52
  /*
37
- *= require direct_uploads
38
53
  *= require active_storage_drag_and_drop
39
54
  */
40
55
  ```
@@ -61,7 +76,7 @@ Call the method `drag_and_drop_file_field` on your model's form:
61
76
  = form.submit
62
77
  ```
63
78
  The first parameter is a symbol representing the method of the ActiveStorage attachment and an
64
- optional second parameter sets the the text on the drag and drop zone.
79
+ optional second parameter sets the text on the drag and drop zone.
65
80
  ```ruby
66
81
  form.drag_and_drop_file_field :images, 'Drag and drop images here!'
67
82
  ```
@@ -72,8 +87,6 @@ The content of the dropzone can also be passed as a block of ERB or HAML:
72
87
  Drag images here!
73
88
  ```
74
89
 
75
-
76
-
77
90
  ### Strong Parameters
78
91
 
79
92
  In your controller you can permit the params like so:
@@ -113,41 +126,78 @@ for the event and call `preventDefault()` on the event.
113
126
 
114
127
  | Event name | Event target | Event data (`event.detail`) | Description |
115
128
  | --- | --- | --- | --- |
116
- | `dnd-uploads:start` | `<form>` | None | A form containing files for direct upload fields was submitted. |
117
- | `dnd-upload:initialize` | `<input>` | `{id, file, iconContainer}` | Dispatched for every file after form submission. |
118
- | `dnd-upload:start` | `<input>` | `{id, file, iconContainer}` | A direct upload is starting. |
119
- | `dnd-upload:before-blob-request` | `<input>` | `{id, file, iconContainer, xhr}` | Before making a request to your application for direct upload metadata. |
120
- | `dnd-upload:before-storage-request` | `<input>` | `{id, file, iconContainer, xhr}` | Before making a request to store a file. |
121
- | `dnd-upload:progress` | `<input>` | `{id, file, iconContainer, progress}` | As requests to store files progress. |
122
- | `dnd-upload:error` | `<input>` | `{id, file, iconContainer, error}` | An error occurred. An `alert` will display unless this event is canceled. |
123
- | `dnd-upload:end` | `<input>` | `{id, file, iconContainer}` | A direct upload has ended. |
124
- | `dnd-uploads:end` | `<form>` | None | All direct uploads have ended. |
129
+ | `dnd-uploads:start` | `<form>` | None | All of the uploads begin either by submission of the form or a call to processUploadQueue() |
130
+ | `dnd-upload:initialize` | `<input>` | `{ id, file, iconContainer }` | Dispatched for every file before the UI elements representing the file are added to the dropzone, default can be prevented to add your own UI. |
131
+ | `dnd-upload:placeholder` | `<input>` | `{ id, file, iconContainer }` | Paints the UI for each file that has been queued for attachment but hasn't been attached yet (e.g. after a failed validation in the form) can be prevented as above. |
132
+ | `dnd-upload:start` | `<input>` | `{ id, file, iconContainer }` | An upload is starting. |
133
+ | `dnd-upload:before-blob-request` | `<input>` | `{ id, file, iconContainer, xhr }` | Before making a request to your application for upload metadata. |
134
+ | `dnd-upload:before-storage-request` | `<input>` | `{ id, file, iconContainer, xhr }` | Before making a request to store a file. |
135
+ | `dnd-upload:progress` | `<input>` | `{ id, file, iconContainer, progress }` | Called as requests to store files progress. Default UI sets the width of the `direct-upload__progress` element. |
136
+ | `dnd-upload:cancel` | `<input>` | `{ id, file, iconContainer }` | A user triggered the cancelation of an upload, the upload is removed from the queue and the preventable default UI removes matching upload icons from the iconContainer. |
137
+ | `dnd-upload:error` | `<input>` | `{ id, file, iconContainer, error }` | An error occurred pertaining to a specific file. The default can be prevented to supply your own UI for errors. |
138
+ | `dnd-upload:end` | `<input>` | `{ id, file, iconContainer }` | An upload has ended. Default can be prevented to supply your own UI for the end of an upload. |
139
+ | `dnd-uploads:error` | `<form>` | `{ error }` | An error occurred unrelated to a specific file. The default can be prevented to supply your own UI for errors. |
140
+ | `dnd-uploads:end` | `<form>` | None | All uploads have ended. |
125
141
 
126
142
  To override the default behaviour of any of these events catch them with an event listener and call
127
143
  `preventDefault()` on the event:
128
144
  ```javascript
129
145
  document.addEventListener('dnd-upload:error', function (event) {
130
- # do something...
146
+ # do something
131
147
  event.preventDefault()
132
148
  })
133
149
  ```
134
150
 
135
- To asynchronously trigger uploading without form submission dispatch a
136
- `dnd-uploads:process-upload-queue` event:
151
+ ### Globally Exported JavaScript
152
+ #### Upload Asynchronously
153
+ To asynchronously trigger uploading without form submission call the processUploadQueue function
154
+ exported on the window under ActiveStorageDragAndDrop and pass the form containing the uploads and
155
+ a callback function as arguments:
137
156
  ```javascript
138
157
  var callback = function(error) {
139
158
  if (error) {
140
- // ...handle error...
159
+ // handle error
141
160
  } else {
142
- // ...do your stuff
161
+ // do your stuff
143
162
  }
144
163
  }
145
164
 
146
- const uploadEvent = document.createEvent('Event')
147
- uploadEvent.initEvent('dnd-uploads:process-upload-queue', true, true)
148
- uploadEvent.detail = { callback }
149
- form.dispatchEvent(uploadEvent)
165
+ window.ActiveStorageDragAndDrop.processUploadQueue(form, callback)
166
+ ```
167
+ #### Custom Upload Icons
168
+ To customise how the upload icons for each file are added to the DOM you can redefine
169
+ `window.ActiveStroageDragAndDrop.paintUploadIcon(iconContainer, id, file, complete)` where the
170
+ arguments it receives are:
171
+ | Parameter | Type | Description |
172
+ | --- | --- | --- |
173
+ | `iconContainer` | `HTMLElement` | The element to insert the upload icon markup into. |
174
+ | `id` | `string` | A unique identifier which will be used for any future UI events on this upload. |
175
+ | `file` | `File` | The object representing the file and its metadata. |
176
+ | `complete` | `boolean` | Is true if the upload is finished and false otherwise. |
177
+ This is the default implementation:
178
+ ```javascript
179
+ export function paintUploadIcon (iconContainer: HTMLElement, id: string | number, file: File, complete: boolean) {
180
+ const uploadStatus = (complete ? 'complete' : 'pending')
181
+ const progress = (complete ? 100 : 0)
182
+ iconContainer.insertAdjacentHTML('beforeend', `
183
+ <div data-direct-upload-id="${id}">
184
+ <div class="direct-upload direct-upload--${uploadStatus}">
185
+ <div class="direct-upload__progress" style="width: ${progress}%"></div>
186
+ <span class="direct-upload__filename">${file.name}</span>
187
+ <span class="direct-upload__filesize">${fileSizeSI(file.size)}</span>
188
+ </div>
189
+ <a href='remove' class='direct-upload__remove'>X</a>
190
+ </div>
191
+ `)
192
+ }
150
193
  ```
194
+ All of the built in UI that manipulates these icons can be overriden by attaching to their event
195
+ and preventing the default behaviour. But to take advantage of the built in ui events though you should
196
+ follow these rules:
197
+ - The root level element must have a `data-direct-upload-id` attribute set to the id passed to `paintUploadIcon`.
198
+ - The progress section consists of a parent with the class `direct-upload` and a direct child with
199
+ the class `direct-upload__progress`.
200
+ - The element that will cancel the upload when clicked has the class `direct-upload__remove`.
151
201
 
152
202
  ## Development
153
203
 
@@ -155,13 +205,13 @@ Install yarn to manage js dependencies. After checking out the repo, run `bin/se
155
205
  dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an
156
206
  interactive prompt that will allow you to experiment.
157
207
 
158
- After making a change to the javascript in `app/javascript` compile it to
159
- `app/assets/javascripts/active_storage_drag_and_drop.js` by running
160
- `yarn webpack`.
208
+ Use `yarn dev` to build JavaScript files automatically on change. Use with
209
+ `gem 'active_storage_drag_and_drop', path: [local-gem-repo]` to develop and debug the gem in place
210
+ in a rails app. You can run the JS tests with `yarn test` and you can see the coverage as well as
211
+ the tests by running `yarn cover`.
161
212
 
162
- Use `yarn webpack --mode=development --watch` to build files
163
- automatically on change. Use with `gem 'active_storage_drag_and_drop', path: [local-gem-repo]` to
164
- develop and debug the gem in place in a rails app.
213
+ After making changes to JavaScript run `yarn build` before committing changes to transpile the
214
+ JavaScript for production.
165
215
 
166
216
  To install this gem onto your local machine, run `bundle exec rake install`. To release a new
167
217
  version, update the version number in `version.rb`, and then run `bundle exec rake release`, which
@@ -50,5 +50,5 @@ Gem::Specification.new do |spec|
50
50
  spec.add_development_dependency 'simplecov'
51
51
  spec.add_development_dependency 'sqlite3'
52
52
  spec.add_dependency 'rack', '~> 2.0.6'
53
- spec.add_dependency 'rails', '~> 5.2'
53
+ spec.add_dependency 'rails', '~> 5.2.2.1'
54
54
  end
@@ -1,171 +1 @@
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 let event = this.dispatch('initialize');\n if (!event.defaultPrevented) {\n const { detail } = event;\n const { id, file, iconContainer } = detail;\n Object(_helpers__WEBPACK_IMPORTED_MODULE_0__[\"fileUploadUIPainter\"])(iconContainer, id, file.name, false);\n }\n }\n\n start(callback) {\n this.upload.create((error, blob) => {\n if (error) {\n // Handle the error\n this.dispatchError(error);\n callback(error);\n } else {\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 let event = this.dispatch('end');\n Object(_helpers__WEBPACK_IMPORTED_MODULE_0__[\"defaultEndEventUI\"])(event);\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 Object(_helpers__WEBPACK_IMPORTED_MODULE_0__[\"defaultErrorEventUI\"])(event);\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 let event = this.dispatch('progress', { progress });\n if (!event.defaultPrevented) {\n const { id, progress } = event.detail;\n const progressElement = document.getElementById(`direct-upload-progress-${id}`);\n progressElement.style.width = `${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, defaultErrorEventUI, defaultEndEventUI, hasClassnameInHeirarchy, getClassnameFromHeirarchy, fileUploadUIPainter */
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__, \"defaultErrorEventUI\", function() { return defaultErrorEventUI; });\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"defaultEndEventUI\", function() { return defaultEndEventUI; });\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/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"fileUploadUIPainter\", function() { return fileUploadUIPainter; });\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 defaultErrorEventUI(event) {\n if (!event.defaultPrevented) {\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}\n\nfunction defaultEndEventUI(event) {\n if (!event.defaultPrevented) {\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\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 }\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 }\n}\n\nfunction fileUploadUIPainter(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\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//# 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 processUploadQueue(event) {\n const form = event.target;\n const { callback } = event.detail;\n const nextUpload = new _upload_queue_processor__WEBPACK_IMPORTED_MODULE_0__[\"UploadQueueProcessor\"](form);\n if (nextUpload.current_uploaders.length > 0) {\n nextUpload.start(error => {\n if (error) {\n callback(error);\n } else {\n callback();\n }\n });\n } else {\n callback();\n }\n}\n\nfunction handleFormSubmissionEvent(event) {\n if (formSubmitted) {\n return;\n }\n formSubmitted = true;\n const form = event.target;\n const nextUpload = 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 (nextUpload.current_uploaders.length > 0) {\n // inputs.forEach(disable)\n event.preventDefault();\n nextUpload.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 document.querySelectorAll(\"input[type='hidden'][data-direct-upload-id][data-uploaded-file-name]\").forEach(uploadedFile => {\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 let event = _helpers__WEBPACK_IMPORTED_MODULE_1__[\"dispatchEvent\"](uploadedFile, 'dnd-upload:placeholder', { detail });\n if (!event.defaultPrevented) {\n const { detail } = event;\n const { id, fileName, iconContainer } = detail;\n _helpers__WEBPACK_IMPORTED_MODULE_1__[\"fileUploadUIPainter\"](iconContainer, id, fileName, true);\n }\n });\n}\n\nfunction createUploadersForFileInput(event) {\n if (event.target.type === 'file' && event.target.dataset.dnd === 'true') {\n const input = event.target;\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\nfunction preventDragover(event) {\n if (_helpers__WEBPACK_IMPORTED_MODULE_1__[\"hasClassnameInHeirarchy\"](event.target, 'asdndzone')) {\n event.preventDefault();\n }\n}\n\nfunction createUploadersForDroppedFiles(event) {\n let asdndz = _helpers__WEBPACK_IMPORTED_MODULE_1__[\"getClassnameFromHeirarchy\"](event.target, 'asdndzone');\n if (asdndz) {\n event.preventDefault();\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\nfunction removeFileFromQueue(event) {\n if (event.target.dataset.dndDelete === 'true' && event.target.hasAttribute('data-direct-upload-id')) {\n event.preventDefault();\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\nfunction start() {\n if (started) {\n return;\n }\n started = true;\n document.addEventListener('submit', didSubmitForm);\n document.addEventListener('ajax:before', didSubmitRemoteElement);\n document.addEventListener('dnd-uploads:process-upload-queue', processUploadQueue);\n\n // input[type=file][data-dnd=true]\n document.addEventListener('change', createUploadersForFileInput);\n document.addEventListener('dragover', preventDragover);\n document.addEventListener('drop', createUploadersForDroppedFiles);\n document.addEventListener('click', removeFileFromQueue);\n 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\nclass ValidationError extends Error {\n constructor(...args) {\n super(...args);\n Error.captureStackTrace(this, ValidationError);\n }\n}\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 this.dispatchError(error);\n callback(error);\n } else {\n startNextUploader();\n }\n });\n } else {\n callback();\n let event = this.dispatch('end');\n Object(_helpers__WEBPACK_IMPORTED_MODULE_0__[\"defaultEndEventUI\"])(event);\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, `dnd-uploads:${name}`, { detail });\n }\n\n dispatchError(error) {\n const event = this.dispatch('error', { error });\n Object(_helpers__WEBPACK_IMPORTED_MODULE_0__[\"defaultErrorEventUI\"])(event);\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 const error = validateUploader(input, file);\n if (error) {\n let detail = {\n id: null,\n file: file,\n iconContainer: input.dataset.iconContainerId,\n error: error\n };\n return dispatchErrorWithoutAttachment(input, detail);\n }\n if (!input.multiple) {\n removeAttachedFiles(input);\n }\n uploaders.push(new _direct_upload_controller__WEBPACK_IMPORTED_MODULE_1__[\"DragAndDropUploadController\"](input, file));\n}\n\nfunction removeAttachedFiles(input) {\n input.closest('label.asdndzone').querySelectorAll('[data-direct-upload-id]').forEach(element => {\n element.remove();\n });\n uploaders.splice(0, uploaders.length);\n}\n\nfunction dispatchErrorWithoutAttachment(input, detail) {\n let event = Object(_helpers__WEBPACK_IMPORTED_MODULE_0__[\"dispatchEvent\"])(input, 'dnd-upload:error', { detail });\n if (!event.defaultPrevented) {\n const { error, iconContainer, file } = event.detail;\n Object(_helpers__WEBPACK_IMPORTED_MODULE_0__[\"fileUploadUIPainter\"])(iconContainer, 'error', file.name, true);\n const element = document.getElementById(`direct-upload-error`);\n element.classList.add('direct-upload--error');\n element.setAttribute('title', error);\n }\n return event;\n}\n\nfunction validateUploader(input, file) {\n const sizeLimit = input.getAttribute('size_limit');\n if (input.accept !== '' && !input.accept.split(', ').includes(file.type)) {\n return new ValidationError('Invalid filetype');\n } else if (sizeLimit && file.size > sizeLimit) {\n return new ValidationError(`File too large. Can be no larger than ${humanFileSize(sizeLimit)}`);\n }\n}\n\nfunction humanFileSize(bytes) {\n var thresh = 1000;\n if (Math.abs(bytes) < thresh) {\n return bytes + ' B';\n }\n var units = ['kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];\n var u = -1;\n do {\n bytes /= thresh;\n ++u;\n } while (Math.abs(bytes) >= thresh && u < units.length - 1);\n return bytes.toFixed(1) + ' ' + units[u];\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
- });
1
+ !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.ActiveStorageDragAndDrop=t():e.ActiveStorageDragAndDrop=t()}(window,function(){return function(e){var t={};function r(n){if(t[n])return t[n].exports;var i=t[n]={i:n,l:!1,exports:{}};return e[n].call(i.exports,i,i.exports,r),i.l=!0,i.exports}return r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var i in e)r.d(n,i,function(t){return e[t]}.bind(null,i));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=2)}([function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.dispatchEvent=function(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},n=r.bubbles,i=void 0===n||n,o=r.cancelable,a=void 0===o||o,u=r.detail,s=void 0===u?{}:u,l=new CustomEvent(t,{bubbles:i,cancelable:a,detail:s});return e.dispatchEvent(l),l},t.fileSizeSI=function(e){var t=Math.log(e)/Math.log(1e3)|0;return(e/Math.pow(1e3,t)+.5|0)+(t?"kMGTPEZY"[--t]+"B":" Bytes")}},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.errorUI=function(e){var t=e.detail.id,r=e.detail,n=r.error,i=r.iconContainer,o=r.file;if(e.defaultPrevented)return;t||(t="error",window.ActiveStorageDragAndDrop.paintUploadIcon(i,t,o,!1));var a=document.querySelector('[data-direct-upload-id="'+t+'"] .direct-upload');if(!a)return;a.setAttribute("title",n),a.classList.add("direct-upload--error")},t.endUI=function(e){var t=e.detail.id;if(!t||e.defaultPrevented)return;var r=document.querySelector('[data-direct-upload-id="'+t+'"] .direct-upload');if(!r)return;var n=r.classList;n.remove("direct-upload--pending"),n.add("direct-upload--complete")},t.initializeUI=function(e){if(e.defaultPrevented)return;var t=e.detail,r=t.id,n=t.file,i=t.iconContainer;window.ActiveStorageDragAndDrop.paintUploadIcon(i,r,n,!1)},t.progressUI=function(e){if(e.defaultPrevented)return;var t=e.detail,r=t.id,n=t.progress,i=document.querySelector('[data-direct-upload-id="'+r+'"] .direct-upload__progress');i&&(i.style.width=n+"%")},t.placeholderUI=function(e){if(e.defaultPrevented)return;var t=e.detail,r=t.id,n=t.file,i=t.iconContainer;window.ActiveStorageDragAndDrop.paintUploadIcon(i,r,n,!0)},t.cancelUI=function(e){if(e.defaultPrevented)return;var t=e.detail.id;document.querySelectorAll('[data-direct-upload-id="'+t+'"]').forEach(function(e){e.remove()})},t.paintUploadIcon=function(e,t,r,i){var o=i?"complete":"pending",a=i?100:0;e.insertAdjacentHTML("beforeend",'\n <div data-direct-upload-id="'+t+'">\n <div class="direct-upload direct-upload--'+o+'">\n <div class="direct-upload__progress" style="width: '+a+'%"></div>\n <span class="direct-upload__filename">'+r.name+'</span>\n <span class="direct-upload__filesize">'+(0,n.fileSizeSI)(r.size)+"</span>\n </div>\n <a href='remove' class='direct-upload__remove'>X</a>\n </div>\n ")};var n=r(0)},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.processUploadQueue=t.paintUploadIcon=t.start=void 0;var n=r(3),i=r(1);t.start=n.start,t.paintUploadIcon=i.paintUploadIcon,t.processUploadQueue=n.processUploadQueue,setTimeout(function(){(0,n.start)()},1)},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.formSubmitted=void 0,t.handleProcessUploadQueueEvent=s,t.processUploadQueue=l,t.addAttachedFileIcons=d,t.preventDragover=c,t.handleSubmit=f,t.removeFileFromQueue=h,t.queueUploadsForFileInput=p,t.queueUploadsForDroppedFiles=v,t.start=function(){if(a)return;a=!0,document.addEventListener("change",p),document.addEventListener("click",h),document.addEventListener("drop",v,!0),document.addEventListener("submit",f),document.addEventListener("dnd-uploads:process-upload-queue",s),document.addEventListener("ajax:before",f),document.addEventListener("dragover",c),d()},t.findOrInitializeFormController=y;var n=r(4),i=r(1),o=r(0),a=!1,u=(t.formSubmitted=!1,new Map);function s(e){console.warn("WARNING! The processs-upload-queue event is deprecated. Call window.ActiveStorageDragAndDrop.processUploadQueue(form, callback) instead.");var t=e.detail.callback;l(e.target,t)}function l(e,t){y(e).start(function(e){t(e)})}function d(){document.querySelectorAll("input[type='hidden'][data-direct-upload-id][data-uploaded-file]").forEach(function(e){var t=e.dataset,r={id:t.directUploadId,file:JSON.parse(t.uploadedFile),iconContainer:document.getElementById(t.iconContainerId)},n=(0,o.dispatchEvent)(e,"dnd-upload:placeholder",{detail:r});(0,i.placeholderUI)(n)})}function c(e){var t=e.target;t instanceof Element&&t.closest(".asdndzone")&&e.preventDefault()}function f(e){if(!this.formSubmitted){this.formSubmitted=!0;var t=y(e.target);0!==t.uploadControllers.length&&(e.preventDefault(),t.start(function(e){e||t.form.submit()}))}}function h(e){var t=e.target;if(t instanceof HTMLElement&&t.classList.contains("direct-upload__remove")){var r=t.closest("[data-direct-upload-id]");if(!(r instanceof HTMLElement))throw new Error("Cannot remove queued upload because there is no enclosing element with a data-direct-upload-id attribute.");e.preventDefault(),y(t.closest("form")).unqueueUpload(parseInt(r.dataset.directUploadId))}}function p(e){var t=e.target;if(t instanceof HTMLInputElement&&"file"===t.type&&"true"===t.dataset.dnd){var r=y(t.form);Array.from(t.files).forEach(function(e){return r.queueUpload(t,e)}),t.value=""}}function v(e){var t=e.target,r=e.dataTransfer;if(t instanceof Element&&r instanceof DataTransfer){var n=t.closest(".asdndzone");if(n instanceof HTMLElement){var i=document.getElementById(n.dataset.dndInputId);if(!(i instanceof HTMLInputElement))throw new Error("There is no file input element with the dnd-input-id specified on the drop zone.");e.preventDefault();var o=y(i.form);Array.from(r.files).forEach(function(e){return o.queueUpload(i,e)})}}}function y(e){var t=u.get(e);if(t)return t;if(!(e instanceof HTMLFormElement))throw new Error("Can only initialize form controller with a form element.");return t=new n.DragAndDropFormController(e),u.set(e,t),t}},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.DragAndDropFormController=void 0;var n=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}(),i=r(0),o=r(1),a=r(5);t.DragAndDropFormController=function(){function e(t){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.form=t,this.uploadControllers=[]}return n(e,[{key:"start",value:function(e){var t=this;this.dispatch("start"),function r(){var n=t.uploadControllers.shift();if(n)n.start(function(i){i?(t.dispatchError(i,n),e(i)):r()});else{e();var i=t.dispatch("end");(0,o.endUI)(i)}}()}},{key:"dispatch",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return(0,i.dispatchEvent)(this.form,"dnd-uploads:"+e,{detail:t})}},{key:"dispatchError",value:function(e,t){var r=t.file,n=t.iconContainer,a=(0,i.dispatchEvent)(this.form,"dnd-upload:error",{detail:{error:e,file:r,iconContainer:n}});(0,o.errorUI)(a)}},{key:"queueUpload",value:function(e,t){e.getAttribute("multiple")||this.unqueueUploadsPerInput(e);try{this.uploadControllers.push(new a.DragAndDropUploadController(e,t))}catch(r){!function(e,t){var r=(0,i.dispatchEvent)(e,"dnd-upload:error",{detail:t});(0,o.errorUI)(r)}(e,{id:null,file:t,error:r,iconContainer:document.getElementById(e.dataset.iconContainerId)})}}},{key:"unqueueUploadsPerInput",value:function(e){var t=e.closest("label.asdndzone");t&&(t.querySelectorAll("[data-direct-upload-id]").forEach(function(e){e.remove()}),this.uploadControllers.splice(0,this.uploadControllers.length))}},{key:"unqueueUpload",value:function(e){var t=this.uploadControllers.findIndex(function(t){return t.upload.id===e}),r=this.uploadControllers[t];this.uploadControllers.splice(t,1);var n=r&&r.dispatch instanceof Function?r.dispatch("cancel"):this.dispatch("cancel",{id:"error"});(0,o.cancelUI)(n)}}]),e}()},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.DragAndDropUploadController=void 0;var n=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}(),i=r(0),o=r(1),a=r(6);function u(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}t.DragAndDropUploadController=function(){function e(t,r){u(this,e),function(e,t){var r=parseInt(e.getAttribute("size_limit")),n=e.getAttribute("accept");if(n&&!n.split(", ").includes(t.type))throw new s("Invalid filetype");if(r&&t.size>r)throw new s("File too large. Can be no larger than "+(0,i.fileSizeSI)(r))}(t,r);var n=t.closest("form"),l=document.getElementById(t.dataset.iconContainerId);if(n instanceof HTMLFormElement&&l){this.input=t,this.form=n,this.url=this.input.dataset.directUploadUrl,this.iconContainer=l,this.file=r,this.upload=new a.DirectUpload(this.file,this.url,this);var d=this.dispatch("initialize");(0,o.initializeUI)(d)}}return n(e,[{key:"start",value:function(e){var t=this;this.dispatch("start"),this.upload.create(function(r,n){if(r)t.dispatchError(r),e(r);else{var i=document.createElement("input");i.setAttribute("type","hidden"),i.setAttribute("value",n.signed_id),i.setAttribute("name",t.input.getAttribute("name")||""),i.setAttribute("data-direct-upload-id",t.upload.id),t.form.appendChild(i);var a=t.dispatch("end");(0,o.endUI)(a),e(r)}})}},{key:"dispatch",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return t.file=this.file,t.id=this.upload.id,t.iconContainer=this.iconContainer,(0,i.dispatchEvent)(this.input,"dnd-upload:"+e,{detail:t})}},{key:"dispatchError",value:function(e){var t=this.dispatch("error",{error:e});(0,o.errorUI)(t)}},{key:"directUploadWillCreateBlobWithXHR",value:function(e){this.dispatch("before-blob-request",{xhr:e})}},{key:"directUploadWillStoreFileWithXHR",value:function(e){var t=this;this.dispatch("before-storage-request",{xhr:e}),e.upload.addEventListener("progress",function(e){return t.uploadRequestDidProgress(e)})}},{key:"uploadRequestDidProgress",value:function(e){var t=e.loaded/e.total*100;if(t){var r=this.dispatch("progress",{progress:t});(0,o.progressUI)(r)}}}]),e}();var s=function(e){function t(){var e;u(this,t);for(var r=arguments.length,n=Array(r),i=0;i<r;i++)n[i]=arguments[i];var o=function(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}(this,(e=t.__proto__||Object.getPrototypeOf(t)).call.apply(e,[this].concat(n)));return Error.captureStackTrace(o,t),o}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}(t,Error),t}()},function(e,t,r){!function(e){"use strict";var t,r=(function(e,t){e.exports=function(e){var t=["0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f"];function r(e,t){var r=e[0],n=e[1],i=e[2],o=e[3];r+=(n&i|~n&o)+t[0]-680876936|0,o+=((r=(r<<7|r>>>25)+n|0)&n|~r&i)+t[1]-389564586|0,i+=((o=(o<<12|o>>>20)+r|0)&r|~o&n)+t[2]+606105819|0,n+=((i=(i<<17|i>>>15)+o|0)&o|~i&r)+t[3]-1044525330|0,r+=((n=(n<<22|n>>>10)+i|0)&i|~n&o)+t[4]-176418897|0,o+=((r=(r<<7|r>>>25)+n|0)&n|~r&i)+t[5]+1200080426|0,i+=((o=(o<<12|o>>>20)+r|0)&r|~o&n)+t[6]-1473231341|0,n+=((i=(i<<17|i>>>15)+o|0)&o|~i&r)+t[7]-45705983|0,r+=((n=(n<<22|n>>>10)+i|0)&i|~n&o)+t[8]+1770035416|0,o+=((r=(r<<7|r>>>25)+n|0)&n|~r&i)+t[9]-1958414417|0,i+=((o=(o<<12|o>>>20)+r|0)&r|~o&n)+t[10]-42063|0,n+=((i=(i<<17|i>>>15)+o|0)&o|~i&r)+t[11]-1990404162|0,r+=((n=(n<<22|n>>>10)+i|0)&i|~n&o)+t[12]+1804603682|0,o+=((r=(r<<7|r>>>25)+n|0)&n|~r&i)+t[13]-40341101|0,i+=((o=(o<<12|o>>>20)+r|0)&r|~o&n)+t[14]-1502002290|0,n+=((i=(i<<17|i>>>15)+o|0)&o|~i&r)+t[15]+1236535329|0,r+=((n=(n<<22|n>>>10)+i|0)&o|i&~o)+t[1]-165796510|0,o+=((r=(r<<5|r>>>27)+n|0)&i|n&~i)+t[6]-1069501632|0,i+=((o=(o<<9|o>>>23)+r|0)&n|r&~n)+t[11]+643717713|0,n+=((i=(i<<14|i>>>18)+o|0)&r|o&~r)+t[0]-373897302|0,r+=((n=(n<<20|n>>>12)+i|0)&o|i&~o)+t[5]-701558691|0,o+=((r=(r<<5|r>>>27)+n|0)&i|n&~i)+t[10]+38016083|0,i+=((o=(o<<9|o>>>23)+r|0)&n|r&~n)+t[15]-660478335|0,n+=((i=(i<<14|i>>>18)+o|0)&r|o&~r)+t[4]-405537848|0,r+=((n=(n<<20|n>>>12)+i|0)&o|i&~o)+t[9]+568446438|0,o+=((r=(r<<5|r>>>27)+n|0)&i|n&~i)+t[14]-1019803690|0,i+=((o=(o<<9|o>>>23)+r|0)&n|r&~n)+t[3]-187363961|0,n+=((i=(i<<14|i>>>18)+o|0)&r|o&~r)+t[8]+1163531501|0,r+=((n=(n<<20|n>>>12)+i|0)&o|i&~o)+t[13]-1444681467|0,o+=((r=(r<<5|r>>>27)+n|0)&i|n&~i)+t[2]-51403784|0,i+=((o=(o<<9|o>>>23)+r|0)&n|r&~n)+t[7]+1735328473|0,n+=((i=(i<<14|i>>>18)+o|0)&r|o&~r)+t[12]-1926607734|0,r+=((n=(n<<20|n>>>12)+i|0)^i^o)+t[5]-378558|0,o+=((r=(r<<4|r>>>28)+n|0)^n^i)+t[8]-2022574463|0,i+=((o=(o<<11|o>>>21)+r|0)^r^n)+t[11]+1839030562|0,n+=((i=(i<<16|i>>>16)+o|0)^o^r)+t[14]-35309556|0,r+=((n=(n<<23|n>>>9)+i|0)^i^o)+t[1]-1530992060|0,o+=((r=(r<<4|r>>>28)+n|0)^n^i)+t[4]+1272893353|0,i+=((o=(o<<11|o>>>21)+r|0)^r^n)+t[7]-155497632|0,n+=((i=(i<<16|i>>>16)+o|0)^o^r)+t[10]-1094730640|0,r+=((n=(n<<23|n>>>9)+i|0)^i^o)+t[13]+681279174|0,o+=((r=(r<<4|r>>>28)+n|0)^n^i)+t[0]-358537222|0,i+=((o=(o<<11|o>>>21)+r|0)^r^n)+t[3]-722521979|0,n+=((i=(i<<16|i>>>16)+o|0)^o^r)+t[6]+76029189|0,r+=((n=(n<<23|n>>>9)+i|0)^i^o)+t[9]-640364487|0,o+=((r=(r<<4|r>>>28)+n|0)^n^i)+t[12]-421815835|0,i+=((o=(o<<11|o>>>21)+r|0)^r^n)+t[15]+530742520|0,n+=((i=(i<<16|i>>>16)+o|0)^o^r)+t[2]-995338651|0,r+=(i^((n=(n<<23|n>>>9)+i|0)|~o))+t[0]-198630844|0,o+=(n^((r=(r<<6|r>>>26)+n|0)|~i))+t[7]+1126891415|0,i+=(r^((o=(o<<10|o>>>22)+r|0)|~n))+t[14]-1416354905|0,n+=(o^((i=(i<<15|i>>>17)+o|0)|~r))+t[5]-57434055|0,r+=(i^((n=(n<<21|n>>>11)+i|0)|~o))+t[12]+1700485571|0,o+=(n^((r=(r<<6|r>>>26)+n|0)|~i))+t[3]-1894986606|0,i+=(r^((o=(o<<10|o>>>22)+r|0)|~n))+t[10]-1051523|0,n+=(o^((i=(i<<15|i>>>17)+o|0)|~r))+t[1]-2054922799|0,r+=(i^((n=(n<<21|n>>>11)+i|0)|~o))+t[8]+1873313359|0,o+=(n^((r=(r<<6|r>>>26)+n|0)|~i))+t[15]-30611744|0,i+=(r^((o=(o<<10|o>>>22)+r|0)|~n))+t[6]-1560198380|0,n+=(o^((i=(i<<15|i>>>17)+o|0)|~r))+t[13]+1309151649|0,r+=(i^((n=(n<<21|n>>>11)+i|0)|~o))+t[4]-145523070|0,o+=(n^((r=(r<<6|r>>>26)+n|0)|~i))+t[11]-1120210379|0,i+=(r^((o=(o<<10|o>>>22)+r|0)|~n))+t[2]+718787259|0,n=((n+=(o^((i=(i<<15|i>>>17)+o|0)|~r))+t[9]-343485551|0)<<21|n>>>11)+i|0,e[0]=r+e[0]|0,e[1]=n+e[1]|0,e[2]=i+e[2]|0,e[3]=o+e[3]|0}function n(e){var t,r=[];for(t=0;t<64;t+=4)r[t>>2]=e.charCodeAt(t)+(e.charCodeAt(t+1)<<8)+(e.charCodeAt(t+2)<<16)+(e.charCodeAt(t+3)<<24);return r}function i(e){var t,r=[];for(t=0;t<64;t+=4)r[t>>2]=e[t]+(e[t+1]<<8)+(e[t+2]<<16)+(e[t+3]<<24);return r}function o(e){var t,i,o,a,u,s,l=e.length,d=[1732584193,-271733879,-1732584194,271733878];for(t=64;t<=l;t+=64)r(d,n(e.substring(t-64,t)));for(e=e.substring(t-64),i=e.length,o=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],t=0;t<i;t+=1)o[t>>2]|=e.charCodeAt(t)<<(t%4<<3);if(o[t>>2]|=128<<(t%4<<3),t>55)for(r(d,o),t=0;t<16;t+=1)o[t]=0;return a=(a=8*l).toString(16).match(/(.*?)(.{0,8})$/),u=parseInt(a[2],16),s=parseInt(a[1],16)||0,o[14]=u,o[15]=s,r(d,o),d}function a(e){var r,n="";for(r=0;r<4;r+=1)n+=t[e>>8*r+4&15]+t[e>>8*r&15];return n}function u(e){var t;for(t=0;t<e.length;t+=1)e[t]=a(e[t]);return e.join("")}function s(e){return/[\u0080-\uFFFF]/.test(e)&&(e=unescape(encodeURIComponent(e))),e}function l(e){var t,r=[],n=e.length;for(t=0;t<n-1;t+=2)r.push(parseInt(e.substr(t,2),16));return String.fromCharCode.apply(String,r)}function d(){this.reset()}return u(o("hello")),"undefined"==typeof ArrayBuffer||ArrayBuffer.prototype.slice||function(){function t(e,t){return(e=0|e||0)<0?Math.max(e+t,0):Math.min(e,t)}ArrayBuffer.prototype.slice=function(r,n){var i,o,a,u,s=this.byteLength,l=t(r,s),d=s;return n!==e&&(d=t(n,s)),l>d?new ArrayBuffer(0):(i=d-l,o=new ArrayBuffer(i),a=new Uint8Array(o),u=new Uint8Array(this,l,i),a.set(u),o)}}(),d.prototype.append=function(e){return this.appendBinary(s(e)),this},d.prototype.appendBinary=function(e){this._buff+=e,this._length+=e.length;var t,i=this._buff.length;for(t=64;t<=i;t+=64)r(this._hash,n(this._buff.substring(t-64,t)));return this._buff=this._buff.substring(t-64),this},d.prototype.end=function(e){var t,r,n=this._buff,i=n.length,o=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];for(t=0;t<i;t+=1)o[t>>2]|=n.charCodeAt(t)<<(t%4<<3);return this._finish(o,i),r=u(this._hash),e&&(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(e){return this._buff=e.buff,this._length=e.length,this._hash=e.hash,this},d.prototype.destroy=function(){delete this._hash,delete this._buff,delete this._length},d.prototype._finish=function(e,t){var n,i,o,a=t;if(e[a>>2]|=128<<(a%4<<3),a>55)for(r(this._hash,e),a=0;a<16;a+=1)e[a]=0;n=(n=8*this._length).toString(16).match(/(.*?)(.{0,8})$/),i=parseInt(n[2],16),o=parseInt(n[1],16)||0,e[14]=i,e[15]=o,r(this._hash,e)},d.hash=function(e,t){return d.hashBinary(s(e),t)},d.hashBinary=function(e,t){var r=u(o(e));return t?l(r):r},d.ArrayBuffer=function(){this.reset()},d.ArrayBuffer.prototype.append=function(e){var t,n,o,a,u,s=(n=this._buff.buffer,o=e,a=!0,(u=new Uint8Array(n.byteLength+o.byteLength)).set(new Uint8Array(n)),u.set(new Uint8Array(o),n.byteLength),a?u:u.buffer),l=s.length;for(this._length+=e.byteLength,t=64;t<=l;t+=64)r(this._hash,i(s.subarray(t-64,t)));return this._buff=t-64<l?new Uint8Array(s.buffer.slice(t-64)):new Uint8Array(0),this},d.ArrayBuffer.prototype.end=function(e){var t,r,n=this._buff,i=n.length,o=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];for(t=0;t<i;t+=1)o[t>>2]|=n[t]<<(t%4<<3);return this._finish(o,i),r=u(this._hash),e&&(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 e,t=d.prototype.getState.call(this);return t.buff=(e=t.buff,String.fromCharCode.apply(null,new Uint8Array(e))),t},d.ArrayBuffer.prototype.setState=function(e){return e.buff=function(e,t){var r,n=e.length,i=new ArrayBuffer(n),o=new Uint8Array(i);for(r=0;r<n;r+=1)o[r]=e.charCodeAt(r);return t?o:i}(e.buff,!0),d.prototype.setState.call(this,e)},d.ArrayBuffer.prototype.destroy=d.prototype.destroy,d.ArrayBuffer.prototype._finish=d.prototype._finish,d.ArrayBuffer.hash=function(e,t){var n=u(function(e){var t,n,o,a,u,s,l=e.length,d=[1732584193,-271733879,-1732584194,271733878];for(t=64;t<=l;t+=64)r(d,i(e.subarray(t-64,t)));for(e=t-64<l?e.subarray(t-64):new Uint8Array(0),n=e.length,o=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],t=0;t<n;t+=1)o[t>>2]|=e[t]<<(t%4<<3);if(o[t>>2]|=128<<(t%4<<3),t>55)for(r(d,o),t=0;t<16;t+=1)o[t]=0;return a=(a=8*l).toString(16).match(/(.*?)(.{0,8})$/),u=parseInt(a[2],16),s=parseInt(a[1],16)||0,o[14]=u,o[15]=s,r(d,o),d}(new Uint8Array(e)));return t?l(n):n},d}()}(t={exports:{}},t.exports),t.exports),n=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},i=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}(),o=File.prototype.slice||File.prototype.mozSlice||File.prototype.webkitSlice,a=function(){function e(t){n(this,e),this.file=t,this.chunkSize=2097152,this.chunkCount=Math.ceil(this.file.size/this.chunkSize),this.chunkIndex=0}return i(e,null,[{key:"create",value:function(t,r){var n=new e(t);n.create(r)}}]),i(e,[{key:"create",value:function(e){var t=this;this.callback=e,this.md5Buffer=new r.ArrayBuffer,this.fileReader=new FileReader,this.fileReader.addEventListener("load",function(e){return t.fileReaderDidLoad(e)}),this.fileReader.addEventListener("error",function(e){return t.fileReaderDidError(e)}),this.readNextChunk()}},{key:"fileReaderDidLoad",value:function(e){if(this.md5Buffer.append(e.target.result),!this.readNextChunk()){var t=this.md5Buffer.end(!0),r=btoa(t);this.callback(null,r)}}},{key:"fileReaderDidError",value:function(e){this.callback("Error reading "+this.file.name)}},{key:"readNextChunk",value:function(){if(this.chunkIndex<this.chunkCount||0==this.chunkIndex&&0==this.chunkCount){var e=this.chunkIndex*this.chunkSize,t=Math.min(e+this.chunkSize,this.file.size),r=o.call(this.file,e,t);return this.fileReader.readAsArrayBuffer(r),this.chunkIndex++,!0}return!1}}]),e}();function u(e,t){return"string"==typeof e&&(t=e,e=document),e.querySelector(t)}function s(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},n=e.disabled,i=r.bubbles,o=r.cancelable,a=r.detail,u=document.createEvent("Event");u.initEvent(t,i||!0,o||!0),u.detail=a||{};try{e.disabled=!1,e.dispatchEvent(u)}finally{e.disabled=n}return u}function l(e){return Array.isArray(e)?e:Array.from?Array.from(e):[].slice.call(e)}var d=function(){function e(t,r,i){var o=this;n(this,e),this.file=t,this.attributes={filename:t.name,content_type:t.type,byte_size:t.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",function(e){var t=u(document.head,'meta[name="'+e+'"]');if(t)return t.getAttribute("content")}("csrf-token")),this.xhr.addEventListener("load",function(e){return o.requestDidLoad(e)}),this.xhr.addEventListener("error",function(e){return o.requestDidError(e)})}return i(e,[{key:"create",value:function(e){this.callback=e,this.xhr.send(JSON.stringify({blob:this.attributes}))}},{key:"requestDidLoad",value:function(e){if(this.status>=200&&this.status<300){var t=this.response,r=t.direct_upload;delete t.direct_upload,this.attributes=t,this.directUploadData=r,this.callback(null,this.toJSON())}else this.requestDidError(e)}},{key:"requestDidError",value:function(e){this.callback('Error creating Blob for "'+this.file.name+'". Status: '+this.status)}},{key:"toJSON",value:function(){var e={};for(var t in this.attributes)e[t]=this.attributes[t];return e}},{key:"status",get:function(){return this.xhr.status}},{key:"response",get:function(){var e=this.xhr,t=e.responseType,r=e.response;return"json"==t?r:JSON.parse(r)}}]),e}(),c=function(){function e(t){var r=this;n(this,e),this.blob=t,this.file=t.file;var i=t.directUploadData,o=i.url,a=i.headers;for(var u in this.xhr=new XMLHttpRequest,this.xhr.open("PUT",o,!0),this.xhr.responseType="text",a)this.xhr.setRequestHeader(u,a[u]);this.xhr.addEventListener("load",function(e){return r.requestDidLoad(e)}),this.xhr.addEventListener("error",function(e){return r.requestDidError(e)})}return i(e,[{key:"create",value:function(e){this.callback=e,this.xhr.send(this.file.slice())}},{key:"requestDidLoad",value:function(e){var t=this.xhr,r=t.status,n=t.response;r>=200&&r<300?this.callback(null,n):this.requestDidError(e)}},{key:"requestDidError",value:function(e){this.callback('Error storing "'+this.file.name+'". Status: '+this.xhr.status)}}]),e}(),f=0,h=function(){function e(t,r,i){n(this,e),this.id=++f,this.file=t,this.url=r,this.delegate=i}return i(e,[{key:"create",value:function(e){var t=this;a.create(this.file,function(r,n){if(r)e(r);else{var i=new d(t.file,n,t.url);p(t.delegate,"directUploadWillCreateBlobWithXHR",i.xhr),i.create(function(r){if(r)e(r);else{var n=new c(i);p(t.delegate,"directUploadWillStoreFileWithXHR",n.xhr),n.create(function(t){t?e(t):e(null,i.toJSON())})}})}})}}]),e}();function p(e,t){if(e&&"function"==typeof e[t]){for(var r=arguments.length,n=Array(r>2?r-2:0),i=2;i<r;i++)n[i-2]=arguments[i];return e[t].apply(e,n)}}var v=function(){function e(t,r){n(this,e),this.input=t,this.file=r,this.directUpload=new h(this.file,this.url,this),this.dispatch("initialize")}return i(e,[{key:"start",value:function(e){var t=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),t.dispatchError(n)):r.value=i.signed_id,t.dispatch("end"),e(n)})}},{key:"uploadRequestDidProgress",value:function(e){var t=e.loaded/e.total*100;t&&this.dispatch("progress",{progress:t})}},{key:"dispatch",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return t.file=this.file,t.id=this.directUpload.id,s(this.input,"direct-upload:"+e,{detail:t})}},{key:"dispatchError",value:function(e){var t=this.dispatch("error",{error:e});t.defaultPrevented||alert(e)}},{key:"directUploadWillCreateBlobWithXHR",value:function(e){this.dispatch("before-blob-request",{xhr:e})}},{key:"directUploadWillStoreFileWithXHR",value:function(e){var t=this;this.dispatch("before-storage-request",{xhr:e}),e.upload.addEventListener("progress",function(e){return t.uploadRequestDidProgress(e)})}},{key:"url",get:function(){return this.input.getAttribute("data-direct-upload-url")}}]),e}(),y="input[type=file][data-direct-upload-url]:not([disabled])",b=function(){function e(t){var r,i;n(this,e),this.form=t,this.inputs=(r=t,i=y,"string"==typeof r&&(i=r,r=document),l(r.querySelectorAll(i))).filter(function(e){return e.files.length})}return i(e,[{key:"start",value:function(e){var t=this,r=this.createDirectUploadControllers();this.dispatch("start"),function n(){var i=r.shift();i?i.start(function(r){r?(e(r),t.dispatch("end")):n()}):(e(),t.dispatch("end"))}()}},{key:"createDirectUploadControllers",value:function(){var e=[];return this.inputs.forEach(function(t){l(t.files).forEach(function(r){var n=new v(t,r);e.push(n)})}),e}},{key:"dispatch",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return s(this.form,"direct-uploads:"+e,{detail:t})}}]),e}(),m="data-direct-uploads-processing",g=new WeakMap,A=!1;function E(){A||(A=!0,document.addEventListener("click",_,!0),document.addEventListener("submit",k),document.addEventListener("ajax:before",w))}function _(e){var t=e.target;"INPUT"!=t.tagName&&"BUTTON"!=t.tagName||"submit"!=t.type||!t.form||g.set(t.form,t)}function k(e){U(e)}function w(e){"FORM"==e.target.tagName&&U(e)}function U(e){var t=e.target;if(t.hasAttribute(m))e.preventDefault();else{var r=new b(t),n=r.inputs;n.length&&(e.preventDefault(),t.setAttribute(m,""),n.forEach(C),r.start(function(e){t.removeAttribute(m),e?n.forEach(S):function(e){var t=g.get(e)||u(e,"input[type=submit], button[type=submit]");if(t){var r=t,n=r.disabled;t.disabled=!1,t.focus(),t.click(),t.disabled=n}else(t=document.createElement("input")).type="submit",t.style.display="none",e.appendChild(t),t.click(),e.removeChild(t);g.delete(e)}(t)}))}}function C(e){e.disabled=!0}function S(e){e.disabled=!1}setTimeout(function(){window.ActiveStorage&&E()},1),e.start=E,e.DirectUpload=h,Object.defineProperty(e,"__esModule",{value:!0})}(t)}])});