@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,317 @@
|
|
|
1
|
+
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
2
|
+
import { useMemo, useCallback, useState } from 'react';
|
|
3
|
+
import { ReactFlow, Background, useReactFlow, useOnViewportChange } from '@xyflow/react';
|
|
4
|
+
import { DrawingMode, EditMode, ViewMode } from '../../typings.js';
|
|
5
|
+
import ImageNode from '../nodes/image-node.js';
|
|
6
|
+
import RectangleNode from '../nodes/rectangle-node.js';
|
|
7
|
+
import PathNode from '../nodes/path-node.js';
|
|
8
|
+
import { useRectangleDrawing } from '../../hooks/use-rectangle-drawing.js';
|
|
9
|
+
import { usePenDrawing } from '../../hooks/use-pen-drawing.js';
|
|
10
|
+
import styles from './react-flow-canvas.module.scss.js';
|
|
11
|
+
import { FolderIcon } from '../../icons/index.js';
|
|
12
|
+
|
|
13
|
+
const CustomControls = ()=>{
|
|
14
|
+
const { zoomIn, zoomOut, fitView, getZoom } = useReactFlow();
|
|
15
|
+
const [zoom, setZoom] = useState(()=>Math.round(getZoom() * 100));
|
|
16
|
+
// Listen for viewport changes (including mouse wheel zoom)
|
|
17
|
+
useOnViewportChange({
|
|
18
|
+
onChange: (viewport)=>{
|
|
19
|
+
setZoom(Math.round(viewport.zoom * 100));
|
|
20
|
+
console.log('🔍 Zoom changed:', viewport.zoom);
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
const handleZoomIn = ()=>{
|
|
24
|
+
zoomIn();
|
|
25
|
+
// No need to manually update zoom state, useOnViewportChange will handle it
|
|
26
|
+
};
|
|
27
|
+
const handleZoomOut = ()=>{
|
|
28
|
+
zoomOut();
|
|
29
|
+
// No need to manually update zoom state, useOnViewportChange will handle it
|
|
30
|
+
};
|
|
31
|
+
const handleFitView = ()=>{
|
|
32
|
+
fitView();
|
|
33
|
+
// No need to manually update zoom state, useOnViewportChange will handle it
|
|
34
|
+
};
|
|
35
|
+
return /*#__PURE__*/ jsx(Fragment, {
|
|
36
|
+
children: /*#__PURE__*/ jsxs("div", {
|
|
37
|
+
className: styles.zoomControls,
|
|
38
|
+
children: [
|
|
39
|
+
/*#__PURE__*/ jsx("button", {
|
|
40
|
+
className: styles.controlButton,
|
|
41
|
+
onClick: handleZoomOut,
|
|
42
|
+
children: "−"
|
|
43
|
+
}),
|
|
44
|
+
/*#__PURE__*/ jsxs("span", {
|
|
45
|
+
className: styles.zoomPercentage,
|
|
46
|
+
children: [
|
|
47
|
+
zoom,
|
|
48
|
+
"%"
|
|
49
|
+
]
|
|
50
|
+
}),
|
|
51
|
+
/*#__PURE__*/ jsx("button", {
|
|
52
|
+
className: styles.controlButton,
|
|
53
|
+
onClick: handleZoomIn,
|
|
54
|
+
children: "+"
|
|
55
|
+
}),
|
|
56
|
+
/*#__PURE__*/ jsx("button", {
|
|
57
|
+
className: styles.controlButton,
|
|
58
|
+
onClick: handleFitView,
|
|
59
|
+
children: "⛶"
|
|
60
|
+
})
|
|
61
|
+
]
|
|
62
|
+
})
|
|
63
|
+
});
|
|
64
|
+
};
|
|
65
|
+
const ReactFlowCanvas = ({ nodes, edges, onNodesChange, onEdgesChange, onConnect, editMode, drawingMode, viewMode, selectedColor = '#3b82f6', onCreateRectangle, onCreatePath, onSelectionChange, onTextEditComplete, onPathPointsChange, onPathPointDragStateChange, isEditingPathPoints: _isEditingPathPoints = false, hoveredNodeId, onNodeMouseEnter, onNodeMouseLeave, onNodeClick, showBackground = true })=>{
|
|
66
|
+
// console.log('🖼️ ReactFlowCanvas 接收到 showBackground:', showBackground);
|
|
67
|
+
const { containerRef: rectContainerRef, previewRect } = useRectangleDrawing({
|
|
68
|
+
editMode,
|
|
69
|
+
drawingMode,
|
|
70
|
+
onCreateRectangle
|
|
71
|
+
});
|
|
72
|
+
const { containerRef: penContainerRef, isDrawing: isDrawingPen, previewPath, currentPoints, firstPoint, canClose, forceComplete } = usePenDrawing({
|
|
73
|
+
editMode,
|
|
74
|
+
drawingMode,
|
|
75
|
+
onCreatePath
|
|
76
|
+
});
|
|
77
|
+
const nodeTypes = useMemo(()=>({
|
|
78
|
+
imageNode: (props)=>/*#__PURE__*/ jsx(ImageNode, {
|
|
79
|
+
...props,
|
|
80
|
+
editMode: editMode,
|
|
81
|
+
viewMode: viewMode,
|
|
82
|
+
showBackground: showBackground
|
|
83
|
+
}),
|
|
84
|
+
rectangleNode: (props)=>/*#__PURE__*/ jsx(RectangleNode, {
|
|
85
|
+
...props,
|
|
86
|
+
editMode: editMode,
|
|
87
|
+
viewMode: viewMode,
|
|
88
|
+
onTextEditComplete: onTextEditComplete,
|
|
89
|
+
isHovered: hoveredNodeId === props.id
|
|
90
|
+
}),
|
|
91
|
+
pathNode: (props)=>/*#__PURE__*/ jsx(PathNode, {
|
|
92
|
+
...props,
|
|
93
|
+
editMode: editMode,
|
|
94
|
+
viewMode: viewMode,
|
|
95
|
+
onTextEditComplete: onTextEditComplete,
|
|
96
|
+
onPathPointsChange: onPathPointsChange,
|
|
97
|
+
onPathPointDragStateChange: onPathPointDragStateChange ? (_id, isDragging)=>onPathPointDragStateChange(isDragging) : undefined,
|
|
98
|
+
isHovered: hoveredNodeId === props.id
|
|
99
|
+
})
|
|
100
|
+
}), [
|
|
101
|
+
editMode,
|
|
102
|
+
viewMode,
|
|
103
|
+
onTextEditComplete,
|
|
104
|
+
onPathPointsChange,
|
|
105
|
+
onPathPointDragStateChange,
|
|
106
|
+
hoveredNodeId,
|
|
107
|
+
showBackground
|
|
108
|
+
]);
|
|
109
|
+
// Use a callback ref to assign both drawing hooks to the same container
|
|
110
|
+
const containerRef = useCallback((node)=>{
|
|
111
|
+
if (node) {
|
|
112
|
+
rectContainerRef.current = node;
|
|
113
|
+
penContainerRef.current = node;
|
|
114
|
+
}
|
|
115
|
+
}, [
|
|
116
|
+
rectContainerRef,
|
|
117
|
+
penContainerRef
|
|
118
|
+
]);
|
|
119
|
+
const getCursor = ()=>{
|
|
120
|
+
return 'default';
|
|
121
|
+
};
|
|
122
|
+
// Handle pane click for auto-completing pen drawing
|
|
123
|
+
const handlePaneClick = useCallback((event)=>{
|
|
124
|
+
// Check if any modifier keys are pressed - if so, don't auto-complete
|
|
125
|
+
// This prevents accidental completion when using Shift for line constraints
|
|
126
|
+
const hasModifierKeys = event && (event.shiftKey || event.ctrlKey || event.altKey || event.metaKey);
|
|
127
|
+
console.log('📋 ReactFlow pane clicked', {
|
|
128
|
+
drawingMode,
|
|
129
|
+
editMode,
|
|
130
|
+
isDrawingPen,
|
|
131
|
+
hasModifierKeys,
|
|
132
|
+
willForceComplete: drawingMode === DrawingMode.PEN && editMode === EditMode.LAYER && isDrawingPen && !hasModifierKeys
|
|
133
|
+
});
|
|
134
|
+
// Only auto-complete if we're in pen drawing mode, actually drawing, and no modifier keys are pressed
|
|
135
|
+
if (drawingMode === DrawingMode.PEN && editMode === EditMode.LAYER && isDrawingPen && !hasModifierKeys) {
|
|
136
|
+
console.log('🔴 Force completing path from pane click');
|
|
137
|
+
forceComplete();
|
|
138
|
+
}
|
|
139
|
+
}, [
|
|
140
|
+
drawingMode,
|
|
141
|
+
editMode,
|
|
142
|
+
isDrawingPen,
|
|
143
|
+
forceComplete
|
|
144
|
+
]);
|
|
145
|
+
// Add wheel event listener for debugging
|
|
146
|
+
const handleWheel = useCallback((event)=>{
|
|
147
|
+
console.log('🖱️ Wheel event detected:', {
|
|
148
|
+
deltaY: event.deltaY,
|
|
149
|
+
ctrlKey: event.ctrlKey,
|
|
150
|
+
metaKey: event.metaKey,
|
|
151
|
+
target: event.target
|
|
152
|
+
});
|
|
153
|
+
}, []);
|
|
154
|
+
return /*#__PURE__*/ jsxs("div", {
|
|
155
|
+
ref: containerRef,
|
|
156
|
+
className: styles.reactFlowWrapper,
|
|
157
|
+
style: {
|
|
158
|
+
cursor: getCursor(),
|
|
159
|
+
position: 'relative'
|
|
160
|
+
},
|
|
161
|
+
onWheel: handleWheel,
|
|
162
|
+
children: [
|
|
163
|
+
/*#__PURE__*/ jsxs(ReactFlow, {
|
|
164
|
+
nodes: nodes,
|
|
165
|
+
edges: edges,
|
|
166
|
+
onNodesChange: onNodesChange,
|
|
167
|
+
onEdgesChange: onEdgesChange,
|
|
168
|
+
onConnect: onConnect,
|
|
169
|
+
onSelectionChange: onSelectionChange,
|
|
170
|
+
onPaneClick: handlePaneClick,
|
|
171
|
+
onNodeMouseEnter: onNodeMouseEnter,
|
|
172
|
+
onNodeMouseLeave: onNodeMouseLeave,
|
|
173
|
+
onNodeClick: onNodeClick,
|
|
174
|
+
nodeTypes: nodeTypes,
|
|
175
|
+
className: styles.reactFlowCanvas,
|
|
176
|
+
style: {
|
|
177
|
+
background: '#F5F5F5'
|
|
178
|
+
},
|
|
179
|
+
defaultViewport: {
|
|
180
|
+
x: 0,
|
|
181
|
+
y: 0,
|
|
182
|
+
zoom: 1
|
|
183
|
+
},
|
|
184
|
+
minZoom: 0.1,
|
|
185
|
+
maxZoom: 4,
|
|
186
|
+
nodesConnectable: false,
|
|
187
|
+
nodesDraggable: viewMode === ViewMode.EDIT && drawingMode === DrawingMode.NONE,
|
|
188
|
+
elementsSelectable: true,
|
|
189
|
+
selectNodesOnDrag: false,
|
|
190
|
+
panOnDrag: viewMode === ViewMode.VIEW || viewMode === ViewMode.EDIT && drawingMode === DrawingMode.NONE,
|
|
191
|
+
panOnScroll: false,
|
|
192
|
+
zoomOnScroll: true,
|
|
193
|
+
zoomOnDoubleClick: viewMode === ViewMode.EDIT && drawingMode !== DrawingMode.PEN,
|
|
194
|
+
nodeOrigin: [
|
|
195
|
+
0,
|
|
196
|
+
0
|
|
197
|
+
],
|
|
198
|
+
preventScrolling: true,
|
|
199
|
+
children: [
|
|
200
|
+
/*#__PURE__*/ jsx(CustomControls, {}),
|
|
201
|
+
/*#__PURE__*/ jsx(Background, {
|
|
202
|
+
bgColor: "#F5F5F5"
|
|
203
|
+
}),
|
|
204
|
+
nodes.length === 0 && /*#__PURE__*/ jsxs("div", {
|
|
205
|
+
className: styles.emptyState,
|
|
206
|
+
children: [
|
|
207
|
+
/*#__PURE__*/ jsx(FolderIcon, {
|
|
208
|
+
className: styles.emptyIcon
|
|
209
|
+
}),
|
|
210
|
+
/*#__PURE__*/ jsx("div", {
|
|
211
|
+
className: styles.emptyTitle,
|
|
212
|
+
children: "目前沒有資料"
|
|
213
|
+
}),
|
|
214
|
+
/*#__PURE__*/ jsx("div", {
|
|
215
|
+
className: styles.emptySubText,
|
|
216
|
+
children: "請上傳底圖並繪製圖層"
|
|
217
|
+
})
|
|
218
|
+
]
|
|
219
|
+
})
|
|
220
|
+
]
|
|
221
|
+
}),
|
|
222
|
+
previewRect && /*#__PURE__*/ jsx("div", {
|
|
223
|
+
style: {
|
|
224
|
+
position: 'absolute',
|
|
225
|
+
left: previewRect.x,
|
|
226
|
+
top: previewRect.y,
|
|
227
|
+
width: previewRect.width,
|
|
228
|
+
height: previewRect.height,
|
|
229
|
+
border: `2px dashed ${selectedColor}`,
|
|
230
|
+
backgroundColor: `${selectedColor}33`,
|
|
231
|
+
pointerEvents: 'none',
|
|
232
|
+
zIndex: 1000
|
|
233
|
+
}
|
|
234
|
+
}),
|
|
235
|
+
drawingMode === DrawingMode.PEN && editMode === EditMode.LAYER && /*#__PURE__*/ jsxs("svg", {
|
|
236
|
+
style: {
|
|
237
|
+
position: 'absolute',
|
|
238
|
+
top: 0,
|
|
239
|
+
left: 0,
|
|
240
|
+
width: '100%',
|
|
241
|
+
height: '100%',
|
|
242
|
+
pointerEvents: 'none',
|
|
243
|
+
zIndex: 1000
|
|
244
|
+
},
|
|
245
|
+
children: [
|
|
246
|
+
previewPath && previewPath.length > 1 && /*#__PURE__*/ jsx("path", {
|
|
247
|
+
d: `M ${previewPath.map((p)=>`${p.x} ${p.y}`).join(' L ')}`,
|
|
248
|
+
stroke: selectedColor,
|
|
249
|
+
strokeWidth: "2",
|
|
250
|
+
strokeDasharray: "5,5",
|
|
251
|
+
fill: "none",
|
|
252
|
+
fillOpacity: 0,
|
|
253
|
+
strokeLinecap: "round",
|
|
254
|
+
strokeLinejoin: "round"
|
|
255
|
+
}),
|
|
256
|
+
currentPoints && currentPoints.length >= 3 && /*#__PURE__*/ jsx("path", {
|
|
257
|
+
d: `M ${currentPoints[currentPoints.length - 1].x} ${currentPoints[currentPoints.length - 1].y} L ${currentPoints[0].x} ${currentPoints[0].y}`,
|
|
258
|
+
stroke: selectedColor,
|
|
259
|
+
strokeWidth: "1",
|
|
260
|
+
strokeDasharray: "2,2",
|
|
261
|
+
fill: "none",
|
|
262
|
+
strokeLinecap: "round",
|
|
263
|
+
opacity: "0.5"
|
|
264
|
+
}),
|
|
265
|
+
firstPoint && canClose && /*#__PURE__*/ jsxs(Fragment, {
|
|
266
|
+
children: [
|
|
267
|
+
/*#__PURE__*/ jsxs("circle", {
|
|
268
|
+
cx: firstPoint.x,
|
|
269
|
+
cy: firstPoint.y,
|
|
270
|
+
r: "8",
|
|
271
|
+
fill: "none",
|
|
272
|
+
stroke: "#10b981",
|
|
273
|
+
strokeWidth: "2",
|
|
274
|
+
opacity: "0.6",
|
|
275
|
+
children: [
|
|
276
|
+
/*#__PURE__*/ jsx("animate", {
|
|
277
|
+
attributeName: "r",
|
|
278
|
+
values: "6;10;6",
|
|
279
|
+
dur: "1.5s",
|
|
280
|
+
repeatCount: "indefinite"
|
|
281
|
+
}),
|
|
282
|
+
/*#__PURE__*/ jsx("animate", {
|
|
283
|
+
attributeName: "opacity",
|
|
284
|
+
values: "0.8;0.3;0.8",
|
|
285
|
+
dur: "1.5s",
|
|
286
|
+
repeatCount: "indefinite"
|
|
287
|
+
})
|
|
288
|
+
]
|
|
289
|
+
}),
|
|
290
|
+
/*#__PURE__*/ jsx("circle", {
|
|
291
|
+
cx: firstPoint.x,
|
|
292
|
+
cy: firstPoint.y,
|
|
293
|
+
r: "5",
|
|
294
|
+
fill: "#10b981",
|
|
295
|
+
stroke: "white",
|
|
296
|
+
strokeWidth: "2",
|
|
297
|
+
style: {
|
|
298
|
+
cursor: 'default'
|
|
299
|
+
}
|
|
300
|
+
})
|
|
301
|
+
]
|
|
302
|
+
}),
|
|
303
|
+
currentPoints && currentPoints.map((point, index)=>/*#__PURE__*/ jsx("circle", {
|
|
304
|
+
cx: point.x,
|
|
305
|
+
cy: point.y,
|
|
306
|
+
r: index === 0 && canClose ? '0' : '4',
|
|
307
|
+
fill: selectedColor,
|
|
308
|
+
stroke: "white",
|
|
309
|
+
strokeWidth: "2"
|
|
310
|
+
}, index))
|
|
311
|
+
]
|
|
312
|
+
})
|
|
313
|
+
]
|
|
314
|
+
});
|
|
315
|
+
};
|
|
316
|
+
|
|
317
|
+
export { ReactFlowCanvas as default };
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
var styles = {"reactFlowWrapper":"react-flow-canvas-module_reactFlowWrapper__tOAkU","reactFlowCanvas":"react-flow-canvas-module_reactFlowCanvas__w-TCn","emptyState":"react-flow-canvas-module_emptyState__5VgEA","emptyIcon":"react-flow-canvas-module_emptyIcon__QemKW","emptyTitle":"react-flow-canvas-module_emptyTitle__YOEpE","emptySubText":"react-flow-canvas-module_emptySubText__k3DUo","zoomControls":"react-flow-canvas-module_zoomControls__MC-ik","controlButton":"react-flow-canvas-module_controlButton__GLHpS","zoomPercentage":"react-flow-canvas-module_zoomPercentage__Mlyal"};
|
|
2
|
+
|
|
3
|
+
export { styles as default };
|