@ederzeel/nuxt-schema-form-nightly 0.1.0-28989865.c565459 → 0.1.0-28997068.dca840d
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/package.json +1 -1
- package/playground/components/Editor.vue +44 -0
- package/playground/components/TestForm.vue +24 -0
- package/playground/nuxt.config.ts +5 -5
- package/playground/package.json +3 -1
- package/playground/pages/index.vue +7 -17
- package/playground/plugins/monaco-editor.js +19 -0
- package/src/runtime/components/SComponent.vue +6 -20
package/package.json
CHANGED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
<script lang="ts" setup>
|
|
2
|
+
// import formSchema from '@/assets/schema.json'
|
|
3
|
+
import { Draft2019 } from 'json-schema-library'
|
|
4
|
+
import { computed } from 'vue'
|
|
5
|
+
|
|
6
|
+
const props = defineProps<{
|
|
7
|
+
schema: Record<string, unknown>
|
|
8
|
+
}>()
|
|
9
|
+
|
|
10
|
+
const colorMode = useColorMode()
|
|
11
|
+
const schemaString = ref(JSON.stringify(props.schema, null, 2))
|
|
12
|
+
const error = ref()
|
|
13
|
+
const schemaObject = ref(new Draft2019(JSON.parse(schemaString.value)))
|
|
14
|
+
const schema = ref(schemaObject.value.rootSchema)
|
|
15
|
+
const state = ref(schemaObject.value.getTemplate())
|
|
16
|
+
|
|
17
|
+
const monacoOptions = computed(() => ({
|
|
18
|
+
minimap: { enabled: false },
|
|
19
|
+
theme: colorMode.value === 'dark' ? 'vs-dark' : 'vs-light',
|
|
20
|
+
contextmenu: false,
|
|
21
|
+
lineNumbers: 'off',
|
|
22
|
+
scrollBeyondLastLine: false
|
|
23
|
+
}))
|
|
24
|
+
</script>
|
|
25
|
+
|
|
26
|
+
<template>
|
|
27
|
+
<div class="w-full gap-10 flex">
|
|
28
|
+
<div
|
|
29
|
+
class="w-1/2 h-[80vh] rounded-md ring-1 focus:ring-2 ring-gray-300 dark:ring-gray-700 overflow-hidden shadow-sm"
|
|
30
|
+
>
|
|
31
|
+
<MonacoEditor v-model="schemaString" :options="monacoOptions" lang="json" class="h-full rounded-md" />
|
|
32
|
+
<!-- <UFormGroup :error="error"> -->
|
|
33
|
+
<!-- <UTextarea v-model="schemaString" @update:model-value="onUpdate" :rows="25" class="w-full" /> -->
|
|
34
|
+
<!-- </UFormGroup> -->
|
|
35
|
+
</div>
|
|
36
|
+
<div class="w-1/2">
|
|
37
|
+
<SForm v-if="schema && error == null" v-model="state" :schema="schema">
|
|
38
|
+
<template #submit>
|
|
39
|
+
{{ undefined }}
|
|
40
|
+
</template>
|
|
41
|
+
</SForm>
|
|
42
|
+
</div>
|
|
43
|
+
</div>
|
|
44
|
+
</template>
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="w-full flex justify-center">
|
|
3
|
+
<div class="w-full max-w-[800px]">
|
|
4
|
+
<SForm v-if="schema" v-model="state" :schema="schema" @submit="onSubmit">
|
|
5
|
+
<template #submit>
|
|
6
|
+
{{ undefined }}
|
|
7
|
+
</template>
|
|
8
|
+
</SForm>
|
|
9
|
+
</div>
|
|
10
|
+
</div>
|
|
11
|
+
</template>
|
|
12
|
+
|
|
13
|
+
<script lang="ts" setup>
|
|
14
|
+
import { type JsonSchema } from 'json-schema-library'
|
|
15
|
+
const props = defineProps<{
|
|
16
|
+
state: { [key: string]: unknown }
|
|
17
|
+
schema: JsonSchema
|
|
18
|
+
}>()
|
|
19
|
+
const state = ref(props.state)
|
|
20
|
+
|
|
21
|
+
const onSubmit = (value: unknown) => {
|
|
22
|
+
console.log(value)
|
|
23
|
+
}
|
|
24
|
+
</script>
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
// https://nuxt.com/docs/api/configuration/nuxt-config
|
|
2
2
|
export default defineNuxtConfig({
|
|
3
|
-
modules: [
|
|
3
|
+
modules: ["../src/module", "@nuxt/ui", "nuxt-monaco-editor"],
|
|
4
4
|
components: {
|
|
5
5
|
global: true,
|
|
6
|
-
dirs: [
|
|
6
|
+
dirs: ["@/components"],
|
|
7
7
|
},
|
|
8
8
|
devtools: { enabled: true },
|
|
9
9
|
colorMode: {
|
|
10
|
-
preference:
|
|
10
|
+
preference: "light",
|
|
11
11
|
},
|
|
12
|
-
compatibilityDate:
|
|
13
|
-
})
|
|
12
|
+
compatibilityDate: "2025-01-31",
|
|
13
|
+
});
|
package/playground/package.json
CHANGED
|
@@ -1,17 +1,11 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<div class="w-full flex justify-center">
|
|
3
|
-
<div class="w-full max-w-[
|
|
4
|
-
<
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
@submit="onSubmit"
|
|
10
|
-
>
|
|
11
|
-
<template #submit>
|
|
12
|
-
{{ undefined }}
|
|
13
|
-
</template>
|
|
14
|
-
</SForm>
|
|
3
|
+
<div class="w-full max-w-[1200px] p-10">
|
|
4
|
+
<div class="pb-10 flex place-content-between">
|
|
5
|
+
<h1>Demo</h1>
|
|
6
|
+
<ColorMode />
|
|
7
|
+
</div>
|
|
8
|
+
<Editor :schema="schema" />
|
|
15
9
|
</div>
|
|
16
10
|
</div>
|
|
17
11
|
</template>
|
|
@@ -19,12 +13,8 @@
|
|
|
19
13
|
<script lang="ts" setup>
|
|
20
14
|
import ColorMode from '@/components/ColorMode.vue'
|
|
21
15
|
import formSchema from '@/assets/schema.json'
|
|
22
|
-
import { Draft2019 } from 'json-schema-library'
|
|
23
16
|
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
const schema = ref(parsedSchema.rootSchema)
|
|
27
|
-
const state = ref(parsedSchema.getTemplate())
|
|
17
|
+
const schema = ref(formSchema)
|
|
28
18
|
|
|
29
19
|
const onSubmit = (value: unknown) => {
|
|
30
20
|
console.log(value)
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// import { defineNuxtPlugin } from "#app";
|
|
2
|
+
// import * as monaco from "monaco-editor";
|
|
3
|
+
//
|
|
4
|
+
export default defineNuxtPlugin(() => {
|
|
5
|
+
// monaco.editor.defineTheme("myCustomTheme", {
|
|
6
|
+
// base: "vs-dark", // Base theme can be 'vs', 'vs-dark', or 'hc-black'
|
|
7
|
+
// inherit: true, // Inherit rules from the base theme
|
|
8
|
+
// rules: [
|
|
9
|
+
// { token: "comment", foreground: "ffa500" },
|
|
10
|
+
// { token: "keyword", foreground: "008800", fontStyle: "bold" },
|
|
11
|
+
// // Add more rules as needed
|
|
12
|
+
// ],
|
|
13
|
+
// colors: {
|
|
14
|
+
// "editor.background": "#1e1e1e",
|
|
15
|
+
// "editor.foreground": "#d4d4d4",
|
|
16
|
+
// // Add more colors as needed
|
|
17
|
+
// },
|
|
18
|
+
// });
|
|
19
|
+
});
|
|
@@ -12,13 +12,13 @@ export type SComponentProps = {
|
|
|
12
12
|
type: string
|
|
13
13
|
properties?: Properties
|
|
14
14
|
enum?: string[]
|
|
15
|
-
description?: string
|
|
15
|
+
description?: string
|
|
16
16
|
jsonSchemaPath: string
|
|
17
17
|
validateFields: (fields: string[]) => Promise<boolean>
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
const props = defineProps<SComponentProps>()
|
|
21
|
-
const value = defineModel<unknown>({ required: true })
|
|
21
|
+
const value = defineModel<unknown>({ required: true, default: '' })
|
|
22
22
|
|
|
23
23
|
const options = computed(() => ({
|
|
24
24
|
...props,
|
|
@@ -35,23 +35,9 @@ const options = computed(() => ({
|
|
|
35
35
|
v-model="value"
|
|
36
36
|
/>
|
|
37
37
|
|
|
38
|
-
<SInputField
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
/>
|
|
43
|
-
<SToggle
|
|
44
|
-
v-else-if="type === 'boolean'"
|
|
45
|
-
v-bind="options"
|
|
46
|
-
v-model="value"
|
|
47
|
-
/>
|
|
48
|
-
<SObject
|
|
49
|
-
v-else-if="type === 'object'"
|
|
50
|
-
v-bind="options"
|
|
51
|
-
v-model="value"
|
|
52
|
-
/>
|
|
53
|
-
<div v-else>
|
|
54
|
-
else
|
|
55
|
-
</div>
|
|
38
|
+
<SInputField v-else-if="type === 'string'" v-bind="options" v-model="value" />
|
|
39
|
+
<SToggle v-else-if="type === 'boolean'" v-bind="options" v-model="value" />
|
|
40
|
+
<SObject v-else-if="type === 'object'" v-bind="options" v-model="value" />
|
|
41
|
+
<div v-else>else</div>
|
|
56
42
|
</div>
|
|
57
43
|
</template>
|