@ai-matrx/records-ui 0.115.66 → 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,