@yimoka/designable-react 0.0.0-stage → 0.1.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 (142) hide show
  1. package/README.md +6 -2
  2. package/dist/src/adapter/UIAdapterProvider.d.ts +7 -0
  3. package/dist/src/adapter/UIAdapterProvider.js +10 -0
  4. package/dist/src/adapter/context-core.d.ts +2 -0
  5. package/dist/src/adapter/context-core.js +3 -0
  6. package/dist/src/adapter/context.d.ts +6 -0
  7. package/dist/src/adapter/context.js +9 -0
  8. package/dist/src/adapter/default-components.d.ts +8 -0
  9. package/dist/src/adapter/default-components.js +38 -0
  10. package/dist/src/adapter/default.d.ts +2 -0
  11. package/dist/src/adapter/default.js +9 -0
  12. package/dist/src/adapter/index.d.ts +3 -0
  13. package/dist/src/adapter/index.js +3 -0
  14. package/dist/src/adapter/types.d.ts +63 -0
  15. package/dist/src/adapter/types.js +1 -0
  16. package/dist/src/containers/Designer.d.ts +3 -0
  17. package/dist/src/containers/Designer.js +63 -0
  18. package/dist/src/containers/Sandbox.d.ts +4 -0
  19. package/dist/src/containers/Sandbox.js +3 -0
  20. package/dist/src/containers/SandboxComponent.d.ts +3 -0
  21. package/dist/src/containers/SandboxComponent.js +15 -0
  22. package/dist/src/containers/Simulator.d.ts +3 -0
  23. package/dist/src/containers/Simulator.js +70 -0
  24. package/dist/src/containers/Viewport.d.ts +6 -0
  25. package/dist/src/containers/Viewport.js +71 -0
  26. package/dist/src/containers/Workbench.d.ts +2 -0
  27. package/dist/src/containers/Workbench.js +9 -0
  28. package/dist/src/containers/Workspace.d.ts +7 -0
  29. package/dist/src/containers/Workspace.js +39 -0
  30. package/dist/src/containers/index.d.ts +6 -0
  31. package/dist/src/containers/index.js +6 -0
  32. package/dist/src/containers/sandbox-types.d.ts +7 -0
  33. package/dist/src/containers/sandbox-types.js +1 -0
  34. package/dist/src/containers/sandbox-utils.d.ts +6 -0
  35. package/dist/src/containers/sandbox-utils.js +40 -0
  36. package/dist/src/containers/useSandbox.d.ts +3 -0
  37. package/dist/src/containers/useSandbox.js +77 -0
  38. package/dist/src/context.d.ts +7 -0
  39. package/dist/src/context.js +6 -0
  40. package/dist/src/hooks/index.d.ts +26 -0
  41. package/dist/src/hooks/index.js +26 -0
  42. package/dist/src/hooks/useComponents.d.ts +2 -0
  43. package/dist/src/hooks/useComponents.js +3 -0
  44. package/dist/src/hooks/useCurrentNode.d.ts +2 -0
  45. package/dist/src/hooks/useCurrentNode.js +7 -0
  46. package/dist/src/hooks/useCurrentNodeSelected.d.ts +1 -0
  47. package/dist/src/hooks/useCurrentNodeSelected.js +7 -0
  48. package/dist/src/hooks/useCursor.d.ts +2 -0
  49. package/dist/src/hooks/useCursor.js +5 -0
  50. package/dist/src/hooks/useDesigner.d.ts +3 -0
  51. package/dist/src/hooks/useDesigner.js +15 -0
  52. package/dist/src/hooks/useHistory.d.ts +2 -0
  53. package/dist/src/hooks/useHistory.js +5 -0
  54. package/dist/src/hooks/useHover.d.ts +2 -0
  55. package/dist/src/hooks/useHover.js +5 -0
  56. package/dist/src/hooks/useLayout.d.ts +2 -0
  57. package/dist/src/hooks/useLayout.js +8 -0
  58. package/dist/src/hooks/useNodeIdProps.d.ts +2 -0
  59. package/dist/src/hooks/useNodeIdProps.js +17 -0
  60. package/dist/src/hooks/useOperation.d.ts +2 -0
  61. package/dist/src/hooks/useOperation.js +5 -0
  62. package/dist/src/hooks/useOutline.d.ts +2 -0
  63. package/dist/src/hooks/useOutline.js +5 -0
  64. package/dist/src/hooks/useOutlineDragon.d.ts +2 -0
  65. package/dist/src/hooks/useOutlineDragon.js +5 -0
  66. package/dist/src/hooks/usePosition.d.ts +1 -0
  67. package/dist/src/hooks/usePosition.js +2 -0
  68. package/dist/src/hooks/usePrefix.d.ts +1 -0
  69. package/dist/src/hooks/usePrefix.js +5 -0
  70. package/dist/src/hooks/useRegistry.d.ts +2 -0
  71. package/dist/src/hooks/useRegistry.js +6 -0
  72. package/dist/src/hooks/useScreen.d.ts +2 -0
  73. package/dist/src/hooks/useScreen.js +2 -0
  74. package/dist/src/hooks/useSelected.d.ts +1 -0
  75. package/dist/src/hooks/useSelected.js +5 -0
  76. package/dist/src/hooks/useSelection.d.ts +2 -0
  77. package/dist/src/hooks/useSelection.js +5 -0
  78. package/dist/src/hooks/useTheme.d.ts +1 -0
  79. package/dist/src/hooks/useTheme.js +2 -0
  80. package/dist/src/hooks/useTree.d.ts +2 -0
  81. package/dist/src/hooks/useTree.js +5 -0
  82. package/dist/src/hooks/useTreeNode.d.ts +2 -0
  83. package/dist/src/hooks/useTreeNode.js +3 -0
  84. package/dist/src/hooks/useValidNodeOffsetRect.d.ts +2 -0
  85. package/dist/src/hooks/useValidNodeOffsetRect.js +81 -0
  86. package/dist/src/hooks/useViewport.d.ts +2 -0
  87. package/dist/src/hooks/useViewport.js +5 -0
  88. package/dist/src/hooks/useViewportDragon.d.ts +3 -0
  89. package/dist/src/hooks/useViewportDragon.js +6 -0
  90. package/dist/src/hooks/useWorkbench.d.ts +2 -0
  91. package/dist/src/hooks/useWorkbench.js +5 -0
  92. package/dist/src/hooks/useWorkspace.d.ts +2 -0
  93. package/dist/src/hooks/useWorkspace.js +17 -0
  94. package/dist/src/index.d.ts +8 -0
  95. package/dist/src/index.js +8 -0
  96. package/dist/src/locales/global.d.ts +17 -0
  97. package/dist/src/locales/global.js +16 -0
  98. package/dist/src/locales/icons.d.ts +157 -0
  99. package/dist/src/locales/icons.js +156 -0
  100. package/dist/src/locales/index.d.ts +5 -0
  101. package/dist/src/locales/index.js +7 -0
  102. package/dist/src/locales/operations.d.ts +57 -0
  103. package/dist/src/locales/operations.js +56 -0
  104. package/dist/src/locales/panels.d.ts +19 -0
  105. package/dist/src/locales/panels.js +18 -0
  106. package/dist/src/shared/globals.d.ts +5 -0
  107. package/dist/src/shared/globals.js +5 -0
  108. package/dist/src/types.d.ts +36 -0
  109. package/dist/src/types.js +1 -0
  110. package/dist/src/widgets/AuxToolWidget/Cover.d.ts +2 -0
  111. package/dist/src/widgets/AuxToolWidget/Cover.js +48 -0
  112. package/dist/src/widgets/AuxToolWidget/Helpers.d.ts +6 -0
  113. package/dist/src/widgets/AuxToolWidget/Helpers.js +74 -0
  114. package/dist/src/widgets/AuxToolWidget/Insertion.d.ts +2 -0
  115. package/dist/src/widgets/AuxToolWidget/Insertion.js +99 -0
  116. package/dist/src/widgets/AuxToolWidget/Selection.d.ts +7 -0
  117. package/dist/src/widgets/AuxToolWidget/Selection.js +61 -0
  118. package/dist/src/widgets/AuxToolWidget/index.d.ts +5 -0
  119. package/dist/src/widgets/AuxToolWidget/index.js +35 -0
  120. package/dist/src/widgets/DesignerToolsWidget/index.d.ts +9 -0
  121. package/dist/src/widgets/DesignerToolsWidget/index.js +179 -0
  122. package/dist/src/widgets/DroppableWidget/index.d.ts +9 -0
  123. package/dist/src/widgets/DroppableWidget/index.js +20 -0
  124. package/dist/src/widgets/EmptyWidget/index.d.ts +5 -0
  125. package/dist/src/widgets/EmptyWidget/index.js +25 -0
  126. package/dist/src/widgets/GhostWidget/index.d.ts +2 -0
  127. package/dist/src/widgets/GhostWidget/index.js +47 -0
  128. package/dist/src/widgets/HistoryWidget/index.d.ts +2 -0
  129. package/dist/src/widgets/HistoryWidget/index.js +409 -0
  130. package/dist/src/widgets/IconWidget/index.d.ts +26 -0
  131. package/dist/src/widgets/IconWidget/index.js +203 -0
  132. package/dist/src/widgets/NodePathWidget/index.d.ts +6 -0
  133. package/dist/src/widgets/NodePathWidget/index.js +32 -0
  134. package/dist/src/widgets/NodeTitleWidget/index.d.ts +6 -0
  135. package/dist/src/widgets/NodeTitleWidget/index.js +13 -0
  136. package/dist/src/widgets/TextWidget/index.d.ts +10 -0
  137. package/dist/src/widgets/TextWidget/index.js +36 -0
  138. package/dist/src/widgets/ViewToolsWidget/index.d.ts +11 -0
  139. package/dist/src/widgets/ViewToolsWidget/index.js +76 -0
  140. package/dist/src/widgets/index.d.ts +11 -0
  141. package/dist/src/widgets/index.js +11 -0
  142. package/package.json +61 -4
@@ -0,0 +1,99 @@
1
+ import { observer } from '@formily/reactive-react';
2
+ import { ClosestPosition } from '@yimoka/designable-core';
3
+ import React from 'react';
4
+ import { useDragon, usePrefix } from "../../hooks/index.js";
5
+ const beforeDirections = [
6
+ ClosestPosition.Before,
7
+ ClosestPosition.ForbidBefore,
8
+ ];
9
+ const afterDirections = [
10
+ ClosestPosition.After,
11
+ ClosestPosition.ForbidAfter,
12
+ ];
13
+ const innerAfterDirections = [
14
+ ClosestPosition.InnerAfter,
15
+ ClosestPosition.Under,
16
+ ClosestPosition.ForbidInnerAfter,
17
+ ClosestPosition.ForbidUnder,
18
+ ];
19
+ const innerBeforeDirections = [
20
+ ClosestPosition.InnerBefore,
21
+ ClosestPosition.Upper,
22
+ ClosestPosition.ForbidInnerBefore,
23
+ ClosestPosition.ForbidUpper,
24
+ ];
25
+ const createBaseStyle = () => ({
26
+ position: 'absolute',
27
+ transform: 'perspective(1px) translate3d(0,0,0)',
28
+ top: 0,
29
+ left: 0,
30
+ backgroundColor: '#1890ff',
31
+ pointerEvents: 'none',
32
+ zIndex: 2,
33
+ });
34
+ const createVerticalLineStyle = (rect, x) => ({
35
+ width: 2,
36
+ height: rect.height,
37
+ transform: `perspective(1px) translate3d(${x}px,${rect.y}px,0)`,
38
+ });
39
+ const createHorizontalLineStyle = (rect, y) => ({
40
+ width: rect.width,
41
+ height: 2,
42
+ transform: `perspective(1px) translate3d(${rect.x}px,${y}px,0)`,
43
+ });
44
+ const createInnerBorderStyle = (rect) => ({
45
+ width: rect.width,
46
+ height: rect.height,
47
+ transform: `perspective(1px) translate3d(${rect.x}px,${rect.y}px,0)`,
48
+ backgroundColor: 'transparent',
49
+ border: '2px dashed #1890ff',
50
+ });
51
+ const applyForbiddenStyle = (style, direction) => {
52
+ if (!direction || !String(direction).includes('FORBID'))
53
+ return style;
54
+ return {
55
+ ...style,
56
+ backgroundColor: style.backgroundColor === 'transparent' ? 'transparent' : 'red',
57
+ border: style.border ? '2px dashed red' : style.border,
58
+ };
59
+ };
60
+ const createPositionStyle = (direction, rect, isInlineLayout) => {
61
+ if (beforeDirections.includes(direction)) {
62
+ return createVerticalLineStyle(rect, rect.x);
63
+ }
64
+ if (afterDirections.includes(direction)) {
65
+ return createVerticalLineStyle(rect, rect.x + rect.width - 2);
66
+ }
67
+ if (innerAfterDirections.includes(direction)) {
68
+ return isInlineLayout
69
+ ? createVerticalLineStyle(rect, rect.x + rect.width - 2)
70
+ : createHorizontalLineStyle(rect, rect.y + rect.height - 2);
71
+ }
72
+ if (innerBeforeDirections.includes(direction)) {
73
+ return isInlineLayout
74
+ ? createVerticalLineStyle(rect, rect.x)
75
+ : createHorizontalLineStyle(rect, rect.y);
76
+ }
77
+ if (direction === ClosestPosition.Inner)
78
+ return createInnerBorderStyle(rect);
79
+ return undefined;
80
+ };
81
+ export const Insertion = observer(() => {
82
+ const viewportDragon = useDragon();
83
+ const prefix = usePrefix('aux-insertion');
84
+ const createInsertionStyle = () => {
85
+ const closestDirection = viewportDragon?.closestDirection;
86
+ const closestRect = viewportDragon?.closestOffsetRect;
87
+ const isInlineLayout = viewportDragon?.getClosestLayout?.() === 'horizontal';
88
+ const baseStyle = createBaseStyle();
89
+ if (!closestRect)
90
+ return { ...baseStyle, display: 'none' };
91
+ const positionStyle = createPositionStyle(closestDirection, closestRect, isInlineLayout);
92
+ if (!positionStyle) {
93
+ return { ...baseStyle, display: 'none' };
94
+ }
95
+ return applyForbiddenStyle({ ...baseStyle, ...positionStyle }, closestDirection);
96
+ };
97
+ return React.createElement("div", { className: prefix, style: createInsertionStyle() });
98
+ });
99
+ Insertion.displayName = 'Insertion';
@@ -0,0 +1,7 @@
1
+ import type { TreeNode } from '@yimoka/designable-core';
2
+ import React from 'react';
3
+ export interface ISelectionBoxProps {
4
+ node: TreeNode;
5
+ }
6
+ export declare const SelectionBox: React.FC<ISelectionBoxProps>;
7
+ export declare const Selection: React.MemoExoticComponent<import("@formily/reactive-react").ReactFC<unknown>>;
@@ -0,0 +1,61 @@
1
+ import { observer } from '@formily/reactive-react';
2
+ import { CursorStatus } from '@yimoka/designable-core';
3
+ import React, { Fragment } from 'react';
4
+ import { useCursor, useDesigner, useDragon, usePrefix, useSelection, useTree, useValidNodeOffsetRect, } from "../../hooks/index.js";
5
+ import { Helpers } from "./Helpers.js";
6
+ export const SelectionBox = observer((props) => {
7
+ const designer = useDesigner();
8
+ const prefix = usePrefix('aux-selection-box');
9
+ const rect = useValidNodeOffsetRect(props.node);
10
+ const nodeSelectionIdAttrName = designer?.props?.nodeSelectionIdAttrName;
11
+ if (!rect?.width || !rect?.height)
12
+ return null;
13
+ const selectionIdProps = nodeSelectionIdAttrName
14
+ ? { [nodeSelectionIdAttrName]: props.node.id }
15
+ : {};
16
+ return (React.createElement("div", { ...selectionIdProps, className: prefix, style: {
17
+ boxSizing: 'border-box',
18
+ height: rect.height,
19
+ left: 0,
20
+ pointerEvents: 'none',
21
+ position: 'absolute',
22
+ top: 0,
23
+ transform: `perspective(1px) translate3d(${rect.x}px,${rect.y}px,0)`,
24
+ width: rect.width,
25
+ } },
26
+ React.createElement("div", { className: `${prefix}-inner`, style: {
27
+ border: '1px solid #1890ff',
28
+ boxShadow: '0 0 0 1px rgba(24, 144, 255, 0.18)',
29
+ boxSizing: 'border-box',
30
+ height: '100%',
31
+ width: '100%',
32
+ } })));
33
+ });
34
+ SelectionBox.displayName = 'SelectionBox';
35
+ export const Selection = observer(() => {
36
+ const cursor = useCursor();
37
+ const selection = useSelection();
38
+ const tree = useTree();
39
+ const viewportDragon = useDragon();
40
+ const isDragging = cursor?.status === CursorStatus.DragStart
41
+ || cursor?.status === CursorStatus.Dragging;
42
+ if (!selection || !tree)
43
+ return null;
44
+ if (isDragging && viewportDragon?.touchNode)
45
+ return null;
46
+ return (React.createElement(Fragment, null,
47
+ selection.selected.map((id) => {
48
+ const node = tree.findById(id);
49
+ if (!node || node.hidden)
50
+ return null;
51
+ return (React.createElement(SelectionBox, { key: id, node: node }));
52
+ }),
53
+ selection.selected.length === 1 ? (() => {
54
+ const [id] = selection.selected;
55
+ const node = tree.findById(id);
56
+ if (!node || node.hidden)
57
+ return null;
58
+ return React.createElement(Helpers, { key: `${id}-helpers`, node: node });
59
+ })() : null));
60
+ });
61
+ Selection.displayName = 'Selection';
@@ -0,0 +1,5 @@
1
+ import React from 'react';
2
+ export declare const AuxToolWidget: {
3
+ (): React.JSX.Element | null;
4
+ displayName: string;
5
+ };
@@ -0,0 +1,35 @@
1
+ import React, { useEffect, useRef } from 'react';
2
+ import { useDesigner, usePrefix, useViewport } from "../../hooks/index.js";
3
+ import { Cover } from "./Cover.js";
4
+ import { Insertion } from "./Insertion.js";
5
+ import { Selection } from "./Selection.js";
6
+ export const AuxToolWidget = () => {
7
+ const engine = useDesigner();
8
+ const viewport = useViewport();
9
+ const prefix = usePrefix('auxtool');
10
+ const ref = useRef(null);
11
+ useEffect(() => {
12
+ if (!engine)
13
+ return;
14
+ return engine.subscribeWith('viewport:scroll', () => {
15
+ if (viewport?.isIframe && ref.current) {
16
+ ref.current.style.transform = `perspective(1px) translate3d(${-viewport.scrollX}px,${-viewport.scrollY}px,0)`;
17
+ }
18
+ });
19
+ }, [engine, viewport]);
20
+ if (!viewport)
21
+ return null;
22
+ return (React.createElement("div", { ref: ref, className: prefix, style: {
23
+ position: 'absolute',
24
+ top: 0,
25
+ left: 0,
26
+ right: 0,
27
+ bottom: 0,
28
+ pointerEvents: 'none',
29
+ zIndex: 2,
30
+ } },
31
+ React.createElement(Insertion, null),
32
+ React.createElement(Cover, null),
33
+ React.createElement(Selection, null)));
34
+ };
35
+ AuxToolWidget.displayName = 'AuxToolWidget';
@@ -0,0 +1,9 @@
1
+ import React from 'react';
2
+ type DesignerToolsType = 'HISTORY' | 'CURSOR' | 'SCREEN_TYPE';
3
+ export interface IDesignerToolsWidgetProps {
4
+ className?: string;
5
+ style?: React.CSSProperties;
6
+ use?: DesignerToolsType[];
7
+ }
8
+ export declare const DesignerToolsWidget: React.FC<IDesignerToolsWidgetProps>;
9
+ export {};
@@ -0,0 +1,179 @@
1
+ import { BorderOutlined, CloseOutlined, DesktopOutlined, DragOutlined, MobileOutlined, RedoOutlined, ReloadOutlined, RotateLeftOutlined, UndoOutlined, } from '@ant-design/icons';
2
+ import { observer } from '@formily/reactive-react';
3
+ import { CursorType, resetDragDropState, ScreenType } from '@yimoka/designable-core';
4
+ import cls from 'classnames';
5
+ import React, { Fragment, useRef } from 'react';
6
+ import { useUIAdapter } from "../../adapter/index.js";
7
+ import { useCursor, useHistory, useOperation, usePrefix, useRegistry, useScreen, useWorkbench, } from "../../hooks/index.js";
8
+ import { IconWidget } from "../IconWidget/index.js";
9
+ const toFiniteScreenSize = (value) => {
10
+ if (value === undefined || value === '')
11
+ return undefined;
12
+ const numberValue = typeof value === 'number' ? value : Number(value);
13
+ return Number.isFinite(numberValue) ? numberValue : undefined;
14
+ };
15
+ export const DesignerToolsWidget = observer((props) => {
16
+ const { Button, ButtonGroup, InputNumber, Tooltip } = useUIAdapter();
17
+ const screen = useScreen();
18
+ const cursor = useCursor();
19
+ const workbench = useWorkbench();
20
+ const history = useHistory();
21
+ const operation = useOperation();
22
+ const registry = useRegistry();
23
+ const sizeRef = useRef({});
24
+ const [activeSizeTarget, setActiveSizeTarget] = React.useState();
25
+ const prefix = usePrefix('designer-tools');
26
+ const use = props.use ?? ['HISTORY', 'CURSOR', 'SCREEN_TYPE'];
27
+ const syncHistoryInteractionState = () => {
28
+ resetDragDropState();
29
+ operation?.dragClean();
30
+ operation?.hover?.clear?.();
31
+ };
32
+ const getIconTooltip = (iconName, fallback) => {
33
+ const token = `icons.${iconName}`;
34
+ const tooltip = registry?.getDesignerMessage(token);
35
+ if (!tooltip) {
36
+ return fallback;
37
+ }
38
+ return String(tooltip);
39
+ };
40
+ const renderHistoryController = () => {
41
+ if (!use.includes('HISTORY'))
42
+ return null;
43
+ return (React.createElement(ButtonGroup, { className: `${prefix}-group`, style: { marginRight: 20 } },
44
+ React.createElement(Tooltip, { title: getIconTooltip('Undo', '撤销') },
45
+ React.createElement(Button, { ariaLabel: "\u64A4\u9500", disabled: !history?.allowUndo, onClick: () => {
46
+ history?.undo();
47
+ syncHistoryInteractionState();
48
+ } },
49
+ React.createElement(IconWidget, { infer: React.createElement(UndoOutlined, null) }))),
50
+ React.createElement(Tooltip, { title: getIconTooltip('Redo', '重做') },
51
+ React.createElement(Button, { ariaLabel: "\u91CD\u505A", disabled: !history?.allowRedo, onClick: () => {
52
+ history?.redo();
53
+ syncHistoryInteractionState();
54
+ } },
55
+ React.createElement(IconWidget, { infer: React.createElement(RedoOutlined, null) })))));
56
+ };
57
+ const renderCursorController = () => {
58
+ if (workbench?.type !== 'DESIGNABLE')
59
+ return null;
60
+ if (!use.includes('CURSOR'))
61
+ return null;
62
+ return (React.createElement(ButtonGroup, { className: `${prefix}-group`, style: { marginRight: 20 } },
63
+ React.createElement(Tooltip, { title: getIconTooltip('Move', '移动') },
64
+ React.createElement(Button, { ariaLabel: "\u79FB\u52A8", disabled: cursor?.type === CursorType.Move, onClick: () => {
65
+ cursor?.setType(CursorType.Move);
66
+ } },
67
+ React.createElement(IconWidget, { infer: React.createElement(DragOutlined, null) }))),
68
+ React.createElement(Tooltip, { title: getIconTooltip('Selection', '选择') },
69
+ React.createElement(Button, { ariaLabel: "\u9009\u62E9", disabled: cursor?.type === CursorType.Selection, onClick: () => {
70
+ cursor?.setType(CursorType.Selection);
71
+ } },
72
+ React.createElement(IconWidget, { infer: React.createElement(BorderOutlined, null) })))));
73
+ };
74
+ const renderResponsiveController = () => {
75
+ if (!use.includes('SCREEN_TYPE'))
76
+ return null;
77
+ if (screen?.type !== ScreenType.Responsive)
78
+ return null;
79
+ const width = toFiniteScreenSize(screen?.width);
80
+ const height = toFiniteScreenSize(screen?.height);
81
+ const shouldShowResetButton = activeSizeTarget === 'width'
82
+ ? screen?.width !== '100%'
83
+ : activeSizeTarget === 'height'
84
+ ? screen?.height !== '100%'
85
+ : screen?.width !== '100%' || screen?.height !== '100%';
86
+ return (React.createElement(Fragment, null,
87
+ React.createElement("span", { onFocus: () => {
88
+ setActiveSizeTarget('width');
89
+ } },
90
+ React.createElement(InputNumber, { style: { width: 70, textAlign: 'center' }, value: width, onChange: (value) => {
91
+ const nextWidth = toFiniteScreenSize(value ?? undefined);
92
+ sizeRef.current.width = nextWidth;
93
+ if (nextWidth !== undefined) {
94
+ screen?.setSize(nextWidth, screen.height);
95
+ }
96
+ }, onPressEnter: () => {
97
+ screen?.setSize(sizeRef.current.width, screen.height);
98
+ } })),
99
+ React.createElement("span", { "aria-hidden": "true", style: {
100
+ alignItems: 'center',
101
+ color: '#999',
102
+ display: 'inline-flex',
103
+ height: 32,
104
+ justifyContent: 'center',
105
+ padding: '0 3px',
106
+ } },
107
+ React.createElement(IconWidget, { infer: React.createElement(CloseOutlined, null), size: 10 })),
108
+ React.createElement("span", { style: { marginRight: 10 }, onFocus: () => {
109
+ setActiveSizeTarget('height');
110
+ } },
111
+ React.createElement(InputNumber, { style: {
112
+ width: 70,
113
+ textAlign: 'center',
114
+ }, value: height, onChange: (value) => {
115
+ const nextHeight = toFiniteScreenSize(value ?? undefined);
116
+ sizeRef.current.height = nextHeight;
117
+ if (nextHeight !== undefined) {
118
+ screen?.setSize(screen.width, nextHeight);
119
+ }
120
+ }, onPressEnter: () => {
121
+ screen?.setSize(screen.width, sizeRef.current.height);
122
+ } })),
123
+ shouldShowResetButton && (React.createElement(Button, { ariaLabel: "\u91CD\u7F6E\u5C3A\u5BF8", style: { marginRight: 20 }, onClick: () => {
124
+ if (activeSizeTarget === 'width') {
125
+ sizeRef.current.width = undefined;
126
+ screen?.setSize('100%', screen.height);
127
+ return;
128
+ }
129
+ if (activeSizeTarget === 'height') {
130
+ sizeRef.current.height = undefined;
131
+ screen?.setSize(screen.width, '100%');
132
+ return;
133
+ }
134
+ screen?.resetSize();
135
+ } },
136
+ React.createElement(IconWidget, { infer: React.createElement(ReloadOutlined, null) })))));
137
+ };
138
+ const renderScreenTypeController = () => {
139
+ if (!use.includes('SCREEN_TYPE'))
140
+ return null;
141
+ return (React.createElement(ButtonGroup, { className: `${prefix}-group`, style: { marginRight: 20 } },
142
+ React.createElement(Tooltip, { title: getIconTooltip('PC', 'PC') },
143
+ React.createElement(Button, { ariaLabel: "PC", disabled: screen?.type === ScreenType.PC, onClick: () => {
144
+ screen?.setType(ScreenType.PC);
145
+ } },
146
+ React.createElement(IconWidget, { infer: React.createElement(DesktopOutlined, null) }))),
147
+ React.createElement(Tooltip, { title: getIconTooltip('Mobile', '移动端') },
148
+ React.createElement(Button, { ariaLabel: "\u79FB\u52A8\u7AEF", disabled: screen?.type === ScreenType.Mobile, onClick: () => {
149
+ screen?.setType(ScreenType.Mobile);
150
+ } },
151
+ React.createElement(IconWidget, { infer: React.createElement(MobileOutlined, null) }))),
152
+ React.createElement(Tooltip, { title: getIconTooltip('Responsive', '响应式') },
153
+ React.createElement(Button, { ariaLabel: "\u54CD\u5E94\u5F0F", disabled: screen?.type === ScreenType.Responsive, onClick: () => {
154
+ screen?.setType(ScreenType.Responsive);
155
+ } },
156
+ React.createElement(IconWidget, { infer: React.createElement(MobileOutlined, null) })))));
157
+ };
158
+ const renderMobileController = () => {
159
+ if (!use.includes('SCREEN_TYPE'))
160
+ return null;
161
+ if (screen?.type !== ScreenType.Mobile)
162
+ return null;
163
+ return (React.createElement(Tooltip, { title: getIconTooltip('Flip', '翻转') },
164
+ React.createElement(Button, { ariaLabel: "\u7FFB\u8F6C", style: { marginRight: 20 }, onClick: () => {
165
+ screen?.setFlip(!screen.flip);
166
+ } },
167
+ React.createElement(IconWidget, { infer: React.createElement(RotateLeftOutlined, null), style: {
168
+ transition: 'all .15s ease-in',
169
+ transform: screen?.flip ? 'rotate(-90deg)' : '',
170
+ } }))));
171
+ };
172
+ return (React.createElement("div", { className: cls(prefix, props.className), style: props.style },
173
+ renderHistoryController(),
174
+ renderCursorController(),
175
+ renderScreenTypeController(),
176
+ renderMobileController(),
177
+ renderResponsiveController()));
178
+ });
179
+ DesignerToolsWidget.displayName = 'DesignerToolsWidget';
@@ -0,0 +1,9 @@
1
+ import type { TreeNode } from '@yimoka/designable-core';
2
+ import React from 'react';
3
+ export interface IDroppableWidgetProps extends React.HTMLAttributes<HTMLDivElement> {
4
+ node?: TreeNode;
5
+ placeholder?: boolean;
6
+ height?: number;
7
+ hasChildren?: boolean;
8
+ }
9
+ export declare const DroppableWidget: React.FC<IDroppableWidgetProps>;
@@ -0,0 +1,20 @@
1
+ import { observer } from '@formily/reactive-react';
2
+ import cls from 'classnames';
3
+ import React from 'react';
4
+ import { useNodeIdProps, usePrefix, useTreeNode } from "../../hooks/index.js";
5
+ import { NodeTitleWidget } from "../NodeTitleWidget/index.js";
6
+ export const DroppableWidget = observer(({ children, className, hasChildren: hasChildrenProp, height = 40, node, placeholder = true, style, ...props }) => {
7
+ const currentNode = useTreeNode();
8
+ const prefix = usePrefix('droppable');
9
+ const target = node ?? currentNode ?? undefined;
10
+ const nodeIdProps = useNodeIdProps(target);
11
+ const hasChildren = hasChildrenProp ?? Boolean(target?.children?.length || React.Children.count(children));
12
+ const renderContent = () => {
13
+ if (hasChildren || !placeholder) {
14
+ return children;
15
+ }
16
+ return (React.createElement("div", { className: `${prefix}-placeholder`, style: { height } }, target ? React.createElement(NodeTitleWidget, { node: target }) : null));
17
+ };
18
+ return (React.createElement("div", { ...props, ...nodeIdProps, className: cls(prefix, className), style: style }, renderContent()));
19
+ });
20
+ DroppableWidget.displayName = 'DroppableWidget';
@@ -0,0 +1,5 @@
1
+ import React from 'react';
2
+ export interface IEmptyWidgetProps extends React.HTMLAttributes<HTMLDivElement> {
3
+ description?: React.ReactNode;
4
+ }
5
+ export declare const EmptyWidget: React.FC<IEmptyWidgetProps>;
@@ -0,0 +1,25 @@
1
+ import { observer } from '@formily/reactive-react';
2
+ import cls from 'classnames';
3
+ import React from 'react';
4
+ import { usePrefix, useTree } from "../../hooks/index.js";
5
+ export const EmptyWidget = observer(({ children, className, description = '从左侧拖入组件开始设计', style, ...props }) => {
6
+ const tree = useTree();
7
+ const prefix = usePrefix('empty');
8
+ if (tree?.children?.length)
9
+ return null;
10
+ return (React.createElement("div", { ...props, className: cls(prefix, className), style: {
11
+ alignItems: 'center',
12
+ color: '#8c8c8c',
13
+ display: 'flex',
14
+ flexDirection: 'column',
15
+ fontSize: 13,
16
+ inset: 0,
17
+ justifyContent: 'center',
18
+ minHeight: 180,
19
+ pointerEvents: 'none',
20
+ position: 'absolute',
21
+ textAlign: 'center',
22
+ ...style,
23
+ } }, children ?? (React.createElement("div", null, description))));
24
+ });
25
+ EmptyWidget.displayName = 'EmptyWidget';
@@ -0,0 +1,2 @@
1
+ import React from 'react';
2
+ export declare const GhostWidget: React.MemoExoticComponent<import("@formily/reactive-react").ReactFC<unknown>>;
@@ -0,0 +1,47 @@
1
+ import { autorun } from '@formily/reactive';
2
+ import { observer } from '@formily/reactive-react';
3
+ import { CursorStatus } from '@yimoka/designable-core';
4
+ import React, { useEffect, useRef } from 'react';
5
+ import { useCursor, useDragon, usePrefix } from "../../hooks/index.js";
6
+ import { NodeTitleWidget } from "../NodeTitleWidget/index.js";
7
+ export const GhostWidget = observer(() => {
8
+ const dragon = useDragon();
9
+ const cursor = useCursor();
10
+ const ref = useRef(null);
11
+ const prefix = usePrefix('ghost');
12
+ const draggingNodes = dragon?.dragNodes ?? [];
13
+ const firstNode = draggingNodes[0];
14
+ useEffect(() => autorun(() => {
15
+ const x = cursor?.position?.topClientX ?? 0;
16
+ const y = cursor?.position?.topClientY ?? 0;
17
+ const transform = `perspective(1px) translate3d(${x - 18}px,${y - 12}px,0) scale(0.8)`;
18
+ if (!ref.current)
19
+ return;
20
+ ref.current.style.transform = transform;
21
+ }), [cursor]);
22
+ const renderNodes = () => (React.createElement("span", { style: {
23
+ whiteSpace: 'nowrap',
24
+ } },
25
+ React.createElement(NodeTitleWidget, { node: firstNode }),
26
+ draggingNodes.length > 1 ? '...' : ''));
27
+ if (!firstNode)
28
+ return null;
29
+ return cursor?.status === CursorStatus.Dragging ? (React.createElement("div", { ref: ref, className: prefix, style: {
30
+ paddingLeft: 25,
31
+ paddingRight: 15,
32
+ height: 30,
33
+ display: 'flex',
34
+ justifyContent: 'center',
35
+ alignItems: 'center',
36
+ position: 'fixed',
37
+ color: '#fff',
38
+ fontSize: 12,
39
+ zIndex: 9999,
40
+ borderRadius: 50,
41
+ backgroundColor: 'rgba(0, 100, 255, 0.8)',
42
+ pointerEvents: 'none',
43
+ left: 0,
44
+ top: 0,
45
+ } }, renderNodes())) : null;
46
+ });
47
+ GhostWidget.displayName = 'GhostWidget';
@@ -0,0 +1,2 @@
1
+ import React from 'react';
2
+ export declare const HistoryWidget: React.FC;