@formvk/schema 0.0.0-stage → 1.0.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/CHANGELOG.md +14 -0
- package/README.md +65 -2
- package/dist/index.d.ts +778 -0
- package/dist/index.js +1034 -0
- package/dist/index.js.map +1 -0
- package/package.json +27 -3
package/CHANGELOG.md
ADDED
package/README.md
CHANGED
|
@@ -1,3 +1,66 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @formvk/schema
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Schema-first layer for Formvk. `createFragment` turns registered components into typed schema constructors, `createSchema` assembles a typed object schema, and `{{ ... }}` expressions are compiled into reactive field state when the schema is rendered by `@formvk/react` or `@formvk/vue`.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm add @formvk/schema
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import { createFragment, createSchema } from '@formvk/schema'
|
|
15
|
+
|
|
16
|
+
const f = createFragment()
|
|
17
|
+
|
|
18
|
+
export const schema = createSchema({
|
|
19
|
+
username: f.Field({ title: 'Username', component: 'Input', required: true }),
|
|
20
|
+
tags: f.Array(f.Field({ component: 'Input' })),
|
|
21
|
+
})
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Register component props to get full type inference for `componentProps`:
|
|
25
|
+
|
|
26
|
+
```ts
|
|
27
|
+
const f = createFragment<{
|
|
28
|
+
Input: { placeholder?: string; value?: string }
|
|
29
|
+
}>()
|
|
30
|
+
|
|
31
|
+
const schema = createSchema({
|
|
32
|
+
username: f.Input({ title: 'Username', componentProps: { placeholder: 'Your name' } }),
|
|
33
|
+
})
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Expressions use the `{{ ... }}` syntax and are evaluated against form values and scope:
|
|
37
|
+
|
|
38
|
+
```ts
|
|
39
|
+
const schema = createSchema({
|
|
40
|
+
limit: f.Input({ title: 'Limit' }),
|
|
41
|
+
name: f.Input({
|
|
42
|
+
title: 'Name',
|
|
43
|
+
maxLength: '{{$values.limit}}',
|
|
44
|
+
}),
|
|
45
|
+
})
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## API
|
|
49
|
+
|
|
50
|
+
- `createFragment(options?)` — returns `Field`, `Object`, `Array`, `Void`, `transform`, plus one constructor per registered component name.
|
|
51
|
+
- `createSchema(properties, patches?)` — builds a typed `object` schema.
|
|
52
|
+
- `Schema` — imperative schema tree; `ISchema` is the plain-object form.
|
|
53
|
+
- Expressions — `SchemaExpression`, `ExpressionProps`, `createExpression`, `createExpressionFn`, `getExpression`.
|
|
54
|
+
- Compiler — `compile`, `shallowCompile`, `registerCompiler`, `silent`.
|
|
55
|
+
- Types — `FieldSchema`, `ObjectSchema`, `ArraySchema`, `VoidSchema`, `Fragment`, `SchemaCreator`.
|
|
56
|
+
|
|
57
|
+
In Vue/React apps, `createSchemaField` from `@formvk/vue` / `@formvk/react` binds component maps to a fragment and renders the schema.
|
|
58
|
+
|
|
59
|
+
## Documentation
|
|
60
|
+
|
|
61
|
+
- Schema guide: https://formvk.github.io/core/guide/schema
|
|
62
|
+
- Schema API: https://formvk.github.io/core/api/schema
|
|
63
|
+
|
|
64
|
+
## License
|
|
65
|
+
|
|
66
|
+
MIT
|