@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
package/rollup.config.js
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import React, { useEffect, useRef } from 'react'
|
|
2
|
-
import { Engine, GlobalRegistry } from '@formily-design/core'
|
|
3
|
-
import { DesignerEngineContext } from '../context'
|
|
4
|
-
import { IDesignerProps } from '../types'
|
|
5
|
-
import { GhostWidget } from '../widgets'
|
|
6
|
-
import { useDesigner } from '../hooks'
|
|
7
|
-
import { Layout } from './Layout'
|
|
8
|
-
import * as icons from '../icons'
|
|
9
|
-
|
|
10
|
-
GlobalRegistry.registerDesignerIcons(icons)
|
|
11
|
-
|
|
12
|
-
export const Designer: React.FC<IDesignerProps> = (props) => {
|
|
13
|
-
const engine = useDesigner()
|
|
14
|
-
const ref = useRef<Engine>()
|
|
15
|
-
useEffect(() => {
|
|
16
|
-
if (props.engine) {
|
|
17
|
-
if (props.engine && ref.current) {
|
|
18
|
-
if (props.engine !== ref.current) {
|
|
19
|
-
ref.current.unmount()
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
props.engine.mount()
|
|
23
|
-
ref.current = props.engine
|
|
24
|
-
}
|
|
25
|
-
return () => {
|
|
26
|
-
if (props.engine) {
|
|
27
|
-
props.engine.unmount()
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
}, [props.engine])
|
|
31
|
-
|
|
32
|
-
if (engine)
|
|
33
|
-
throw new Error(
|
|
34
|
-
'There can only be one Designable Engine Context in the React Tree'
|
|
35
|
-
)
|
|
36
|
-
|
|
37
|
-
return (
|
|
38
|
-
<Layout {...props}>
|
|
39
|
-
<DesignerEngineContext.Provider value={props.engine}>
|
|
40
|
-
{props.children}
|
|
41
|
-
<GhostWidget />
|
|
42
|
-
</DesignerEngineContext.Provider>
|
|
43
|
-
</Layout>
|
|
44
|
-
)
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
Designer.defaultProps = {
|
|
48
|
-
prefixCls: 'dn-',
|
|
49
|
-
theme: 'light',
|
|
50
|
-
}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import React, { useContext, Fragment, useRef, useLayoutEffect } from 'react'
|
|
2
|
-
import { each } from '@formily-design/shared'
|
|
3
|
-
import { DesignerLayoutContext } from '../context'
|
|
4
|
-
import { IDesignerLayoutProps } from '../types'
|
|
5
|
-
import cls from 'classnames'
|
|
6
|
-
|
|
7
|
-
export const Layout: React.FC<IDesignerLayoutProps> = (props) => {
|
|
8
|
-
const layout = useContext(DesignerLayoutContext)
|
|
9
|
-
const ref = useRef<HTMLDivElement>()
|
|
10
|
-
useLayoutEffect(() => {
|
|
11
|
-
if (ref.current) {
|
|
12
|
-
each(props.variables, (value, key) => {
|
|
13
|
-
ref.current.style.setProperty(`--${key}`, value)
|
|
14
|
-
})
|
|
15
|
-
}
|
|
16
|
-
}, [])
|
|
17
|
-
|
|
18
|
-
if (layout) {
|
|
19
|
-
return <Fragment>{props.children}</Fragment>
|
|
20
|
-
}
|
|
21
|
-
return (
|
|
22
|
-
<div
|
|
23
|
-
ref={ref}
|
|
24
|
-
className={cls(
|
|
25
|
-
{
|
|
26
|
-
[`${props.prefixCls}app`]: true,
|
|
27
|
-
[`${props.prefixCls}${props.theme}`]: props.theme,
|
|
28
|
-
},
|
|
29
|
-
props.className
|
|
30
|
-
)}
|
|
31
|
-
style={props.style}
|
|
32
|
-
>
|
|
33
|
-
<DesignerLayoutContext.Provider
|
|
34
|
-
value={{
|
|
35
|
-
theme: props.theme,
|
|
36
|
-
prefixCls: props.prefixCls,
|
|
37
|
-
position: props.position,
|
|
38
|
-
}}
|
|
39
|
-
>
|
|
40
|
-
{props.children}
|
|
41
|
-
</DesignerLayoutContext.Provider>
|
|
42
|
-
</div>
|
|
43
|
-
)
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
Layout.defaultProps = {
|
|
47
|
-
theme: 'light',
|
|
48
|
-
prefixCls: 'dn-',
|
|
49
|
-
position: 'fixed',
|
|
50
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import React from 'react'
|
|
2
|
-
import { ScreenType } from '@formily-design/core'
|
|
3
|
-
import { requestIdle } from '@formily-design/shared'
|
|
4
|
-
import { observer } from '@formily/reactive-react'
|
|
5
|
-
import { useScreen } from '../hooks'
|
|
6
|
-
import {
|
|
7
|
-
MobileSimulator,
|
|
8
|
-
PCSimulator,
|
|
9
|
-
ResponsiveSimulator,
|
|
10
|
-
} from '../simulators'
|
|
11
|
-
|
|
12
|
-
export type ISimulatorProps = React.HTMLAttributes<HTMLDivElement>
|
|
13
|
-
|
|
14
|
-
export const Simulator: React.FC<ISimulatorProps> = observer(
|
|
15
|
-
(props: ISimulatorProps) => {
|
|
16
|
-
const screen = useScreen()
|
|
17
|
-
if (screen.type === ScreenType.PC)
|
|
18
|
-
return <PCSimulator {...props}>{props.children}</PCSimulator>
|
|
19
|
-
if (screen.type === ScreenType.Mobile)
|
|
20
|
-
return <MobileSimulator {...props}>{props.children}</MobileSimulator>
|
|
21
|
-
if (screen.type === ScreenType.Responsive)
|
|
22
|
-
return (
|
|
23
|
-
<ResponsiveSimulator {...props}>{props.children}</ResponsiveSimulator>
|
|
24
|
-
)
|
|
25
|
-
return <PCSimulator {...props}>{props.children}</PCSimulator>
|
|
26
|
-
},
|
|
27
|
-
{
|
|
28
|
-
scheduler: requestIdle,
|
|
29
|
-
}
|
|
30
|
-
)
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import React, { useLayoutEffect, useRef, useState } from 'react'
|
|
2
|
-
import { usePrefix, useViewport } from '../hooks'
|
|
3
|
-
import { AuxToolWidget, EmptyWidget } from '../widgets'
|
|
4
|
-
import { Viewport as ViewportType } from '@formily-design/core'
|
|
5
|
-
import { requestIdle, globalThisPolyfill } from '@formily-design/shared'
|
|
6
|
-
import cls from 'classnames'
|
|
7
|
-
export interface IViewportProps
|
|
8
|
-
extends Omit<React.HTMLAttributes<HTMLDivElement>, 'placeholder'> {
|
|
9
|
-
placeholder?: React.ReactNode
|
|
10
|
-
dragTipsDirection?: 'left' | 'right'
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export const Viewport: React.FC<IViewportProps> = ({
|
|
14
|
-
placeholder,
|
|
15
|
-
dragTipsDirection,
|
|
16
|
-
...props
|
|
17
|
-
}) => {
|
|
18
|
-
const [loaded, setLoaded] = useState(false)
|
|
19
|
-
const prefix = usePrefix('viewport')
|
|
20
|
-
const viewport = useViewport()
|
|
21
|
-
const ref = useRef<HTMLDivElement>()
|
|
22
|
-
const viewportRef = useRef<ViewportType>()
|
|
23
|
-
const isFrameRef = useRef(false)
|
|
24
|
-
useLayoutEffect(() => {
|
|
25
|
-
const frameElement = ref.current.querySelector('iframe')
|
|
26
|
-
if (!viewport) return
|
|
27
|
-
if (viewportRef.current && viewportRef.current !== viewport) {
|
|
28
|
-
viewportRef.current.onUnmount()
|
|
29
|
-
}
|
|
30
|
-
if (frameElement) {
|
|
31
|
-
frameElement.addEventListener('load', () => {
|
|
32
|
-
viewport.onMount(frameElement, frameElement.contentWindow)
|
|
33
|
-
requestIdle(() => {
|
|
34
|
-
isFrameRef.current = true
|
|
35
|
-
setLoaded(true)
|
|
36
|
-
})
|
|
37
|
-
})
|
|
38
|
-
} else {
|
|
39
|
-
viewport.onMount(ref.current, globalThisPolyfill)
|
|
40
|
-
requestIdle(() => {
|
|
41
|
-
isFrameRef.current = false
|
|
42
|
-
setLoaded(true)
|
|
43
|
-
})
|
|
44
|
-
}
|
|
45
|
-
viewportRef.current = viewport
|
|
46
|
-
return () => {
|
|
47
|
-
viewport.onUnmount()
|
|
48
|
-
}
|
|
49
|
-
}, [viewport])
|
|
50
|
-
|
|
51
|
-
return (
|
|
52
|
-
<div
|
|
53
|
-
{...props}
|
|
54
|
-
ref={ref}
|
|
55
|
-
className={cls(prefix, props.className)}
|
|
56
|
-
style={{
|
|
57
|
-
opacity: !loaded ? 0 : 1,
|
|
58
|
-
overflow: isFrameRef.current ? 'hidden' : 'overlay',
|
|
59
|
-
...props.style,
|
|
60
|
-
}}
|
|
61
|
-
>
|
|
62
|
-
{props.children}
|
|
63
|
-
<AuxToolWidget />
|
|
64
|
-
<EmptyWidget dragTipsDirection={dragTipsDirection}>
|
|
65
|
-
{placeholder}
|
|
66
|
-
</EmptyWidget>
|
|
67
|
-
</div>
|
|
68
|
-
)
|
|
69
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import React from 'react'
|
|
2
|
-
import { observer } from '@formily/reactive-react'
|
|
3
|
-
import { useWorkbench } from '../hooks'
|
|
4
|
-
import { Workspace } from './Workspace'
|
|
5
|
-
|
|
6
|
-
export const Workbench: React.FC<{ children?: React.ReactNode }> = observer(
|
|
7
|
-
(props) => {
|
|
8
|
-
const workbench = useWorkbench()
|
|
9
|
-
return (
|
|
10
|
-
<Workspace id={workbench.currentWorkspace?.id}>
|
|
11
|
-
{props.children}
|
|
12
|
-
</Workspace>
|
|
13
|
-
)
|
|
14
|
-
}
|
|
15
|
-
)
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import React, { useMemo, useRef, Fragment } from 'react'
|
|
2
|
-
import { useDesigner } from '../hooks'
|
|
3
|
-
import { WorkspaceContext } from '../context'
|
|
4
|
-
export interface IWorkspaceProps {
|
|
5
|
-
children?: React.ReactNode
|
|
6
|
-
id?: string
|
|
7
|
-
title?: string
|
|
8
|
-
description?: string
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export const Workspace: React.FC<IWorkspaceProps> = ({
|
|
12
|
-
id,
|
|
13
|
-
title,
|
|
14
|
-
description,
|
|
15
|
-
...props
|
|
16
|
-
}) => {
|
|
17
|
-
const oldId = useRef<string>()
|
|
18
|
-
const designer = useDesigner()
|
|
19
|
-
const workspace = useMemo(() => {
|
|
20
|
-
if (!designer) return
|
|
21
|
-
if (oldId.current && oldId.current !== id) {
|
|
22
|
-
const old = designer.workbench.findWorkspaceById(oldId.current)
|
|
23
|
-
if (old) old.viewport.detachEvents()
|
|
24
|
-
}
|
|
25
|
-
const workspace = {
|
|
26
|
-
id: id || 'index',
|
|
27
|
-
title,
|
|
28
|
-
description,
|
|
29
|
-
}
|
|
30
|
-
designer.workbench.ensureWorkspace(workspace)
|
|
31
|
-
oldId.current = workspace.id
|
|
32
|
-
return workspace
|
|
33
|
-
}, [id, designer])
|
|
34
|
-
return (
|
|
35
|
-
<Fragment>
|
|
36
|
-
<WorkspaceContext.Provider value={workspace}>
|
|
37
|
-
{props.children}
|
|
38
|
-
</WorkspaceContext.Provider>
|
|
39
|
-
</Fragment>
|
|
40
|
-
)
|
|
41
|
-
}
|
package/src/containers/index.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
@import '../variables.less';
|
|
2
|
-
|
|
3
|
-
.@{prefix-cls}-viewport {
|
|
4
|
-
height: 100%;
|
|
5
|
-
width: 100%;
|
|
6
|
-
min-height: 100px;
|
|
7
|
-
position: relative;
|
|
8
|
-
outline: none;
|
|
9
|
-
box-sizing: border-box;
|
|
10
|
-
user-select: none;
|
|
11
|
-
overflow: overlay;
|
|
12
|
-
|
|
13
|
-
// & > * {
|
|
14
|
-
// width: fit-content;
|
|
15
|
-
// height: fit-content;
|
|
16
|
-
// min-width: 100%;
|
|
17
|
-
// min-height: 100%;
|
|
18
|
-
// }
|
|
19
|
-
}
|
package/src/context.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { createContext } from 'react'
|
|
2
|
-
import { TreeNode, Engine } from '@formily-design/core'
|
|
3
|
-
import {
|
|
4
|
-
IDesignerLayoutContext,
|
|
5
|
-
IWorkspaceContext,
|
|
6
|
-
IDesignerComponents,
|
|
7
|
-
} from './types'
|
|
8
|
-
|
|
9
|
-
export const DesignerComponentsContext = createContext<IDesignerComponents>({})
|
|
10
|
-
|
|
11
|
-
export const DesignerLayoutContext = createContext<IDesignerLayoutContext>(null)
|
|
12
|
-
|
|
13
|
-
export const DesignerEngineContext = createContext<Engine>(null)
|
|
14
|
-
|
|
15
|
-
export const TreeNodeContext = createContext<TreeNode>(null)
|
|
16
|
-
|
|
17
|
-
export const WorkspaceContext = createContext<IWorkspaceContext>(null)
|
package/src/hooks/index.ts
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
export * from './useDesigner'
|
|
2
|
-
export * from './useCursor'
|
|
3
|
-
export * from './useScreen'
|
|
4
|
-
export * from './useTree'
|
|
5
|
-
export * from './useTheme'
|
|
6
|
-
export * from './usePosition'
|
|
7
|
-
export * from './useTreeNode'
|
|
8
|
-
export * from './useHover'
|
|
9
|
-
export * from './useViewport'
|
|
10
|
-
export * from './useOutline'
|
|
11
|
-
export * from './useSelection'
|
|
12
|
-
export * from './useOperation'
|
|
13
|
-
export * from './useWorkbench'
|
|
14
|
-
export * from './useWorkspace'
|
|
15
|
-
export * from './useLayout'
|
|
16
|
-
export * from './useHistory'
|
|
17
|
-
export * from './usePrefix'
|
|
18
|
-
export * from './useRegistry'
|
|
19
|
-
export * from './useValidNodeOffsetRect'
|
|
20
|
-
export * from './useMoveHelper'
|
|
21
|
-
export * from './useNodeIdProps'
|
|
22
|
-
export * from './useTransformHelper'
|
|
23
|
-
export * from './useSelectedNode'
|
|
24
|
-
export * from './useSelected'
|
|
25
|
-
export * from './useComponents'
|
package/src/hooks/useCursor.ts
DELETED
package/src/hooks/useDesigner.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { useContext, useEffect } from 'react'
|
|
2
|
-
import { Engine } from '@formily-design/core'
|
|
3
|
-
import { DesignerEngineContext } from '../context'
|
|
4
|
-
import { isFn, globalThisPolyfill } from '@formily-design/shared'
|
|
5
|
-
export interface IEffects {
|
|
6
|
-
(engine: Engine): void
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export const useDesigner = (effects?: IEffects): Engine => {
|
|
10
|
-
const designer: Engine =
|
|
11
|
-
globalThisPolyfill['__DESIGNABLE_ENGINE__'] ||
|
|
12
|
-
useContext(DesignerEngineContext)
|
|
13
|
-
useEffect(() => {
|
|
14
|
-
if (isFn(effects)) {
|
|
15
|
-
return effects(designer)
|
|
16
|
-
}
|
|
17
|
-
}, [])
|
|
18
|
-
return designer
|
|
19
|
-
}
|
package/src/hooks/useHistory.ts
DELETED
package/src/hooks/useHover.ts
DELETED
package/src/hooks/useLayout.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { useContext } from 'react'
|
|
2
|
-
import { DesignerLayoutContext } from '../context'
|
|
3
|
-
import { IDesignerLayoutContext } from '../types'
|
|
4
|
-
import { globalThisPolyfill } from '@formily-design/shared'
|
|
5
|
-
|
|
6
|
-
export const useLayout = (): IDesignerLayoutContext => {
|
|
7
|
-
return (
|
|
8
|
-
globalThisPolyfill['__DESIGNABLE_LAYOUT__'] ||
|
|
9
|
-
useContext(DesignerLayoutContext)
|
|
10
|
-
)
|
|
11
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { TreeNode } from '@formily-design/core'
|
|
2
|
-
import { useDesigner } from './useDesigner'
|
|
3
|
-
import { useTreeNode } from './useTreeNode'
|
|
4
|
-
|
|
5
|
-
export const useNodeIdProps = (node?: TreeNode) => {
|
|
6
|
-
const target = useTreeNode()
|
|
7
|
-
const designer = useDesigner()
|
|
8
|
-
return {
|
|
9
|
-
[designer.props.nodeIdAttrName]: node ? node.id : target.id,
|
|
10
|
-
}
|
|
11
|
-
}
|
package/src/hooks/useOutline.ts
DELETED
package/src/hooks/usePosition.ts
DELETED
package/src/hooks/usePrefix.ts
DELETED
package/src/hooks/useRegistry.ts
DELETED
package/src/hooks/useScreen.ts
DELETED
package/src/hooks/useSelected.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { useSelected } from './useSelected'
|
|
2
|
-
import { useTree } from './useTree'
|
|
3
|
-
|
|
4
|
-
export const useSelectedNode = (workspaceId?: string) => {
|
|
5
|
-
const selected = useSelected(workspaceId)
|
|
6
|
-
const tree = useTree(workspaceId)
|
|
7
|
-
return tree?.findById?.(selected[0])
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* @deprecated
|
|
12
|
-
* please use useSelectedNode
|
|
13
|
-
*/
|
|
14
|
-
export const useCurrentNode = useSelectedNode
|
package/src/hooks/useTheme.ts
DELETED
package/src/hooks/useTree.ts
DELETED
package/src/hooks/useTreeNode.ts
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { useState, useEffect, useMemo, useCallback } from 'react'
|
|
2
|
-
import { TreeNode, CursorStatus, CursorDragType } from '@formily-design/core'
|
|
3
|
-
import { LayoutObserver } from '@formily-design/shared'
|
|
4
|
-
import { useViewport } from './useViewport'
|
|
5
|
-
import { useDesigner } from './useDesigner'
|
|
6
|
-
|
|
7
|
-
const isEqualRect = (rect1: DOMRect, rect2: DOMRect) => {
|
|
8
|
-
return (
|
|
9
|
-
rect1?.x === rect2?.x &&
|
|
10
|
-
rect1?.y === rect2?.y &&
|
|
11
|
-
rect1?.width === rect2?.width &&
|
|
12
|
-
rect1?.height === rect2?.height
|
|
13
|
-
)
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export const useValidNodeOffsetRect = (node: TreeNode) => {
|
|
17
|
-
const engine = useDesigner()
|
|
18
|
-
const viewport = useViewport()
|
|
19
|
-
const [, forceUpdate] = useState(null)
|
|
20
|
-
const rectRef = useMemo(
|
|
21
|
-
() => ({ current: viewport.getValidNodeOffsetRect(node) as any }),
|
|
22
|
-
[viewport]
|
|
23
|
-
)
|
|
24
|
-
|
|
25
|
-
const element = viewport.findElementById(node?.id)
|
|
26
|
-
|
|
27
|
-
const compute = useCallback(() => {
|
|
28
|
-
if (
|
|
29
|
-
engine.cursor.status !== CursorStatus.Normal &&
|
|
30
|
-
engine.cursor.dragType === CursorDragType.Move
|
|
31
|
-
)
|
|
32
|
-
return
|
|
33
|
-
const nextRect = viewport.getValidNodeOffsetRect(node) as any
|
|
34
|
-
if (!isEqualRect(rectRef.current, nextRect) && nextRect) {
|
|
35
|
-
rectRef.current = nextRect
|
|
36
|
-
forceUpdate([])
|
|
37
|
-
}
|
|
38
|
-
}, [viewport, node])
|
|
39
|
-
|
|
40
|
-
useEffect(() => {
|
|
41
|
-
const layoutObserver = new LayoutObserver(compute)
|
|
42
|
-
if (element) layoutObserver.observe(element)
|
|
43
|
-
return () => {
|
|
44
|
-
layoutObserver.disconnect()
|
|
45
|
-
}
|
|
46
|
-
}, [node, viewport, element])
|
|
47
|
-
return rectRef.current
|
|
48
|
-
}
|
package/src/hooks/useViewport.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { useContext } from 'react'
|
|
2
|
-
import { useDesigner } from './useDesigner'
|
|
3
|
-
import { WorkspaceContext } from '../context'
|
|
4
|
-
import { Workspace } from '@formily-design/core'
|
|
5
|
-
import { globalThisPolyfill } from '@formily-design/shared'
|
|
6
|
-
|
|
7
|
-
export const useWorkspace = (id?: string): Workspace => {
|
|
8
|
-
const designer = useDesigner()
|
|
9
|
-
const workspaceId = id || useContext(WorkspaceContext)?.id
|
|
10
|
-
if (workspaceId) {
|
|
11
|
-
return designer.workbench.findWorkspaceById(workspaceId)
|
|
12
|
-
}
|
|
13
|
-
if (globalThisPolyfill['__DESIGNABLE_WORKSPACE__'])
|
|
14
|
-
return globalThisPolyfill['__DESIGNABLE_WORKSPACE__']
|
|
15
|
-
return designer.workbench.currentWorkspace
|
|
16
|
-
}
|