@wenle_2523097/agri-map 1.0.2 → 1.0.4

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.
Files changed (99) hide show
  1. package/dist/components/ConfigProvider/index.d.ts +15 -0
  2. package/dist/components/DualScaleControl/index.d.ts +10 -0
  3. package/dist/components/Icons/SelectIcon.d.ts +68 -0
  4. package/dist/components/Icons/index.d.ts +43 -0
  5. package/dist/components/Irrigation/index.d.ts +8 -0
  6. package/dist/components/Irrigation/toolbar.d.ts +6 -0
  7. package/dist/components/Loading/index.d.ts +40 -0
  8. package/dist/components/MapContent/index.d.ts +17 -0
  9. package/dist/components/MapSizeHandler/index.d.ts +24 -0
  10. package/dist/components/Marker/ClusterView.d.ts +29 -0
  11. package/dist/components/Marker/MapClickHandler.d.ts +25 -0
  12. package/dist/components/Marker/index.d.ts +61 -0
  13. package/dist/components/Marker/parseClusterConfig.d.ts +25 -0
  14. package/dist/components/Marker/toolbar.d.ts +6 -0
  15. package/dist/components/Marker/useEditHandlers.d.ts +44 -0
  16. package/dist/components/Marker/useIconConfig.d.ts +23 -0
  17. package/dist/components/Marker/useMarkerCommands.d.ts +30 -0
  18. package/dist/components/Measurement/toolbar.d.ts +20 -0
  19. package/dist/components/MiniMap/index.d.ts +16 -0
  20. package/dist/components/Notification/index.d.ts +12 -0
  21. package/dist/components/PlotGroupLayer/index.d.ts +8 -0
  22. package/dist/components/PlotLayer/index.d.ts +7 -0
  23. package/dist/components/PlotLayer/label.d.ts +12 -0
  24. package/dist/components/PlotLayer/leaflet-types.d.ts +59 -0
  25. package/dist/components/PlotLayer/parseConfig.d.ts +15 -0
  26. package/dist/components/PlotLayer/toolbar.d.ts +6 -0
  27. package/dist/components/PlotLayer/types.d.ts +10 -0
  28. package/dist/components/PlotLayer/usePlotCommands.d.ts +33 -0
  29. package/dist/components/PlotLayer/usePlotData.d.ts +32 -0
  30. package/dist/components/PlotLayer/usePlotEditMode.d.ts +92 -0
  31. package/dist/components/Road/index.d.ts +8 -0
  32. package/dist/components/Road/toolbar.d.ts +6 -0
  33. package/dist/components/TianDiTuLayer/index.d.ts +15 -0
  34. package/dist/components/Track/ClusterView.d.ts +20 -0
  35. package/dist/components/Track/TrackView.d.ts +24 -0
  36. package/dist/components/Track/commands.d.ts +53 -0
  37. package/dist/components/Track/constants.d.ts +34 -0
  38. package/dist/components/Track/index.d.ts +54 -0
  39. package/dist/components/Track/parseConfig.d.ts +40 -0
  40. package/dist/components/Track/types.d.ts +38 -0
  41. package/dist/components/Track/useMarkerIcon.d.ts +14 -0
  42. package/dist/components/Track/useTrackCommands.d.ts +56 -0
  43. package/dist/components/shared/BaseEditToolbar.d.ts +100 -0
  44. package/dist/components/shared/ToolbarButton.d.ts +49 -0
  45. package/dist/components/shared/index.d.ts +5 -0
  46. package/dist/constants/device.d.ts +14 -0
  47. package/dist/constants/index.d.ts +20 -0
  48. package/dist/constants/map.d.ts +13 -0
  49. package/dist/constants/plot.d.ts +33 -0
  50. package/dist/constants/road.d.ts +12 -0
  51. package/dist/constants/styles.d.ts +57 -0
  52. package/dist/constants/theme.d.ts +47 -0
  53. package/dist/constants/unit.d.ts +11 -0
  54. package/dist/hooks/index.d.ts +8 -0
  55. package/dist/hooks/useEditMode.d.ts +75 -0
  56. package/dist/hooks/useLatestRef.d.ts +17 -0
  57. package/dist/hooks/usePolylineEditor.d.ts +65 -0
  58. package/dist/hooks/usePolylineRenderer.d.ts +34 -0
  59. package/dist/hooks/useTheme.d.ts +13 -0
  60. package/dist/index.d.ts +312 -0
  61. package/dist/index.esm.js +30 -0
  62. package/dist/index.esm.js.map +1 -1
  63. package/dist/index.js +30 -0
  64. package/dist/index.js.map +1 -1
  65. package/dist/index.umd.js +30 -0
  66. package/dist/index.umd.js.map +1 -1
  67. package/dist/types/basic.d.ts +57 -0
  68. package/dist/types/components.d.ts +56 -0
  69. package/dist/types/config.d.ts +112 -0
  70. package/dist/types/decorator.d.ts +26 -0
  71. package/dist/types/icon.d.ts +52 -0
  72. package/dist/types/index.d.ts +20 -0
  73. package/dist/types/irrigation.d.ts +315 -0
  74. package/dist/types/layer.d.ts +40 -0
  75. package/dist/types/loading.d.ts +62 -0
  76. package/dist/types/marker.d.ts +299 -0
  77. package/dist/types/measurement.d.ts +121 -0
  78. package/dist/types/notification.d.ts +50 -0
  79. package/dist/types/plot.d.ts +479 -0
  80. package/dist/types/road.d.ts +382 -0
  81. package/dist/types/toolbar.d.ts +176 -0
  82. package/dist/types/track.d.ts +386 -0
  83. package/dist/utils/area.d.ts +57 -0
  84. package/dist/utils/clusterIcon.d.ts +16 -0
  85. package/dist/utils/createAntPath.d.ts +13 -0
  86. package/dist/utils/geometry.d.ts +41 -0
  87. package/dist/utils/iconCache.d.ts +49 -0
  88. package/dist/utils/iconUtils.d.ts +46 -0
  89. package/dist/utils/index.d.ts +11 -0
  90. package/dist/utils/leafletIcons.d.ts +40 -0
  91. package/dist/utils/mapAnimation.d.ts +14 -0
  92. package/dist/utils/markerSvg.d.ts +19 -0
  93. package/dist/utils/pulseIcon.d.ts +28 -0
  94. package/dist/utils/spatialIndex.d.ts +56 -0
  95. package/dist/utils/toggleItemState.d.ts +15 -0
  96. package/dist/utils/trackSimplify.d.ts +23 -0
  97. package/package.json +7 -3
  98. package/dist/index.css +0 -4635
  99. package/dist/index.css.map +0 -1
@@ -0,0 +1,49 @@
1
+ /**
2
+ * 工具栏按钮组件
3
+ * @description 提供统一样式的工具栏按钮,避免与 Ant Design Button 命名冲突
4
+ */
5
+ import type { ButtonVariant, ToolbarSize, ToolbarColor } from './BaseEditToolbar';
6
+ export interface ToolbarButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
7
+ /** 按钮样式变体(兼容,优先使用 color) */
8
+ variant?: ButtonVariant;
9
+ /** 按钮颜色 */
10
+ color?: ToolbarColor;
11
+ /** 按钮尺寸 */
12
+ size?: ToolbarSize;
13
+ /** 图标 */
14
+ icon?: React.ReactNode;
15
+ /** 是否禁用 */
16
+ disabled?: boolean;
17
+ /** 是否仅显示图标(不显示文字) */
18
+ iconOnly?: boolean;
19
+ /** 类名前缀(可选,默认从 Context 获取) */
20
+ classPrefix?: string;
21
+ /** 子元素 */
22
+ children?: React.ReactNode;
23
+ }
24
+ /**
25
+ * 工具栏按钮组件
26
+ * @description 提供与 BaseEditToolbar 按钮一致的样式
27
+ *
28
+ * @example
29
+ * ```tsx
30
+ * // 在 Marker 组件中使用
31
+ * <Marker
32
+ * editMode={{
33
+ * enabled: ['create', 'move', 'delete'],
34
+ * toolbar: (
35
+ * <ToolbarButton variant="primary" onClick={() => console.log('clicked')}>
36
+ * 自定义按钮
37
+ * </ToolbarButton>
38
+ * )
39
+ * }}
40
+ * />
41
+ *
42
+ * // 带图标
43
+ * <ToolbarButton variant="danger" icon={<DeleteIcon />}>
44
+ * 删除
45
+ * </ToolbarButton>
46
+ * ```
47
+ */
48
+ declare const ToolbarButton: import("react").ForwardRefExoticComponent<ToolbarButtonProps & import("react").RefAttributes<HTMLButtonElement>>;
49
+ export default ToolbarButton;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * 共享组件导出
3
+ */
4
+ export { default as BaseEditToolbar, type BaseEditToolbarProps, type BaseEditToolbarRef, type ButtonVariant, type ToolbarColor, type ToolbarPresetColors, type ToolbarSize, ToolbarContext, useToolbarContext } from './BaseEditToolbar';
5
+ export { default as ToolbarButton, type ToolbarButtonProps } from './ToolbarButton';
@@ -0,0 +1,14 @@
1
+ /**
2
+ * 设备相关常量定义
3
+ */
4
+ /** 设备类型枚举值映射 */
5
+ export declare const DeviceType: {
6
+ readonly TRACTOR: "tractor";
7
+ readonly HARVESTER: "harvester";
8
+ readonly SEEDER: "seeder";
9
+ readonly SPRAYER: "sprayer";
10
+ readonly DRONE: "drone";
11
+ readonly OTHER: "other";
12
+ };
13
+ /** 设备类型颜色配置 */
14
+ export declare const DEVICE_TYPE_COLORS: Record<string, string>;
@@ -0,0 +1,20 @@
1
+ /**
2
+ * 常量定义
3
+ * @description 组件库中使用的各种常量配置
4
+ *
5
+ * 按领域拆分的常量模块:
6
+ * - plot.ts: 地块相关常量
7
+ * - road.ts: 道路相关常量
8
+ * - device.ts: 设备相关常量
9
+ * - map.ts: 地图配置常量
10
+ * - unit.ts: 单位换算常量
11
+ * - theme.ts: 主题配置常量
12
+ * - styles.ts: 默认 PathOptions 样式常量
13
+ */
14
+ export { PlotType, PlotStatus, PLOT_TYPE_COLORS, getPlotTypeColor, type PlotTypeColorConfig, } from './plot';
15
+ export { RoadType, ROAD_TYPE_STYLES, } from './road';
16
+ export { DeviceType, DEVICE_TYPE_COLORS, } from './device';
17
+ export { DEFAULT_MAP_CONFIG, } from './map';
18
+ export { UNIT_CONVERSION, } from './unit';
19
+ export { THEME_CONFIG, THEME_CSS_VARS, getThemeColors, type ThemeMode, type ThemeColors, } from './theme';
20
+ export { PLOT_DEFAULT_PATH, PLOT_DEFAULT_SELECTED_PATH, PLOT_DEFAULT_EDIT_PATH, PLOT_DEFAULT_HIGHLIGHT_PATH, PLOT_FALLBACK_PATH, PLOT_PM_CREATE_OPTIONS, PLOT_CLIP_FRAGMENT_DEFAULT, PLOT_CLIP_FRAGMENT_SELECTED, ROAD_DEFAULT_PATH, ROAD_DEFAULT_SELECTED_PATH, ROAD_PM_PATH_OPTIONS, IRRIGATION_DEFAULT_PATH, IRRIGATION_DEFAULT_SELECTED_PATH, IRRIGATION_PM_PATH_OPTIONS, PM_TEMPLATE_LINE_STYLE, PM_HINT_LINE_STYLE, PM_DRAW_COMMON_OPTIONS, } from './styles';
@@ -0,0 +1,13 @@
1
+ /**
2
+ * 地图配置常量定义
3
+ */
4
+ /**
5
+ * 默认地图配置
6
+ */
7
+ export declare const DEFAULT_MAP_CONFIG: {
8
+ readonly DEFAULT_CENTER: [number, number];
9
+ readonly DEFAULT_ZOOM: 13;
10
+ readonly MIN_ZOOM: 3;
11
+ readonly MAX_ZOOM: 18;
12
+ readonly TILE_LAYER_URL: "https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png";
13
+ };
@@ -0,0 +1,33 @@
1
+ /**
2
+ * 地块相关常量定义
3
+ */
4
+ /** 地块类型枚举值映射 */
5
+ export declare const PlotType: {
6
+ readonly FARMLAND: "farmland";
7
+ readonly VEGETABLE: "vegetable";
8
+ readonly ORCHARD: "orchard";
9
+ readonly FOREST: "forest";
10
+ readonly GRASSLAND: "grassland";
11
+ readonly PADDY: "paddy";
12
+ readonly GREENHOUSE: "greenhouse";
13
+ };
14
+ /** 地块状态枚举值映射 */
15
+ export declare const PlotStatus: {
16
+ readonly CULTIVATING: "cultivating";
17
+ readonly FALLOW: "fallow";
18
+ readonly HARVESTING: "harvesting";
19
+ readonly PLANTING: "planting";
20
+ readonly IRRIGATING: "irrigating";
21
+ };
22
+ /** 地块类型颜色配置 */
23
+ export interface PlotTypeColorConfig {
24
+ fillColor: string;
25
+ color: string;
26
+ }
27
+ export declare const PLOT_TYPE_COLORS: Record<string, PlotTypeColorConfig>;
28
+ /**
29
+ * 根据地块类型获取颜色配置
30
+ * @param type - 地块类型
31
+ * @returns 颜色配置 { fillColor, color }
32
+ */
33
+ export declare const getPlotTypeColor: (type: string | undefined) => PlotTypeColorConfig;
@@ -0,0 +1,12 @@
1
+ /**
2
+ * 道路相关常量定义
3
+ */
4
+ import type { PathOptions } from '../types';
5
+ /** 道路类型枚举值映射 */
6
+ export declare const RoadType: {
7
+ readonly MAIN: "main";
8
+ readonly SECONDARY: "secondary";
9
+ readonly FOOTPATH: "footpath";
10
+ };
11
+ /** 道路类型样式配置 */
12
+ export declare const ROAD_TYPE_STYLES: Record<string, PathOptions>;
@@ -0,0 +1,57 @@
1
+ /**
2
+ * 默认 PathOptions 样式常量
3
+ * @description 集中管理各组件的默认视觉样式,便于全局统一调整
4
+ *
5
+ * ⚠️ 颜色值必须与 src/styles/_variables.scss 中的语义色变量保持同步:
6
+ * PLOT_DEFAULT_PATH.color/fillColor → $color-plot (#1668dc)
7
+ * PLOT_DEFAULT_SELECTED_PATH.color/fillColor → $color-plot-selected (#d32029)
8
+ * PLOT_DEFAULT_EDIT_PATH.color/fillColor → $color-plot-edit (#faad14)
9
+ * PLOT_DEFAULT_HIGHLIGHT_PATH.color/fillColor → $color-plot-highlight (#fa8c16)
10
+ * ROAD_PM_PATH_OPTIONS.color → $color-road-edit (#8B4513)
11
+ * IRRIGATION_DEFAULT_PATH.color → $color-irrigation (#1E90FF)
12
+ * IRRIGATION_PM_PATH_OPTIONS.color → $color-irrigation (#1E90FF)
13
+ * PM_*.color / IRRIGATION_DEFAULT_SELECTED_PATH.color → $color-primary (#1677ff)
14
+ * PLOT_CLIP_FRAGMENT_*.color → $color-success (#52c41a)
15
+ */
16
+ import type { PathOptions } from '../types';
17
+ /** 地块默认样式 */
18
+ export declare const PLOT_DEFAULT_PATH: PathOptions;
19
+ /** 地块选中样式 */
20
+ export declare const PLOT_DEFAULT_SELECTED_PATH: PathOptions;
21
+ /** 地块编辑样式 */
22
+ export declare const PLOT_DEFAULT_EDIT_PATH: PathOptions;
23
+ /** 地块高亮样式(分组高亮) */
24
+ export declare const PLOT_DEFAULT_HIGHLIGHT_PATH: PathOptions;
25
+ /** 地块无类型时的回退样式 */
26
+ export declare const PLOT_FALLBACK_PATH: PathOptions;
27
+ /** 地块新建绘制时的 PM 样式 */
28
+ export declare const PLOT_PM_CREATE_OPTIONS: PathOptions;
29
+ /** 地块剪切碎片默认样式 */
30
+ export declare const PLOT_CLIP_FRAGMENT_DEFAULT: PathOptions;
31
+ /** 地块剪切碎片选中样式 */
32
+ export declare const PLOT_CLIP_FRAGMENT_SELECTED: PathOptions;
33
+ /** 道路默认样式 */
34
+ export declare const ROAD_DEFAULT_PATH: PathOptions;
35
+ /** 道路选中样式 */
36
+ export declare const ROAD_DEFAULT_SELECTED_PATH: PathOptions;
37
+ /** 道路编辑样式 */
38
+ export declare const ROAD_DEFAULT_EDIT_PATH: PathOptions;
39
+ /** 道路 PM 编辑器全局样式 */
40
+ export declare const ROAD_PM_PATH_OPTIONS: PathOptions;
41
+ /** 灌溉渠默认样式 */
42
+ export declare const IRRIGATION_DEFAULT_PATH: PathOptions;
43
+ /** 灌溉渠选中样式 */
44
+ export declare const IRRIGATION_DEFAULT_SELECTED_PATH: PathOptions;
45
+ /** 灌溉渠编辑样式 */
46
+ export declare const IRRIGATION_DEFAULT_EDIT_PATH: PathOptions;
47
+ /** 灌溉渠 PM 编辑器全局样式 */
48
+ export declare const IRRIGATION_PM_PATH_OPTIONS: PathOptions;
49
+ /** PM 绘制时的临时线样式(templineStyle) */
50
+ export declare const PM_TEMPLATE_LINE_STYLE: PathOptions;
51
+ /** PM 绘制时的提示线样式(hintlineStyle) */
52
+ export declare const PM_HINT_LINE_STYLE: PathOptions;
53
+ /** PM 绘制公共配置(snappable / snapDistance) */
54
+ export declare const PM_DRAW_COMMON_OPTIONS: {
55
+ readonly snappable: true;
56
+ readonly snapDistance: 20;
57
+ };
@@ -0,0 +1,47 @@
1
+ /**
2
+ * 主题配置常量
3
+ * @description 集中管理所有主题相关的颜色和样式配置
4
+ *
5
+ * ⚠️ 颜色值必须与 src/styles/_variables.scss 中的主题变量保持同步:
6
+ * light.controlBg → $theme-light-control-bg
7
+ * light.primaryColor → $theme-light-primary / $color-primary
8
+ * dark.controlBg → $theme-dark-control-bg
9
+ * dark.primaryColor → $theme-dark-primary / $dark-color-primary
10
+ */
11
+ /**
12
+ * 主题模式类型
13
+ */
14
+ export type ThemeMode = 'light' | 'dark';
15
+ /**
16
+ * 主题颜色配置接口
17
+ * @deprecated 请使用 CSS 变量或 SCSS 变量获取主题颜色,此接口将在下个大版本移除
18
+ */
19
+ export interface ThemeColors {
20
+ /** 控件背景色 */
21
+ controlBg: string;
22
+ /** 控件文字颜色 */
23
+ controlText: string;
24
+ /** 主色调 */
25
+ primaryColor: string;
26
+ /** 边框颜色 */
27
+ borderColor: string;
28
+ /** 阴影颜色 */
29
+ shadowColor: string;
30
+ }
31
+ /**
32
+ * 主题配置映射
33
+ * @deprecated 请使用 CSS 变量或 SCSS 变量获取主题颜色,此接口将在下个大版本移除
34
+ */
35
+ export declare const THEME_CONFIG: Record<ThemeMode, ThemeColors>;
36
+ /**
37
+ * 根据主题获取颜色配置
38
+ * @deprecated 请使用 CSS 变量或 SCSS 变量获取主题颜色,此函数将在下个大版本移除
39
+ * @param theme 主题模式
40
+ * @returns 主题颜色配置
41
+ */
42
+ export declare const getThemeColors: (theme: ThemeMode) => ThemeColors;
43
+ /**
44
+ * CSS 变量映射(用于 JS 运行时设置 CSS 变量给非 Leaflet 控件)
45
+ * ⚠️ 值必须与 src/styles/_variables.scss 保持同步
46
+ */
47
+ export declare const THEME_CSS_VARS: Record<ThemeMode, Record<string, string>>;
@@ -0,0 +1,11 @@
1
+ /**
2
+ * 单位换算常量定义
3
+ */
4
+ /**
5
+ * 单位换算常量
6
+ */
7
+ export declare const UNIT_CONVERSION: {
8
+ readonly SQUARE_METERS_TO_MU: 0.0015;
9
+ readonly MU_TO_SQUARE_METERS: 666.67;
10
+ readonly EARTH_RADIUS: 6371000;
11
+ };
@@ -0,0 +1,8 @@
1
+ /**
2
+ * 自定义 Hooks 导出
3
+ */
4
+ export { useLatestRef } from './useLatestRef';
5
+ export { useEditMode, type EditModeConfig, type EditModeResult } from './useEditMode';
6
+ export { useTheme } from './useTheme';
7
+ export { usePolylineRenderer } from './usePolylineRenderer';
8
+ export { usePolylineEditor, usePolylineSave } from './usePolylineEditor';
@@ -0,0 +1,75 @@
1
+ /**
2
+ * 解析编辑模式的 Hook
3
+ * @description 统一处理各组件的 editMode 属性解析逻辑
4
+ */
5
+ import type { ReactNode } from 'react';
6
+ import type { ToolbarColor, ToolbarSize } from '../components/shared/BaseEditToolbar';
7
+ /**
8
+ * 编辑模式对象配置
9
+ */
10
+ export interface EditModeObjectConfig<T extends string> {
11
+ /** 启用的编辑按钮 */
12
+ enabled?: boolean | T[];
13
+ /** 自定义工具栏内容 */
14
+ toolbar?: ReactNode;
15
+ /** 内置按钮的统一颜色(支持预设色和自定义颜色) */
16
+ color?: ToolbarColor;
17
+ /** 内置按钮的统一尺寸(支持预设尺寸和自定义数字) */
18
+ size?: ToolbarSize;
19
+ /** 是否仅显示图标(不显示文字) */
20
+ iconOnly?: boolean;
21
+ }
22
+ /**
23
+ * 编辑模式类型
24
+ * - `false`: 禁用编辑
25
+ * - `true`: 启用全部编辑功能
26
+ * - `T[]`: 启用指定的编辑按钮
27
+ * - `EditModeObjectConfig<T>`: 对象配置,支持自定义工具栏
28
+ */
29
+ export type EditModeConfig<T extends string> = boolean | T[] | EditModeObjectConfig<T>;
30
+ /**
31
+ * 编辑模式解析结果
32
+ */
33
+ export interface EditModeResult<T extends string> {
34
+ /** 是否启用编辑模式 */
35
+ editEnabled: boolean;
36
+ /** 启用的按钮列表 */
37
+ enabledButtons: T[];
38
+ /** 自定义工具栏内容 */
39
+ customToolbar?: ReactNode;
40
+ /** 内置按钮的统一颜色 */
41
+ color?: ToolbarColor;
42
+ /** 内置按钮的统一尺寸 */
43
+ size?: ToolbarSize;
44
+ /** 是否仅显示图标 */
45
+ iconOnly?: boolean;
46
+ }
47
+ /**
48
+ * 解析编辑模式配置
49
+ * @param editModeProp 编辑模式属性值
50
+ * @param defaultButtons 当 editMode 为 true 时默认启用的按钮
51
+ * @returns EditModeResult
52
+ *
53
+ * @example
54
+ * ```ts
55
+ * // PlotLayer
56
+ * const { editEnabled, enabledButtons } = useEditMode(
57
+ * editModeProp,
58
+ * ['redraw', 'clip', 'move', 'create', 'delete'] as const
59
+ * );
60
+ *
61
+ * // Marker
62
+ * const { editEnabled, enabledButtons } = useEditMode(
63
+ * editModeProp,
64
+ * ['create', 'move', 'delete'] as const
65
+ * );
66
+ *
67
+ * // 使用对象配置
68
+ * const { editEnabled, enabledButtons, customToolbar } = useEditMode(
69
+ * { enabled: ['create', 'move'], toolbar: <Button>自定义</Button> },
70
+ * ['create', 'move', 'delete'] as const
71
+ * );
72
+ * ```
73
+ */
74
+ export declare function useEditMode<T extends string>(editModeProp: EditModeConfig<T> | undefined, defaultButtons: readonly T[]): EditModeResult<T>;
75
+ export default useEditMode;
@@ -0,0 +1,17 @@
1
+ /**
2
+ * 保持 ref 始终指向最新值的 Hook
3
+ * @description 用于在回调中访问最新值,避免闭包陷阱
4
+ */
5
+ /**
6
+ * 返回一个 ref,其 current 始终指向传入的最新值
7
+ * @param value 需要保持引用的值
8
+ * @returns React.MutableRefObject<T>
9
+ *
10
+ * @example
11
+ * ```ts
12
+ * const onClickRef = useLatestRef(onClick);
13
+ * // 在回调中使用 onClickRef.current
14
+ * ```
15
+ */
16
+ export declare function useLatestRef<T>(value: T): import("react").MutableRefObject<T>;
17
+ export default useLatestRef;
@@ -0,0 +1,65 @@
1
+ /**
2
+ * 折线编辑器状态管理 Hook
3
+ *
4
+ * 封装 Irrigation / Road 等折线类组件共享的编辑状态机逻辑:
5
+ * - currentMode / tempPoints 状态管理
6
+ * - pendingCreate 流程(新建 → 保存 → 抽屉 → 完成/取消)
7
+ * - handleCancel(清理编辑状态)
8
+ * - Escape 快捷键取消
9
+ * - normalizedData 变化时自动重置 pendingCreate 状态
10
+ * - pm:create / pm:edit 事件监听
11
+ */
12
+ import L from 'leaflet';
13
+ import type { Coordinate } from '../types';
14
+ export interface UsePolylineEditorOptions {
15
+ /** Leaflet 地图实例 */
16
+ map: L.Map;
17
+ /** 编辑中的图层引用(由组件持有,类型各不相同) */
18
+ editingLayerRef: React.MutableRefObject<L.Polyline | null>;
19
+ /** 标准化后的数据源,用于检测 pendingCreate 保存后的数据变化 */
20
+ normalizedData: unknown[];
21
+ /** Whether PM event listeners (pm:create, pm:edit, etc.) should be active. Default: true */
22
+ pmEventsEnabled?: boolean;
23
+ /** Called when pm:create fires. Use this to convert the drawn layer type (e.g., asIrrigationLayer). */
24
+ onDrawnLayer?: (drawnLayer: L.Polyline) => void;
25
+ /** Optional runtime guard for pm:create event. Return false to skip handling. */
26
+ pmCreateGuard?: () => boolean;
27
+ }
28
+ export interface UsePolylineEditorReturn {
29
+ /** 当前编辑模式 */
30
+ currentMode: 'idle' | 'create' | 'edit';
31
+ /** 设置当前编辑模式 */
32
+ setCurrentMode: React.Dispatch<React.SetStateAction<'idle' | 'create' | 'edit'>>;
33
+ /** 临时坐标点(绘制/编辑中的坐标) */
34
+ tempPoints: Coordinate[];
35
+ /** 设置临时坐标点 */
36
+ setTempPoints: React.Dispatch<React.SetStateAction<Coordinate[]>>;
37
+ /** 新建待提交标记 ref(详见各组件中 pendingCreateRef 注释) */
38
+ pendingCreateRef: React.MutableRefObject<boolean>;
39
+ /** 编辑前原始坐标 ref */
40
+ originalPointsRef: React.MutableRefObject<Coordinate[] | null>;
41
+ /** currentMode 的最新引用(用于在回调和事件处理中读取最新值) */
42
+ currentModeRef: React.MutableRefObject<'idle' | 'create' | 'edit'>;
43
+ /** 取消操作:清理所有编辑状态 */
44
+ handleCancel: () => void;
45
+ }
46
+ export declare function usePolylineEditor(options: UsePolylineEditorOptions): UsePolylineEditorReturn;
47
+ export interface UsePolylineSaveOptions {
48
+ map: L.Map;
49
+ currentMode: 'idle' | 'create' | 'edit';
50
+ tempPoints: Coordinate[];
51
+ value: string | number | null;
52
+ editingLayerRef: React.MutableRefObject<L.Polyline | null>;
53
+ pendingCreateRef: React.MutableRefObject<boolean>;
54
+ originalPointsRef: React.MutableRefObject<Coordinate[] | null>;
55
+ layerByIdRef: React.MutableRefObject<Record<string | number, L.Polyline>>;
56
+ setCurrentMode: React.Dispatch<React.SetStateAction<'idle' | 'create' | 'edit'>>;
57
+ setTempPoints: React.Dispatch<React.SetStateAction<Coordinate[]>>;
58
+ /** Called when create save is triggered with the new points */
59
+ onCreateSave: (points: Coordinate[]) => void;
60
+ /** Called when edit save is triggered with id, oldPoints, newPoints */
61
+ onEditSave: (id: string | number, oldPoints: Coordinate[], newPoints: Coordinate[]) => void;
62
+ }
63
+ export declare function usePolylineSave(options: UsePolylineSaveOptions): {
64
+ handleSave: () => void;
65
+ };
@@ -0,0 +1,34 @@
1
+ /**
2
+ * @fileoverview 线要素渲染 hook(共享逻辑)
3
+ * @description 提取 Irrigation 和 Road 组件中重复的图层管理逻辑:
4
+ * - 主渲染 useEffect 的图层创建/销毁/编辑模式过滤
5
+ * - 组件卸载时清理编辑图层 (editingLayerRef)
6
+ * @module hooks/usePolylineRenderer
7
+ */
8
+ import { type MutableRefObject } from 'react';
9
+ import L from 'leaflet';
10
+ interface UsePolylineRendererOptions {
11
+ map: L.Map | null;
12
+ normalizedData: any[];
13
+ value: string | number | null;
14
+ currentMode: 'idle' | 'create' | 'edit';
15
+ /** 渲染单条数据到 layerGroup 中 */
16
+ renderItem: (item: any, layerGroup: L.LayerGroup, index: number) => void;
17
+ layerGroupRef: MutableRefObject<L.LayerGroup | null>;
18
+ layerByIdRef: MutableRefObject<Record<string | number, any>>;
19
+ editingLayerRef: MutableRefObject<any | null>;
20
+ deps: any[];
21
+ }
22
+ /**
23
+ * 管理线要素图层的创建与清理
24
+ *
25
+ * 负责:
26
+ * 1. 编辑模式下过滤数据(create/edit 模式不渲染已有要素)
27
+ * 2. 创建 LayerGroup 并将数据渲染进去
28
+ * 3. 组件卸载时移除 editingLayerRef
29
+ *
30
+ * 注意:editingLayerRef 的日常生命周期(handleRedraw/handleEdit 创建、
31
+ * handleCancel/handleSave 销毁)由组件自行管理,此 hook 仅在组件卸载时兜底清理。
32
+ */
33
+ export declare function usePolylineRenderer(options: UsePolylineRendererOptions): void;
34
+ export {};
@@ -0,0 +1,13 @@
1
+ /**
2
+ * 主题 Hook
3
+ * @description 提供统一的主题访问接口
4
+ */
5
+ import { type ThemeMode, type ThemeColors } from '../constants/theme';
6
+ /**
7
+ * 获取当前主题及颜色配置的 Hook
8
+ * @returns 主题模式和颜色配置
9
+ */
10
+ export declare const useTheme: () => {
11
+ theme: ThemeMode;
12
+ colors: ThemeColors;
13
+ };