@constructive-io/sheets 0.4.1 → 0.6.0
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/README.md +19 -24
- package/dist/advanced.cjs +250 -405
- package/dist/advanced.cjs.map +1 -1
- package/dist/advanced.d.cts +9 -10
- package/dist/advanced.d.ts +9 -10
- package/dist/advanced.js +3 -3
- package/dist/auth.cjs +10 -10
- package/dist/auth.cjs.map +1 -1
- package/dist/auth.d.cts +5 -4
- package/dist/auth.d.ts +5 -4
- package/dist/auth.js +3 -3
- package/dist/{chunk-GLVZSPV2.js → chunk-4EZ6A23C.js} +4 -3
- package/dist/chunk-4EZ6A23C.js.map +1 -0
- package/dist/{chunk-3BNOZQIJ.js → chunk-KKAWMVEG.js} +11 -11
- package/dist/chunk-KKAWMVEG.js.map +1 -0
- package/dist/{chunk-FG2LRZP5.js → chunk-KOZAW264.js} +4 -3
- package/dist/chunk-KOZAW264.js.map +1 -0
- package/dist/{chunk-BWJVRYJT.js → chunk-KVPVEXWB.js} +40 -17
- package/dist/chunk-KVPVEXWB.js.map +1 -0
- package/dist/{chunk-BWKB52JB.js → chunk-LR64FLWO.js} +231 -379
- package/dist/chunk-LR64FLWO.js.map +1 -0
- package/dist/{chunk-SDKHWE7G.js → chunk-ZETPUEXH.js} +27 -2
- package/dist/chunk-ZETPUEXH.js.map +1 -0
- package/dist/{date-editor-CXKKGNL6.js → date-editor-QT47WY5T.js} +5 -3
- package/dist/date-editor-QT47WY5T.js.map +1 -0
- package/dist/{editor-props-M6Dh0P9f.d.ts → grid-cell-types-C3ARj148.d.cts} +70 -62
- package/dist/{editor-props-M6Dh0P9f.d.cts → grid-cell-types-C3ARj148.d.ts} +70 -62
- package/dist/index.cjs +564 -493
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +86 -35
- package/dist/index.d.ts +86 -35
- package/dist/index.js +264 -72
- package/dist/index.js.map +1 -1
- package/dist/{sheets-context-9u9r7Bs0.d.ts → sheets-context-B03WDhZ9.d.cts} +13 -6
- package/dist/{sheets-context-BjGIHocT.d.cts → sheets-context-DmVCOgiX.d.ts} +13 -6
- package/dist/styles.css +6 -0
- package/dist/testing.cjs +99 -33
- package/dist/testing.cjs.map +1 -1
- package/dist/testing.d.cts +11 -7
- package/dist/testing.d.ts +11 -7
- package/dist/testing.js +34 -8
- package/dist/testing.js.map +1 -1
- package/package.json +15 -16
- package/dist/chunk-3BNOZQIJ.js.map +0 -1
- package/dist/chunk-BWJVRYJT.js.map +0 -1
- package/dist/chunk-BWKB52JB.js.map +0 -1
- package/dist/chunk-FG2LRZP5.js.map +0 -1
- package/dist/chunk-GLVZSPV2.js.map +0 -1
- package/dist/chunk-SDKHWE7G.js.map +0 -1
- package/dist/date-editor-CXKKGNL6.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -2,14 +2,19 @@
|
|
|
2
2
|
import {
|
|
3
3
|
DOM_EDITOR_REGISTRY,
|
|
4
4
|
OverlayMeasureContext,
|
|
5
|
+
canRunSheetsMutation,
|
|
5
6
|
computeOverlayGeometry,
|
|
6
7
|
createPostGraphileAdapter,
|
|
7
8
|
createSheetsCell,
|
|
8
9
|
executeFieldUpload,
|
|
9
10
|
getImageMetadata,
|
|
10
|
-
|
|
11
|
+
getSheetsWriteCapability,
|
|
11
12
|
resolveRelationFieldMap,
|
|
12
|
-
|
|
13
|
+
resolveSheetsIdentifier,
|
|
14
|
+
resolveSheetsRowIdentity,
|
|
15
|
+
sheetsIdentifierCacheKey,
|
|
16
|
+
sheetsIdentifierToWhere,
|
|
17
|
+
sheetsRowKey,
|
|
13
18
|
sheetsTableQueryKeys,
|
|
14
19
|
transformToPostGraphileVariables,
|
|
15
20
|
useSheetsAdapter,
|
|
@@ -19,24 +24,26 @@ import {
|
|
|
19
24
|
useSheetsTable,
|
|
20
25
|
useSheetsTableCursor,
|
|
21
26
|
validateOrderByVariables
|
|
22
|
-
} from "./chunk-
|
|
27
|
+
} from "./chunk-LR64FLWO.js";
|
|
23
28
|
import {
|
|
24
29
|
SheetsAuthGate,
|
|
25
30
|
useSheetsForgotPassword,
|
|
26
31
|
useSheetsLogin,
|
|
27
32
|
useSheetsRegister,
|
|
28
33
|
useSheetsResetPassword
|
|
29
|
-
} from "./chunk-
|
|
34
|
+
} from "./chunk-KKAWMVEG.js";
|
|
30
35
|
import {
|
|
31
36
|
SheetsProvider
|
|
32
|
-
} from "./chunk-
|
|
37
|
+
} from "./chunk-KVPVEXWB.js";
|
|
33
38
|
import {
|
|
34
39
|
DataError,
|
|
35
40
|
createSheetsExecute,
|
|
36
41
|
createSheetsUpload,
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
42
|
+
isSheetsScopeKey,
|
|
43
|
+
resolveDownloadUrl,
|
|
44
|
+
sheetsQueryKeys
|
|
45
|
+
} from "./chunk-ZETPUEXH.js";
|
|
46
|
+
import "./chunk-4EZ6A23C.js";
|
|
40
47
|
import {
|
|
41
48
|
SheetsContext,
|
|
42
49
|
buildRelationInfoFromMeta,
|
|
@@ -47,7 +54,7 @@ import {
|
|
|
47
54
|
useSheetsContext,
|
|
48
55
|
useSheetsStore,
|
|
49
56
|
useSheetsStoreApi
|
|
50
|
-
} from "./chunk-
|
|
57
|
+
} from "./chunk-KOZAW264.js";
|
|
51
58
|
import {
|
|
52
59
|
BOOLEAN_TYPES,
|
|
53
60
|
BUILTIN_EDITOR_TYPES,
|
|
@@ -495,7 +502,9 @@ function SheetsControls(props) {
|
|
|
495
502
|
gridSelection,
|
|
496
503
|
deleteSelected,
|
|
497
504
|
onAddRow,
|
|
498
|
-
onExport
|
|
505
|
+
onExport,
|
|
506
|
+
canDelete = true,
|
|
507
|
+
readOnlyReason
|
|
499
508
|
} = props;
|
|
500
509
|
const filterableColumns = useMemo(() => {
|
|
501
510
|
if (Object.keys(fieldTypeMap).length === 0) return columnKeys;
|
|
@@ -530,7 +539,16 @@ function SheetsControls(props) {
|
|
|
530
539
|
"data-part-id": "sheets-controls",
|
|
531
540
|
className: "flex shrink-0 flex-wrap items-center justify-between gap-4 py-4",
|
|
532
541
|
children: [
|
|
533
|
-
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
|
|
542
|
+
/* @__PURE__ */ jsxs("div", { className: "flex min-w-0 flex-wrap items-center gap-2", children: [
|
|
543
|
+
readOnlyReason && /* @__PURE__ */ jsx(
|
|
544
|
+
"span",
|
|
545
|
+
{
|
|
546
|
+
className: "border-border bg-muted text-muted-foreground inline-flex h-8 items-center rounded-md border px-2.5 text-xs",
|
|
547
|
+
role: "status",
|
|
548
|
+
title: readOnlyReason,
|
|
549
|
+
children: "Read-only"
|
|
550
|
+
}
|
|
551
|
+
),
|
|
534
552
|
/* @__PURE__ */ jsxs(Button, { variant: "outline", size: "sm", onClick: () => openSearch?.(), children: [
|
|
535
553
|
/* @__PURE__ */ jsx(RiSearch2Line, { className: "text-muted-foreground/60 -ms-1.5 size-5", "aria-hidden": "true" }),
|
|
536
554
|
"Search"
|
|
@@ -552,11 +570,20 @@ function SheetsControls(props) {
|
|
|
552
570
|
] }),
|
|
553
571
|
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
|
|
554
572
|
showSelection && /* @__PURE__ */ jsxs(AlertDialog, { children: [
|
|
555
|
-
/* @__PURE__ */ jsx(AlertDialogTrigger, { asChild: true, children: /* @__PURE__ */ jsxs(
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
573
|
+
/* @__PURE__ */ jsx(AlertDialogTrigger, { asChild: true, children: /* @__PURE__ */ jsxs(
|
|
574
|
+
Button,
|
|
575
|
+
{
|
|
576
|
+
variant: "destructive-outline",
|
|
577
|
+
size: "sm",
|
|
578
|
+
disabled: !canDelete || selectedRowCount === 0,
|
|
579
|
+
title: !canDelete ? readOnlyReason ?? "Delete is unavailable for this table." : void 0,
|
|
580
|
+
children: [
|
|
581
|
+
/* @__PURE__ */ jsx(RiDeleteBin6Line, { className: "-ms-1.5 size-5", "aria-hidden": "true" }),
|
|
582
|
+
"Delete",
|
|
583
|
+
selectedRowCount > 0 ? ` (${selectedRowCount})` : ""
|
|
584
|
+
]
|
|
585
|
+
}
|
|
586
|
+
) }),
|
|
560
587
|
/* @__PURE__ */ jsxs(AlertDialogContent, { children: [
|
|
561
588
|
/* @__PURE__ */ jsxs(AlertDialogHeader, { children: [
|
|
562
589
|
/* @__PURE__ */ jsx(AlertDialogTitle, { children: "Delete rows?" }),
|
|
@@ -666,7 +693,9 @@ function buildContextMenuItems({
|
|
|
666
693
|
isEnabled,
|
|
667
694
|
onAddRow,
|
|
668
695
|
requestDelete,
|
|
669
|
-
selectedRowCount
|
|
696
|
+
selectedRowCount,
|
|
697
|
+
canAddRows = true,
|
|
698
|
+
canDeleteRows = true
|
|
670
699
|
}) {
|
|
671
700
|
const cmd = (key2, commandId, label, icon, shortcut) => ({
|
|
672
701
|
key: key2,
|
|
@@ -686,6 +715,7 @@ function buildContextMenuItems({
|
|
|
686
715
|
key: "add-row",
|
|
687
716
|
label: "Add row",
|
|
688
717
|
icon: /* @__PURE__ */ jsx2(RiAddLine2, { className: "size-4", "aria-hidden": "true" }),
|
|
718
|
+
disabled: !canAddRows,
|
|
689
719
|
run: onAddRow
|
|
690
720
|
},
|
|
691
721
|
{
|
|
@@ -693,7 +723,7 @@ function buildContextMenuItems({
|
|
|
693
723
|
label: selectedRowCount > 1 ? `Delete ${selectedRowCount} rows` : "Delete row",
|
|
694
724
|
icon: /* @__PURE__ */ jsx2(RiDeleteBin6Line2, { className: "size-4", "aria-hidden": "true" }),
|
|
695
725
|
destructive: true,
|
|
696
|
-
disabled: selectedRowCount === 0,
|
|
726
|
+
disabled: !canDeleteRows || selectedRowCount === 0,
|
|
697
727
|
run: requestDelete
|
|
698
728
|
}
|
|
699
729
|
];
|
|
@@ -705,7 +735,9 @@ function SheetsContextMenu({
|
|
|
705
735
|
isEnabled,
|
|
706
736
|
onAddRow,
|
|
707
737
|
onDeleteRows,
|
|
708
|
-
selectedRowCount
|
|
738
|
+
selectedRowCount,
|
|
739
|
+
canAddRows = true,
|
|
740
|
+
canDeleteRows = true
|
|
709
741
|
}) {
|
|
710
742
|
const [confirmDelete, setConfirmDelete] = useState2(false);
|
|
711
743
|
const open = state !== null;
|
|
@@ -714,7 +746,9 @@ function SheetsContextMenu({
|
|
|
714
746
|
isEnabled,
|
|
715
747
|
onAddRow,
|
|
716
748
|
requestDelete: () => setConfirmDelete(true),
|
|
717
|
-
selectedRowCount
|
|
749
|
+
selectedRowCount,
|
|
750
|
+
canAddRows,
|
|
751
|
+
canDeleteRows
|
|
718
752
|
});
|
|
719
753
|
return /* @__PURE__ */ jsxs2(Fragment2, { children: [
|
|
720
754
|
/* @__PURE__ */ jsxs2(DropdownMenu, { open, onOpenChange: (next) => !next && onClose(), children: [
|
|
@@ -1236,12 +1270,12 @@ function SheetsErrorState({ error, onRetry }) {
|
|
|
1236
1270
|
onRetry && /* @__PURE__ */ jsx6(Button3, { variant: "outline", size: "sm", onClick: onRetry, children: "Retry" })
|
|
1237
1271
|
] });
|
|
1238
1272
|
}
|
|
1239
|
-
function SheetsEmptyState({ tableName, onAddRow }) {
|
|
1273
|
+
function SheetsEmptyState({ tableName, onAddRow, readOnlyReason }) {
|
|
1240
1274
|
return /* @__PURE__ */ jsxs5(SheetsStateShell, { children: [
|
|
1241
1275
|
/* @__PURE__ */ jsx6(RiInboxLine, { className: "text-muted-foreground h-8 w-8" }),
|
|
1242
1276
|
/* @__PURE__ */ jsxs5("div", { className: "space-y-1", children: [
|
|
1243
1277
|
/* @__PURE__ */ jsx6("p", { className: "text-foreground text-sm font-medium", children: "No rows yet" }),
|
|
1244
|
-
/* @__PURE__ */ jsx6("p", { className: "text-muted-foreground max-w-md text-sm", children: tableName ? `The "${tableName}" table is empty.` : "This table is empty." })
|
|
1278
|
+
/* @__PURE__ */ jsx6("p", { className: "text-muted-foreground max-w-md text-sm", children: readOnlyReason ?? (tableName ? `The "${tableName}" table is empty.` : "This table is empty.") })
|
|
1245
1279
|
] }),
|
|
1246
1280
|
onAddRow && /* @__PURE__ */ jsxs5(Button3, { variant: "outline", size: "sm", onClick: onAddRow, children: [
|
|
1247
1281
|
/* @__PURE__ */ jsx6(RiAddLine3, { className: "h-4 w-4" }),
|
|
@@ -1479,6 +1513,8 @@ var CellRegistry = new CellRegistryClass();
|
|
|
1479
1513
|
// src/cell-types/type-mapping.ts
|
|
1480
1514
|
function mapToFrontendCellType(metadata) {
|
|
1481
1515
|
const { gqlType, isArray, pgAlias, pgType } = metadata;
|
|
1516
|
+
const encodedType = mapEncodingToCellType(metadata.encoding);
|
|
1517
|
+
if (encodedType) return encodedType;
|
|
1482
1518
|
if (pgAlias) {
|
|
1483
1519
|
const aliasType = mapAliasToCellType(pgAlias);
|
|
1484
1520
|
if (aliasType !== "unknown") return aliasType;
|
|
@@ -1494,6 +1530,38 @@ function mapToFrontendCellType(metadata) {
|
|
|
1494
1530
|
const fallbackResult = mapGraphQLTypeToCellType(gqlType, isArray, metadata.subtype, null);
|
|
1495
1531
|
return fallbackResult;
|
|
1496
1532
|
}
|
|
1533
|
+
function mapEncodingToCellType(encoding) {
|
|
1534
|
+
if (!encoding) return null;
|
|
1535
|
+
switch (encoding.kind) {
|
|
1536
|
+
case "bigint":
|
|
1537
|
+
return "integer";
|
|
1538
|
+
case "datetime":
|
|
1539
|
+
return "datetime";
|
|
1540
|
+
case "date":
|
|
1541
|
+
return "date";
|
|
1542
|
+
case "time":
|
|
1543
|
+
return "time";
|
|
1544
|
+
case "interval":
|
|
1545
|
+
return "interval";
|
|
1546
|
+
case "uuid":
|
|
1547
|
+
return "uuid";
|
|
1548
|
+
case "inet":
|
|
1549
|
+
return "inet";
|
|
1550
|
+
case "point":
|
|
1551
|
+
return "geometry-point";
|
|
1552
|
+
case "geojson":
|
|
1553
|
+
return encoding.geometrySubtype === "Point" ? "geometry-point" : "geometry";
|
|
1554
|
+
case "vector":
|
|
1555
|
+
return "number-array";
|
|
1556
|
+
case "composite":
|
|
1557
|
+
return "json";
|
|
1558
|
+
case "ltree":
|
|
1559
|
+
case "bytea":
|
|
1560
|
+
return "text";
|
|
1561
|
+
default:
|
|
1562
|
+
return null;
|
|
1563
|
+
}
|
|
1564
|
+
}
|
|
1497
1565
|
function mapAliasToCellType(alias) {
|
|
1498
1566
|
const aliasMap = {
|
|
1499
1567
|
// Media types
|
|
@@ -1698,9 +1766,9 @@ function isStructuredDataType(cellType) {
|
|
|
1698
1766
|
}
|
|
1699
1767
|
function createColumnSchemaFromMeta(field) {
|
|
1700
1768
|
const { name, type } = field;
|
|
1701
|
-
const { gqlType, isArray,
|
|
1769
|
+
const { gqlType, isArray, subtype } = type;
|
|
1702
1770
|
const nullable = !gqlType.endsWith("!");
|
|
1703
|
-
const cellType =
|
|
1771
|
+
const cellType = mapToFrontendCellType(field.type);
|
|
1704
1772
|
const label = name.replace(/([A-Z])/g, " $1").replace(/^./, (str) => str.toUpperCase()).trim();
|
|
1705
1773
|
return {
|
|
1706
1774
|
id: name,
|
|
@@ -2500,6 +2568,9 @@ var DRAFT_ACTION_COLUMN_KEY = "__draft_action__";
|
|
|
2500
2568
|
|
|
2501
2569
|
// src/grid/hooks/use-cell-editing.ts
|
|
2502
2570
|
import { useCallback as useCallback7 } from "react";
|
|
2571
|
+
function legacyRowIdentifier(row) {
|
|
2572
|
+
return typeof row.id === "string" || typeof row.id === "number" ? row.id : null;
|
|
2573
|
+
}
|
|
2503
2574
|
function normalizeRelationPatchValue(rawValue, relationKind) {
|
|
2504
2575
|
let value = rawValue;
|
|
2505
2576
|
if (typeof value === "string") {
|
|
@@ -2523,8 +2594,9 @@ function normalizeRelationPatchValue(rawValue, relationKind) {
|
|
|
2523
2594
|
if (value === "") value = null;
|
|
2524
2595
|
return value;
|
|
2525
2596
|
}
|
|
2526
|
-
function resolveServerPatch(colKey, rawValue, fieldMetaMap, relationInfoByField) {
|
|
2597
|
+
function resolveServerPatch(colKey, rawValue, fieldMetaMap, relationInfoByField, readOnlyFields) {
|
|
2527
2598
|
if (!colKey || colKey === DRAFT_ACTION_COLUMN_KEY) return { kind: "noop" };
|
|
2599
|
+
if (readOnlyFields?.has(colKey)) return { kind: "noop" };
|
|
2528
2600
|
const metaField = fieldMetaMap.get(colKey);
|
|
2529
2601
|
if (colKey === "id" && metaField?.type?.gqlType === "UUID") return { kind: "noop" };
|
|
2530
2602
|
const relationInfo = relationInfoByField.get(colKey);
|
|
@@ -2546,6 +2618,9 @@ function useCellEditing({
|
|
|
2546
2618
|
updateDraftCell,
|
|
2547
2619
|
tableKey,
|
|
2548
2620
|
update,
|
|
2621
|
+
getRowIdentifier = legacyRowIdentifier,
|
|
2622
|
+
readOnlyFields,
|
|
2623
|
+
canUpdate = true,
|
|
2549
2624
|
onCellEdit,
|
|
2550
2625
|
applyOptimisticPatch
|
|
2551
2626
|
}) {
|
|
@@ -2612,18 +2687,21 @@ function useCellEditing({
|
|
|
2612
2687
|
});
|
|
2613
2688
|
return { type: "draft" };
|
|
2614
2689
|
}
|
|
2615
|
-
|
|
2690
|
+
if (!canUpdate) return { type: "noop" };
|
|
2691
|
+
const resolution = resolveServerPatch(colKey, rawValue, fieldMetaMap, relationInfoByField, readOnlyFields);
|
|
2616
2692
|
if (resolution.kind === "noop") return { type: "noop" };
|
|
2617
2693
|
const { field: patchField, value } = resolution;
|
|
2694
|
+
const rowIdentifier = getRowIdentifier(rowData);
|
|
2695
|
+
if (rowIdentifier === null) return { type: "noop" };
|
|
2618
2696
|
const revertOptimisticPatch = applyOptimisticPatch?.(rowIndex, { [patchField]: value });
|
|
2619
2697
|
let result;
|
|
2620
2698
|
try {
|
|
2621
|
-
result = await update(
|
|
2699
|
+
result = await update(rowIdentifier, { [patchField]: value });
|
|
2622
2700
|
} catch (error) {
|
|
2623
2701
|
revertOptimisticPatch?.();
|
|
2624
2702
|
throw error;
|
|
2625
2703
|
}
|
|
2626
|
-
onCellEdit?.(
|
|
2704
|
+
onCellEdit?.(rowIdentifier, patchField, value);
|
|
2627
2705
|
return {
|
|
2628
2706
|
type: "server",
|
|
2629
2707
|
updatedRow: result?.updatedRow ?? null,
|
|
@@ -2631,17 +2709,23 @@ function useCellEditing({
|
|
|
2631
2709
|
patchValue: value
|
|
2632
2710
|
};
|
|
2633
2711
|
},
|
|
2634
|
-
[combinedRows, fieldMetaMap, relationInfoByField, tableKey, update, onCellEdit, updateDraftCell, applyOptimisticPatch]
|
|
2712
|
+
[combinedRows, fieldMetaMap, relationInfoByField, tableKey, update, getRowIdentifier, readOnlyFields, canUpdate, onCellEdit, updateDraftCell, applyOptimisticPatch]
|
|
2635
2713
|
);
|
|
2636
2714
|
}
|
|
2637
2715
|
|
|
2638
2716
|
// src/grid/hooks/use-batch-commit.ts
|
|
2639
2717
|
import { useCallback as useCallback8, useRef as useRef2 } from "react";
|
|
2718
|
+
function legacyRowIdentifier2(row) {
|
|
2719
|
+
return typeof row.id === "string" || typeof row.id === "number" ? row.id : null;
|
|
2720
|
+
}
|
|
2640
2721
|
function useBatchCommit({
|
|
2641
2722
|
combinedRows,
|
|
2642
2723
|
fieldMetaMap,
|
|
2643
2724
|
relationInfoByField,
|
|
2644
2725
|
update,
|
|
2726
|
+
getRowIdentifier = legacyRowIdentifier2,
|
|
2727
|
+
readOnlyFields,
|
|
2728
|
+
canUpdate = true,
|
|
2645
2729
|
applyOptimisticPatch,
|
|
2646
2730
|
resyncRow,
|
|
2647
2731
|
editCell,
|
|
@@ -2661,11 +2745,14 @@ function useBatchCommit({
|
|
|
2661
2745
|
draftWrites.push(w);
|
|
2662
2746
|
continue;
|
|
2663
2747
|
}
|
|
2664
|
-
|
|
2748
|
+
if (!canUpdate) continue;
|
|
2749
|
+
const resolution = resolveServerPatch(w.colKey, w.value, fieldMetaMap, relationInfoByField, readOnlyFields);
|
|
2665
2750
|
if (resolution.kind === "noop") continue;
|
|
2751
|
+
const rowIdentifier = getRowIdentifier(rowData);
|
|
2752
|
+
if (rowIdentifier === null) continue;
|
|
2666
2753
|
resolved.push({
|
|
2667
2754
|
rowIndex: w.rowIndex,
|
|
2668
|
-
rowId:
|
|
2755
|
+
rowId: rowIdentifier,
|
|
2669
2756
|
field: resolution.field,
|
|
2670
2757
|
value: resolution.value,
|
|
2671
2758
|
// Capture the PRIOR value of the patched field BEFORE any optimistic patch.
|
|
@@ -2720,7 +2807,7 @@ function useBatchCommit({
|
|
|
2720
2807
|
}
|
|
2721
2808
|
return { applied: resolved.length };
|
|
2722
2809
|
},
|
|
2723
|
-
[combinedRows, fieldMetaMap, relationInfoByField, update, applyOptimisticPatch, resyncRow, editCell, onCellEdit, record]
|
|
2810
|
+
[combinedRows, fieldMetaMap, relationInfoByField, update, getRowIdentifier, readOnlyFields, canUpdate, applyOptimisticPatch, resyncRow, editCell, onCellEdit, record]
|
|
2724
2811
|
);
|
|
2725
2812
|
commitRef.current = commitCells;
|
|
2726
2813
|
return commitCells;
|
|
@@ -3092,11 +3179,24 @@ function tagDraftStyle(cell, hasError) {
|
|
|
3092
3179
|
return { ...cell, styleHint: { ...cell.styleHint, draft: true, error: hasError } };
|
|
3093
3180
|
}
|
|
3094
3181
|
function useSheetsContent(args) {
|
|
3095
|
-
const {
|
|
3182
|
+
const {
|
|
3183
|
+
data,
|
|
3184
|
+
columnKeys,
|
|
3185
|
+
fieldMetaMap,
|
|
3186
|
+
registry,
|
|
3187
|
+
tableName,
|
|
3188
|
+
options,
|
|
3189
|
+
relationInfoByField,
|
|
3190
|
+
meta,
|
|
3191
|
+
serverRowsReadOnly = false,
|
|
3192
|
+
serverReadOnlyFields,
|
|
3193
|
+
getRowIdentifier,
|
|
3194
|
+
supportsScalarSelfCommit = true
|
|
3195
|
+
} = args;
|
|
3096
3196
|
const relationFieldNamesFromMeta = useMemo7(() => buildRelationFieldNameSet(meta, tableName), [meta, tableName]);
|
|
3097
3197
|
const cache2 = useMemo7(
|
|
3098
3198
|
() => /* @__PURE__ */ new Map(),
|
|
3099
|
-
[data, columnKeys, fieldMetaMap, registry, relationFieldNamesFromMeta, relationInfoByField, options]
|
|
3199
|
+
[data, columnKeys, fieldMetaMap, registry, relationFieldNamesFromMeta, relationInfoByField, options, serverRowsReadOnly, serverReadOnlyFields, getRowIdentifier, supportsScalarSelfCommit]
|
|
3100
3200
|
);
|
|
3101
3201
|
const getSheetsCell = useCallback11(
|
|
3102
3202
|
(rowIndex, colKey) => {
|
|
@@ -3138,6 +3238,7 @@ function useSheetsContent(args) {
|
|
|
3138
3238
|
isDraftIdCell,
|
|
3139
3239
|
hasForeignKeyField: canEditRelationInline
|
|
3140
3240
|
});
|
|
3241
|
+
const tableForcedReadOnly = !isDraftRow2 && (serverRowsReadOnly || Boolean(serverReadOnlyFields?.has(colKey)));
|
|
3141
3242
|
let valueForCell = rawValue;
|
|
3142
3243
|
if (relationInfo && relationInfo.relationField && relationInfo.relationField !== colKey) {
|
|
3143
3244
|
const relatedValue = rowData?.[relationInfo.relationField];
|
|
@@ -3165,17 +3266,22 @@ function useSheetsContent(args) {
|
|
|
3165
3266
|
fieldName: colKey
|
|
3166
3267
|
};
|
|
3167
3268
|
const cellType = registry.resolveTypeKey(matchInput, () => route.cellType);
|
|
3269
|
+
const rowIdentifier = !isDraftRow2 ? getRowIdentifier?.(rowData) : null;
|
|
3270
|
+
const selfCommittingEditor = isRelation || MEDIA_TYPES.has(cellType);
|
|
3271
|
+
const lacksScalarEditorIdentity = selfCommittingEditor && (!supportsScalarSelfCommit || rowIdentifier != null && typeof rowIdentifier === "object");
|
|
3272
|
+
const forcedReadOnly = tableForcedReadOnly || lacksScalarEditorIdentity;
|
|
3168
3273
|
const metadata = {
|
|
3169
3274
|
cellType,
|
|
3170
3275
|
fieldName: colKey,
|
|
3171
3276
|
fieldMeta,
|
|
3172
3277
|
relationInfo,
|
|
3173
3278
|
relationOptions: relationInfo ? options || {} : void 0,
|
|
3174
|
-
canEdit: route.canEdit,
|
|
3175
|
-
isReadonly: route.isReadonly,
|
|
3279
|
+
canEdit: route.canEdit && !forcedReadOnly,
|
|
3280
|
+
isReadonly: route.isReadonly || forcedReadOnly,
|
|
3176
3281
|
activationBehavior: route.activationBehavior
|
|
3177
3282
|
};
|
|
3178
|
-
const
|
|
3283
|
+
const resolvedCell = registry.toSheetsCell(cellType, valueForCell, { metadata });
|
|
3284
|
+
const cell = forcedReadOnly && !resolvedCell.readonly ? { ...resolvedCell, readonly: true } : resolvedCell;
|
|
3179
3285
|
const displaySafe = suppressDraftIdText(cell, {
|
|
3180
3286
|
isDraftRow: isDraftRow2,
|
|
3181
3287
|
colKey,
|
|
@@ -3190,7 +3296,7 @@ function useSheetsContent(args) {
|
|
|
3190
3296
|
cache2.set(cacheKey, { value: rawValue, resolution });
|
|
3191
3297
|
return resolution;
|
|
3192
3298
|
},
|
|
3193
|
-
[data, columnKeys, fieldMetaMap, registry, relationFieldNamesFromMeta, relationInfoByField, options]
|
|
3299
|
+
[data, columnKeys, fieldMetaMap, registry, relationFieldNamesFromMeta, relationInfoByField, options, serverRowsReadOnly, serverReadOnlyFields, getRowIdentifier, supportsScalarSelfCommit]
|
|
3194
3300
|
);
|
|
3195
3301
|
return { getSheetsCell };
|
|
3196
3302
|
}
|
|
@@ -3246,13 +3352,18 @@ function useGridOperations(data, deleteRow, gridSelection, clearSelection, optio
|
|
|
3246
3352
|
} else {
|
|
3247
3353
|
failures += 1;
|
|
3248
3354
|
}
|
|
3249
|
-
} else if (
|
|
3355
|
+
} else if (options?.canDeleteServerRows !== false) {
|
|
3356
|
+
const identifier = options?.getRowIdentifier ? options.getRowIdentifier(record) : typeof record?.id === "string" || typeof record?.id === "number" ? record.id : null;
|
|
3357
|
+
if (identifier === null) {
|
|
3358
|
+
failures += 1;
|
|
3359
|
+
continue;
|
|
3360
|
+
}
|
|
3250
3361
|
try {
|
|
3251
|
-
await deleteRow(
|
|
3362
|
+
await deleteRow(identifier);
|
|
3252
3363
|
successes += 1;
|
|
3253
3364
|
serverSuccesses += 1;
|
|
3254
3365
|
} catch (error) {
|
|
3255
|
-
sheetsLogger().error(
|
|
3366
|
+
sheetsLogger().error("Failed to delete record", { identifier, error });
|
|
3256
3367
|
failures += 1;
|
|
3257
3368
|
}
|
|
3258
3369
|
} else {
|
|
@@ -4128,6 +4239,7 @@ function useInfiniteGridData({
|
|
|
4128
4239
|
|
|
4129
4240
|
// src/grid/hooks/use-load-grid.ts
|
|
4130
4241
|
import { useMemo as useMemo12 } from "react";
|
|
4242
|
+
import { assessTableWriteCapability, getRowIdentityDefinition } from "@constructive-io/data";
|
|
4131
4243
|
function buildFieldMetaMap2(fields, tableName, fieldTypeOverrides) {
|
|
4132
4244
|
const map = /* @__PURE__ */ new Map();
|
|
4133
4245
|
if (!fields || fields.length === 0) return map;
|
|
@@ -4161,6 +4273,10 @@ function useDataLoading({
|
|
|
4161
4273
|
return candidate ?? null;
|
|
4162
4274
|
}, [meta, tableName]);
|
|
4163
4275
|
const tableSchema = useMemo12(() => buildTableSchema(tableMeta), [tableMeta]);
|
|
4276
|
+
const writeCapability = useMemo12(
|
|
4277
|
+
() => tableMeta ? assessTableWriteCapability(tableMeta) : null,
|
|
4278
|
+
[tableMeta]
|
|
4279
|
+
);
|
|
4164
4280
|
const fieldMetaMap = useMemo12(() => {
|
|
4165
4281
|
const candidate = meta?._meta?.tables?.find((t) => t?.name === tableName);
|
|
4166
4282
|
const fields = candidate?.fields || [];
|
|
@@ -4196,8 +4312,12 @@ function useDataLoading({
|
|
|
4196
4312
|
const create = async (payload) => {
|
|
4197
4313
|
const result = await createRow(payload);
|
|
4198
4314
|
const createdRow = result?.createdRow;
|
|
4199
|
-
if (!createdRow || typeof createdRow
|
|
4200
|
-
|
|
4315
|
+
if (!createdRow || typeof createdRow !== "object" || !tableMeta) {
|
|
4316
|
+
throw new Error(`Create mutation for '${tableName}' did not return a row identity.`);
|
|
4317
|
+
}
|
|
4318
|
+
const identity = resolveSheetsRowIdentity(tableMeta, createdRow);
|
|
4319
|
+
if (identity.status !== "identified") {
|
|
4320
|
+
throw new Error(`Create mutation for '${tableName}' returned an incomplete primary-key identity.`);
|
|
4201
4321
|
}
|
|
4202
4322
|
return { createdRow };
|
|
4203
4323
|
};
|
|
@@ -4217,6 +4337,7 @@ function useDataLoading({
|
|
|
4217
4337
|
refetch,
|
|
4218
4338
|
meta,
|
|
4219
4339
|
tableMeta,
|
|
4340
|
+
writeCapability,
|
|
4220
4341
|
tableSchema,
|
|
4221
4342
|
fieldMetaMap,
|
|
4222
4343
|
allRelationFields
|
|
@@ -4233,6 +4354,7 @@ function useDataLoading({
|
|
|
4233
4354
|
refetch,
|
|
4234
4355
|
meta,
|
|
4235
4356
|
tableMeta,
|
|
4357
|
+
writeCapability,
|
|
4236
4358
|
tableSchema,
|
|
4237
4359
|
fieldMetaMap,
|
|
4238
4360
|
allRelationFields
|
|
@@ -4250,7 +4372,8 @@ function buildTableSchema(metaTable) {
|
|
|
4250
4372
|
if (!field) continue;
|
|
4251
4373
|
columns.push(createColumnSchemaFromMeta(field));
|
|
4252
4374
|
}
|
|
4253
|
-
const
|
|
4375
|
+
const identity = getRowIdentityDefinition(metaTable);
|
|
4376
|
+
const primaryKeyFields = identity.status === "keyed" ? identity.fields.map((field) => field.fieldName) : [];
|
|
4254
4377
|
const inflection = metaTable.inflection;
|
|
4255
4378
|
const metadata = {
|
|
4256
4379
|
label: metaTable.name ?? void 0,
|
|
@@ -4387,6 +4510,33 @@ function useSheets(props) {
|
|
|
4387
4510
|
isInitialLoading: ctx.isLoading && rows.length === 0
|
|
4388
4511
|
};
|
|
4389
4512
|
}, [infiniteScroll, infiniteGridData, dataLoadingResult.contextValue]);
|
|
4513
|
+
const writeCapability = useMemo13(() => getSheetsWriteCapability(tableMeta), [tableMeta]);
|
|
4514
|
+
const canCreate = canRunSheetsMutation(writeCapability, "create");
|
|
4515
|
+
const canUpdate = canRunSheetsMutation(writeCapability, "update");
|
|
4516
|
+
const canDelete = canRunSheetsMutation(writeCapability, "delete");
|
|
4517
|
+
const primaryKeyFields = useMemo13(
|
|
4518
|
+
() => new Set(writeCapability?.status === "mutable" ? writeCapability.primaryKeyFields : []),
|
|
4519
|
+
[writeCapability]
|
|
4520
|
+
);
|
|
4521
|
+
const supportsScalarSelfCommit = writeCapability?.status === "mutable" && writeCapability.primaryKeyFields.length === 1 && writeCapability.primaryKeyFields[0] === "id";
|
|
4522
|
+
const readOnlyReason = writeCapability?.status === "read-only" ? "This table is read-only because it has no primary key." : null;
|
|
4523
|
+
const getRowIdentifier = useCallback16(
|
|
4524
|
+
(row) => {
|
|
4525
|
+
if (!tableMeta) return null;
|
|
4526
|
+
const resolution = resolveSheetsRowIdentity(tableMeta, row);
|
|
4527
|
+
return resolution.status === "identified" ? resolution.identifier : null;
|
|
4528
|
+
},
|
|
4529
|
+
[tableMeta]
|
|
4530
|
+
);
|
|
4531
|
+
const getRowId = useCallback16(
|
|
4532
|
+
(row, index) => {
|
|
4533
|
+
const draftMeta = getDraftMeta(row);
|
|
4534
|
+
if (draftMeta) return draftMeta.draftRowId;
|
|
4535
|
+
if (row && tableMeta) return sheetsRowKey(tableMeta, row, index);
|
|
4536
|
+
return `${tableMeta?.schemaName ?? ""}:${tableName}:row:${index}`;
|
|
4537
|
+
},
|
|
4538
|
+
[tableMeta, tableName]
|
|
4539
|
+
);
|
|
4390
4540
|
const lastLoadEmitRef = useRef5(null);
|
|
4391
4541
|
useEffect4(() => {
|
|
4392
4542
|
if (dataError) {
|
|
@@ -4537,7 +4687,11 @@ function useSheets(props) {
|
|
|
4537
4687
|
tableName,
|
|
4538
4688
|
options: { relationChipLimit, relationLabelMaxLength },
|
|
4539
4689
|
relationInfoByField,
|
|
4540
|
-
meta: filterMeta
|
|
4690
|
+
meta: filterMeta,
|
|
4691
|
+
serverRowsReadOnly: !canUpdate,
|
|
4692
|
+
serverReadOnlyFields: primaryKeyFields,
|
|
4693
|
+
getRowIdentifier,
|
|
4694
|
+
supportsScalarSelfCommit
|
|
4541
4695
|
});
|
|
4542
4696
|
const effectiveColumnOrder = useMemo13(() => {
|
|
4543
4697
|
if (columnKeys.length > 0) return columnKeys;
|
|
@@ -4599,9 +4753,11 @@ function useSheets(props) {
|
|
|
4599
4753
|
const gridOpsOptions = useMemo13(
|
|
4600
4754
|
() => ({
|
|
4601
4755
|
onRemoveDraftRow: (draftRowId) => removeDraftRow(tableKey, draftRowId),
|
|
4756
|
+
getRowIdentifier,
|
|
4757
|
+
canDeleteServerRows: canDelete,
|
|
4602
4758
|
feedback: operationFeedback
|
|
4603
4759
|
}),
|
|
4604
|
-
[removeDraftRow, tableKey, operationFeedback]
|
|
4760
|
+
[removeDraftRow, tableKey, getRowIdentifier, canDelete, operationFeedback]
|
|
4605
4761
|
);
|
|
4606
4762
|
const { deleteSelected: baseDeleteSelected } = useGridOperations(
|
|
4607
4763
|
combinedRows,
|
|
@@ -4643,6 +4799,9 @@ function useSheets(props) {
|
|
|
4643
4799
|
updateDraftCell,
|
|
4644
4800
|
tableKey,
|
|
4645
4801
|
update,
|
|
4802
|
+
getRowIdentifier,
|
|
4803
|
+
readOnlyFields: primaryKeyFields,
|
|
4804
|
+
canUpdate,
|
|
4646
4805
|
onCellEdit,
|
|
4647
4806
|
applyOptimisticPatch: applyOptimisticCellPatch
|
|
4648
4807
|
});
|
|
@@ -4660,6 +4819,9 @@ function useSheets(props) {
|
|
|
4660
4819
|
fieldMetaMap,
|
|
4661
4820
|
relationInfoByField,
|
|
4662
4821
|
update,
|
|
4822
|
+
getRowIdentifier,
|
|
4823
|
+
readOnlyFields: primaryKeyFields,
|
|
4824
|
+
canUpdate,
|
|
4663
4825
|
applyOptimisticPatch: applyOptimisticCellPatch,
|
|
4664
4826
|
resyncRow,
|
|
4665
4827
|
editCell,
|
|
@@ -4697,6 +4859,7 @@ function useSheets(props) {
|
|
|
4697
4859
|
if (infiniteScroll) infiniteGridData.invalidate();
|
|
4698
4860
|
}, [infiniteScroll, infiniteGridData]);
|
|
4699
4861
|
const handleRowAppended = useCallback16(async () => {
|
|
4862
|
+
if (!canCreate) return void 0;
|
|
4700
4863
|
if (draftRows.length > 0) {
|
|
4701
4864
|
return serverRowCount + draftRows.length - 1;
|
|
4702
4865
|
}
|
|
@@ -4720,6 +4883,7 @@ function useSheets(props) {
|
|
|
4720
4883
|
tableKey,
|
|
4721
4884
|
draftRows,
|
|
4722
4885
|
serverRowCount,
|
|
4886
|
+
canCreate,
|
|
4723
4887
|
emit
|
|
4724
4888
|
]);
|
|
4725
4889
|
const { selectedRowCount, selectedDraftRowEntries, hasDraftSelection } = useGridSelectionState({
|
|
@@ -4865,6 +5029,11 @@ function useSheets(props) {
|
|
|
4865
5029
|
resizeColumn: gridActions.resizeColumn,
|
|
4866
5030
|
frozenCount,
|
|
4867
5031
|
selectedRowCount,
|
|
5032
|
+
canCreate,
|
|
5033
|
+
canUpdate,
|
|
5034
|
+
canDelete,
|
|
5035
|
+
readOnlyReason,
|
|
5036
|
+
getRowId,
|
|
4868
5037
|
isSubmittingDrafts,
|
|
4869
5038
|
submitDraftButtonDisabled,
|
|
4870
5039
|
submitDraftLabel,
|
|
@@ -5810,7 +5979,7 @@ function parseNumeric(text) {
|
|
|
5810
5979
|
const n = Number(trimmed);
|
|
5811
5980
|
return Number.isFinite(n) ? { ok: true, value: n } : { ok: false, value: null };
|
|
5812
5981
|
}
|
|
5813
|
-
function InlineCellEditor({ value, initialText, numeric, onCommit, onCancel }) {
|
|
5982
|
+
function InlineCellEditor({ ariaLabel, value, initialText, numeric, onCommit, onCancel }) {
|
|
5814
5983
|
const [text, setText] = useState6(() => initialText != null ? initialText : seedText(value));
|
|
5815
5984
|
const inputRef = useRef7(null);
|
|
5816
5985
|
const gridRef = useRef7(null);
|
|
@@ -5854,6 +6023,7 @@ function InlineCellEditor({ value, initialText, numeric, onCommit, onCancel }) {
|
|
|
5854
6023
|
return /* @__PURE__ */ jsx20(
|
|
5855
6024
|
"input",
|
|
5856
6025
|
{
|
|
6026
|
+
"aria-label": ariaLabel,
|
|
5857
6027
|
ref: inputRef,
|
|
5858
6028
|
value: text,
|
|
5859
6029
|
onChange: (e) => setText(e.target.value),
|
|
@@ -5970,15 +6140,15 @@ var SheetsCellHostInner = memo2(
|
|
|
5970
6140
|
draftClasses,
|
|
5971
6141
|
props.className
|
|
5972
6142
|
),
|
|
5973
|
-
children: isDraftActionCell ? /* @__PURE__ */ jsx21(
|
|
6143
|
+
children: isDraftActionCell ? draftAction ? /* @__PURE__ */ jsx21(
|
|
5974
6144
|
DraftActionCellView,
|
|
5975
6145
|
{
|
|
5976
|
-
status: draftAction
|
|
5977
|
-
errored: draftAction
|
|
5978
|
-
disabled: draftAction
|
|
6146
|
+
status: draftAction.status,
|
|
6147
|
+
errored: draftAction.errored,
|
|
6148
|
+
disabled: draftAction.disabled,
|
|
5979
6149
|
onSubmit: submitDraft
|
|
5980
6150
|
}
|
|
5981
|
-
) : props.isEditing ? (
|
|
6151
|
+
) : null : props.isEditing ? (
|
|
5982
6152
|
// Inline (in-cell) edit for the simple text-representable types — a bare <input>
|
|
5983
6153
|
// overlaying the view. `isEditing` is set true ONLY for inline-edit intents (the
|
|
5984
6154
|
// shell short-circuits inline-toggle/overlay/none before here), so the cell kind is
|
|
@@ -5986,6 +6156,7 @@ var SheetsCellHostInner = memo2(
|
|
|
5986
6156
|
/* @__PURE__ */ jsx21(
|
|
5987
6157
|
InlineCellEditor,
|
|
5988
6158
|
{
|
|
6159
|
+
ariaLabel: `Edit ${props.resolution.fieldMeta?.name ?? props.colKey}`,
|
|
5989
6160
|
value: props.value,
|
|
5990
6161
|
initialText: props.inlineInitialText,
|
|
5991
6162
|
numeric: props.resolution.cell.kind === "number",
|
|
@@ -6903,10 +7074,6 @@ var Sheets = forwardRef(SheetsInnerComponent);
|
|
|
6903
7074
|
var EMPTY_OBJ = {};
|
|
6904
7075
|
var noop = () => {
|
|
6905
7076
|
};
|
|
6906
|
-
function rowIdAt(rows, index) {
|
|
6907
|
-
const id = rows[index]?.id;
|
|
6908
|
-
return id != null ? String(id) : String(index);
|
|
6909
|
-
}
|
|
6910
7077
|
var OVERLAY_MARGIN_PX = 12;
|
|
6911
7078
|
var OVERLAY_MIN_BELOW_PX = 320;
|
|
6912
7079
|
function SheetsDomInner({
|
|
@@ -6968,6 +7135,7 @@ function SheetsDomInner({
|
|
|
6968
7135
|
[columnSizing, resizeColumn]
|
|
6969
7136
|
);
|
|
6970
7137
|
const combinedRows = shell.combinedRows;
|
|
7138
|
+
const getRowId = shell.getRowId;
|
|
6971
7139
|
const selection = s.selection.gridSelection;
|
|
6972
7140
|
const setSelection = s.selection.setGridSelection;
|
|
6973
7141
|
const activeCell = selection?.current?.cell;
|
|
@@ -6975,15 +7143,15 @@ function SheetsDomInner({
|
|
|
6975
7143
|
if (!selection) return EMPTY_OBJ;
|
|
6976
7144
|
const map = {};
|
|
6977
7145
|
for (const index of selection.rows.toArray()) {
|
|
6978
|
-
map[
|
|
7146
|
+
map[getRowId(combinedRows[index], index)] = true;
|
|
6979
7147
|
}
|
|
6980
7148
|
return map;
|
|
6981
|
-
}, [selection, combinedRows]);
|
|
7149
|
+
}, [selection, combinedRows, getRowId]);
|
|
6982
7150
|
const onRowSelectionChange = useCallback19(
|
|
6983
7151
|
(updater) => {
|
|
6984
7152
|
const next = functionalUpdate(updater, rowSelection);
|
|
6985
7153
|
const indexById = /* @__PURE__ */ new Map();
|
|
6986
|
-
for (let i = 0; i < combinedRows.length; i++) indexById.set(
|
|
7154
|
+
for (let i = 0; i < combinedRows.length; i++) indexById.set(getRowId(combinedRows[i], i), i);
|
|
6987
7155
|
let rows = RangeSet.empty();
|
|
6988
7156
|
let lowest;
|
|
6989
7157
|
for (const id of Object.keys(next)) {
|
|
@@ -6999,7 +7167,7 @@ function SheetsDomInner({
|
|
|
6999
7167
|
}
|
|
7000
7168
|
setSelection({ current: { cell: [0, lowest] }, rows, columns: RangeSet.empty() });
|
|
7001
7169
|
},
|
|
7002
|
-
[rowSelection, combinedRows, setSelection]
|
|
7170
|
+
[rowSelection, combinedRows, getRowId, setSelection]
|
|
7003
7171
|
);
|
|
7004
7172
|
const table = useSheetsTableInstance({
|
|
7005
7173
|
columns,
|
|
@@ -7010,7 +7178,8 @@ function SheetsDomInner({
|
|
|
7010
7178
|
onColumnSizingChange,
|
|
7011
7179
|
// Pinning is shell-derived (frozenCount), never edited from the grid → no writer needed.
|
|
7012
7180
|
onColumnPinningChange: noop,
|
|
7013
|
-
onRowSelectionChange
|
|
7181
|
+
onRowSelectionChange,
|
|
7182
|
+
getRowId
|
|
7014
7183
|
});
|
|
7015
7184
|
const rowCount = combinedRows.length;
|
|
7016
7185
|
const shiftAnchorRef = useRef10(null);
|
|
@@ -7325,7 +7494,7 @@ function SheetsDomInner({
|
|
|
7325
7494
|
value: rowValue,
|
|
7326
7495
|
cell: resolution.cell,
|
|
7327
7496
|
colKey: active.colKey,
|
|
7328
|
-
rowId:
|
|
7497
|
+
rowId: getRowId(combinedRows[active.rowIndex], active.rowIndex),
|
|
7329
7498
|
rowIndex: active.rowIndex,
|
|
7330
7499
|
tableName: props.tableName,
|
|
7331
7500
|
fieldMeta: resolution.fieldMeta,
|
|
@@ -7424,9 +7593,10 @@ function SheetsDomInner({
|
|
|
7424
7593
|
SheetsEmptyState,
|
|
7425
7594
|
{
|
|
7426
7595
|
tableName,
|
|
7427
|
-
|
|
7596
|
+
readOnlyReason: shell.readOnlyReason,
|
|
7597
|
+
onAddRow: shell.canCreate ? () => {
|
|
7428
7598
|
void s.draft.appendRow();
|
|
7429
|
-
}
|
|
7599
|
+
} : void 0
|
|
7430
7600
|
}
|
|
7431
7601
|
);
|
|
7432
7602
|
}
|
|
@@ -7448,7 +7618,9 @@ function SheetsDomInner({
|
|
|
7448
7618
|
gridSelection: s.selection.gridSelection ?? null,
|
|
7449
7619
|
setGridSelection: shell.setGridSelectionForControls,
|
|
7450
7620
|
deleteSelected: s.draft.deleteSelected,
|
|
7451
|
-
onAddRow: handleAddRow,
|
|
7621
|
+
onAddRow: shell.canCreate ? handleAddRow : void 0,
|
|
7622
|
+
canDelete: shell.canDelete,
|
|
7623
|
+
readOnlyReason: shell.readOnlyReason,
|
|
7452
7624
|
onExport: handleExport
|
|
7453
7625
|
}
|
|
7454
7626
|
) }),
|
|
@@ -7531,7 +7703,9 @@ function SheetsDomInner({
|
|
|
7531
7703
|
isEnabled: isCommandEnabled,
|
|
7532
7704
|
onAddRow: handleAddRow,
|
|
7533
7705
|
onDeleteRows: s.draft.deleteSelected,
|
|
7534
|
-
selectedRowCount: selection?.rows.length ?? 0
|
|
7706
|
+
selectedRowCount: selection?.rows.length ?? 0,
|
|
7707
|
+
canAddRows: shell.canCreate,
|
|
7708
|
+
canDeleteRows: shell.canDelete
|
|
7535
7709
|
}
|
|
7536
7710
|
)
|
|
7537
7711
|
] });
|
|
@@ -7575,17 +7749,21 @@ var BLUR_HEIGHT_MAX_PX = 140;
|
|
|
7575
7749
|
var TableItem = memo3(function TableItem2({ table, activeTable, onTableSelect, itemRef }) {
|
|
7576
7750
|
const isActive = activeTable === table.value;
|
|
7577
7751
|
return /* @__PURE__ */ jsx25(
|
|
7578
|
-
|
|
7752
|
+
Button7,
|
|
7579
7753
|
{
|
|
7580
7754
|
ref: isActive ? itemRef : void 0,
|
|
7755
|
+
"aria-pressed": isActive,
|
|
7581
7756
|
"data-testid": "table-item",
|
|
7757
|
+
static: true,
|
|
7758
|
+
size: "sm",
|
|
7759
|
+
type: "button",
|
|
7760
|
+
variant: "ghost",
|
|
7582
7761
|
className: cn(
|
|
7583
|
-
|
|
7584
|
-
duration-200`,
|
|
7762
|
+
"group relative my-1 flex h-8 w-full shrink items-center justify-between rounded-lg px-2 text-left text-xs font-normal transition-colors duration-150",
|
|
7585
7763
|
isActive ? "bg-primary/10 text-foreground ring-primary/30 dark:bg-primary/15 dark:ring-primary/40 ring-1" : "text-muted-foreground hover:text-foreground"
|
|
7586
7764
|
),
|
|
7587
7765
|
onClick: () => onTableSelect(table.value),
|
|
7588
|
-
children: /* @__PURE__ */ jsx25("
|
|
7766
|
+
children: /* @__PURE__ */ jsx25("span", { className: "flex min-w-0 flex-1 items-center", children: /* @__PURE__ */ jsxs14(Tooltip, { children: [
|
|
7589
7767
|
/* @__PURE__ */ jsx25(TooltipTrigger, { asChild: true, children: /* @__PURE__ */ jsx25("span", { className: "truncate text-xs", children: table.label }) }),
|
|
7590
7768
|
/* @__PURE__ */ jsx25(TooltipContent, { side: "right", align: "start", children: /* @__PURE__ */ jsx25("span", { className: "text-xs font-medium", children: table.label }) })
|
|
7591
7769
|
] }) })
|
|
@@ -7949,7 +8127,8 @@ function createScalarFieldSpec(metaField, options, uniqueFields, primaryFields)
|
|
|
7949
8127
|
isArray: metaField.type.isArray,
|
|
7950
8128
|
pgAlias: metaField.type.pgAlias,
|
|
7951
8129
|
pgType: metaField.type.pgType,
|
|
7952
|
-
subtype: metaField.type.subtype ?? void 0
|
|
8130
|
+
subtype: metaField.type.subtype ?? void 0,
|
|
8131
|
+
encoding: metaField.type.encoding
|
|
7953
8132
|
});
|
|
7954
8133
|
if (metaField.type.isArray) {
|
|
7955
8134
|
return null;
|
|
@@ -7977,13 +8156,17 @@ function createScalarFieldSpec(metaField, options, uniqueFields, primaryFields)
|
|
|
7977
8156
|
pgAlias: metaField.type.pgAlias ?? void 0,
|
|
7978
8157
|
pgType: metaField.type.pgType ?? void 0,
|
|
7979
8158
|
subtype: metaField.type.subtype ?? void 0,
|
|
7980
|
-
typmod: metaField.type.typmod ?? void 0
|
|
8159
|
+
typmod: metaField.type.typmod ?? void 0,
|
|
8160
|
+
encoding: metaField.type.encoding ?? void 0
|
|
7981
8161
|
},
|
|
7982
8162
|
constraints: {
|
|
7983
8163
|
isUnique: uniqueFields.has(metaField.name) || void 0,
|
|
7984
8164
|
isPrimaryKey: primaryFields.has(metaField.name) || void 0
|
|
7985
8165
|
}
|
|
7986
8166
|
};
|
|
8167
|
+
if (metaField.enumValues?.values?.length) {
|
|
8168
|
+
spec.enumValues = [...metaField.enumValues.values];
|
|
8169
|
+
}
|
|
7987
8170
|
if (maxLength != null) {
|
|
7988
8171
|
spec.maxLength = maxLength;
|
|
7989
8172
|
}
|
|
@@ -8007,6 +8190,7 @@ function createScalarFieldSpec(metaField, options, uniqueFields, primaryFields)
|
|
|
8007
8190
|
return spec;
|
|
8008
8191
|
}
|
|
8009
8192
|
function buildDescription(metaField) {
|
|
8193
|
+
if (metaField.description) return metaField.description;
|
|
8010
8194
|
const details = [];
|
|
8011
8195
|
const { pgAlias, pgType, subtype } = metaField.type;
|
|
8012
8196
|
if (pgAlias && pgAlias !== pgType) {
|
|
@@ -8024,6 +8208,7 @@ function humanize(name) {
|
|
|
8024
8208
|
return name.replace(HUMAN_CASE_REGEX, "$1 $2").replace(/^./, (str) => str.toUpperCase());
|
|
8025
8209
|
}
|
|
8026
8210
|
function isFieldNullable(metaField) {
|
|
8211
|
+
if (metaField.isNotNull === true || metaField.type.isNotNull === true) return false;
|
|
8027
8212
|
const gqlType = metaField.type.gqlType;
|
|
8028
8213
|
if (gqlType.endsWith("!")) return false;
|
|
8029
8214
|
return true;
|
|
@@ -8438,6 +8623,7 @@ export {
|
|
|
8438
8623
|
buildRelationInfoFromMeta,
|
|
8439
8624
|
buildScalarFormSpec,
|
|
8440
8625
|
buildZodSchema,
|
|
8626
|
+
canRunSheetsMutation,
|
|
8441
8627
|
clear as clearSheetsSelection,
|
|
8442
8628
|
computeDraftMetaSignature,
|
|
8443
8629
|
countConditions,
|
|
@@ -8457,6 +8643,7 @@ export {
|
|
|
8457
8643
|
findTableFormSpec,
|
|
8458
8644
|
getCellsInRange,
|
|
8459
8645
|
getDraftMeta,
|
|
8646
|
+
getSheetsWriteCapability,
|
|
8460
8647
|
isArrayCellType,
|
|
8461
8648
|
isDraftRow,
|
|
8462
8649
|
isImageField,
|
|
@@ -8468,10 +8655,15 @@ export {
|
|
|
8468
8655
|
sheetsTableQueryKeys as queryKeys,
|
|
8469
8656
|
resolveCellType,
|
|
8470
8657
|
resolveDownloadUrl,
|
|
8658
|
+
resolveSheetsIdentifier,
|
|
8659
|
+
resolveSheetsRowIdentity,
|
|
8471
8660
|
selectCell,
|
|
8472
8661
|
selectRange,
|
|
8473
8662
|
selectRow,
|
|
8663
|
+
sheetsIdentifierCacheKey,
|
|
8664
|
+
sheetsIdentifierToWhere,
|
|
8474
8665
|
sheetsQueryKeys,
|
|
8666
|
+
sheetsRowKey,
|
|
8475
8667
|
toTSV,
|
|
8476
8668
|
toggleRow,
|
|
8477
8669
|
tokensFromCssVars,
|