mirror of
https://github.com/nocobase/nocobase
synced 2024-11-15 11:36:42 +00:00
fix(client/demos): gird x-initializer
This commit is contained in:
parent
5ec50d32bb
commit
d2275455be
@ -1,18 +1,60 @@
|
||||
import { ISchema, observer, useFieldSchema } from '@formily/react';
|
||||
import { uid } from '@formily/shared';
|
||||
import {
|
||||
BlockItem,
|
||||
CardItem,
|
||||
DragHandler,
|
||||
Form,
|
||||
Grid,
|
||||
Markdown,
|
||||
SchemaComponent,
|
||||
SchemaComponentProvider,
|
||||
SchemaInitializer,
|
||||
SchemaInitializerProvider
|
||||
} from '@nocobase/client';
|
||||
import React from 'react';
|
||||
|
||||
const gridRowColWrap = (schema) => {
|
||||
return {
|
||||
type: 'void',
|
||||
'x-component': 'Grid.Row',
|
||||
properties: {
|
||||
[uid()]: {
|
||||
type: 'void',
|
||||
'x-component': 'Grid.Col',
|
||||
properties: {
|
||||
[schema.name || uid()]: schema,
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
export const AddBlockButton = (props: any) => {
|
||||
const { insertPosition, component } = props;
|
||||
return (
|
||||
<SchemaInitializer.Button
|
||||
insertPosition={insertPosition}
|
||||
wrap={gridRowColWrap}
|
||||
items={[
|
||||
{
|
||||
key: 'media',
|
||||
type: 'itemGroup',
|
||||
title: 'Other blocks',
|
||||
children: [
|
||||
{
|
||||
key: 'markdown',
|
||||
type: 'item',
|
||||
title: 'Markdown',
|
||||
component: 'MarkdownBlockInitializer',
|
||||
},
|
||||
],
|
||||
},
|
||||
]}
|
||||
component={component}
|
||||
title={component ? undefined : 'Add block'}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
const Block = observer((props) => {
|
||||
const fieldSchema = useFieldSchema();
|
||||
return (
|
||||
@ -29,7 +71,7 @@ const schema: ISchema = {
|
||||
grid: {
|
||||
type: 'void',
|
||||
'x-component': 'Grid',
|
||||
'x-item-initializer': 'AddBlockItem',
|
||||
'x-initializer': 'AddBlockButton',
|
||||
'x-uid': uid(),
|
||||
properties: {},
|
||||
},
|
||||
@ -38,8 +80,8 @@ const schema: ISchema = {
|
||||
|
||||
export default function App() {
|
||||
return (
|
||||
<SchemaComponentProvider components={{ BlockItem, Block, Grid, CardItem, Markdown, Form }}>
|
||||
<SchemaInitializerProvider>
|
||||
<SchemaComponentProvider components={{ Grid, CardItem, Markdown }}>
|
||||
<SchemaInitializerProvider initializers={{ AddBlockButton }}>
|
||||
<SchemaComponent schema={schema} />
|
||||
</SchemaInitializerProvider>
|
||||
</SchemaComponentProvider>
|
||||
|
Loading…
Reference in New Issue
Block a user