2022-01-10 19:22:21 +08:00
|
|
|
|
---
|
|
|
|
|
nav:
|
|
|
|
|
path: /client
|
|
|
|
|
group:
|
|
|
|
|
path: /client
|
|
|
|
|
---
|
|
|
|
|
|
2022-02-07 21:52:51 +08:00
|
|
|
|
# SchemaInitializer
|
2022-01-10 19:22:21 +08:00
|
|
|
|
|
|
|
|
|
用于配置各种 schema 的初始化
|
|
|
|
|
|
2022-02-07 21:52:51 +08:00
|
|
|
|
## SchemaInitializer.Button
|
|
|
|
|
|
|
|
|
|
常规区块的初始化按钮
|
|
|
|
|
|
|
|
|
|
```tsx | pure
|
2022-02-08 12:17:06 +08:00
|
|
|
|
const items = [
|
|
|
|
|
{
|
|
|
|
|
title: 'Data blocks',
|
|
|
|
|
children: [
|
|
|
|
|
{
|
|
|
|
|
title: 'Table',
|
|
|
|
|
component: 'TableBlockInitializerItem',
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
title: 'Form',
|
|
|
|
|
component: 'FormBlockInitializerItem',
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
export const AddBlockButton = () => {
|
|
|
|
|
return (
|
|
|
|
|
<SchemaInitializer.Button
|
|
|
|
|
// 待插入的节点,wrap 处理
|
|
|
|
|
wrap={(schema) => schema}
|
|
|
|
|
// 插入位置
|
|
|
|
|
insertPosition={'beforeBegin'}
|
|
|
|
|
// 菜单项
|
|
|
|
|
items={items}
|
|
|
|
|
>Create block</SchemaInitializer.Button>
|
|
|
|
|
);
|
|
|
|
|
}
|
2022-02-07 21:52:51 +08:00
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
动态字段的配置
|
|
|
|
|
|
|
|
|
|
```tsx | pure
|
|
|
|
|
const useFormItemInitializerFields = () => {
|
|
|
|
|
const { fields } = useCollection();
|
|
|
|
|
return fields.map(field => {
|
|
|
|
|
return {
|
|
|
|
|
key: field.name,
|
2022-02-08 12:17:06 +08:00
|
|
|
|
component: 'FormItemInitializerItem'
|
2022-02-07 21:52:51 +08:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-08 12:17:06 +08:00
|
|
|
|
export const AddFieldButton = () => {
|
|
|
|
|
return (
|
|
|
|
|
<SchemaInitializer.Button
|
|
|
|
|
// 待插入的节点,wrap 处理
|
|
|
|
|
wrap={(schema) => schema}
|
|
|
|
|
// 插入位置
|
|
|
|
|
insertPosition={'beforeBegin'}
|
|
|
|
|
items={[
|
|
|
|
|
{
|
|
|
|
|
title: 'Display fields',
|
|
|
|
|
children: useFormItemInitializerFields(),
|
|
|
|
|
},
|
|
|
|
|
]}
|
|
|
|
|
>Configure fields</SchemaInitializer.Button>
|
|
|
|
|
)
|
|
|
|
|
}
|
2022-02-07 21:52:51 +08:00
|
|
|
|
```
|
2022-01-10 19:22:21 +08:00
|
|
|
|
|
2022-02-07 21:52:51 +08:00
|
|
|
|
## SchemaInitializer.Item
|
2022-01-10 19:22:21 +08:00
|
|
|
|
|
2022-02-07 21:52:51 +08:00
|
|
|
|
扩展项
|
2022-01-10 19:22:21 +08:00
|
|
|
|
|
2022-02-07 21:52:51 +08:00
|
|
|
|
```tsx | pure
|
2022-02-08 12:17:06 +08:00
|
|
|
|
const TableBlockInitializerItem = (props) => {
|
2022-02-07 21:52:51 +08:00
|
|
|
|
const { insert } = props;
|
|
|
|
|
return (
|
|
|
|
|
<SchemaInitializer.Item
|
|
|
|
|
icon={<TableOutlined />}
|
|
|
|
|
onClick={(info) => {
|
|
|
|
|
console.log({ info });
|
|
|
|
|
insert({
|
|
|
|
|
type: 'void',
|
|
|
|
|
title: info.key,
|
|
|
|
|
'x-component': 'Hello',
|
|
|
|
|
});
|
|
|
|
|
}}
|
|
|
|
|
items={[
|
|
|
|
|
{
|
|
|
|
|
type: 'itemGroup',
|
|
|
|
|
title: 'select a data source',
|
|
|
|
|
children: [
|
|
|
|
|
{
|
|
|
|
|
key: 'users',
|
|
|
|
|
title: 'Users',
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
key: 'posts',
|
|
|
|
|
title: 'Posts',
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
]}
|
|
|
|
|
>
|
|
|
|
|
Table
|
|
|
|
|
</SchemaInitializer.Item>
|
|
|
|
|
);
|
|
|
|
|
};
|
2022-01-10 19:22:21 +08:00
|
|
|
|
```
|
2022-02-07 21:52:51 +08:00
|
|
|
|
|
|
|
|
|
## Examples
|
|
|
|
|
|
|
|
|
|
### Block
|
|
|
|
|
|
|
|
|
|
<code src="./demos/demo1.tsx" />
|
|
|
|
|
|
|
|
|
|
### Action
|
|
|
|
|
|
|
|
|
|
<code src="./demos/demo2.tsx" />
|
|
|
|
|
|
|
|
|
|
### FormItem
|
|
|
|
|
|
|
|
|
|
<code src="./demos/demo3.tsx" />
|
|
|
|
|
|
|
|
|
|
### Table.Column
|
|
|
|
|
|
|
|
|
|
<code src="./demos/demo4.tsx" />
|