vanjs-jsf 0.4.0 → 0.5.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.
package/README.md CHANGED
@@ -1,344 +1,350 @@
1
- # VanJS-JSF — a JSON Schema Form Library for VanJS
2
-
3
- **Generate dynamic UI forms effortlessly with TypeScript and JSON Schema, powered by the JSON Schema Form Headless UI framework.**
4
-
5
- ## Description
6
-
7
- This library provides a robust and flexible solution for dynamically generating user interface (UI) forms using JSON Schema definitions. It is built on **TypeScript** for type safety and leverages the powerful [JSON Schema Form Headless UI](https://github.com/remoteoss/json-schema-form) framework, which you can find documented [here](https://json-schema-form.vercel.app). It ensures a lightweight, modern, accessible, and customizable form-building experience.
8
-
9
- ### Features
10
-
11
- - [x] **Dynamic Form Generation**: Create forms directly from JSON Schema, reducing repetitive coding tasks.
12
- - [x] **Theming API**: Inject CSS classes for every form element via a `theme` object — works with Tailwind, Bootstrap, or any CSS framework.
13
- - [x] **Layout Map**: Control per-field spatial distribution (e.g. grid column spans) without coupling CSS classes to JSON Schema.
14
- - [x] **Customizable**: Tailor form styles, layouts, and behaviours to meet specific UI/UX requirements.
15
- - [x] **Headless UI Integration**: Utilize Headless UI's components for accessible and modern interfaces.
16
- - [x] **TypeScript-first Approach**: Enjoy strong typing and enhanced developer experience with TypeScript.
17
- - [x] **Validation Support**: Easily integrate JSON Schema-based validation for seamless user input handling.
18
- - [ ] **Extensible Architecture**: Add custom widgets, field types, and behaviours as needed.
19
-
20
- ### Available components
21
-
22
- The currently supported form element types are:
23
-
24
- - text = "text"
25
- - number = "number"
26
- - textarea = "textarea"
27
- - select = "select"
28
- - radio = "radio"
29
- - date = "date" (Pikaday)
30
- - code = "code" (CodeMirror with JSON, JavaScript, TypeScript support)
31
- - fieldset = "fieldset"
32
- - file = "file" (drag & drop, with configurable `readAs` mode and size validation)
33
-
34
- ## Getting Started
35
-
36
- 1. Install the library:
37
-
38
- ```bash
39
- npm install vanjs-jsf
40
- ```
41
-
42
- 2. Import and define your JSON Schema with `x-jsf-presentation` hints:
43
-
44
- ```typescript
45
- import van from "vanjs-core";
46
- import { jsform } from "vanjs-jsf";
47
-
48
- const { div, h1, p, button } = van.tags;
49
-
50
- const schema = {
51
- type: "object",
52
- properties: {
53
- userName: {
54
- type: "string",
55
- title: "Name",
56
- "x-jsf-presentation": { inputType: "text" },
57
- },
58
- age: {
59
- type: "number",
60
- title: "Age",
61
- "x-jsf-presentation": { inputType: "number" },
62
- },
63
- },
64
- required: ["userName"],
65
- "x-jsf-order": ["userName", "age"],
66
- };
67
- ```
68
-
69
- 3. Create a config with initial values and render the form:
70
-
71
- ```typescript
72
- const initialValues = { userName: "Simon" };
73
- const config = {
74
- strictInputType: false,
75
- initialValues: initialValues,
76
- formValues: initialValues,
77
- };
78
-
79
- const handleOnSubmit = (e: Event) => {
80
- e.preventDefault();
81
- const values = config.formValues;
82
- alert(`Submitted: ${JSON.stringify(values, null, 2)}`);
83
- };
84
-
85
- van.add(
86
- document.body,
87
- div(
88
- h1("json-schema-form + VanJS"),
89
- p("Dynamic form generated from JSON Schema."),
90
- jsform(
91
- {
92
- name: "my-jsf-form",
93
- schema: schema,
94
- config: config,
95
- onsubmit: handleOnSubmit,
96
- },
97
- button({ type: "submit" }, "Submit"),
98
- ),
99
- ),
100
- );
101
- ```
102
-
103
- ## File Upload Field
104
-
105
- The `file` field type renders a drag & drop zone with file info display. Define it in your schema:
106
-
107
- ```typescript
108
- const schema = {
109
- type: "object",
110
- properties: {
111
- document: {
112
- type: "string",
113
- title: "Upload Document",
114
- description: "PDF or image, max 5 MB",
115
- "x-jsf-presentation": {
116
- inputType: "file",
117
- accept: ".pdf,.png,.jpg",
118
- maxSizeMB: 5,
119
- readAs: "auto",
120
- },
121
- },
122
- },
123
- "x-jsf-order": ["document"],
124
- };
125
- ```
126
-
127
- ### `readAs` modes
128
-
129
- | Value | Behaviour |
130
- | ------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------- |
131
- | `"auto"` (default) | Text extensions (json, csv, txt, xml, yaml, md, html, css, js, ts, sql, etc.) are read as text. All other files are read as binary and returned as base64. |
132
- | `"text"` | Always reads the file as text (`readAsText`). |
133
- | `"dataURL"` | Returns a data URL string (`readAsDataURL`). |
134
- | `"arrayBuffer"` | Reads as ArrayBuffer and returns base64 (`readAsArrayBuffer`). |
135
-
136
- The file content is stored in `formValues` under the field name. Additional metadata is stored as `<fieldName>__fileName`, `<fieldName>__fileSize`, and `<fieldName>__fileType`.
137
-
138
- ## Theming
139
-
140
- By default, vanjs-jsf applies minimal semantic CSS classes (e.g. `jsf-dropzone`, `jsf-file-info`). You can import the default styles:
141
-
142
- ```typescript
143
- import "vanjs-jsf/dist/jsf-defaults.css";
144
- ```
145
-
146
- To fully customize the appearance, pass a `theme` object to `jsform()`. Theme classes apply to every element type in the form. Per-field classes defined in `x-jsf-presentation` (e.g. `class`, `titleClass`, `containerClass`) take priority over theme classes.
147
-
148
- ```typescript
149
- import { jsform, JsfTheme } from "vanjs-jsf";
150
-
151
- const myTheme: JsfTheme = {
152
- // Structure
153
- container: "mb-4",
154
- label: "block text-sm font-medium text-gray-700 mb-1",
155
- description: "text-gray-500 text-xs mb-1",
156
- error: "text-red-500 text-xs mt-1",
157
- requiredIndicator: "text-red-500 ml-1",
158
-
159
- // Inputs
160
- input: "w-full border border-gray-300 rounded px-3 py-2",
161
- textarea: "w-full border border-gray-300 rounded px-3 py-2 resize-y",
162
- select: "w-full border border-gray-300 rounded px-3 py-2",
163
- option: "bg-white",
164
-
165
- // Radio
166
- radioGroup: "flex flex-col gap-2",
167
- radioLabel: "flex items-center gap-2 cursor-pointer",
168
- radioInput: "accent-blue-500",
169
-
170
- // Fieldset
171
- fieldset: "border border-gray-200 rounded p-4",
172
- legend: "text-sm font-semibold text-gray-700",
173
-
174
- // File upload
175
- dropZone:
176
- "border-2 border-dashed border-gray-300 rounded-lg p-6 text-center cursor-pointer hover:border-blue-400 transition-colors",
177
- dropZoneActive:
178
- "border-2 border-dashed border-blue-500 rounded-lg p-6 text-center cursor-pointer bg-blue-50",
179
- dropZoneText: "text-gray-500 text-sm m-0",
180
- fileInfoBar: "mt-2 flex items-center gap-2",
181
- fileName: "font-semibold",
182
- fileSize: "text-gray-400 text-sm",
183
- fileClearButton:
184
- "text-sm border border-gray-300 rounded px-2 py-0.5 hover:bg-gray-100",
185
- fileReading: "mt-2 text-gray-400 text-sm",
186
- };
187
-
188
- const formEl = jsform({
189
- schema: mySchema,
190
- config: { initialValues: {}, formValues: {} },
191
- theme: myTheme,
192
- onsubmit: handleSubmit,
193
- });
194
- ```
195
-
196
- ### JsfTheme properties
197
-
198
- | Property | Applies to |
199
- | ------------------- | ------------------------------------------------------ |
200
- | `container` | Wrapper `<div>` of each field |
201
- | `label` | `<label>` elements |
202
- | `description` | Description `<div>` below the label |
203
- | `error` | Error `<p>` below the input |
204
- | `requiredIndicator` | `<span>` with "\*" next to required field labels |
205
- | `input` | `<input>` for text, number, and date fields |
206
- | `textarea` | `<textarea>` elements |
207
- | `select` | `<select>` elements |
208
- | `option` | `<option>` elements inside selects |
209
- | `radioGroup` | Container `<div>` for radio options |
210
- | `radioLabel` | `<label>` wrapping each radio option |
211
- | `radioInput` | `<input type="radio">` elements |
212
- | `fieldset` | `<fieldset>` elements |
213
- | `legend` | `<legend>` elements (falls back to `label` if not set) |
214
- | `dropZone` | File drop zone container (normal state) |
215
- | `dropZoneActive` | File drop zone during dragover |
216
- | `dropZoneText` | Text inside the drop zone |
217
- | `fileInfoBar` | Container for uploaded file info |
218
- | `fileName` | File name `<strong>` |
219
- | `fileSize` | File size `<small>` |
220
- | `fileClearButton` | "Clear" button |
221
- | `fileReading` | "Reading file..." indicator |
222
-
223
- ## Layout
224
-
225
- The `layout` attribute lets you assign extra CSS classes to specific field containers by name, without modifying the JSON Schema. This is useful for controlling column spans in CSS grid layouts.
226
-
227
- ```typescript
228
- import { jsform, JsfTheme, JsfLayout } from "vanjs-jsf";
229
-
230
- const theme: JsfTheme = {
231
- container: "mb-4",
232
- input: "w-full border rounded px-3 py-2",
233
- label: "block text-sm font-medium mb-1",
234
- };
235
-
236
- const layout: JsfLayout = {
237
- host: "col-span-2", // full row
238
- dbname: "col-span-2", // full row
239
- // port, user, password, schema → no entry → default 1 column
240
- };
241
-
242
- const formEl = jsform({
243
- schema: connectionSchema,
244
- config: { initialValues: {}, formValues: {} },
245
- theme,
246
- layout,
247
- });
248
- ```
249
-
250
- Wrap the form in a grid container to activate the column distribution:
251
-
252
- ```css
253
- .jsf-grid > form {
254
- display: grid;
255
- grid-template-columns: 1fr 1fr;
256
- gap: 0 1rem;
257
- }
258
- ```
259
-
260
- ```typescript
261
- const { div } = van.tags;
262
- van.add(document.body, div({ class: "jsf-grid" }, formEl));
263
- ```
264
-
265
- This produces a layout like:
266
-
267
- ```text
268
- ┌─────────────── host ────────────────┐
269
- │ 192.168.1.176 │
270
- ├────── port ──────┬──── user ────────┤
271
- │ 5432 │ wolfops │
272
- ├──── password ────┬──── schema ──────┤
273
- │ •••••••• │ public │
274
- ├─────────────── dbname ──────────────┤
275
- │ wolfops_dev │
276
- └─────────────────────────────────────┘
277
- ```
278
-
279
- ### Nested fields
280
-
281
- For fields inside a fieldset, `layout` supports both the full path and the short name:
282
-
283
- ```typescript
284
- const layout: JsfLayout = {
285
- "connection.host": "col-span-2", // by full path
286
- port: "col-span-1", // by short name (also works for nested)
287
- };
288
- ```
289
-
290
- The full path (`fieldset.fieldName`) is checked first, then the short name.
291
-
292
- ### Class resolution order
293
-
294
- For each element, the resolved class follows this priority:
295
-
296
- 1. **Per-field class** from `x-jsf-presentation` (e.g. `class`, `titleClass`, `containerClass`)
297
- 2. **Theme class** from the `theme` object
298
- 3. **Empty string** (no class applied)
299
-
300
- Layout classes are appended *after* the resolved container class, so they combine with both per-field and theme classes.
301
-
302
- ### Visibility
303
-
304
- Hidden fields receive the `jsf-hidden` CSS class instead of inline `display: none`. Make sure your CSS includes:
305
-
306
- ```css
307
- .jsf-hidden {
308
- display: none;
309
- }
310
- ```
311
-
312
- This is included in `jsf-defaults.css`.
313
-
314
- ## Development
315
-
316
- ```bash
317
- npm install # Install dependencies
318
- npm run dev # Start Vite dev server (port 3030)
319
- npm run build # Bundle with esbuild → dist/index.js
320
- npm run types # Generate type declarations → dist/*.d.ts
321
- npm run lint # Run ESLint
322
- npm run lint:fix # Run ESLint with auto-fix
323
- ```
324
-
325
- ## Publishing
326
-
327
- 1. Update the version in `package.json`
328
- 2. Run the publish script with your npm OTP:
329
-
330
- ```bash
331
- ./publish.sh <otp>
332
- ```
333
-
334
- This cleans `dist/`, rebuilds the bundle and type declarations, copies `jsf-defaults.css` to `dist/`, and publishes to npm.
335
-
336
- The package is available at: https://www.npmjs.com/package/vanjs-jsf
337
-
338
- ## Contributing
339
-
340
- Contributions are welcome! Please submit a pull request if you have ideas, feedback, or improvements. Your contributions will help make this library more robust and useful for the community.
341
-
342
- ## License
343
-
344
- This project is licensed under the Apache 2 License. For details, see the [LICENSE](./LICENSE) file.
1
+ # VanJS-JSF — a JSON Schema Form Library for VanJS
2
+
3
+ **Generate dynamic UI forms effortlessly with TypeScript and JSON Schema, powered by the JSON Schema Form Headless UI framework.**
4
+
5
+ ## Description
6
+
7
+ This library provides a robust and flexible solution for dynamically generating user interface (UI) forms using JSON Schema definitions. It is built on **TypeScript** for type safety and leverages the powerful [JSON Schema Form Headless UI](https://github.com/remoteoss/json-schema-form) framework, which you can find documented [here](https://json-schema-form.vercel.app). It ensures a lightweight, modern, accessible, and customizable form-building experience.
8
+
9
+ ### Features
10
+
11
+ - [x] **Dynamic Form Generation**: Create forms directly from JSON Schema, reducing repetitive coding tasks.
12
+ - [x] **Theming API**: Inject CSS classes for every form element via a `theme` object — works with Tailwind, Bootstrap, or any CSS framework.
13
+ - [x] **Layout Map**: Control per-field spatial distribution (e.g. grid column spans) without coupling CSS classes to JSON Schema.
14
+ - [x] **Customizable**: Tailor form styles, layouts, and behaviours to meet specific UI/UX requirements.
15
+ - [x] **Headless UI Integration**: Utilize Headless UI's components for accessible and modern interfaces.
16
+ - [x] **TypeScript-first Approach**: Enjoy strong typing and enhanced developer experience with TypeScript.
17
+ - [x] **Validation Support**: Easily integrate JSON Schema-based validation for seamless user input handling.
18
+ - [ ] **Extensible Architecture**: Add custom widgets, field types, and behaviours as needed.
19
+
20
+ ### Available components
21
+
22
+ The currently supported form element types are:
23
+
24
+ - text = "text"
25
+ - number = "number"
26
+ - textarea = "textarea"
27
+ - password = "password"
28
+ - select = "select"
29
+ - radio = "radio"
30
+ - date = "date" (Pikaday)
31
+ - code = "code" (CodeMirror with JSON, JavaScript, TypeScript support)
32
+ - fieldset = "fieldset"
33
+ - file = "file" (drag & drop, with configurable `readAs` mode and size validation)
34
+ - array (repeatable list of scalar items: number/integer/string/boolean, with add/remove controls)
35
+
36
+ ## Getting Started
37
+
38
+ 1. Install the library:
39
+
40
+ ```bash
41
+ npm install vanjs-jsf
42
+ ```
43
+
44
+ 2. Import and define your JSON Schema with `x-jsf-presentation` hints:
45
+
46
+ ```typescript
47
+ import van from "vanjs-core";
48
+ import { jsform } from "vanjs-jsf";
49
+
50
+ const { div, h1, p, button } = van.tags;
51
+
52
+ const schema = {
53
+ type: "object",
54
+ properties: {
55
+ userName: {
56
+ type: "string",
57
+ title: "Name",
58
+ "x-jsf-presentation": { inputType: "text" },
59
+ },
60
+ age: {
61
+ type: "number",
62
+ title: "Age",
63
+ "x-jsf-presentation": { inputType: "number" },
64
+ },
65
+ },
66
+ required: ["userName"],
67
+ "x-jsf-order": ["userName", "age"],
68
+ };
69
+ ```
70
+
71
+ 3. Create a config with initial values and render the form:
72
+
73
+ ```typescript
74
+ const initialValues = { userName: "Simon" };
75
+ const config = {
76
+ strictInputType: false,
77
+ initialValues: initialValues,
78
+ formValues: initialValues,
79
+ };
80
+
81
+ const handleOnSubmit = (e: Event) => {
82
+ e.preventDefault();
83
+ const values = config.formValues;
84
+ alert(`Submitted: ${JSON.stringify(values, null, 2)}`);
85
+ };
86
+
87
+ van.add(
88
+ document.body,
89
+ div(
90
+ h1("json-schema-form + VanJS"),
91
+ p("Dynamic form generated from JSON Schema."),
92
+ jsform(
93
+ {
94
+ name: "my-jsf-form",
95
+ schema: schema,
96
+ config: config,
97
+ onsubmit: handleOnSubmit,
98
+ },
99
+ button({ type: "submit" }, "Submit"),
100
+ ),
101
+ ),
102
+ );
103
+ ```
104
+
105
+ ## File Upload Field
106
+
107
+ The `file` field type renders a drag & drop zone with file info display. Define it in your schema:
108
+
109
+ ```typescript
110
+ const schema = {
111
+ type: "object",
112
+ properties: {
113
+ document: {
114
+ type: "string",
115
+ title: "Upload Document",
116
+ description: "PDF or image, max 5 MB",
117
+ "x-jsf-presentation": {
118
+ inputType: "file",
119
+ accept: ".pdf,.png,.jpg",
120
+ maxSizeMB: 5,
121
+ readAs: "auto",
122
+ },
123
+ },
124
+ },
125
+ "x-jsf-order": ["document"],
126
+ };
127
+ ```
128
+
129
+ ### `readAs` modes
130
+
131
+ | Value | Behaviour |
132
+ | ------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------- |
133
+ | `"auto"` (default) | Text extensions (json, csv, txt, xml, yaml, md, html, css, js, ts, sql, etc.) are read as text. All other files are read as binary and returned as base64. |
134
+ | `"text"` | Always reads the file as text (`readAsText`). |
135
+ | `"dataURL"` | Returns a data URL string (`readAsDataURL`). |
136
+ | `"arrayBuffer"` | Reads as ArrayBuffer and returns base64 (`readAsArrayBuffer`). |
137
+
138
+ The file content is stored in `formValues` under the field name. Additional metadata is stored as `<fieldName>__fileName`, `<fieldName>__fileSize`, and `<fieldName>__fileType`.
139
+
140
+ ## Theming
141
+
142
+ By default, vanjs-jsf applies minimal semantic CSS classes (e.g. `jsf-dropzone`, `jsf-file-info`). You can import the default styles:
143
+
144
+ ```typescript
145
+ import "vanjs-jsf/dist/jsf-defaults.css";
146
+ ```
147
+
148
+ To fully customize the appearance, pass a `theme` object to `jsform()`. Theme classes apply to every element type in the form. Per-field classes defined in `x-jsf-presentation` (e.g. `class`, `titleClass`, `containerClass`) take priority over theme classes.
149
+
150
+ ```typescript
151
+ import { jsform, JsfTheme } from "vanjs-jsf";
152
+
153
+ const myTheme: JsfTheme = {
154
+ // Structure
155
+ container: "mb-4",
156
+ label: "block text-sm font-medium text-gray-700 mb-1",
157
+ description: "text-gray-500 text-xs mb-1",
158
+ error: "text-red-500 text-xs mt-1",
159
+ requiredIndicator: "text-red-500 ml-1",
160
+
161
+ // Inputs
162
+ input: "w-full border border-gray-300 rounded px-3 py-2",
163
+ textarea: "w-full border border-gray-300 rounded px-3 py-2 resize-y",
164
+ select: "w-full border border-gray-300 rounded px-3 py-2",
165
+ option: "bg-white",
166
+
167
+ // Radio
168
+ radioGroup: "flex flex-col gap-2",
169
+ radioLabel: "flex items-center gap-2 cursor-pointer",
170
+ radioInput: "accent-blue-500",
171
+
172
+ // Fieldset
173
+ fieldset: "border border-gray-200 rounded p-4",
174
+ legend: "text-sm font-semibold text-gray-700",
175
+
176
+ // File upload
177
+ dropZone:
178
+ "border-2 border-dashed border-gray-300 rounded-lg p-6 text-center cursor-pointer hover:border-blue-400 transition-colors",
179
+ dropZoneActive:
180
+ "border-2 border-dashed border-blue-500 rounded-lg p-6 text-center cursor-pointer bg-blue-50",
181
+ dropZoneText: "text-gray-500 text-sm m-0",
182
+ fileInfoBar: "mt-2 flex items-center gap-2",
183
+ fileName: "font-semibold",
184
+ fileSize: "text-gray-400 text-sm",
185
+ fileClearButton:
186
+ "text-sm border border-gray-300 rounded px-2 py-0.5 hover:bg-gray-100",
187
+ fileReading: "mt-2 text-gray-400 text-sm",
188
+ };
189
+
190
+ const formEl = jsform({
191
+ schema: mySchema,
192
+ config: { initialValues: {}, formValues: {} },
193
+ theme: myTheme,
194
+ onsubmit: handleSubmit,
195
+ });
196
+ ```
197
+
198
+ ### JsfTheme properties
199
+
200
+ | Property | Applies to |
201
+ | ------------------- | ------------------------------------------------------ |
202
+ | `container` | Wrapper `<div>` of each field |
203
+ | `label` | `<label>` elements |
204
+ | `description` | Description `<div>` below the label |
205
+ | `error` | Error `<p>` below the input |
206
+ | `requiredIndicator` | `<span>` with "\*" next to required field labels |
207
+ | `input` | `<input>` for text, number, and date fields |
208
+ | `textarea` | `<textarea>` elements |
209
+ | `select` | `<select>` elements |
210
+ | `option` | `<option>` elements inside selects |
211
+ | `radioGroup` | Container `<div>` for radio options |
212
+ | `radioLabel` | `<label>` wrapping each radio option |
213
+ | `radioInput` | `<input type="radio">` elements |
214
+ | `fieldset` | `<fieldset>` elements |
215
+ | `legend` | `<legend>` elements (falls back to `label` if not set) |
216
+ | `arrayItems` | Container `<div>` wrapping the list of array items |
217
+ | `arrayRow` | `<div>` wrapping each array item (input + remove) |
218
+ | `arrayAddButton` | "Add" button to append a new array item |
219
+ | `arrayRemoveButton` | "Remove" button next to each array item |
220
+ | `dropZone` | File drop zone container (normal state) |
221
+ | `dropZoneActive` | File drop zone during dragover |
222
+ | `dropZoneText` | Text inside the drop zone |
223
+ | `fileInfoBar` | Container for uploaded file info |
224
+ | `fileName` | File name `<strong>` |
225
+ | `fileSize` | File size `<small>` |
226
+ | `fileClearButton` | "Clear" button |
227
+ | `fileReading` | "Reading file..." indicator |
228
+
229
+ ## Layout
230
+
231
+ The `layout` attribute lets you assign extra CSS classes to specific field containers by name, without modifying the JSON Schema. This is useful for controlling column spans in CSS grid layouts.
232
+
233
+ ```typescript
234
+ import { jsform, JsfTheme, JsfLayout } from "vanjs-jsf";
235
+
236
+ const theme: JsfTheme = {
237
+ container: "mb-4",
238
+ input: "w-full border rounded px-3 py-2",
239
+ label: "block text-sm font-medium mb-1",
240
+ };
241
+
242
+ const layout: JsfLayout = {
243
+ host: "col-span-2", // full row
244
+ dbname: "col-span-2", // full row
245
+ // port, user, password, schema → no entry → default 1 column
246
+ };
247
+
248
+ const formEl = jsform({
249
+ schema: connectionSchema,
250
+ config: { initialValues: {}, formValues: {} },
251
+ theme,
252
+ layout,
253
+ });
254
+ ```
255
+
256
+ Wrap the form in a grid container to activate the column distribution:
257
+
258
+ ```css
259
+ .jsf-grid > form {
260
+ display: grid;
261
+ grid-template-columns: 1fr 1fr;
262
+ gap: 0 1rem;
263
+ }
264
+ ```
265
+
266
+ ```typescript
267
+ const { div } = van.tags;
268
+ van.add(document.body, div({ class: "jsf-grid" }, formEl));
269
+ ```
270
+
271
+ This produces a layout like:
272
+
273
+ ```text
274
+ ┌─────────────── host ────────────────┐
275
+ │ 192.168.1.176 │
276
+ ├────── port ──────┬──── user ────────┤
277
+ │ 5432 │ wolfops │
278
+ ├──── password ────┬──── schema ──────┤
279
+ │ •••••••• │ public │
280
+ ├─────────────── dbname ──────────────┤
281
+ │ wolfops_dev │
282
+ └─────────────────────────────────────┘
283
+ ```
284
+
285
+ ### Nested fields
286
+
287
+ For fields inside a fieldset, `layout` supports both the full path and the short name:
288
+
289
+ ```typescript
290
+ const layout: JsfLayout = {
291
+ "connection.host": "col-span-2", // by full path
292
+ port: "col-span-1", // by short name (also works for nested)
293
+ };
294
+ ```
295
+
296
+ The full path (`fieldset.fieldName`) is checked first, then the short name.
297
+
298
+ ### Class resolution order
299
+
300
+ For each element, the resolved class follows this priority:
301
+
302
+ 1. **Per-field class** from `x-jsf-presentation` (e.g. `class`, `titleClass`, `containerClass`)
303
+ 2. **Theme class** from the `theme` object
304
+ 3. **Empty string** (no class applied)
305
+
306
+ Layout classes are appended *after* the resolved container class, so they combine with both per-field and theme classes.
307
+
308
+ ### Visibility
309
+
310
+ Hidden fields receive the `jsf-hidden` CSS class instead of inline `display: none`. Make sure your CSS includes:
311
+
312
+ ```css
313
+ .jsf-hidden {
314
+ display: none;
315
+ }
316
+ ```
317
+
318
+ This is included in `jsf-defaults.css`.
319
+
320
+ ## Development
321
+
322
+ ```bash
323
+ npm install # Install dependencies
324
+ npm run dev # Start Vite dev server (port 3030)
325
+ npm run build # Bundle with esbuild → dist/index.js
326
+ npm run types # Generate type declarations → dist/*.d.ts
327
+ npm run lint # Run ESLint
328
+ npm run lint:fix # Run ESLint with auto-fix
329
+ ```
330
+
331
+ ## Publishing
332
+
333
+ 1. Update the version in `package.json`
334
+ 2. Run the publish script with your npm OTP:
335
+
336
+ ```bash
337
+ ./publish.sh <otp>
338
+ ```
339
+
340
+ This cleans `dist/`, rebuilds the bundle and type declarations, copies `jsf-defaults.css` to `dist/`, and publishes to npm.
341
+
342
+ The package is available at: https://www.npmjs.com/package/vanjs-jsf
343
+
344
+ ## Contributing
345
+
346
+ Contributions are welcome! Please submit a pull request if you have ideas, feedback, or improvements. Your contributions will help make this library more robust and useful for the community.
347
+
348
+ ## License
349
+
350
+ This project is licensed under the Apache 2 License. For details, see the [LICENSE](./LICENSE) file.