@arbidocs/blocks 0.3.113 → 0.3.115

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
@@ -2376,7 +2376,8 @@ function StudioEditor({
2376
2376
  live,
2377
2377
  initialSlug,
2378
2378
  testIdPrefix = "studio",
2379
- publishAsset
2379
+ publishAsset,
2380
+ resetSeam = false
2380
2381
  }) {
2381
2382
  const arbi = react.useArbi();
2382
2383
  const materialize = react$1.useMemo(
@@ -2407,6 +2408,14 @@ function StudioEditor({
2407
2408
  cancelled = true;
2408
2409
  };
2409
2410
  }, [slug, live]);
2411
+ react$1.useEffect(() => {
2412
+ if (!resetSeam) return;
2413
+ const w = window;
2414
+ w.__studioResetSlug = (s) => persistence.deletePage(arbi, live, s);
2415
+ return () => {
2416
+ delete w.__studioResetSlug;
2417
+ };
2418
+ }, [resetSeam, arbi, live, persistence]);
2410
2419
  const persist4 = react$1.useCallback(
2411
2420
  async (toSave) => {
2412
2421
  setSaving(true);
@@ -2692,6 +2701,26 @@ function createStudioPersistence(cfg) {
2692
2701
  function loadPublished(arbi, live, slug) {
2693
2702
  return readPage(arbi, live, publishedKey(slug), publishedFile(slug));
2694
2703
  }
2704
+ async function deletePage(arbi, live, slug) {
2705
+ try {
2706
+ localStorage.removeItem(pageKey(slug));
2707
+ localStorage.removeItem(publishedKey(slug));
2708
+ } catch {
2709
+ }
2710
+ if (!canUseArbi(arbi, live)) return;
2711
+ try {
2712
+ await arbi.selectWorkspace(WORKSPACE_ID);
2713
+ const docs = await arbi.documents.list();
2714
+ const names = [pageFile(slug), publishedFile(slug)];
2715
+ const ids = docs.filter(
2716
+ (d) => (d.folder ?? "").includes(FOLDER) && names.some((n) => (d.file_name ?? "").endsWith(n))
2717
+ ).map((d) => d.external_id);
2718
+ if (ids.length) await arbi.documents.delete(ids);
2719
+ console.info(`[studio] deleted ${ids.length} doc(s) for "${slug}" from ARBI`);
2720
+ } catch (e) {
2721
+ console.warn(`[studio] ARBI delete failed for "${slug}"`, e);
2722
+ }
2723
+ }
2695
2724
  async function saveTheme(arbi, live, theme) {
2696
2725
  try {
2697
2726
  localStorage.setItem(THEME_KEY, JSON.stringify(theme));
@@ -2728,7 +2757,7 @@ function createStudioPersistence(cfg) {
2728
2757
  return null;
2729
2758
  }
2730
2759
  }
2731
- return { savePage, loadPage, savePublished, loadPublished, saveTheme, loadTheme };
2760
+ return { savePage, loadPage, savePublished, loadPublished, deletePage, saveTheme, loadTheme };
2732
2761
  }
2733
2762
  function AiTextField({
2734
2763
  value,
@@ -2886,7 +2915,9 @@ function ImageFieldControl({
2886
2915
  const [busy, setBusy] = react$1.useState(false);
2887
2916
  const arbi = react.useArbi();
2888
2917
  const gen = useImageGen();
2918
+ const queryClient = reactQuery.useQueryClient();
2889
2919
  const tp = (...q) => tid(`${testIdPrefix}-image`, name, ...q);
2920
+ const refreshAssets = () => queryClient.invalidateQueries({ queryKey: ["arbi", "documents", workspaceId] });
2890
2921
  const { data: docs } = react.useDocuments(workspaceId);
2891
2922
  const imageDocs = react$1.useMemo(
2892
2923
  () => (docs ?? []).filter(
@@ -2907,7 +2938,10 @@ function ImageFieldControl({
2907
2938
  await arbi.selectWorkspace(workspaceId);
2908
2939
  const res = await arbi.documents.uploadFile(file, file.name, { folder });
2909
2940
  const id = res.doc_ext_ids?.[0];
2910
- if (id) onChange(asAssetRef(id));
2941
+ if (id) {
2942
+ onChange(asAssetRef(id));
2943
+ void refreshAssets();
2944
+ }
2911
2945
  } finally {
2912
2946
  setBusy(false);
2913
2947
  }
@@ -2915,7 +2949,10 @@ function ImageFieldControl({
2915
2949
  const onGenerate = async () => {
2916
2950
  if (!prompt.trim() || gen.isGenerating) return;
2917
2951
  const id = await gen.generate(prompt);
2918
- if (id) onChange(asAssetRef(id));
2952
+ if (id) {
2953
+ onChange(asAssetRef(id));
2954
+ void refreshAssets();
2955
+ }
2919
2956
  };
2920
2957
  const MODES = [
2921
2958
  { key: "asset", label: "Assets", icon: lucideReact.ImagePlus },
@@ -2960,7 +2997,7 @@ function ImageFieldControl({
2960
2997
  {
2961
2998
  src: thumb,
2962
2999
  alt: d.file_name ?? "",
2963
- className: "aspect-square w-full object-cover"
3000
+ className: "aspect-square w-full bg-muted object-contain"
2964
3001
  }
2965
3002
  ) : /* @__PURE__ */ jsxRuntime.jsx("span", { className: "flex aspect-square w-full items-center justify-center bg-muted text-muted-foreground", children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.ImagePlus, { className: "size-4" }) })
2966
3003
  },