sales-frontend-components 0.0.218 → 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 -21
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.esm.js +54 -21
- package/dist/index.esm.js.map +1 -1
- package/package.json +15 -15
package/dist/index.cjs.js
CHANGED
|
@@ -149,16 +149,6 @@ var isClient = () => {
|
|
|
149
149
|
return false;
|
|
150
150
|
}
|
|
151
151
|
};
|
|
152
|
-
var getBusinessWorkDivisionCode = (pathname) => {
|
|
153
|
-
return location.pathname.split("/")[1] ?? "";
|
|
154
|
-
};
|
|
155
|
-
var getServicePath = () => {
|
|
156
|
-
if (typeof window.isStorybookEnv === "boolean") {
|
|
157
|
-
return "";
|
|
158
|
-
} else {
|
|
159
|
-
return `/${getBusinessWorkDivisionCode()}`;
|
|
160
|
-
}
|
|
161
|
-
};
|
|
162
152
|
var isAndroidDevice = () => {
|
|
163
153
|
if (isClient() === false) {
|
|
164
154
|
return false;
|
|
@@ -495,6 +485,55 @@ var GENDER_LABEL_MAP = {
|
|
|
495
485
|
var getGenderName = (genderCode) => {
|
|
496
486
|
return genderCode ? GENDER_LABEL_MAP[genderCode] : "";
|
|
497
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
|
+
};
|
|
498
537
|
|
|
499
538
|
const FormDatePicker = ({
|
|
500
539
|
name,
|
|
@@ -4895,16 +4934,6 @@ function DudDownload() {
|
|
|
4895
4934
|
const useDownloader = () => {
|
|
4896
4935
|
const [isError, setIsError] = React.useState(false);
|
|
4897
4936
|
const [isLoading, setIsLoading] = React.useState(false);
|
|
4898
|
-
const downloadFile = async (url, fileName) => {
|
|
4899
|
-
try {
|
|
4900
|
-
const servicePath = getServicePath();
|
|
4901
|
-
const downloadUrl = `${servicePath}/internal/api/download?filename=${encodeURIComponent(fileName)}&filepath=${encodeURIComponent(url)}`;
|
|
4902
|
-
window.location.href = downloadUrl;
|
|
4903
|
-
} catch (e) {
|
|
4904
|
-
console.error(e);
|
|
4905
|
-
throw e;
|
|
4906
|
-
}
|
|
4907
|
-
};
|
|
4908
4937
|
const onClick = async (downloaderProps) => {
|
|
4909
4938
|
const { downloadTargetInfo, onAllSuccess, onAnyError, startIndex = 0 } = downloaderProps;
|
|
4910
4939
|
setIsLoading(true);
|
|
@@ -4937,7 +4966,11 @@ const useDownloader = () => {
|
|
|
4937
4966
|
if (!url) {
|
|
4938
4967
|
throw new Error("Download URL is empty");
|
|
4939
4968
|
}
|
|
4940
|
-
|
|
4969
|
+
if (info.isOpenNewWindow) {
|
|
4970
|
+
await downloadFromNewWindow(url, info.fileName);
|
|
4971
|
+
} else {
|
|
4972
|
+
await downloadFromCurrentWindow(url, info.fileName);
|
|
4973
|
+
}
|
|
4941
4974
|
info.onSuccess?.();
|
|
4942
4975
|
} catch (error) {
|
|
4943
4976
|
console.error(`Download failed at index ${i}`, error);
|