actiontext 7.0.8 → 7.1.3.2

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of actiontext might be problematic. Click here for more details.

@@ -1,11 +1,7 @@
1
- var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
2
-
3
- var activestorage = {exports: {}};
4
-
5
- (function (module, exports) {
6
- (function(global, factory) {
7
- factory(exports) ;
8
- })(commonjsGlobal, (function(exports) {
1
+ (function(factory) {
2
+ typeof define === "function" && define.amd ? define(factory) : factory();
3
+ })((function() {
4
+ "use strict";
9
5
  var sparkMd5 = {
10
6
  exports: {}
11
7
  };
@@ -506,7 +502,7 @@ var activestorage = {exports: {}};
506
502
  }
507
503
  }
508
504
  class BlobRecord {
509
- constructor(file, checksum, url) {
505
+ constructor(file, checksum, url, customHeaders = {}) {
510
506
  this.file = file;
511
507
  this.attributes = {
512
508
  filename: file.name,
@@ -520,6 +516,9 @@ var activestorage = {exports: {}};
520
516
  this.xhr.setRequestHeader("Content-Type", "application/json");
521
517
  this.xhr.setRequestHeader("Accept", "application/json");
522
518
  this.xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest");
519
+ Object.keys(customHeaders).forEach((headerKey => {
520
+ this.xhr.setRequestHeader(headerKey, customHeaders[headerKey]);
521
+ }));
523
522
  const csrfToken = getMetaValue("csrf-token");
524
523
  if (csrfToken != undefined) {
525
524
  this.xhr.setRequestHeader("X-CSRF-Token", csrfToken);
@@ -599,11 +598,12 @@ var activestorage = {exports: {}};
599
598
  }
600
599
  let id = 0;
601
600
  class DirectUpload {
602
- constructor(file, url, delegate) {
601
+ constructor(file, url, delegate, customHeaders = {}) {
603
602
  this.id = ++id;
604
603
  this.file = file;
605
604
  this.url = url;
606
605
  this.delegate = delegate;
606
+ this.customHeaders = customHeaders;
607
607
  }
608
608
  create(callback) {
609
609
  FileChecksum.create(this.file, ((error, checksum) => {
@@ -611,7 +611,7 @@ var activestorage = {exports: {}};
611
611
  callback(error);
612
612
  return;
613
613
  }
614
- const blob = new BlobRecord(this.file, checksum, this.url);
614
+ const blob = new BlobRecord(this.file, checksum, this.url, this.customHeaders);
615
615
  notify(this.delegate, "directUploadWillCreateBlobWithXHR", blob.xhr);
616
616
  blob.create((error => {
617
617
  if (error) {
@@ -753,9 +753,9 @@ var activestorage = {exports: {}};
753
753
  }
754
754
  }
755
755
  function didClick(event) {
756
- const {target: target} = event;
757
- if ((target.tagName == "INPUT" || target.tagName == "BUTTON") && target.type == "submit" && target.form) {
758
- submitButtonsByForm.set(target.form, target);
756
+ const button = event.target.closest("button, input");
757
+ if (button && button.type === "submit" && button.form) {
758
+ submitButtonsByForm.set(button.form, button);
759
759
  }
760
760
  }
761
761
  function didSubmitForm(event) {
@@ -818,63 +818,45 @@ var activestorage = {exports: {}};
818
818
  }
819
819
  }
820
820
  setTimeout(autostart, 1);
821
- exports.DirectUpload = DirectUpload;
822
- exports.start = start;
823
- Object.defineProperty(exports, "__esModule", {
824
- value: true
825
- });
826
- }));
827
- }(activestorage, activestorage.exports));
828
-
829
- class AttachmentUpload {
830
- constructor(attachment, element) {
831
- this.attachment = attachment;
832
- this.element = element;
833
- this.directUpload = new activestorage.exports.DirectUpload(attachment.file, this.directUploadUrl, this);
834
- }
835
-
836
- start() {
837
- this.directUpload.create(this.directUploadDidComplete.bind(this));
838
- }
839
-
840
- directUploadWillStoreFileWithXHR(xhr) {
841
- xhr.upload.addEventListener("progress", event => {
842
- const progress = event.loaded / event.total * 100;
843
- this.attachment.setUploadProgress(progress);
844
- });
845
- }
846
-
847
- directUploadDidComplete(error, attributes) {
848
- if (error) {
849
- throw new Error(`Direct upload failed: ${error}`)
850
- }
851
-
852
- this.attachment.setAttributes({
853
- sgid: attributes.attachable_sgid,
854
- url: this.createBlobUrl(attributes.signed_id, attributes.filename)
855
- });
856
- }
857
-
858
- createBlobUrl(signedId, filename) {
859
- return this.blobUrlTemplate
860
- .replace(":signed_id", signedId)
861
- .replace(":filename", encodeURIComponent(filename))
862
- }
863
-
864
- get directUploadUrl() {
865
- return this.element.dataset.directUploadUrl
866
- }
867
-
868
- get blobUrlTemplate() {
869
- return this.element.dataset.blobUrlTemplate
870
- }
871
- }
872
-
873
- addEventListener("trix-attachment-add", event => {
874
- const { attachment, target } = event;
875
-
876
- if (attachment.file) {
877
- const upload = new AttachmentUpload(attachment, target);
878
- upload.start();
821
+ class AttachmentUpload {
822
+ constructor(attachment, element) {
823
+ this.attachment = attachment;
824
+ this.element = element;
825
+ this.directUpload = new DirectUpload(attachment.file, this.directUploadUrl, this);
826
+ }
827
+ start() {
828
+ this.directUpload.create(this.directUploadDidComplete.bind(this));
829
+ }
830
+ directUploadWillStoreFileWithXHR(xhr) {
831
+ xhr.upload.addEventListener("progress", (event => {
832
+ const progress = event.loaded / event.total * 100;
833
+ this.attachment.setUploadProgress(progress);
834
+ }));
835
+ }
836
+ directUploadDidComplete(error, attributes) {
837
+ if (error) {
838
+ throw new Error(`Direct upload failed: ${error}`);
839
+ }
840
+ this.attachment.setAttributes({
841
+ sgid: attributes.attachable_sgid,
842
+ url: this.createBlobUrl(attributes.signed_id, attributes.filename)
843
+ });
844
+ }
845
+ createBlobUrl(signedId, filename) {
846
+ return this.blobUrlTemplate.replace(":signed_id", signedId).replace(":filename", encodeURIComponent(filename));
847
+ }
848
+ get directUploadUrl() {
849
+ return this.element.dataset.directUploadUrl;
850
+ }
851
+ get blobUrlTemplate() {
852
+ return this.element.dataset.blobUrlTemplate;
853
+ }
879
854
  }
880
- });
855
+ addEventListener("trix-attachment-add", (event => {
856
+ const {attachment: attachment, target: target} = event;
857
+ if (attachment.file) {
858
+ const upload = new AttachmentUpload(attachment, target);
859
+ upload.start();
860
+ }
861
+ }));
862
+ }));