@rytass/wms-map-react-components 0.1.10 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/components/breadcrumb/breadcrumb-edit-modal.cjs +92 -0
- package/components/breadcrumb/breadcrumb-edit-modal.d.cts +9 -0
- package/components/breadcrumb/breadcrumb-edit-modal.module.scss.cjs +5 -0
- package/components/breadcrumb/breadcrumb.cjs +171 -0
- package/components/breadcrumb/breadcrumb.d.cts +11 -0
- package/components/breadcrumb/breadcrumb.d.ts +1 -1
- package/components/breadcrumb/breadcrumb.module.scss.cjs +5 -0
- package/components/canvas/react-flow-canvas.cjs +321 -0
- package/components/canvas/react-flow-canvas.d.cts +38 -0
- package/components/canvas/react-flow-canvas.d.ts +1 -1
- package/components/canvas/react-flow-canvas.module.scss.cjs +5 -0
- package/components/modal/wms-map-content.cjs +808 -0
- package/components/modal/wms-map-content.d.cts +4 -0
- package/components/modal/wms-map-content.d.ts +1 -1
- package/components/modal/wms-map-modal-container.cjs +130 -0
- package/components/modal/wms-map-modal-container.d.cts +5 -0
- package/components/modal/wms-map-modal-container.d.ts +1 -1
- package/components/modal/wms-map-modal-container.module.scss.cjs +5 -0
- package/components/nodes/base-node.d.cts +12 -0
- package/components/nodes/base-node.d.ts +1 -1
- package/components/nodes/image-node.cjs +236 -0
- package/components/nodes/image-node.d.cts +17 -0
- package/components/nodes/image-node.d.ts +1 -1
- package/components/nodes/image-node.module.scss.cjs +5 -0
- package/components/nodes/path-node.cjs +553 -0
- package/components/nodes/path-node.d.cts +19 -0
- package/components/nodes/path-node.d.ts +1 -1
- package/components/nodes/path-node.module.scss.cjs +5 -0
- package/components/nodes/rectangle-node.cjs +239 -0
- package/components/nodes/rectangle-node.d.cts +11 -0
- package/components/nodes/rectangle-node.d.ts +1 -1
- package/components/nodes/rectangle-node.module.scss.cjs +5 -0
- package/components/ui/context-menu.cjs +171 -0
- package/components/ui/context-menu.d.cts +25 -0
- package/components/ui/context-menu.module.scss.cjs +5 -0
- package/components/ui/toolbar.cjs +286 -0
- package/components/ui/toolbar.d.cts +23 -0
- package/components/ui/toolbar.d.ts +1 -1
- package/components/ui/toolbar.module.scss.cjs +5 -0
- package/components/ui/view-mode-toolbar.cjs +44 -0
- package/components/ui/view-mode-toolbar.d.cts +9 -0
- package/components/ui/view-mode-toolbar.d.ts +1 -1
- package/components/ui/view-mode-toolbar.module.scss.cjs +5 -0
- package/constants/index.cjs +54 -0
- package/constants/index.d.cts +45 -0
- package/constants/index.d.ts +2 -2
- package/constants/text-mappings.cjs +46 -0
- package/constants/text-mappings.d.cts +181 -0
- package/hooks/use-context-menu.cjs +231 -0
- package/hooks/use-context-menu.d.cts +37 -0
- package/hooks/use-context-menu.d.ts +1 -1
- package/hooks/use-direct-state-history.cjs +217 -0
- package/hooks/use-direct-state-history.d.cts +58 -0
- package/hooks/use-direct-state-history.d.ts +2 -2
- package/hooks/use-pen-drawing.cjs +366 -0
- package/hooks/use-pen-drawing.d.cts +30 -0
- package/hooks/use-pen-drawing.d.ts +1 -1
- package/hooks/use-rectangle-drawing.cjs +139 -0
- package/hooks/use-rectangle-drawing.d.cts +19 -0
- package/hooks/use-rectangle-drawing.d.ts +1 -1
- package/hooks/use-text-editing.cjs +156 -0
- package/hooks/use-text-editing.d.cts +19 -0
- package/icons/index.cjs +233 -0
- package/icons/index.d.cts +16 -0
- package/index.cjs +26 -0
- package/index.d.cts +5 -0
- package/index.d.ts +5 -5
- package/package.json +68 -3
- package/types/callback.types.d.cts +7 -0
- package/types/callback.types.d.ts +1 -1
- package/types/canvas.types.d.cts +35 -0
- package/types/canvas.types.d.ts +1 -1
- package/types/component-props.types.d.cts +45 -0
- package/types/component-props.types.d.ts +2 -2
- package/types/history.types.d.cts +24 -0
- package/types/history.types.d.ts +2 -2
- package/types/index.d.cts +5 -0
- package/types/index.d.ts +5 -5
- package/types/react-flow.types.d.cts +30 -0
- package/typings.cjs +44 -0
- package/typings.d.cts +136 -0
- package/utils/api-data-transform.cjs +221 -0
- package/utils/api-data-transform.d.cts +33 -0
- package/utils/api-data-transform.d.ts +1 -1
- package/utils/color-utils.cjs +58 -0
- package/utils/color-utils.d.cts +17 -0
- package/utils/debug-logger.cjs +45 -0
- package/utils/debug-logger.d.cts +33 -0
- package/utils/map-data-transform.cjs +360 -0
- package/utils/map-data-transform.d.cts +18 -0
- package/utils/map-data-transform.d.ts +1 -1
- package/utils/node-operations.cjs +88 -0
- package/utils/node-operations.d.cts +26 -0
- package/utils/node-utils.cjs +40 -0
- package/utils/node-utils.d.cts +10 -0
- package/index.cjs.css +0 -1
- package/index.cjs.js +0 -5128
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
5
|
+
var React = require('react');
|
|
6
|
+
var react = require('@mezzanine-ui/react');
|
|
7
|
+
var breadcrumbEditModal_module = require('./breadcrumb-edit-modal.module.scss.cjs');
|
|
8
|
+
var reactHookForm = require('react-hook-form');
|
|
9
|
+
|
|
10
|
+
const BreadcrumbEditModal = ({ open, warehouseId, onClose, onConfirm })=>{
|
|
11
|
+
const [editingValue, setEditingValue] = React.useState(warehouseId);
|
|
12
|
+
const methods = reactHookForm.useForm({
|
|
13
|
+
mode: 'onChange',
|
|
14
|
+
defaultValues: {
|
|
15
|
+
editingValue: warehouseId
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
// 當 modal 開啟時更新編輯值
|
|
19
|
+
React.useEffect(()=>{
|
|
20
|
+
if (open) {
|
|
21
|
+
setEditingValue(warehouseId);
|
|
22
|
+
methods.reset({
|
|
23
|
+
editingValue: warehouseId
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
}, [
|
|
27
|
+
open,
|
|
28
|
+
warehouseId,
|
|
29
|
+
methods
|
|
30
|
+
]);
|
|
31
|
+
const handleConfirm = ()=>{
|
|
32
|
+
const formData = methods.getValues();
|
|
33
|
+
const newValue = formData.editingValue?.trim() || editingValue?.trim();
|
|
34
|
+
onConfirm(newValue);
|
|
35
|
+
onClose();
|
|
36
|
+
};
|
|
37
|
+
const handleCancel = ()=>{
|
|
38
|
+
setEditingValue(warehouseId); // 重置為原始值
|
|
39
|
+
onClose();
|
|
40
|
+
};
|
|
41
|
+
return /*#__PURE__*/ jsxRuntime.jsx(react.Modal, {
|
|
42
|
+
open: open,
|
|
43
|
+
onClose: handleCancel,
|
|
44
|
+
modalType: "standard",
|
|
45
|
+
title: "修改當前區域名稱",
|
|
46
|
+
titleAlign: "left",
|
|
47
|
+
statusTypeIconLayout: "horizontal",
|
|
48
|
+
cancelText: "取消",
|
|
49
|
+
confirmText: "確認",
|
|
50
|
+
onCancel: handleCancel,
|
|
51
|
+
onConfirm: handleConfirm,
|
|
52
|
+
cancelButtonProps: {
|
|
53
|
+
type: 'button',
|
|
54
|
+
size: 'main',
|
|
55
|
+
variant: 'base-secondary'
|
|
56
|
+
},
|
|
57
|
+
confirmButtonProps: {
|
|
58
|
+
type: 'button',
|
|
59
|
+
size: 'main',
|
|
60
|
+
variant: 'base-primary'
|
|
61
|
+
},
|
|
62
|
+
showStatusTypeIcon: false,
|
|
63
|
+
showDismissButton: true,
|
|
64
|
+
showModalFooter: true,
|
|
65
|
+
showModalHeader: true,
|
|
66
|
+
children: /*#__PURE__*/ jsxRuntime.jsxs("div", {
|
|
67
|
+
className: breadcrumbEditModal_module.modalContent,
|
|
68
|
+
children: [
|
|
69
|
+
/*#__PURE__*/ jsxRuntime.jsx("label", {
|
|
70
|
+
className: breadcrumbEditModal_module.fieldLabel,
|
|
71
|
+
children: "名稱"
|
|
72
|
+
}),
|
|
73
|
+
/*#__PURE__*/ jsxRuntime.jsx("input", {
|
|
74
|
+
...methods.register('editingValue', {
|
|
75
|
+
required: true
|
|
76
|
+
}),
|
|
77
|
+
type: "text",
|
|
78
|
+
placeholder: "請輸入區域名稱",
|
|
79
|
+
style: {
|
|
80
|
+
width: '100%',
|
|
81
|
+
padding: '8px',
|
|
82
|
+
border: '1px solid #ccc',
|
|
83
|
+
borderRadius: '4px',
|
|
84
|
+
fontSize: '14px'
|
|
85
|
+
}
|
|
86
|
+
})
|
|
87
|
+
]
|
|
88
|
+
})
|
|
89
|
+
});
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
module.exports = BreadcrumbEditModal;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { FC } from 'react';
|
|
2
|
+
interface BreadcrumbEditModalProps {
|
|
3
|
+
open: boolean;
|
|
4
|
+
warehouseId: string;
|
|
5
|
+
onClose: () => void;
|
|
6
|
+
onConfirm: (newName: string) => void;
|
|
7
|
+
}
|
|
8
|
+
declare const BreadcrumbEditModal: FC<BreadcrumbEditModalProps>;
|
|
9
|
+
export default BreadcrumbEditModal;
|
|
@@ -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 breadcrumbEditModal = require('./breadcrumb-edit-modal.cjs');
|
|
7
|
+
var typings = require('../../typings.cjs');
|
|
8
|
+
var breadcrumb_module = require('./breadcrumb.module.scss.cjs');
|
|
9
|
+
|
|
10
|
+
const Breadcrumb = ({ warehouseIds, viewMode, showBreadcrumbEditButton = ()=>true, onWarehouseClick, onNameChange })=>{
|
|
11
|
+
const [showDropdown, setShowDropdown] = React.useState(false);
|
|
12
|
+
const [showEditModal, setShowEditModal] = React.useState(false);
|
|
13
|
+
const [editingIndex, setEditingIndex] = React.useState(-1);
|
|
14
|
+
const dropdownRef = React.useRef(null);
|
|
15
|
+
// 當超過3個項目時,需要收合顯示
|
|
16
|
+
const shouldCollapse = warehouseIds.length > 3;
|
|
17
|
+
// 點擊外部關閉 dropdown
|
|
18
|
+
React.useEffect(()=>{
|
|
19
|
+
const handleClickOutside = (event)=>{
|
|
20
|
+
if (dropdownRef.current && !dropdownRef.current.contains(event.target)) {
|
|
21
|
+
setShowDropdown(false);
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
if (showDropdown) {
|
|
25
|
+
document.addEventListener('mousedown', handleClickOutside);
|
|
26
|
+
}
|
|
27
|
+
return ()=>{
|
|
28
|
+
document.removeEventListener('mousedown', handleClickOutside);
|
|
29
|
+
};
|
|
30
|
+
}, [
|
|
31
|
+
showDropdown
|
|
32
|
+
]);
|
|
33
|
+
const handleEditClick = ()=>{
|
|
34
|
+
// 預設編輯最後一個項目
|
|
35
|
+
const lastIndex = warehouseIds.length - 1;
|
|
36
|
+
setEditingIndex(lastIndex);
|
|
37
|
+
setShowEditModal(true);
|
|
38
|
+
};
|
|
39
|
+
const handleEditConfirm = async (newName)=>{
|
|
40
|
+
if (onNameChange) {
|
|
41
|
+
await onNameChange(newName);
|
|
42
|
+
}
|
|
43
|
+
setShowEditModal(false);
|
|
44
|
+
setEditingIndex(-1);
|
|
45
|
+
};
|
|
46
|
+
const handleEditCancel = ()=>{
|
|
47
|
+
setShowEditModal(false);
|
|
48
|
+
setEditingIndex(-1);
|
|
49
|
+
};
|
|
50
|
+
const renderCollapsedBreadcrumb = ()=>{
|
|
51
|
+
const first = warehouseIds[0];
|
|
52
|
+
const secondLast = warehouseIds[warehouseIds.length - 2];
|
|
53
|
+
const last = warehouseIds[warehouseIds.length - 1];
|
|
54
|
+
const hiddenItems = warehouseIds.slice(1, warehouseIds.length - 2);
|
|
55
|
+
const handleItemClick = (warehouseId, index)=>{
|
|
56
|
+
onWarehouseClick?.(warehouseId, index);
|
|
57
|
+
};
|
|
58
|
+
return /*#__PURE__*/ jsxRuntime.jsxs(jsxRuntime.Fragment, {
|
|
59
|
+
children: [
|
|
60
|
+
/*#__PURE__*/ jsxRuntime.jsx("span", {
|
|
61
|
+
className: `${breadcrumb_module.warehouseIdText} ${breadcrumb_module.clickable}`,
|
|
62
|
+
onClick: ()=>handleItemClick(first, 0),
|
|
63
|
+
children: first
|
|
64
|
+
}),
|
|
65
|
+
/*#__PURE__*/ jsxRuntime.jsx("span", {
|
|
66
|
+
className: breadcrumb_module.separator,
|
|
67
|
+
children: "/"
|
|
68
|
+
}),
|
|
69
|
+
/*#__PURE__*/ jsxRuntime.jsxs("div", {
|
|
70
|
+
className: breadcrumb_module.ellipsisContainer,
|
|
71
|
+
ref: dropdownRef,
|
|
72
|
+
children: [
|
|
73
|
+
/*#__PURE__*/ jsxRuntime.jsx("span", {
|
|
74
|
+
className: breadcrumb_module.ellipsis,
|
|
75
|
+
onClick: ()=>setShowDropdown(!showDropdown),
|
|
76
|
+
children: "..."
|
|
77
|
+
}),
|
|
78
|
+
showDropdown && hiddenItems.length > 0 && /*#__PURE__*/ jsxRuntime.jsx("div", {
|
|
79
|
+
className: breadcrumb_module.dropdown,
|
|
80
|
+
children: hiddenItems.map((id, index)=>/*#__PURE__*/ jsxRuntime.jsx("div", {
|
|
81
|
+
className: breadcrumb_module.dropdownItem,
|
|
82
|
+
onClick: (e)=>{
|
|
83
|
+
e.preventDefault();
|
|
84
|
+
e.stopPropagation();
|
|
85
|
+
handleItemClick(id, index + 1);
|
|
86
|
+
setShowDropdown(false); // 點擊後隱藏 dropdown
|
|
87
|
+
},
|
|
88
|
+
children: id
|
|
89
|
+
}, index))
|
|
90
|
+
})
|
|
91
|
+
]
|
|
92
|
+
}),
|
|
93
|
+
/*#__PURE__*/ jsxRuntime.jsx("span", {
|
|
94
|
+
className: breadcrumb_module.separator,
|
|
95
|
+
children: "/"
|
|
96
|
+
}),
|
|
97
|
+
/*#__PURE__*/ jsxRuntime.jsx("span", {
|
|
98
|
+
className: `${breadcrumb_module.warehouseIdText} ${breadcrumb_module.clickable}`,
|
|
99
|
+
onClick: ()=>handleItemClick(secondLast, warehouseIds.length - 2),
|
|
100
|
+
children: secondLast
|
|
101
|
+
}),
|
|
102
|
+
/*#__PURE__*/ jsxRuntime.jsx("span", {
|
|
103
|
+
className: breadcrumb_module.separator,
|
|
104
|
+
children: "/"
|
|
105
|
+
}),
|
|
106
|
+
/*#__PURE__*/ jsxRuntime.jsx("span", {
|
|
107
|
+
className: `${breadcrumb_module.warehouseIdText} ${breadcrumb_module.lastItem} ${breadcrumb_module.clickable}`,
|
|
108
|
+
onClick: ()=>handleItemClick(last, warehouseIds.length - 1),
|
|
109
|
+
children: last
|
|
110
|
+
})
|
|
111
|
+
]
|
|
112
|
+
});
|
|
113
|
+
};
|
|
114
|
+
const renderFullBreadcrumb = ()=>{
|
|
115
|
+
const handleItemClick = (warehouseId, index)=>{
|
|
116
|
+
onWarehouseClick?.(warehouseId, index);
|
|
117
|
+
};
|
|
118
|
+
return warehouseIds.map((id, index)=>/*#__PURE__*/ jsxRuntime.jsxs(React.Fragment, {
|
|
119
|
+
children: [
|
|
120
|
+
/*#__PURE__*/ jsxRuntime.jsx("span", {
|
|
121
|
+
className: `${breadcrumb_module.warehouseIdText} ${breadcrumb_module.clickable} ${index === warehouseIds.length - 1 ? breadcrumb_module.lastItem : ''}`,
|
|
122
|
+
onClick: ()=>handleItemClick(id, index),
|
|
123
|
+
children: id
|
|
124
|
+
}),
|
|
125
|
+
index < warehouseIds.length - 1 && /*#__PURE__*/ jsxRuntime.jsx("span", {
|
|
126
|
+
className: breadcrumb_module.separator,
|
|
127
|
+
children: "/"
|
|
128
|
+
})
|
|
129
|
+
]
|
|
130
|
+
}, index));
|
|
131
|
+
};
|
|
132
|
+
return /*#__PURE__*/ jsxRuntime.jsxs(jsxRuntime.Fragment, {
|
|
133
|
+
children: [
|
|
134
|
+
/*#__PURE__*/ jsxRuntime.jsx("div", {
|
|
135
|
+
className: breadcrumb_module.breadcrumbSection,
|
|
136
|
+
children: /*#__PURE__*/ jsxRuntime.jsxs("div", {
|
|
137
|
+
className: breadcrumb_module.warehouseIdSection,
|
|
138
|
+
children: [
|
|
139
|
+
shouldCollapse ? renderCollapsedBreadcrumb() : renderFullBreadcrumb(),
|
|
140
|
+
viewMode === typings.ViewMode.EDIT && showBreadcrumbEditButton(warehouseIds) && /*#__PURE__*/ jsxRuntime.jsx("button", {
|
|
141
|
+
className: breadcrumb_module.editButton,
|
|
142
|
+
onClick: handleEditClick,
|
|
143
|
+
title: "編輯當前區域名稱",
|
|
144
|
+
children: /*#__PURE__*/ jsxRuntime.jsx("svg", {
|
|
145
|
+
width: "16",
|
|
146
|
+
height: "16",
|
|
147
|
+
viewBox: "0 0 16 16",
|
|
148
|
+
fill: "none",
|
|
149
|
+
children: /*#__PURE__*/ jsxRuntime.jsx("path", {
|
|
150
|
+
d: "M11.7803 2.21967C12.0732 1.92678 12.5481 1.92678 12.841 2.21967L13.7803 3.15901C14.0732 3.45191 14.0732 3.92678 13.7803 4.21967L5.11364 12.8863L2.66697 13.3333L3.11364 10.8863L11.7803 2.21967Z",
|
|
151
|
+
stroke: "currentColor",
|
|
152
|
+
strokeWidth: "1.33",
|
|
153
|
+
strokeLinecap: "round",
|
|
154
|
+
strokeLinejoin: "round"
|
|
155
|
+
})
|
|
156
|
+
})
|
|
157
|
+
})
|
|
158
|
+
]
|
|
159
|
+
})
|
|
160
|
+
}),
|
|
161
|
+
/*#__PURE__*/ jsxRuntime.jsx(breadcrumbEditModal, {
|
|
162
|
+
open: showEditModal,
|
|
163
|
+
warehouseId: editingIndex >= 0 ? warehouseIds[editingIndex] : '',
|
|
164
|
+
onClose: handleEditCancel,
|
|
165
|
+
onConfirm: handleEditConfirm
|
|
166
|
+
})
|
|
167
|
+
]
|
|
168
|
+
});
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
module.exports = Breadcrumb;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { FC } from 'react';
|
|
2
|
+
import { ViewMode } from '../../typings.cjs';
|
|
3
|
+
interface BreadcrumbProps {
|
|
4
|
+
warehouseIds: string[];
|
|
5
|
+
viewMode: ViewMode;
|
|
6
|
+
showBreadcrumbEditButton?: (warehouseIds: string[]) => boolean;
|
|
7
|
+
onWarehouseClick?: (warehouseId: string, index: number) => void;
|
|
8
|
+
onNameChange?: (name: string) => Promise<void>;
|
|
9
|
+
}
|
|
10
|
+
declare const Breadcrumb: FC<BreadcrumbProps>;
|
|
11
|
+
export default Breadcrumb;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var styles = {"breadcrumbSection":"breadcrumb-module_breadcrumbSection__Qn8A3","warehouseIdSection":"breadcrumb-module_warehouseIdSection__7CzsY","separator":"breadcrumb-module_separator__uLhtn","warehouseIdText":"breadcrumb-module_warehouseIdText__QOxRw","lastItem":"breadcrumb-module_lastItem__OGKzD","clickable":"breadcrumb-module_clickable__YD5aj","ellipsisContainer":"breadcrumb-module_ellipsisContainer__4hIiu","ellipsis":"breadcrumb-module_ellipsis__NYd8X","dropdown":"breadcrumb-module_dropdown__BqvP8","dropdownItem":"breadcrumb-module_dropdownItem__YdggW","editButton":"breadcrumb-module_editButton__Wuk8T"};
|
|
4
|
+
|
|
5
|
+
module.exports = styles;
|
|
@@ -0,0 +1,321 @@
|
|
|
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 imageNode = require('../nodes/image-node.cjs');
|
|
9
|
+
var rectangleNode = require('../nodes/rectangle-node.cjs');
|
|
10
|
+
var pathNode = require('../nodes/path-node.cjs');
|
|
11
|
+
var useRectangleDrawing = require('../../hooks/use-rectangle-drawing.cjs');
|
|
12
|
+
var usePenDrawing = require('../../hooks/use-pen-drawing.cjs');
|
|
13
|
+
var reactFlowCanvas_module = require('./react-flow-canvas.module.scss.cjs');
|
|
14
|
+
var index = require('../../icons/index.cjs');
|
|
15
|
+
|
|
16
|
+
const CustomControls = ()=>{
|
|
17
|
+
const { zoomIn, zoomOut, fitView, getZoom } = react.useReactFlow();
|
|
18
|
+
const [zoom, setZoom] = React.useState(()=>Math.round(getZoom() * 100));
|
|
19
|
+
// Listen for viewport changes (including mouse wheel zoom)
|
|
20
|
+
react.useOnViewportChange({
|
|
21
|
+
onChange: (viewport)=>{
|
|
22
|
+
setZoom(Math.round(viewport.zoom * 100));
|
|
23
|
+
console.log('🔍 Zoom changed:', viewport.zoom);
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
const handleZoomIn = ()=>{
|
|
27
|
+
zoomIn();
|
|
28
|
+
// No need to manually update zoom state, useOnViewportChange will handle it
|
|
29
|
+
};
|
|
30
|
+
const handleZoomOut = ()=>{
|
|
31
|
+
zoomOut();
|
|
32
|
+
// No need to manually update zoom state, useOnViewportChange will handle it
|
|
33
|
+
};
|
|
34
|
+
const handleFitView = ()=>{
|
|
35
|
+
fitView();
|
|
36
|
+
// No need to manually update zoom state, useOnViewportChange will handle it
|
|
37
|
+
};
|
|
38
|
+
return /*#__PURE__*/ jsxRuntime.jsx(jsxRuntime.Fragment, {
|
|
39
|
+
children: /*#__PURE__*/ jsxRuntime.jsxs("div", {
|
|
40
|
+
className: reactFlowCanvas_module.zoomControls,
|
|
41
|
+
children: [
|
|
42
|
+
/*#__PURE__*/ jsxRuntime.jsx("button", {
|
|
43
|
+
className: reactFlowCanvas_module.controlButton,
|
|
44
|
+
onClick: handleZoomOut,
|
|
45
|
+
children: "−"
|
|
46
|
+
}),
|
|
47
|
+
/*#__PURE__*/ jsxRuntime.jsxs("span", {
|
|
48
|
+
className: reactFlowCanvas_module.zoomPercentage,
|
|
49
|
+
children: [
|
|
50
|
+
zoom,
|
|
51
|
+
"%"
|
|
52
|
+
]
|
|
53
|
+
}),
|
|
54
|
+
/*#__PURE__*/ jsxRuntime.jsx("button", {
|
|
55
|
+
className: reactFlowCanvas_module.controlButton,
|
|
56
|
+
onClick: handleZoomIn,
|
|
57
|
+
children: "+"
|
|
58
|
+
}),
|
|
59
|
+
/*#__PURE__*/ jsxRuntime.jsx("button", {
|
|
60
|
+
className: reactFlowCanvas_module.controlButton,
|
|
61
|
+
onClick: handleFitView,
|
|
62
|
+
children: "⛶"
|
|
63
|
+
})
|
|
64
|
+
]
|
|
65
|
+
})
|
|
66
|
+
});
|
|
67
|
+
};
|
|
68
|
+
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, onNodeDoubleClick, showBackground = true })=>{
|
|
69
|
+
// console.log('🖼️ ReactFlowCanvas 接收到 showBackground:', showBackground);
|
|
70
|
+
const { containerRef: rectContainerRef, previewRect } = useRectangleDrawing.useRectangleDrawing({
|
|
71
|
+
editMode,
|
|
72
|
+
drawingMode,
|
|
73
|
+
onCreateRectangle
|
|
74
|
+
});
|
|
75
|
+
const { containerRef: penContainerRef, isDrawing: isDrawingPen, previewPath, currentPoints, firstPoint, canClose, forceComplete } = usePenDrawing.usePenDrawing({
|
|
76
|
+
editMode,
|
|
77
|
+
drawingMode,
|
|
78
|
+
onCreatePath
|
|
79
|
+
});
|
|
80
|
+
const nodeTypes = React.useMemo(()=>({
|
|
81
|
+
imageNode: (props)=>/*#__PURE__*/ jsxRuntime.jsx(imageNode, {
|
|
82
|
+
...props,
|
|
83
|
+
editMode: editMode,
|
|
84
|
+
viewMode: viewMode,
|
|
85
|
+
showBackground: showBackground
|
|
86
|
+
}),
|
|
87
|
+
rectangleNode: (props)=>/*#__PURE__*/ jsxRuntime.jsx(rectangleNode, {
|
|
88
|
+
...props,
|
|
89
|
+
editMode: editMode,
|
|
90
|
+
viewMode: viewMode,
|
|
91
|
+
onTextEditComplete: onTextEditComplete,
|
|
92
|
+
isHovered: hoveredNodeId === props.id
|
|
93
|
+
}),
|
|
94
|
+
pathNode: (props)=>/*#__PURE__*/ jsxRuntime.jsx(pathNode, {
|
|
95
|
+
...props,
|
|
96
|
+
editMode: editMode,
|
|
97
|
+
viewMode: viewMode,
|
|
98
|
+
onTextEditComplete: onTextEditComplete,
|
|
99
|
+
onPathPointsChange: onPathPointsChange,
|
|
100
|
+
onPathPointDragStateChange: onPathPointDragStateChange ? (_id, isDragging)=>onPathPointDragStateChange(isDragging) : undefined,
|
|
101
|
+
isHovered: hoveredNodeId === props.id
|
|
102
|
+
})
|
|
103
|
+
}), [
|
|
104
|
+
editMode,
|
|
105
|
+
viewMode,
|
|
106
|
+
onTextEditComplete,
|
|
107
|
+
onPathPointsChange,
|
|
108
|
+
onPathPointDragStateChange,
|
|
109
|
+
hoveredNodeId,
|
|
110
|
+
showBackground
|
|
111
|
+
]);
|
|
112
|
+
// Use a callback ref to assign both drawing hooks to the same container
|
|
113
|
+
const containerRef = React.useCallback((node)=>{
|
|
114
|
+
if (node) {
|
|
115
|
+
rectContainerRef.current = node;
|
|
116
|
+
penContainerRef.current = node;
|
|
117
|
+
}
|
|
118
|
+
}, [
|
|
119
|
+
rectContainerRef,
|
|
120
|
+
penContainerRef
|
|
121
|
+
]);
|
|
122
|
+
const getCursor = ()=>{
|
|
123
|
+
return 'default';
|
|
124
|
+
};
|
|
125
|
+
// Handle pane click for auto-completing pen drawing
|
|
126
|
+
const handlePaneClick = React.useCallback((event)=>{
|
|
127
|
+
// Check if any modifier keys are pressed - if so, don't auto-complete
|
|
128
|
+
// This prevents accidental completion when using Shift for line constraints
|
|
129
|
+
const hasModifierKeys = event && (event.shiftKey || event.ctrlKey || event.altKey || event.metaKey);
|
|
130
|
+
console.log('📋 ReactFlow pane clicked', {
|
|
131
|
+
drawingMode,
|
|
132
|
+
editMode,
|
|
133
|
+
isDrawingPen,
|
|
134
|
+
hasModifierKeys,
|
|
135
|
+
willForceComplete: drawingMode === typings.DrawingMode.PEN && editMode === typings.EditMode.LAYER && isDrawingPen && !hasModifierKeys
|
|
136
|
+
});
|
|
137
|
+
// Only auto-complete if we're in pen drawing mode, actually drawing, and no modifier keys are pressed
|
|
138
|
+
if (drawingMode === typings.DrawingMode.PEN && editMode === typings.EditMode.LAYER && isDrawingPen && !hasModifierKeys) {
|
|
139
|
+
console.log('🔴 Force completing path from pane click');
|
|
140
|
+
forceComplete();
|
|
141
|
+
}
|
|
142
|
+
}, [
|
|
143
|
+
drawingMode,
|
|
144
|
+
editMode,
|
|
145
|
+
isDrawingPen,
|
|
146
|
+
forceComplete
|
|
147
|
+
]);
|
|
148
|
+
// Add wheel event listener for debugging
|
|
149
|
+
const handleWheel = React.useCallback((event)=>{
|
|
150
|
+
console.log('🖱️ Wheel event detected:', {
|
|
151
|
+
deltaY: event.deltaY,
|
|
152
|
+
ctrlKey: event.ctrlKey,
|
|
153
|
+
metaKey: event.metaKey,
|
|
154
|
+
target: event.target
|
|
155
|
+
});
|
|
156
|
+
}, []);
|
|
157
|
+
return /*#__PURE__*/ jsxRuntime.jsxs("div", {
|
|
158
|
+
ref: containerRef,
|
|
159
|
+
className: reactFlowCanvas_module.reactFlowWrapper,
|
|
160
|
+
style: {
|
|
161
|
+
cursor: getCursor(),
|
|
162
|
+
position: 'relative'
|
|
163
|
+
},
|
|
164
|
+
onWheel: handleWheel,
|
|
165
|
+
children: [
|
|
166
|
+
/*#__PURE__*/ jsxRuntime.jsxs(react.ReactFlow, {
|
|
167
|
+
nodes: nodes,
|
|
168
|
+
edges: edges,
|
|
169
|
+
onNodesChange: onNodesChange,
|
|
170
|
+
onEdgesChange: onEdgesChange,
|
|
171
|
+
onConnect: onConnect,
|
|
172
|
+
onSelectionChange: onSelectionChange,
|
|
173
|
+
onPaneClick: handlePaneClick,
|
|
174
|
+
onNodeMouseEnter: onNodeMouseEnter,
|
|
175
|
+
onNodeMouseLeave: onNodeMouseLeave,
|
|
176
|
+
onNodeClick: onNodeClick,
|
|
177
|
+
onNodeDoubleClick: onNodeDoubleClick,
|
|
178
|
+
nodeTypes: nodeTypes,
|
|
179
|
+
className: reactFlowCanvas_module.reactFlowCanvas,
|
|
180
|
+
style: {
|
|
181
|
+
background: '#F5F5F5'
|
|
182
|
+
},
|
|
183
|
+
defaultViewport: {
|
|
184
|
+
x: 0,
|
|
185
|
+
y: 0,
|
|
186
|
+
zoom: 1
|
|
187
|
+
},
|
|
188
|
+
minZoom: 0.1,
|
|
189
|
+
maxZoom: 4,
|
|
190
|
+
nodesConnectable: false,
|
|
191
|
+
nodesDraggable: viewMode === typings.ViewMode.EDIT && drawingMode === typings.DrawingMode.NONE,
|
|
192
|
+
elementsSelectable: true,
|
|
193
|
+
selectNodesOnDrag: false,
|
|
194
|
+
panOnDrag: viewMode === typings.ViewMode.VIEW || viewMode === typings.ViewMode.EDIT && drawingMode === typings.DrawingMode.NONE,
|
|
195
|
+
panOnScroll: false,
|
|
196
|
+
zoomOnScroll: true,
|
|
197
|
+
zoomOnDoubleClick: false,
|
|
198
|
+
nodeOrigin: [
|
|
199
|
+
0,
|
|
200
|
+
0
|
|
201
|
+
],
|
|
202
|
+
preventScrolling: true,
|
|
203
|
+
children: [
|
|
204
|
+
/*#__PURE__*/ jsxRuntime.jsx(CustomControls, {}),
|
|
205
|
+
/*#__PURE__*/ jsxRuntime.jsx(react.Background, {
|
|
206
|
+
bgColor: "#F5F5F5"
|
|
207
|
+
}),
|
|
208
|
+
nodes.length === 0 && /*#__PURE__*/ jsxRuntime.jsxs("div", {
|
|
209
|
+
className: reactFlowCanvas_module.emptyState,
|
|
210
|
+
children: [
|
|
211
|
+
/*#__PURE__*/ jsxRuntime.jsx(index.FolderIcon, {
|
|
212
|
+
className: reactFlowCanvas_module.emptyIcon
|
|
213
|
+
}),
|
|
214
|
+
/*#__PURE__*/ jsxRuntime.jsx("div", {
|
|
215
|
+
className: reactFlowCanvas_module.emptyTitle,
|
|
216
|
+
children: "目前沒有資料"
|
|
217
|
+
}),
|
|
218
|
+
/*#__PURE__*/ jsxRuntime.jsx("div", {
|
|
219
|
+
className: reactFlowCanvas_module.emptySubText,
|
|
220
|
+
children: "請上傳底圖並繪製圖層"
|
|
221
|
+
})
|
|
222
|
+
]
|
|
223
|
+
})
|
|
224
|
+
]
|
|
225
|
+
}),
|
|
226
|
+
previewRect && /*#__PURE__*/ jsxRuntime.jsx("div", {
|
|
227
|
+
style: {
|
|
228
|
+
position: 'absolute',
|
|
229
|
+
left: previewRect.x,
|
|
230
|
+
top: previewRect.y,
|
|
231
|
+
width: previewRect.width,
|
|
232
|
+
height: previewRect.height,
|
|
233
|
+
border: `2px dashed ${selectedColor}`,
|
|
234
|
+
backgroundColor: `${selectedColor}33`,
|
|
235
|
+
pointerEvents: 'none',
|
|
236
|
+
zIndex: 1000
|
|
237
|
+
}
|
|
238
|
+
}),
|
|
239
|
+
drawingMode === typings.DrawingMode.PEN && editMode === typings.EditMode.LAYER && /*#__PURE__*/ jsxRuntime.jsxs("svg", {
|
|
240
|
+
style: {
|
|
241
|
+
position: 'absolute',
|
|
242
|
+
top: 0,
|
|
243
|
+
left: 0,
|
|
244
|
+
width: '100%',
|
|
245
|
+
height: '100%',
|
|
246
|
+
pointerEvents: 'none',
|
|
247
|
+
zIndex: 1000
|
|
248
|
+
},
|
|
249
|
+
children: [
|
|
250
|
+
previewPath && previewPath.length > 1 && /*#__PURE__*/ jsxRuntime.jsx("path", {
|
|
251
|
+
d: `M ${previewPath.map((p)=>`${p.x} ${p.y}`).join(' L ')}`,
|
|
252
|
+
stroke: selectedColor,
|
|
253
|
+
strokeWidth: "2",
|
|
254
|
+
strokeDasharray: "5,5",
|
|
255
|
+
fill: "none",
|
|
256
|
+
fillOpacity: 0,
|
|
257
|
+
strokeLinecap: "round",
|
|
258
|
+
strokeLinejoin: "round"
|
|
259
|
+
}),
|
|
260
|
+
currentPoints && currentPoints.length >= 3 && /*#__PURE__*/ jsxRuntime.jsx("path", {
|
|
261
|
+
d: `M ${currentPoints[currentPoints.length - 1].x} ${currentPoints[currentPoints.length - 1].y} L ${currentPoints[0].x} ${currentPoints[0].y}`,
|
|
262
|
+
stroke: selectedColor,
|
|
263
|
+
strokeWidth: "1",
|
|
264
|
+
strokeDasharray: "2,2",
|
|
265
|
+
fill: "none",
|
|
266
|
+
strokeLinecap: "round",
|
|
267
|
+
opacity: "0.5"
|
|
268
|
+
}),
|
|
269
|
+
firstPoint && canClose && /*#__PURE__*/ jsxRuntime.jsxs(jsxRuntime.Fragment, {
|
|
270
|
+
children: [
|
|
271
|
+
/*#__PURE__*/ jsxRuntime.jsxs("circle", {
|
|
272
|
+
cx: firstPoint.x,
|
|
273
|
+
cy: firstPoint.y,
|
|
274
|
+
r: "8",
|
|
275
|
+
fill: "none",
|
|
276
|
+
stroke: "#10b981",
|
|
277
|
+
strokeWidth: "2",
|
|
278
|
+
opacity: "0.6",
|
|
279
|
+
children: [
|
|
280
|
+
/*#__PURE__*/ jsxRuntime.jsx("animate", {
|
|
281
|
+
attributeName: "r",
|
|
282
|
+
values: "6;10;6",
|
|
283
|
+
dur: "1.5s",
|
|
284
|
+
repeatCount: "indefinite"
|
|
285
|
+
}),
|
|
286
|
+
/*#__PURE__*/ jsxRuntime.jsx("animate", {
|
|
287
|
+
attributeName: "opacity",
|
|
288
|
+
values: "0.8;0.3;0.8",
|
|
289
|
+
dur: "1.5s",
|
|
290
|
+
repeatCount: "indefinite"
|
|
291
|
+
})
|
|
292
|
+
]
|
|
293
|
+
}),
|
|
294
|
+
/*#__PURE__*/ jsxRuntime.jsx("circle", {
|
|
295
|
+
cx: firstPoint.x,
|
|
296
|
+
cy: firstPoint.y,
|
|
297
|
+
r: "5",
|
|
298
|
+
fill: "#10b981",
|
|
299
|
+
stroke: "white",
|
|
300
|
+
strokeWidth: "2",
|
|
301
|
+
style: {
|
|
302
|
+
cursor: 'default'
|
|
303
|
+
}
|
|
304
|
+
})
|
|
305
|
+
]
|
|
306
|
+
}),
|
|
307
|
+
currentPoints && currentPoints.map((point, index)=>/*#__PURE__*/ jsxRuntime.jsx("circle", {
|
|
308
|
+
cx: point.x,
|
|
309
|
+
cy: point.y,
|
|
310
|
+
r: index === 0 && canClose ? '0' : '4',
|
|
311
|
+
fill: selectedColor,
|
|
312
|
+
stroke: "white",
|
|
313
|
+
strokeWidth: "2"
|
|
314
|
+
}, index))
|
|
315
|
+
]
|
|
316
|
+
})
|
|
317
|
+
]
|
|
318
|
+
});
|
|
319
|
+
};
|
|
320
|
+
|
|
321
|
+
module.exports = ReactFlowCanvas;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import React, { FC } from 'react';
|
|
2
|
+
import { Connection, Edge, EdgeChange, Node as ReactFlowNode, NodeChange, OnSelectionChangeParams } from '@xyflow/react';
|
|
3
|
+
import { DrawingMode, EditMode, ViewMode } from '../../typings.cjs';
|
|
4
|
+
interface ReactFlowCanvasProps {
|
|
5
|
+
nodes: ReactFlowNode[];
|
|
6
|
+
edges: Edge[];
|
|
7
|
+
onNodesChange: (changes: NodeChange[]) => void;
|
|
8
|
+
onEdgesChange: (changes: EdgeChange[]) => void;
|
|
9
|
+
onConnect: (connection: Connection) => void;
|
|
10
|
+
editMode: EditMode;
|
|
11
|
+
drawingMode: DrawingMode;
|
|
12
|
+
viewMode: ViewMode;
|
|
13
|
+
selectedColor?: string;
|
|
14
|
+
onCreateRectangle: (startX: number, startY: number, endX: number, endY: number) => void;
|
|
15
|
+
onCreatePath: (points: {
|
|
16
|
+
x: number;
|
|
17
|
+
y: number;
|
|
18
|
+
}[]) => void;
|
|
19
|
+
onSelectionChange?: (params: OnSelectionChangeParams) => void;
|
|
20
|
+
onTextEditComplete?: (id: string, oldText: string, newText: string) => void;
|
|
21
|
+
onPathPointsChange?: (id: string, oldPoints: {
|
|
22
|
+
x: number;
|
|
23
|
+
y: number;
|
|
24
|
+
}[], newPoints: {
|
|
25
|
+
x: number;
|
|
26
|
+
y: number;
|
|
27
|
+
}[]) => void;
|
|
28
|
+
onPathPointDragStateChange?: (isDragging: boolean) => void;
|
|
29
|
+
isEditingPathPoints?: boolean;
|
|
30
|
+
hoveredNodeId?: string | null;
|
|
31
|
+
onNodeMouseEnter?: (event: React.MouseEvent, node: ReactFlowNode) => void;
|
|
32
|
+
onNodeMouseLeave?: (event: React.MouseEvent, node: ReactFlowNode) => void;
|
|
33
|
+
onNodeClick?: (event: React.MouseEvent, node: ReactFlowNode) => void;
|
|
34
|
+
onNodeDoubleClick?: (event: React.MouseEvent, node: ReactFlowNode) => void;
|
|
35
|
+
showBackground?: boolean;
|
|
36
|
+
}
|
|
37
|
+
declare const ReactFlowCanvas: FC<ReactFlowCanvasProps>;
|
|
38
|
+
export default ReactFlowCanvas;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React, { FC } from 'react';
|
|
2
2
|
import { Connection, Edge, EdgeChange, Node as ReactFlowNode, NodeChange, OnSelectionChangeParams } from '@xyflow/react';
|
|
3
|
-
import { DrawingMode, EditMode, ViewMode } from '../../typings';
|
|
3
|
+
import { DrawingMode, EditMode, ViewMode } from '../../typings.js';
|
|
4
4
|
interface ReactFlowCanvasProps {
|
|
5
5
|
nodes: ReactFlowNode[];
|
|
6
6
|
edges: Edge[];
|