@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,17 +0,0 @@
|
|
|
1
|
-
@import '../../variables.less';
|
|
2
|
-
|
|
3
|
-
.@{prefix-cls}-icon {
|
|
4
|
-
display: inline-block;
|
|
5
|
-
color: inherit;
|
|
6
|
-
font-style: normal;
|
|
7
|
-
line-height: 0;
|
|
8
|
-
text-align: center;
|
|
9
|
-
text-transform: none;
|
|
10
|
-
vertical-align: -0.125em;
|
|
11
|
-
text-rendering: optimizeLegibility;
|
|
12
|
-
-webkit-font-smoothing: antialiased;
|
|
13
|
-
-moz-osx-font-smoothing: grayscale;
|
|
14
|
-
svg {
|
|
15
|
-
pointer-events: none;
|
|
16
|
-
}
|
|
17
|
-
}
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import React from 'react'
|
|
2
|
-
import { Space, Typography, Divider, TypographyProps } from 'antd'
|
|
3
|
-
import { observer } from '@formily/reactive-react'
|
|
4
|
-
import { usePrefix, useTreeNode, useSelected } from '../../hooks'
|
|
5
|
-
import { IconWidget } from '../IconWidget'
|
|
6
|
-
import { TextWidget } from '../TextWidget'
|
|
7
|
-
import cls from 'classnames'
|
|
8
|
-
import './styles.less'
|
|
9
|
-
|
|
10
|
-
export interface INodeActionsWidgetProps {
|
|
11
|
-
children?: React.ReactNode
|
|
12
|
-
className?: string
|
|
13
|
-
style?: React.CSSProperties
|
|
14
|
-
activeShown?: boolean
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export interface INodeActionsWidgetActionProps
|
|
18
|
-
extends Omit<React.ComponentProps<'a'>, 'title' | 'type' | 'ref'>,
|
|
19
|
-
Partial<TypographyProps['Link']> {
|
|
20
|
-
className?: string
|
|
21
|
-
style?: React.CSSProperties
|
|
22
|
-
title: React.ReactNode
|
|
23
|
-
icon?: React.ReactNode
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export const NodeActionsWidget: React.FC<INodeActionsWidgetProps> & {
|
|
27
|
-
Action?: React.FC<INodeActionsWidgetActionProps>
|
|
28
|
-
} = observer((props) => {
|
|
29
|
-
const node = useTreeNode()
|
|
30
|
-
const prefix = usePrefix('node-actions')
|
|
31
|
-
const selected = useSelected()
|
|
32
|
-
if (selected.indexOf(node.id) === -1 && props.activeShown) return null
|
|
33
|
-
return (
|
|
34
|
-
<div className={cls(prefix, props.className)} style={props.style}>
|
|
35
|
-
<div className={prefix + '-content'}>
|
|
36
|
-
<Space split={<Divider type="vertical" />}>{props.children}</Space>
|
|
37
|
-
</div>
|
|
38
|
-
</div>
|
|
39
|
-
)
|
|
40
|
-
})
|
|
41
|
-
|
|
42
|
-
NodeActionsWidget.Action = ({ icon, title, ...props }) => {
|
|
43
|
-
const prefix = usePrefix('node-actions-item')
|
|
44
|
-
return (
|
|
45
|
-
<Typography.Link
|
|
46
|
-
{...props}
|
|
47
|
-
className={cls(props.className, prefix)}
|
|
48
|
-
data-click-stop-propagation="true"
|
|
49
|
-
>
|
|
50
|
-
<span className={prefix + '-text'}>
|
|
51
|
-
<IconWidget infer={icon} />
|
|
52
|
-
<TextWidget>{title}</TextWidget>
|
|
53
|
-
</span>
|
|
54
|
-
</Typography.Link>
|
|
55
|
-
)
|
|
56
|
-
}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
.dn-node-actions {
|
|
2
|
-
display: flex;
|
|
3
|
-
align-items: center;
|
|
4
|
-
justify-content: center;
|
|
5
|
-
width: 100%;
|
|
6
|
-
overflow: hidden;
|
|
7
|
-
padding-top: 8px;
|
|
8
|
-
padding-bottom: 8px;
|
|
9
|
-
&-content {
|
|
10
|
-
position: relative;
|
|
11
|
-
padding: 0 20px;
|
|
12
|
-
display: flex;
|
|
13
|
-
align-items: center;
|
|
14
|
-
line-height: 1;
|
|
15
|
-
&::before {
|
|
16
|
-
position: absolute;
|
|
17
|
-
content: '';
|
|
18
|
-
display: block;
|
|
19
|
-
height: 0;
|
|
20
|
-
width: 300%;
|
|
21
|
-
top: 50%;
|
|
22
|
-
border-bottom: 1px dashed #d9d9d9;
|
|
23
|
-
right: 100%;
|
|
24
|
-
}
|
|
25
|
-
&::after {
|
|
26
|
-
position: absolute;
|
|
27
|
-
content: '';
|
|
28
|
-
display: block;
|
|
29
|
-
height: 0;
|
|
30
|
-
width: 300%;
|
|
31
|
-
top: 50%;
|
|
32
|
-
border-bottom: 1px dashed #d9d9d9;
|
|
33
|
-
left: 100%;
|
|
34
|
-
}
|
|
35
|
-
a {
|
|
36
|
-
&:hover {
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
&-item {
|
|
41
|
-
&-text {
|
|
42
|
-
font-size: 10px;
|
|
43
|
-
display: flex;
|
|
44
|
-
align-items: center;
|
|
45
|
-
line-height: 1;
|
|
46
|
-
.dn-icon {
|
|
47
|
-
margin-right: 6px;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
}
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import React from 'react'
|
|
2
|
-
import { Breadcrumb } from 'antd'
|
|
3
|
-
import { useSelectedNode, useSelection, usePrefix, useHover } from '../../hooks'
|
|
4
|
-
import { IconWidget } from '../IconWidget'
|
|
5
|
-
import { NodeTitleWidget } from '../NodeTitleWidget'
|
|
6
|
-
import { observer } from '@formily/reactive-react'
|
|
7
|
-
import './styles.less'
|
|
8
|
-
|
|
9
|
-
export interface INodePathWidgetProps {
|
|
10
|
-
workspaceId?: string
|
|
11
|
-
maxItems?: number
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export const NodePathWidget: React.FC<INodePathWidgetProps> = observer(
|
|
15
|
-
(props) => {
|
|
16
|
-
const selected = useSelectedNode(props.workspaceId)
|
|
17
|
-
const selection = useSelection(props.workspaceId)
|
|
18
|
-
const hover = useHover(props.workspaceId)
|
|
19
|
-
const prefix = usePrefix('node-path')
|
|
20
|
-
if (!selected) return <React.Fragment />
|
|
21
|
-
const maxItems = props.maxItems ?? 3
|
|
22
|
-
const nodes = selected
|
|
23
|
-
.getParents()
|
|
24
|
-
.slice(0, maxItems - 1)
|
|
25
|
-
.reverse()
|
|
26
|
-
.concat(selected)
|
|
27
|
-
return (
|
|
28
|
-
<Breadcrumb
|
|
29
|
-
className={prefix}
|
|
30
|
-
items={nodes.map((node, key) => {
|
|
31
|
-
return {
|
|
32
|
-
title: (
|
|
33
|
-
<>
|
|
34
|
-
{key === 0 && (
|
|
35
|
-
<IconWidget infer="Position" style={{ marginRight: 3 }} />
|
|
36
|
-
)}
|
|
37
|
-
<a
|
|
38
|
-
href=""
|
|
39
|
-
onMouseEnter={() => {
|
|
40
|
-
hover.setHover(node)
|
|
41
|
-
}}
|
|
42
|
-
onClick={(e) => {
|
|
43
|
-
e.stopPropagation()
|
|
44
|
-
e.preventDefault()
|
|
45
|
-
selection.select(node)
|
|
46
|
-
}}
|
|
47
|
-
>
|
|
48
|
-
<NodeTitleWidget node={node} />
|
|
49
|
-
</a>
|
|
50
|
-
</>
|
|
51
|
-
),
|
|
52
|
-
}
|
|
53
|
-
})}
|
|
54
|
-
/>
|
|
55
|
-
)
|
|
56
|
-
}
|
|
57
|
-
)
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import React, { Fragment } from 'react'
|
|
2
|
-
import { observer } from '@formily/reactive-react'
|
|
3
|
-
import { TreeNode } from '@formily-design/core'
|
|
4
|
-
export interface INodeTitleWidgetProps {
|
|
5
|
-
node: TreeNode
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export const NodeTitleWidget: React.FC<INodeTitleWidgetProps> = observer(
|
|
9
|
-
(props) => {
|
|
10
|
-
const takeNode = () => {
|
|
11
|
-
const node = props.node
|
|
12
|
-
if (node.componentName === '$$ResourceNode$$') {
|
|
13
|
-
return node.children[0]
|
|
14
|
-
}
|
|
15
|
-
return node
|
|
16
|
-
}
|
|
17
|
-
const node = takeNode()
|
|
18
|
-
return <Fragment>{node.getMessage('title') || node.componentName}</Fragment>
|
|
19
|
-
}
|
|
20
|
-
)
|
|
@@ -1,63 +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 interface IInsertionProps {
|
|
7
|
-
workspaceId?: string
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export const Insertion: React.FC<IInsertionProps> = observer(
|
|
11
|
-
({ workspaceId }) => {
|
|
12
|
-
const moveHelper = useMoveHelper(workspaceId)
|
|
13
|
-
const prefix = usePrefix('outline-tree-insertion')
|
|
14
|
-
const createInsertionStyle = (): React.CSSProperties => {
|
|
15
|
-
const closestDirection = moveHelper.outlineClosestDirection
|
|
16
|
-
const closestRect = moveHelper.outlineClosestOffsetRect
|
|
17
|
-
const baseStyle: React.CSSProperties = {
|
|
18
|
-
position: 'absolute',
|
|
19
|
-
transform: 'perspective(1px) translate3d(0,0,0)',
|
|
20
|
-
top: 0,
|
|
21
|
-
left: 0,
|
|
22
|
-
}
|
|
23
|
-
if (!closestRect) return baseStyle
|
|
24
|
-
if (
|
|
25
|
-
closestDirection === ClosestPosition.After ||
|
|
26
|
-
closestDirection === ClosestPosition.InnerAfter ||
|
|
27
|
-
closestDirection === ClosestPosition.Under ||
|
|
28
|
-
closestDirection === ClosestPosition.ForbidAfter ||
|
|
29
|
-
closestDirection === ClosestPosition.ForbidInnerAfter ||
|
|
30
|
-
closestDirection === ClosestPosition.ForbidUnder
|
|
31
|
-
) {
|
|
32
|
-
baseStyle.width = closestRect.width
|
|
33
|
-
baseStyle.height = 2
|
|
34
|
-
baseStyle.transform = `perspective(1px) translate3d(${
|
|
35
|
-
closestRect.x
|
|
36
|
-
}px,${closestRect.y + closestRect.height - 2}px,0)`
|
|
37
|
-
} else if (
|
|
38
|
-
closestDirection === ClosestPosition.Before ||
|
|
39
|
-
closestDirection === ClosestPosition.InnerBefore ||
|
|
40
|
-
closestDirection === ClosestPosition.Upper ||
|
|
41
|
-
closestDirection === ClosestPosition.ForbidBefore ||
|
|
42
|
-
closestDirection === ClosestPosition.ForbidInnerBefore ||
|
|
43
|
-
closestDirection === ClosestPosition.ForbidUpper
|
|
44
|
-
) {
|
|
45
|
-
baseStyle.width = closestRect.width
|
|
46
|
-
baseStyle.height = 2
|
|
47
|
-
baseStyle.transform = `perspective(1px) translate3d(${closestRect.x}px,${closestRect.y}px,0)`
|
|
48
|
-
}
|
|
49
|
-
if (closestDirection.includes('FORBID')) {
|
|
50
|
-
baseStyle.backgroundColor = 'red'
|
|
51
|
-
} else {
|
|
52
|
-
baseStyle.backgroundColor = ''
|
|
53
|
-
}
|
|
54
|
-
return baseStyle
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
if (!moveHelper?.closestNode) return null
|
|
58
|
-
|
|
59
|
-
return <div className={prefix} style={createInsertionStyle()}></div>
|
|
60
|
-
}
|
|
61
|
-
)
|
|
62
|
-
|
|
63
|
-
Insertion.displayName = 'Insertion'
|
|
@@ -1,198 +0,0 @@
|
|
|
1
|
-
import React, { useRef, useContext, useEffect } from 'react'
|
|
2
|
-
import {
|
|
3
|
-
TreeNode,
|
|
4
|
-
ClosestPosition,
|
|
5
|
-
CursorStatus,
|
|
6
|
-
DragMoveEvent,
|
|
7
|
-
} from '@formily-design/core'
|
|
8
|
-
import { isFn } from '@formily-design/shared'
|
|
9
|
-
import { autorun } from '@formily/reactive'
|
|
10
|
-
import { observer } from '@formily/reactive-react'
|
|
11
|
-
import {
|
|
12
|
-
usePrefix,
|
|
13
|
-
useCursor,
|
|
14
|
-
useSelection,
|
|
15
|
-
useMoveHelper,
|
|
16
|
-
useDesigner,
|
|
17
|
-
} from '../../hooks'
|
|
18
|
-
import { IconWidget } from '../IconWidget'
|
|
19
|
-
import { NodeTitleWidget } from '../NodeTitleWidget'
|
|
20
|
-
import { NodeContext } from './context'
|
|
21
|
-
import cls from 'classnames'
|
|
22
|
-
import './styles.less'
|
|
23
|
-
export interface IOutlineTreeNodeProps {
|
|
24
|
-
node: TreeNode
|
|
25
|
-
style?: React.CSSProperties
|
|
26
|
-
className?: string
|
|
27
|
-
workspaceId?: string
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export const OutlineTreeNode: React.FC<IOutlineTreeNodeProps> = observer(
|
|
31
|
-
({ node, className, style, workspaceId }) => {
|
|
32
|
-
const prefix = usePrefix('outline-tree-node')
|
|
33
|
-
const engine = useDesigner()
|
|
34
|
-
const ref = useRef<HTMLDivElement>()
|
|
35
|
-
const ctx = useContext(NodeContext)
|
|
36
|
-
const request = useRef(null)
|
|
37
|
-
const cursor = useCursor()
|
|
38
|
-
const selection = useSelection(workspaceId)
|
|
39
|
-
const moveHelper = useMoveHelper(workspaceId)
|
|
40
|
-
|
|
41
|
-
useEffect(() => {
|
|
42
|
-
return engine.subscribeTo(DragMoveEvent, () => {
|
|
43
|
-
const closestNodeId = moveHelper?.closestNode?.id
|
|
44
|
-
const closestDirection = moveHelper?.outlineClosestDirection
|
|
45
|
-
const id = node.id
|
|
46
|
-
if (!ref.current) return
|
|
47
|
-
if (
|
|
48
|
-
closestNodeId === id &&
|
|
49
|
-
closestDirection === ClosestPosition.Inner
|
|
50
|
-
) {
|
|
51
|
-
if (!ref.current.classList.contains('droppable')) {
|
|
52
|
-
ref.current.classList.add('droppable')
|
|
53
|
-
}
|
|
54
|
-
if (!ref.current.classList.contains('expanded')) {
|
|
55
|
-
if (request.current) {
|
|
56
|
-
clearTimeout(request.current)
|
|
57
|
-
request.current = null
|
|
58
|
-
}
|
|
59
|
-
request.current = setTimeout(() => {
|
|
60
|
-
ref.current.classList.add('expanded')
|
|
61
|
-
}, 600)
|
|
62
|
-
}
|
|
63
|
-
} else {
|
|
64
|
-
if (request.current) {
|
|
65
|
-
clearTimeout(request.current)
|
|
66
|
-
request.current = null
|
|
67
|
-
}
|
|
68
|
-
if (ref.current.classList.contains('droppable')) {
|
|
69
|
-
ref.current.classList.remove('droppable')
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
})
|
|
73
|
-
}, [node, moveHelper, cursor])
|
|
74
|
-
|
|
75
|
-
useEffect(() => {
|
|
76
|
-
return autorun(() => {
|
|
77
|
-
const selectedIds = selection?.selected || []
|
|
78
|
-
const id = node.id
|
|
79
|
-
if (!ref.current) return
|
|
80
|
-
if (selectedIds.includes(id)) {
|
|
81
|
-
if (!ref.current.classList.contains('selected')) {
|
|
82
|
-
ref.current.classList.add('selected')
|
|
83
|
-
}
|
|
84
|
-
} else {
|
|
85
|
-
if (ref.current.classList.contains('selected')) {
|
|
86
|
-
ref.current.classList.remove('selected')
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
if (
|
|
90
|
-
cursor.status === CursorStatus.Dragging &&
|
|
91
|
-
moveHelper?.dragNodes?.length
|
|
92
|
-
) {
|
|
93
|
-
if (ref.current.classList.contains('selected')) {
|
|
94
|
-
ref.current.classList.remove('selected')
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
})
|
|
98
|
-
}, [node, selection, moveHelper])
|
|
99
|
-
|
|
100
|
-
if (!node) return null
|
|
101
|
-
|
|
102
|
-
const renderIcon = (node: TreeNode) => {
|
|
103
|
-
const icon = node.designerProps.icon
|
|
104
|
-
if (icon) {
|
|
105
|
-
return <IconWidget infer={icon} size={12} />
|
|
106
|
-
}
|
|
107
|
-
if (node === node?.root) {
|
|
108
|
-
return <IconWidget infer="Page" size={12} />
|
|
109
|
-
} else if (node.designerProps?.droppable) {
|
|
110
|
-
return <IconWidget infer="Container" size={12} />
|
|
111
|
-
}
|
|
112
|
-
return <IconWidget infer="Component" size={12} />
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
const renderTitle = (node: TreeNode) => {
|
|
116
|
-
if (isFn(ctx.renderTitle)) return ctx.renderTitle(node)
|
|
117
|
-
return (
|
|
118
|
-
<span>
|
|
119
|
-
<NodeTitleWidget node={node} />
|
|
120
|
-
</span>
|
|
121
|
-
)
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
const renderActions = (node: TreeNode) => {
|
|
125
|
-
if (isFn(ctx.renderActions)) return ctx.renderActions(node)
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
return (
|
|
129
|
-
<div
|
|
130
|
-
style={style}
|
|
131
|
-
ref={ref}
|
|
132
|
-
className={cls(prefix, className, 'expanded')}
|
|
133
|
-
data-designer-outline-node-id={node.id}
|
|
134
|
-
>
|
|
135
|
-
<div className={prefix + '-header'}>
|
|
136
|
-
<div
|
|
137
|
-
className={prefix + '-header-head'}
|
|
138
|
-
style={{
|
|
139
|
-
left: -node.depth * 16,
|
|
140
|
-
width: node.depth * 16,
|
|
141
|
-
}}
|
|
142
|
-
></div>
|
|
143
|
-
<div className={prefix + '-header-content'}>
|
|
144
|
-
<div className={prefix + '-header-base'}>
|
|
145
|
-
{(node?.children?.length > 0 || node === node.root) && (
|
|
146
|
-
<div
|
|
147
|
-
className={prefix + '-expand'}
|
|
148
|
-
onClick={(e) => {
|
|
149
|
-
e.preventDefault()
|
|
150
|
-
e.stopPropagation()
|
|
151
|
-
if (ref.current?.classList?.contains('expanded')) {
|
|
152
|
-
ref.current?.classList.remove('expanded')
|
|
153
|
-
} else {
|
|
154
|
-
ref.current?.classList.add('expanded')
|
|
155
|
-
}
|
|
156
|
-
}}
|
|
157
|
-
>
|
|
158
|
-
<IconWidget infer="Expand" size={10} />
|
|
159
|
-
</div>
|
|
160
|
-
)}
|
|
161
|
-
<div className={prefix + '-icon'}>{renderIcon(node)}</div>
|
|
162
|
-
<div className={prefix + '-title'}>{renderTitle(node)}</div>
|
|
163
|
-
</div>
|
|
164
|
-
<div
|
|
165
|
-
className={prefix + '-header-actions'}
|
|
166
|
-
data-click-stop-propagation
|
|
167
|
-
>
|
|
168
|
-
{renderActions(node)}
|
|
169
|
-
{node !== node.root && (
|
|
170
|
-
<IconWidget
|
|
171
|
-
className={cls(prefix + '-hidden-icon', {
|
|
172
|
-
hidden: node.hidden,
|
|
173
|
-
})}
|
|
174
|
-
infer={node.hidden ? 'EyeClose' : 'Eye'}
|
|
175
|
-
size={14}
|
|
176
|
-
onClick={() => {
|
|
177
|
-
node.hidden = !node.hidden
|
|
178
|
-
}}
|
|
179
|
-
/>
|
|
180
|
-
)}
|
|
181
|
-
</div>
|
|
182
|
-
</div>
|
|
183
|
-
</div>
|
|
184
|
-
<div className={prefix + '-children'}>
|
|
185
|
-
{node.children?.map((child) => {
|
|
186
|
-
return (
|
|
187
|
-
<OutlineTreeNode
|
|
188
|
-
node={child}
|
|
189
|
-
key={child.id}
|
|
190
|
-
workspaceId={workspaceId}
|
|
191
|
-
/>
|
|
192
|
-
)
|
|
193
|
-
})}
|
|
194
|
-
</div>
|
|
195
|
-
</div>
|
|
196
|
-
)
|
|
197
|
-
}
|
|
198
|
-
)
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { TreeNode } from '@formily-design/core'
|
|
2
|
-
import React, { createContext } from 'react'
|
|
3
|
-
|
|
4
|
-
interface INodeContext {
|
|
5
|
-
renderTitle?: (node: TreeNode) => React.ReactNode
|
|
6
|
-
renderActions?: (node: TreeNode) => React.ReactNode
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export const NodeContext = createContext<INodeContext>(null)
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import React, { useRef, useLayoutEffect } from 'react'
|
|
2
|
-
import cls from 'classnames'
|
|
3
|
-
import { useTree, usePrefix, useOutline, useWorkbench } from '../../hooks'
|
|
4
|
-
import { observer } from '@formily/reactive-react'
|
|
5
|
-
import { OutlineTreeNode } from './OutlineNode'
|
|
6
|
-
import { Insertion } from './Insertion'
|
|
7
|
-
import { TreeNode, Viewport } from '@formily-design/core'
|
|
8
|
-
import { NodeContext } from './context'
|
|
9
|
-
import { globalThisPolyfill } from '@formily-design/shared'
|
|
10
|
-
|
|
11
|
-
export interface IOutlineTreeWidgetProps {
|
|
12
|
-
className?: string
|
|
13
|
-
style?: React.CSSProperties
|
|
14
|
-
onClose?: () => void
|
|
15
|
-
renderTitle?: (node: TreeNode) => React.ReactNode
|
|
16
|
-
renderActions?: (node: TreeNode) => React.ReactNode
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export const OutlineTreeWidget: React.FC<IOutlineTreeWidgetProps> = observer(
|
|
20
|
-
({ onClose, style, renderActions, renderTitle, className, ...props }) => {
|
|
21
|
-
const ref = useRef<HTMLDivElement>()
|
|
22
|
-
const prefix = usePrefix('outline-tree')
|
|
23
|
-
const workbench = useWorkbench()
|
|
24
|
-
const current = workbench?.activeWorkspace || workbench?.currentWorkspace
|
|
25
|
-
const workspaceId = current?.id
|
|
26
|
-
const tree = useTree(workspaceId)
|
|
27
|
-
const outline = useOutline(workspaceId)
|
|
28
|
-
const outlineRef = useRef<Viewport>()
|
|
29
|
-
useLayoutEffect(() => {
|
|
30
|
-
if (!workspaceId) return
|
|
31
|
-
if (outlineRef.current && outlineRef.current !== outline) {
|
|
32
|
-
outlineRef.current.onUnmount()
|
|
33
|
-
}
|
|
34
|
-
if (ref.current && outline) {
|
|
35
|
-
outline.onMount(ref.current, globalThisPolyfill)
|
|
36
|
-
}
|
|
37
|
-
outlineRef.current = outline
|
|
38
|
-
return () => {
|
|
39
|
-
outline.onUnmount()
|
|
40
|
-
}
|
|
41
|
-
}, [workspaceId, outline])
|
|
42
|
-
|
|
43
|
-
if (!outline || !workspaceId) return null
|
|
44
|
-
return (
|
|
45
|
-
<NodeContext.Provider value={{ renderActions, renderTitle }}>
|
|
46
|
-
<div
|
|
47
|
-
{...props}
|
|
48
|
-
className={cls(prefix + '-container', className)}
|
|
49
|
-
style={style}
|
|
50
|
-
>
|
|
51
|
-
<div className={prefix + '-content'} ref={ref}>
|
|
52
|
-
<OutlineTreeNode node={tree} workspaceId={workspaceId} />
|
|
53
|
-
<div
|
|
54
|
-
className={prefix + '-aux'}
|
|
55
|
-
style={{
|
|
56
|
-
pointerEvents: 'none',
|
|
57
|
-
}}
|
|
58
|
-
>
|
|
59
|
-
<Insertion workspaceId={workspaceId} />
|
|
60
|
-
</div>
|
|
61
|
-
</div>
|
|
62
|
-
</div>
|
|
63
|
-
</NodeContext.Provider>
|
|
64
|
-
)
|
|
65
|
-
}
|
|
66
|
-
)
|