@ai-matrx/records-ui 0.115.46 → 0.115.47

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.js CHANGED
@@ -2030,14 +2030,24 @@ function RefusalLine({ error, className }) {
2030
2030
  // src/FieldRetype.tsx
2031
2031
  import { jsx as jsx6, jsxs as jsxs4 } from "react/jsx-runtime";
2032
2032
  var RETYPE_TARGETS = [
2033
- { id: "text", behaviour: "text", kind: null, label: "Text", holds: "words" },
2034
- { id: "number", behaviour: "range", kind: "number", label: "Number", holds: "a number" },
2033
+ { id: "text", behaviour: "text", kind: null, label: "Text", holds: "words", via: "behaviour" },
2034
+ { id: "number", behaviour: "range", kind: "number", label: "Number", holds: "a number", via: "behaviour" },
2035
2035
  // A DATE is a `range` of kind date: `migrate_retype` alone cannot say "date" (it keeps the old
2036
2036
  // kind, so every date would be kept aside), so this one goes through `custom.field_update`'s own
2037
2037
  // retype arm (`parity_type: datetime`), which converts on the SAME trigger and keeps what does not
2038
2038
  // fit in `_retired` with the reason — measured on the live store 2026-09-28.
2039
- { id: "date", behaviour: "range", kind: "date", label: "Date", holds: "a date" },
2040
- { id: "checkbox", behaviour: "boolean", kind: null, label: "Yes / no", holds: "a yes or a no" }
2039
+ { id: "date", behaviour: "range", kind: "date", label: "Date", holds: "a date", via: "kind", parity: "datetime" },
2040
+ { id: "checkbox", behaviour: "boolean", kind: null, label: "Yes / no", holds: "a yes or a no", via: "behaviour" },
2041
+ // THE REST OF WHAT THE STORE'S RETYPE TAKES (walk 2026-10-10: a text column could only become Number,
2042
+ // Date or Yes/no, so it could not become a Choice, Phone, Email or Link — the Sheet allowed any
2043
+ // kind the values convert to). All go through `custom.field_update`'s `parity_type` arm, the same
2044
+ // conversion trigger, which keeps what does not fit in `_retired` with the reason.
2045
+ { id: "email", behaviour: "text", kind: null, label: "Email address", holds: "email addresses", via: "kind", parity: "email" },
2046
+ { id: "phone", behaviour: "text", kind: null, label: "Phone number", holds: "phone numbers", via: "kind", parity: "phone" },
2047
+ { id: "url", behaviour: "text", kind: null, label: "Link", holds: "web addresses", via: "kind", parity: "url" },
2048
+ { id: "currency", behaviour: "range", kind: "number", label: "Money", holds: "an amount of money", via: "kind", parity: "currency" },
2049
+ { id: "percent", behaviour: "range", kind: "number", label: "Percentage", holds: "a percentage", via: "kind", parity: "percent" },
2050
+ { id: "select", behaviour: "text", kind: null, label: "Choice", holds: "one choice from a list", via: "kind", parity: "select" }
2041
2051
  ];
2042
2052
  var PREVIEW_GROUPS = 1e3;
2043
2053
  function retypeableFrom(field2) {
@@ -2059,6 +2069,7 @@ function currentTarget(field2) {
2059
2069
  const kind = String(editorKindFor(field2));
2060
2070
  if (String(field2.type) === "boolean") return "checkbox";
2061
2071
  if (kind === "datetime" || kind === "date") return "date";
2072
+ if (kind === "email" || kind === "phone" || kind === "url" || kind === "currency" || kind === "percent") return kind;
2062
2073
  if (String(field2.type) === "range") return "number";
2063
2074
  return "text";
2064
2075
  }
@@ -2102,8 +2113,8 @@ function FieldRetype({ field: field2, tableId, onRetyped }) {
2102
2113
  setRefusal(null);
2103
2114
  let holding;
2104
2115
  let aside;
2105
- if (to.id === "date") {
2106
- const done = await client.fieldUpdate({ field_id: field2.id, patch: { parity_type: "datetime" } });
2116
+ if (to.via !== "behaviour") {
2117
+ const done = await client.fieldUpdate({ field_id: field2.id, patch: { parity_type: to.parity } });
2107
2118
  setBusy(false);
2108
2119
  if (!done.ok) {
2109
2120
  setRefusal(done.error);
@@ -5360,7 +5371,7 @@ function FormulaTextEditor({
5360
5371
  value: text,
5361
5372
  rows: 2,
5362
5373
  "aria-label": "The formula",
5363
- placeholder: "{Visit fee} - {Deposit taken}",
5374
+ placeholder: columns.length > 0 ? `{${fieldName(columns[0])}}` : "Write a formula",
5364
5375
  className: "font-mono text-xs",
5365
5376
  onChange: (e) => onText(e.target.value)
5366
5377
  }
@@ -8909,7 +8920,7 @@ function FieldEditor(props) {
8909
8920
  const statusGroupsSent = Object.fromEntries(shownStatusRows.filter((r) => !editing || r.ref in statusGroups || !(r.ref in statusKeys)).map((r) => [r.ref, r.group]));
8910
8921
  const statusGroupsChanged = type === "status" && editing && Object.keys(statusGroupsSent).length > 0;
8911
8922
  const formulaChanged = formulaText.trim() !== startingFormulaText.trim();
8912
- 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;
8923
+ 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;
8913
8924
  const noun = onEntity ? "field" : "column";
8914
8925
  const nameTaken = columnNameTakenBy(label, others.map(fieldName));
8915
8926
  const nameLine = nameTaken ? columnNameTakenLine(nameTaken, noun) : columnNameProblemLine(label, noun);
@@ -9515,7 +9526,7 @@ function FieldEditor(props) {
9515
9526
  Button17,
9516
9527
  {
9517
9528
  size: "sm",
9518
- disabled: mutation.saving || Boolean(formulaMissing),
9529
+ disabled: mutation.saving || Boolean(formulaMissing) || Boolean(nameLine) && label.trim() !== (field2?.label ?? "").trim(),
9519
9530
  ...missingShown ? { "aria-describedby": "field-editor-missing" } : {},
9520
9531
  onClick: () => {
9521
9532
  if (missing) {
@@ -24023,7 +24034,18 @@ function useGroupFacts(args) {
24023
24034
  }, [client, tableId, groupKey, chosenKey, filterKey, version]);
24024
24035
  return facts;
24025
24036
  }
24037
+ function yesNoGroupWords(field2, value) {
24038
+ const answer = value === true || value === "true" ? true : value === false || value === "false" ? false : null;
24039
+ if (answer === null) return null;
24040
+ const name = (field2.label || field2.key).trim();
24041
+ return answer ? `\u2713 ${name}` : `\u2014 Not ${name.charAt(0).toLowerCase()}${name.slice(1)}`;
24042
+ }
24026
24043
  function GroupLabel({ field: field2, value, withheld = null }) {
24044
+ if (field2 && editorKindFor(field2) === "checkbox") {
24045
+ if (groupValueKey(value) === "") return /* @__PURE__ */ jsx81("span", { className: "text-muted-foreground", "data-records-group-label": "", children: "Not answered" });
24046
+ const words2 = yesNoGroupWords(field2, value);
24047
+ if (words2) return /* @__PURE__ */ jsx81("span", { "data-records-group-label": "", children: words2 });
24048
+ }
24027
24049
  if (groupValueKey(value) === "" && !(field2 && withheld)) return /* @__PURE__ */ jsx81("span", { className: "text-muted-foreground", children: "No value" });
24028
24050
  if (!field2) return /* @__PURE__ */ jsx81("span", { children: String(value) });
24029
24051
  return /* @__PURE__ */ jsx81("span", { className: "inline-flex min-w-0 items-center", "data-records-group-label": "", children: /* @__PURE__ */ jsx81(RecordValue, { inCell: true, field: field2, value, format: formatForField(field2), withheld }) });
@@ -24057,11 +24079,16 @@ function groupFactsFor(facts, fields, chosen) {
24057
24079
  return { count: fact.count, aggregates };
24058
24080
  };
24059
24081
  }
24060
- function useGroupLabel(fields, groupKey) {
24082
+ function useGroupLabel(fields, groupKey, thenKeys = []) {
24083
+ const thenJoined = thenKeys.join("|");
24061
24084
  return useMemo34(() => {
24062
- const field2 = groupKey ? fields.find((f) => f.key === groupKey) : void 0;
24063
- return (group) => /* @__PURE__ */ jsx81(GroupLabel, { field: field2, value: group.value, withheld: groupKey ? groupWithheldNotice(group.rows, groupKey, group.value) : null });
24064
- }, [fields, groupKey]);
24085
+ const keys = groupKey ? [groupKey, ...thenJoined ? thenJoined.split("|") : []] : [];
24086
+ return (group) => {
24087
+ const key = keys[group.ancestors?.length ?? 0] ?? groupKey;
24088
+ const field2 = key ? fields.find((f) => f.key === key) : void 0;
24089
+ return /* @__PURE__ */ jsx81(GroupLabel, { field: field2, value: group.value, withheld: key ? groupWithheldNotice(group.rows, key, group.value) : null });
24090
+ };
24091
+ }, [fields, groupKey, thenJoined]);
24065
24092
  }
24066
24093
 
24067
24094
  // src/gridUndo.tsx
@@ -25842,7 +25869,7 @@ function GridBody({
25842
25869
  const summaries = useColumnSummaries({ tableId, chosen: chosenSummaries, filter: readFilter, version: summaryVersion });
25843
25870
  const drillConfig = useGridDrillConfig({ tableId, state: drillState, presentation, onPresentationChange, version: records.data });
25844
25871
  const groupFacts = useGroupFacts({ tableId, groupKey: rowGroupKey, chosen: chosenSummaries, filter: readFilter, version: summaryVersion });
25845
- const groupLabel2 = useGroupLabel(fields.data ?? [], rowGroupKey);
25872
+ const groupLabel2 = useGroupLabel(fields.data ?? [], rowGroupKey, (presentation.grouping?.then ?? []).map((t) => t.field));
25846
25873
  const [duplicated, setDuplicated] = useState71(null);
25847
25874
  const duplicate = useCallback28(
25848
25875
  async (row) => {
@@ -26770,7 +26797,7 @@ function GridBody({
26770
26797
  rowNoun: "record",
26771
26798
  ...thenKeys.length > 0 ? { thenColumnIds: thenKeys } : {},
26772
26799
  ...aggregates ? { aggregates } : {},
26773
- ...rowsGrouped ? { renderLabel: (group) => group.ancestors ? void 0 : groupLabel2(group), order: "first-seen", emptyLabel: "No value" } : {},
26800
+ ...rowsGrouped ? { renderLabel: groupLabel2, order: "first-seen", emptyLabel: "No value" } : {},
26774
26801
  ...facts ? { groupFacts: facts } : {},
26775
26802
  ...!rowsGrouped && view?.order ? { order: view.order } : {},
26776
26803
  ...view?.collapsed ? { collapsed: view.collapsed } : {},
@@ -35219,6 +35246,17 @@ function baselineSpan(start, end) {
35219
35246
  if (!start) return null;
35220
35247
  return { first: start, last: end && end >= start ? end : start };
35221
35248
  }
35249
+ function taskListNeedsYear(days, currentYear) {
35250
+ const years = new Set(days.map((d) => Number(d.slice(0, 4))));
35251
+ return years.size > 1 || years.size === 1 && !years.has(currentYear);
35252
+ }
35253
+ function taskListDay(day2, withYear) {
35254
+ const m = /^(\d{4})-(\d{2})-(\d{2})$/.exec(day2);
35255
+ if (!m) return day2;
35256
+ const at = new Date(Number(m[1]), Number(m[2]) - 1, Number(m[3]));
35257
+ const short = at.toLocaleDateString(void 0, { month: "short", day: "numeric" });
35258
+ return withYear ? `${short} '${(m[1] ?? "").slice(2)}` : short;
35259
+ }
35222
35260
 
35223
35261
  // src/TimelineView.tsx
35224
35262
  import { Fragment as Fragment45, jsx as jsx120, jsxs as jsxs109 } from "react/jsx-runtime";
@@ -35296,9 +35334,6 @@ function packRows(bars) {
35296
35334
  return { ...bar, row };
35297
35335
  });
35298
35336
  }
35299
- function shortDay(day2) {
35300
- return dayAt(day2).toLocaleDateString(void 0, { month: "short", day: "numeric" });
35301
- }
35302
35337
  function windowStart(anchor, zoom, firstDay) {
35303
35338
  const from = dayAt(addDays(anchor, -WINDOW[zoom].lead));
35304
35339
  if (zoom === "day" || zoom === "week") from.setDate(from.getDate() - daysSinceWeekStart(from.getDay(), firstDay));
@@ -36137,6 +36172,11 @@ function TimelineView({
36137
36172
  }) })
36138
36173
  ] })
36139
36174
  ) : null;
36175
+ const listYear = ganttOn && taskListNeedsYear(placed.flatMap((p) => {
36176
+ const at = shown5(p);
36177
+ return [at.first, at.last];
36178
+ }), Number(today.slice(0, 4)));
36179
+ const listDayW = listYear ? "w-[3.75rem]" : "w-12";
36140
36180
  const LABEL_COLUMN = cn58("sticky left-0 z-30 shrink-0 border-r bg-background", ganttOn ? "w-64 sm:w-80" : "w-24 sm:w-36");
36141
36181
  const todayLine = todayX !== null ? /* @__PURE__ */ jsx120(
36142
36182
  "div",
@@ -36150,8 +36190,8 @@ function TimelineView({
36150
36190
  const headerRow = (segments, className2, key) => /* @__PURE__ */ jsxs109("div", { className: "flex", "data-timeline-scale": key, children: [
36151
36191
  hasLabel ? /* @__PURE__ */ jsx120("div", { className: cn58(LABEL_COLUMN, "border-b"), children: ganttOn && key === "bottom" ? /* @__PURE__ */ jsxs109("div", { className: "flex h-full items-center gap-1 px-1.5 text-[11px] text-muted-foreground", "data-timeline-list-head": "", children: [
36152
36192
  /* @__PURE__ */ jsx120("span", { className: "min-w-0 flex-1 truncate", children: "Task" }),
36153
- /* @__PURE__ */ jsx120("span", { className: "w-12 shrink-0", children: "Start" }),
36154
- /* @__PURE__ */ jsx120("span", { className: "w-12 shrink-0", children: "End" }),
36193
+ /* @__PURE__ */ jsx120("span", { className: cn58(listDayW, "shrink-0"), children: "Start" }),
36194
+ /* @__PURE__ */ jsx120("span", { className: cn58(listDayW, "shrink-0"), children: "End" }),
36155
36195
  /* @__PURE__ */ jsx120("span", { className: "w-14 shrink-0 text-right", children: "Days" })
36156
36196
  ] }) : null }) : null,
36157
36197
  /* @__PURE__ */ jsxs109("div", { className: "relative shrink-0", style: { width, height: 22 }, children: [
@@ -36183,9 +36223,9 @@ function TimelineView({
36183
36223
  const slip = slipDays(baselineOf(b.p.row)?.last ?? null, at.last);
36184
36224
  return /* @__PURE__ */ jsxs109("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: [
36185
36225
  /* @__PURE__ */ jsx120("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) }),
36186
- /* @__PURE__ */ jsx120("span", { className: "w-12 shrink-0 whitespace-nowrap tabular-nums text-muted-foreground", children: shortDay(at.first) }),
36187
- /* @__PURE__ */ jsx120("span", { className: "w-12 shrink-0 whitespace-nowrap tabular-nums text-muted-foreground", children: shortDay(at.last) }),
36188
- /* @__PURE__ */ jsxs109("span", { className: "w-14 shrink-0 text-right tabular-nums", title: slip !== null ? slipWords(slip) : void 0, children: [
36226
+ /* @__PURE__ */ jsx120("span", { className: cn58(listDayW, "shrink-0 whitespace-nowrap tabular-nums text-muted-foreground"), children: taskListDay(at.first, listYear) }),
36227
+ /* @__PURE__ */ jsx120("span", { className: cn58(listDayW, "shrink-0 whitespace-nowrap tabular-nums text-muted-foreground"), children: taskListDay(at.last, listYear) }),
36228
+ /* @__PURE__ */ jsxs109("span", { className: "w-14 shrink-0 whitespace-nowrap text-right tabular-nums", title: slip !== null ? slipWords(slip) : void 0, children: [
36189
36229
  daysBetween(at.first, at.last) + 1,
36190
36230
  "d",
36191
36231
  slip !== null && slip !== 0 ? /* @__PURE__ */ jsx120("span", { className: cn58("ml-1", slip > 0 ? "text-destructive" : "text-emerald-600"), children: slip > 0 ? `+${slip}` : slip }) : null
@@ -39407,7 +39447,7 @@ function useSeedGuard() {
39407
39447
  import { useTable as useTable23 } from "@ai-matrx/records/react";
39408
39448
 
39409
39449
  // src/viewActions.ts
39410
- var VIEW_LOCKED_REASON = "This view is locked. Someone who can edit this table can unlock it.";
39450
+ var VIEW_LOCKED_REASON = "Locked \xB7 ask an editor to unlock";
39411
39451
  var NOOP3 = () => {
39412
39452
  };
39413
39453
  function viewActions(whyNot, host, locked = false, personal = false) {
@@ -39446,6 +39486,9 @@ function copyName(name, taken) {
39446
39486
  if (!taken.includes(next)) return next;
39447
39487
  }
39448
39488
  }
39489
+ function viewActionReasons(actions) {
39490
+ return [...new Set(actions.flatMap((a) => a.disabledReason ? [a.disabledReason] : []))];
39491
+ }
39449
39492
 
39450
39493
  // src/ViewBar.tsx
39451
39494
  import { Fragment as Fragment49, jsx as jsx131, jsxs as jsxs119 } from "react/jsx-runtime";
@@ -39479,6 +39522,7 @@ function ViewBar({ tableId, activeViewId, onActiveView, seed, settings, onViews,
39479
39522
  const claimSeed = useSeedGuard();
39480
39523
  const table = useTable23(tableId);
39481
39524
  const rights = useTableRights(table.data);
39525
+ const tableThere = Boolean(table.data);
39482
39526
  const notify = useRecordsUi().notify;
39483
39527
  const [views, setViews] = useState109(() => initialViews ?? null);
39484
39528
  const [error, setError] = useState109(null);
@@ -39558,7 +39602,7 @@ function ViewBar({ tableId, activeViewId, onActiveView, seed, settings, onViews,
39558
39602
  }
39559
39603
  setUnavailable(false);
39560
39604
  const mine = result.data;
39561
- const missing = (seed ?? []).filter((s) => !seedIsSatisfied(s, mine));
39605
+ const missing = tableThere ? (seed ?? []).filter((s) => !seedIsSatisfied(s, mine)) : [];
39562
39606
  if (missing.length > 0) {
39563
39607
  for (const spec of missing) {
39564
39608
  if (!claimSeed(spec.name)) continue;
@@ -39583,7 +39627,7 @@ function ViewBar({ tableId, activeViewId, onActiveView, seed, settings, onViews,
39583
39627
  setError(null);
39584
39628
  setViews(mine);
39585
39629
  onViews?.(mine);
39586
- }, [client, readViews, tableId, seedKey]);
39630
+ }, [client, readViews, tableId, seedKey, tableThere]);
39587
39631
  useEffect89(() => {
39588
39632
  if (!readOnMount.current) {
39589
39633
  readOnMount.current = true;
@@ -39907,29 +39951,35 @@ function ViewBar({ tableId, activeViewId, onActiveView, seed, settings, onViews,
39907
39951
  /* @__PURE__ */ jsx131(Button80, { size: "sm", type: "submit", className: "h-7", children: "Save" })
39908
39952
  ]
39909
39953
  }
39910
- ) : viewActions(rights.admin || current.personal ? null : rightsReason(rights, "structure") ?? ACTION_NO_ACCESS_REASON, {
39911
- rename: () => setRenaming(current.name),
39912
- duplicate: () => duplicate(current),
39913
- archive: () => archive(current),
39914
- ...rights.admin ? { toggleLock: () => toggleLock(current) } : {},
39915
- // Collaborative -> personal is the creator's or an editor's; personal -> collaborative is the creator's,
39916
- // and a personal view is only ever listed to its creator.
39917
- ...rights.admin || current.personal ? { togglePersonal: () => togglePersonal(current) } : {},
39918
- moveToSection: () => setMovingTo("")
39919
- }, current.presentation?.locked === true, current.personal === true).map((action3) => /* @__PURE__ */ jsx131(
39920
- Tile2,
39921
- {
39922
- variant: "quiet",
39923
- ...action3.destructive ? { danger: true } : {},
39924
- disabled: action3.disabledReason !== void 0,
39925
- "data-view-action": action3.id,
39926
- onClick: () => void action3.run(),
39927
- icon: /* @__PURE__ */ jsx131(ObjectActionGlyph, { name: action3.icon, className: "h-3.5 w-3.5 shrink-0" }),
39928
- title: /* @__PURE__ */ jsx131("span", { title: action3.disabledReason, children: action3.label }),
39929
- ...action3.disabledReason ? { line: /* @__PURE__ */ jsx131("span", { "data-view-action-reason": "", children: action3.disabledReason }) } : {}
39930
- },
39931
- action3.id
39932
- )) }) : null,
39954
+ ) : (() => {
39955
+ const actions = viewActions(rights.admin || current.personal ? null : rightsReason(rights, "structure") ?? ACTION_NO_ACCESS_REASON, {
39956
+ rename: () => setRenaming(current.name),
39957
+ duplicate: () => duplicate(current),
39958
+ archive: () => archive(current),
39959
+ ...rights.admin ? { toggleLock: () => toggleLock(current) } : {},
39960
+ // Collaborative -> personal is the creator's or an editor's; personal -> collaborative is the creator's,
39961
+ // and a personal view is only ever listed to its creator.
39962
+ ...rights.admin || current.personal ? { togglePersonal: () => togglePersonal(current) } : {},
39963
+ moveToSection: () => setMovingTo("")
39964
+ }, current.presentation?.locked === true, current.personal === true);
39965
+ const reasons = viewActionReasons(actions);
39966
+ return /* @__PURE__ */ jsxs119(Fragment49, { children: [
39967
+ reasons.map((reason) => /* @__PURE__ */ jsx131("p", { className: "truncate px-2 py-1 text-xs text-muted-foreground", "data-view-actions-reason": "", title: reason, children: reason }, reason)),
39968
+ actions.map((action3) => /* @__PURE__ */ jsx131(
39969
+ Tile2,
39970
+ {
39971
+ variant: "quiet",
39972
+ ...action3.destructive ? { danger: true } : {},
39973
+ disabled: action3.disabledReason !== void 0,
39974
+ "data-view-action": action3.id,
39975
+ onClick: () => void action3.run(),
39976
+ icon: /* @__PURE__ */ jsx131(ObjectActionGlyph, { name: action3.icon, className: "h-3.5 w-3.5 shrink-0" }),
39977
+ title: /* @__PURE__ */ jsx131("span", { title: action3.disabledReason, children: action3.label })
39978
+ },
39979
+ action3.id
39980
+ ))
39981
+ ] });
39982
+ })() }) : null,
39933
39983
  settings ? /* @__PURE__ */ jsx131("div", { className: "mt-1 border-t border-border pt-1", "data-view-settings": "", children: settings }) : null
39934
39984
  ] })
39935
39985
  ] });