@arbidocs/blocks 0.5.152 → 0.5.153

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.
@@ -10069,11 +10069,13 @@ function ConnectedWorkspaceTrash({
10069
10069
  }) {
10070
10070
  const trash = react$1.useWorkspaceTrash(workspaceExtId);
10071
10071
  const invalidate = react$1.useInvalidateStorage();
10072
+ const hide = react$1.useHideFromWorkspaceTrash();
10072
10073
  const { purgeDeletedDocuments, restoreDocuments } = react$1.useStorageActions();
10073
10074
  const { notify: notify19 } = chunk46LX6EQT_cjs.useBlocksEnvironment();
10074
10075
  const [pending, setPending] = react.useState(null);
10075
10076
  const [includeOthers, setIncludeOthers] = react.useState(false);
10076
10077
  const [busy, setBusy] = react.useState(false);
10078
+ const [removing, setRemoving] = react.useState(null);
10077
10079
  const page = trash.data;
10078
10080
  const items = page?.items ?? [];
10079
10081
  const manager = page?.can_manage ?? false;
@@ -10082,15 +10084,17 @@ function ConnectedWorkspaceTrash({
10082
10084
  const removable = items.filter((d) => !d.restoring);
10083
10085
  const emptiable = manager ? removable : removable.filter((d) => d.mine);
10084
10086
  const emptiableBytes = emptiable.reduce((sum, d) => sum + d.bytes, 0);
10085
- const run = async (action, failure) => {
10087
+ const run = async (action, failure, undo) => {
10086
10088
  setBusy(true);
10087
10089
  try {
10088
10090
  notify19(await action(), "success");
10089
- await invalidate();
10091
+ void invalidate();
10090
10092
  } catch (error) {
10093
+ undo?.();
10091
10094
  notify19(error instanceof Error ? error.message : failure, "error");
10092
10095
  } finally {
10093
10096
  setBusy(false);
10097
+ setRemoving(null);
10094
10098
  setPending(null);
10095
10099
  setIncludeOthers(false);
10096
10100
  }
@@ -10101,20 +10105,36 @@ function ConnectedWorkspaceTrash({
10101
10105
  }, "Could not restore");
10102
10106
  const confirm = () => {
10103
10107
  if (!pending) return;
10108
+ const withOthers = pending.kind === "empty" && manager && includeOthers;
10109
+ const undo = hide(
10110
+ workspaceExtId,
10111
+ pending.kind === "purge" ? [pending.doc.external_id] : emptiable.map((d) => d.external_id),
10112
+ withOthers
10113
+ );
10114
+ setRemoving(pending.kind);
10115
+ setPending(null);
10104
10116
  if (pending.kind === "purge") {
10105
- void run(async () => {
10106
- await purgeDeletedDocuments(workspaceExtId, { externalIds: [pending.doc.external_id] });
10107
- return `Deleted permanently \xB7 ${chunk4ZR4O5SP_cjs.formatBytes(pending.doc.bytes)} freed`;
10108
- }, "Could not delete permanently");
10117
+ void run(
10118
+ async () => {
10119
+ await purgeDeletedDocuments(workspaceExtId, { externalIds: [pending.doc.external_id] });
10120
+ return `Deleted permanently \xB7 ${chunk4ZR4O5SP_cjs.formatBytes(pending.doc.bytes)} freed`;
10121
+ },
10122
+ "Could not delete permanently",
10123
+ undo
10124
+ );
10109
10125
  return;
10110
10126
  }
10111
- const freed = emptiableBytes + (includeOthers ? others?.bytes ?? 0 : 0);
10112
- void run(async () => {
10113
- const removed = await purgeDeletedDocuments(workspaceExtId, {
10114
- includeOthersPrivate: manager && includeOthers
10115
- });
10116
- return `Trash emptied \xB7 ${removed.length} ${removed.length === 1 ? "item" : "items"} \xB7 ${chunk4ZR4O5SP_cjs.formatBytes(freed)} freed`;
10117
- }, "Could not empty the trash");
10127
+ const freed = emptiableBytes + (withOthers ? others?.bytes ?? 0 : 0);
10128
+ void run(
10129
+ async () => {
10130
+ const removed = await purgeDeletedDocuments(workspaceExtId, {
10131
+ includeOthersPrivate: withOthers
10132
+ });
10133
+ return `Trash emptied \xB7 ${removed.length} ${removed.length === 1 ? "item" : "items"} \xB7 ${chunk4ZR4O5SP_cjs.formatBytes(freed)} freed`;
10134
+ },
10135
+ "Could not empty the trash",
10136
+ undo
10137
+ );
10118
10138
  };
10119
10139
  const nothingToEmpty = emptiable.length === 0 && !(manager && othersCount > 0);
10120
10140
  return /* @__PURE__ */ jsxRuntime.jsxs("section", { className: "space-y-2", "data-testid": testId, children: [
@@ -10123,7 +10143,7 @@ function ConnectedWorkspaceTrash({
10123
10143
  title && /* @__PURE__ */ jsxRuntime.jsx("h4", { className: "truncate text-sm font-medium text-foreground", children: title }),
10124
10144
  /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-xs text-muted-foreground", children: manager ? chunk4ZR4O5SP_cjs.RECENTLY_DELETED_NOTE : `${chunk4ZR4O5SP_cjs.RECENTLY_DELETED_NOTE} You can remove your own deleted items.` })
10125
10145
  ] }),
10126
- /* @__PURE__ */ jsxRuntime.jsxs(
10146
+ /* @__PURE__ */ jsxRuntime.jsx(
10127
10147
  ui.Button,
10128
10148
  {
10129
10149
  size: "sm",
@@ -10131,10 +10151,13 @@ function ConnectedWorkspaceTrash({
10131
10151
  disabled: busy || trash.isLoading || nothingToEmpty,
10132
10152
  onClick: () => setPending({ kind: "empty" }),
10133
10153
  "data-testid": `${testId}-empty`,
10134
- children: [
10154
+ children: removing === "empty" ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
10155
+ /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Loader2, { className: "mr-1.5 size-4 animate-spin", "aria-hidden": "true" }),
10156
+ "Emptying\u2026"
10157
+ ] }) : /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
10135
10158
  /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Trash2, { className: "mr-1.5 size-4" }),
10136
10159
  manager ? "Empty trash" : "Empty my trash"
10137
- ]
10160
+ ] })
10138
10161
  }
10139
10162
  )
10140
10163
  ] }),
@@ -10327,7 +10350,7 @@ function ConnectedStorageProjectCard({
10327
10350
  setBusy(true);
10328
10351
  try {
10329
10352
  notify19(await action(), "success");
10330
- await invalidate();
10353
+ void invalidate();
10331
10354
  } catch (error) {
10332
10355
  notify19(error instanceof Error ? error.message : failure, "error");
10333
10356
  } finally {