@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/dist/index.d.cts CHANGED
@@ -2425,7 +2425,8 @@ interface SaveToTableSource {
2425
2425
  /** Rows a host already holds (a rendered table's headers and cells). */
2426
2426
  grid?: {
2427
2427
  headers: string[];
2428
- rows: string[][];
2428
+ rows: string[][]; /** What the rows came out of ("table", "sheet"); the offered line says "from a <it>". Default "table". */
2429
+ from?: string | undefined;
2429
2430
  } | undefined;
2430
2431
  /** What it came from, in words — the name a new table is offered, and the import's source name. */
2431
2432
  title?: string | null | undefined;
package/dist/index.d.ts CHANGED
@@ -2425,7 +2425,8 @@ interface SaveToTableSource {
2425
2425
  /** Rows a host already holds (a rendered table's headers and cells). */
2426
2426
  grid?: {
2427
2427
  headers: string[];
2428
- rows: string[][];
2428
+ rows: string[][]; /** What the rows came out of ("table", "sheet"); the offered line says "from a <it>". Default "table". */
2429
+ from?: string | undefined;
2429
2430
  } | undefined;
2430
2431
  /** What it came from, in words — the name a new table is offered, and the import's source name. */
2431
2432
  title?: string | null | undefined;
package/dist/index.js CHANGED
@@ -23538,11 +23538,11 @@ function readTableShape(text) {
23538
23538
  function hasTableShape(text) {
23539
23539
  return readTableShapes(text).length > 0;
23540
23540
  }
23541
- function shapeOfGrid(headers, cells, name = null) {
23541
+ function shapeOfGrid(headers, cells, name = null, from = "table") {
23542
23542
  const labels = uniqueLabels(headers.map((h) => cellWords(String(h ?? ""))));
23543
23543
  const rows = rowsOf(labels, cells.map((r) => r.map((c) => cellWords(String(c ?? "")))));
23544
23544
  if (labels.length === 0) return null;
23545
- const said2 = rows.length === 0 ? `${plural3(labels.length, "column", "columns")} and no rows yet` : `${sizeWords(rows.length, labels.length)} from a table`;
23545
+ const said2 = rows.length === 0 ? `${plural3(labels.length, "column", "columns")} and no rows yet` : `${sizeWords(rows.length, labels.length)} from a ${from}`;
23546
23546
  return { kind: "table", headers: labels, rows, name, at: null, splits: [], said: said2 };
23547
23547
  }
23548
23548
  var MOST_GUESSED_CHOICES = 12;
@@ -28399,6 +28399,34 @@ import {
28399
28399
  cn as cn48
28400
28400
  } from "@ai-matrx/design-system";
28401
28401
 
28402
+ // src/unfinishedTable.ts
28403
+ var UNFINISHED_WINDOW_MS = 24 * 60 * 60 * 1e3;
28404
+ async function findUnfinishedTable(client, wantedName, wantedKeys, now = Date.now()) {
28405
+ const name = wantedName.trim().toLowerCase();
28406
+ if (!name) return null;
28407
+ const listed = await client.tableList();
28408
+ if (!listed.ok) return null;
28409
+ const candidates = listed.data.filter((t) => {
28410
+ if (t.is_kernel || t.name.trim().toLowerCase() !== name) return false;
28411
+ const made = Date.parse(t.created_at);
28412
+ return Number.isFinite(made) && now - made <= UNFINISHED_WINDOW_MS;
28413
+ });
28414
+ if (candidates.length === 0) return null;
28415
+ const counted = await client.tableRowCounts({ table_ids: candidates.map((t) => t.id) });
28416
+ if (!counted.ok) return null;
28417
+ const withRows = new Set(counted.data.filter((c) => c.visible_rows > 0).map((c) => c.table_id));
28418
+ const wanted = new Set(wantedKeys);
28419
+ const ordered = [...candidates].sort((a, b) => Date.parse(b.created_at) - Date.parse(a.created_at));
28420
+ for (const t of ordered) {
28421
+ if (withRows.has(t.id)) continue;
28422
+ const read = await client.fields({ table_id: t.id });
28423
+ if (!read.ok) continue;
28424
+ const have = new Set(read.data.map((f) => f.key));
28425
+ if ([...have].every((k) => wanted.has(k))) return { tableId: t.id, haveKeys: have };
28426
+ }
28427
+ return null;
28428
+ }
28429
+
28402
28430
  // src/TablesHome.tsx
28403
28431
  import { useEffect as useEffect62, useState as useState79 } from "react";
28404
28432
  import { useRecordsClient as useRecordsClient52, useTables as useTables2 } from "@ai-matrx/records/react";
@@ -30516,7 +30544,7 @@ var SAVE_TO_TABLE_TYPES = [
30516
30544
  ];
30517
30545
  function shapesOfSource(source) {
30518
30546
  if (source.grid) {
30519
- const s = shapeOfGrid(source.grid.headers, source.grid.rows, source.title ?? null);
30547
+ const s = shapeOfGrid(source.grid.headers, source.grid.rows, source.title ?? null, source.grid.from);
30520
30548
  return s ? [s] : [];
30521
30549
  }
30522
30550
  if (source.value !== void 0) {
@@ -30635,16 +30663,31 @@ function SaveToTable({ source, shapeIndex = 0, onOpenTable, onSaved, onClose, ma
30635
30663
  ...c.guess.type === "datetime" && c.guess.kind ? { kind: c.guess.kind } : {}
30636
30664
  };
30637
30665
  });
30638
- const tableName2 = freeName(name ?? proposedName, (tables.data ?? []).map((t) => t.name));
30639
30666
  setPhase("making");
30640
30667
  try {
30641
- const born = await declareTable(client, { name: tableName2, fields });
30642
- if (!born.ok) {
30643
- setProblem(born.error);
30644
- setPhase("ready");
30645
- return;
30668
+ const earlier = await findUnfinishedTable(client, name ?? proposedName, fields.map((f) => f.key));
30669
+ let tableName2;
30670
+ let newId;
30671
+ if (earlier) {
30672
+ tableName2 = (name ?? proposedName).trim();
30673
+ newId = earlier.tableId;
30674
+ const lacking = fields.filter((f) => !earlier.haveKeys.has(f.key));
30675
+ const added = await addFields(client, newId, lacking);
30676
+ if (!added.ok) {
30677
+ setProblem(added.error);
30678
+ setPhase("ready");
30679
+ return;
30680
+ }
30681
+ } else {
30682
+ tableName2 = freeName(name ?? proposedName, (tables.data ?? []).map((t) => t.name));
30683
+ const born = await declareTable(client, { name: tableName2, fields });
30684
+ if (!born.ok) {
30685
+ setProblem(born.error);
30686
+ setPhase("ready");
30687
+ return;
30688
+ }
30689
+ newId = born.data;
30646
30690
  }
30647
- const newId = born.data;
30648
30691
  if (description.trim()) {
30649
30692
  const described = await (0, writeOnTheWinningVersion_exports.updateOnTheWinningVersion)(
30650
30693
  client,
@@ -52809,6 +52852,13 @@ function phoneTableActions(actions) {
52809
52852
 
52810
52853
  // src/toolbarFit.ts
52811
52854
  import { useEffect as useEffect123, useLayoutEffect as useLayoutEffect6, useState as useState149 } from "react";
52855
+ function widthAtFold(piece, fold) {
52856
+ for (let f = Math.min(fold, (piece.byFold?.length ?? 0) - 1); f >= 0; f -= 1) {
52857
+ const w = piece.byFold?.[f];
52858
+ if (w != null && w > 0) return w;
52859
+ }
52860
+ return piece.full ?? piece.now;
52861
+ }
52812
52862
  var FOLDED_GUESS = { look: 104, chooser: 96, tools: 120 };
52813
52863
  var SLOT_MIN = 36;
52814
52864
  function toolbarFold(input) {
@@ -52821,7 +52871,7 @@ function toolbarFold(input) {
52821
52871
  const widthAt = ({ piece, stage, guess }, fold) => {
52822
52872
  if (piece.now === 0 && piece.full === null) return 0;
52823
52873
  if (fold >= stage) return piece.folded ?? (folded >= stage ? piece.now : Math.min(guess, piece.full ?? piece.now));
52824
- return piece.full ?? piece.now;
52874
+ return widthAtFold(piece, fold);
52825
52875
  };
52826
52876
  const withGap = (width) => width > 0 ? width + gap : 0;
52827
52877
  const shareNow = input.share ? withGap(input.share.now) : 0;
@@ -52864,18 +52914,40 @@ function rowNeeds(row) {
52864
52914
  }
52865
52915
  return { needs: needs + gap * Math.max(0, pieces.length - 1), gap };
52866
52916
  }
52917
+ var STAGE_OF = { look: 1, chooser: 2, tools: 3, share: 4 };
52918
+ function createFitMemory() {
52919
+ const widths = {
52920
+ look: { full: null, folded: null, byFold: [] },
52921
+ chooser: { full: null, folded: null, byFold: [] },
52922
+ tools: { full: null, folded: null, byFold: [] },
52923
+ share: { full: null, folded: null, byFold: [] }
52924
+ };
52925
+ return {
52926
+ /** Record one piece's measured width (`now`; `present`: the piece is on the row) with the row at `current`. */
52927
+ piece(name, current, now, present) {
52928
+ const w = widths[name];
52929
+ const stage = STAGE_OF[name];
52930
+ if (present && now > 0) {
52931
+ if (current >= stage) w.folded = now;
52932
+ else {
52933
+ if (name === "tools") w.byFold[current] = now;
52934
+ if (name !== "tools" || current === 0 || w.full === null) w.full = now;
52935
+ }
52936
+ }
52937
+ if (!present && current < stage) {
52938
+ w.full = null;
52939
+ w.byFold = [];
52940
+ }
52941
+ return { now, full: w.full, folded: w.folded, byFold: w.byFold };
52942
+ }
52943
+ };
52944
+ }
52867
52945
  var useIsoLayoutEffect = typeof window === "undefined" ? useEffect123 : useLayoutEffect6;
52868
52946
  function useToolbarFit(row) {
52869
52947
  const [fold, setFold] = useState149(0);
52870
52948
  useIsoLayoutEffect(() => {
52871
52949
  if (!row) return;
52872
- const widths = {
52873
- look: { full: null, folded: null },
52874
- chooser: { full: null, folded: null },
52875
- tools: { full: null, folded: null },
52876
- share: { full: null, folded: null }
52877
- };
52878
- const stageOf = { look: 1, chooser: 2, tools: 3, share: 4 };
52950
+ const memory = createFitMemory();
52879
52951
  let current = 0;
52880
52952
  let pending = 0;
52881
52953
  let stopped = false;
@@ -52887,13 +52959,7 @@ function useToolbarFit(row) {
52887
52959
  const read = (name) => {
52888
52960
  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}"]`);
52889
52961
  const now = !el ? 0 : name === "tools" ? slotNeeds(el) : naturalWidth(el);
52890
- const w = widths[name];
52891
- if (el && now > 0) {
52892
- if (current >= stageOf[name]) w.folded = now;
52893
- else w.full = now;
52894
- }
52895
- if (!el && current < stageOf[name]) w.full = null;
52896
- return { now, full: w.full, folded: w.folded };
52962
+ return memory.piece(name, current, now, !!el);
52897
52963
  };
52898
52964
  const look = read("look");
52899
52965
  const chooser = read("chooser");