@formily-design/react 1.0.0 → 1.0.1

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.
Files changed (170) hide show
  1. package/package.json +4 -4
  2. package/copy.ts +0 -6
  3. package/dist/designable.react.umd.production.css +0 -1
  4. package/dist/designable.react.umd.production.js +0 -6
  5. package/dist/designable.react.umd.production.min.css +0 -1
  6. package/dist/designable.react.umd.production.min.js +0 -3769
  7. package/rollup.config.js +0 -3
  8. package/src/containers/Designer.tsx +0 -50
  9. package/src/containers/Layout.tsx +0 -50
  10. package/src/containers/Simulator.tsx +0 -30
  11. package/src/containers/Viewport.tsx +0 -69
  12. package/src/containers/Workbench.tsx +0 -15
  13. package/src/containers/Workspace.tsx +0 -41
  14. package/src/containers/index.ts +0 -7
  15. package/src/containers/styles.less +0 -19
  16. package/src/context.ts +0 -17
  17. package/src/hooks/index.ts +0 -25
  18. package/src/hooks/useComponents.ts +0 -3
  19. package/src/hooks/useCursor.ts +0 -6
  20. package/src/hooks/useDesigner.ts +0 -19
  21. package/src/hooks/useHistory.ts +0 -6
  22. package/src/hooks/useHover.ts +0 -6
  23. package/src/hooks/useLayout.ts +0 -11
  24. package/src/hooks/useMoveHelper.ts +0 -6
  25. package/src/hooks/useNodeIdProps.ts +0 -11
  26. package/src/hooks/useOperation.ts +0 -6
  27. package/src/hooks/useOutline.ts +0 -6
  28. package/src/hooks/usePosition.ts +0 -5
  29. package/src/hooks/usePrefix.ts +0 -5
  30. package/src/hooks/useRegistry.ts +0 -6
  31. package/src/hooks/useScreen.ts +0 -5
  32. package/src/hooks/useSelected.ts +0 -6
  33. package/src/hooks/useSelectedNode.ts +0 -14
  34. package/src/hooks/useSelection.ts +0 -6
  35. package/src/hooks/useTheme.ts +0 -5
  36. package/src/hooks/useTransformHelper.ts +0 -6
  37. package/src/hooks/useTree.ts +0 -6
  38. package/src/hooks/useTreeNode.ts +0 -6
  39. package/src/hooks/useValidNodeOffsetRect.ts +0 -48
  40. package/src/hooks/useViewport.ts +0 -6
  41. package/src/hooks/useWorkbench.ts +0 -6
  42. package/src/hooks/useWorkspace.ts +0 -16
  43. package/src/icons/actions.tsx +0 -138
  44. package/src/icons/add.tsx +0 -8
  45. package/src/icons/animations.tsx +0 -325
  46. package/src/icons/boolean.tsx +0 -7
  47. package/src/icons/clone.tsx +0 -9
  48. package/src/icons/close.tsx +0 -7
  49. package/src/icons/code.tsx +0 -5
  50. package/src/icons/command.tsx +0 -8
  51. package/src/icons/component.tsx +0 -5
  52. package/src/icons/container.tsx +0 -8
  53. package/src/icons/corner.tsx +0 -26
  54. package/src/icons/delete.tsx +0 -9
  55. package/src/icons/design.tsx +0 -7
  56. package/src/icons/display.tsx +0 -17
  57. package/src/icons/dragmove.tsx +0 -10
  58. package/src/icons/expand.tsx +0 -5
  59. package/src/icons/expression.tsx +0 -5
  60. package/src/icons/eyes.tsx +0 -15
  61. package/src/icons/flex.tsx +0 -85
  62. package/src/icons/flip.tsx +0 -5
  63. package/src/icons/focus.tsx +0 -5
  64. package/src/icons/font.tsx +0 -61
  65. package/src/icons/formula.tsx +0 -5
  66. package/src/icons/freemove.tsx +0 -10
  67. package/src/icons/help.tsx +0 -8
  68. package/src/icons/hidden.tsx +0 -5
  69. package/src/icons/history.tsx +0 -7
  70. package/src/icons/image.tsx +0 -9
  71. package/src/icons/index.ts +0 -53
  72. package/src/icons/json.tsx +0 -5
  73. package/src/icons/logo.tsx +0 -5
  74. package/src/icons/menu.tsx +0 -7
  75. package/src/icons/mobile.tsx +0 -8
  76. package/src/icons/move.tsx +0 -5
  77. package/src/icons/number.tsx +0 -7
  78. package/src/icons/outline.tsx +0 -5
  79. package/src/icons/page.tsx +0 -9
  80. package/src/icons/pc.tsx +0 -7
  81. package/src/icons/play.tsx +0 -8
  82. package/src/icons/position.tsx +0 -30
  83. package/src/icons/pushpin.tsx +0 -29
  84. package/src/icons/recover.tsx +0 -5
  85. package/src/icons/redo.tsx +0 -5
  86. package/src/icons/remove.tsx +0 -5
  87. package/src/icons/responsive.tsx +0 -9
  88. package/src/icons/return.tsx +0 -5
  89. package/src/icons/selection.tsx +0 -5
  90. package/src/icons/setting.tsx +0 -5
  91. package/src/icons/shadow.tsx +0 -20
  92. package/src/icons/shift.tsx +0 -5
  93. package/src/icons/sources.tsx +0 -3377
  94. package/src/icons/text.tsx +0 -13
  95. package/src/icons/undo.tsx +0 -7
  96. package/src/icons/upload.tsx +0 -8
  97. package/src/index.ts +0 -9
  98. package/src/locales/global.ts +0 -16
  99. package/src/locales/icons.ts +0 -132
  100. package/src/locales/index.ts +0 -7
  101. package/src/locales/operations.ts +0 -50
  102. package/src/locales/panels.ts +0 -26
  103. package/src/panels/CompositePanel.tsx +0 -195
  104. package/src/panels/SettingsPanel.tsx +0 -85
  105. package/src/panels/StudioPanel.tsx +0 -54
  106. package/src/panels/ToolbarPanel.tsx +0 -19
  107. package/src/panels/ViewPanel.tsx +0 -62
  108. package/src/panels/ViewportPanel.tsx +0 -10
  109. package/src/panels/WorkspacePanel.tsx +0 -31
  110. package/src/panels/index.ts +0 -8
  111. package/src/panels/styles.less +0 -331
  112. package/src/simulators/MobileSimulator/body.tsx +0 -78
  113. package/src/simulators/MobileSimulator/index.tsx +0 -21
  114. package/src/simulators/MobileSimulator/styles.less +0 -29
  115. package/src/simulators/PCSimulator/index.tsx +0 -17
  116. package/src/simulators/PCSimulator/styles.less +0 -11
  117. package/src/simulators/ResponsiveSimulator/handle.tsx +0 -29
  118. package/src/simulators/ResponsiveSimulator/index.tsx +0 -193
  119. package/src/simulators/ResponsiveSimulator/styles.less +0 -56
  120. package/src/simulators/index.tsx +0 -3
  121. package/src/theme.less +0 -224
  122. package/src/types.ts +0 -41
  123. package/src/variables.less +0 -1
  124. package/src/widgets/AuxToolWidget/Copy.tsx +0 -28
  125. package/src/widgets/AuxToolWidget/Cover.tsx +0 -76
  126. package/src/widgets/AuxToolWidget/DashedBox.tsx +0 -55
  127. package/src/widgets/AuxToolWidget/Delete.tsx +0 -29
  128. package/src/widgets/AuxToolWidget/DragHandler.tsx +0 -29
  129. package/src/widgets/AuxToolWidget/FreeSelection.tsx +0 -53
  130. package/src/widgets/AuxToolWidget/Helpers.tsx +0 -116
  131. package/src/widgets/AuxToolWidget/Insertion.tsx +0 -80
  132. package/src/widgets/AuxToolWidget/ResizeHandler.tsx +0 -35
  133. package/src/widgets/AuxToolWidget/Selection.tsx +0 -85
  134. package/src/widgets/AuxToolWidget/Selector.tsx +0 -125
  135. package/src/widgets/AuxToolWidget/SnapLine.tsx +0 -40
  136. package/src/widgets/AuxToolWidget/SpaceBlock.tsx +0 -112
  137. package/src/widgets/AuxToolWidget/TranslateHandler.tsx +0 -29
  138. package/src/widgets/AuxToolWidget/index.tsx +0 -40
  139. package/src/widgets/AuxToolWidget/styles.less +0 -383
  140. package/src/widgets/ComponentTreeWidget/index.tsx +0 -99
  141. package/src/widgets/ComponentTreeWidget/styles.less +0 -6
  142. package/src/widgets/DesignerToolsWidget/index.tsx +0 -206
  143. package/src/widgets/DesignerToolsWidget/styles.less +0 -29
  144. package/src/widgets/DroppableWidget/index.tsx +0 -63
  145. package/src/widgets/DroppableWidget/styles.less +0 -11
  146. package/src/widgets/EmptyWidget/index.tsx +0 -58
  147. package/src/widgets/EmptyWidget/styles.less +0 -27
  148. package/src/widgets/GhostWidget/index.tsx +0 -47
  149. package/src/widgets/GhostWidget/styles.less +0 -20
  150. package/src/widgets/HistoryWidget/index.tsx +0 -42
  151. package/src/widgets/HistoryWidget/styles.less +0 -23
  152. package/src/widgets/IconWidget/index.tsx +0 -152
  153. package/src/widgets/IconWidget/styles.less +0 -17
  154. package/src/widgets/NodeActionsWidget/index.tsx +0 -56
  155. package/src/widgets/NodeActionsWidget/styles.less +0 -51
  156. package/src/widgets/NodePathWidget/index.tsx +0 -57
  157. package/src/widgets/NodePathWidget/styles.less +0 -16
  158. package/src/widgets/NodeTitleWidget/index.tsx +0 -20
  159. package/src/widgets/OutlineWidget/Insertion.tsx +0 -63
  160. package/src/widgets/OutlineWidget/OutlineNode.tsx +0 -198
  161. package/src/widgets/OutlineWidget/context.ts +0 -9
  162. package/src/widgets/OutlineWidget/index.tsx +0 -66
  163. package/src/widgets/OutlineWidget/styles.less +0 -195
  164. package/src/widgets/ResourceWidget/index.tsx +0 -110
  165. package/src/widgets/ResourceWidget/styles.less +0 -87
  166. package/src/widgets/TextWidget/index.tsx +0 -43
  167. package/src/widgets/ViewToolsWidget/index.tsx +0 -72
  168. package/src/widgets/index.ts +0 -15
  169. package/tsconfig.build.json +0 -10
  170. package/tsconfig.json +0 -5
package/rollup.config.js DELETED
@@ -1,3 +0,0 @@
1
- import baseConfig from '../../scripts/rollup.base.js'
2
-
3
- export default baseConfig('designable.react', 'Designable.React')
@@ -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
- }
@@ -1,7 +0,0 @@
1
- import './styles.less'
2
- export * from './Layout'
3
- export * from './Designer'
4
- export * from './Workspace'
5
- export * from './Simulator'
6
- export * from './Viewport'
7
- export * from './Workbench'
@@ -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)
@@ -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'
@@ -1,3 +0,0 @@
1
- import { useContext } from 'react'
2
- import { DesignerComponentsContext } from '../context'
3
- export const useComponents = () => useContext(DesignerComponentsContext)
@@ -1,6 +0,0 @@
1
- import { useDesigner } from './useDesigner'
2
-
3
- export const useCursor = () => {
4
- const designer = useDesigner()
5
- return designer.cursor
6
- }
@@ -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
- }
@@ -1,6 +0,0 @@
1
- import { useWorkspace } from './useWorkspace'
2
-
3
- export const useHistory = (workspaceId?: string) => {
4
- const workspace = useWorkspace(workspaceId)
5
- return workspace?.history
6
- }
@@ -1,6 +0,0 @@
1
- import { useOperation } from './useOperation'
2
-
3
- export const useHover = (workspaceId?: string) => {
4
- const operation = useOperation(workspaceId)
5
- return operation?.hover
6
- }
@@ -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,6 +0,0 @@
1
- import { useOperation } from './useOperation'
2
-
3
- export const useMoveHelper = (workspaceId?: string) => {
4
- const operation = useOperation(workspaceId)
5
- return operation?.moveHelper
6
- }
@@ -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
- }
@@ -1,6 +0,0 @@
1
- import { useWorkspace } from './useWorkspace'
2
-
3
- export const useOperation = (workspaceId?: string) => {
4
- const workspace = useWorkspace(workspaceId)
5
- return workspace?.operation
6
- }
@@ -1,6 +0,0 @@
1
- import { useWorkspace } from './useWorkspace'
2
-
3
- export const useOutline = (workspaceId?: string) => {
4
- const workspace = useWorkspace(workspaceId)
5
- return workspace?.outline
6
- }
@@ -1,5 +0,0 @@
1
- import { useLayout } from './useLayout'
2
-
3
- export const usePosition = () => {
4
- return useLayout()?.position
5
- }
@@ -1,5 +0,0 @@
1
- import { useLayout } from './useLayout'
2
-
3
- export const usePrefix = (after = '') => {
4
- return useLayout()?.prefixCls + after
5
- }
@@ -1,6 +0,0 @@
1
- import { GlobalRegistry, IDesignerRegistry } from '@formily-design/core'
2
- import { globalThisPolyfill } from '@formily-design/shared'
3
-
4
- export const useRegistry = (): IDesignerRegistry => {
5
- return globalThisPolyfill['__DESIGNER_REGISTRY__'] || GlobalRegistry
6
- }
@@ -1,5 +0,0 @@
1
- import { useDesigner } from './useDesigner'
2
-
3
- export const useScreen = () => {
4
- return useDesigner().screen
5
- }
@@ -1,6 +0,0 @@
1
- import { useSelection } from './useSelection'
2
-
3
- export const useSelected = (workspaceId?: string) => {
4
- const selection = useSelection(workspaceId)
5
- return selection?.selected || []
6
- }
@@ -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
@@ -1,6 +0,0 @@
1
- import { useOperation } from './useOperation'
2
-
3
- export const useSelection = (workspaceId?: string) => {
4
- const operation = useOperation(workspaceId)
5
- return operation?.selection
6
- }
@@ -1,5 +0,0 @@
1
- import { useLayout } from './useLayout'
2
-
3
- export const useTheme = () => {
4
- return useLayout()?.theme
5
- }
@@ -1,6 +0,0 @@
1
- import { useOperation } from './useOperation'
2
-
3
- export const useTransformHelper = (workspaceId?: string) => {
4
- const operation = useOperation(workspaceId)
5
- return operation?.transformHelper
6
- }
@@ -1,6 +0,0 @@
1
- import { useOperation } from './useOperation'
2
-
3
- export const useTree = (workspaceId?: string) => {
4
- const operation = useOperation(workspaceId)
5
- return operation?.tree
6
- }
@@ -1,6 +0,0 @@
1
- import { useContext } from 'react'
2
- import { TreeNodeContext } from '../context'
3
-
4
- export const useTreeNode = () => {
5
- return useContext(TreeNodeContext)
6
- }
@@ -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
- }
@@ -1,6 +0,0 @@
1
- import { useWorkspace } from './useWorkspace'
2
-
3
- export const useViewport = (workspaceId?: string) => {
4
- const workspace = useWorkspace(workspaceId)
5
- return workspace?.viewport
6
- }
@@ -1,6 +0,0 @@
1
- import { useDesigner } from './useDesigner'
2
-
3
- export const useWorkbench = () => {
4
- const designer = useDesigner()
5
- return designer.workbench
6
- }
@@ -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
- }