pdyform 2.0.1 → 2.0.2
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/packages/core/dist/chunk-TP3IHKWV.js +69 -0
- package/packages/core/dist/{chunk-GQASS6PM.js → chunk-WEDHXOHH.js} +22 -0
- package/packages/core/dist/formState.cjs +187 -0
- package/packages/core/dist/formState.d.cts +17 -0
- package/packages/core/dist/formState.d.ts +17 -0
- package/packages/core/dist/formState.js +15 -0
- package/packages/core/dist/index.cjs +92 -2
- package/packages/core/dist/index.d.cts +2 -1
- package/packages/core/dist/index.d.ts +2 -1
- package/packages/core/dist/index.js +21 -3
- package/packages/core/dist/utils.cjs +27 -2
- package/packages/core/dist/utils.d.cts +4 -1
- package/packages/core/dist/utils.d.ts +4 -1
- package/packages/core/dist/utils.js +9 -3
- package/packages/core/node_modules/.vite/vitest/results.json +1 -1
- package/packages/core/src/formState.ts +79 -0
- package/packages/core/src/index.ts +1 -0
- package/packages/core/src/utils.ts +24 -0
- package/packages/core/test/formState.test.ts +71 -0
- package/packages/core/test/utils.test.ts +80 -1
- package/packages/core/tsup.config.ts +1 -1
- package/packages/react/dist/index.cjs +14 -43
- package/packages/react/dist/index.js +20 -43
- package/packages/react/node_modules/.vite/vitest/results.json +1 -1
- package/packages/react/src/DynamicForm.tsx +20 -44
- package/packages/react/src/components/InputRenderer.tsx +2 -6
- package/packages/vue/dist/index.js +5 -5
- package/packages/vue/dist/index.mjs +769 -787
- package/packages/vue/node_modules/.vite/vitest/results.json +1 -1
- package/packages/vue/src/DynamicForm.vue +18 -36
- package/packages/vue/src/components/InputRenderer.vue +2 -6
- package/packages/core/dist/parser.cjs +0 -1
- package/packages/core/dist/parser.d.cts +0 -2
- package/packages/core/dist/parser.d.ts +0 -2
- package/packages/core/dist/parser.js +0 -0
- package/packages/core/src/parser.ts +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":"1.6.1","results":[[":test/DynamicForm.test.ts",{"duration":
|
|
1
|
+
{"version":"1.6.1","results":[[":test/DynamicForm.test.ts",{"duration":19,"failed":false}],[":test/FormFieldRenderer.test.ts",{"duration":77,"failed":false}]]}
|
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
-
import { ref
|
|
3
|
-
import type { FormSchema } from 'pdyform/core';
|
|
4
|
-
import {
|
|
2
|
+
import { ref } from 'vue';
|
|
3
|
+
import type { FormSchema, FormRuntimeState } from 'pdyform/core';
|
|
4
|
+
import {
|
|
5
|
+
createFormRuntimeState,
|
|
6
|
+
applyFieldChange,
|
|
7
|
+
runSubmitValidation,
|
|
8
|
+
setSubmitting,
|
|
9
|
+
} from 'pdyform/core';
|
|
5
10
|
import FormFieldRenderer from './FormFieldRenderer.vue';
|
|
6
11
|
|
|
7
12
|
const props = defineProps<{
|
|
@@ -11,43 +16,20 @@ const props = defineProps<{
|
|
|
11
16
|
|
|
12
17
|
const emit = defineEmits(['submit']);
|
|
13
18
|
|
|
14
|
-
const
|
|
15
|
-
const errors = ref<Record<string, string>>({});
|
|
16
|
-
const isSubmitting = ref(false);
|
|
17
|
-
|
|
18
|
-
onMounted(() => {
|
|
19
|
-
values.value = getDefaultValues(props.schema.fields);
|
|
20
|
-
});
|
|
19
|
+
const formState = ref<FormRuntimeState>(createFormRuntimeState(props.schema.fields));
|
|
21
20
|
|
|
22
21
|
const handleFieldChange = (name: string, value: any) => {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
const field = props.schema.fields.find(f => f.name === name);
|
|
26
|
-
if (field) {
|
|
27
|
-
const error = validateField(value, field);
|
|
28
|
-
errors.value[name] = error || '';
|
|
29
|
-
}
|
|
22
|
+
formState.value = applyFieldChange(props.schema.fields, formState.value, name, value);
|
|
30
23
|
};
|
|
31
24
|
|
|
32
25
|
const handleSubmit = () => {
|
|
33
|
-
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
props.schema.fields.forEach((field) => {
|
|
38
|
-
const error = validateField(values.value[field.name], field);
|
|
39
|
-
if (error) {
|
|
40
|
-
newErrors[field.name] = error;
|
|
41
|
-
hasError = true;
|
|
42
|
-
}
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
errors.value = newErrors;
|
|
26
|
+
const submittingState = setSubmitting(formState.value, true);
|
|
27
|
+
const { state: validatedState, hasError } = runSubmitValidation(props.schema.fields, submittingState);
|
|
28
|
+
formState.value = validatedState;
|
|
46
29
|
|
|
47
30
|
if (!hasError) {
|
|
48
|
-
emit('submit', { ...values
|
|
31
|
+
emit('submit', { ...validatedState.values });
|
|
49
32
|
}
|
|
50
|
-
isSubmitting.value = false;
|
|
51
33
|
};
|
|
52
34
|
</script>
|
|
53
35
|
|
|
@@ -63,8 +45,8 @@ const handleSubmit = () => {
|
|
|
63
45
|
<FormFieldRenderer
|
|
64
46
|
v-if="!field.hidden"
|
|
65
47
|
:field="field"
|
|
66
|
-
:model-value="values[field.name]"
|
|
67
|
-
:error="errors[field.name]"
|
|
48
|
+
:model-value="formState.values[field.name]"
|
|
49
|
+
:error="formState.errors[field.name]"
|
|
68
50
|
@update:model-value="(val: any) => handleFieldChange(field.name, val)"
|
|
69
51
|
/>
|
|
70
52
|
</template>
|
|
@@ -72,10 +54,10 @@ const handleSubmit = () => {
|
|
|
72
54
|
|
|
73
55
|
<button
|
|
74
56
|
type="submit"
|
|
75
|
-
:disabled="isSubmitting"
|
|
57
|
+
:disabled="formState.isSubmitting"
|
|
76
58
|
class="inline-flex items-center justify-center rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 bg-primary text-primary-foreground hover:bg-primary/90 h-10 px-4 py-2 w-full"
|
|
77
59
|
>
|
|
78
|
-
{{ isSubmitting ? 'Submitting...' : (schema.submitButtonText || 'Submit') }}
|
|
60
|
+
{{ formState.isSubmitting ? 'Submitting...' : (schema.submitButtonText || 'Submit') }}
|
|
79
61
|
</button>
|
|
80
62
|
</form>
|
|
81
63
|
</template>
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
+
import { normalizeFieldValue } from 'pdyform/core';
|
|
2
3
|
import type { FieldRendererProps } from '../fieldComponentMap';
|
|
3
4
|
import Input from '../components/Input.vue';
|
|
4
5
|
|
|
@@ -6,12 +7,7 @@ const props = defineProps<FieldRendererProps>();
|
|
|
6
7
|
const emit = defineEmits<{ 'update:modelValue': [value: any] }>();
|
|
7
8
|
|
|
8
9
|
const handleInput = (nextValue: any) => {
|
|
9
|
-
|
|
10
|
-
emit('update:modelValue', nextValue);
|
|
11
|
-
return;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
emit('update:modelValue', nextValue === '' ? '' : Number(nextValue));
|
|
10
|
+
emit('update:modelValue', normalizeFieldValue(props.field, nextValue));
|
|
15
11
|
};
|
|
16
12
|
</script>
|
|
17
13
|
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
File without changes
|
|
File without changes
|