@rytass/wms-map-react-components 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/LICENSE +21 -0
- package/README.md +77 -0
- package/components/breadcrumb/breadcrumb-edit-modal.d.ts +9 -0
- package/components/breadcrumb/breadcrumb-edit-modal.js +92 -0
- package/components/breadcrumb/breadcrumb-edit-modal.module.scss.js +3 -0
- package/components/breadcrumb/breadcrumb.d.ts +8 -0
- package/components/breadcrumb/breadcrumb.js +167 -0
- package/components/breadcrumb/breadcrumb.module.scss.js +3 -0
- package/components/canvas/react-flow-canvas.d.ts +37 -0
- package/components/canvas/react-flow-canvas.js +317 -0
- package/components/canvas/react-flow-canvas.module.scss.js +3 -0
- package/components/modal/wms-map-content.d.ts +4 -0
- package/components/modal/wms-map-content.js +753 -0
- package/components/modal/wms-map-header.d.ts +6 -0
- package/components/modal/wms-map-header.js +19 -0
- package/components/modal/wms-map-header.module.scss.js +3 -0
- package/components/modal/wms-map-modal-container.d.ts +4 -0
- package/components/modal/wms-map-modal-container.js +95 -0
- package/components/modal/wms-map-modal-container.module.scss.js +3 -0
- package/components/nodes/base-node.d.ts +12 -0
- package/components/nodes/image-node.d.ts +17 -0
- package/components/nodes/image-node.js +233 -0
- package/components/nodes/image-node.module.scss.js +3 -0
- package/components/nodes/path-node.d.ts +19 -0
- package/components/nodes/path-node.js +550 -0
- package/components/nodes/path-node.module.scss.js +3 -0
- package/components/nodes/rectangle-node.d.ts +11 -0
- package/components/nodes/rectangle-node.js +236 -0
- package/components/nodes/rectangle-node.module.scss.js +3 -0
- package/components/ui/context-menu.d.ts +25 -0
- package/components/ui/context-menu.js +168 -0
- package/components/ui/context-menu.module.scss.js +3 -0
- package/components/ui/toolbar.d.ts +23 -0
- package/components/ui/toolbar.js +278 -0
- package/components/ui/toolbar.module.scss.js +3 -0
- package/components/ui/view-mode-toolbar.d.ts +9 -0
- package/components/ui/view-mode-toolbar.js +41 -0
- package/components/ui/view-mode-toolbar.module.scss.js +3 -0
- package/constants/index.d.ts +45 -0
- package/constants/index.js +37 -0
- package/constants/text-mappings.d.ts +181 -0
- package/constants/text-mappings.js +44 -0
- package/hooks/use-context-menu.d.ts +37 -0
- package/hooks/use-context-menu.js +228 -0
- package/hooks/use-direct-state-history.d.ts +58 -0
- package/hooks/use-direct-state-history.js +214 -0
- package/hooks/use-pen-drawing.d.ts +30 -0
- package/hooks/use-pen-drawing.js +363 -0
- package/hooks/use-rectangle-drawing.d.ts +19 -0
- package/hooks/use-rectangle-drawing.js +136 -0
- package/hooks/use-text-editing.d.ts +19 -0
- package/hooks/use-text-editing.js +153 -0
- package/icons/index.d.ts +15 -0
- package/icons/index.js +209 -0
- package/index.cjs.css +1 -0
- package/index.cjs.js +5033 -0
- package/index.css +1 -0
- package/index.d.ts +5 -0
- package/index.js +4 -0
- package/package.json +40 -0
- package/types/callback.types.d.ts +7 -0
- package/types/canvas.types.d.ts +35 -0
- package/types/component-props.types.d.ts +41 -0
- package/types/history.types.d.ts +24 -0
- package/types/index.d.ts +5 -0
- package/types/react-flow.types.d.ts +30 -0
- package/typings.d.ts +140 -0
- package/typings.js +37 -0
- package/utils/api-data-transform.d.ts +33 -0
- package/utils/api-data-transform.js +218 -0
- package/utils/color-utils.d.ts +17 -0
- package/utils/color-utils.js +55 -0
- package/utils/debug-logger.d.ts +33 -0
- package/utils/debug-logger.js +41 -0
- package/utils/map-data-transform.d.ts +18 -0
- package/utils/map-data-transform.js +342 -0
- package/utils/node-operations.d.ts +26 -0
- package/utils/node-operations.js +83 -0
- package/utils/node-utils.d.ts +10 -0
- package/utils/node-utils.js +37 -0
|
@@ -0,0 +1,550 @@
|
|
|
1
|
+
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
2
|
+
import { useState, useRef, useCallback } from 'react';
|
|
3
|
+
import { useReactFlow } from '@xyflow/react';
|
|
4
|
+
import { ViewMode, EditMode } from '../../typings.js';
|
|
5
|
+
import { DEFAULT_PATH_LABEL, DEFAULT_RECTANGLE_COLOR, ACTIVE_OPACITY, RECTANGLE_INACTIVE_OPACITY } from '../../constants/index.js';
|
|
6
|
+
import { useContextMenu } from '../../hooks/use-context-menu.js';
|
|
7
|
+
import { useTextEditing } from '../../hooks/use-text-editing.js';
|
|
8
|
+
import { createPathCopy } from '../../utils/node-operations.js';
|
|
9
|
+
import { createHoverColor } from '../../utils/color-utils.js';
|
|
10
|
+
import ContextMenu from '../ui/context-menu.js';
|
|
11
|
+
import styles from './path-node.module.scss.js';
|
|
12
|
+
|
|
13
|
+
const PathNode = ({ data, selected, id, editMode, viewMode, onTextEditComplete, onPathPointsChange, onPathPointDragStateChange, isHovered = false })=>{
|
|
14
|
+
const { points = [], color = DEFAULT_RECTANGLE_COLOR, strokeWidth = 2, label = DEFAULT_PATH_LABEL } = data;
|
|
15
|
+
// Get React Flow instance for viewport and node operations
|
|
16
|
+
const { setNodes, getNodes, getViewport } = useReactFlow();
|
|
17
|
+
// Dragging state - optimized for performance
|
|
18
|
+
const [isDraggingPoint, setIsDraggingPoint] = useState(false);
|
|
19
|
+
const [dragPointIndex, setDragPointIndex] = useState(null);
|
|
20
|
+
const dragStartRef = useRef(null);
|
|
21
|
+
const originalPointsRef = useRef([]);
|
|
22
|
+
// Use refs for immediate access to current drag values
|
|
23
|
+
const currentDragOffsetRef = useRef({
|
|
24
|
+
x: 0,
|
|
25
|
+
y: 0
|
|
26
|
+
});
|
|
27
|
+
const currentSyncOffsetRef = useRef({
|
|
28
|
+
x: 0,
|
|
29
|
+
y: 0
|
|
30
|
+
});
|
|
31
|
+
// Visual-only state for smooth dragging (doesn't trigger React Flow updates)
|
|
32
|
+
const [dragOffset, setDragOffset] = useState({
|
|
33
|
+
x: 0,
|
|
34
|
+
y: 0
|
|
35
|
+
});
|
|
36
|
+
const [dragSyncOffset, setDragSyncOffset] = useState({
|
|
37
|
+
x: 0,
|
|
38
|
+
y: 0
|
|
39
|
+
});
|
|
40
|
+
// Only editable in LAYER mode and EDIT view mode
|
|
41
|
+
const isEditable = viewMode === ViewMode.EDIT && editMode === EditMode.LAYER;
|
|
42
|
+
// Check if this node should be selectable (only in LAYER mode)
|
|
43
|
+
const isSelectable = editMode === EditMode.LAYER;
|
|
44
|
+
const opacity = editMode === EditMode.LAYER ? ACTIVE_OPACITY : RECTANGLE_INACTIVE_OPACITY;
|
|
45
|
+
// Context menu functionality
|
|
46
|
+
const { contextMenu, handleContextMenu, handleCloseContextMenu, handleDelete, arrangeActions, arrangeStates, getNodes: getNodesFromHook, setNodes: setNodesFromHook } = useContextMenu({
|
|
47
|
+
id,
|
|
48
|
+
editMode,
|
|
49
|
+
isEditable,
|
|
50
|
+
nodeType: 'pathNode'
|
|
51
|
+
});
|
|
52
|
+
// Text editing functionality
|
|
53
|
+
const { isEditing, editingText, inputRef, setEditingText, handleDoubleClick, handleKeyDown, handleBlur } = useTextEditing({
|
|
54
|
+
id,
|
|
55
|
+
label,
|
|
56
|
+
isEditable,
|
|
57
|
+
onTextEditComplete
|
|
58
|
+
});
|
|
59
|
+
// Calculate path dimensions - use fixed bounds during dragging to prevent unwanted shifts
|
|
60
|
+
const getBounds = useCallback((pointsToUse = points)=>{
|
|
61
|
+
if (pointsToUse.length === 0) return {
|
|
62
|
+
minX: 0,
|
|
63
|
+
minY: 0,
|
|
64
|
+
maxX: 0,
|
|
65
|
+
maxY: 0
|
|
66
|
+
};
|
|
67
|
+
const xs = pointsToUse.map((p)=>p.x);
|
|
68
|
+
const ys = pointsToUse.map((p)=>p.y);
|
|
69
|
+
return {
|
|
70
|
+
minX: Math.min(...xs),
|
|
71
|
+
minY: Math.min(...ys),
|
|
72
|
+
maxX: Math.max(...xs),
|
|
73
|
+
maxY: Math.max(...ys)
|
|
74
|
+
};
|
|
75
|
+
}, [
|
|
76
|
+
points
|
|
77
|
+
]);
|
|
78
|
+
// Always use current bounds for rendering
|
|
79
|
+
const bounds = getBounds();
|
|
80
|
+
const width = Math.max(bounds.maxX - bounds.minX, 10);
|
|
81
|
+
const height = Math.max(bounds.maxY - bounds.minY, 10);
|
|
82
|
+
// Check if path is closed (first and last points are the same)
|
|
83
|
+
const isClosedPath = points.length > 2 && Math.abs(points[0].x - points[points.length - 1].x) < 0.1 && Math.abs(points[0].y - points[points.length - 1].y) < 0.1;
|
|
84
|
+
// Simple approach: show ALL points, including duplicate first/last in closed paths
|
|
85
|
+
const displayPoints = points;
|
|
86
|
+
// Debug logging for path editing
|
|
87
|
+
console.log('🔍 PathNode render', {
|
|
88
|
+
id: id.slice(-4),
|
|
89
|
+
isClosedPath,
|
|
90
|
+
pointsCount: points.length,
|
|
91
|
+
points: points.map((p, i)=>`${i}:(${p.x.toFixed(1)},${p.y.toFixed(1)})`).join(' ')
|
|
92
|
+
});
|
|
93
|
+
// Performance-optimized drag handling - separate visual updates from data updates
|
|
94
|
+
const handlePointMouseDown = useCallback((pointIndex, event)=>{
|
|
95
|
+
if (!isEditable) return;
|
|
96
|
+
const isFirstPoint = pointIndex === 0;
|
|
97
|
+
const isLastPoint = pointIndex === points.length - 1;
|
|
98
|
+
console.log('🚀 Point drag start (performance mode)', {
|
|
99
|
+
id: id.slice(-4),
|
|
100
|
+
pointIndex,
|
|
101
|
+
isClosedPath,
|
|
102
|
+
isFirstPoint,
|
|
103
|
+
isLastPoint,
|
|
104
|
+
totalPoints: points.length
|
|
105
|
+
});
|
|
106
|
+
// Store original state
|
|
107
|
+
dragStartRef.current = {
|
|
108
|
+
x: event.clientX,
|
|
109
|
+
y: event.clientY
|
|
110
|
+
};
|
|
111
|
+
originalPointsRef.current = [
|
|
112
|
+
...points
|
|
113
|
+
];
|
|
114
|
+
setDragPointIndex(pointIndex);
|
|
115
|
+
setIsDraggingPoint(true);
|
|
116
|
+
// Notify parent about drag state change
|
|
117
|
+
onPathPointDragStateChange?.(id, true);
|
|
118
|
+
// Reset visual offsets
|
|
119
|
+
setDragOffset({
|
|
120
|
+
x: 0,
|
|
121
|
+
y: 0
|
|
122
|
+
});
|
|
123
|
+
setDragSyncOffset({
|
|
124
|
+
x: 0,
|
|
125
|
+
y: 0
|
|
126
|
+
});
|
|
127
|
+
currentDragOffsetRef.current = {
|
|
128
|
+
x: 0,
|
|
129
|
+
y: 0
|
|
130
|
+
};
|
|
131
|
+
currentSyncOffsetRef.current = {
|
|
132
|
+
x: 0,
|
|
133
|
+
y: 0
|
|
134
|
+
};
|
|
135
|
+
const handleMouseMove = (e)=>{
|
|
136
|
+
if (!dragStartRef.current) return;
|
|
137
|
+
const viewport = getViewport();
|
|
138
|
+
const deltaX = (e.clientX - dragStartRef.current.x) / viewport.zoom;
|
|
139
|
+
const deltaY = (e.clientY - dragStartRef.current.y) / viewport.zoom;
|
|
140
|
+
// Store current values in refs for immediate access
|
|
141
|
+
currentDragOffsetRef.current = {
|
|
142
|
+
x: deltaX,
|
|
143
|
+
y: deltaY
|
|
144
|
+
};
|
|
145
|
+
// Update visual state - triggers re-render for smooth dragging
|
|
146
|
+
setDragOffset({
|
|
147
|
+
x: deltaX,
|
|
148
|
+
y: deltaY
|
|
149
|
+
});
|
|
150
|
+
// For closed paths, also update sync point visual offset
|
|
151
|
+
if (isClosedPath && points.length > 2) {
|
|
152
|
+
if (isFirstPoint || isLastPoint) {
|
|
153
|
+
currentSyncOffsetRef.current = {
|
|
154
|
+
x: deltaX,
|
|
155
|
+
y: deltaY
|
|
156
|
+
};
|
|
157
|
+
setDragSyncOffset({
|
|
158
|
+
x: deltaX,
|
|
159
|
+
y: deltaY
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
const handleMouseUp = ()=>{
|
|
165
|
+
console.log('🏁 Point drag end (performance mode)', {
|
|
166
|
+
id: id.slice(-4),
|
|
167
|
+
pointIndex,
|
|
168
|
+
finalOffset: currentDragOffsetRef.current
|
|
169
|
+
});
|
|
170
|
+
if (!dragStartRef.current) return;
|
|
171
|
+
// Use ref values for immediate access to final position
|
|
172
|
+
const deltaX = currentDragOffsetRef.current.x;
|
|
173
|
+
const deltaY = currentDragOffsetRef.current.y;
|
|
174
|
+
console.log('📍 Final position calculation', {
|
|
175
|
+
originalPoint: originalPointsRef.current[pointIndex],
|
|
176
|
+
deltaX,
|
|
177
|
+
deltaY,
|
|
178
|
+
finalPoint: {
|
|
179
|
+
x: originalPointsRef.current[pointIndex].x + deltaX,
|
|
180
|
+
y: originalPointsRef.current[pointIndex].y + deltaY
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
// Now update the actual data (only once at the end)
|
|
184
|
+
const newPoints = [
|
|
185
|
+
...originalPointsRef.current
|
|
186
|
+
];
|
|
187
|
+
const targetPoint = {
|
|
188
|
+
x: originalPointsRef.current[pointIndex].x + deltaX,
|
|
189
|
+
y: originalPointsRef.current[pointIndex].y + deltaY
|
|
190
|
+
};
|
|
191
|
+
// Update the dragged point
|
|
192
|
+
newPoints[pointIndex] = targetPoint;
|
|
193
|
+
// For closed paths, sync first and last points
|
|
194
|
+
if (isClosedPath && newPoints.length > 2) {
|
|
195
|
+
if (isFirstPoint) {
|
|
196
|
+
newPoints[newPoints.length - 1] = targetPoint;
|
|
197
|
+
console.log('🔄 Final sync: last point with first point', targetPoint);
|
|
198
|
+
} else if (isLastPoint) {
|
|
199
|
+
newPoints[0] = targetPoint;
|
|
200
|
+
console.log('🔄 Final sync: first point with last point', targetPoint);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
// Calculate new bounds and position like rectangle resize
|
|
204
|
+
const newBounds = getBounds(newPoints);
|
|
205
|
+
const currentNode = getNodes().find((n)=>n.id === id);
|
|
206
|
+
if (currentNode) {
|
|
207
|
+
// Calculate position adjustment based on bounds change (like rectangle anchor)
|
|
208
|
+
const oldBounds = getBounds(originalPointsRef.current);
|
|
209
|
+
const positionDelta = {
|
|
210
|
+
x: newBounds.minX - oldBounds.minX,
|
|
211
|
+
y: newBounds.minY - oldBounds.minY
|
|
212
|
+
};
|
|
213
|
+
const newPosition = {
|
|
214
|
+
x: currentNode.position.x + positionDelta.x,
|
|
215
|
+
y: currentNode.position.y + positionDelta.y
|
|
216
|
+
};
|
|
217
|
+
console.log('📍 Position adjustment for anchor behavior', {
|
|
218
|
+
oldBounds: `(${oldBounds.minX}, ${oldBounds.minY})`,
|
|
219
|
+
newBounds: `(${newBounds.minX}, ${newBounds.minY})`,
|
|
220
|
+
positionDelta,
|
|
221
|
+
oldPosition: currentNode.position,
|
|
222
|
+
newPosition
|
|
223
|
+
});
|
|
224
|
+
// Update both data and position simultaneously (like rectangle resize)
|
|
225
|
+
setNodes((nodes)=>nodes.map((node)=>node.id === id ? {
|
|
226
|
+
...node,
|
|
227
|
+
data: {
|
|
228
|
+
...node.data,
|
|
229
|
+
points: newPoints
|
|
230
|
+
},
|
|
231
|
+
position: newPosition
|
|
232
|
+
} : node));
|
|
233
|
+
} else {
|
|
234
|
+
// Fallback: just update data if node not found
|
|
235
|
+
setNodes((nodes)=>nodes.map((node)=>node.id === id ? {
|
|
236
|
+
...node,
|
|
237
|
+
data: {
|
|
238
|
+
...node.data,
|
|
239
|
+
points: newPoints
|
|
240
|
+
}
|
|
241
|
+
} : node));
|
|
242
|
+
}
|
|
243
|
+
// Record history for undo/redo
|
|
244
|
+
if (onPathPointsChange && originalPointsRef.current) {
|
|
245
|
+
setTimeout(()=>{
|
|
246
|
+
console.log('💾 Recording history', {
|
|
247
|
+
originalPoints: originalPointsRef.current,
|
|
248
|
+
newPoints
|
|
249
|
+
});
|
|
250
|
+
onPathPointsChange(id, originalPointsRef.current, newPoints);
|
|
251
|
+
}, 10);
|
|
252
|
+
}
|
|
253
|
+
// Reset states
|
|
254
|
+
setIsDraggingPoint(false);
|
|
255
|
+
setDragPointIndex(null);
|
|
256
|
+
setDragOffset({
|
|
257
|
+
x: 0,
|
|
258
|
+
y: 0
|
|
259
|
+
});
|
|
260
|
+
setDragSyncOffset({
|
|
261
|
+
x: 0,
|
|
262
|
+
y: 0
|
|
263
|
+
});
|
|
264
|
+
currentDragOffsetRef.current = {
|
|
265
|
+
x: 0,
|
|
266
|
+
y: 0
|
|
267
|
+
};
|
|
268
|
+
currentSyncOffsetRef.current = {
|
|
269
|
+
x: 0,
|
|
270
|
+
y: 0
|
|
271
|
+
};
|
|
272
|
+
// Notify parent about drag state change
|
|
273
|
+
onPathPointDragStateChange?.(id, false);
|
|
274
|
+
// Cleanup
|
|
275
|
+
dragStartRef.current = null;
|
|
276
|
+
originalPointsRef.current = [];
|
|
277
|
+
document.removeEventListener('mousemove', handleMouseMove);
|
|
278
|
+
document.removeEventListener('mouseup', handleMouseUp);
|
|
279
|
+
};
|
|
280
|
+
document.addEventListener('mousemove', handleMouseMove);
|
|
281
|
+
document.addEventListener('mouseup', handleMouseUp);
|
|
282
|
+
}, [
|
|
283
|
+
id,
|
|
284
|
+
isEditable,
|
|
285
|
+
points,
|
|
286
|
+
isClosedPath,
|
|
287
|
+
onPathPointsChange,
|
|
288
|
+
onPathPointDragStateChange,
|
|
289
|
+
setNodes,
|
|
290
|
+
getViewport,
|
|
291
|
+
getBounds,
|
|
292
|
+
getNodes
|
|
293
|
+
]);
|
|
294
|
+
// Create SVG path string using fixed bounds during drag to prevent React Flow repositioning
|
|
295
|
+
const pathString = displayPoints.length > 0 ? (()=>{
|
|
296
|
+
// Use fixed bounds during drag to maintain stable React Flow node positioning
|
|
297
|
+
const pathPoints = displayPoints.map((p, index)=>{
|
|
298
|
+
const baseX = p.x - bounds.minX;
|
|
299
|
+
const baseY = p.y - bounds.minY;
|
|
300
|
+
// Apply drag offsets for visual feedback during dragging
|
|
301
|
+
const { x, y } = (()=>{
|
|
302
|
+
if (isDraggingPoint && dragPointIndex === index) {
|
|
303
|
+
return {
|
|
304
|
+
x: baseX + dragOffset.x,
|
|
305
|
+
y: baseY + dragOffset.y
|
|
306
|
+
};
|
|
307
|
+
} else if (isDraggingPoint && isClosedPath && points.length > 2) {
|
|
308
|
+
// Apply sync offset to opposite point in closed paths
|
|
309
|
+
const isFirstPoint = index === 0;
|
|
310
|
+
const isLastPoint = index === points.length - 1;
|
|
311
|
+
const draggedIsFirst = dragPointIndex === 0;
|
|
312
|
+
const draggedIsLast = dragPointIndex === points.length - 1;
|
|
313
|
+
if (draggedIsFirst && isLastPoint || draggedIsLast && isFirstPoint) {
|
|
314
|
+
return {
|
|
315
|
+
x: baseX + dragSyncOffset.x,
|
|
316
|
+
y: baseY + dragSyncOffset.y
|
|
317
|
+
};
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
return {
|
|
321
|
+
x: baseX,
|
|
322
|
+
y: baseY
|
|
323
|
+
};
|
|
324
|
+
})();
|
|
325
|
+
return `${x} ${y}`;
|
|
326
|
+
});
|
|
327
|
+
if (isClosedPath) {
|
|
328
|
+
// For closed paths, remove the duplicate last point and add Z to close
|
|
329
|
+
return `M ${pathPoints.slice(0, -1).join(' L ')} Z`;
|
|
330
|
+
} else {
|
|
331
|
+
// For open paths, connect all points
|
|
332
|
+
return `M ${pathPoints.join(' L ')}`;
|
|
333
|
+
}
|
|
334
|
+
})() : '';
|
|
335
|
+
console.log('🎨 SVG path generation (fixed bounds during drag)', {
|
|
336
|
+
id: id.slice(-4),
|
|
337
|
+
isClosedPath,
|
|
338
|
+
isDragging: isDraggingPoint,
|
|
339
|
+
draggedIndex: isDraggingPoint ? dragPointIndex : null,
|
|
340
|
+
pointsCount: displayPoints.length,
|
|
341
|
+
bounds: `(${bounds.minX}, ${bounds.minY}) to (${bounds.maxX}, ${bounds.maxY})`,
|
|
342
|
+
boundsSource: isDraggingPoint && originalPointsRef.current.length > 0 ? 'original (fixed)' : 'current',
|
|
343
|
+
pathPreview: pathString.substring(0, 50) + (pathString.length > 50 ? '...' : '')
|
|
344
|
+
});
|
|
345
|
+
// Handle copy and paste
|
|
346
|
+
const handleCopyPaste = useCallback(()=>{
|
|
347
|
+
const currentNode = getNodesFromHook().find((node)=>node.id === id);
|
|
348
|
+
if (!currentNode) {
|
|
349
|
+
console.error('Current node not found');
|
|
350
|
+
return;
|
|
351
|
+
}
|
|
352
|
+
setNodesFromHook((nds)=>{
|
|
353
|
+
// Calculate next zIndex
|
|
354
|
+
const maxZIndex = Math.max(...nds.map((n)=>n.zIndex || 0), 0);
|
|
355
|
+
const copiedNode = createPathCopy({
|
|
356
|
+
currentNode,
|
|
357
|
+
data: {
|
|
358
|
+
points,
|
|
359
|
+
color,
|
|
360
|
+
strokeWidth,
|
|
361
|
+
label
|
|
362
|
+
}
|
|
363
|
+
});
|
|
364
|
+
const nodeWithZIndex = {
|
|
365
|
+
...copiedNode,
|
|
366
|
+
zIndex: maxZIndex + 1
|
|
367
|
+
};
|
|
368
|
+
return [
|
|
369
|
+
...nds,
|
|
370
|
+
nodeWithZIndex
|
|
371
|
+
];
|
|
372
|
+
});
|
|
373
|
+
handleCloseContextMenu();
|
|
374
|
+
}, [
|
|
375
|
+
id,
|
|
376
|
+
points,
|
|
377
|
+
color,
|
|
378
|
+
strokeWidth,
|
|
379
|
+
label,
|
|
380
|
+
getNodesFromHook,
|
|
381
|
+
setNodesFromHook,
|
|
382
|
+
handleCloseContextMenu
|
|
383
|
+
]);
|
|
384
|
+
// 在檢視模式下計算 hover 顏色
|
|
385
|
+
const displayColor = viewMode === ViewMode.VIEW && isHovered ? createHoverColor(color) : color;
|
|
386
|
+
return /*#__PURE__*/ jsxs("div", {
|
|
387
|
+
className: `${styles.pathNode} ${selected && isEditable ? styles.selected : ''} ${!isSelectable ? styles.nonSelectable : ''}`,
|
|
388
|
+
children: [
|
|
389
|
+
/*#__PURE__*/ jsxs("div", {
|
|
390
|
+
className: styles.pathContainer,
|
|
391
|
+
style: {
|
|
392
|
+
width: `${width}px`,
|
|
393
|
+
height: `${height}px`,
|
|
394
|
+
opacity: opacity,
|
|
395
|
+
border: selected && isEditable ? '2px solid #3b82f6' : 'none',
|
|
396
|
+
borderRadius: '4px',
|
|
397
|
+
position: 'relative',
|
|
398
|
+
cursor: viewMode === ViewMode.VIEW ? 'pointer' : 'default',
|
|
399
|
+
transition: viewMode === ViewMode.VIEW ? 'all 0.2s ease' : 'none'
|
|
400
|
+
},
|
|
401
|
+
onDoubleClick: viewMode === ViewMode.EDIT ? handleDoubleClick : undefined,
|
|
402
|
+
onContextMenu: viewMode === ViewMode.EDIT ? handleContextMenu : undefined,
|
|
403
|
+
children: [
|
|
404
|
+
/*#__PURE__*/ jsx("svg", {
|
|
405
|
+
width: width,
|
|
406
|
+
height: height,
|
|
407
|
+
style: {
|
|
408
|
+
overflow: 'visible'
|
|
409
|
+
},
|
|
410
|
+
children: /*#__PURE__*/ jsx("path", {
|
|
411
|
+
d: pathString,
|
|
412
|
+
stroke: displayColor,
|
|
413
|
+
strokeWidth: strokeWidth,
|
|
414
|
+
fill: isClosedPath ? displayColor : 'none',
|
|
415
|
+
fillOpacity: isClosedPath ? 0.2 : 0,
|
|
416
|
+
strokeLinecap: "round",
|
|
417
|
+
strokeLinejoin: "round"
|
|
418
|
+
})
|
|
419
|
+
}),
|
|
420
|
+
selected && isEditable && /*#__PURE__*/ jsx("div", {
|
|
421
|
+
className: "nodrag",
|
|
422
|
+
style: {
|
|
423
|
+
position: 'absolute',
|
|
424
|
+
top: 0,
|
|
425
|
+
left: 0,
|
|
426
|
+
width: `${width}px`,
|
|
427
|
+
height: `${height}px`,
|
|
428
|
+
pointerEvents: 'none',
|
|
429
|
+
zIndex: 1000
|
|
430
|
+
},
|
|
431
|
+
children: displayPoints.map((point, index)=>{
|
|
432
|
+
// Use fixed bounds during dragging to maintain stable positioning
|
|
433
|
+
const relativeX = point.x - bounds.minX;
|
|
434
|
+
const relativeY = point.y - bounds.minY;
|
|
435
|
+
const isBeingDragged = dragPointIndex === index && isDraggingPoint;
|
|
436
|
+
// Apply visual offset during drag for smooth feedback
|
|
437
|
+
const { visualX, visualY } = (()=>{
|
|
438
|
+
if (isBeingDragged) {
|
|
439
|
+
// Apply drag offset to the dragged point
|
|
440
|
+
return {
|
|
441
|
+
visualX: relativeX + dragOffset.x,
|
|
442
|
+
visualY: relativeY + dragOffset.y
|
|
443
|
+
};
|
|
444
|
+
} else if (isDraggingPoint && isClosedPath && points.length > 2) {
|
|
445
|
+
// Apply sync offset to the opposite point in closed paths
|
|
446
|
+
const isFirstPoint = index === 0;
|
|
447
|
+
const isLastPoint = index === points.length - 1;
|
|
448
|
+
const draggedIsFirst = dragPointIndex === 0;
|
|
449
|
+
const draggedIsLast = dragPointIndex === points.length - 1;
|
|
450
|
+
if (draggedIsFirst && isLastPoint || draggedIsLast && isFirstPoint) {
|
|
451
|
+
return {
|
|
452
|
+
visualX: relativeX + dragSyncOffset.x,
|
|
453
|
+
visualY: relativeY + dragSyncOffset.y
|
|
454
|
+
};
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
return {
|
|
458
|
+
visualX: relativeX,
|
|
459
|
+
visualY: relativeY
|
|
460
|
+
};
|
|
461
|
+
})();
|
|
462
|
+
return /*#__PURE__*/ jsx("div", {
|
|
463
|
+
className: "nodrag nopan",
|
|
464
|
+
style: {
|
|
465
|
+
position: 'absolute',
|
|
466
|
+
left: `${visualX - 6}px`,
|
|
467
|
+
top: `${visualY - 6}px`,
|
|
468
|
+
width: '12px',
|
|
469
|
+
height: '12px',
|
|
470
|
+
borderRadius: '50%',
|
|
471
|
+
background: displayColor,
|
|
472
|
+
border: '2px solid white',
|
|
473
|
+
cursor: isDraggingPoint ? 'grabbing' : 'grab',
|
|
474
|
+
zIndex: 1001,
|
|
475
|
+
pointerEvents: 'auto',
|
|
476
|
+
boxShadow: isBeingDragged ? '0 4px 8px rgba(0,0,0,0.4)' : '0 2px 4px rgba(0,0,0,0.3)',
|
|
477
|
+
transform: isBeingDragged ? 'scale(1.3)' : 'scale(1)',
|
|
478
|
+
transition: isDraggingPoint ? 'none' : 'all 0.2s ease',
|
|
479
|
+
opacity: isBeingDragged ? 0.8 : 1
|
|
480
|
+
},
|
|
481
|
+
onMouseDown: (e)=>{
|
|
482
|
+
// React Flow best practice: use nodrag class and proper event handling
|
|
483
|
+
e.stopPropagation();
|
|
484
|
+
handlePointMouseDown(index, e);
|
|
485
|
+
},
|
|
486
|
+
title: `Point ${index + 1}`
|
|
487
|
+
}, `point-${index}`);
|
|
488
|
+
})
|
|
489
|
+
}),
|
|
490
|
+
/*#__PURE__*/ jsx("div", {
|
|
491
|
+
style: {
|
|
492
|
+
position: 'absolute',
|
|
493
|
+
top: '50%',
|
|
494
|
+
left: '50%',
|
|
495
|
+
transform: 'translate(-50%, -50%)',
|
|
496
|
+
display: 'flex',
|
|
497
|
+
alignItems: 'center',
|
|
498
|
+
justifyContent: 'center',
|
|
499
|
+
color: 'white',
|
|
500
|
+
fontSize: '12px',
|
|
501
|
+
fontWeight: 'bold',
|
|
502
|
+
textShadow: '1px 1px 2px rgba(0,0,0,0.8)',
|
|
503
|
+
pointerEvents: isEditing ? 'auto' : 'none',
|
|
504
|
+
width: '90%',
|
|
505
|
+
textAlign: 'center'
|
|
506
|
+
},
|
|
507
|
+
children: isEditing ? /*#__PURE__*/ jsx("input", {
|
|
508
|
+
ref: inputRef,
|
|
509
|
+
type: "text",
|
|
510
|
+
value: editingText,
|
|
511
|
+
onChange: (e)=>setEditingText(e.target.value),
|
|
512
|
+
onKeyDown: handleKeyDown,
|
|
513
|
+
onBlur: handleBlur,
|
|
514
|
+
className: "nodrag",
|
|
515
|
+
style: {
|
|
516
|
+
background: 'transparent',
|
|
517
|
+
border: 'none',
|
|
518
|
+
outline: 'none',
|
|
519
|
+
color: 'white',
|
|
520
|
+
fontSize: '12px',
|
|
521
|
+
fontWeight: 'bold',
|
|
522
|
+
textAlign: 'center',
|
|
523
|
+
width: '90%',
|
|
524
|
+
textShadow: '1px 1px 2px rgba(0,0,0,0.5)'
|
|
525
|
+
},
|
|
526
|
+
onClick: (e)=>e.stopPropagation()
|
|
527
|
+
}) : /*#__PURE__*/ jsx("span", {
|
|
528
|
+
style: {
|
|
529
|
+
cursor: 'default'
|
|
530
|
+
},
|
|
531
|
+
children: label
|
|
532
|
+
})
|
|
533
|
+
})
|
|
534
|
+
]
|
|
535
|
+
}),
|
|
536
|
+
viewMode === ViewMode.EDIT && /*#__PURE__*/ jsx(ContextMenu, {
|
|
537
|
+
visible: contextMenu.visible,
|
|
538
|
+
x: contextMenu.x,
|
|
539
|
+
y: contextMenu.y,
|
|
540
|
+
onClose: handleCloseContextMenu,
|
|
541
|
+
onCopyPaste: handleCopyPaste,
|
|
542
|
+
onDelete: handleDelete,
|
|
543
|
+
arrangeActions: arrangeActions,
|
|
544
|
+
arrangeStates: arrangeStates
|
|
545
|
+
})
|
|
546
|
+
]
|
|
547
|
+
});
|
|
548
|
+
};
|
|
549
|
+
|
|
550
|
+
export { PathNode as default };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { FC } from 'react';
|
|
2
|
+
import { NodeProps } from '@xyflow/react';
|
|
3
|
+
import { EditMode, ViewMode } from '../../typings';
|
|
4
|
+
interface RectangleNodeProps extends NodeProps {
|
|
5
|
+
editMode: EditMode;
|
|
6
|
+
viewMode: ViewMode;
|
|
7
|
+
onTextEditComplete?: (id: string, oldText: string, newText: string) => void;
|
|
8
|
+
isHovered?: boolean;
|
|
9
|
+
}
|
|
10
|
+
declare const RectangleNode: FC<RectangleNodeProps>;
|
|
11
|
+
export default RectangleNode;
|