@tanstack/solid-form 0.22.1 → 0.23.0
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.d.ts +1 -4
- package/dist/index.js +1 -2
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/index.ts +1 -22
- package/src/tests/createField.test.tsx +9 -24
- package/src/tests/createForm.test.tsx +10 -25
- package/dist/createFormFactory.d.ts +0 -8
- package/dist/createFormFactory.js +0 -11
- package/dist/createFormFactory.js.map +0 -1
- package/src/createFormFactory.ts +0 -36
- package/src/tests/createFormFactory.test.tsx +0 -38
package/dist/index.d.ts
CHANGED
@@ -1,7 +1,4 @@
|
|
1
|
-
export
|
2
|
-
export { FormApi, FieldApi, functionalUpdate } from '@tanstack/form-core';
|
1
|
+
export * from '@tanstack/form-core';
|
3
2
|
export { createForm } from './createForm';
|
4
3
|
export type { CreateField, FieldComponent } from './createField';
|
5
4
|
export { createField, Field } from './createField';
|
6
|
-
export type { FormFactory } from './createFormFactory';
|
7
|
-
export { createFormFactory } from './createFormFactory';
|
package/dist/index.js
CHANGED
@@ -1,5 +1,4 @@
|
|
1
|
-
export
|
1
|
+
export * from '@tanstack/form-core';
|
2
2
|
export { createForm } from './createForm';
|
3
3
|
export { createField, Field } from './createField';
|
4
|
-
export { createFormFactory } from './createFormFactory';
|
5
4
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAA;AAEnC,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AAGzC,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,eAAe,CAAA"}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@tanstack/solid-form",
|
3
|
-
"version": "0.
|
3
|
+
"version": "0.23.0",
|
4
4
|
"description": "Powerful, type-safe forms for Solid.",
|
5
5
|
"author": "tannerlinsley",
|
6
6
|
"license": "MIT",
|
@@ -38,7 +38,7 @@
|
|
38
38
|
},
|
39
39
|
"dependencies": {
|
40
40
|
"@tanstack/solid-store": "^0.4.1",
|
41
|
-
"@tanstack/form-core": "0.
|
41
|
+
"@tanstack/form-core": "0.23.0"
|
42
42
|
},
|
43
43
|
"peerDependencies": {
|
44
44
|
"solid-js": "^1.6.0"
|
package/src/index.ts
CHANGED
@@ -1,27 +1,6 @@
|
|
1
|
-
export
|
2
|
-
DeepKeys,
|
3
|
-
DeepValue,
|
4
|
-
FieldApiOptions,
|
5
|
-
FieldInfo,
|
6
|
-
FieldMeta,
|
7
|
-
FieldOptions,
|
8
|
-
FieldState,
|
9
|
-
FormOptions,
|
10
|
-
FormState,
|
11
|
-
RequiredByKey,
|
12
|
-
Updater,
|
13
|
-
UpdaterFn,
|
14
|
-
ValidationCause,
|
15
|
-
ValidationError,
|
16
|
-
ValidationMeta,
|
17
|
-
} from '@tanstack/form-core'
|
18
|
-
|
19
|
-
export { FormApi, FieldApi, functionalUpdate } from '@tanstack/form-core'
|
1
|
+
export * from '@tanstack/form-core'
|
20
2
|
|
21
3
|
export { createForm } from './createForm'
|
22
4
|
|
23
5
|
export type { CreateField, FieldComponent } from './createField'
|
24
6
|
export { createField, Field } from './createField'
|
25
|
-
|
26
|
-
export type { FormFactory } from './createFormFactory'
|
27
|
-
export { createFormFactory } from './createFormFactory'
|
@@ -3,7 +3,7 @@ import { render, waitFor } from '@solidjs/testing-library'
|
|
3
3
|
import userEvent from '@testing-library/user-event'
|
4
4
|
import '@testing-library/jest-dom/vitest'
|
5
5
|
import { Index, Show, createEffect } from 'solid-js'
|
6
|
-
import { createForm
|
6
|
+
import { createForm } from '../index'
|
7
7
|
import { sleep } from './utils'
|
8
8
|
|
9
9
|
const user = userEvent.setup()
|
@@ -15,10 +15,8 @@ describe('createField', () => {
|
|
15
15
|
lastName: string
|
16
16
|
}
|
17
17
|
|
18
|
-
const formFactory = createFormFactory<Person>()
|
19
|
-
|
20
18
|
function Comp() {
|
21
|
-
const form =
|
19
|
+
const form = createForm<Person>()
|
22
20
|
|
23
21
|
return (
|
24
22
|
<>
|
@@ -51,10 +49,8 @@ describe('createField', () => {
|
|
51
49
|
lastName: string
|
52
50
|
}
|
53
51
|
|
54
|
-
const formFactory = createFormFactory<Person>()
|
55
|
-
|
56
52
|
function Comp() {
|
57
|
-
const form =
|
53
|
+
const form = createForm<Person>(() => ({
|
58
54
|
defaultValues: {
|
59
55
|
firstName: 'FirstName',
|
60
56
|
lastName: 'LastName',
|
@@ -93,10 +89,8 @@ describe('createField', () => {
|
|
93
89
|
}
|
94
90
|
const error = 'Please enter a different value'
|
95
91
|
|
96
|
-
const formFactory = createFormFactory<Person>()
|
97
|
-
|
98
92
|
function Comp() {
|
99
|
-
const form =
|
93
|
+
const form = createForm<Person>()
|
100
94
|
|
101
95
|
return (
|
102
96
|
<>
|
@@ -136,10 +130,8 @@ describe('createField', () => {
|
|
136
130
|
}
|
137
131
|
const error = 'Please enter a different value'
|
138
132
|
|
139
|
-
const formFactory = createFormFactory<Person>()
|
140
|
-
|
141
133
|
function Comp() {
|
142
|
-
const form =
|
134
|
+
const form = createForm<Person>()
|
143
135
|
|
144
136
|
return (
|
145
137
|
<>
|
@@ -184,10 +176,8 @@ describe('createField', () => {
|
|
184
176
|
const onChangeError = 'Please enter a different value (onChangeError)'
|
185
177
|
const onBlurError = 'Please enter a different value (onBlurError)'
|
186
178
|
|
187
|
-
const formFactory = createFormFactory<Person>()
|
188
|
-
|
189
179
|
function Comp() {
|
190
|
-
const form =
|
180
|
+
const form = createForm<Person>()
|
191
181
|
|
192
182
|
return (
|
193
183
|
<>
|
@@ -235,10 +225,8 @@ describe('createField', () => {
|
|
235
225
|
}
|
236
226
|
const error = 'Please enter a different value'
|
237
227
|
|
238
|
-
const formFactory = createFormFactory<Person>()
|
239
|
-
|
240
228
|
function Comp() {
|
241
|
-
const form =
|
229
|
+
const form = createForm<Person>()
|
242
230
|
|
243
231
|
return (
|
244
232
|
<>
|
@@ -284,10 +272,8 @@ describe('createField', () => {
|
|
284
272
|
const onChangeError = 'Please enter a different value (onChangeError)'
|
285
273
|
const onBlurError = 'Please enter a different value (onBlurError)'
|
286
274
|
|
287
|
-
const formFactory = createFormFactory<Person>()
|
288
|
-
|
289
275
|
function Comp() {
|
290
|
-
const form =
|
276
|
+
const form = createForm<Person>()
|
291
277
|
|
292
278
|
return (
|
293
279
|
<>
|
@@ -342,10 +328,9 @@ describe('createField', () => {
|
|
342
328
|
}
|
343
329
|
const mockFn = vi.fn()
|
344
330
|
const error = 'Please enter a different value'
|
345
|
-
const formFactory = createFormFactory<Person>()
|
346
331
|
|
347
332
|
function Comp() {
|
348
|
-
const form =
|
333
|
+
const form = createForm<Person>()
|
349
334
|
|
350
335
|
return (
|
351
336
|
<>
|
@@ -2,7 +2,7 @@ import { describe, expect, it, vi } from 'vitest'
|
|
2
2
|
import { render, screen, waitFor } from '@solidjs/testing-library'
|
3
3
|
import userEvent from '@testing-library/user-event'
|
4
4
|
import { Show, createSignal, onCleanup } from 'solid-js'
|
5
|
-
import { createForm
|
5
|
+
import { createForm } from '../index'
|
6
6
|
import { sleep } from './utils'
|
7
7
|
import type { ValidationErrorMap } from '@tanstack/form-core'
|
8
8
|
|
@@ -15,10 +15,8 @@ describe('createForm', () => {
|
|
15
15
|
lastName: string
|
16
16
|
}
|
17
17
|
|
18
|
-
const formFactory = createFormFactory<Person>()
|
19
|
-
|
20
18
|
function Comp() {
|
21
|
-
const form =
|
19
|
+
const form = createForm<Person>()
|
22
20
|
return (
|
23
21
|
<>
|
24
22
|
<form.Field
|
@@ -50,14 +48,12 @@ describe('createForm', () => {
|
|
50
48
|
lastName: string
|
51
49
|
}
|
52
50
|
|
53
|
-
const formFactory = createFormFactory<Person>()
|
54
|
-
|
55
51
|
function Comp() {
|
56
|
-
const form =
|
52
|
+
const form = createForm(() => ({
|
57
53
|
defaultValues: {
|
58
54
|
firstName: 'FirstName',
|
59
55
|
lastName: 'LastName',
|
60
|
-
},
|
56
|
+
} as Person,
|
61
57
|
}))
|
62
58
|
|
63
59
|
return (
|
@@ -159,10 +155,8 @@ describe('createForm', () => {
|
|
159
155
|
}
|
160
156
|
const error = 'Please enter a different value'
|
161
157
|
|
162
|
-
const formFactory = createFormFactory<Person>()
|
163
|
-
|
164
158
|
function Comp() {
|
165
|
-
const form =
|
159
|
+
const form = createForm<Person>(() => ({
|
166
160
|
validators: {
|
167
161
|
onChange: ({ value }) =>
|
168
162
|
value.firstName.includes('other') ? error : undefined,
|
@@ -205,10 +199,8 @@ describe('createForm', () => {
|
|
205
199
|
}
|
206
200
|
const error = 'Please enter a different value'
|
207
201
|
|
208
|
-
const formFactory = createFormFactory<Person>()
|
209
|
-
|
210
202
|
function Comp() {
|
211
|
-
const form =
|
203
|
+
const form = createForm<Person>(() => ({
|
212
204
|
validators: {
|
213
205
|
onChange: ({ value }) =>
|
214
206
|
value.firstName.includes('other') ? error : undefined,
|
@@ -257,10 +249,8 @@ describe('createForm', () => {
|
|
257
249
|
const onChangeError = 'Please enter a different value (onChangeError)'
|
258
250
|
const onBlurError = 'Please enter a different value (onBlurError)'
|
259
251
|
|
260
|
-
const formFactory = createFormFactory<Person>()
|
261
|
-
|
262
252
|
function Comp() {
|
263
|
-
const form =
|
253
|
+
const form = createForm<Person>(() => ({
|
264
254
|
validators: {
|
265
255
|
onChange: ({ value }) =>
|
266
256
|
value.firstName.includes('other') ? onChangeError : undefined,
|
@@ -312,10 +302,8 @@ describe('createForm', () => {
|
|
312
302
|
}
|
313
303
|
const error = 'Please enter a different value'
|
314
304
|
|
315
|
-
const formFactory = createFormFactory<Person>()
|
316
|
-
|
317
305
|
function Comp() {
|
318
|
-
const form =
|
306
|
+
const form = createForm<Person>(() => ({
|
319
307
|
validators: {
|
320
308
|
onChangeAsync: async () => {
|
321
309
|
await sleep(10)
|
@@ -365,10 +353,8 @@ describe('createForm', () => {
|
|
365
353
|
const onChangeError = 'Please enter a different value (onChangeError)'
|
366
354
|
const onBlurError = 'Please enter a different value (onBlurError)'
|
367
355
|
|
368
|
-
const formFactory = createFormFactory<Person>()
|
369
|
-
|
370
356
|
function Comp() {
|
371
|
-
const form =
|
357
|
+
const form = createForm<Person>(() => ({
|
372
358
|
validators: {
|
373
359
|
async onChangeAsync() {
|
374
360
|
await sleep(10)
|
@@ -427,10 +413,9 @@ describe('createForm', () => {
|
|
427
413
|
}
|
428
414
|
const mockFn = vi.fn()
|
429
415
|
const error = 'Please enter a different value'
|
430
|
-
const formFactory = createFormFactory<Person>()
|
431
416
|
|
432
417
|
function Comp() {
|
433
|
-
const form =
|
418
|
+
const form = createForm<Person>(() => ({
|
434
419
|
validators: {
|
435
420
|
onChangeAsyncDebounceMs: 100,
|
436
421
|
onChangeAsync: async () => {
|
@@ -1,8 +0,0 @@
|
|
1
|
-
import { Field, createField } from './createField';
|
2
|
-
import type { FormApi, FormOptions, Validator } from '@tanstack/form-core';
|
3
|
-
export type FormFactory<TFormData, TFormValidator extends Validator<TFormData, unknown> | undefined = undefined> = {
|
4
|
-
createForm: (opts?: () => FormOptions<TFormData, TFormValidator>) => FormApi<TFormData, TFormValidator>;
|
5
|
-
createField: typeof createField;
|
6
|
-
Field: typeof Field;
|
7
|
-
};
|
8
|
-
export declare function createFormFactory<TFormData, TFormValidator extends Validator<TFormData, unknown> | undefined = undefined>(defaultOpts?: () => FormOptions<TFormData, TFormValidator>): FormFactory<TFormData, TFormValidator>;
|
@@ -1,11 +0,0 @@
|
|
1
|
-
import { mergeProps } from 'solid-js';
|
2
|
-
import { Field, createField, } from './createField';
|
3
|
-
import { createForm } from './createForm';
|
4
|
-
export function createFormFactory(defaultOpts) {
|
5
|
-
return {
|
6
|
-
createForm: (opts) => createForm(() => mergeProps(defaultOpts?.() ?? {}, opts?.() ?? {})),
|
7
|
-
createField,
|
8
|
-
Field: Field,
|
9
|
-
};
|
10
|
-
}
|
11
|
-
//# sourceMappingURL=createFormFactory.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"createFormFactory.js","sourceRoot":"","sources":["../src/createFormFactory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AACrC,OAAO,EAEL,KAAK,EAEL,WAAW,GACZ,MAAM,eAAe,CAAA;AACtB,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AAczC,MAAM,UAAU,iBAAiB,CAI/B,WAA0D;IAE1D,OAAO;QACL,UAAU,EAAE,CAAC,IAAI,EAAE,EAAE,CACnB,UAAU,CAA4B,GAAG,EAAE,CACzC,UAAU,CAAC,WAAW,EAAE,EAAE,IAAI,EAAE,EAAE,IAAI,EAAE,EAAE,IAAI,EAAE,CAAC,CAClD;QACH,WAAW;QACX,KAAK,EAAE,KAAK;KACb,CAAA;AACH,CAAC"}
|
package/src/createFormFactory.ts
DELETED
@@ -1,36 +0,0 @@
|
|
1
|
-
import { mergeProps } from 'solid-js'
|
2
|
-
import {
|
3
|
-
type CreateField,
|
4
|
-
Field,
|
5
|
-
type FieldComponent,
|
6
|
-
createField,
|
7
|
-
} from './createField'
|
8
|
-
import { createForm } from './createForm'
|
9
|
-
import type { FormApi, FormOptions, Validator } from '@tanstack/form-core'
|
10
|
-
|
11
|
-
export type FormFactory<
|
12
|
-
TFormData,
|
13
|
-
TFormValidator extends Validator<TFormData, unknown> | undefined = undefined,
|
14
|
-
> = {
|
15
|
-
createForm: (
|
16
|
-
opts?: () => FormOptions<TFormData, TFormValidator>,
|
17
|
-
) => FormApi<TFormData, TFormValidator>
|
18
|
-
createField: typeof createField
|
19
|
-
Field: typeof Field
|
20
|
-
}
|
21
|
-
|
22
|
-
export function createFormFactory<
|
23
|
-
TFormData,
|
24
|
-
TFormValidator extends Validator<TFormData, unknown> | undefined = undefined,
|
25
|
-
>(
|
26
|
-
defaultOpts?: () => FormOptions<TFormData, TFormValidator>,
|
27
|
-
): FormFactory<TFormData, TFormValidator> {
|
28
|
-
return {
|
29
|
-
createForm: (opts) =>
|
30
|
-
createForm<TFormData, TFormValidator>(() =>
|
31
|
-
mergeProps(defaultOpts?.() ?? {}, opts?.() ?? {}),
|
32
|
-
),
|
33
|
-
createField,
|
34
|
-
Field: Field,
|
35
|
-
}
|
36
|
-
}
|
@@ -1,38 +0,0 @@
|
|
1
|
-
import { describe, expect, it } from 'vitest'
|
2
|
-
import { render } from '@solidjs/testing-library'
|
3
|
-
import { createFormFactory } from '../index'
|
4
|
-
|
5
|
-
describe('createFormFactory', () => {
|
6
|
-
it('should allow default values to be set', async () => {
|
7
|
-
type Person = {
|
8
|
-
firstName: string
|
9
|
-
lastName: string
|
10
|
-
}
|
11
|
-
|
12
|
-
const formFactory = createFormFactory<Person>(() => ({
|
13
|
-
defaultValues: {
|
14
|
-
firstName: 'FirstName',
|
15
|
-
lastName: 'LastName',
|
16
|
-
},
|
17
|
-
}))
|
18
|
-
|
19
|
-
function Comp() {
|
20
|
-
const form = formFactory.createForm()
|
21
|
-
|
22
|
-
return (
|
23
|
-
<>
|
24
|
-
<form.Field
|
25
|
-
name="firstName"
|
26
|
-
children={(field) => {
|
27
|
-
return <p>{field().state.value}</p>
|
28
|
-
}}
|
29
|
-
/>
|
30
|
-
</>
|
31
|
-
)
|
32
|
-
}
|
33
|
-
|
34
|
-
const { findByText, queryByText } = render(() => <Comp />)
|
35
|
-
expect(await findByText('FirstName')).toBeInTheDocument()
|
36
|
-
expect(queryByText('LastName')).not.toBeInTheDocument()
|
37
|
-
})
|
38
|
-
})
|