@proveanything/smartlinks-utils-ui 1.13.14 → 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?.message || "Failed to load assets");
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?.message || "Upload failed");
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?.message || "URL import failed");
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?.message || "Remote URL ingest failed");
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?.message || "Delete failed");
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?.message || "Restore failed");
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?.message || "Replace failed");
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?.message || "Update failed");
253
+ if (mountedRef.current) setError(friendlyAssetError(err, "Update failed"));
232
254
  return null;
233
255
  }
234
256
  }, [scope]);
@@ -3686,7 +3708,10 @@ var AssetPickerContent = ({
3686
3708
  const handleUrlImport = useCallback(async (url, name) => {
3687
3709
  const targetScope = uploadScope;
3688
3710
  const sameAsActive = targetScope === activeScope;
3689
- const result = await uploadFromUrl(url, name, sameAsActive ? void 0 : targetScope);
3711
+ const result = await uploadFromRemoteUrl(url, {
3712
+ name,
3713
+ ...sameAsActive ? {} : { scopeOverride: targetScope }
3714
+ });
3690
3715
  if (result) {
3691
3716
  setTab("browse");
3692
3717
  if (!multiple) {
@@ -3696,7 +3721,7 @@ var AssetPickerContent = ({
3696
3721
  await reconcileAfterUpload(targetScope);
3697
3722
  }
3698
3723
  return result;
3699
- }, [uploadFromUrl, multiple, onSelect, toSelection, uploadScope, activeScope, reconcileAfterUpload]);
3724
+ }, [uploadFromRemoteUrl, multiple, onSelect, toSelection, uploadScope, activeScope, reconcileAfterUpload]);
3700
3725
  const handleRemoteIngest = useCallback(async (url, name) => {
3701
3726
  const targetScope = uploadScope;
3702
3727
  const sameAsActive = targetScope === activeScope;
@@ -3883,6 +3908,14 @@ var AssetPickerContent = ({
3883
3908
  )
3884
3909
  ] })
3885
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
+ ),
3886
3919
  tab === "browse" && /* @__PURE__ */ jsx(
3887
3920
  ScopedAssetBrowser,
3888
3921
  {
@@ -4048,15 +4081,24 @@ var PickerDialog = ({ open, onClose, maxWidth, children }) => {
4048
4081
  /* @__PURE__ */ jsx(
4049
4082
  "div",
4050
4083
  {
4051
- className: "absolute inset-0 bg-black/50 backdrop-blur-sm",
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
+ },
4052
4090
  onClick: onClose
4053
4091
  }
4054
4092
  ),
4055
4093
  /* @__PURE__ */ jsxs(
4056
4094
  "div",
4057
4095
  {
4058
- 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",
4059
- style: { maxWidth: maxWidth || "56rem" },
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
+ },
4060
4102
  onClick: (e) => e.stopPropagation(),
4061
4103
  onMouseDown: (e) => e.stopPropagation(),
4062
4104
  onTouchStart: (e) => e.stopPropagation(),
@@ -4113,5 +4155,5 @@ var AssetPicker = (props) => {
4113
4155
  assertStylesLoaded();
4114
4156
 
4115
4157
  export { ASSET_MIME_FILTERS, AssetPicker, useAppRegistry, useAssets };
4116
- //# sourceMappingURL=chunk-I3T36FSI.js.map
4117
- //# sourceMappingURL=chunk-I3T36FSI.js.map
4158
+ //# sourceMappingURL=chunk-5NKKNCFT.js.map
4159
+ //# sourceMappingURL=chunk-5NKKNCFT.js.map