@formdef/core 0.1.0 → 0.1.2

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/README.md CHANGED
@@ -1,10 +1,34 @@
1
+ <a href="https://formdef.mauricereim.de"><img src="https://formdef.mauricereim.de/brand/banner-light.png" alt="formdef. Describe a form once. Render it as a React component." width="100%" /></a>
2
+
1
3
  # @formdef/core
2
4
 
3
5
  Describe a form once as a typed object, render it as a React component — with the compiler
4
- checking that every widget fits the value it receives.
6
+ checking that every widget fits the value it receives. Built on
7
+ [TanStack Form](https://tanstack.com/form).
8
+
9
+ `createForm` comes from the registry that names your widgets, which
10
+ [Getting started](https://formdef.mauricereim.de/getting-started) sets up:
11
+
12
+ ```tsx
13
+ export const SignIn = createForm({
14
+ schema: z.object({ email: z.email(), remember: z.boolean() }),
15
+ defaultValues: { email: '', remember: false },
16
+ fields: {
17
+ email: { widget: 'text', props: { label: 'Email' } },
18
+ remember: { widget: 'checkbox', props: { label: 'Remember me' } },
19
+ },
20
+ })
21
+ ```
22
+
23
+ ## Installation
5
24
 
6
- Built on [TanStack Form](https://tanstack.com/form). Not released yet; see the
7
- [repository](https://github.com/maurice-rm/formdef) for the current state.
25
+ ```bash
26
+ npm install @formdef/core @tanstack/react-form zod
27
+ ```
28
+
29
+ Zod stands for any schema library that implements [Standard Schema](https://standardschema.dev).
30
+ The widgets for shadcn/ui come from formdef's shadcn registry; the
31
+ [installation guide](https://formdef.mauricereim.de/installation) shows how to add it.
8
32
 
9
33
  ## Requirements
10
34
 
@@ -13,6 +37,11 @@ Built on [TanStack Form](https://tanstack.com/form). Not released yet; see the
13
37
  - TypeScript 5.4 or later
14
38
  - Node 22 or later
15
39
 
40
+ ## Documentation
41
+
42
+ [formdef.mauricereim.de](https://formdef.mauricereim.de), starting with
43
+ [Getting started](https://formdef.mauricereim.de/getting-started).
44
+
16
45
  ## License
17
46
 
18
47
  [MIT](https://github.com/maurice-rm/formdef/blob/main/LICENSE)
package/dist/index.d.cts CHANGED
@@ -338,15 +338,16 @@ type ConfigParts = {
338
338
  formComponents: object;
339
339
  handle: unknown;
340
340
  };
341
- type NamesIn<TEntry> = TEntry extends string ? TEntry : TEntry extends {
341
+ type NamesInEntries<TEntries, TSeen> = [TEntries] extends [TSeen] ? never : NamesIn<TEntries, TSeen | TEntries>;
342
+ type NamesIn<TEntry, TSeen> = TEntry extends string ? TEntry : TEntry extends {
342
343
  layout: readonly (infer TNested)[];
343
- } ? NamesIn<TNested> : TEntry extends {
344
+ } ? NamesInEntries<TNested, TSeen> : TEntry extends {
344
345
  row: readonly (infer TNested)[];
345
- } ? NamesIn<TNested> : never;
346
+ } ? NamesInEntries<TNested, TSeen> : never;
346
347
  type UndescribedNames<TConfig> = TConfig extends {
347
348
  layout: readonly (infer TEntry)[];
348
349
  fields: infer TFields;
349
- } ? Exclude<NamesIn<TEntry>, keyof TFields> : never;
350
+ } ? Exclude<NamesInEntries<TEntry, never>, keyof TFields> : never;
350
351
  type UndescribedName<TName extends string> = `formdef: the layout names "${TName}", which fields does not describe`;
351
352
  /**
352
353
  * Checks the root `layout` of a config written as `TConfig`, sections and rows included: a name
@@ -636,7 +637,7 @@ type FieldsForm = {
636
637
  };
637
638
  type ValuesOf<TForm extends FieldsForm> = TForm["state"]["values"];
638
639
  type FieldsParts<TWidgets, TFormComponents, TStructure, TForm> = OwnParts<TWidgets, TFormComponents, TStructure> & {
639
- handle: TForm;
640
+ handle: NoInfer<TForm>;
640
641
  };
641
642
  /**
642
643
  * What {@link createRegistry} returns: TanStack's form hook for the registered widgets and form
package/dist/index.d.ts CHANGED
@@ -338,15 +338,16 @@ type ConfigParts = {
338
338
  formComponents: object;
339
339
  handle: unknown;
340
340
  };
341
- type NamesIn<TEntry> = TEntry extends string ? TEntry : TEntry extends {
341
+ type NamesInEntries<TEntries, TSeen> = [TEntries] extends [TSeen] ? never : NamesIn<TEntries, TSeen | TEntries>;
342
+ type NamesIn<TEntry, TSeen> = TEntry extends string ? TEntry : TEntry extends {
342
343
  layout: readonly (infer TNested)[];
343
- } ? NamesIn<TNested> : TEntry extends {
344
+ } ? NamesInEntries<TNested, TSeen> : TEntry extends {
344
345
  row: readonly (infer TNested)[];
345
- } ? NamesIn<TNested> : never;
346
+ } ? NamesInEntries<TNested, TSeen> : never;
346
347
  type UndescribedNames<TConfig> = TConfig extends {
347
348
  layout: readonly (infer TEntry)[];
348
349
  fields: infer TFields;
349
- } ? Exclude<NamesIn<TEntry>, keyof TFields> : never;
350
+ } ? Exclude<NamesInEntries<TEntry, never>, keyof TFields> : never;
350
351
  type UndescribedName<TName extends string> = `formdef: the layout names "${TName}", which fields does not describe`;
351
352
  /**
352
353
  * Checks the root `layout` of a config written as `TConfig`, sections and rows included: a name
@@ -636,7 +637,7 @@ type FieldsForm = {
636
637
  };
637
638
  type ValuesOf<TForm extends FieldsForm> = TForm["state"]["values"];
638
639
  type FieldsParts<TWidgets, TFormComponents, TStructure, TForm> = OwnParts<TWidgets, TFormComponents, TStructure> & {
639
- handle: TForm;
640
+ handle: NoInfer<TForm>;
640
641
  };
641
642
  /**
642
643
  * What {@link createRegistry} returns: TanStack's form hook for the registered widgets and form
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@formdef/core",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "Describe a form once as a typed object, render it as a React component, with the compiler checking that every widget fits its value. Built on TanStack Form.",
5
5
  "keywords": [
6
6
  "react",
@@ -14,7 +14,7 @@
14
14
  ],
15
15
  "license": "MIT",
16
16
  "author": "Maurice Reim",
17
- "homepage": "https://github.com/maurice-rm/formdef#readme",
17
+ "homepage": "https://formdef.mauricereim.de",
18
18
  "repository": {
19
19
  "type": "git",
20
20
  "url": "git+https://github.com/maurice-rm/formdef.git",