@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.
- package/README.md +6 -2
- package/dist/src/adapter/UIAdapterProvider.d.ts +7 -0
- package/dist/src/adapter/UIAdapterProvider.js +10 -0
- package/dist/src/adapter/context-core.d.ts +2 -0
- package/dist/src/adapter/context-core.js +3 -0
- package/dist/src/adapter/context.d.ts +6 -0
- package/dist/src/adapter/context.js +9 -0
- package/dist/src/adapter/default-components.d.ts +8 -0
- package/dist/src/adapter/default-components.js +38 -0
- package/dist/src/adapter/default.d.ts +2 -0
- package/dist/src/adapter/default.js +9 -0
- package/dist/src/adapter/index.d.ts +3 -0
- package/dist/src/adapter/index.js +3 -0
- package/dist/src/adapter/types.d.ts +63 -0
- package/dist/src/adapter/types.js +1 -0
- package/dist/src/containers/Designer.d.ts +3 -0
- package/dist/src/containers/Designer.js +63 -0
- package/dist/src/containers/Sandbox.d.ts +4 -0
- package/dist/src/containers/Sandbox.js +3 -0
- package/dist/src/containers/SandboxComponent.d.ts +3 -0
- package/dist/src/containers/SandboxComponent.js +15 -0
- package/dist/src/containers/Simulator.d.ts +3 -0
- package/dist/src/containers/Simulator.js +70 -0
- package/dist/src/containers/Viewport.d.ts +6 -0
- package/dist/src/containers/Viewport.js +71 -0
- package/dist/src/containers/Workbench.d.ts +2 -0
- package/dist/src/containers/Workbench.js +9 -0
- package/dist/src/containers/Workspace.d.ts +7 -0
- package/dist/src/containers/Workspace.js +39 -0
- package/dist/src/containers/index.d.ts +6 -0
- package/dist/src/containers/index.js +6 -0
- package/dist/src/containers/sandbox-types.d.ts +7 -0
- package/dist/src/containers/sandbox-types.js +1 -0
- package/dist/src/containers/sandbox-utils.d.ts +6 -0
- package/dist/src/containers/sandbox-utils.js +40 -0
- package/dist/src/containers/useSandbox.d.ts +3 -0
- package/dist/src/containers/useSandbox.js +77 -0
- package/dist/src/context.d.ts +7 -0
- package/dist/src/context.js +6 -0
- package/dist/src/hooks/index.d.ts +26 -0
- package/dist/src/hooks/index.js +26 -0
- package/dist/src/hooks/useComponents.d.ts +2 -0
- package/dist/src/hooks/useComponents.js +3 -0
- package/dist/src/hooks/useCurrentNode.d.ts +2 -0
- package/dist/src/hooks/useCurrentNode.js +7 -0
- package/dist/src/hooks/useCurrentNodeSelected.d.ts +1 -0
- package/dist/src/hooks/useCurrentNodeSelected.js +7 -0
- package/dist/src/hooks/useCursor.d.ts +2 -0
- package/dist/src/hooks/useCursor.js +5 -0
- package/dist/src/hooks/useDesigner.d.ts +3 -0
- package/dist/src/hooks/useDesigner.js +15 -0
- package/dist/src/hooks/useHistory.d.ts +2 -0
- package/dist/src/hooks/useHistory.js +5 -0
- package/dist/src/hooks/useHover.d.ts +2 -0
- package/dist/src/hooks/useHover.js +5 -0
- package/dist/src/hooks/useLayout.d.ts +2 -0
- package/dist/src/hooks/useLayout.js +8 -0
- package/dist/src/hooks/useNodeIdProps.d.ts +2 -0
- package/dist/src/hooks/useNodeIdProps.js +17 -0
- package/dist/src/hooks/useOperation.d.ts +2 -0
- package/dist/src/hooks/useOperation.js +5 -0
- package/dist/src/hooks/useOutline.d.ts +2 -0
- package/dist/src/hooks/useOutline.js +5 -0
- package/dist/src/hooks/useOutlineDragon.d.ts +2 -0
- package/dist/src/hooks/useOutlineDragon.js +5 -0
- package/dist/src/hooks/usePosition.d.ts +1 -0
- package/dist/src/hooks/usePosition.js +2 -0
- package/dist/src/hooks/usePrefix.d.ts +1 -0
- package/dist/src/hooks/usePrefix.js +5 -0
- package/dist/src/hooks/useRegistry.d.ts +2 -0
- package/dist/src/hooks/useRegistry.js +6 -0
- package/dist/src/hooks/useScreen.d.ts +2 -0
- package/dist/src/hooks/useScreen.js +2 -0
- package/dist/src/hooks/useSelected.d.ts +1 -0
- package/dist/src/hooks/useSelected.js +5 -0
- package/dist/src/hooks/useSelection.d.ts +2 -0
- package/dist/src/hooks/useSelection.js +5 -0
- package/dist/src/hooks/useTheme.d.ts +1 -0
- package/dist/src/hooks/useTheme.js +2 -0
- package/dist/src/hooks/useTree.d.ts +2 -0
- package/dist/src/hooks/useTree.js +5 -0
- package/dist/src/hooks/useTreeNode.d.ts +2 -0
- package/dist/src/hooks/useTreeNode.js +3 -0
- package/dist/src/hooks/useValidNodeOffsetRect.d.ts +2 -0
- package/dist/src/hooks/useValidNodeOffsetRect.js +81 -0
- package/dist/src/hooks/useViewport.d.ts +2 -0
- package/dist/src/hooks/useViewport.js +5 -0
- package/dist/src/hooks/useViewportDragon.d.ts +3 -0
- package/dist/src/hooks/useViewportDragon.js +6 -0
- package/dist/src/hooks/useWorkbench.d.ts +2 -0
- package/dist/src/hooks/useWorkbench.js +5 -0
- package/dist/src/hooks/useWorkspace.d.ts +2 -0
- package/dist/src/hooks/useWorkspace.js +17 -0
- package/dist/src/index.d.ts +8 -0
- package/dist/src/index.js +8 -0
- package/dist/src/locales/global.d.ts +17 -0
- package/dist/src/locales/global.js +16 -0
- package/dist/src/locales/icons.d.ts +157 -0
- package/dist/src/locales/icons.js +156 -0
- package/dist/src/locales/index.d.ts +5 -0
- package/dist/src/locales/index.js +7 -0
- package/dist/src/locales/operations.d.ts +57 -0
- package/dist/src/locales/operations.js +56 -0
- package/dist/src/locales/panels.d.ts +19 -0
- package/dist/src/locales/panels.js +18 -0
- package/dist/src/shared/globals.d.ts +5 -0
- package/dist/src/shared/globals.js +5 -0
- package/dist/src/types.d.ts +36 -0
- package/dist/src/types.js +1 -0
- package/dist/src/widgets/AuxToolWidget/Cover.d.ts +2 -0
- package/dist/src/widgets/AuxToolWidget/Cover.js +48 -0
- package/dist/src/widgets/AuxToolWidget/Helpers.d.ts +6 -0
- package/dist/src/widgets/AuxToolWidget/Helpers.js +74 -0
- package/dist/src/widgets/AuxToolWidget/Insertion.d.ts +2 -0
- package/dist/src/widgets/AuxToolWidget/Insertion.js +99 -0
- package/dist/src/widgets/AuxToolWidget/Selection.d.ts +7 -0
- package/dist/src/widgets/AuxToolWidget/Selection.js +61 -0
- package/dist/src/widgets/AuxToolWidget/index.d.ts +5 -0
- package/dist/src/widgets/AuxToolWidget/index.js +35 -0
- package/dist/src/widgets/DesignerToolsWidget/index.d.ts +9 -0
- package/dist/src/widgets/DesignerToolsWidget/index.js +179 -0
- package/dist/src/widgets/DroppableWidget/index.d.ts +9 -0
- package/dist/src/widgets/DroppableWidget/index.js +20 -0
- package/dist/src/widgets/EmptyWidget/index.d.ts +5 -0
- package/dist/src/widgets/EmptyWidget/index.js +25 -0
- package/dist/src/widgets/GhostWidget/index.d.ts +2 -0
- package/dist/src/widgets/GhostWidget/index.js +47 -0
- package/dist/src/widgets/HistoryWidget/index.d.ts +2 -0
- package/dist/src/widgets/HistoryWidget/index.js +409 -0
- package/dist/src/widgets/IconWidget/index.d.ts +26 -0
- package/dist/src/widgets/IconWidget/index.js +203 -0
- package/dist/src/widgets/NodePathWidget/index.d.ts +6 -0
- package/dist/src/widgets/NodePathWidget/index.js +32 -0
- package/dist/src/widgets/NodeTitleWidget/index.d.ts +6 -0
- package/dist/src/widgets/NodeTitleWidget/index.js +13 -0
- package/dist/src/widgets/TextWidget/index.d.ts +10 -0
- package/dist/src/widgets/TextWidget/index.js +36 -0
- package/dist/src/widgets/ViewToolsWidget/index.d.ts +11 -0
- package/dist/src/widgets/ViewToolsWidget/index.js +76 -0
- package/dist/src/widgets/index.d.ts +11 -0
- package/dist/src/widgets/index.js +11 -0
- package/package.json +61 -4
|
@@ -0,0 +1,409 @@
|
|
|
1
|
+
import { observer } from '@formily/reactive-react';
|
|
2
|
+
import { CursorStatus, CursorType, resetDragDropState, } from '@yimoka/designable-core';
|
|
3
|
+
import cls from 'classnames';
|
|
4
|
+
import React from 'react';
|
|
5
|
+
import { useUIAdapter } from "../../adapter/index.js";
|
|
6
|
+
import { useOperation, usePrefix, useWorkbench } from "../../hooks/index.js";
|
|
7
|
+
import { TextWidget } from "../TextWidget/index.js";
|
|
8
|
+
const formatDate = (timestamp) => {
|
|
9
|
+
const date = new Date(timestamp);
|
|
10
|
+
const pad = (n) => n.toString().padStart(2, '0');
|
|
11
|
+
return `${date.getFullYear().toString()
|
|
12
|
+
.slice(-2)}/${pad(date.getMonth() + 1)}/${pad(date.getDate())} ${pad(date.getHours())}:${pad(date.getMinutes())}:${pad(date.getSeconds())}`;
|
|
13
|
+
};
|
|
14
|
+
const formatTime = (timestamp) => {
|
|
15
|
+
const date = new Date(timestamp);
|
|
16
|
+
const pad = (n) => n.toString().padStart(2, '0');
|
|
17
|
+
return `${pad(date.getHours())}:${pad(date.getMinutes())}:${pad(date.getSeconds())}`;
|
|
18
|
+
};
|
|
19
|
+
const OperationFallbackMessages = {
|
|
20
|
+
append_node: '追加节点',
|
|
21
|
+
clear_design: '清空画布',
|
|
22
|
+
clone_node: '复制节点',
|
|
23
|
+
default_state: '初始状态',
|
|
24
|
+
drop_node: '拖入节点',
|
|
25
|
+
from_node: '子树更新',
|
|
26
|
+
init_schema: '初始化 Schema',
|
|
27
|
+
import_schema: '导入 Schema',
|
|
28
|
+
insert_after: '后置插入',
|
|
29
|
+
insert_before: '前置插入',
|
|
30
|
+
insert_children: '插入子节点',
|
|
31
|
+
insert_node: '插入节点',
|
|
32
|
+
load_design: '加载设计',
|
|
33
|
+
move_outline_node: '大纲排序',
|
|
34
|
+
paste_node: '粘贴节点',
|
|
35
|
+
prepend_node: '头部追加',
|
|
36
|
+
remove_node: '删除节点',
|
|
37
|
+
set_schema_controlled: '同步 Schema',
|
|
38
|
+
update_children: '覆盖子节点',
|
|
39
|
+
update_node_props: '属性更改',
|
|
40
|
+
update_props: '属性更改',
|
|
41
|
+
update_tree_schema: '应用 Schema',
|
|
42
|
+
wrap_node: '包装节点',
|
|
43
|
+
};
|
|
44
|
+
const formatOperationFallback = (token) => (OperationFallbackMessages[token]
|
|
45
|
+
?? token
|
|
46
|
+
.split('_')
|
|
47
|
+
.filter(Boolean)
|
|
48
|
+
.map(segment => segment.charAt(0).toUpperCase() + segment.slice(1))
|
|
49
|
+
.join(' ')
|
|
50
|
+
?? '操作记录');
|
|
51
|
+
const countNodes = (node) => {
|
|
52
|
+
if (!node)
|
|
53
|
+
return 0;
|
|
54
|
+
return 1 + (node.children ?? []).reduce((total, child) => total + countNodes(child), 0);
|
|
55
|
+
};
|
|
56
|
+
const getSelectedIds = (selected) => (Array.isArray(selected) ? selected.filter((id) => typeof id === 'string') : []);
|
|
57
|
+
const findNodeById = (node, id) => {
|
|
58
|
+
if (!node)
|
|
59
|
+
return undefined;
|
|
60
|
+
if (node.id === id)
|
|
61
|
+
return node;
|
|
62
|
+
for (const child of node.children ?? []) {
|
|
63
|
+
const matched = findNodeById(child, id);
|
|
64
|
+
if (matched)
|
|
65
|
+
return matched;
|
|
66
|
+
}
|
|
67
|
+
return undefined;
|
|
68
|
+
};
|
|
69
|
+
const getNodeFieldName = (node) => {
|
|
70
|
+
const name = node?.props?.name;
|
|
71
|
+
if (typeof name === 'string' && name.trim())
|
|
72
|
+
return name;
|
|
73
|
+
return undefined;
|
|
74
|
+
};
|
|
75
|
+
const formatNodeLabel = (node) => {
|
|
76
|
+
if (!node)
|
|
77
|
+
return 'Root';
|
|
78
|
+
const componentName = node.componentName || node.id || 'Node';
|
|
79
|
+
const fieldName = getNodeFieldName(node);
|
|
80
|
+
if (!fieldName || fieldName === componentName)
|
|
81
|
+
return componentName;
|
|
82
|
+
return `${componentName}(${fieldName})`;
|
|
83
|
+
};
|
|
84
|
+
const getSnapshotSummary = (data) => {
|
|
85
|
+
const snapshot = data;
|
|
86
|
+
const tree = snapshot?.operation?.tree;
|
|
87
|
+
const nodeCount = countNodes(tree);
|
|
88
|
+
const selectedIds = getSelectedIds(snapshot?.operation?.selected);
|
|
89
|
+
const selectedLabels = selectedIds
|
|
90
|
+
.map(id => findNodeById(tree, id))
|
|
91
|
+
.filter((node) => !!node)
|
|
92
|
+
.map(formatNodeLabel);
|
|
93
|
+
return {
|
|
94
|
+
nodeCount,
|
|
95
|
+
rootName: tree?.componentName || 'Root',
|
|
96
|
+
selectedCount: selectedIds.length,
|
|
97
|
+
targetName: selectedLabels.length ? selectedLabels.slice(0, 2).join(', ') : formatNodeLabel(tree),
|
|
98
|
+
};
|
|
99
|
+
};
|
|
100
|
+
const getHistoryStatus = (index, current) => {
|
|
101
|
+
if (index === current) {
|
|
102
|
+
return {
|
|
103
|
+
background: '#1677ff',
|
|
104
|
+
borderColor: '#1677ff',
|
|
105
|
+
color: '#fff',
|
|
106
|
+
label: '当前',
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
if (index < current) {
|
|
110
|
+
return {
|
|
111
|
+
background: '#f6faff',
|
|
112
|
+
borderColor: '#d6e8ff',
|
|
113
|
+
color: '#1677ff',
|
|
114
|
+
label: '回退',
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
return {
|
|
118
|
+
background: '#fff7e6',
|
|
119
|
+
borderColor: '#ffe0a3',
|
|
120
|
+
color: '#ad6800',
|
|
121
|
+
label: '重做',
|
|
122
|
+
};
|
|
123
|
+
};
|
|
124
|
+
const getHistoryActionState = (allow, enabledLabel, disabledLabel) => ({
|
|
125
|
+
background: allow ? '#eef6ff' : '#f7f9fc',
|
|
126
|
+
borderColor: allow ? '#cfe6ff' : '#e7edf5',
|
|
127
|
+
color: allow ? '#1677ff' : '#9aa5b5',
|
|
128
|
+
label: allow ? enabledLabel : disabledLabel,
|
|
129
|
+
});
|
|
130
|
+
const getNodeDelta = (summary, previousSummary) => {
|
|
131
|
+
if (!previousSummary)
|
|
132
|
+
return undefined;
|
|
133
|
+
return summary.nodeCount - previousSummary.nodeCount;
|
|
134
|
+
};
|
|
135
|
+
const formatNodeDelta = (delta) => {
|
|
136
|
+
if (delta === undefined)
|
|
137
|
+
return undefined;
|
|
138
|
+
if (delta > 0)
|
|
139
|
+
return `+${delta}节点`;
|
|
140
|
+
if (delta < 0)
|
|
141
|
+
return `${delta}节点`;
|
|
142
|
+
return '结构不变';
|
|
143
|
+
};
|
|
144
|
+
const getNodeDeltaStyle = (delta) => {
|
|
145
|
+
if (delta === undefined) {
|
|
146
|
+
return {
|
|
147
|
+
background: '#f7f9fc',
|
|
148
|
+
color: '#8b98aa',
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
if (delta > 0) {
|
|
152
|
+
return {
|
|
153
|
+
background: '#edf8f0',
|
|
154
|
+
color: '#237804',
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
if (delta < 0) {
|
|
158
|
+
return {
|
|
159
|
+
background: '#fff1f0',
|
|
160
|
+
color: '#cf1322',
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
return {
|
|
164
|
+
background: '#f7f9fc',
|
|
165
|
+
color: '#6b7788',
|
|
166
|
+
};
|
|
167
|
+
};
|
|
168
|
+
const createHistoryItemLabel = (title, summary, index, total, status) => (`${title},第 ${index + 1}/${total} 步,${status.label},${summary.targetName},${summary.nodeCount || 1} 个节点`);
|
|
169
|
+
const resetOperationSelection = (operation) => {
|
|
170
|
+
if (!operation?.tree || !operation.selection?.select)
|
|
171
|
+
return;
|
|
172
|
+
operation.selection.select(operation.tree);
|
|
173
|
+
};
|
|
174
|
+
const resetOperationCursor = (operation) => {
|
|
175
|
+
operation?.engine?.cursor?.setStatus?.(CursorStatus.Normal);
|
|
176
|
+
operation?.engine?.cursor?.setType?.(CursorType.Move);
|
|
177
|
+
};
|
|
178
|
+
const restoreHistoryInteractionState = (operation) => {
|
|
179
|
+
resetDragDropState();
|
|
180
|
+
operation?.dragClean?.();
|
|
181
|
+
operation?.hover?.clear?.();
|
|
182
|
+
resetOperationSelection(operation);
|
|
183
|
+
resetOperationCursor(operation);
|
|
184
|
+
};
|
|
185
|
+
const createHistoryItemRenderModel = (item, index, current, historyItems) => {
|
|
186
|
+
const type = item.type || 'default_state';
|
|
187
|
+
const token = type.replace(/:/g, '_');
|
|
188
|
+
const summary = getSnapshotSummary(item.data);
|
|
189
|
+
const previousSummary = index > 0
|
|
190
|
+
? getSnapshotSummary(historyItems[index - 1]?.data)
|
|
191
|
+
: undefined;
|
|
192
|
+
const status = getHistoryStatus(index, current);
|
|
193
|
+
const nodeDelta = getNodeDelta(summary, previousSummary);
|
|
194
|
+
return {
|
|
195
|
+
isActive: current === index,
|
|
196
|
+
nodeDeltaStyle: getNodeDeltaStyle(nodeDelta),
|
|
197
|
+
nodeDeltaText: formatNodeDelta(nodeDelta),
|
|
198
|
+
status,
|
|
199
|
+
summary,
|
|
200
|
+
title: formatOperationFallback(token),
|
|
201
|
+
token,
|
|
202
|
+
type,
|
|
203
|
+
};
|
|
204
|
+
};
|
|
205
|
+
const HistorySummaryBar = ({ current, prefix, total, canRedo, canUndo, }) => (React.createElement("div", { "aria-label": `历史记录 ${current + 1}/${total}`, className: `${prefix}-summary`, role: "status", style: {
|
|
206
|
+
alignItems: 'center',
|
|
207
|
+
background: 'rgba(255, 255, 255, 0.96)',
|
|
208
|
+
border: '1px solid #e6ebf2',
|
|
209
|
+
borderRadius: 6,
|
|
210
|
+
boxSizing: 'border-box',
|
|
211
|
+
color: '#566273',
|
|
212
|
+
display: 'flex',
|
|
213
|
+
flexShrink: 0,
|
|
214
|
+
fontSize: 11,
|
|
215
|
+
gap: 3,
|
|
216
|
+
justifyContent: 'space-between',
|
|
217
|
+
lineHeight: '16px',
|
|
218
|
+
marginBottom: 2,
|
|
219
|
+
padding: '2px 4px',
|
|
220
|
+
position: 'sticky',
|
|
221
|
+
top: 0,
|
|
222
|
+
zIndex: 1,
|
|
223
|
+
} },
|
|
224
|
+
React.createElement("span", { style: { color: '#1f2a37', fontWeight: 700 } },
|
|
225
|
+
current + 1,
|
|
226
|
+
"/",
|
|
227
|
+
total),
|
|
228
|
+
React.createElement("span", { style: { alignItems: 'center', display: 'flex', gap: 4, minWidth: 0 } }, [
|
|
229
|
+
getHistoryActionState(canUndo, '可撤销', '不可撤销'),
|
|
230
|
+
getHistoryActionState(canRedo, '可重做', '不可重做'),
|
|
231
|
+
].map(item => (React.createElement("span", { key: item.label, style: {
|
|
232
|
+
background: item.background,
|
|
233
|
+
border: `1px solid ${item.borderColor}`,
|
|
234
|
+
borderRadius: 999,
|
|
235
|
+
color: item.color,
|
|
236
|
+
fontSize: 10,
|
|
237
|
+
fontWeight: 600,
|
|
238
|
+
lineHeight: '14px',
|
|
239
|
+
padding: '0 5px',
|
|
240
|
+
whiteSpace: 'nowrap',
|
|
241
|
+
} }, item.label))))));
|
|
242
|
+
const NodeDeltaBadge = ({ className, style, text, }) => {
|
|
243
|
+
if (!text)
|
|
244
|
+
return null;
|
|
245
|
+
return (React.createElement("span", { className: className, style: {
|
|
246
|
+
background: style.background,
|
|
247
|
+
borderRadius: 4,
|
|
248
|
+
color: style.color,
|
|
249
|
+
flexShrink: 0,
|
|
250
|
+
fontSize: 9,
|
|
251
|
+
fontWeight: 700,
|
|
252
|
+
lineHeight: '12px',
|
|
253
|
+
padding: '0 2px',
|
|
254
|
+
whiteSpace: 'nowrap',
|
|
255
|
+
} }, text));
|
|
256
|
+
};
|
|
257
|
+
const handleHistoryItemKeyDown = (event, actions) => {
|
|
258
|
+
if (event.key === 'Enter' || event.key === ' ') {
|
|
259
|
+
event.preventDefault();
|
|
260
|
+
actions.goToHistory();
|
|
261
|
+
return;
|
|
262
|
+
}
|
|
263
|
+
if (event.key === 'ArrowDown') {
|
|
264
|
+
event.preventDefault();
|
|
265
|
+
actions.focusItem(actions.displayIndex + 1);
|
|
266
|
+
return;
|
|
267
|
+
}
|
|
268
|
+
if (event.key === 'ArrowUp') {
|
|
269
|
+
event.preventDefault();
|
|
270
|
+
actions.focusItem(actions.displayIndex - 1);
|
|
271
|
+
return;
|
|
272
|
+
}
|
|
273
|
+
if (event.key === 'Home') {
|
|
274
|
+
event.preventDefault();
|
|
275
|
+
actions.focusItem(0);
|
|
276
|
+
return;
|
|
277
|
+
}
|
|
278
|
+
if (event.key === 'End') {
|
|
279
|
+
event.preventDefault();
|
|
280
|
+
actions.focusItem(actions.total - 1);
|
|
281
|
+
}
|
|
282
|
+
};
|
|
283
|
+
const HistoryItemView = ({ current, displayIndex, historyItems, item, index, operation, prefix, total, onFocusItem, onRef, onGoTo, }) => {
|
|
284
|
+
const { isActive, nodeDeltaStyle, nodeDeltaText, status, summary, title, token, type, } = createHistoryItemRenderModel(item, index, current, historyItems);
|
|
285
|
+
const gotoHistory = () => {
|
|
286
|
+
if (isActive)
|
|
287
|
+
return;
|
|
288
|
+
onGoTo(index);
|
|
289
|
+
restoreHistoryInteractionState(operation);
|
|
290
|
+
};
|
|
291
|
+
const handleKeyDown = (event) => {
|
|
292
|
+
handleHistoryItemKeyDown(event, {
|
|
293
|
+
displayIndex,
|
|
294
|
+
focusItem: onFocusItem,
|
|
295
|
+
goToHistory: gotoHistory,
|
|
296
|
+
total,
|
|
297
|
+
});
|
|
298
|
+
};
|
|
299
|
+
return (React.createElement("div", { key: `${item.timestamp}-${index}-${type}`, ref: element => onRef(displayIndex, element), "aria-current": isActive ? 'step' : undefined, "aria-disabled": isActive, "aria-label": createHistoryItemLabel(title, summary, index, total, status), className: cls(`${prefix}-item`, {
|
|
300
|
+
active: isActive,
|
|
301
|
+
}), role: "button", style: {
|
|
302
|
+
background: isActive ? '#eef6ff' : '#fff',
|
|
303
|
+
border: `1px solid ${isActive ? '#9dccff' : '#e6ebf2'}`,
|
|
304
|
+
borderLeft: `2px solid ${status.borderColor}`,
|
|
305
|
+
borderRadius: 4,
|
|
306
|
+
boxShadow: isActive ? '0 1px 4px rgba(22, 119, 255, 0.08)' : 'none',
|
|
307
|
+
boxSizing: 'border-box',
|
|
308
|
+
color: '#1f2a37',
|
|
309
|
+
cursor: 'pointer',
|
|
310
|
+
display: 'block',
|
|
311
|
+
minHeight: 22,
|
|
312
|
+
outline: 'none',
|
|
313
|
+
padding: '1px 4px',
|
|
314
|
+
transition: 'border-color 0.16s ease, box-shadow 0.16s ease, background 0.16s ease',
|
|
315
|
+
width: '100%',
|
|
316
|
+
}, tabIndex: 0, onClick: gotoHistory, onKeyDown: handleKeyDown },
|
|
317
|
+
React.createElement("span", { style: { minWidth: 0 } },
|
|
318
|
+
React.createElement("span", { style: {
|
|
319
|
+
alignItems: 'center',
|
|
320
|
+
display: 'flex',
|
|
321
|
+
gap: 3,
|
|
322
|
+
minWidth: 0,
|
|
323
|
+
} },
|
|
324
|
+
React.createElement("span", { className: `${prefix}-item-title`, style: {
|
|
325
|
+
color: isActive ? '#0958d9' : '#1f2a37',
|
|
326
|
+
display: 'block',
|
|
327
|
+
flex: 1,
|
|
328
|
+
fontSize: 12,
|
|
329
|
+
fontWeight: 700,
|
|
330
|
+
lineHeight: '14px',
|
|
331
|
+
minWidth: 0,
|
|
332
|
+
overflow: 'hidden',
|
|
333
|
+
textOverflow: 'ellipsis',
|
|
334
|
+
whiteSpace: 'nowrap',
|
|
335
|
+
} },
|
|
336
|
+
React.createElement(TextWidget, { defaultMessage: formatOperationFallback(token), token: `operations.${token}` })),
|
|
337
|
+
React.createElement("span", { "aria-label": isActive ? '当前历史' : undefined, style: {
|
|
338
|
+
background: 'transparent',
|
|
339
|
+
border: 0,
|
|
340
|
+
borderRadius: 0,
|
|
341
|
+
color: isActive ? '#0958d9' : status.color,
|
|
342
|
+
flexShrink: 0,
|
|
343
|
+
fontSize: 9,
|
|
344
|
+
fontWeight: 700,
|
|
345
|
+
lineHeight: '13px',
|
|
346
|
+
minWidth: 0,
|
|
347
|
+
padding: 0,
|
|
348
|
+
textAlign: 'center',
|
|
349
|
+
} }, status.label),
|
|
350
|
+
React.createElement(NodeDeltaBadge, { className: `${prefix}-item-delta`, style: nodeDeltaStyle, text: nodeDeltaText }),
|
|
351
|
+
React.createElement("span", { className: `${prefix}-item-timestamp`, style: {
|
|
352
|
+
color: '#8b98aa',
|
|
353
|
+
flexShrink: 0,
|
|
354
|
+
fontSize: 9,
|
|
355
|
+
lineHeight: '11px',
|
|
356
|
+
}, title: formatDate(item.timestamp) },
|
|
357
|
+
index + 1,
|
|
358
|
+
" \u00B7 ",
|
|
359
|
+
formatTime(item.timestamp))),
|
|
360
|
+
React.createElement("span", { style: {
|
|
361
|
+
color: '#6b7788',
|
|
362
|
+
display: 'block',
|
|
363
|
+
fontSize: 10,
|
|
364
|
+
lineHeight: '12px',
|
|
365
|
+
marginTop: 1,
|
|
366
|
+
overflow: 'hidden',
|
|
367
|
+
textOverflow: 'ellipsis',
|
|
368
|
+
whiteSpace: 'nowrap',
|
|
369
|
+
} },
|
|
370
|
+
summary.targetName,
|
|
371
|
+
" \u00B7 ",
|
|
372
|
+
summary.nodeCount || 1,
|
|
373
|
+
"\u8282\u70B9",
|
|
374
|
+
summary.selectedCount ? ` · 选${summary.selectedCount}` : ''))));
|
|
375
|
+
};
|
|
376
|
+
const getActiveWorkspace = (workbench) => (workbench?.activeWorkspace || workbench?.currentWorkspace);
|
|
377
|
+
export const HistoryWidget = observer(() => {
|
|
378
|
+
const { Empty } = useUIAdapter();
|
|
379
|
+
const workbench = useWorkbench();
|
|
380
|
+
const currentWorkspace = getActiveWorkspace(workbench);
|
|
381
|
+
const operation = useOperation(currentWorkspace?.id);
|
|
382
|
+
const prefix = usePrefix('history');
|
|
383
|
+
const historyItems = currentWorkspace?.history.list() ?? [];
|
|
384
|
+
const historyCurrent = currentWorkspace?.history.current ?? 0;
|
|
385
|
+
const historyTotal = historyItems.length;
|
|
386
|
+
const historyItemRefs = React.useRef([]);
|
|
387
|
+
if (!currentWorkspace || historyItems.length === 0) {
|
|
388
|
+
return (React.createElement("div", { className: prefix },
|
|
389
|
+
React.createElement(Empty, { description: "\u6682\u65E0\u5386\u53F2\u8BB0\u5F55" })));
|
|
390
|
+
}
|
|
391
|
+
const displayedHistoryItems = [...historyItems]
|
|
392
|
+
.map((item, index) => ({ item, index }))
|
|
393
|
+
.reverse();
|
|
394
|
+
const focusHistoryItem = (displayIndex) => {
|
|
395
|
+
const maxIndex = displayedHistoryItems.length - 1;
|
|
396
|
+
const nextIndex = Math.max(0, Math.min(displayIndex, maxIndex));
|
|
397
|
+
historyItemRefs.current[nextIndex]?.focus();
|
|
398
|
+
};
|
|
399
|
+
const setHistoryItemRef = (displayIndex, element) => {
|
|
400
|
+
historyItemRefs.current[displayIndex] = element;
|
|
401
|
+
};
|
|
402
|
+
return (React.createElement("div", { className: prefix, style: {
|
|
403
|
+
display: 'flex',
|
|
404
|
+
flexDirection: 'column',
|
|
405
|
+
gap: 0,
|
|
406
|
+
} },
|
|
407
|
+
React.createElement(HistorySummaryBar, { canRedo: !!currentWorkspace.history.allowRedo, canUndo: !!currentWorkspace.history.allowUndo, current: historyCurrent, prefix: prefix, total: historyTotal }),
|
|
408
|
+
displayedHistoryItems.map(({ item, index }, displayIndex) => (React.createElement(HistoryItemView, { key: `${item.timestamp}-${index}-${item.type || 'default_state'}`, current: historyCurrent, displayIndex: displayIndex, historyItems: historyItems, index: index, item: item, operation: operation, prefix: prefix, total: historyTotal, onFocusItem: focusHistoryItem, onGoTo: currentWorkspace.history.goTo.bind(currentWorkspace.history), onRef: setHistoryItemRef })))));
|
|
409
|
+
});
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export interface IconProviderProps {
|
|
3
|
+
tooltip?: boolean;
|
|
4
|
+
}
|
|
5
|
+
export interface IShadowSVGProps {
|
|
6
|
+
content?: string;
|
|
7
|
+
width?: number | string;
|
|
8
|
+
height?: number | string;
|
|
9
|
+
}
|
|
10
|
+
interface IIconTooltipProps {
|
|
11
|
+
title?: React.ReactNode;
|
|
12
|
+
[key: string]: unknown;
|
|
13
|
+
}
|
|
14
|
+
export interface IIconWidgetProps extends React.HTMLAttributes<HTMLElement> {
|
|
15
|
+
tooltip?: React.ReactNode | IIconTooltipProps;
|
|
16
|
+
infer: React.ReactNode | {
|
|
17
|
+
shadow?: string;
|
|
18
|
+
[key: string]: unknown;
|
|
19
|
+
};
|
|
20
|
+
size?: number | string;
|
|
21
|
+
}
|
|
22
|
+
export declare const IconWidget: React.FC<React.PropsWithChildren<IIconWidgetProps>> & {
|
|
23
|
+
ShadowSVG: React.FC<IShadowSVGProps>;
|
|
24
|
+
Provider: React.FC<React.PropsWithChildren<IconProviderProps>>;
|
|
25
|
+
};
|
|
26
|
+
export {};
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
import { observer } from '@formily/reactive-react';
|
|
2
|
+
import cls from 'classnames';
|
|
3
|
+
import { isFunction, isPlainObject, isString } from 'lodash-es';
|
|
4
|
+
import React, { createContext, useContext, useEffect, useRef } from 'react';
|
|
5
|
+
import { usePrefix, useRegistry, useTheme } from "../../hooks/index.js";
|
|
6
|
+
const IconContext = createContext(null);
|
|
7
|
+
const isNumSize = (val) => /^[\d.]+$/.test(String(val));
|
|
8
|
+
const isImageIconSource = (value) => (/^(https?:)?\/\//.test(value)
|
|
9
|
+
|| /^(data:image\/|blob:)/.test(value)
|
|
10
|
+
|| value.startsWith('/')
|
|
11
|
+
|| value.startsWith('./')
|
|
12
|
+
|| value.startsWith('../')
|
|
13
|
+
|| /\.(svg|png|jpe?g|gif|webp|avif)(\?.*)?$/i.test(value));
|
|
14
|
+
const SVG_NAMESPACE = 'http://www.w3.org/2000/svg';
|
|
15
|
+
const SAFE_SVG_TAGS = new Set([
|
|
16
|
+
'circle',
|
|
17
|
+
'clipPath',
|
|
18
|
+
'defs',
|
|
19
|
+
'ellipse',
|
|
20
|
+
'g',
|
|
21
|
+
'line',
|
|
22
|
+
'linearGradient',
|
|
23
|
+
'path',
|
|
24
|
+
'polygon',
|
|
25
|
+
'polyline',
|
|
26
|
+
'radialGradient',
|
|
27
|
+
'rect',
|
|
28
|
+
'stop',
|
|
29
|
+
'svg',
|
|
30
|
+
]);
|
|
31
|
+
const SAFE_SVG_ATTRS = new Set([
|
|
32
|
+
'aria-hidden',
|
|
33
|
+
'clip-path',
|
|
34
|
+
'cx',
|
|
35
|
+
'cy',
|
|
36
|
+
'd',
|
|
37
|
+
'fill',
|
|
38
|
+
'fill-opacity',
|
|
39
|
+
'fill-rule',
|
|
40
|
+
'focusable',
|
|
41
|
+
'height',
|
|
42
|
+
'id',
|
|
43
|
+
'offset',
|
|
44
|
+
'opacity',
|
|
45
|
+
'points',
|
|
46
|
+
'r',
|
|
47
|
+
'rx',
|
|
48
|
+
'ry',
|
|
49
|
+
'stroke',
|
|
50
|
+
'stroke-linecap',
|
|
51
|
+
'stroke-linejoin',
|
|
52
|
+
'stroke-opacity',
|
|
53
|
+
'stroke-width',
|
|
54
|
+
'style',
|
|
55
|
+
'transform',
|
|
56
|
+
'viewBox',
|
|
57
|
+
'width',
|
|
58
|
+
'x',
|
|
59
|
+
'x1',
|
|
60
|
+
'x2',
|
|
61
|
+
'y',
|
|
62
|
+
'y1',
|
|
63
|
+
'y2',
|
|
64
|
+
]);
|
|
65
|
+
const UNSAFE_SVG_ATTR_PATTERN = /^on/i;
|
|
66
|
+
const UNSAFE_SVG_URL_PATTERN = /url\(\s*['"]?\s*javascript:/i;
|
|
67
|
+
const sanitizeSvgNode = (sourceNode, documentRef) => {
|
|
68
|
+
const { tagName } = sourceNode;
|
|
69
|
+
if (!SAFE_SVG_TAGS.has(tagName))
|
|
70
|
+
return null;
|
|
71
|
+
const nextNode = documentRef.createElementNS(SVG_NAMESPACE, tagName);
|
|
72
|
+
Array.from(sourceNode.attributes).forEach((attr) => {
|
|
73
|
+
if (UNSAFE_SVG_ATTR_PATTERN.test(attr.name))
|
|
74
|
+
return;
|
|
75
|
+
if (!SAFE_SVG_ATTRS.has(attr.name))
|
|
76
|
+
return;
|
|
77
|
+
if (UNSAFE_SVG_URL_PATTERN.test(attr.value))
|
|
78
|
+
return;
|
|
79
|
+
nextNode.setAttribute(attr.name, attr.value);
|
|
80
|
+
});
|
|
81
|
+
Array.from(sourceNode.children).forEach((child) => {
|
|
82
|
+
const sanitizedChild = sanitizeSvgNode(child, documentRef);
|
|
83
|
+
if (sanitizedChild) {
|
|
84
|
+
nextNode.appendChild(sanitizedChild);
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
return nextNode;
|
|
88
|
+
};
|
|
89
|
+
const parseSafeSvgContent = (content, documentRef) => {
|
|
90
|
+
if (!content || typeof DOMParser === 'undefined')
|
|
91
|
+
return [];
|
|
92
|
+
const parser = new DOMParser();
|
|
93
|
+
const parsed = parser.parseFromString(`<svg xmlns="${SVG_NAMESPACE}">${content}</svg>`, 'image/svg+xml');
|
|
94
|
+
if (parsed.querySelector('parsererror'))
|
|
95
|
+
return [];
|
|
96
|
+
return Array.from(parsed.documentElement.children)
|
|
97
|
+
.map(child => sanitizeSvgNode(child, documentRef))
|
|
98
|
+
.filter((node) => !!node);
|
|
99
|
+
};
|
|
100
|
+
const ShadowSVG = (props) => {
|
|
101
|
+
const ref = useRef(null);
|
|
102
|
+
const width = isNumSize(props.width) ? `${props.width}px` : props.width;
|
|
103
|
+
const height = isNumSize(props.height) ? `${props.height}px` : props.height;
|
|
104
|
+
useEffect(() => {
|
|
105
|
+
if (!ref.current)
|
|
106
|
+
return;
|
|
107
|
+
const root = ref.current.shadowRoot ?? ref.current.attachShadow({ mode: 'open' });
|
|
108
|
+
const svg = document.createElementNS(SVG_NAMESPACE, 'svg');
|
|
109
|
+
svg.setAttribute('viewBox', '0 0 1024 1024');
|
|
110
|
+
if (width)
|
|
111
|
+
svg.style.width = String(width);
|
|
112
|
+
if (height)
|
|
113
|
+
svg.style.height = String(height);
|
|
114
|
+
parseSafeSvgContent(props.content, document).forEach(node => svg.appendChild(node));
|
|
115
|
+
root.replaceChildren(svg);
|
|
116
|
+
}, [width, height, props.content]);
|
|
117
|
+
return React.createElement("div", { ref: ref });
|
|
118
|
+
};
|
|
119
|
+
const IconProvider = props => (React.createElement(IconContext.Provider, { value: props }, props.children));
|
|
120
|
+
const renderImageIcon = (source, height, width) => {
|
|
121
|
+
if (!isImageIconSource(source))
|
|
122
|
+
return null;
|
|
123
|
+
return (React.createElement("img", { alt: "", height: height, src: source, width: width }));
|
|
124
|
+
};
|
|
125
|
+
const renderComponentIcon = (infer, height, width) => React.createElement(infer, {
|
|
126
|
+
height,
|
|
127
|
+
width,
|
|
128
|
+
fill: 'currentColor',
|
|
129
|
+
});
|
|
130
|
+
const renderElementIcon = (infer, height, width) => {
|
|
131
|
+
if (infer.type === 'svg') {
|
|
132
|
+
return React.cloneElement(infer, {
|
|
133
|
+
height,
|
|
134
|
+
width,
|
|
135
|
+
fill: 'currentColor',
|
|
136
|
+
viewBox: infer.props.viewBox || '0 0 1024 1024',
|
|
137
|
+
focusable: 'false',
|
|
138
|
+
'aria-hidden': 'true',
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
if (infer.type === 'path' || infer.type === 'g') {
|
|
142
|
+
return (React.createElement("svg", { "aria-hidden": "true", fill: "currentColor", focusable: "false", height: height, viewBox: "0 0 1024 1024", width: width }, infer));
|
|
143
|
+
}
|
|
144
|
+
return infer;
|
|
145
|
+
};
|
|
146
|
+
const IconWidgetComponent = observer((props) => {
|
|
147
|
+
const { children: ignoredChildren, infer, size: sizeProp, tooltip: tooltipProp, ...spanProps } = props;
|
|
148
|
+
void ignoredChildren;
|
|
149
|
+
const theme = useTheme();
|
|
150
|
+
const context = useContext(IconContext);
|
|
151
|
+
const registry = useRegistry();
|
|
152
|
+
const prefix = usePrefix('icon');
|
|
153
|
+
const size = sizeProp || '1em';
|
|
154
|
+
const height = spanProps.style?.height || size;
|
|
155
|
+
const width = spanProps.style?.width || size;
|
|
156
|
+
const takeIcon = (infer) => {
|
|
157
|
+
if (isString(infer)) {
|
|
158
|
+
const finded = registry?.getDesignerIcon(infer);
|
|
159
|
+
return finded ? takeIcon(finded) : renderImageIcon(infer, height, width);
|
|
160
|
+
}
|
|
161
|
+
if (isFunction(infer))
|
|
162
|
+
return renderComponentIcon(infer, height, width);
|
|
163
|
+
if (React.isValidElement(infer))
|
|
164
|
+
return renderElementIcon(infer, height, width);
|
|
165
|
+
if (isPlainObject(infer)) {
|
|
166
|
+
const inferObj = infer;
|
|
167
|
+
if (theme && inferObj[theme]) {
|
|
168
|
+
return takeIcon(inferObj[theme]);
|
|
169
|
+
}
|
|
170
|
+
if (inferObj.shadow) {
|
|
171
|
+
return (React.createElement(ShadowSVG, { content: inferObj.shadow, height: height, width: width }));
|
|
172
|
+
}
|
|
173
|
+
return null;
|
|
174
|
+
}
|
|
175
|
+
return null;
|
|
176
|
+
};
|
|
177
|
+
const renderTooltips = (children) => {
|
|
178
|
+
if (!isString(infer) && context?.tooltip)
|
|
179
|
+
return children;
|
|
180
|
+
const tooltip = tooltipProp || registry?.getDesignerMessage(`icons.${infer}`);
|
|
181
|
+
if (tooltip) {
|
|
182
|
+
const title = React.isValidElement(tooltip) || isString(tooltip)
|
|
183
|
+
? String(tooltip)
|
|
184
|
+
: String(tooltip.title ?? '');
|
|
185
|
+
const cloneProps = { title };
|
|
186
|
+
return React.cloneElement(children, cloneProps);
|
|
187
|
+
}
|
|
188
|
+
return children;
|
|
189
|
+
};
|
|
190
|
+
if (!infer)
|
|
191
|
+
return null;
|
|
192
|
+
const icon = takeIcon(infer);
|
|
193
|
+
if (!icon)
|
|
194
|
+
return null;
|
|
195
|
+
return renderTooltips(React.createElement("span", { ...spanProps, className: cls(prefix, spanProps.className), style: {
|
|
196
|
+
...spanProps.style,
|
|
197
|
+
cursor: spanProps.onClick ? 'pointer' : spanProps.style?.cursor,
|
|
198
|
+
} }, icon));
|
|
199
|
+
});
|
|
200
|
+
export const IconWidget = Object.assign(IconWidgetComponent, {
|
|
201
|
+
ShadowSVG,
|
|
202
|
+
Provider: IconProvider,
|
|
203
|
+
});
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { observer } from '@formily/reactive-react';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { useUIAdapter } from "../../adapter/index.js";
|
|
4
|
+
import { useCurrentNode, useHover, usePrefix, useSelection } from "../../hooks/index.js";
|
|
5
|
+
import { NodeTitleWidget } from "../NodeTitleWidget/index.js";
|
|
6
|
+
export const NodePathWidget = observer((props) => {
|
|
7
|
+
const { Breadcrumb } = useUIAdapter();
|
|
8
|
+
const selected = useCurrentNode(props.workspaceId);
|
|
9
|
+
const selection = useSelection(props.workspaceId);
|
|
10
|
+
const hover = useHover(props.workspaceId);
|
|
11
|
+
const prefix = usePrefix('node-path');
|
|
12
|
+
if (!selected)
|
|
13
|
+
return React.createElement(React.Fragment, null);
|
|
14
|
+
const maxItems = props.maxItems ?? 3;
|
|
15
|
+
const nodes = selected
|
|
16
|
+
.getParents()
|
|
17
|
+
.slice(0, maxItems - 1)
|
|
18
|
+
.reverse()
|
|
19
|
+
.concat(selected);
|
|
20
|
+
const items = nodes.map(node => ({
|
|
21
|
+
key: node.id,
|
|
22
|
+
title: (React.createElement(React.Fragment, null,
|
|
23
|
+
React.createElement(NodeTitleWidget, { node: node }))),
|
|
24
|
+
onClick: () => {
|
|
25
|
+
selection?.select(node);
|
|
26
|
+
},
|
|
27
|
+
onMouseEnter: () => {
|
|
28
|
+
hover?.setHover(node);
|
|
29
|
+
},
|
|
30
|
+
}));
|
|
31
|
+
return (React.createElement(Breadcrumb, { className: prefix, items: items, separator: "/" }));
|
|
32
|
+
});
|