@xbeeant/form-engine-react 0.0.1 → 0.0.2

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.
Files changed (2) hide show
  1. package/README.md +92 -64
  2. package/package.json +4 -3
package/README.md CHANGED
@@ -1,69 +1,97 @@
1
- # React + TypeScript + Vite
2
-
3
- This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.
4
-
5
- Currently, two official plugins are available:
6
-
7
- - [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react) uses [Babel](https://babeljs.io/) for Fast Refresh
8
- - [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh
9
-
10
- ## Expanding the ESLint configuration
11
-
12
- If you are developing a production application, we recommend updating the configuration to enable type-aware lint rules:
13
-
14
- ```js
15
- export default tseslint.config([
16
- globalIgnores(['dist']),
17
- {
18
- files: ['**/*.{ts,tsx}'],
19
- extends: [
20
- // Other configs...
21
-
22
- // Remove tseslint.configs.recommended and replace with this
23
- ...tseslint.configs.recommendedTypeChecked,
24
- // Alternatively, use this for stricter rules
25
- ...tseslint.configs.strictTypeChecked,
26
- // Optionally, add this for stylistic rules
27
- ...tseslint.configs.stylisticTypeChecked,
28
-
29
- // Other configs...
30
- ],
31
- languageOptions: {
32
- parserOptions: {
33
- project: ['./tsconfig.node.json', './tsconfig.app.json'],
34
- tsconfigRootDir: import.meta.dirname,
35
- },
36
- // other options...
37
- },
38
- },
39
- ])
1
+ # @xbeeant/form-engine-react
2
+
3
+ `@xbeeant/form-engine` React 渲染适配层。
4
+
5
+ 通过 `useSyncExternalStore` + 按路径精准版本订阅渲染字段,联动更新只重渲染受影响的组件;Schema 解析与路径计算全部在 Core 完成,本包直接消费渲染树。
6
+
7
+ ## 安装
8
+
9
+ ```bash
10
+ npm install @xbeeant/form-engine-react @xbeeant/form-engine
40
11
  ```
41
12
 
42
- You can also install [eslint-plugin-react-x](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-x) and [eslint-plugin-react-dom](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-dom) for React-specific lint rules:
43
-
44
- ```js
45
- // eslint.config.js
46
- import reactX from 'eslint-plugin-react-x'
47
- import reactDom from 'eslint-plugin-react-dom'
48
-
49
- export default tseslint.config([
50
- globalIgnores(['dist']),
51
- {
52
- files: ['**/*.{ts,tsx}'],
53
- extends: [
54
- // Other configs...
55
- // Enable lint rules for React
56
- reactX.configs['recommended-typescript'],
57
- // Enable lint rules for React DOM
58
- reactDom.configs.recommended,
59
- ],
60
- languageOptions: {
61
- parserOptions: {
62
- project: ['./tsconfig.node.json', './tsconfig.app.json'],
63
- tsconfigRootDir: import.meta.dirname,
64
- },
65
- // other options...
13
+ peerDependencies:`react >= 18`、`react-dom >= 18`。
14
+
15
+ ## 快速开始
16
+
17
+ ```tsx
18
+ import { useForm, NexusForm } from '@xbeeant/form-engine-react';
19
+ import { registerAntdUI } from '@xbeeant/form-engine-ui';
20
+
21
+ const schema = {
22
+ type: 'object',
23
+ displayType: 'row',
24
+ properties: {
25
+ username: {
26
+ type: 'string',
27
+ widget: 'input',
28
+ title: '用户名',
29
+ required: true,
66
30
  },
31
+ age: { type: 'integer', widget: 'number', title: '年龄' },
67
32
  },
68
- ])
33
+ };
34
+
35
+ function App() {
36
+ const [form] = useForm();
37
+ return (
38
+ <NexusForm
39
+ form={form}
40
+ schema={schema}
41
+ initialValues={{ username: 'alice' }}
42
+ onFinish={(values) => console.log(values)}
43
+ onFinishFailed={(errors) => console.log(errors)}
44
+ footer
45
+ />
46
+ );
47
+ }
48
+ ```
49
+
50
+ > 需要先注册 UI 组件:`registerAntdUI(engine)`(engine 由 `useForm()` 内部创建)或 `engine.use(antdPreset)` 注入 `@xbeeant/form-engine-ui`。未注册 widget 的字段会优雅降级渲染。
51
+
52
+ ## API
53
+
54
+ ### NexusForm
55
+
56
+ | Prop | 类型 | 说明 |
57
+ | :--- | :--- | :--- |
58
+ | `form` | `FormController` | 由 `useForm()` 创建的表单实例 |
59
+ | `schema` | `NexusSchema` | Schema 定义(缺省则渲染 children) |
60
+ | `initialValues` | `Record<string, unknown>` | 初始值 |
61
+ | `widgets` / `layouts` | `Record<string, (props) => ReactNode>` | 额外注册的组件 |
62
+ | `onFinish` | `(formData) => void \| Promise` | 提交成功回调 |
63
+ | `onFinishFailed` | `(errors: Map<string, string[]>) => void` | 校验失败回调 |
64
+ | `footer` | `boolean \| ReactNode` | 是否显示默认提交/重置按钮,或自定义 |
65
+ | `displayType` / `labelWidth` / `label` / `colon` / `column` / `readOnly` | — | 表单布局配置,优先级:组件 props > Schema 顶层 > 默认值 |
66
+ | `className` / `style` / `children` | — | 常规属性 |
67
+
68
+ ### useForm
69
+
70
+ ```ts
71
+ const [form] = useForm(); // 返回 [FormController],可选 useForm(engine) 复用已有实例
69
72
  ```
73
+
74
+ `FormController` 常用方法:`submit()`、`resetFields()`、`setValues(values)`、`setValueByPath(path, value)`、`getValues(paths?)`、`getAllValues()`、`getHiddenValues()`、`validateFields(paths?)`、`getFieldError(path)`、`setSchema(schema)`、`setSchemaByPath(path, patch)`、`registerValidator(path, fn)`、`scrollToPath(path)` 等。`submit` 失败时自动滚动聚焦第一个错误字段。
75
+
76
+ ### Hooks
77
+
78
+ | Hook | 说明 |
79
+ | :--- | :--- |
80
+ | `useFormData()` | 订阅完整 formData(全局快照) |
81
+ | `useFieldValue(path)` | 订阅单字段值(精准版本订阅,仅该字段重渲染) |
82
+ | `useFieldState(path)` | 订阅单字段完整状态(value / errors / visible / required ...) |
83
+ | `useWatch(path)` | 监听字段值变化(`(value, oldValue) => void`) |
84
+ | `useWatchState(path)` | 监听字段状态变化 |
85
+ | `useWatchMultiple(paths)` | 同时监听多个字段 |
86
+ | `useWatchAll()` | 监听所有字段值变化 |
87
+ | `useEngine()` | 获取当前引擎实例 |
88
+ | `useFieldValidator(path, validator)` | 为字段注册校验器 |
89
+ | `useFormConfig()` | 获取表单布局配置(displayType / labelWidth / column ...) |
90
+
91
+ ## 关联包
92
+
93
+ | 包 | 说明 |
94
+ | :--- | :--- |
95
+ | `@xbeeant/form-engine` | 表单引擎核心(纯 TypeScript) |
96
+ | `@xbeeant/form-engine-ui` | Ant Design 控件与布局库 |
97
+ | `@xbeeant/form-engine-designer` | Schema 可视化设计器 |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xbeeant/form-engine-react",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "publishConfig": {
5
5
  "access": "public",
6
6
  "registry": "https://registry.npmjs.org/"
@@ -70,6 +70,7 @@
70
70
  }
71
71
  },
72
72
  "dependencies": {
73
- "@xbeeant/form-engine": "^0.0.1"
74
- }
73
+ "@xbeeant/form-engine": "^0.0.2"
74
+ },
75
+ "gitHead": "5e640d99e81bec24182061a9f431c39647e562dd"
75
76
  }