Skip to content

Commit 4828061

Browse files
authored
Fixes #16, add readOnly flag (#17)
* Fixes #16, add readOnly flag * adding tests * fix style
1 parent 4d762e1 commit 4828061

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+2615
-681
lines changed

demo/components/ui/sheet.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as SheetPrimitive from "@radix-ui/react-dialog";
2-
import { type VariantProps, cva } from "class-variance-authority";
2+
import { cva, type VariantProps } from "class-variance-authority";
33
import { X } from "lucide-react";
44
import * as React from "react";
55

demo/components/ui/sidebar.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Slot } from "@radix-ui/react-slot";
2-
import { cva } from "class-variance-authority";
32
import type { VariantProps } from "class-variance-authority";
3+
import { cva } from "class-variance-authority";
44
import { PanelLeft } from "lucide-react";
55
import * as React from "react";
66

demo/components/ui/toast.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
import * as ToastPrimitives from "@radix-ui/react-toast";
2-
import { type VariantProps, cva } from "class-variance-authority";
2+
import { cva, type VariantProps } from "class-variance-authority";
33
import { X } from "lucide-react";
4-
5-
import { cn } from "../../../src/lib/utils.ts";
64
import {
7-
forwardRef,
85
type ComponentPropsWithoutRef,
96
type ComponentRef,
7+
forwardRef,
108
type ReactElement,
119
} from "react";
10+
import { cn } from "../../../src/lib/utils.ts";
1211

1312
const ToastProvider = ToastPrimitives.Provider;
1413

demo/pages/Index.tsx

Lines changed: 75 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -4,36 +4,41 @@ import {
44
Code,
55
FileJson,
66
GitBranch,
7-
User,
87
Package,
8+
Pencil,
9+
PencilOff,
910
RefreshCw,
11+
User,
1012
} from "lucide-react";
1113
import React, { useState } from "react";
1214
import { exampleSchema } from "../../demo/utils/schemaExample.ts";
13-
import JsonSchemaEditor from "../../src/components/SchemaEditor/JsonSchemaEditor.tsx";
1415
import { JsonValidator } from "../../src/components/features/JsonValidator.tsx";
1516
import { SchemaInferencer } from "../../src/components/features/SchemaInferencer.tsx";
17+
import JsonSchemaEditor from "../../src/components/SchemaEditor/JsonSchemaEditor.tsx";
1618
import { Button } from "../../src/components/ui/button.tsx";
17-
import type { JSONSchema } from "../../src/types/jsonSchema.ts";
18-
import { en } from "../../src/i18n/locales/en.ts";
1919
import {
2020
Select,
2121
SelectContent,
2222
SelectItem,
2323
SelectTrigger,
2424
SelectValue,
2525
} from "../../src/components/ui/select.tsx";
26+
import { en } from "../../src/i18n/locales/en.ts";
2627
import { TranslationContext } from "../../src/i18n/translation-context.ts";
28+
import type { JSONSchema } from "../../src/types/jsonSchema.ts";
2729

2830
const Index = () => {
2931
const [schema, setSchema] = useState<JSONSchema>(exampleSchema);
32+
const [readOnly, setReadOnly] = useState<boolean>(false);
3033
const [inferDialogOpen, setInferDialogOpen] = useState(false);
3134
const [validateDialogOpen, setValidateDialogOpen] = useState(false);
3235
const [language, setLanguage] = useState("en");
3336
const [translation, setTranslation] = useState(en);
3437

3538
const handleReset = () => setSchema(exampleSchema);
3639

40+
const handleReadOnlyToggle = () => setReadOnly(!readOnly);
41+
3742
const handleClear = () =>
3843
setSchema({
3944
type: "object",
@@ -90,42 +95,68 @@ const Index = () => {
9095

9196
{/* Action Buttons */}
9297
<div className="flex flex-wrap justify-center gap-4 mb-8 animate-in">
93-
<Button variant="outline" onClick={handleReset} className="gap-2">
94-
<RefreshCw size={16} />
95-
Reset to Example
96-
</Button>
97-
<Button variant="outline" onClick={handleClear} className="gap-2">
98-
<CirclePlus size={16} />
99-
Start from Scratch
100-
</Button>
101-
<Button
102-
variant="outline"
103-
onClick={handleInferSchema}
104-
className="gap-2"
105-
>
106-
<Code size={16} />
107-
Infer from JSON
108-
</Button>
109-
<Button
110-
variant="outline"
111-
onClick={handleValidateJson}
112-
className="gap-2"
113-
>
114-
<CheckCircle size={16} />
115-
Validate JSON
116-
</Button>
117-
<div>
118-
<Select value={language} onValueChange={handleLanguageChange}>
119-
<SelectTrigger className="h-10 font-medium">
120-
<SelectValue placeholder="Language" />
121-
</SelectTrigger>
122-
<SelectContent>
123-
<SelectItem value="en">English</SelectItem>
124-
<SelectItem value="de">German</SelectItem>
125-
<SelectItem value="fr">French</SelectItem>
126-
<SelectItem value="ru">Russian</SelectItem>
127-
</SelectContent>
128-
</Select>
98+
<div className="flex flex-nowrap gap-4">
99+
<Button
100+
variant="outline"
101+
onClick={handleReset}
102+
className="gap-2"
103+
>
104+
<RefreshCw size={16} />
105+
Reset to Example
106+
</Button>
107+
<Button
108+
variant="outline"
109+
onClick={handleClear}
110+
className="gap-2"
111+
>
112+
<CirclePlus size={16} />
113+
Start from Scratch
114+
</Button>
115+
<Button
116+
variant="outline"
117+
onClick={handleInferSchema}
118+
className="gap-2"
119+
>
120+
<Code size={16} />
121+
Infer from JSON
122+
</Button>
123+
<Button
124+
variant="outline"
125+
onClick={handleValidateJson}
126+
className="gap-2"
127+
>
128+
<CheckCircle size={16} />
129+
Validate JSON
130+
</Button>
131+
<Button
132+
variant="outline"
133+
onClick={handleReadOnlyToggle}
134+
className="gap-2"
135+
>
136+
{!readOnly && (
137+
<>
138+
<PencilOff size={16} /> Read-Only
139+
</>
140+
)}
141+
{readOnly && (
142+
<>
143+
<Pencil size={16} /> Writable
144+
</>
145+
)}
146+
</Button>
147+
<div>
148+
<Select value={language} onValueChange={handleLanguageChange}>
149+
<SelectTrigger className="h-10 font-medium">
150+
<SelectValue placeholder="Language" />
151+
</SelectTrigger>
152+
<SelectContent>
153+
<SelectItem value="en">English</SelectItem>
154+
<SelectItem value="de">German</SelectItem>
155+
<SelectItem value="fr">French</SelectItem>
156+
<SelectItem value="ru">Russian</SelectItem>
157+
</SelectContent>
158+
</Select>
159+
</div>
129160
</div>
130161
</div>
131162
</div>
@@ -137,6 +168,7 @@ const Index = () => {
137168
<div className="max-w-4xl mx-auto lg:max-w-none">
138169
<JsonSchemaEditor
139170
schema={schema}
171+
readOnly={readOnly}
140172
setSchema={setSchema}
141173
className="shadow-lg animate-in border-border/50 backdrop-blur-xs"
142174
/>
@@ -427,7 +459,9 @@ const Index = () => {
427459
<link.icon size={14} className="opacity-70" />
428460
<span>{link.text}</span>
429461
</a>
430-
{index < array.length - 1 && <span className="mx-1"></span>}
462+
{index < array.length - 1 && (
463+
<span className="mx-1"></span>
464+
)}
431465
</React.Fragment>
432466
))}
433467
</div>

0 commit comments

Comments
 (0)