@whatsaaaa/form-builder-affects 0.0.0 → 0.1.1

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Whatsaaaa
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,79 @@
1
+ # @whatsaaaa/form-builder-affects
2
+
3
+ Show, hide and clear the fields, sections and steps of JSON form definitions by conditions.
4
+
5
+ [![npm version](https://img.shields.io/npm/v/@whatsaaaa/form-builder-affects)](https://www.npmjs.com/package/@whatsaaaa/form-builder-affects)
6
+ [![npm downloads](https://img.shields.io/npm/dm/@whatsaaaa/form-builder-affects)](https://www.npmjs.com/package/@whatsaaaa/form-builder-affects)
7
+ [![CI](https://img.shields.io/github/actions/workflow/status/whatsaaaa/form-builder/ci.yml?branch=main&label=CI)](https://github.com/whatsaaaa/form-builder/actions/workflows/ci.yml)
8
+ [![Coverage](https://codecov.io/gh/whatsaaaa/form-builder/graph/badge.svg?flag=affects)](https://codecov.io/gh/whatsaaaa/form-builder)
9
+ [![Bundle size](https://deno.bundlejs.com/badge?q=@whatsaaaa/form-builder-affects&treeshake=%5B%7Baffects%7D%5D&config=%7B%22esbuild%22:%7B%22external%22:%5B%22valibot%22,%22@whatsaaaa/form-builder-schema%22%5D%7D%7D)](https://bundlejs.com/?q=@whatsaaaa/form-builder-affects&treeshake=%5B%7Baffects%7D%5D&config=%7B%22esbuild%22:%7B%22external%22:%5B%22valibot%22,%22@whatsaaaa/form-builder-schema%22%5D%7D%7D)
10
+ [![Types](https://img.shields.io/npm/types/@whatsaaaa/form-builder-affects)](https://www.npmjs.com/package/@whatsaaaa/form-builder-affects)
11
+ [![License](https://img.shields.io/npm/l/@whatsaaaa/form-builder-affects)](https://github.com/whatsaaaa/form-builder/blob/main/LICENSE)
12
+
13
+ This package is an extension for [`@whatsaaaa/form-builder-schema`](https://github.com/whatsaaaa/form-builder/tree/main/packages/schema). It adds `affects` to definitions: conditions on the values of other fields that show a field, hide it, or hide it and clear its value. A hidden field isn't validated, in every Formisch package and in a plain `v.parse`.
14
+
15
+ ## Install
16
+
17
+ ```sh
18
+ pnpm add @whatsaaaa/form-builder-affects @whatsaaaa/form-builder-schema valibot
19
+ ```
20
+
21
+ ## Example
22
+
23
+ Give the schema builder the extension, and write `affects` on the fields:
24
+
25
+ ```ts
26
+ import { affects } from '@whatsaaaa/form-builder-affects'
27
+ import { createSchemaBuilder, type JsonForm } from '@whatsaaaa/form-builder-schema'
28
+
29
+ const builder = createSchemaBuilder({ extensions: [affects()] })
30
+
31
+ const json: JsonForm = {
32
+ version: '1',
33
+ fields: [
34
+ {
35
+ name: 'accountType',
36
+ type: 'radio',
37
+ required: true,
38
+ options: [
39
+ { value: 'personal', label: 'Personal' },
40
+ { value: 'business', label: 'Business' },
41
+ ],
42
+ },
43
+ {
44
+ name: 'vatId',
45
+ type: 'text',
46
+ required: true,
47
+ affects: [{ effect: 'hideAndClear', when: { field: 'accountType', notEquals: 'business' } }],
48
+ },
49
+ ],
50
+ }
51
+
52
+ const schema = builder.build(json) // vatId is required only for a business account
53
+ ```
54
+
55
+ With the Vue or React adapter, pass the builder to `useJsonForm`, and hidden fields, sections and steps leave the form. Without the extension, `affects` is an unknown key, so a definition never runs without its conditions by mistake.
56
+
57
+ ## Highlights
58
+
59
+ - Three effects: `show`, `hide`, and `hideAndClear`, which also blanks the value
60
+ - Conditions on any field by its path, combined with `all` and `any`
61
+ - Works on fields at any depth, display elements, and the layout's sections and steps
62
+ - Hidden fields skip validation, so a required field only counts while it shows
63
+ - Checks every condition against the fields it reads, and reports loops
64
+ - `getVisibility` tells a renderer in any framework what to hide and clear
65
+ - Ships a `definition.schema.json` with `affects` for editor autocompletion
66
+
67
+ ## Documentation
68
+
69
+ The [guide](https://github.com/whatsaaaa/form-builder/blob/main/packages/affects/docs/guide.md) covers effects, conditions and their operators, what a hidden field does, groups, sections and steps, loops, checks, rendering and TypeScript.
70
+
71
+ ## Related packages
72
+
73
+ - [`@whatsaaaa/form-builder-schema`](https://github.com/whatsaaaa/form-builder/tree/main/packages/schema): build Formisch-ready Valibot schemas from JSON definitions
74
+ - [`@whatsaaaa/form-builder-vue`](https://github.com/whatsaaaa/form-builder/tree/main/frameworks/vue): render definitions with your own Vue components
75
+ - [`@whatsaaaa/form-builder-react`](https://github.com/whatsaaaa/form-builder/tree/main/frameworks/react): render definitions with your own React components
76
+
77
+ ## License
78
+
79
+ [MIT](https://github.com/whatsaaaa/form-builder/blob/main/LICENSE)