@constructive-io/schema-builder 0.7.1 → 0.9.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/CHANGELOG.md +25 -0
- package/dist/{create-table-card-COzwEhdq.js → create-table-card-Cp96Mwkr.js} +13 -13
- package/dist/{create-table-card-COzwEhdq.js.map → create-table-card-Cp96Mwkr.js.map} +1 -1
- package/dist/{create-table-card--0VzN5yH.cjs → create-table-card-DXN0SCsn.cjs} +13 -13
- package/dist/{create-table-card--0VzN5yH.cjs.map → create-table-card-DXN0SCsn.cjs.map} +1 -1
- package/dist/editor-view-C5z6x0St.js +100 -0
- package/dist/editor-view-C5z6x0St.js.map +1 -0
- package/dist/editor-view-CKrOtZX_.cjs +141 -0
- package/dist/editor-view-CKrOtZX_.cjs.map +1 -0
- package/dist/{empty-state-card-5t7LygTB.cjs → empty-state-card-CV7DnIsA.cjs} +25 -17
- package/dist/empty-state-card-CV7DnIsA.cjs.map +1 -0
- package/dist/{empty-state-card-C-Nylatg.js → empty-state-card-sYoB01xr.js} +25 -17
- package/dist/empty-state-card-sYoB01xr.js.map +1 -0
- package/dist/fields.cjs +1 -1
- package/dist/fields.js +1 -1
- package/dist/index.cjs +70 -47
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +71 -48
- package/dist/index.js.map +1 -1
- package/dist/{indexes-view-CVZLjX89.cjs → indexes-view-BhRQc36j.cjs} +96 -125
- package/dist/indexes-view-BhRQc36j.cjs.map +1 -0
- package/dist/{indexes-view-C459lTHp.js → indexes-view-BkRtR8bd.js} +97 -126
- package/dist/indexes-view-BkRtR8bd.js.map +1 -0
- package/dist/indexes.cjs +1 -1
- package/dist/indexes.js +1 -1
- package/dist/{policies-view-CQP9A-ag.cjs → policies-view-DJTfKoYr.cjs} +192 -175
- package/dist/policies-view-DJTfKoYr.cjs.map +1 -0
- package/dist/{policies-view-A-FmHKS3.js → policies-view-OPigTnq3.js} +195 -178
- package/dist/policies-view-OPigTnq3.js.map +1 -0
- package/dist/policies.cjs +3 -3
- package/dist/policies.js +3 -3
- package/dist/{policy-config-form-BdbAHY7a.cjs → policy-config-form-CvHIN2iR.cjs} +5 -5
- package/dist/{policy-config-form-BdbAHY7a.cjs.map → policy-config-form-CvHIN2iR.cjs.map} +1 -1
- package/dist/{policy-config-form-Bx7TWk3Q.js → policy-config-form-PuVpbmcl.js} +5 -5
- package/dist/{policy-config-form-Bx7TWk3Q.js.map → policy-config-form-PuVpbmcl.js.map} +1 -1
- package/dist/{relationships-view-BQc_AHUo.cjs → relationships-view-CtPwFiIi.cjs} +210 -267
- package/dist/relationships-view-CtPwFiIi.cjs.map +1 -0
- package/dist/{relationships-view-QhPgBPiK.js → relationships-view-Db7zZAyz.js} +211 -268
- package/dist/relationships-view-Db7zZAyz.js.map +1 -0
- package/dist/relationships.cjs +1 -1
- package/dist/relationships.js +1 -1
- package/dist/{schema-builder-sidebar-Dv99hNGo.cjs → schema-builder-sidebar-BwpMkqyr.cjs} +135 -94
- package/dist/schema-builder-sidebar-BwpMkqyr.cjs.map +1 -0
- package/dist/{schema-builder-sidebar-CRwUC03L.js → schema-builder-sidebar-C3MMtjfg.js} +136 -95
- package/dist/schema-builder-sidebar-C3MMtjfg.js.map +1 -0
- package/dist/{table-editor-tS9seYfW.cjs → table-editor-CruD2mZQ.cjs} +414 -477
- package/dist/table-editor-CruD2mZQ.cjs.map +1 -0
- package/dist/{table-editor-5bkA0pji.js → table-editor-D80Qu4QF.js} +415 -478
- package/dist/table-editor-D80Qu4QF.js.map +1 -0
- package/dist/tables.cjs +1 -1
- package/dist/tables.d.cts +3 -1
- package/dist/tables.d.ts +3 -1
- package/dist/tables.js +1 -1
- package/package.json +8 -8
- package/dist/empty-state-card-5t7LygTB.cjs.map +0 -1
- package/dist/empty-state-card-C-Nylatg.js.map +0 -1
- package/dist/indexes-view-C459lTHp.js.map +0 -1
- package/dist/indexes-view-CVZLjX89.cjs.map +0 -1
- package/dist/policies-view-A-FmHKS3.js.map +0 -1
- package/dist/policies-view-CQP9A-ag.cjs.map +0 -1
- package/dist/relationships-view-BQc_AHUo.cjs.map +0 -1
- package/dist/relationships-view-QhPgBPiK.js.map +0 -1
- package/dist/schema-builder-sidebar-CRwUC03L.js.map +0 -1
- package/dist/schema-builder-sidebar-Dv99hNGo.cjs.map +0 -1
- package/dist/table-editor-5bkA0pji.js.map +0 -1
- package/dist/table-editor-tS9seYfW.cjs.map +0 -1
|
@@ -3,14 +3,14 @@ import { A as useDeleteUniqueConstraintMutation, B as getAllFieldTypes, C as use
|
|
|
3
3
|
import { a as useTypesLibraryExpanded, c as springs, i as useToggleTypesLibraryExpanded, o as durations, s as easings, t as useUpdateTable } from "./use-update-table-DlLX9fdE.js";
|
|
4
4
|
import { t as CARD_WIDTHS } from "./card-widths-pI4Kw4Xz.js";
|
|
5
5
|
import { t as handleActivationKeyDown } from "./keyboard-activation-BQiV0scm.js";
|
|
6
|
-
import { t as EmptyStateCard } from "./empty-state-card-
|
|
7
|
-
import { t as CreateTableCard } from "./create-table-card-
|
|
6
|
+
import { t as EmptyStateCard } from "./empty-state-card-sYoB01xr.js";
|
|
7
|
+
import { t as CreateTableCard } from "./create-table-card-Cp96Mwkr.js";
|
|
8
8
|
import { useCardStack } from "@constructive-io/ui/stack";
|
|
9
9
|
import { AnimatePresence, motion } from "motion/react";
|
|
10
10
|
import { memo, startTransition, useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
11
11
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
12
12
|
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@constructive-io/ui/tooltip";
|
|
13
|
-
import { RiDragDropLine, RiFingerprintLine, RiKey2Line, RiSearchLine,
|
|
13
|
+
import { RiDragDropLine, RiFingerprintLine, RiKey2Line, RiSearchLine, RiSparklingLine } from "@remixicon/react";
|
|
14
14
|
import { Check, ChevronLeft, ChevronRight, ChevronsUpDownIcon, CircleDot, Database, Fingerprint, Key, Loader2, Lock, Plus, Table2, Trash2, X, Zap } from "lucide-react";
|
|
15
15
|
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
|
16
16
|
import { Button } from "@constructive-io/ui/button";
|
|
@@ -19,9 +19,9 @@ import { CSS } from "@dnd-kit/utilities";
|
|
|
19
19
|
import { toast } from "@constructive-io/ui/toast";
|
|
20
20
|
import { Combobox, ComboboxEmpty, ComboboxInput, ComboboxItem, ComboboxList, ComboboxPopup, ComboboxTrigger } from "@constructive-io/ui/combobox";
|
|
21
21
|
import { Input } from "@constructive-io/ui/input";
|
|
22
|
-
import { Label } from "@constructive-io/ui/label";
|
|
23
22
|
import { ScrollArea } from "@constructive-io/ui/scroll-area";
|
|
24
23
|
import { Checkbox } from "@constructive-io/ui/checkbox";
|
|
24
|
+
import { Label } from "@constructive-io/ui/label";
|
|
25
25
|
import { Collapsible, CollapsibleTrigger } from "@constructive-io/ui/collapsible";
|
|
26
26
|
import { InputGroup, InputGroupAddon, InputGroupInput } from "@constructive-io/ui/input-group";
|
|
27
27
|
|
|
@@ -61,32 +61,32 @@ const DraggableFieldType = memo(function DraggableFieldType({ typeInfo, isDraggi
|
|
|
61
61
|
style,
|
|
62
62
|
...listeners,
|
|
63
63
|
...attributes,
|
|
64
|
-
|
|
65
|
-
|
|
64
|
+
title: typeInfo.description,
|
|
65
|
+
className: cn("group flex h-9 cursor-grab items-center gap-2.5 rounded-lg px-2 active:cursor-grabbing", "touch-none select-none hover:bg-overlay-hover outline-none focus-visible:ring-[3px] focus-visible:ring-ring/50", {
|
|
66
66
|
"opacity-50": isBeingDragged && !isDragging,
|
|
67
|
-
"
|
|
67
|
+
"bg-card shadow-card-lg": isDragging
|
|
68
68
|
}, className),
|
|
69
69
|
children: [
|
|
70
|
-
/* @__PURE__ */ jsx("
|
|
71
|
-
className: "bg-muted
|
|
72
|
-
children: IconComponent ? /* @__PURE__ */ jsx(IconComponent, { className: "
|
|
73
|
-
className: "font-mono text-
|
|
70
|
+
/* @__PURE__ */ jsx("span", {
|
|
71
|
+
className: "bg-muted text-muted-foreground group-hover:text-foreground grid size-6 shrink-0 place-items-center rounded-md",
|
|
72
|
+
children: IconComponent ? /* @__PURE__ */ jsx(IconComponent, { className: "size-3.5" }) : /* @__PURE__ */ jsx("span", {
|
|
73
|
+
className: "font-mono text-[11px] font-medium",
|
|
74
74
|
children: typeInfo.type.charAt(0).toUpperCase()
|
|
75
75
|
})
|
|
76
76
|
}),
|
|
77
|
-
/* @__PURE__ */ jsxs("
|
|
78
|
-
className: "min-w-0 flex-1",
|
|
77
|
+
/* @__PURE__ */ jsxs("span", {
|
|
78
|
+
className: "flex min-w-0 flex-1 items-baseline gap-2",
|
|
79
79
|
children: [/* @__PURE__ */ jsx("span", {
|
|
80
|
-
className: "text-foreground
|
|
80
|
+
className: "text-foreground shrink-0 text-[13px]",
|
|
81
81
|
children: typeInfo.label
|
|
82
|
-
}), /* @__PURE__ */ jsx("
|
|
83
|
-
className: "text-muted-foreground truncate text-xs",
|
|
82
|
+
}), /* @__PURE__ */ jsx("span", {
|
|
83
|
+
className: "text-muted-foreground min-w-0 truncate text-xs",
|
|
84
84
|
children: typeInfo.description
|
|
85
85
|
})]
|
|
86
86
|
}),
|
|
87
|
-
/* @__PURE__ */ jsx(
|
|
88
|
-
|
|
89
|
-
|
|
87
|
+
/* @__PURE__ */ jsx(RiDragDropLine, {
|
|
88
|
+
"aria-hidden": "true",
|
|
89
|
+
className: "text-muted-foreground size-3.5 shrink-0 opacity-0 group-hover:opacity-100"
|
|
90
90
|
})
|
|
91
91
|
]
|
|
92
92
|
});
|
|
@@ -113,18 +113,16 @@ function DraggableFieldTypeIcon({ typeInfo, isDragging = false, className }) {
|
|
|
113
113
|
...listeners,
|
|
114
114
|
...attributes,
|
|
115
115
|
"aria-label": `Drag ${typeInfo.label} field type`,
|
|
116
|
-
className: cn(
|
|
117
|
-
transition-[background-color,border-color,box-shadow,opacity] duration-150 ease-out active:cursor-grabbing`, "flex items-center justify-center", "touch-none select-none", {
|
|
116
|
+
className: cn("group bg-card shadow-card hover:bg-muted relative flex aspect-square w-10 cursor-grab items-center justify-center rounded-lg active:cursor-grabbing", "touch-none select-none outline-none focus-visible:ring-[3px] focus-visible:ring-ring/50", {
|
|
118
117
|
"opacity-50": isBeingDragged && !isDragging,
|
|
119
|
-
"
|
|
120
|
-
"hover:border-primary/40 hover:shadow-sm": !isBeingDragged
|
|
118
|
+
"shadow-card-lg": isDragging
|
|
121
119
|
}, className),
|
|
122
120
|
type: "button",
|
|
123
|
-
children: [IconComponent ? /* @__PURE__ */ jsx(IconComponent, { className: cn("text-
|
|
124
|
-
className: "text-
|
|
121
|
+
children: [IconComponent ? /* @__PURE__ */ jsx(IconComponent, { className: cn("text-foreground/70 size-4", "group-hover:text-foreground") }) : /* @__PURE__ */ jsx("span", {
|
|
122
|
+
className: "text-foreground/70 group-hover:text-foreground font-mono text-xs font-medium",
|
|
125
123
|
children: typeInfo.type.charAt(0).toUpperCase()
|
|
126
124
|
}), badge && /* @__PURE__ */ jsx("span", {
|
|
127
|
-
className: cn("absolute inset-x-0 bottom-0.5", "flex items-center justify-center", "text-muted-foreground
|
|
125
|
+
className: cn("absolute inset-x-0 bottom-0.5", "flex items-center justify-center", "text-muted-foreground group-hover:text-foreground/70", "font-mono text-[7px] font-medium uppercase leading-none tracking-wide"),
|
|
128
126
|
children: badge
|
|
129
127
|
})]
|
|
130
128
|
})
|
|
@@ -414,233 +412,188 @@ function useUpdateFieldOrder() {
|
|
|
414
412
|
//#region src/schema/schema-builder-fields/components/table-editor/constraint-card.tsx
|
|
415
413
|
const CONSTRAINT_CONFIG = {
|
|
416
414
|
primaryKey: {
|
|
417
|
-
label: "Primary
|
|
415
|
+
label: "Primary key",
|
|
418
416
|
description: "Uniquely identifies each row (automatically sets UNIQUE + NOT NULL)",
|
|
419
|
-
badge: "PK",
|
|
420
417
|
icon: Key,
|
|
421
|
-
|
|
422
|
-
selected: "ring-2 ring-blue-500/50 bg-blue-500/5",
|
|
423
|
-
badge: "bg-blue-500/10 text-blue-600 border-blue-500/20",
|
|
424
|
-
icon: "text-blue-500"
|
|
425
|
-
}
|
|
418
|
+
tint: "text-blue-600 dark:text-blue-400"
|
|
426
419
|
},
|
|
427
420
|
unique: {
|
|
428
421
|
label: "Unique",
|
|
429
422
|
description: "All values in this column must be different",
|
|
430
|
-
badge: "UNIQUE",
|
|
431
423
|
icon: Fingerprint,
|
|
432
|
-
|
|
433
|
-
selected: "ring-2 ring-purple-500/50 bg-purple-500/5",
|
|
434
|
-
badge: "bg-purple-500/10 text-purple-600 border-purple-500/20",
|
|
435
|
-
icon: "text-purple-500"
|
|
436
|
-
}
|
|
424
|
+
tint: "text-purple-600 dark:text-purple-400"
|
|
437
425
|
},
|
|
438
426
|
nullable: {
|
|
439
427
|
label: "Nullable",
|
|
440
428
|
description: "Allow NULL values in this column",
|
|
441
|
-
badge: "NULLABLE",
|
|
442
429
|
icon: CircleDot,
|
|
443
|
-
|
|
444
|
-
selected: "ring-2 ring-green-500/50 bg-green-500/5",
|
|
445
|
-
badge: "bg-green-500/10 text-green-600 border-green-500/20",
|
|
446
|
-
icon: "text-green-500"
|
|
447
|
-
}
|
|
430
|
+
tint: "text-green-600 dark:text-green-400"
|
|
448
431
|
}
|
|
449
432
|
};
|
|
433
|
+
/**
|
|
434
|
+
* A checkbox with room for an explanation. The whole card is the checkbox's
|
|
435
|
+
* label, so it toggles like one: no press animation, just the tick and a
|
|
436
|
+
* quiet selected surface.
|
|
437
|
+
*/
|
|
450
438
|
function ConstraintCard({ type, selected, disabled, disabledReason, onToggle }) {
|
|
451
|
-
const
|
|
452
|
-
const
|
|
453
|
-
return /* @__PURE__ */ jsxs("
|
|
454
|
-
className: cn(
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
}),
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
]
|
|
482
|
-
})
|
|
483
|
-
]
|
|
484
|
-
}), /* @__PURE__ */ jsx("p", {
|
|
485
|
-
className: "text-muted-foreground text-xs leading-relaxed",
|
|
486
|
-
children: config.description
|
|
439
|
+
const { label, description, icon: Icon, tint } = CONSTRAINT_CONFIG[type];
|
|
440
|
+
const active = selected && !disabled;
|
|
441
|
+
return /* @__PURE__ */ jsxs("label", {
|
|
442
|
+
className: cn("flex items-center gap-3 rounded-lg border px-3 py-2.5", disabled ? "cursor-not-allowed opacity-60" : "cursor-pointer", active ? "border-primary/35 bg-primary/[0.04]" : cn("border-border bg-card", !disabled && "hover:bg-overlay-hover")),
|
|
443
|
+
children: [
|
|
444
|
+
/* @__PURE__ */ jsx("span", {
|
|
445
|
+
className: cn("grid size-7 shrink-0 place-items-center rounded-md", active ? cn("bg-background", tint) : "bg-muted text-muted-foreground"),
|
|
446
|
+
children: /* @__PURE__ */ jsx(Icon, {
|
|
447
|
+
"aria-hidden": "true",
|
|
448
|
+
className: "size-3.5"
|
|
449
|
+
})
|
|
450
|
+
}),
|
|
451
|
+
/* @__PURE__ */ jsxs("span", {
|
|
452
|
+
className: "flex min-w-0 flex-1 flex-col gap-0.5",
|
|
453
|
+
children: [/* @__PURE__ */ jsxs("span", {
|
|
454
|
+
className: "flex items-baseline gap-1.5",
|
|
455
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
456
|
+
className: "text-foreground text-[13px] font-medium",
|
|
457
|
+
children: label
|
|
458
|
+
}), disabled && disabledReason ? /* @__PURE__ */ jsxs("span", {
|
|
459
|
+
className: "text-muted-foreground text-xs",
|
|
460
|
+
children: [
|
|
461
|
+
"(",
|
|
462
|
+
disabledReason,
|
|
463
|
+
")"
|
|
464
|
+
]
|
|
465
|
+
}) : null]
|
|
466
|
+
}), /* @__PURE__ */ jsx("span", {
|
|
467
|
+
className: "text-muted-foreground text-xs",
|
|
468
|
+
children: description
|
|
487
469
|
})]
|
|
488
|
-
})
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
470
|
+
}),
|
|
471
|
+
/* @__PURE__ */ jsx(Checkbox, {
|
|
472
|
+
checked: selected,
|
|
473
|
+
className: "shrink-0",
|
|
474
|
+
disabled,
|
|
475
|
+
onCheckedChange: () => onToggle()
|
|
476
|
+
})
|
|
477
|
+
]
|
|
478
|
+
});
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
//#endregion
|
|
482
|
+
//#region src/schema/schema-builder-fields/components/table-editor/form-field.tsx
|
|
483
|
+
/**
|
|
484
|
+
* One labelled control with an optional hint. Every field in the field
|
|
485
|
+
* editor uses it, so the rhythm stays the same everywhere: 8px from label to
|
|
486
|
+
* control, 6px from control to hint.
|
|
487
|
+
*/
|
|
488
|
+
function FormField({ label, htmlFor, hint, subtle = false, children, className }) {
|
|
489
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
490
|
+
className: cn("flex min-w-0 flex-col gap-2", className),
|
|
491
|
+
children: [/* @__PURE__ */ jsx(Label, {
|
|
492
|
+
className: subtle ? "text-muted-foreground text-xs" : void 0,
|
|
493
|
+
htmlFor,
|
|
494
|
+
children: label
|
|
495
|
+
}), /* @__PURE__ */ jsxs("div", {
|
|
496
|
+
className: "flex flex-col gap-1.5",
|
|
497
|
+
children: [children, hint ? /* @__PURE__ */ jsx("p", {
|
|
498
|
+
className: "text-muted-foreground text-xs",
|
|
499
|
+
children: hint
|
|
500
|
+
}) : null]
|
|
495
501
|
})]
|
|
496
502
|
});
|
|
497
503
|
}
|
|
504
|
+
/** A titled group of fields, such as Constraints or Validation rules. */
|
|
505
|
+
function FormSection({ title, children }) {
|
|
506
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
507
|
+
className: "flex flex-col gap-2",
|
|
508
|
+
children: [/* @__PURE__ */ jsx(Label, { children: title }), children]
|
|
509
|
+
});
|
|
510
|
+
}
|
|
498
511
|
|
|
499
512
|
//#endregion
|
|
500
513
|
//#region src/schema/schema-builder-fields/components/table-editor/validation-rules-section.tsx
|
|
514
|
+
const LENGTH_RULES = [{
|
|
515
|
+
key: "minLength",
|
|
516
|
+
label: "Min length",
|
|
517
|
+
placeholder: "e.g., 3"
|
|
518
|
+
}, {
|
|
519
|
+
key: "maxLength",
|
|
520
|
+
label: "Max length",
|
|
521
|
+
placeholder: "e.g., 255"
|
|
522
|
+
}];
|
|
523
|
+
const RANGE_RULES = [{
|
|
524
|
+
key: "minValue",
|
|
525
|
+
label: "Min value",
|
|
526
|
+
placeholder: "e.g., 0",
|
|
527
|
+
decimal: true
|
|
528
|
+
}, {
|
|
529
|
+
key: "maxValue",
|
|
530
|
+
label: "Max value",
|
|
531
|
+
placeholder: "e.g., 100",
|
|
532
|
+
decimal: true
|
|
533
|
+
}];
|
|
534
|
+
const PRECISION_RULE = {
|
|
535
|
+
key: "precision",
|
|
536
|
+
label: "Precision",
|
|
537
|
+
placeholder: "e.g., 10",
|
|
538
|
+
hint: "Total digits"
|
|
539
|
+
};
|
|
540
|
+
const SCALE_RULE = {
|
|
541
|
+
key: "scale",
|
|
542
|
+
label: "Scale",
|
|
543
|
+
placeholder: "e.g., 2",
|
|
544
|
+
hint: "Decimal places"
|
|
545
|
+
};
|
|
501
546
|
function ValidationRulesSection({ dataType, values, onChange, disabled }) {
|
|
502
547
|
const configurable = getFieldTypeInfo(dataType)?.configurable;
|
|
503
|
-
if (!
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
disabled
|
|
540
|
-
})]
|
|
541
|
-
})]
|
|
542
|
-
}),
|
|
543
|
-
configurable.pattern && /* @__PURE__ */ jsxs("div", {
|
|
544
|
-
className: "space-y-2",
|
|
545
|
-
children: [
|
|
546
|
-
/* @__PURE__ */ jsx(Label, {
|
|
547
|
-
htmlFor: "pattern",
|
|
548
|
-
className: "text-muted-foreground text-xs",
|
|
549
|
-
children: "Regex Pattern"
|
|
550
|
-
}),
|
|
551
|
-
/* @__PURE__ */ jsx(Input, {
|
|
548
|
+
if (!configurable) return null;
|
|
549
|
+
const numericRows = [[...configurable.precision ? [PRECISION_RULE] : [], ...configurable.scale ? [SCALE_RULE] : []], configurable.range ? RANGE_RULES : []].filter((row) => row.length > 0);
|
|
550
|
+
if (!configurable.length && !configurable.pattern && numericRows.length === 0) return null;
|
|
551
|
+
const numberField = ({ key, label, placeholder, hint, decimal }) => /* @__PURE__ */ jsx(FormField, {
|
|
552
|
+
hint,
|
|
553
|
+
htmlFor: key,
|
|
554
|
+
label,
|
|
555
|
+
subtle: true,
|
|
556
|
+
children: /* @__PURE__ */ jsx(Input, {
|
|
557
|
+
disabled,
|
|
558
|
+
id: key,
|
|
559
|
+
onChange: (e) => onChange(key, e.target.value ? (decimal ? parseFloat : parseInt)(e.target.value) : void 0),
|
|
560
|
+
placeholder,
|
|
561
|
+
type: "number",
|
|
562
|
+
value: values[key] ?? ""
|
|
563
|
+
})
|
|
564
|
+
}, key);
|
|
565
|
+
return /* @__PURE__ */ jsx(FormSection, {
|
|
566
|
+
title: /* @__PURE__ */ jsxs(Fragment, { children: ["Validation rules ", /* @__PURE__ */ jsx("span", {
|
|
567
|
+
className: "text-muted-foreground",
|
|
568
|
+
children: "(optional)"
|
|
569
|
+
})] }),
|
|
570
|
+
children: /* @__PURE__ */ jsxs("div", {
|
|
571
|
+
className: "flex flex-col gap-4",
|
|
572
|
+
children: [
|
|
573
|
+
configurable.length ? /* @__PURE__ */ jsx("div", {
|
|
574
|
+
className: "grid grid-cols-2 gap-4",
|
|
575
|
+
children: LENGTH_RULES.map(numberField)
|
|
576
|
+
}) : null,
|
|
577
|
+
configurable.pattern ? /* @__PURE__ */ jsx(FormField, {
|
|
578
|
+
hint: "Validate values with a regular expression",
|
|
579
|
+
htmlFor: "pattern",
|
|
580
|
+
label: "Regex pattern",
|
|
581
|
+
subtle: true,
|
|
582
|
+
children: /* @__PURE__ */ jsx(Input, {
|
|
583
|
+
className: "font-mono text-sm",
|
|
584
|
+
disabled,
|
|
552
585
|
id: "pattern",
|
|
553
|
-
placeholder: "e.g., ^[a-z]+$",
|
|
554
|
-
value: values.pattern ?? "",
|
|
555
586
|
onChange: (e) => onChange("pattern", e.target.value || void 0),
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
}),
|
|
559
|
-
/* @__PURE__ */ jsx("p", {
|
|
560
|
-
className: "text-muted-foreground text-xs",
|
|
561
|
-
children: "Validate values with a regular expression"
|
|
587
|
+
placeholder: "e.g., ^[a-z]+$",
|
|
588
|
+
value: values.pattern ?? ""
|
|
562
589
|
})
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
/* @__PURE__ */ jsx(Label, {
|
|
571
|
-
htmlFor: "precision",
|
|
572
|
-
className: "text-muted-foreground text-xs",
|
|
573
|
-
children: "Precision"
|
|
574
|
-
}),
|
|
575
|
-
/* @__PURE__ */ jsx(Input, {
|
|
576
|
-
id: "precision",
|
|
577
|
-
type: "number",
|
|
578
|
-
placeholder: "e.g., 10",
|
|
579
|
-
value: values.precision ?? "",
|
|
580
|
-
onChange: (e) => onChange("precision", e.target.value ? parseInt(e.target.value) : void 0),
|
|
581
|
-
disabled
|
|
582
|
-
}),
|
|
583
|
-
/* @__PURE__ */ jsx("p", {
|
|
584
|
-
className: "text-muted-foreground text-xs",
|
|
585
|
-
children: "Total digits"
|
|
586
|
-
})
|
|
587
|
-
]
|
|
588
|
-
}), configurable.scale && /* @__PURE__ */ jsxs("div", {
|
|
589
|
-
className: "space-y-2",
|
|
590
|
-
children: [
|
|
591
|
-
/* @__PURE__ */ jsx(Label, {
|
|
592
|
-
htmlFor: "scale",
|
|
593
|
-
className: "text-muted-foreground text-xs",
|
|
594
|
-
children: "Scale"
|
|
595
|
-
}),
|
|
596
|
-
/* @__PURE__ */ jsx(Input, {
|
|
597
|
-
id: "scale",
|
|
598
|
-
type: "number",
|
|
599
|
-
placeholder: "e.g., 2",
|
|
600
|
-
value: values.scale ?? "",
|
|
601
|
-
onChange: (e) => onChange("scale", e.target.value ? parseInt(e.target.value) : void 0),
|
|
602
|
-
disabled
|
|
603
|
-
}),
|
|
604
|
-
/* @__PURE__ */ jsx("p", {
|
|
605
|
-
className: "text-muted-foreground text-xs",
|
|
606
|
-
children: "Decimal places"
|
|
607
|
-
})
|
|
608
|
-
]
|
|
609
|
-
})]
|
|
610
|
-
}),
|
|
611
|
-
configurable.range && /* @__PURE__ */ jsxs("div", {
|
|
612
|
-
className: "grid grid-cols-2 gap-4",
|
|
613
|
-
children: [/* @__PURE__ */ jsxs("div", {
|
|
614
|
-
className: "space-y-2",
|
|
615
|
-
children: [/* @__PURE__ */ jsx(Label, {
|
|
616
|
-
htmlFor: "minValue",
|
|
617
|
-
className: "text-muted-foreground text-xs",
|
|
618
|
-
children: "Min Value"
|
|
619
|
-
}), /* @__PURE__ */ jsx(Input, {
|
|
620
|
-
id: "minValue",
|
|
621
|
-
type: "number",
|
|
622
|
-
placeholder: "e.g., 0",
|
|
623
|
-
value: values.minValue ?? "",
|
|
624
|
-
onChange: (e) => onChange("minValue", e.target.value ? parseFloat(e.target.value) : void 0),
|
|
625
|
-
disabled
|
|
626
|
-
})]
|
|
627
|
-
}), /* @__PURE__ */ jsxs("div", {
|
|
628
|
-
className: "space-y-2",
|
|
629
|
-
children: [/* @__PURE__ */ jsx(Label, {
|
|
630
|
-
htmlFor: "maxValue",
|
|
631
|
-
className: "text-muted-foreground text-xs",
|
|
632
|
-
children: "Max Value"
|
|
633
|
-
}), /* @__PURE__ */ jsx(Input, {
|
|
634
|
-
id: "maxValue",
|
|
635
|
-
type: "number",
|
|
636
|
-
placeholder: "e.g., 100",
|
|
637
|
-
value: values.maxValue ?? "",
|
|
638
|
-
onChange: (e) => onChange("maxValue", e.target.value ? parseFloat(e.target.value) : void 0),
|
|
639
|
-
disabled
|
|
640
|
-
})]
|
|
641
|
-
})]
|
|
642
|
-
})
|
|
643
|
-
]
|
|
590
|
+
}) : null,
|
|
591
|
+
numericRows.map((row) => /* @__PURE__ */ jsx("div", {
|
|
592
|
+
className: "grid grid-cols-2 gap-4",
|
|
593
|
+
children: row.map(numberField)
|
|
594
|
+
}, row[0].key))
|
|
595
|
+
]
|
|
596
|
+
})
|
|
644
597
|
});
|
|
645
598
|
}
|
|
646
599
|
|
|
@@ -846,12 +799,10 @@ const AddFieldCard = ({ editingField: initialEditingField, preSelectedType, prim
|
|
|
846
799
|
children: /* @__PURE__ */ jsxs("div", {
|
|
847
800
|
className: "space-y-6 p-6",
|
|
848
801
|
children: [
|
|
849
|
-
/* @__PURE__ */
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
children: "Field Name"
|
|
854
|
-
}), /* @__PURE__ */ jsx(Input, {
|
|
802
|
+
/* @__PURE__ */ jsx(FormField, {
|
|
803
|
+
htmlFor: "columnName",
|
|
804
|
+
label: "Field name",
|
|
805
|
+
children: /* @__PURE__ */ jsx(Input, {
|
|
855
806
|
id: "columnName",
|
|
856
807
|
ref: fieldNameInputRef,
|
|
857
808
|
placeholder: "e.g., user_email",
|
|
@@ -859,11 +810,11 @@ const AddFieldCard = ({ editingField: initialEditingField, preSelectedType, prim
|
|
|
859
810
|
onChange: (e) => setColumnName(e.target.value),
|
|
860
811
|
disabled: isPending,
|
|
861
812
|
autoComplete: "off"
|
|
862
|
-
})
|
|
813
|
+
})
|
|
863
814
|
}),
|
|
864
|
-
/* @__PURE__ */
|
|
865
|
-
|
|
866
|
-
children:
|
|
815
|
+
/* @__PURE__ */ jsx(FormField, {
|
|
816
|
+
label: "Data type",
|
|
817
|
+
children: /* @__PURE__ */ jsxs(Combobox, {
|
|
867
818
|
items: fieldTypeOptions,
|
|
868
819
|
value: selectedFieldTypeOption,
|
|
869
820
|
onValueChange: (next) => {
|
|
@@ -923,12 +874,12 @@ const AddFieldCard = ({ editingField: initialEditingField, preSelectedType, prim
|
|
|
923
874
|
} })
|
|
924
875
|
]
|
|
925
876
|
})]
|
|
926
|
-
})
|
|
877
|
+
})
|
|
927
878
|
}),
|
|
928
|
-
/* @__PURE__ */
|
|
929
|
-
|
|
930
|
-
children:
|
|
931
|
-
className: "
|
|
879
|
+
/* @__PURE__ */ jsx(FormSection, {
|
|
880
|
+
title: "Constraints",
|
|
881
|
+
children: /* @__PURE__ */ jsxs("div", {
|
|
882
|
+
className: "flex flex-col gap-2",
|
|
932
883
|
children: [
|
|
933
884
|
/* @__PURE__ */ jsx(ConstraintCard, {
|
|
934
885
|
type: "primaryKey",
|
|
@@ -938,7 +889,7 @@ const AddFieldCard = ({ editingField: initialEditingField, preSelectedType, prim
|
|
|
938
889
|
}),
|
|
939
890
|
/* @__PURE__ */ jsx(ConstraintCard, {
|
|
940
891
|
type: "unique",
|
|
941
|
-
selected: constraints.unique
|
|
892
|
+
selected: Boolean(constraints.unique || constraints.primaryKey),
|
|
942
893
|
onToggle: () => handleConstraintToggle("unique"),
|
|
943
894
|
disabled: isPending || constraints.primaryKey,
|
|
944
895
|
disabledReason: constraints.primaryKey ? "set by PK" : void 0
|
|
@@ -951,30 +902,22 @@ const AddFieldCard = ({ editingField: initialEditingField, preSelectedType, prim
|
|
|
951
902
|
disabledReason: constraints.primaryKey ? "disabled by PK" : void 0
|
|
952
903
|
})
|
|
953
904
|
]
|
|
954
|
-
})
|
|
905
|
+
})
|
|
955
906
|
}),
|
|
956
|
-
/* @__PURE__ */
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
onChange: (e) => setDefaultValue(e.target.value),
|
|
971
|
-
disabled: isPending
|
|
972
|
-
}),
|
|
973
|
-
/* @__PURE__ */ jsx("p", {
|
|
974
|
-
className: "text-muted-foreground text-xs",
|
|
975
|
-
children: "SQL functions or static values"
|
|
976
|
-
})
|
|
977
|
-
]
|
|
907
|
+
/* @__PURE__ */ jsx(FormField, {
|
|
908
|
+
hint: "SQL functions or static values",
|
|
909
|
+
htmlFor: "defaultValue",
|
|
910
|
+
label: /* @__PURE__ */ jsxs(Fragment, { children: ["Default value ", /* @__PURE__ */ jsx("span", {
|
|
911
|
+
className: "text-muted-foreground",
|
|
912
|
+
children: "(optional)"
|
|
913
|
+
})] }),
|
|
914
|
+
children: /* @__PURE__ */ jsx(Input, {
|
|
915
|
+
id: "defaultValue",
|
|
916
|
+
placeholder: "e.g., 0, true, now()",
|
|
917
|
+
value: defaultValue,
|
|
918
|
+
onChange: (e) => setDefaultValue(e.target.value),
|
|
919
|
+
disabled: isPending
|
|
920
|
+
})
|
|
978
921
|
}),
|
|
979
922
|
/* @__PURE__ */ jsx(ValidationRulesSection, {
|
|
980
923
|
dataType,
|
|
@@ -1003,52 +946,60 @@ const AddFieldCard = ({ editingField: initialEditingField, preSelectedType, prim
|
|
|
1003
946
|
|
|
1004
947
|
//#endregion
|
|
1005
948
|
//#region src/schema/schema-builder-fields/components/table-editor/fields-list-view.tsx
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
949
|
+
const CONSTRAINT_STYLE = {
|
|
950
|
+
pk: {
|
|
951
|
+
className: "bg-amber-500/10 text-amber-700 dark:text-amber-300",
|
|
952
|
+
icon: RiKey2Line,
|
|
953
|
+
label: "Primary key"
|
|
954
|
+
},
|
|
955
|
+
unique: {
|
|
956
|
+
className: "bg-violet-500/10 text-violet-700 dark:text-violet-300",
|
|
957
|
+
icon: RiFingerprintLine,
|
|
958
|
+
label: "Unique"
|
|
959
|
+
}
|
|
960
|
+
};
|
|
961
|
+
/** Keys stand out as tinted labels; required and nullable read as plain words, since every column is one or the other. */
|
|
962
|
+
function ConstraintIndicator({ type }) {
|
|
963
|
+
const { className, icon: Icon, label } = CONSTRAINT_STYLE[type];
|
|
1019
964
|
return /* @__PURE__ */ jsxs("span", {
|
|
1020
|
-
className: cn(
|
|
1021
|
-
|
|
1022
|
-
|
|
965
|
+
className: cn("inline-flex h-5 items-center gap-1 rounded-md px-1.5 text-[11px] font-medium whitespace-nowrap", className),
|
|
966
|
+
children: [/* @__PURE__ */ jsx(Icon, {
|
|
967
|
+
"aria-hidden": "true",
|
|
968
|
+
className: "size-3"
|
|
969
|
+
}), label]
|
|
1023
970
|
});
|
|
1024
971
|
}
|
|
972
|
+
const GRID = "grid grid-cols-[36px_minmax(0,1.3fr)_minmax(0,1fr)_minmax(0,1.1fr)_minmax(0,1fr)] items-center gap-3";
|
|
1025
973
|
function FieldsListView({ fields, constraints, selectedFieldIds, onSelectionChange, onFieldClick, disabled }) {
|
|
1026
|
-
const
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
974
|
+
const { primaryKeyIds, uniqueIds } = useMemo(() => {
|
|
975
|
+
const primaryKey = constraints.find((c) => c.type === "primary_key");
|
|
976
|
+
return {
|
|
977
|
+
primaryKeyIds: new Set(primaryKey?.fields ?? []),
|
|
978
|
+
uniqueIds: new Set(constraints.flatMap((c) => c.type === "unique" && c.fields.length === 1 ? c.fields : []))
|
|
979
|
+
};
|
|
980
|
+
}, [constraints]);
|
|
981
|
+
const handleSelectAll = useCallback((checked) => onSelectionChange(checked ? new Set(fields.map((f) => f.id)) : /* @__PURE__ */ new Set()), [fields, onSelectionChange]);
|
|
1031
982
|
const handleSelectRow = useCallback((fieldId, checked) => {
|
|
1032
|
-
const
|
|
1033
|
-
if (checked)
|
|
1034
|
-
else
|
|
1035
|
-
onSelectionChange(
|
|
983
|
+
const next = new Set(selectedFieldIds);
|
|
984
|
+
if (checked) next.add(fieldId);
|
|
985
|
+
else next.delete(fieldId);
|
|
986
|
+
onSelectionChange(next);
|
|
1036
987
|
}, [selectedFieldIds, onSelectionChange]);
|
|
1037
988
|
const allSelected = fields.length > 0 && selectedFieldIds.size === fields.length;
|
|
1038
989
|
const someSelected = selectedFieldIds.size > 0 && selectedFieldIds.size < fields.length;
|
|
1039
990
|
return /* @__PURE__ */ jsxs("div", {
|
|
1040
|
-
className: "min-w-[
|
|
991
|
+
className: "min-w-[640px]",
|
|
1041
992
|
children: [
|
|
1042
993
|
/* @__PURE__ */ jsxs("div", {
|
|
1043
|
-
className: cn(
|
|
1044
|
-
grid-cols-[40px_minmax(0,1.2fr)_minmax(0,1fr)_minmax(0,1fr)_minmax(0,1.2fr)] gap-3 border-b px-3 py-2`, "text-muted-foreground/70 text-[10px] font-semibold tracking-widest uppercase"),
|
|
994
|
+
className: cn(GRID, "bg-muted/60 text-muted-foreground px-3 py-2 text-xs"),
|
|
1045
995
|
children: [
|
|
1046
996
|
/* @__PURE__ */ jsx("div", {
|
|
1047
997
|
className: "flex items-center justify-center",
|
|
1048
998
|
children: /* @__PURE__ */ jsx(Checkbox, {
|
|
1049
999
|
checked: allSelected,
|
|
1050
1000
|
indeterminate: someSelected,
|
|
1051
|
-
|
|
1001
|
+
"aria-label": "Select all fields",
|
|
1002
|
+
onCheckedChange: (checked) => handleSelectAll(checked === true),
|
|
1052
1003
|
disabled: disabled || fields.length === 0
|
|
1053
1004
|
})
|
|
1054
1005
|
}),
|
|
@@ -1059,123 +1010,112 @@ function FieldsListView({ fields, constraints, selectedFieldIds, onSelectionChan
|
|
|
1059
1010
|
]
|
|
1060
1011
|
}),
|
|
1061
1012
|
/* @__PURE__ */ jsx("div", {
|
|
1062
|
-
className: "divide-border
|
|
1063
|
-
children: fields.map((field
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
tabIndex: disabled ? -1 : 0,
|
|
1073
|
-
"aria-disabled": disabled || void 0,
|
|
1074
|
-
"data-chat-component": "field-row",
|
|
1075
|
-
"data-chat-field-name": field.name,
|
|
1076
|
-
"data-chat-field-type": field.type,
|
|
1077
|
-
"data-chat-nullable": String(field.constraints.nullable),
|
|
1078
|
-
className: cn(`group grid grid-cols-[40px_minmax(0,1.2fr)_minmax(0,1fr)_minmax(0,1fr)_minmax(0,1.2fr)] gap-3 px-3
|
|
1079
|
-
py-2.5`, "cursor-pointer transition-colors duration-150 ease-out", "hover:bg-muted/40", isSelected && "bg-primary/5"),
|
|
1080
|
-
style: { animationDelay: `${index * 30}ms` },
|
|
1081
|
-
onClick: () => {
|
|
1082
|
-
if (!disabled) onFieldClick(field);
|
|
1083
|
-
},
|
|
1084
|
-
onKeyDown: (event) => {
|
|
1085
|
-
handleActivationKeyDown(event, () => onFieldClick(field), disabled);
|
|
1086
|
-
},
|
|
1087
|
-
children: [
|
|
1088
|
-
/* @__PURE__ */ jsx("div", {
|
|
1089
|
-
className: "flex items-center justify-center",
|
|
1090
|
-
onClick: (e) => e.stopPropagation(),
|
|
1091
|
-
children: /* @__PURE__ */ jsx(Checkbox, {
|
|
1092
|
-
checked: isSelected,
|
|
1093
|
-
onCheckedChange: (checked) => handleSelectRow(field.id, checked),
|
|
1094
|
-
disabled
|
|
1095
|
-
})
|
|
1096
|
-
}),
|
|
1097
|
-
/* @__PURE__ */ jsx("div", {
|
|
1098
|
-
className: "flex items-center gap-2",
|
|
1099
|
-
children: /* @__PURE__ */ jsx("span", {
|
|
1100
|
-
className: cn("truncate font-mono text-[13px] font-medium tracking-tight", "text-foreground/90 group-hover:text-foreground", "transition-colors duration-200"),
|
|
1101
|
-
children: field.name
|
|
1102
|
-
})
|
|
1103
|
-
}),
|
|
1104
|
-
/* @__PURE__ */ jsx("div", {
|
|
1105
|
-
className: "flex items-center",
|
|
1106
|
-
children: /* @__PURE__ */ jsxs("div", {
|
|
1107
|
-
className: cn("inline-flex items-center gap-1.5 rounded-md px-2 py-1", "bg-muted/60 group-hover:bg-muted/80", "border-border/40 border", "transition-[background-color,border-color] duration-150 ease-out"),
|
|
1108
|
-
children: [fieldTypeInfo?.icon && /* @__PURE__ */ jsx("span", {
|
|
1109
|
-
className: "text-muted-foreground/70 flex items-center",
|
|
1110
|
-
children: typeof fieldTypeInfo.icon === "string" ? /* @__PURE__ */ jsx("span", {
|
|
1111
|
-
className: "text-xs",
|
|
1112
|
-
children: fieldTypeInfo.icon
|
|
1113
|
-
}) : /* @__PURE__ */ jsx(fieldTypeInfo.icon, { className: "size-3.5" })
|
|
1114
|
-
}), /* @__PURE__ */ jsx("span", {
|
|
1115
|
-
className: "text-foreground/70 font-mono text-[11px] font-medium",
|
|
1116
|
-
children: fieldTypeInfo?.label || field.type
|
|
1117
|
-
})]
|
|
1118
|
-
})
|
|
1119
|
-
}),
|
|
1120
|
-
/* @__PURE__ */ jsxs("div", {
|
|
1121
|
-
className: "flex flex-wrap items-center gap-1",
|
|
1122
|
-
children: [
|
|
1123
|
-
isPartOfPrimaryKey && /* @__PURE__ */ jsx(ConstraintIndicator, {
|
|
1124
|
-
type: "pk",
|
|
1125
|
-
label: "PK"
|
|
1126
|
-
}),
|
|
1127
|
-
isUnique && /* @__PURE__ */ jsx(ConstraintIndicator, {
|
|
1128
|
-
type: "unique",
|
|
1129
|
-
label: "Unique"
|
|
1130
|
-
}),
|
|
1131
|
-
isNullable && /* @__PURE__ */ jsx(ConstraintIndicator, {
|
|
1132
|
-
type: "nullable",
|
|
1133
|
-
label: "Null"
|
|
1134
|
-
}),
|
|
1135
|
-
isRequired && /* @__PURE__ */ jsx(ConstraintIndicator, {
|
|
1136
|
-
type: "required",
|
|
1137
|
-
label: "Req"
|
|
1138
|
-
}),
|
|
1139
|
-
!isPartOfPrimaryKey && !isNullable && !isUnique && !isRequired && /* @__PURE__ */ jsx("span", {
|
|
1140
|
-
className: "text-muted-foreground/30 text-xs",
|
|
1141
|
-
children: "—"
|
|
1142
|
-
})
|
|
1143
|
-
]
|
|
1144
|
-
}),
|
|
1145
|
-
/* @__PURE__ */ jsx("div", {
|
|
1146
|
-
className: "flex items-center",
|
|
1147
|
-
children: field.constraints.defaultValue ? /* @__PURE__ */ jsx("code", {
|
|
1148
|
-
className: cn("text-muted-foreground truncate rounded px-1.5 py-0.5 font-mono text-[11px]", "bg-muted/40 group-hover:bg-muted/60", "transition-colors duration-200"),
|
|
1149
|
-
children: field.constraints.defaultValue.toString()
|
|
1150
|
-
}) : /* @__PURE__ */ jsx("span", {
|
|
1151
|
-
className: "text-muted-foreground/30 text-[11px] italic",
|
|
1152
|
-
children: "null"
|
|
1153
|
-
})
|
|
1154
|
-
})
|
|
1155
|
-
]
|
|
1156
|
-
}, field.id);
|
|
1157
|
-
})
|
|
1013
|
+
className: "divide-border divide-y",
|
|
1014
|
+
children: fields.map((field) => /* @__PURE__ */ jsx(FieldRow, {
|
|
1015
|
+
disabled,
|
|
1016
|
+
field,
|
|
1017
|
+
isPrimaryKey: primaryKeyIds.has(field.id),
|
|
1018
|
+
isSelected: selectedFieldIds.has(field.id),
|
|
1019
|
+
isUnique: uniqueIds.has(field.id),
|
|
1020
|
+
onOpen: onFieldClick,
|
|
1021
|
+
onSelect: handleSelectRow
|
|
1022
|
+
}, field.id))
|
|
1158
1023
|
}),
|
|
1159
1024
|
fields.length === 0 && /* @__PURE__ */ jsxs("div", {
|
|
1160
|
-
className: "flex flex-col items-center justify-center py-
|
|
1161
|
-
children: [
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
/* @__PURE__ */ jsx("p", {
|
|
1167
|
-
className: "text-muted-foreground/60 text-sm font-medium",
|
|
1168
|
-
children: "No fields defined"
|
|
1169
|
-
}),
|
|
1170
|
-
/* @__PURE__ */ jsx("p", {
|
|
1171
|
-
className: "text-muted-foreground/40 mt-1 text-xs",
|
|
1172
|
-
children: "Add your first field to start building the schema"
|
|
1025
|
+
className: "flex flex-col items-center justify-center gap-2 py-10",
|
|
1026
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
1027
|
+
className: "bg-muted text-muted-foreground grid size-9 place-items-center rounded-xl",
|
|
1028
|
+
children: /* @__PURE__ */ jsx(RiSparklingLine, {
|
|
1029
|
+
"aria-hidden": "true",
|
|
1030
|
+
className: "size-4"
|
|
1173
1031
|
})
|
|
1174
|
-
|
|
1032
|
+
}), /* @__PURE__ */ jsxs("div", {
|
|
1033
|
+
className: "text-center",
|
|
1034
|
+
children: [/* @__PURE__ */ jsx("p", {
|
|
1035
|
+
className: "text-foreground text-[13px] font-medium",
|
|
1036
|
+
children: "No fields yet"
|
|
1037
|
+
}), /* @__PURE__ */ jsx("p", {
|
|
1038
|
+
className: "text-muted-foreground mt-0.5 text-xs",
|
|
1039
|
+
children: "Add a field, or drop a type from the library."
|
|
1040
|
+
})]
|
|
1041
|
+
})]
|
|
1175
1042
|
})
|
|
1176
1043
|
]
|
|
1177
1044
|
});
|
|
1178
1045
|
}
|
|
1046
|
+
/** One field. Memoized so a selection change re-renders only the rows it touches. */
|
|
1047
|
+
const FieldRow = memo(function FieldRow({ field, isSelected, isPrimaryKey, isUnique, disabled, onSelect, onOpen }) {
|
|
1048
|
+
const typeInfo = getFieldTypeInfo(field.type);
|
|
1049
|
+
const TypeIcon = typeInfo?.icon;
|
|
1050
|
+
const isRequired = !field.constraints.nullable;
|
|
1051
|
+
const defaultValue = field.constraints.defaultValue;
|
|
1052
|
+
const hasDefault = defaultValue !== void 0 && defaultValue !== null && defaultValue !== "";
|
|
1053
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
1054
|
+
role: "button",
|
|
1055
|
+
tabIndex: disabled ? -1 : 0,
|
|
1056
|
+
"aria-disabled": disabled || void 0,
|
|
1057
|
+
"data-chat-component": "field-row",
|
|
1058
|
+
"data-chat-field-name": field.name,
|
|
1059
|
+
"data-chat-field-type": field.type,
|
|
1060
|
+
"data-chat-nullable": String(field.constraints.nullable),
|
|
1061
|
+
className: cn(GRID, "group hover:bg-overlay-hover cursor-pointer px-3 py-2 outline-none focus-visible:ring-[3px] focus-visible:ring-ring/50 focus-visible:ring-inset", isSelected && "bg-primary/[0.05]"),
|
|
1062
|
+
onClick: () => {
|
|
1063
|
+
if (!disabled) onOpen(field);
|
|
1064
|
+
},
|
|
1065
|
+
onKeyDown: (event) => handleActivationKeyDown(event, () => onOpen(field), disabled),
|
|
1066
|
+
children: [
|
|
1067
|
+
/* @__PURE__ */ jsx("div", {
|
|
1068
|
+
className: "flex items-center justify-center",
|
|
1069
|
+
onClick: (e) => e.stopPropagation(),
|
|
1070
|
+
children: /* @__PURE__ */ jsx(Checkbox, {
|
|
1071
|
+
"aria-label": `Select ${field.name}`,
|
|
1072
|
+
checked: isSelected,
|
|
1073
|
+
disabled,
|
|
1074
|
+
onCheckedChange: (checked) => onSelect(field.id, checked === true)
|
|
1075
|
+
})
|
|
1076
|
+
}),
|
|
1077
|
+
/* @__PURE__ */ jsx("span", {
|
|
1078
|
+
className: "text-foreground min-w-0 truncate font-mono text-[13px]",
|
|
1079
|
+
title: field.name,
|
|
1080
|
+
children: field.name
|
|
1081
|
+
}),
|
|
1082
|
+
/* @__PURE__ */ jsx("div", {
|
|
1083
|
+
className: "flex min-w-0 items-center",
|
|
1084
|
+
children: /* @__PURE__ */ jsxs("span", {
|
|
1085
|
+
className: "bg-muted/50 inline-flex h-6 min-w-0 items-center gap-1.5 rounded-md px-2 text-xs ring-1 ring-foreground/[0.07] ring-inset",
|
|
1086
|
+
children: [TypeIcon ? /* @__PURE__ */ jsx("span", {
|
|
1087
|
+
className: "text-muted-foreground flex items-center",
|
|
1088
|
+
children: typeof TypeIcon === "string" ? /* @__PURE__ */ jsx("span", {
|
|
1089
|
+
className: "text-xs",
|
|
1090
|
+
children: TypeIcon
|
|
1091
|
+
}) : /* @__PURE__ */ jsx(TypeIcon, { className: "size-3.5" })
|
|
1092
|
+
}) : null, /* @__PURE__ */ jsx("span", {
|
|
1093
|
+
className: "text-foreground/80 truncate",
|
|
1094
|
+
children: typeInfo?.label || field.type
|
|
1095
|
+
})]
|
|
1096
|
+
})
|
|
1097
|
+
}),
|
|
1098
|
+
/* @__PURE__ */ jsx("div", {
|
|
1099
|
+
className: "flex min-w-0 flex-wrap items-center gap-1.5",
|
|
1100
|
+
children: isPrimaryKey ? /* @__PURE__ */ jsx(ConstraintIndicator, { type: "pk" }) : /* @__PURE__ */ jsxs(Fragment, { children: [isUnique ? /* @__PURE__ */ jsx(ConstraintIndicator, { type: "unique" }) : null, /* @__PURE__ */ jsx("span", {
|
|
1101
|
+
className: cn("text-xs", isRequired ? "text-foreground/75" : "text-muted-foreground"),
|
|
1102
|
+
children: isRequired ? "Required" : "Nullable"
|
|
1103
|
+
})] })
|
|
1104
|
+
}),
|
|
1105
|
+
/* @__PURE__ */ jsx("div", {
|
|
1106
|
+
className: "flex min-w-0 items-center",
|
|
1107
|
+
children: hasDefault ? /* @__PURE__ */ jsx("code", {
|
|
1108
|
+
className: "bg-muted/60 text-foreground/75 truncate rounded px-1.5 py-0.5 font-mono text-xs",
|
|
1109
|
+
children: String(defaultValue)
|
|
1110
|
+
}) : /* @__PURE__ */ jsx("span", {
|
|
1111
|
+
"aria-label": "No default",
|
|
1112
|
+
className: "text-subtle-foreground text-xs",
|
|
1113
|
+
children: "—"
|
|
1114
|
+
})
|
|
1115
|
+
})
|
|
1116
|
+
]
|
|
1117
|
+
});
|
|
1118
|
+
});
|
|
1179
1119
|
|
|
1180
1120
|
//#endregion
|
|
1181
1121
|
//#region src/schema/schema-builder-fields/components/table-editor/fields-section.tsx
|
|
@@ -1199,15 +1139,14 @@ function FieldsSection({ onAddFieldRef } = {}) {
|
|
|
1199
1139
|
useEffect(() => {
|
|
1200
1140
|
setSelectedFieldIds(/* @__PURE__ */ new Set());
|
|
1201
1141
|
}, [currentTable?.id]);
|
|
1202
|
-
const
|
|
1203
|
-
if (!field) return {};
|
|
1142
|
+
const constraintInfoFor = useCallback((field) => {
|
|
1204
1143
|
const pkConstraint = constraints.find((c) => c.type === "primary_key");
|
|
1205
1144
|
const uniqueConstraint = constraints.find((c) => c.type === "unique" && c.fields.length === 1 && c.fields[0] === field.id);
|
|
1206
1145
|
return {
|
|
1207
1146
|
primaryKeyConstraintId: pkConstraint?.id,
|
|
1208
1147
|
uniqueConstraintId: uniqueConstraint?.id,
|
|
1209
|
-
allPrimaryKeyFieldIds: pkConstraint?.fields
|
|
1210
|
-
isPartOfPrimaryKey: pkConstraint?.fields.includes(field.id)
|
|
1148
|
+
allPrimaryKeyFieldIds: pkConstraint?.fields ?? [],
|
|
1149
|
+
isPartOfPrimaryKey: pkConstraint?.fields.includes(field.id) ?? false
|
|
1211
1150
|
};
|
|
1212
1151
|
}, [constraints]);
|
|
1213
1152
|
const handleAddField = useCallback(() => {
|
|
@@ -1224,7 +1163,7 @@ function FieldsSection({ onAddFieldRef } = {}) {
|
|
|
1224
1163
|
});
|
|
1225
1164
|
}, [stack, remoteFields]);
|
|
1226
1165
|
const handleFieldClick = useCallback((field) => {
|
|
1227
|
-
const constraintInfo =
|
|
1166
|
+
const constraintInfo = constraintInfoFor(field);
|
|
1228
1167
|
stack.push({
|
|
1229
1168
|
id: `edit-field-${field.id}`,
|
|
1230
1169
|
title: "Edit Field",
|
|
@@ -1242,7 +1181,7 @@ function FieldsSection({ onAddFieldRef } = {}) {
|
|
|
1242
1181
|
});
|
|
1243
1182
|
}, [
|
|
1244
1183
|
stack,
|
|
1245
|
-
|
|
1184
|
+
constraintInfoFor,
|
|
1246
1185
|
remoteFields
|
|
1247
1186
|
]);
|
|
1248
1187
|
const handleFieldDrop = useCallback((field) => {
|
|
@@ -1266,16 +1205,12 @@ function FieldsSection({ onAddFieldRef } = {}) {
|
|
|
1266
1205
|
if (selectedFieldIds.size === 0) return;
|
|
1267
1206
|
const fieldsToDelete = sortedFields.filter((f) => selectedFieldIds.has(f.id));
|
|
1268
1207
|
if (fieldsToDelete.length === 0) return;
|
|
1269
|
-
const pkConstraint = constraints.find((c) => c.type === "primary_key");
|
|
1270
1208
|
setIsDeleting(true);
|
|
1271
1209
|
const results = await Promise.allSettled(fieldsToDelete.map((field) => {
|
|
1272
|
-
const isPartOfPrimaryKey =
|
|
1273
|
-
const uniqueConstraint = constraints.find((c) => c.type === "unique" && c.fields.length === 1 && c.fields[0] === field.id);
|
|
1210
|
+
const { isPartOfPrimaryKey, ...keys } = constraintInfoFor(field);
|
|
1274
1211
|
return deleteFieldMutation.mutateAsync({
|
|
1275
1212
|
id: field.id,
|
|
1276
|
-
|
|
1277
|
-
uniqueConstraintId: uniqueConstraint?.id,
|
|
1278
|
-
allPrimaryKeyFieldIds: pkConstraint?.fields || [],
|
|
1213
|
+
...keys,
|
|
1279
1214
|
wasPartOfPrimaryKey: isPartOfPrimaryKey
|
|
1280
1215
|
});
|
|
1281
1216
|
}));
|
|
@@ -1303,30 +1238,42 @@ function FieldsSection({ onAddFieldRef } = {}) {
|
|
|
1303
1238
|
}, [
|
|
1304
1239
|
selectedFieldIds,
|
|
1305
1240
|
sortedFields,
|
|
1306
|
-
|
|
1241
|
+
constraintInfoFor,
|
|
1307
1242
|
deleteFieldMutation
|
|
1308
1243
|
]);
|
|
1309
1244
|
return /* @__PURE__ */ jsxs("div", {
|
|
1310
1245
|
"data-chat-component": "fields-section",
|
|
1311
1246
|
"data-chat-table-name": currentTable?.name ?? "",
|
|
1312
1247
|
"data-chat-field-count": String(remoteFields.length),
|
|
1313
|
-
className: "
|
|
1248
|
+
className: "flex flex-col gap-2.5",
|
|
1314
1249
|
children: [/* @__PURE__ */ jsxs("div", {
|
|
1315
|
-
className: "flex items-center justify-between",
|
|
1316
|
-
children: [/* @__PURE__ */
|
|
1317
|
-
className: "text-
|
|
1318
|
-
children: "Fields"
|
|
1319
|
-
|
|
1320
|
-
|
|
1250
|
+
className: "flex h-7 items-center justify-between gap-2",
|
|
1251
|
+
children: [/* @__PURE__ */ jsxs("h3", {
|
|
1252
|
+
className: "text-foreground text-[13px] font-medium",
|
|
1253
|
+
children: ["Fields", /* @__PURE__ */ jsx("span", {
|
|
1254
|
+
className: "text-subtle-foreground ml-1.5 font-normal tabular-nums",
|
|
1255
|
+
children: remoteFields.length
|
|
1256
|
+
})]
|
|
1257
|
+
}), selectedFieldIds.size > 0 ? /* @__PURE__ */ jsxs(Button, {
|
|
1258
|
+
variant: "ghost",
|
|
1321
1259
|
size: "sm",
|
|
1322
|
-
className: "text-destructive hover:bg-destructive/10 hover:text-destructive
|
|
1260
|
+
className: "text-destructive hover:bg-destructive/10 hover:text-destructive h-7 gap-1.5 px-2 text-xs",
|
|
1323
1261
|
onClick: handleBulkDelete,
|
|
1324
1262
|
disabled: isDeleting,
|
|
1325
|
-
children: [isDeleting ? /* @__PURE__ */ jsx(Loader2, { className: "size-3.5 animate-spin" }) : /* @__PURE__ */ jsx(Trash2, { className: "size-3.5" }), isDeleting ? "Deleting
|
|
1263
|
+
children: [isDeleting ? /* @__PURE__ */ jsx(Loader2, { className: "size-3.5 animate-spin" }) : /* @__PURE__ */ jsx(Trash2, { className: "size-3.5" }), isDeleting ? "Deleting…" : `Delete ${selectedFieldIds.size}`]
|
|
1264
|
+
}) : /* @__PURE__ */ jsxs(Button, {
|
|
1265
|
+
className: "h-7 gap-1.5 px-2 text-xs",
|
|
1266
|
+
onClick: handleAddField,
|
|
1267
|
+
size: "sm",
|
|
1268
|
+
variant: "ghost",
|
|
1269
|
+
children: [/* @__PURE__ */ jsx(Plus, {
|
|
1270
|
+
"aria-hidden": "true",
|
|
1271
|
+
className: "size-3.5"
|
|
1272
|
+
}), "Add field"]
|
|
1326
1273
|
})]
|
|
1327
1274
|
}), /* @__PURE__ */ jsxs("div", {
|
|
1328
1275
|
ref: setDropZoneRef,
|
|
1329
|
-
className: cn("bg-card
|
|
1276
|
+
className: cn("bg-card overflow-hidden rounded-xl shadow-card ring-inset", isOverDropZone ? "ring-primary/50 ring-2" : null),
|
|
1330
1277
|
children: [/* @__PURE__ */ jsx("div", {
|
|
1331
1278
|
className: "overflow-x-auto",
|
|
1332
1279
|
children: /* @__PURE__ */ jsx(FieldsListView, {
|
|
@@ -1338,17 +1285,13 @@ function FieldsSection({ onAddFieldRef } = {}) {
|
|
|
1338
1285
|
disabled: isDeleting
|
|
1339
1286
|
})
|
|
1340
1287
|
}), /* @__PURE__ */ jsxs("div", {
|
|
1341
|
-
className: cn("flex items-center justify-center gap-
|
|
1342
|
-
children: [/* @__PURE__ */
|
|
1343
|
-
|
|
1344
|
-
size: "sm",
|
|
1345
|
-
className: cn("gap-1.5 px-3 text-xs font-medium", "hover:bg-primary/10 hover:text-primary hover:border-primary/30", "transition-[background-color,border-color,color,scale] duration-150 ease-out motion-safe:active:scale-[0.96]"),
|
|
1288
|
+
className: cn("text-muted-foreground flex items-center justify-center gap-1.5 border-t border-dashed border-foreground/10 px-4 py-2.5 text-xs", isOverDropZone && "bg-primary/[0.06] text-primary"),
|
|
1289
|
+
children: [/* @__PURE__ */ jsx("button", {
|
|
1290
|
+
className: "text-foreground/80 hover:text-foreground cursor-pointer rounded font-medium outline-none focus-visible:ring-[3px] focus-visible:ring-ring/50",
|
|
1346
1291
|
onClick: handleAddField,
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
children: "or drag field types here"
|
|
1351
|
-
})]
|
|
1292
|
+
type: "button",
|
|
1293
|
+
children: "Add a field"
|
|
1294
|
+
}), /* @__PURE__ */ jsx("span", { children: "or drop a type from the library here" })]
|
|
1352
1295
|
})]
|
|
1353
1296
|
})]
|
|
1354
1297
|
});
|
|
@@ -1421,22 +1364,19 @@ function NoTableSelectedView({ className }) {
|
|
|
1421
1364
|
|
|
1422
1365
|
//#endregion
|
|
1423
1366
|
//#region src/schema/schema-builder-tables/components/table-editor/table-metadata-section.tsx
|
|
1424
|
-
function TableMetadataReadOnly({ tableName }) {
|
|
1425
|
-
return /* @__PURE__ */
|
|
1426
|
-
className: "
|
|
1427
|
-
children: /* @__PURE__ */ jsxs("h2", {
|
|
1428
|
-
className: "
|
|
1367
|
+
function TableMetadataReadOnly({ tableName, description }) {
|
|
1368
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
1369
|
+
className: "min-w-0",
|
|
1370
|
+
children: [/* @__PURE__ */ jsxs("h2", {
|
|
1371
|
+
className: "text-foreground truncate text-base font-medium tracking-tight",
|
|
1429
1372
|
children: [/* @__PURE__ */ jsx("span", {
|
|
1430
1373
|
className: "sr-only",
|
|
1431
|
-
children: "Table"
|
|
1432
|
-
}),
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
})
|
|
1438
|
-
})]
|
|
1439
|
-
})
|
|
1374
|
+
children: "Table "
|
|
1375
|
+
}), tableName]
|
|
1376
|
+
}), description ? /* @__PURE__ */ jsx("p", {
|
|
1377
|
+
className: "text-muted-foreground mt-0.5 text-pretty text-[13px]",
|
|
1378
|
+
children: description
|
|
1379
|
+
}) : null]
|
|
1440
1380
|
});
|
|
1441
1381
|
}
|
|
1442
1382
|
function TableMetadataEditable({ currentTable }) {
|
|
@@ -1481,8 +1421,8 @@ function TableMetadataEditable({ currentTable }) {
|
|
|
1481
1421
|
return /* @__PURE__ */ jsxs("div", {
|
|
1482
1422
|
className: "flex flex-wrap items-center justify-between gap-3",
|
|
1483
1423
|
children: [/* @__PURE__ */ jsx("h2", {
|
|
1484
|
-
className: "text-foreground text-balance text-
|
|
1485
|
-
children: "Edit
|
|
1424
|
+
className: "text-foreground text-balance text-base font-medium tracking-tight",
|
|
1425
|
+
children: "Edit table"
|
|
1486
1426
|
}), /* @__PURE__ */ jsxs("form", {
|
|
1487
1427
|
onSubmit: handleFormSubmit,
|
|
1488
1428
|
className: "flex min-w-0 items-center gap-2",
|
|
@@ -1529,7 +1469,10 @@ function TableMetadataEditable({ currentTable }) {
|
|
|
1529
1469
|
function TableMetadataSection({ isEditable = false }) {
|
|
1530
1470
|
const { currentTable } = useSchemaBuilderSelectors();
|
|
1531
1471
|
if (!currentTable?.name || !currentTable?.id) return null;
|
|
1532
|
-
if (!isEditable) return /* @__PURE__ */ jsx(TableMetadataReadOnly, {
|
|
1472
|
+
if (!isEditable) return /* @__PURE__ */ jsx(TableMetadataReadOnly, {
|
|
1473
|
+
description: currentTable.description,
|
|
1474
|
+
tableName: currentTable.name
|
|
1475
|
+
});
|
|
1533
1476
|
return /* @__PURE__ */ jsx(TableMetadataEditable, { currentTable: {
|
|
1534
1477
|
id: currentTable.id,
|
|
1535
1478
|
name: currentTable.name
|
|
@@ -1589,7 +1532,7 @@ function TypesLibrary() {
|
|
|
1589
1532
|
})]
|
|
1590
1533
|
}),
|
|
1591
1534
|
/* @__PURE__ */ jsx("div", {
|
|
1592
|
-
className: "scrollbar-neutral-thin min-h-0 flex-1 space-y-
|
|
1535
|
+
className: "scrollbar-neutral-thin min-h-0 flex-1 space-y-3 overflow-auto px-2 pb-2",
|
|
1593
1536
|
children: totalFilteredCount === 0 ? /* @__PURE__ */ jsx("div", {
|
|
1594
1537
|
className: "text-muted-foreground p-4 text-center text-sm",
|
|
1595
1538
|
children: /* @__PURE__ */ jsxs("p", { children: [
|
|
@@ -1610,7 +1553,7 @@ function TypesLibrary() {
|
|
|
1610
1553
|
})] })
|
|
1611
1554
|
}),
|
|
1612
1555
|
/* @__PURE__ */ jsxs("div", {
|
|
1613
|
-
className: "text-muted-foreground
|
|
1556
|
+
className: "text-muted-foreground flex items-center gap-1.5 border-t border-dashed border-foreground/10 px-3 py-2 text-xs",
|
|
1614
1557
|
children: [/* @__PURE__ */ jsx(RiDragDropLine, { className: "h-3 w-3" }), /* @__PURE__ */ jsx("span", { children: "Drag or use the keyboard to add fields." })]
|
|
1615
1558
|
})
|
|
1616
1559
|
]
|
|
@@ -1622,7 +1565,7 @@ function TypesSection({ title, types, isExpanded, onToggleExpand }) {
|
|
|
1622
1565
|
onOpenChange: onToggleExpand,
|
|
1623
1566
|
className: "flex min-h-0 shrink-0 flex-col",
|
|
1624
1567
|
children: [/* @__PURE__ */ jsxs(CollapsibleTrigger, {
|
|
1625
|
-
className: "group flex w-full cursor-pointer items-center gap-
|
|
1568
|
+
className: "group text-muted-foreground hover:text-foreground flex h-7 w-full cursor-pointer items-center gap-1.5 rounded-md px-1.5 text-xs outline-none focus-visible:ring-[3px] focus-visible:ring-ring/50",
|
|
1626
1569
|
children: [
|
|
1627
1570
|
/* @__PURE__ */ jsx(motion.div, {
|
|
1628
1571
|
animate: { rotate: isExpanded ? 90 : 0 },
|
|
@@ -1632,14 +1575,11 @@ function TypesSection({ title, types, isExpanded, onToggleExpand }) {
|
|
|
1632
1575
|
damping: 25
|
|
1633
1576
|
},
|
|
1634
1577
|
className: "flex shrink-0 items-center justify-center",
|
|
1635
|
-
children: /* @__PURE__ */ jsx(ChevronRight, { className: "
|
|
1578
|
+
children: /* @__PURE__ */ jsx(ChevronRight, { className: "size-3 opacity-70" })
|
|
1636
1579
|
}),
|
|
1580
|
+
/* @__PURE__ */ jsx("span", { children: title }),
|
|
1637
1581
|
/* @__PURE__ */ jsx("span", {
|
|
1638
|
-
className: "text-
|
|
1639
|
-
children: title
|
|
1640
|
-
}),
|
|
1641
|
-
/* @__PURE__ */ jsx("span", {
|
|
1642
|
-
className: "text-muted-foreground/70 ml-auto text-[10px] tabular-nums",
|
|
1582
|
+
className: "text-subtle-foreground ml-auto tabular-nums",
|
|
1643
1583
|
children: types.length
|
|
1644
1584
|
})
|
|
1645
1585
|
]
|
|
@@ -1667,7 +1607,7 @@ function TypesSection({ title, types, isExpanded, onToggleExpand }) {
|
|
|
1667
1607
|
},
|
|
1668
1608
|
className: "min-h-0 overflow-hidden",
|
|
1669
1609
|
children: /* @__PURE__ */ jsx("div", {
|
|
1670
|
-
className: "mt-
|
|
1610
|
+
className: "mt-0.5 flex flex-col gap-px",
|
|
1671
1611
|
children: types.map((typeInfo) => /* @__PURE__ */ jsx(DraggableFieldType, {
|
|
1672
1612
|
typeInfo,
|
|
1673
1613
|
className: "w-full"
|
|
@@ -1763,7 +1703,7 @@ function useFieldDnD(currentTable) {
|
|
|
1763
1703
|
|
|
1764
1704
|
//#endregion
|
|
1765
1705
|
//#region src/schema/schema-builder-fields/components/table-editor/table-editor.tsx
|
|
1766
|
-
const PANEL_WIDTH_EXPANDED =
|
|
1706
|
+
const PANEL_WIDTH_EXPANDED = 320;
|
|
1767
1707
|
const PANEL_WIDTH_COLLAPSED = 56;
|
|
1768
1708
|
const tweenConfig = {
|
|
1769
1709
|
duration: durations.normal,
|
|
@@ -1772,14 +1712,11 @@ const tweenConfig = {
|
|
|
1772
1712
|
const totalTypesCount = FIELD_TYPE_CATEGORIES.reduce((sum, cat) => sum + cat.types.length, 0);
|
|
1773
1713
|
function TypesLibraryHeader({ isExpanded, onToggle }) {
|
|
1774
1714
|
return /* @__PURE__ */ jsxs("div", {
|
|
1775
|
-
className: "flex items-center justify-between
|
|
1776
|
-
children: [/* @__PURE__ */ jsxs("
|
|
1777
|
-
className: "
|
|
1778
|
-
children: [/* @__PURE__ */ jsx("
|
|
1779
|
-
className: "text-
|
|
1780
|
-
children: "Types Library"
|
|
1781
|
-
}), /* @__PURE__ */ jsx("span", {
|
|
1782
|
-
className: "text-muted-foreground bg-muted rounded-md px-1.5 py-0.5 text-xs tabular-nums",
|
|
1715
|
+
className: "flex h-12 shrink-0 items-center justify-between px-3",
|
|
1716
|
+
children: [/* @__PURE__ */ jsxs("h3", {
|
|
1717
|
+
className: "text-foreground text-[13px] font-medium",
|
|
1718
|
+
children: ["Types library", /* @__PURE__ */ jsx("span", {
|
|
1719
|
+
className: "text-subtle-foreground ml-1.5 font-normal tabular-nums",
|
|
1783
1720
|
children: totalTypesCount
|
|
1784
1721
|
})]
|
|
1785
1722
|
}), /* @__PURE__ */ jsx(Button, {
|
|
@@ -1794,7 +1731,7 @@ function TypesLibraryHeader({ isExpanded, onToggle }) {
|
|
|
1794
1731
|
}
|
|
1795
1732
|
function CollapsedHeader({ onToggle }) {
|
|
1796
1733
|
return /* @__PURE__ */ jsx("div", {
|
|
1797
|
-
className: "flex items-center justify-center
|
|
1734
|
+
className: "flex h-12 shrink-0 items-center justify-center",
|
|
1798
1735
|
children: /* @__PURE__ */ jsx(Button, {
|
|
1799
1736
|
variant: "ghost",
|
|
1800
1737
|
size: "sm",
|
|
@@ -1823,10 +1760,10 @@ function TableEditor() {
|
|
|
1823
1760
|
"data-chat-table-name": currentTable?.name ?? "",
|
|
1824
1761
|
className: "relative flex min-h-0 min-w-0 flex-1 overflow-hidden",
|
|
1825
1762
|
children: [/* @__PURE__ */ jsx("div", {
|
|
1826
|
-
className: cn("scrollbar-neutral-thin relative min-h-0 w-full min-w-0 flex-1 overflow-auto !pr-0", currentTable && (panelExpanded ? "sm:!pr-[
|
|
1763
|
+
className: cn("scrollbar-neutral-thin relative min-h-0 w-full min-w-0 flex-1 overflow-auto !pr-0", currentTable && (panelExpanded ? "sm:!pr-[320px]" : "sm:!pr-14")),
|
|
1827
1764
|
style: { paddingRight: currentTable ? panelExpanded ? PANEL_WIDTH_EXPANDED : PANEL_WIDTH_COLLAPSED : 0 },
|
|
1828
1765
|
children: currentTable ? /* @__PURE__ */ jsxs("div", {
|
|
1829
|
-
className: "min-h-full min-w-
|
|
1766
|
+
className: "mx-auto flex min-h-full w-full max-w-4xl min-w-0 flex-col gap-5 px-3 py-5 pb-10 sm:px-6",
|
|
1830
1767
|
children: [/* @__PURE__ */ jsx(TableMetadataSection, {}), /* @__PURE__ */ jsx(FieldsSection, { onAddFieldRef: handleAddFieldRef })]
|
|
1831
1768
|
}) : /* @__PURE__ */ jsx("div", {
|
|
1832
1769
|
className: "flex min-h-full min-w-full items-start justify-center p-6 pb-12",
|
|
@@ -1834,7 +1771,7 @@ function TableEditor() {
|
|
|
1834
1771
|
})
|
|
1835
1772
|
}), currentTable && /* @__PURE__ */ jsx("div", {
|
|
1836
1773
|
"data-state": panelExpanded ? "expanded" : "collapsed",
|
|
1837
|
-
className: "bg-
|
|
1774
|
+
className: "bg-sidebar border-sidebar-border absolute top-0 right-0 z-10 hidden h-full flex-col border-l sm:flex",
|
|
1838
1775
|
style: { width: panelExpanded ? PANEL_WIDTH_EXPANDED : PANEL_WIDTH_COLLAPSED },
|
|
1839
1776
|
children: /* @__PURE__ */ jsxs("div", {
|
|
1840
1777
|
className: "relative flex h-full min-h-0 flex-1 flex-col overflow-hidden",
|
|
@@ -1903,4 +1840,4 @@ function TableEditor() {
|
|
|
1903
1840
|
|
|
1904
1841
|
//#endregion
|
|
1905
1842
|
export { useUpdateFieldOrder as a, useUpdateField as i, useCreateField as n, useDeleteField as r, TableEditor as t };
|
|
1906
|
-
//# sourceMappingURL=table-editor-
|
|
1843
|
+
//# sourceMappingURL=table-editor-D80Qu4QF.js.map
|