From e56b2b7bf69304aedf570d7371f3fb0ad4e1b96f Mon Sep 17 00:00:00 2001 From: chenos Date: Sun, 20 Feb 2022 10:21:22 +0800 Subject: [PATCH] feat(client): improve code --- .../antd/block-item/BlockItem.tsx | 52 ++++++++++++++++++- .../antd/form-item/FormItem.tsx | 16 +++++- .../antd/form/Form.Designer.tsx | 7 ++- .../src/schema-component/antd/grid/Grid.tsx | 4 +- .../antd/markdown/Markdown.Void.Designer.tsx | 7 ++- .../antd/void-table/VoidTable.Designer.tsx | 7 ++- .../common/dnd-context/index.tsx | 5 +- .../common/sortable-item/SortableItem.tsx | 23 ++++---- .../DetailsActionInitializer/index.tsx | 13 +++-- .../FormItemInitializer/index.tsx | 2 +- .../schema-initializer/SchemaInitializer.tsx | 9 +++- .../schema-settings/GeneralSchemaDesigner.tsx | 18 +++++-- .../src/schema-settings/SchemaSettings.tsx | 24 +++++++-- 13 files changed, 147 insertions(+), 40 deletions(-) diff --git a/packages/client/src/schema-component/antd/block-item/BlockItem.tsx b/packages/client/src/schema-component/antd/block-item/BlockItem.tsx index 25e5656a7..9e1e985d5 100644 --- a/packages/client/src/schema-component/antd/block-item/BlockItem.tsx +++ b/packages/client/src/schema-component/antd/block-item/BlockItem.tsx @@ -1,3 +1,5 @@ +import { css } from '@emotion/css'; +import cls from 'classnames'; import React from 'react'; import { SortableItem } from '../../common'; import { useDesigner } from '../../hooks'; @@ -5,7 +7,55 @@ import { useDesigner } from '../../hooks'; export const BlockItem: React.FC = (props) => { const Designer = useDesigner(); return ( - + .general-schema-designer { + display: block; + } + } + &.nb-form-item:hover { + .general-schema-designer { + background: rgba(241, 139, 98, 0.06) !important; + border: 0 !important; + top: -5px !important; + bottom: -5px !important; + left: -5px !important; + right: -5px !important; + } + } + .general-schema-designer { + position: absolute; + z-index: 999; + top: 0; + bottom: 0; + left: 0; + right: 0; + display: none; + border: 2px solid rgba(241, 139, 98, 0.3); + pointer-events: none; + .general-schema-designer-icons { + position: absolute; + right: 2px; + top: 2px; + line-height: 16px; + pointer-events: all; + .ant-space-item { + background-color: #f18b62; + color: #fff; + line-height: 16px; + width: 16px; + padding-left: 1px; + } + } + } + `, + )} + > {props.children} diff --git a/packages/client/src/schema-component/antd/form-item/FormItem.tsx b/packages/client/src/schema-component/antd/form-item/FormItem.tsx index 08a10fb7d..9d5ae654a 100644 --- a/packages/client/src/schema-component/antd/form-item/FormItem.tsx +++ b/packages/client/src/schema-component/antd/form-item/FormItem.tsx @@ -1,11 +1,25 @@ import { FormItem as Item } from '@formily/antd'; import React from 'react'; +import { GeneralSchemaDesigner, SchemaSettings } from '../../../schema-settings'; import { BlockItem } from '../block-item'; -export const FormItem: React.FC = (props) => { +export const FormItem: any = (props) => { return ( ); }; + +FormItem.Designer = () => { + return ( + + + + ); +}; diff --git a/packages/client/src/schema-component/antd/form/Form.Designer.tsx b/packages/client/src/schema-component/antd/form/Form.Designer.tsx index c879a46e2..8c6d95cce 100644 --- a/packages/client/src/schema-component/antd/form/Form.Designer.tsx +++ b/packages/client/src/schema-component/antd/form/Form.Designer.tsx @@ -4,7 +4,12 @@ import { GeneralSchemaDesigner, SchemaSettings } from '../../../schema-settings' export const FormDesigner = () => { return ( - + ); }; diff --git a/packages/client/src/schema-component/antd/grid/Grid.tsx b/packages/client/src/schema-component/antd/grid/Grid.tsx index 8b4b87efd..b539004ed 100644 --- a/packages/client/src/schema-component/antd/grid/Grid.tsx +++ b/packages/client/src/schema-component/antd/grid/Grid.tsx @@ -17,7 +17,7 @@ const ColDivider = (props) => { }); const droppableStyle = { - backgroundColor: isOver ? 'green' : undefined, + backgroundColor: isOver ? 'rgba(241, 139, 98, .1)' : undefined, }; return
; @@ -32,7 +32,7 @@ const RowDivider = (props) => { const droppableStyle = {}; if (isOver) { - droppableStyle['backgroundColor'] = 'green'; + droppableStyle['backgroundColor'] = 'rgba(241, 139, 98, .1)'; } const [active, setActive] = useState(false); diff --git a/packages/client/src/schema-component/antd/markdown/Markdown.Void.Designer.tsx b/packages/client/src/schema-component/antd/markdown/Markdown.Void.Designer.tsx index 0859b2faf..0ace6166b 100644 --- a/packages/client/src/schema-component/antd/markdown/Markdown.Void.Designer.tsx +++ b/packages/client/src/schema-component/antd/markdown/Markdown.Void.Designer.tsx @@ -13,7 +13,12 @@ export const MarkdownVoidDesigner = () => { }} /> - + ); }; diff --git a/packages/client/src/schema-component/antd/void-table/VoidTable.Designer.tsx b/packages/client/src/schema-component/antd/void-table/VoidTable.Designer.tsx index 5e93d3d9a..cd6480215 100644 --- a/packages/client/src/schema-component/antd/void-table/VoidTable.Designer.tsx +++ b/packages/client/src/schema-component/antd/void-table/VoidTable.Designer.tsx @@ -4,7 +4,12 @@ import { GeneralSchemaDesigner, SchemaSettings } from '../../../schema-settings' export const VoidTableDesigner = () => { return ( - + ); }; diff --git a/packages/client/src/schema-component/common/dnd-context/index.tsx b/packages/client/src/schema-component/common/dnd-context/index.tsx index d46c6b1c4..8d5761351 100644 --- a/packages/client/src/schema-component/common/dnd-context/index.tsx +++ b/packages/client/src/schema-component/common/dnd-context/index.tsx @@ -1,4 +1,4 @@ -import { DndContext as DndKitContext, DragEndEvent, rectIntersection } from '@dnd-kit/core'; +import { DndContext as DndKitContext, DragEndEvent, DragOverlay, rectIntersection } from '@dnd-kit/core'; import { observer } from '@formily/react'; import React from 'react'; import { useAPIClient } from '../../../'; @@ -49,6 +49,9 @@ const useDragEnd = () => { export const DndContext = observer((props) => { return ( + + 拖拽中 + {props.children} ); diff --git a/packages/client/src/schema-component/common/sortable-item/SortableItem.tsx b/packages/client/src/schema-component/common/sortable-item/SortableItem.tsx index 18b07abfc..54c8e6736 100644 --- a/packages/client/src/schema-component/common/sortable-item/SortableItem.tsx +++ b/packages/client/src/schema-component/common/sortable-item/SortableItem.tsx @@ -19,7 +19,7 @@ export const Sortable = (props: any) => { const droppableStyle = { ...style }; if (isOver) { - droppableStyle['color'] = 'green'; + droppableStyle['color'] = 'rgba(241, 139, 98, .1)'; } return ( @@ -35,17 +35,13 @@ export const SortableItem: React.FC = observer((props) => { const field = useField(); const fieldSchema = useFieldSchema(); return ( - + {props.children} ); }); -export const DragHandler = () => { +export const DragHandler = (props) => { const { isDragging, attributes, listeners, setNodeRef, transform } = useContext(DraggableContext); const style = transform ? { @@ -57,18 +53,19 @@ export const DragHandler = () => {
-
- Drag -
{ {...listeners} {...attributes} > -
Drag
+ {props.children}
); diff --git a/packages/client/src/schema-initializer/Initializers/DetailsActionInitializer/index.tsx b/packages/client/src/schema-initializer/Initializers/DetailsActionInitializer/index.tsx index e964ffccf..c0a929f06 100644 --- a/packages/client/src/schema-initializer/Initializers/DetailsActionInitializer/index.tsx +++ b/packages/client/src/schema-initializer/Initializers/DetailsActionInitializer/index.tsx @@ -58,21 +58,20 @@ export const DetailsActionInitializer = observer((props: any) => { children: [ { type: 'item', - title: 'Create', + title: 'Edit', component: InitializeAction, schema: { - title: 'Create', - 'x-action': 'posts:create', - 'x-align': 'left', + title: 'Edit', + 'x-action': 'update', }, }, { type: 'item', - title: 'Update', + title: 'Delete', component: InitializeAction, schema: { - title: 'Update', - 'x-action': 'posts:update', + title: 'Delete', + 'x-action': 'delete', }, }, ], diff --git a/packages/client/src/schema-initializer/Initializers/FormItemInitializer/index.tsx b/packages/client/src/schema-initializer/Initializers/FormItemInitializer/index.tsx index ec9cebec3..8363f95d6 100644 --- a/packages/client/src/schema-initializer/Initializers/FormItemInitializer/index.tsx +++ b/packages/client/src/schema-initializer/Initializers/FormItemInitializer/index.tsx @@ -16,7 +16,7 @@ const useFormItems = () => { component: InitializeFormItem, schema: { name: field.name, - 'x-designer': 'TestDesigner', + 'x-designer': 'FormItem.Designer', 'x-component': 'CollectionField', 'x-decorator': 'FormItem', 'x-collection-field': `${name}.${field.name}`, diff --git a/packages/client/src/schema-initializer/SchemaInitializer.tsx b/packages/client/src/schema-initializer/SchemaInitializer.tsx index d27305bdd..02fe6722a 100644 --- a/packages/client/src/schema-initializer/SchemaInitializer.tsx +++ b/packages/client/src/schema-initializer/SchemaInitializer.tsx @@ -92,7 +92,14 @@ SchemaInitializer.Button = observer((props: SchemaInitializerButtonProps) => { {...dropdown} overlay={menu} > -