diff --git a/packages/core/client/src/schema-component/antd/grid/Grid.tsx b/packages/core/client/src/schema-component/antd/grid/Grid.tsx index ee42b9f5fc..928ce5057e 100644 --- a/packages/core/client/src/schema-component/antd/grid/Grid.tsx +++ b/packages/core/client/src/schema-component/antd/grid/Grid.tsx @@ -1,4 +1,4 @@ -import { useDndMonitor, useDroppable } from '@dnd-kit/core'; +import { useDndContext, useDndMonitor, useDroppable } from '@dnd-kit/core'; import { css } from '@emotion/css'; import { observer, RecursionField, Schema, useField, useFieldSchema } from '@formily/react'; import { uid } from '@formily/shared'; @@ -24,9 +24,25 @@ const ColDivider = (props) => { backgroundColor: isOver ? 'rgba(241, 139, 98, .1)' : undefined, }; + const dndContext = useDndContext() + const activeSchema: Schema | undefined = dndContext.active?.data.current?.schema?.parent + const blocksLength: number = activeSchema ? Object.keys(activeSchema.properties).length : 0; + + + let visible = true + if (blocksLength === 1) { + if (props.first) { + visible = activeSchema !== props.cols[0] + } else { + const currentSchema = props.cols[props.index] + const downSchema = props.cols[props.index + 1] + visible = activeSchema !== currentSchema && downSchema !== activeSchema + } + } + return (
{ const [active, setActive] = useState(false); + const dndContext = useDndContext() + const currentSchema = props.rows[props.index] + const activeSchema = dndContext.active?.data.current?.schema?.parent.parent + + const colsLength: number = activeSchema?.mapProperties((schema) => { + return schema['x-component'] === 'Grid.Col' + }).filter(Boolean).length + + let visible = true + + // col > 1 时不需要隐藏 + if (colsLength === 1) { + if (props.first) { + visible = activeSchema !== props.rows[0] + } else { + const downSchema = props.rows[props.index + 1] + visible = activeSchema !== currentSchema && downSchema !== activeSchema + } + } + useDndMonitor({ onDragStart(event) { setActive(true); @@ -68,7 +104,7 @@ const RowDivider = (props) => { return ( { const { render } = useSchemaInitializer(fieldSchema['x-initializer']); const addr = field.address.toString(); const rows = useRowProperties(); + return (
{ { const fieldSchema = useFieldSchema(); const addr = field.address.toString(); const cols = useColProperties(); + return (
{ )} > {