@rails/actiontext 7.2.100 → 8.0.0-beta1

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.
@@ -853,25 +853,47 @@ class AttachmentUpload {
853
853
  }
854
854
  start() {
855
855
  this.directUpload.create(this.directUploadDidComplete.bind(this));
856
+ this.dispatch("start");
856
857
  }
857
858
  directUploadWillStoreFileWithXHR(xhr) {
858
859
  xhr.upload.addEventListener("progress", (event => {
859
860
  const progress = event.loaded / event.total * 100;
860
861
  this.attachment.setUploadProgress(progress);
862
+ if (progress) {
863
+ this.dispatch("progress", {
864
+ progress: progress
865
+ });
866
+ }
861
867
  }));
862
868
  }
863
869
  directUploadDidComplete(error, attributes) {
864
870
  if (error) {
865
- throw new Error(`Direct upload failed: ${error}`);
871
+ this.dispatchError(error);
872
+ } else {
873
+ this.attachment.setAttributes({
874
+ sgid: attributes.attachable_sgid,
875
+ url: this.createBlobUrl(attributes.signed_id, attributes.filename)
876
+ });
877
+ this.dispatch("end");
866
878
  }
867
- this.attachment.setAttributes({
868
- sgid: attributes.attachable_sgid,
869
- url: this.createBlobUrl(attributes.signed_id, attributes.filename)
870
- });
871
879
  }
872
880
  createBlobUrl(signedId, filename) {
873
881
  return this.blobUrlTemplate.replace(":signed_id", signedId).replace(":filename", encodeURIComponent(filename));
874
882
  }
883
+ dispatch(name, detail = {}) {
884
+ detail.attachment = this.attachment;
885
+ return dispatchEvent(this.element, `direct-upload:${name}`, {
886
+ detail: detail
887
+ });
888
+ }
889
+ dispatchError(error) {
890
+ const event = this.dispatch("error", {
891
+ error: error
892
+ });
893
+ if (!event.defaultPrevented) {
894
+ alert(error);
895
+ }
896
+ }
875
897
  get directUploadUrl() {
876
898
  return this.element.dataset.directUploadUrl;
877
899
  }
@@ -826,25 +826,47 @@
826
826
  }
827
827
  start() {
828
828
  this.directUpload.create(this.directUploadDidComplete.bind(this));
829
+ this.dispatch("start");
829
830
  }
830
831
  directUploadWillStoreFileWithXHR(xhr) {
831
832
  xhr.upload.addEventListener("progress", (event => {
832
833
  const progress = event.loaded / event.total * 100;
833
834
  this.attachment.setUploadProgress(progress);
835
+ if (progress) {
836
+ this.dispatch("progress", {
837
+ progress: progress
838
+ });
839
+ }
834
840
  }));
835
841
  }
836
842
  directUploadDidComplete(error, attributes) {
837
843
  if (error) {
838
- throw new Error(`Direct upload failed: ${error}`);
844
+ this.dispatchError(error);
845
+ } else {
846
+ this.attachment.setAttributes({
847
+ sgid: attributes.attachable_sgid,
848
+ url: this.createBlobUrl(attributes.signed_id, attributes.filename)
849
+ });
850
+ this.dispatch("end");
839
851
  }
840
- this.attachment.setAttributes({
841
- sgid: attributes.attachable_sgid,
842
- url: this.createBlobUrl(attributes.signed_id, attributes.filename)
843
- });
844
852
  }
845
853
  createBlobUrl(signedId, filename) {
846
854
  return this.blobUrlTemplate.replace(":signed_id", signedId).replace(":filename", encodeURIComponent(filename));
847
855
  }
856
+ dispatch(name, detail = {}) {
857
+ detail.attachment = this.attachment;
858
+ return dispatchEvent(this.element, `direct-upload:${name}`, {
859
+ detail: detail
860
+ });
861
+ }
862
+ dispatchError(error) {
863
+ const event = this.dispatch("error", {
864
+ error: error
865
+ });
866
+ if (!event.defaultPrevented) {
867
+ alert(error);
868
+ }
869
+ }
848
870
  get directUploadUrl() {
849
871
  return this.element.dataset.directUploadUrl;
850
872
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rails/actiontext",
3
- "version": "7.2.100",
3
+ "version": "8.0.0-beta1",
4
4
  "description": "Edit and display rich text in Rails applications",
5
5
  "module": "app/assets/javascripts/actiontext.esm.js",
6
6
  "main": "app/assets/javascripts/actiontext.js",
@@ -22,7 +22,7 @@
22
22
  ],
23
23
  "license": "MIT",
24
24
  "dependencies": {
25
- "@rails/activestorage": ">= 7.2.0-alpha"
25
+ "@rails/activestorage": ">= 8.0.0-alpha"
26
26
  },
27
27
  "peerDependencies": {
28
28
  "trix": "^2.0.0"