@formvk/react 0.1.0 → 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 +16 -0
- package/README.md +60 -0
- package/dist/index.js +91 -295
- package/dist/index.js.map +1 -1
- package/package.json +10 -6
- package/src/__tests__/expression.spec.tsx +0 -87
- package/src/__tests__/form.spec.tsx +0 -164
- package/src/__tests__/hooks.spec.tsx +0 -198
- package/src/__tests__/render.spec.tsx +0 -704
- package/src/__tests__/schema.spec.tsx +0 -598
- package/src/__tests__/shared.tsx +0 -44
- package/src/components/ExpressionScope.tsx +0 -16
- package/src/components/FormConsumer.tsx +0 -20
- package/src/components/FormProvider.tsx +0 -35
- package/src/components/ReactiveField.tsx +0 -161
- package/src/components/RecursionField.tsx +0 -113
- package/src/components/SchemaField.tsx +0 -195
- package/src/components/index.ts +0 -7
- package/src/hooks/index.ts +0 -6
- package/src/hooks/useAttach.ts +0 -20
- package/src/hooks/useField.ts +0 -8
- package/src/hooks/useFieldSchema.ts +0 -8
- package/src/hooks/useForm.ts +0 -8
- package/src/hooks/useFormEffects.ts +0 -19
- package/src/hooks/useParentForm.ts +0 -18
- package/src/index.ts +0 -5
- package/src/shared/connect.tsx +0 -72
- package/src/shared/context.ts +0 -15
- package/src/shared/createForm.ts +0 -10
- package/src/shared/index.ts +0 -2
- package/src/types/index.ts +0 -144
- package/src/utils/getRawComponent.ts +0 -12
- package/src/utils/slots.ts +0 -9
- package/tsconfig.build.json +0 -9
- package/tsconfig.json +0 -7
- package/vite.config.ts +0 -32
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# @formvk/react
|
|
2
|
+
|
|
3
|
+
## 1.0.0
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- 65c066c: 添加readme.md文档
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [65c066c]
|
|
12
|
+
- @formvk/core@1.0.0
|
|
13
|
+
- @formvk/reactive@1.0.0
|
|
14
|
+
- @formvk/reactive-react@1.0.0
|
|
15
|
+
- @formvk/schema@1.0.0
|
|
16
|
+
- @formvk/shared@1.0.0
|
package/README.md
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# @formvk/react
|
|
2
|
+
|
|
3
|
+
React bindings for Formvk. It connects the `@formvk/core` form model and `@formvk/schema` to React components, with field updates powered by `@formvk/reactive-react`.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm add @formvk/react react react-dom
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
`react` and `react-dom` (`>= 18`) are peer dependencies.
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
```tsx
|
|
16
|
+
import { createForm, createSchema, createSchemaField, FormProvider } from '@formvk/react'
|
|
17
|
+
import { useState } from 'react'
|
|
18
|
+
|
|
19
|
+
function Input(props: { value?: string }) {
|
|
20
|
+
return <input value={props.value ?? ''} readOnly />
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// schema and component factory are static: build them once at module scope
|
|
24
|
+
const { SchemaField, fragment: f } = createSchemaField({
|
|
25
|
+
components: { Input },
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
const schema = createSchema({
|
|
29
|
+
name: f.Input({ title: 'Name' }),
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
export default function App() {
|
|
33
|
+
// the form is a stateful model: create it lazily inside the component
|
|
34
|
+
const [form] = useState(() => createForm({ values: { name: '' } }))
|
|
35
|
+
|
|
36
|
+
return (
|
|
37
|
+
<FormProvider form={form}>
|
|
38
|
+
<SchemaField schema={schema} />
|
|
39
|
+
</FormProvider>
|
|
40
|
+
)
|
|
41
|
+
}
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## API
|
|
45
|
+
|
|
46
|
+
- **Components** — `FormProvider`, `SchemaField`, `createSchemaField`, `RecursionField`, `ExpressionScope`, `FormConsumer`, `ReactiveField`.
|
|
47
|
+
- **Hooks** — `useForm`, `useField`, `useFieldSchema`, `useAttach`, `useFormEffects`, `useParentForm`.
|
|
48
|
+
- **Helpers** — `createForm`, `connect`, `mapProps`, `mapReadPretty`.
|
|
49
|
+
- **Schema** — re-exports `@formvk/schema` (`createFragment`, `createSchema`, `ISchema`, expression types, ...).
|
|
50
|
+
|
|
51
|
+
Components that read observable state directly should be wrapped with `observer` from `@formvk/reactive-react`. `FormConsumer` exposes form state through a render prop.
|
|
52
|
+
|
|
53
|
+
## Documentation
|
|
54
|
+
|
|
55
|
+
- React API: https://formvk.github.io/core/api/react
|
|
56
|
+
- Getting started: https://formvk.github.io/core/guide/getting-started
|
|
57
|
+
|
|
58
|
+
## License
|
|
59
|
+
|
|
60
|
+
MIT
|