notform 2.2.4 → 3.0.0-alpha.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 +77 -67
- package/dist/index.d.ts +402 -413
- package/dist/index.js +719 -644
- package/package.json +14 -13
package/README.md
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
<
|
|
2
|
-
<
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
<
|
|
6
|
-
<a href="https://
|
|
7
|
-
<a href="https://
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img alt="header" src="https://shieldcn.dev/header/surface.svg?title=NotForm%28Core%29&subtitle=Headless%2C+schema-agnostic+form+management+for+Vue+3&logo=https%3A%2F%2Fnotformdocs.vercel.app%2Ffavicon.svg&size=wide&mode=dark&font=fira-code" />
|
|
3
|
+
</p>
|
|
4
|
+
|
|
5
|
+
<p align="center">
|
|
6
|
+
<a href="https://www.npmjs.com/package/notform"><img alt="version" src="https://shieldcn.dev/npm/notform.svg?variant=secondary&size=xs&font=fira-code&label=Version" /></a>
|
|
7
|
+
<a href="https://www.npmjs.com/package/notform"><img alt="downloads" src="https://shieldcn.dev/npm/dm/notform.svg?variant=secondary&size=xs&font=fira-code&label=Downloads" /></a>
|
|
8
|
+
<a href="https://www.npmjs.com/package/notform"><img alt="Custom badge" src="https://shieldcn.dev/bundlephobia/min/notform.svg?variant=secondary&size=xs&font=fira-code&label=Unpacked+Size" /></a>
|
|
8
9
|
</p>
|
|
9
|
-
</div>
|
|
10
10
|
|
|
11
11
|
`notform` is the core NotForm package for Vue 3.
|
|
12
12
|
|
|
@@ -26,6 +26,8 @@ pnpm add zod
|
|
|
26
26
|
|
|
27
27
|
## Basic Usage
|
|
28
28
|
|
|
29
|
+
### Single Fields
|
|
30
|
+
|
|
29
31
|
```vue
|
|
30
32
|
<script setup lang="ts">
|
|
31
33
|
import { NotField, NotForm, NotMessage, useNotForm } from 'notform'
|
|
@@ -51,7 +53,7 @@ const form = useNotForm({
|
|
|
51
53
|
<template>
|
|
52
54
|
<NotForm
|
|
53
55
|
:form="form"
|
|
54
|
-
@submit
|
|
56
|
+
@submit="form.submit"
|
|
55
57
|
@reset="form.reset()"
|
|
56
58
|
>
|
|
57
59
|
<NotField
|
|
@@ -105,62 +107,81 @@ const form = useNotForm({
|
|
|
105
107
|
</template>
|
|
106
108
|
```
|
|
107
109
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
The core package exports:
|
|
111
|
-
|
|
112
|
-
- `useNotForm`
|
|
113
|
-
- `NotForm`
|
|
114
|
-
- `NotField`
|
|
115
|
-
- `NotMessage`
|
|
116
|
-
- `NotArrayField`
|
|
117
|
-
|
|
118
|
-
The form instance manages values, errors, touched and dirty state, validation, submission state, and reset behavior.
|
|
119
|
-
|
|
120
|
-
## Array Fields
|
|
110
|
+
### Array Fields
|
|
121
111
|
|
|
122
112
|
`NotArrayField` provides renderless operations for dynamic arrays while preserving stable item keys during reordering.
|
|
123
113
|
|
|
124
114
|
```vue
|
|
125
|
-
<
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
>
|
|
129
|
-
<div
|
|
130
|
-
v-for="(item, index) in items"
|
|
131
|
-
:key="item.key"
|
|
132
|
-
>
|
|
133
|
-
<NotField :path="item.path" v-slot="{ events, path }">
|
|
134
|
-
<label :for="path">Tag {{ index + 1 }}</label>
|
|
135
|
-
<input
|
|
136
|
-
:id="path"
|
|
137
|
-
v-model="form.values.tags[index]"
|
|
138
|
-
v-bind="events"
|
|
139
|
-
:name="path"
|
|
140
|
-
type="text"
|
|
141
|
-
>
|
|
142
|
-
<NotMessage :path="path" />
|
|
143
|
-
</NotField>
|
|
115
|
+
<script setup lang="ts">
|
|
116
|
+
import { NotArrayField, NotField, NotForm, NotMessage, useNotForm } from 'notform'
|
|
117
|
+
import { z } from 'zod'
|
|
144
118
|
|
|
145
|
-
|
|
146
|
-
Remove
|
|
147
|
-
</button>
|
|
148
|
-
</div>
|
|
119
|
+
const tagSchema = z.string()
|
|
149
120
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
</NotArrayField>
|
|
154
|
-
```
|
|
121
|
+
const schema = z.object({
|
|
122
|
+
tags: z.array(tagSchema).optional(),
|
|
123
|
+
})
|
|
155
124
|
|
|
156
|
-
|
|
125
|
+
const form = useNotForm({
|
|
126
|
+
initialValues: {
|
|
127
|
+
tags: [''],
|
|
128
|
+
},
|
|
129
|
+
onSubmit(values) {
|
|
130
|
+
console.log('Submitted:', values)
|
|
131
|
+
},
|
|
132
|
+
schema,
|
|
133
|
+
})
|
|
134
|
+
</script>
|
|
157
135
|
|
|
158
|
-
|
|
136
|
+
<template>
|
|
137
|
+
<NotForm
|
|
138
|
+
:form="form"
|
|
139
|
+
@submit="form.submit"
|
|
140
|
+
@reset="form.reset()"
|
|
141
|
+
>
|
|
142
|
+
<NotArrayField
|
|
143
|
+
v-slot="{ items, append, remove }"
|
|
144
|
+
path="tags"
|
|
145
|
+
:item-schema="tagSchema"
|
|
146
|
+
>
|
|
147
|
+
<div
|
|
148
|
+
v-for="(item, index) in items"
|
|
149
|
+
:key="item.key"
|
|
150
|
+
>
|
|
151
|
+
<NotField
|
|
152
|
+
v-slot="{ events, path }"
|
|
153
|
+
:path="item.path"
|
|
154
|
+
>
|
|
155
|
+
<label :for="path">Tag {{ index + 1 }}</label>
|
|
156
|
+
|
|
157
|
+
<input
|
|
158
|
+
:id="path"
|
|
159
|
+
v-model="form.values.tags[index]"
|
|
160
|
+
v-bind="events"
|
|
161
|
+
:name="path"
|
|
162
|
+
type="text"
|
|
163
|
+
>
|
|
164
|
+
|
|
165
|
+
<NotMessage :path="path" />
|
|
166
|
+
</NotField>
|
|
167
|
+
|
|
168
|
+
<button
|
|
169
|
+
type="button"
|
|
170
|
+
@click="remove(index)"
|
|
171
|
+
>
|
|
172
|
+
Remove
|
|
173
|
+
</button>
|
|
174
|
+
</div>
|
|
159
175
|
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
176
|
+
<button
|
|
177
|
+
type="button"
|
|
178
|
+
@click="append('')"
|
|
179
|
+
>
|
|
180
|
+
Add tag
|
|
181
|
+
</button>
|
|
182
|
+
</NotArrayField>
|
|
183
|
+
</NotForm>
|
|
184
|
+
</template>
|
|
164
185
|
```
|
|
165
186
|
|
|
166
187
|
## Requirements
|
|
@@ -169,17 +190,6 @@ const errors = form.getFieldErrors('email')
|
|
|
169
190
|
- Node.js 24 or later for development in this repository
|
|
170
191
|
- A Standard Schema-compatible validator
|
|
171
192
|
|
|
172
|
-
## Development
|
|
173
|
-
|
|
174
|
-
From the repository root:
|
|
175
|
-
|
|
176
|
-
```bash
|
|
177
|
-
pnpm install
|
|
178
|
-
pnpm --filter notform test
|
|
179
|
-
pnpm --filter notform typecheck
|
|
180
|
-
pnpm --filter notform build
|
|
181
|
-
```
|
|
182
|
-
|
|
183
193
|
## License
|
|
184
194
|
|
|
185
195
|
[MIT](../../LICENSE) © [Favour Emeka](https://github.com/favorodera)
|