@rytass/wms-map-react-components 0.1.9 → 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.js +1 -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.js +1 -0
- 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.js +1 -0
- 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-content.js +1 -0
- 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.js +1 -0
- 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.js +1 -0
- 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.js +1 -0
- 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.js +1 -0
- 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.js +1 -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.js +1 -0
- 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.js +1 -0
- 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-context-menu.js +1 -0
- 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-direct-state-history.js +1 -0
- 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-pen-drawing.js +1 -0
- 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-rectangle-drawing.js +1 -0
- package/hooks/use-text-editing.cjs +156 -0
- package/hooks/use-text-editing.d.cts +19 -0
- package/hooks/use-text-editing.js +1 -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,239 @@
|
|
|
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 useContextMenu = require('../../hooks/use-context-menu.cjs');
|
|
10
|
+
var useTextEditing = require('../../hooks/use-text-editing.cjs');
|
|
11
|
+
var nodeOperations = require('../../utils/node-operations.cjs');
|
|
12
|
+
var colorUtils = require('../../utils/color-utils.cjs');
|
|
13
|
+
var contextMenu = require('../ui/context-menu.cjs');
|
|
14
|
+
var rectangleNode_module = require('./rectangle-node.module.scss.cjs');
|
|
15
|
+
|
|
16
|
+
const RectangleNode = ({ data, selected, id, editMode, viewMode, onTextEditComplete, isHovered = false })=>{
|
|
17
|
+
const { setNodes } = react.useReactFlow();
|
|
18
|
+
const updateNodeInternals = react.useUpdateNodeInternals();
|
|
19
|
+
const { width = index.DEFAULT_RECTANGLE_WIDTH, height = index.DEFAULT_RECTANGLE_HEIGHT, color = index.DEFAULT_RECTANGLE_COLOR, label = index.DEFAULT_RECTANGLE_LABEL } = data;
|
|
20
|
+
const [currentSize, setCurrentSize] = React.useState({
|
|
21
|
+
width,
|
|
22
|
+
height
|
|
23
|
+
});
|
|
24
|
+
const [isResizing, setIsResizing] = React.useState(false);
|
|
25
|
+
// Sync state with node data changes
|
|
26
|
+
React.useEffect(()=>{
|
|
27
|
+
setCurrentSize({
|
|
28
|
+
width,
|
|
29
|
+
height
|
|
30
|
+
});
|
|
31
|
+
}, [
|
|
32
|
+
width,
|
|
33
|
+
height
|
|
34
|
+
]);
|
|
35
|
+
// Only editable in LAYER mode
|
|
36
|
+
const isEditable = viewMode === typings.ViewMode.EDIT && editMode === typings.EditMode.LAYER;
|
|
37
|
+
// Check if this node should be selectable (only in LAYER mode)
|
|
38
|
+
const isSelectable = editMode === typings.EditMode.LAYER;
|
|
39
|
+
const opacity = editMode === typings.EditMode.LAYER ? index.ACTIVE_OPACITY : index.RECTANGLE_INACTIVE_OPACITY;
|
|
40
|
+
// Context menu functionality
|
|
41
|
+
const { contextMenu: contextMenu$1, handleContextMenu, handleCloseContextMenu, handleDelete, arrangeActions, arrangeStates, getNodes, setNodes: setNodesFromHook } = useContextMenu.useContextMenu({
|
|
42
|
+
id,
|
|
43
|
+
editMode,
|
|
44
|
+
isEditable,
|
|
45
|
+
nodeType: 'rectangleNode'
|
|
46
|
+
});
|
|
47
|
+
// Text editing functionality
|
|
48
|
+
const { isEditing, editingText, inputRef, setEditingText, handleDoubleClick, handleKeyDown, handleBlur } = useTextEditing.useTextEditing({
|
|
49
|
+
id,
|
|
50
|
+
label,
|
|
51
|
+
isEditable,
|
|
52
|
+
onTextEditComplete
|
|
53
|
+
});
|
|
54
|
+
// Handle resize start
|
|
55
|
+
const handleResizeStart = React.useCallback(// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
56
|
+
(_event, _params)=>{
|
|
57
|
+
// 開始調整大小時可以執行額外的邏輯,例如禁用拖拽
|
|
58
|
+
// 這裡保持空白,但提供了擴展點
|
|
59
|
+
}, []);
|
|
60
|
+
// Handle resize with size sync and position update (diagonal anchor)
|
|
61
|
+
const handleResize = React.useCallback(// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
62
|
+
(_event, params)=>{
|
|
63
|
+
const newSize = {
|
|
64
|
+
width: params.width,
|
|
65
|
+
height: params.height
|
|
66
|
+
};
|
|
67
|
+
setCurrentSize(newSize);
|
|
68
|
+
// 標記正在調整大小,避免在 WmsMapModal 中記錄歷史
|
|
69
|
+
if (!isResizing) {
|
|
70
|
+
setIsResizing(true);
|
|
71
|
+
}
|
|
72
|
+
// 即時更新節點以提供視覺回饋,同時更新位置以保持對角錨點
|
|
73
|
+
setNodes((nodes)=>nodes.map((node)=>node.id === id ? {
|
|
74
|
+
...node,
|
|
75
|
+
data: {
|
|
76
|
+
...node.data,
|
|
77
|
+
width: params.width,
|
|
78
|
+
height: params.height,
|
|
79
|
+
isResizing: true
|
|
80
|
+
},
|
|
81
|
+
position: {
|
|
82
|
+
x: params.x ?? 0,
|
|
83
|
+
y: params.y ?? 0
|
|
84
|
+
}
|
|
85
|
+
} : node));
|
|
86
|
+
}, [
|
|
87
|
+
id,
|
|
88
|
+
setNodes,
|
|
89
|
+
isResizing
|
|
90
|
+
]);
|
|
91
|
+
// Handle resize end to ensure final state is saved
|
|
92
|
+
const handleResizeEnd = React.useCallback(// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
93
|
+
(_event, params)=>{
|
|
94
|
+
const newSize = {
|
|
95
|
+
width: params.width,
|
|
96
|
+
height: params.height
|
|
97
|
+
};
|
|
98
|
+
setCurrentSize(newSize);
|
|
99
|
+
// 清除調整大小標記
|
|
100
|
+
setIsResizing(false);
|
|
101
|
+
// 最終更新節點資料,移除 isResizing 標記,同時更新位置
|
|
102
|
+
// 這次更新會觸發歷史記錄(因為沒有 isResizing 標記)
|
|
103
|
+
setNodes((nodes)=>nodes.map((node)=>node.id === id ? {
|
|
104
|
+
...node,
|
|
105
|
+
data: {
|
|
106
|
+
...node.data,
|
|
107
|
+
width: params.width,
|
|
108
|
+
height: params.height,
|
|
109
|
+
isResizing: undefined
|
|
110
|
+
},
|
|
111
|
+
position: {
|
|
112
|
+
x: params.x ?? 0,
|
|
113
|
+
y: params.y ?? 0
|
|
114
|
+
}
|
|
115
|
+
} : node));
|
|
116
|
+
// 確保內部狀態同步
|
|
117
|
+
updateNodeInternals(id);
|
|
118
|
+
}, [
|
|
119
|
+
id,
|
|
120
|
+
setNodes,
|
|
121
|
+
updateNodeInternals
|
|
122
|
+
]);
|
|
123
|
+
// Handle copy and paste
|
|
124
|
+
const handleCopyPaste = React.useCallback(()=>{
|
|
125
|
+
const currentNode = getNodes().find((node)=>node.id === id);
|
|
126
|
+
if (!currentNode) {
|
|
127
|
+
console.error('Current node not found');
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
setNodesFromHook((nds)=>{
|
|
131
|
+
// Calculate next zIndex
|
|
132
|
+
const maxZIndex = Math.max(...nds.map((n)=>n.zIndex || 0), 0);
|
|
133
|
+
const copiedNode = nodeOperations.createRectangleCopy({
|
|
134
|
+
currentNode,
|
|
135
|
+
data: {
|
|
136
|
+
width: currentSize.width,
|
|
137
|
+
height: currentSize.height,
|
|
138
|
+
color,
|
|
139
|
+
label
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
const nodeWithZIndex = {
|
|
143
|
+
...copiedNode,
|
|
144
|
+
zIndex: maxZIndex + 1
|
|
145
|
+
};
|
|
146
|
+
return [
|
|
147
|
+
...nds,
|
|
148
|
+
nodeWithZIndex
|
|
149
|
+
];
|
|
150
|
+
});
|
|
151
|
+
handleCloseContextMenu();
|
|
152
|
+
}, [
|
|
153
|
+
id,
|
|
154
|
+
currentSize,
|
|
155
|
+
color,
|
|
156
|
+
label,
|
|
157
|
+
getNodes,
|
|
158
|
+
setNodesFromHook,
|
|
159
|
+
handleCloseContextMenu
|
|
160
|
+
]);
|
|
161
|
+
// 在檢視模式下計算 hover 顏色
|
|
162
|
+
const displayColor = viewMode === typings.ViewMode.VIEW && isHovered ? colorUtils.createHoverColor(color) : color;
|
|
163
|
+
return /*#__PURE__*/ jsxRuntime.jsxs("div", {
|
|
164
|
+
className: `${rectangleNode_module.rectangleNode} ${selected && isEditable ? rectangleNode_module.selected : ''} ${!isSelectable ? rectangleNode_module.nonSelectable : ''}`,
|
|
165
|
+
children: [
|
|
166
|
+
selected && isEditable && /*#__PURE__*/ jsxRuntime.jsx(react.NodeResizer, {
|
|
167
|
+
minWidth: index.MIN_RESIZE_WIDTH,
|
|
168
|
+
minHeight: index.MIN_RESIZE_HEIGHT,
|
|
169
|
+
keepAspectRatio: false,
|
|
170
|
+
onResizeStart: handleResizeStart,
|
|
171
|
+
onResize: handleResize,
|
|
172
|
+
onResizeEnd: handleResizeEnd,
|
|
173
|
+
isVisible: selected && isEditable,
|
|
174
|
+
color: "#5570d3",
|
|
175
|
+
handleClassName: rectangleNode_module.customResizeHandle
|
|
176
|
+
}),
|
|
177
|
+
/*#__PURE__*/ jsxRuntime.jsx("div", {
|
|
178
|
+
className: rectangleNode_module.rectangleContainer,
|
|
179
|
+
style: {
|
|
180
|
+
width: `${currentSize.width}px`,
|
|
181
|
+
height: `${currentSize.height}px`,
|
|
182
|
+
backgroundColor: `${displayColor}33`,
|
|
183
|
+
opacity: opacity,
|
|
184
|
+
border: selected && isEditable ? '2px solid #3b82f6' : `2px solid ${displayColor}`,
|
|
185
|
+
borderRadius: '4px',
|
|
186
|
+
display: 'flex',
|
|
187
|
+
alignItems: 'center',
|
|
188
|
+
justifyContent: 'center',
|
|
189
|
+
color: 'white',
|
|
190
|
+
fontSize: '12px',
|
|
191
|
+
fontWeight: 'bold',
|
|
192
|
+
textShadow: '1px 1px 2px rgba(0,0,0,0.5)',
|
|
193
|
+
position: 'relative',
|
|
194
|
+
cursor: viewMode === typings.ViewMode.VIEW ? 'pointer' : 'default',
|
|
195
|
+
transition: viewMode === typings.ViewMode.VIEW ? 'all 0.2s ease' : 'none'
|
|
196
|
+
},
|
|
197
|
+
onDoubleClick: viewMode === typings.ViewMode.EDIT ? handleDoubleClick : undefined,
|
|
198
|
+
onContextMenu: viewMode === typings.ViewMode.EDIT ? handleContextMenu : undefined,
|
|
199
|
+
children: isEditing ? /*#__PURE__*/ jsxRuntime.jsx("input", {
|
|
200
|
+
ref: inputRef,
|
|
201
|
+
type: "text",
|
|
202
|
+
value: editingText,
|
|
203
|
+
onChange: (e)=>setEditingText(e.target.value),
|
|
204
|
+
onKeyDown: handleKeyDown,
|
|
205
|
+
onBlur: handleBlur,
|
|
206
|
+
style: {
|
|
207
|
+
background: 'transparent',
|
|
208
|
+
border: 'none',
|
|
209
|
+
outline: 'none',
|
|
210
|
+
color: 'white',
|
|
211
|
+
fontSize: '12px',
|
|
212
|
+
fontWeight: 'bold',
|
|
213
|
+
textAlign: 'center',
|
|
214
|
+
width: '90%',
|
|
215
|
+
textShadow: '1px 1px 2px rgba(0,0,0,0.5)'
|
|
216
|
+
},
|
|
217
|
+
onClick: (e)=>e.stopPropagation()
|
|
218
|
+
}) : /*#__PURE__*/ jsxRuntime.jsx("span", {
|
|
219
|
+
style: {
|
|
220
|
+
cursor: 'default'
|
|
221
|
+
},
|
|
222
|
+
children: label
|
|
223
|
+
})
|
|
224
|
+
}),
|
|
225
|
+
viewMode === typings.ViewMode.EDIT && /*#__PURE__*/ jsxRuntime.jsx(contextMenu, {
|
|
226
|
+
visible: contextMenu$1.visible,
|
|
227
|
+
x: contextMenu$1.x,
|
|
228
|
+
y: contextMenu$1.y,
|
|
229
|
+
onClose: handleCloseContextMenu,
|
|
230
|
+
onCopyPaste: handleCopyPaste,
|
|
231
|
+
onDelete: handleDelete,
|
|
232
|
+
arrangeActions: arrangeActions,
|
|
233
|
+
arrangeStates: arrangeStates
|
|
234
|
+
})
|
|
235
|
+
]
|
|
236
|
+
});
|
|
237
|
+
};
|
|
238
|
+
|
|
239
|
+
module.exports = RectangleNode;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { FC } from 'react';
|
|
2
|
+
import { NodeProps } from '@xyflow/react';
|
|
3
|
+
import { EditMode, ViewMode } from '../../typings.cjs';
|
|
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;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { FC } from 'react';
|
|
2
2
|
import { NodeProps } from '@xyflow/react';
|
|
3
|
-
import { EditMode, ViewMode } from '../../typings';
|
|
3
|
+
import { EditMode, ViewMode } from '../../typings.js';
|
|
4
4
|
interface RectangleNodeProps extends NodeProps {
|
|
5
5
|
editMode: EditMode;
|
|
6
6
|
viewMode: ViewMode;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var styles = {"rectangleNode":"rectangle-node-module_rectangleNode__gQkvp","selected":"rectangle-node-module_selected__QiPsy","nonSelectable":"rectangle-node-module_nonSelectable__5Fz40","rectangleContainer":"rectangle-node-module_rectangleContainer__8dFeg","customResizeHandle":"rectangle-node-module_customResizeHandle__0ckhO"};
|
|
4
|
+
|
|
5
|
+
module.exports = styles;
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
5
|
+
var React = require('react');
|
|
6
|
+
var reactDom = require('react-dom');
|
|
7
|
+
var contextMenu_module = require('./context-menu.module.scss.cjs');
|
|
8
|
+
|
|
9
|
+
const ContextMenu = ({ visible, x, y, onClose, onCopyPaste, onDelete, arrangeActions, arrangeStates })=>{
|
|
10
|
+
const menuRef = React.useRef(null);
|
|
11
|
+
const [showArrangeSubmenu, setShowArrangeSubmenu] = React.useState(false);
|
|
12
|
+
// Handle clicking outside to close menu
|
|
13
|
+
React.useEffect(()=>{
|
|
14
|
+
if (!visible) return;
|
|
15
|
+
const handleClickOutside = (event)=>{
|
|
16
|
+
const target = event.target;
|
|
17
|
+
const menuElement = menuRef.current;
|
|
18
|
+
if (menuElement) {
|
|
19
|
+
const isInsideMenu = menuElement.contains(target);
|
|
20
|
+
if (!isInsideMenu) {
|
|
21
|
+
onClose();
|
|
22
|
+
}
|
|
23
|
+
} else {
|
|
24
|
+
onClose();
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
const handleKeyDown = (event)=>{
|
|
28
|
+
if (event.key === 'Escape') {
|
|
29
|
+
onClose();
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
// Add small delay to prevent immediate closing when the menu appears
|
|
33
|
+
const timeoutId = setTimeout(()=>{
|
|
34
|
+
document.addEventListener('mousedown', handleClickOutside, true);
|
|
35
|
+
document.addEventListener('click', handleClickOutside, true);
|
|
36
|
+
document.addEventListener('keydown', handleKeyDown, true);
|
|
37
|
+
}, 50);
|
|
38
|
+
return ()=>{
|
|
39
|
+
clearTimeout(timeoutId);
|
|
40
|
+
document.removeEventListener('mousedown', handleClickOutside, true);
|
|
41
|
+
document.removeEventListener('click', handleClickOutside, true);
|
|
42
|
+
document.removeEventListener('keydown', handleKeyDown, true);
|
|
43
|
+
};
|
|
44
|
+
}, [
|
|
45
|
+
visible,
|
|
46
|
+
onClose
|
|
47
|
+
]);
|
|
48
|
+
if (!visible) return null;
|
|
49
|
+
// Adjust position to ensure menu stays within viewport
|
|
50
|
+
const adjustedX = Math.min(x, window.innerWidth - 150); // 150 is approximate menu width
|
|
51
|
+
const adjustedY = Math.min(y, window.innerHeight - 120); // 120 is approximate menu height
|
|
52
|
+
const contextMenuElement = /*#__PURE__*/ jsxRuntime.jsxs("div", {
|
|
53
|
+
ref: menuRef,
|
|
54
|
+
className: contextMenu_module.contextMenu,
|
|
55
|
+
style: {
|
|
56
|
+
position: 'fixed',
|
|
57
|
+
left: Math.max(0, adjustedX),
|
|
58
|
+
top: Math.max(0, adjustedY),
|
|
59
|
+
zIndex: 10000
|
|
60
|
+
},
|
|
61
|
+
children: [
|
|
62
|
+
/*#__PURE__*/ jsxRuntime.jsx("div", {
|
|
63
|
+
className: contextMenu_module.menuItem,
|
|
64
|
+
onClick: onCopyPaste,
|
|
65
|
+
children: /*#__PURE__*/ jsxRuntime.jsxs("div", {
|
|
66
|
+
className: contextMenu_module.menuItemContent,
|
|
67
|
+
children: [
|
|
68
|
+
/*#__PURE__*/ jsxRuntime.jsx("span", {
|
|
69
|
+
className: contextMenu_module.menuItemText,
|
|
70
|
+
children: "複製並貼上"
|
|
71
|
+
}),
|
|
72
|
+
/*#__PURE__*/ jsxRuntime.jsx("span", {
|
|
73
|
+
className: contextMenu_module.menuItemShortcut,
|
|
74
|
+
children: "⌘D"
|
|
75
|
+
})
|
|
76
|
+
]
|
|
77
|
+
})
|
|
78
|
+
}),
|
|
79
|
+
/*#__PURE__*/ jsxRuntime.jsx("div", {
|
|
80
|
+
className: contextMenu_module.menuItem,
|
|
81
|
+
onClick: onDelete,
|
|
82
|
+
children: /*#__PURE__*/ jsxRuntime.jsxs("div", {
|
|
83
|
+
className: contextMenu_module.menuItemContent,
|
|
84
|
+
children: [
|
|
85
|
+
/*#__PURE__*/ jsxRuntime.jsx("span", {
|
|
86
|
+
className: contextMenu_module.menuItemText,
|
|
87
|
+
children: "刪除"
|
|
88
|
+
}),
|
|
89
|
+
/*#__PURE__*/ jsxRuntime.jsx("span", {
|
|
90
|
+
className: contextMenu_module.menuItemShortcut,
|
|
91
|
+
children: "Del"
|
|
92
|
+
})
|
|
93
|
+
]
|
|
94
|
+
})
|
|
95
|
+
}),
|
|
96
|
+
/*#__PURE__*/ jsxRuntime.jsxs("div", {
|
|
97
|
+
className: `${contextMenu_module.menuItem} ${contextMenu_module.hasSubmenu}`,
|
|
98
|
+
onMouseEnter: ()=>setShowArrangeSubmenu(true),
|
|
99
|
+
onMouseLeave: ()=>setShowArrangeSubmenu(false),
|
|
100
|
+
children: [
|
|
101
|
+
"排列順序",
|
|
102
|
+
/*#__PURE__*/ jsxRuntime.jsx("span", {
|
|
103
|
+
className: contextMenu_module.arrow,
|
|
104
|
+
children: "▶"
|
|
105
|
+
}),
|
|
106
|
+
showArrangeSubmenu && /*#__PURE__*/ jsxRuntime.jsxs("div", {
|
|
107
|
+
className: contextMenu_module.submenu,
|
|
108
|
+
style: {
|
|
109
|
+
position: 'absolute',
|
|
110
|
+
left: '100%',
|
|
111
|
+
top: 0,
|
|
112
|
+
zIndex: 10001
|
|
113
|
+
},
|
|
114
|
+
onMouseEnter: ()=>setShowArrangeSubmenu(true),
|
|
115
|
+
onMouseLeave: ()=>setShowArrangeSubmenu(false),
|
|
116
|
+
children: [
|
|
117
|
+
/*#__PURE__*/ jsxRuntime.jsx("div", {
|
|
118
|
+
className: `${contextMenu_module.menuItem} ${!arrangeStates.canBringToFront ? contextMenu_module.disabled : ''}`,
|
|
119
|
+
onClick: (e)=>{
|
|
120
|
+
e.stopPropagation();
|
|
121
|
+
if (arrangeStates.canBringToFront) {
|
|
122
|
+
arrangeActions.onBringToFront();
|
|
123
|
+
onClose();
|
|
124
|
+
}
|
|
125
|
+
},
|
|
126
|
+
children: "移至最前"
|
|
127
|
+
}),
|
|
128
|
+
/*#__PURE__*/ jsxRuntime.jsx("div", {
|
|
129
|
+
className: `${contextMenu_module.menuItem} ${!arrangeStates.canBringForward ? contextMenu_module.disabled : ''}`,
|
|
130
|
+
onClick: (e)=>{
|
|
131
|
+
e.stopPropagation();
|
|
132
|
+
if (arrangeStates.canBringForward) {
|
|
133
|
+
arrangeActions.onBringForward();
|
|
134
|
+
onClose();
|
|
135
|
+
}
|
|
136
|
+
},
|
|
137
|
+
children: "置前"
|
|
138
|
+
}),
|
|
139
|
+
/*#__PURE__*/ jsxRuntime.jsx("div", {
|
|
140
|
+
className: `${contextMenu_module.menuItem} ${!arrangeStates.canSendBackward ? contextMenu_module.disabled : ''}`,
|
|
141
|
+
onClick: (e)=>{
|
|
142
|
+
e.stopPropagation();
|
|
143
|
+
if (arrangeStates.canSendBackward) {
|
|
144
|
+
arrangeActions.onSendBackward();
|
|
145
|
+
onClose();
|
|
146
|
+
}
|
|
147
|
+
},
|
|
148
|
+
children: "置後"
|
|
149
|
+
}),
|
|
150
|
+
/*#__PURE__*/ jsxRuntime.jsx("div", {
|
|
151
|
+
className: `${contextMenu_module.menuItem} ${!arrangeStates.canSendToBack ? contextMenu_module.disabled : ''}`,
|
|
152
|
+
onClick: (e)=>{
|
|
153
|
+
e.stopPropagation();
|
|
154
|
+
if (arrangeStates.canSendToBack) {
|
|
155
|
+
arrangeActions.onSendToBack();
|
|
156
|
+
onClose();
|
|
157
|
+
}
|
|
158
|
+
},
|
|
159
|
+
children: "移至最後"
|
|
160
|
+
})
|
|
161
|
+
]
|
|
162
|
+
})
|
|
163
|
+
]
|
|
164
|
+
})
|
|
165
|
+
]
|
|
166
|
+
});
|
|
167
|
+
// Render to document body to avoid z-index issues
|
|
168
|
+
return /*#__PURE__*/ reactDom.createPortal(contextMenuElement, document.body);
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
module.exports = ContextMenu;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { FC } from 'react';
|
|
2
|
+
interface ArrangeActions {
|
|
3
|
+
onBringToFront: () => void;
|
|
4
|
+
onBringForward: () => void;
|
|
5
|
+
onSendBackward: () => void;
|
|
6
|
+
onSendToBack: () => void;
|
|
7
|
+
}
|
|
8
|
+
interface ArrangeStates {
|
|
9
|
+
canBringToFront: boolean;
|
|
10
|
+
canBringForward: boolean;
|
|
11
|
+
canSendBackward: boolean;
|
|
12
|
+
canSendToBack: boolean;
|
|
13
|
+
}
|
|
14
|
+
interface ContextMenuProps {
|
|
15
|
+
visible: boolean;
|
|
16
|
+
x: number;
|
|
17
|
+
y: number;
|
|
18
|
+
onClose: () => void;
|
|
19
|
+
onCopyPaste: () => void;
|
|
20
|
+
onDelete: () => void;
|
|
21
|
+
arrangeActions: ArrangeActions;
|
|
22
|
+
arrangeStates: ArrangeStates;
|
|
23
|
+
}
|
|
24
|
+
declare const ContextMenu: FC<ContextMenuProps>;
|
|
25
|
+
export default ContextMenu;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var styles = {"contextMenu":"context-menu-module_contextMenu__sLD6R","menuItem":"context-menu-module_menuItem__f0SPx","disabled":"context-menu-module_disabled__08MXH","menuItemContent":"context-menu-module_menuItemContent__GXixI","menuItemText":"context-menu-module_menuItemText__GLxb4","menuItemShortcut":"context-menu-module_menuItemShortcut__z-DrG","hasSubmenu":"context-menu-module_hasSubmenu__JYdzl","arrow":"context-menu-module_arrow__nLoR1","submenu":"context-menu-module_submenu__pV8AQ"};
|
|
4
|
+
|
|
5
|
+
module.exports = styles;
|