@rails/activestorage 6.1.4-1 → 7.0.0-rc1

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.
package/package.json CHANGED
@@ -1,7 +1,8 @@
1
1
  {
2
2
  "name": "@rails/activestorage",
3
- "version": "6.1.4-1",
3
+ "version": "7.0.0-rc1",
4
4
  "description": "Attach cloud and local files in Rails applications",
5
+ "module": "app/assets/javascripts/activestorage.esm.js",
5
6
  "main": "app/assets/javascripts/activestorage.js",
6
7
  "files": [
7
8
  "app/assets/javascripts/*.js",
@@ -18,19 +19,15 @@
18
19
  "author": "Javan Makhmali <javan@javan.us>",
19
20
  "license": "MIT",
20
21
  "dependencies": {
21
- "spark-md5": "^3.0.0"
22
+ "spark-md5": "^3.0.1"
22
23
  },
23
24
  "devDependencies": {
24
- "babel-core": "^6.25.0",
25
- "babel-plugin-external-helpers": "^6.22.0",
26
- "babel-preset-env": "^1.6.0",
25
+ "@rollup/plugin-node-resolve": "^11.0.1",
26
+ "@rollup/plugin-commonjs": "^19.0.1",
27
27
  "eslint": "^4.3.0",
28
- "eslint-plugin-import": "^2.7.0",
29
- "rollup": "^0.58.2",
30
- "rollup-plugin-babel": "^3.0.4",
31
- "rollup-plugin-commonjs": "^9.1.0",
32
- "rollup-plugin-node-resolve": "^3.3.0",
33
- "rollup-plugin-uglify": "^3.0.0"
28
+ "eslint-plugin-import": "^2.23.4",
29
+ "rollup": "^2.35.1",
30
+ "rollup-plugin-terser": "^7.0.2"
34
31
  },
35
32
  "scripts": {
36
33
  "prebuild": "yarn lint",
@@ -1,16 +1,19 @@
1
1
  import { getMetaValue } from "./helpers"
2
2
 
3
3
  export class BlobRecord {
4
- constructor(file, checksum, url) {
4
+ constructor(file, checksum, url, directUploadToken, attachmentName) {
5
5
  this.file = file
6
6
 
7
7
  this.attributes = {
8
8
  filename: file.name,
9
9
  content_type: file.type || "application/octet-stream",
10
10
  byte_size: file.size,
11
- checksum: checksum
11
+ checksum: checksum,
12
12
  }
13
13
 
14
+ this.directUploadToken = directUploadToken
15
+ this.attachmentName = attachmentName
16
+
14
17
  this.xhr = new XMLHttpRequest
15
18
  this.xhr.open("POST", url, true)
16
19
  this.xhr.responseType = "json"
@@ -43,7 +46,11 @@ export class BlobRecord {
43
46
 
44
47
  create(callback) {
45
48
  this.callback = callback
46
- this.xhr.send(JSON.stringify({ blob: this.attributes }))
49
+ this.xhr.send(JSON.stringify({
50
+ blob: this.attributes,
51
+ direct_upload_token: this.directUploadToken,
52
+ attachment_name: this.attachmentName
53
+ }))
47
54
  }
48
55
 
49
56
  requestDidLoad(event) {
@@ -5,10 +5,12 @@ import { BlobUpload } from "./blob_upload"
5
5
  let id = 0
6
6
 
7
7
  export class DirectUpload {
8
- constructor(file, url, delegate) {
8
+ constructor(file, url, serviceName, attachmentName, delegate) {
9
9
  this.id = ++id
10
10
  this.file = file
11
11
  this.url = url
12
+ this.serviceName = serviceName
13
+ this.attachmentName = attachmentName
12
14
  this.delegate = delegate
13
15
  }
14
16
 
@@ -19,7 +21,7 @@ export class DirectUpload {
19
21
  return
20
22
  }
21
23
 
22
- const blob = new BlobRecord(this.file, checksum, this.url)
24
+ const blob = new BlobRecord(this.file, checksum, this.url, this.serviceName, this.attachmentName)
23
25
  notify(this.delegate, "directUploadWillCreateBlobWithXHR", blob.xhr)
24
26
 
25
27
  blob.create(error => {
@@ -5,7 +5,7 @@ export class DirectUploadController {
5
5
  constructor(input, file) {
6
6
  this.input = input
7
7
  this.file = file
8
- this.directUpload = new DirectUpload(this.file, this.url, this)
8
+ this.directUpload = new DirectUpload(this.file, this.url, this.directUploadToken, this.attachmentName, this)
9
9
  this.dispatch("initialize")
10
10
  }
11
11
 
@@ -41,6 +41,14 @@ export class DirectUploadController {
41
41
  return this.input.getAttribute("data-direct-upload-url")
42
42
  }
43
43
 
44
+ get directUploadToken() {
45
+ return this.input.getAttribute("data-direct-upload-token")
46
+ }
47
+
48
+ get attachmentName() {
49
+ return this.input.getAttribute("data-direct-upload-attachment-name")
50
+ }
51
+
44
52
  dispatch(name, detail = {}) {
45
53
  detail.file = this.file
46
54
  detail.id = this.directUpload.id
package/src/ujs.js CHANGED
@@ -9,7 +9,7 @@ export function start() {
9
9
  if (!started) {
10
10
  started = true
11
11
  document.addEventListener("click", didClick, true)
12
- document.addEventListener("submit", didSubmitForm)
12
+ document.addEventListener("submit", didSubmitForm, true)
13
13
  document.addEventListener("ajax:before", didSubmitRemoteElement)
14
14
  }
15
15
  }