Skip to content

Commit 0176196

Browse files
committed
[playground] Add schema editors
1 parent ecb9fab commit 0176196

File tree

2 files changed

+29
-16
lines changed

2 files changed

+29
-16
lines changed

apps/playground/src/app.svelte

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import Github from "./github.svelte";
1313
import OpenBook from "./open-book.svelte";
1414
import ThemePicker from "./theme-picker.svelte";
15+
import Editor from './editor.svelte';
1516
1617
import { samples } from "./samples";
1718
@@ -181,23 +182,10 @@
181182
</div>
182183
<div class="flex gap-8">
183184
<div class="flex-[4] flex flex-col gap-2">
184-
<div class="h-[400px] border rounded overflow-auto p-2">
185-
<pre class="w-0"><code>{JSON.stringify(schema, null, 2)}</code></pre>
186-
</div>
185+
<Editor class="font-mono h-[400px] border rounded p-2 data-[error=true]:border-red-500 data-[error=true]:outline-none bg-transparent" bind:value={schema} />
187186
<div class="flex gap-2">
188-
<div class="h-[400px] flex-1 border rounded overflow-auto p-2">
189-
<pre class="w-0"><code
190-
>{JSON.stringify(
191-
uiSchema,
192-
(_, v) =>
193-
typeof v === "function" ? `Component(${v.componentName})` : v,
194-
2
195-
)}</code
196-
></pre>
197-
</div>
198-
<div class="h-[400px] flex-1 border rounded overflow-auto p-2">
199-
<pre class="w-0"><code>{JSON.stringify(value, null, 2)}</code></pre>
200-
</div>
187+
<Editor class="font-mono h-[400px] grow border rounded p-2 data-[error=true]:border-red-500 data-[error=true]:outline-none bg-transparent" bind:value={uiSchema} />
188+
<Editor class="font-mono h-[400px] grow border rounded p-2 data-[error=true]:border-red-500 data-[error=true]:outline-none bg-transparent" bind:value={value} />
201189
</div>
202190
</div>
203191
<ShadowHost class="flex-[3] max-h-[808px] overflow-y-auto" style={`${themeStyle}\n${iconSetStyle}`}>

apps/playground/src/editor.svelte

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<script lang="ts" generics="T">
2+
import type { HTMLTextareaAttributes } from "svelte/elements";
3+
import { proxy } from "@sjsf/form/lib/svelte.svelte";
4+
5+
let {
6+
value = $bindable(),
7+
...rest
8+
}: { value: T } & Omit<HTMLTextareaAttributes, "value"> = $props();
9+
10+
let error = $state(false);
11+
12+
const mapped = proxy(
13+
() => JSON.stringify(value, null, 2),
14+
(str) => {
15+
try {
16+
value = JSON.parse(str);
17+
error = false;
18+
} catch (e) {
19+
error = true;
20+
}
21+
}
22+
);
23+
</script>
24+
25+
<textarea {...rest} data-error={error} bind:value={mapped.value}></textarea>

0 commit comments

Comments
 (0)