@ai-matrx/records-ui 0.115.46 → 0.115.48

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
@@ -1617,29 +1617,29 @@ function clauseFor(f, value, now = /* @__PURE__ */ new Date()) {
1617
1617
  }
1618
1618
  case "select": {
1619
1619
  const ticked = value.values ?? (value.value === "" ? [] : [value.value]);
1620
- const blank = ticked.includes(BLANK_VALUE);
1620
+ const blank2 = ticked.includes(BLANK_VALUE);
1621
1621
  const words2 = ticked.filter((w) => w !== BLANK_VALUE);
1622
- if (!blank && words2.length === 0) return value.negated ? null : { rule: constant(false) };
1622
+ if (!blank2 && words2.length === 0) return value.negated ? null : { rule: constant(false) };
1623
1623
  const present = op("present", field(f));
1624
1624
  const kind = String(editorKindFor(f));
1625
1625
  if (kind === "datetime" || kind === "date") {
1626
1626
  if (words2.length === 0) return { rule: value.negated ? present : not(present) };
1627
1627
  const holdsDays = String((f.config ?? {})["kind"] ?? "") === "date";
1628
- if (words2.length === 1 && !blank && !value.negated) return { flat: { [f.key]: dayWindow(words2[0], holdsDays) } };
1628
+ if (words2.length === 1 && !blank2 && !value.negated) return { flat: { [f.key]: dayWindow(words2[0], holdsDays) } };
1629
1629
  const leaves = words2.map((day2) => withinWindow(f, dayWindow(day2, holdsDays)));
1630
1630
  const anyDay = leaves.length === 1 ? leaves[0] : op("or", ...leaves);
1631
- if (!value.negated) return { rule: blank ? op("or", not(present), anyDay) : anyDay };
1632
- return { rule: blank ? op("and", present, not(anyDay)) : not(anyDay) };
1631
+ if (!value.negated) return { rule: blank2 ? op("or", not(present), anyDay) : anyDay };
1632
+ return { rule: blank2 ? op("and", present, not(anyDay)) : not(anyDay) };
1633
1633
  }
1634
1634
  const asStored = (w) => (0, import_first_page.holdsNumbers)(f) || kind === "rating" ? Number.isFinite(Number(w)) ? Number(w) : w : kind === "checkbox" && (w === "true" || w === "false") ? w === "true" : w;
1635
1635
  const stored = words2.map(asStored);
1636
1636
  const anyWord = stored.length === 0 ? null : stored.length === 1 ? op("eq", field(f), constant(stored[0])) : op("or", ...stored.map((w) => op("eq", field(f), constant(w))));
1637
1637
  if (!value.negated) {
1638
- if (!blank && stored.length === 1) return { flat: { [f.key]: stored[0] } };
1639
- if (!blank) return { rule: anyWord };
1638
+ if (!blank2 && stored.length === 1) return { flat: { [f.key]: stored[0] } };
1639
+ if (!blank2) return { rule: anyWord };
1640
1640
  return { rule: anyWord ? op("or", not(present), anyWord) : not(present) };
1641
1641
  }
1642
- if (blank) return { rule: anyWord ? op("and", present, not(anyWord)) : present };
1642
+ if (blank2) return { rule: anyWord ? op("and", present, not(anyWord)) : present };
1643
1643
  return { rule: op("or", not(present), not(anyWord)) };
1644
1644
  }
1645
1645
  case "boolean":
@@ -2647,14 +2647,24 @@ function RefusalLine({ error, className }) {
2647
2647
  // src/FieldRetype.tsx
2648
2648
  var import_jsx_runtime6 = require("react/jsx-runtime");
2649
2649
  var RETYPE_TARGETS = [
2650
- { id: "text", behaviour: "text", kind: null, label: "Text", holds: "words" },
2651
- { id: "number", behaviour: "range", kind: "number", label: "Number", holds: "a number" },
2650
+ { id: "text", behaviour: "text", kind: null, label: "Text", holds: "words", via: "behaviour" },
2651
+ { id: "number", behaviour: "range", kind: "number", label: "Number", holds: "a number", via: "behaviour" },
2652
2652
  // A DATE is a `range` of kind date: `migrate_retype` alone cannot say "date" (it keeps the old
2653
2653
  // kind, so every date would be kept aside), so this one goes through `custom.field_update`'s own
2654
2654
  // retype arm (`parity_type: datetime`), which converts on the SAME trigger and keeps what does not
2655
2655
  // fit in `_retired` with the reason — measured on the live store 2026-09-28.
2656
- { id: "date", behaviour: "range", kind: "date", label: "Date", holds: "a date" },
2657
- { id: "checkbox", behaviour: "boolean", kind: null, label: "Yes / no", holds: "a yes or a no" }
2656
+ { id: "date", behaviour: "range", kind: "date", label: "Date", holds: "a date", via: "kind", parity: "datetime" },
2657
+ { id: "checkbox", behaviour: "boolean", kind: null, label: "Yes / no", holds: "a yes or a no", via: "behaviour" },
2658
+ // THE REST OF WHAT THE STORE'S RETYPE TAKES (walk 2026-10-10: a text column could only become Number,
2659
+ // Date or Yes/no, so it could not become a Choice, Phone, Email or Link — the Sheet allowed any
2660
+ // kind the values convert to). All go through `custom.field_update`'s `parity_type` arm, the same
2661
+ // conversion trigger, which keeps what does not fit in `_retired` with the reason.
2662
+ { id: "email", behaviour: "text", kind: null, label: "Email address", holds: "email addresses", via: "kind", parity: "email" },
2663
+ { id: "phone", behaviour: "text", kind: null, label: "Phone number", holds: "phone numbers", via: "kind", parity: "phone" },
2664
+ { id: "url", behaviour: "text", kind: null, label: "Link", holds: "web addresses", via: "kind", parity: "url" },
2665
+ { id: "currency", behaviour: "range", kind: "number", label: "Money", holds: "an amount of money", via: "kind", parity: "currency" },
2666
+ { id: "percent", behaviour: "range", kind: "number", label: "Percentage", holds: "a percentage", via: "kind", parity: "percent" },
2667
+ { id: "select", behaviour: "text", kind: null, label: "Choice", holds: "one choice from a list", via: "kind", parity: "select" }
2658
2668
  ];
2659
2669
  var PREVIEW_GROUPS = 1e3;
2660
2670
  function retypeableFrom(field2) {
@@ -2676,6 +2686,7 @@ function currentTarget(field2) {
2676
2686
  const kind = String(editorKindFor(field2));
2677
2687
  if (String(field2.type) === "boolean") return "checkbox";
2678
2688
  if (kind === "datetime" || kind === "date") return "date";
2689
+ if (kind === "email" || kind === "phone" || kind === "url" || kind === "currency" || kind === "percent") return kind;
2679
2690
  if (String(field2.type) === "range") return "number";
2680
2691
  return "text";
2681
2692
  }
@@ -2719,8 +2730,8 @@ function FieldRetype({ field: field2, tableId, onRetyped }) {
2719
2730
  setRefusal(null);
2720
2731
  let holding;
2721
2732
  let aside;
2722
- if (to.id === "date") {
2723
- const done = await client.fieldUpdate({ field_id: field2.id, patch: { parity_type: "datetime" } });
2733
+ if (to.via !== "behaviour") {
2734
+ const done = await client.fieldUpdate({ field_id: field2.id, patch: { parity_type: to.parity } });
2724
2735
  setBusy(false);
2725
2736
  if (!done.ok) {
2726
2737
  setRefusal(done.error);
@@ -5886,7 +5897,7 @@ function FormulaTextEditor({
5886
5897
  value: text,
5887
5898
  rows: 2,
5888
5899
  "aria-label": "The formula",
5889
- placeholder: "{Visit fee} - {Deposit taken}",
5900
+ placeholder: columns.length > 0 ? `{${fieldName(columns[0])}}` : "Write a formula",
5890
5901
  className: "font-mono text-xs",
5891
5902
  onChange: (e) => onText(e.target.value)
5892
5903
  }
@@ -9413,7 +9424,7 @@ function FieldEditor(props) {
9413
9424
  const statusGroupsSent = Object.fromEntries(shownStatusRows.filter((r) => !editing || r.ref in statusGroups || !(r.ref in statusKeys)).map((r) => [r.ref, r.group]));
9414
9425
  const statusGroupsChanged = type === "status" && editing && Object.keys(statusGroupsSent).length > 0;
9415
9426
  const formulaChanged = formulaText.trim() !== startingFormulaText.trim();
9416
- const formulaMissing = type !== "formula" || !formulaWritten ? null : editing && !formulaChanged ? null : formulaText.trim() === "" ? "Write the formula this column works out." : formulaOk === false ? "The formula has a mistake \u2014 it is marked above." : formulaOk === null ? "Checking the formula\u2026" : null;
9427
+ const formulaMissing = type !== "formula" || !formulaWritten ? null : editing && !formulaChanged ? null : formulaText.trim() === "" ? "Write the formula" : formulaOk === false ? "The formula has a mistake \u2014 it is marked above." : formulaOk === null ? "Checking the formula\u2026" : null;
9417
9428
  const noun = onEntity ? "field" : "column";
9418
9429
  const nameTaken = columnNameTakenBy(label, others.map(fieldName));
9419
9430
  const nameLine = nameTaken ? columnNameTakenLine(nameTaken, noun) : columnNameProblemLine(label, noun);
@@ -10019,7 +10030,7 @@ function FieldEditor(props) {
10019
10030
  import_design_system33.Button,
10020
10031
  {
10021
10032
  size: "sm",
10022
- disabled: mutation.saving || Boolean(formulaMissing),
10033
+ disabled: mutation.saving || Boolean(formulaMissing) || Boolean(nameLine) && label.trim() !== (field2?.label ?? "").trim(),
10023
10034
  ...missingShown ? { "aria-describedby": "field-editor-missing" } : {},
10024
10035
  onClick: () => {
10025
10036
  if (missing) {
@@ -18082,6 +18093,7 @@ function useMergedGridControls(args) {
18082
18093
  /* @__PURE__ */ (0, import_jsx_runtime63.jsx)(
18083
18094
  import_design_system55.Dialog,
18084
18095
  {
18096
+ modal: true,
18085
18097
  open: dialog?.kind === "retype",
18086
18098
  onOpenChange: (open) => {
18087
18099
  if (!open) close();
@@ -21746,7 +21758,10 @@ var IMPORT_KINDS = [
21746
21758
  { kind: "date", label: "Date" },
21747
21759
  { kind: "number", label: "Number" },
21748
21760
  { kind: "currency", label: "Money" },
21749
- { kind: "checkbox", label: "Checkbox" }
21761
+ { kind: "checkbox", label: "Checkbox" },
21762
+ { kind: "email", label: "Email" },
21763
+ { kind: "phone", label: "Phone" },
21764
+ { kind: "url", label: "Link" }
21750
21765
  ];
21751
21766
  function importKindOfPlan(type) {
21752
21767
  if (type === "text" || type === "long_text") return "text";
@@ -21754,6 +21769,7 @@ function importKindOfPlan(type) {
21754
21769
  if (type === "number" || type === "range" || type === "integer" || type === "decimal") return "number";
21755
21770
  if (type === "currency") return "currency";
21756
21771
  if (type === "checkbox" || type === "boolean") return "checkbox";
21772
+ if (type === "email" || type === "phone" || type === "url") return type;
21757
21773
  return null;
21758
21774
  }
21759
21775
  function declarationFor(kind) {
@@ -21791,6 +21807,19 @@ function exactDuplicateRows(rows, headers) {
21791
21807
  });
21792
21808
  return out;
21793
21809
  }
21810
+ var EMAIL = /^[^\s@]+@[^\s@]+\.[^\s@]{2,}$/;
21811
+ var PHONE = /^\+?[\d\s().-]{7,20}$/;
21812
+ var URLISH = /^(https?:\/\/|www\.)\S+$/i;
21813
+ function looksLike(rows, header) {
21814
+ const cells = rows.map((r) => String(r[header] ?? "").trim()).filter((c) => c !== "");
21815
+ if (cells.length < 2) return null;
21816
+ const share = (test) => cells.filter(test).length / cells.length;
21817
+ if (share((c) => EMAIL.test(c)) >= 0.6) return "email";
21818
+ if (share((c) => URLISH.test(c)) >= 0.6) return "url";
21819
+ const isPhone = (c) => PHONE.test(c) && /[\d]/.test(c) && c.replace(/\D/g, "").length >= 7 && c.replace(/\D/g, "").length <= 15 && /[()\s.+-]/.test(c);
21820
+ if (share(isPhone) >= 0.6) return "phone";
21821
+ return null;
21822
+ }
21794
21823
 
21795
21824
  // src/importCombine.ts
21796
21825
  var import_records42 = require("@ai-matrx/records");
@@ -22395,6 +22424,7 @@ function ImportWizard({ tableId, source, onDone, onWrote, autoRun, className })
22395
22424
  for (const c of plan?.columns ?? []) {
22396
22425
  const k = importKindOfPlan(c.type);
22397
22426
  out[c.header] = (k === "text" || c.type === "select") && looksLikeDates(effectiveRows, c.header) ? "date" : k;
22427
+ if (out[c.header] === "text") out[c.header] = looksLike(effectiveRows, c.header) ?? "text";
22398
22428
  if (combined?.multiValued.has(c.header) && (k === null || c.type === "select")) out[c.header] = "text";
22399
22429
  }
22400
22430
  return out;
@@ -22575,6 +22605,25 @@ function ImportWizard({ tableId, source, onDone, onWrote, autoRun, className })
22575
22605
  }
22576
22606
  setColumnsAdded(added);
22577
22607
  }
22608
+ if (makesColumns && plan) {
22609
+ const wantedKeys = plan.columns.map((c) => c.header).filter((h) => !leftOut.has(h)).map((h) => sendMapping[h]).filter((k) => Boolean(k));
22610
+ const now = await client.fields({ table_id: tableId });
22611
+ if (now.ok) {
22612
+ const order = new Map(wantedKeys.map((k, i) => [k, i]));
22613
+ const current = now.data.filter((f) => order.has(f.key)).sort((a, b) => (a.sort ?? 0) - (b.sort ?? 0)).map((f) => f.key);
22614
+ const inFileOrder = current.every((k, i) => k === wantedKeys.filter((w) => current.includes(w))[i]);
22615
+ if (!inFileOrder) {
22616
+ const slots = now.data.filter((f) => order.has(f.key)).map((f) => f.sort ?? 0).sort((a, b) => a - b);
22617
+ const byKey = new Map(now.data.map((f) => [f.key, f]));
22618
+ const present = wantedKeys.filter((k) => byKey.has(k));
22619
+ for (let i = 0; i < present.length; i += 1) {
22620
+ const f = byKey.get(present[i]);
22621
+ const to = slots[i] ?? (i + 1) * 10;
22622
+ if ((f.sort ?? 0) !== to) await client.fieldUpdate({ field_id: f.id, patch: { sort: to } });
22623
+ }
22624
+ }
22625
+ }
22626
+ }
22578
22627
  setPhase("writing");
22579
22628
  const opened = await client.importBegin({
22580
22629
  table_id: tableId,
@@ -23795,9 +23844,9 @@ var PERCENT = /^[+-]?\d+(?:\.\d+)?\s?%$/;
23795
23844
  var ISO_DATE = /^\d{4}-\d{2}-\d{2}(?:[T ]\d{2}:\d{2}(?::\d{2}(?:\.\d+)?)?(?:Z|[+-]\d{2}:?\d{2})?)?$/;
23796
23845
  var SLASH_DATE = /^\d{1,2}\/\d{1,2}\/\d{2,4}$/;
23797
23846
  var WORD_DATE = /^(?:\d{1,2}\s+)?(?:jan|feb|mar|apr|may|jun|jul|aug|sep|sept|oct|nov|dec)[a-z]*\.?\s+\d{1,2}(?:st|nd|rd|th)?,?\s+\d{4}$|^\d{1,2}\s+(?:jan|feb|mar|apr|may|jun|jul|aug|sep|sept|oct|nov|dec)[a-z]*\.?\s+\d{4}$/i;
23798
- var EMAIL = /^[^\s@]+@[^\s@]+\.[^\s@]{2,}$/;
23847
+ var EMAIL2 = /^[^\s@]+@[^\s@]+\.[^\s@]{2,}$/;
23799
23848
  var URL_WORD = /^https?:\/\/\S+$/i;
23800
- var PHONE = /^\+?[\d\s().-]{7,20}$/;
23849
+ var PHONE2 = /^\+?[\d\s().-]{7,20}$/;
23801
23850
  var YES = /* @__PURE__ */ new Set(["yes", "true", "y", "\u2713", "\u2714", "checked", "done"]);
23802
23851
  var NO = /* @__PURE__ */ new Set(["no", "false", "n", "\u2717", "\u2718", "unchecked", ""]);
23803
23852
  function isDate(v) {
@@ -23817,9 +23866,9 @@ function guessColumn(values) {
23817
23866
  }
23818
23867
  if (every((v) => PERCENT.test(v))) return { type: "percent" };
23819
23868
  if (every(isDate)) return { type: "datetime", kind: every((v) => !/\d:\d/.test(v)) ? "date" : "datetime" };
23820
- if (every((v) => EMAIL.test(v))) return { type: "email" };
23869
+ if (every((v) => EMAIL2.test(v))) return { type: "email" };
23821
23870
  if (every((v) => URL_WORD.test(v))) return { type: "url" };
23822
- if (every((v) => PHONE.test(v) && (v.match(/\d/g)?.length ?? 0) >= 7)) return { type: "phone" };
23871
+ if (every((v) => PHONE2.test(v) && (v.match(/\d/g)?.length ?? 0) >= 7)) return { type: "phone" };
23823
23872
  if (filled.some((v) => v.length > 120 || v.includes("\n"))) return { type: "long_text" };
23824
23873
  const distinct = [];
23825
23874
  for (const v of filled) if (!distinct.some((d) => d.toLowerCase() === v.toLowerCase())) distinct.push(v);
@@ -24165,7 +24214,7 @@ function noValueList(columnId2) {
24165
24214
  }
24166
24215
  function facetsFromGroups(columnId2, key, rows, limit, distinctCount, order = "count") {
24167
24216
  const counts = /* @__PURE__ */ new Map();
24168
- let blank = 0;
24217
+ let blank2 = 0;
24169
24218
  let total = 0;
24170
24219
  let maxLength = 0;
24171
24220
  let unlistable = 0;
@@ -24176,7 +24225,7 @@ function facetsFromGroups(columnId2, key, rows, limit, distinctCount, order = "c
24176
24225
  const said2 = raw === null || raw === void 0 ? "" : String(raw).trim();
24177
24226
  const text = order === "newest" && /^\d{4}-\d{2}-\d{2}/.test(said2) ? said2.slice(0, 10) : said2;
24178
24227
  if (text === "") {
24179
- blank += n;
24228
+ blank2 += n;
24180
24229
  continue;
24181
24230
  }
24182
24231
  maxLength = Math.max(maxLength, text.length);
@@ -24194,8 +24243,8 @@ function facetsFromGroups(columnId2, key, rows, limit, distinctCount, order = "c
24194
24243
  return {
24195
24244
  columnId: columnId2,
24196
24245
  totalRows: total,
24197
- filled: total - blank,
24198
- blank,
24246
+ filled: total - blank2,
24247
+ blank: blank2,
24199
24248
  distinctCount: known,
24200
24249
  maxLength,
24201
24250
  unlistable,
@@ -24305,7 +24354,18 @@ function useGroupFacts(args) {
24305
24354
  }, [client, tableId, groupKey, chosenKey, filterKey, version]);
24306
24355
  return facts;
24307
24356
  }
24357
+ function yesNoGroupWords(field2, value) {
24358
+ const answer = value === true || value === "true" ? true : value === false || value === "false" ? false : null;
24359
+ if (answer === null) return null;
24360
+ const name = (field2.label || field2.key).trim();
24361
+ return answer ? `\u2713 ${name}` : `\u2014 Not ${name.charAt(0).toLowerCase()}${name.slice(1)}`;
24362
+ }
24308
24363
  function GroupLabel({ field: field2, value, withheld = null }) {
24364
+ if (field2 && editorKindFor(field2) === "checkbox") {
24365
+ if (groupValueKey(value) === "") return /* @__PURE__ */ (0, import_jsx_runtime81.jsx)("span", { className: "text-muted-foreground", "data-records-group-label": "", children: "Not answered" });
24366
+ const words2 = yesNoGroupWords(field2, value);
24367
+ if (words2) return /* @__PURE__ */ (0, import_jsx_runtime81.jsx)("span", { "data-records-group-label": "", children: words2 });
24368
+ }
24309
24369
  if (groupValueKey(value) === "" && !(field2 && withheld)) return /* @__PURE__ */ (0, import_jsx_runtime81.jsx)("span", { className: "text-muted-foreground", children: "No value" });
24310
24370
  if (!field2) return /* @__PURE__ */ (0, import_jsx_runtime81.jsx)("span", { children: String(value) });
24311
24371
  return /* @__PURE__ */ (0, import_jsx_runtime81.jsx)("span", { className: "inline-flex min-w-0 items-center", "data-records-group-label": "", children: /* @__PURE__ */ (0, import_jsx_runtime81.jsx)(RecordValue, { inCell: true, field: field2, value, format: formatForField(field2), withheld }) });
@@ -24339,11 +24399,16 @@ function groupFactsFor(facts, fields, chosen) {
24339
24399
  return { count: fact.count, aggregates };
24340
24400
  };
24341
24401
  }
24342
- function useGroupLabel(fields, groupKey) {
24402
+ function useGroupLabel(fields, groupKey, thenKeys = []) {
24403
+ const thenJoined = thenKeys.join("|");
24343
24404
  return (0, import_react129.useMemo)(() => {
24344
- const field2 = groupKey ? fields.find((f) => f.key === groupKey) : void 0;
24345
- return (group) => /* @__PURE__ */ (0, import_jsx_runtime81.jsx)(GroupLabel, { field: field2, value: group.value, withheld: groupKey ? groupWithheldNotice(group.rows, groupKey, group.value) : null });
24346
- }, [fields, groupKey]);
24405
+ const keys = groupKey ? [groupKey, ...thenJoined ? thenJoined.split("|") : []] : [];
24406
+ return (group) => {
24407
+ const key = keys[group.ancestors?.length ?? 0] ?? groupKey;
24408
+ const field2 = key ? fields.find((f) => f.key === key) : void 0;
24409
+ return /* @__PURE__ */ (0, import_jsx_runtime81.jsx)(GroupLabel, { field: field2, value: group.value, withheld: key ? groupWithheldNotice(group.rows, key, group.value) : null });
24410
+ };
24411
+ }, [fields, groupKey, thenJoined]);
24347
24412
  }
24348
24413
 
24349
24414
  // src/gridUndo.tsx
@@ -26089,7 +26154,7 @@ function GridBody({
26089
26154
  const summaries = useColumnSummaries({ tableId, chosen: chosenSummaries, filter: readFilter, version: summaryVersion });
26090
26155
  const drillConfig = useGridDrillConfig({ tableId, state: drillState, presentation, onPresentationChange, version: records.data });
26091
26156
  const groupFacts = useGroupFacts({ tableId, groupKey: rowGroupKey, chosen: chosenSummaries, filter: readFilter, version: summaryVersion });
26092
- const groupLabel2 = useGroupLabel(fields.data ?? [], rowGroupKey);
26157
+ const groupLabel2 = useGroupLabel(fields.data ?? [], rowGroupKey, (presentation.grouping?.then ?? []).map((t) => t.field));
26093
26158
  const [duplicated, setDuplicated] = (0, import_react143.useState)(null);
26094
26159
  const duplicate = (0, import_react143.useCallback)(
26095
26160
  async (row) => {
@@ -27017,7 +27082,7 @@ function GridBody({
27017
27082
  rowNoun: "record",
27018
27083
  ...thenKeys.length > 0 ? { thenColumnIds: thenKeys } : {},
27019
27084
  ...aggregates ? { aggregates } : {},
27020
- ...rowsGrouped ? { renderLabel: (group) => group.ancestors ? void 0 : groupLabel2(group), order: "first-seen", emptyLabel: "No value" } : {},
27085
+ ...rowsGrouped ? { renderLabel: groupLabel2, order: "first-seen", emptyLabel: "No value" } : {},
27021
27086
  ...facts ? { groupFacts: facts } : {},
27022
27087
  ...!rowsGrouped && view?.order ? { order: view.order } : {},
27023
27088
  ...view?.collapsed ? { collapsed: view.collapsed } : {},
@@ -28943,6 +29008,10 @@ function NewTableStart({
28943
29008
  onMade?.();
28944
29009
  setStep({ at: "wizard", tableId: result.data, source, made: true });
28945
29010
  }, [busy, client, fileName, importName, importReady, onMade, parsed, target]);
29011
+ const openImported = (tableId) => {
29012
+ (0, import_react155.tableShapeChanged)(tableId);
29013
+ onOpenTable?.(tableId);
29014
+ };
28946
29015
  const back = () => {
28947
29016
  setError(null);
28948
29017
  setStep({ at: "choose" });
@@ -29138,10 +29207,10 @@ function NewTableStart({
29138
29207
  /* @__PURE__ */ (0, import_jsx_runtime92.jsx)(import_design_system76.Button, { disabled: !importReady || busy, onClick: () => void continueImport(), "data-new-table-continue": "", children: busy ? "Creating\u2026" : "Next: columns" })
29139
29208
  ] });
29140
29209
  } else {
29141
- body = /* @__PURE__ */ (0, import_jsx_runtime92.jsx)("div", { "data-new-table-wizard": "", children: /* @__PURE__ */ (0, import_jsx_runtime92.jsx)(ImportWizard, { tableId: step2.tableId, source: step2.source, autoRun: step2.made, onDone: () => onOpenTable?.(step2.tableId) }) });
29210
+ body = /* @__PURE__ */ (0, import_jsx_runtime92.jsx)("div", { "data-new-table-wizard": "", children: /* @__PURE__ */ (0, import_jsx_runtime92.jsx)(ImportWizard, { tableId: step2.tableId, source: step2.source, autoRun: step2.made, onWrote: () => (0, import_react155.tableShapeChanged)(step2.tableId), onDone: () => openImported(step2.tableId) }) });
29142
29211
  footer = /* @__PURE__ */ (0, import_jsx_runtime92.jsxs)(import_jsx_runtime92.Fragment, { children: [
29143
29212
  !step2.made ? /* @__PURE__ */ (0, import_jsx_runtime92.jsx)(import_design_system76.Button, { variant: "ghost", className: "mr-auto", onClick: () => setStep({ at: "import" }), children: "Back" }) : null,
29144
- /* @__PURE__ */ (0, import_jsx_runtime92.jsx)(import_design_system76.Button, { variant: "outline", onClick: () => onOpenTable?.(step2.tableId), "data-new-table-open": "", children: "Open the table" })
29213
+ /* @__PURE__ */ (0, import_jsx_runtime92.jsx)(import_design_system76.Button, { variant: "outline", onClick: () => openImported(step2.tableId), "data-new-table-open": "", children: "Open the table" })
29145
29214
  ] });
29146
29215
  }
29147
29216
  return /* @__PURE__ */ (0, import_jsx_runtime92.jsxs)(
@@ -31986,10 +32055,10 @@ function ColumnsAtOnce({
31986
32055
  const orderMoved = rows.some((f, i) => f.id !== draft[i]?.id);
31987
32056
  const hiddenChanged = look ? JSON.stringify([...hidden].sort()) !== JSON.stringify([...look.hidden].sort()) : false;
31988
32057
  const lookChanged = Boolean(look) && (hiddenChanged || orderMoved && look.order !== null);
31989
- const blank = draft.find((d) => d.label.trim() === "");
31990
- const dirty = batch.length > 0 || lookChanged || Boolean(blank);
32058
+ const blank2 = draft.find((d) => d.label.trim() === "");
32059
+ const dirty = batch.length > 0 || lookChanged || Boolean(blank2);
31991
32060
  const save = async () => {
31992
- if (blank) return;
32061
+ if (blank2) return;
31993
32062
  setSaving(true);
31994
32063
  try {
31995
32064
  for (const one of batch) {
@@ -32102,7 +32171,7 @@ function ColumnsAtOnce({
32102
32171
  draft.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime107.jsx)("li", { className: "px-2 py-2 text-muted-foreground", children: "This table has no fields yet." }) : null
32103
32172
  ] }),
32104
32173
  dirty ? /* @__PURE__ */ (0, import_jsx_runtime107.jsxs)("div", { className: "flex flex-wrap items-center gap-2", "data-records-columns-save": "", children: [
32105
- /* @__PURE__ */ (0, import_jsx_runtime107.jsx)(import_design_system92.Button, { size: "sm", disabled: saving || Boolean(blank), onClick: () => void save(), children: saving ? "Saving\u2026" : "Save columns" }),
32174
+ /* @__PURE__ */ (0, import_jsx_runtime107.jsx)(import_design_system92.Button, { size: "sm", disabled: saving || Boolean(blank2), onClick: () => void save(), children: saving ? "Saving\u2026" : "Save columns" }),
32106
32175
  /* @__PURE__ */ (0, import_jsx_runtime107.jsx)(
32107
32176
  import_design_system92.Button,
32108
32177
  {
@@ -32116,7 +32185,7 @@ function ColumnsAtOnce({
32116
32185
  children: "Discard"
32117
32186
  }
32118
32187
  ),
32119
- blank ? /* @__PURE__ */ (0, import_jsx_runtime107.jsx)("span", { className: "text-muted-foreground", children: "Every column needs a name." }) : null
32188
+ blank2 ? /* @__PURE__ */ (0, import_jsx_runtime107.jsx)("span", { className: "text-muted-foreground", children: "Every column needs a name." }) : null
32120
32189
  ] }) : null
32121
32190
  ] });
32122
32191
  }
@@ -35376,6 +35445,17 @@ function baselineSpan(start, end) {
35376
35445
  if (!start) return null;
35377
35446
  return { first: start, last: end && end >= start ? end : start };
35378
35447
  }
35448
+ function taskListNeedsYear(days, currentYear) {
35449
+ const years = new Set(days.map((d) => Number(d.slice(0, 4))));
35450
+ return years.size > 1 || years.size === 1 && !years.has(currentYear);
35451
+ }
35452
+ function taskListDay(day2, withYear) {
35453
+ const m = /^(\d{4})-(\d{2})-(\d{2})$/.exec(day2);
35454
+ if (!m) return day2;
35455
+ const at = new Date(Number(m[1]), Number(m[2]) - 1, Number(m[3]));
35456
+ const short = at.toLocaleDateString(void 0, { month: "short", day: "numeric" });
35457
+ return withYear ? `${short} '${(m[1] ?? "").slice(2)}` : short;
35458
+ }
35379
35459
 
35380
35460
  // src/TimelineView.tsx
35381
35461
  var import_jsx_runtime120 = require("react/jsx-runtime");
@@ -35453,9 +35533,6 @@ function packRows(bars) {
35453
35533
  return { ...bar, row };
35454
35534
  });
35455
35535
  }
35456
- function shortDay(day2) {
35457
- return dayAt(day2).toLocaleDateString(void 0, { month: "short", day: "numeric" });
35458
- }
35459
35536
  function windowStart(anchor, zoom, firstDay) {
35460
35537
  const from = dayAt(addDays(anchor, -WINDOW[zoom].lead));
35461
35538
  if (zoom === "day" || zoom === "week") from.setDate(from.getDate() - daysSinceWeekStart(from.getDay(), firstDay));
@@ -36294,6 +36371,11 @@ function TimelineView({
36294
36371
  }) })
36295
36372
  ] })
36296
36373
  ) : null;
36374
+ const listYear = ganttOn && taskListNeedsYear(placed.flatMap((p) => {
36375
+ const at = shown5(p);
36376
+ return [at.first, at.last];
36377
+ }), Number(today.slice(0, 4)));
36378
+ const listDayW = listYear ? "w-[3.75rem]" : "w-12";
36297
36379
  const LABEL_COLUMN = (0, import_design_system102.cn)("sticky left-0 z-30 shrink-0 border-r bg-background", ganttOn ? "w-64 sm:w-80" : "w-24 sm:w-36");
36298
36380
  const todayLine = todayX !== null ? /* @__PURE__ */ (0, import_jsx_runtime120.jsx)(
36299
36381
  "div",
@@ -36307,8 +36389,8 @@ function TimelineView({
36307
36389
  const headerRow = (segments, className2, key) => /* @__PURE__ */ (0, import_jsx_runtime120.jsxs)("div", { className: "flex", "data-timeline-scale": key, children: [
36308
36390
  hasLabel ? /* @__PURE__ */ (0, import_jsx_runtime120.jsx)("div", { className: (0, import_design_system102.cn)(LABEL_COLUMN, "border-b"), children: ganttOn && key === "bottom" ? /* @__PURE__ */ (0, import_jsx_runtime120.jsxs)("div", { className: "flex h-full items-center gap-1 px-1.5 text-[11px] text-muted-foreground", "data-timeline-list-head": "", children: [
36309
36391
  /* @__PURE__ */ (0, import_jsx_runtime120.jsx)("span", { className: "min-w-0 flex-1 truncate", children: "Task" }),
36310
- /* @__PURE__ */ (0, import_jsx_runtime120.jsx)("span", { className: "w-12 shrink-0", children: "Start" }),
36311
- /* @__PURE__ */ (0, import_jsx_runtime120.jsx)("span", { className: "w-12 shrink-0", children: "End" }),
36392
+ /* @__PURE__ */ (0, import_jsx_runtime120.jsx)("span", { className: (0, import_design_system102.cn)(listDayW, "shrink-0"), children: "Start" }),
36393
+ /* @__PURE__ */ (0, import_jsx_runtime120.jsx)("span", { className: (0, import_design_system102.cn)(listDayW, "shrink-0"), children: "End" }),
36312
36394
  /* @__PURE__ */ (0, import_jsx_runtime120.jsx)("span", { className: "w-14 shrink-0 text-right", children: "Days" })
36313
36395
  ] }) : null }) : null,
36314
36396
  /* @__PURE__ */ (0, import_jsx_runtime120.jsxs)("div", { className: "relative shrink-0", style: { width, height: 22 }, children: [
@@ -36340,9 +36422,9 @@ function TimelineView({
36340
36422
  const slip = slipDays(baselineOf(b.p.row)?.last ?? null, at.last);
36341
36423
  return /* @__PURE__ */ (0, import_jsx_runtime120.jsxs)("div", { "data-timeline-list-row": b.p.row.id, className: "flex items-center gap-1 px-1.5 text-xs", style: { height: ROW_PX }, children: [
36342
36424
  /* @__PURE__ */ (0, import_jsx_runtime120.jsx)("button", { type: "button", className: "min-w-0 flex-1 truncate text-left hover:underline", onClick: () => onOpenRecord?.(b.p.row.id), children: titleOf(b.p.row) }),
36343
- /* @__PURE__ */ (0, import_jsx_runtime120.jsx)("span", { className: "w-12 shrink-0 whitespace-nowrap tabular-nums text-muted-foreground", children: shortDay(at.first) }),
36344
- /* @__PURE__ */ (0, import_jsx_runtime120.jsx)("span", { className: "w-12 shrink-0 whitespace-nowrap tabular-nums text-muted-foreground", children: shortDay(at.last) }),
36345
- /* @__PURE__ */ (0, import_jsx_runtime120.jsxs)("span", { className: "w-14 shrink-0 text-right tabular-nums", title: slip !== null ? slipWords(slip) : void 0, children: [
36425
+ /* @__PURE__ */ (0, import_jsx_runtime120.jsx)("span", { className: (0, import_design_system102.cn)(listDayW, "shrink-0 whitespace-nowrap tabular-nums text-muted-foreground"), children: taskListDay(at.first, listYear) }),
36426
+ /* @__PURE__ */ (0, import_jsx_runtime120.jsx)("span", { className: (0, import_design_system102.cn)(listDayW, "shrink-0 whitespace-nowrap tabular-nums text-muted-foreground"), children: taskListDay(at.last, listYear) }),
36427
+ /* @__PURE__ */ (0, import_jsx_runtime120.jsxs)("span", { className: "w-14 shrink-0 whitespace-nowrap text-right tabular-nums", title: slip !== null ? slipWords(slip) : void 0, children: [
36346
36428
  daysBetween(at.first, at.last) + 1,
36347
36429
  "d",
36348
36430
  slip !== null && slip !== 0 ? /* @__PURE__ */ (0, import_jsx_runtime120.jsx)("span", { className: (0, import_design_system102.cn)("ml-1", slip > 0 ? "text-destructive" : "text-emerald-600"), children: slip > 0 ? `+${slip}` : slip }) : null
@@ -39532,7 +39614,7 @@ function useSeedGuard() {
39532
39614
  var import_react233 = require("@ai-matrx/records/react");
39533
39615
 
39534
39616
  // src/viewActions.ts
39535
- var VIEW_LOCKED_REASON = "This view is locked. Someone who can edit this table can unlock it.";
39617
+ var VIEW_LOCKED_REASON = "Locked \xB7 ask an editor to unlock";
39536
39618
  var NOOP3 = () => {
39537
39619
  };
39538
39620
  function viewActions(whyNot, host, locked = false, personal = false) {
@@ -39571,6 +39653,9 @@ function copyName(name, taken) {
39571
39653
  if (!taken.includes(next)) return next;
39572
39654
  }
39573
39655
  }
39656
+ function viewActionReasons(actions) {
39657
+ return [...new Set(actions.flatMap((a) => a.disabledReason ? [a.disabledReason] : []))];
39658
+ }
39574
39659
 
39575
39660
  // src/ViewBar.tsx
39576
39661
  var import_jsx_runtime131 = require("react/jsx-runtime");
@@ -39604,6 +39689,7 @@ function ViewBar({ tableId, activeViewId, onActiveView, seed, settings, onViews,
39604
39689
  const claimSeed = useSeedGuard();
39605
39690
  const table = (0, import_react233.useTable)(tableId);
39606
39691
  const rights = useTableRights(table.data);
39692
+ const tableThere = Boolean(table.data);
39607
39693
  const notify = useRecordsUi().notify;
39608
39694
  const [views, setViews] = (0, import_react231.useState)(() => initialViews ?? null);
39609
39695
  const [error, setError] = (0, import_react231.useState)(null);
@@ -39683,7 +39769,7 @@ function ViewBar({ tableId, activeViewId, onActiveView, seed, settings, onViews,
39683
39769
  }
39684
39770
  setUnavailable(false);
39685
39771
  const mine = result.data;
39686
- const missing = (seed ?? []).filter((s) => !seedIsSatisfied(s, mine));
39772
+ const missing = tableThere ? (seed ?? []).filter((s) => !seedIsSatisfied(s, mine)) : [];
39687
39773
  if (missing.length > 0) {
39688
39774
  for (const spec of missing) {
39689
39775
  if (!claimSeed(spec.name)) continue;
@@ -39708,7 +39794,7 @@ function ViewBar({ tableId, activeViewId, onActiveView, seed, settings, onViews,
39708
39794
  setError(null);
39709
39795
  setViews(mine);
39710
39796
  onViews?.(mine);
39711
- }, [client, readViews, tableId, seedKey]);
39797
+ }, [client, readViews, tableId, seedKey, tableThere]);
39712
39798
  (0, import_react231.useEffect)(() => {
39713
39799
  if (!readOnMount.current) {
39714
39800
  readOnMount.current = true;
@@ -40032,29 +40118,35 @@ function ViewBar({ tableId, activeViewId, onActiveView, seed, settings, onViews,
40032
40118
  /* @__PURE__ */ (0, import_jsx_runtime131.jsx)(import_design_system112.Button, { size: "sm", type: "submit", className: "h-7", children: "Save" })
40033
40119
  ]
40034
40120
  }
40035
- ) : viewActions(rights.admin || current.personal ? null : rightsReason(rights, "structure") ?? ACTION_NO_ACCESS_REASON, {
40036
- rename: () => setRenaming(current.name),
40037
- duplicate: () => duplicate(current),
40038
- archive: () => archive(current),
40039
- ...rights.admin ? { toggleLock: () => toggleLock(current) } : {},
40040
- // Collaborative -> personal is the creator's or an editor's; personal -> collaborative is the creator's,
40041
- // and a personal view is only ever listed to its creator.
40042
- ...rights.admin || current.personal ? { togglePersonal: () => togglePersonal(current) } : {},
40043
- moveToSection: () => setMovingTo("")
40044
- }, current.presentation?.locked === true, current.personal === true).map((action3) => /* @__PURE__ */ (0, import_jsx_runtime131.jsx)(
40045
- import_controls2.Tile,
40046
- {
40047
- variant: "quiet",
40048
- ...action3.destructive ? { danger: true } : {},
40049
- disabled: action3.disabledReason !== void 0,
40050
- "data-view-action": action3.id,
40051
- onClick: () => void action3.run(),
40052
- icon: /* @__PURE__ */ (0, import_jsx_runtime131.jsx)(ObjectActionGlyph, { name: action3.icon, className: "h-3.5 w-3.5 shrink-0" }),
40053
- title: /* @__PURE__ */ (0, import_jsx_runtime131.jsx)("span", { title: action3.disabledReason, children: action3.label }),
40054
- ...action3.disabledReason ? { line: /* @__PURE__ */ (0, import_jsx_runtime131.jsx)("span", { "data-view-action-reason": "", children: action3.disabledReason }) } : {}
40055
- },
40056
- action3.id
40057
- )) }) : null,
40121
+ ) : (() => {
40122
+ const actions = viewActions(rights.admin || current.personal ? null : rightsReason(rights, "structure") ?? ACTION_NO_ACCESS_REASON, {
40123
+ rename: () => setRenaming(current.name),
40124
+ duplicate: () => duplicate(current),
40125
+ archive: () => archive(current),
40126
+ ...rights.admin ? { toggleLock: () => toggleLock(current) } : {},
40127
+ // Collaborative -> personal is the creator's or an editor's; personal -> collaborative is the creator's,
40128
+ // and a personal view is only ever listed to its creator.
40129
+ ...rights.admin || current.personal ? { togglePersonal: () => togglePersonal(current) } : {},
40130
+ moveToSection: () => setMovingTo("")
40131
+ }, current.presentation?.locked === true, current.personal === true);
40132
+ const reasons = viewActionReasons(actions);
40133
+ return /* @__PURE__ */ (0, import_jsx_runtime131.jsxs)(import_jsx_runtime131.Fragment, { children: [
40134
+ reasons.map((reason) => /* @__PURE__ */ (0, import_jsx_runtime131.jsx)("p", { className: "truncate px-2 py-1 text-xs text-muted-foreground", "data-view-actions-reason": "", title: reason, children: reason }, reason)),
40135
+ actions.map((action3) => /* @__PURE__ */ (0, import_jsx_runtime131.jsx)(
40136
+ import_controls2.Tile,
40137
+ {
40138
+ variant: "quiet",
40139
+ ...action3.destructive ? { danger: true } : {},
40140
+ disabled: action3.disabledReason !== void 0,
40141
+ "data-view-action": action3.id,
40142
+ onClick: () => void action3.run(),
40143
+ icon: /* @__PURE__ */ (0, import_jsx_runtime131.jsx)(ObjectActionGlyph, { name: action3.icon, className: "h-3.5 w-3.5 shrink-0" }),
40144
+ title: /* @__PURE__ */ (0, import_jsx_runtime131.jsx)("span", { title: action3.disabledReason, children: action3.label })
40145
+ },
40146
+ action3.id
40147
+ ))
40148
+ ] });
40149
+ })() }) : null,
40058
40150
  settings ? /* @__PURE__ */ (0, import_jsx_runtime131.jsx)("div", { className: "mt-1 border-t border-border pt-1", "data-view-settings": "", children: settings }) : null
40059
40151
  ] })
40060
40152
  ] });
@@ -41818,6 +41910,41 @@ function ActionInbox({
41818
41910
 
41819
41911
  // src/HistoryPanel.tsx
41820
41912
  var import_react244 = require("react");
41913
+
41914
+ // src/undoChange.ts
41915
+ function blank(value) {
41916
+ return value === null || value === void 0 || value === "";
41917
+ }
41918
+ function sameValue2(a, b) {
41919
+ if (blank(a) || blank(b)) return blank(a) && blank(b);
41920
+ if (a === b) return true;
41921
+ if (typeof a !== "object" || typeof b !== "object") return false;
41922
+ if (Array.isArray(a) !== Array.isArray(b)) return false;
41923
+ const left = a;
41924
+ const right = b;
41925
+ const keys = /* @__PURE__ */ new Set([...Object.keys(left), ...Object.keys(right)]);
41926
+ for (const key of keys) if (!sameValue2(left[key], right[key])) return false;
41927
+ return true;
41928
+ }
41929
+ function planUndo(changes, current, only) {
41930
+ const doc = current ?? {};
41931
+ return changes.filter((change) => !only || change.key === only).map((change) => {
41932
+ const now = doc[change.key];
41933
+ const state = sameValue2(now, change.before) ? "already" : sameValue2(now, change.after) ? "clean" : "conflict";
41934
+ return { key: change.key, label: change.label, current: now, after: change.after, before: change.before, state };
41935
+ });
41936
+ }
41937
+ function undoPatch(lines, replaceLaterEdits) {
41938
+ const patch = {};
41939
+ for (const line of lines) {
41940
+ if (line.state === "already") continue;
41941
+ if (line.state === "conflict" && !replaceLaterEdits) continue;
41942
+ patch[line.key] = blank(line.before) ? null : line.before;
41943
+ }
41944
+ return patch;
41945
+ }
41946
+
41947
+ // src/HistoryPanel.tsx
41821
41948
  var import_react245 = require("@ai-matrx/records/react");
41822
41949
  var import_design_system118 = require("@ai-matrx/design-system");
41823
41950
  var import_format12 = require("@ai-matrx/kit/format");
@@ -42090,6 +42217,7 @@ function HistoryPanel({ tableId, recordId, onAskAboutField, className }) {
42090
42217
  const [error, setError] = (0, import_react244.useState)(null);
42091
42218
  const [open, setOpen] = (0, import_react244.useState)(null);
42092
42219
  const [pending, setPending] = (0, import_react244.useState)({ phase: "idle" });
42220
+ const [undo, setUndo] = (0, import_react244.useState)({ phase: "idle" });
42093
42221
  const seenAtPreview = (0, import_react244.useRef)(null);
42094
42222
  const [said2, setSaid] = (0, import_react244.useState)(null);
42095
42223
  const listRef = (0, import_react244.useRef)(null);
@@ -42139,6 +42267,37 @@ function HistoryPanel({ tableId, recordId, onAskAboutField, className }) {
42139
42267
  }
42140
42268
  setPending({ phase: "confirm", version, fieldKey, preview: asked3.data });
42141
42269
  }
42270
+ async function startUndo(entry, only) {
42271
+ setSaid(null);
42272
+ setPending({ phase: "idle" });
42273
+ setUndo({ phase: "asking", version: entry.version, only });
42274
+ const read = await client.recordRead({ record_id: recordId, withVersion: true });
42275
+ if (!read.ok) {
42276
+ setUndo({ phase: "idle" });
42277
+ setError(read.error);
42278
+ return;
42279
+ }
42280
+ const lines = planUndo(entry.changes, read.data.document, only);
42281
+ setUndo({ phase: "confirm", version: entry.version, only, lines, seen: read.data.version ?? await (0, recordVersions_exports.readVersionNow)(client, recordId) });
42282
+ }
42283
+ async function doUndo(replaceLaterEdits) {
42284
+ if (undo.phase !== "confirm") return;
42285
+ const { version, only, lines, seen } = undo;
42286
+ setUndo({ phase: "writing", version, only });
42287
+ const patch = undoPatch(lines, replaceLaterEdits);
42288
+ const written = await (0, recordVersions_exports.updateRecordAt)(client, { record_id: recordId, patch, version: seen });
42289
+ setUndo({ phase: "idle" });
42290
+ if (!written.ok) {
42291
+ setError(written.error);
42292
+ return;
42293
+ }
42294
+ const count = Object.keys(patch).length;
42295
+ const kept = lines.filter((line) => line.state === "conflict" && !replaceLaterEdits).length;
42296
+ setSaid(
42297
+ `Undone as version ${written.data}. ${count} ${count === 1 ? "value" : "values"} put back` + (kept ? `, ${kept} later ${kept === 1 ? "edit" : "edits"} kept` : "") + ". Every other field is as it was."
42298
+ );
42299
+ await load();
42300
+ }
42142
42301
  async function doRestore(version, fieldKey) {
42143
42302
  setPending({ phase: "writing", version, fieldKey });
42144
42303
  const written = await (0, recordVersions_exports.restoreAt)(client, { record_id: recordId, version, field_key: fieldKey, seenVersion: seenAtPreview.current });
@@ -42197,6 +42356,10 @@ function HistoryPanel({ tableId, recordId, onAskAboutField, className }) {
42197
42356
  canRestore: rights.write && entry.version >= newestMakerVersion && !(entry.migration_id && makerIds.has(entry.migration_id)),
42198
42357
  whyNotRestore: entry.migration_id && makerIds.has(entry.migration_id) ? `This version is a ${migrationWords(makers.find((m) => m.id === entry.migration_id)?.verb ?? "split").toLowerCase()}. Undo it in the Migration log below, so no copy is left behind.` : rights.write && entry.version < newestMakerVersion ? "A newer split still holds some of these values. Undo it in the Migration log below first, so no copy is left behind." : rights.why("write"),
42199
42358
  pending,
42359
+ undo,
42360
+ onUndo: (only) => void startUndo(entry, only),
42361
+ onUndoConfirm: (replace) => void doUndo(replace),
42362
+ onUndoCancel: () => setUndo({ phase: "idle" }),
42200
42363
  onRestore: (fieldKey) => void startRestore(entry.version, fieldKey),
42201
42364
  onConfirm: (fieldKey) => void doRestore(entry.version, fieldKey),
42202
42365
  onCancel: () => setPending({ phase: "idle" }),
@@ -42226,6 +42389,10 @@ function VersionRow({
42226
42389
  canRestore,
42227
42390
  whyNotRestore,
42228
42391
  pending,
42392
+ undo,
42393
+ onUndo,
42394
+ onUndoConfirm,
42395
+ onUndoCancel,
42229
42396
  onRestore,
42230
42397
  onConfirm,
42231
42398
  onCancel,
@@ -42233,6 +42400,9 @@ function VersionRow({
42233
42400
  }) {
42234
42401
  const mine = pending.phase !== "idle" && pending.version === entry.version;
42235
42402
  const confirming = mine && pending.phase === "confirm" ? pending : null;
42403
+ const canUndo = canRestore && entry.operation !== "insert" && entry.version > 1 && entry.changes.length > 0;
42404
+ const undoMine = undo.phase !== "idle" && undo.version === entry.version;
42405
+ const undoConfirming = undoMine && undo.phase === "confirm" ? undo : null;
42236
42406
  return /* @__PURE__ */ (0, import_jsx_runtime137.jsxs)("li", { className: "flex flex-col", children: [
42237
42407
  /* @__PURE__ */ (0, import_jsx_runtime137.jsxs)(
42238
42408
  "div",
@@ -42288,13 +42458,24 @@ function VersionRow({
42288
42458
  {
42289
42459
  change,
42290
42460
  field: byKey.get(change.key),
42291
- canRestore,
42292
- onRestore: () => onRestore(change.key),
42461
+ canRestore: canUndo,
42462
+ onRestore: () => onUndo(change.key),
42293
42463
  ...onAskAboutField ? { onAskAboutField } : {}
42294
42464
  },
42295
42465
  change.key
42296
42466
  )) }),
42297
- canRestore ? confirming ? /* @__PURE__ */ (0, import_jsx_runtime137.jsx)(
42467
+ undoConfirming ? /* @__PURE__ */ (0, import_jsx_runtime137.jsx)(ConfirmUndo, { lines: undoConfirming.lines, onConfirm: onUndoConfirm, onCancel: onUndoCancel }) : undoMine && undo.phase === "writing" ? /* @__PURE__ */ (0, import_jsx_runtime137.jsx)("p", { className: "text-[11px] text-muted-foreground", children: "Undoing\u2026" }) : canRestore && !confirming && !(mine && pending.phase === "writing") ? canUndo ? /* @__PURE__ */ (0, import_jsx_runtime137.jsx)("div", { className: "flex", children: /* @__PURE__ */ (0, import_jsx_runtime137.jsx)(
42468
+ import_design_system118.Button,
42469
+ {
42470
+ size: "sm",
42471
+ variant: "secondary",
42472
+ className: "h-6 px-2 text-[11px]",
42473
+ disabled: undoMine,
42474
+ onClick: () => onUndo(null),
42475
+ children: undoMine ? "Working out what would change\u2026" : "Undo this change"
42476
+ }
42477
+ ) }) : null : null,
42478
+ canRestore && !undoMine ? confirming ? /* @__PURE__ */ (0, import_jsx_runtime137.jsx)(
42298
42479
  ConfirmRestore,
42299
42480
  {
42300
42481
  preview: confirming.preview,
@@ -42376,9 +42557,64 @@ function ChangeLine({
42376
42557
  children: "Who changed this?"
42377
42558
  }
42378
42559
  ) : null,
42379
- canRestore ? /* @__PURE__ */ (0, import_jsx_runtime137.jsx)(import_design_system118.Button, { size: "sm", variant: "ghost", className: "h-5 shrink-0 px-1 text-[10px]", onClick: onRestore, children: "Put this one back" }) : null
42560
+ canRestore ? /* @__PURE__ */ (0, import_jsx_runtime137.jsx)(import_design_system118.Button, { size: "sm", variant: "ghost", className: "h-5 shrink-0 px-1 text-[10px]", onClick: onRestore, children: "Undo this one" }) : null
42380
42561
  ] });
42381
42562
  }
42563
+ function ConfirmUndo({
42564
+ lines,
42565
+ onConfirm,
42566
+ onCancel
42567
+ }) {
42568
+ const clean = lines.filter((line) => line.state === "clean");
42569
+ const conflicts = lines.filter((line) => line.state === "conflict");
42570
+ const already = lines.filter((line) => line.state === "already");
42571
+ const nothing = clean.length + conflicts.length === 0;
42572
+ return /* @__PURE__ */ (0, import_jsx_runtime137.jsxs)("div", { "data-undo-confirm": "", className: "flex flex-col gap-1 rounded border border-amber-500/40 bg-amber-500/5 p-2", children: [
42573
+ /* @__PURE__ */ (0, import_jsx_runtime137.jsx)("p", { className: "text-[11px] font-medium", children: nothing ? "Nothing to undo \u2014 every value this version changed already says what it said before." : `Undoing this would put back ${clean.length + conflicts.length} ${clean.length + conflicts.length === 1 ? "value" : "values"}:` }),
42574
+ /* @__PURE__ */ (0, import_jsx_runtime137.jsx)("ul", { className: "flex flex-col gap-0.5", children: [...clean, ...conflicts].map((line) => /* @__PURE__ */ (0, import_jsx_runtime137.jsxs)("li", { "data-undo-line": line.key, "data-undo-state": line.state, className: "text-[11px]", children: [
42575
+ /* @__PURE__ */ (0, import_jsx_runtime137.jsx)("span", { className: "font-medium", children: line.label }),
42576
+ " ",
42577
+ /* @__PURE__ */ (0, import_jsx_runtime137.jsx)("span", { className: "text-muted-foreground", children: say(line.current, void 0) }),
42578
+ /* @__PURE__ */ (0, import_jsx_runtime137.jsx)("span", { className: "mx-1 text-muted-foreground", children: "\u2192" }),
42579
+ /* @__PURE__ */ (0, import_jsx_runtime137.jsx)("strong", { className: "font-medium", children: blankSays(line.before) }),
42580
+ line.state === "conflict" ? /* @__PURE__ */ (0, import_jsx_runtime137.jsx)("span", { className: "ml-1 text-amber-700 dark:text-amber-400", children: "edited again since" }) : null
42581
+ ] }, line.key)) }),
42582
+ already.length ? /* @__PURE__ */ (0, import_jsx_runtime137.jsxs)("p", { className: "text-[11px] text-muted-foreground", children: [
42583
+ "Already back: ",
42584
+ already.map((line) => line.label).join(", "),
42585
+ "."
42586
+ ] }) : null,
42587
+ conflicts.length ? /* @__PURE__ */ (0, import_jsx_runtime137.jsxs)("p", { className: "text-[11px] text-muted-foreground", children: [
42588
+ conflicts.map((line) => line.label).join(", "),
42589
+ " ",
42590
+ conflicts.length === 1 ? "was" : "were",
42591
+ " edited again after this change. Keep the newer ",
42592
+ conflicts.length === 1 ? "edit" : "edits",
42593
+ ", or replace ",
42594
+ conflicts.length === 1 ? "it" : "them",
42595
+ "?"
42596
+ ] }) : /* @__PURE__ */ (0, import_jsx_runtime137.jsx)("p", { className: "text-[11px] text-muted-foreground", children: "It is saved as a new version. Nothing in the history is erased, and later edits to other fields stay." }),
42597
+ /* @__PURE__ */ (0, import_jsx_runtime137.jsxs)("div", { className: "flex flex-wrap gap-1", children: [
42598
+ conflicts.length ? /* @__PURE__ */ (0, import_jsx_runtime137.jsxs)(import_jsx_runtime137.Fragment, { children: [
42599
+ clean.length ? /* @__PURE__ */ (0, import_jsx_runtime137.jsx)(import_design_system118.Button, { size: "sm", className: "h-6 px-2 text-[11px]", onClick: () => onConfirm(false), children: "Undo the rest, keep newer edits" }) : null,
42600
+ /* @__PURE__ */ (0, import_jsx_runtime137.jsx)(
42601
+ import_design_system118.Button,
42602
+ {
42603
+ size: "sm",
42604
+ variant: clean.length ? "secondary" : "primary",
42605
+ className: "h-6 px-2 text-[11px]",
42606
+ onClick: () => onConfirm(true),
42607
+ children: "Replace newer edits too"
42608
+ }
42609
+ )
42610
+ ] }) : /* @__PURE__ */ (0, import_jsx_runtime137.jsx)(import_design_system118.Button, { size: "sm", className: "h-6 px-2 text-[11px]", disabled: nothing, onClick: () => onConfirm(false), children: "Yes, undo it" }),
42611
+ /* @__PURE__ */ (0, import_jsx_runtime137.jsx)(import_design_system118.Button, { size: "sm", variant: "ghost", className: "h-6 px-2 text-[11px]", onClick: onCancel, children: "Cancel" })
42612
+ ] })
42613
+ ] });
42614
+ }
42615
+ function blankSays(value) {
42616
+ return value === null || value === void 0 || value === "" ? "cleared" : say(value, void 0);
42617
+ }
42382
42618
  function ConfirmRestore({
42383
42619
  preview,
42384
42620
  busy,
@@ -42699,11 +42935,12 @@ function FieldHistoryPanel({
42699
42935
  const label = (fields.data ?? []).find((f) => f.key === fieldKey)?.label || (0, import_text_case20.humanizeIdentifier)(fieldKey);
42700
42936
  if (error) return /* @__PURE__ */ (0, import_jsx_runtime139.jsx)(RefusalNotice, { error, className });
42701
42937
  if (!rows || fields.loading && !fields.data || table.loading && !table.data) return /* @__PURE__ */ (0, import_jsx_runtime139.jsx)(import_design_system120.Skeleton, { className: (0, import_design_system120.cn)("h-40 w-full", className) });
42702
- async function start(row) {
42938
+ async function start(row, back = false) {
42703
42939
  setSaid(null);
42704
- setPending({ phase: "asking", recordId: row.record_id, version: row.version });
42940
+ const target = back ? row.version - 1 : row.version;
42941
+ setPending({ phase: "asking", recordId: row.record_id, version: target, back });
42705
42942
  const [asked3, seen] = await Promise.all([
42706
- client.restorePreview({ record_id: row.record_id, version: row.version, field_key: fieldKey }),
42943
+ client.restorePreview({ record_id: row.record_id, version: target, field_key: fieldKey }),
42707
42944
  (0, recordVersions_exports.readVersionNow)(client, row.record_id)
42708
42945
  ]);
42709
42946
  seenAtPreview.current = seen;
@@ -42712,17 +42949,20 @@ function FieldHistoryPanel({
42712
42949
  setError(asked3.error);
42713
42950
  return;
42714
42951
  }
42715
- setPending({ phase: "confirm", recordId: row.record_id, version: row.version, preview: asked3.data });
42952
+ const laterEdit = back && asked3.data.changes.some((c) => c.key === fieldKey && !sameValue2(c.before, row.after));
42953
+ setPending({ phase: "confirm", recordId: row.record_id, version: target, preview: asked3.data, back, laterEdit });
42716
42954
  }
42717
- async function confirm(recordOf2, version) {
42718
- setPending({ phase: "writing", recordId: recordOf2, version });
42955
+ async function confirm(recordOf2, version, back = false) {
42956
+ setPending({ phase: "writing", recordId: recordOf2, version, back });
42719
42957
  const written = await (0, recordVersions_exports.restoreAt)(client, { record_id: recordOf2, version, field_key: fieldKey, seenVersion: seenAtPreview.current });
42720
42958
  setPending({ phase: "idle" });
42721
42959
  if (!written.ok) {
42722
42960
  setError(written.error);
42723
42961
  return;
42724
42962
  }
42725
- setSaid(`Put back as version ${written.data.version}. Every earlier version is still here.`);
42963
+ setSaid(
42964
+ back ? `Change undone as version ${written.data.version}. Other fields keep their later edits.` : `Put back as version ${written.data.version}. Every earlier version is still here.`
42965
+ );
42726
42966
  await load();
42727
42967
  }
42728
42968
  return /* @__PURE__ */ (0, import_jsx_runtime139.jsxs)("section", { className: (0, import_design_system120.cn)("flex min-h-0 flex-col gap-2", className), children: [
@@ -42740,8 +42980,10 @@ function FieldHistoryPanel({
42740
42980
  label,
42741
42981
  " has never been changed on anything you can see."
42742
42982
  ] }) : /* @__PURE__ */ (0, import_jsx_runtime139.jsx)("ol", { className: "flex min-h-0 flex-col divide-y overflow-y-auto rounded border", children: rows.map((row) => {
42743
- const mine = pending.phase !== "idle" && pending.recordId === row.record_id && pending.version === row.version;
42744
- const confirming = mine && pending.phase === "confirm" ? pending : null;
42983
+ const matches2 = (back) => pending.phase !== "idle" && pending.recordId === row.record_id && Boolean(pending.back) === back && pending.version === (back ? row.version - 1 : row.version);
42984
+ const mineValue = matches2(false);
42985
+ const mineBack = matches2(true);
42986
+ const confirming = (mineValue || mineBack) && pending.phase === "confirm" ? pending : null;
42745
42987
  return /* @__PURE__ */ (0, import_jsx_runtime139.jsxs)("li", { className: "flex flex-col", children: [
42746
42988
  /* @__PURE__ */ (0, import_jsx_runtime139.jsxs)("div", { className: "flex items-baseline gap-2 px-2 py-1.5 text-xs", children: [
42747
42989
  onOpenRecord ? /* @__PURE__ */ (0, import_jsx_runtime139.jsx)(
@@ -42780,21 +43022,38 @@ function FieldHistoryPanel({
42780
43022
  size: "sm",
42781
43023
  variant: "ghost",
42782
43024
  className: "h-5 shrink-0 px-1 text-[10px]",
42783
- disabled: mine,
43025
+ disabled: mineValue,
42784
43026
  onClick: () => void start(row),
42785
43027
  children: "Put this back"
42786
43028
  }
43029
+ ) : null,
43030
+ rights.write && row.version > 1 ? /* @__PURE__ */ (0, import_jsx_runtime139.jsx)(
43031
+ import_design_system120.Button,
43032
+ {
43033
+ size: "sm",
43034
+ variant: "ghost",
43035
+ className: "h-5 shrink-0 px-1 text-[10px]",
43036
+ disabled: mineBack,
43037
+ onClick: () => void start(row, true),
43038
+ children: "Undo this change"
43039
+ }
42787
43040
  ) : null
42788
43041
  ] }),
42789
- confirming ? /* @__PURE__ */ (0, import_jsx_runtime139.jsx)("div", { className: "border-t px-2 py-2", children: /* @__PURE__ */ (0, import_jsx_runtime139.jsx)(
42790
- ConfirmRestore,
42791
- {
42792
- preview: confirming.preview,
42793
- busy: false,
42794
- onConfirm: () => void confirm(confirming.recordId, confirming.version),
42795
- onCancel: () => setPending({ phase: "idle" })
42796
- }
42797
- ) }) : null
43042
+ confirming ? /* @__PURE__ */ (0, import_jsx_runtime139.jsxs)("div", { className: "border-t px-2 py-2", children: [
43043
+ confirming.laterEdit ? /* @__PURE__ */ (0, import_jsx_runtime139.jsxs)("p", { "data-later-edit": "", className: "mb-1 text-[11px] font-medium text-amber-700 dark:text-amber-400", children: [
43044
+ label,
43045
+ " was edited again after this change. Undoing replaces that newer value; Cancel keeps it."
43046
+ ] }) : null,
43047
+ /* @__PURE__ */ (0, import_jsx_runtime139.jsx)(
43048
+ ConfirmRestore,
43049
+ {
43050
+ preview: confirming.preview,
43051
+ busy: false,
43052
+ onConfirm: () => void confirm(confirming.recordId, confirming.version, confirming.back === true),
43053
+ onCancel: () => setPending({ phase: "idle" })
43054
+ }
43055
+ )
43056
+ ] }) : null
42798
43057
  ] }, `${row.record_id}-${row.version}`);
42799
43058
  }) }),
42800
43059
  rights.write ? null : /* @__PURE__ */ (0, import_jsx_runtime139.jsx)("p", { className: "text-[11px] text-muted-foreground", children: rights.why("write") })