@proveanything/smartlinks-utils-ui 1.13.15 → 1.13.18

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,33 @@ 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 details = err.details;
23
+ if (details && typeof details === "object") {
24
+ if (typeof details.errorText === "string" && details.errorText.trim()) {
25
+ return details.errorText.trim();
26
+ }
27
+ if (typeof details.message === "string" && details.message.trim()) {
28
+ return details.message.trim();
29
+ }
30
+ }
31
+ const resp = err.errorResponse;
32
+ if (resp) {
33
+ const detailText = resp.details?.errorText;
34
+ if (typeof detailText === "string" && detailText.trim()) return detailText.trim();
35
+ if (typeof resp.message === "string" && resp.message.trim()) return resp.message.trim();
36
+ if (typeof resp.errorText === "string" && resp.errorText.trim()) return resp.errorText.trim();
37
+ }
38
+ if (typeof err.errorText === "string" && err.errorText.trim()) return err.errorText.trim();
39
+ const raw = typeof err.message === "string" ? err.message : String(err);
40
+ const stripped = raw.replace(/^Error\s+\d+:\s*/i, "").trim();
41
+ return stripped || fallback;
42
+ }
43
+
44
+ // src/components/AssetPicker/useAssets.ts
18
45
  function useAssets({ scope, accept, pageSize, appId, listAppId }) {
19
46
  const [assets, setAssets] = useState([]);
20
47
  const [loading, setLoading] = useState(true);
@@ -62,7 +89,7 @@ function useAssets({ scope, accept, pageSize, appId, listAppId }) {
62
89
  }
63
90
  } catch (err) {
64
91
  if (mountedRef.current) {
65
- setError(err?.message || "Failed to load assets");
92
+ setError(friendlyAssetError(err, "Failed to load assets"));
66
93
  setAssets([]);
67
94
  }
68
95
  } finally {
@@ -75,6 +102,7 @@ function useAssets({ scope, accept, pageSize, appId, listAppId }) {
75
102
  const upload = useCallback(async (file, onProgress, scopeOverride) => {
76
103
  setUploading(true);
77
104
  setUploadProgress(0);
105
+ setError(null);
78
106
  try {
79
107
  const result = await SL.asset.upload({
80
108
  file,
@@ -92,7 +120,7 @@ function useAssets({ scope, accept, pageSize, appId, listAppId }) {
92
120
  }
93
121
  return result;
94
122
  } catch (err) {
95
- if (mountedRef.current) setError(err?.message || "Upload failed");
123
+ if (mountedRef.current) setError(friendlyAssetError(err, "Upload failed"));
96
124
  return null;
97
125
  } finally {
98
126
  if (mountedRef.current) {
@@ -104,6 +132,7 @@ function useAssets({ scope, accept, pageSize, appId, listAppId }) {
104
132
  const uploadFromUrl = useCallback(async (url, name, scopeOverride) => {
105
133
  setUploading(true);
106
134
  setUploadProgress(0);
135
+ setError(null);
107
136
  try {
108
137
  const response = await fetch(url);
109
138
  if (!response.ok) throw new Error(`Failed to fetch: ${response.statusText}`);
@@ -112,7 +141,7 @@ function useAssets({ scope, accept, pageSize, appId, listAppId }) {
112
141
  const file = new File([blob], fileName, { type: blob.type });
113
142
  return await upload(file, void 0, scopeOverride);
114
143
  } catch (err) {
115
- if (mountedRef.current) setError(err?.message || "URL import failed");
144
+ if (mountedRef.current) setError(friendlyAssetError(err, "URL import failed"));
116
145
  return null;
117
146
  } finally {
118
147
  if (mountedRef.current) {
@@ -124,6 +153,7 @@ function useAssets({ scope, accept, pageSize, appId, listAppId }) {
124
153
  const uploadFromRemoteUrl = useCallback(async (url, opts) => {
125
154
  setUploading(true);
126
155
  setUploadProgress(0);
156
+ setError(null);
127
157
  try {
128
158
  const result = await SL.asset.uploadFromUrl({
129
159
  url,
@@ -137,7 +167,7 @@ function useAssets({ scope, accept, pageSize, appId, listAppId }) {
137
167
  }
138
168
  return result;
139
169
  } catch (err) {
140
- if (mountedRef.current) setError(err?.message || "Remote URL ingest failed");
170
+ if (mountedRef.current) setError(friendlyAssetError(err, "We couldn't import that URL. Please check it's correct and publicly accessible."));
141
171
  return null;
142
172
  } finally {
143
173
  if (mountedRef.current) {
@@ -159,7 +189,7 @@ function useAssets({ scope, accept, pageSize, appId, listAppId }) {
159
189
  }
160
190
  return true;
161
191
  } catch (err) {
162
- if (mountedRef.current) setError(err?.message || "Delete failed");
192
+ if (mountedRef.current) setError(friendlyAssetError(err, "Delete failed"));
163
193
  return false;
164
194
  }
165
195
  }, [scope]);
@@ -179,7 +209,7 @@ function useAssets({ scope, accept, pageSize, appId, listAppId }) {
179
209
  }
180
210
  return result;
181
211
  } catch (err) {
182
- if (mountedRef.current) setError(err?.message || "Restore failed");
212
+ if (mountedRef.current) setError(friendlyAssetError(err, "Restore failed"));
183
213
  return null;
184
214
  }
185
215
  }, [scope]);
@@ -191,6 +221,7 @@ function useAssets({ scope, accept, pageSize, appId, listAppId }) {
191
221
  }
192
222
  setUploading(true);
193
223
  setUploadProgress(0);
224
+ setError(null);
194
225
  try {
195
226
  const result = await SL.asset.replaceFile({
196
227
  collectionId,
@@ -206,7 +237,7 @@ function useAssets({ scope, accept, pageSize, appId, listAppId }) {
206
237
  }
207
238
  return result;
208
239
  } catch (err) {
209
- if (mountedRef.current) setError(err?.message || "Replace failed");
240
+ if (mountedRef.current) setError(friendlyAssetError(err, "Replace failed"));
210
241
  return null;
211
242
  } finally {
212
243
  if (mountedRef.current) {
@@ -228,7 +259,7 @@ function useAssets({ scope, accept, pageSize, appId, listAppId }) {
228
259
  }
229
260
  return result;
230
261
  } catch (err) {
231
- if (mountedRef.current) setError(err?.message || "Update failed");
262
+ if (mountedRef.current) setError(friendlyAssetError(err, "Update failed"));
232
263
  return null;
233
264
  }
234
265
  }, [scope]);
@@ -3886,6 +3917,14 @@ var AssetPickerContent = ({
3886
3917
  )
3887
3918
  ] })
3888
3919
  ] }),
3920
+ assetsError && tab !== "browse" && /* @__PURE__ */ jsx(
3921
+ "div",
3922
+ {
3923
+ role: "alert",
3924
+ className: "px-3 py-2 text-xs rounded-md border border-destructive/40 bg-destructive/10 text-destructive",
3925
+ children: assetsError
3926
+ }
3927
+ ),
3889
3928
  tab === "browse" && /* @__PURE__ */ jsx(
3890
3929
  ScopedAssetBrowser,
3891
3930
  {
@@ -4051,15 +4090,24 @@ var PickerDialog = ({ open, onClose, maxWidth, children }) => {
4051
4090
  /* @__PURE__ */ jsx(
4052
4091
  "div",
4053
4092
  {
4054
- className: "absolute inset-0 bg-black/50 backdrop-blur-sm",
4093
+ className: "absolute inset-0 backdrop-blur-sm",
4094
+ style: {
4095
+ backgroundColor: "rgba(0, 0, 0, 0.2)",
4096
+ backdropFilter: "blur(4px)",
4097
+ WebkitBackdropFilter: "blur(4px)"
4098
+ },
4055
4099
  onClick: onClose
4056
4100
  }
4057
4101
  ),
4058
4102
  /* @__PURE__ */ jsxs(
4059
4103
  "div",
4060
4104
  {
4061
- className: "relative z-10 w-full max-h-[85vh] bg-background rounded-xl shadow-2xl border border-border flex flex-col overflow-hidden mx-4",
4062
- style: { maxWidth: maxWidth || "56rem" },
4105
+ className: "relative z-10 w-full max-h-[85vh] bg-background border border-border flex flex-col overflow-hidden mx-4",
4106
+ style: {
4107
+ maxWidth: maxWidth || "56rem",
4108
+ borderRadius: "0.75rem",
4109
+ 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)"
4110
+ },
4063
4111
  onClick: (e) => e.stopPropagation(),
4064
4112
  onMouseDown: (e) => e.stopPropagation(),
4065
4113
  onTouchStart: (e) => e.stopPropagation(),
@@ -4116,5 +4164,5 @@ var AssetPicker = (props) => {
4116
4164
  assertStylesLoaded();
4117
4165
 
4118
4166
  export { ASSET_MIME_FILTERS, AssetPicker, useAppRegistry, useAssets };
4119
- //# sourceMappingURL=chunk-LRWXRRNJ.js.map
4120
- //# sourceMappingURL=chunk-LRWXRRNJ.js.map
4167
+ //# sourceMappingURL=chunk-2LIV5MSN.js.map
4168
+ //# sourceMappingURL=chunk-2LIV5MSN.js.map