sales-frontend-components 0.0.219 → 0.0.220
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/dist/index.cjs.js +54 -28
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.esm.js +54 -28
- package/dist/index.esm.js.map +1 -1
- package/package.json +15 -15
package/dist/index.cjs.js
CHANGED
|
@@ -485,6 +485,55 @@ var GENDER_LABEL_MAP = {
|
|
|
485
485
|
var getGenderName = (genderCode) => {
|
|
486
486
|
return genderCode ? GENDER_LABEL_MAP[genderCode] : "";
|
|
487
487
|
};
|
|
488
|
+
var getBlobUrl = async (url) => {
|
|
489
|
+
let downloadUrl = "";
|
|
490
|
+
if (url.startsWith("http")) {
|
|
491
|
+
const response = await fetch(url);
|
|
492
|
+
if (!response.ok) {
|
|
493
|
+
throw new Error(`Failed to download ${url}`);
|
|
494
|
+
}
|
|
495
|
+
const blob = await response.blob();
|
|
496
|
+
downloadUrl = window.URL.createObjectURL(blob);
|
|
497
|
+
} else if (url.startsWith("blob")) {
|
|
498
|
+
downloadUrl = url;
|
|
499
|
+
} else if (url.startsWith("data")) {
|
|
500
|
+
downloadUrl = URL.createObjectURL(base64ToBlob(url));
|
|
501
|
+
} else {
|
|
502
|
+
throw new Error(`unknown type : ${url}`);
|
|
503
|
+
}
|
|
504
|
+
return downloadUrl;
|
|
505
|
+
};
|
|
506
|
+
var downloadFromNewWindow = async (url, fileName) => {
|
|
507
|
+
try {
|
|
508
|
+
const aTag = document.createElement("a");
|
|
509
|
+
const downloadUrl = await getBlobUrl(url);
|
|
510
|
+
aTag.href = downloadUrl;
|
|
511
|
+
aTag.download = fileName;
|
|
512
|
+
const newWin = window.open();
|
|
513
|
+
newWin?.document.body.appendChild(aTag);
|
|
514
|
+
aTag.click();
|
|
515
|
+
aTag.remove();
|
|
516
|
+
window.URL.revokeObjectURL(downloadUrl);
|
|
517
|
+
} catch (e) {
|
|
518
|
+
console.error(e);
|
|
519
|
+
throw e;
|
|
520
|
+
}
|
|
521
|
+
};
|
|
522
|
+
var downloadFromCurrentWindow = async (url, fileName) => {
|
|
523
|
+
try {
|
|
524
|
+
const a = document.createElement("a");
|
|
525
|
+
const downloadUrl = await getBlobUrl(url);
|
|
526
|
+
a.href = downloadUrl;
|
|
527
|
+
a.download = fileName;
|
|
528
|
+
document.body.appendChild(a);
|
|
529
|
+
a.click();
|
|
530
|
+
a.remove();
|
|
531
|
+
window.URL.revokeObjectURL(downloadUrl);
|
|
532
|
+
} catch (e) {
|
|
533
|
+
console.error(e);
|
|
534
|
+
throw e;
|
|
535
|
+
}
|
|
536
|
+
};
|
|
488
537
|
|
|
489
538
|
const FormDatePicker = ({
|
|
490
539
|
name,
|
|
@@ -4885,33 +4934,6 @@ function DudDownload() {
|
|
|
4885
4934
|
const useDownloader = () => {
|
|
4886
4935
|
const [isError, setIsError] = React.useState(false);
|
|
4887
4936
|
const [isLoading, setIsLoading] = React.useState(false);
|
|
4888
|
-
const downloadFile = async (url, fileName) => {
|
|
4889
|
-
try {
|
|
4890
|
-
let downloadUrl = "";
|
|
4891
|
-
if (url.startsWith("http")) {
|
|
4892
|
-
const response = await fetch(url);
|
|
4893
|
-
if (!response.ok) {
|
|
4894
|
-
throw new Error(`Failed to download ${url}`);
|
|
4895
|
-
}
|
|
4896
|
-
const blob = await response.blob();
|
|
4897
|
-
downloadUrl = window.URL.createObjectURL(blob);
|
|
4898
|
-
} else if (url.startsWith("blob")) {
|
|
4899
|
-
downloadUrl = url;
|
|
4900
|
-
} else {
|
|
4901
|
-
throw new Error(`unknown type : ${url}`);
|
|
4902
|
-
}
|
|
4903
|
-
const a = document.createElement("a");
|
|
4904
|
-
a.href = downloadUrl;
|
|
4905
|
-
a.download = fileName || url.split("/").pop() || "download";
|
|
4906
|
-
document.body.appendChild(a);
|
|
4907
|
-
a.click();
|
|
4908
|
-
a.remove();
|
|
4909
|
-
window.URL.revokeObjectURL(downloadUrl);
|
|
4910
|
-
} catch (e) {
|
|
4911
|
-
console.error(e);
|
|
4912
|
-
throw e;
|
|
4913
|
-
}
|
|
4914
|
-
};
|
|
4915
4937
|
const onClick = async (downloaderProps) => {
|
|
4916
4938
|
const { downloadTargetInfo, onAllSuccess, onAnyError, startIndex = 0 } = downloaderProps;
|
|
4917
4939
|
setIsLoading(true);
|
|
@@ -4944,7 +4966,11 @@ const useDownloader = () => {
|
|
|
4944
4966
|
if (!url) {
|
|
4945
4967
|
throw new Error("Download URL is empty");
|
|
4946
4968
|
}
|
|
4947
|
-
|
|
4969
|
+
if (info.isOpenNewWindow) {
|
|
4970
|
+
await downloadFromNewWindow(url, info.fileName);
|
|
4971
|
+
} else {
|
|
4972
|
+
await downloadFromCurrentWindow(url, info.fileName);
|
|
4973
|
+
}
|
|
4948
4974
|
info.onSuccess?.();
|
|
4949
4975
|
} catch (error) {
|
|
4950
4976
|
console.error(`Download failed at index ${i}`, error);
|