@proveanything/smartlinks-utils-ui 1.13.3 → 1.13.4

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,66 +15,6 @@ var ASSET_MIME_FILTERS = [
15
15
  { value: "document", label: "Documents", prefix: "application/" },
16
16
  { value: "pdf", label: "PDFs", prefix: "application/pdf" }
17
17
  ];
18
- function safeDecode(value) {
19
- if (!value) return "";
20
- try {
21
- return decodeURIComponent(value);
22
- } catch {
23
- return value;
24
- }
25
- }
26
- function getAssetIdentityKeys(asset2) {
27
- const keys = [];
28
- if (asset2.id) keys.push(`id:${asset2.id}`);
29
- const normalizedUrl = safeDecode(asset2.url).trim().toLowerCase();
30
- if (normalizedUrl) keys.push(`url:${normalizedUrl}`);
31
- const normalizedThumb = safeDecode(asset2.thumbnail).trim().toLowerCase();
32
- if (normalizedThumb) keys.push(`thumb:${normalizedThumb}`);
33
- const normalizedHash = asset2.hash?.trim().toLowerCase();
34
- if (normalizedHash) keys.push(`hash:${normalizedHash}`);
35
- return keys;
36
- }
37
- function scoreAsset(asset2) {
38
- const productId = asset2.productId ?? asset2.metadata?.productId;
39
- const proofId = asset2.proofId ?? asset2.metadata?.proofId;
40
- const plainName = asset2.name && !asset2.name.startsWith("sites/") ? 1 : 0;
41
- const plainCleanName = asset2.cleanName && !asset2.cleanName.startsWith("sites/") ? 1 : 0;
42
- return (proofId ? 32 : 0) + (productId ? 16 : 0) + (asset2.thumbnail ? 8 : 0) + (asset2.mimeType ? 4 : 0) + (asset2.size ? 2 : 0) + plainName + plainCleanName;
43
- }
44
- function mergeAssets(a, b) {
45
- const keepB = scoreAsset(b) > scoreAsset(a);
46
- const primary = keepB ? b : a;
47
- const secondary = keepB ? a : b;
48
- return {
49
- ...secondary,
50
- ...primary,
51
- metadata: {
52
- ...secondary.metadata || {},
53
- ...primary.metadata || {}
54
- },
55
- labels: Array.from(/* @__PURE__ */ new Set([...secondary.labels || [], ...primary.labels || []])),
56
- thumbnail: primary.thumbnail ?? secondary.thumbnail ?? null,
57
- app: primary.app ?? secondary.app ?? null,
58
- thumbnails: primary.thumbnails ?? secondary.thumbnails
59
- };
60
- }
61
- function dedupeAssetList(items) {
62
- const deduped = [];
63
- const keyToIndex = /* @__PURE__ */ new Map();
64
- for (const asset2 of items) {
65
- const keys = getAssetIdentityKeys(asset2);
66
- const existingIndex = keys.map((key) => keyToIndex.get(key)).find((index) => index !== void 0);
67
- if (existingIndex === void 0) {
68
- const nextIndex = deduped.push(asset2) - 1;
69
- keys.forEach((key) => keyToIndex.set(key, nextIndex));
70
- continue;
71
- }
72
- const merged = mergeAssets(deduped[existingIndex], asset2);
73
- deduped[existingIndex] = merged;
74
- getAssetIdentityKeys(merged).forEach((key) => keyToIndex.set(key, existingIndex));
75
- }
76
- return deduped;
77
- }
78
18
  function useAssets({ scope, accept, pageSize, appId, listAppId }) {
79
19
  const [assets, setAssets] = useState([]);
80
20
  const [loading, setLoading] = useState(true);
@@ -102,19 +42,7 @@ function useAssets({ scope, accept, pageSize, appId, listAppId }) {
102
42
  ...listAppId ? { appId: listAppId } : {}
103
43
  });
104
44
  if (mountedRef.current) {
105
- const raw = result;
106
- const deduped = dedupeAssetList(raw);
107
- const idCounts = /* @__PURE__ */ new Map();
108
- for (const a of raw) idCounts.set(a.id, (idCounts.get(a.id) || 0) + 1);
109
- const dupIds = Array.from(idCounts.entries()).filter(([, n]) => n > 1);
110
- console.debug("[AssetPicker] list", {
111
- scope,
112
- listAppId,
113
- rawCount: raw.length,
114
- dedupedCount: deduped.length,
115
- duplicateIds: dupIds
116
- });
117
- setAssets(deduped);
45
+ setAssets(result);
118
46
  }
119
47
  } catch (err) {
120
48
  if (mountedRef.current) {
@@ -144,7 +72,7 @@ function useAssets({ scope, accept, pageSize, appId, listAppId }) {
144
72
  }
145
73
  });
146
74
  if (mountedRef.current && !scopeOverride) {
147
- setAssets((prev) => dedupeAssetList([result, ...prev]));
75
+ setAssets((prev) => [result, ...prev]);
148
76
  }
149
77
  return result;
150
78
  } catch (err) {
@@ -189,7 +117,7 @@ function useAssets({ scope, accept, pageSize, appId, listAppId }) {
189
117
  admin: true
190
118
  });
191
119
  if (mountedRef.current && !opts?.scopeOverride) {
192
- setAssets((prev) => dedupeAssetList([result, ...prev]));
120
+ setAssets((prev) => [result, ...prev]);
193
121
  }
194
122
  return result;
195
123
  } catch (err) {
@@ -228,10 +156,10 @@ function useAssets({ scope, accept, pageSize, appId, listAppId }) {
228
156
  try {
229
157
  const result = await SL.asset.restoreAdmin(collectionId, assetId);
230
158
  if (mountedRef.current) {
231
- setAssets((prev) => dedupeAssetList((() => {
159
+ setAssets((prev) => {
232
160
  const exists = prev.some((a) => a.id === assetId);
233
161
  return exists ? prev.map((a) => a.id === assetId ? result : a) : [result, ...prev];
234
- })()));
162
+ });
235
163
  }
236
164
  return result;
237
165
  } catch (err) {
@@ -258,7 +186,7 @@ function useAssets({ scope, accept, pageSize, appId, listAppId }) {
258
186
  }
259
187
  });
260
188
  if (mountedRef.current) {
261
- setAssets((prev) => dedupeAssetList(prev.map((a) => a.id === assetId ? result : a)));
189
+ setAssets((prev) => prev.map((a) => a.id === assetId ? result : a));
262
190
  }
263
191
  return result;
264
192
  } catch (err) {
@@ -280,7 +208,7 @@ function useAssets({ scope, accept, pageSize, appId, listAppId }) {
280
208
  try {
281
209
  const result = await SL.asset.updateAdmin({ collectionId, assetId, ...patch });
282
210
  if (mountedRef.current) {
283
- setAssets((prev) => dedupeAssetList(prev.map((a) => a.id === assetId ? result : a)));
211
+ setAssets((prev) => prev.map((a) => a.id === assetId ? result : a));
284
212
  }
285
213
  return result;
286
214
  } catch (err) {
@@ -2163,7 +2091,7 @@ var AttachToContextToggle = ({ checked, onChange, contextLabel }) => /* @__PURE_
2163
2091
  /* @__PURE__ */ jsx("span", { className: "block", children: checked ? `Asset will be tagged to ${contextLabel}.` : `Asset will be added to the collection (available everywhere). Tick to attach it to ${contextLabel} instead.` })
2164
2092
  ] })
2165
2093
  ] });
2166
- var ScopedAssetBrowser = ({ scope: _scope, accept: _accept, pageSize: _pageSize, viewMode, search, selectedIds, onToggleSelect, onDoubleClickSelect, onDelete, allowDelete, emptyText, listAppId: _listAppId, requireProductId, currentAppId, currentAppName, getAppName, assets, loading, error, refresh, remove, updateAsset, replaceFile }) => {
2094
+ var ScopedAssetBrowser = ({ scope: _scope, accept: _accept, pageSize: _pageSize, viewMode, search, selectedIds, onToggleSelect, onDoubleClickSelect, onDelete, allowDelete, emptyText, listAppId: _listAppId, currentAppId, currentAppName, getAppName, assets, loading, error, refresh, remove, updateAsset, replaceFile }) => {
2167
2095
  const replaceInputRef = React7.useRef(null);
2168
2096
  const replaceTargetRef = React7.useRef(null);
2169
2097
  const handleRename = useCallback(async (asset2) => {
@@ -2222,10 +2150,6 @@ var ScopedAssetBrowser = ({ scope: _scope, accept: _accept, pageSize: _pageSize,
2222
2150
  const filteredAssets = useMemo(() => {
2223
2151
  const q = search.trim().toLowerCase();
2224
2152
  return assets.filter((a) => {
2225
- if (requireProductId) {
2226
- const pid = a.productId || a.metadata?.productId || (a.scope?.type === "product" ? a.scope?.productId : void 0);
2227
- if (pid !== requireProductId) return false;
2228
- }
2229
2153
  if (q) {
2230
2154
  const hit = (a.name || "").toLowerCase().includes(q) || (a.cleanName || "").toLowerCase().includes(q) || (a.mimeType || "").toLowerCase().includes(q) || (a.labels || []).some((l) => l.toLowerCase().includes(q));
2231
2155
  if (!hit) return false;
@@ -2238,7 +2162,7 @@ var ScopedAssetBrowser = ({ scope: _scope, accept: _accept, pageSize: _pageSize,
2238
2162
  }
2239
2163
  return true;
2240
2164
  });
2241
- }, [assets, search, activeLabels, requireProductId]);
2165
+ }, [assets, search, activeLabels]);
2242
2166
  if (loading && assets.length === 0) {
2243
2167
  return /* @__PURE__ */ jsx("div", { className: "flex items-center justify-center py-12", children: /* @__PURE__ */ jsx(Loader2, { className: "w-6 h-6 text-muted-foreground animate-spin" }) });
2244
2168
  }
@@ -2696,7 +2620,6 @@ var AssetPickerContent = ({
2696
2620
  allowDelete,
2697
2621
  emptyText,
2698
2622
  listAppId,
2699
- requireProductId: hasProductScope && scopeTab === "product" ? productScope.productId : void 0,
2700
2623
  currentAppId: appId,
2701
2624
  currentAppName: resolvedAppName,
2702
2625
  getAppName,
@@ -2910,5 +2833,5 @@ var AssetPicker = (props) => {
2910
2833
  assertStylesLoaded();
2911
2834
 
2912
2835
  export { ASSET_MIME_FILTERS, AssetPicker, useAppRegistry, useAssets };
2913
- //# sourceMappingURL=chunk-VP4LZEEZ.js.map
2914
- //# sourceMappingURL=chunk-VP4LZEEZ.js.map
2836
+ //# sourceMappingURL=chunk-R3B5CK2M.js.map
2837
+ //# sourceMappingURL=chunk-R3B5CK2M.js.map