@rails/actiontext 8.0.201 → 8.1.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.
|
@@ -672,7 +672,7 @@ class DirectUploadController {
|
|
|
672
672
|
}));
|
|
673
673
|
}
|
|
674
674
|
uploadRequestDidProgress(event) {
|
|
675
|
-
const progress = event.loaded / event.total *
|
|
675
|
+
const progress = event.loaded / event.total * 90;
|
|
676
676
|
if (progress) {
|
|
677
677
|
this.dispatch("progress", {
|
|
678
678
|
progress: progress
|
|
@@ -707,6 +707,42 @@ class DirectUploadController {
|
|
|
707
707
|
xhr: xhr
|
|
708
708
|
});
|
|
709
709
|
xhr.upload.addEventListener("progress", (event => this.uploadRequestDidProgress(event)));
|
|
710
|
+
xhr.upload.addEventListener("loadend", (() => {
|
|
711
|
+
this.simulateResponseProgress(xhr);
|
|
712
|
+
}));
|
|
713
|
+
}
|
|
714
|
+
simulateResponseProgress(xhr) {
|
|
715
|
+
let progress = 90;
|
|
716
|
+
const startTime = Date.now();
|
|
717
|
+
const updateProgress = () => {
|
|
718
|
+
const elapsed = Date.now() - startTime;
|
|
719
|
+
const estimatedResponseTime = this.estimateResponseTime();
|
|
720
|
+
const responseProgress = Math.min(elapsed / estimatedResponseTime, 1);
|
|
721
|
+
progress = 90 + responseProgress * 9;
|
|
722
|
+
this.dispatch("progress", {
|
|
723
|
+
progress: progress
|
|
724
|
+
});
|
|
725
|
+
if (xhr.readyState !== XMLHttpRequest.DONE && progress < 99) {
|
|
726
|
+
requestAnimationFrame(updateProgress);
|
|
727
|
+
}
|
|
728
|
+
};
|
|
729
|
+
xhr.addEventListener("loadend", (() => {
|
|
730
|
+
this.dispatch("progress", {
|
|
731
|
+
progress: 100
|
|
732
|
+
});
|
|
733
|
+
}));
|
|
734
|
+
requestAnimationFrame(updateProgress);
|
|
735
|
+
}
|
|
736
|
+
estimateResponseTime() {
|
|
737
|
+
const fileSize = this.file.size;
|
|
738
|
+
const MB = 1024 * 1024;
|
|
739
|
+
if (fileSize < MB) {
|
|
740
|
+
return 1e3;
|
|
741
|
+
} else if (fileSize < 10 * MB) {
|
|
742
|
+
return 2e3;
|
|
743
|
+
} else {
|
|
744
|
+
return 3e3 + fileSize / MB * 50;
|
|
745
|
+
}
|
|
710
746
|
}
|
|
711
747
|
}
|
|
712
748
|
|
|
@@ -857,7 +893,7 @@ class AttachmentUpload {
|
|
|
857
893
|
}
|
|
858
894
|
directUploadWillStoreFileWithXHR(xhr) {
|
|
859
895
|
xhr.upload.addEventListener("progress", (event => {
|
|
860
|
-
const progress = event.loaded / event.total *
|
|
896
|
+
const progress = event.loaded / event.total * 90;
|
|
861
897
|
this.attachment.setUploadProgress(progress);
|
|
862
898
|
if (progress) {
|
|
863
899
|
this.dispatch("progress", {
|
|
@@ -865,6 +901,44 @@ class AttachmentUpload {
|
|
|
865
901
|
});
|
|
866
902
|
}
|
|
867
903
|
}));
|
|
904
|
+
xhr.upload.addEventListener("loadend", (() => {
|
|
905
|
+
this.simulateResponseProgress(xhr);
|
|
906
|
+
}));
|
|
907
|
+
}
|
|
908
|
+
simulateResponseProgress(xhr) {
|
|
909
|
+
let progress = 90;
|
|
910
|
+
const startTime = Date.now();
|
|
911
|
+
const updateProgress = () => {
|
|
912
|
+
const elapsed = Date.now() - startTime;
|
|
913
|
+
const estimatedResponseTime = this.estimateResponseTime();
|
|
914
|
+
const responseProgress = Math.min(elapsed / estimatedResponseTime, 1);
|
|
915
|
+
progress = 90 + responseProgress * 9;
|
|
916
|
+
this.attachment.setUploadProgress(progress);
|
|
917
|
+
this.dispatch("progress", {
|
|
918
|
+
progress: progress
|
|
919
|
+
});
|
|
920
|
+
if (xhr.readyState !== XMLHttpRequest.DONE && progress < 99) {
|
|
921
|
+
requestAnimationFrame(updateProgress);
|
|
922
|
+
}
|
|
923
|
+
};
|
|
924
|
+
xhr.addEventListener("loadend", (() => {
|
|
925
|
+
this.attachment.setUploadProgress(100);
|
|
926
|
+
this.dispatch("progress", {
|
|
927
|
+
progress: 100
|
|
928
|
+
});
|
|
929
|
+
}));
|
|
930
|
+
requestAnimationFrame(updateProgress);
|
|
931
|
+
}
|
|
932
|
+
estimateResponseTime() {
|
|
933
|
+
const fileSize = this.attachment.file.size;
|
|
934
|
+
const MB = 1024 * 1024;
|
|
935
|
+
if (fileSize < MB) {
|
|
936
|
+
return 1e3;
|
|
937
|
+
} else if (fileSize < 10 * MB) {
|
|
938
|
+
return 2e3;
|
|
939
|
+
} else {
|
|
940
|
+
return 3e3 + fileSize / MB * 50;
|
|
941
|
+
}
|
|
868
942
|
}
|
|
869
943
|
directUploadDidComplete(error, attributes) {
|
|
870
944
|
if (error) {
|
|
@@ -661,7 +661,7 @@
|
|
|
661
661
|
}));
|
|
662
662
|
}
|
|
663
663
|
uploadRequestDidProgress(event) {
|
|
664
|
-
const progress = event.loaded / event.total *
|
|
664
|
+
const progress = event.loaded / event.total * 90;
|
|
665
665
|
if (progress) {
|
|
666
666
|
this.dispatch("progress", {
|
|
667
667
|
progress: progress
|
|
@@ -696,6 +696,42 @@
|
|
|
696
696
|
xhr: xhr
|
|
697
697
|
});
|
|
698
698
|
xhr.upload.addEventListener("progress", (event => this.uploadRequestDidProgress(event)));
|
|
699
|
+
xhr.upload.addEventListener("loadend", (() => {
|
|
700
|
+
this.simulateResponseProgress(xhr);
|
|
701
|
+
}));
|
|
702
|
+
}
|
|
703
|
+
simulateResponseProgress(xhr) {
|
|
704
|
+
let progress = 90;
|
|
705
|
+
const startTime = Date.now();
|
|
706
|
+
const updateProgress = () => {
|
|
707
|
+
const elapsed = Date.now() - startTime;
|
|
708
|
+
const estimatedResponseTime = this.estimateResponseTime();
|
|
709
|
+
const responseProgress = Math.min(elapsed / estimatedResponseTime, 1);
|
|
710
|
+
progress = 90 + responseProgress * 9;
|
|
711
|
+
this.dispatch("progress", {
|
|
712
|
+
progress: progress
|
|
713
|
+
});
|
|
714
|
+
if (xhr.readyState !== XMLHttpRequest.DONE && progress < 99) {
|
|
715
|
+
requestAnimationFrame(updateProgress);
|
|
716
|
+
}
|
|
717
|
+
};
|
|
718
|
+
xhr.addEventListener("loadend", (() => {
|
|
719
|
+
this.dispatch("progress", {
|
|
720
|
+
progress: 100
|
|
721
|
+
});
|
|
722
|
+
}));
|
|
723
|
+
requestAnimationFrame(updateProgress);
|
|
724
|
+
}
|
|
725
|
+
estimateResponseTime() {
|
|
726
|
+
const fileSize = this.file.size;
|
|
727
|
+
const MB = 1024 * 1024;
|
|
728
|
+
if (fileSize < MB) {
|
|
729
|
+
return 1e3;
|
|
730
|
+
} else if (fileSize < 10 * MB) {
|
|
731
|
+
return 2e3;
|
|
732
|
+
} else {
|
|
733
|
+
return 3e3 + fileSize / MB * 50;
|
|
734
|
+
}
|
|
699
735
|
}
|
|
700
736
|
}
|
|
701
737
|
const inputSelector = "input[type=file][data-direct-upload-url]:not([disabled])";
|
|
@@ -830,7 +866,7 @@
|
|
|
830
866
|
}
|
|
831
867
|
directUploadWillStoreFileWithXHR(xhr) {
|
|
832
868
|
xhr.upload.addEventListener("progress", (event => {
|
|
833
|
-
const progress = event.loaded / event.total *
|
|
869
|
+
const progress = event.loaded / event.total * 90;
|
|
834
870
|
this.attachment.setUploadProgress(progress);
|
|
835
871
|
if (progress) {
|
|
836
872
|
this.dispatch("progress", {
|
|
@@ -838,6 +874,44 @@
|
|
|
838
874
|
});
|
|
839
875
|
}
|
|
840
876
|
}));
|
|
877
|
+
xhr.upload.addEventListener("loadend", (() => {
|
|
878
|
+
this.simulateResponseProgress(xhr);
|
|
879
|
+
}));
|
|
880
|
+
}
|
|
881
|
+
simulateResponseProgress(xhr) {
|
|
882
|
+
let progress = 90;
|
|
883
|
+
const startTime = Date.now();
|
|
884
|
+
const updateProgress = () => {
|
|
885
|
+
const elapsed = Date.now() - startTime;
|
|
886
|
+
const estimatedResponseTime = this.estimateResponseTime();
|
|
887
|
+
const responseProgress = Math.min(elapsed / estimatedResponseTime, 1);
|
|
888
|
+
progress = 90 + responseProgress * 9;
|
|
889
|
+
this.attachment.setUploadProgress(progress);
|
|
890
|
+
this.dispatch("progress", {
|
|
891
|
+
progress: progress
|
|
892
|
+
});
|
|
893
|
+
if (xhr.readyState !== XMLHttpRequest.DONE && progress < 99) {
|
|
894
|
+
requestAnimationFrame(updateProgress);
|
|
895
|
+
}
|
|
896
|
+
};
|
|
897
|
+
xhr.addEventListener("loadend", (() => {
|
|
898
|
+
this.attachment.setUploadProgress(100);
|
|
899
|
+
this.dispatch("progress", {
|
|
900
|
+
progress: 100
|
|
901
|
+
});
|
|
902
|
+
}));
|
|
903
|
+
requestAnimationFrame(updateProgress);
|
|
904
|
+
}
|
|
905
|
+
estimateResponseTime() {
|
|
906
|
+
const fileSize = this.attachment.file.size;
|
|
907
|
+
const MB = 1024 * 1024;
|
|
908
|
+
if (fileSize < MB) {
|
|
909
|
+
return 1e3;
|
|
910
|
+
} else if (fileSize < 10 * MB) {
|
|
911
|
+
return 2e3;
|
|
912
|
+
} else {
|
|
913
|
+
return 3e3 + fileSize / MB * 50;
|
|
914
|
+
}
|
|
841
915
|
}
|
|
842
916
|
directUploadDidComplete(error, attributes) {
|
|
843
917
|
if (error) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rails/actiontext",
|
|
3
|
-
"version": "8.0
|
|
3
|
+
"version": "8.1.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": ">= 8.
|
|
25
|
+
"@rails/activestorage": ">= 8.1.0-alpha"
|
|
26
26
|
},
|
|
27
27
|
"peerDependencies": {
|
|
28
28
|
"trix": "^2.0.0"
|
|
@@ -31,6 +31,7 @@
|
|
|
31
31
|
"@rollup/plugin-commonjs": "^19.0.1",
|
|
32
32
|
"@rollup/plugin-node-resolve": "^11.0.1",
|
|
33
33
|
"rollup": "^2.35.1",
|
|
34
|
+
"rollup-plugin-terser": "^7.0.2",
|
|
34
35
|
"trix": "^2.0.0"
|
|
35
36
|
},
|
|
36
37
|
"scripts": {
|