@ederzeel/nuxt-schema-form-nightly 0.1.0-28998176.40c4602 → 0.1.0-29020128.b61d8e4

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 CHANGED
@@ -6,6 +6,40 @@ Runtime form generation for Nuxt apps.
6
6
 
7
7
  ### Install
8
8
 
9
- 1. Install the `@LiamEderzeel/nuxt-schema-form` module to your project
9
+ 1. Install the `@ederzeel/nuxt-schema-form` module to your project
10
10
 
11
- `pnpm install @LiamEderzeel/nuxt-schema-form`
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 : renderer.name"
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(null)
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?.validate(field, { silent: true }))) {
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
- ref="formRef"
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: string
5
- description: string
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
- :label="props.title || id"
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
- <h3>{{ props.properties.title }}</h3>
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)"
@@ -1,8 +1,8 @@
1
1
  <script lang="ts" setup>
2
2
  const props = defineProps<{
3
3
  id: string
4
- title: string
5
- description: string
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
- :label="props.title || id"
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: string
5
- description: string
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
- :label="props.title || id"
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: string
5
- description: string
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-28998176.40c4602",
3
+ "version": "0.1.0-29020128.b61d8e4",
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"