@tanstack/preact-form 2.0.0-alpha.2 → 2.0.0-alpha.3

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.
@@ -1,5 +1,5 @@
1
1
  import { Subscribe } from "../Subscribe.public.js";
2
- import { useValueFieldSubscription } from "../PreactForm/fieldSubscriptions.lib.js";
2
+ import { useArrayFieldSubscription, useValueFieldSubscription } from "../PreactForm/fieldSubscriptions.lib.js";
3
3
  import { useField } from "../PreactForm/useField.lib.js";
4
4
  import { attachPreactFormComponents } from "../PreactForm/Components.lib.js";
5
5
  import { FieldContext, FormContext } from "./contexts.lib.js";
@@ -12,6 +12,9 @@ function attachPreactAppFormComponents(form, formComponents, fieldComponents) {
12
12
  const resultForm = attachPreactFormComponents(form, fieldComponents);
13
13
  resultForm.AppForm = createAppForm(form);
14
14
  resultForm.Field = createFieldWithContext(form, fieldComponents);
15
+ const arrayField = createFieldWithContext(form, fieldComponents, useArrayFieldSubscription);
16
+ arrayField.displayName = "TanStackForm.ArrayField";
17
+ resultForm.ArrayField = arrayField;
15
18
  resultForm.FormGroup = createFormGroupWithContext(resultForm);
16
19
  return Object.assign(resultForm, formComponents);
17
20
  }
@@ -25,13 +28,12 @@ function createAppForm(form) {
25
28
  AppForm.displayName = "TanStackForm.AppForm";
26
29
  return AppForm;
27
30
  }
28
- function createFieldWithContext(form, fieldComponents) {
31
+ function createFieldWithContext(form, fieldComponents, useFieldSubscription = useValueFieldSubscription) {
29
32
  const TanStackFormField = (props) => {
30
- const fieldApi = useField({
33
+ const field = useFieldSubscription(useField({
31
34
  ...props,
32
35
  form
33
- }, fieldComponents);
34
- const field = useValueFieldSubscription(fieldApi);
36
+ }, fieldComponents));
35
37
  return /* @__PURE__ */ jsx(FieldContext.Provider, {
36
38
  value: field,
37
39
  children: props.children(field)
@@ -1,46 +1,22 @@
1
1
  import { CrossVersionPreactNode } from "../preactTypes.public.js";
2
2
  import { PreactTanStackFormComponents } from "../PreactForm/Components.public.js";
3
3
  import { FieldGroupApi } from "./FieldGroupApi.public.js";
4
- import { DeepKeys, DeepKeysWhereValueIncludes, DeepValue, FormApi } from "@tanstack/form-core";
4
+ import { FieldGroupFieldBindings, FieldGroupFieldBindingsProps, FieldGroupFieldData, FieldGroupFields, FieldGroupFieldsPropName, FieldGroupHelper, FormApi } from "@tanstack/form-core";
5
5
  import { FunctionComponent } from "preact/compat";
6
6
  //#region src/FieldGroup/withFields.public.d.ts
7
- declare const fieldGroupFieldSlotValueSymbol: unique symbol;
8
7
  declare const fieldGroupFieldsSymbol: unique symbol;
9
- type FieldGroupFieldSlotMode = 'strict' | 'loose';
10
- interface FieldGroupFieldSlot<out TValue, out TMode extends FieldGroupFieldSlotMode = FieldGroupFieldSlotMode> {
11
- readonly mode: TMode;
12
- readonly [fieldGroupFieldSlotValueSymbol]: TValue;
13
- }
14
- type AnyFieldGroupFieldSlot = FieldGroupFieldSlot<any>;
15
- type StrictFieldGroupFieldSlot<TValue> = FieldGroupFieldSlot<TValue, 'strict'>;
16
- type LooseFieldGroupFieldSlot<TValue> = FieldGroupFieldSlot<TValue, 'loose'>;
17
- type FieldGroupFieldSlotValue<TSlot> = TSlot extends FieldGroupFieldSlot<infer TValue> ? TValue : never;
18
- type FieldGroupFieldSlotModeOf<TSlot> = TSlot extends FieldGroupFieldSlot<any, infer TMode> ? TMode : never;
19
- type IsSame<TTypeA, TTypeB> = [TTypeA] extends [TTypeB] ? [TTypeB] extends [TTypeA] ? true : false : false;
20
- type FieldGroupFieldSlotAllows<TSlot, TValue> = TSlot extends FieldGroupFieldSlot<infer TAcceptedValue, infer TMode> ? TMode extends 'strict' ? IsSame<TValue, TAcceptedValue> : [TValue] extends [TAcceptedValue] ? true : false : false;
21
- type FieldGroupFieldNameForSlot<TFieldData, TSlot extends AnyFieldGroupFieldSlot> = { [TFieldName in DeepKeys<TFieldData>]: FieldGroupFieldSlotAllows<TSlot, DeepValue<TFieldData, TFieldName>> extends true ? TFieldName : never; }[DeepKeys<TFieldData>];
22
- type FieldGroupFields = Record<string, AnyFieldGroupFieldSlot>;
23
- type FieldGroupFieldNames<TFieldData, TFields extends FieldGroupFields> = { [TFieldName in keyof TFields]: FieldGroupFieldNameForSlot<TFieldData, TFields[TFieldName]>; };
24
- type FieldGroupFieldData<TFields extends FieldGroupFields> = { [TFieldName in keyof TFields]: TFields[TFieldName] extends FieldGroupFieldSlot<infer TValue, any> ? TValue : never; };
25
8
  type FieldGroupFieldsOf<TFieldGroup> = TFieldGroup extends {
26
- readonly [fieldGroupFieldsSymbol]: infer TFields;
9
+ readonly [fieldGroupFieldsSymbol]: infer TFields extends FieldGroupFields;
27
10
  } ? TFields : never;
28
11
  type PreactFieldGroup<TFields extends FieldGroupFields, TFieldComponents extends Record<string, FunctionComponent<any>> = Record<never, never>> = FieldGroupApi<FieldGroupFieldData<TFields>, TFieldComponents> & {
29
12
  readonly [fieldGroupFieldsSymbol]: TFields;
30
13
  };
31
14
  type FieldGroupFieldComponentsOf<TFieldGroup> = TFieldGroup extends PreactFieldGroup<any, infer TFieldComponents> ? TFieldComponents : never;
32
15
  type FieldGroupForm<TFieldComponents extends Record<string, FunctionComponent<any>> = Record<never, never>, TFormData = any> = FormApi<TFormData, any> & PreactTanStackFormComponents<TFormData, any, TFieldComponents>;
33
- type FieldGroupFieldBindingForSlot<TFormData, TSlot extends AnyFieldGroupFieldSlot> = TSlot extends FieldGroupFieldSlot<infer TValue, infer TMode> ? TMode extends 'strict' ? FieldGroupFieldNameForSlot<TFormData, TSlot> : DeepKeysWhereValueIncludes<TFormData, TValue> : never;
34
- type FieldGroupFieldBindings<TFields extends FieldGroupFields, TFormData = any> = { [TFieldName in keyof TFields]: FieldGroupFieldBindingForSlot<TFormData, TFields[TFieldName]>; };
35
16
  type FieldGroupFieldBindingsOf<TFieldGroup, TFormData> = FieldGroupFieldsOf<TFieldGroup> extends FieldGroupFields ? FieldGroupFieldBindings<FieldGroupFieldsOf<TFieldGroup>, TFormData> : never;
36
- type FieldGroupFieldsPropName<TProps, TFieldGroup extends PreactFieldGroup<any, any>> = { [TPropName in keyof TProps]-?: IsSame<TProps[TPropName], TFieldGroup> extends true ? TPropName : never; }[keyof TProps];
37
17
  type FieldGroupWithFieldsFn<TFieldGroup extends PreactFieldGroup<any, any>> = <TProps extends object, TFieldsPropName extends FieldGroupFieldsPropName<TProps, TFieldGroup>>(Component: (props: TProps) => CrossVersionPreactNode, fieldsPropName: TFieldsPropName) => <TFormData>(props: Omit<TProps, TFieldsPropName | 'form'> & {
38
18
  form: FieldGroupForm<FieldGroupFieldComponentsOf<TFieldGroup>, TFormData>;
39
- } & { [TPropName in TFieldsPropName]: FieldGroupFieldBindingsOf<TFieldGroup, TFormData>; }) => CrossVersionPreactNode;
40
- interface FieldGroupHelper {
41
- strict: <TValue>() => StrictFieldGroupFieldSlot<TValue>;
42
- loose: <TValue>() => LooseFieldGroupFieldSlot<TValue>;
43
- }
19
+ } & FieldGroupFieldBindingsProps<FieldGroupFieldsOf<TFieldGroup>, TFormData, TFieldsPropName>) => CrossVersionPreactNode;
44
20
  interface FieldGroupDefinition<TFields extends FieldGroupFields, TFieldComponents extends Record<string, FunctionComponent<any>>> {
45
21
  /** The virtual field-group API injected into the bound component. */
46
22
  fields: PreactFieldGroup<TFields, TFieldComponents>;
@@ -52,4 +28,4 @@ type DefineFieldGroupFn<TFieldComponents extends Record<string, FunctionComponen
52
28
  /** Defines a reusable group of virtual fields. */
53
29
  declare const defineFieldGroup: DefineFieldGroupFn<Record<never, never>>;
54
30
  //#endregion
55
- export { AnyFieldGroupFieldSlot, DefineFieldGroupFn, FieldGroupDefinition, FieldGroupFieldBindingForSlot, FieldGroupFieldBindings, FieldGroupFieldBindingsOf, FieldGroupFieldComponentsOf, FieldGroupFieldData, FieldGroupFieldNameForSlot, FieldGroupFieldNames, FieldGroupFieldSlot, FieldGroupFieldSlotAllows, FieldGroupFieldSlotMode, FieldGroupFieldSlotModeOf, FieldGroupFieldSlotValue, FieldGroupFields, FieldGroupFieldsOf, FieldGroupFieldsPropName, FieldGroupForm, FieldGroupHelper, FieldGroupWithFieldsFn, LooseFieldGroupFieldSlot, PreactFieldGroup, StrictFieldGroupFieldSlot, defineFieldGroup };
31
+ export { DefineFieldGroupFn, FieldGroupDefinition, FieldGroupFieldBindingsOf, FieldGroupFieldComponentsOf, FieldGroupFieldsOf, FieldGroupForm, FieldGroupWithFieldsFn, PreactFieldGroup, defineFieldGroup };
package/dist/index.d.ts CHANGED
@@ -5,7 +5,7 @@ import { AnyPreactFormApi, PreactFormApi } from "./PreactForm/formApiTypes.publi
5
5
  import { UseFormHook, useForm } from "./PreactForm/useForm.public.js";
6
6
  import { PreactFormType } from "./PreactForm/formType.public.js";
7
7
  import { AnyFieldGroupApi, FieldGroupApi, FieldGroupArrayFieldComponent, FieldGroupFieldComponent, FieldGroupFormState, FieldGroupSubscribeComponent, FieldGroupSubscribeProps } from "./FieldGroup/FieldGroupApi.public.js";
8
- import { AnyFieldGroupFieldSlot, DefineFieldGroupFn, FieldGroupDefinition, FieldGroupFieldBindingForSlot, FieldGroupFieldBindings, FieldGroupFieldBindingsOf, FieldGroupFieldComponentsOf, FieldGroupFieldData, FieldGroupFieldNameForSlot, FieldGroupFieldNames, FieldGroupFieldSlot, FieldGroupFieldSlotAllows, FieldGroupFieldSlotMode, FieldGroupFieldSlotModeOf, FieldGroupFieldSlotValue, FieldGroupFields, FieldGroupFieldsOf, FieldGroupFieldsPropName, FieldGroupForm, FieldGroupHelper, FieldGroupWithFieldsFn, LooseFieldGroupFieldSlot, PreactFieldGroup, StrictFieldGroupFieldSlot, defineFieldGroup } from "./FieldGroup/withFields.public.js";
8
+ import { DefineFieldGroupFn, FieldGroupDefinition, FieldGroupFieldBindingsOf, FieldGroupFieldComponentsOf, FieldGroupFieldsOf, FieldGroupForm, FieldGroupWithFieldsFn, PreactFieldGroup, defineFieldGroup } from "./FieldGroup/withFields.public.js";
9
9
  import "./types.public.js";
10
10
  import { Subscribe, SubscribeProps, SubscribeSource } from "./Subscribe.public.js";
11
11
  import { AppFormComponent, PreactAppFormApi } from "./AppForm/PreactAppFormApi.public.js";
@@ -14,4 +14,4 @@ import { createFormHook } from "./AppForm/createFormHook.public.js";
14
14
  import { FormHookHelpers, getFormHookHelpers } from "./AppForm/getFormHookHelpers.public.js";
15
15
  export * from "@tanstack/form-core";
16
16
  export * from "@tanstack/preact-store";
17
- export { AnyFieldGroupApi, AnyFieldGroupFieldSlot, AnyPreactFormApi, AnyPreactFormComponentMap, AppFormComponent, AppFormHookResult, CreateFormHookOptions, CrossVersionPreactNode, DefaultPreactFormComponentMap, DefineFieldGroupFn, FieldGroupApi, FieldGroupArrayFieldComponent, FieldGroupDefinition, FieldGroupFieldBindingForSlot, FieldGroupFieldBindings, FieldGroupFieldBindingsOf, FieldGroupFieldComponent, FieldGroupFieldComponentsOf, FieldGroupFieldData, FieldGroupFieldNameForSlot, FieldGroupFieldNames, FieldGroupFieldSlot, FieldGroupFieldSlotAllows, FieldGroupFieldSlotMode, FieldGroupFieldSlotModeOf, FieldGroupFieldSlotValue, FieldGroupFields, FieldGroupFieldsOf, FieldGroupFieldsPropName, FieldGroupForm, FieldGroupFormState, FieldGroupHelper, FieldGroupSubscribeComponent, FieldGroupSubscribeProps, FieldGroupWithFieldsFn, FormHookHelpers, LooseFieldGroupFieldSlot, PreactAppFormApi, PreactFieldApi, PreactFieldGroup, PreactFormApi, PreactFormArrayFieldComponent, PreactFormComponentMap, PreactFormFieldComponent, PreactFormFieldProps, PreactFormGroupApi, PreactFormGroupArrayFieldComponent, PreactFormGroupComponent, PreactFormGroupFieldComponent, PreactFormGroupProps, PreactFormGroupSubscribeComponent, PreactFormGroupSubscribeProps, PreactFormSubscribeComponent, PreactFormSubscribeProps, PreactFormType, PreactTanStackFormComponents, StrictFieldGroupFieldSlot, Subscribe, SubscribeProps, SubscribeSource, UseAppFormHook, UseFormHook, createFormHook, defineFieldGroup, getFormHookHelpers, useForm };
17
+ export { AnyFieldGroupApi, AnyPreactFormApi, AnyPreactFormComponentMap, AppFormComponent, AppFormHookResult, CreateFormHookOptions, CrossVersionPreactNode, DefaultPreactFormComponentMap, DefineFieldGroupFn, FieldGroupApi, FieldGroupArrayFieldComponent, FieldGroupDefinition, FieldGroupFieldBindingsOf, FieldGroupFieldComponent, FieldGroupFieldComponentsOf, FieldGroupFieldsOf, FieldGroupForm, FieldGroupFormState, FieldGroupSubscribeComponent, FieldGroupSubscribeProps, FieldGroupWithFieldsFn, FormHookHelpers, PreactAppFormApi, PreactFieldApi, PreactFieldGroup, PreactFormApi, PreactFormArrayFieldComponent, PreactFormComponentMap, PreactFormFieldComponent, PreactFormFieldProps, PreactFormGroupApi, PreactFormGroupArrayFieldComponent, PreactFormGroupComponent, PreactFormGroupFieldComponent, PreactFormGroupProps, PreactFormGroupSubscribeComponent, PreactFormGroupSubscribeProps, PreactFormSubscribeComponent, PreactFormSubscribeProps, PreactFormType, PreactTanStackFormComponents, Subscribe, SubscribeProps, SubscribeSource, UseAppFormHook, UseFormHook, createFormHook, defineFieldGroup, getFormHookHelpers, useForm };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/preact-form",
3
- "version": "2.0.0-alpha.2",
3
+ "version": "2.0.0-alpha.3",
4
4
  "description": "Powerful, type-safe forms for Preact.",
5
5
  "author": "tannerlinsley",
6
6
  "license": "MIT",
@@ -34,14 +34,14 @@
34
34
  "dist"
35
35
  ],
36
36
  "dependencies": {
37
- "@tanstack/preact-store": "^0.13.2",
38
- "@tanstack/form-core": "2.0.0-alpha.2"
37
+ "@tanstack/form-core": "2.0.0-alpha.3",
38
+ "@tanstack/preact-store": "^0.13.2"
39
39
  },
40
40
  "devDependencies": {
41
41
  "@eslint-react/eslint-plugin": "^5.18.3",
42
42
  "@preact/preset-vite": "^2.10.2",
43
- "@testing-library/preact": "^3.2.4",
44
43
  "preact": "^10.26.4",
44
+ "vitest-browser-preact": "^1.1.0",
45
45
  "zod": "^4.4.3"
46
46
  },
47
47
  "peerDependencies": {