@ai-matrx/records-ui 0.115.66 → 0.115.68
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 +12 -0
- package/dist/index.cjs +58 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +58 -10
- package/dist/index.js.map +1 -1
- package/dist/table-shape.cjs +2 -2
- package/dist/table-shape.cjs.map +1 -1
- package/dist/table-shape.d.cts +3 -1
- package/dist/table-shape.d.ts +3 -1
- package/dist/table-shape.js +2 -2
- package/dist/table-shape.js.map +1 -1
- package/package.json +4 -4
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
|
|
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,39 @@ 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 named = listed.data.filter((t) => !t.is_kernel && t.name.trim().toLowerCase() === name);
|
|
28410
|
+
if (named.length === 0) return null;
|
|
28411
|
+
const headers = await client.recordHeaders({ ids: named.map((t) => t.id) });
|
|
28412
|
+
if (!headers.ok) return null;
|
|
28413
|
+
const madeAt = /* @__PURE__ */ new Map();
|
|
28414
|
+
for (const h of headers.data) {
|
|
28415
|
+
const at = Date.parse(h.created_at);
|
|
28416
|
+
if (h.mine && h.deleted_at === null && Number.isFinite(at) && now - at <= UNFINISHED_WINDOW_MS) madeAt.set(h.id, at);
|
|
28417
|
+
}
|
|
28418
|
+
const candidates = named.filter((t) => madeAt.has(t.id));
|
|
28419
|
+
if (candidates.length === 0) return null;
|
|
28420
|
+
const counted = await client.tableRowCounts({ table_ids: candidates.map((t) => t.id) });
|
|
28421
|
+
if (!counted.ok) return null;
|
|
28422
|
+
const withRows = new Set(counted.data.filter((c) => c.visible_rows > 0).map((c) => c.table_id));
|
|
28423
|
+
const wanted = new Set(wantedKeys);
|
|
28424
|
+
const ordered = [...candidates].sort((a, b) => (madeAt.get(b.id) ?? 0) - (madeAt.get(a.id) ?? 0));
|
|
28425
|
+
for (const t of ordered) {
|
|
28426
|
+
if (withRows.has(t.id)) continue;
|
|
28427
|
+
const read = await client.fields({ table_id: t.id });
|
|
28428
|
+
if (!read.ok) continue;
|
|
28429
|
+
const have = new Set(read.data.map((f) => f.key));
|
|
28430
|
+
if ([...have].every((k) => wanted.has(k))) return { tableId: t.id, haveKeys: have };
|
|
28431
|
+
}
|
|
28432
|
+
return null;
|
|
28433
|
+
}
|
|
28434
|
+
|
|
28402
28435
|
// src/TablesHome.tsx
|
|
28403
28436
|
import { useEffect as useEffect62, useState as useState79 } from "react";
|
|
28404
28437
|
import { useRecordsClient as useRecordsClient52, useTables as useTables2 } from "@ai-matrx/records/react";
|
|
@@ -30516,7 +30549,7 @@ var SAVE_TO_TABLE_TYPES = [
|
|
|
30516
30549
|
];
|
|
30517
30550
|
function shapesOfSource(source) {
|
|
30518
30551
|
if (source.grid) {
|
|
30519
|
-
const s = shapeOfGrid(source.grid.headers, source.grid.rows, source.title ?? null);
|
|
30552
|
+
const s = shapeOfGrid(source.grid.headers, source.grid.rows, source.title ?? null, source.grid.from);
|
|
30520
30553
|
return s ? [s] : [];
|
|
30521
30554
|
}
|
|
30522
30555
|
if (source.value !== void 0) {
|
|
@@ -30635,16 +30668,31 @@ function SaveToTable({ source, shapeIndex = 0, onOpenTable, onSaved, onClose, ma
|
|
|
30635
30668
|
...c.guess.type === "datetime" && c.guess.kind ? { kind: c.guess.kind } : {}
|
|
30636
30669
|
};
|
|
30637
30670
|
});
|
|
30638
|
-
const tableName2 = freeName(name ?? proposedName, (tables.data ?? []).map((t) => t.name));
|
|
30639
30671
|
setPhase("making");
|
|
30640
30672
|
try {
|
|
30641
|
-
const
|
|
30642
|
-
|
|
30643
|
-
|
|
30644
|
-
|
|
30645
|
-
|
|
30673
|
+
const earlier = await findUnfinishedTable(client, name ?? proposedName, fields.map((f) => f.key));
|
|
30674
|
+
let tableName2;
|
|
30675
|
+
let newId;
|
|
30676
|
+
if (earlier) {
|
|
30677
|
+
tableName2 = (name ?? proposedName).trim();
|
|
30678
|
+
newId = earlier.tableId;
|
|
30679
|
+
const lacking = fields.filter((f) => !earlier.haveKeys.has(f.key));
|
|
30680
|
+
const added = await addFields(client, newId, lacking);
|
|
30681
|
+
if (!added.ok) {
|
|
30682
|
+
setProblem(added.error);
|
|
30683
|
+
setPhase("ready");
|
|
30684
|
+
return;
|
|
30685
|
+
}
|
|
30686
|
+
} else {
|
|
30687
|
+
tableName2 = freeName(name ?? proposedName, (tables.data ?? []).map((t) => t.name));
|
|
30688
|
+
const born = await declareTable(client, { name: tableName2, fields });
|
|
30689
|
+
if (!born.ok) {
|
|
30690
|
+
setProblem(born.error);
|
|
30691
|
+
setPhase("ready");
|
|
30692
|
+
return;
|
|
30693
|
+
}
|
|
30694
|
+
newId = born.data;
|
|
30646
30695
|
}
|
|
30647
|
-
const newId = born.data;
|
|
30648
30696
|
if (description.trim()) {
|
|
30649
30697
|
const described = await (0, writeOnTheWinningVersion_exports.updateOnTheWinningVersion)(
|
|
30650
30698
|
client,
|