@bettercms-ai/kit 3.1.19 → 3.1.21
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/controls/table/table-editor.d.ts +3 -1
- package/dist/controls/table/table-editor.js +38 -5
- package/dist/controls/table/table-editor.js.map +1 -1
- package/dist/engine/frame.js +7 -2
- package/dist/engine/frame.js.map +1 -1
- package/dist/schema/table.d.ts +18 -1
- package/dist/schema/table.js +37 -4
- package/dist/schema/table.js.map +1 -1
- package/package.json +1 -1
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
*/
|
|
19
19
|
import * as React from "react";
|
|
20
20
|
import type { FieldPath } from "../../schema/types";
|
|
21
|
-
import { type RefResolver, type TableCell, type TableColumn, type TableColumnType, type TableFieldOptions, type TableResponsive, type TableRow, type TableValue } from "../../schema/table";
|
|
21
|
+
import { type PasteRefusal, type RefResolver, type TableCell, type TableColumn, type TableColumnType, type TableFieldOptions, type TableResponsive, type TableRow, type TableValue } from "../../schema/table";
|
|
22
22
|
export interface TableEditorProps {
|
|
23
23
|
value: TableValue;
|
|
24
24
|
onChange: (v: TableValue) => void;
|
|
@@ -58,6 +58,8 @@ export declare const TYPE_UI: Record<TableColumnType, {
|
|
|
58
58
|
icon: IconCmp;
|
|
59
59
|
dev?: boolean;
|
|
60
60
|
}>;
|
|
61
|
+
/** GAP-203: why pasted text was left out of number cells, in the number control's words. */
|
|
62
|
+
export declare function numberPasteNote(refused: PasteRefusal[]): string;
|
|
61
63
|
/** What a person typed → the cell. A value that doesn't fit its column (e.g. "Partly" in Yes / No) becomes a text cell. */
|
|
62
64
|
export declare function typedCell(prev: TableCell | undefined, col: TableColumn, row: TableRow, raw: string): TableCell;
|
|
63
65
|
/** Change a column's type; filled cells are re-read as the new type (words that don't fit become a text cell). */
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { GENERAL_TABLE, boolLabels, cellNote, cellText, cellType, cellValue, coerce, isCellObject, isEmptyCell, isObjLike, normalizeTable, orderedRows, parseDelimited, parseTableElement, pasteRange, tableFromRows, tableToRows, tkey, toBool, toNumber, withValue } from "../../schema/table.js";
|
|
1
|
+
import { GENERAL_TABLE, boolLabels, cellNote, cellText, cellType, cellValue, coerce, isCellObject, isEmptyCell, isObjLike, normalizeTable, orderedRows, parseDelimited, parseTableElement, pasteRange, pastedNumber, tableFromRows, tableToRows, tkey, toBool, toNumber, withValue } from "../../schema/table.js";
|
|
2
2
|
import { cn } from "../../lib/cn.js";
|
|
3
3
|
import { useKitServices } from "../../context.js";
|
|
4
4
|
import { Button, IconButton } from "../../ui/button.js";
|
|
@@ -107,6 +107,14 @@ var clean = (r) => {
|
|
|
107
107
|
].forEach((k) => !x[k] && delete x[k]);
|
|
108
108
|
return x;
|
|
109
109
|
};
|
|
110
|
+
/** GAP-203: why pasted text was left out of number cells, in the number control's words. */
|
|
111
|
+
function numberPasteNote(refused) {
|
|
112
|
+
const [first] = refused;
|
|
113
|
+
if (!first) return "";
|
|
114
|
+
const where = first.column.trim() ? ` in ${first.column.trim()}` : "";
|
|
115
|
+
const more = refused.length - 1;
|
|
116
|
+
return more ? `“${first.text}”${where} and ${more} more ${more === 1 ? "cell" : "cells"} aren't numbers, so they aren't pasted. Use digits, like 1234.5.` : `“${first.text}”${where} isn't a number, so it isn't pasted. Use digits, like 1234.5.`;
|
|
117
|
+
}
|
|
110
118
|
/** What a person typed → the cell. A value that doesn't fit its column (e.g. "Partly" in Yes / No) becomes a text cell. */
|
|
111
119
|
function typedCell(prev, col, row, raw) {
|
|
112
120
|
const colType = row.type ?? col.type;
|
|
@@ -462,10 +470,26 @@ function Grid({ ctx, label, full }) {
|
|
|
462
470
|
if (tbl) range = tableToRows(parseTableElement(tbl)).slice(r < 0 ? 0 : 1);
|
|
463
471
|
}
|
|
464
472
|
if (!range.length && /[\t\n]/.test(text.trim())) range = parseDelimited(text);
|
|
465
|
-
if (!range.length)
|
|
473
|
+
if (!range.length) {
|
|
474
|
+
const row = r >= 0 ? rows[r]?.row : void 0;
|
|
475
|
+
const col = cols[c];
|
|
476
|
+
const ty = row && col ? cellType(col, row, row.cells[col._key]) : void 0;
|
|
477
|
+
const plain = text.trim();
|
|
478
|
+
if (!col || !ty || !NUMERIC.includes(ty) || !plain || pastedNumber(plain, {
|
|
479
|
+
type: ty,
|
|
480
|
+
unit: col.unit
|
|
481
|
+
}) !== null) return false;
|
|
482
|
+
e.preventDefault();
|
|
483
|
+
toast?.("Paste not applied", { description: numberPasteNote([{
|
|
484
|
+
text: plain,
|
|
485
|
+
column: col.label
|
|
486
|
+
}]) });
|
|
487
|
+
return true;
|
|
488
|
+
}
|
|
466
489
|
e.preventDefault();
|
|
467
490
|
const blank = t.rows.every((x) => Object.values(x.cells).every((v) => isEmptyCell(cellValue(v)))) && cols.every((x) => !x.label.trim());
|
|
468
491
|
let next;
|
|
492
|
+
const refused = [];
|
|
469
493
|
if (blank && !lock && range.length > 1) {
|
|
470
494
|
const n = tableFromRows(range, { header: true });
|
|
471
495
|
next = {
|
|
@@ -480,7 +504,14 @@ function Grid({ ctx, label, full }) {
|
|
|
480
504
|
}, {
|
|
481
505
|
row: r,
|
|
482
506
|
col: c
|
|
483
|
-
}, range, {
|
|
507
|
+
}, range, {
|
|
508
|
+
lockColumns: lock,
|
|
509
|
+
refused
|
|
510
|
+
});
|
|
511
|
+
if (refused.length && refused.length === range.flat().filter((x) => x.trim()).length) {
|
|
512
|
+
toast?.("Paste not applied", { description: numberPasteNote(refused) });
|
|
513
|
+
return true;
|
|
514
|
+
}
|
|
484
515
|
const body = next.rows.filter((x) => !x.footer).length;
|
|
485
516
|
if (ctx.options.maxRows && body > ctx.options.maxRows) {
|
|
486
517
|
toast?.("Paste not applied", { description: `It would make ${body} rows; this table allows ${ctx.options.maxRows}.` });
|
|
@@ -491,7 +522,9 @@ function Grid({ ctx, label, full }) {
|
|
|
491
522
|
return true;
|
|
492
523
|
}
|
|
493
524
|
set(next);
|
|
494
|
-
|
|
525
|
+
const pasted = `Pasted ${range.length} ${range.length === 1 ? "row" : "rows"}`;
|
|
526
|
+
if (refused.length) toast?.(pasted, { description: numberPasteNote(refused) });
|
|
527
|
+
else toast?.(pasted);
|
|
495
528
|
return true;
|
|
496
529
|
};
|
|
497
530
|
const drag = React.useRef(null);
|
|
@@ -2725,6 +2758,6 @@ function TableSettings({ ctx }) {
|
|
|
2725
2758
|
}
|
|
2726
2759
|
var dropUndefined = (o) => Object.fromEntries(Object.entries(o).filter(([, v]) => v !== void 0));
|
|
2727
2760
|
//#endregion
|
|
2728
|
-
export { TYPE_UI, TableEditor, TableFullScreenButton, TableItemEditor, linkNote, moveRowTo, offered, retype, setTotals, typedCell, unlinkNote };
|
|
2761
|
+
export { TYPE_UI, TableEditor, TableFullScreenButton, TableItemEditor, linkNote, moveRowTo, numberPasteNote, offered, retype, setTotals, typedCell, unlinkNote };
|
|
2729
2762
|
|
|
2730
2763
|
//# sourceMappingURL=table-editor.js.map
|