@datenlotse/jsonjoy-builder 0.4.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/LICENSE +21 -0
- package/README.md +203 -0
- package/dist/components/SchemaEditor/AddFieldButton.js +312 -0
- package/dist/components/SchemaEditor/JsonSchemaEditor.js +166 -0
- package/dist/components/SchemaEditor/JsonSchemaVisualizer.js +96 -0
- package/dist/components/SchemaEditor/SchemaField.js +104 -0
- package/dist/components/SchemaEditor/SchemaFieldList.js +84 -0
- package/dist/components/SchemaEditor/SchemaPropertyEditor.js +249 -0
- package/dist/components/SchemaEditor/SchemaTypeSelector.js +55 -0
- package/dist/components/SchemaEditor/SchemaVisualEditor.js +77 -0
- package/dist/components/SchemaEditor/TypeDropdown.js +72 -0
- package/dist/components/SchemaEditor/TypeEditor.js +71 -0
- package/dist/components/SchemaEditor/types/ArrayEditor.js +173 -0
- package/dist/components/SchemaEditor/types/BooleanEditor.js +107 -0
- package/dist/components/SchemaEditor/types/NumberEditor.js +583 -0
- package/dist/components/SchemaEditor/types/ObjectEditor.js +90 -0
- package/dist/components/SchemaEditor/types/StringEditor.js +542 -0
- package/dist/components/features/JsonValidator.js +239 -0
- package/dist/components/features/SchemaInferencer.js +107 -0
- package/dist/components/ui/badge.js +25 -0
- package/dist/components/ui/button.js +41 -0
- package/dist/components/ui/dialog.js +73 -0
- package/dist/components/ui/input.js +11 -0
- package/dist/components/ui/label.js +13 -0
- package/dist/components/ui/select.js +90 -0
- package/dist/components/ui/switch.js +14 -0
- package/dist/components/ui/tabs.js +24 -0
- package/dist/components/ui/tooltip.js +15 -0
- package/dist/hooks/use-monaco-theme.js +197 -0
- package/dist/hooks/use-translation.js +14 -0
- package/dist/i18n/locales/de.js +143 -0
- package/dist/i18n/locales/en.js +143 -0
- package/dist/i18n/locales/es.js +143 -0
- package/dist/i18n/locales/fr.js +143 -0
- package/dist/i18n/locales/ru.js +143 -0
- package/dist/i18n/locales/uk.js +143 -0
- package/dist/i18n/locales/zh.js +143 -0
- package/dist/i18n/translation-context.js +4 -0
- package/dist/i18n/translation-keys.js +0 -0
- package/dist/index.css +3830 -0
- package/dist/index.d.ts +995 -0
- package/dist/index.js +10 -0
- package/dist/lib/schema-inference.js +266 -0
- package/dist/lib/schemaCompile.js +113 -0
- package/dist/lib/schemaEditor.js +167 -0
- package/dist/lib/utils.js +40 -0
- package/dist/types/jsonSchema.js +98 -0
- package/dist/types/validation.js +215 -0
- package/dist/utils/jsonValidator.js +162 -0
- package/package.json +112 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Ophir LOJKINE
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
# JSON Schema Builder
|
|
2
|
+
|
|
3
|
+
[](https://json.ophir.dev)
|
|
4
|
+
|
|
5
|
+
A modern, React-based visual JSON Schema editor for creating and manipulating JSON Schema definitions with an intuitive interface.
|
|
6
|
+
|
|
7
|
+
**Try online**: https://json.ophir.dev
|
|
8
|
+
|
|
9
|
+
[](https://www.npmjs.com/package/jsonjoy-builder)
|
|
10
|
+
[](https://www.npmjs.com/package/jsonjoy-builder)
|
|
11
|
+
[](https://www.npmjs.com/package/jsonjoy-builder)
|
|
12
|
+
|
|
13
|
+
## Features
|
|
14
|
+
|
|
15
|
+
- **Visual Schema Editor**: Design your JSON Schema through an intuitive interface without writing raw JSON
|
|
16
|
+
- **Real-time JSON Preview**: See your schema in JSON format as you build it visually
|
|
17
|
+
- **Schema Inference**: Generate schemas automatically from existing JSON data
|
|
18
|
+
- **JSON Validation**: Test JSON data against your schema with detailed validation feedback
|
|
19
|
+
- **Responsive Design**: Fully responsive interface that works on desktop and mobile devices
|
|
20
|
+
|
|
21
|
+
## Getting Started
|
|
22
|
+
|
|
23
|
+
### Installing
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
npm install jsonjoy-builder
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Also install react if you haven't done so yet.
|
|
30
|
+
|
|
31
|
+
Then use like this:
|
|
32
|
+
|
|
33
|
+
```jsx
|
|
34
|
+
import "jsonjoy-builder/styles.css";
|
|
35
|
+
import { type JSONSchema, SchemaVisualEditor } from "jsonjoy-builder";
|
|
36
|
+
import { useState } from "react";
|
|
37
|
+
|
|
38
|
+
export function App() {
|
|
39
|
+
const [schema, setSchema] = useState<JSONSchema>({});
|
|
40
|
+
return (
|
|
41
|
+
<div>
|
|
42
|
+
<h1>JSONJoy Builder</h1>
|
|
43
|
+
<SchemaVisualEditor schema={schema} onChange={setSchema}/>
|
|
44
|
+
</div>
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### Styling
|
|
50
|
+
|
|
51
|
+
To style the component, add custom CSS. For basic styling, there are some CSS custom properties ("variables")
|
|
52
|
+
you can set:
|
|
53
|
+
|
|
54
|
+
```css
|
|
55
|
+
.jsonjoy {
|
|
56
|
+
--jsonjoy-background: #f8fafc;
|
|
57
|
+
--jsonjoy-foreground: #020817;
|
|
58
|
+
--jsonjoy-card: #fff;
|
|
59
|
+
--jsonjoy-card-foreground: #020817;
|
|
60
|
+
--jsonjoy-popover: #fff;
|
|
61
|
+
--jsonjoy-popover-foreground: #020817;
|
|
62
|
+
--jsonjoy-primary: #0080ff;
|
|
63
|
+
--jsonjoy-primary-foreground: #f8fafc;
|
|
64
|
+
--jsonjoy-secondary: #f1f5f9;
|
|
65
|
+
--jsonjoy-secondary-foreground: #0f172a;
|
|
66
|
+
--jsonjoy-muted: #f1f5f9;
|
|
67
|
+
--jsonjoy-muted-foreground: #64748b;
|
|
68
|
+
--jsonjoy-accent: #f1f5f9;
|
|
69
|
+
--jsonjoy-accent-foreground: #0f172a;
|
|
70
|
+
--jsonjoy-destructive: #ef4444;
|
|
71
|
+
--jsonjoy-destructive-foreground: #f8fafc;
|
|
72
|
+
--jsonjoy-border: #e2e8f0;
|
|
73
|
+
--jsonjoy-input: #e2e8f0;
|
|
74
|
+
--jsonjoy-ring: #020817;
|
|
75
|
+
--jsonjoy-radius: .8rem;
|
|
76
|
+
--jsonjoy-font-sans: "Inter", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
|
|
77
|
+
}
|
|
78
|
+
.jsonjoy.dark {
|
|
79
|
+
/** same, but for dark mode */
|
|
80
|
+
}
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### Localization
|
|
84
|
+
|
|
85
|
+
By default, the editor uses English. To localize, you need to set a language via the `TranslationContext`:
|
|
86
|
+
|
|
87
|
+
```jsx
|
|
88
|
+
import "jsonjoy-builder/styles.css";
|
|
89
|
+
import { type JSONSchema, SchemaVisualEditor, TranslationContext, de } from "jsonjoy-builder";
|
|
90
|
+
import { useState } from "react";
|
|
91
|
+
|
|
92
|
+
export function App() {
|
|
93
|
+
const [schema, setSchema] = useState<JSONSchema>({});
|
|
94
|
+
return (
|
|
95
|
+
<TranslationContext value={de}>
|
|
96
|
+
<SchemaVisualEditor schema={schema} onChange={setSchema}/>
|
|
97
|
+
</TranslationContext>
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
Currently we have localizations for English, German, French, Russian, Ukrainian, Spanish and Chinese. You can define your own translation like this.
|
|
103
|
+
If you do, consider opening a PR with the translations!
|
|
104
|
+
|
|
105
|
+
```ts
|
|
106
|
+
import { type Translation } from "jsonjoy-builder";
|
|
107
|
+
|
|
108
|
+
const es: Translation = {
|
|
109
|
+
// add translations here (see type Translation for the available keys and default values)
|
|
110
|
+
};
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
See also the [English localizations file](https://github.com/lovasoa/jsonjoy-builder/blob/main/src/i18n/locales/en.ts) for the default localizations.
|
|
114
|
+
|
|
115
|
+
### Development
|
|
116
|
+
|
|
117
|
+
```bash
|
|
118
|
+
git clone https://github.com/lovasoa/jsonjoy-builder.git
|
|
119
|
+
cd jsonjoy-builder
|
|
120
|
+
npm install
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
Start the development server:
|
|
124
|
+
|
|
125
|
+
```bash
|
|
126
|
+
npm run dev
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
The demo application will be available at http://localhost:5173
|
|
130
|
+
|
|
131
|
+
### Building for Production
|
|
132
|
+
|
|
133
|
+
Build this library for production:
|
|
134
|
+
|
|
135
|
+
```bash
|
|
136
|
+
npm run build
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
The built files will be available in the `dist` directory.
|
|
140
|
+
|
|
141
|
+
## Project Architecture
|
|
142
|
+
|
|
143
|
+
### Core Components
|
|
144
|
+
|
|
145
|
+
- **JsonSchemaEditor**: The main component that provides tabs for switching between visual and JSON views
|
|
146
|
+
- **SchemaVisualEditor**: Handles the visual representation and editing of schemas
|
|
147
|
+
- **JsonSchemaVisualizer**: Provides JSON view with Monaco editor for direct schema editing
|
|
148
|
+
- **SchemaInferencer**: Dialog component for generating schemas from JSON data
|
|
149
|
+
- **JsonValidator**: Dialog component for validating JSON against the current schema
|
|
150
|
+
|
|
151
|
+
### Key Features
|
|
152
|
+
|
|
153
|
+
#### Schema Inference
|
|
154
|
+
|
|
155
|
+
The `SchemaInferencer` component can automatically generate JSON Schema definitions from existing JSON data. This feature uses a recursion-based inference system to detect:
|
|
156
|
+
|
|
157
|
+
- Object structures and properties
|
|
158
|
+
- Array types and their item schemas
|
|
159
|
+
- String formats (dates, emails, URIs)
|
|
160
|
+
- Numeric types (integers vs. floats)
|
|
161
|
+
- Required fields
|
|
162
|
+
|
|
163
|
+
#### JSON Validation
|
|
164
|
+
|
|
165
|
+
Validate any JSON document against your schema with:
|
|
166
|
+
- Real-time feedback
|
|
167
|
+
- Detailed error reporting
|
|
168
|
+
- Format validation for emails, dates, and other special formats
|
|
169
|
+
|
|
170
|
+
## Technology Stack
|
|
171
|
+
|
|
172
|
+
- **React**: UI framework
|
|
173
|
+
- **TypeScript**: Type-safe development
|
|
174
|
+
- **Rsbuild** / **Rslib**: Build tool and development server
|
|
175
|
+
- **ShadCN UI**: Component library
|
|
176
|
+
- **Monaco Editor**: Code editor for JSON viewing/editing
|
|
177
|
+
- **Ajv**: JSON Schema validation
|
|
178
|
+
- **Zod**: Type-safe json parsing in ts
|
|
179
|
+
- **Lucide Icons**: Icon library
|
|
180
|
+
- **Node.js Test Runner**: Simple built-in testing
|
|
181
|
+
|
|
182
|
+
## Development Scripts
|
|
183
|
+
|
|
184
|
+
| Command | Description |
|
|
185
|
+
|---------|-------------|
|
|
186
|
+
| `npm run dev` | Start development server |
|
|
187
|
+
| `npm run build` | Build for production |
|
|
188
|
+
| `npm run build:dev` | Build with development settings |
|
|
189
|
+
| `npm run lint` | Run linter |
|
|
190
|
+
| `npm run format` | Format code |
|
|
191
|
+
| `npm run check` | Type check the project |
|
|
192
|
+
| `npm run fix` | Fix linting issues |
|
|
193
|
+
| `npm run typecheck` | Type check with TypeScript |
|
|
194
|
+
| `npm run preview` | Preview production build |
|
|
195
|
+
| `npm run test` | Run tests |
|
|
196
|
+
|
|
197
|
+
## License
|
|
198
|
+
|
|
199
|
+
This project is licensed under the MIT License - see the LICENSE file for details.
|
|
200
|
+
|
|
201
|
+
## Author
|
|
202
|
+
|
|
203
|
+
[@ophir.dev](https://ophir.dev)
|
|
@@ -0,0 +1,312 @@
|
|
|
1
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { CirclePlus, HelpCircle, Info } from "lucide-react";
|
|
3
|
+
import { useId, useState } from "react";
|
|
4
|
+
import { Badge } from "../ui/badge.js";
|
|
5
|
+
import { Button } from "../ui/button.js";
|
|
6
|
+
import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle } from "../ui/dialog.js";
|
|
7
|
+
import { Input } from "../ui/input.js";
|
|
8
|
+
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "../ui/tooltip.js";
|
|
9
|
+
import { useTranslation } from "../../hooks/use-translation.js";
|
|
10
|
+
import SchemaTypeSelector from "./SchemaTypeSelector.js";
|
|
11
|
+
const AddFieldButton = ({ onAddField, variant = "primary" })=>{
|
|
12
|
+
const [dialogOpen, setDialogOpen] = useState(false);
|
|
13
|
+
const [fieldName, setFieldName] = useState("");
|
|
14
|
+
const [fieldType, setFieldType] = useState("string");
|
|
15
|
+
const [fieldDesc, setFieldDesc] = useState("");
|
|
16
|
+
const [fieldRequired, setFieldRequired] = useState(false);
|
|
17
|
+
const fieldNameId = useId();
|
|
18
|
+
const fieldDescId = useId();
|
|
19
|
+
const fieldRequiredId = useId();
|
|
20
|
+
const fieldTypeId = useId();
|
|
21
|
+
const t = useTranslation();
|
|
22
|
+
const handleSubmit = (e)=>{
|
|
23
|
+
e.preventDefault();
|
|
24
|
+
if (!fieldName.trim()) return;
|
|
25
|
+
onAddField({
|
|
26
|
+
name: fieldName,
|
|
27
|
+
type: fieldType,
|
|
28
|
+
description: fieldDesc,
|
|
29
|
+
required: fieldRequired
|
|
30
|
+
});
|
|
31
|
+
setFieldName("");
|
|
32
|
+
setFieldType("string");
|
|
33
|
+
setFieldDesc("");
|
|
34
|
+
setFieldRequired(false);
|
|
35
|
+
setDialogOpen(false);
|
|
36
|
+
};
|
|
37
|
+
return /*#__PURE__*/ jsxs(Fragment, {
|
|
38
|
+
children: [
|
|
39
|
+
/*#__PURE__*/ jsxs(Button, {
|
|
40
|
+
type: "button",
|
|
41
|
+
onClick: ()=>setDialogOpen(true),
|
|
42
|
+
variant: "primary" === variant ? "default" : "outline",
|
|
43
|
+
size: "sm",
|
|
44
|
+
className: "flex items-center gap-1.5 group",
|
|
45
|
+
children: [
|
|
46
|
+
/*#__PURE__*/ jsx(CirclePlus, {
|
|
47
|
+
size: 16,
|
|
48
|
+
className: "group-hover:scale-110 transition-transform"
|
|
49
|
+
}),
|
|
50
|
+
/*#__PURE__*/ jsx("span", {
|
|
51
|
+
children: t.fieldAddNewButton
|
|
52
|
+
})
|
|
53
|
+
]
|
|
54
|
+
}),
|
|
55
|
+
/*#__PURE__*/ jsx(Dialog, {
|
|
56
|
+
open: dialogOpen,
|
|
57
|
+
onOpenChange: setDialogOpen,
|
|
58
|
+
children: /*#__PURE__*/ jsxs(DialogContent, {
|
|
59
|
+
className: "md:max-w-[1200px] max-h-[85vh] w-[95vw] p-4 sm:p-6 jsonjoy",
|
|
60
|
+
children: [
|
|
61
|
+
/*#__PURE__*/ jsxs(DialogHeader, {
|
|
62
|
+
className: "mb-4",
|
|
63
|
+
children: [
|
|
64
|
+
/*#__PURE__*/ jsxs(DialogTitle, {
|
|
65
|
+
className: "text-xl flex flex-wrap items-center gap-2",
|
|
66
|
+
children: [
|
|
67
|
+
t.fieldAddNewLabel,
|
|
68
|
+
/*#__PURE__*/ jsx(Badge, {
|
|
69
|
+
variant: "secondary",
|
|
70
|
+
className: "text-xs",
|
|
71
|
+
children: t.fieldAddNewBadge
|
|
72
|
+
})
|
|
73
|
+
]
|
|
74
|
+
}),
|
|
75
|
+
/*#__PURE__*/ jsx(DialogDescription, {
|
|
76
|
+
className: "text-sm",
|
|
77
|
+
children: t.fieldAddNewDescription
|
|
78
|
+
})
|
|
79
|
+
]
|
|
80
|
+
}),
|
|
81
|
+
/*#__PURE__*/ jsxs("form", {
|
|
82
|
+
onSubmit: handleSubmit,
|
|
83
|
+
className: "space-y-6",
|
|
84
|
+
children: [
|
|
85
|
+
/*#__PURE__*/ jsxs("div", {
|
|
86
|
+
className: "grid grid-cols-1 lg:grid-cols-2 gap-6",
|
|
87
|
+
children: [
|
|
88
|
+
/*#__PURE__*/ jsxs("div", {
|
|
89
|
+
className: "space-y-4 min-w-[280px]",
|
|
90
|
+
children: [
|
|
91
|
+
/*#__PURE__*/ jsxs("div", {
|
|
92
|
+
children: [
|
|
93
|
+
/*#__PURE__*/ jsxs("div", {
|
|
94
|
+
className: "flex flex-wrap items-center gap-2 mb-1.5",
|
|
95
|
+
children: [
|
|
96
|
+
/*#__PURE__*/ jsx("label", {
|
|
97
|
+
htmlFor: fieldNameId,
|
|
98
|
+
className: "text-sm font-medium",
|
|
99
|
+
children: t.fieldNameLabel
|
|
100
|
+
}),
|
|
101
|
+
/*#__PURE__*/ jsx(TooltipProvider, {
|
|
102
|
+
children: /*#__PURE__*/ jsxs(Tooltip, {
|
|
103
|
+
children: [
|
|
104
|
+
/*#__PURE__*/ jsx(TooltipTrigger, {
|
|
105
|
+
asChild: true,
|
|
106
|
+
children: /*#__PURE__*/ jsx(Info, {
|
|
107
|
+
className: "h-4 w-4 text-muted-foreground shrink-0"
|
|
108
|
+
})
|
|
109
|
+
}),
|
|
110
|
+
/*#__PURE__*/ jsx(TooltipContent, {
|
|
111
|
+
className: "max-w-[90vw]",
|
|
112
|
+
children: /*#__PURE__*/ jsx("p", {
|
|
113
|
+
children: t.fieldNameTooltip
|
|
114
|
+
})
|
|
115
|
+
})
|
|
116
|
+
]
|
|
117
|
+
})
|
|
118
|
+
})
|
|
119
|
+
]
|
|
120
|
+
}),
|
|
121
|
+
/*#__PURE__*/ jsx(Input, {
|
|
122
|
+
id: fieldNameId,
|
|
123
|
+
value: fieldName,
|
|
124
|
+
onChange: (e)=>setFieldName(e.target.value),
|
|
125
|
+
placeholder: t.fieldNamePlaceholder,
|
|
126
|
+
className: "font-mono text-sm w-full",
|
|
127
|
+
required: true
|
|
128
|
+
})
|
|
129
|
+
]
|
|
130
|
+
}),
|
|
131
|
+
/*#__PURE__*/ jsxs("div", {
|
|
132
|
+
children: [
|
|
133
|
+
/*#__PURE__*/ jsxs("div", {
|
|
134
|
+
className: "flex flex-wrap items-center gap-2 mb-1.5",
|
|
135
|
+
children: [
|
|
136
|
+
/*#__PURE__*/ jsx("label", {
|
|
137
|
+
htmlFor: fieldDescId,
|
|
138
|
+
className: "text-sm font-medium",
|
|
139
|
+
children: t.fieldDescription
|
|
140
|
+
}),
|
|
141
|
+
/*#__PURE__*/ jsx(TooltipProvider, {
|
|
142
|
+
children: /*#__PURE__*/ jsxs(Tooltip, {
|
|
143
|
+
children: [
|
|
144
|
+
/*#__PURE__*/ jsx(TooltipTrigger, {
|
|
145
|
+
asChild: true,
|
|
146
|
+
children: /*#__PURE__*/ jsx(Info, {
|
|
147
|
+
className: "h-4 w-4 text-muted-foreground shrink-0"
|
|
148
|
+
})
|
|
149
|
+
}),
|
|
150
|
+
/*#__PURE__*/ jsx(TooltipContent, {
|
|
151
|
+
className: "max-w-[90vw]",
|
|
152
|
+
children: /*#__PURE__*/ jsx("p", {
|
|
153
|
+
children: t.fieldDescriptionTooltip
|
|
154
|
+
})
|
|
155
|
+
})
|
|
156
|
+
]
|
|
157
|
+
})
|
|
158
|
+
})
|
|
159
|
+
]
|
|
160
|
+
}),
|
|
161
|
+
/*#__PURE__*/ jsx(Input, {
|
|
162
|
+
id: fieldDescId,
|
|
163
|
+
value: fieldDesc,
|
|
164
|
+
onChange: (e)=>setFieldDesc(e.target.value),
|
|
165
|
+
placeholder: t.fieldDescriptionPlaceholder,
|
|
166
|
+
className: "text-sm w-full"
|
|
167
|
+
})
|
|
168
|
+
]
|
|
169
|
+
}),
|
|
170
|
+
/*#__PURE__*/ jsxs("div", {
|
|
171
|
+
className: "flex items-center gap-3 p-3 rounded-lg border bg-muted/50",
|
|
172
|
+
children: [
|
|
173
|
+
/*#__PURE__*/ jsx("input", {
|
|
174
|
+
type: "checkbox",
|
|
175
|
+
id: fieldRequiredId,
|
|
176
|
+
checked: fieldRequired,
|
|
177
|
+
onChange: (e)=>setFieldRequired(e.target.checked),
|
|
178
|
+
className: "rounded border-gray-300 shrink-0"
|
|
179
|
+
}),
|
|
180
|
+
/*#__PURE__*/ jsx("label", {
|
|
181
|
+
htmlFor: fieldRequiredId,
|
|
182
|
+
className: "text-sm",
|
|
183
|
+
children: t.fieldRequiredLabel
|
|
184
|
+
})
|
|
185
|
+
]
|
|
186
|
+
})
|
|
187
|
+
]
|
|
188
|
+
}),
|
|
189
|
+
/*#__PURE__*/ jsxs("div", {
|
|
190
|
+
className: "space-y-4 min-w-[280px]",
|
|
191
|
+
children: [
|
|
192
|
+
/*#__PURE__*/ jsxs("div", {
|
|
193
|
+
children: [
|
|
194
|
+
/*#__PURE__*/ jsxs("div", {
|
|
195
|
+
className: "flex flex-wrap items-center gap-2 mb-1.5",
|
|
196
|
+
children: [
|
|
197
|
+
/*#__PURE__*/ jsx("label", {
|
|
198
|
+
htmlFor: fieldTypeId,
|
|
199
|
+
className: "text-sm font-medium",
|
|
200
|
+
children: t.fieldType
|
|
201
|
+
}),
|
|
202
|
+
/*#__PURE__*/ jsx(TooltipProvider, {
|
|
203
|
+
children: /*#__PURE__*/ jsxs(Tooltip, {
|
|
204
|
+
children: [
|
|
205
|
+
/*#__PURE__*/ jsx(TooltipTrigger, {
|
|
206
|
+
asChild: true,
|
|
207
|
+
children: /*#__PURE__*/ jsx(HelpCircle, {
|
|
208
|
+
className: "h-4 w-4 text-muted-foreground shrink-0"
|
|
209
|
+
})
|
|
210
|
+
}),
|
|
211
|
+
/*#__PURE__*/ jsx(TooltipContent, {
|
|
212
|
+
side: "left",
|
|
213
|
+
className: "w-72 max-w-[90vw]",
|
|
214
|
+
children: /*#__PURE__*/ jsxs("div", {
|
|
215
|
+
className: "grid grid-cols-2 gap-x-4 gap-y-1 text-xs",
|
|
216
|
+
children: [
|
|
217
|
+
/*#__PURE__*/ jsxs("div", {
|
|
218
|
+
children: [
|
|
219
|
+
"• ",
|
|
220
|
+
t.fieldTypeTooltipString
|
|
221
|
+
]
|
|
222
|
+
}),
|
|
223
|
+
/*#__PURE__*/ jsxs("div", {
|
|
224
|
+
children: [
|
|
225
|
+
"• ",
|
|
226
|
+
t.fieldTypeTooltipNumber
|
|
227
|
+
]
|
|
228
|
+
}),
|
|
229
|
+
/*#__PURE__*/ jsxs("div", {
|
|
230
|
+
children: [
|
|
231
|
+
"• ",
|
|
232
|
+
t.fieldTypeTooltipBoolean
|
|
233
|
+
]
|
|
234
|
+
}),
|
|
235
|
+
/*#__PURE__*/ jsxs("div", {
|
|
236
|
+
children: [
|
|
237
|
+
"• ",
|
|
238
|
+
t.fieldTypeTooltipObject
|
|
239
|
+
]
|
|
240
|
+
}),
|
|
241
|
+
/*#__PURE__*/ jsxs("div", {
|
|
242
|
+
className: "col-span-2",
|
|
243
|
+
children: [
|
|
244
|
+
"• ",
|
|
245
|
+
t.fieldTypeTooltipArray
|
|
246
|
+
]
|
|
247
|
+
})
|
|
248
|
+
]
|
|
249
|
+
})
|
|
250
|
+
})
|
|
251
|
+
]
|
|
252
|
+
})
|
|
253
|
+
})
|
|
254
|
+
]
|
|
255
|
+
}),
|
|
256
|
+
/*#__PURE__*/ jsx(SchemaTypeSelector, {
|
|
257
|
+
id: fieldTypeId,
|
|
258
|
+
value: fieldType,
|
|
259
|
+
onChange: setFieldType
|
|
260
|
+
})
|
|
261
|
+
]
|
|
262
|
+
}),
|
|
263
|
+
/*#__PURE__*/ jsxs("div", {
|
|
264
|
+
className: "rounded-lg border bg-muted/50 p-3 hidden md:block",
|
|
265
|
+
children: [
|
|
266
|
+
/*#__PURE__*/ jsx("p", {
|
|
267
|
+
className: "text-xs font-medium mb-2",
|
|
268
|
+
children: t.fieldTypeExample
|
|
269
|
+
}),
|
|
270
|
+
/*#__PURE__*/ jsxs("code", {
|
|
271
|
+
className: "text-sm bg-background/80 p-2 rounded block overflow-x-auto",
|
|
272
|
+
children: [
|
|
273
|
+
"string" === fieldType && '"example"',
|
|
274
|
+
"number" === fieldType && "42",
|
|
275
|
+
"boolean" === fieldType && "true",
|
|
276
|
+
"object" === fieldType && '{ "key": "value" }',
|
|
277
|
+
"array" === fieldType && '["item1", "item2"]'
|
|
278
|
+
]
|
|
279
|
+
})
|
|
280
|
+
]
|
|
281
|
+
})
|
|
282
|
+
]
|
|
283
|
+
})
|
|
284
|
+
]
|
|
285
|
+
}),
|
|
286
|
+
/*#__PURE__*/ jsxs(DialogFooter, {
|
|
287
|
+
className: "mt-6 gap-2 flex-wrap",
|
|
288
|
+
children: [
|
|
289
|
+
/*#__PURE__*/ jsx(Button, {
|
|
290
|
+
type: "button",
|
|
291
|
+
variant: "outline",
|
|
292
|
+
size: "sm",
|
|
293
|
+
onClick: ()=>setDialogOpen(false),
|
|
294
|
+
children: t.fieldAddNewCancel
|
|
295
|
+
}),
|
|
296
|
+
/*#__PURE__*/ jsx(Button, {
|
|
297
|
+
type: "submit",
|
|
298
|
+
size: "sm",
|
|
299
|
+
children: t.fieldAddNewConfirm
|
|
300
|
+
})
|
|
301
|
+
]
|
|
302
|
+
})
|
|
303
|
+
]
|
|
304
|
+
})
|
|
305
|
+
]
|
|
306
|
+
})
|
|
307
|
+
})
|
|
308
|
+
]
|
|
309
|
+
});
|
|
310
|
+
};
|
|
311
|
+
const SchemaEditor_AddFieldButton = AddFieldButton;
|
|
312
|
+
export { SchemaEditor_AddFieldButton as default };
|