@tanstack/solid-form 1.32.0 → 1.33.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.
@@ -0,0 +1,50 @@
1
+ import { FormGroupApi } from '@tanstack/form-core';
2
+ import { createComponent, createComputed, createSignal, onCleanup, onMount, } from 'solid-js';
3
+ import { useStore } from '@tanstack/solid-store';
4
+ // ugly way to trick solid into triggering updates for changes on the formGroupApi
5
+ function makeFormGroupReactive(formGroupApi) {
6
+ const [group, setGroup] = createSignal(formGroupApi, { equals: false });
7
+ // Handle shallow comparison to make sure that Derived doesn't create a new setGroup call every time
8
+ const store = useStore(formGroupApi.store, (store) => store);
9
+ // Run before initial render
10
+ createComputed(() => {
11
+ // Use the store to track dependencies
12
+ store();
13
+ setGroup(formGroupApi);
14
+ });
15
+ return group;
16
+ }
17
+ export function createFormGroup(opts) {
18
+ const options = opts();
19
+ const api = new FormGroupApi(options);
20
+ let mounted = false;
21
+ // Instantiates form group meta and removes it when unrendered
22
+ onMount(() => {
23
+ const cleanupFn = api.mount();
24
+ mounted = true;
25
+ onCleanup(() => {
26
+ cleanupFn();
27
+ mounted = false;
28
+ });
29
+ });
30
+ /**
31
+ * formGroupApi.update should not have any side effects. Think of it like a `useRef`
32
+ * that we need to keep updated every render with the most up-to-date information.
33
+ *
34
+ * createComputed to make sure this effect runs before render effects
35
+ */
36
+ createComputed(() => {
37
+ if (!mounted)
38
+ return;
39
+ api.update(opts());
40
+ });
41
+ return makeFormGroupReactive(api);
42
+ }
43
+ export function FormGroup(props) {
44
+ const formGroupApi = createFormGroup(() => {
45
+ const { children, ...formGroupOptions } = props;
46
+ return formGroupOptions;
47
+ });
48
+ return <>{createComponent(() => props.children(formGroupApi), {})}</>;
49
+ }
50
+ //# sourceMappingURL=createFormGroup.jsx.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createFormGroup.jsx","sourceRoot":"","sources":["../../src/createFormGroup.tsx"],"names":[],"mappings":"AAAA,O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B,CAAC,CAAC,CAAA;IAEF,OAAO,qBAAqB,CAyB1B,GAAG,CAAC,CAAA;AACR,CAAC;AAsRD,MAAM,UAAU,SAAS,CAwCvB,KAyBC;IAED,MAAM,YAAY,GAAG,eAAe,CAyBlC,GAAG,EAAE;QACL,MAAM,EAAE,QAAQ,EAAE,GAAG,gBAAgB,EAAE,GAAG,KAAK,CAAA;QAC/C,OAAO,gBAAgB,CAAA;IACzB,CAAC,CAAC,CAAA;IAEF,OAAO,EAAE,CAAC,eAAe,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,QAAQ,CAAC,YAAY,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,CAAA;AACvE,CAAC"}
@@ -3,5 +3,6 @@ export { useStore } from '@tanstack/solid-store';
3
3
  export * from './createField';
4
4
  export * from './createForm';
5
5
  export * from './createFieldGroup';
6
+ export * from './createFormGroup';
6
7
  export * from './createFormHook';
7
8
  export * from './types';
@@ -3,6 +3,7 @@ export { useStore } from '@tanstack/solid-store';
3
3
  export * from './createField';
4
4
  export * from './createForm';
5
5
  export * from './createFieldGroup';
6
+ export * from './createFormGroup';
6
7
  export * from './createFormHook';
7
8
  export * from './types';
8
9
  //# sourceMappingURL=index.jsx.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.jsx","sourceRoot":"","sources":["../../src/index.tsx"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAA;AAEnC,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAA;AAEhD,cAAc,eAAe,CAAA;AAC7B,cAAc,cAAc,CAAA;AAC5B,cAAc,oBAAoB,CAAA;AAClC,cAAc,kBAAkB,CAAA;AAChC,cAAc,SAAS,CAAA"}
1
+ {"version":3,"file":"index.jsx","sourceRoot":"","sources":["../../src/index.tsx"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAA;AAEnC,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAA;AAEhD,cAAc,eAAe,CAAA;AAC7B,cAAc,cAAc,CAAA;AAC5B,cAAc,oBAAoB,CAAA;AAClC,cAAc,mBAAmB,CAAA;AACjC,cAAc,kBAAkB,CAAA;AAChC,cAAc,SAAS,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/solid-form",
3
- "version": "1.32.0",
3
+ "version": "1.33.0",
4
4
  "description": "Powerful, type-safe forms for Solid.",
5
5
  "author": "tannerlinsley",
6
6
  "license": "MIT",
@@ -41,8 +41,8 @@
41
41
  "src"
42
42
  ],
43
43
  "dependencies": {
44
- "@tanstack/solid-store": "^0.9.1",
45
- "@tanstack/form-core": "1.32.0"
44
+ "@tanstack/solid-store": "^0.11.0",
45
+ "@tanstack/form-core": "1.33.0"
46
46
  },
47
47
  "devDependencies": {
48
48
  "solid-js": "^1.9.9",
@@ -60,7 +60,8 @@
60
60
  "test:types:ts55": "node ../../node_modules/typescript55/lib/tsc.js",
61
61
  "test:types:ts56": "node ../../node_modules/typescript56/lib/tsc.js",
62
62
  "test:types:ts57": "node ../../node_modules/typescript57/lib/tsc.js",
63
- "test:types:ts58": "tsc",
63
+ "test:types:ts58": "node ../../node_modules/typescript58/lib/tsc.js",
64
+ "test:types:ts59": "tsc",
64
65
  "test:lib": "vitest",
65
66
  "test:lib:dev": "pnpm run test:lib --watch",
66
67
  "test:build": "publint --strict",
@@ -2,6 +2,7 @@ import { FormApi, functionalUpdate } from '@tanstack/form-core'
2
2
  import { createComputed, onMount } from 'solid-js'
3
3
  import { useStore } from '@tanstack/solid-store'
4
4
  import { Field, createField } from './createField'
5
+ import { FormGroup } from './createFormGroup'
5
6
  import type {
6
7
  FormAsyncValidateOrFn,
7
8
  FormOptions,
@@ -10,6 +11,7 @@ import type {
10
11
  } from '@tanstack/form-core'
11
12
  import type { JSXElement } from 'solid-js'
12
13
  import type { FieldComponent } from './createField'
14
+ import type { FormGroupComponent } from './createFormGroup'
13
15
 
14
16
  export interface SolidFormApi<
15
17
  TParentData,
@@ -39,6 +41,20 @@ export interface SolidFormApi<
39
41
  TFormOnServer,
40
42
  TSubmitMeta
41
43
  >
44
+ FormGroup: FormGroupComponent<
45
+ TParentData,
46
+ TFormOnMount,
47
+ TFormOnChange,
48
+ TFormOnChangeAsync,
49
+ TFormOnBlur,
50
+ TFormOnBlurAsync,
51
+ TFormOnSubmit,
52
+ TFormOnSubmitAsync,
53
+ TFormOnDynamic,
54
+ TFormOnDynamicAsync,
55
+ TFormOnServer,
56
+ TSubmitMeta
57
+ >
42
58
  useStore: <
43
59
  TSelected = NoInfer<
44
60
  FormState<
@@ -217,6 +233,7 @@ export function createForm<
217
233
  > = api as never
218
234
 
219
235
  extendedApi.Field = (props) => <Field {...props} form={api} />
236
+ extendedApi.FormGroup = (props) => <FormGroup {...props} form={api} />
220
237
  extendedApi.useStore = (selector) => useStore(api.store, selector)
221
238
  extendedApi.Subscribe = (props) =>
222
239
  functionalUpdate(props.children, useStore(api.store, props.selector))