@proveanything/smartlinks-utils-ui 0.10.3 → 0.10.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.
@@ -336,6 +336,10 @@ interface RecordsAdminI18n {
336
336
  previewAs: string;
337
337
  previewAsDefault: string;
338
338
  confirmDelete: string;
339
+ /** Confirm dialog title shown when the row trash is clicked in the item list. */
340
+ deleteConfirmTitle: string;
341
+ /** Confirm dialog body. `{name}` is replaced with the record's friendly label. */
342
+ deleteConfirmBody: string;
339
343
  unsavedBadge: string;
340
344
  unsavedPromptTitle: string;
341
345
  unsavedPromptBody: string;
@@ -92,6 +92,8 @@ var DEFAULT_I18N = {
92
92
  previewAs: "Preview as",
93
93
  previewAsDefault: "Same as edited",
94
94
  confirmDelete: "Confirm delete",
95
+ deleteConfirmTitle: "Delete this record?",
96
+ deleteConfirmBody: "Are you sure you want to delete \u201C{name}\u201D? This cannot be undone.",
95
97
  unsavedBadge: "Unsaved",
96
98
  unsavedPromptTitle: "Unsaved changes",
97
99
  unsavedPromptBody: "You have unsaved changes. What would you like to do?",
@@ -2949,9 +2951,9 @@ function useEditorBridge(args) {
2949
2951
  const next = session?.status ?? null;
2950
2952
  prevStatusRef.current = next;
2951
2953
  if (next === "saved" && prev !== "saved") {
2952
- onSaved?.();
2954
+ onSaved?.(session?.recordId);
2953
2955
  }
2954
- }, [session?.status]);
2956
+ }, [session?.status, session?.recordId]);
2955
2957
  const remove = useMemo(() => async () => {
2956
2958
  if (!session) return;
2957
2959
  await session.remove();
@@ -3077,7 +3079,7 @@ function useShellEditorTarget(args) {
3077
3079
  facetRule: resolved.facetRule
3078
3080
  },
3079
3081
  defaultData,
3080
- onSaved: () => onSaved(resolved.source !== "self"),
3082
+ onSaved: (recordId) => onSaved(resolved.source !== "self", recordId),
3081
3083
  onDeleted
3082
3084
  });
3083
3085
  return { editorTargetSpec, editorCtx };
@@ -5830,6 +5832,17 @@ function ItemListView({
5830
5832
  i18n
5831
5833
  }) {
5832
5834
  const newLabel = i18n.newItem.includes("{noun}") ? i18n.newItem.replace("{noun}", itemNoun) : i18n.newItem;
5835
+ const [pendingDeleteId, setPendingDeleteId] = useState(null);
5836
+ const pendingRecord = useMemo(
5837
+ () => pendingDeleteId ? items.find((it) => (it.itemId ?? "") === pendingDeleteId) ?? null : null,
5838
+ [pendingDeleteId, items]
5839
+ );
5840
+ const guardedCtx = useMemo(() => ({
5841
+ ...ctx,
5842
+ onDelete: (id) => setPendingDeleteId(id)
5843
+ }), [ctx]);
5844
+ const confirmName = pendingRecord?.label ?? itemNoun;
5845
+ const confirmBody = i18n.deleteConfirmBody.includes("{name}") ? i18n.deleteConfirmBody.replace("{name}", confirmName) : i18n.deleteConfirmBody;
5833
5846
  const toolbar = /* @__PURE__ */ jsxs("div", { className: "ra-item-toolbar", children: [
5834
5847
  /* @__PURE__ */ jsxs("div", { className: "ra-item-toolbar-title", children: [
5835
5848
  /* @__PURE__ */ jsx("h2", { className: "ra-display", style: { fontSize: "0.95rem", margin: 0 }, children: i18n.itemListTitle }),
@@ -5887,16 +5900,16 @@ function ItemListView({
5887
5900
  }
5888
5901
  );
5889
5902
  } else if (renderItemList) {
5890
- body = renderItemList(items, ctx);
5903
+ body = renderItemList(items, guardedCtx);
5891
5904
  } else if (view === "table") {
5892
5905
  body = /* @__PURE__ */ jsx(
5893
5906
  DefaultItemTable,
5894
5907
  {
5895
5908
  items,
5896
5909
  columns: itemColumns,
5897
- selectedId: ctx.selectedId,
5898
- onOpen: ctx.onOpen,
5899
- onDelete: ctx.onDelete,
5910
+ selectedId: guardedCtx.selectedId,
5911
+ onOpen: guardedCtx.onOpen,
5912
+ onDelete: guardedCtx.onDelete,
5900
5913
  rowActions,
5901
5914
  rowClipboard,
5902
5915
  i18n
@@ -5908,8 +5921,8 @@ function ItemListView({
5908
5921
  {
5909
5922
  items,
5910
5923
  variant: view,
5911
- selectedId: ctx.selectedId,
5912
- ctx,
5924
+ selectedId: guardedCtx.selectedId,
5925
+ ctx: guardedCtx,
5913
5926
  renderCard: renderItemCard,
5914
5927
  cardSize,
5915
5928
  rowActions,
@@ -5941,7 +5954,23 @@ function ItemListView({
5941
5954
  ]
5942
5955
  }
5943
5956
  ) : null,
5944
- /* @__PURE__ */ jsx("div", { className: "ra-item-list-body", children: body })
5957
+ /* @__PURE__ */ jsx("div", { className: "ra-item-list-body", children: body }),
5958
+ /* @__PURE__ */ jsx(
5959
+ ConfirmDialog,
5960
+ {
5961
+ open: pendingDeleteId !== null,
5962
+ title: i18n.deleteConfirmTitle,
5963
+ body: confirmBody,
5964
+ saveLabel: "",
5965
+ discardLabel: i18n.delete,
5966
+ cancelLabel: i18n.pasteConfirmCancel,
5967
+ onChoice: (choice) => {
5968
+ const id = pendingDeleteId;
5969
+ setPendingDeleteId(null);
5970
+ if (choice === "discard" && id !== null) ctx.onDelete(id);
5971
+ }
5972
+ }
5973
+ )
5945
5974
  ] });
5946
5975
  }
5947
5976
  var EditorItemNav = ({
@@ -7740,7 +7769,7 @@ function RecordsAdminShellInner(props) {
7740
7769
  },
7741
7770
  defaultData,
7742
7771
  deriveDraftLabel,
7743
- onSaved: (isCreate) => {
7772
+ onSaved: (isCreate, savedRecordId) => {
7744
7773
  onTelemetry?.({ type: "record.save", recordType, ref: editingTargetScope?.raw ?? "", isCreate });
7745
7774
  if (ruleWizardStep !== null) {
7746
7775
  setRuleWizardStep(null);
@@ -7751,6 +7780,9 @@ function RecordsAdminShellInner(props) {
7751
7780
  setSelectedRecordId(null);
7752
7781
  setDraftKind(null);
7753
7782
  }
7783
+ if (isCreate && isCollection && savedRecordId && isDraftId3(selectedItemId)) {
7784
+ setSelectedItemId(savedRecordId);
7785
+ }
7754
7786
  refetchAll();
7755
7787
  },
7756
7788
  onDeleted: () => {