@rails/actiontext 8.1.0-beta1 → 8.1.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.
|
@@ -882,19 +882,21 @@ function autostart() {
|
|
|
882
882
|
setTimeout(autostart, 1);
|
|
883
883
|
|
|
884
884
|
class AttachmentUpload {
|
|
885
|
-
constructor(attachment, element) {
|
|
885
|
+
constructor(attachment, element, file = attachment.file) {
|
|
886
886
|
this.attachment = attachment;
|
|
887
887
|
this.element = element;
|
|
888
|
-
this.directUpload = new DirectUpload(
|
|
888
|
+
this.directUpload = new DirectUpload(file, this.directUploadUrl, this);
|
|
889
|
+
this.file = file;
|
|
889
890
|
}
|
|
890
891
|
start() {
|
|
891
|
-
|
|
892
|
-
|
|
892
|
+
return new Promise(((resolve, reject) => {
|
|
893
|
+
this.directUpload.create(((error, attributes) => this.directUploadDidComplete(error, attributes, resolve, reject)));
|
|
894
|
+
this.dispatch("start");
|
|
895
|
+
}));
|
|
893
896
|
}
|
|
894
897
|
directUploadWillStoreFileWithXHR(xhr) {
|
|
895
898
|
xhr.upload.addEventListener("progress", (event => {
|
|
896
899
|
const progress = event.loaded / event.total * 90;
|
|
897
|
-
this.attachment.setUploadProgress(progress);
|
|
898
900
|
if (progress) {
|
|
899
901
|
this.dispatch("progress", {
|
|
900
902
|
progress: progress
|
|
@@ -913,7 +915,6 @@ class AttachmentUpload {
|
|
|
913
915
|
const estimatedResponseTime = this.estimateResponseTime();
|
|
914
916
|
const responseProgress = Math.min(elapsed / estimatedResponseTime, 1);
|
|
915
917
|
progress = 90 + responseProgress * 9;
|
|
916
|
-
this.attachment.setUploadProgress(progress);
|
|
917
918
|
this.dispatch("progress", {
|
|
918
919
|
progress: progress
|
|
919
920
|
});
|
|
@@ -922,7 +923,6 @@ class AttachmentUpload {
|
|
|
922
923
|
}
|
|
923
924
|
};
|
|
924
925
|
xhr.addEventListener("loadend", (() => {
|
|
925
|
-
this.attachment.setUploadProgress(100);
|
|
926
926
|
this.dispatch("progress", {
|
|
927
927
|
progress: 100
|
|
928
928
|
});
|
|
@@ -930,7 +930,7 @@ class AttachmentUpload {
|
|
|
930
930
|
requestAnimationFrame(updateProgress);
|
|
931
931
|
}
|
|
932
932
|
estimateResponseTime() {
|
|
933
|
-
const fileSize = this.
|
|
933
|
+
const fileSize = this.file.size;
|
|
934
934
|
const MB = 1024 * 1024;
|
|
935
935
|
if (fileSize < MB) {
|
|
936
936
|
return 1e3;
|
|
@@ -940,11 +940,11 @@ class AttachmentUpload {
|
|
|
940
940
|
return 3e3 + fileSize / MB * 50;
|
|
941
941
|
}
|
|
942
942
|
}
|
|
943
|
-
directUploadDidComplete(error, attributes) {
|
|
943
|
+
directUploadDidComplete(error, attributes, resolve, reject) {
|
|
944
944
|
if (error) {
|
|
945
|
-
this.dispatchError(error);
|
|
945
|
+
this.dispatchError(error, reject);
|
|
946
946
|
} else {
|
|
947
|
-
|
|
947
|
+
resolve({
|
|
948
948
|
sgid: attributes.attachable_sgid,
|
|
949
949
|
url: this.createBlobUrl(attributes.signed_id, attributes.filename)
|
|
950
950
|
});
|
|
@@ -960,12 +960,12 @@ class AttachmentUpload {
|
|
|
960
960
|
detail: detail
|
|
961
961
|
});
|
|
962
962
|
}
|
|
963
|
-
dispatchError(error) {
|
|
963
|
+
dispatchError(error, reject) {
|
|
964
964
|
const event = this.dispatch("error", {
|
|
965
965
|
error: error
|
|
966
966
|
});
|
|
967
967
|
if (!event.defaultPrevented) {
|
|
968
|
-
|
|
968
|
+
reject(error);
|
|
969
969
|
}
|
|
970
970
|
}
|
|
971
971
|
get directUploadUrl() {
|
|
@@ -979,7 +979,11 @@ class AttachmentUpload {
|
|
|
979
979
|
addEventListener("trix-attachment-add", (event => {
|
|
980
980
|
const {attachment: attachment, target: target} = event;
|
|
981
981
|
if (attachment.file) {
|
|
982
|
-
const upload = new AttachmentUpload(attachment, target);
|
|
983
|
-
|
|
982
|
+
const upload = new AttachmentUpload(attachment, target, attachment.file);
|
|
983
|
+
const onProgress = event => attachment.setUploadProgress(event.detail.progress);
|
|
984
|
+
target.addEventListener("direct-upload:progress", onProgress);
|
|
985
|
+
upload.start().then((attributes => attachment.setAttributes(attributes))).catch((error => alert(error))).finally((() => target.removeEventListener("direct-upload:progress", onProgress)));
|
|
984
986
|
}
|
|
985
987
|
}));
|
|
988
|
+
|
|
989
|
+
export { AttachmentUpload };
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
(function(factory) {
|
|
2
|
-
typeof define === "function" && define.amd ? define(factory) :
|
|
3
|
-
})
|
|
1
|
+
(function(global, factory) {
|
|
2
|
+
typeof exports === "object" && typeof module !== "undefined" ? factory(exports) : typeof define === "function" && define.amd ? define([ "exports" ], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self,
|
|
3
|
+
factory(global.ActionText = {}));
|
|
4
|
+
})(this, (function(exports) {
|
|
4
5
|
"use strict";
|
|
5
6
|
var sparkMd5 = {
|
|
6
7
|
exports: {}
|
|
@@ -855,19 +856,21 @@
|
|
|
855
856
|
}
|
|
856
857
|
setTimeout(autostart, 1);
|
|
857
858
|
class AttachmentUpload {
|
|
858
|
-
constructor(attachment, element) {
|
|
859
|
+
constructor(attachment, element, file = attachment.file) {
|
|
859
860
|
this.attachment = attachment;
|
|
860
861
|
this.element = element;
|
|
861
|
-
this.directUpload = new DirectUpload(
|
|
862
|
+
this.directUpload = new DirectUpload(file, this.directUploadUrl, this);
|
|
863
|
+
this.file = file;
|
|
862
864
|
}
|
|
863
865
|
start() {
|
|
864
|
-
|
|
865
|
-
|
|
866
|
+
return new Promise(((resolve, reject) => {
|
|
867
|
+
this.directUpload.create(((error, attributes) => this.directUploadDidComplete(error, attributes, resolve, reject)));
|
|
868
|
+
this.dispatch("start");
|
|
869
|
+
}));
|
|
866
870
|
}
|
|
867
871
|
directUploadWillStoreFileWithXHR(xhr) {
|
|
868
872
|
xhr.upload.addEventListener("progress", (event => {
|
|
869
873
|
const progress = event.loaded / event.total * 90;
|
|
870
|
-
this.attachment.setUploadProgress(progress);
|
|
871
874
|
if (progress) {
|
|
872
875
|
this.dispatch("progress", {
|
|
873
876
|
progress: progress
|
|
@@ -886,7 +889,6 @@
|
|
|
886
889
|
const estimatedResponseTime = this.estimateResponseTime();
|
|
887
890
|
const responseProgress = Math.min(elapsed / estimatedResponseTime, 1);
|
|
888
891
|
progress = 90 + responseProgress * 9;
|
|
889
|
-
this.attachment.setUploadProgress(progress);
|
|
890
892
|
this.dispatch("progress", {
|
|
891
893
|
progress: progress
|
|
892
894
|
});
|
|
@@ -895,7 +897,6 @@
|
|
|
895
897
|
}
|
|
896
898
|
};
|
|
897
899
|
xhr.addEventListener("loadend", (() => {
|
|
898
|
-
this.attachment.setUploadProgress(100);
|
|
899
900
|
this.dispatch("progress", {
|
|
900
901
|
progress: 100
|
|
901
902
|
});
|
|
@@ -903,7 +904,7 @@
|
|
|
903
904
|
requestAnimationFrame(updateProgress);
|
|
904
905
|
}
|
|
905
906
|
estimateResponseTime() {
|
|
906
|
-
const fileSize = this.
|
|
907
|
+
const fileSize = this.file.size;
|
|
907
908
|
const MB = 1024 * 1024;
|
|
908
909
|
if (fileSize < MB) {
|
|
909
910
|
return 1e3;
|
|
@@ -913,11 +914,11 @@
|
|
|
913
914
|
return 3e3 + fileSize / MB * 50;
|
|
914
915
|
}
|
|
915
916
|
}
|
|
916
|
-
directUploadDidComplete(error, attributes) {
|
|
917
|
+
directUploadDidComplete(error, attributes, resolve, reject) {
|
|
917
918
|
if (error) {
|
|
918
|
-
this.dispatchError(error);
|
|
919
|
+
this.dispatchError(error, reject);
|
|
919
920
|
} else {
|
|
920
|
-
|
|
921
|
+
resolve({
|
|
921
922
|
sgid: attributes.attachable_sgid,
|
|
922
923
|
url: this.createBlobUrl(attributes.signed_id, attributes.filename)
|
|
923
924
|
});
|
|
@@ -933,12 +934,12 @@
|
|
|
933
934
|
detail: detail
|
|
934
935
|
});
|
|
935
936
|
}
|
|
936
|
-
dispatchError(error) {
|
|
937
|
+
dispatchError(error, reject) {
|
|
937
938
|
const event = this.dispatch("error", {
|
|
938
939
|
error: error
|
|
939
940
|
});
|
|
940
941
|
if (!event.defaultPrevented) {
|
|
941
|
-
|
|
942
|
+
reject(error);
|
|
942
943
|
}
|
|
943
944
|
}
|
|
944
945
|
get directUploadUrl() {
|
|
@@ -951,8 +952,14 @@
|
|
|
951
952
|
addEventListener("trix-attachment-add", (event => {
|
|
952
953
|
const {attachment: attachment, target: target} = event;
|
|
953
954
|
if (attachment.file) {
|
|
954
|
-
const upload = new AttachmentUpload(attachment, target);
|
|
955
|
-
|
|
955
|
+
const upload = new AttachmentUpload(attachment, target, attachment.file);
|
|
956
|
+
const onProgress = event => attachment.setUploadProgress(event.detail.progress);
|
|
957
|
+
target.addEventListener("direct-upload:progress", onProgress);
|
|
958
|
+
upload.start().then((attributes => attachment.setAttributes(attributes))).catch((error => alert(error))).finally((() => target.removeEventListener("direct-upload:progress", onProgress)));
|
|
956
959
|
}
|
|
957
960
|
}));
|
|
961
|
+
exports.AttachmentUpload = AttachmentUpload;
|
|
962
|
+
Object.defineProperty(exports, "__esModule", {
|
|
963
|
+
value: true
|
|
964
|
+
});
|
|
958
965
|
}));
|
package/package.json
CHANGED