@arbidocs/blocks 0.3.112 → 0.3.113
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.
- package/dist/index.cjs +23 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +24 -3
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -1451,14 +1451,35 @@ function useAssetResolverActive() {
|
|
|
1451
1451
|
function isAssetRef(src) {
|
|
1452
1452
|
return !!src && src.startsWith(ASSET_REF_PREFIX);
|
|
1453
1453
|
}
|
|
1454
|
+
function useAssetImage(docId) {
|
|
1455
|
+
const arbi = react.useArbi();
|
|
1456
|
+
const { data: thumbs } = react.useThumbnails([docId]);
|
|
1457
|
+
const thumb = thumbs?.[docId];
|
|
1458
|
+
const { data: objectUrl } = reactQuery.useQuery({
|
|
1459
|
+
queryKey: ["arbi", "asset-image", docId],
|
|
1460
|
+
queryFn: async () => {
|
|
1461
|
+
const res = await arbi.documents.download(docId);
|
|
1462
|
+
const blob = await res.blob();
|
|
1463
|
+
return URL.createObjectURL(blob);
|
|
1464
|
+
},
|
|
1465
|
+
// Only download when the thumbnail is genuinely absent (not merely loading).
|
|
1466
|
+
enabled: !!docId && thumbs != null && !thumb && arbi.hasWorkspace,
|
|
1467
|
+
staleTime: 10 * 6e4
|
|
1468
|
+
});
|
|
1469
|
+
react$1.useEffect(() => {
|
|
1470
|
+
return () => {
|
|
1471
|
+
if (objectUrl) URL.revokeObjectURL(objectUrl);
|
|
1472
|
+
};
|
|
1473
|
+
}, [objectUrl]);
|
|
1474
|
+
return thumb ?? objectUrl;
|
|
1475
|
+
}
|
|
1454
1476
|
function AssetThumb({
|
|
1455
1477
|
docId,
|
|
1456
1478
|
alt,
|
|
1457
1479
|
className,
|
|
1458
1480
|
testId
|
|
1459
1481
|
}) {
|
|
1460
|
-
const
|
|
1461
|
-
const src = data?.[docId];
|
|
1482
|
+
const src = useAssetImage(docId);
|
|
1462
1483
|
return /* @__PURE__ */ jsxRuntime.jsx("img", { src: src ?? void 0, alt: alt ?? "", className, "data-testid": testId });
|
|
1463
1484
|
}
|
|
1464
1485
|
var ASPECT = {
|