@ederzeel/nuxt-schema-form-nightly 0.1.0-29022504.228f28e → 0.1.0-29031029.28754c0
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/dist/runtime/components/SComponent.vue +10 -10
- package/dist/runtime/components/SDate.vue +5 -1
- package/dist/runtime/components/SForm.vue +25 -2
- package/dist/runtime/components/SObject.vue +2 -1
- package/dist/runtime/components/SSelect.vue +1 -1
- package/dist/runtime/components/STextarea.vue +1 -1
- package/package.json +12 -2
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<script lang="ts" setup>
|
|
2
|
-
import { computed } from 'vue'
|
|
2
|
+
import { computed, defineEmits } from 'vue'
|
|
3
3
|
|
|
4
4
|
type Properties = {
|
|
5
5
|
properties?: { [key: string]: unknown }
|
|
@@ -23,26 +23,26 @@ export type SComponentProps = {
|
|
|
23
23
|
|
|
24
24
|
const props = withDefaults(defineProps<SComponentProps>(), { id: '', jsonSchemaPath: 'test' })
|
|
25
25
|
const value = defineModel<unknown>({ required: true, default: '' })
|
|
26
|
+
const emit = defineEmits(['submit'])
|
|
26
27
|
|
|
27
28
|
const options = computed(() => ({
|
|
28
29
|
...props,
|
|
29
|
-
jsonSchemaPath: `${props.
|
|
30
|
+
jsonSchemaPath: `${props.jsonSchemaPath}.${props.id}`
|
|
30
31
|
}))
|
|
32
|
+
const onSubmit = () => {
|
|
33
|
+
emit('submit')
|
|
34
|
+
}
|
|
31
35
|
</script>
|
|
32
36
|
|
|
33
37
|
<template>
|
|
34
38
|
<div class="s-form-group">
|
|
35
|
-
<component
|
|
36
|
-
|
|
37
|
-
:is="typeof renderer === 'string' ? renderer : undefined"
|
|
38
|
-
v-if="renderer"
|
|
39
|
-
v-model="value"
|
|
40
|
-
/>
|
|
39
|
+
<component v-if="renderer" v-bind="options" v-model="value"
|
|
40
|
+
:is="typeof renderer === 'string' ? renderer : undefined" @submit="onSubmit" />
|
|
41
41
|
|
|
42
|
-
<SDate v-else-if="type === 'string' && format === 'date
|
|
42
|
+
<SDate v-else-if="type === 'string' && format === 'full-date'" v-bind="options" v-model="value" />
|
|
43
43
|
<SInputField v-else-if="type === 'string'" v-bind="options" v-model="value" />
|
|
44
44
|
<SToggle v-else-if="type === 'boolean'" v-bind="options" v-model="value" />
|
|
45
|
-
<SObject v-else-if="type === 'object'" v-bind="options" v-model="value" />
|
|
45
|
+
<SObject v-else-if="type === 'object'" v-bind="options" v-model="value" @submit="onSubmit" />
|
|
46
46
|
<div v-else>else</div>
|
|
47
47
|
</div>
|
|
48
48
|
</template>
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
<script lang="ts" setup>
|
|
2
2
|
import { format } from 'date-fns'
|
|
3
|
-
import {
|
|
3
|
+
import { ref, watch } from 'vue'
|
|
4
4
|
import DatePicker from './DatePicker.vue'
|
|
5
|
+
|
|
5
6
|
const props = defineProps<{
|
|
6
7
|
id: string
|
|
7
8
|
title?: string
|
|
@@ -12,6 +13,9 @@ const props = defineProps<{
|
|
|
12
13
|
|
|
13
14
|
const value = defineModel<string>({ required: true })
|
|
14
15
|
const date = ref(new Date(value.value))
|
|
16
|
+
watch(date, () => {
|
|
17
|
+
value.value = date.value.toISOString()
|
|
18
|
+
})
|
|
15
19
|
</script>
|
|
16
20
|
|
|
17
21
|
<template>
|
|
@@ -4,7 +4,7 @@ import convertToYup from 'json-schema-yup-transformer'
|
|
|
4
4
|
import type { JsonSchema } from 'json-schema-library'
|
|
5
5
|
import { computed, ref } from 'vue'
|
|
6
6
|
|
|
7
|
-
const props = defineProps<{ schema: JsonSchema }>()
|
|
7
|
+
const props = defineProps<{ schema: JsonSchema; customValidation?: CustomValidation[] }>()
|
|
8
8
|
|
|
9
9
|
const value = defineModel<Record<string, unknown>>({ required: true })
|
|
10
10
|
const formRef = ref()
|
|
@@ -17,6 +17,12 @@ async function onSubmit(_event: unknown) {
|
|
|
17
17
|
|
|
18
18
|
const formValidationSchema = computed(() => convertToYup(props.schema))
|
|
19
19
|
|
|
20
|
+
export type CustomValidation = {
|
|
21
|
+
field: string
|
|
22
|
+
message: string
|
|
23
|
+
validate(state: any): boolean
|
|
24
|
+
}
|
|
25
|
+
|
|
20
26
|
const validateFields = async (fields: string[]) => {
|
|
21
27
|
let allValid = true
|
|
22
28
|
for (const field of fields) {
|
|
@@ -25,14 +31,31 @@ const validateFields = async (fields: string[]) => {
|
|
|
25
31
|
}
|
|
26
32
|
}
|
|
27
33
|
|
|
34
|
+
if (props.customValidation) {
|
|
35
|
+
for (const { field, message, validate } of props.customValidation) {
|
|
36
|
+
if (!fields.includes(field)) continue
|
|
37
|
+
if (!validate(value.value)) {
|
|
38
|
+
const errors = [{ path: field, message }]
|
|
39
|
+
formRef.value.setErrors(errors, field)
|
|
40
|
+
allValid = false
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
28
45
|
return allValid
|
|
29
46
|
}
|
|
47
|
+
|
|
48
|
+
const submit = () => {
|
|
49
|
+
formRef.value.submit()
|
|
50
|
+
}
|
|
30
51
|
</script>
|
|
31
52
|
|
|
32
53
|
<template>
|
|
33
54
|
<div>
|
|
55
|
+
<!-- {{ formRef ? formRef.errors : undefined }} -->
|
|
34
56
|
<UForm ref="formRef" :state="value" :schema="formValidationSchema" autocomplete="on" @submit="onSubmit">
|
|
35
|
-
<SComponent v-model="value" v-bind="schema" :validate-fields="validateFields"
|
|
57
|
+
<SComponent v-model="value" v-bind="schema" :validate-fields="validateFields" @submit="submit"
|
|
58
|
+
:isRequired="true" />
|
|
36
59
|
<slot />
|
|
37
60
|
|
|
38
61
|
<slot name="submit">
|
|
@@ -15,7 +15,7 @@ const props = defineProps<{
|
|
|
15
15
|
type PropertiesType = {
|
|
16
16
|
[key: string]: unknown
|
|
17
17
|
}
|
|
18
|
-
const emit = defineEmits(['update:modelValue'])
|
|
18
|
+
const emit = defineEmits(['update:modelValue', 'submit'])
|
|
19
19
|
const onInput = (value: unknown, key: string) => {
|
|
20
20
|
emit('update:modelValue', { ...props.modelValue, [key]: value })
|
|
21
21
|
}
|
|
@@ -36,6 +36,7 @@ const onInput = (value: unknown, key: string) => {
|
|
|
36
36
|
:isRequired="required.includes(key)"
|
|
37
37
|
class="mt-4"
|
|
38
38
|
@update:model-value="event => onInput(event, key)"
|
|
39
|
+
@submit="() => emit('submit')"
|
|
39
40
|
/>
|
|
40
41
|
</div>
|
|
41
42
|
</template>
|
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-29031029.28754c0",
|
|
4
4
|
"description": "A runtime form generator for nuxt",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -20,6 +20,10 @@
|
|
|
20
20
|
"dev": "nuxi dev playground",
|
|
21
21
|
"dev:build": "nuxi build playground",
|
|
22
22
|
"dev:prepare": "nuxt-module-build build --stub && nuxt-module-build prepare && nuxi prepare playground",
|
|
23
|
+
"docs:dev": "nuxi dev docs",
|
|
24
|
+
"docs:build": "nuxi build docs",
|
|
25
|
+
"docs:generate": "nuxi generate docs",
|
|
26
|
+
"docs:preview": "nuxi preview docs",
|
|
23
27
|
"test": "vitest test",
|
|
24
28
|
"lint": "eslint .",
|
|
25
29
|
"release": "bumpp --commit \"release: v%s\" --push --tag"
|
|
@@ -40,12 +44,18 @@
|
|
|
40
44
|
"url": "https://github.com/LiamEderzeel/nuxt-schema-form/issues"
|
|
41
45
|
},
|
|
42
46
|
"homepage": "https://github.com/LiamEderzeel/nuxt-schema-form#readme",
|
|
43
|
-
"packageManager": "pnpm@
|
|
47
|
+
"packageManager": "pnpm@10.1.0+sha512.c89847b0667ddab50396bbbd008a2a43cf3b581efd59cf5d9aa8923ea1fb4b8106c041d540d08acb095037594d73ebc51e1ec89ee40c88b30b8a66c0fae0ac1b",
|
|
48
|
+
"pnpm": {
|
|
49
|
+
"onlyBuiltDependencies": [
|
|
50
|
+
"better-sqlite3"
|
|
51
|
+
]
|
|
52
|
+
},
|
|
44
53
|
"devDependencies": {
|
|
45
54
|
"@eslint/js": "^9.19.0",
|
|
46
55
|
"@nuxt/eslint-config": "^1.0.0",
|
|
47
56
|
"@nuxt/kit": "^3.15.4",
|
|
48
57
|
"@nuxt/module-builder": "^0.8.4",
|
|
58
|
+
"@nuxt/ui": "^2.21.0",
|
|
49
59
|
"@types/eslint": "^9.6.1",
|
|
50
60
|
"eslint": "^9.19.0",
|
|
51
61
|
"eslint-config-prettier": "^10.0.1",
|