@proveanything/smartlinks-utils-ui 1.13.15 → 1.13.16
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.
|
@@ -15,6 +15,24 @@ var ASSET_MIME_FILTERS = [
|
|
|
15
15
|
{ value: "document", label: "Documents", prefix: "application/" },
|
|
16
16
|
{ value: "pdf", label: "PDFs", prefix: "application/pdf" }
|
|
17
17
|
];
|
|
18
|
+
|
|
19
|
+
// src/components/AssetPicker/errors.ts
|
|
20
|
+
function friendlyAssetError(err, fallback) {
|
|
21
|
+
if (!err) return fallback;
|
|
22
|
+
const resp = err.errorResponse;
|
|
23
|
+
if (resp) {
|
|
24
|
+
const detailText = resp.details?.errorText;
|
|
25
|
+
if (typeof detailText === "string" && detailText.trim()) return detailText.trim();
|
|
26
|
+
if (typeof resp.message === "string" && resp.message.trim()) return resp.message.trim();
|
|
27
|
+
}
|
|
28
|
+
if (typeof err.errorText === "string" && err.errorText.trim()) return err.errorText.trim();
|
|
29
|
+
const raw = typeof err.message === "string" ? err.message : String(err);
|
|
30
|
+
const stripped = raw.replace(/^Error\s+\d+:\s*/i, "").trim();
|
|
31
|
+
if (stripped) return stripped;
|
|
32
|
+
return fallback;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// src/components/AssetPicker/useAssets.ts
|
|
18
36
|
function useAssets({ scope, accept, pageSize, appId, listAppId }) {
|
|
19
37
|
const [assets, setAssets] = useState([]);
|
|
20
38
|
const [loading, setLoading] = useState(true);
|
|
@@ -62,7 +80,7 @@ function useAssets({ scope, accept, pageSize, appId, listAppId }) {
|
|
|
62
80
|
}
|
|
63
81
|
} catch (err) {
|
|
64
82
|
if (mountedRef.current) {
|
|
65
|
-
setError(err
|
|
83
|
+
setError(friendlyAssetError(err, "Failed to load assets"));
|
|
66
84
|
setAssets([]);
|
|
67
85
|
}
|
|
68
86
|
} finally {
|
|
@@ -75,6 +93,7 @@ function useAssets({ scope, accept, pageSize, appId, listAppId }) {
|
|
|
75
93
|
const upload = useCallback(async (file, onProgress, scopeOverride) => {
|
|
76
94
|
setUploading(true);
|
|
77
95
|
setUploadProgress(0);
|
|
96
|
+
setError(null);
|
|
78
97
|
try {
|
|
79
98
|
const result = await SL.asset.upload({
|
|
80
99
|
file,
|
|
@@ -92,7 +111,7 @@ function useAssets({ scope, accept, pageSize, appId, listAppId }) {
|
|
|
92
111
|
}
|
|
93
112
|
return result;
|
|
94
113
|
} catch (err) {
|
|
95
|
-
if (mountedRef.current) setError(err
|
|
114
|
+
if (mountedRef.current) setError(friendlyAssetError(err, "Upload failed"));
|
|
96
115
|
return null;
|
|
97
116
|
} finally {
|
|
98
117
|
if (mountedRef.current) {
|
|
@@ -104,6 +123,7 @@ function useAssets({ scope, accept, pageSize, appId, listAppId }) {
|
|
|
104
123
|
const uploadFromUrl = useCallback(async (url, name, scopeOverride) => {
|
|
105
124
|
setUploading(true);
|
|
106
125
|
setUploadProgress(0);
|
|
126
|
+
setError(null);
|
|
107
127
|
try {
|
|
108
128
|
const response = await fetch(url);
|
|
109
129
|
if (!response.ok) throw new Error(`Failed to fetch: ${response.statusText}`);
|
|
@@ -112,7 +132,7 @@ function useAssets({ scope, accept, pageSize, appId, listAppId }) {
|
|
|
112
132
|
const file = new File([blob], fileName, { type: blob.type });
|
|
113
133
|
return await upload(file, void 0, scopeOverride);
|
|
114
134
|
} catch (err) {
|
|
115
|
-
if (mountedRef.current) setError(err
|
|
135
|
+
if (mountedRef.current) setError(friendlyAssetError(err, "URL import failed"));
|
|
116
136
|
return null;
|
|
117
137
|
} finally {
|
|
118
138
|
if (mountedRef.current) {
|
|
@@ -124,6 +144,7 @@ function useAssets({ scope, accept, pageSize, appId, listAppId }) {
|
|
|
124
144
|
const uploadFromRemoteUrl = useCallback(async (url, opts) => {
|
|
125
145
|
setUploading(true);
|
|
126
146
|
setUploadProgress(0);
|
|
147
|
+
setError(null);
|
|
127
148
|
try {
|
|
128
149
|
const result = await SL.asset.uploadFromUrl({
|
|
129
150
|
url,
|
|
@@ -137,7 +158,7 @@ function useAssets({ scope, accept, pageSize, appId, listAppId }) {
|
|
|
137
158
|
}
|
|
138
159
|
return result;
|
|
139
160
|
} catch (err) {
|
|
140
|
-
if (mountedRef.current) setError(err
|
|
161
|
+
if (mountedRef.current) setError(friendlyAssetError(err, "We couldn't import that URL. Please check it's correct and publicly accessible."));
|
|
141
162
|
return null;
|
|
142
163
|
} finally {
|
|
143
164
|
if (mountedRef.current) {
|
|
@@ -159,7 +180,7 @@ function useAssets({ scope, accept, pageSize, appId, listAppId }) {
|
|
|
159
180
|
}
|
|
160
181
|
return true;
|
|
161
182
|
} catch (err) {
|
|
162
|
-
if (mountedRef.current) setError(err
|
|
183
|
+
if (mountedRef.current) setError(friendlyAssetError(err, "Delete failed"));
|
|
163
184
|
return false;
|
|
164
185
|
}
|
|
165
186
|
}, [scope]);
|
|
@@ -179,7 +200,7 @@ function useAssets({ scope, accept, pageSize, appId, listAppId }) {
|
|
|
179
200
|
}
|
|
180
201
|
return result;
|
|
181
202
|
} catch (err) {
|
|
182
|
-
if (mountedRef.current) setError(err
|
|
203
|
+
if (mountedRef.current) setError(friendlyAssetError(err, "Restore failed"));
|
|
183
204
|
return null;
|
|
184
205
|
}
|
|
185
206
|
}, [scope]);
|
|
@@ -191,6 +212,7 @@ function useAssets({ scope, accept, pageSize, appId, listAppId }) {
|
|
|
191
212
|
}
|
|
192
213
|
setUploading(true);
|
|
193
214
|
setUploadProgress(0);
|
|
215
|
+
setError(null);
|
|
194
216
|
try {
|
|
195
217
|
const result = await SL.asset.replaceFile({
|
|
196
218
|
collectionId,
|
|
@@ -206,7 +228,7 @@ function useAssets({ scope, accept, pageSize, appId, listAppId }) {
|
|
|
206
228
|
}
|
|
207
229
|
return result;
|
|
208
230
|
} catch (err) {
|
|
209
|
-
if (mountedRef.current) setError(err
|
|
231
|
+
if (mountedRef.current) setError(friendlyAssetError(err, "Replace failed"));
|
|
210
232
|
return null;
|
|
211
233
|
} finally {
|
|
212
234
|
if (mountedRef.current) {
|
|
@@ -228,7 +250,7 @@ function useAssets({ scope, accept, pageSize, appId, listAppId }) {
|
|
|
228
250
|
}
|
|
229
251
|
return result;
|
|
230
252
|
} catch (err) {
|
|
231
|
-
if (mountedRef.current) setError(err
|
|
253
|
+
if (mountedRef.current) setError(friendlyAssetError(err, "Update failed"));
|
|
232
254
|
return null;
|
|
233
255
|
}
|
|
234
256
|
}, [scope]);
|
|
@@ -3886,6 +3908,14 @@ var AssetPickerContent = ({
|
|
|
3886
3908
|
)
|
|
3887
3909
|
] })
|
|
3888
3910
|
] }),
|
|
3911
|
+
assetsError && tab !== "browse" && /* @__PURE__ */ jsx(
|
|
3912
|
+
"div",
|
|
3913
|
+
{
|
|
3914
|
+
role: "alert",
|
|
3915
|
+
className: "px-3 py-2 text-xs rounded-md border border-destructive/40 bg-destructive/10 text-destructive",
|
|
3916
|
+
children: assetsError
|
|
3917
|
+
}
|
|
3918
|
+
),
|
|
3889
3919
|
tab === "browse" && /* @__PURE__ */ jsx(
|
|
3890
3920
|
ScopedAssetBrowser,
|
|
3891
3921
|
{
|
|
@@ -4051,15 +4081,24 @@ var PickerDialog = ({ open, onClose, maxWidth, children }) => {
|
|
|
4051
4081
|
/* @__PURE__ */ jsx(
|
|
4052
4082
|
"div",
|
|
4053
4083
|
{
|
|
4054
|
-
className: "absolute inset-0
|
|
4084
|
+
className: "absolute inset-0 backdrop-blur-sm",
|
|
4085
|
+
style: {
|
|
4086
|
+
backgroundColor: "rgba(0, 0, 0, 0.2)",
|
|
4087
|
+
backdropFilter: "blur(4px)",
|
|
4088
|
+
WebkitBackdropFilter: "blur(4px)"
|
|
4089
|
+
},
|
|
4055
4090
|
onClick: onClose
|
|
4056
4091
|
}
|
|
4057
4092
|
),
|
|
4058
4093
|
/* @__PURE__ */ jsxs(
|
|
4059
4094
|
"div",
|
|
4060
4095
|
{
|
|
4061
|
-
className: "relative z-10 w-full max-h-[85vh] bg-background
|
|
4062
|
-
style: {
|
|
4096
|
+
className: "relative z-10 w-full max-h-[85vh] bg-background border border-border flex flex-col overflow-hidden mx-4",
|
|
4097
|
+
style: {
|
|
4098
|
+
maxWidth: maxWidth || "56rem",
|
|
4099
|
+
borderRadius: "0.75rem",
|
|
4100
|
+
boxShadow: "0 25px 60px -15px rgb(0 0 0 / 0.35), 0 10px 25px -10px rgb(0 0 0 / 0.25), 0 0 0 1px rgb(0 0 0 / 0.05)"
|
|
4101
|
+
},
|
|
4063
4102
|
onClick: (e) => e.stopPropagation(),
|
|
4064
4103
|
onMouseDown: (e) => e.stopPropagation(),
|
|
4065
4104
|
onTouchStart: (e) => e.stopPropagation(),
|
|
@@ -4116,5 +4155,5 @@ var AssetPicker = (props) => {
|
|
|
4116
4155
|
assertStylesLoaded();
|
|
4117
4156
|
|
|
4118
4157
|
export { ASSET_MIME_FILTERS, AssetPicker, useAppRegistry, useAssets };
|
|
4119
|
-
//# sourceMappingURL=chunk-
|
|
4120
|
-
//# sourceMappingURL=chunk-
|
|
4158
|
+
//# sourceMappingURL=chunk-5NKKNCFT.js.map
|
|
4159
|
+
//# sourceMappingURL=chunk-5NKKNCFT.js.map
|