autoform-svelte 0.1.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 ADDED
@@ -0,0 +1,100 @@
1
+ # autoform-svelte
2
+
3
+ Schema-first generated forms for Svelte 5 with adapter-based schema support.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ bun install autoform-svelte
9
+ ```
10
+
11
+ If you use Zod schemas:
12
+
13
+ ```bash
14
+ bun install zod
15
+ ```
16
+
17
+ ## Usage
18
+
19
+ ```svelte
20
+ <script lang="ts">
21
+ import { Autoform } from "autoform-svelte";
22
+ import { zodAdapter } from "autoform-svelte/adapters/zod";
23
+ import { z } from "zod";
24
+
25
+ const schema = z.object({
26
+ query: z.string().min(1),
27
+ enabled: z.boolean().default(true),
28
+ });
29
+
30
+ let data = $state({
31
+ query: "",
32
+ enabled: true,
33
+ });
34
+ </script>
35
+
36
+ <Autoform
37
+ {schema}
38
+ adapter={zodAdapter}
39
+ bind:data
40
+ onsubmit={(e) => console.log("submit", e.detail.data)}
41
+ oncancel={() => console.log("cancel")}
42
+ />
43
+ ```
44
+
45
+ ## Adapters
46
+
47
+ - `zodAdapter` from `autoform-svelte/adapters/zod`
48
+ - `jsonSchemaAdapter` (default) from `autoform-svelte`
49
+ - `createCustomAdapter()` for custom libraries
50
+
51
+ ```ts
52
+ import { createCustomAdapter } from "autoform-svelte";
53
+
54
+ const myAdapter = createCustomAdapter((schema) => schema.toJSON());
55
+ ```
56
+
57
+ ## Field metadata
58
+
59
+ Use schema metadata to customize form rendering:
60
+
61
+ ```ts
62
+ z.string().meta({
63
+ form: {
64
+ label: "Message",
65
+ widget: "textarea",
66
+ placeholder: "Write your message",
67
+ },
68
+ });
69
+
70
+ z.object({
71
+ title: z.string(),
72
+ details: z.string(),
73
+ }).meta({
74
+ form: {
75
+ reorderable: true,
76
+ },
77
+ });
78
+ ```
79
+
80
+ Supported keys:
81
+
82
+ - `form.widget`: `"input" | "textarea"` (string fields only, default is `"input"`)
83
+ - `form.label`: field label override
84
+ - `form.placeholder`: placeholder text for supported controls (input/textarea/select/date/number)
85
+ - `form.reorderable`: enable object key reordering controls (default is disabled)
86
+
87
+ ## Component API
88
+
89
+ - `schema`: `unknown` (required)
90
+ - `adapter?`: `SchemaAdapter` (default: `jsonSchemaAdapter`)
91
+ - `data`: `Record<string, any>` (bindable)
92
+ - `title?`: `string`
93
+ - `submitLabel?`: `string` (default: `"Save"`)
94
+ - `cancelLabel?`: `string` (default: `"Cancel"`)
95
+
96
+ ## Events
97
+
98
+ - `submit`: `{ data: Record<string, any> }`
99
+ - `cancel`
100
+ - `error`: `{ errors: string[] }`
package/dist/index.css ADDED
@@ -0,0 +1 @@
1
+ .af-form.svelte-18268fr{display:flex;flex-direction:column;gap:.75rem}.af-title.svelte-18268fr{margin:0;font-size:1rem;font-weight:600}.af-errors.svelte-18268fr{border:1px solid #ef4444;border-radius:.375rem;padding:.625rem;font-size:.75rem;color:#dc2626}.af-actions.svelte-18268fr{display:flex;justify-content:space-between;margin-top:.5rem}.af-btn.svelte-18268fr{border-radius:.375rem;border:1px solid transparent;padding:.375rem .625rem;font-size:.75rem;cursor:pointer}.af-btn.svelte-18268fr:disabled{opacity:.5;cursor:not-allowed}.af-btn-primary.svelte-18268fr{background:#2563eb;color:#fff}.af-btn-secondary.svelte-18268fr{border-color:color-mix(in oklab,currentColor 22%,transparent);background:transparent;color:inherit}.af-label.svelte-yr0bu8{font-size:.875rem;font-weight:500}.af-help.svelte-yr0bu8{margin:0;font-size:.75rem;color:color-mix(in oklab,currentColor 60%,transparent)}.af-input.svelte-yr0bu8{width:100%;border:1px solid color-mix(in oklab,currentColor 22%,transparent);border-radius:.375rem;padding:.5rem .625rem;background:transparent;box-sizing:border-box}.af-label.svelte-1cde0jg{font-size:.875rem;font-weight:500}.af-help.svelte-1cde0jg{margin:0;font-size:.75rem;color:color-mix(in oklab,currentColor 60%,transparent)}.af-input.svelte-1cde0jg{width:100%;border:1px solid color-mix(in oklab,currentColor 22%,transparent);border-radius:.375rem;padding:.5rem .625rem;background:transparent;box-sizing:border-box}.af-checkbox-row.svelte-1onbcyh{display:inline-flex;align-items:center;gap:.5rem;font-size:.875rem}.af-help.svelte-1onbcyh{margin:0;font-size:.75rem;color:color-mix(in oklab,currentColor 60%,transparent)}.af-label.svelte-6rq2q9{font-size:.875rem;font-weight:500}.af-help.svelte-6rq2q9{margin:0;font-size:.75rem;color:color-mix(in oklab,currentColor 60%,transparent)}.af-input.svelte-6rq2q9{width:100%;border:1px solid color-mix(in oklab,currentColor 22%,transparent);border-radius:.375rem;padding:.5rem .625rem;background:transparent;box-sizing:border-box}.af-label.svelte-5p4vbg{font-size:.875rem;font-weight:500}.af-help.svelte-5p4vbg{margin:0;font-size:.75rem;color:color-mix(in oklab,currentColor 60%,transparent)}.af-input.svelte-5p4vbg{width:100%;border:1px solid color-mix(in oklab,currentColor 22%,transparent);border-radius:.375rem;padding:.5rem .625rem;background:transparent;box-sizing:border-box}.af-label.svelte-1c6lbe6{font-size:.875rem;font-weight:500}.af-label-row.svelte-1c6lbe6{display:flex;align-items:center;justify-content:space-between;gap:.5rem}.af-help.svelte-1c6lbe6{margin:0;font-size:.75rem;color:color-mix(in oklab,currentColor 60%,transparent)}.af-input.svelte-1c6lbe6{width:100%;border:1px solid color-mix(in oklab,currentColor 22%,transparent);border-radius:.375rem;padding:.5rem .625rem;background:transparent;box-sizing:border-box}.af-nested.svelte-1c6lbe6{border-left:2px solid color-mix(in oklab,currentColor 18%,transparent);padding-left:.75rem;margin:.5rem 0}.af-move-row.svelte-1c6lbe6{display:flex;align-items:center;gap:.375rem;margin-bottom:.375rem}.af-btn.svelte-1c6lbe6{border-radius:.375rem;border:1px solid transparent;padding:.375rem .625rem;font-size:.75rem;cursor:pointer}.af-btn.svelte-1c6lbe6:disabled{opacity:.5;cursor:not-allowed}.af-btn-secondary.svelte-1c6lbe6{border-color:color-mix(in oklab,currentColor 22%,transparent);background:transparent;color:inherit}.af-btn-danger.svelte-1c6lbe6{border-color:#dc2626;color:#dc2626;background:transparent}.af-label.svelte-zpgw7y{font-size:.875rem;font-weight:500}.af-label-row.svelte-zpgw7y{display:flex;align-items:center;justify-content:space-between;gap:.5rem}.af-help.svelte-zpgw7y{margin:0;font-size:.75rem;color:color-mix(in oklab,currentColor 60%,transparent)}.af-nested.svelte-zpgw7y{border-left:2px solid color-mix(in oklab,currentColor 18%,transparent);padding-left:.75rem;margin:.5rem 0}.af-move-row.svelte-zpgw7y{display:flex;align-items:center;gap:.375rem;margin-bottom:.375rem}.af-btn.svelte-zpgw7y{border-radius:.375rem;border:1px solid transparent;padding:.375rem .625rem;font-size:.75rem;cursor:pointer}.af-btn.svelte-zpgw7y:disabled{opacity:.5;cursor:not-allowed}.af-btn-secondary.svelte-zpgw7y{border-color:color-mix(in oklab,currentColor 22%,transparent);background:transparent;color:inherit}.af-btn-danger.svelte-zpgw7y{border-color:#dc2626;color:#dc2626;background:transparent}.af-label.svelte-1a7i94f{font-size:.875rem;font-weight:500}.af-help.svelte-1a7i94f{margin:0;font-size:.75rem;color:color-mix(in oklab,currentColor 60%,transparent)}