@teamnovu/kit-vue-forms 0.0.17 → 0.0.18
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/{index.mjs → index.js} +8 -9
- package/dist/types/util.d.ts +1 -1
- package/package.json +2 -1
- package/src/composables/useForm.ts +0 -1
- package/src/types/util.ts +1 -1
- package/tests/formState.test.ts +10 -3
- package/tests/subform.test.ts +19 -0
- package/tests/useForm.test.ts +22 -0
- package/vitest.config.ts +2 -0
|
@@ -3,7 +3,6 @@ var G = (e, r, t) => r in e ? T(e, r, { enumerable: !0, configurable: !0, writab
|
|
|
3
3
|
var _ = (e, r, t) => G(e, typeof r != "symbol" ? r + "" : r, t);
|
|
4
4
|
import { toValue as L, toRaw as Z, computed as u, unref as d, reactive as E, toRefs as N, toRef as D, ref as W, watch as y, isRef as z, getCurrentScope as q, onBeforeUnmount as H, defineComponent as S, renderSlot as j, normalizeProps as M, guardReactiveProps as B, resolveComponent as Q, createBlock as O, openBlock as $, withCtx as A, resolveDynamicComponent as X, mergeProps as Y } from "vue";
|
|
5
5
|
import "zod";
|
|
6
|
-
import "@vueuse/core";
|
|
7
6
|
function g(e) {
|
|
8
7
|
const r = L(e), t = Z(r);
|
|
9
8
|
return structuredClone(t);
|
|
@@ -391,7 +390,7 @@ function fr(e, r, t) {
|
|
|
391
390
|
}
|
|
392
391
|
};
|
|
393
392
|
}
|
|
394
|
-
function
|
|
393
|
+
function Fr(e) {
|
|
395
394
|
const r = u(() => Object.freeze(g(e.initialData))), t = W(g(r)), s = E({
|
|
396
395
|
initialData: r,
|
|
397
396
|
data: t
|
|
@@ -418,7 +417,7 @@ function Er(e) {
|
|
|
418
417
|
};
|
|
419
418
|
return l;
|
|
420
419
|
}
|
|
421
|
-
const
|
|
420
|
+
const Er = /* @__PURE__ */ S({
|
|
422
421
|
__name: "Field",
|
|
423
422
|
props: {
|
|
424
423
|
form: {},
|
|
@@ -433,7 +432,7 @@ const wr = /* @__PURE__ */ S({
|
|
|
433
432
|
}), s = E(t);
|
|
434
433
|
return (a, o) => j(a.$slots, "default", M(B(s)));
|
|
435
434
|
}
|
|
436
|
-
}),
|
|
435
|
+
}), wr = /* @__PURE__ */ S({
|
|
437
436
|
inheritAttrs: !1,
|
|
438
437
|
__name: "FormFieldWrapper",
|
|
439
438
|
props: {
|
|
@@ -466,7 +465,7 @@ const wr = /* @__PURE__ */ S({
|
|
|
466
465
|
}, 8, ["form", "path"]);
|
|
467
466
|
};
|
|
468
467
|
}
|
|
469
|
-
}),
|
|
468
|
+
}), Pr = /* @__PURE__ */ S({
|
|
470
469
|
__name: "FormPart",
|
|
471
470
|
props: {
|
|
472
471
|
form: {},
|
|
@@ -478,8 +477,8 @@ const wr = /* @__PURE__ */ S({
|
|
|
478
477
|
}
|
|
479
478
|
});
|
|
480
479
|
export {
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
480
|
+
Er as Field,
|
|
481
|
+
wr as FormFieldWrapper,
|
|
482
|
+
Pr as FormPart,
|
|
483
|
+
Fr as useForm
|
|
485
484
|
};
|
package/dist/types/util.d.ts
CHANGED
|
@@ -15,7 +15,7 @@ type CleanupAntiCollapse<T extends string> = T extends `${infer Left}${AntiColla
|
|
|
15
15
|
type RecursePaths<T, Seen = never> = T extends Seen ? never : T extends Array<infer ArrayType> ? `${number}` | `${number}.${RecursePaths<ArrayType, Seen | T>}` : T extends object ? {
|
|
16
16
|
[K in keyof T]-?: `${AntiCollapse}${Exclude<K, symbol>}${'' | `.${RecursePaths<T[K], Seen | T>}`}`;
|
|
17
17
|
}[keyof T] : never;
|
|
18
|
-
export type Paths<T, Seen = never> = CleanupAntiCollapse<RecursePaths<T, Seen
|
|
18
|
+
export type Paths<T, Seen = never> = CleanupAntiCollapse<RecursePaths<T, Seen>> | '';
|
|
19
19
|
/**
|
|
20
20
|
* Removes the last part of a dot-connected path.
|
|
21
21
|
*/
|
package/package.json
CHANGED
|
@@ -7,7 +7,6 @@ import { useFieldRegistry } from './useFieldRegistry'
|
|
|
7
7
|
import { useFormState } from './useFormState'
|
|
8
8
|
import { createSubformInterface, type SubformOptions } from './useSubform'
|
|
9
9
|
import { useValidation, type ValidationOptions } from './useValidation'
|
|
10
|
-
import { syncRef } from '@vueuse/core'
|
|
11
10
|
|
|
12
11
|
// TODO @Elias implement validation strategy handling
|
|
13
12
|
|
package/src/types/util.ts
CHANGED
|
@@ -59,7 +59,7 @@ type RecursePaths<T, Seen = never> =
|
|
|
59
59
|
}[keyof T]
|
|
60
60
|
: never
|
|
61
61
|
|
|
62
|
-
export type Paths<T, Seen = never> = CleanupAntiCollapse<RecursePaths<T, Seen>>
|
|
62
|
+
export type Paths<T, Seen = never> = CleanupAntiCollapse<RecursePaths<T, Seen>> | ''
|
|
63
63
|
|
|
64
64
|
/**
|
|
65
65
|
* Removes the last part of a dot-connected path.
|
package/tests/formState.test.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { reactive } from 'vue'
|
|
|
3
3
|
import { useFieldRegistry } from '../src/composables/useFieldRegistry'
|
|
4
4
|
import { useFormState } from '../src/composables/useFormState'
|
|
5
5
|
import { useForm } from '../src'
|
|
6
|
+
import { useValidation } from '../src/composables/useValidation'
|
|
6
7
|
|
|
7
8
|
describe('useFormState', () => {
|
|
8
9
|
it('should detect dirty state when form data changes', () => {
|
|
@@ -45,10 +46,12 @@ describe('useFormState', () => {
|
|
|
45
46
|
email: 'john@example.com',
|
|
46
47
|
}
|
|
47
48
|
const data = reactive(initialData)
|
|
48
|
-
const
|
|
49
|
+
const state = reactive({
|
|
49
50
|
data,
|
|
50
51
|
initialData,
|
|
51
52
|
})
|
|
53
|
+
const validationState = useValidation(state, {})
|
|
54
|
+
const fields = useFieldRegistry(state, validationState)
|
|
52
55
|
|
|
53
56
|
const nameField = fields.defineField({ path: 'name' })
|
|
54
57
|
fields.defineField({ path: 'email' })
|
|
@@ -62,12 +65,16 @@ describe('useFormState', () => {
|
|
|
62
65
|
})
|
|
63
66
|
|
|
64
67
|
it('should handle empty fields map', () => {
|
|
65
|
-
const initialData = {
|
|
68
|
+
const initialData = {
|
|
69
|
+
name: 'John',
|
|
70
|
+
}
|
|
66
71
|
const data = reactive(initialData)
|
|
67
|
-
const
|
|
72
|
+
const state = reactive({
|
|
68
73
|
data,
|
|
69
74
|
initialData,
|
|
70
75
|
})
|
|
76
|
+
const validationState = useValidation(state, {})
|
|
77
|
+
const fields = useFieldRegistry(state, validationState)
|
|
71
78
|
|
|
72
79
|
const formState = useFormState(fields)
|
|
73
80
|
|
package/tests/subform.test.ts
CHANGED
|
@@ -1345,4 +1345,23 @@ describe('Subform Implementation', () => {
|
|
|
1345
1345
|
})
|
|
1346
1346
|
})
|
|
1347
1347
|
})
|
|
1348
|
+
|
|
1349
|
+
describe('Toplevel array subform', () => {
|
|
1350
|
+
it('can handle arrays on top level', async () => {
|
|
1351
|
+
const schema = z.array(z.string())
|
|
1352
|
+
|
|
1353
|
+
const form = useForm({
|
|
1354
|
+
initialData: { test: ['item1', 'item2'] },
|
|
1355
|
+
schema,
|
|
1356
|
+
})
|
|
1357
|
+
|
|
1358
|
+
const subform = form.getSubForm('test')
|
|
1359
|
+
|
|
1360
|
+
const rootField = subform.defineField({ path: '' })
|
|
1361
|
+
const itemField = subform.defineField({ path: '0' })
|
|
1362
|
+
|
|
1363
|
+
expect(rootField.data.value).toEqual(['item1', 'item2'])
|
|
1364
|
+
expect(itemField.data.value).toEqual('item1')
|
|
1365
|
+
})
|
|
1366
|
+
})
|
|
1348
1367
|
})
|
package/tests/useForm.test.ts
CHANGED
|
@@ -193,4 +193,26 @@ describe('useForm', () => {
|
|
|
193
193
|
expect(form.errors.value.general).toEqual([])
|
|
194
194
|
expect(form.errors.value.propertyErrors).toEqual({})
|
|
195
195
|
})
|
|
196
|
+
|
|
197
|
+
it('can handle arrays on top level', async () => {
|
|
198
|
+
const schema = z.array(z.string())
|
|
199
|
+
|
|
200
|
+
const form = useForm({
|
|
201
|
+
initialData: ['item1', 'item2'],
|
|
202
|
+
schema,
|
|
203
|
+
})
|
|
204
|
+
|
|
205
|
+
const result = await form.validateForm()
|
|
206
|
+
|
|
207
|
+
expect(result.isValid).toBe(true)
|
|
208
|
+
expect(form.isValidated.value).toBe(true)
|
|
209
|
+
expect(form.errors.value.general).toEqual([])
|
|
210
|
+
expect(form.errors.value.propertyErrors).toEqual({})
|
|
211
|
+
|
|
212
|
+
const rootField = form.defineField({ path: '' })
|
|
213
|
+
const itemField = form.defineField({ path: '1' })
|
|
214
|
+
|
|
215
|
+
expect(rootField.data.value).toEqual(['item1', 'item2'])
|
|
216
|
+
expect(itemField.data.value).toBe('item2')
|
|
217
|
+
})
|
|
196
218
|
})
|