@rytass/wms-map-react-components 0.1.10 → 0.2.0
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/components/breadcrumb/breadcrumb-edit-modal.cjs +92 -0
- package/components/breadcrumb/breadcrumb-edit-modal.d.cts +9 -0
- package/components/breadcrumb/breadcrumb-edit-modal.module.scss.cjs +5 -0
- package/components/breadcrumb/breadcrumb.cjs +171 -0
- package/components/breadcrumb/breadcrumb.d.cts +11 -0
- package/components/breadcrumb/breadcrumb.d.ts +1 -1
- package/components/breadcrumb/breadcrumb.module.scss.cjs +5 -0
- package/components/canvas/react-flow-canvas.cjs +321 -0
- package/components/canvas/react-flow-canvas.d.cts +38 -0
- package/components/canvas/react-flow-canvas.d.ts +1 -1
- package/components/canvas/react-flow-canvas.module.scss.cjs +5 -0
- package/components/modal/wms-map-content.cjs +808 -0
- package/components/modal/wms-map-content.d.cts +4 -0
- package/components/modal/wms-map-content.d.ts +1 -1
- package/components/modal/wms-map-modal-container.cjs +130 -0
- package/components/modal/wms-map-modal-container.d.cts +5 -0
- package/components/modal/wms-map-modal-container.d.ts +1 -1
- package/components/modal/wms-map-modal-container.module.scss.cjs +5 -0
- package/components/nodes/base-node.d.cts +12 -0
- package/components/nodes/base-node.d.ts +1 -1
- package/components/nodes/image-node.cjs +236 -0
- package/components/nodes/image-node.d.cts +17 -0
- package/components/nodes/image-node.d.ts +1 -1
- package/components/nodes/image-node.module.scss.cjs +5 -0
- package/components/nodes/path-node.cjs +553 -0
- package/components/nodes/path-node.d.cts +19 -0
- package/components/nodes/path-node.d.ts +1 -1
- package/components/nodes/path-node.module.scss.cjs +5 -0
- package/components/nodes/rectangle-node.cjs +239 -0
- package/components/nodes/rectangle-node.d.cts +11 -0
- package/components/nodes/rectangle-node.d.ts +1 -1
- package/components/nodes/rectangle-node.module.scss.cjs +5 -0
- package/components/ui/context-menu.cjs +171 -0
- package/components/ui/context-menu.d.cts +25 -0
- package/components/ui/context-menu.module.scss.cjs +5 -0
- package/components/ui/toolbar.cjs +286 -0
- package/components/ui/toolbar.d.cts +23 -0
- package/components/ui/toolbar.d.ts +1 -1
- package/components/ui/toolbar.module.scss.cjs +5 -0
- package/components/ui/view-mode-toolbar.cjs +44 -0
- package/components/ui/view-mode-toolbar.d.cts +9 -0
- package/components/ui/view-mode-toolbar.d.ts +1 -1
- package/components/ui/view-mode-toolbar.module.scss.cjs +5 -0
- package/constants/index.cjs +54 -0
- package/constants/index.d.cts +45 -0
- package/constants/index.d.ts +2 -2
- package/constants/text-mappings.cjs +46 -0
- package/constants/text-mappings.d.cts +181 -0
- package/hooks/use-context-menu.cjs +231 -0
- package/hooks/use-context-menu.d.cts +37 -0
- package/hooks/use-context-menu.d.ts +1 -1
- package/hooks/use-direct-state-history.cjs +217 -0
- package/hooks/use-direct-state-history.d.cts +58 -0
- package/hooks/use-direct-state-history.d.ts +2 -2
- package/hooks/use-pen-drawing.cjs +366 -0
- package/hooks/use-pen-drawing.d.cts +30 -0
- package/hooks/use-pen-drawing.d.ts +1 -1
- package/hooks/use-rectangle-drawing.cjs +139 -0
- package/hooks/use-rectangle-drawing.d.cts +19 -0
- package/hooks/use-rectangle-drawing.d.ts +1 -1
- package/hooks/use-text-editing.cjs +156 -0
- package/hooks/use-text-editing.d.cts +19 -0
- package/icons/index.cjs +233 -0
- package/icons/index.d.cts +16 -0
- package/index.cjs +26 -0
- package/index.d.cts +5 -0
- package/index.d.ts +5 -5
- package/package.json +68 -3
- package/types/callback.types.d.cts +7 -0
- package/types/callback.types.d.ts +1 -1
- package/types/canvas.types.d.cts +35 -0
- package/types/canvas.types.d.ts +1 -1
- package/types/component-props.types.d.cts +45 -0
- package/types/component-props.types.d.ts +2 -2
- package/types/history.types.d.cts +24 -0
- package/types/history.types.d.ts +2 -2
- package/types/index.d.cts +5 -0
- package/types/index.d.ts +5 -5
- package/types/react-flow.types.d.cts +30 -0
- package/typings.cjs +44 -0
- package/typings.d.cts +136 -0
- package/utils/api-data-transform.cjs +221 -0
- package/utils/api-data-transform.d.cts +33 -0
- package/utils/api-data-transform.d.ts +1 -1
- package/utils/color-utils.cjs +58 -0
- package/utils/color-utils.d.cts +17 -0
- package/utils/debug-logger.cjs +45 -0
- package/utils/debug-logger.d.cts +33 -0
- package/utils/map-data-transform.cjs +360 -0
- package/utils/map-data-transform.d.cts +18 -0
- package/utils/map-data-transform.d.ts +1 -1
- package/utils/node-operations.cjs +88 -0
- package/utils/node-operations.d.cts +26 -0
- package/utils/node-utils.cjs +40 -0
- package/utils/node-utils.d.cts +10 -0
- package/index.cjs.css +0 -1
- package/index.cjs.js +0 -5128
|
@@ -0,0 +1,808 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
5
|
+
var React = require('react');
|
|
6
|
+
var react = require('@xyflow/react');
|
|
7
|
+
var typings = require('../../typings.cjs');
|
|
8
|
+
var index = require('../../constants/index.cjs');
|
|
9
|
+
var nodeUtils = require('../../utils/node-utils.cjs');
|
|
10
|
+
var nodeOperations = require('../../utils/node-operations.cjs');
|
|
11
|
+
var mapDataTransform = require('../../utils/map-data-transform.cjs');
|
|
12
|
+
var useDirectStateHistory = require('../../hooks/use-direct-state-history.cjs');
|
|
13
|
+
var debugLogger = require('../../utils/debug-logger.cjs');
|
|
14
|
+
var toolbar = require('../ui/toolbar.cjs');
|
|
15
|
+
var breadcrumb = require('../breadcrumb/breadcrumb.cjs');
|
|
16
|
+
var reactFlowCanvas = require('../canvas/react-flow-canvas.cjs');
|
|
17
|
+
var viewModeToolbar = require('../ui/view-mode-toolbar.cjs');
|
|
18
|
+
var textMappings = require('../../constants/text-mappings.cjs');
|
|
19
|
+
|
|
20
|
+
const WMSMapContent = ({ editMode, drawingMode, selectedColor, viewMode, colorPalette, showBreadcrumbEditButton, onEditModeChange, onToggleRectangleTool, onTogglePenTool, onColorChange, onNodeClick, onNodeDoubleClick, onSave, onBreadcrumbClick, onNameChange, initialNodes: propsInitialNodes = [], initialEdges: propsInitialEdges = [], onUpload, getFilenameFQDN, maxFileSizeKB = 30720, warehouseIds = [
|
|
21
|
+
...index.DEFAULT_WAREHOUSE_IDS
|
|
22
|
+
] })=>{
|
|
23
|
+
const renderCount = React.useRef(0);
|
|
24
|
+
renderCount.current += 1;
|
|
25
|
+
const [nodes, setNodes, onNodesChangeOriginal] = react.useNodesState(propsInitialNodes);
|
|
26
|
+
const [edges, setEdges, onEdgesChange] = react.useEdgesState(propsInitialEdges);
|
|
27
|
+
const [selectedNodes, setSelectedNodes] = React.useState([]);
|
|
28
|
+
const [isEditingPathPoints, setIsEditingPathPoints] = React.useState(false);
|
|
29
|
+
const [hoveredNodeId, setHoveredNodeId] = React.useState(null);
|
|
30
|
+
const [showBackground, setShowBackground] = React.useState(true);
|
|
31
|
+
const showBackgroundRef = React.useRef(true);
|
|
32
|
+
const [isUploading, setIsUploading] = React.useState(false);
|
|
33
|
+
const { getViewport, getNodes, getEdges } = react.useReactFlow();
|
|
34
|
+
const colorChangeTimeoutRef = React.useRef(null);
|
|
35
|
+
// 根據當前模式為節點套用正確的狀態規則
|
|
36
|
+
const applyNodeStateRules = React.useCallback((nodes)=>{
|
|
37
|
+
const getNodePermissions = (node)=>{
|
|
38
|
+
const isViewMode = viewMode === typings.ViewMode.VIEW;
|
|
39
|
+
const isImageNode = node.type === 'imageNode';
|
|
40
|
+
const isRectangleNode = node.type === 'rectangleNode';
|
|
41
|
+
const isPathNode = node.type === 'pathNode';
|
|
42
|
+
const isBackgroundMode = editMode === typings.EditMode.BACKGROUND;
|
|
43
|
+
const isLayerMode = editMode === typings.EditMode.LAYER;
|
|
44
|
+
return {
|
|
45
|
+
selectable: !isViewMode && (isImageNode && isBackgroundMode || (isRectangleNode || isPathNode) && isLayerMode),
|
|
46
|
+
draggable: !isViewMode && (isImageNode && isBackgroundMode || (isRectangleNode || isPathNode) && isLayerMode),
|
|
47
|
+
deletable: !isViewMode && (isImageNode && isBackgroundMode || isPathNode && isLayerMode)
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
return nodes.map((node)=>({
|
|
51
|
+
...node,
|
|
52
|
+
...getNodePermissions(node)
|
|
53
|
+
}));
|
|
54
|
+
}, [
|
|
55
|
+
viewMode,
|
|
56
|
+
editMode
|
|
57
|
+
]);
|
|
58
|
+
// 根據編輯模式和視圖模式動態更新所有節點的可選取性和可拖曳性
|
|
59
|
+
React.useEffect(()=>{
|
|
60
|
+
setNodes((currentNodes)=>applyNodeStateRules(currentNodes));
|
|
61
|
+
}, [
|
|
62
|
+
editMode,
|
|
63
|
+
viewMode,
|
|
64
|
+
setNodes,
|
|
65
|
+
applyNodeStateRules
|
|
66
|
+
]);
|
|
67
|
+
// 使用直接狀態 undo/redo 系統
|
|
68
|
+
const { saveState, undo, redo, canUndo, canRedo, initializeHistory, getHistorySummary } = useDirectStateHistory.useDirectStateHistory({
|
|
69
|
+
maxHistorySize: index.UI_CONFIG.HISTORY_SIZE,
|
|
70
|
+
debugMode: true
|
|
71
|
+
});
|
|
72
|
+
// 調試:監聽歷史狀態變化
|
|
73
|
+
React.useEffect(()=>{
|
|
74
|
+
const summary = getHistorySummary();
|
|
75
|
+
debugLogger.debugLog('history', '直接狀態歷史:', summary);
|
|
76
|
+
if (summary.operations) {
|
|
77
|
+
const recentOperations = summary.operations.slice(-5).map((op)=>`[${op.index}]${op.operation}${op.isCurrent ? ' (當前)' : ''}`).join(' → ');
|
|
78
|
+
if (recentOperations) {
|
|
79
|
+
debugLogger.debugLog('history', '操作序列:', recentOperations);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}, [
|
|
83
|
+
getHistorySummary,
|
|
84
|
+
nodes.length,
|
|
85
|
+
edges.length
|
|
86
|
+
]);
|
|
87
|
+
// 用於追蹤上一次的 initialNodes 以進行比較
|
|
88
|
+
const prevInitialNodesRef = React.useRef([]);
|
|
89
|
+
// 監聽 initialNodes 變化,當接收到新資料時清空並載入
|
|
90
|
+
React.useEffect(()=>{
|
|
91
|
+
const currentNodeIds = propsInitialNodes.map((n)=>n.id).sort();
|
|
92
|
+
const prevNodeIds = prevInitialNodesRef.current.map((n)=>n.id).sort();
|
|
93
|
+
const hasChanged = currentNodeIds.length !== prevNodeIds.length || currentNodeIds.some((id, index)=>id !== prevNodeIds[index]);
|
|
94
|
+
if (hasChanged) {
|
|
95
|
+
debugLogger.debugLog(textMappings.TEXT_MAPPINGS.DEBUG.DATA_LOADING, textMappings.TEXT_MAPPINGS.MESSAGES.DETECT_INITIAL_NODES_CHANGE, {
|
|
96
|
+
[textMappings.TEXT_MAPPINGS.MESSAGES.NEW_DATA_NODES]: propsInitialNodes.length,
|
|
97
|
+
[textMappings.TEXT_MAPPINGS.MESSAGES.NEW_DATA_EDGES]: propsInitialEdges.length,
|
|
98
|
+
[textMappings.TEXT_MAPPINGS.MESSAGES.CURRENT_NODES]: nodes.length,
|
|
99
|
+
[textMappings.TEXT_MAPPINGS.MESSAGES.CURRENT_EDGES]: edges.length,
|
|
100
|
+
[textMappings.TEXT_MAPPINGS.MESSAGES.NODE_ID_CHANGE]: {
|
|
101
|
+
[textMappings.TEXT_MAPPINGS.MESSAGES.NEW_IDS]: currentNodeIds,
|
|
102
|
+
[textMappings.TEXT_MAPPINGS.MESSAGES.OLD_IDS]: prevNodeIds
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
const nodesWithCorrectStates = applyNodeStateRules(propsInitialNodes);
|
|
106
|
+
setNodes(nodesWithCorrectStates);
|
|
107
|
+
setEdges(propsInitialEdges);
|
|
108
|
+
setSelectedNodes([]);
|
|
109
|
+
setIsEditingPathPoints(false);
|
|
110
|
+
setHoveredNodeId(null);
|
|
111
|
+
setTimeout(()=>{
|
|
112
|
+
initializeHistory(nodesWithCorrectStates, propsInitialEdges, editMode);
|
|
113
|
+
debugLogger.debugSuccess(textMappings.TEXT_MAPPINGS.DEBUG.HISTORY, textMappings.TEXT_MAPPINGS.MESSAGES.HISTORY_REINITIALIZE, {
|
|
114
|
+
[textMappings.TEXT_MAPPINGS.MESSAGES.NODE_COUNT]: nodesWithCorrectStates.length,
|
|
115
|
+
[textMappings.TEXT_MAPPINGS.MESSAGES.EDGE_COUNT]: propsInitialEdges.length,
|
|
116
|
+
[textMappings.TEXT_MAPPINGS.MESSAGES.OPERATION]: textMappings.TEXT_MAPPINGS.OPERATIONS.LOAD_NEW_DATA
|
|
117
|
+
});
|
|
118
|
+
}, index.UI_CONFIG.NODE_SAVE_DELAY);
|
|
119
|
+
prevInitialNodesRef.current = [
|
|
120
|
+
...propsInitialNodes
|
|
121
|
+
];
|
|
122
|
+
debugLogger.debugSuccess(textMappings.TEXT_MAPPINGS.DEBUG.DATA_LOADING, textMappings.TEXT_MAPPINGS.MESSAGES.DATA_LOADING_COMPLETE, {
|
|
123
|
+
[textMappings.TEXT_MAPPINGS.MESSAGES.LOADED_NODES]: nodesWithCorrectStates.length,
|
|
124
|
+
[textMappings.TEXT_MAPPINGS.MESSAGES.LOADED_EDGES]: propsInitialEdges.length,
|
|
125
|
+
[textMappings.TEXT_MAPPINGS.MESSAGES.CURRENT_MODE]: {
|
|
126
|
+
viewMode,
|
|
127
|
+
editMode
|
|
128
|
+
},
|
|
129
|
+
[textMappings.TEXT_MAPPINGS.MESSAGES.NODE_TYPE_STATS]: {
|
|
130
|
+
[textMappings.TEXT_MAPPINGS.MESSAGES.IMAGE_NODE]: nodesWithCorrectStates.filter((n)=>n.type === 'imageNode').length,
|
|
131
|
+
[textMappings.TEXT_MAPPINGS.MESSAGES.RECTANGLE_NODE]: nodesWithCorrectStates.filter((n)=>n.type === 'rectangleNode').length,
|
|
132
|
+
[textMappings.TEXT_MAPPINGS.MESSAGES.PATH_NODE]: nodesWithCorrectStates.filter((n)=>n.type === 'pathNode').length
|
|
133
|
+
},
|
|
134
|
+
[textMappings.TEXT_MAPPINGS.MESSAGES.NODE_STATE_STATS]: {
|
|
135
|
+
[textMappings.TEXT_MAPPINGS.MESSAGES.SELECTABLE]: nodesWithCorrectStates.filter((n)=>n.selectable).length,
|
|
136
|
+
[textMappings.TEXT_MAPPINGS.MESSAGES.DRAGGABLE]: nodesWithCorrectStates.filter((n)=>n.draggable).length,
|
|
137
|
+
[textMappings.TEXT_MAPPINGS.MESSAGES.DELETABLE]: nodesWithCorrectStates.filter((n)=>n.deletable).length
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
}, [
|
|
142
|
+
propsInitialNodes,
|
|
143
|
+
propsInitialEdges,
|
|
144
|
+
nodes.length,
|
|
145
|
+
edges.length,
|
|
146
|
+
setNodes,
|
|
147
|
+
setEdges,
|
|
148
|
+
applyNodeStateRules,
|
|
149
|
+
viewMode,
|
|
150
|
+
editMode,
|
|
151
|
+
initializeHistory
|
|
152
|
+
]);
|
|
153
|
+
// 初始化歷史記錄(只在組件首次載入或節點/邊清空時執行)
|
|
154
|
+
React.useEffect(()=>{
|
|
155
|
+
if (nodes.length > 0 || edges.length > 0) {
|
|
156
|
+
const summary = getHistorySummary();
|
|
157
|
+
if (!summary.operations || summary.operations.length === 0) {
|
|
158
|
+
debugLogger.debugLog(textMappings.TEXT_MAPPINGS.DEBUG.HISTORY, textMappings.TEXT_MAPPINGS.MESSAGES.FIRST_HISTORY_INIT, {
|
|
159
|
+
[textMappings.TEXT_MAPPINGS.MESSAGES.NODE_COUNT]: nodes.length,
|
|
160
|
+
[textMappings.TEXT_MAPPINGS.MESSAGES.EDGE_COUNT]: edges.length
|
|
161
|
+
});
|
|
162
|
+
initializeHistory(nodes, edges, editMode);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}, [
|
|
166
|
+
edges,
|
|
167
|
+
initializeHistory,
|
|
168
|
+
nodes,
|
|
169
|
+
getHistorySummary,
|
|
170
|
+
editMode
|
|
171
|
+
]);
|
|
172
|
+
// 立即觸發顏色變更記錄(當執行其他操作時)
|
|
173
|
+
const flushColorChangeHistory = React.useCallback(()=>{
|
|
174
|
+
if (colorChangeTimeoutRef.current) {
|
|
175
|
+
clearTimeout(colorChangeTimeoutRef.current);
|
|
176
|
+
saveState(nodes, edges, 'change-color', editMode);
|
|
177
|
+
colorChangeTimeoutRef.current = null;
|
|
178
|
+
}
|
|
179
|
+
}, [
|
|
180
|
+
saveState,
|
|
181
|
+
nodes,
|
|
182
|
+
edges,
|
|
183
|
+
editMode
|
|
184
|
+
]);
|
|
185
|
+
// 其他方法保持不變,但移除 console.log
|
|
186
|
+
const onNodesChange = React.useCallback((changes)=>{
|
|
187
|
+
if (changes.length > 0) {
|
|
188
|
+
debugLogger.debugLog('reactFlow', 'onNodesChange 觸發:', changes.map((c)=>({
|
|
189
|
+
type: c.type,
|
|
190
|
+
id: 'id' in c ? c.id : 'Unknown'
|
|
191
|
+
})));
|
|
192
|
+
}
|
|
193
|
+
onNodesChangeOriginal(changes);
|
|
194
|
+
const hasDragEnd = changes.some((change)=>change.type === 'position' && change.dragging === false);
|
|
195
|
+
const hasDataChange = changes.some((change)=>change.type === 'replace' && !change.item?.data?.isResizing);
|
|
196
|
+
if (hasDragEnd) {
|
|
197
|
+
setTimeout(()=>{
|
|
198
|
+
saveState(nodes, edges, 'move-shape', editMode);
|
|
199
|
+
}, 10);
|
|
200
|
+
} else if (hasDataChange) {
|
|
201
|
+
const changedNodeIds = changes.filter((c)=>c.type === 'replace').map((c)=>c.id || c.item?.id).filter(Boolean);
|
|
202
|
+
debugLogger.debugLog('nodes', '檢測到資料變更:', {
|
|
203
|
+
changedNodes: changedNodeIds
|
|
204
|
+
});
|
|
205
|
+
setTimeout(()=>{
|
|
206
|
+
flushColorChangeHistory();
|
|
207
|
+
saveState(nodes, edges, `data-change-${changedNodeIds.join(',')}`, editMode);
|
|
208
|
+
debugLogger.debugSuccess('history', '立即記錄資料變更歷史:', {
|
|
209
|
+
changedNodes: changedNodeIds,
|
|
210
|
+
operation: `data-change-${changedNodeIds.join(',')}`
|
|
211
|
+
});
|
|
212
|
+
}, 10);
|
|
213
|
+
}
|
|
214
|
+
}, [
|
|
215
|
+
onNodesChangeOriginal,
|
|
216
|
+
saveState,
|
|
217
|
+
flushColorChangeHistory,
|
|
218
|
+
nodes,
|
|
219
|
+
edges,
|
|
220
|
+
editMode
|
|
221
|
+
]);
|
|
222
|
+
const onConnect = React.useCallback((params)=>{
|
|
223
|
+
setEdges((eds)=>react.addEdge(params, eds));
|
|
224
|
+
}, [
|
|
225
|
+
setEdges
|
|
226
|
+
]);
|
|
227
|
+
const handleSave = ()=>{
|
|
228
|
+
const mapData = mapDataTransform.transformNodesToMapData(nodes);
|
|
229
|
+
mapDataTransform.logMapData(mapData);
|
|
230
|
+
if (onSave) {
|
|
231
|
+
onSave(mapData);
|
|
232
|
+
}
|
|
233
|
+
};
|
|
234
|
+
const handleUpload = async (files)=>{
|
|
235
|
+
if (!onUpload) {
|
|
236
|
+
console.error('上傳功能未配置:缺少 onUpload');
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
setIsUploading(true);
|
|
240
|
+
try {
|
|
241
|
+
// 步驟 1: 上傳檔案,取得檔名或 URL 陣列
|
|
242
|
+
const uploadedResults = await onUpload(files);
|
|
243
|
+
if (uploadedResults.length !== files.length) {
|
|
244
|
+
console.warn('部分檔案上傳失敗');
|
|
245
|
+
}
|
|
246
|
+
// 步驟 2: 處理每個上傳成功的檔案
|
|
247
|
+
const processPromises = uploadedResults.map(async (result, index$1)=>{
|
|
248
|
+
try {
|
|
249
|
+
// 步驟 3: 取得完整 URL(如果有 getFilenameFQDN 則使用,否則假設 result 就是 URL)
|
|
250
|
+
const imageUrl = getFilenameFQDN ? await Promise.resolve(getFilenameFQDN(result)) : result;
|
|
251
|
+
// 步驟 4: 載入圖片取得尺寸
|
|
252
|
+
return new Promise((resolve, reject)=>{
|
|
253
|
+
const img = new Image();
|
|
254
|
+
img.onload = ()=>{
|
|
255
|
+
const { width, height } = nodeUtils.calculateImageSize(img.width, img.height);
|
|
256
|
+
const viewport = getViewport();
|
|
257
|
+
const position = nodeUtils.calculateStaggeredPosition(index$1, 100, 100, viewport.x, viewport.y, viewport.zoom);
|
|
258
|
+
const newNode = {
|
|
259
|
+
id: `image-${Date.now()}-${index$1}`,
|
|
260
|
+
type: 'imageNode',
|
|
261
|
+
position,
|
|
262
|
+
selectable: editMode === typings.EditMode.BACKGROUND,
|
|
263
|
+
draggable: editMode === typings.EditMode.BACKGROUND,
|
|
264
|
+
data: {
|
|
265
|
+
imageUrl,
|
|
266
|
+
width,
|
|
267
|
+
height,
|
|
268
|
+
originalWidth: img.width,
|
|
269
|
+
originalHeight: img.height,
|
|
270
|
+
fileName: result,
|
|
271
|
+
uploadedUrl: imageUrl
|
|
272
|
+
}
|
|
273
|
+
};
|
|
274
|
+
setTimeout(()=>{
|
|
275
|
+
setNodes((nds)=>{
|
|
276
|
+
const maxZIndex = Math.max(...nds.map((n)=>n.zIndex || 0), 0);
|
|
277
|
+
const nodeWithZIndex = {
|
|
278
|
+
...newNode,
|
|
279
|
+
zIndex: maxZIndex + 1
|
|
280
|
+
};
|
|
281
|
+
const newNodes = [
|
|
282
|
+
...nds,
|
|
283
|
+
nodeWithZIndex
|
|
284
|
+
];
|
|
285
|
+
setTimeout(()=>{
|
|
286
|
+
saveState(newNodes, edges, `upload-image-${result}`, editMode);
|
|
287
|
+
}, index.UI_CONFIG.NODE_SAVE_DELAY);
|
|
288
|
+
return newNodes;
|
|
289
|
+
});
|
|
290
|
+
}, index$1 * index.UI_CONFIG.STAGGER_DELAY);
|
|
291
|
+
resolve();
|
|
292
|
+
};
|
|
293
|
+
img.onerror = ()=>{
|
|
294
|
+
console.error(`圖片載入失敗: ${result} (${imageUrl})`);
|
|
295
|
+
reject(new Error(`圖片載入失敗: ${result}`));
|
|
296
|
+
};
|
|
297
|
+
img.src = imageUrl;
|
|
298
|
+
});
|
|
299
|
+
} catch (error) {
|
|
300
|
+
console.error(`處理檔案失敗: ${result}`, error);
|
|
301
|
+
throw error;
|
|
302
|
+
}
|
|
303
|
+
});
|
|
304
|
+
await Promise.allSettled(processPromises);
|
|
305
|
+
} catch (error) {
|
|
306
|
+
console.error('上傳過程發生錯誤:', error);
|
|
307
|
+
} finally{
|
|
308
|
+
setIsUploading(false);
|
|
309
|
+
}
|
|
310
|
+
};
|
|
311
|
+
const handleDeleteAll = React.useCallback(()=>{
|
|
312
|
+
if (editMode === typings.EditMode.BACKGROUND) {
|
|
313
|
+
setNodes((nds)=>{
|
|
314
|
+
const newNodes = nds.filter((node)=>node.type !== 'imageNode');
|
|
315
|
+
setTimeout(()=>{
|
|
316
|
+
saveState(newNodes, edges, 'delete-images', editMode);
|
|
317
|
+
}, 10);
|
|
318
|
+
return newNodes;
|
|
319
|
+
});
|
|
320
|
+
} else if (editMode === typings.EditMode.LAYER) {
|
|
321
|
+
setNodes((nds)=>{
|
|
322
|
+
const newNodes = nds.filter((node)=>node.type !== 'rectangleNode' && node.type !== 'pathNode');
|
|
323
|
+
setTimeout(()=>{
|
|
324
|
+
saveState(newNodes, [], 'delete-layers', editMode);
|
|
325
|
+
}, 10);
|
|
326
|
+
return newNodes;
|
|
327
|
+
});
|
|
328
|
+
setEdges([]);
|
|
329
|
+
}
|
|
330
|
+
}, [
|
|
331
|
+
editMode,
|
|
332
|
+
setNodes,
|
|
333
|
+
saveState,
|
|
334
|
+
edges,
|
|
335
|
+
setEdges
|
|
336
|
+
]);
|
|
337
|
+
const handleCreateRectangle = React.useCallback((startX, startY, endX, endY)=>{
|
|
338
|
+
const width = Math.abs(endX - startX);
|
|
339
|
+
const height = Math.abs(endY - startY);
|
|
340
|
+
if (width < index.MIN_RECTANGLE_SIZE || height < index.MIN_RECTANGLE_SIZE) return;
|
|
341
|
+
flushColorChangeHistory();
|
|
342
|
+
setNodes((nds)=>{
|
|
343
|
+
const maxZIndex = Math.max(...nds.map((n)=>n.zIndex || 0), 0);
|
|
344
|
+
const newRectangle = {
|
|
345
|
+
id: `rectangle-${Date.now()}`,
|
|
346
|
+
type: 'rectangleNode',
|
|
347
|
+
position: {
|
|
348
|
+
x: Math.min(startX, endX),
|
|
349
|
+
y: Math.min(startY, endY)
|
|
350
|
+
},
|
|
351
|
+
zIndex: maxZIndex + 1,
|
|
352
|
+
selectable: editMode === typings.EditMode.LAYER,
|
|
353
|
+
draggable: editMode === typings.EditMode.LAYER,
|
|
354
|
+
data: {
|
|
355
|
+
width,
|
|
356
|
+
height,
|
|
357
|
+
color: selectedColor,
|
|
358
|
+
label: index.DEFAULT_RECTANGLE_LABEL
|
|
359
|
+
}
|
|
360
|
+
};
|
|
361
|
+
const newNodes = [
|
|
362
|
+
...nds,
|
|
363
|
+
newRectangle
|
|
364
|
+
];
|
|
365
|
+
setTimeout(()=>{
|
|
366
|
+
saveState(newNodes, edges, 'draw-rectangle', editMode);
|
|
367
|
+
}, 10);
|
|
368
|
+
return newNodes;
|
|
369
|
+
});
|
|
370
|
+
}, [
|
|
371
|
+
flushColorChangeHistory,
|
|
372
|
+
setNodes,
|
|
373
|
+
editMode,
|
|
374
|
+
selectedColor,
|
|
375
|
+
saveState,
|
|
376
|
+
edges
|
|
377
|
+
]);
|
|
378
|
+
const handleCreatePath = React.useCallback((points)=>{
|
|
379
|
+
if (points.length < 2) return;
|
|
380
|
+
flushColorChangeHistory();
|
|
381
|
+
setNodes((nds)=>{
|
|
382
|
+
const maxZIndex = Math.max(...nds.map((n)=>n.zIndex || 0), 0);
|
|
383
|
+
const newPath = {
|
|
384
|
+
id: `path-${Date.now()}`,
|
|
385
|
+
type: 'pathNode',
|
|
386
|
+
position: {
|
|
387
|
+
x: Math.min(...points.map((p)=>p.x)),
|
|
388
|
+
y: Math.min(...points.map((p)=>p.y))
|
|
389
|
+
},
|
|
390
|
+
zIndex: maxZIndex + 1,
|
|
391
|
+
selectable: editMode === typings.EditMode.LAYER,
|
|
392
|
+
draggable: editMode === typings.EditMode.LAYER,
|
|
393
|
+
data: {
|
|
394
|
+
points,
|
|
395
|
+
color: selectedColor,
|
|
396
|
+
strokeWidth: 2,
|
|
397
|
+
label: index.DEFAULT_PATH_LABEL
|
|
398
|
+
}
|
|
399
|
+
};
|
|
400
|
+
const newNodes = [
|
|
401
|
+
...nds,
|
|
402
|
+
newPath
|
|
403
|
+
];
|
|
404
|
+
setTimeout(()=>{
|
|
405
|
+
saveState(newNodes, edges, 'draw-path', editMode);
|
|
406
|
+
}, 10);
|
|
407
|
+
return newNodes;
|
|
408
|
+
});
|
|
409
|
+
}, [
|
|
410
|
+
flushColorChangeHistory,
|
|
411
|
+
setNodes,
|
|
412
|
+
editMode,
|
|
413
|
+
selectedColor,
|
|
414
|
+
saveState,
|
|
415
|
+
edges
|
|
416
|
+
]);
|
|
417
|
+
// 復原/重做功能實作
|
|
418
|
+
const handleUndo = React.useCallback(()=>{
|
|
419
|
+
debugLogger.debugLog('history', '執行 Undo - 按鈕點擊');
|
|
420
|
+
const result = undo();
|
|
421
|
+
if (result) {
|
|
422
|
+
setNodes(result.nodes);
|
|
423
|
+
setEdges(result.edges);
|
|
424
|
+
onEditModeChange(result.editMode);
|
|
425
|
+
debugLogger.debugSuccess('history', 'Undo 成功:', {
|
|
426
|
+
nodes: result.nodes.length,
|
|
427
|
+
edges: result.edges.length,
|
|
428
|
+
editMode: result.editMode
|
|
429
|
+
});
|
|
430
|
+
}
|
|
431
|
+
}, [
|
|
432
|
+
undo,
|
|
433
|
+
setNodes,
|
|
434
|
+
setEdges,
|
|
435
|
+
onEditModeChange
|
|
436
|
+
]);
|
|
437
|
+
const handleRedo = React.useCallback(()=>{
|
|
438
|
+
debugLogger.debugLog('history', '執行 Redo - 按鈕點擊');
|
|
439
|
+
const result = redo();
|
|
440
|
+
if (result) {
|
|
441
|
+
setNodes(result.nodes);
|
|
442
|
+
setEdges(result.edges);
|
|
443
|
+
onEditModeChange(result.editMode);
|
|
444
|
+
debugLogger.debugSuccess('history', 'Redo 成功:', {
|
|
445
|
+
nodes: result.nodes.length,
|
|
446
|
+
edges: result.edges.length,
|
|
447
|
+
editMode: result.editMode
|
|
448
|
+
});
|
|
449
|
+
}
|
|
450
|
+
}, [
|
|
451
|
+
redo,
|
|
452
|
+
setNodes,
|
|
453
|
+
setEdges,
|
|
454
|
+
onEditModeChange
|
|
455
|
+
]);
|
|
456
|
+
const handleSelectionChange = React.useCallback((params)=>{
|
|
457
|
+
setSelectedNodes(params.nodes);
|
|
458
|
+
if (params.nodes.length === 1 && (params.nodes[0].type === 'rectangleNode' || params.nodes[0].type === 'pathNode')) {
|
|
459
|
+
const selectedNode = params.nodes[0];
|
|
460
|
+
const nodeColor = selectedNode.data?.color;
|
|
461
|
+
if (nodeColor && typeof nodeColor === 'string') {
|
|
462
|
+
onColorChange(nodeColor);
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
}, [
|
|
466
|
+
onColorChange
|
|
467
|
+
]);
|
|
468
|
+
const handleColorChangeInternal = React.useCallback((color)=>{
|
|
469
|
+
onColorChange(color);
|
|
470
|
+
const selectedColorableNodes = selectedNodes.filter((node)=>node.type === 'rectangleNode' || node.type === 'pathNode');
|
|
471
|
+
if (selectedColorableNodes.length > 0) {
|
|
472
|
+
setNodes((nds)=>{
|
|
473
|
+
const newNodes = nds.map((node)=>{
|
|
474
|
+
if (selectedColorableNodes.some((selected)=>selected.id === node.id)) {
|
|
475
|
+
return {
|
|
476
|
+
...node,
|
|
477
|
+
data: {
|
|
478
|
+
...node.data,
|
|
479
|
+
color
|
|
480
|
+
}
|
|
481
|
+
};
|
|
482
|
+
}
|
|
483
|
+
return node;
|
|
484
|
+
});
|
|
485
|
+
if (colorChangeTimeoutRef.current) {
|
|
486
|
+
clearTimeout(colorChangeTimeoutRef.current);
|
|
487
|
+
}
|
|
488
|
+
colorChangeTimeoutRef.current = setTimeout(()=>{
|
|
489
|
+
saveState(newNodes, edges, 'change-color', editMode);
|
|
490
|
+
colorChangeTimeoutRef.current = null;
|
|
491
|
+
}, index.UI_CONFIG.COLOR_CHANGE_DELAY);
|
|
492
|
+
return newNodes;
|
|
493
|
+
});
|
|
494
|
+
}
|
|
495
|
+
}, [
|
|
496
|
+
selectedNodes,
|
|
497
|
+
setNodes,
|
|
498
|
+
onColorChange,
|
|
499
|
+
saveState,
|
|
500
|
+
edges,
|
|
501
|
+
editMode
|
|
502
|
+
]);
|
|
503
|
+
// 其他回調函數也移除 console.log 並使用 debugLog
|
|
504
|
+
const handleTextEditComplete = React.useCallback((id, oldText, newText)=>{
|
|
505
|
+
debugLogger.debugLog('nodes', '文字編輯完成,手動記錄歷史:', {
|
|
506
|
+
id,
|
|
507
|
+
oldText,
|
|
508
|
+
newText
|
|
509
|
+
});
|
|
510
|
+
flushColorChangeHistory();
|
|
511
|
+
setTimeout(()=>{
|
|
512
|
+
const currentNodes = getNodes();
|
|
513
|
+
const currentEdges = getEdges();
|
|
514
|
+
debugLogger.debugLog('history', '保存文字編輯後的狀態:', {
|
|
515
|
+
id,
|
|
516
|
+
nodesCount: currentNodes.length,
|
|
517
|
+
edgesCount: currentEdges.length,
|
|
518
|
+
updatedNode: currentNodes.find((n)=>n.id === id)?.data?.label
|
|
519
|
+
});
|
|
520
|
+
saveState(currentNodes, currentEdges, `text-edit-${id}`, editMode);
|
|
521
|
+
}, 20);
|
|
522
|
+
}, [
|
|
523
|
+
saveState,
|
|
524
|
+
flushColorChangeHistory,
|
|
525
|
+
getNodes,
|
|
526
|
+
getEdges,
|
|
527
|
+
editMode
|
|
528
|
+
]);
|
|
529
|
+
const handlePathPointsChange = React.useCallback((id, oldPoints, newPoints)=>{
|
|
530
|
+
debugLogger.debugLog('nodes', '路徑節點點位變更,記錄歷史:', {
|
|
531
|
+
id,
|
|
532
|
+
oldPoints,
|
|
533
|
+
newPoints
|
|
534
|
+
});
|
|
535
|
+
flushColorChangeHistory();
|
|
536
|
+
setTimeout(()=>{
|
|
537
|
+
const currentNodes = getNodes();
|
|
538
|
+
const currentEdges = getEdges();
|
|
539
|
+
debugLogger.debugLog('history', '保存路徑點位編輯後的狀態:', {
|
|
540
|
+
id,
|
|
541
|
+
nodesCount: currentNodes.length,
|
|
542
|
+
edgesCount: currentEdges.length,
|
|
543
|
+
updatedPointsCount: currentNodes.find((n)=>n.id === id)?.data?.points?.length || 0
|
|
544
|
+
});
|
|
545
|
+
saveState(currentNodes, currentEdges, `path-edit-${id}`, editMode);
|
|
546
|
+
}, 20);
|
|
547
|
+
}, [
|
|
548
|
+
saveState,
|
|
549
|
+
flushColorChangeHistory,
|
|
550
|
+
getNodes,
|
|
551
|
+
getEdges,
|
|
552
|
+
editMode
|
|
553
|
+
]);
|
|
554
|
+
const handlePathPointDragStateChange = React.useCallback((isDragging)=>{
|
|
555
|
+
debugLogger.debugLog('events', '路徑點拖曳狀態變更:', String(isDragging));
|
|
556
|
+
setIsEditingPathPoints(isDragging);
|
|
557
|
+
}, []);
|
|
558
|
+
const handleNodeMouseEnter = React.useCallback((_event, node)=>{
|
|
559
|
+
const flowNode = node;
|
|
560
|
+
if (viewMode === typings.ViewMode.VIEW && (flowNode.type === 'rectangleNode' || flowNode.type === 'pathNode')) {
|
|
561
|
+
debugLogger.debugLog('events', 'Node hover enter (React Flow)', {
|
|
562
|
+
id: flowNode.id.slice(-4),
|
|
563
|
+
type: flowNode.type,
|
|
564
|
+
viewMode,
|
|
565
|
+
originalColor: flowNode.data?.color
|
|
566
|
+
});
|
|
567
|
+
setHoveredNodeId(flowNode.id);
|
|
568
|
+
}
|
|
569
|
+
}, [
|
|
570
|
+
viewMode
|
|
571
|
+
]);
|
|
572
|
+
const handleNodeMouseLeave = React.useCallback((_event, node)=>{
|
|
573
|
+
const flowNode = node;
|
|
574
|
+
if (viewMode === typings.ViewMode.VIEW && (flowNode.type === 'rectangleNode' || flowNode.type === 'pathNode')) {
|
|
575
|
+
debugLogger.debugLog('events', 'Node hover leave (React Flow)', {
|
|
576
|
+
id: flowNode.id.slice(-4),
|
|
577
|
+
type: flowNode.type,
|
|
578
|
+
viewMode
|
|
579
|
+
});
|
|
580
|
+
setHoveredNodeId(null);
|
|
581
|
+
}
|
|
582
|
+
}, [
|
|
583
|
+
viewMode
|
|
584
|
+
]);
|
|
585
|
+
const clickTimerRef = React.useRef(null);
|
|
586
|
+
React.useEffect(()=>()=>{
|
|
587
|
+
if (clickTimerRef.current) {
|
|
588
|
+
clearTimeout(clickTimerRef.current);
|
|
589
|
+
clickTimerRef.current = null;
|
|
590
|
+
}
|
|
591
|
+
}, []);
|
|
592
|
+
const handleNodeClick = React.useCallback((_event, node)=>{
|
|
593
|
+
const flowNode = node;
|
|
594
|
+
const fireClick = ()=>{
|
|
595
|
+
debugLogger.debugLog('events', 'Node clicked (React Flow)', {
|
|
596
|
+
id: flowNode.id.slice(-4),
|
|
597
|
+
type: flowNode.type,
|
|
598
|
+
viewMode,
|
|
599
|
+
editMode
|
|
600
|
+
});
|
|
601
|
+
mapDataTransform.logNodeData(flowNode);
|
|
602
|
+
if (onNodeClick) {
|
|
603
|
+
const nodeClickInfo = mapDataTransform.transformNodeToClickInfo(flowNode);
|
|
604
|
+
if (nodeClickInfo) {
|
|
605
|
+
debugLogger.debugLog('events', '將點擊資訊傳遞給父組件:', nodeClickInfo);
|
|
606
|
+
onNodeClick(nodeClickInfo);
|
|
607
|
+
}
|
|
608
|
+
}
|
|
609
|
+
};
|
|
610
|
+
// 沒有訂閱雙擊事件時,單擊直接觸發避免引入無謂的 350ms 延遲
|
|
611
|
+
if (!onNodeDoubleClick) {
|
|
612
|
+
fireClick();
|
|
613
|
+
return;
|
|
614
|
+
}
|
|
615
|
+
// 延遲觸發 click,讓 double click 有機會取消
|
|
616
|
+
if (clickTimerRef.current) {
|
|
617
|
+
clearTimeout(clickTimerRef.current);
|
|
618
|
+
}
|
|
619
|
+
clickTimerRef.current = setTimeout(()=>{
|
|
620
|
+
clickTimerRef.current = null;
|
|
621
|
+
fireClick();
|
|
622
|
+
}, 350);
|
|
623
|
+
}, [
|
|
624
|
+
viewMode,
|
|
625
|
+
editMode,
|
|
626
|
+
onNodeClick,
|
|
627
|
+
onNodeDoubleClick
|
|
628
|
+
]);
|
|
629
|
+
const handleNodeDoubleClick = React.useCallback((_event, node)=>{
|
|
630
|
+
// 取消待執行的 click,避免 double click 同時觸發 click
|
|
631
|
+
if (clickTimerRef.current) {
|
|
632
|
+
clearTimeout(clickTimerRef.current);
|
|
633
|
+
clickTimerRef.current = null;
|
|
634
|
+
}
|
|
635
|
+
const flowNode = node;
|
|
636
|
+
debugLogger.debugLog('events', 'Node double clicked (React Flow)', {
|
|
637
|
+
id: flowNode.id.slice(-4),
|
|
638
|
+
type: flowNode.type,
|
|
639
|
+
viewMode,
|
|
640
|
+
editMode
|
|
641
|
+
});
|
|
642
|
+
mapDataTransform.logNodeData(flowNode);
|
|
643
|
+
if (onNodeDoubleClick) {
|
|
644
|
+
const nodeDoubleClickInfo = mapDataTransform.transformNodeToClickInfo(flowNode);
|
|
645
|
+
if (nodeDoubleClickInfo) {
|
|
646
|
+
debugLogger.debugLog('events', '將雙擊資訊傳遞給父組件:', nodeDoubleClickInfo);
|
|
647
|
+
onNodeDoubleClick(nodeDoubleClickInfo);
|
|
648
|
+
}
|
|
649
|
+
}
|
|
650
|
+
}, [
|
|
651
|
+
viewMode,
|
|
652
|
+
editMode,
|
|
653
|
+
onNodeDoubleClick
|
|
654
|
+
]);
|
|
655
|
+
const handleToggleBackground = React.useCallback((show)=>{
|
|
656
|
+
debugLogger.debugLog('ui', '切換底圖顯示:', {
|
|
657
|
+
showBackground: show
|
|
658
|
+
});
|
|
659
|
+
showBackgroundRef.current = show;
|
|
660
|
+
setShowBackground(show);
|
|
661
|
+
}, []);
|
|
662
|
+
React.useEffect(()=>{
|
|
663
|
+
debugLogger.debugLog('ui', 'showBackground 狀態變化:', String(showBackground));
|
|
664
|
+
}, [
|
|
665
|
+
showBackground
|
|
666
|
+
]);
|
|
667
|
+
const handleCopyPasteSelectedNodes = React.useCallback(()=>{
|
|
668
|
+
if (selectedNodes.length === 0) {
|
|
669
|
+
debugLogger.debugLog('keyboard', 'Command+D 複製貼上:沒有選中的節點');
|
|
670
|
+
return;
|
|
671
|
+
}
|
|
672
|
+
const copyableNodes = selectedNodes.filter((node)=>node.type === 'imageNode' || node.type === 'rectangleNode' || node.type === 'pathNode');
|
|
673
|
+
if (copyableNodes.length === 0) {
|
|
674
|
+
debugLogger.debugLog('keyboard', 'Command+D 複製貼上:選中的節點中沒有可複製的類型');
|
|
675
|
+
return;
|
|
676
|
+
}
|
|
677
|
+
setNodes((currentNodes)=>{
|
|
678
|
+
const maxZIndex = Math.max(...currentNodes.map((n)=>n.zIndex || 0), 0);
|
|
679
|
+
const newNodes = [
|
|
680
|
+
...currentNodes
|
|
681
|
+
];
|
|
682
|
+
const createCopiedNode = (nodeToClone)=>{
|
|
683
|
+
const nodeCreationMap = {
|
|
684
|
+
imageNode: ()=>nodeOperations.createImageCopy({
|
|
685
|
+
currentNode: nodeToClone,
|
|
686
|
+
data: nodeToClone.data
|
|
687
|
+
}),
|
|
688
|
+
rectangleNode: ()=>nodeOperations.createRectangleCopy({
|
|
689
|
+
currentNode: nodeToClone,
|
|
690
|
+
data: nodeToClone.data
|
|
691
|
+
}),
|
|
692
|
+
pathNode: ()=>nodeOperations.createPathCopy({
|
|
693
|
+
currentNode: nodeToClone,
|
|
694
|
+
data: nodeToClone.data
|
|
695
|
+
})
|
|
696
|
+
};
|
|
697
|
+
return nodeCreationMap[nodeToClone.type]?.() || null;
|
|
698
|
+
};
|
|
699
|
+
const copiedNodes = copyableNodes.map((nodeToClone, index)=>{
|
|
700
|
+
const copiedNode = createCopiedNode(nodeToClone);
|
|
701
|
+
return copiedNode ? {
|
|
702
|
+
...copiedNode,
|
|
703
|
+
zIndex: maxZIndex + 1 + index
|
|
704
|
+
} : null;
|
|
705
|
+
}).filter((node)=>node !== null);
|
|
706
|
+
return [
|
|
707
|
+
...newNodes,
|
|
708
|
+
...copiedNodes
|
|
709
|
+
];
|
|
710
|
+
});
|
|
711
|
+
setTimeout(()=>{
|
|
712
|
+
saveState(nodes, edges, 'copy-paste-nodes', editMode);
|
|
713
|
+
}, 10);
|
|
714
|
+
debugLogger.debugLog('keyboard', `執行 Command+D 複製貼上成功,複製節點數: ${copyableNodes.length}`, {
|
|
715
|
+
copiedNodeIds: copyableNodes.map((n)=>n.id),
|
|
716
|
+
copiedNodeTypes: copyableNodes.map((n)=>n.type)
|
|
717
|
+
});
|
|
718
|
+
}, [
|
|
719
|
+
selectedNodes,
|
|
720
|
+
setNodes,
|
|
721
|
+
nodes,
|
|
722
|
+
edges,
|
|
723
|
+
saveState,
|
|
724
|
+
editMode
|
|
725
|
+
]);
|
|
726
|
+
// 全域鍵盤快捷鍵處理
|
|
727
|
+
React.useEffect(()=>{
|
|
728
|
+
const handleGlobalKeyDown = (event)=>{
|
|
729
|
+
const activeElement = document.activeElement;
|
|
730
|
+
const isEditingText = activeElement && (activeElement.tagName === 'INPUT' || activeElement.tagName === 'TEXTAREA') && activeElement.getAttribute('type') !== 'color';
|
|
731
|
+
if (isEditingText) {
|
|
732
|
+
return;
|
|
733
|
+
}
|
|
734
|
+
if (event.metaKey && event.key.toLowerCase() === 'd') {
|
|
735
|
+
event.preventDefault();
|
|
736
|
+
event.stopPropagation();
|
|
737
|
+
handleCopyPasteSelectedNodes();
|
|
738
|
+
}
|
|
739
|
+
};
|
|
740
|
+
document.addEventListener('keydown', handleGlobalKeyDown, true);
|
|
741
|
+
return ()=>{
|
|
742
|
+
document.removeEventListener('keydown', handleGlobalKeyDown, true);
|
|
743
|
+
};
|
|
744
|
+
}, [
|
|
745
|
+
handleCopyPasteSelectedNodes
|
|
746
|
+
]);
|
|
747
|
+
return /*#__PURE__*/ jsxRuntime.jsxs(jsxRuntime.Fragment, {
|
|
748
|
+
children: [
|
|
749
|
+
/*#__PURE__*/ jsxRuntime.jsx(breadcrumb, {
|
|
750
|
+
warehouseIds: warehouseIds,
|
|
751
|
+
viewMode: viewMode,
|
|
752
|
+
showBreadcrumbEditButton: showBreadcrumbEditButton,
|
|
753
|
+
onWarehouseClick: onBreadcrumbClick,
|
|
754
|
+
onNameChange: onNameChange
|
|
755
|
+
}),
|
|
756
|
+
viewMode === typings.ViewMode.EDIT && /*#__PURE__*/ jsxRuntime.jsx(toolbar, {
|
|
757
|
+
onUpload: handleUpload,
|
|
758
|
+
onDeleteAll: handleDeleteAll,
|
|
759
|
+
onSave: handleSave,
|
|
760
|
+
editMode: editMode,
|
|
761
|
+
drawingMode: drawingMode,
|
|
762
|
+
onEditModeChange: onEditModeChange,
|
|
763
|
+
onToggleRectangleTool: onToggleRectangleTool,
|
|
764
|
+
onTogglePenTool: onTogglePenTool,
|
|
765
|
+
onUndo: handleUndo,
|
|
766
|
+
onRedo: handleRedo,
|
|
767
|
+
canUndo: canUndo,
|
|
768
|
+
canRedo: canRedo,
|
|
769
|
+
onColorChange: handleColorChangeInternal,
|
|
770
|
+
selectedColor: selectedColor,
|
|
771
|
+
colorPalette: colorPalette,
|
|
772
|
+
isUploading: isUploading,
|
|
773
|
+
maxFileSizeKB: maxFileSizeKB
|
|
774
|
+
}),
|
|
775
|
+
/*#__PURE__*/ jsxRuntime.jsx(reactFlowCanvas, {
|
|
776
|
+
nodes: nodes,
|
|
777
|
+
edges: edges,
|
|
778
|
+
onNodesChange: onNodesChange,
|
|
779
|
+
onEdgesChange: onEdgesChange,
|
|
780
|
+
onConnect: onConnect,
|
|
781
|
+
editMode: editMode,
|
|
782
|
+
drawingMode: drawingMode,
|
|
783
|
+
viewMode: viewMode,
|
|
784
|
+
selectedColor: selectedColor,
|
|
785
|
+
onCreateRectangle: handleCreateRectangle,
|
|
786
|
+
onCreatePath: handleCreatePath,
|
|
787
|
+
onSelectionChange: handleSelectionChange,
|
|
788
|
+
onTextEditComplete: handleTextEditComplete,
|
|
789
|
+
onPathPointsChange: handlePathPointsChange,
|
|
790
|
+
onPathPointDragStateChange: handlePathPointDragStateChange,
|
|
791
|
+
isEditingPathPoints: isEditingPathPoints,
|
|
792
|
+
hoveredNodeId: hoveredNodeId,
|
|
793
|
+
onNodeMouseEnter: handleNodeMouseEnter,
|
|
794
|
+
onNodeMouseLeave: handleNodeMouseLeave,
|
|
795
|
+
onNodeClick: handleNodeClick,
|
|
796
|
+
onNodeDoubleClick: handleNodeDoubleClick,
|
|
797
|
+
showBackground: showBackground
|
|
798
|
+
}),
|
|
799
|
+
/*#__PURE__*/ jsxRuntime.jsx(viewModeToolbar, {
|
|
800
|
+
viewMode: viewMode,
|
|
801
|
+
showBackground: showBackground,
|
|
802
|
+
onToggleBackground: handleToggleBackground
|
|
803
|
+
})
|
|
804
|
+
]
|
|
805
|
+
});
|
|
806
|
+
};
|
|
807
|
+
|
|
808
|
+
module.exports = WMSMapContent;
|