@ai-matrx/records-ui 0.116.108 → 0.116.110

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/CHANGELOG.md CHANGED
@@ -1,10 +1,39 @@
1
1
  # Changelog
2
2
 
3
- ## 0.116.108
3
+ ## 0.116.110
4
4
 
5
5
  UNVERIFIED: this release has no Unreleased entry and the source comparison could not be made (the caller supplied no source comparison). Whether source changed is unknown; consumer action is unknown.
6
6
  Check the package's gitHead on npm against this version's gitHead: `git diff <previous gitHead> <this gitHead> -- apps/shared/records-ui/src`.
7
7
 
8
+ ## 0.116.109
9
+
10
+ SOURCE CHANGED WITH NO RELEASE NOTE. This release shipped source changes that nobody described in an Unreleased entry,
11
+ so they may include breaking API changes. Consumer action is UNKNOWN: read the diff before upgrading.
12
+ Diff: `git diff d324df1734 5a535efe67 -- apps/shared/records-ui/src`
13
+
14
+ Changed shipped source files (2):
15
+ - `apps/shared/records-ui/src/DocRender.tsx`
16
+ - `apps/shared/records-ui/src/DocTemplate.tsx`
17
+
18
+ ## 0.116.108
19
+
20
+ Automatic changed-only republish (docs/metadata drift since the last published version; verified: `git diff 45e5dca239 d324df1734 -- apps/shared/records-ui/src`
21
+ has no shipped-source changes outside tests, fixtures and docs). No consumer action required.
22
+
23
+ ## 0.116.107
24
+
25
+ Automatic changed-only republish (docs/metadata drift since the last published version; verified: `git diff 33bd1514e6 45e5dca239 -- apps/shared/records-ui/src`
26
+ has no shipped-source changes outside tests, fixtures and docs). No consumer action required.
27
+
28
+ ## 0.116.106
29
+
30
+ SOURCE CHANGED WITH NO RELEASE NOTE. This release shipped source changes that nobody described in an Unreleased entry,
31
+ so they may include breaking API changes. Consumer action is UNKNOWN: read the diff before upgrading.
32
+ Diff: `git diff 5b7c48a99c 33bd1514e6 -- apps/shared/records-ui/src`
33
+
34
+ Changed shipped source files (1):
35
+ - `apps/shared/records-ui/src/RecordsTableCard.tsx`
36
+
8
37
  ## 0.116.105
9
38
 
10
39
  Automatic changed-only republish (docs/metadata drift since the last published version; verified: `git diff 82d533cb27 5b7c48a99c -- apps/shared/records-ui/src`
package/dist/index.cjs CHANGED
@@ -26045,6 +26045,7 @@ function EnrichPanel({ tableId, fieldId, className }) {
26045
26045
  });
26046
26046
  const chosen = setup.preset ? (0, import_records42.aiFieldPreset)(setup.preset) : void 0;
26047
26047
  const readsPictures = (0, import_records42.presetInputs)(setup.preset, attachmentColumns.map((f) => f.key));
26048
+ const readsRecord = readsPictures ?? (0, import_records42.defaultEnrichInputs)(fields.data ?? [], target?.key ?? "");
26048
26049
  const applyPreset = (preset, answer) => {
26049
26050
  const reads = preset === "describe_image" ? attachmentColumns.map((f) => f.name ?? f.label) : void 0;
26050
26051
  const sentence2 = (0, import_records42.presetInstruction)(preset, { answer, reads });
@@ -26129,7 +26130,7 @@ function EnrichPanel({ tableId, fieldId, className }) {
26129
26130
  review_interval_days: setup.every ? Number(setup.every) : null,
26130
26131
  enabled: false,
26131
26132
  // Describe image reads the table's attachment columns: name them, or the model is shown nothing.
26132
- ...readsPictures ? { inputs: readsPictures } : {}
26133
+ ...readsRecord.length > 0 ? { inputs: readsRecord } : {}
26133
26134
  }
26134
26135
  ),
26135
26136
  children: "Set it up"
@@ -27880,6 +27881,7 @@ function DocTemplate({ tableId, seed, pageSettings, activeTemplateId, onActiveTe
27880
27881
  };
27881
27882
  const [unresolved, setUnresolved] = (0, import_react141.useState)([]);
27882
27883
  const [saving, setSaving] = (0, import_react141.useState)(false);
27884
+ const [askingToRemove, setAskingToRemove] = (0, import_react141.useState)(false);
27883
27885
  const load = (0, import_react141.useCallback)(async () => {
27884
27886
  const held = await client.docTemplates({ table_id: tableId });
27885
27887
  if (!held.ok) {
@@ -27952,6 +27954,19 @@ function DocTemplate({ tableId, seed, pageSettings, activeTemplateId, onActiveTe
27952
27954
  setActiveId(saved.data);
27953
27955
  await load();
27954
27956
  }
27957
+ async function remove(templateId) {
27958
+ setAskingToRemove(false);
27959
+ const gone = await client.docTemplateDelete({ template_id: templateId });
27960
+ if (!gone.ok) {
27961
+ setError(gone.error);
27962
+ return;
27963
+ }
27964
+ setActiveId(null);
27965
+ setDraftName("");
27966
+ setDraftBody("");
27967
+ setDraftLayout({ ...EMPTY_LAYOUT });
27968
+ await load();
27969
+ }
27955
27970
  if (fields.error) return /* @__PURE__ */ (0, import_jsx_runtime89.jsx)(RefusalNotice, { error: fields.error, onRetry: fields.reload, className });
27956
27971
  if (error) {
27957
27972
  return /* @__PURE__ */ (0, import_jsx_runtime89.jsx)(
@@ -28004,7 +28019,18 @@ function DocTemplate({ tableId, seed, pageSettings, activeTemplateId, onActiveTe
28004
28019
  children: "New template"
28005
28020
  }
28006
28021
  ),
28007
- /* @__PURE__ */ (0, import_jsx_runtime89.jsx)(import_design_system76.Button, { size: "sm", className: "ml-auto", disabled: saving, onClick: () => void save(), children: saving ? "Saving\u2026" : "Save" })
28022
+ /* @__PURE__ */ (0, import_jsx_runtime89.jsxs)("span", { className: "ml-auto flex shrink-0 items-center gap-1", children: [
28023
+ activeId && askingToRemove ? /* @__PURE__ */ (0, import_jsx_runtime89.jsxs)(import_jsx_runtime89.Fragment, { children: [
28024
+ /* @__PURE__ */ (0, import_jsx_runtime89.jsxs)("span", { className: "text-xs text-destructive", children: [
28025
+ "Remove \\u201c",
28026
+ templates.find((t) => t.id === activeId)?.name ?? draftName,
28027
+ "\\u201d? Trash brings it back."
28028
+ ] }),
28029
+ /* @__PURE__ */ (0, import_jsx_runtime89.jsx)(import_design_system76.Button, { size: "sm", variant: "destructive", "data-doc-template-remove-confirm": "", onClick: () => void remove(activeId), children: "Remove it" }),
28030
+ /* @__PURE__ */ (0, import_jsx_runtime89.jsx)(import_design_system76.Button, { size: "sm", variant: "ghost", onClick: () => setAskingToRemove(false), children: "Keep it" })
28031
+ ] }) : activeId ? /* @__PURE__ */ (0, import_jsx_runtime89.jsx)(import_design_system76.Button, { size: "sm", variant: "ghost", "data-doc-template-remove": "", disabled: saving, onClick: () => setAskingToRemove(true), children: "Remove" }) : null,
28032
+ /* @__PURE__ */ (0, import_jsx_runtime89.jsx)(import_design_system76.Button, { size: "sm", disabled: saving, onClick: () => void save(), children: saving ? "Saving\u2026" : "Save" })
28033
+ ] })
28008
28034
  ] }),
28009
28035
  /* @__PURE__ */ (0, import_jsx_runtime89.jsxs)("label", { className: "flex flex-col gap-1", children: [
28010
28036
  /* @__PURE__ */ (0, import_jsx_runtime89.jsx)(import_design_system76.Label, { className: "text-xs font-medium", children: "Name" }),
@@ -32451,7 +32477,7 @@ init_refusals();
32451
32477
  var import_jsx_runtime104 = require("react/jsx-runtime");
32452
32478
  function keptWhileAway(outcome, readBackUnsent, readBackRefusal) {
32453
32479
  if (!readBackUnsent || outcome.written === 0) return outcome;
32454
- const values = outcome.readBack + outcome.missing;
32480
+ const values = outcome.readBack + outcome.missing + (outcome.waiting ?? 0);
32455
32481
  return {
32456
32482
  ...outcome,
32457
32483
  readBack: 0,
@@ -32463,7 +32489,9 @@ function keptWhileAway(outcome, readBackUnsent, readBackRefusal) {
32463
32489
  function outcomeSentence(outcome) {
32464
32490
  const waiting = outcome.waiting ?? 0;
32465
32491
  if (waiting > 0) {
32466
- return `${waiting} ${waiting === 1 ? "value is" : "values are"} saved on this computer and will be sent to the table when you are back online.`;
32492
+ const kept2 = `${waiting} ${waiting === 1 ? "value is" : "values are"} saved on this computer and will be sent to the table when you are back online.`;
32493
+ const rest = outcome.missing > 0 ? ` ${outcome.missing} could not be found afterwards.` : "";
32494
+ return outcome.readBack > 0 ? `${outcome.readBack} in the table. ${kept2}${rest}` : `${kept2}${rest}`;
32467
32495
  }
32468
32496
  const whole = outcome.missing === 0 && outcome.refusals.length === 0;
32469
32497
  return whole ? `All ${outcome.readBack} ${outcome.readBack === 1 ? "value is" : "values are"} in the table \u2014 read back out of it, not just accepted.` : `${outcome.readBack} of ${outcome.readBack + outcome.missing} values are in the table. The rest are not, and nothing was lost from what you copied \u2014 it is still on your clipboard.`;
@@ -35915,15 +35943,19 @@ function GridBody({
35915
35943
  const readBackRefusal = reread.ok ? void 0 : `The rows were written and this could not read them back to check: ${refusalSentence(reread.error)}`;
35916
35944
  if (readBackRefusal !== void 0) refusals.push(readBackRefusal);
35917
35945
  const seen = new Map((reread.ok ? reread.data : []).map((r) => [r.id, r.document ?? {}]));
35946
+ const unsent = new Set((reread.ok ? reread.data : []).filter((r) => r.waiting).map((r) => r.id));
35947
+ let waiting = 0;
35918
35948
  for (const entry of expected) {
35919
35949
  const stored = seen.get(entry.recordId);
35920
35950
  for (const [key, value] of Object.entries(entry.document)) {
35921
- if (stored !== void 0 && storedValueAgrees(fieldOf2.get(key), stored[key], value, choiceOptions.current.get(key))) readBack += 1;
35922
- else missing += 1;
35951
+ if (stored !== void 0 && storedValueAgrees(fieldOf2.get(key), stored[key], value, choiceOptions.current.get(key))) {
35952
+ if (unsent.has(entry.recordId)) waiting += 1;
35953
+ else readBack += 1;
35954
+ } else missing += 1;
35923
35955
  }
35924
35956
  }
35925
35957
  records.reload();
35926
- return keptWhileAway({ written: lines2, readBack, missing, refusals }, !reread.ok && isUnsentWrite(reread.error), readBackRefusal);
35958
+ return keptWhileAway({ written: lines2, readBack, missing, refusals, waiting }, !reread.ok && isUnsentWrite(reread.error), readBackRefusal);
35927
35959
  },
35928
35960
  [rows, client, tableId, editing, undo, records, versions, fields.data]
35929
35961
  );
@@ -36002,6 +36034,8 @@ function GridBody({
36002
36034
  let missing = 0;
36003
36035
  const fieldOf2 = new Map((fields.data ?? []).map((f) => [f.key, f]));
36004
36036
  const seen = /* @__PURE__ */ new Map();
36037
+ const unsent = /* @__PURE__ */ new Set();
36038
+ let waiting = 0;
36005
36039
  const READ_BACK_PAGE = 500;
36006
36040
  let readBackRefusal;
36007
36041
  let readBackUnsent = false;
@@ -36015,6 +36049,7 @@ function GridBody({
36015
36049
  }
36016
36050
  for (const row of reread.data.rows) {
36017
36051
  seen.set(row.id, row.document ?? {});
36052
+ if (row.waiting) unsent.add(row.id);
36018
36053
  }
36019
36054
  if (reread.data.rows.length + (reread.data.locked ?? 0) < READ_BACK_PAGE) break;
36020
36055
  if (expected.every((e) => seen.has(e.recordId))) break;
@@ -36023,14 +36058,15 @@ function GridBody({
36023
36058
  const stored = seen.get(entry.recordId);
36024
36059
  for (const [key, value] of Object.entries(entry.document)) {
36025
36060
  if (stored !== void 0 && storedValueAgrees(fieldOf2.get(key), stored[key], value, choiceOptions.current.get(key))) {
36026
- readBack += 1;
36061
+ if (unsent.has(entry.recordId)) waiting += 1;
36062
+ else readBack += 1;
36027
36063
  } else {
36028
36064
  missing += 1;
36029
36065
  }
36030
36066
  }
36031
36067
  }
36032
36068
  records.reload();
36033
- return keptWhileAway({ written, readBack, missing, refusals }, readBackUnsent, readBackRefusal);
36069
+ return keptWhileAway({ written, readBack, missing, refusals, waiting }, readBackUnsent, readBackRefusal);
36034
36070
  }, [pastePlan, client, tableId, records, merged, applyPasteAsOne, versions, fields.data]);
36035
36071
  const columnIds = (0, import_react197.useMemo)(() => ordered.map((field2) => field2.key), [ordered]);
36036
36072
  const lookWrites = (0, import_react197.useRef)(null);
@@ -38736,7 +38772,8 @@ var VERB_WORDS = {
38736
38772
  rename: "Renamed",
38737
38773
  delete: "Removed"
38738
38774
  };
38739
- function migrationWords(verb) {
38775
+ function migrationWords(verb, targetKind) {
38776
+ if (verb === "retype" && targetKind === "record") return "Moved to another table";
38740
38777
  return VERB_WORDS[verb] ?? (0, import_text_case19.humanizeIdentifier)(verb);
38741
38778
  }
38742
38779
  function useMigrationLog(recordId) {
@@ -38789,12 +38826,12 @@ function MigrationLog({ entries, readError, canUndo, whyNotUndo, onUndone, class
38789
38826
  return;
38790
38827
  }
38791
38828
  const removed = back.data.removed ? " The record it made is archived, so no copy is left behind." : "";
38792
- await onUndone(`${migrationWords(entry.verb)} undone.${removed}`);
38829
+ await onUndone(`${migrationWords(entry.verb, entry.target_kind)} undone.${removed}`);
38793
38830
  }
38794
38831
  return /* @__PURE__ */ (0, import_jsx_runtime131.jsxs)("section", { "aria-label": "Migration log", className: (0, import_design_system111.cn)("flex flex-col gap-1", className), "data-records-migration-log": "", children: [
38795
38832
  /* @__PURE__ */ (0, import_jsx_runtime131.jsx)("h4", { className: "text-xs font-medium", children: "Migration log" }),
38796
38833
  /* @__PURE__ */ (0, import_jsx_runtime131.jsx)("ul", { className: "flex flex-col divide-y rounded border text-xs", children: entries.map((entry) => /* @__PURE__ */ (0, import_jsx_runtime131.jsxs)("li", { "data-migration-id": entry.id, className: "flex items-center gap-2 px-2 py-1.5", children: [
38797
- /* @__PURE__ */ (0, import_jsx_runtime131.jsx)("span", { className: "shrink-0 font-medium", children: migrationWords(entry.verb) }),
38834
+ /* @__PURE__ */ (0, import_jsx_runtime131.jsx)("span", { className: "shrink-0 font-medium", children: migrationWords(entry.verb, entry.target_kind) }),
38798
38835
  /* @__PURE__ */ (0, import_jsx_runtime131.jsx)("span", { className: "min-w-0 flex-1 truncate text-muted-foreground", title: entry.note ? withoutInternalCodes(entry.note) : void 0, children: entry.note ? withoutInternalCodes(entry.note) : "" }),
38799
38836
  /* @__PURE__ */ (0, import_jsx_runtime131.jsx)("span", { className: "min-w-28 shrink-0 whitespace-nowrap text-right text-muted-foreground", title: new Date(entry.applied_at).toLocaleString(), children: whenText(entry.applied_at) }),
38800
38837
  entry.undone_at ? /* @__PURE__ */ (0, import_jsx_runtime131.jsx)("span", { className: "w-14 shrink-0 text-right text-muted-foreground", children: "Undone" }) : canUndo ? /* @__PURE__ */ (0, import_jsx_runtime131.jsx)(
@@ -38978,6 +39015,7 @@ function HistoryPanel({ tableId, recordId, onAskAboutField, className }) {
38978
39015
  VersionRow,
38979
39016
  {
38980
39017
  entry,
39018
+ madeBy: entry.migration_id ? (shape.entries ?? []).find((m) => m.id === entry.migration_id) ?? null : null,
38981
39019
  byKey,
38982
39020
  expanded: open === entry.version,
38983
39021
  onToggle: () => setOpen(open === entry.version ? null : entry.version),
@@ -39011,6 +39049,7 @@ function HistoryPanel({ tableId, recordId, onAskAboutField, className }) {
39011
39049
  }
39012
39050
  function VersionRow({
39013
39051
  entry,
39052
+ madeBy,
39014
39053
  byKey,
39015
39054
  expanded,
39016
39055
  onToggle,
@@ -39062,7 +39101,7 @@ function VersionRow({
39062
39101
  children: [
39063
39102
  /* @__PURE__ */ (0, import_jsx_runtime132.jsxs)("span", { className: "flex min-w-0 items-baseline gap-1.5", children: [
39064
39103
  /* @__PURE__ */ (0, import_jsx_runtime132.jsx)(Who, { actor: entry.actor, changes: entry.changes }),
39065
- /* @__PURE__ */ (0, import_jsx_runtime132.jsx)("span", { className: "shrink-0 text-muted-foreground", children: verbWords(operationWords(entry.operation_label)) }),
39104
+ /* @__PURE__ */ (0, import_jsx_runtime132.jsx)("span", { className: "shrink-0 text-muted-foreground", children: verbWords(madeBy ? migrationWords(madeBy.verb, madeBy.target_kind) : operationWords(entry.operation_label)) }),
39066
39105
  entry.undoable ? /* @__PURE__ */ (0, import_jsx_runtime132.jsx)(import_design_system112.Badge, { variant: "secondary", className: "min-w-0 shrink truncate text-[10px]", title: "part of a bigger change", children: "part of a bigger change" }) : null,
39067
39106
  /* @__PURE__ */ (0, import_jsx_runtime132.jsxs)("span", { className: "ml-auto flex shrink-0 items-baseline gap-1.5 whitespace-nowrap text-muted-foreground", children: [
39068
39107
  /* @__PURE__ */ (0, import_jsx_runtime132.jsxs)("span", { className: "tabular-nums", children: [
@@ -39173,9 +39212,9 @@ function ChangeLine({
39173
39212
  return /* @__PURE__ */ (0, import_jsx_runtime132.jsxs)("li", { "data-change-key": change.key, className: "flex items-baseline gap-2 text-[11px]", children: [
39174
39213
  /* @__PURE__ */ (0, import_jsx_runtime132.jsx)("span", { className: "w-24 shrink-0 truncate font-medium", title: change.label, children: change.label || (0, import_text_case20.humanizeIdentifier)(change.key) }),
39175
39214
  /* @__PURE__ */ (0, import_jsx_runtime132.jsxs)("span", { className: "min-w-0 flex-1 truncate", children: [
39176
- /* @__PURE__ */ (0, import_jsx_runtime132.jsx)("span", { className: "text-muted-foreground line-through", children: say(change.before, field2) }),
39215
+ /* @__PURE__ */ (0, import_jsx_runtime132.jsx)("span", { className: "text-muted-foreground line-through", children: change.before_words ?? say(change.before, field2) }),
39177
39216
  /* @__PURE__ */ (0, import_jsx_runtime132.jsx)("span", { className: "mx-1 text-muted-foreground", children: "\u2192" }),
39178
- /* @__PURE__ */ (0, import_jsx_runtime132.jsx)("strong", { className: "font-medium", children: say(change.after, field2) })
39217
+ /* @__PURE__ */ (0, import_jsx_runtime132.jsx)("strong", { className: "font-medium", children: change.after_words ?? say(change.after, field2) })
39179
39218
  ] }),
39180
39219
  change.rule ? /* @__PURE__ */ (0, import_jsx_runtime132.jsxs)(import_design_system112.Badge, { variant: "outline", className: "shrink-0 text-[10px]", title: "Worked out by a rule", children: [
39181
39220
  "rule v",
@@ -39263,9 +39302,9 @@ function ConfirmRestore({
39263
39302
  /* @__PURE__ */ (0, import_jsx_runtime132.jsx)("ul", { className: "flex flex-col gap-0.5", children: preview.changes.map((change) => /* @__PURE__ */ (0, import_jsx_runtime132.jsxs)("li", { className: "text-[11px]", children: [
39264
39303
  /* @__PURE__ */ (0, import_jsx_runtime132.jsx)("span", { className: "font-medium", children: change.label }),
39265
39304
  " ",
39266
- /* @__PURE__ */ (0, import_jsx_runtime132.jsx)("span", { className: "text-muted-foreground", children: say(change.before, void 0) }),
39305
+ /* @__PURE__ */ (0, import_jsx_runtime132.jsx)("span", { className: "text-muted-foreground", children: change.before_words ?? say(change.before, void 0) }),
39267
39306
  /* @__PURE__ */ (0, import_jsx_runtime132.jsx)("span", { className: "mx-1 text-muted-foreground", children: "\u2192" }),
39268
- /* @__PURE__ */ (0, import_jsx_runtime132.jsx)("strong", { className: "font-medium", children: change.after === null || change.after === void 0 ? "cleared" : say(change.after, void 0) })
39307
+ /* @__PURE__ */ (0, import_jsx_runtime132.jsx)("strong", { className: "font-medium", children: change.after === null || change.after === void 0 ? "cleared" : change.after_words ?? say(change.after, void 0) })
39269
39308
  ] }, change.key)) }),
39270
39309
  /* @__PURE__ */ (0, import_jsx_runtime132.jsx)("p", { className: "text-[11px] text-muted-foreground", children: "It is saved as a new version. Nothing in the history is erased, and this can be put back too." }),
39271
39310
  /* @__PURE__ */ (0, import_jsx_runtime132.jsxs)("div", { className: "flex gap-1", children: [
@@ -40674,10 +40713,14 @@ function RecordPanel({ tableId, recordId, onClose, onAskAboutField, onPage = fal
40674
40713
  const record = (0, import_react230.useRecord)(recordId, true, { tableId });
40675
40714
  const answered = Boolean(record.data) && !record.error;
40676
40715
  const panelRef = (0, import_react229.useRef)(null);
40716
+ const opened = (0, import_react229.useRef)(false);
40677
40717
  (0, import_react229.useEffect)(() => {
40678
40718
  if (onPage) return;
40679
40719
  const panel = panelRef.current;
40720
+ const first = !opened.current;
40721
+ opened.current = true;
40680
40722
  if (!panel || panel.contains(document.activeElement)) return;
40723
+ if (!first && document.activeElement instanceof Element && document.activeElement.closest("[data-matrx-table-spreadsheet]")) return;
40681
40724
  panel.focus({ preventScroll: true });
40682
40725
  }, [recordId, onPage]);
40683
40726
  return /* @__PURE__ */ (0, import_jsx_runtime138.jsxs)(
@@ -51273,6 +51316,8 @@ function ViewBar({ tableId, activeViewId, onActiveView, seed, settings, onViews,
51273
51316
  if (!claimSeed(spec.name)) continue;
51274
51317
  const written = await declareView(client, { ...spec, subject: tableId });
51275
51318
  if (!written.ok) {
51319
+ const now = await readViews();
51320
+ if (now.ok && seedIsSatisfied(spec, now.data)) continue;
51276
51321
  setError(written.error);
51277
51322
  onViews?.(null);
51278
51323
  return;
@@ -57398,6 +57443,8 @@ function DocRender({ templateId, recordId, filename, onRendered, className }) {
57398
57443
  const [showing, setShowing] = (0, import_react333.useState)(null);
57399
57444
  const [error, setError] = (0, import_react333.useState)(null);
57400
57445
  const [busy, setBusy] = (0, import_react333.useState)(null);
57446
+ const [askingToRemove, setAskingToRemove] = (0, import_react333.useState)(false);
57447
+ const [removed, setRemoved] = (0, import_react333.useState)(null);
57401
57448
  const paper = (0, import_react333.useRef)(null);
57402
57449
  const load = (0, import_react333.useCallback)(async () => {
57403
57450
  const [body, held] = await Promise.all([
@@ -57435,6 +57482,31 @@ function DocRender({ templateId, recordId, filename, onRendered, className }) {
57435
57482
  if (row) onRendered?.(row);
57436
57483
  }
57437
57484
  }
57485
+ async function remove(renderId) {
57486
+ setAskingToRemove(false);
57487
+ setBusy("remove");
57488
+ const gone = await client.docRenderDelete({ render_id: renderId });
57489
+ setBusy(null);
57490
+ if (!gone.ok) {
57491
+ setError(gone.error);
57492
+ return;
57493
+ }
57494
+ setShowing(null);
57495
+ setRemoved(renderId);
57496
+ await load();
57497
+ }
57498
+ async function undoRemove(renderId) {
57499
+ setBusy("remove");
57500
+ const back = await client.docRenderRestore({ render_id: renderId });
57501
+ setBusy(null);
57502
+ if (!back.ok) {
57503
+ setError(back.error);
57504
+ return;
57505
+ }
57506
+ setRemoved(null);
57507
+ await load();
57508
+ setShowing(renderId);
57509
+ }
57438
57510
  async function toPdf() {
57439
57511
  const element = paper.current;
57440
57512
  if (!element) return;
@@ -57493,6 +57565,14 @@ function DocRender({ templateId, recordId, filename, onRendered, className }) {
57493
57565
  render.id
57494
57566
  )),
57495
57567
  /* @__PURE__ */ (0, import_jsx_runtime190.jsxs)("span", { className: "ml-auto flex items-center gap-1", children: [
57568
+ frozen && askingToRemove ? /* @__PURE__ */ (0, import_jsx_runtime190.jsxs)(import_jsx_runtime190.Fragment, { children: [
57569
+ /* @__PURE__ */ (0, import_jsx_runtime190.jsx)("span", { className: "text-destructive", children: "This removes the saved version." }),
57570
+ /* @__PURE__ */ (0, import_jsx_runtime190.jsx)(import_design_system166.Button, { size: "sm", variant: "destructive", "data-doc-render-remove-confirm": "", disabled: busy !== null, onClick: () => void remove(frozen.id), children: "Remove it" }),
57571
+ /* @__PURE__ */ (0, import_jsx_runtime190.jsx)(import_design_system166.Button, { size: "sm", variant: "ghost", onClick: () => setAskingToRemove(false), children: "Keep it" })
57572
+ ] }) : frozen ? /* @__PURE__ */ (0, import_jsx_runtime190.jsx)(import_design_system166.Button, { size: "sm", variant: "ghost", "data-doc-render-remove": "", disabled: busy !== null, onClick: () => setAskingToRemove(true), children: "Remove" }) : removed ? /* @__PURE__ */ (0, import_jsx_runtime190.jsxs)(import_jsx_runtime190.Fragment, { children: [
57573
+ /* @__PURE__ */ (0, import_jsx_runtime190.jsx)("span", { className: "text-muted-foreground", children: "Removed." }),
57574
+ /* @__PURE__ */ (0, import_jsx_runtime190.jsx)(import_design_system166.Button, { size: "sm", variant: "ghost", "data-doc-render-undo": "", disabled: busy !== null, onClick: () => void undoRemove(removed), children: "Undo" })
57575
+ ] }) : null,
57496
57576
  /* @__PURE__ */ (0, import_jsx_runtime190.jsx)(import_design_system166.Button, { size: "sm", disabled: busy !== null, onClick: () => void freeze(), children: busy === "freeze" ? "Freezing\u2026" : "Freeze this version" }),
57497
57577
  /* @__PURE__ */ (0, import_jsx_runtime190.jsx)(import_design_system166.Button, { size: "sm", variant: "ghost", disabled: busy !== null, onClick: () => void toPdf(), children: busy === "pdf" ? "Making the PDF\u2026" : "PDF" })
57498
57578
  ] })
@@ -66638,6 +66718,7 @@ var import_design_system197 = require("@ai-matrx/design-system");
66638
66718
  var import_icons5 = require("@ai-matrx/design-system/icons");
66639
66719
  var import_field_formats24 = require("@ai-matrx/design-system/field-formats");
66640
66720
  var import_controls30 = require("@ai-matrx/design-system/controls");
66721
+ var import_first_page10 = require("@ai-matrx/records/first-page");
66641
66722
  init_names();
66642
66723
  init_plainWords();
66643
66724
 
@@ -66972,16 +67053,22 @@ function sectionColumns(fields, titleField, props) {
66972
67053
  return { name, group, note, readsOn, values };
66973
67054
  }
66974
67055
  var NATURAL2 = new Intl.Collator(void 0, { numeric: true, sensitivity: "base" });
66975
- function orderedRows(rows, nameKey) {
67056
+ function orderedRows(rows, nameKey, direction = "asc") {
66976
67057
  if (!nameKey) return [...rows];
66977
67058
  const nameOf3 = (r) => String((r.document ?? {})[nameKey] ?? "");
67059
+ const sign = direction === "desc" ? -1 : 1;
66978
67060
  return [...rows].sort((a, b) => {
66979
67061
  const x = nameOf3(a);
66980
67062
  const y = nameOf3(b);
66981
67063
  if (x === "" || y === "") return x === "" ? y === "" ? 0 : 1 : -1;
66982
- return NATURAL2.compare(x, y);
67064
+ return sign * NATURAL2.compare(x, y);
66983
67065
  });
66984
67066
  }
67067
+ function tableSortedRows(rows, sort, fields) {
67068
+ const field2 = fields.find((f) => f.key === sort.id);
67069
+ if (!field2 || (0, import_first_page10.sortAsFor)(field2) !== "text") return [...rows];
67070
+ return orderedRows(rows, sort.id, sort.direction);
67071
+ }
66985
67072
  function sectionGroups(rows, groupKey) {
66986
67073
  if (!groupKey) return [{ key: UNGROUPED2, rows: [...rows] }];
66987
67074
  const map = /* @__PURE__ */ new Map();
@@ -67374,7 +67461,6 @@ function TableSectionCard(props) {
67374
67461
  const fieldsRead = (0, import_react392.useFields)(tableId);
67375
67462
  const tableSort = (0, import_first_page3.defaultSortOf)(table.data ?? null, fieldsRead.data ?? []);
67376
67463
  const page = (0, import_react392.useRecordPage)(fieldsRead.data ? tableId : null, { pageSize: 200, ...tableSort ? { sort: [{ field: tableSort.id, direction: tableSort.direction }] } : {} });
67377
- const sortedByStore = tableSort !== null;
67378
67464
  const mutation = (0, import_react392.useRecordMutation)();
67379
67465
  const [adding, setAdding] = (0, import_react391.useState)(null);
67380
67466
  const [failed, setFailed] = (0, import_react391.useState)(null);
@@ -67386,7 +67472,7 @@ function TableSectionCard(props) {
67386
67472
  const readsOnField = cols.readsOn ? fields.find((f) => f.key === cols.readsOn) : void 0;
67387
67473
  const readsOnColorKey = cols.readsOn ? cols.values.find((f) => formatForField(f)?.options?.contrastWith?.readsOnField === cols.readsOn)?.key : void 0;
67388
67474
  const columns = columnsOf(cols.values);
67389
- const rows = sortedByStore ? page.data?.rows ?? [] : orderedRows(page.data?.rows ?? [], cols.name);
67475
+ const rows = tableSort ? tableSortedRows(page.data?.rows ?? [], tableSort, fields) : orderedRows(page.data?.rows ?? [], cols.name);
67390
67476
  const groups = sectionGroups(rows, cols.group);
67391
67477
  const level = rows[0]?.level ?? null;
67392
67478
  const mayWrite = !readOnly && (rows.length === 0 ? !readOnly : (0, import_field_kinds9.atLeast)(level, "edit_content"));