@ai-matrx/records-ui 0.115.43 → 0.115.44

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
@@ -5169,6 +5169,29 @@ function columnNameTakenBy(name, others) {
5169
5169
  function columnNameTakenLine(taken, noun = "column") {
5170
5170
  return `Another ${noun} is already called \u201C${taken}\u201D`;
5171
5171
  }
5172
+ var COLUMN_NAME_MAX = 80;
5173
+ var KEPT_NAMES = {
5174
+ id: "Reference number",
5175
+ created_at: "Date added",
5176
+ updated_at: "Last updated",
5177
+ deleted_at: "Date removed",
5178
+ created_by: "Added by",
5179
+ updated_by: "Changed by",
5180
+ organization_id: "Organization",
5181
+ table_id: "Table",
5182
+ version: "Version number",
5183
+ data: "Details",
5184
+ metadata: "More details",
5185
+ data_class: "Category"
5186
+ };
5187
+ var asKept = (name) => said(name).toLowerCase().replace(/[^a-z0-9\s_]/g, "").replace(/\s+/g, "_").replace(/^_+|_+$/g, "").replace(/_+/g, "_");
5188
+ function columnNameProblemLine(name, noun = "column") {
5189
+ const wanted = said(name);
5190
+ if (wanted === "") return null;
5191
+ if (wanted.length > COLUMN_NAME_MAX) return `${wanted.length} characters; a ${noun} name takes up to ${COLUMN_NAME_MAX}`;
5192
+ const instead = KEPT_NAMES[asKept(wanted)];
5193
+ return instead ? `\u201C${wanted}\u201D is kept by every table. Try \u201C${instead}\u201D` : null;
5194
+ }
5172
5195
 
5173
5196
  // src/FieldEditor.tsx
5174
5197
  import { useEffect as useEffect19, useMemo as useMemo12, useRef as useRef15, useState as useState27 } from "react";
@@ -5250,6 +5273,7 @@ function FormulaTextEditor({
5250
5273
  onChecked,
5251
5274
  columns,
5252
5275
  sampleRecordId,
5276
+ purpose,
5253
5277
  className
5254
5278
  }) {
5255
5279
  const client = useRecordsClient7();
@@ -5325,7 +5349,8 @@ function FormulaTextEditor({
5325
5349
  columns,
5326
5350
  mistake: parsed && !parsed.ok ? parsed.error : error ? refusalSentence(error) : null,
5327
5351
  functions: FORMULA_FUNCTION_NAMES,
5328
- onFormula: onText
5352
+ onFormula: onText,
5353
+ ...purpose ? { purpose } : {}
5329
5354
  }) }) : null
5330
5355
  ] }),
5331
5356
  /* @__PURE__ */ jsx18(
@@ -7891,11 +7916,11 @@ function startingChoiceColors(field2, words2) {
7891
7916
  function choiceDisplayPatch(field2, rows) {
7892
7917
  const held = displayFormatOf(field2);
7893
7918
  const before = choiceLooksOf(field2);
7894
- const changed = rows.some((row) => {
7919
+ const changed2 = rows.some((row) => {
7895
7920
  const was = before.find((l) => choiceWord(l.value) === choiceWord(row.value))?.color ?? null;
7896
7921
  return was !== row.color;
7897
7922
  });
7898
- if (!changed) return null;
7923
+ if (!changed2) return null;
7899
7924
  const heldChoices = Array.isArray(held?.options["choices"]) ? held.options["choices"] : [];
7900
7925
  const choices = rows.map((row) => {
7901
7926
  const kept = heldChoices.find((c) => typeof c["value"] === "string" && choiceWord(c["value"]) === choiceWord(row.value)) ?? {};
@@ -7965,7 +7990,7 @@ function guessStatusGroup(words2) {
7965
7990
  if (["inprogress", "doing", "started", "active", "inreview", "review"].includes(w)) return "in_progress";
7966
7991
  return "todo";
7967
7992
  }
7968
- function statusGroupRows(field2, rows, keyOfId, changed) {
7993
+ function statusGroupRows(field2, rows, keyOfId, changed2) {
7969
7994
  const out = [];
7970
7995
  for (const r of rows) {
7971
7996
  const words2 = r.words.trim();
@@ -7973,7 +7998,7 @@ function statusGroupRows(field2, rows, keyOfId, changed) {
7973
7998
  const ref = r.id ?? words2;
7974
7999
  const key = r.id ? keyOfId[r.id] : void 0;
7975
8000
  const held = field2 && key ? statusGroupOf2(field2, key) : void 0;
7976
- out.push({ ref, words: words2, group: changed[ref] ?? held ?? guessStatusGroup(words2) });
8001
+ out.push({ ref, words: words2, group: changed2[ref] ?? held ?? guessStatusGroup(words2) });
7977
8002
  }
7978
8003
  return out;
7979
8004
  }
@@ -8667,6 +8692,12 @@ var KINDS_WITH_A_DEFAULT = /* @__PURE__ */ new Set([
8667
8692
  function takesADefault(field2) {
8668
8693
  return KINDS_WITH_A_DEFAULT.has(String(pickableTypeOf(field2) ?? editorKindFor(field2)));
8669
8694
  }
8695
+ function newColumnTakesADefault(type) {
8696
+ return KINDS_WITH_A_DEFAULT.has(type);
8697
+ }
8698
+ function newColumnDefaultGoes(type) {
8699
+ return type === "select" || type === "multi_select" || type === "status" ? "right-after" : "in-the-create";
8700
+ }
8670
8701
  function defaultToKeep(value) {
8671
8702
  if (value === void 0 || value === null) return null;
8672
8703
  if (typeof value === "string") {
@@ -8857,6 +8888,10 @@ function FieldEditor(props) {
8857
8888
  const sourcesFor = (kind) => kind === "rollup" || kind === "count" ? totalSources : relations;
8858
8889
  const choice = fieldTypeChoice(type);
8859
8890
  const editing = Boolean(field2);
8891
+ useEffect19(() => {
8892
+ if (!editing) setStartsWith(null);
8893
+ }, [type, editing]);
8894
+ const newDefault = !editing && !onEntity && newColumnTakesADefault(type) ? defaultToKeep(startsWith) : null;
8860
8895
  const farFieldsOfLink = useFields2(field2 && sourceKindOf(field2) === "link" && !onEntity ? field2.relation_target ?? null : null);
8861
8896
  const farTable = useTable(field2 && sourceKindOf(field2) === "link" && !onEntity ? field2.relation_target ?? null : null);
8862
8897
  const linkReaders = useMemo12(
@@ -8877,6 +8912,7 @@ function FieldEditor(props) {
8877
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;
8878
8913
  const noun = onEntity ? "field" : "column";
8879
8914
  const nameTaken = columnNameTakenBy(label, others.map(fieldName));
8915
+ const nameLine = nameTaken ? columnNameTakenLine(nameTaken, noun) : columnNameProblemLine(label, noun);
8880
8916
  const listsChoices = type === "select" || type === "multi_select" || type === "status";
8881
8917
  const buttonMissing = type === "button" && buttonSettings.do ? buttonNeeds(buttonSettings) : null;
8882
8918
  const missing = buttonMissing ?? (editing ? formulaMissing ?? (listsChoices ? whatTheChoiceListIsMissing(choiceList) : null) : formulaMissing ?? (listsChoices ? whatTheChoiceListIsMissing(newChoices) : null) ?? (type === "formula" && formulaWritten ? null : whatIsMissing(
@@ -9016,6 +9052,7 @@ function FieldEditor(props) {
9016
9052
  ...type === "rollup" ? { via, agg, ...agg === "count" ? {} : { of }, ...rollupFilter ? { filter: rollupFilter } : {} } : {},
9017
9053
  ...type === "formula" ? formulaWritten ? { formula_text: formulaText.trim() } : { expr: formulaExpression(formulaOp, formulaFields, formulaSeparator) } : {}
9018
9054
  };
9055
+ if (newDefault !== null && newColumnDefaultGoes(type) === "in-the-create") spec.default = newDefault;
9019
9056
  const written = onEntity ? await entityMutation.declare({ token: entityToken, spec }) : await tableMutation.declare({ table_id: tableId, spec });
9020
9057
  if (written === null) return;
9021
9058
  const landed = onEntity ? await client.entityFields({ token: entityToken }) : await client.fields({ table_id: tableId });
@@ -9024,6 +9061,14 @@ function FieldEditor(props) {
9024
9061
  return;
9025
9062
  }
9026
9063
  setNotLanded(false);
9064
+ if (newDefault !== null && newColumnDefaultGoes(type) === "right-after") {
9065
+ const defaulted = await client.fieldUpdate({ field_id: written, patch: { default: newDefault } });
9066
+ if (!defaulted.ok) {
9067
+ tableShapeChanged4(tableId);
9068
+ setBackfillError(defaulted.error);
9069
+ return;
9070
+ }
9071
+ }
9027
9072
  if (type === "autonumber") {
9028
9073
  const numbered = await client.autonumberBackfill({ field_id: written });
9029
9074
  if (!numbered.ok) {
@@ -9077,10 +9122,19 @@ function FieldEditor(props) {
9077
9122
  if (to?.textContent === "Cancel") return;
9078
9123
  setAttempted(true);
9079
9124
  },
9080
- ...nameTaken ? { "aria-invalid": true, "aria-describedby": "field-editor-name-taken" } : {}
9125
+ ...nameLine ? { "aria-invalid": true, "aria-describedby": "field-editor-name-taken" } : {}
9081
9126
  }
9082
9127
  ),
9083
- nameTaken ? /* @__PURE__ */ jsx38("span", { id: "field-editor-name-taken", "data-field-editor-name-taken": "", className: "truncate text-[11px] text-destructive", title: columnNameTakenLine(nameTaken, noun), children: columnNameTakenLine(nameTaken, noun) }) : null
9128
+ nameLine ? /* @__PURE__ */ jsx38(
9129
+ "span",
9130
+ {
9131
+ id: "field-editor-name-taken",
9132
+ ...nameTaken ? { "data-field-editor-name-taken": "" } : { "data-field-editor-name-problem": "" },
9133
+ className: "truncate text-[11px] text-destructive",
9134
+ title: nameLine,
9135
+ children: nameLine
9136
+ }
9137
+ ) : null
9084
9138
  ] }),
9085
9139
  /* @__PURE__ */ jsxs34("div", { className: "flex flex-col gap-1", children: [
9086
9140
  /* @__PURE__ */ jsx38(Label8, { className: "text-xs", children: "What it holds" }),
@@ -9292,6 +9346,7 @@ function FieldEditor(props) {
9292
9346
  "A value that is not one of the choices is added to them"
9293
9347
  ] }) : null
9294
9348
  ] }),
9349
+ !editing && !onEntity && newColumnTakesADefault(type) ? /* @__PURE__ */ jsx38(NewColumnDefault, { type, choices: options, value: startsWith, onChange: setStartsWith }) : null,
9295
9350
  editing && field2 && takesADefault(liveField ?? field2) ? /* @__PURE__ */ jsxs34("div", { className: "flex flex-col gap-1", "data-records-field-default": "", children: [
9296
9351
  /* @__PURE__ */ jsx38(Label8, { htmlFor: "records-field-default", className: "text-xs", children: DEFAULT_LABEL }),
9297
9352
  /* @__PURE__ */ jsx38(
@@ -9850,6 +9905,35 @@ function entityReferenceKindsOf(field2) {
9850
9905
  const raw = (field2?.config ?? {})["allowed_types"];
9851
9906
  return Array.isArray(raw) ? raw.filter((t) => typeof t === "string") : [];
9852
9907
  }
9908
+ function NewColumnDefault({
9909
+ type,
9910
+ choices,
9911
+ value,
9912
+ onChange
9913
+ }) {
9914
+ const none = "__none__";
9915
+ return /* @__PURE__ */ jsxs34("div", { className: "flex flex-col gap-1", "data-records-field-default": "", "data-records-new-field-default": "", children: [
9916
+ /* @__PURE__ */ jsx38(Label8, { htmlFor: "records-new-field-default", className: "text-xs", children: DEFAULT_LABEL }),
9917
+ type === "checkbox" ? /* @__PURE__ */ jsxs34("label", { className: "flex items-center gap-2", children: [
9918
+ /* @__PURE__ */ jsx38(Checkbox4, { id: "records-new-field-default", "aria-label": DEFAULT_LABEL, checked: value === true, onCheckedChange: (on) => onChange(on === true ? true : null) }),
9919
+ /* @__PURE__ */ jsx38("span", { children: "Ticked" })
9920
+ ] }) : type === "select" || type === "multi_select" || type === "status" ? /* @__PURE__ */ jsxs34(Select6, { value: typeof value === "string" && choices.includes(value) ? value : none, onValueChange: (v) => onChange(v === none ? null : v), children: [
9921
+ /* @__PURE__ */ jsx38(SelectTrigger6, { id: "records-new-field-default", size: "sm", "aria-label": DEFAULT_LABEL, children: /* @__PURE__ */ jsx38(SelectValue6, {}) }),
9922
+ /* @__PURE__ */ jsxs34(SelectContent6, { children: [
9923
+ /* @__PURE__ */ jsx38(SelectItem6, { value: none, children: "Nothing" }),
9924
+ choices.map((c) => /* @__PURE__ */ jsx38(SelectItem6, { value: c, children: c }, c))
9925
+ ] })
9926
+ ] }) : /* @__PURE__ */ jsx38(
9927
+ BasicInput9,
9928
+ {
9929
+ id: "records-new-field-default",
9930
+ value: typeof value === "string" ? value : value === null || value === void 0 ? "" : String(value),
9931
+ placeholder: "Nothing",
9932
+ onChange: (e) => onChange(e.target.value)
9933
+ }
9934
+ )
9935
+ ] });
9936
+ }
9853
9937
 
9854
9938
  // src/buttonCell.tsx
9855
9939
  import { Fragment as Fragment11, jsx as jsx39, jsxs as jsxs35 } from "react/jsx-runtime";
@@ -10604,6 +10688,17 @@ function FieldControl({ field: field2, value, onChange, disabled, id, autoOpen,
10604
10688
  case "json":
10605
10689
  return /* @__PURE__ */ jsx43(JsonControl, { field: field2, value, onChange, disabled, id: inputId });
10606
10690
  case "long_text":
10691
+ if (host.textBox) {
10692
+ return host.textBox({
10693
+ value: value === null || value === void 0 ? "" : String(value),
10694
+ onChange: (next) => onChange(next === "" ? null : next),
10695
+ label: fieldName(field2),
10696
+ rows: 3,
10697
+ where: asForm ? "form" : "cell",
10698
+ id: inputId,
10699
+ disabled
10700
+ });
10701
+ }
10607
10702
  return /* @__PURE__ */ jsx43(
10608
10703
  BasicTextarea4,
10609
10704
  {
@@ -12568,6 +12663,9 @@ function opensAsAList(field2, takesFiles = false) {
12568
12663
  function asksAboutAChoice(draft) {
12569
12664
  return isTypedDraft(draft) && draft.judged !== null && "ask" in draft.judged;
12570
12665
  }
12666
+ function opensInsideAMenu(to) {
12667
+ return to instanceof Element && to.closest("[data-radix-popper-content-wrapper]") !== null;
12668
+ }
12571
12669
  function takesANewline(field2) {
12572
12670
  const kind = editorKindFor(field2);
12573
12671
  return kind === "long_text" || kind === "json";
@@ -12629,6 +12727,7 @@ function OpenCell({
12629
12727
  const blur = blurCommits ? {
12630
12728
  onBlur: (event) => {
12631
12729
  if (event.currentTarget.contains(event.relatedTarget)) return;
12730
+ if (opensInsideAMenu(event.relatedTarget)) return;
12632
12731
  once(() => onCommit(null, "blur"));
12633
12732
  }
12634
12733
  } : {};
@@ -13066,6 +13165,44 @@ function EmptyRecords({ words: words2 }) {
13066
13165
  );
13067
13166
  }
13068
13167
 
13168
+ // src/tableCleanAsk.ts
13169
+ import { useSyncExternalStore as useSyncExternalStore3 } from "react";
13170
+ var hearers = /* @__PURE__ */ new Map();
13171
+ var watchers = /* @__PURE__ */ new Set();
13172
+ var changed = () => {
13173
+ for (const w of watchers) w();
13174
+ };
13175
+ function hearTableCleanAsks(tableId, open) {
13176
+ const set = hearers.get(tableId) ?? /* @__PURE__ */ new Set();
13177
+ set.add(open);
13178
+ hearers.set(tableId, set);
13179
+ changed();
13180
+ return () => {
13181
+ set.delete(open);
13182
+ if (set.size === 0) hearers.delete(tableId);
13183
+ changed();
13184
+ };
13185
+ }
13186
+ function askToCleanTable(tableId) {
13187
+ const set = hearers.get(tableId);
13188
+ if (!set || set.size === 0) return false;
13189
+ [...set][set.size - 1]();
13190
+ return true;
13191
+ }
13192
+ function tableCanBeCleaned(tableId) {
13193
+ return (hearers.get(tableId)?.size ?? 0) > 0;
13194
+ }
13195
+ function useTableCanBeCleaned(tableId) {
13196
+ return useSyncExternalStore3(
13197
+ (onChange) => {
13198
+ watchers.add(onChange);
13199
+ return () => void watchers.delete(onChange);
13200
+ },
13201
+ () => tableCanBeCleaned(tableId),
13202
+ () => false
13203
+ );
13204
+ }
13205
+
13069
13206
  // src/gridControls.tsx
13070
13207
  import { copyText as writeClipboardText, readText as readClipboardText } from "@ai-matrx/kit/clipboard";
13071
13208
  import { onRecordChanged } from "@ai-matrx/records/core";
@@ -13795,10 +13932,10 @@ function TablePicker({ dataSource, value, onChange, disabled, tables }) {
13795
13932
  const pickerOptions = options.map((t) => {
13796
13933
  const twin = (sameName.get(`${t.organization_id}|${t.table_name.trim().toLowerCase()}`) ?? 0) > 1;
13797
13934
  const row = t;
13798
- const second = [
13799
- row.created_by_name ? `by ${row.created_by_name}` : null,
13800
- row.updated_at ? `changed ${new Date(row.updated_at).toLocaleDateString()}` : null
13801
- ].filter(Boolean).join(" \xB7 ");
13935
+ const secondOf = (r) => [r.created_by_name ? `by ${r.created_by_name}` : null, r.updated_at ? `changed ${new Date(r.updated_at).toLocaleDateString()}` : null].filter(Boolean).join(" \xB7 ");
13936
+ const base2 = secondOf(row);
13937
+ const alike = options.filter((o) => o.organization_id === t.organization_id && o.table_name.trim().toLowerCase() === t.table_name.trim().toLowerCase() && secondOf(o) === base2).length;
13938
+ const second = alike > 1 ? [base2, `#${t.table_id.slice(0, 4)}`].filter(Boolean).join(" \xB7 ") : base2;
13802
13939
  return {
13803
13940
  value: t.table_id,
13804
13941
  // The organization hint already tells two same-named tables apart across organizations.
@@ -15535,6 +15672,8 @@ function ActionForm({
15535
15672
  const previewRow = rows.find((r) => r.id === previewId) ?? rows[0] ?? null;
15536
15673
  const candidate = actionOf(draft, original);
15537
15674
  const complete = draft.steps.every((s) => s.field !== "");
15675
+ const [formulaChecks, setFormulaChecks] = useState46({});
15676
+ const formulaWrong = draft.steps.some((s, i) => s.set === "compute" && formulaChecks[i] === false);
15538
15677
  useEffect33(() => {
15539
15678
  if (seed) setDraft(draftOf(seed.action));
15540
15679
  }, [seed]);
@@ -15543,6 +15682,7 @@ function ActionForm({
15543
15682
  ...draft.kind === "agent" && !draft.prompt.trim() ? ["An agent action needs what the agent does with the row."] : [],
15544
15683
  ...draft.kind === "update" && draft.steps.length === 0 ? ["The action changes nothing yet."] : [],
15545
15684
  ...complete ? [] : ["Every change needs its column before the action can be saved."],
15685
+ ...formulaWrong ? ["A formula has a mistake."] : [],
15546
15686
  ...error ? [refusalSentence(error)] : []
15547
15687
  ];
15548
15688
  if (live) live.current = { action: candidate, problems };
@@ -15658,15 +15798,25 @@ function ActionForm({
15658
15798
  "aria-label": `Value for change ${index + 1}`,
15659
15799
  onChange: (e) => setStep(index, { value: e.target.value })
15660
15800
  }
15661
- ) : step2.set === "compute" ? /* @__PURE__ */ jsx57(
15662
- BasicInput12,
15663
- {
15664
- className: "h-7 w-56",
15665
- value: step2.formula,
15666
- "aria-label": `Formula for change ${index + 1}`,
15667
- placeholder: "{Visit fee} - {Deposit taken}",
15668
- onChange: (e) => setStep(index, { formula: e.target.value })
15669
- }
15801
+ ) : step2.set === "compute" ? (
15802
+ // THE ONE FORMULA BOX (Sheet parity): the store checks it as it is typed, and the host's
15803
+ // "Help with this…" (`formulaHelp`) sees this table's columns and puts its answer back.
15804
+ /* @__PURE__ */ jsx57(
15805
+ FormulaTextEditor,
15806
+ {
15807
+ className: "basis-full",
15808
+ tableId,
15809
+ text: step2.formula,
15810
+ onText: (formula) => setStep(index, { formula }),
15811
+ onChecked: (ok) => setFormulaChecks((held) => ({ ...held, [index]: ok })),
15812
+ columns: fields.filter((f) => f.id !== step2.field),
15813
+ sampleRecordId: previewRow?.id ?? null,
15814
+ purpose: `A row action step: sets ${(() => {
15815
+ const target = fields.find((f) => f.id === step2.field);
15816
+ return target ? fieldName(target) : "a column";
15817
+ })()} when the button is pressed.`
15818
+ }
15819
+ )
15670
15820
  ) : null,
15671
15821
  /* @__PURE__ */ jsx57(
15672
15822
  Button29,
@@ -16419,7 +16569,7 @@ function WholeTextDialog({
16419
16569
  const whole = useWholeText(target?.pointer ?? null);
16420
16570
  const [draft, setDraft] = useState50(null);
16421
16571
  const [cleanNote, setCleanNote] = useState50(null);
16422
- const renderText = useRecordsUi().renderText;
16572
+ const { renderText, textBox } = useRecordsUi();
16423
16573
  const [reading, setReading] = useState50(false);
16424
16574
  const startingText = target === null ? null : target.pointer ? whole.state === "ready" ? whole.text : null : typeof target.value === "string" ? target.value : target.value === null || target.value === void 0 ? "" : String(target.value);
16425
16575
  useEffect37(() => {
@@ -16450,7 +16600,28 @@ function WholeTextDialog({
16450
16600
  /* @__PURE__ */ jsx62(Button34, { size: "sm", variant: reading ? "ghost" : "secondary", role: "tab", "aria-selected": !reading, onClick: () => setReading(false), "data-records-whole-text-mode": "words", children: mayWrite ? "Edit" : "Words" }),
16451
16601
  /* @__PURE__ */ jsx62(Button34, { size: "sm", variant: reading ? "secondary" : "ghost", role: "tab", "aria-selected": reading, onClick: () => setReading(true), "data-records-whole-text-mode": "preview", children: "Preview" })
16452
16602
  ] }) : null,
16453
- ready && reading && renderText ? /* @__PURE__ */ jsx62("div", { className: "max-h-[60vh] min-h-[8rem] overflow-auto rounded-md border px-3 py-2 text-sm", "data-records-whole-text-preview": "", children: draft ? renderText(draft, "cell") : /* @__PURE__ */ jsx62("span", { className: "text-muted-foreground", children: "\u2014" }) }) : ready ? /* @__PURE__ */ jsx62(
16603
+ ready && reading && renderText ? /* @__PURE__ */ jsx62("div", { className: "max-h-[60vh] min-h-[8rem] overflow-auto rounded-md border px-3 py-2 text-sm", "data-records-whole-text-preview": "", children: draft ? renderText(draft, "cell") : /* @__PURE__ */ jsx62("span", { className: "text-muted-foreground", children: "\u2014" }) }) : ready && textBox ? (
16604
+ // THE HOST'S TEXT BOX (`textBox`): the same words, with its "…" menu (Clean up, Help with
16605
+ // this…, Copy, Save, Share). What its menu puts in the box is unsaved until Save.
16606
+ /* @__PURE__ */ jsx62("div", { "data-records-whole-text-box": "", children: textBox({
16607
+ value: draft ?? "",
16608
+ onChange: (next) => {
16609
+ setDraft(next);
16610
+ setCleanNote(null);
16611
+ },
16612
+ label: title,
16613
+ rows: 16,
16614
+ where: "whole-text",
16615
+ autoFocus: true,
16616
+ readOnly: !mayWrite,
16617
+ onKeyDown: (e) => {
16618
+ if (e.key === "Enter" && (e.metaKey || e.ctrlKey)) {
16619
+ e.preventDefault();
16620
+ save();
16621
+ }
16622
+ }
16623
+ }) })
16624
+ ) : ready ? /* @__PURE__ */ jsx62(
16454
16625
  BasicTextarea6,
16455
16626
  {
16456
16627
  autoFocus: true,
@@ -16763,6 +16934,8 @@ function useMergedGridControls(args) {
16763
16934
  const tableVersion = (0, recordVersions_exports.useTableVersion)(client, tableId, table);
16764
16935
  const mutation = useFieldMutation2();
16765
16936
  const [dialog, setDialog] = useState51(null);
16937
+ const canClean = Boolean(enabled && args.bulkApply);
16938
+ useEffect38(() => canClean ? hearTableCleanAsks(tableId, () => setDialog({ kind: "cleanTable" })) : void 0, [canClean, tableId]);
16766
16939
  const lastColumnDialog = useRef26(null);
16767
16940
  const insertEpoch = useRef26(0);
16768
16941
  if (dialog?.kind === "settings" || dialog?.kind === "insert") {
@@ -18231,7 +18404,7 @@ function CustomRecordForm({
18231
18404
  const t = setTimeout(() => globalThis.document?.getElementById(`field-${first.id}`)?.focus(), 0);
18232
18405
  return () => clearTimeout(t);
18233
18406
  }, [focusFirstRequired, recordId, fields.data]);
18234
- const [changed, setChanged] = useState54({});
18407
+ const [changed2, setChanged] = useState54({});
18235
18408
  const [answered, setAnswered] = useState54(null);
18236
18409
  const formRows = useMemo26(
18237
18410
  () => existing.data ? [{ id: existing.data.record_id, document: existing.data.document, level: "", hidden: {} }] : [],
@@ -18243,7 +18416,7 @@ function CustomRecordForm({
18243
18416
  if (recordId && !pinned.current) pinned.current = versions.seen(recordId);
18244
18417
  };
18245
18418
  const changedRef = useRef28({});
18246
- changedRef.current = changed;
18419
+ changedRef.current = changed2;
18247
18420
  useEffect40(() => {
18248
18421
  const document3 = existing.data?.document;
18249
18422
  if (!document3) return;
@@ -18270,7 +18443,7 @@ function CustomRecordForm({
18270
18443
  if (existing.error) return /* @__PURE__ */ jsx66(RefusalNotice, { error: existing.error, className });
18271
18444
  const storeSaid = said2.error && said2.error !== answered ? said2.error : null;
18272
18445
  const fieldProblems = predicted.filter((p) => p.field_key);
18273
- const problemsShown = (key) => touched || changed[key] ? fieldProblems.filter((p) => p.field_key === key) : [];
18446
+ const problemsShown = (key) => touched || changed2[key] ? fieldProblems.filter((p) => p.field_key === key) : [];
18274
18447
  const storeRefusalIsOnAField = storeSaid !== null && !said2.conflict && storeSaid.code === "refused_by_rule" && (fields.data ?? []).some((f) => problemsShown(f.key).length > 0);
18275
18448
  const stored = existing.data?.document;
18276
18449
  const focusField = (field2) => {
@@ -18303,11 +18476,11 @@ function CustomRecordForm({
18303
18476
  setAnswered(null);
18304
18477
  if (recordId) {
18305
18478
  const version = await (pinned.current ?? versions.seen(recordId));
18306
- if (Object.keys(changed).length === 0) {
18479
+ if (Object.keys(changed2).length === 0) {
18307
18480
  onSaved?.(recordId);
18308
18481
  return;
18309
18482
  }
18310
- const patch = Object.fromEntries(Object.entries(document2).filter(([key]) => changed[key]));
18483
+ const patch = Object.fromEntries(Object.entries(document2).filter(([key]) => changed2[key]));
18311
18484
  setEdit({ saving: true, error: null, conflict: null });
18312
18485
  const answered2 = await (0, writeOnTheWinningVersion_exports.updateOnTheWinningVersion)(client, recordId, patch, version, stored ?? {});
18313
18486
  setEdit({
@@ -20089,7 +20262,7 @@ function withTypeMark(field2, header) {
20089
20262
  }
20090
20263
 
20091
20264
  // src/ReverseColumns.tsx
20092
- import { useCallback as useCallback20, useEffect as useEffect45, useMemo as useMemo30, useRef as useRef30, useState as useState59, useSyncExternalStore as useSyncExternalStore3 } from "react";
20265
+ import { useCallback as useCallback20, useEffect as useEffect45, useMemo as useMemo30, useRef as useRef30, useState as useState59, useSyncExternalStore as useSyncExternalStore4 } from "react";
20093
20266
  import { isReverseField } from "@ai-matrx/records";
20094
20267
 
20095
20268
  // src/groupReads.ts
@@ -20228,8 +20401,8 @@ function ReverseCell({ held, column, rowId, tableId }) {
20228
20401
  );
20229
20402
  const readAnswer = () => held.answers?.[column.key]?.[rowId];
20230
20403
  const readReading = () => held.reading;
20231
- const answer = useSyncExternalStore3(subscribe, readAnswer, readAnswer);
20232
- const reading = useSyncExternalStore3(subscribe, readReading, readReading);
20404
+ const answer = useSyncExternalStore4(subscribe, readAnswer, readAnswer);
20405
+ const reading = useSyncExternalStore4(subscribe, readReading, readReading);
20233
20406
  const chips = /* @__PURE__ */ jsx70(ReverseLinkChips, { column, answer, loading: reading, clamp: { tableId, recordId: rowId } });
20234
20407
  if (column.read_only) return chips;
20235
20408
  return /* @__PURE__ */ jsx70(ReverseLinksEditCell, { tableId, recordId: rowId, column, chips });
@@ -20923,7 +21096,7 @@ function titleRepeats(rows, header) {
20923
21096
  }
20924
21097
  return { distinct: seen.size, filled };
20925
21098
  }
20926
- function sameRecordLikely(rows, header) {
21099
+ function sameRecordLikely(rows, header, notIdentity) {
20927
21100
  const groups = /* @__PURE__ */ new Map();
20928
21101
  for (const r of rows) {
20929
21102
  const key = relationNameKey(String(r[header] ?? ""));
@@ -20937,6 +21110,7 @@ function sameRecordLikely(rows, header) {
20937
21110
  const headers = /* @__PURE__ */ new Set();
20938
21111
  for (const r of rows) for (const h of Object.keys(r)) if (h !== header) headers.add(h);
20939
21112
  for (const h of headers) {
21113
+ if (notIdentity?.has(h)) continue;
20940
21114
  let agrees = true;
20941
21115
  for (const g of repeating) {
20942
21116
  const values = new Set(g.map((r) => String(r[h] ?? "").trim()).filter((v) => v !== ""));
@@ -21255,9 +21429,17 @@ function ImportWizard({ tableId, source, onDone, onWrote, autoRun, className })
21255
21429
  }, [rows, plan, leftOut]);
21256
21430
  const titleStats = useMemo31(() => titleHeader ? titleRepeats(distinctRows, titleHeader) : null, [distinctRows, titleHeader]);
21257
21431
  const titleRepeating = Boolean(titleStats && titleStats.filled > 0 && titleStats.distinct < titleStats.filled);
21432
+ const notIdentity = useMemo31(() => {
21433
+ const out = /* @__PURE__ */ new Set();
21434
+ for (const c of plan?.columns ?? []) {
21435
+ const k = importKindOfPlan(c.type);
21436
+ if (k === "currency" || k === "date" || k === "checkbox" || looksLikeDates(distinctRows, c.header)) out.add(c.header);
21437
+ }
21438
+ return out;
21439
+ }, [plan, distinctRows]);
21258
21440
  const combineDefault = useMemo31(
21259
- () => titleRepeating && titleHeader && sameRecordLikely(distinctRows, titleHeader) ? "combine" : "each",
21260
- [distinctRows, titleHeader, titleRepeating]
21441
+ () => titleRepeating && titleHeader && sameRecordLikely(distinctRows, titleHeader, notIdentity) ? "combine" : "each",
21442
+ [distinctRows, titleHeader, titleRepeating, notIdentity]
21261
21443
  );
21262
21444
  const combining = titleRepeating && (combine ?? combineDefault) === "combine";
21263
21445
  const combined = useMemo31(() => combining && titleHeader ? combineRows(rows, titleHeader) : null, [combining, rows, titleHeader]);
@@ -23467,7 +23649,7 @@ function useGroupLabel(fields, groupKey) {
23467
23649
  }
23468
23650
 
23469
23651
  // src/gridUndo.tsx
23470
- import { useCallback as useCallback22, useEffect as useEffect49, useLayoutEffect as useLayoutEffect4, useMemo as useMemo34, useRef as useRef32, useState as useState65, useSyncExternalStore as useSyncExternalStore4 } from "react";
23652
+ import { useCallback as useCallback22, useEffect as useEffect49, useLayoutEffect as useLayoutEffect4, useMemo as useMemo34, useRef as useRef32, useState as useState65, useSyncExternalStore as useSyncExternalStore5 } from "react";
23471
23653
  import { tableShapeChanged as tableShapeChanged6, useRecordsClient as useRecordsClient38 } from "@ai-matrx/records/react";
23472
23654
  import { announceRecordChanged as announceRecordChanged2 } from "@ai-matrx/records/core";
23473
23655
  import { Button as Button46 } from "@ai-matrx/design-system";
@@ -23632,7 +23814,7 @@ function useUndoSource(undo) {
23632
23814
  return source;
23633
23815
  }
23634
23816
  function UndoRedoLive({ source }) {
23635
- const face = useSyncExternalStore4(source.subscribe, source.face, source.face);
23817
+ const face = useSyncExternalStore5(source.subscribe, source.face, source.face);
23636
23818
  return /* @__PURE__ */ jsx79(UndoRedoPair, { face, onUndo: source.undo, onRedo: source.redo });
23637
23819
  }
23638
23820
  function UndoRedoPair({ face, onUndo, onRedo }) {
@@ -27736,6 +27918,7 @@ import {
27736
27918
  Textarea as Textarea3,
27737
27919
  cn as cn42
27738
27920
  } from "@ai-matrx/design-system";
27921
+ import { Tile } from "@ai-matrx/design-system/controls";
27739
27922
 
27740
27923
  // src/newTableColumns.ts
27741
27924
  import { RESOLVABLE_FIELD_TYPE_WORDS } from "@ai-matrx/records/templates";
@@ -28171,24 +28354,15 @@ function NewTableStart({
28171
28354
  "or",
28172
28355
  /* @__PURE__ */ jsx89("span", { className: "h-px flex-1 bg-border" })
28173
28356
  ] }),
28174
- /* @__PURE__ */ jsxs79(
28175
- "button",
28357
+ /* @__PURE__ */ jsx89(
28358
+ Tile,
28176
28359
  {
28177
- type: "button",
28178
28360
  "data-new-table-import": "",
28179
28361
  onClick: () => fileInput.current?.click(),
28180
- className: cn42(
28181
- "group flex w-full items-center gap-3 rounded-lg border border-dashed px-4 py-4 text-left transition-colors",
28182
- "hover:border-primary hover:bg-primary/5 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",
28183
- dragging ? "border-primary bg-primary/5" : "border-border"
28184
- ),
28185
- children: [
28186
- /* @__PURE__ */ jsx89("span", { className: "flex h-10 w-10 shrink-0 items-center justify-center rounded-md bg-primary/10 text-primary", children: /* @__PURE__ */ jsx89(Icon, { d: ICON.upload }) }),
28187
- /* @__PURE__ */ jsxs79("span", { className: "flex min-w-0 flex-col", children: [
28188
- /* @__PURE__ */ jsx89("span", { className: "text-sm font-medium", children: "Import a file" }),
28189
- /* @__PURE__ */ jsx89("span", { className: "text-xs text-muted-foreground", children: "CSV, Excel or TSV \xB7 drop it here" })
28190
- ] })
28191
- ]
28362
+ icon: /* @__PURE__ */ jsx89(Icon, { d: ICON.upload }),
28363
+ title: "Import a file",
28364
+ line: "CSV, Excel or TSV \xB7 drop it here",
28365
+ ...dragging ? { selected: true } : {}
28192
28366
  }
28193
28367
  ),
28194
28368
  /* @__PURE__ */ jsx89(
@@ -28366,15 +28540,7 @@ function ChoiceCard({
28366
28540
  onClick,
28367
28541
  ...rest
28368
28542
  }) {
28369
- const inner2 = /* @__PURE__ */ jsxs79(Fragment30, { children: [
28370
- /* @__PURE__ */ jsx89("span", { className: "flex h-8 w-8 shrink-0 items-center justify-center rounded-md bg-muted text-muted-foreground group-hover:text-foreground", children: /* @__PURE__ */ jsx89(Icon, { d: icon }) }),
28371
- /* @__PURE__ */ jsxs79("span", { className: "flex min-w-0 flex-col", children: [
28372
- /* @__PURE__ */ jsx89("span", { className: "truncate text-sm font-medium", children: title }),
28373
- /* @__PURE__ */ jsx89("span", { className: "truncate text-xs text-muted-foreground", children: words2 })
28374
- ] })
28375
- ] });
28376
- const cls = "group flex min-h-[3.5rem] w-full items-center gap-3 rounded-lg border px-3 py-2.5 text-left transition-colors hover:bg-accent focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring";
28377
- return href ? /* @__PURE__ */ jsx89("a", { href, className: cls, ...rest, children: inner2 }) : /* @__PURE__ */ jsx89("button", { type: "button", className: cls, onClick, ...rest, children: inner2 });
28543
+ return href ? /* @__PURE__ */ jsx89(Tile, { asChild: true, icon: /* @__PURE__ */ jsx89(Icon, { d: icon }), title, line: words2, ...rest, children: /* @__PURE__ */ jsx89("a", { href }) }) : /* @__PURE__ */ jsx89(Tile, { icon: /* @__PURE__ */ jsx89(Icon, { d: icon }), title, line: words2, onClick, ...rest });
28378
28544
  }
28379
28545
  var ICON = {
28380
28546
  upload: "M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4M17 8l-5-5-5 5M12 3v12",
@@ -29038,7 +29204,8 @@ var GLYPHS = {
29038
29204
  "split": [["path", { "d": "M16 3h5v5" }], ["path", { "d": "M8 3H3v5" }], ["path", { "d": "M12 22v-8.3a4 4 0 0 0-1.172-2.872L3 3" }], ["path", { "d": "m15 9 6-6" }]],
29039
29205
  "arrow-up-from-line": [["path", { "d": "m18 9-6-6-6 6" }], ["path", { "d": "M12 3v14" }], ["path", { "d": "M5 21h14" }]],
29040
29206
  "lock": [["rect", { "width": "18", "height": "11", "x": "3", "y": "11", "rx": "2", "ry": "2" }], ["path", { "d": "M7 11V7a5 5 0 0 1 10 0v4" }]],
29041
- "lock-open": [["rect", { "width": "18", "height": "11", "x": "3", "y": "11", "rx": "2", "ry": "2" }], ["path", { "d": "M7 11V7a5 5 0 0 1 9.9-1" }]]
29207
+ "lock-open": [["rect", { "width": "18", "height": "11", "x": "3", "y": "11", "rx": "2", "ry": "2" }], ["path", { "d": "M7 11V7a5 5 0 0 1 9.9-1" }]],
29208
+ "eraser": [["path", { "d": "m7 21-4.3-4.3c-1-1-1-2.5 0-3.4l9.6-9.6c1-1 2.5-1 3.4 0l5.6 5.6c1 1 1 2.5 0 3.4L13 21" }], ["path", { "d": "M22 21H7" }], ["path", { "d": "m5 11 9 9" }]]
29042
29209
  };
29043
29210
  function ObjectActionGlyph({ name, ...props }) {
29044
29211
  return /* @__PURE__ */ jsx93(
@@ -31026,8 +31193,8 @@ function TableAccessLevel({ tableId, fields }) {
31026
31193
  facts.set_by === "platform" ? /* @__PURE__ */ jsx104("span", { className: "text-muted-foreground", children: "Set by the platform" }) : null
31027
31194
  ] });
31028
31195
  }
31029
- const changed = draft !== facts.level || draft === "confidential" && (picked.length !== facts.readers.length || picked.some((f) => !facts.readers.some((r) => r.field === f)));
31030
- const ready = changed && reason.trim().length >= 3 && !busy;
31196
+ const changed2 = draft !== facts.level || draft === "confidential" && (picked.length !== facts.readers.length || picked.some((f) => !facts.readers.some((r) => r.field === f)));
31197
+ const ready = changed2 && reason.trim().length >= 3 && !busy;
31031
31198
  const apply = async () => {
31032
31199
  setBusy(true);
31033
31200
  setRefused(null);
@@ -31079,7 +31246,7 @@ function TableAccessLevel({ tableId, fields }) {
31079
31246
  );
31080
31247
  }) })
31081
31248
  ] }) : null,
31082
- changed ? /* @__PURE__ */ jsxs93(Fragment35, { children: [
31249
+ changed2 ? /* @__PURE__ */ jsxs93(Fragment35, { children: [
31083
31250
  /* @__PURE__ */ jsx104(
31084
31251
  Textarea5,
31085
31252
  {
@@ -33264,14 +33431,14 @@ function PipelineBoard({
33264
33431
  return;
33265
33432
  }
33266
33433
  const notes = /* @__PURE__ */ new Map();
33267
- const changed = [];
33434
+ const changed2 = [];
33268
33435
  for (const r of res.data.results) {
33269
33436
  const note = batchNote(r, to);
33270
33437
  if (note) notes.set(r.record_id, note);
33271
33438
  if (r.verdict === "moved" && typeof r.version === "number") versions.wrote(r.record_id, r.version);
33272
- if (r.verdict === "changed_since_loaded") changed.push(r.record_id);
33439
+ if (r.verdict === "changed_since_loaded") changed2.push(r.record_id);
33273
33440
  }
33274
- if (changed.length > 0) versions.refresh(changed);
33441
+ if (changed2.length > 0) versions.refresh(changed2);
33275
33442
  setBatch(notes);
33276
33443
  setBatchSaid(batchSentence(res.data.moved, res.data.needs_approval, res.data.not_moved, label));
33277
33444
  clearSelection();
@@ -39116,6 +39283,7 @@ function ArchivedPortals({
39116
39283
  import { useCallback as useCallback43, useEffect as useEffect89, useRef as useRef50, useState as useState109 } from "react";
39117
39284
  import { useRecordsClient as useRecordsClient74 } from "@ai-matrx/records/react";
39118
39285
  import { Badge as Badge15, Button as Button80, Input as Input7, Popover as Popover16, PopoverContent as PopoverContent16, PopoverTrigger as PopoverTrigger16, Skeleton as Skeleton18, cn as cn65 } from "@ai-matrx/design-system";
39286
+ import { Button as ControlButton, Switch as Switch5, Tile as Tile2 } from "@ai-matrx/design-system/controls";
39119
39287
  import { DndContext, PointerSensor, closestCenter, useDroppable, useSensor, useSensors } from "@dnd-kit/core";
39120
39288
  import { SortableContext, useSortable, verticalListSortingStrategy } from "@dnd-kit/sortable";
39121
39289
  import { CSS as CSS2 } from "@dnd-kit/utilities";
@@ -39510,10 +39678,10 @@ function ViewBar({ tableId, activeViewId, onActiveView, seed, settings, onViews,
39510
39678
  }
39511
39679
  ) : /* @__PURE__ */ jsxs119("div", { className: "group flex min-h-7 items-center gap-1 px-2 text-[11px] font-medium uppercase tracking-wide text-muted-foreground", children: [
39512
39680
  /* @__PURE__ */ jsxs119(
39513
- "button",
39681
+ ControlButton,
39514
39682
  {
39515
- type: "button",
39516
- className: "flex min-w-0 flex-1 items-center gap-1 text-left",
39683
+ variant: "quiet",
39684
+ className: "min-w-0 flex-1 justify-start gap-1 px-0",
39517
39685
  "aria-expanded": !shut.includes(group.name),
39518
39686
  "data-view-section-toggle": "",
39519
39687
  onClick: () => toggleShut(group.name),
@@ -39525,33 +39693,28 @@ function ViewBar({ tableId, activeViewId, onActiveView, seed, settings, onViews,
39525
39693
  }
39526
39694
  ),
39527
39695
  rights.admin ? /* @__PURE__ */ jsxs119(Fragment49, { children: [
39528
- /* @__PURE__ */ jsx131("button", { type: "button", className: "shrink-0 normal-case hover:text-foreground", "data-view-section-rename": "", onClick: () => setRenamingSection({ from: group.name, draft: group.name }), children: "Rename" }),
39529
- /* @__PURE__ */ jsx131("button", { type: "button", className: "shrink-0 normal-case hover:text-destructive", "data-view-section-delete": "", title: "The views stay; they leave the section", onClick: () => void renameSection(group.name, null), children: "Delete" })
39696
+ /* @__PURE__ */ jsx131(ControlButton, { variant: "quiet", className: "shrink-0 normal-case", "data-view-section-rename": "", onClick: () => setRenamingSection({ from: group.name, draft: group.name }), children: "Rename" }),
39697
+ /* @__PURE__ */ jsx131(ControlButton, { variant: "danger", className: "shrink-0 normal-case", "data-view-section-delete": "", title: "The views stay; they leave the section", onClick: () => void renameSection(group.name, null), children: "Delete" })
39530
39698
  ] }) : null
39531
39699
  ] }) : null,
39532
- group.name !== null && shut.includes(group.name) && !group.views.some((v) => v.id === active) ? null : group.views.map((view) => /* @__PURE__ */ jsx131(SortableRow, { id: view.id, disabled: !(rights.admin || view.personal) || view.presentation?.locked === true, children: /* @__PURE__ */ jsxs119(
39533
- "button",
39700
+ group.name !== null && shut.includes(group.name) && !group.views.some((v) => v.id === active) ? null : group.views.map((view) => /* @__PURE__ */ jsx131(SortableRow, { id: view.id, disabled: !(rights.admin || view.personal) || view.presentation?.locked === true, children: /* @__PURE__ */ jsx131(
39701
+ Tile2,
39534
39702
  {
39535
- type: "button",
39536
- "aria-pressed": view.id === active,
39537
- className: cn65(
39538
- "flex min-h-8 w-full items-center gap-2 rounded-sm px-2 text-left text-xs text-popover-foreground hover:bg-accent hover:text-accent-foreground",
39539
- group.name !== null && "pl-4",
39540
- view.id === active && "font-medium"
39541
- ),
39703
+ variant: "quiet",
39704
+ selected: view.id === active,
39705
+ className: cn65(group.name !== null && "pl-4"),
39542
39706
  onClick: () => {
39543
39707
  if (justDragged.current) return;
39544
39708
  setActive(view.id);
39545
39709
  onActiveView?.(view);
39546
39710
  setOpen(false);
39547
39711
  },
39548
- title: view.ruleId ? "Membership is this view's Rule" : "The whole table",
39549
- children: [
39550
- /* @__PURE__ */ jsx131("span", { className: "min-w-0 flex-1 truncate", children: view.name }),
39712
+ title: /* @__PURE__ */ jsx131("span", { title: view.ruleId ? "Membership is this view's Rule" : "The whole table", children: view.name }),
39713
+ end: /* @__PURE__ */ jsxs119(Fragment49, { children: [
39551
39714
  view.presentation?.locked === true ? /* @__PURE__ */ jsx131(Badge15, { variant: "neutral", className: "shrink-0 px-1.5 py-0 text-[10px]", "data-view-locked": "", title: VIEW_LOCKED_REASON, children: "Locked" }) : null,
39552
39715
  view.personal ? /* @__PURE__ */ jsx131(Badge15, { variant: "neutral", className: "shrink-0 px-1.5 py-0 text-[10px]", "data-view-personal": "", title: "Only you see this view", children: "Personal" }) : null,
39553
39716
  view.isDefault ? /* @__PURE__ */ jsx131(Badge15, { variant: "neutral", className: "shrink-0 px-1.5 py-0 text-[10px]", "data-view-default": "", children: "Default" }) : null
39554
- ]
39717
+ ] })
39555
39718
  }
39556
39719
  ) }, view.id))
39557
39720
  ] })
@@ -39582,7 +39745,7 @@ function ViewBar({ tableId, activeViewId, onActiveView, seed, settings, onViews,
39582
39745
  /* @__PURE__ */ jsx131(Button80, { size: "sm", type: "submit", className: "h-7", children: "Save" })
39583
39746
  ] }),
39584
39747
  rights.admin ? /* @__PURE__ */ jsxs119("label", { className: "flex items-center gap-1.5 text-[11px] text-muted-foreground", children: [
39585
- /* @__PURE__ */ jsx131("input", { type: "checkbox", checked: namingPersonal, onChange: (e) => setNamingPersonal(e.target.checked), "data-view-new-personal": "" }),
39748
+ /* @__PURE__ */ jsx131(Switch5, { checked: namingPersonal, onCheckedChange: setNamingPersonal, "data-view-new-personal": "" }),
39586
39749
  "Personal (only you see it)"
39587
39750
  ] }) : null
39588
39751
  ]
@@ -39594,8 +39757,8 @@ function ViewBar({ tableId, activeViewId, onActiveView, seed, settings, onViews,
39594
39757
  current.name,
39595
39758
  "\u201D to"
39596
39759
  ] }),
39597
- sectionNames(views).map((name) => /* @__PURE__ */ jsx131("button", { type: "button", disabled: current.section === name, className: "flex min-h-8 w-full items-center rounded-sm px-2 text-left text-xs hover:bg-accent disabled:opacity-60", onClick: () => void moveToSection(current, name), children: name }, name)),
39598
- current.section ? /* @__PURE__ */ jsx131("button", { type: "button", className: "flex min-h-8 w-full items-center rounded-sm px-2 text-left text-xs hover:bg-accent", "data-view-section-none": "", onClick: () => void moveToSection(current, null), children: "No section" }) : null,
39760
+ sectionNames(views).map((name) => /* @__PURE__ */ jsx131(Tile2, { variant: "quiet", disabled: current.section === name, title: name, onClick: () => void moveToSection(current, name) }, name)),
39761
+ current.section ? /* @__PURE__ */ jsx131(Tile2, { variant: "quiet", "data-view-section-none": "", title: "No section", onClick: () => void moveToSection(current, null) }) : null,
39599
39762
  /* @__PURE__ */ jsxs119(
39600
39763
  "form",
39601
39764
  {
@@ -39649,25 +39812,17 @@ function ViewBar({ tableId, activeViewId, onActiveView, seed, settings, onViews,
39649
39812
  // and a personal view is only ever listed to its creator.
39650
39813
  ...rights.admin || current.personal ? { togglePersonal: () => togglePersonal(current) } : {},
39651
39814
  moveToSection: () => setMovingTo("")
39652
- }, current.presentation?.locked === true, current.personal === true).map((action3) => /* @__PURE__ */ jsxs119(
39653
- "button",
39815
+ }, current.presentation?.locked === true, current.personal === true).map((action3) => /* @__PURE__ */ jsx131(
39816
+ Tile2,
39654
39817
  {
39655
- type: "button",
39818
+ variant: "quiet",
39819
+ ...action3.destructive ? { danger: true } : {},
39656
39820
  disabled: action3.disabledReason !== void 0,
39657
39821
  "data-view-action": action3.id,
39658
- title: action3.disabledReason,
39659
39822
  onClick: () => void action3.run(),
39660
- className: cn65(
39661
- "flex min-h-8 w-full items-center gap-2 rounded-sm px-2 text-left text-xs text-popover-foreground hover:bg-accent hover:text-accent-foreground disabled:pointer-events-none disabled:opacity-60",
39662
- action3.destructive && "text-destructive hover:text-destructive"
39663
- ),
39664
- children: [
39665
- /* @__PURE__ */ jsx131(ObjectActionGlyph, { name: action3.icon, className: "h-3.5 w-3.5 shrink-0" }),
39666
- /* @__PURE__ */ jsxs119("span", { className: "flex min-w-0 flex-1 flex-col", children: [
39667
- /* @__PURE__ */ jsx131("span", { className: "truncate", children: action3.label }),
39668
- action3.disabledReason ? /* @__PURE__ */ jsx131("span", { className: "truncate text-[11px] text-muted-foreground", "data-view-action-reason": "", children: action3.disabledReason }) : null
39669
- ] })
39670
- ]
39823
+ icon: /* @__PURE__ */ jsx131(ObjectActionGlyph, { name: action3.icon, className: "h-3.5 w-3.5 shrink-0" }),
39824
+ title: /* @__PURE__ */ jsx131("span", { title: action3.disabledReason, children: action3.label }),
39825
+ ...action3.disabledReason ? { line: /* @__PURE__ */ jsx131("span", { "data-view-action-reason": "", children: action3.disabledReason }) } : {}
39671
39826
  },
39672
39827
  action3.id
39673
39828
  )) }) : null,
@@ -40658,12 +40813,12 @@ function keepHolds(ids, hold) {
40658
40813
  }
40659
40814
  function forgetHolds(ids) {
40660
40815
  const next = readHolds();
40661
- let changed = false;
40816
+ let changed2 = false;
40662
40817
  for (const id of ids) if (id in next) {
40663
40818
  delete next[id];
40664
- changed = true;
40819
+ changed2 = true;
40665
40820
  }
40666
- if (changed) writeHolds(next);
40821
+ if (changed2) writeHolds(next);
40667
40822
  }
40668
40823
  function scrollWithinList(list, el) {
40669
40824
  const box = list.getBoundingClientRect();
@@ -41449,6 +41604,7 @@ import { useEffect as useEffect93, useMemo as useMemo65, useState as useState113
41449
41604
  import { readTypedDate as readTypedDate3, typedDateText as typedDateText3 } from "@ai-matrx/records";
41450
41605
  import { useRecordsClient as useRecordsClient78 } from "@ai-matrx/records/react";
41451
41606
  import { Button as Button84, Skeleton as Skeleton21, cn as cn69 } from "@ai-matrx/design-system";
41607
+ import { Button as ControlButton2, Field as ControlField } from "@ai-matrx/design-system/controls";
41452
41608
  import { humanizeIdentifier as humanizeIdentifier16 } from "@ai-matrx/kit/text-case";
41453
41609
  import { Fragment as Fragment52, jsx as jsx135, jsxs as jsxs123 } from "react/jsx-runtime";
41454
41610
  function endOfDayIso(day2, zone2 = getPersonTimeZone()) {
@@ -41489,7 +41645,7 @@ function AsOfControl({ value, onChange, className }) {
41489
41645
  }
41490
41646
  return /* @__PURE__ */ jsxs123("div", { className: cn69("flex h-6 items-center gap-1", className), "data-records-as-of": "", children: [
41491
41647
  /* @__PURE__ */ jsx135(
41492
- "input",
41648
+ ControlField,
41493
41649
  {
41494
41650
  type: "text",
41495
41651
  inputMode: "numeric",
@@ -41498,7 +41654,7 @@ function AsOfControl({ value, onChange, className }) {
41498
41654
  "aria-label": "As of",
41499
41655
  "aria-invalid": bad,
41500
41656
  "data-records-as-of-box": "",
41501
- className: cn69("h-6 w-24 rounded border bg-background px-1.5 text-[11px]", bad && "border-destructive"),
41657
+ className: "w-24",
41502
41658
  onChange: (e) => setText(e.target.value),
41503
41659
  onBlur: (e) => commit(e.target.value),
41504
41660
  onKeyDown: (e) => {
@@ -41519,12 +41675,12 @@ function AsOfControl({ value, onChange, className }) {
41519
41675
  }
41520
41676
  ),
41521
41677
  /* @__PURE__ */ jsx135("div", { role: "group", "aria-label": "Clock", className: "flex overflow-hidden rounded border text-[11px]", children: ["recorded", "world"].map((which) => /* @__PURE__ */ jsx135(
41522
- "button",
41678
+ ControlButton2,
41523
41679
  {
41524
- type: "button",
41525
- "aria-pressed": clock === which,
41680
+ variant: clock === which ? "primary" : "quiet",
41681
+ pressed: clock === which,
41526
41682
  "data-records-as-of-clock": which,
41527
- className: cn69("h-6 whitespace-nowrap px-1.5", clock === which ? "bg-primary text-primary-foreground" : "hover:bg-muted"),
41683
+ className: "whitespace-nowrap",
41528
41684
  onClick: () => value && onChange({ day: value.day, clock: which }),
41529
41685
  disabled: !value,
41530
41686
  children: which === "recorded" ? "Said then" : "True then"
@@ -41716,7 +41872,7 @@ function HistoryPanel({ tableId, recordId, onAskAboutField, className }) {
41716
41872
  const listRef = useRef53(null);
41717
41873
  const [asOf, setAsOf] = useState115(null);
41718
41874
  const today = useRecord4(recordId, false, { tableId });
41719
- const changed = useRecordChangeRevision(recordId);
41875
+ const changed2 = useRecordChangeRevision(recordId);
41720
41876
  const shape = useMigrationLog(recordId);
41721
41877
  const load = useCallback47(async () => {
41722
41878
  const answered = await client.recordHistory({ record_id: recordId });
@@ -41726,7 +41882,7 @@ function HistoryPanel({ tableId, recordId, onAskAboutField, className }) {
41726
41882
  }
41727
41883
  setError(null);
41728
41884
  setEntries(answered.data);
41729
- }, [client, recordId, changed]);
41885
+ }, [client, recordId, changed2]);
41730
41886
  useEffect95(() => {
41731
41887
  void load();
41732
41888
  }, [load]);
@@ -44435,7 +44591,7 @@ function DigestScheduler({
44435
44591
  import { useCallback as useCallback54, useEffect as useEffect104, useState as useState124 } from "react";
44436
44592
  import { useRecordsClient as useRecordsClient88 } from "@ai-matrx/records/react";
44437
44593
  import { hasQuietHours as hasQuietHours2 } from "@ai-matrx/records";
44438
- import { Badge as Badge23, Button as Button95, Skeleton as Skeleton30, Switch as Switch5, cn as cn82 } from "@ai-matrx/design-system";
44594
+ import { Badge as Badge23, Button as Button95, Skeleton as Skeleton30, Switch as Switch6, cn as cn82 } from "@ai-matrx/design-system";
44439
44595
 
44440
44596
  // src/WebhooksPanel.tsx
44441
44597
  import { useCallback as useCallback53, useEffect as useEffect103, useState as useState123 } from "react";
@@ -44778,7 +44934,7 @@ function SubscriptionsPanel({ tableId, activeRuleId, className }) {
44778
44934
  ] })
44779
44935
  ] }),
44780
44936
  subscription.i_may_mute ? /* @__PURE__ */ jsx148(
44781
- Switch5,
44937
+ Switch6,
44782
44938
  {
44783
44939
  checked: !subscription.muted,
44784
44940
  disabled: busy === subscription.rule_id,
@@ -51948,7 +52104,7 @@ function TableReferenceDialog({
51948
52104
  import { formatCount as formatCount7 } from "@ai-matrx/kit/format";
51949
52105
  import { useState as useState147 } from "react";
51950
52106
  import { tableShapeChanged as tableShapeChanged13, useRecordsClient as useRecordsClient105 } from "@ai-matrx/records/react";
51951
- import { Button as Button117, Dialog as Dialog20, DialogContent as DialogContent20, DialogFooter as DialogFooter13, DialogHeader as DialogHeader20, DialogTitle as DialogTitle20, ErrorBox as ErrorBox8, Input as Input11, Switch as Switch6 } from "@ai-matrx/design-system";
52107
+ import { Button as Button117, Dialog as Dialog20, DialogContent as DialogContent20, DialogFooter as DialogFooter13, DialogHeader as DialogHeader20, DialogTitle as DialogTitle20, ErrorBox as ErrorBox8, Input as Input11, Switch as Switch7 } from "@ai-matrx/design-system";
51952
52108
  import { Fragment as Fragment69, jsx as jsx172, jsxs as jsxs160 } from "react/jsx-runtime";
51953
52109
  function copyNameFor(name) {
51954
52110
  return `${name.trim() || "Table"} (copy)`;
@@ -52034,7 +52190,7 @@ function TableDuplicateDialog({ tableId, name, open, onOpenChange, onDuplicated
52034
52190
  ),
52035
52191
  /* @__PURE__ */ jsxs160("label", { className: "flex items-center justify-between gap-2", children: [
52036
52192
  /* @__PURE__ */ jsx172("span", { children: "Copy its records" }),
52037
- /* @__PURE__ */ jsx172(Switch6, { checked: withRecords, disabled: copying, onCheckedChange: setWithRecords, "aria-label": "Copy its records" })
52193
+ /* @__PURE__ */ jsx172(Switch7, { checked: withRecords, disabled: copying, onCheckedChange: setWithRecords, "aria-label": "Copy its records" })
52038
52194
  ] }),
52039
52195
  phase.kind === "copying" ? /* @__PURE__ */ jsx172("p", { className: "text-xs text-muted-foreground", "data-table-duplicate-progress": "", children: phase.progress ? duplicateProgressWords(phase.progress) : "Starting the copy\u2026" }) : null,
52040
52196
  phase.kind === "refused" ? /* @__PURE__ */ jsx172(ErrorBox8, { children: phase.sentence }) : null,
@@ -52075,7 +52231,7 @@ function ViewFilter({ tableId, view, onApply, className }) {
52075
52231
  );
52076
52232
  if (!view) return null;
52077
52233
  const count = conditionCount(saved);
52078
- const changed = JSON.stringify(draft) !== savedKey;
52234
+ const changed2 = JSON.stringify(draft) !== savedKey;
52079
52235
  return (
52080
52236
  // THE BUILDER FLOATS OVER THE TABLE (STABLE-TABLES; Notion's filter popover): drawn inside the
52081
52237
  // toolbar row it grew the row and pushed the whole table down (0.13 + 0.13 layout shift).
@@ -52121,7 +52277,7 @@ function ViewFilter({ tableId, view, onApply, className }) {
52121
52277
  }
52122
52278
  ) }),
52123
52279
  view.ruleId ? null : /* @__PURE__ */ jsxs161("div", { className: "flex items-center gap-1", children: [
52124
- changed ? /* @__PURE__ */ jsx173(
52280
+ changed2 ? /* @__PURE__ */ jsx173(
52125
52281
  Button118,
52126
52282
  {
52127
52283
  size: "sm",
@@ -52241,7 +52397,7 @@ function phoneTableActions(actions) {
52241
52397
  }
52242
52398
 
52243
52399
  // src/toolbarFit.ts
52244
- import { useEffect as useEffect122, useState as useState149 } from "react";
52400
+ import { useEffect as useEffect122, useLayoutEffect as useLayoutEffect6, useState as useState149 } from "react";
52245
52401
  var FOLDED_GUESS = { look: 104, chooser: 96, tools: 120 };
52246
52402
  var SLOT_MIN = 36;
52247
52403
  function toolbarFold(input) {
@@ -52297,9 +52453,10 @@ function rowNeeds(row) {
52297
52453
  }
52298
52454
  return { needs: needs + gap * Math.max(0, pieces.length - 1), gap };
52299
52455
  }
52456
+ var useIsoLayoutEffect = typeof window === "undefined" ? useEffect122 : useLayoutEffect6;
52300
52457
  function useToolbarFit(row) {
52301
52458
  const [fold, setFold] = useState149(0);
52302
- useEffect122(() => {
52459
+ useIsoLayoutEffect(() => {
52303
52460
  if (!row) return;
52304
52461
  const widths = {
52305
52462
  look: { full: null, folded: null },
@@ -52361,6 +52518,7 @@ function useToolbarFit(row) {
52361
52518
  content.observe(row, { childList: true, subtree: true, characterData: true, attributes: true, attributeFilter: ["class", "style"] });
52362
52519
  watchSizes();
52363
52520
  if (typeof window !== "undefined") window.addEventListener("resize", schedule);
52521
+ measure();
52364
52522
  schedule();
52365
52523
  return () => {
52366
52524
  stopped = true;
@@ -52814,6 +52972,7 @@ function TablePage({
52814
52972
  }
52815
52973
  }, [pageArchive, client, tableId, table.data, recordsUi.notify]);
52816
52974
  const [moveAsked, setMoveAsked] = useState150(0);
52975
+ const canCleanTable = useTableCanBeCleaned(tableId);
52817
52976
  const [duplicateOpen, setDuplicateOpen] = useState150(false);
52818
52977
  const [referenceOpen, setReferenceOpen] = useState150(false);
52819
52978
  const [subscribeOpen, setSubscribeOpen] = useState150(false);
@@ -53151,6 +53310,17 @@ function TablePage({
53151
53310
  ...mayDo.known && !mayDo.structure ? { disabledReason: "Needs Admin access" } : {},
53152
53311
  run: () => void toggleSubItems()
53153
53312
  },
53313
+ // CLEAN THE WHOLE TABLE (the Sheet's toolbar cleanup): the grid's one review, from the ⋯ too.
53314
+ ...canCleanTable ? [
53315
+ {
53316
+ id: "table-clean",
53317
+ label: CLEAN_TABLE_LABEL,
53318
+ icon: "eraser",
53319
+ group: "manage",
53320
+ ...mayDo.known && !mayDo.write ? { disabledReason: "Needs Editor access" } : {},
53321
+ run: () => void window.setTimeout(() => askToCleanTable(tableId), 0)
53322
+ }
53323
+ ] : [],
53154
53324
  // BREAK DOWN: the grid grouped by one column, through the drill's own question.
53155
53325
  breakDownAction({
53156
53326
  ...mayDo.known && !mayDo.read ? { disabledReason: "Needs Viewer access" } : !view ? { disabledReason: NO_VIEW_REASON } : allFields.data && allFields.data.length === 0 ? { disabledReason: NO_DIMENSION_REASON } : {},