@rytass/wms-map-react-components 0.2.0 → 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/canvas/react-flow-canvas.cjs +7 -1
- package/components/canvas/react-flow-canvas.d.cts +2 -0
- package/components/canvas/react-flow-canvas.d.ts +2 -0
- package/components/canvas/react-flow-canvas.js +7 -1
- package/components/modal/wms-map-content.cjs +29 -2
- package/components/modal/wms-map-content.js +30 -3
- package/components/modal/wms-map-modal-container.cjs +6 -4
- package/components/modal/wms-map-modal-container.d.cts +1 -1
- package/components/modal/wms-map-modal-container.d.ts +1 -1
- package/components/modal/wms-map-modal-container.js +6 -4
- package/components/nodes/image-node.cjs +0 -2
- package/components/nodes/image-node.js +0 -2
- package/components/nodes/path-node.cjs +5 -4
- package/components/nodes/path-node.js +6 -5
- package/components/nodes/rectangle-node.cjs +5 -4
- package/components/nodes/rectangle-node.js +6 -5
- 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/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/index.cjs +2 -0
- package/index.d.cts +1 -0
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/package.json +1 -1
- package/types/component-props.types.d.cts +31 -0
- package/types/component-props.types.d.ts +31 -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/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
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
var typings = require('./typings.cjs');
|
|
4
4
|
var wmsMapModalContainer = require('./components/modal/wms-map-modal-container.cjs');
|
|
5
|
+
var wmsMapPreview = require('./components/preview/wms-map-preview.cjs');
|
|
5
6
|
var mapDataTransform = require('./utils/map-data-transform.cjs');
|
|
6
7
|
var apiDataTransform = require('./utils/api-data-transform.cjs');
|
|
7
8
|
|
|
@@ -15,6 +16,7 @@ exports.MapRangeType = typings.MapRangeType;
|
|
|
15
16
|
exports.ViewMode = typings.ViewMode;
|
|
16
17
|
exports.WMSMapModal = wmsMapModalContainer.default;
|
|
17
18
|
exports.WMSMapModalContent = wmsMapModalContainer.WMSMapModalContent;
|
|
19
|
+
exports.WMSMapPreview = wmsMapPreview;
|
|
18
20
|
exports.logMapData = mapDataTransform.logMapData;
|
|
19
21
|
exports.logNodeData = mapDataTransform.logNodeData;
|
|
20
22
|
exports.transformNodeToClickInfo = mapDataTransform.transformNodeToClickInfo;
|
package/index.d.cts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export * from './typings.cjs';
|
|
2
2
|
export * from './types/index.cjs';
|
|
3
3
|
export { WMSMapModalContent, default as WMSMapModal } from './components/modal/wms-map-modal-container.cjs';
|
|
4
|
+
export { default as WMSMapPreview } from './components/preview/wms-map-preview.cjs';
|
|
4
5
|
export { transformNodeToClickInfo, transformNodesToMapData, logMapData, logNodeData } from './utils/map-data-transform.cjs';
|
|
5
6
|
export { transformApiDataToNodes, validateMapData, loadMapDataFromApi, calculatePolygonBounds, calculateNodeZIndex, } from './utils/api-data-transform.cjs';
|
package/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export * from './typings.js';
|
|
2
2
|
export * from './types/index.js';
|
|
3
3
|
export { WMSMapModalContent, default as WMSMapModal } from './components/modal/wms-map-modal-container.js';
|
|
4
|
+
export { default as WMSMapPreview } from './components/preview/wms-map-preview.js';
|
|
4
5
|
export { transformNodeToClickInfo, transformNodesToMapData, logMapData, logNodeData } from './utils/map-data-transform.js';
|
|
5
6
|
export { transformApiDataToNodes, validateMapData, loadMapDataFromApi, calculatePolygonBounds, calculateNodeZIndex, } from './utils/api-data-transform.js';
|
package/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { DrawingMode, EditMode, LayerDrawingTool, MapRangeColor, MapRangeType, ViewMode } from './typings.js';
|
|
2
2
|
export { default as WMSMapModal, WMSMapModalContent } from './components/modal/wms-map-modal-container.js';
|
|
3
|
+
export { default as WMSMapPreview } from './components/preview/wms-map-preview.js';
|
|
3
4
|
export { logMapData, logNodeData, transformNodeToClickInfo, transformNodesToMapData } from './utils/map-data-transform.js';
|
|
4
5
|
export { calculateNodeZIndex, calculatePolygonBounds, loadMapDataFromApi, transformApiDataToNodes, validateMapData } from './utils/api-data-transform.js';
|
package/package.json
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { CSSProperties } from 'react';
|
|
1
2
|
import { ViewMode, WMSNodeClickInfo, Map, EditMode, DrawingMode } from '../typings.cjs';
|
|
2
3
|
import { FlowNode, FlowEdge } from './react-flow.types.cjs';
|
|
3
4
|
export interface WMSMapModalProps {
|
|
@@ -19,6 +20,13 @@ export interface WMSMapModalProps {
|
|
|
19
20
|
getFilenameFQDN?: (filename: string) => Promise<string> | string;
|
|
20
21
|
maxFileSizeKB?: number;
|
|
21
22
|
warehouseIds?: string[];
|
|
23
|
+
/**
|
|
24
|
+
* 開圖時自動縮放到框住所有節點,預設 true。
|
|
25
|
+
* 只在換到另一張地圖(warehouseIds 改變)或同一張圖第一次拿到非空節點時 fit;
|
|
26
|
+
* 同一張圖的節點增減(編輯後儲存、重新抓資料)不會重新 fit。
|
|
27
|
+
* 換圖時請讓 warehouseIds 不晚於 initialNodes 更新。
|
|
28
|
+
*/
|
|
29
|
+
fitViewOnLoad?: boolean;
|
|
22
30
|
}
|
|
23
31
|
export interface WMSMapContentProps {
|
|
24
32
|
editMode: EditMode;
|
|
@@ -42,4 +50,27 @@ export interface WMSMapContentProps {
|
|
|
42
50
|
getFilenameFQDN?: (filename: string) => Promise<string> | string;
|
|
43
51
|
maxFileSizeKB?: number;
|
|
44
52
|
warehouseIds?: string[];
|
|
53
|
+
/**
|
|
54
|
+
* 開圖時自動縮放到框住所有節點,預設 true。
|
|
55
|
+
* 只在換到另一張地圖(warehouseIds 改變)或同一張圖第一次拿到非空節點時 fit;
|
|
56
|
+
* 同一張圖的節點增減(編輯後儲存、重新抓資料)不會重新 fit。
|
|
57
|
+
* 換圖時請讓 warehouseIds 不晚於 initialNodes 更新。
|
|
58
|
+
*/
|
|
59
|
+
fitViewOnLoad?: boolean;
|
|
60
|
+
}
|
|
61
|
+
export interface WMSMapPreviewProps {
|
|
62
|
+
/** 要顯示的節點(與 WMSMapModal 的 initialNodes 同格式)。 */
|
|
63
|
+
initialNodes: FlowNode[];
|
|
64
|
+
/** 要高亮的範圍節點 id;有值時 fit 只框住這些節點。 */
|
|
65
|
+
highlightIds?: string[];
|
|
66
|
+
/** 有 highlightIds 時是否淡化其餘範圍,預設 true。 */
|
|
67
|
+
dimOthers?: boolean;
|
|
68
|
+
/** fit 時的比例 padding,預設 0.15。 */
|
|
69
|
+
fitPadding?: number;
|
|
70
|
+
/** 是否允許平移與縮放,預設 false(完全靜態)。任何情況下都不可選取或編輯。 */
|
|
71
|
+
interactive?: boolean;
|
|
72
|
+
/** 提供時,背景圖改用 `getFilenameFQDN(data.fileName)` 的結果作為圖片網址。 */
|
|
73
|
+
getFilenameFQDN?: (filename: string) => Promise<string> | string;
|
|
74
|
+
className?: string;
|
|
75
|
+
style?: CSSProperties;
|
|
45
76
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { CSSProperties } from 'react';
|
|
1
2
|
import { ViewMode, WMSNodeClickInfo, Map, EditMode, DrawingMode } from '../typings.js';
|
|
2
3
|
import { FlowNode, FlowEdge } from './react-flow.types.js';
|
|
3
4
|
export interface WMSMapModalProps {
|
|
@@ -19,6 +20,13 @@ export interface WMSMapModalProps {
|
|
|
19
20
|
getFilenameFQDN?: (filename: string) => Promise<string> | string;
|
|
20
21
|
maxFileSizeKB?: number;
|
|
21
22
|
warehouseIds?: string[];
|
|
23
|
+
/**
|
|
24
|
+
* 開圖時自動縮放到框住所有節點,預設 true。
|
|
25
|
+
* 只在換到另一張地圖(warehouseIds 改變)或同一張圖第一次拿到非空節點時 fit;
|
|
26
|
+
* 同一張圖的節點增減(編輯後儲存、重新抓資料)不會重新 fit。
|
|
27
|
+
* 換圖時請讓 warehouseIds 不晚於 initialNodes 更新。
|
|
28
|
+
*/
|
|
29
|
+
fitViewOnLoad?: boolean;
|
|
22
30
|
}
|
|
23
31
|
export interface WMSMapContentProps {
|
|
24
32
|
editMode: EditMode;
|
|
@@ -42,4 +50,27 @@ export interface WMSMapContentProps {
|
|
|
42
50
|
getFilenameFQDN?: (filename: string) => Promise<string> | string;
|
|
43
51
|
maxFileSizeKB?: number;
|
|
44
52
|
warehouseIds?: string[];
|
|
53
|
+
/**
|
|
54
|
+
* 開圖時自動縮放到框住所有節點,預設 true。
|
|
55
|
+
* 只在換到另一張地圖(warehouseIds 改變)或同一張圖第一次拿到非空節點時 fit;
|
|
56
|
+
* 同一張圖的節點增減(編輯後儲存、重新抓資料)不會重新 fit。
|
|
57
|
+
* 換圖時請讓 warehouseIds 不晚於 initialNodes 更新。
|
|
58
|
+
*/
|
|
59
|
+
fitViewOnLoad?: boolean;
|
|
60
|
+
}
|
|
61
|
+
export interface WMSMapPreviewProps {
|
|
62
|
+
/** 要顯示的節點(與 WMSMapModal 的 initialNodes 同格式)。 */
|
|
63
|
+
initialNodes: FlowNode[];
|
|
64
|
+
/** 要高亮的範圍節點 id;有值時 fit 只框住這些節點。 */
|
|
65
|
+
highlightIds?: string[];
|
|
66
|
+
/** 有 highlightIds 時是否淡化其餘範圍,預設 true。 */
|
|
67
|
+
dimOthers?: boolean;
|
|
68
|
+
/** fit 時的比例 padding,預設 0.15。 */
|
|
69
|
+
fitPadding?: number;
|
|
70
|
+
/** 是否允許平移與縮放,預設 false(完全靜態)。任何情況下都不可選取或編輯。 */
|
|
71
|
+
interactive?: boolean;
|
|
72
|
+
/** 提供時,背景圖改用 `getFilenameFQDN(data.fileName)` 的結果作為圖片網址。 */
|
|
73
|
+
getFilenameFQDN?: (filename: string) => Promise<string> | string;
|
|
74
|
+
className?: string;
|
|
75
|
+
style?: CSSProperties;
|
|
45
76
|
}
|
|
@@ -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 };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/** 只有範圍節點(矩形、路徑)會被高亮或淡化;背景圖片節點永遠不動。 */ const RANGE_NODE_TYPES = new Set([
|
|
4
|
+
'rectangleNode',
|
|
5
|
+
'pathNode'
|
|
6
|
+
]);
|
|
7
|
+
/** 被淡化(非高亮)範圍的透明度。 */ const PREVIEW_DIMMED_OPACITY = 0.2;
|
|
8
|
+
/** 被高亮範圍的邊框/線寬(一般為 2px)。 */ const PREVIEW_HIGHLIGHT_STROKE_WIDTH = 4;
|
|
9
|
+
/**
|
|
10
|
+
* 依 highlightIds 為範圍節點標記 previewHighlighted / previewDimmed。
|
|
11
|
+
*
|
|
12
|
+
* - 未提供或為空陣列時不做任何標記(回傳原陣列),避免整張圖被淡化。
|
|
13
|
+
* - dimOthers 為 false 時只標記高亮,其餘範圍維持原樣。
|
|
14
|
+
*/ const applyPreviewHighlight = (nodes, highlightIds, dimOthers = true)=>{
|
|
15
|
+
if (!highlightIds || highlightIds.length === 0) {
|
|
16
|
+
return nodes;
|
|
17
|
+
}
|
|
18
|
+
const highlighted = new Set(highlightIds);
|
|
19
|
+
return nodes.map((node)=>{
|
|
20
|
+
if (!RANGE_NODE_TYPES.has(node.type)) {
|
|
21
|
+
return node;
|
|
22
|
+
}
|
|
23
|
+
const isHighlighted = highlighted.has(node.id);
|
|
24
|
+
const isDimmed = dimOthers && !isHighlighted;
|
|
25
|
+
return {
|
|
26
|
+
...node,
|
|
27
|
+
data: {
|
|
28
|
+
...node.data,
|
|
29
|
+
previewHighlighted: isHighlighted,
|
|
30
|
+
previewDimmed: isDimmed
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
});
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
exports.PREVIEW_DIMMED_OPACITY = PREVIEW_DIMMED_OPACITY;
|
|
37
|
+
exports.PREVIEW_HIGHLIGHT_STROKE_WIDTH = PREVIEW_HIGHLIGHT_STROKE_WIDTH;
|
|
38
|
+
exports.applyPreviewHighlight = applyPreviewHighlight;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { FlowNode } from '../types/react-flow.types.cjs';
|
|
2
|
+
/** 被淡化(非高亮)範圍的透明度。 */
|
|
3
|
+
export declare const PREVIEW_DIMMED_OPACITY = 0.2;
|
|
4
|
+
/** 被高亮範圍的邊框/線寬(一般為 2px)。 */
|
|
5
|
+
export declare const PREVIEW_HIGHLIGHT_STROKE_WIDTH = 4;
|
|
6
|
+
/**
|
|
7
|
+
* 依 highlightIds 為範圍節點標記 previewHighlighted / previewDimmed。
|
|
8
|
+
*
|
|
9
|
+
* - 未提供或為空陣列時不做任何標記(回傳原陣列),避免整張圖被淡化。
|
|
10
|
+
* - dimOthers 為 false 時只標記高亮,其餘範圍維持原樣。
|
|
11
|
+
*/
|
|
12
|
+
export declare const applyPreviewHighlight: (nodes: FlowNode[], highlightIds: readonly string[] | undefined, dimOthers?: boolean) => FlowNode[];
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { FlowNode } from '../types/react-flow.types.js';
|
|
2
|
+
/** 被淡化(非高亮)範圍的透明度。 */
|
|
3
|
+
export declare const PREVIEW_DIMMED_OPACITY = 0.2;
|
|
4
|
+
/** 被高亮範圍的邊框/線寬(一般為 2px)。 */
|
|
5
|
+
export declare const PREVIEW_HIGHLIGHT_STROKE_WIDTH = 4;
|
|
6
|
+
/**
|
|
7
|
+
* 依 highlightIds 為範圍節點標記 previewHighlighted / previewDimmed。
|
|
8
|
+
*
|
|
9
|
+
* - 未提供或為空陣列時不做任何標記(回傳原陣列),避免整張圖被淡化。
|
|
10
|
+
* - dimOthers 為 false 時只標記高亮,其餘範圍維持原樣。
|
|
11
|
+
*/
|
|
12
|
+
export declare const applyPreviewHighlight: (nodes: FlowNode[], highlightIds: readonly string[] | undefined, dimOthers?: boolean) => FlowNode[];
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/** 只有範圍節點(矩形、路徑)會被高亮或淡化;背景圖片節點永遠不動。 */ const RANGE_NODE_TYPES = new Set([
|
|
2
|
+
'rectangleNode',
|
|
3
|
+
'pathNode'
|
|
4
|
+
]);
|
|
5
|
+
/** 被淡化(非高亮)範圍的透明度。 */ const PREVIEW_DIMMED_OPACITY = 0.2;
|
|
6
|
+
/** 被高亮範圍的邊框/線寬(一般為 2px)。 */ const PREVIEW_HIGHLIGHT_STROKE_WIDTH = 4;
|
|
7
|
+
/**
|
|
8
|
+
* 依 highlightIds 為範圍節點標記 previewHighlighted / previewDimmed。
|
|
9
|
+
*
|
|
10
|
+
* - 未提供或為空陣列時不做任何標記(回傳原陣列),避免整張圖被淡化。
|
|
11
|
+
* - dimOthers 為 false 時只標記高亮,其餘範圍維持原樣。
|
|
12
|
+
*/ const applyPreviewHighlight = (nodes, highlightIds, dimOthers = true)=>{
|
|
13
|
+
if (!highlightIds || highlightIds.length === 0) {
|
|
14
|
+
return nodes;
|
|
15
|
+
}
|
|
16
|
+
const highlighted = new Set(highlightIds);
|
|
17
|
+
return nodes.map((node)=>{
|
|
18
|
+
if (!RANGE_NODE_TYPES.has(node.type)) {
|
|
19
|
+
return node;
|
|
20
|
+
}
|
|
21
|
+
const isHighlighted = highlighted.has(node.id);
|
|
22
|
+
const isDimmed = dimOthers && !isHighlighted;
|
|
23
|
+
return {
|
|
24
|
+
...node,
|
|
25
|
+
data: {
|
|
26
|
+
...node.data,
|
|
27
|
+
previewHighlighted: isHighlighted,
|
|
28
|
+
previewDimmed: isDimmed
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
});
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export { PREVIEW_DIMMED_OPACITY, PREVIEW_HIGHLIGHT_STROKE_WIDTH, applyPreviewHighlight };
|