@ai-matrx/records-ui 0.115.65 → 0.115.67

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # Changelog — @ai-matrx/records-ui
2
2
 
3
+ ## 0.115.67
4
+
5
+ Automatic changed-only republish (docs/metadata drift since the last tag — see
6
+ `git diff npm/records-ui/v0.115.66..npm/records-ui/v0.115.67 -- apps/shared/records-ui`).
7
+ No source changes intended and no consumer action required.
8
+
9
+ ## 0.115.66
10
+
11
+ Automatic changed-only republish (docs/metadata drift since the last tag — see
12
+ `git diff npm/records-ui/v0.115.65..npm/records-ui/v0.115.66 -- apps/shared/records-ui`).
13
+ No source changes intended and no consumer action required.
14
+
3
15
  ## 0.115.65
4
16
 
5
17
  Automatic changed-only republish (docs/metadata drift since the last tag — see
package/dist/index.cjs CHANGED
@@ -23831,11 +23831,11 @@ function readTableShape(text) {
23831
23831
  function hasTableShape(text) {
23832
23832
  return readTableShapes(text).length > 0;
23833
23833
  }
23834
- function shapeOfGrid(headers, cells, name = null) {
23834
+ function shapeOfGrid(headers, cells, name = null, from = "table") {
23835
23835
  const labels = uniqueLabels(headers.map((h) => cellWords(String(h ?? ""))));
23836
23836
  const rows = rowsOf(labels, cells.map((r) => r.map((c) => cellWords(String(c ?? "")))));
23837
23837
  if (labels.length === 0) return null;
23838
- const said2 = rows.length === 0 ? `${plural3(labels.length, "column", "columns")} and no rows yet` : `${sizeWords(rows.length, labels.length)} from a table`;
23838
+ const said2 = rows.length === 0 ? `${plural3(labels.length, "column", "columns")} and no rows yet` : `${sizeWords(rows.length, labels.length)} from a ${from}`;
23839
23839
  return { kind: "table", headers: labels, rows, name, at: null, splits: [], said: said2 };
23840
23840
  }
23841
23841
  var MOST_GUESSED_CHOICES = 12;
@@ -28628,6 +28628,34 @@ var import_react167 = require("react");
28628
28628
  var import_react168 = require("@ai-matrx/records/react");
28629
28629
  var import_design_system85 = require("@ai-matrx/design-system");
28630
28630
 
28631
+ // src/unfinishedTable.ts
28632
+ var UNFINISHED_WINDOW_MS = 24 * 60 * 60 * 1e3;
28633
+ async function findUnfinishedTable(client, wantedName, wantedKeys, now = Date.now()) {
28634
+ const name = wantedName.trim().toLowerCase();
28635
+ if (!name) return null;
28636
+ const listed = await client.tableList();
28637
+ if (!listed.ok) return null;
28638
+ const candidates = listed.data.filter((t) => {
28639
+ if (t.is_kernel || t.name.trim().toLowerCase() !== name) return false;
28640
+ const made = Date.parse(t.created_at);
28641
+ return Number.isFinite(made) && now - made <= UNFINISHED_WINDOW_MS;
28642
+ });
28643
+ if (candidates.length === 0) return null;
28644
+ const counted = await client.tableRowCounts({ table_ids: candidates.map((t) => t.id) });
28645
+ if (!counted.ok) return null;
28646
+ const withRows = new Set(counted.data.filter((c) => c.visible_rows > 0).map((c) => c.table_id));
28647
+ const wanted = new Set(wantedKeys);
28648
+ const ordered = [...candidates].sort((a, b) => Date.parse(b.created_at) - Date.parse(a.created_at));
28649
+ for (const t of ordered) {
28650
+ if (withRows.has(t.id)) continue;
28651
+ const read = await client.fields({ table_id: t.id });
28652
+ if (!read.ok) continue;
28653
+ const have = new Set(read.data.map((f) => f.key));
28654
+ if ([...have].every((k) => wanted.has(k))) return { tableId: t.id, haveKeys: have };
28655
+ }
28656
+ return null;
28657
+ }
28658
+
28631
28659
  // src/TablesHome.tsx
28632
28660
  var import_react165 = require("react");
28633
28661
  var import_react166 = require("@ai-matrx/records/react");
@@ -30723,7 +30751,7 @@ var SAVE_TO_TABLE_TYPES = [
30723
30751
  ];
30724
30752
  function shapesOfSource(source) {
30725
30753
  if (source.grid) {
30726
- const s = shapeOfGrid(source.grid.headers, source.grid.rows, source.title ?? null);
30754
+ const s = shapeOfGrid(source.grid.headers, source.grid.rows, source.title ?? null, source.grid.from);
30727
30755
  return s ? [s] : [];
30728
30756
  }
30729
30757
  if (source.value !== void 0) {
@@ -30842,16 +30870,31 @@ function SaveToTable({ source, shapeIndex = 0, onOpenTable, onSaved, onClose, ma
30842
30870
  ...c.guess.type === "datetime" && c.guess.kind ? { kind: c.guess.kind } : {}
30843
30871
  };
30844
30872
  });
30845
- const tableName2 = freeName(name ?? proposedName, (tables.data ?? []).map((t) => t.name));
30846
30873
  setPhase("making");
30847
30874
  try {
30848
- const born = await (0, import_core3.declareTable)(client, { name: tableName2, fields });
30849
- if (!born.ok) {
30850
- setProblem(born.error);
30851
- setPhase("ready");
30852
- return;
30875
+ const earlier = await findUnfinishedTable(client, name ?? proposedName, fields.map((f) => f.key));
30876
+ let tableName2;
30877
+ let newId;
30878
+ if (earlier) {
30879
+ tableName2 = (name ?? proposedName).trim();
30880
+ newId = earlier.tableId;
30881
+ const lacking = fields.filter((f) => !earlier.haveKeys.has(f.key));
30882
+ const added = await (0, import_core3.addFields)(client, newId, lacking);
30883
+ if (!added.ok) {
30884
+ setProblem(added.error);
30885
+ setPhase("ready");
30886
+ return;
30887
+ }
30888
+ } else {
30889
+ tableName2 = freeName(name ?? proposedName, (tables.data ?? []).map((t) => t.name));
30890
+ const born = await (0, import_core3.declareTable)(client, { name: tableName2, fields });
30891
+ if (!born.ok) {
30892
+ setProblem(born.error);
30893
+ setPhase("ready");
30894
+ return;
30895
+ }
30896
+ newId = born.data;
30853
30897
  }
30854
- const newId = born.data;
30855
30898
  if (description.trim()) {
30856
30899
  const described = await (0, writeOnTheWinningVersion_exports.updateOnTheWinningVersion)(
30857
30900
  client,
@@ -52819,6 +52862,13 @@ function phoneTableActions(actions) {
52819
52862
 
52820
52863
  // src/toolbarFit.ts
52821
52864
  var import_react310 = require("react");
52865
+ function widthAtFold(piece, fold) {
52866
+ for (let f = Math.min(fold, (piece.byFold?.length ?? 0) - 1); f >= 0; f -= 1) {
52867
+ const w = piece.byFold?.[f];
52868
+ if (w != null && w > 0) return w;
52869
+ }
52870
+ return piece.full ?? piece.now;
52871
+ }
52822
52872
  var FOLDED_GUESS = { look: 104, chooser: 96, tools: 120 };
52823
52873
  var SLOT_MIN = 36;
52824
52874
  function toolbarFold(input) {
@@ -52831,7 +52881,7 @@ function toolbarFold(input) {
52831
52881
  const widthAt = ({ piece, stage, guess }, fold) => {
52832
52882
  if (piece.now === 0 && piece.full === null) return 0;
52833
52883
  if (fold >= stage) return piece.folded ?? (folded >= stage ? piece.now : Math.min(guess, piece.full ?? piece.now));
52834
- return piece.full ?? piece.now;
52884
+ return widthAtFold(piece, fold);
52835
52885
  };
52836
52886
  const withGap = (width) => width > 0 ? width + gap : 0;
52837
52887
  const shareNow = input.share ? withGap(input.share.now) : 0;
@@ -52874,18 +52924,40 @@ function rowNeeds(row) {
52874
52924
  }
52875
52925
  return { needs: needs + gap * Math.max(0, pieces.length - 1), gap };
52876
52926
  }
52927
+ var STAGE_OF = { look: 1, chooser: 2, tools: 3, share: 4 };
52928
+ function createFitMemory() {
52929
+ const widths = {
52930
+ look: { full: null, folded: null, byFold: [] },
52931
+ chooser: { full: null, folded: null, byFold: [] },
52932
+ tools: { full: null, folded: null, byFold: [] },
52933
+ share: { full: null, folded: null, byFold: [] }
52934
+ };
52935
+ return {
52936
+ /** Record one piece's measured width (`now`; `present`: the piece is on the row) with the row at `current`. */
52937
+ piece(name, current, now, present) {
52938
+ const w = widths[name];
52939
+ const stage = STAGE_OF[name];
52940
+ if (present && now > 0) {
52941
+ if (current >= stage) w.folded = now;
52942
+ else {
52943
+ if (name === "tools") w.byFold[current] = now;
52944
+ if (name !== "tools" || current === 0 || w.full === null) w.full = now;
52945
+ }
52946
+ }
52947
+ if (!present && current < stage) {
52948
+ w.full = null;
52949
+ w.byFold = [];
52950
+ }
52951
+ return { now, full: w.full, folded: w.folded, byFold: w.byFold };
52952
+ }
52953
+ };
52954
+ }
52877
52955
  var useIsoLayoutEffect = typeof window === "undefined" ? import_react310.useEffect : import_react310.useLayoutEffect;
52878
52956
  function useToolbarFit(row) {
52879
52957
  const [fold, setFold] = (0, import_react310.useState)(0);
52880
52958
  useIsoLayoutEffect(() => {
52881
52959
  if (!row) return;
52882
- const widths = {
52883
- look: { full: null, folded: null },
52884
- chooser: { full: null, folded: null },
52885
- tools: { full: null, folded: null },
52886
- share: { full: null, folded: null }
52887
- };
52888
- const stageOf = { look: 1, chooser: 2, tools: 3, share: 4 };
52960
+ const memory = createFitMemory();
52889
52961
  let current = 0;
52890
52962
  let pending = 0;
52891
52963
  let stopped = false;
@@ -52897,13 +52969,7 @@ function useToolbarFit(row) {
52897
52969
  const read = (name) => {
52898
52970
  const el = name === "tools" ? row.querySelector(":scope > [data-toolbar-fit-slot]") : name === "share" ? row.querySelector('[data-toolbar-fit="share"]') : row.querySelector(`:scope > [data-toolbar-fit="${name}"]`);
52899
52971
  const now = !el ? 0 : name === "tools" ? slotNeeds(el) : naturalWidth(el);
52900
- const w = widths[name];
52901
- if (el && now > 0) {
52902
- if (current >= stageOf[name]) w.folded = now;
52903
- else w.full = now;
52904
- }
52905
- if (!el && current < stageOf[name]) w.full = null;
52906
- return { now, full: w.full, folded: w.folded };
52972
+ return memory.piece(name, current, now, !!el);
52907
52973
  };
52908
52974
  const look = read("look");
52909
52975
  const chooser = read("chooser");