@treenity/react 3.0.0 → 3.0.1
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 +91 -0
- package/dist/AclEditor.d.ts +1 -1
- package/dist/AclEditor.d.ts.map +1 -1
- package/dist/AclEditor.js +5 -5
- package/dist/AclEditor.js.map +1 -1
- package/dist/ActionCards.d.ts +9 -0
- package/dist/ActionCards.d.ts.map +1 -0
- package/dist/ActionCards.js +96 -0
- package/dist/ActionCards.js.map +1 -0
- package/dist/App.d.ts.map +1 -1
- package/dist/App.js +71 -185
- package/dist/App.js.map +1 -1
- package/dist/ComponentSection.d.ts +15 -0
- package/dist/ComponentSection.d.ts.map +1 -0
- package/dist/ComponentSection.js +25 -0
- package/dist/ComponentSection.js.map +1 -0
- package/dist/ErrorBoundary.d.ts +18 -0
- package/dist/ErrorBoundary.d.ts.map +1 -0
- package/dist/ErrorBoundary.js +17 -0
- package/dist/ErrorBoundary.js.map +1 -0
- package/dist/Inspector.d.ts +1 -0
- package/dist/Inspector.d.ts.map +1 -1
- package/dist/Inspector.js +22 -347
- package/dist/Inspector.js.map +1 -1
- package/dist/Login.d.ts +8 -0
- package/dist/Login.d.ts.map +1 -0
- package/dist/Login.js +45 -0
- package/dist/Login.js.map +1 -0
- package/dist/NodeEditor.d.ts +11 -0
- package/dist/NodeEditor.d.ts.map +1 -0
- package/dist/NodeEditor.js +157 -0
- package/dist/NodeEditor.js.map +1 -0
- package/dist/Tree.d.ts +1 -0
- package/dist/Tree.d.ts.map +1 -1
- package/dist/Tree.js +8 -27
- package/dist/Tree.js.map +1 -1
- package/dist/bind/engine.js +1 -1
- package/dist/bind/engine.js.map +1 -1
- package/dist/bind/eval.d.ts +1 -1
- package/dist/bind/eval.d.ts.map +1 -1
- package/dist/bind/hook.d.ts +1 -1
- package/dist/bind/hook.d.ts.map +1 -1
- package/dist/bind/hook.js +1 -1
- package/dist/bind/hook.js.map +1 -1
- package/dist/cache.d.ts +1 -1
- package/dist/cache.d.ts.map +1 -1
- package/dist/cache.js +4 -0
- package/dist/cache.js.map +1 -1
- package/dist/client-tree.d.ts +1 -2
- package/dist/client-tree.d.ts.map +1 -1
- package/dist/client-tree.js +12 -5
- package/dist/client-tree.js.map +1 -1
- package/dist/client.d.ts +1 -1
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +2 -4
- package/dist/client.js.map +1 -1
- package/dist/components/ConfirmDialog.d.ts +9 -0
- package/dist/components/ConfirmDialog.d.ts.map +1 -0
- package/dist/components/ConfirmDialog.js +6 -0
- package/dist/components/ConfirmDialog.js.map +1 -0
- package/dist/components/ConfirmPopover.d.ts +8 -0
- package/dist/components/ConfirmPopover.d.ts.map +1 -0
- package/dist/components/ConfirmPopover.js +9 -0
- package/dist/components/ConfirmPopover.js.map +1 -0
- package/dist/components/PathBreadcrumb.d.ts +5 -0
- package/dist/components/PathBreadcrumb.d.ts.map +1 -0
- package/dist/components/PathBreadcrumb.js +16 -0
- package/dist/components/PathBreadcrumb.js.map +1 -0
- package/dist/components/lib/utils.d.ts +3 -0
- package/dist/components/lib/utils.d.ts.map +1 -0
- package/dist/components/lib/utils.js +6 -0
- package/dist/components/lib/utils.js.map +1 -0
- package/dist/components/ui/accordion.js +1 -1
- package/dist/components/ui/accordion.js.map +1 -1
- package/dist/components/ui/alert-dialog.d.ts +19 -0
- package/dist/components/ui/alert-dialog.d.ts.map +1 -0
- package/dist/components/ui/alert-dialog.js +42 -0
- package/dist/components/ui/alert-dialog.js.map +1 -0
- package/dist/components/ui/badge.js +1 -1
- package/dist/components/ui/badge.js.map +1 -1
- package/dist/components/ui/breadcrumb.d.ts +12 -0
- package/dist/components/ui/breadcrumb.d.ts.map +1 -0
- package/dist/components/ui/breadcrumb.js +28 -0
- package/dist/components/ui/breadcrumb.js.map +1 -0
- package/dist/components/ui/button.d.ts +9 -8
- package/dist/components/ui/button.d.ts.map +1 -1
- package/dist/components/ui/button.js +26 -21
- package/dist/components/ui/button.js.map +1 -1
- package/dist/components/ui/card.d.ts +10 -0
- package/dist/components/ui/card.d.ts.map +1 -0
- package/dist/components/ui/card.js +25 -0
- package/dist/components/ui/card.js.map +1 -0
- package/dist/components/ui/checkbox.js +1 -1
- package/dist/components/ui/checkbox.js.map +1 -1
- package/dist/components/ui/collapsible.d.ts +6 -0
- package/dist/components/ui/collapsible.d.ts.map +1 -0
- package/dist/components/ui/collapsible.js +13 -0
- package/dist/components/ui/collapsible.js.map +1 -0
- package/dist/components/ui/command.d.ts +19 -0
- package/dist/components/ui/command.d.ts.map +1 -0
- package/dist/components/ui/command.js +35 -0
- package/dist/components/ui/command.js.map +1 -0
- package/dist/components/ui/dialog.d.ts.map +1 -1
- package/dist/components/ui/dialog.js +1 -1
- package/dist/components/ui/dialog.js.map +1 -1
- package/dist/components/ui/drawer.js +1 -1
- package/dist/components/ui/drawer.js.map +1 -1
- package/dist/components/ui/dropdown-menu.d.ts +26 -0
- package/dist/components/ui/dropdown-menu.d.ts.map +1 -0
- package/dist/components/ui/dropdown-menu.js +52 -0
- package/dist/components/ui/dropdown-menu.js.map +1 -0
- package/dist/components/ui/form-field.d.ts +7 -0
- package/dist/components/ui/form-field.d.ts.map +1 -0
- package/dist/components/ui/form-field.js +17 -0
- package/dist/components/ui/form-field.js.map +1 -0
- package/dist/components/ui/input.js +1 -1
- package/dist/components/ui/input.js.map +1 -1
- package/dist/components/ui/label.js +1 -1
- package/dist/components/ui/label.js.map +1 -1
- package/dist/components/ui/pagination.d.ts +14 -0
- package/dist/components/ui/pagination.d.ts.map +1 -0
- package/dist/components/ui/pagination.js +30 -0
- package/dist/components/ui/pagination.js.map +1 -0
- package/dist/components/ui/popover.js +2 -2
- package/dist/components/ui/popover.js.map +1 -1
- package/dist/components/ui/progress.js +1 -1
- package/dist/components/ui/progress.js.map +1 -1
- package/dist/components/ui/resizable.d.ts +8 -0
- package/dist/components/ui/resizable.d.ts.map +1 -0
- package/dist/components/ui/resizable.js +14 -0
- package/dist/components/ui/resizable.js.map +1 -0
- package/dist/components/ui/scroll-area.d.ts +6 -0
- package/dist/components/ui/scroll-area.d.ts.map +1 -0
- package/dist/components/ui/scroll-area.js +13 -0
- package/dist/components/ui/scroll-area.js.map +1 -0
- package/dist/components/ui/select.js +1 -1
- package/dist/components/ui/select.js.map +1 -1
- package/dist/components/ui/separator.d.ts +5 -0
- package/dist/components/ui/separator.d.ts.map +1 -0
- package/dist/components/ui/separator.js +9 -0
- package/dist/components/ui/separator.js.map +1 -0
- package/dist/components/ui/sheet.d.ts +15 -0
- package/dist/components/ui/sheet.d.ts.map +1 -0
- package/dist/components/ui/sheet.js +40 -0
- package/dist/components/ui/sheet.js.map +1 -0
- package/dist/components/ui/skeleton.d.ts +3 -0
- package/dist/components/ui/skeleton.d.ts.map +1 -0
- package/dist/components/ui/skeleton.js +7 -0
- package/dist/components/ui/skeleton.js.map +1 -0
- package/dist/components/ui/slider.js +1 -1
- package/dist/components/ui/slider.js.map +1 -1
- package/dist/components/ui/switch.js +1 -1
- package/dist/components/ui/switch.js.map +1 -1
- package/dist/components/ui/table.d.ts +11 -0
- package/dist/components/ui/table.d.ts.map +1 -0
- package/dist/components/ui/table.js +29 -0
- package/dist/components/ui/table.js.map +1 -0
- package/dist/components/ui/tabs.d.ts +12 -0
- package/dist/components/ui/tabs.d.ts.map +1 -0
- package/dist/components/ui/tabs.js +29 -0
- package/dist/components/ui/tabs.js.map +1 -0
- package/dist/components/ui/textarea.js +1 -1
- package/dist/components/ui/textarea.js.map +1 -1
- package/dist/components/ui/toggle-group.d.ts +10 -0
- package/dist/components/ui/toggle-group.d.ts.map +1 -0
- package/dist/components/ui/toggle-group.js +23 -0
- package/dist/components/ui/toggle-group.js.map +1 -0
- package/dist/components/ui/toggle.d.ts +10 -0
- package/dist/components/ui/toggle.d.ts.map +1 -0
- package/dist/components/ui/toggle.js +27 -0
- package/dist/components/ui/toggle.js.map +1 -0
- package/dist/components/ui/tooltip.js +1 -1
- package/dist/components/ui/tooltip.js.map +1 -1
- package/dist/context/index.d.ts +27 -10
- package/dist/context/index.d.ts.map +1 -1
- package/dist/context/index.js +43 -36
- package/dist/context/index.js.map +1 -1
- package/dist/events.d.ts +10 -0
- package/dist/events.d.ts.map +1 -0
- package/dist/events.js +78 -0
- package/dist/events.js.map +1 -0
- package/dist/fiber-tree.d.ts +3 -0
- package/dist/fiber-tree.d.ts.map +1 -0
- package/dist/fiber-tree.js +93 -0
- package/dist/fiber-tree.js.map +1 -0
- package/dist/hooks.d.ts +5 -2
- package/dist/hooks.d.ts.map +1 -1
- package/dist/hooks.js +66 -6
- package/dist/hooks.js.map +1 -1
- package/dist/idb.d.ts +1 -1
- package/dist/idb.d.ts.map +1 -1
- package/dist/lib/to-plain.d.ts +2 -0
- package/dist/lib/to-plain.d.ts.map +1 -0
- package/dist/lib/to-plain.js +21 -0
- package/dist/lib/to-plain.js.map +1 -0
- package/dist/main.d.ts +1 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +4 -3
- package/dist/main.js.map +1 -1
- package/dist/mods/clients.d.ts +3 -0
- package/dist/mods/clients.d.ts.map +1 -0
- package/dist/mods/clients.js +4 -0
- package/dist/mods/clients.js.map +1 -0
- package/dist/mods/editor-ui/FieldLabel.d.ts +15 -0
- package/dist/mods/editor-ui/FieldLabel.d.ts.map +1 -0
- package/dist/mods/editor-ui/FieldLabel.js +55 -0
- package/dist/mods/editor-ui/FieldLabel.js.map +1 -0
- package/dist/mods/editor-ui/client.d.ts +1 -1
- package/dist/mods/editor-ui/client.d.ts.map +1 -1
- package/dist/mods/editor-ui/client.js +1 -1
- package/dist/mods/editor-ui/client.js.map +1 -1
- package/dist/mods/editor-ui/default-edit.d.ts +2 -0
- package/dist/mods/editor-ui/default-edit.d.ts.map +1 -0
- package/dist/mods/editor-ui/default-edit.js +54 -0
- package/dist/mods/editor-ui/default-edit.js.map +1 -0
- package/dist/mods/editor-ui/default-view.d.ts +8 -1
- package/dist/mods/editor-ui/default-view.d.ts.map +1 -1
- package/dist/mods/editor-ui/default-view.js +8 -5
- package/dist/mods/editor-ui/default-view.js.map +1 -1
- package/dist/mods/editor-ui/dir-view.js +0 -2
- package/dist/mods/editor-ui/dir-view.js.map +1 -1
- package/dist/mods/editor-ui/empty-placeholder.d.ts +5 -0
- package/dist/mods/editor-ui/empty-placeholder.d.ts.map +1 -0
- package/dist/mods/editor-ui/empty-placeholder.js +14 -0
- package/dist/mods/editor-ui/empty-placeholder.js.map +1 -0
- package/dist/mods/editor-ui/form-field.d.ts +17 -0
- package/dist/mods/editor-ui/form-field.d.ts.map +1 -0
- package/dist/mods/editor-ui/form-field.js +68 -0
- package/dist/mods/editor-ui/form-field.js.map +1 -0
- package/dist/mods/editor-ui/form-fields.d.ts +1 -2
- package/dist/mods/editor-ui/form-fields.d.ts.map +1 -1
- package/dist/mods/editor-ui/form-fields.js +56 -60
- package/dist/mods/editor-ui/form-fields.js.map +1 -1
- package/dist/mods/editor-ui/layout-view.js +3 -2
- package/dist/mods/editor-ui/layout-view.js.map +1 -1
- package/dist/mods/editor-ui/list-items.js +1 -1
- package/dist/mods/editor-ui/list-items.js.map +1 -1
- package/dist/mods/editor-ui/node-utils.d.ts +2 -2
- package/dist/mods/editor-ui/node-utils.d.ts.map +1 -1
- package/dist/mods/editor-ui/node-utils.js +4 -5
- package/dist/mods/editor-ui/node-utils.js.map +1 -1
- package/dist/mods/editor-ui/type-picker.d.ts +15 -0
- package/dist/mods/editor-ui/type-picker.d.ts.map +1 -0
- package/dist/mods/editor-ui/type-picker.js +69 -0
- package/dist/mods/editor-ui/type-picker.js.map +1 -0
- package/dist/mods/editor-ui/user-view.js +1 -1
- package/dist/mods/editor-ui/user-view.js.map +1 -1
- package/dist/mods/servers.d.ts +1 -0
- package/dist/mods/servers.d.ts.map +1 -0
- package/dist/mods/servers.js +4 -0
- package/dist/mods/servers.js.map +1 -0
- package/dist/mods/treenity/groups/index.js +1 -1
- package/dist/mods/treenity/groups/index.js.map +1 -1
- package/dist/mods/treenity/preview.js +1 -1
- package/dist/mods/treenity/preview.js.map +1 -1
- package/dist/mods/treenity/ref-view.js +1 -1
- package/dist/mods/treenity/ref-view.js.map +1 -1
- package/dist/mods/treenity/schema-form.js +1 -1
- package/dist/mods/treenity/schema-form.js.map +1 -1
- package/dist/mods/treenity/seed.js +1 -1
- package/dist/mods/treenity/seed.js.map +1 -1
- package/dist/mods/treenity/type-view.js +1 -1
- package/dist/mods/treenity/type-view.js.map +1 -1
- package/dist/schema-loader.d.ts +1 -1
- package/dist/schema-loader.d.ts.map +1 -1
- package/dist/schema-loader.js +1 -1
- package/dist/schema-loader.js.map +1 -1
- package/dist/symbols.d.ts +5 -0
- package/dist/symbols.d.ts.map +1 -0
- package/dist/symbols.js +16 -0
- package/dist/symbols.js.map +1 -0
- package/dist/trpc.d.ts +10 -3
- package/dist/trpc.d.ts.map +1 -1
- package/package.json +74 -8
- package/src/AclEditor.tsx +11 -18
- package/src/ActionCards.tsx +224 -0
- package/src/App.tsx +204 -385
- package/src/ComponentSection.tsx +113 -0
- package/src/ErrorBoundary.tsx +37 -0
- package/src/Inspector.css +54 -0
- package/src/Inspector.tsx +73 -793
- package/src/Login.tsx +97 -0
- package/src/NodeEditor.tsx +300 -0
- package/src/Tree.css +91 -0
- package/src/Tree.tsx +40 -43
- package/src/bind/bind.test.ts +1 -1
- package/src/bind/engine.ts +1 -1
- package/src/bind/eval.ts +1 -1
- package/src/bind/hook.ts +1 -1
- package/src/bind/pipes.ts +1 -1
- package/src/cache.ts +5 -1
- package/src/client-tree.test.ts +1 -1
- package/src/client-tree.ts +22 -16
- package/src/client.ts +2 -4
- package/src/components/ConfirmDialog.tsx +34 -0
- package/src/components/ConfirmPopover.tsx +41 -0
- package/src/components/PathBreadcrumb.tsx +36 -0
- package/src/components/lib/utils.ts +6 -0
- package/src/components/lib/utils.ts.bak +6 -0
- package/src/components/ui/accordion.tsx +1 -1
- package/src/components/ui/alert-dialog.tsx +189 -0
- package/src/components/ui/badge.tsx +1 -1
- package/src/components/ui/breadcrumb.tsx +108 -0
- package/src/components/ui/button.tsx +53 -31
- package/src/components/ui/card.tsx +91 -0
- package/src/components/ui/checkbox.tsx +1 -1
- package/src/components/ui/collapsible.tsx +31 -0
- package/src/components/ui/command.tsx +177 -0
- package/src/components/ui/dialog.tsx +1 -2
- package/src/components/ui/drawer.tsx +1 -1
- package/src/components/ui/dropdown-menu.tsx +256 -0
- package/src/components/ui/form-field.tsx +37 -0
- package/src/components/ui/input.tsx +1 -1
- package/src/components/ui/label.tsx +1 -1
- package/src/components/ui/pagination.tsx +127 -0
- package/src/components/ui/popover.tsx +2 -2
- package/src/components/ui/progress.tsx +1 -1
- package/src/components/ui/resizable.tsx +47 -0
- package/src/components/ui/scroll-area.tsx +55 -0
- package/src/components/ui/select.tsx +1 -1
- package/src/components/ui/separator.tsx +27 -0
- package/src/components/ui/sheet.tsx +140 -0
- package/src/components/ui/skeleton.tsx +13 -0
- package/src/components/ui/slider.tsx +1 -1
- package/src/components/ui/switch.tsx +1 -1
- package/src/components/ui/table.tsx +115 -0
- package/src/components/ui/tabs.tsx +88 -0
- package/src/components/ui/textarea.tsx +1 -1
- package/src/components/ui/toggle-group.tsx +82 -0
- package/src/components/ui/toggle.tsx +46 -0
- package/src/components/ui/tooltip.tsx +1 -1
- package/src/context/index.tsx +75 -42
- package/src/events.ts +81 -0
- package/src/fiber-tree.ts +112 -0
- package/src/hooks.ts +88 -9
- package/src/idb.ts +1 -1
- package/src/lib/to-plain.ts +21 -0
- package/src/main.tsx +3 -1
- package/src/mods/clients.ts +3 -0
- package/src/mods/editor-ui/FieldLabel.tsx +124 -0
- package/src/mods/editor-ui/client.ts +1 -1
- package/src/mods/editor-ui/default-edit.tsx +99 -0
- package/src/mods/editor-ui/default-view.tsx +13 -8
- package/src/mods/editor-ui/dir-view.tsx +2 -2
- package/src/mods/editor-ui/editor-ui.css +174 -0
- package/src/mods/editor-ui/empty-placeholder.tsx +39 -0
- package/src/mods/editor-ui/form-field.tsx +144 -0
- package/src/mods/editor-ui/form-fields.tsx +132 -113
- package/src/mods/editor-ui/layout-view.tsx +4 -2
- package/src/mods/editor-ui/list-items.tsx +2 -2
- package/src/mods/editor-ui/node-utils.ts +4 -5
- package/src/mods/editor-ui/type-picker.tsx +147 -0
- package/src/mods/editor-ui/user-view.tsx +1 -1
- package/src/mods/servers.ts +2 -0
- package/src/mods/treenity/groups/index.tsx +1 -1
- package/src/mods/treenity/preview.tsx +1 -1
- package/src/mods/treenity/ref-view.tsx +1 -1
- package/src/mods/treenity/schema-form.tsx +1 -1
- package/src/mods/treenity/seed.ts +1 -1
- package/src/mods/treenity/type-view.tsx +1 -1
- package/src/optimistic.test.ts +111 -0
- package/src/remote-tree.test.ts +1 -1
- package/src/remote-tree.ts +1 -1
- package/src/root.css +117 -0
- package/src/schema-loader.ts +1 -1
- package/src/symbols.ts +18 -0
- package/src/index.html +0 -14
- package/src/style.css +0 -1269
- package/src/vite-env.d.ts +0 -3
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
// FieldLabel — interactive label for Inspector fields
|
|
2
|
+
// Click → dropdown menu (value/$ref/$map + copy/clear), drop target for tree nodes
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
DropdownMenu,
|
|
6
|
+
DropdownMenuContent,
|
|
7
|
+
DropdownMenuItem,
|
|
8
|
+
DropdownMenuSeparator,
|
|
9
|
+
DropdownMenuTrigger,
|
|
10
|
+
} from '#components/ui/dropdown-menu';
|
|
11
|
+
import { isRef } from '@treenity/core';
|
|
12
|
+
import { useState } from 'react';
|
|
13
|
+
|
|
14
|
+
type FieldMode = 'value' | 'ref' | 'map';
|
|
15
|
+
|
|
16
|
+
function getFieldMode(v: unknown): FieldMode {
|
|
17
|
+
if (v && typeof v === 'object' && isRef(v)) {
|
|
18
|
+
return (v as { $map?: string }).$map !== undefined ? 'map' : 'ref';
|
|
19
|
+
}
|
|
20
|
+
return 'value';
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const MODE_LABELS: Record<FieldMode, string> = { value: 'val', ref: '$ref', map: '$map' };
|
|
24
|
+
|
|
25
|
+
/** Interactive field label — click for mode menu, drop target for tree nodes */
|
|
26
|
+
export function FieldLabel({ label, value, onChange }: {
|
|
27
|
+
label: string;
|
|
28
|
+
value: unknown;
|
|
29
|
+
onChange?: (next: unknown) => void;
|
|
30
|
+
}) {
|
|
31
|
+
const [dragOver, setDragOver] = useState(false);
|
|
32
|
+
const mode = getFieldMode(value);
|
|
33
|
+
|
|
34
|
+
function switchMode(next: FieldMode) {
|
|
35
|
+
if (!onChange || next === mode) return;
|
|
36
|
+
if (next === 'value') {
|
|
37
|
+
onChange(0);
|
|
38
|
+
} else if (next === 'ref') {
|
|
39
|
+
onChange({ $ref: '.' });
|
|
40
|
+
} else {
|
|
41
|
+
const r = isRef(value) ? (value as { $ref: string }).$ref : '.';
|
|
42
|
+
onChange({ $ref: r, $map: '' });
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (!onChange) {
|
|
47
|
+
return <label>{label}</label>;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return (
|
|
51
|
+
<label
|
|
52
|
+
className={dragOver ? 'text-primary cursor-pointer' : 'cursor-pointer'}
|
|
53
|
+
onDragOver={(e) => {
|
|
54
|
+
if (e.dataTransfer.types.includes('application/treenity-path')) {
|
|
55
|
+
e.preventDefault();
|
|
56
|
+
setDragOver(true);
|
|
57
|
+
}
|
|
58
|
+
}}
|
|
59
|
+
onDragLeave={() => setDragOver(false)}
|
|
60
|
+
onDrop={(e) => {
|
|
61
|
+
e.preventDefault();
|
|
62
|
+
setDragOver(false);
|
|
63
|
+
const path = e.dataTransfer.getData('application/treenity-path');
|
|
64
|
+
if (path && onChange) {
|
|
65
|
+
const existing = isRef(value) ? (value as { $map?: string }).$map : undefined;
|
|
66
|
+
onChange(existing !== undefined ? { $ref: path, $map: existing } : { $ref: path });
|
|
67
|
+
}
|
|
68
|
+
}}
|
|
69
|
+
>
|
|
70
|
+
<DropdownMenu>
|
|
71
|
+
<DropdownMenuTrigger asChild>
|
|
72
|
+
<span className="block overflow-hidden text-ellipsis">{label}</span>
|
|
73
|
+
</DropdownMenuTrigger>
|
|
74
|
+
<DropdownMenuContent align="start" className="min-w-[100px]">
|
|
75
|
+
{(['value', 'ref', 'map'] as FieldMode[]).map((m) => (
|
|
76
|
+
<DropdownMenuItem key={m} onClick={() => switchMode(m)}>
|
|
77
|
+
{mode === m ? '\u25CF ' : '\u00A0\u00A0'}{MODE_LABELS[m]}
|
|
78
|
+
</DropdownMenuItem>
|
|
79
|
+
))}
|
|
80
|
+
<DropdownMenuSeparator />
|
|
81
|
+
<DropdownMenuItem onClick={() => navigator.clipboard.writeText(JSON.stringify(value))}>
|
|
82
|
+
Copy
|
|
83
|
+
</DropdownMenuItem>
|
|
84
|
+
<DropdownMenuItem onClick={() => onChange(undefined)}>
|
|
85
|
+
Clear
|
|
86
|
+
</DropdownMenuItem>
|
|
87
|
+
</DropdownMenuContent>
|
|
88
|
+
</DropdownMenu>
|
|
89
|
+
</label>
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** Inline ref/map editor — $ref + optional $map, compact single/double row */
|
|
94
|
+
export function RefEditor({ value, onChange }: {
|
|
95
|
+
value: { $ref: string; $map?: string };
|
|
96
|
+
onChange: (next: unknown) => void;
|
|
97
|
+
}) {
|
|
98
|
+
const hasMap = value.$map !== undefined;
|
|
99
|
+
|
|
100
|
+
return (
|
|
101
|
+
<div className="flex flex-col gap-1 flex-1 min-w-0">
|
|
102
|
+
<div className="flex items-center gap-1">
|
|
103
|
+
<span className="text-[9px] text-muted-foreground shrink-0 w-5">$ref</span>
|
|
104
|
+
<input
|
|
105
|
+
className="flex-1 min-w-0"
|
|
106
|
+
value={value.$ref}
|
|
107
|
+
onChange={(e) => onChange(hasMap ? { $ref: e.target.value, $map: value.$map } : { $ref: e.target.value })}
|
|
108
|
+
placeholder="path"
|
|
109
|
+
/>
|
|
110
|
+
</div>
|
|
111
|
+
{hasMap && (
|
|
112
|
+
<div className="flex items-center gap-1">
|
|
113
|
+
<span className="text-[9px] text-muted-foreground shrink-0 w-5">$map</span>
|
|
114
|
+
<input
|
|
115
|
+
className="flex-1 min-w-0"
|
|
116
|
+
value={value.$map ?? ''}
|
|
117
|
+
onChange={(e) => onChange({ $ref: value.$ref, $map: e.target.value })}
|
|
118
|
+
placeholder="field"
|
|
119
|
+
/>
|
|
120
|
+
</div>
|
|
121
|
+
)}
|
|
122
|
+
</div>
|
|
123
|
+
);
|
|
124
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { useSchema } from '#schema-loader';
|
|
2
|
+
import { type ComponentData, isRef, register, resolve } from '@treenity/core';
|
|
3
|
+
import { createElement } from 'react';
|
|
4
|
+
import { FieldLabel, RefEditor } from './FieldLabel';
|
|
5
|
+
import { renderField, StringArrayField } from './form-field';
|
|
6
|
+
|
|
7
|
+
function DefaultEditForm({ value, onChange }: { value: ComponentData; onChange?: (next: ComponentData) => void }) {
|
|
8
|
+
const schema = useSchema(value.$type);
|
|
9
|
+
if (schema === undefined) return null;
|
|
10
|
+
|
|
11
|
+
const data: Record<string, unknown> = {};
|
|
12
|
+
for (const [k, v] of Object.entries(value)) {
|
|
13
|
+
if (!k.startsWith('$')) data[k] = v;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const setData = (fn: (prev: Record<string, unknown>) => Record<string, unknown>) => {
|
|
17
|
+
if (!onChange) return;
|
|
18
|
+
const next = fn(data);
|
|
19
|
+
onChange({ ...value, ...next } as ComponentData);
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
// Schema-driven form
|
|
23
|
+
if (schema && Object.keys(schema.properties).length > 0) {
|
|
24
|
+
return (
|
|
25
|
+
<div className="py-0.5 pb-2.5">
|
|
26
|
+
{Object.entries(schema.properties).map(([field, prop]) => {
|
|
27
|
+
const p = prop as {
|
|
28
|
+
type: string; title: string; format?: string; description?: string;
|
|
29
|
+
readOnly?: boolean; enum?: string[]; items?: { type?: string; properties?: Record<string, unknown> };
|
|
30
|
+
refType?: string;
|
|
31
|
+
};
|
|
32
|
+
return renderField(field, {
|
|
33
|
+
type: p.format ?? p.type, label: p.title ?? field, placeholder: p.description,
|
|
34
|
+
readOnly: p.readOnly || !onChange, enum: p.enum, items: p.items, refType: p.refType,
|
|
35
|
+
}, data, setData);
|
|
36
|
+
})}
|
|
37
|
+
</div>
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// Fallback: raw field rendering
|
|
42
|
+
if (Object.keys(data).length > 0) {
|
|
43
|
+
return (
|
|
44
|
+
<div className="py-0.5 pb-2.5">
|
|
45
|
+
{Object.entries(data).map(([k, v]) => {
|
|
46
|
+
const onCh = (next: unknown) => setData((prev) => ({ ...prev, [k]: next }));
|
|
47
|
+
if (v && typeof v === 'object' && isRef(v)) {
|
|
48
|
+
return (
|
|
49
|
+
<div key={k} className="field">
|
|
50
|
+
<FieldLabel label={k} value={v} onChange={onCh} />
|
|
51
|
+
<RefEditor value={v as { $ref: string; $map?: string }} onChange={onCh} />
|
|
52
|
+
</div>
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
return (
|
|
56
|
+
<div key={k} className={`field${Array.isArray(v) || (typeof v === 'object' && v !== null) ? ' stack' : ''}`}>
|
|
57
|
+
<FieldLabel label={k} value={v} onChange={onCh} />
|
|
58
|
+
{typeof v === 'boolean' ? (
|
|
59
|
+
<label className="flex items-center gap-2 cursor-pointer">
|
|
60
|
+
<input type="checkbox" checked={!!data[k]} className="w-auto"
|
|
61
|
+
onChange={(e) => setData((prev) => ({ ...prev, [k]: e.target.checked }))} />
|
|
62
|
+
{data[k] ? 'true' : 'false'}
|
|
63
|
+
</label>
|
|
64
|
+
) : typeof v === 'number' ? (
|
|
65
|
+
<input type="number" value={String(data[k] ?? 0)}
|
|
66
|
+
onChange={(e) => setData((prev) => ({ ...prev, [k]: Number(e.target.value) }))} />
|
|
67
|
+
) : Array.isArray(v) ? (
|
|
68
|
+
<StringArrayField value={data[k] as unknown[]}
|
|
69
|
+
onChange={(next) => setData((prev) => ({ ...prev, [k]: next }))} />
|
|
70
|
+
) : typeof v === 'object' ? (
|
|
71
|
+
(() => {
|
|
72
|
+
const h = resolve('object', 'react:form');
|
|
73
|
+
return h
|
|
74
|
+
? createElement(h as any, {
|
|
75
|
+
value: { $type: 'object', value: data[k] },
|
|
76
|
+
onChange: (next: { value: unknown }) => setData((prev) => ({ ...prev, [k]: next.value })),
|
|
77
|
+
})
|
|
78
|
+
: <pre className="text-[11px] font-mono text-foreground/60">{JSON.stringify(data[k], null, 2)}</pre>;
|
|
79
|
+
})()
|
|
80
|
+
) : (
|
|
81
|
+
<input value={String(data[k] ?? '')}
|
|
82
|
+
onChange={(e) => setData((prev) => ({ ...prev, [k]: e.target.value }))} />
|
|
83
|
+
)}
|
|
84
|
+
</div>
|
|
85
|
+
);
|
|
86
|
+
})}
|
|
87
|
+
</div>
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// Empty
|
|
92
|
+
return (
|
|
93
|
+
<pre className="text-[11px] font-mono text-foreground/60 bg-muted/30 rounded p-2 whitespace-pre-wrap">
|
|
94
|
+
{JSON.stringify(data, null, 2)}
|
|
95
|
+
</pre>
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
register('default', 'react:edit', DefaultEditForm as any);
|
|
@@ -1,8 +1,11 @@
|
|
|
1
|
+
import './editor-ui.css';
|
|
2
|
+
import { Button } from '#components/ui/button';
|
|
1
3
|
import { Render, RenderContext } from '#context';
|
|
2
4
|
import { useChildren } from '#hooks';
|
|
3
5
|
import { trpc } from '#trpc';
|
|
4
|
-
import { type ComponentData, type NodeData, register } from '@treenity/core
|
|
6
|
+
import { type ComponentData, type NodeData, register } from '@treenity/core';
|
|
5
7
|
import { useCallback, useState } from 'react';
|
|
8
|
+
import { EmptyNodePlaceholder } from './empty-placeholder';
|
|
6
9
|
import { getComponents, getPlainFields, getSchema } from './node-utils';
|
|
7
10
|
|
|
8
11
|
/** Fallback for components without their own react handler */
|
|
@@ -45,7 +48,7 @@ function ComponentFieldsView({ value }: { value: ComponentData }) {
|
|
|
45
48
|
);
|
|
46
49
|
}
|
|
47
50
|
|
|
48
|
-
function GenerateViewButton({ type, sample }: { type: string; sample: NodeData }) {
|
|
51
|
+
export function GenerateViewButton({ type, sample, context, label }: { type: string; sample: NodeData; context?: string; label?: string }) {
|
|
49
52
|
const [status, setStatus] = useState<'idle' | 'generating' | 'done' | 'error'>('idle');
|
|
50
53
|
const [error, setError] = useState('');
|
|
51
54
|
|
|
@@ -58,7 +61,7 @@ function GenerateViewButton({ type, sample }: { type: string; sample: NodeData }
|
|
|
58
61
|
await trpc.execute.mutate({
|
|
59
62
|
path: '/metatron',
|
|
60
63
|
action: 'task',
|
|
61
|
-
data: { prompt: `Generate a React view for type "${type}". Sample data:\n${JSON.stringify(clean, null, 2)}` },
|
|
64
|
+
data: { prompt: `Generate a React view for type "${type}"${context ? ` in context "${context}"` : ''}. Sample data:\n${JSON.stringify(clean, null, 2)}` },
|
|
62
65
|
});
|
|
63
66
|
setStatus('done');
|
|
64
67
|
} catch (err: any) {
|
|
@@ -78,12 +81,14 @@ function GenerateViewButton({ type, sample }: { type: string; sample: NodeData }
|
|
|
78
81
|
}
|
|
79
82
|
|
|
80
83
|
return (
|
|
81
|
-
<
|
|
84
|
+
<Button
|
|
85
|
+
variant="outline"
|
|
86
|
+
size="sm"
|
|
82
87
|
onClick={generate}
|
|
83
|
-
className="text-
|
|
88
|
+
className="text-blue-400 border-blue-400/30 hover:text-blue-300 my-2"
|
|
84
89
|
>
|
|
85
|
-
Generate AI View
|
|
86
|
-
</
|
|
90
|
+
{label ?? 'Generate AI View'}
|
|
91
|
+
</Button>
|
|
87
92
|
);
|
|
88
93
|
}
|
|
89
94
|
|
|
@@ -134,7 +139,7 @@ function DefaultNodeView({ value }: { value: NodeData }) {
|
|
|
134
139
|
</RenderContext>
|
|
135
140
|
)}
|
|
136
141
|
|
|
137
|
-
{children.length === 0 && !hasInfo && <
|
|
142
|
+
{children.length === 0 && !hasInfo && <EmptyNodePlaceholder value={value} />}
|
|
138
143
|
</div>
|
|
139
144
|
);
|
|
140
145
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Render, RenderContext } from '#context';
|
|
2
2
|
import { useChildren } from '#hooks';
|
|
3
|
-
import { type NodeData
|
|
3
|
+
import { type NodeData } from '@treenity/core';
|
|
4
4
|
|
|
5
5
|
const STATUS_COLORS: Record<string, [string, string]> = {
|
|
6
6
|
draft: ['var(--accent-subtle, #1a2a3a)', 'var(--accent)'],
|
|
@@ -88,4 +88,4 @@ function FolderView({ value }: { value: NodeData }) {
|
|
|
88
88
|
);
|
|
89
89
|
}
|
|
90
90
|
|
|
91
|
-
register('dir', 'react', FolderView as any);
|
|
91
|
+
// register('dir', 'react', FolderView as any);
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
/* Form fields */
|
|
2
|
+
.field {
|
|
3
|
+
display: flex;
|
|
4
|
+
align-items: center;
|
|
5
|
+
gap: 8px;
|
|
6
|
+
margin-bottom: 4px;
|
|
7
|
+
}
|
|
8
|
+
.field:last-child {
|
|
9
|
+
margin-bottom: 0;
|
|
10
|
+
}
|
|
11
|
+
.field label {
|
|
12
|
+
font-size: 11px;
|
|
13
|
+
font-weight: 500;
|
|
14
|
+
color: var(--text-2);
|
|
15
|
+
width: 60px;
|
|
16
|
+
flex-shrink: 0;
|
|
17
|
+
white-space: nowrap;
|
|
18
|
+
position: relative;
|
|
19
|
+
}
|
|
20
|
+
.field:has(textarea),
|
|
21
|
+
.field.stack {
|
|
22
|
+
flex-direction: column;
|
|
23
|
+
align-items: stretch;
|
|
24
|
+
}
|
|
25
|
+
.field:has(textarea) label,
|
|
26
|
+
.field.stack label {
|
|
27
|
+
min-width: unset;
|
|
28
|
+
margin-bottom: 3px;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/* Component data view — shows field values in default view */
|
|
32
|
+
.comp-view-card {
|
|
33
|
+
background: var(--surface);
|
|
34
|
+
border: 1px solid var(--border);
|
|
35
|
+
border-radius: var(--radius-lg);
|
|
36
|
+
padding: 14px 16px;
|
|
37
|
+
margin-bottom: 12px;
|
|
38
|
+
}
|
|
39
|
+
.comp-view-header {
|
|
40
|
+
font-size: 11px;
|
|
41
|
+
font-weight: 600;
|
|
42
|
+
color: var(--text-3);
|
|
43
|
+
text-transform: uppercase;
|
|
44
|
+
letter-spacing: 0.5px;
|
|
45
|
+
margin-bottom: 10px;
|
|
46
|
+
display: flex;
|
|
47
|
+
align-items: center;
|
|
48
|
+
gap: 8px;
|
|
49
|
+
}
|
|
50
|
+
.comp-view-header .comp-type {
|
|
51
|
+
font-family: var(--mono);
|
|
52
|
+
color: var(--accent);
|
|
53
|
+
background: var(--accent-subtle);
|
|
54
|
+
padding: 1px 6px;
|
|
55
|
+
border-radius: 10px;
|
|
56
|
+
font-size: 10px;
|
|
57
|
+
text-transform: none;
|
|
58
|
+
}
|
|
59
|
+
.comp-view-row {
|
|
60
|
+
display: flex;
|
|
61
|
+
gap: 8px;
|
|
62
|
+
font-size: 13px;
|
|
63
|
+
padding: 3px 0;
|
|
64
|
+
}
|
|
65
|
+
.comp-view-label {
|
|
66
|
+
color: var(--text-3);
|
|
67
|
+
min-width: 80px;
|
|
68
|
+
flex-shrink: 0;
|
|
69
|
+
}
|
|
70
|
+
.comp-view-value {
|
|
71
|
+
color: var(--text);
|
|
72
|
+
word-break: break-word;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/* Info bar — compact chips for components and fields */
|
|
76
|
+
.node-info-bar {
|
|
77
|
+
display: flex;
|
|
78
|
+
flex-wrap: wrap;
|
|
79
|
+
gap: 8px;
|
|
80
|
+
margin-bottom: 20px;
|
|
81
|
+
}
|
|
82
|
+
.node-info-chip {
|
|
83
|
+
display: inline-flex;
|
|
84
|
+
align-items: center;
|
|
85
|
+
gap: 6px;
|
|
86
|
+
padding: 4px 10px;
|
|
87
|
+
border-radius: 16px;
|
|
88
|
+
background: var(--surface);
|
|
89
|
+
border: 1px solid var(--border);
|
|
90
|
+
font-size: 12px;
|
|
91
|
+
}
|
|
92
|
+
.node-info-chip-label {
|
|
93
|
+
color: var(--text-2);
|
|
94
|
+
font-weight: 500;
|
|
95
|
+
}
|
|
96
|
+
.node-info-chip.data .node-info-chip-val {
|
|
97
|
+
color: var(--text);
|
|
98
|
+
max-width: 120px;
|
|
99
|
+
overflow: hidden;
|
|
100
|
+
text-overflow: ellipsis;
|
|
101
|
+
white-space: nowrap;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/* Children grid — file explorer cards with staggered reveal */
|
|
105
|
+
.children-grid {
|
|
106
|
+
display: flex;
|
|
107
|
+
flex-direction: column;
|
|
108
|
+
gap: 2px;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
.child-card {
|
|
112
|
+
display: flex;
|
|
113
|
+
align-items: center;
|
|
114
|
+
gap: 12px;
|
|
115
|
+
padding: 10px 14px;
|
|
116
|
+
border-radius: var(--radius);
|
|
117
|
+
cursor: pointer;
|
|
118
|
+
transition: all var(--transition);
|
|
119
|
+
}
|
|
120
|
+
.child-card:hover {
|
|
121
|
+
background: var(--surface);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
.child-icon {
|
|
125
|
+
width: 32px;
|
|
126
|
+
height: 32px;
|
|
127
|
+
border-radius: 8px;
|
|
128
|
+
background: var(--surface-2);
|
|
129
|
+
border: 1px solid var(--border);
|
|
130
|
+
display: flex;
|
|
131
|
+
align-items: center;
|
|
132
|
+
justify-content: center;
|
|
133
|
+
font-size: 13px;
|
|
134
|
+
font-weight: 600;
|
|
135
|
+
color: var(--text-2);
|
|
136
|
+
flex-shrink: 0;
|
|
137
|
+
}
|
|
138
|
+
.child-info {
|
|
139
|
+
flex: 1;
|
|
140
|
+
min-width: 0;
|
|
141
|
+
}
|
|
142
|
+
.child-name {
|
|
143
|
+
display: block;
|
|
144
|
+
font-size: 13px;
|
|
145
|
+
font-weight: 500;
|
|
146
|
+
color: var(--text);
|
|
147
|
+
overflow: hidden;
|
|
148
|
+
text-overflow: ellipsis;
|
|
149
|
+
white-space: nowrap;
|
|
150
|
+
}
|
|
151
|
+
.child-type {
|
|
152
|
+
display: block;
|
|
153
|
+
font-size: 11px;
|
|
154
|
+
color: var(--text-3);
|
|
155
|
+
font-family: var(--mono);
|
|
156
|
+
margin-top: 1px;
|
|
157
|
+
}
|
|
158
|
+
.child-chevron {
|
|
159
|
+
color: var(--text-3);
|
|
160
|
+
font-size: 18px;
|
|
161
|
+
flex-shrink: 0;
|
|
162
|
+
transition: transform var(--transition);
|
|
163
|
+
}
|
|
164
|
+
.child-card:hover .child-chevron {
|
|
165
|
+
transform: translateX(2px);
|
|
166
|
+
color: var(--text-2);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
.node-empty {
|
|
170
|
+
color: var(--text-3);
|
|
171
|
+
font-size: 13px;
|
|
172
|
+
padding: 40px;
|
|
173
|
+
text-align: center;
|
|
174
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { Button } from '#components/ui/button';
|
|
2
|
+
import { set } from '#hooks';
|
|
3
|
+
import type { NodeData } from '@treenity/core';
|
|
4
|
+
import { Plus } from 'lucide-react';
|
|
5
|
+
import { useState } from 'react';
|
|
6
|
+
import { TypePicker } from './type-picker';
|
|
7
|
+
|
|
8
|
+
export function EmptyNodePlaceholder({ value }: { value: NodeData }) {
|
|
9
|
+
const [picking, setPicking] = useState(false);
|
|
10
|
+
|
|
11
|
+
return (
|
|
12
|
+
<div className="flex flex-col items-center justify-center gap-3 py-12 px-6">
|
|
13
|
+
<div className="text-[13px] text-[--text-3]">Empty node</div>
|
|
14
|
+
<Button
|
|
15
|
+
variant="outline"
|
|
16
|
+
size="sm"
|
|
17
|
+
onClick={() => setPicking(true)}
|
|
18
|
+
className="text-[12px] text-[--text-3] hover:text-[--accent] hover:bg-[--accent]/10"
|
|
19
|
+
>
|
|
20
|
+
<Plus className="w-3.5 h-3.5" />
|
|
21
|
+
Add Component
|
|
22
|
+
</Button>
|
|
23
|
+
|
|
24
|
+
{picking && (
|
|
25
|
+
<TypePicker
|
|
26
|
+
title="Add Component"
|
|
27
|
+
nameLabel="Component name"
|
|
28
|
+
action="Add"
|
|
29
|
+
autoName
|
|
30
|
+
onCancel={() => setPicking(false)}
|
|
31
|
+
onSelect={async (name, type) => {
|
|
32
|
+
setPicking(false);
|
|
33
|
+
await set({ ...value, [name]: { $type: type } });
|
|
34
|
+
}}
|
|
35
|
+
/>
|
|
36
|
+
)}
|
|
37
|
+
</div>
|
|
38
|
+
);
|
|
39
|
+
}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { Button } from '#components/ui/button';
|
|
2
|
+
import { Input } from '#components/ui/input';
|
|
3
|
+
import { isRef, resolveExact } from '@treenity/core';
|
|
4
|
+
import { createElement, useState } from 'react';
|
|
5
|
+
import { FieldLabel, RefEditor } from './FieldLabel';
|
|
6
|
+
|
|
7
|
+
export function renderField(
|
|
8
|
+
name: string,
|
|
9
|
+
fieldSchema: {
|
|
10
|
+
type: string;
|
|
11
|
+
label: string;
|
|
12
|
+
placeholder?: string;
|
|
13
|
+
readOnly?: boolean;
|
|
14
|
+
enum?: string[];
|
|
15
|
+
items?: { type?: string; properties?: Record<string, unknown> };
|
|
16
|
+
refType?: string;
|
|
17
|
+
},
|
|
18
|
+
data: Record<string, unknown>,
|
|
19
|
+
setData: (fn: (prev: Record<string, unknown>) => Record<string, unknown>) => void,
|
|
20
|
+
) {
|
|
21
|
+
if (!fieldSchema.type) return null;
|
|
22
|
+
|
|
23
|
+
const rawValue = data[name];
|
|
24
|
+
const isRefValue = rawValue && typeof rawValue === 'object' && isRef(rawValue);
|
|
25
|
+
|
|
26
|
+
// If value is a $ref/$map, show ref editor instead of the normal field handler
|
|
27
|
+
if (isRefValue) {
|
|
28
|
+
const onFieldChange = fieldSchema.readOnly
|
|
29
|
+
? undefined
|
|
30
|
+
: (next: unknown) => setData((prev) => ({ ...prev, [name]: next }));
|
|
31
|
+
return (
|
|
32
|
+
<div key={name} className="field">
|
|
33
|
+
<FieldLabel label={fieldSchema.label} value={rawValue} onChange={onFieldChange} />
|
|
34
|
+
{onFieldChange && (
|
|
35
|
+
<RefEditor value={rawValue as { $ref: string; $map?: string }} onChange={onFieldChange} />
|
|
36
|
+
)}
|
|
37
|
+
</div>
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const ctx = fieldSchema.readOnly ? 'react' : 'react:form';
|
|
42
|
+
const handler = resolveExact(fieldSchema.type, ctx) ?? resolveExact('string', ctx);
|
|
43
|
+
if (!handler)
|
|
44
|
+
return (
|
|
45
|
+
<div key={name} className="text-[--danger] text-xs">
|
|
46
|
+
No form handler: {fieldSchema.type}
|
|
47
|
+
</div>
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
const fieldData: { $type: string; [k: string]: unknown } = {
|
|
51
|
+
$type: fieldSchema.type,
|
|
52
|
+
value: rawValue,
|
|
53
|
+
label: fieldSchema.label,
|
|
54
|
+
placeholder: fieldSchema.placeholder,
|
|
55
|
+
};
|
|
56
|
+
if (fieldSchema.items) fieldData.items = fieldSchema.items;
|
|
57
|
+
if (fieldSchema.enum) fieldData.enum = fieldSchema.enum;
|
|
58
|
+
if (fieldSchema.refType) fieldData.refType = fieldSchema.refType;
|
|
59
|
+
|
|
60
|
+
const isComplex = fieldSchema.type === 'object' || fieldSchema.type === 'array';
|
|
61
|
+
const onFieldChange = fieldSchema.readOnly
|
|
62
|
+
? undefined
|
|
63
|
+
: (next: unknown) => setData((prev) => ({ ...prev, [name]: (next as { value: unknown }).value }));
|
|
64
|
+
|
|
65
|
+
return (
|
|
66
|
+
<div key={name} className={isComplex ? 'field stack' : 'field'}>
|
|
67
|
+
{fieldSchema.type !== 'boolean' && (
|
|
68
|
+
<FieldLabel
|
|
69
|
+
label={fieldSchema.label}
|
|
70
|
+
value={rawValue}
|
|
71
|
+
onChange={fieldSchema.readOnly ? undefined : (next: unknown) => setData((prev) => ({ ...prev, [name]: next }))}
|
|
72
|
+
/>
|
|
73
|
+
)}
|
|
74
|
+
{createElement(handler as any, {
|
|
75
|
+
value: fieldData,
|
|
76
|
+
onChange: onFieldChange,
|
|
77
|
+
})}
|
|
78
|
+
</div>
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export function StringArrayField({
|
|
83
|
+
value,
|
|
84
|
+
onChange,
|
|
85
|
+
}: {
|
|
86
|
+
value: unknown[];
|
|
87
|
+
onChange: (next: unknown[]) => void;
|
|
88
|
+
}) {
|
|
89
|
+
const [input, setInput] = useState('');
|
|
90
|
+
const isStrings = value.every((v) => typeof v === 'string');
|
|
91
|
+
|
|
92
|
+
if (!isStrings) {
|
|
93
|
+
return (
|
|
94
|
+
<textarea
|
|
95
|
+
value={JSON.stringify(value, null, 2)}
|
|
96
|
+
onChange={(e) => {
|
|
97
|
+
try {
|
|
98
|
+
onChange(JSON.parse(e.target.value));
|
|
99
|
+
} catch {
|
|
100
|
+
/* typing */
|
|
101
|
+
}
|
|
102
|
+
}}
|
|
103
|
+
/>
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const tags = value as string[];
|
|
108
|
+
return (
|
|
109
|
+
<div className="flex-1 space-y-1">
|
|
110
|
+
<div className="flex flex-wrap gap-1">
|
|
111
|
+
{tags.map((tag, i) => (
|
|
112
|
+
<span
|
|
113
|
+
key={i}
|
|
114
|
+
className="inline-flex items-center gap-0.5 text-[11px] font-mono bg-muted text-foreground/70 px-1.5 py-0.5 rounded"
|
|
115
|
+
>
|
|
116
|
+
{tag}
|
|
117
|
+
<Button
|
|
118
|
+
variant="ghost"
|
|
119
|
+
size="icon"
|
|
120
|
+
type="button"
|
|
121
|
+
className="h-5 w-5 p-0 ml-0.5 text-muted-foreground/40 hover:text-foreground leading-none"
|
|
122
|
+
onClick={() => onChange(tags.filter((_, j) => j !== i))}
|
|
123
|
+
>
|
|
124
|
+
x
|
|
125
|
+
</Button>
|
|
126
|
+
</span>
|
|
127
|
+
))}
|
|
128
|
+
</div>
|
|
129
|
+
<Input
|
|
130
|
+
className="h-7 text-xs w-full"
|
|
131
|
+
placeholder="Add item..."
|
|
132
|
+
value={input}
|
|
133
|
+
onChange={(e) => setInput(e.target.value)}
|
|
134
|
+
onKeyDown={(e) => {
|
|
135
|
+
if (e.key !== 'Enter') return;
|
|
136
|
+
e.preventDefault();
|
|
137
|
+
const t = input.trim();
|
|
138
|
+
if (t && !tags.includes(t)) onChange([...tags, t]);
|
|
139
|
+
setInput('');
|
|
140
|
+
}}
|
|
141
|
+
/>
|
|
142
|
+
</div>
|
|
143
|
+
);
|
|
144
|
+
}
|