@rytass/wms-map-react-components 0.1.10 → 0.3.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/CHANGELOG.md +181 -0
- package/README.md +30 -0
- 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 +327 -0
- package/components/canvas/react-flow-canvas.d.cts +40 -0
- package/components/canvas/react-flow-canvas.d.ts +3 -1
- package/components/canvas/react-flow-canvas.js +7 -1
- package/components/canvas/react-flow-canvas.module.scss.cjs +5 -0
- package/components/modal/wms-map-content.cjs +835 -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 +30 -3
- package/components/modal/wms-map-modal-container.cjs +132 -0
- package/components/modal/wms-map-modal-container.d.cts +5 -0
- package/components/modal/wms-map-modal-container.d.ts +2 -2
- package/components/modal/wms-map-modal-container.js +6 -4
- 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 +234 -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 +0 -2
- package/components/nodes/image-node.module.scss.cjs +5 -0
- package/components/nodes/path-node.cjs +554 -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 +6 -5
- package/components/nodes/path-node.module.scss.cjs +5 -0
- package/components/nodes/rectangle-node.cjs +240 -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 +6 -5
- package/components/nodes/rectangle-node.module.scss.cjs +5 -0
- package/components/preview/wms-map-preview.cjs +201 -0
- package/components/preview/wms-map-preview.d.cts +11 -0
- package/components/preview/wms-map-preview.d.ts +11 -0
- package/components/preview/wms-map-preview.js +199 -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-fit-view-when-ready.cjs +74 -0
- package/hooks/use-fit-view-when-ready.d.cts +18 -0
- package/hooks/use-fit-view-when-ready.d.ts +18 -0
- package/hooks/use-fit-view-when-ready.js +72 -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-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 +28 -0
- package/index.d.cts +6 -0
- package/index.d.ts +6 -5
- package/index.js +1 -0
- 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 +76 -0
- package/types/component-props.types.d.ts +33 -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/fit-trigger.cjs +41 -0
- package/utils/fit-trigger.d.cts +37 -0
- package/utils/fit-trigger.d.ts +37 -0
- package/utils/fit-trigger.js +36 -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/utils/preview-highlight.cjs +38 -0
- package/utils/preview-highlight.d.cts +12 -0
- package/utils/preview-highlight.d.ts +12 -0
- package/utils/preview-highlight.js +34 -0
- package/index.cjs.css +0 -1
- package/index.cjs.js +0 -5128
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var typings = require('../typings.cjs');
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* 將 API 資料轉換為 React Flow 節點格式
|
|
7
|
+
* 這個函數是 transformNodesToMapData 的反向操作
|
|
8
|
+
*/ const transformApiDataToNodes = (mapData, imageUrlGenerator)=>{
|
|
9
|
+
// 轉換背景圖片為 ImageNode
|
|
10
|
+
const backgroundNodes = mapData.backgrounds.map((background, index)=>{
|
|
11
|
+
const imageUrl = imageUrlGenerator ? imageUrlGenerator(background.filename) : background.filename;
|
|
12
|
+
return {
|
|
13
|
+
id: background.id,
|
|
14
|
+
type: 'imageNode',
|
|
15
|
+
position: {
|
|
16
|
+
x: background.x,
|
|
17
|
+
y: background.y
|
|
18
|
+
},
|
|
19
|
+
data: {
|
|
20
|
+
imageUrl,
|
|
21
|
+
fileName: background.filename,
|
|
22
|
+
width: background.width,
|
|
23
|
+
height: background.height,
|
|
24
|
+
originalWidth: background.width,
|
|
25
|
+
originalHeight: background.height
|
|
26
|
+
},
|
|
27
|
+
zIndex: index + 1,
|
|
28
|
+
draggable: true,
|
|
29
|
+
selectable: true
|
|
30
|
+
};
|
|
31
|
+
});
|
|
32
|
+
// 轉換範圍為對應的節點,使用 functional 方式處理
|
|
33
|
+
const rangeNodes = mapData.ranges.map((range, index)=>{
|
|
34
|
+
const baseZIndex = backgroundNodes.length + index + 1;
|
|
35
|
+
if (range.type === typings.MapRangeType.RECTANGLE) {
|
|
36
|
+
const rectRange = range;
|
|
37
|
+
return {
|
|
38
|
+
id: rectRange.id,
|
|
39
|
+
type: 'rectangleNode',
|
|
40
|
+
position: {
|
|
41
|
+
x: rectRange.x,
|
|
42
|
+
y: rectRange.y
|
|
43
|
+
},
|
|
44
|
+
data: {
|
|
45
|
+
width: rectRange.width,
|
|
46
|
+
height: rectRange.height,
|
|
47
|
+
color: rectRange.color,
|
|
48
|
+
label: rectRange.id
|
|
49
|
+
},
|
|
50
|
+
zIndex: baseZIndex,
|
|
51
|
+
draggable: true,
|
|
52
|
+
selectable: true
|
|
53
|
+
};
|
|
54
|
+
} else if (range.type === typings.MapRangeType.POLYGON) {
|
|
55
|
+
const polyRange = range;
|
|
56
|
+
// 將絕對座標轉換為相對於中心點的座標
|
|
57
|
+
const relativePoints = polyRange.points.map((point)=>({
|
|
58
|
+
x: point.x,
|
|
59
|
+
y: point.y
|
|
60
|
+
}));
|
|
61
|
+
return {
|
|
62
|
+
id: polyRange.id,
|
|
63
|
+
type: 'pathNode',
|
|
64
|
+
position: {
|
|
65
|
+
x: Math.min(...polyRange.points.map((p)=>p.x)),
|
|
66
|
+
y: Math.min(...polyRange.points.map((p)=>p.y))
|
|
67
|
+
},
|
|
68
|
+
data: {
|
|
69
|
+
points: relativePoints,
|
|
70
|
+
color: polyRange.color,
|
|
71
|
+
label: polyRange.id,
|
|
72
|
+
strokeWidth: 2
|
|
73
|
+
},
|
|
74
|
+
zIndex: baseZIndex,
|
|
75
|
+
draggable: true,
|
|
76
|
+
selectable: true
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
return null;
|
|
80
|
+
}).filter((node)=>node !== null);
|
|
81
|
+
return [
|
|
82
|
+
...backgroundNodes,
|
|
83
|
+
...rangeNodes
|
|
84
|
+
];
|
|
85
|
+
};
|
|
86
|
+
/**
|
|
87
|
+
* 驗證 API 資料格式是否正確
|
|
88
|
+
*/ const validateMapData = (data)=>{
|
|
89
|
+
if (!data || typeof data !== 'object') {
|
|
90
|
+
return false;
|
|
91
|
+
}
|
|
92
|
+
const obj = data;
|
|
93
|
+
// 檢查必要欄位
|
|
94
|
+
if (!obj.id || typeof obj.id !== 'string') {
|
|
95
|
+
console.error('Map data validation failed: missing or invalid id');
|
|
96
|
+
return false;
|
|
97
|
+
}
|
|
98
|
+
if (!Array.isArray(obj.backgrounds)) {
|
|
99
|
+
console.error('Map data validation failed: backgrounds must be an array');
|
|
100
|
+
return false;
|
|
101
|
+
}
|
|
102
|
+
if (!Array.isArray(obj.ranges)) {
|
|
103
|
+
console.error('Map data validation failed: ranges must be an array');
|
|
104
|
+
return false;
|
|
105
|
+
}
|
|
106
|
+
// 驗證背景資料
|
|
107
|
+
for (const bg of obj.backgrounds){
|
|
108
|
+
if (!bg.id || !bg.filename || typeof bg.x !== 'number' || typeof bg.y !== 'number') {
|
|
109
|
+
console.error('Map data validation failed: invalid background data', bg);
|
|
110
|
+
return false;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
// 驗證範圍資料
|
|
114
|
+
for (const range of obj.ranges){
|
|
115
|
+
if (!range.id || !range.type || !range.color) {
|
|
116
|
+
console.error('Map data validation failed: invalid range data', range);
|
|
117
|
+
return false;
|
|
118
|
+
}
|
|
119
|
+
if (range.type === typings.MapRangeType.RECTANGLE) {
|
|
120
|
+
if (typeof range.x !== 'number' || typeof range.y !== 'number' || typeof range.width !== 'number' || typeof range.height !== 'number') {
|
|
121
|
+
console.error('Map data validation failed: invalid rectangle range data', range);
|
|
122
|
+
return false;
|
|
123
|
+
}
|
|
124
|
+
} else if (range.type === typings.MapRangeType.POLYGON) {
|
|
125
|
+
if (!Array.isArray(range.points) || range.points.length < 3) {
|
|
126
|
+
console.error('Map data validation failed: invalid polygon range data', range);
|
|
127
|
+
return false;
|
|
128
|
+
}
|
|
129
|
+
for (const point of range.points){
|
|
130
|
+
if (typeof point.x !== 'number' || typeof point.y !== 'number') {
|
|
131
|
+
console.error('Map data validation failed: invalid polygon point', point);
|
|
132
|
+
return false;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
return true;
|
|
138
|
+
};
|
|
139
|
+
/**
|
|
140
|
+
* 使用範例:模擬從 API 載入資料
|
|
141
|
+
*/ const loadMapDataFromApi = async (mapId)=>{
|
|
142
|
+
try {
|
|
143
|
+
// 模擬 API 呼叫
|
|
144
|
+
console.log(`🌐 模擬載入地圖資料: ${mapId}`);
|
|
145
|
+
// 在實際應用中,這裡會是真實的 API 呼叫
|
|
146
|
+
// const response = await fetch(`/api/maps/${mapId}`);
|
|
147
|
+
// const mapData = await response.json();
|
|
148
|
+
// TODO: 實際應用中需要替換為真實的 API 呼叫
|
|
149
|
+
// 這裡暫時提供示例數據結構
|
|
150
|
+
const mockMapData = {
|
|
151
|
+
id: mapId,
|
|
152
|
+
images: [],
|
|
153
|
+
ranges: []
|
|
154
|
+
};
|
|
155
|
+
// 驗證資料格式
|
|
156
|
+
if (!validateMapData(mockMapData)) {
|
|
157
|
+
throw new Error('Invalid map data format');
|
|
158
|
+
}
|
|
159
|
+
// 轉換為 React Flow 節點
|
|
160
|
+
const generateMockImageUrl = (filename)=>{
|
|
161
|
+
return `data:image/svg+xml,${encodeURIComponent(`<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100"><rect width="100" height="100" fill="#f0f0f0"/><text x="50" y="50" text-anchor="middle" dy=".3em" font-family="Arial" font-size="12">${filename}</text></svg>`)}`;
|
|
162
|
+
};
|
|
163
|
+
const nodes = transformApiDataToNodes(mockMapData, generateMockImageUrl);
|
|
164
|
+
console.log(`✅ 成功載入 ${nodes.length} 個節點`);
|
|
165
|
+
console.log('📊 節點統計:', {
|
|
166
|
+
imageNodes: nodes.filter((n)=>n.type === 'imageNode').length,
|
|
167
|
+
rectangleNodes: nodes.filter((n)=>n.type === 'rectangleNode').length,
|
|
168
|
+
pathNodes: nodes.filter((n)=>n.type === 'pathNode').length
|
|
169
|
+
});
|
|
170
|
+
return nodes;
|
|
171
|
+
} catch (error) {
|
|
172
|
+
console.error('❌ 載入地圖資料失敗:', error);
|
|
173
|
+
throw error;
|
|
174
|
+
}
|
|
175
|
+
};
|
|
176
|
+
/**
|
|
177
|
+
* 輔助函數:計算多邊形的邊界框
|
|
178
|
+
*/ const calculatePolygonBounds = (points)=>{
|
|
179
|
+
if (points.length === 0) {
|
|
180
|
+
return {
|
|
181
|
+
minX: 0,
|
|
182
|
+
minY: 0,
|
|
183
|
+
maxX: 0,
|
|
184
|
+
maxY: 0,
|
|
185
|
+
width: 0,
|
|
186
|
+
height: 0
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
const xs = points.map((p)=>p.x);
|
|
190
|
+
const ys = points.map((p)=>p.y);
|
|
191
|
+
const minX = Math.min(...xs);
|
|
192
|
+
const maxX = Math.max(...xs);
|
|
193
|
+
const minY = Math.min(...ys);
|
|
194
|
+
const maxY = Math.max(...ys);
|
|
195
|
+
return {
|
|
196
|
+
minX,
|
|
197
|
+
maxX,
|
|
198
|
+
minY,
|
|
199
|
+
maxY,
|
|
200
|
+
width: maxX - minX,
|
|
201
|
+
height: maxY - minY
|
|
202
|
+
};
|
|
203
|
+
};
|
|
204
|
+
/**
|
|
205
|
+
* 輔助函數:為節點計算合適的 zIndex
|
|
206
|
+
*/ const calculateNodeZIndex = (nodes, nodeType)=>{
|
|
207
|
+
const maxZIndex = Math.max(...nodes.map((n)=>n.zIndex || 0), 0);
|
|
208
|
+
// 背景圖片應該在最底層
|
|
209
|
+
if (nodeType === 'imageNode') {
|
|
210
|
+
const imageNodes = nodes.filter((n)=>n.type === 'imageNode');
|
|
211
|
+
return imageNodes.length;
|
|
212
|
+
}
|
|
213
|
+
// 其他節點在圖片之上
|
|
214
|
+
return maxZIndex + 1;
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
exports.calculateNodeZIndex = calculateNodeZIndex;
|
|
218
|
+
exports.calculatePolygonBounds = calculatePolygonBounds;
|
|
219
|
+
exports.loadMapDataFromApi = loadMapDataFromApi;
|
|
220
|
+
exports.transformApiDataToNodes = transformApiDataToNodes;
|
|
221
|
+
exports.validateMapData = validateMapData;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Node } from '@xyflow/react';
|
|
2
|
+
import { Map } from '../typings.cjs';
|
|
3
|
+
/**
|
|
4
|
+
* 將 API 資料轉換為 React Flow 節點格式
|
|
5
|
+
* 這個函數是 transformNodesToMapData 的反向操作
|
|
6
|
+
*/
|
|
7
|
+
export declare const transformApiDataToNodes: (mapData: Map, imageUrlGenerator?: (filename: string) => string) => Node[];
|
|
8
|
+
/**
|
|
9
|
+
* 驗證 API 資料格式是否正確
|
|
10
|
+
*/
|
|
11
|
+
export declare const validateMapData: (data: unknown) => data is Map;
|
|
12
|
+
/**
|
|
13
|
+
* 使用範例:模擬從 API 載入資料
|
|
14
|
+
*/
|
|
15
|
+
export declare const loadMapDataFromApi: (mapId: string) => Promise<Node[]>;
|
|
16
|
+
/**
|
|
17
|
+
* 輔助函數:計算多邊形的邊界框
|
|
18
|
+
*/
|
|
19
|
+
export declare const calculatePolygonBounds: (points: {
|
|
20
|
+
x: number;
|
|
21
|
+
y: number;
|
|
22
|
+
}[]) => {
|
|
23
|
+
minX: number;
|
|
24
|
+
maxX: number;
|
|
25
|
+
minY: number;
|
|
26
|
+
maxY: number;
|
|
27
|
+
width: number;
|
|
28
|
+
height: number;
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* 輔助函數:為節點計算合適的 zIndex
|
|
32
|
+
*/
|
|
33
|
+
export declare const calculateNodeZIndex: (nodes: Node[], nodeType: string) => number;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 顏色亮度計算工具函數
|
|
5
|
+
* 用於在檢視模式下創建 hover 效果
|
|
6
|
+
*/ /**
|
|
7
|
+
* 將十六進制顏色轉換為 RGB
|
|
8
|
+
*/ function hexToRgb(hex) {
|
|
9
|
+
// 移除 # 符號
|
|
10
|
+
const cleanHex = hex.replace('#', '');
|
|
11
|
+
// 支援 3 位元和 6 位元的十六進制顏色
|
|
12
|
+
const shorthandRegex = /^([a-f\d])([a-f\d])([a-f\d])$/i;
|
|
13
|
+
const fullHex = cleanHex.replace(shorthandRegex, (_m, r, g, b)=>r + r + g + g + b + b);
|
|
14
|
+
const result = /^([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(fullHex);
|
|
15
|
+
return result ? {
|
|
16
|
+
r: parseInt(result[1], 16),
|
|
17
|
+
g: parseInt(result[2], 16),
|
|
18
|
+
b: parseInt(result[3], 16)
|
|
19
|
+
} : null;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* 將 RGB 轉換為十六進制顏色
|
|
23
|
+
*/ function rgbToHex(r, g, b) {
|
|
24
|
+
const toHex = (n)=>{
|
|
25
|
+
const hex = Math.round(Math.max(0, Math.min(255, n))).toString(16);
|
|
26
|
+
return hex.length === 1 ? '0' + hex : hex;
|
|
27
|
+
};
|
|
28
|
+
return `#${toHex(r)}${toHex(g)}${toHex(b)}`;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* 提高顏色亮度
|
|
32
|
+
* @param color - 十六進制顏色字串 (例如: #ff0000)
|
|
33
|
+
* @param percentage - 亮度提高的百分比 (例如: 15 表示提高 15%)
|
|
34
|
+
* @returns 提高亮度後的十六進制顏色字串
|
|
35
|
+
*/ function increaseBrightness(color, percentage) {
|
|
36
|
+
const rgb = hexToRgb(color);
|
|
37
|
+
if (!rgb) {
|
|
38
|
+
console.warn(`Invalid color format: ${color}`);
|
|
39
|
+
return color;
|
|
40
|
+
}
|
|
41
|
+
// 計算亮度增加的因子
|
|
42
|
+
const factor = 1 + percentage / 100;
|
|
43
|
+
// 應用亮度增加,但不能超過 255
|
|
44
|
+
const newR = Math.min(255, rgb.r * factor);
|
|
45
|
+
const newG = Math.min(255, rgb.g * factor);
|
|
46
|
+
const newB = Math.min(255, rgb.b * factor);
|
|
47
|
+
return rgbToHex(newR, newG, newB);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* 創建 hover 效果顏色(亮度提高 15%)
|
|
51
|
+
* @param color - 原始顏色
|
|
52
|
+
* @returns hover 效果的顏色
|
|
53
|
+
*/ function createHoverColor(color) {
|
|
54
|
+
return increaseBrightness(color, 25);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
exports.createHoverColor = createHoverColor;
|
|
58
|
+
exports.increaseBrightness = increaseBrightness;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 顏色亮度計算工具函數
|
|
3
|
+
* 用於在檢視模式下創建 hover 效果
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* 提高顏色亮度
|
|
7
|
+
* @param color - 十六進制顏色字串 (例如: #ff0000)
|
|
8
|
+
* @param percentage - 亮度提高的百分比 (例如: 15 表示提高 15%)
|
|
9
|
+
* @returns 提高亮度後的十六進制顏色字串
|
|
10
|
+
*/
|
|
11
|
+
export declare function increaseBrightness(color: string, percentage: number): string;
|
|
12
|
+
/**
|
|
13
|
+
* 創建 hover 效果顏色(亮度提高 15%)
|
|
14
|
+
* @param color - 原始顏色
|
|
15
|
+
* @returns hover 效果的顏色
|
|
16
|
+
*/
|
|
17
|
+
export declare function createHoverColor(color: string): string;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 簡化的 Debug Console 管理系統
|
|
5
|
+
* 只有開啟/關閉功能,可透過 WmsMapModal props 控制
|
|
6
|
+
* 使用命名空間避免污染全域範圍
|
|
7
|
+
*/ // WmsMapModal 專用的 debug 命名空間
|
|
8
|
+
const WMS_DEBUG_NAMESPACE = '__WMS_MAP_DEBUG__';
|
|
9
|
+
// 取得 WmsMapModal 專用的 debug 狀態
|
|
10
|
+
const getWmsDebugState = ()=>{
|
|
11
|
+
return Boolean(window[WMS_DEBUG_NAMESPACE]);
|
|
12
|
+
};
|
|
13
|
+
// 設定 WmsMapModal 專用的 debug 狀態
|
|
14
|
+
const setWmsDebugState = (enabled)=>{
|
|
15
|
+
window[WMS_DEBUG_NAMESPACE] = enabled;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* 設定 debug 模式 (僅限 WmsMapModal 範圍)
|
|
19
|
+
*/ const setDebugMode = (enabled)=>{
|
|
20
|
+
setWmsDebugState(enabled);
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* 主要的 debug logger 函數
|
|
24
|
+
*/ const debugLog = (message, ...args)=>{
|
|
25
|
+
if (!getWmsDebugState()) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
const timestamp = new Date().toLocaleTimeString();
|
|
29
|
+
const prefix = `🔧 ${timestamp} [WMS]`;
|
|
30
|
+
console.log(prefix, message, ...args);
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* 成功 debug log
|
|
34
|
+
*/ const debugSuccess = (message, ...args)=>{
|
|
35
|
+
if (!getWmsDebugState()) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
const timestamp = new Date().toLocaleTimeString();
|
|
39
|
+
const prefix = `✅ ${timestamp} [WMS]`;
|
|
40
|
+
console.log(prefix, message, ...args);
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
exports.debugLog = debugLog;
|
|
44
|
+
exports.debugSuccess = debugSuccess;
|
|
45
|
+
exports.setDebugMode = setDebugMode;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 簡化的 Debug Console 管理系統
|
|
3
|
+
* 只有開啟/關閉功能,可透過 WmsMapModal props 控制
|
|
4
|
+
* 使用命名空間避免污染全域範圍
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* 設定 debug 模式 (僅限 WmsMapModal 範圍)
|
|
8
|
+
*/
|
|
9
|
+
export declare const setDebugMode: (enabled: boolean) => void;
|
|
10
|
+
/**
|
|
11
|
+
* 取得 debug 模式狀態 (僅限 WmsMapModal 範圍)
|
|
12
|
+
*/
|
|
13
|
+
export declare const getDebugMode: () => boolean;
|
|
14
|
+
/**
|
|
15
|
+
* 主要的 debug logger 函數
|
|
16
|
+
*/
|
|
17
|
+
export declare const debugLog: (message: string, ...args: (string | number | object)[]) => void;
|
|
18
|
+
/**
|
|
19
|
+
* 成功 debug log
|
|
20
|
+
*/
|
|
21
|
+
export declare const debugSuccess: (message: string, ...args: (string | number | object)[]) => void;
|
|
22
|
+
/**
|
|
23
|
+
* 錯誤 debug log
|
|
24
|
+
*/
|
|
25
|
+
export declare const debugError: (message: string, error?: unknown) => void;
|
|
26
|
+
/**
|
|
27
|
+
* 警告 debug log
|
|
28
|
+
*/
|
|
29
|
+
export declare const debugWarn: (message: string, ...args: (string | number | object)[]) => void;
|
|
30
|
+
/**
|
|
31
|
+
* 群組化的 debug log
|
|
32
|
+
*/
|
|
33
|
+
export declare const debugGroup: (groupName: string, callback: () => void) => void;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/** 節點 id 集合的穩定簽章(排序後以 \u0000 串接),用來判斷「是不是換了一組節點」。 */ const getNodeIdSignature = (nodes)=>nodes.map((node)=>node.id).sort().join('\u0000');
|
|
4
|
+
/** 地圖身分:以整條麵包屑路徑表示,同名子地圖掛在不同父層時仍可區分。 */ const getMapKey = (warehouseIds)=>warehouseIds.join('\u0000');
|
|
5
|
+
const INITIAL_MAP_FIT_STATE = {
|
|
6
|
+
mapKey: null,
|
|
7
|
+
lastSignature: null,
|
|
8
|
+
signatureAtSwitch: null,
|
|
9
|
+
pending: false
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* 判斷是否要對目前的節點 fit 一次。
|
|
13
|
+
*
|
|
14
|
+
* 只在兩種情況 fit:
|
|
15
|
+
* - 換到另一張地圖(mapKey 改變),且新地圖的節點已到;
|
|
16
|
+
* - 同一張地圖第一次拿到非空節點(API 晚到,起初是空陣列)。
|
|
17
|
+
*
|
|
18
|
+
* 同一張地圖的節點增減(例如編輯後儲存、宿主重新抓資料)不會觸發。
|
|
19
|
+
*
|
|
20
|
+
* 換圖時若節點還是舊地圖的(宿主先更新麵包屑、資料稍後才到),會等到節點集合
|
|
21
|
+
* 與換圖當下不同且非空時才 fit。前提是宿主更新 warehouseIds 不晚於更新節點。
|
|
22
|
+
*/ const resolveMapFit = (state, { mapKey, nodeSignature, nodeCount })=>{
|
|
23
|
+
const switched = mapKey !== state.mapKey;
|
|
24
|
+
const pending = switched || state.pending;
|
|
25
|
+
const signatureAtSwitch = switched ? state.lastSignature : state.signatureAtSwitch;
|
|
26
|
+
const shouldFit = pending && nodeCount > 0 && nodeSignature !== signatureAtSwitch;
|
|
27
|
+
return {
|
|
28
|
+
shouldFit,
|
|
29
|
+
state: {
|
|
30
|
+
mapKey,
|
|
31
|
+
lastSignature: nodeSignature,
|
|
32
|
+
signatureAtSwitch,
|
|
33
|
+
pending: pending && !shouldFit
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
exports.INITIAL_MAP_FIT_STATE = INITIAL_MAP_FIT_STATE;
|
|
39
|
+
exports.getMapKey = getMapKey;
|
|
40
|
+
exports.getNodeIdSignature = getNodeIdSignature;
|
|
41
|
+
exports.resolveMapFit = resolveMapFit;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { FlowNode } from '../types/react-flow.types.cjs';
|
|
2
|
+
/** 節點 id 集合的穩定簽章(排序後以 \u0000 串接),用來判斷「是不是換了一組節點」。 */
|
|
3
|
+
export declare const getNodeIdSignature: (nodes: readonly Pick<FlowNode, "id">[]) => string;
|
|
4
|
+
/** 地圖身分:以整條麵包屑路徑表示,同名子地圖掛在不同父層時仍可區分。 */
|
|
5
|
+
export declare const getMapKey: (warehouseIds: readonly string[]) => string;
|
|
6
|
+
export interface MapFitState {
|
|
7
|
+
/** 上一次評估時的地圖身分;null 代表尚未評估過。 */
|
|
8
|
+
readonly mapKey: string | null;
|
|
9
|
+
/** 上一次評估時的節點簽章。 */
|
|
10
|
+
readonly lastSignature: string | null;
|
|
11
|
+
/** 換到目前這張地圖時,畫面上還是哪一組節點(舊地圖的節點不算數)。 */
|
|
12
|
+
readonly signatureAtSwitch: string | null;
|
|
13
|
+
/** 目前地圖是否還在等第一組非空節點。 */
|
|
14
|
+
readonly pending: boolean;
|
|
15
|
+
}
|
|
16
|
+
export declare const INITIAL_MAP_FIT_STATE: MapFitState;
|
|
17
|
+
export interface MapFitInput {
|
|
18
|
+
readonly mapKey: string;
|
|
19
|
+
readonly nodeSignature: string;
|
|
20
|
+
readonly nodeCount: number;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* 判斷是否要對目前的節點 fit 一次。
|
|
24
|
+
*
|
|
25
|
+
* 只在兩種情況 fit:
|
|
26
|
+
* - 換到另一張地圖(mapKey 改變),且新地圖的節點已到;
|
|
27
|
+
* - 同一張地圖第一次拿到非空節點(API 晚到,起初是空陣列)。
|
|
28
|
+
*
|
|
29
|
+
* 同一張地圖的節點增減(例如編輯後儲存、宿主重新抓資料)不會觸發。
|
|
30
|
+
*
|
|
31
|
+
* 換圖時若節點還是舊地圖的(宿主先更新麵包屑、資料稍後才到),會等到節點集合
|
|
32
|
+
* 與換圖當下不同且非空時才 fit。前提是宿主更新 warehouseIds 不晚於更新節點。
|
|
33
|
+
*/
|
|
34
|
+
export declare const resolveMapFit: (state: MapFitState, { mapKey, nodeSignature, nodeCount }: MapFitInput) => {
|
|
35
|
+
shouldFit: boolean;
|
|
36
|
+
state: MapFitState;
|
|
37
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { FlowNode } from '../types/react-flow.types.js';
|
|
2
|
+
/** 節點 id 集合的穩定簽章(排序後以 \u0000 串接),用來判斷「是不是換了一組節點」。 */
|
|
3
|
+
export declare const getNodeIdSignature: (nodes: readonly Pick<FlowNode, "id">[]) => string;
|
|
4
|
+
/** 地圖身分:以整條麵包屑路徑表示,同名子地圖掛在不同父層時仍可區分。 */
|
|
5
|
+
export declare const getMapKey: (warehouseIds: readonly string[]) => string;
|
|
6
|
+
export interface MapFitState {
|
|
7
|
+
/** 上一次評估時的地圖身分;null 代表尚未評估過。 */
|
|
8
|
+
readonly mapKey: string | null;
|
|
9
|
+
/** 上一次評估時的節點簽章。 */
|
|
10
|
+
readonly lastSignature: string | null;
|
|
11
|
+
/** 換到目前這張地圖時,畫面上還是哪一組節點(舊地圖的節點不算數)。 */
|
|
12
|
+
readonly signatureAtSwitch: string | null;
|
|
13
|
+
/** 目前地圖是否還在等第一組非空節點。 */
|
|
14
|
+
readonly pending: boolean;
|
|
15
|
+
}
|
|
16
|
+
export declare const INITIAL_MAP_FIT_STATE: MapFitState;
|
|
17
|
+
export interface MapFitInput {
|
|
18
|
+
readonly mapKey: string;
|
|
19
|
+
readonly nodeSignature: string;
|
|
20
|
+
readonly nodeCount: number;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* 判斷是否要對目前的節點 fit 一次。
|
|
24
|
+
*
|
|
25
|
+
* 只在兩種情況 fit:
|
|
26
|
+
* - 換到另一張地圖(mapKey 改變),且新地圖的節點已到;
|
|
27
|
+
* - 同一張地圖第一次拿到非空節點(API 晚到,起初是空陣列)。
|
|
28
|
+
*
|
|
29
|
+
* 同一張地圖的節點增減(例如編輯後儲存、宿主重新抓資料)不會觸發。
|
|
30
|
+
*
|
|
31
|
+
* 換圖時若節點還是舊地圖的(宿主先更新麵包屑、資料稍後才到),會等到節點集合
|
|
32
|
+
* 與換圖當下不同且非空時才 fit。前提是宿主更新 warehouseIds 不晚於更新節點。
|
|
33
|
+
*/
|
|
34
|
+
export declare const resolveMapFit: (state: MapFitState, { mapKey, nodeSignature, nodeCount }: MapFitInput) => {
|
|
35
|
+
shouldFit: boolean;
|
|
36
|
+
state: MapFitState;
|
|
37
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/** 節點 id 集合的穩定簽章(排序後以 \u0000 串接),用來判斷「是不是換了一組節點」。 */ const getNodeIdSignature = (nodes)=>nodes.map((node)=>node.id).sort().join('\u0000');
|
|
2
|
+
/** 地圖身分:以整條麵包屑路徑表示,同名子地圖掛在不同父層時仍可區分。 */ const getMapKey = (warehouseIds)=>warehouseIds.join('\u0000');
|
|
3
|
+
const INITIAL_MAP_FIT_STATE = {
|
|
4
|
+
mapKey: null,
|
|
5
|
+
lastSignature: null,
|
|
6
|
+
signatureAtSwitch: null,
|
|
7
|
+
pending: false
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* 判斷是否要對目前的節點 fit 一次。
|
|
11
|
+
*
|
|
12
|
+
* 只在兩種情況 fit:
|
|
13
|
+
* - 換到另一張地圖(mapKey 改變),且新地圖的節點已到;
|
|
14
|
+
* - 同一張地圖第一次拿到非空節點(API 晚到,起初是空陣列)。
|
|
15
|
+
*
|
|
16
|
+
* 同一張地圖的節點增減(例如編輯後儲存、宿主重新抓資料)不會觸發。
|
|
17
|
+
*
|
|
18
|
+
* 換圖時若節點還是舊地圖的(宿主先更新麵包屑、資料稍後才到),會等到節點集合
|
|
19
|
+
* 與換圖當下不同且非空時才 fit。前提是宿主更新 warehouseIds 不晚於更新節點。
|
|
20
|
+
*/ const resolveMapFit = (state, { mapKey, nodeSignature, nodeCount })=>{
|
|
21
|
+
const switched = mapKey !== state.mapKey;
|
|
22
|
+
const pending = switched || state.pending;
|
|
23
|
+
const signatureAtSwitch = switched ? state.lastSignature : state.signatureAtSwitch;
|
|
24
|
+
const shouldFit = pending && nodeCount > 0 && nodeSignature !== signatureAtSwitch;
|
|
25
|
+
return {
|
|
26
|
+
shouldFit,
|
|
27
|
+
state: {
|
|
28
|
+
mapKey,
|
|
29
|
+
lastSignature: nodeSignature,
|
|
30
|
+
signatureAtSwitch,
|
|
31
|
+
pending: pending && !shouldFit
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export { INITIAL_MAP_FIT_STATE, getMapKey, getNodeIdSignature, resolveMapFit };
|