@formily-design/react 1.0.0 → 1.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.
- package/esm/panels/styles.less +14 -0
- package/lib/panels/styles.less +14 -0
- package/package.json +4 -4
- package/copy.ts +0 -6
- package/dist/designable.react.umd.production.css +0 -1
- package/dist/designable.react.umd.production.js +0 -6
- package/dist/designable.react.umd.production.min.css +0 -1
- package/dist/designable.react.umd.production.min.js +0 -3769
- package/rollup.config.js +0 -3
- package/src/containers/Designer.tsx +0 -50
- package/src/containers/Layout.tsx +0 -50
- package/src/containers/Simulator.tsx +0 -30
- package/src/containers/Viewport.tsx +0 -69
- package/src/containers/Workbench.tsx +0 -15
- package/src/containers/Workspace.tsx +0 -41
- package/src/containers/index.ts +0 -7
- package/src/containers/styles.less +0 -19
- package/src/context.ts +0 -17
- package/src/hooks/index.ts +0 -25
- package/src/hooks/useComponents.ts +0 -3
- package/src/hooks/useCursor.ts +0 -6
- package/src/hooks/useDesigner.ts +0 -19
- package/src/hooks/useHistory.ts +0 -6
- package/src/hooks/useHover.ts +0 -6
- package/src/hooks/useLayout.ts +0 -11
- package/src/hooks/useMoveHelper.ts +0 -6
- package/src/hooks/useNodeIdProps.ts +0 -11
- package/src/hooks/useOperation.ts +0 -6
- package/src/hooks/useOutline.ts +0 -6
- package/src/hooks/usePosition.ts +0 -5
- package/src/hooks/usePrefix.ts +0 -5
- package/src/hooks/useRegistry.ts +0 -6
- package/src/hooks/useScreen.ts +0 -5
- package/src/hooks/useSelected.ts +0 -6
- package/src/hooks/useSelectedNode.ts +0 -14
- package/src/hooks/useSelection.ts +0 -6
- package/src/hooks/useTheme.ts +0 -5
- package/src/hooks/useTransformHelper.ts +0 -6
- package/src/hooks/useTree.ts +0 -6
- package/src/hooks/useTreeNode.ts +0 -6
- package/src/hooks/useValidNodeOffsetRect.ts +0 -48
- package/src/hooks/useViewport.ts +0 -6
- package/src/hooks/useWorkbench.ts +0 -6
- package/src/hooks/useWorkspace.ts +0 -16
- package/src/icons/actions.tsx +0 -138
- package/src/icons/add.tsx +0 -8
- package/src/icons/animations.tsx +0 -325
- package/src/icons/boolean.tsx +0 -7
- package/src/icons/clone.tsx +0 -9
- package/src/icons/close.tsx +0 -7
- package/src/icons/code.tsx +0 -5
- package/src/icons/command.tsx +0 -8
- package/src/icons/component.tsx +0 -5
- package/src/icons/container.tsx +0 -8
- package/src/icons/corner.tsx +0 -26
- package/src/icons/delete.tsx +0 -9
- package/src/icons/design.tsx +0 -7
- package/src/icons/display.tsx +0 -17
- package/src/icons/dragmove.tsx +0 -10
- package/src/icons/expand.tsx +0 -5
- package/src/icons/expression.tsx +0 -5
- package/src/icons/eyes.tsx +0 -15
- package/src/icons/flex.tsx +0 -85
- package/src/icons/flip.tsx +0 -5
- package/src/icons/focus.tsx +0 -5
- package/src/icons/font.tsx +0 -61
- package/src/icons/formula.tsx +0 -5
- package/src/icons/freemove.tsx +0 -10
- package/src/icons/help.tsx +0 -8
- package/src/icons/hidden.tsx +0 -5
- package/src/icons/history.tsx +0 -7
- package/src/icons/image.tsx +0 -9
- package/src/icons/index.ts +0 -53
- package/src/icons/json.tsx +0 -5
- package/src/icons/logo.tsx +0 -5
- package/src/icons/menu.tsx +0 -7
- package/src/icons/mobile.tsx +0 -8
- package/src/icons/move.tsx +0 -5
- package/src/icons/number.tsx +0 -7
- package/src/icons/outline.tsx +0 -5
- package/src/icons/page.tsx +0 -9
- package/src/icons/pc.tsx +0 -7
- package/src/icons/play.tsx +0 -8
- package/src/icons/position.tsx +0 -30
- package/src/icons/pushpin.tsx +0 -29
- package/src/icons/recover.tsx +0 -5
- package/src/icons/redo.tsx +0 -5
- package/src/icons/remove.tsx +0 -5
- package/src/icons/responsive.tsx +0 -9
- package/src/icons/return.tsx +0 -5
- package/src/icons/selection.tsx +0 -5
- package/src/icons/setting.tsx +0 -5
- package/src/icons/shadow.tsx +0 -20
- package/src/icons/shift.tsx +0 -5
- package/src/icons/sources.tsx +0 -3377
- package/src/icons/text.tsx +0 -13
- package/src/icons/undo.tsx +0 -7
- package/src/icons/upload.tsx +0 -8
- package/src/index.ts +0 -9
- package/src/locales/global.ts +0 -16
- package/src/locales/icons.ts +0 -132
- package/src/locales/index.ts +0 -7
- package/src/locales/operations.ts +0 -50
- package/src/locales/panels.ts +0 -26
- package/src/panels/CompositePanel.tsx +0 -195
- package/src/panels/SettingsPanel.tsx +0 -85
- package/src/panels/StudioPanel.tsx +0 -54
- package/src/panels/ToolbarPanel.tsx +0 -19
- package/src/panels/ViewPanel.tsx +0 -62
- package/src/panels/ViewportPanel.tsx +0 -10
- package/src/panels/WorkspacePanel.tsx +0 -31
- package/src/panels/index.ts +0 -8
- package/src/panels/styles.less +0 -331
- package/src/simulators/MobileSimulator/body.tsx +0 -78
- package/src/simulators/MobileSimulator/index.tsx +0 -21
- package/src/simulators/MobileSimulator/styles.less +0 -29
- package/src/simulators/PCSimulator/index.tsx +0 -17
- package/src/simulators/PCSimulator/styles.less +0 -11
- package/src/simulators/ResponsiveSimulator/handle.tsx +0 -29
- package/src/simulators/ResponsiveSimulator/index.tsx +0 -193
- package/src/simulators/ResponsiveSimulator/styles.less +0 -56
- package/src/simulators/index.tsx +0 -3
- package/src/theme.less +0 -224
- package/src/types.ts +0 -41
- package/src/variables.less +0 -1
- package/src/widgets/AuxToolWidget/Copy.tsx +0 -28
- package/src/widgets/AuxToolWidget/Cover.tsx +0 -76
- package/src/widgets/AuxToolWidget/DashedBox.tsx +0 -55
- package/src/widgets/AuxToolWidget/Delete.tsx +0 -29
- package/src/widgets/AuxToolWidget/DragHandler.tsx +0 -29
- package/src/widgets/AuxToolWidget/FreeSelection.tsx +0 -53
- package/src/widgets/AuxToolWidget/Helpers.tsx +0 -116
- package/src/widgets/AuxToolWidget/Insertion.tsx +0 -80
- package/src/widgets/AuxToolWidget/ResizeHandler.tsx +0 -35
- package/src/widgets/AuxToolWidget/Selection.tsx +0 -85
- package/src/widgets/AuxToolWidget/Selector.tsx +0 -125
- package/src/widgets/AuxToolWidget/SnapLine.tsx +0 -40
- package/src/widgets/AuxToolWidget/SpaceBlock.tsx +0 -112
- package/src/widgets/AuxToolWidget/TranslateHandler.tsx +0 -29
- package/src/widgets/AuxToolWidget/index.tsx +0 -40
- package/src/widgets/AuxToolWidget/styles.less +0 -383
- package/src/widgets/ComponentTreeWidget/index.tsx +0 -99
- package/src/widgets/ComponentTreeWidget/styles.less +0 -6
- package/src/widgets/DesignerToolsWidget/index.tsx +0 -206
- package/src/widgets/DesignerToolsWidget/styles.less +0 -29
- package/src/widgets/DroppableWidget/index.tsx +0 -63
- package/src/widgets/DroppableWidget/styles.less +0 -11
- package/src/widgets/EmptyWidget/index.tsx +0 -58
- package/src/widgets/EmptyWidget/styles.less +0 -27
- package/src/widgets/GhostWidget/index.tsx +0 -47
- package/src/widgets/GhostWidget/styles.less +0 -20
- package/src/widgets/HistoryWidget/index.tsx +0 -42
- package/src/widgets/HistoryWidget/styles.less +0 -23
- package/src/widgets/IconWidget/index.tsx +0 -152
- package/src/widgets/IconWidget/styles.less +0 -17
- package/src/widgets/NodeActionsWidget/index.tsx +0 -56
- package/src/widgets/NodeActionsWidget/styles.less +0 -51
- package/src/widgets/NodePathWidget/index.tsx +0 -57
- package/src/widgets/NodePathWidget/styles.less +0 -16
- package/src/widgets/NodeTitleWidget/index.tsx +0 -20
- package/src/widgets/OutlineWidget/Insertion.tsx +0 -63
- package/src/widgets/OutlineWidget/OutlineNode.tsx +0 -198
- package/src/widgets/OutlineWidget/context.ts +0 -9
- package/src/widgets/OutlineWidget/index.tsx +0 -66
- package/src/widgets/OutlineWidget/styles.less +0 -195
- package/src/widgets/ResourceWidget/index.tsx +0 -110
- package/src/widgets/ResourceWidget/styles.less +0 -87
- package/src/widgets/TextWidget/index.tsx +0 -43
- package/src/widgets/ViewToolsWidget/index.tsx +0 -72
- package/src/widgets/index.ts +0 -15
- package/tsconfig.build.json +0 -10
- package/tsconfig.json +0 -5
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import React from 'react'
|
|
2
|
-
import { TreeNode } from '@formily-design/core'
|
|
3
|
-
import { IconWidget } from '../IconWidget'
|
|
4
|
-
import { usePrefix } from '../../hooks'
|
|
5
|
-
import { Button } from 'antd'
|
|
6
|
-
|
|
7
|
-
export interface IDeleteProps {
|
|
8
|
-
node: TreeNode
|
|
9
|
-
style?: React.CSSProperties
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export const Delete: React.FC<IDeleteProps> = ({ node, style }) => {
|
|
13
|
-
const prefix = usePrefix('aux-copy')
|
|
14
|
-
if (node === node.root) return null
|
|
15
|
-
return (
|
|
16
|
-
<Button
|
|
17
|
-
className={prefix}
|
|
18
|
-
style={style}
|
|
19
|
-
type="primary"
|
|
20
|
-
onClick={() => {
|
|
21
|
-
TreeNode.remove([node])
|
|
22
|
-
}}
|
|
23
|
-
>
|
|
24
|
-
<IconWidget infer="Remove" />
|
|
25
|
-
</Button>
|
|
26
|
-
)
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
Delete.displayName = 'Delete'
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import React from 'react'
|
|
2
|
-
import { TreeNode } from '@formily-design/core'
|
|
3
|
-
import { observer } from '@formily/reactive-react'
|
|
4
|
-
import { IconWidget } from '../IconWidget'
|
|
5
|
-
import { useDesigner, usePrefix } from '../../hooks'
|
|
6
|
-
import { Button } from 'antd'
|
|
7
|
-
|
|
8
|
-
export interface IDragHandlerProps {
|
|
9
|
-
node: TreeNode
|
|
10
|
-
style?: React.CSSProperties
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export const DragHandler: React.FC<IDragHandlerProps> = observer(
|
|
14
|
-
({ node, style }) => {
|
|
15
|
-
const designer = useDesigner()
|
|
16
|
-
const prefix = usePrefix('aux-drag-handler')
|
|
17
|
-
if (node === node.root || !node.allowDrag()) return null
|
|
18
|
-
const handlerProps = {
|
|
19
|
-
[designer.props.nodeDragHandlerAttrName]: 'true',
|
|
20
|
-
}
|
|
21
|
-
return (
|
|
22
|
-
<Button {...handlerProps} className={prefix} style={style} type="primary">
|
|
23
|
-
<IconWidget infer="Move" />
|
|
24
|
-
</Button>
|
|
25
|
-
)
|
|
26
|
-
}
|
|
27
|
-
)
|
|
28
|
-
|
|
29
|
-
DragHandler.displayName = 'DragHandler'
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import React from 'react'
|
|
2
|
-
import { useCursor, usePrefix, useViewport, useOperation } from '../../hooks'
|
|
3
|
-
import { observer } from '@formily/reactive-react'
|
|
4
|
-
import { CursorDragType, CursorStatus } from '@formily-design/core'
|
|
5
|
-
import { calcRectByStartEndPoint } from '@formily-design/shared'
|
|
6
|
-
import cls from 'classnames'
|
|
7
|
-
|
|
8
|
-
export const FreeSelection = observer(() => {
|
|
9
|
-
const cursor = useCursor()
|
|
10
|
-
const viewport = useViewport()
|
|
11
|
-
const operation = useOperation()
|
|
12
|
-
const prefix = usePrefix('aux-free-selection')
|
|
13
|
-
const createSelectionStyle = () => {
|
|
14
|
-
const startDragPoint = viewport.getOffsetPoint({
|
|
15
|
-
x: cursor.dragStartPosition.topClientX,
|
|
16
|
-
y: cursor.dragStartPosition.topClientY,
|
|
17
|
-
})
|
|
18
|
-
const currentPoint = viewport.getOffsetPoint({
|
|
19
|
-
x: cursor.position.topClientX,
|
|
20
|
-
y: cursor.position.topClientY,
|
|
21
|
-
})
|
|
22
|
-
const rect = calcRectByStartEndPoint(
|
|
23
|
-
startDragPoint,
|
|
24
|
-
currentPoint,
|
|
25
|
-
viewport.dragScrollXDelta,
|
|
26
|
-
viewport.dragScrollYDelta
|
|
27
|
-
)
|
|
28
|
-
const baseStyle: React.CSSProperties = {
|
|
29
|
-
position: 'absolute',
|
|
30
|
-
top: 0,
|
|
31
|
-
left: 0,
|
|
32
|
-
opacity: 0.2,
|
|
33
|
-
borderWidth: 1,
|
|
34
|
-
borderStyle: 'solid',
|
|
35
|
-
transform: `perspective(1px) translate3d(${rect.x}px,${rect.y}px,0)`,
|
|
36
|
-
height: rect.height,
|
|
37
|
-
width: rect.width,
|
|
38
|
-
pointerEvents: 'none',
|
|
39
|
-
boxSizing: 'border-box',
|
|
40
|
-
zIndex: 1,
|
|
41
|
-
}
|
|
42
|
-
return baseStyle
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
if (
|
|
46
|
-
operation.moveHelper.hasDragNodes ||
|
|
47
|
-
cursor.status !== CursorStatus.Dragging ||
|
|
48
|
-
cursor.dragType !== CursorDragType.Move
|
|
49
|
-
)
|
|
50
|
-
return null
|
|
51
|
-
|
|
52
|
-
return <div className={cls(prefix)} style={createSelectionStyle()}></div>
|
|
53
|
-
})
|
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
import React, { useRef, useState, useLayoutEffect } from 'react'
|
|
2
|
-
import { TreeNode } from '@formily-design/core'
|
|
3
|
-
import { reaction } from '@formily/reactive'
|
|
4
|
-
import { usePrefix, useViewport } from '../../hooks'
|
|
5
|
-
import { Selector } from './Selector'
|
|
6
|
-
import { Copy } from './Copy'
|
|
7
|
-
import { Delete } from './Delete'
|
|
8
|
-
import { DragHandler } from './DragHandler'
|
|
9
|
-
import cls from 'classnames'
|
|
10
|
-
|
|
11
|
-
const HELPER_DEBOUNCE_TIMEOUT = 100
|
|
12
|
-
|
|
13
|
-
export interface IHelpersProps {
|
|
14
|
-
node: TreeNode
|
|
15
|
-
nodeRect: DOMRect
|
|
16
|
-
}
|
|
17
|
-
export interface IViewportState {
|
|
18
|
-
viewportWidth?: number
|
|
19
|
-
viewportHeight?: number
|
|
20
|
-
viewportScrollX?: number
|
|
21
|
-
viewportScrollY?: number
|
|
22
|
-
viewportIsScrollTop?: boolean
|
|
23
|
-
viewportIsScrollBottom?: boolean
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export const Helpers: React.FC<IHelpersProps> = ({ node, nodeRect }) => {
|
|
27
|
-
const prefix = usePrefix('aux-helpers')
|
|
28
|
-
const viewport = useViewport()
|
|
29
|
-
const unmountRef = useRef(false)
|
|
30
|
-
const ref = useRef<HTMLDivElement>()
|
|
31
|
-
const [position, setPosition] = useState('top-right')
|
|
32
|
-
|
|
33
|
-
useLayoutEffect(() => {
|
|
34
|
-
let request = null
|
|
35
|
-
|
|
36
|
-
const getYInViewport = (nodeRect: DOMRect, helpersRect: DOMRect) => {
|
|
37
|
-
if (nodeRect.top - viewport.scrollY > helpersRect.height) {
|
|
38
|
-
return 'top'
|
|
39
|
-
} else if (
|
|
40
|
-
viewport.isScrollTop &&
|
|
41
|
-
nodeRect.height + helpersRect.height > viewport.height
|
|
42
|
-
) {
|
|
43
|
-
return 'inner-top'
|
|
44
|
-
} else if (
|
|
45
|
-
nodeRect.bottom >= viewport.scrollY + viewport.height &&
|
|
46
|
-
nodeRect.height + helpersRect.height > viewport.height
|
|
47
|
-
) {
|
|
48
|
-
return 'inner-bottom'
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
return 'bottom'
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
const getXInViewport = (nodeRect: DOMRect, helpersRect: DOMRect) => {
|
|
55
|
-
const widthDelta = helpersRect.width - nodeRect.width
|
|
56
|
-
if (widthDelta >= 0) {
|
|
57
|
-
if (nodeRect.x < widthDelta) {
|
|
58
|
-
return 'left'
|
|
59
|
-
} else if (nodeRect.right + widthDelta > viewport.width) {
|
|
60
|
-
return 'right'
|
|
61
|
-
} else {
|
|
62
|
-
return 'center'
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
return 'right'
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
const update = () => {
|
|
69
|
-
const helpersRect = ref.current?.getBoundingClientRect()
|
|
70
|
-
if (!helpersRect || !nodeRect) return
|
|
71
|
-
if (unmountRef.current) return
|
|
72
|
-
setPosition(
|
|
73
|
-
getYInViewport(nodeRect, helpersRect) +
|
|
74
|
-
'-' +
|
|
75
|
-
getXInViewport(nodeRect, helpersRect)
|
|
76
|
-
)
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
update()
|
|
80
|
-
|
|
81
|
-
return reaction(
|
|
82
|
-
() => [
|
|
83
|
-
viewport.width,
|
|
84
|
-
viewport.height,
|
|
85
|
-
viewport.scrollX,
|
|
86
|
-
viewport.scrollY,
|
|
87
|
-
viewport.isScrollBottom,
|
|
88
|
-
viewport.isScrollTop,
|
|
89
|
-
],
|
|
90
|
-
() => {
|
|
91
|
-
clearTimeout(request)
|
|
92
|
-
request = setTimeout(update, HELPER_DEBOUNCE_TIMEOUT)
|
|
93
|
-
}
|
|
94
|
-
)
|
|
95
|
-
}, [viewport, nodeRect])
|
|
96
|
-
|
|
97
|
-
if (!nodeRect || !node) return null
|
|
98
|
-
|
|
99
|
-
return (
|
|
100
|
-
<div
|
|
101
|
-
className={cls(prefix, {
|
|
102
|
-
[position]: true,
|
|
103
|
-
})}
|
|
104
|
-
ref={ref}
|
|
105
|
-
>
|
|
106
|
-
<div className={cls(prefix + '-content')}>
|
|
107
|
-
<Selector node={node} />
|
|
108
|
-
{node?.allowClone() === false ? null : <Copy node={node} />}
|
|
109
|
-
{node?.allowDrag() === false ? null : <DragHandler node={node} />}
|
|
110
|
-
{node?.allowDelete() === false ? null : <Delete node={node} />}
|
|
111
|
-
</div>
|
|
112
|
-
</div>
|
|
113
|
-
)
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
Helpers.displayName = 'Helpers'
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import React from 'react'
|
|
2
|
-
import { useMoveHelper, usePrefix } from '../../hooks'
|
|
3
|
-
import { ClosestPosition } from '@formily-design/core'
|
|
4
|
-
import { observer } from '@formily/reactive-react'
|
|
5
|
-
|
|
6
|
-
export const Insertion = observer(() => {
|
|
7
|
-
const moveHelper = useMoveHelper()
|
|
8
|
-
const prefix = usePrefix('aux-insertion')
|
|
9
|
-
const createInsertionStyle = (): React.CSSProperties => {
|
|
10
|
-
const closestDirection = moveHelper.viewportClosestDirection
|
|
11
|
-
const closestRect = moveHelper.viewportClosestOffsetRect
|
|
12
|
-
const isInlineLayout = moveHelper.closestNode?.moveLayout === 'horizontal'
|
|
13
|
-
const baseStyle: React.CSSProperties = {
|
|
14
|
-
position: 'absolute',
|
|
15
|
-
transform: 'perspective(1px) translate3d(0,0,0)',
|
|
16
|
-
top: 0,
|
|
17
|
-
left: 0,
|
|
18
|
-
}
|
|
19
|
-
if (!closestRect) return baseStyle
|
|
20
|
-
if (
|
|
21
|
-
closestDirection === ClosestPosition.Before ||
|
|
22
|
-
closestDirection === ClosestPosition.ForbidBefore
|
|
23
|
-
) {
|
|
24
|
-
baseStyle.width = 2
|
|
25
|
-
baseStyle.height = closestRect.height
|
|
26
|
-
baseStyle.transform = `perspective(1px) translate3d(${closestRect.x}px,${closestRect.y}px,0)`
|
|
27
|
-
} else if (
|
|
28
|
-
closestDirection === ClosestPosition.After ||
|
|
29
|
-
closestDirection === ClosestPosition.ForbidAfter
|
|
30
|
-
) {
|
|
31
|
-
baseStyle.width = 2
|
|
32
|
-
baseStyle.height = closestRect.height
|
|
33
|
-
baseStyle.transform = `perspective(1px) translate3d(${
|
|
34
|
-
closestRect.x + closestRect.width - 2
|
|
35
|
-
}px,${closestRect.y}px,0)`
|
|
36
|
-
} else if (
|
|
37
|
-
closestDirection === ClosestPosition.InnerAfter ||
|
|
38
|
-
closestDirection === ClosestPosition.Under ||
|
|
39
|
-
closestDirection === ClosestPosition.ForbidInnerAfter ||
|
|
40
|
-
closestDirection === ClosestPosition.ForbidUnder
|
|
41
|
-
) {
|
|
42
|
-
if (isInlineLayout) {
|
|
43
|
-
baseStyle.width = 2
|
|
44
|
-
baseStyle.height = closestRect.height
|
|
45
|
-
baseStyle.transform = `perspective(1px) translate3d(${
|
|
46
|
-
closestRect.x + closestRect.width - 2
|
|
47
|
-
}px,${closestRect.y}px,0)`
|
|
48
|
-
} else {
|
|
49
|
-
baseStyle.width = closestRect.width
|
|
50
|
-
baseStyle.height = 2
|
|
51
|
-
baseStyle.transform = `perspective(1px) translate3d(${
|
|
52
|
-
closestRect.x
|
|
53
|
-
}px,${closestRect.y + closestRect.height - 2}px,0)`
|
|
54
|
-
}
|
|
55
|
-
} else if (
|
|
56
|
-
closestDirection === ClosestPosition.InnerBefore ||
|
|
57
|
-
closestDirection === ClosestPosition.Upper ||
|
|
58
|
-
closestDirection === ClosestPosition.ForbidInnerBefore ||
|
|
59
|
-
closestDirection === ClosestPosition.ForbidUpper
|
|
60
|
-
) {
|
|
61
|
-
if (isInlineLayout) {
|
|
62
|
-
baseStyle.width = 2
|
|
63
|
-
baseStyle.height = closestRect.height
|
|
64
|
-
baseStyle.transform = `perspective(1px) translate3d(${closestRect.x}px,${closestRect.y}px,0)`
|
|
65
|
-
} else {
|
|
66
|
-
baseStyle.width = closestRect.width
|
|
67
|
-
baseStyle.height = 2
|
|
68
|
-
baseStyle.transform = `perspective(1px) translate3d(${closestRect.x}px,${closestRect.y}px,0)`
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
if (closestDirection.includes('FORBID')) {
|
|
72
|
-
baseStyle.backgroundColor = 'red'
|
|
73
|
-
}
|
|
74
|
-
return baseStyle
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
return <div className={prefix} style={createInsertionStyle()}></div>
|
|
78
|
-
})
|
|
79
|
-
|
|
80
|
-
Insertion.displayName = 'Insertion'
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import React from 'react'
|
|
2
|
-
import cls from 'classnames'
|
|
3
|
-
import { useDesigner, usePrefix } from '../../hooks'
|
|
4
|
-
import { TreeNode } from '@formily-design/core'
|
|
5
|
-
|
|
6
|
-
export interface IResizeHandlerProps {
|
|
7
|
-
node: TreeNode
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export const ResizeHandler: React.FC<IResizeHandlerProps> = (props) => {
|
|
11
|
-
const designer = useDesigner()
|
|
12
|
-
const prefix = usePrefix('aux-node-resize-handler')
|
|
13
|
-
const createHandler = (value: string) => {
|
|
14
|
-
return {
|
|
15
|
-
[designer.props.nodeResizeHandlerAttrName]: value,
|
|
16
|
-
className: cls(prefix, value),
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
const allowResize = props.node.allowResize()
|
|
20
|
-
if (!allowResize) return null
|
|
21
|
-
const allowX = allowResize.includes('x')
|
|
22
|
-
const allowY = allowResize.includes('y')
|
|
23
|
-
return (
|
|
24
|
-
<>
|
|
25
|
-
{allowX && <div {...createHandler('left-center')}></div>}
|
|
26
|
-
{allowX && <div {...createHandler('right-center')}></div>}
|
|
27
|
-
{allowY && <div {...createHandler('center-top')}></div>}
|
|
28
|
-
{allowY && <div {...createHandler('center-bottom')}></div>}
|
|
29
|
-
{allowX && allowY && <div {...createHandler('left-top')}></div>}
|
|
30
|
-
{allowY && allowY && <div {...createHandler('right-top')}></div>}
|
|
31
|
-
{allowX && allowY && <div {...createHandler('left-bottom')}></div>}
|
|
32
|
-
{allowY && allowY && <div {...createHandler('right-bottom')}></div>}
|
|
33
|
-
</>
|
|
34
|
-
)
|
|
35
|
-
}
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
import React, { Fragment } from 'react'
|
|
2
|
-
import { Helpers } from './Helpers'
|
|
3
|
-
import { ResizeHandler } from './ResizeHandler'
|
|
4
|
-
import {
|
|
5
|
-
useSelection,
|
|
6
|
-
useValidNodeOffsetRect,
|
|
7
|
-
useTree,
|
|
8
|
-
useCursor,
|
|
9
|
-
useMoveHelper,
|
|
10
|
-
usePrefix,
|
|
11
|
-
useDesigner,
|
|
12
|
-
} from '../../hooks'
|
|
13
|
-
import { observer } from '@formily/reactive-react'
|
|
14
|
-
import { TreeNode } from '@formily-design/core'
|
|
15
|
-
import { TranslateHandler } from './TranslateHandler'
|
|
16
|
-
export interface ISelectionBoxProps {
|
|
17
|
-
node: TreeNode
|
|
18
|
-
showHelpers: boolean
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export const SelectionBox: React.FC<ISelectionBoxProps> = (props) => {
|
|
22
|
-
const designer = useDesigner()
|
|
23
|
-
const prefix = usePrefix('aux-selection-box')
|
|
24
|
-
const innerPrefix = usePrefix('aux-selection-box-inner')
|
|
25
|
-
const nodeRect = useValidNodeOffsetRect(props.node)
|
|
26
|
-
const createSelectionStyle = () => {
|
|
27
|
-
const baseStyle: React.CSSProperties = {
|
|
28
|
-
position: 'absolute',
|
|
29
|
-
top: 0,
|
|
30
|
-
left: 0,
|
|
31
|
-
boxSizing: 'border-box',
|
|
32
|
-
zIndex: 4,
|
|
33
|
-
}
|
|
34
|
-
if (nodeRect) {
|
|
35
|
-
baseStyle.transform = `perspective(1px) translate3d(${nodeRect.x}px,${nodeRect.y}px,0)`
|
|
36
|
-
baseStyle.height = nodeRect.height
|
|
37
|
-
baseStyle.width = nodeRect.width
|
|
38
|
-
}
|
|
39
|
-
return baseStyle
|
|
40
|
-
}
|
|
41
|
-
if (!nodeRect) return null
|
|
42
|
-
|
|
43
|
-
if (!nodeRect.width || !nodeRect.height) return null
|
|
44
|
-
|
|
45
|
-
const selectionId = {
|
|
46
|
-
[designer.props?.nodeSelectionIdAttrName]: props.node.id,
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
return (
|
|
50
|
-
<div {...selectionId} className={prefix} style={createSelectionStyle()}>
|
|
51
|
-
<div className={innerPrefix}></div>
|
|
52
|
-
<ResizeHandler node={props.node} />
|
|
53
|
-
<TranslateHandler node={props.node} />
|
|
54
|
-
{props.showHelpers && (
|
|
55
|
-
<Helpers {...props} node={props.node} nodeRect={nodeRect} />
|
|
56
|
-
)}
|
|
57
|
-
</div>
|
|
58
|
-
)
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
export const Selection = observer(() => {
|
|
62
|
-
const selection = useSelection()
|
|
63
|
-
const tree = useTree()
|
|
64
|
-
const cursor = useCursor()
|
|
65
|
-
const viewportMoveHelper = useMoveHelper()
|
|
66
|
-
if (cursor.status !== 'NORMAL' && viewportMoveHelper.touchNode) return null
|
|
67
|
-
return (
|
|
68
|
-
<Fragment>
|
|
69
|
-
{selection.selected.map((id) => {
|
|
70
|
-
const node = tree.findById(id)
|
|
71
|
-
if (!node) return
|
|
72
|
-
if (node.hidden) return
|
|
73
|
-
return (
|
|
74
|
-
<SelectionBox
|
|
75
|
-
key={id}
|
|
76
|
-
node={node}
|
|
77
|
-
showHelpers={selection.selected.length === 1}
|
|
78
|
-
/>
|
|
79
|
-
)
|
|
80
|
-
})}
|
|
81
|
-
</Fragment>
|
|
82
|
-
)
|
|
83
|
-
})
|
|
84
|
-
|
|
85
|
-
Selection.displayName = 'Selection'
|
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
import React, { useEffect, useState, useRef } from 'react'
|
|
2
|
-
import { TreeNode } from '@formily-design/core'
|
|
3
|
-
import { useHover, useSelection, usePrefix } from '../../hooks'
|
|
4
|
-
import { IconWidget } from '../IconWidget'
|
|
5
|
-
import { NodeTitleWidget } from '../NodeTitleWidget'
|
|
6
|
-
import { Button } from 'antd'
|
|
7
|
-
import { observer } from '@formily/reactive-react'
|
|
8
|
-
|
|
9
|
-
const useMouseHover = <T extends { current: HTMLElement }>(
|
|
10
|
-
ref: T,
|
|
11
|
-
enter?: () => void,
|
|
12
|
-
leave?: () => void
|
|
13
|
-
) => {
|
|
14
|
-
useEffect(() => {
|
|
15
|
-
let timer = null
|
|
16
|
-
let unmounted = false
|
|
17
|
-
const onMouseOver = (e: MouseEvent) => {
|
|
18
|
-
const target: HTMLElement = e.target as any
|
|
19
|
-
clearTimeout(timer)
|
|
20
|
-
timer = setTimeout(() => {
|
|
21
|
-
if (unmounted) return
|
|
22
|
-
if (ref?.current?.contains(target)) {
|
|
23
|
-
enter && enter()
|
|
24
|
-
} else {
|
|
25
|
-
leave && leave()
|
|
26
|
-
}
|
|
27
|
-
}, 100)
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
document.addEventListener('mouseover', onMouseOver)
|
|
31
|
-
return () => {
|
|
32
|
-
unmounted = true
|
|
33
|
-
document.removeEventListener('mouseover', onMouseOver)
|
|
34
|
-
}
|
|
35
|
-
}, [])
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export interface ISelectorProps {
|
|
39
|
-
node: TreeNode
|
|
40
|
-
style?: React.CSSProperties
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export const Selector: React.FC<ISelectorProps> = observer(({ node }) => {
|
|
44
|
-
const hover = useHover()
|
|
45
|
-
const [expand, setExpand] = useState(false)
|
|
46
|
-
const ref = useRef<HTMLDivElement>(null)
|
|
47
|
-
const selection = useSelection()
|
|
48
|
-
const prefix = usePrefix('aux-selector')
|
|
49
|
-
const renderIcon = (node: TreeNode) => {
|
|
50
|
-
const icon = node.designerProps.icon
|
|
51
|
-
if (icon) {
|
|
52
|
-
return <IconWidget infer={icon} />
|
|
53
|
-
}
|
|
54
|
-
if (node === node.root) {
|
|
55
|
-
return <IconWidget infer="Page" />
|
|
56
|
-
} else if (node.designerProps?.droppable) {
|
|
57
|
-
return <IconWidget infer="Container" />
|
|
58
|
-
}
|
|
59
|
-
return <IconWidget infer="Component" />
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
const renderMenu = () => {
|
|
63
|
-
const parents = node.getParents()
|
|
64
|
-
return (
|
|
65
|
-
<div
|
|
66
|
-
className={prefix + '-menu'}
|
|
67
|
-
style={{
|
|
68
|
-
position: 'absolute',
|
|
69
|
-
top: '100%',
|
|
70
|
-
left: 0,
|
|
71
|
-
}}
|
|
72
|
-
>
|
|
73
|
-
{parents.slice(0, 4).map((parent) => {
|
|
74
|
-
return (
|
|
75
|
-
<Button
|
|
76
|
-
key={parent.id}
|
|
77
|
-
type="primary"
|
|
78
|
-
onClick={() => {
|
|
79
|
-
selection.select(parent.id)
|
|
80
|
-
}}
|
|
81
|
-
onMouseEnter={() => {
|
|
82
|
-
hover.setHover(parent)
|
|
83
|
-
}}
|
|
84
|
-
>
|
|
85
|
-
{renderIcon(parent)}
|
|
86
|
-
<span style={{ transform: 'scale(0.85)', marginLeft: 2 }}>
|
|
87
|
-
<NodeTitleWidget node={parent} />
|
|
88
|
-
</span>
|
|
89
|
-
</Button>
|
|
90
|
-
)
|
|
91
|
-
})}
|
|
92
|
-
</div>
|
|
93
|
-
)
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
useMouseHover(
|
|
97
|
-
ref,
|
|
98
|
-
() => {
|
|
99
|
-
setExpand(true)
|
|
100
|
-
},
|
|
101
|
-
() => {
|
|
102
|
-
setExpand(false)
|
|
103
|
-
}
|
|
104
|
-
)
|
|
105
|
-
|
|
106
|
-
return (
|
|
107
|
-
<div ref={ref} className={prefix}>
|
|
108
|
-
<Button
|
|
109
|
-
className={prefix + '-title'}
|
|
110
|
-
type="primary"
|
|
111
|
-
onMouseEnter={() => {
|
|
112
|
-
hover.setHover(node)
|
|
113
|
-
}}
|
|
114
|
-
>
|
|
115
|
-
{renderIcon(node)}
|
|
116
|
-
<span>
|
|
117
|
-
<NodeTitleWidget node={node} />
|
|
118
|
-
</span>
|
|
119
|
-
</Button>
|
|
120
|
-
{expand && renderMenu()}
|
|
121
|
-
</div>
|
|
122
|
-
)
|
|
123
|
-
})
|
|
124
|
-
|
|
125
|
-
Selector.displayName = 'Selector'
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import React from 'react'
|
|
2
|
-
import { useTransformHelper, useCursor, usePrefix } from '../../hooks'
|
|
3
|
-
import { observer } from '@formily/reactive-react'
|
|
4
|
-
import { CursorStatus } from '@formily-design/core'
|
|
5
|
-
|
|
6
|
-
export const SnapLine = observer(() => {
|
|
7
|
-
const cursor = useCursor()
|
|
8
|
-
const transformHelper = useTransformHelper()
|
|
9
|
-
const prefix = usePrefix('aux-snap-line')
|
|
10
|
-
const createLineStyle = (rect: DOMRect) => {
|
|
11
|
-
const baseStyle: React.CSSProperties = {
|
|
12
|
-
top: 0,
|
|
13
|
-
left: 0,
|
|
14
|
-
height: rect.height || 1,
|
|
15
|
-
width: rect.width || 1,
|
|
16
|
-
transform: `perspective(1px) translate3d(${rect.x}px,${rect.y}px,0)`,
|
|
17
|
-
background: `#b0b1f3`,
|
|
18
|
-
position: 'absolute',
|
|
19
|
-
zIndex: 2,
|
|
20
|
-
}
|
|
21
|
-
return baseStyle
|
|
22
|
-
}
|
|
23
|
-
if (cursor.status !== CursorStatus.Dragging) return null
|
|
24
|
-
return (
|
|
25
|
-
<>
|
|
26
|
-
{transformHelper.closestSnapLines.map((line: any, key) => {
|
|
27
|
-
if (line.type !== 'normal') return null
|
|
28
|
-
return (
|
|
29
|
-
<div
|
|
30
|
-
key={key}
|
|
31
|
-
className={prefix}
|
|
32
|
-
style={createLineStyle(line.rect)}
|
|
33
|
-
></div>
|
|
34
|
-
)
|
|
35
|
-
})}
|
|
36
|
-
</>
|
|
37
|
-
)
|
|
38
|
-
})
|
|
39
|
-
|
|
40
|
-
SnapLine.displayName = 'SnapLine'
|