@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,130 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
7
|
+
var React = require('react');
|
|
8
|
+
var react = require('@mezzanine-ui/react');
|
|
9
|
+
var react$1 = require('@xyflow/react');
|
|
10
|
+
var typings = require('../../typings.cjs');
|
|
11
|
+
var index = require('../../constants/index.cjs');
|
|
12
|
+
var wmsMapContent = require('./wms-map-content.cjs');
|
|
13
|
+
var debugLogger = require('../../utils/debug-logger.cjs');
|
|
14
|
+
var wmsMapModalContainer_module = require('./wms-map-modal-container.module.scss.cjs');
|
|
15
|
+
|
|
16
|
+
const WMSMapModalContent = ({ editMode, drawingMode, selectedColor, viewMode, colorPalette, showBreadcrumbEditButton, onEditModeChange, onToggleRectangleTool, onTogglePenTool, onColorChange, onNodeClick, onNodeDoubleClick, onSave, onBreadcrumbClick, onNameChange, initialNodes, initialEdges, onUpload, getFilenameFQDN, maxFileSizeKB, warehouseIds })=>{
|
|
17
|
+
return /*#__PURE__*/ jsxRuntime.jsx("div", {
|
|
18
|
+
className: wmsMapModalContainer_module.content,
|
|
19
|
+
children: /*#__PURE__*/ jsxRuntime.jsx(react$1.ReactFlowProvider, {
|
|
20
|
+
children: /*#__PURE__*/ jsxRuntime.jsx(wmsMapContent, {
|
|
21
|
+
editMode: editMode,
|
|
22
|
+
drawingMode: drawingMode,
|
|
23
|
+
selectedColor: selectedColor,
|
|
24
|
+
viewMode: viewMode,
|
|
25
|
+
colorPalette: colorPalette,
|
|
26
|
+
showBreadcrumbEditButton: showBreadcrumbEditButton,
|
|
27
|
+
onEditModeChange: onEditModeChange,
|
|
28
|
+
onToggleRectangleTool: onToggleRectangleTool,
|
|
29
|
+
onTogglePenTool: onTogglePenTool,
|
|
30
|
+
onColorChange: onColorChange,
|
|
31
|
+
onNodeClick: onNodeClick,
|
|
32
|
+
onNodeDoubleClick: onNodeDoubleClick,
|
|
33
|
+
onSave: onSave,
|
|
34
|
+
onBreadcrumbClick: onBreadcrumbClick,
|
|
35
|
+
onNameChange: onNameChange,
|
|
36
|
+
initialNodes: initialNodes,
|
|
37
|
+
initialEdges: initialEdges,
|
|
38
|
+
onUpload: onUpload,
|
|
39
|
+
getFilenameFQDN: getFilenameFQDN,
|
|
40
|
+
maxFileSizeKB: maxFileSizeKB,
|
|
41
|
+
warehouseIds: warehouseIds
|
|
42
|
+
})
|
|
43
|
+
})
|
|
44
|
+
});
|
|
45
|
+
};
|
|
46
|
+
const WMSMapModalContainer = ({ open, onClose, viewMode = typings.ViewMode.EDIT, colorPalette, showBreadcrumbEditButton, onNodeClick, onNodeDoubleClick, onSave, onBreadcrumbClick, onNameChange, initialNodes, initialEdges, debugMode = false, title, onUpload, getFilenameFQDN, maxFileSizeKB, warehouseIds })=>{
|
|
47
|
+
const [editMode, setEditMode] = React.useState(typings.EditMode.BACKGROUND);
|
|
48
|
+
const [drawingMode, setDrawingMode] = React.useState(typings.DrawingMode.NONE);
|
|
49
|
+
const [selectedColor, setSelectedColor] = React.useState(()=>{
|
|
50
|
+
if (colorPalette && colorPalette.length > 0) {
|
|
51
|
+
return colorPalette[0];
|
|
52
|
+
}
|
|
53
|
+
return index.DEFAULT_RECTANGLE_COLOR;
|
|
54
|
+
});
|
|
55
|
+
// 設定 debug 模式
|
|
56
|
+
React.useEffect(()=>{
|
|
57
|
+
debugLogger.setDebugMode(debugMode);
|
|
58
|
+
}, [
|
|
59
|
+
debugMode
|
|
60
|
+
]);
|
|
61
|
+
// 當 colorPalette 變化時,確保選中的顏色仍然有效
|
|
62
|
+
React.useEffect(()=>{
|
|
63
|
+
if (colorPalette && colorPalette.length > 0) {
|
|
64
|
+
if (!colorPalette.includes(selectedColor)) {
|
|
65
|
+
setSelectedColor(colorPalette[0]);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}, [
|
|
69
|
+
colorPalette,
|
|
70
|
+
selectedColor
|
|
71
|
+
]);
|
|
72
|
+
const handleEditModeChange = React.useCallback((mode)=>{
|
|
73
|
+
setEditMode(mode);
|
|
74
|
+
setDrawingMode(typings.DrawingMode.NONE); // 切換編輯模式時重設繪圖模式
|
|
75
|
+
}, []);
|
|
76
|
+
const handleToggleRectangleTool = React.useCallback(()=>{
|
|
77
|
+
if (editMode !== typings.EditMode.LAYER) return;
|
|
78
|
+
setDrawingMode((prev)=>prev === typings.DrawingMode.RECTANGLE ? typings.DrawingMode.NONE : typings.DrawingMode.RECTANGLE);
|
|
79
|
+
}, [
|
|
80
|
+
editMode
|
|
81
|
+
]);
|
|
82
|
+
const handleTogglePenTool = React.useCallback(()=>{
|
|
83
|
+
if (editMode !== typings.EditMode.LAYER) return;
|
|
84
|
+
setDrawingMode((prev)=>prev === typings.DrawingMode.PEN ? typings.DrawingMode.NONE : typings.DrawingMode.PEN);
|
|
85
|
+
}, [
|
|
86
|
+
editMode
|
|
87
|
+
]);
|
|
88
|
+
const handleColorChange = React.useCallback((color)=>{
|
|
89
|
+
setSelectedColor(color);
|
|
90
|
+
}, []);
|
|
91
|
+
return /*#__PURE__*/ jsxRuntime.jsx(react.Modal, {
|
|
92
|
+
open: open,
|
|
93
|
+
onClose: onClose,
|
|
94
|
+
className: wmsMapModalContainer_module.modal,
|
|
95
|
+
modalType: "standard",
|
|
96
|
+
title: title ?? '編輯倉儲空間',
|
|
97
|
+
titleAlign: "left",
|
|
98
|
+
statusTypeIconLayout: "horizontal",
|
|
99
|
+
showStatusTypeIcon: false,
|
|
100
|
+
showDismissButton: true,
|
|
101
|
+
showModalFooter: false,
|
|
102
|
+
showModalHeader: true,
|
|
103
|
+
children: /*#__PURE__*/ jsxRuntime.jsx(WMSMapModalContent, {
|
|
104
|
+
editMode: editMode,
|
|
105
|
+
drawingMode: drawingMode,
|
|
106
|
+
selectedColor: selectedColor,
|
|
107
|
+
viewMode: viewMode,
|
|
108
|
+
colorPalette: colorPalette,
|
|
109
|
+
showBreadcrumbEditButton: showBreadcrumbEditButton,
|
|
110
|
+
onEditModeChange: handleEditModeChange,
|
|
111
|
+
onToggleRectangleTool: handleToggleRectangleTool,
|
|
112
|
+
onTogglePenTool: handleTogglePenTool,
|
|
113
|
+
onColorChange: handleColorChange,
|
|
114
|
+
onNodeClick: onNodeClick,
|
|
115
|
+
onNodeDoubleClick: onNodeDoubleClick,
|
|
116
|
+
onSave: onSave,
|
|
117
|
+
onBreadcrumbClick: onBreadcrumbClick,
|
|
118
|
+
onNameChange: onNameChange,
|
|
119
|
+
initialNodes: initialNodes,
|
|
120
|
+
initialEdges: initialEdges,
|
|
121
|
+
onUpload: onUpload,
|
|
122
|
+
getFilenameFQDN: getFilenameFQDN,
|
|
123
|
+
maxFileSizeKB: maxFileSizeKB,
|
|
124
|
+
warehouseIds: warehouseIds
|
|
125
|
+
})
|
|
126
|
+
});
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
exports.WMSMapModalContent = WMSMapModalContent;
|
|
130
|
+
exports.default = WMSMapModalContainer;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import React, { FC } from 'react';
|
|
2
|
+
import { WMSMapContentProps, WMSMapModalProps } from '../../types/index.cjs';
|
|
3
|
+
export declare const WMSMapModalContent: ({ editMode, drawingMode, selectedColor, viewMode, colorPalette, showBreadcrumbEditButton, onEditModeChange, onToggleRectangleTool, onTogglePenTool, onColorChange, onNodeClick, onNodeDoubleClick, onSave, onBreadcrumbClick, onNameChange, initialNodes, initialEdges, onUpload, getFilenameFQDN, maxFileSizeKB, warehouseIds, }: WMSMapContentProps) => React.JSX.Element;
|
|
4
|
+
declare const WMSMapModalContainer: FC<WMSMapModalProps>;
|
|
5
|
+
export default WMSMapModalContainer;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React, { FC } from 'react';
|
|
2
|
-
import { WMSMapContentProps, WMSMapModalProps } from '../../types';
|
|
2
|
+
import { WMSMapContentProps, WMSMapModalProps } from '../../types/index.js';
|
|
3
3
|
export declare const WMSMapModalContent: ({ editMode, drawingMode, selectedColor, viewMode, colorPalette, showBreadcrumbEditButton, onEditModeChange, onToggleRectangleTool, onTogglePenTool, onColorChange, onNodeClick, onNodeDoubleClick, onSave, onBreadcrumbClick, onNameChange, initialNodes, initialEdges, onUpload, getFilenameFQDN, maxFileSizeKB, warehouseIds, }: WMSMapContentProps) => React.JSX.Element;
|
|
4
4
|
declare const WMSMapModalContainer: FC<WMSMapModalProps>;
|
|
5
5
|
export default WMSMapModalContainer;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { FC, ReactNode } from 'react';
|
|
2
|
+
import { NodeProps } from '@xyflow/react';
|
|
3
|
+
import { EditMode } from '../../typings.cjs';
|
|
4
|
+
interface BaseNodeProps extends NodeProps {
|
|
5
|
+
editMode: EditMode;
|
|
6
|
+
label: string;
|
|
7
|
+
onCopyPaste: () => void;
|
|
8
|
+
children: ReactNode;
|
|
9
|
+
className?: string;
|
|
10
|
+
}
|
|
11
|
+
declare const BaseNode: FC<BaseNodeProps>;
|
|
12
|
+
export default BaseNode;
|
|
@@ -0,0 +1,236 @@
|
|
|
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 nodeOperations = require('../../utils/node-operations.cjs');
|
|
11
|
+
var contextMenu = require('../ui/context-menu.cjs');
|
|
12
|
+
var imageNode_module = require('./image-node.module.scss.cjs');
|
|
13
|
+
|
|
14
|
+
const ImageNode$1 = ({ data, selected, id, editMode, viewMode, showBackground = true })=>{
|
|
15
|
+
const { setNodes } = react.useReactFlow();
|
|
16
|
+
const updateNodeInternals = react.useUpdateNodeInternals();
|
|
17
|
+
const { imageUrl, width = index.DEFAULT_IMAGE_WIDTH, height = index.DEFAULT_IMAGE_HEIGHT, fileName, originalWidth = width, originalHeight = height } = data;
|
|
18
|
+
const [currentSize, setCurrentSize] = React.useState({
|
|
19
|
+
width,
|
|
20
|
+
height
|
|
21
|
+
});
|
|
22
|
+
const [isResizing, setIsResizing] = React.useState(false);
|
|
23
|
+
// Sync currentSize with node data when it changes
|
|
24
|
+
React.useEffect(()=>{
|
|
25
|
+
setCurrentSize({
|
|
26
|
+
width,
|
|
27
|
+
height
|
|
28
|
+
});
|
|
29
|
+
}, [
|
|
30
|
+
width,
|
|
31
|
+
height
|
|
32
|
+
]);
|
|
33
|
+
// Calculate aspect ratio
|
|
34
|
+
const aspectRatio = originalWidth / originalHeight;
|
|
35
|
+
// Check if this node should be editable based on edit mode and view mode
|
|
36
|
+
const isEditable = viewMode === typings.ViewMode.EDIT && editMode === typings.EditMode.BACKGROUND;
|
|
37
|
+
// Check if this node should be selectable (only in BACKGROUND mode or VIEW mode)
|
|
38
|
+
const isSelectable = editMode === typings.EditMode.BACKGROUND || viewMode === typings.ViewMode.VIEW;
|
|
39
|
+
const opacity = editMode === typings.EditMode.BACKGROUND ? index.ACTIVE_OPACITY : index.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: 'imageNode'
|
|
46
|
+
});
|
|
47
|
+
React.useCallback((updates)=>{
|
|
48
|
+
setNodes((nodes)=>nodes.map((node)=>node.id === id ? {
|
|
49
|
+
...node,
|
|
50
|
+
data: {
|
|
51
|
+
...node.data,
|
|
52
|
+
...updates
|
|
53
|
+
}
|
|
54
|
+
} : node));
|
|
55
|
+
updateNodeInternals(id);
|
|
56
|
+
}, [
|
|
57
|
+
id,
|
|
58
|
+
setNodes,
|
|
59
|
+
updateNodeInternals
|
|
60
|
+
]);
|
|
61
|
+
const handleResize = React.useCallback(// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
62
|
+
(_event, params)=>{
|
|
63
|
+
const newWidth = params.width;
|
|
64
|
+
const newHeight = newWidth / aspectRatio;
|
|
65
|
+
// 在 resize 過程中更新本地狀態和節點資料以提供正確的視覺回饋
|
|
66
|
+
const newSize = {
|
|
67
|
+
width: newWidth,
|
|
68
|
+
height: newHeight
|
|
69
|
+
};
|
|
70
|
+
setCurrentSize(newSize);
|
|
71
|
+
// 標記正在調整大小,避免在 WmsMapModal 中記錄歷史
|
|
72
|
+
if (!isResizing) {
|
|
73
|
+
setIsResizing(true);
|
|
74
|
+
}
|
|
75
|
+
// 即時更新節點以提供視覺回饋
|
|
76
|
+
setNodes((nodes)=>nodes.map((node)=>node.id === id ? {
|
|
77
|
+
...node,
|
|
78
|
+
data: {
|
|
79
|
+
...node.data,
|
|
80
|
+
width: newWidth,
|
|
81
|
+
height: newHeight,
|
|
82
|
+
isResizing: true
|
|
83
|
+
},
|
|
84
|
+
position: {
|
|
85
|
+
x: params.x ?? 0,
|
|
86
|
+
y: params.y ?? 0
|
|
87
|
+
}
|
|
88
|
+
} : node));
|
|
89
|
+
}, [
|
|
90
|
+
aspectRatio,
|
|
91
|
+
id,
|
|
92
|
+
setNodes,
|
|
93
|
+
isResizing
|
|
94
|
+
]);
|
|
95
|
+
const handleResizeStart = React.useCallback(// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
96
|
+
(_event, _params)=>{
|
|
97
|
+
// 開始調整大小時可以執行額外的邏輯,例如禁用拖拽
|
|
98
|
+
// 這裡保持空白,但提供了擴展點
|
|
99
|
+
}, []);
|
|
100
|
+
const handleResizeEnd = React.useCallback(// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
101
|
+
(_event, params)=>{
|
|
102
|
+
const newWidth = params.width;
|
|
103
|
+
const newHeight = newWidth / aspectRatio;
|
|
104
|
+
// 清除調整大小標記
|
|
105
|
+
setIsResizing(false);
|
|
106
|
+
// 最終更新節點資料,移除 isResizing 標記
|
|
107
|
+
// 這次更新會觸發歷史記錄(因為沒有 isResizing 標記)
|
|
108
|
+
setNodes((nodes)=>nodes.map((node)=>node.id === id ? {
|
|
109
|
+
...node,
|
|
110
|
+
data: {
|
|
111
|
+
...node.data,
|
|
112
|
+
width: newWidth,
|
|
113
|
+
height: newHeight,
|
|
114
|
+
isResizing: undefined
|
|
115
|
+
},
|
|
116
|
+
position: {
|
|
117
|
+
x: params.x ?? 0,
|
|
118
|
+
y: params.y ?? 0
|
|
119
|
+
}
|
|
120
|
+
} : node));
|
|
121
|
+
// 確保內部狀態同步
|
|
122
|
+
updateNodeInternals(id);
|
|
123
|
+
}, [
|
|
124
|
+
aspectRatio,
|
|
125
|
+
id,
|
|
126
|
+
setNodes,
|
|
127
|
+
updateNodeInternals
|
|
128
|
+
]);
|
|
129
|
+
// Handle copy and paste
|
|
130
|
+
const handleCopyPaste = React.useCallback(()=>{
|
|
131
|
+
const currentNode = getNodes().find((node)=>node.id === id);
|
|
132
|
+
if (!currentNode) {
|
|
133
|
+
console.error('Current node not found');
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
setNodesFromHook((nds)=>{
|
|
137
|
+
// Calculate next zIndex
|
|
138
|
+
const maxZIndex = Math.max(...nds.map((n)=>n.zIndex || 0), 0);
|
|
139
|
+
const copiedNode = nodeOperations.createImageCopy({
|
|
140
|
+
currentNode,
|
|
141
|
+
data: {
|
|
142
|
+
imageUrl,
|
|
143
|
+
width: currentSize.width,
|
|
144
|
+
height: currentSize.height,
|
|
145
|
+
fileName,
|
|
146
|
+
originalWidth,
|
|
147
|
+
originalHeight
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
const nodeWithZIndex = {
|
|
151
|
+
...copiedNode,
|
|
152
|
+
zIndex: maxZIndex + 1
|
|
153
|
+
};
|
|
154
|
+
return [
|
|
155
|
+
...nds,
|
|
156
|
+
nodeWithZIndex
|
|
157
|
+
];
|
|
158
|
+
});
|
|
159
|
+
handleCloseContextMenu();
|
|
160
|
+
}, [
|
|
161
|
+
id,
|
|
162
|
+
imageUrl,
|
|
163
|
+
currentSize,
|
|
164
|
+
fileName,
|
|
165
|
+
originalWidth,
|
|
166
|
+
originalHeight,
|
|
167
|
+
getNodes,
|
|
168
|
+
setNodesFromHook,
|
|
169
|
+
handleCloseContextMenu
|
|
170
|
+
]);
|
|
171
|
+
// 計算節點的顯示狀態 - 在檢視模式下受 showBackground 控制
|
|
172
|
+
const isVisible = viewMode === typings.ViewMode.EDIT || showBackground;
|
|
173
|
+
// console.log('🖼️ ImageNode 顯示計算:', {
|
|
174
|
+
// id: id.slice(-4),
|
|
175
|
+
// viewMode,
|
|
176
|
+
// showBackground,
|
|
177
|
+
// isVisible
|
|
178
|
+
// });
|
|
179
|
+
return /*#__PURE__*/ jsxRuntime.jsxs("div", {
|
|
180
|
+
className: `${imageNode_module.imageNode} ${selected ? imageNode_module.selected : ''} ${!isSelectable ? imageNode_module.nonSelectable : ''}`,
|
|
181
|
+
style: {
|
|
182
|
+
opacity: isVisible ? opacity : 0,
|
|
183
|
+
pointerEvents: isVisible ? 'auto' : 'none',
|
|
184
|
+
transition: 'opacity 0.3s ease'
|
|
185
|
+
},
|
|
186
|
+
children: [
|
|
187
|
+
selected && isEditable && /*#__PURE__*/ jsxRuntime.jsx(react.NodeResizer, {
|
|
188
|
+
minWidth: 50,
|
|
189
|
+
minHeight: 50 / aspectRatio,
|
|
190
|
+
keepAspectRatio: true,
|
|
191
|
+
onResizeStart: handleResizeStart,
|
|
192
|
+
onResize: handleResize,
|
|
193
|
+
onResizeEnd: handleResizeEnd,
|
|
194
|
+
isVisible: selected && isEditable,
|
|
195
|
+
color: "#5570d3",
|
|
196
|
+
handleClassName: imageNode_module.customResizeHandle
|
|
197
|
+
}),
|
|
198
|
+
/*#__PURE__*/ jsxRuntime.jsxs("div", {
|
|
199
|
+
className: imageNode_module.imageContainer,
|
|
200
|
+
onContextMenu: viewMode === typings.ViewMode.EDIT ? handleContextMenu : undefined,
|
|
201
|
+
children: [
|
|
202
|
+
/*#__PURE__*/ jsxRuntime.jsx("img", {
|
|
203
|
+
src: imageUrl,
|
|
204
|
+
alt: fileName || 'Uploaded image',
|
|
205
|
+
className: imageNode_module.image,
|
|
206
|
+
style: {
|
|
207
|
+
width: `${currentSize.width}px`,
|
|
208
|
+
height: `${currentSize.height}px`,
|
|
209
|
+
maxWidth: '100%',
|
|
210
|
+
maxHeight: '100%',
|
|
211
|
+
opacity: opacity
|
|
212
|
+
},
|
|
213
|
+
draggable: false
|
|
214
|
+
}),
|
|
215
|
+
fileName && /*#__PURE__*/ jsxRuntime.jsx("div", {
|
|
216
|
+
className: imageNode_module.imageLabel,
|
|
217
|
+
children: fileName
|
|
218
|
+
})
|
|
219
|
+
]
|
|
220
|
+
}),
|
|
221
|
+
viewMode === typings.ViewMode.EDIT && /*#__PURE__*/ jsxRuntime.jsx(contextMenu, {
|
|
222
|
+
visible: contextMenu$1.visible,
|
|
223
|
+
x: contextMenu$1.x,
|
|
224
|
+
y: contextMenu$1.y,
|
|
225
|
+
onClose: handleCloseContextMenu,
|
|
226
|
+
onCopyPaste: handleCopyPaste,
|
|
227
|
+
onDelete: handleDelete,
|
|
228
|
+
arrangeActions: arrangeActions,
|
|
229
|
+
arrangeStates: arrangeStates
|
|
230
|
+
})
|
|
231
|
+
]
|
|
232
|
+
});
|
|
233
|
+
};
|
|
234
|
+
var ImageNode = /*#__PURE__*/ React.memo(ImageNode$1);
|
|
235
|
+
|
|
236
|
+
module.exports = ImageNode;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { NodeProps } from '@xyflow/react';
|
|
3
|
+
import { EditMode, ViewMode } from '../../typings.cjs';
|
|
4
|
+
interface ImageNodeProps extends NodeProps {
|
|
5
|
+
editMode: EditMode;
|
|
6
|
+
viewMode: ViewMode;
|
|
7
|
+
onResizeComplete?: (id: string, oldSize: {
|
|
8
|
+
width: number;
|
|
9
|
+
height: number;
|
|
10
|
+
}, newSize: {
|
|
11
|
+
width: number;
|
|
12
|
+
height: number;
|
|
13
|
+
}) => void;
|
|
14
|
+
showBackground?: boolean;
|
|
15
|
+
}
|
|
16
|
+
declare const _default: React.NamedExoticComponent<ImageNodeProps>;
|
|
17
|
+
export default _default;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React 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 ImageNodeProps extends NodeProps {
|
|
5
5
|
editMode: EditMode;
|
|
6
6
|
viewMode: ViewMode;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var styles = {"imageNode":"image-node-module_imageNode__RA0Qo","selected":"image-node-module_selected__XB4vQ","image":"image-node-module_image__GnlBw","nonSelectable":"image-node-module_nonSelectable__GF-N6","imageContainer":"image-node-module_imageContainer__Bs4MJ","imageLabel":"image-node-module_imageLabel__BwBbB","customResizeHandle":"image-node-module_customResizeHandle__wBp7h"};
|
|
4
|
+
|
|
5
|
+
module.exports = styles;
|