@tanstack/react-form 0.1.2 → 0.2.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.
Files changed (159) hide show
  1. package/build/legacy/createFormFactory.cjs +42 -0
  2. package/build/legacy/createFormFactory.cjs.map +1 -0
  3. package/build/legacy/createFormFactory.d.cts +12 -0
  4. package/build/legacy/createFormFactory.d.ts +12 -0
  5. package/build/legacy/createFormFactory.js +17 -0
  6. package/build/legacy/createFormFactory.js.map +1 -0
  7. package/build/legacy/formContext.cjs +51 -0
  8. package/build/legacy/formContext.cjs.map +1 -0
  9. package/build/legacy/formContext.d.cts +13 -0
  10. package/build/legacy/formContext.d.ts +13 -0
  11. package/build/legacy/formContext.js +15 -0
  12. package/build/legacy/formContext.js.map +1 -0
  13. package/build/legacy/index.cjs +46 -0
  14. package/build/legacy/index.cjs.map +1 -0
  15. package/build/legacy/index.d.cts +7 -0
  16. package/build/legacy/index.d.ts +7 -0
  17. package/build/legacy/index.js +15 -0
  18. package/build/legacy/index.js.map +1 -0
  19. package/build/legacy/types.cjs +19 -0
  20. package/build/legacy/types.cjs.map +1 -0
  21. package/build/legacy/types.d.cts +7 -0
  22. package/build/legacy/types.d.ts +7 -0
  23. package/build/legacy/types.js +1 -0
  24. package/build/legacy/types.js.map +1 -0
  25. package/build/legacy/useField.cjs +80 -0
  26. package/build/legacy/useField.cjs.map +1 -0
  27. package/build/legacy/useField.d.cts +27 -0
  28. package/build/{lib → legacy}/useField.d.ts +10 -9
  29. package/build/legacy/useField.js +44 -0
  30. package/build/legacy/useField.js.map +1 -0
  31. package/build/legacy/useForm.cjs +70 -0
  32. package/build/legacy/useForm.cjs.map +1 -0
  33. package/build/legacy/useForm.d.cts +23 -0
  34. package/build/{lib → legacy}/useForm.d.ts +9 -7
  35. package/build/legacy/useForm.js +35 -0
  36. package/build/legacy/useForm.js.map +1 -0
  37. package/build/modern/createFormFactory.cjs +42 -0
  38. package/build/modern/createFormFactory.cjs.map +1 -0
  39. package/build/modern/createFormFactory.d.cts +12 -0
  40. package/build/modern/createFormFactory.d.ts +12 -0
  41. package/build/modern/createFormFactory.js +17 -0
  42. package/build/modern/createFormFactory.js.map +1 -0
  43. package/build/modern/formContext.cjs +51 -0
  44. package/build/modern/formContext.cjs.map +1 -0
  45. package/build/modern/formContext.d.cts +13 -0
  46. package/build/modern/formContext.d.ts +13 -0
  47. package/build/modern/formContext.js +15 -0
  48. package/build/modern/formContext.js.map +1 -0
  49. package/build/modern/index.cjs +46 -0
  50. package/build/modern/index.cjs.map +1 -0
  51. package/build/modern/index.d.cts +7 -0
  52. package/build/modern/index.d.ts +7 -0
  53. package/build/modern/index.js +15 -0
  54. package/build/modern/index.js.map +1 -0
  55. package/build/modern/types.cjs +19 -0
  56. package/build/modern/types.cjs.map +1 -0
  57. package/build/modern/types.d.cts +7 -0
  58. package/build/modern/types.d.ts +7 -0
  59. package/build/modern/types.js +1 -0
  60. package/build/modern/types.js.map +1 -0
  61. package/build/modern/useField.cjs +80 -0
  62. package/build/modern/useField.cjs.map +1 -0
  63. package/build/modern/useField.d.cts +27 -0
  64. package/build/modern/useField.d.ts +27 -0
  65. package/build/modern/useField.js +44 -0
  66. package/build/modern/useField.js.map +1 -0
  67. package/build/modern/useForm.cjs +70 -0
  68. package/build/modern/useForm.cjs.map +1 -0
  69. package/build/modern/useForm.d.cts +23 -0
  70. package/build/modern/useForm.d.ts +23 -0
  71. package/build/modern/useForm.js +35 -0
  72. package/build/modern/useForm.js.map +1 -0
  73. package/package.json +28 -22
  74. package/build/lib/_virtual/_rollupPluginBabelHelpers.cjs +0 -19
  75. package/build/lib/_virtual/_rollupPluginBabelHelpers.cjs.map +0 -1
  76. package/build/lib/_virtual/_rollupPluginBabelHelpers.js +0 -17
  77. package/build/lib/_virtual/_rollupPluginBabelHelpers.js.map +0 -1
  78. package/build/lib/_virtual/_rollupPluginBabelHelpers.legacy.cjs +0 -19
  79. package/build/lib/_virtual/_rollupPluginBabelHelpers.legacy.cjs.map +0 -1
  80. package/build/lib/_virtual/_rollupPluginBabelHelpers.legacy.js +0 -17
  81. package/build/lib/_virtual/_rollupPluginBabelHelpers.legacy.js.map +0 -1
  82. package/build/lib/createFormFactory.cjs +0 -18
  83. package/build/lib/createFormFactory.cjs.map +0 -1
  84. package/build/lib/createFormFactory.d.ts +0 -9
  85. package/build/lib/createFormFactory.d.ts.map +0 -1
  86. package/build/lib/createFormFactory.js +0 -16
  87. package/build/lib/createFormFactory.js.map +0 -1
  88. package/build/lib/createFormFactory.legacy.cjs +0 -18
  89. package/build/lib/createFormFactory.legacy.cjs.map +0 -1
  90. package/build/lib/createFormFactory.legacy.js +0 -16
  91. package/build/lib/createFormFactory.legacy.js.map +0 -1
  92. package/build/lib/formContext.cjs +0 -35
  93. package/build/lib/formContext.cjs.map +0 -1
  94. package/build/lib/formContext.d.ts +0 -11
  95. package/build/lib/formContext.d.ts.map +0 -1
  96. package/build/lib/formContext.js +0 -13
  97. package/build/lib/formContext.js.map +0 -1
  98. package/build/lib/formContext.legacy.cjs +0 -35
  99. package/build/lib/formContext.legacy.cjs.map +0 -1
  100. package/build/lib/formContext.legacy.js +0 -13
  101. package/build/lib/formContext.legacy.js.map +0 -1
  102. package/build/lib/index.cjs +0 -26
  103. package/build/lib/index.cjs.map +0 -1
  104. package/build/lib/index.d.ts +0 -8
  105. package/build/lib/index.d.ts.map +0 -1
  106. package/build/lib/index.js +0 -5
  107. package/build/lib/index.js.map +0 -1
  108. package/build/lib/index.legacy.cjs +0 -26
  109. package/build/lib/index.legacy.cjs.map +0 -1
  110. package/build/lib/index.legacy.js +0 -5
  111. package/build/lib/index.legacy.js.map +0 -1
  112. package/build/lib/tests/createFormFactory.test.d.ts +0 -3
  113. package/build/lib/tests/createFormFactory.test.d.ts.map +0 -1
  114. package/build/lib/tests/useField.test.d.ts +0 -3
  115. package/build/lib/tests/useField.test.d.ts.map +0 -1
  116. package/build/lib/tests/useForm.test.d.ts +0 -3
  117. package/build/lib/tests/useForm.test.d.ts.map +0 -1
  118. package/build/lib/tests/utils.d.ts +0 -2
  119. package/build/lib/tests/utils.d.ts.map +0 -1
  120. package/build/lib/types.d.ts +0 -5
  121. package/build/lib/types.d.ts.map +0 -1
  122. package/build/lib/useField.cjs +0 -83
  123. package/build/lib/useField.cjs.map +0 -1
  124. package/build/lib/useField.d.ts.map +0 -1
  125. package/build/lib/useField.js +0 -80
  126. package/build/lib/useField.js.map +0 -1
  127. package/build/lib/useField.legacy.cjs +0 -83
  128. package/build/lib/useField.legacy.cjs.map +0 -1
  129. package/build/lib/useField.legacy.js +0 -80
  130. package/build/lib/useField.legacy.js.map +0 -1
  131. package/build/lib/useForm.cjs +0 -52
  132. package/build/lib/useForm.cjs.map +0 -1
  133. package/build/lib/useForm.d.ts.map +0 -1
  134. package/build/lib/useForm.js +0 -50
  135. package/build/lib/useForm.js.map +0 -1
  136. package/build/lib/useForm.legacy.cjs +0 -52
  137. package/build/lib/useForm.legacy.cjs.map +0 -1
  138. package/build/lib/useForm.legacy.js +0 -50
  139. package/build/lib/useForm.legacy.js.map +0 -1
  140. package/build/lib/utils/isBrowser.cjs +0 -8
  141. package/build/lib/utils/isBrowser.cjs.map +0 -1
  142. package/build/lib/utils/isBrowser.d.ts +0 -2
  143. package/build/lib/utils/isBrowser.d.ts.map +0 -1
  144. package/build/lib/utils/isBrowser.js +0 -6
  145. package/build/lib/utils/isBrowser.js.map +0 -1
  146. package/build/lib/utils/isBrowser.legacy.cjs +0 -8
  147. package/build/lib/utils/isBrowser.legacy.cjs.map +0 -1
  148. package/build/lib/utils/isBrowser.legacy.js +0 -6
  149. package/build/lib/utils/isBrowser.legacy.js.map +0 -1
  150. package/build/lib/utils/useIsomorphicLayoutEffect.cjs +0 -11
  151. package/build/lib/utils/useIsomorphicLayoutEffect.cjs.map +0 -1
  152. package/build/lib/utils/useIsomorphicLayoutEffect.d.ts +0 -3
  153. package/build/lib/utils/useIsomorphicLayoutEffect.d.ts.map +0 -1
  154. package/build/lib/utils/useIsomorphicLayoutEffect.js +0 -9
  155. package/build/lib/utils/useIsomorphicLayoutEffect.js.map +0 -1
  156. package/build/lib/utils/useIsomorphicLayoutEffect.legacy.cjs +0 -11
  157. package/build/lib/utils/useIsomorphicLayoutEffect.legacy.cjs.map +0 -1
  158. package/build/lib/utils/useIsomorphicLayoutEffect.legacy.js +0 -9
  159. package/build/lib/utils/useIsomorphicLayoutEffect.legacy.js.map +0 -1
@@ -0,0 +1,44 @@
1
+ // src/useField.tsx
2
+ import React, { useState } from "react";
3
+ import { useStore } from "@tanstack/react-store";
4
+ import { FieldApi, functionalUpdate } from "@tanstack/form-core";
5
+ import { useFormContext, formContext } from "./formContext.js";
6
+ import { useIsomorphicLayoutEffect } from "./utils/useIsomorphicLayoutEffect.js";
7
+ function useField(opts) {
8
+ const { formApi, parentFieldName } = useFormContext();
9
+ const [fieldApi] = useState(() => {
10
+ const name = (typeof opts.index === "number" ? [parentFieldName, opts.index, opts.name] : [parentFieldName, opts.name]).filter((d) => d !== void 0).join(".");
11
+ const api = new FieldApi({ ...opts, form: formApi, name });
12
+ api.Field = Field;
13
+ return api;
14
+ });
15
+ useIsomorphicLayoutEffect(() => {
16
+ fieldApi.update({ ...opts, form: formApi });
17
+ });
18
+ useStore(
19
+ fieldApi.store,
20
+ opts.mode === "array" ? (state) => {
21
+ return [state.meta, Object.keys(state.value || []).length];
22
+ } : void 0
23
+ );
24
+ useIsomorphicLayoutEffect(() => fieldApi.mount(), [fieldApi]);
25
+ return fieldApi;
26
+ }
27
+ function Field({
28
+ children,
29
+ ...fieldOptions
30
+ }) {
31
+ const fieldApi = useField(fieldOptions);
32
+ return /* @__PURE__ */ React.createElement(
33
+ formContext.Provider,
34
+ {
35
+ value: { formApi: fieldApi.form, parentFieldName: fieldApi.name },
36
+ children: functionalUpdate(children, fieldApi)
37
+ }
38
+ );
39
+ }
40
+ export {
41
+ Field,
42
+ useField
43
+ };
44
+ //# sourceMappingURL=useField.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/useField.tsx"],"sourcesContent":["import React, { useState } from 'react'\nimport { useStore } from '@tanstack/react-store'\nimport type {\n DeepKeys,\n DeepValue,\n FieldOptions,\n Narrow,\n} from '@tanstack/form-core'\nimport { FieldApi, functionalUpdate } from '@tanstack/form-core'\nimport { useFormContext, formContext } from './formContext'\nimport { useIsomorphicLayoutEffect } from './utils/useIsomorphicLayoutEffect'\nimport type { UseFieldOptions } from './types'\n\ndeclare module '@tanstack/form-core' {\n // eslint-disable-next-line no-shadow\n interface FieldApi<TData, TFormData> {\n Field: FieldComponent<TData, TFormData>\n }\n}\n\nexport type UseField<TFormData> = <TField extends DeepKeys<TFormData>>(\n opts?: { name: Narrow<TField> } & UseFieldOptions<\n DeepValue<TFormData, TField>,\n TFormData\n >,\n) => FieldApi<DeepValue<TFormData, TField>, TFormData>\n\nexport function useField<TData, TFormData>(\n opts: UseFieldOptions<TData, TFormData>,\n): FieldApi<TData, TFormData> {\n // Get the form API either manually or from context\n const { formApi, parentFieldName } = useFormContext()\n\n const [fieldApi] = useState<FieldApi<TData, TFormData>>(() => {\n const name = (\n typeof opts.index === 'number'\n ? [parentFieldName, opts.index, opts.name]\n : [parentFieldName, opts.name]\n )\n .filter((d) => d !== undefined)\n .join('.')\n\n const api = new FieldApi({ ...opts, form: formApi, name: name as any })\n\n api.Field = Field as any\n\n return api\n })\n\n /**\n * fieldApi.update should not have any side effects. Think of it like a `useRef`\n * that we need to keep updated every render with the most up-to-date information.\n */\n useIsomorphicLayoutEffect(() => {\n fieldApi.update({ ...opts, form: formApi } as never)\n })\n\n useStore(\n fieldApi.store as any,\n opts.mode === 'array'\n ? (state: any) => {\n return [state.meta, Object.keys(state.value || []).length]\n }\n : undefined,\n )\n\n // Instantiates field meta and removes it when unrendered\n useIsomorphicLayoutEffect(() => fieldApi.mount(), [fieldApi])\n\n return fieldApi\n}\n\n// export type FieldValue<TFormData, TField> = TFormData extends any[]\n// ? TField extends `[${infer TIndex extends number | 'i'}].${infer TRest}`\n// ? DeepValue<TFormData[TIndex extends 'i' ? number : TIndex], TRest>\n// : TField extends `[${infer TIndex extends number | 'i'}]`\n// ? TFormData[TIndex extends 'i' ? number : TIndex]\n// : never\n// : TField extends `${infer TPrefix}[${infer TIndex extends\n// | number\n// | 'i'}].${infer TRest}`\n// ? DeepValue<\n// DeepValue<TFormData, TPrefix>[TIndex extends 'i' ? number : TIndex],\n// TRest\n// >\n// : TField extends `${infer TPrefix}[${infer TIndex extends number | 'i'}]`\n// ? DeepValue<TFormData, TPrefix>[TIndex extends 'i' ? number : TIndex]\n// : DeepValue<TFormData, TField>\n\nexport type FieldValue<TFormData, TField> = TFormData extends any[]\n ? unknown extends TField\n ? TFormData[number]\n : DeepValue<TFormData[number], TField>\n : DeepValue<TFormData, TField>\n\n// type Test1 = FieldValue<{ foo: { bar: string }[] }, 'foo'>\n// // ^?\n// type Test2 = FieldValue<{ foo: { bar: string }[] }, 'foo[i]'>\n// // ^?\n// type Test3 = FieldValue<{ foo: { bar: string }[] }, 'foo[2].bar'>\n// // ^?\n\nexport type FieldComponent<TParentData, TFormData> = <TField>({\n children,\n ...fieldOptions\n}: {\n children: (\n fieldApi: FieldApi<FieldValue<TParentData, TField>, TFormData>,\n ) => any\n} & Omit<\n UseFieldOptions<FieldValue<TParentData, TField>, TFormData>,\n 'name' | 'index'\n> &\n (TParentData extends any[]\n ? {\n name?: TField extends undefined ? TField : DeepKeys<TParentData>\n index: number\n }\n : {\n name: TField extends undefined ? TField : DeepKeys<TParentData>\n index?: never\n })) => any\n\nexport function Field<TData, TFormData>({\n children,\n ...fieldOptions\n}: {\n children: (fieldApi: FieldApi<TData, TFormData>) => any\n} & UseFieldOptions<TData, TFormData>) {\n const fieldApi = useField(fieldOptions as any)\n\n return (\n <formContext.Provider\n value={{ formApi: fieldApi.form, parentFieldName: fieldApi.name }}\n children={functionalUpdate(children, fieldApi as any)}\n />\n )\n}\n"],"mappings":";AAAA,OAAO,SAAS,gBAAgB;AAChC,SAAS,gBAAgB;AAOzB,SAAS,UAAU,wBAAwB;AAC3C,SAAS,gBAAgB,mBAAmB;AAC5C,SAAS,iCAAiC;AAiBnC,SAAS,SACd,MAC4B;AAE5B,QAAM,EAAE,SAAS,gBAAgB,IAAI,eAAe;AAEpD,QAAM,CAAC,QAAQ,IAAI,SAAqC,MAAM;AAC5D,UAAM,QACJ,OAAO,KAAK,UAAU,WAClB,CAAC,iBAAiB,KAAK,OAAO,KAAK,IAAI,IACvC,CAAC,iBAAiB,KAAK,IAAI,GAE9B,OAAO,CAAC,MAAM,MAAM,MAAS,EAC7B,KAAK,GAAG;AAEX,UAAM,MAAM,IAAI,SAAS,EAAE,GAAG,MAAM,MAAM,SAAS,KAAkB,CAAC;AAEtE,QAAI,QAAQ;AAEZ,WAAO;AAAA,EACT,CAAC;AAMD,4BAA0B,MAAM;AAC9B,aAAS,OAAO,EAAE,GAAG,MAAM,MAAM,QAAQ,CAAU;AAAA,EACrD,CAAC;AAED;AAAA,IACE,SAAS;AAAA,IACT,KAAK,SAAS,UACV,CAAC,UAAe;AACd,aAAO,CAAC,MAAM,MAAM,OAAO,KAAK,MAAM,SAAS,CAAC,CAAC,EAAE,MAAM;AAAA,IAC3D,IACA;AAAA,EACN;AAGA,4BAA0B,MAAM,SAAS,MAAM,GAAG,CAAC,QAAQ,CAAC;AAE5D,SAAO;AACT;AAqDO,SAAS,MAAwB;AAAA,EACtC;AAAA,EACA,GAAG;AACL,GAEuC;AACrC,QAAM,WAAW,SAAS,YAAmB;AAE7C,SACE;AAAA,IAAC,YAAY;AAAA,IAAZ;AAAA,MACC,OAAO,EAAE,SAAS,SAAS,MAAM,iBAAiB,SAAS,KAAK;AAAA,MAChE,UAAU,iBAAiB,UAAU,QAAe;AAAA;AAAA,EACtD;AAEJ;","names":[]}
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/useForm.tsx
31
+ var useForm_exports = {};
32
+ __export(useForm_exports, {
33
+ useForm: () => useForm
34
+ });
35
+ module.exports = __toCommonJS(useForm_exports);
36
+ var import_form_core = require("@tanstack/form-core");
37
+ var import_react_store = require("@tanstack/react-store");
38
+ var import_react = __toESM(require("react"), 1);
39
+ var import_useField = require("./useField.cjs");
40
+ var import_formContext = require("./formContext.cjs");
41
+ var import_useIsomorphicLayoutEffect = require("./utils/useIsomorphicLayoutEffect.cjs");
42
+ function useForm(opts) {
43
+ const [formApi] = (0, import_react.useState)(() => {
44
+ const api = new import_form_core.FormApi(opts);
45
+ api.Provider = (props) => /* @__PURE__ */ import_react.default.createElement(import_formContext.formContext.Provider, { ...props, value: { formApi: api } });
46
+ api.Field = import_useField.Field;
47
+ api.useField = import_useField.useField;
48
+ api.useStore = (selector) => {
49
+ return (0, import_react_store.useStore)(api.store, selector);
50
+ };
51
+ api.Subscribe = (props) => {
52
+ return (0, import_form_core.functionalUpdate)(
53
+ props.children,
54
+ // eslint-disable-next-line react-hooks/rules-of-hooks
55
+ (0, import_react_store.useStore)(api.store, props.selector)
56
+ );
57
+ };
58
+ return api;
59
+ });
60
+ formApi.useStore((state) => state.isSubmitting);
61
+ (0, import_useIsomorphicLayoutEffect.useIsomorphicLayoutEffect)(() => {
62
+ formApi.update(opts);
63
+ });
64
+ return formApi;
65
+ }
66
+ // Annotate the CommonJS export names for ESM import in node:
67
+ 0 && (module.exports = {
68
+ useForm
69
+ });
70
+ //# sourceMappingURL=useForm.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/useForm.tsx"],"sourcesContent":["import type { FormState, FormOptions } from '@tanstack/form-core'\nimport { FormApi, functionalUpdate } from '@tanstack/form-core'\nimport type { NoInfer } from '@tanstack/react-store'\nimport { useStore } from '@tanstack/react-store'\nimport React, { type ReactNode, useState } from 'react'\nimport { type UseField, type FieldComponent, Field, useField } from './useField'\nimport { formContext } from './formContext'\nimport { useIsomorphicLayoutEffect } from './utils/useIsomorphicLayoutEffect'\n\ndeclare module '@tanstack/form-core' {\n // eslint-disable-next-line no-shadow\n interface FormApi<TFormData> {\n Provider: (props: { children: any }) => any\n Field: FieldComponent<TFormData, TFormData>\n useField: UseField<TFormData>\n useStore: <TSelected = NoInfer<FormState<TFormData>>>(\n selector?: (state: NoInfer<FormState<TFormData>>) => TSelected,\n ) => TSelected\n Subscribe: <TSelected = NoInfer<FormState<TFormData>>>(props: {\n selector?: (state: NoInfer<FormState<TFormData>>) => TSelected\n children: ((state: NoInfer<TSelected>) => ReactNode) | ReactNode\n }) => any\n }\n}\n\nexport function useForm<TData>(opts?: FormOptions<TData>): FormApi<TData> {\n const [formApi] = useState(() => {\n // @ts-ignore\n const api = new FormApi<TData>(opts)\n\n // eslint-disable-next-line react/display-name\n api.Provider = (props) => (\n <formContext.Provider {...props} value={{ formApi: api }} />\n )\n api.Field = Field as any\n api.useField = useField as any\n api.useStore = (\n // @ts-ignore\n selector,\n ) => {\n // eslint-disable-next-line react-hooks/rules-of-hooks\n return useStore(api.store as any, selector as any) as any\n }\n api.Subscribe = (\n // @ts-ignore\n props,\n ) => {\n return functionalUpdate(\n props.children,\n // eslint-disable-next-line react-hooks/rules-of-hooks\n useStore(api.store as any, props.selector as any),\n ) as any\n }\n\n return api\n })\n\n formApi.useStore((state) => state.isSubmitting)\n\n /**\n * formApi.update should not have any side effects. Think of it like a `useRef`\n * that we need to keep updated every render with the most up-to-date information.\n */\n useIsomorphicLayoutEffect(() => {\n formApi.update(opts)\n })\n\n return formApi as any\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,uBAA0C;AAE1C,yBAAyB;AACzB,mBAAgD;AAChD,sBAAoE;AACpE,yBAA4B;AAC5B,uCAA0C;AAkBnC,SAAS,QAAe,MAA2C;AACxE,QAAM,CAAC,OAAO,QAAI,uBAAS,MAAM;AAE/B,UAAM,MAAM,IAAI,yBAAe,IAAI;AAGnC,QAAI,WAAW,CAAC,UACd,6BAAAA,QAAA,cAAC,+BAAY,UAAZ,EAAsB,GAAG,OAAO,OAAO,EAAE,SAAS,IAAI,GAAG;AAE5D,QAAI,QAAQ;AACZ,QAAI,WAAW;AACf,QAAI,WAAW,CAEb,aACG;AAEH,iBAAO,6BAAS,IAAI,OAAc,QAAe;AAAA,IACnD;AACA,QAAI,YAAY,CAEd,UACG;AACH,iBAAO;AAAA,QACL,MAAM;AAAA;AAAA,YAEN,6BAAS,IAAI,OAAc,MAAM,QAAe;AAAA,MAClD;AAAA,IACF;AAEA,WAAO;AAAA,EACT,CAAC;AAED,UAAQ,SAAS,CAAC,UAAU,MAAM,YAAY;AAM9C,kEAA0B,MAAM;AAC9B,YAAQ,OAAO,IAAI;AAAA,EACrB,CAAC;AAED,SAAO;AACT;","names":["React"]}
@@ -0,0 +1,23 @@
1
+ import { FormState, FormOptions, FormApi } from '@tanstack/form-core';
2
+ import { NoInfer } from '@tanstack/react-store';
3
+ import { ReactNode } from 'react';
4
+ import { FieldComponent, UseField } from './useField.cjs';
5
+ import './types.cjs';
6
+
7
+ declare module '@tanstack/form-core' {
8
+ interface FormApi<TFormData> {
9
+ Provider: (props: {
10
+ children: any;
11
+ }) => any;
12
+ Field: FieldComponent<TFormData, TFormData>;
13
+ useField: UseField<TFormData>;
14
+ useStore: <TSelected = NoInfer<FormState<TFormData>>>(selector?: (state: NoInfer<FormState<TFormData>>) => TSelected) => TSelected;
15
+ Subscribe: <TSelected = NoInfer<FormState<TFormData>>>(props: {
16
+ selector?: (state: NoInfer<FormState<TFormData>>) => TSelected;
17
+ children: ((state: NoInfer<TSelected>) => ReactNode) | ReactNode;
18
+ }) => any;
19
+ }
20
+ }
21
+ declare function useForm<TData>(opts?: FormOptions<TData>): FormApi<TData>;
22
+
23
+ export { useForm };
@@ -0,0 +1,23 @@
1
+ import { FormState, FormOptions, FormApi } from '@tanstack/form-core';
2
+ import { NoInfer } from '@tanstack/react-store';
3
+ import { ReactNode } from 'react';
4
+ import { FieldComponent, UseField } from './useField.js';
5
+ import './types.js';
6
+
7
+ declare module '@tanstack/form-core' {
8
+ interface FormApi<TFormData> {
9
+ Provider: (props: {
10
+ children: any;
11
+ }) => any;
12
+ Field: FieldComponent<TFormData, TFormData>;
13
+ useField: UseField<TFormData>;
14
+ useStore: <TSelected = NoInfer<FormState<TFormData>>>(selector?: (state: NoInfer<FormState<TFormData>>) => TSelected) => TSelected;
15
+ Subscribe: <TSelected = NoInfer<FormState<TFormData>>>(props: {
16
+ selector?: (state: NoInfer<FormState<TFormData>>) => TSelected;
17
+ children: ((state: NoInfer<TSelected>) => ReactNode) | ReactNode;
18
+ }) => any;
19
+ }
20
+ }
21
+ declare function useForm<TData>(opts?: FormOptions<TData>): FormApi<TData>;
22
+
23
+ export { useForm };
@@ -0,0 +1,35 @@
1
+ // src/useForm.tsx
2
+ import { FormApi, functionalUpdate } from "@tanstack/form-core";
3
+ import { useStore } from "@tanstack/react-store";
4
+ import React, { useState } from "react";
5
+ import { Field, useField } from "./useField.js";
6
+ import { formContext } from "./formContext.js";
7
+ import { useIsomorphicLayoutEffect } from "./utils/useIsomorphicLayoutEffect.js";
8
+ function useForm(opts) {
9
+ const [formApi] = useState(() => {
10
+ const api = new FormApi(opts);
11
+ api.Provider = (props) => /* @__PURE__ */ React.createElement(formContext.Provider, { ...props, value: { formApi: api } });
12
+ api.Field = Field;
13
+ api.useField = useField;
14
+ api.useStore = (selector) => {
15
+ return useStore(api.store, selector);
16
+ };
17
+ api.Subscribe = (props) => {
18
+ return functionalUpdate(
19
+ props.children,
20
+ // eslint-disable-next-line react-hooks/rules-of-hooks
21
+ useStore(api.store, props.selector)
22
+ );
23
+ };
24
+ return api;
25
+ });
26
+ formApi.useStore((state) => state.isSubmitting);
27
+ useIsomorphicLayoutEffect(() => {
28
+ formApi.update(opts);
29
+ });
30
+ return formApi;
31
+ }
32
+ export {
33
+ useForm
34
+ };
35
+ //# sourceMappingURL=useForm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/useForm.tsx"],"sourcesContent":["import type { FormState, FormOptions } from '@tanstack/form-core'\nimport { FormApi, functionalUpdate } from '@tanstack/form-core'\nimport type { NoInfer } from '@tanstack/react-store'\nimport { useStore } from '@tanstack/react-store'\nimport React, { type ReactNode, useState } from 'react'\nimport { type UseField, type FieldComponent, Field, useField } from './useField'\nimport { formContext } from './formContext'\nimport { useIsomorphicLayoutEffect } from './utils/useIsomorphicLayoutEffect'\n\ndeclare module '@tanstack/form-core' {\n // eslint-disable-next-line no-shadow\n interface FormApi<TFormData> {\n Provider: (props: { children: any }) => any\n Field: FieldComponent<TFormData, TFormData>\n useField: UseField<TFormData>\n useStore: <TSelected = NoInfer<FormState<TFormData>>>(\n selector?: (state: NoInfer<FormState<TFormData>>) => TSelected,\n ) => TSelected\n Subscribe: <TSelected = NoInfer<FormState<TFormData>>>(props: {\n selector?: (state: NoInfer<FormState<TFormData>>) => TSelected\n children: ((state: NoInfer<TSelected>) => ReactNode) | ReactNode\n }) => any\n }\n}\n\nexport function useForm<TData>(opts?: FormOptions<TData>): FormApi<TData> {\n const [formApi] = useState(() => {\n // @ts-ignore\n const api = new FormApi<TData>(opts)\n\n // eslint-disable-next-line react/display-name\n api.Provider = (props) => (\n <formContext.Provider {...props} value={{ formApi: api }} />\n )\n api.Field = Field as any\n api.useField = useField as any\n api.useStore = (\n // @ts-ignore\n selector,\n ) => {\n // eslint-disable-next-line react-hooks/rules-of-hooks\n return useStore(api.store as any, selector as any) as any\n }\n api.Subscribe = (\n // @ts-ignore\n props,\n ) => {\n return functionalUpdate(\n props.children,\n // eslint-disable-next-line react-hooks/rules-of-hooks\n useStore(api.store as any, props.selector as any),\n ) as any\n }\n\n return api\n })\n\n formApi.useStore((state) => state.isSubmitting)\n\n /**\n * formApi.update should not have any side effects. Think of it like a `useRef`\n * that we need to keep updated every render with the most up-to-date information.\n */\n useIsomorphicLayoutEffect(() => {\n formApi.update(opts)\n })\n\n return formApi as any\n}\n"],"mappings":";AACA,SAAS,SAAS,wBAAwB;AAE1C,SAAS,gBAAgB;AACzB,OAAO,SAAyB,gBAAgB;AAChD,SAA6C,OAAO,gBAAgB;AACpE,SAAS,mBAAmB;AAC5B,SAAS,iCAAiC;AAkBnC,SAAS,QAAe,MAA2C;AACxE,QAAM,CAAC,OAAO,IAAI,SAAS,MAAM;AAE/B,UAAM,MAAM,IAAI,QAAe,IAAI;AAGnC,QAAI,WAAW,CAAC,UACd,oCAAC,YAAY,UAAZ,EAAsB,GAAG,OAAO,OAAO,EAAE,SAAS,IAAI,GAAG;AAE5D,QAAI,QAAQ;AACZ,QAAI,WAAW;AACf,QAAI,WAAW,CAEb,aACG;AAEH,aAAO,SAAS,IAAI,OAAc,QAAe;AAAA,IACnD;AACA,QAAI,YAAY,CAEd,UACG;AACH,aAAO;AAAA,QACL,MAAM;AAAA;AAAA,QAEN,SAAS,IAAI,OAAc,MAAM,QAAe;AAAA,MAClD;AAAA,IACF;AAEA,WAAO;AAAA,EACT,CAAC;AAED,UAAQ,SAAS,CAAC,UAAU,MAAM,YAAY;AAM9C,4BAA0B,MAAM;AAC9B,YAAQ,OAAO,IAAI;AAAA,EACrB,CAAC;AAED,SAAO;AACT;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/react-form",
3
- "version": "0.1.2",
3
+ "version": "0.2.0",
4
4
  "description": "Powerful, type-safe forms for React.",
5
5
  "author": "tannerlinsley",
6
6
  "license": "MIT",
@@ -10,28 +10,37 @@
10
10
  "type": "github",
11
11
  "url": "https://github.com/sponsors/tannerlinsley"
12
12
  },
13
+ "sideEffects": false,
14
+ "files": [
15
+ "build",
16
+ "src"
17
+ ],
13
18
  "type": "module",
14
- "types": "build/lib/index.d.ts",
15
- "main": "build/lib/index.legacy.cjs",
16
- "module": "build/lib/index.legacy.js",
19
+ "types": "build/legacy/index.d.ts",
20
+ "main": "build/legacy/index.cjs",
21
+ "module": "build/legacy/index.js",
17
22
  "exports": {
18
23
  ".": {
19
- "types": "./build/lib/index.d.ts",
20
- "import": "./build/lib/index.js",
21
- "require": "./build/lib/index.cjs",
22
- "default": "./build/lib/index.cjs"
24
+ "import": {
25
+ "types": "./build/modern/index.d.ts",
26
+ "default": "./build/modern/index.js"
27
+ },
28
+ "require": {
29
+ "types": "./build/modern/index.d.cts",
30
+ "default": "./build/modern/index.cjs"
31
+ }
23
32
  },
24
33
  "./package.json": "./package.json"
25
34
  },
26
- "sideEffects": false,
27
- "files": [
28
- "build/lib/*",
29
- "src",
30
- "build/codemods",
31
- "!build/codemods/jest.config.js",
32
- "!build/codemods/**/__testfixtures__",
33
- "!build/codemods/**/__tests__"
34
- ],
35
+ "nx": {
36
+ "targets": {
37
+ "test:build": {
38
+ "dependsOn": [
39
+ "build"
40
+ ]
41
+ }
42
+ }
43
+ },
35
44
  "devDependencies": {
36
45
  "@types/jscodeshift": "^0.11.3",
37
46
  "@types/react": "^18.0.14",
@@ -44,7 +53,7 @@
44
53
  "dependencies": {
45
54
  "@tanstack/react-store": "0.1.3",
46
55
  "@tanstack/store": "0.1.3",
47
- "@tanstack/form-core": "0.1.2"
56
+ "@tanstack/form-core": "0.2.0"
48
57
  },
49
58
  "peerDependencies": {
50
59
  "react": "^17.0.0 || ^18.0.0",
@@ -66,9 +75,6 @@
66
75
  "test:lib": "vitest run --coverage",
67
76
  "test:lib:dev": "pnpm run test:lib --watch",
68
77
  "test:build": "publint --strict",
69
- "build": "pnpm build:rollup && pnpm build:codemods && pnpm build:types",
70
- "build:rollup": "rollup --config rollup.config.js",
71
- "build:codemods": "cpy ../codemods/src/**/* ./build/codemods",
72
- "build:types": "tsc --emitDeclarationOnly"
78
+ "build": "tsup"
73
79
  }
74
80
  }
@@ -1,19 +0,0 @@
1
- 'use strict';
2
-
3
- function _extends() {
4
- _extends = Object.assign ? Object.assign.bind() : function (target) {
5
- for (var i = 1; i < arguments.length; i++) {
6
- var source = arguments[i];
7
- for (var key in source) {
8
- if (Object.prototype.hasOwnProperty.call(source, key)) {
9
- target[key] = source[key];
10
- }
11
- }
12
- }
13
- return target;
14
- };
15
- return _extends.apply(this, arguments);
16
- }
17
-
18
- exports.extends = _extends;
19
- //# sourceMappingURL=_rollupPluginBabelHelpers.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"_rollupPluginBabelHelpers.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;"}
@@ -1,17 +0,0 @@
1
- function _extends() {
2
- _extends = Object.assign ? Object.assign.bind() : function (target) {
3
- for (var i = 1; i < arguments.length; i++) {
4
- var source = arguments[i];
5
- for (var key in source) {
6
- if (Object.prototype.hasOwnProperty.call(source, key)) {
7
- target[key] = source[key];
8
- }
9
- }
10
- }
11
- return target;
12
- };
13
- return _extends.apply(this, arguments);
14
- }
15
-
16
- export { _extends as extends };
17
- //# sourceMappingURL=_rollupPluginBabelHelpers.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"_rollupPluginBabelHelpers.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;"}
@@ -1,19 +0,0 @@
1
- 'use strict';
2
-
3
- function _extends() {
4
- _extends = Object.assign ? Object.assign.bind() : function (target) {
5
- for (var i = 1; i < arguments.length; i++) {
6
- var source = arguments[i];
7
- for (var key in source) {
8
- if (Object.prototype.hasOwnProperty.call(source, key)) {
9
- target[key] = source[key];
10
- }
11
- }
12
- }
13
- return target;
14
- };
15
- return _extends.apply(this, arguments);
16
- }
17
-
18
- exports.extends = _extends;
19
- //# sourceMappingURL=_rollupPluginBabelHelpers.legacy.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"_rollupPluginBabelHelpers.legacy.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;"}
@@ -1,17 +0,0 @@
1
- function _extends() {
2
- _extends = Object.assign ? Object.assign.bind() : function (target) {
3
- for (var i = 1; i < arguments.length; i++) {
4
- var source = arguments[i];
5
- for (var key in source) {
6
- if (Object.prototype.hasOwnProperty.call(source, key)) {
7
- target[key] = source[key];
8
- }
9
- }
10
- }
11
- return target;
12
- };
13
- return _extends.apply(this, arguments);
14
- }
15
-
16
- export { _extends as extends };
17
- //# sourceMappingURL=_rollupPluginBabelHelpers.legacy.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"_rollupPluginBabelHelpers.legacy.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;"}
@@ -1,18 +0,0 @@
1
- 'use strict';
2
-
3
- var useField = require('./useField.cjs');
4
- var useForm = require('./useForm.cjs');
5
-
6
- function createFormFactory(defaultOpts) {
7
- return {
8
- useForm: opts => {
9
- const formOptions = Object.assign({}, defaultOpts, opts);
10
- return useForm.useForm(formOptions);
11
- },
12
- useField: useField.useField,
13
- Field: useField.Field
14
- };
15
- }
16
-
17
- exports.createFormFactory = createFormFactory;
18
- //# sourceMappingURL=createFormFactory.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"createFormFactory.cjs","sources":["../../src/createFormFactory.ts"],"sourcesContent":["import type { FormApi, FormOptions } from '@tanstack/form-core'\n\nimport { type UseField, type FieldComponent, Field, useField } from './useField'\nimport { useForm } from './useForm'\n\nexport type FormFactory<TFormData> = {\n useForm: (opts?: FormOptions<TFormData>) => FormApi<TFormData>\n useField: UseField<TFormData>\n Field: FieldComponent<TFormData, TFormData>\n}\n\nexport function createFormFactory<TFormData>(\n defaultOpts?: FormOptions<TFormData>,\n): FormFactory<TFormData> {\n return {\n useForm: (opts) => {\n const formOptions = Object.assign({}, defaultOpts, opts)\n return useForm<TFormData>(formOptions)\n },\n useField: useField as any,\n Field: Field as any,\n }\n}\n"],"names":["createFormFactory","defaultOpts","useForm","opts","formOptions","Object","assign","useField","Field"],"mappings":";;;;;AAWO,SAASA,iBAAiBA,CAC/BC,WAAoC,EACZ;EACxB,OAAO;IACLC,OAAO,EAAGC,IAAI,IAAK;AACjB,MAAA,MAAMC,WAAW,GAAGC,MAAM,CAACC,MAAM,CAAC,EAAE,EAAEL,WAAW,EAAEE,IAAI,CAAC,CAAA;MACxD,OAAOD,eAAO,CAAYE,WAAW,CAAC,CAAA;KACvC;AACDG,IAAAA,QAAQ,EAAEA,iBAAe;AACzBC,IAAAA,KAAK,EAAEA,cAAAA;GACR,CAAA;AACH;;;;"}
@@ -1,9 +0,0 @@
1
- import type { FormApi, FormOptions } from '@tanstack/form-core';
2
- import { type UseField, type FieldComponent } from './useField';
3
- export type FormFactory<TFormData> = {
4
- useForm: (opts?: FormOptions<TFormData>) => FormApi<TFormData>;
5
- useField: UseField<TFormData>;
6
- Field: FieldComponent<TFormData, TFormData>;
7
- };
8
- export declare function createFormFactory<TFormData>(defaultOpts?: FormOptions<TFormData>): FormFactory<TFormData>;
9
- //# sourceMappingURL=createFormFactory.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"createFormFactory.d.ts","sourceRoot":"","sources":["../../src/createFormFactory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA;AAE/D,OAAO,EAAE,KAAK,QAAQ,EAAE,KAAK,cAAc,EAAmB,MAAM,YAAY,CAAA;AAGhF,MAAM,MAAM,WAAW,CAAC,SAAS,IAAI;IACnC,OAAO,EAAE,CAAC,IAAI,CAAC,EAAE,WAAW,CAAC,SAAS,CAAC,KAAK,OAAO,CAAC,SAAS,CAAC,CAAA;IAC9D,QAAQ,EAAE,QAAQ,CAAC,SAAS,CAAC,CAAA;IAC7B,KAAK,EAAE,cAAc,CAAC,SAAS,EAAE,SAAS,CAAC,CAAA;CAC5C,CAAA;AAED,wBAAgB,iBAAiB,CAAC,SAAS,EACzC,WAAW,CAAC,EAAE,WAAW,CAAC,SAAS,CAAC,GACnC,WAAW,CAAC,SAAS,CAAC,CASxB"}
@@ -1,16 +0,0 @@
1
- import { useField, Field } from './useField.js';
2
- import { useForm } from './useForm.js';
3
-
4
- function createFormFactory(defaultOpts) {
5
- return {
6
- useForm: opts => {
7
- const formOptions = Object.assign({}, defaultOpts, opts);
8
- return useForm(formOptions);
9
- },
10
- useField: useField,
11
- Field: Field
12
- };
13
- }
14
-
15
- export { createFormFactory };
16
- //# sourceMappingURL=createFormFactory.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"createFormFactory.js","sources":["../../src/createFormFactory.ts"],"sourcesContent":["import type { FormApi, FormOptions } from '@tanstack/form-core'\n\nimport { type UseField, type FieldComponent, Field, useField } from './useField'\nimport { useForm } from './useForm'\n\nexport type FormFactory<TFormData> = {\n useForm: (opts?: FormOptions<TFormData>) => FormApi<TFormData>\n useField: UseField<TFormData>\n Field: FieldComponent<TFormData, TFormData>\n}\n\nexport function createFormFactory<TFormData>(\n defaultOpts?: FormOptions<TFormData>,\n): FormFactory<TFormData> {\n return {\n useForm: (opts) => {\n const formOptions = Object.assign({}, defaultOpts, opts)\n return useForm<TFormData>(formOptions)\n },\n useField: useField as any,\n Field: Field as any,\n }\n}\n"],"names":["createFormFactory","defaultOpts","useForm","opts","formOptions","Object","assign","useField","Field"],"mappings":";;;AAWO,SAASA,iBAAiBA,CAC/BC,WAAoC,EACZ;EACxB,OAAO;IACLC,OAAO,EAAGC,IAAI,IAAK;AACjB,MAAA,MAAMC,WAAW,GAAGC,MAAM,CAACC,MAAM,CAAC,EAAE,EAAEL,WAAW,EAAEE,IAAI,CAAC,CAAA;MACxD,OAAOD,OAAO,CAAYE,WAAW,CAAC,CAAA;KACvC;AACDG,IAAAA,QAAQ,EAAEA,QAAe;AACzBC,IAAAA,KAAK,EAAEA,KAAAA;GACR,CAAA;AACH;;;;"}
@@ -1,18 +0,0 @@
1
- 'use strict';
2
-
3
- var useField = require('./useField.legacy.cjs');
4
- var useForm = require('./useForm.legacy.cjs');
5
-
6
- function createFormFactory(defaultOpts) {
7
- return {
8
- useForm: opts => {
9
- const formOptions = Object.assign({}, defaultOpts, opts);
10
- return useForm.useForm(formOptions);
11
- },
12
- useField: useField.useField,
13
- Field: useField.Field
14
- };
15
- }
16
-
17
- exports.createFormFactory = createFormFactory;
18
- //# sourceMappingURL=createFormFactory.legacy.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"createFormFactory.legacy.cjs","sources":["../../src/createFormFactory.ts"],"sourcesContent":["import type { FormApi, FormOptions } from '@tanstack/form-core'\n\nimport { type UseField, type FieldComponent, Field, useField } from './useField'\nimport { useForm } from './useForm'\n\nexport type FormFactory<TFormData> = {\n useForm: (opts?: FormOptions<TFormData>) => FormApi<TFormData>\n useField: UseField<TFormData>\n Field: FieldComponent<TFormData, TFormData>\n}\n\nexport function createFormFactory<TFormData>(\n defaultOpts?: FormOptions<TFormData>,\n): FormFactory<TFormData> {\n return {\n useForm: (opts) => {\n const formOptions = Object.assign({}, defaultOpts, opts)\n return useForm<TFormData>(formOptions)\n },\n useField: useField as any,\n Field: Field as any,\n }\n}\n"],"names":["createFormFactory","defaultOpts","useForm","opts","formOptions","Object","assign","useField","Field"],"mappings":";;;;;AAWO,SAASA,iBAAiBA,CAC/BC,WAAoC,EACZ;EACxB,OAAO;IACLC,OAAO,EAAGC,IAAI,IAAK;AACjB,MAAA,MAAMC,WAAW,GAAGC,MAAM,CAACC,MAAM,CAAC,EAAE,EAAEL,WAAW,EAAEE,IAAI,CAAC,CAAA;MACxD,OAAOD,eAAO,CAAYE,WAAW,CAAC,CAAA;KACvC;AACDG,IAAAA,QAAQ,EAAEA,iBAAe;AACzBC,IAAAA,KAAK,EAAEA,cAAAA;GACR,CAAA;AACH;;;;"}
@@ -1,16 +0,0 @@
1
- import { useField, Field } from './useField.legacy.js';
2
- import { useForm } from './useForm.legacy.js';
3
-
4
- function createFormFactory(defaultOpts) {
5
- return {
6
- useForm: opts => {
7
- const formOptions = Object.assign({}, defaultOpts, opts);
8
- return useForm(formOptions);
9
- },
10
- useField: useField,
11
- Field: Field
12
- };
13
- }
14
-
15
- export { createFormFactory };
16
- //# sourceMappingURL=createFormFactory.legacy.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"createFormFactory.legacy.js","sources":["../../src/createFormFactory.ts"],"sourcesContent":["import type { FormApi, FormOptions } from '@tanstack/form-core'\n\nimport { type UseField, type FieldComponent, Field, useField } from './useField'\nimport { useForm } from './useForm'\n\nexport type FormFactory<TFormData> = {\n useForm: (opts?: FormOptions<TFormData>) => FormApi<TFormData>\n useField: UseField<TFormData>\n Field: FieldComponent<TFormData, TFormData>\n}\n\nexport function createFormFactory<TFormData>(\n defaultOpts?: FormOptions<TFormData>,\n): FormFactory<TFormData> {\n return {\n useForm: (opts) => {\n const formOptions = Object.assign({}, defaultOpts, opts)\n return useForm<TFormData>(formOptions)\n },\n useField: useField as any,\n Field: Field as any,\n }\n}\n"],"names":["createFormFactory","defaultOpts","useForm","opts","formOptions","Object","assign","useField","Field"],"mappings":";;;AAWO,SAASA,iBAAiBA,CAC/BC,WAAoC,EACZ;EACxB,OAAO;IACLC,OAAO,EAAGC,IAAI,IAAK;AACjB,MAAA,MAAMC,WAAW,GAAGC,MAAM,CAACC,MAAM,CAAC,EAAE,EAAEL,WAAW,EAAEE,IAAI,CAAC,CAAA;MACxD,OAAOD,OAAO,CAAYE,WAAW,CAAC,CAAA;KACvC;AACDG,IAAAA,QAAQ,EAAEA,QAAe;AACzBC,IAAAA,KAAK,EAAEA,KAAAA;GACR,CAAA;AACH;;;;"}
@@ -1,35 +0,0 @@
1
- 'use strict';
2
-
3
- var React = require('react');
4
-
5
- function _interopNamespaceDefault(e) {
6
- var n = Object.create(null);
7
- if (e) {
8
- Object.keys(e).forEach(function (k) {
9
- if (k !== 'default') {
10
- var d = Object.getOwnPropertyDescriptor(e, k);
11
- Object.defineProperty(n, k, d.get ? d : {
12
- enumerable: true,
13
- get: function () { return e[k]; }
14
- });
15
- }
16
- });
17
- }
18
- n.default = e;
19
- return Object.freeze(n);
20
- }
21
-
22
- var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
23
-
24
- const formContext = /*#__PURE__*/React__namespace.createContext(null);
25
- function useFormContext() {
26
- const formApi = React__namespace.useContext(formContext);
27
- if (!formApi) {
28
- throw new Error("You are trying to use the form API outside of a form!");
29
- }
30
- return formApi;
31
- }
32
-
33
- exports.formContext = formContext;
34
- exports.useFormContext = useFormContext;
35
- //# sourceMappingURL=formContext.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"formContext.cjs","sources":["../../src/formContext.ts"],"sourcesContent":["import type { FormApi } from '@tanstack/form-core'\nimport * as React from 'react'\n\nexport const formContext = React.createContext<{\n formApi: FormApi<any>\n parentFieldName?: string\n} | null>(null!)\n\nexport function useFormContext() {\n const formApi = React.useContext(formContext)\n\n if (!formApi) {\n throw new Error(`You are trying to use the form API outside of a form!`)\n }\n\n return formApi\n}\n"],"names":["formContext","React","createContext","useFormContext","formApi","useContext","Error"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAGO,MAAMA,WAAW,gBAAGC,gBAAK,CAACC,aAAa,CAGpC,IAAK,EAAC;AAET,SAASC,cAAcA,GAAG;AAC/B,EAAA,MAAMC,OAAO,GAAGH,gBAAK,CAACI,UAAU,CAACL,WAAW,CAAC,CAAA;EAE7C,IAAI,CAACI,OAAO,EAAE;IACZ,MAAM,IAAIE,KAAK,CAAA,uDAAwD,CAAC,CAAA;AAC1E,GAAA;AAEA,EAAA,OAAOF,OAAO,CAAA;AAChB;;;;;"}
@@ -1,11 +0,0 @@
1
- import type { FormApi } from '@tanstack/form-core';
2
- import * as React from 'react';
3
- export declare const formContext: React.Context<{
4
- formApi: FormApi<any>;
5
- parentFieldName?: string | undefined;
6
- } | null>;
7
- export declare function useFormContext(): {
8
- formApi: FormApi<any>;
9
- parentFieldName?: string | undefined;
10
- };
11
- //# sourceMappingURL=formContext.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"formContext.d.ts","sourceRoot":"","sources":["../../src/formContext.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAClD,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAE9B,eAAO,MAAM,WAAW;aACb,QAAQ,GAAG,CAAC;;SAEP,CAAA;AAEhB,wBAAgB,cAAc;;;EAQ7B"}
@@ -1,13 +0,0 @@
1
- import * as React from 'react';
2
-
3
- const formContext = /*#__PURE__*/React.createContext(null);
4
- function useFormContext() {
5
- const formApi = React.useContext(formContext);
6
- if (!formApi) {
7
- throw new Error("You are trying to use the form API outside of a form!");
8
- }
9
- return formApi;
10
- }
11
-
12
- export { formContext, useFormContext };
13
- //# sourceMappingURL=formContext.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"formContext.js","sources":["../../src/formContext.ts"],"sourcesContent":["import type { FormApi } from '@tanstack/form-core'\nimport * as React from 'react'\n\nexport const formContext = React.createContext<{\n formApi: FormApi<any>\n parentFieldName?: string\n} | null>(null!)\n\nexport function useFormContext() {\n const formApi = React.useContext(formContext)\n\n if (!formApi) {\n throw new Error(`You are trying to use the form API outside of a form!`)\n }\n\n return formApi\n}\n"],"names":["formContext","React","createContext","useFormContext","formApi","useContext","Error"],"mappings":";;AAGO,MAAMA,WAAW,gBAAGC,KAAK,CAACC,aAAa,CAGpC,IAAK,EAAC;AAET,SAASC,cAAcA,GAAG;AAC/B,EAAA,MAAMC,OAAO,GAAGH,KAAK,CAACI,UAAU,CAACL,WAAW,CAAC,CAAA;EAE7C,IAAI,CAACI,OAAO,EAAE;IACZ,MAAM,IAAIE,KAAK,CAAA,uDAAwD,CAAC,CAAA;AAC1E,GAAA;AAEA,EAAA,OAAOF,OAAO,CAAA;AAChB;;;;"}
@@ -1,35 +0,0 @@
1
- 'use strict';
2
-
3
- var React = require('react');
4
-
5
- function _interopNamespaceDefault(e) {
6
- var n = Object.create(null);
7
- if (e) {
8
- Object.keys(e).forEach(function (k) {
9
- if (k !== 'default') {
10
- var d = Object.getOwnPropertyDescriptor(e, k);
11
- Object.defineProperty(n, k, d.get ? d : {
12
- enumerable: true,
13
- get: function () { return e[k]; }
14
- });
15
- }
16
- });
17
- }
18
- n.default = e;
19
- return Object.freeze(n);
20
- }
21
-
22
- var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
23
-
24
- const formContext = /*#__PURE__*/React__namespace.createContext(null);
25
- function useFormContext() {
26
- const formApi = React__namespace.useContext(formContext);
27
- if (!formApi) {
28
- throw new Error("You are trying to use the form API outside of a form!");
29
- }
30
- return formApi;
31
- }
32
-
33
- exports.formContext = formContext;
34
- exports.useFormContext = useFormContext;
35
- //# sourceMappingURL=formContext.legacy.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"formContext.legacy.cjs","sources":["../../src/formContext.ts"],"sourcesContent":["import type { FormApi } from '@tanstack/form-core'\nimport * as React from 'react'\n\nexport const formContext = React.createContext<{\n formApi: FormApi<any>\n parentFieldName?: string\n} | null>(null!)\n\nexport function useFormContext() {\n const formApi = React.useContext(formContext)\n\n if (!formApi) {\n throw new Error(`You are trying to use the form API outside of a form!`)\n }\n\n return formApi\n}\n"],"names":["formContext","React","createContext","useFormContext","formApi","useContext","Error"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAGO,MAAMA,WAAW,gBAAGC,gBAAK,CAACC,aAAa,CAGpC,IAAK,EAAC;AAET,SAASC,cAAcA,GAAG;AAC/B,EAAA,MAAMC,OAAO,GAAGH,gBAAK,CAACI,UAAU,CAACL,WAAW,CAAC,CAAA;EAE7C,IAAI,CAACI,OAAO,EAAE;IACZ,MAAM,IAAIE,KAAK,CAAA,uDAAwD,CAAC,CAAA;AAC1E,GAAA;AAEA,EAAA,OAAOF,OAAO,CAAA;AAChB;;;;;"}