@ederzeel/nuxt-schema-form-nightly 0.1.0-28998176.40c4602 → 0.1.0-29021155.86a2d08
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 +36 -2
- package/dist/runtime/components/SComponent.vue +1 -1
- package/dist/runtime/components/SForm.vue +5 -20
- package/dist/runtime/components/SInputField.vue +4 -11
- package/dist/runtime/components/SObject.vue +4 -1
- package/dist/runtime/components/SRow.vue +38 -0
- package/dist/runtime/components/SSelect.vue +4 -12
- package/dist/runtime/components/STextarea.vue +4 -11
- package/dist/runtime/components/SToggle.vue +3 -7
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -6,6 +6,40 @@ Runtime form generation for Nuxt apps.
|
|
|
6
6
|
|
|
7
7
|
### Install
|
|
8
8
|
|
|
9
|
-
1. Install the `@
|
|
9
|
+
1. Install the `@ederzeel/nuxt-schema-form` module to your project
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
`$ npx nuxi module add @ederzeel/nuxt-schema-form`
|
|
12
|
+
|
|
13
|
+
### Usage
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
<script lang="ts" setup>
|
|
17
|
+
import { Draft2019 } from 'json-schema-library'
|
|
18
|
+
|
|
19
|
+
const schemaObject = ref(
|
|
20
|
+
new Draft2019({
|
|
21
|
+
title: 'From',
|
|
22
|
+
description: 'A minimal form example',
|
|
23
|
+
type: 'object',
|
|
24
|
+
required: ['firstname'],
|
|
25
|
+
properties: {
|
|
26
|
+
firstname: {
|
|
27
|
+
title: 'Firstname',
|
|
28
|
+
description: 'Firstname field for submitting a first name',
|
|
29
|
+
type: 'string',
|
|
30
|
+
default: ''
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
})
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
const schema = ref(schemaObject.value.rootSchema)
|
|
37
|
+
const state = ref(schemaObject.value.getTemplate())
|
|
38
|
+
</script>
|
|
39
|
+
|
|
40
|
+
<template>
|
|
41
|
+
<div>
|
|
42
|
+
<SForm v-if="schema" v-model="state" :schema="schema"> </SForm>
|
|
43
|
+
</div>
|
|
44
|
+
</template>
|
|
45
|
+
```
|
|
@@ -30,7 +30,7 @@ const options = computed(() => ({
|
|
|
30
30
|
<div class="s-form-group">
|
|
31
31
|
<component
|
|
32
32
|
v-bind="options"
|
|
33
|
-
:is="typeof renderer === 'string' ? renderer :
|
|
33
|
+
:is="typeof renderer === 'string' ? renderer : undefined"
|
|
34
34
|
v-if="renderer"
|
|
35
35
|
v-model="value"
|
|
36
36
|
/>
|
|
@@ -7,7 +7,7 @@ import { computed, ref } from 'vue'
|
|
|
7
7
|
const props = defineProps<{ schema: JsonSchema }>()
|
|
8
8
|
|
|
9
9
|
const value = defineModel<Record<string, unknown>>({ required: true })
|
|
10
|
-
const formRef = ref(
|
|
10
|
+
const formRef = ref()
|
|
11
11
|
|
|
12
12
|
const emit = defineEmits(['submit'])
|
|
13
13
|
|
|
@@ -20,7 +20,7 @@ const formValidationSchema = computed(() => convertToYup(props.schema))
|
|
|
20
20
|
const validateFields = async (fields: string[]) => {
|
|
21
21
|
let allValid = true
|
|
22
22
|
for (const field of fields) {
|
|
23
|
-
if (!(await formRef.value
|
|
23
|
+
if (!(await formRef.value.validate(field, { silent: true }))) {
|
|
24
24
|
allValid = false
|
|
25
25
|
}
|
|
26
26
|
}
|
|
@@ -31,27 +31,12 @@ const validateFields = async (fields: string[]) => {
|
|
|
31
31
|
|
|
32
32
|
<template>
|
|
33
33
|
<div>
|
|
34
|
-
<UForm
|
|
35
|
-
|
|
36
|
-
:state="value"
|
|
37
|
-
:schema="formValidationSchema"
|
|
38
|
-
autocomplete="on"
|
|
39
|
-
@submit="onSubmit"
|
|
40
|
-
>
|
|
41
|
-
<SComponent
|
|
42
|
-
v-model="value"
|
|
43
|
-
v-bind="schema"
|
|
44
|
-
:validate-fields="validateFields"
|
|
45
|
-
/>
|
|
34
|
+
<UForm ref="formRef" :state="value" :schema="formValidationSchema" autocomplete="on" @submit="onSubmit">
|
|
35
|
+
<SComponent v-model="value" v-bind="schema" :validate-fields="validateFields" />
|
|
46
36
|
<slot />
|
|
47
37
|
|
|
48
38
|
<slot name="submit">
|
|
49
|
-
<UButton
|
|
50
|
-
class="btn"
|
|
51
|
-
type="submit"
|
|
52
|
-
>
|
|
53
|
-
Submit
|
|
54
|
-
</UButton>
|
|
39
|
+
<UButton class="btn" type="submit"> Submit </UButton>
|
|
55
40
|
</slot>
|
|
56
41
|
</UForm>
|
|
57
42
|
</div>
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
<script lang="ts" setup>
|
|
2
2
|
const props = defineProps<{
|
|
3
3
|
id: string
|
|
4
|
-
title
|
|
5
|
-
description
|
|
4
|
+
title?: string
|
|
5
|
+
description?: string
|
|
6
6
|
type: string
|
|
7
7
|
}>()
|
|
8
8
|
|
|
@@ -11,15 +11,8 @@ const value = defineModel<string | number>({ required: true })
|
|
|
11
11
|
|
|
12
12
|
<template>
|
|
13
13
|
<div>
|
|
14
|
-
<UFormGroup
|
|
15
|
-
:
|
|
16
|
-
:description="props.description"
|
|
17
|
-
:name="props.id"
|
|
18
|
-
>
|
|
19
|
-
<UInput
|
|
20
|
-
v-model="value"
|
|
21
|
-
:type="props.type"
|
|
22
|
-
/>
|
|
14
|
+
<UFormGroup :label="props.title || id" :description="props.description" :name="props.id">
|
|
15
|
+
<UInput v-model="value" :type="props.type" />
|
|
23
16
|
</UFormGroup>
|
|
24
17
|
</div>
|
|
25
18
|
</template>
|
|
@@ -3,6 +3,8 @@ import SComponent from './SComponent.vue'
|
|
|
3
3
|
|
|
4
4
|
const props = defineProps<{
|
|
5
5
|
id: string
|
|
6
|
+
title?: string
|
|
7
|
+
description?: string
|
|
6
8
|
jsonSchemaPath: string
|
|
7
9
|
properties: PropertiesType
|
|
8
10
|
modelValue: Record<string, unknown>
|
|
@@ -19,7 +21,8 @@ const onInput = (value: unknown, key: string) => {
|
|
|
19
21
|
|
|
20
22
|
<template>
|
|
21
23
|
<div>
|
|
22
|
-
<
|
|
24
|
+
<h2 v-if="props.title" class="mb-4 text-2xl leading-none tracking-tight">{{ props.title }}</h2>
|
|
25
|
+
<p v-if="props.description" class="mb-4">{{ props.description }}</p>
|
|
23
26
|
|
|
24
27
|
<SComponent
|
|
25
28
|
v-for="[key, options] of Object.entries(properties)"
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
<script lang="ts" setup>
|
|
2
|
+
import SComponent from './SComponent.vue'
|
|
3
|
+
|
|
4
|
+
const props = defineProps<{
|
|
5
|
+
id: string
|
|
6
|
+
title?: string
|
|
7
|
+
description?: string
|
|
8
|
+
jsonSchemaPath: string
|
|
9
|
+
properties: PropertiesType
|
|
10
|
+
modelValue: Record<string, unknown>
|
|
11
|
+
}>()
|
|
12
|
+
|
|
13
|
+
type PropertiesType = {
|
|
14
|
+
[key: string]: unknown
|
|
15
|
+
}
|
|
16
|
+
const emit = defineEmits(['update:modelValue'])
|
|
17
|
+
const onInput = (value: unknown, key: string) => {
|
|
18
|
+
emit('update:modelValue', { ...props.modelValue, [key]: value })
|
|
19
|
+
}
|
|
20
|
+
</script>
|
|
21
|
+
|
|
22
|
+
<template>
|
|
23
|
+
<div class="flex flex-row gap-4 justify-stretch">
|
|
24
|
+
<h2 v-if="props.title" class="mb-4 text-2xl leading-none tracking-tight">{{ props.title }}</h2>
|
|
25
|
+
<p v-if="props.description" class="mb-4">{{ props.description }}</p>
|
|
26
|
+
|
|
27
|
+
<SComponent
|
|
28
|
+
v-for="[key, options] of Object.entries(properties)"
|
|
29
|
+
:id="id.length <= 0 ? `${key}` : `${id}.${key}`"
|
|
30
|
+
:key="key"
|
|
31
|
+
:model-value="modelValue[key]"
|
|
32
|
+
:json-schema-path="jsonSchemaPath?.length <= 0 ? `properties.${key}` : `${jsonSchemaPath}.properties.${key}`"
|
|
33
|
+
v-bind="options"
|
|
34
|
+
class="flex flex-col flex-1"
|
|
35
|
+
@update:model-value="event => onInput(event, key)"
|
|
36
|
+
/>
|
|
37
|
+
</div>
|
|
38
|
+
</template>
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
<script lang="ts" setup>
|
|
2
2
|
const props = defineProps<{
|
|
3
3
|
id: string
|
|
4
|
-
title
|
|
5
|
-
description
|
|
4
|
+
title?: string
|
|
5
|
+
description?: string
|
|
6
6
|
enum: string[]
|
|
7
7
|
}>()
|
|
8
8
|
|
|
@@ -11,16 +11,8 @@ const value = defineModel<string>({ required: true })
|
|
|
11
11
|
|
|
12
12
|
<template>
|
|
13
13
|
<div>
|
|
14
|
-
<UFormGroup
|
|
15
|
-
:
|
|
16
|
-
:description="props.description"
|
|
17
|
-
:name="props.id"
|
|
18
|
-
>
|
|
19
|
-
<USelect
|
|
20
|
-
v-model="value"
|
|
21
|
-
placeholder="select size"
|
|
22
|
-
:options="props.enum"
|
|
23
|
-
/>
|
|
14
|
+
<UFormGroup :label="props.title || id" :description="props.description" :name="props.id">
|
|
15
|
+
<USelect v-model="value" placeholder="select size" :options="props.enum" />
|
|
24
16
|
</UFormGroup>
|
|
25
17
|
</div>
|
|
26
18
|
</template>
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
<script lang="ts" setup>
|
|
2
2
|
const props = defineProps<{
|
|
3
3
|
id: string
|
|
4
|
-
title
|
|
5
|
-
description
|
|
4
|
+
title?: string
|
|
5
|
+
description?: string
|
|
6
6
|
}>()
|
|
7
7
|
|
|
8
8
|
const value = defineModel<string | number>({ required: true })
|
|
@@ -10,15 +10,8 @@ const value = defineModel<string | number>({ required: true })
|
|
|
10
10
|
|
|
11
11
|
<template>
|
|
12
12
|
<div>
|
|
13
|
-
<UFormGroup
|
|
14
|
-
|
|
15
|
-
:description="props.description"
|
|
16
|
-
:name="props.id"
|
|
17
|
-
>
|
|
18
|
-
<UTextarea
|
|
19
|
-
v-model="value"
|
|
20
|
-
v-bind="properties"
|
|
21
|
-
/>
|
|
13
|
+
<UFormGroup :label="props.title || id" :description="props.description" :name="props.id">
|
|
14
|
+
<UTextarea v-model="value" v-bind="properties" />
|
|
22
15
|
</UFormGroup>
|
|
23
16
|
</div>
|
|
24
17
|
</template>
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
<script lang="ts" setup>
|
|
2
2
|
const props = defineProps<{
|
|
3
3
|
id: string
|
|
4
|
-
title
|
|
5
|
-
description
|
|
4
|
+
title?: string
|
|
5
|
+
description?: string
|
|
6
6
|
}>()
|
|
7
7
|
|
|
8
8
|
const value = defineModel<boolean>({ required: true })
|
|
@@ -10,11 +10,7 @@ const value = defineModel<boolean>({ required: true })
|
|
|
10
10
|
|
|
11
11
|
<template>
|
|
12
12
|
<div>
|
|
13
|
-
<UFormGroup
|
|
14
|
-
:label="props.title || id"
|
|
15
|
-
:description="props.description"
|
|
16
|
-
:name="props.id"
|
|
17
|
-
>
|
|
13
|
+
<UFormGroup :label="props.title || id" :description="props.description" :name="props.id">
|
|
18
14
|
<UToggle v-model="value" />
|
|
19
15
|
</UFormGroup>
|
|
20
16
|
</div>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ederzeel/nuxt-schema-form-nightly",
|
|
3
|
-
"version": "0.1.0-
|
|
3
|
+
"version": "0.1.0-29021155.86a2d08",
|
|
4
4
|
"description": "A runtime form generator for nuxt",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -34,6 +34,7 @@
|
|
|
34
34
|
"form"
|
|
35
35
|
],
|
|
36
36
|
"author": "Liam Ederzeel",
|
|
37
|
+
"funding": "https://github.com/sponsors/liamederzeel",
|
|
37
38
|
"license": "MIT",
|
|
38
39
|
"bugs": {
|
|
39
40
|
"url": "https://github.com/LiamEderzeel/nuxt-schema-form/issues"
|