@arbidocs/blocks 0.3.112 → 0.3.114

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 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 { data } = react.useThumbnails([docId]);
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 = {
@@ -2865,7 +2886,9 @@ function ImageFieldControl({
2865
2886
  const [busy, setBusy] = react$1.useState(false);
2866
2887
  const arbi = react.useArbi();
2867
2888
  const gen = useImageGen();
2889
+ const queryClient = reactQuery.useQueryClient();
2868
2890
  const tp = (...q) => tid(`${testIdPrefix}-image`, name, ...q);
2891
+ const refreshAssets = () => queryClient.invalidateQueries({ queryKey: ["arbi", "documents", workspaceId] });
2869
2892
  const { data: docs } = react.useDocuments(workspaceId);
2870
2893
  const imageDocs = react$1.useMemo(
2871
2894
  () => (docs ?? []).filter(
@@ -2886,7 +2909,10 @@ function ImageFieldControl({
2886
2909
  await arbi.selectWorkspace(workspaceId);
2887
2910
  const res = await arbi.documents.uploadFile(file, file.name, { folder });
2888
2911
  const id = res.doc_ext_ids?.[0];
2889
- if (id) onChange(asAssetRef(id));
2912
+ if (id) {
2913
+ onChange(asAssetRef(id));
2914
+ void refreshAssets();
2915
+ }
2890
2916
  } finally {
2891
2917
  setBusy(false);
2892
2918
  }
@@ -2894,7 +2920,10 @@ function ImageFieldControl({
2894
2920
  const onGenerate = async () => {
2895
2921
  if (!prompt.trim() || gen.isGenerating) return;
2896
2922
  const id = await gen.generate(prompt);
2897
- if (id) onChange(asAssetRef(id));
2923
+ if (id) {
2924
+ onChange(asAssetRef(id));
2925
+ void refreshAssets();
2926
+ }
2898
2927
  };
2899
2928
  const MODES = [
2900
2929
  { key: "asset", label: "Assets", icon: lucideReact.ImagePlus },