@solidxai/core-ui 0.1.13-beta.5 → 0.1.13-beta.6
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"downloadMediaFile.d.ts","sourceRoot":"","sources":["../../src/helpers/downloadMediaFile.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"downloadMediaFile.d.ts","sourceRoot":"","sources":["../../src/helpers/downloadMediaFile.tsx"],"names":[],"mappings":"AAsCA,eAAO,MAAM,iBAAiB,YAAa,MAAM,aAAa,MAAM,SAMnE,CAAC"}
|
|
@@ -1,17 +1,92 @@
|
|
|
1
|
-
var
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
11
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
12
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
13
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
14
|
+
function step(op) {
|
|
15
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
16
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
17
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
18
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
19
|
+
switch (op[0]) {
|
|
20
|
+
case 0: case 1: t = op; break;
|
|
21
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
22
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
23
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
24
|
+
default:
|
|
25
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
26
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
27
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
28
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
29
|
+
if (t[2]) _.ops.pop();
|
|
30
|
+
_.trys.pop(); continue;
|
|
31
|
+
}
|
|
32
|
+
op = body.call(thisArg, _);
|
|
33
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
34
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
var triggerLinkClick = function (href, fileName, openInNewTab) {
|
|
38
|
+
if (openInNewTab === void 0) { openInNewTab = false; }
|
|
2
39
|
var link = document.createElement("a");
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
40
|
+
link.href = href;
|
|
41
|
+
if (openInNewTab) {
|
|
42
|
+
link.target = "_blank";
|
|
43
|
+
link.rel = "noopener noreferrer";
|
|
44
|
+
}
|
|
6
45
|
link.download = fileName || "";
|
|
7
46
|
document.body.appendChild(link);
|
|
8
47
|
link.click();
|
|
9
48
|
document.body.removeChild(link);
|
|
10
49
|
};
|
|
50
|
+
// Anchor `download` attribute is ignored by browsers for cross-origin URLs
|
|
51
|
+
// (e.g. S3), so cross-origin media would open inline instead of downloading.
|
|
52
|
+
// Mutating the URL's query params also breaks presigned S3 URLs, since the
|
|
53
|
+
// signature is computed over the exact query string at signing time.
|
|
54
|
+
// Fetching the file and downloading it via a same-origin blob: URL avoids both issues.
|
|
55
|
+
var triggerBrowserDownload = function (url, fileName) { return __awaiter(void 0, void 0, void 0, function () {
|
|
56
|
+
var response, blob, blobUrl, e_1;
|
|
57
|
+
return __generator(this, function (_a) {
|
|
58
|
+
switch (_a.label) {
|
|
59
|
+
case 0:
|
|
60
|
+
_a.trys.push([0, 3, , 4]);
|
|
61
|
+
return [4 /*yield*/, fetch(url)];
|
|
62
|
+
case 1:
|
|
63
|
+
response = _a.sent();
|
|
64
|
+
if (!response.ok) {
|
|
65
|
+
throw new Error("Failed to fetch file: ".concat(response.status));
|
|
66
|
+
}
|
|
67
|
+
return [4 /*yield*/, response.blob()];
|
|
68
|
+
case 2:
|
|
69
|
+
blob = _a.sent();
|
|
70
|
+
blobUrl = URL.createObjectURL(blob);
|
|
71
|
+
triggerLinkClick(blobUrl, fileName);
|
|
72
|
+
URL.revokeObjectURL(blobUrl);
|
|
73
|
+
return [3 /*break*/, 4];
|
|
74
|
+
case 3:
|
|
75
|
+
e_1 = _a.sent();
|
|
76
|
+
console.error("Failed to download file via fetch, falling back to direct link:", e_1);
|
|
77
|
+
// Fallback for cases fetch can't handle (e.g. no CORS on the host).
|
|
78
|
+
// This won't force a download for cross-origin URLs, but it's the
|
|
79
|
+
// best available option when the blob fetch fails.
|
|
80
|
+
triggerLinkClick(url, fileName, true);
|
|
81
|
+
return [3 /*break*/, 4];
|
|
82
|
+
case 4: return [2 /*return*/];
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
}); };
|
|
11
86
|
export var downloadMediaFile = function (fileUrl, fileName) {
|
|
12
87
|
if (!fileUrl) {
|
|
13
88
|
return;
|
|
14
89
|
}
|
|
15
|
-
triggerBrowserDownload(fileUrl, fileName);
|
|
90
|
+
void triggerBrowserDownload(fileUrl, fileName);
|
|
16
91
|
};
|
|
17
92
|
//# sourceMappingURL=downloadMediaFile.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"downloadMediaFile.js","sourceRoot":"","sources":["../../src/helpers/downloadMediaFile.tsx"],"names":[],"mappings":"AAAA,IAAM,
|
|
1
|
+
{"version":3,"file":"downloadMediaFile.js","sourceRoot":"","sources":["../../src/helpers/downloadMediaFile.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAM,gBAAgB,GAAG,UAAC,IAAY,EAAE,QAAiB,EAAE,YAAoB;IAApB,6BAAA,EAAA,oBAAoB;IAC3E,IAAM,IAAI,GAAG,QAAQ,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC;IACzC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IAEjB,IAAI,YAAY,EAAE;QACd,IAAI,CAAC,MAAM,GAAG,QAAQ,CAAC;QACvB,IAAI,CAAC,GAAG,GAAG,qBAAqB,CAAC;KACpC;IACD,IAAI,CAAC,QAAQ,GAAG,QAAQ,IAAI,EAAE,CAAC;IAC/B,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;IAChC,IAAI,CAAC,KAAK,EAAE,CAAC;IACb,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;AACpC,CAAC,CAAC;AAEF,2EAA2E;AAC3E,6EAA6E;AAC7E,2EAA2E;AAC3E,qEAAqE;AACrE,uFAAuF;AACvF,IAAM,sBAAsB,GAAG,UAAO,GAAW,EAAE,QAAiB;;;;;;gBAE3C,qBAAM,KAAK,CAAC,GAAG,CAAC,EAAA;;gBAA3B,QAAQ,GAAG,SAAgB;gBACjC,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE;oBACd,MAAM,IAAI,KAAK,CAAC,gCAAyB,QAAQ,CAAC,MAAM,CAAE,CAAC,CAAC;iBAC/D;gBACY,qBAAM,QAAQ,CAAC,IAAI,EAAE,EAAA;;gBAA5B,IAAI,GAAG,SAAqB;gBAC5B,OAAO,GAAG,GAAG,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;gBAC1C,gBAAgB,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;gBACpC,GAAG,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC;;;;gBAE7B,OAAO,CAAC,KAAK,CAAC,iEAAiE,EAAE,GAAC,CAAC,CAAC;gBACpF,oEAAoE;gBACpE,kEAAkE;gBAClE,mDAAmD;gBACnD,gBAAgB,CAAC,GAAG,EAAE,QAAQ,EAAE,IAAI,CAAC,CAAC;;;;;KAE7C,CAAC;AAEF,MAAM,CAAC,IAAM,iBAAiB,GAAG,UAAC,OAAe,EAAE,QAAiB;IAChE,IAAI,CAAC,OAAO,EAAE;QACV,OAAO;KACV;IAED,KAAK,sBAAsB,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;AACnD,CAAC,CAAC","sourcesContent":["const triggerLinkClick = (href: string, fileName?: string, openInNewTab = false) => {\n const link = document.createElement(\"a\");\n link.href = href;\n\n if (openInNewTab) {\n link.target = \"_blank\";\n link.rel = \"noopener noreferrer\";\n }\n link.download = fileName || \"\";\n document.body.appendChild(link);\n link.click();\n document.body.removeChild(link);\n};\n\n// Anchor `download` attribute is ignored by browsers for cross-origin URLs\n// (e.g. S3), so cross-origin media would open inline instead of downloading.\n// Mutating the URL's query params also breaks presigned S3 URLs, since the\n// signature is computed over the exact query string at signing time.\n// Fetching the file and downloading it via a same-origin blob: URL avoids both issues.\nconst triggerBrowserDownload = async (url: string, fileName?: string) => {\n try {\n const response = await fetch(url);\n if (!response.ok) {\n throw new Error(`Failed to fetch file: ${response.status}`);\n }\n const blob = await response.blob();\n const blobUrl = URL.createObjectURL(blob);\n triggerLinkClick(blobUrl, fileName);\n URL.revokeObjectURL(blobUrl);\n } catch(e) {\n console.error(\"Failed to download file via fetch, falling back to direct link:\", e);\n // Fallback for cases fetch can't handle (e.g. no CORS on the host).\n // This won't force a download for cross-origin URLs, but it's the\n // best available option when the blob fetch fails.\n triggerLinkClick(url, fileName, true);\n }\n};\n\nexport const downloadMediaFile = (fileUrl: string, fileName?: string) => {\n if (!fileUrl) {\n return;\n }\n\n void triggerBrowserDownload(fileUrl, fileName);\n};\n"]}
|
|
@@ -1,18 +1,45 @@
|
|
|
1
|
-
const
|
|
1
|
+
const triggerLinkClick = (href: string, fileName?: string, openInNewTab = false) => {
|
|
2
2
|
const link = document.createElement("a");
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
link.href = href;
|
|
4
|
+
|
|
5
|
+
if (openInNewTab) {
|
|
6
|
+
link.target = "_blank";
|
|
7
|
+
link.rel = "noopener noreferrer";
|
|
8
|
+
}
|
|
6
9
|
link.download = fileName || "";
|
|
7
10
|
document.body.appendChild(link);
|
|
8
|
-
link.click()
|
|
11
|
+
link.click();
|
|
9
12
|
document.body.removeChild(link);
|
|
10
13
|
};
|
|
11
14
|
|
|
15
|
+
// Anchor `download` attribute is ignored by browsers for cross-origin URLs
|
|
16
|
+
// (e.g. S3), so cross-origin media would open inline instead of downloading.
|
|
17
|
+
// Mutating the URL's query params also breaks presigned S3 URLs, since the
|
|
18
|
+
// signature is computed over the exact query string at signing time.
|
|
19
|
+
// Fetching the file and downloading it via a same-origin blob: URL avoids both issues.
|
|
20
|
+
const triggerBrowserDownload = async (url: string, fileName?: string) => {
|
|
21
|
+
try {
|
|
22
|
+
const response = await fetch(url);
|
|
23
|
+
if (!response.ok) {
|
|
24
|
+
throw new Error(`Failed to fetch file: ${response.status}`);
|
|
25
|
+
}
|
|
26
|
+
const blob = await response.blob();
|
|
27
|
+
const blobUrl = URL.createObjectURL(blob);
|
|
28
|
+
triggerLinkClick(blobUrl, fileName);
|
|
29
|
+
URL.revokeObjectURL(blobUrl);
|
|
30
|
+
} catch(e) {
|
|
31
|
+
console.error("Failed to download file via fetch, falling back to direct link:", e);
|
|
32
|
+
// Fallback for cases fetch can't handle (e.g. no CORS on the host).
|
|
33
|
+
// This won't force a download for cross-origin URLs, but it's the
|
|
34
|
+
// best available option when the blob fetch fails.
|
|
35
|
+
triggerLinkClick(url, fileName, true);
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
|
|
12
39
|
export const downloadMediaFile = (fileUrl: string, fileName?: string) => {
|
|
13
40
|
if (!fileUrl) {
|
|
14
41
|
return;
|
|
15
42
|
}
|
|
16
43
|
|
|
17
|
-
triggerBrowserDownload(fileUrl, fileName);
|
|
44
|
+
void triggerBrowserDownload(fileUrl, fileName);
|
|
18
45
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@solidxai/core-ui",
|
|
3
|
-
"version": "0.1.13-beta.
|
|
3
|
+
"version": "0.1.13-beta.6",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"build:tailwind": "tailwindcss -i ./src/resources/solid-tailwind.css -o ./src/resources/solid-tailwind-generated.css -c ./tailwind.config.js --minify",
|
|
6
6
|
"prebuild": "npm run build:tailwind && npm run copy-resources && npm run copy-styles",
|