@ray-js/robot-map 0.0.8-beta.5 → 0.0.8-beta.7

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.
@@ -66,6 +66,15 @@ const componentOptions = {
66
66
  }
67
67
  }
68
68
  },
69
+ customZones: {
70
+ type: Object,
71
+ value: {},
72
+ observer: function (newValue, oldValue) {
73
+ if (!isEqual(newValue, oldValue) && this.data.initialized && this.render) {
74
+ this.render.onReceiveCustomZones(newValue);
75
+ }
76
+ }
77
+ },
69
78
  spots: {
70
79
  type: Array,
71
80
  observer: function (newValue, oldValue) {
@@ -166,6 +175,9 @@ const componentOptions = {
166
175
  if (this.data.cleanZones) {
167
176
  this.render.onReceiveCleanZones(this.data.cleanZones);
168
177
  }
178
+ if (this.data.customZones) {
179
+ this.render.onReceiveCustomZones(this.data.customZones);
180
+ }
169
181
  if (this.data.virtualWalls) {
170
182
  this.render.onReceiveVirtualWalls(this.data.virtualWalls);
171
183
  }
@@ -99,6 +99,14 @@ export default Render({
99
99
  this.mapInstance.drawCleanZones(zones)
100
100
  },
101
101
 
102
+ // 接收自定义区域(按类型分组)
103
+ onReceiveCustomZones(customZones) {
104
+ if (!this.mapInstance || !customZones) return
105
+ Object.entries(customZones).forEach(([type, zones]) => {
106
+ this.mapInstance.drawCustomZones(type, zones)
107
+ })
108
+ },
109
+
102
110
  // 接收虚拟墙
103
111
  onReceiveVirtualWalls(walls) {
104
112
  if (!this.mapInstance || !walls) return
@@ -1,6 +1,6 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
3
- const _excluded = ["map", "path", "roomProperties", "forbiddenSweepZones", "forbiddenMopZones", "cleanZones", "virtualWalls", "spots", "wayPoints", "detectedObjects", "customElements", "furnitures", "config", "runtime", "onMapReady"];
3
+ const _excluded = ["map", "path", "roomProperties", "forbiddenSweepZones", "forbiddenMopZones", "cleanZones", "customZones", "virtualWalls", "spots", "wayPoints", "detectedObjects", "customElements", "furnitures", "config", "runtime", "onMapReady"];
4
4
  import "core-js/modules/esnext.iterator.constructor.js";
5
5
  import "core-js/modules/esnext.iterator.for-each.js";
6
6
  import "core-js/modules/esnext.iterator.map.js";
@@ -11,6 +11,7 @@ import { MAP_CALLBACK_METHODS, MAP_API_METHODS } from '@ray-js/robot-map-sdk';
11
11
  import { nanoid } from 'nanoid/non-secure';
12
12
  import RjsComponent from './RjsComponent';
13
13
  import { robotMapDefaultProps } from './props';
14
+ import { EXCLUDED_API_METHODS } from './types';
14
15
 
15
16
  // 存储待处理的请求:requestId -> { resolve, reject }
16
17
 
@@ -22,6 +23,7 @@ const RjsRobotMap = _ref => {
22
23
  forbiddenSweepZones = [],
23
24
  forbiddenMopZones = [],
24
25
  cleanZones = [],
26
+ customZones = {},
25
27
  virtualWalls = [],
26
28
  spots = [],
27
29
  wayPoints = [],
@@ -59,6 +61,9 @@ const RjsRobotMap = _ref => {
59
61
  // 在 TS 层创建 mapApi,每个方法返回 Promise
60
62
  const createMapApi = useCallback(() => {
61
63
  const mapApi = MAP_API_METHODS.reduce((acc, methodName) => {
64
+ if (EXCLUDED_API_METHODS.includes(methodName)) {
65
+ return acc;
66
+ }
62
67
  acc[methodName] = function () {
63
68
  for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
64
69
  args[_key2] = arguments[_key2];
@@ -145,6 +150,7 @@ const RjsRobotMap = _ref => {
145
150
  forbiddenSweepZones: forbiddenSweepZones,
146
151
  forbiddenMopZones: forbiddenMopZones,
147
152
  cleanZones: cleanZones,
153
+ customZones: customZones,
148
154
  virtualWalls: virtualWalls,
149
155
  spots: spots,
150
156
  wayPoints: wayPoints,
package/lib/RobotMap.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import React from 'react';
2
2
  import { RobotMapProps } from './props';
3
3
  declare const RobotMap: {
4
- ({ map, path, roomProperties, forbiddenSweepZones, forbiddenMopZones, cleanZones, virtualWalls, spots, wayPoints, detectedObjects, customElements, customCarpets, furnitures, heatmap, onMapReady, config, runtime, ...callbacks }: RobotMapProps): React.JSX.Element;
4
+ ({ map, path, roomProperties, forbiddenSweepZones, forbiddenMopZones, cleanZones, customZones, virtualWalls, spots, wayPoints, detectedObjects, customElements, customCarpets, furnitures, heatmap, onMapReady, config, runtime, ...callbacks }: RobotMapProps): React.JSX.Element;
5
5
  defaultProps: RobotMapProps;
6
6
  displayName: string;
7
7
  };
package/lib/RobotMap.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
2
2
  import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
3
- const _excluded = ["map", "path", "roomProperties", "forbiddenSweepZones", "forbiddenMopZones", "cleanZones", "virtualWalls", "spots", "wayPoints", "detectedObjects", "customElements", "customCarpets", "furnitures", "heatmap", "onMapReady", "config", "runtime"];
3
+ const _excluded = ["map", "path", "roomProperties", "forbiddenSweepZones", "forbiddenMopZones", "cleanZones", "customZones", "virtualWalls", "spots", "wayPoints", "detectedObjects", "customElements", "customCarpets", "furnitures", "heatmap", "onMapReady", "config", "runtime"];
4
4
  import "core-js/modules/esnext.iterator.constructor.js";
5
5
  import "core-js/modules/esnext.iterator.for-each.js";
6
6
  import "core-js/modules/esnext.iterator.map.js";
@@ -14,6 +14,8 @@ import { isEqual } from 'lodash-es';
14
14
  import { MAP_API_METHODS, MAP_CALLBACK_METHODS } from '@ray-js/robot-map-sdk';
15
15
  import { nanoid } from 'nanoid/non-secure';
16
16
  import { robotMapDefaultProps } from './props';
17
+ import { EXCLUDED_API_METHODS } from './types';
18
+
17
19
  // 回调名到事件名的映射
18
20
  const CALLBACK_TO_EVENT_MAP = _objectSpread({
19
21
  onInitialized: 'onInitialized'
@@ -29,6 +31,7 @@ const RobotMap = _ref => {
29
31
  forbiddenSweepZones,
30
32
  forbiddenMopZones,
31
33
  cleanZones,
34
+ customZones,
32
35
  virtualWalls,
33
36
  spots,
34
37
  wayPoints,
@@ -57,6 +60,7 @@ const RobotMap = _ref => {
57
60
  onReceiveForbiddenSweepZones: () => {},
58
61
  onReceiveForbiddenMopZones: () => {},
59
62
  onReceiveCleanZones: () => {},
63
+ onReceiveCustomZones: () => {},
60
64
  onReceiveVirtualWalls: () => {},
61
65
  onReceiveSpots: () => {},
62
66
  onReceiveWayPoints: () => {},
@@ -108,6 +112,7 @@ const RobotMap = _ref => {
108
112
  triggersRef.current.onReceiveForbiddenSweepZones = invoke.current.bind('onReceiveForbiddenSweepZones');
109
113
  triggersRef.current.onReceiveForbiddenMopZones = invoke.current.bind('onReceiveForbiddenMopZones');
110
114
  triggersRef.current.onReceiveCleanZones = invoke.current.bind('onReceiveCleanZones');
115
+ triggersRef.current.onReceiveCustomZones = invoke.current.bind('onReceiveCustomZones');
111
116
  triggersRef.current.onReceiveVirtualWalls = invoke.current.bind('onReceiveVirtualWalls');
112
117
  triggersRef.current.onReceiveSpots = invoke.current.bind('onReceiveSpots');
113
118
  triggersRef.current.onReceiveWayPoints = invoke.current.bind('onReceiveWayPoints');
@@ -124,6 +129,9 @@ const RobotMap = _ref => {
124
129
  invoke.current.define(eventName, function () {
125
130
  if (eventName === 'onInitialized') {
126
131
  const mapApi = MAP_API_METHODS.reduce((acc, methodName) => {
132
+ if (EXCLUDED_API_METHODS.includes(methodName)) {
133
+ return acc;
134
+ }
127
135
  acc[methodName] = invoke.current.bind(methodName);
128
136
  return acc;
129
137
  }, {});
@@ -172,6 +180,14 @@ const RobotMap = _ref => {
172
180
  triggersRef.current.onReceiveCleanZones(cleanZones);
173
181
  }
174
182
  }, [cleanZones, mapApi]);
183
+ useEffect(() => {
184
+ if (mapApi && customZones) {
185
+ Object.entries(customZones).forEach(_ref2 => {
186
+ let [type, zones] = _ref2;
187
+ triggersRef.current.onReceiveCustomZones(type, zones);
188
+ });
189
+ }
190
+ }, [customZones, mapApi]);
175
191
  useEffect(() => {
176
192
  if (mapApi && virtualWalls) {
177
193
  triggersRef.current.onReceiveVirtualWalls(virtualWalls);
package/lib/props.d.ts CHANGED
@@ -49,6 +49,13 @@ export interface RobotMapProps extends MapCallbacks {
49
49
  * @description.en Defines areas where the robot performs cleaning operations.
50
50
  */
51
51
  cleanZones?: ZoneParam[];
52
+ /**
53
+ * @description.zh 自定义区域(按类型分组)
54
+ * @description.en Custom zones grouped by type
55
+ * @description.zh 通过 config.customZoneTypes 声明的自定义区域类型的数据;key 为区域类型名,value 为该类型的 ZoneParam 数组。
56
+ * @description.en Data for custom zone types declared via config.customZoneTypes; keyed by type name, value is an array of ZoneParam for that type.
57
+ */
58
+ customZones?: Record<string, ZoneParam[]>;
52
59
  /**
53
60
  * @description.zh 虚拟墙
54
61
  * @description.en Virtual walls
package/lib/types.d.ts CHANGED
@@ -1,8 +1,17 @@
1
1
  import { MapApi as OriginalMapApi } from '@ray-js/robot-map-sdk';
2
+ /**
3
+ * SDK 侧存在但不暴露给使用方的命令式 API。使用方应通过 props 与运行时配置驱动这些行为。
4
+ * Imperative APIs that exist on the SDK but are intentionally hidden from consumers.
5
+ * Consumers should drive these behaviors via props and runtime config instead.
6
+ */
7
+ export declare const EXCLUDED_API_METHODS: readonly ["drawCustomZones", "clearCustomZones", "setEditingCustomZones"];
8
+ type ExcludedApiMethod = (typeof EXCLUDED_API_METHODS)[number];
9
+ type PublicMapApi = Omit<OriginalMapApi, ExcludedApiMethod>;
2
10
  /**
3
11
  * MapApi 类型定义(所有方法返回 Promise)
4
12
  * MapApi type definition (all methods return Promise)
5
13
  */
6
14
  export type MapApi = {
7
- [K in keyof OriginalMapApi]: OriginalMapApi[K] extends (...args: infer Args) => infer Return ? (...args: Args) => Promise<Return> : OriginalMapApi[K];
15
+ [K in keyof PublicMapApi]: PublicMapApi[K] extends (...args: infer Args) => infer Return ? (...args: Args) => Promise<Return> : PublicMapApi[K];
8
16
  };
17
+ export {};
package/lib/types.js CHANGED
@@ -1 +1,11 @@
1
- export {};
1
+ /**
2
+ * SDK 侧存在但不暴露给使用方的命令式 API。使用方应通过 props 与运行时配置驱动这些行为。
3
+ * Imperative APIs that exist on the SDK but are intentionally hidden from consumers.
4
+ * Consumers should drive these behaviors via props and runtime config instead.
5
+ */
6
+ export const EXCLUDED_API_METHODS = ['drawCustomZones', 'clearCustomZones', 'setEditingCustomZones'];
7
+
8
+ /**
9
+ * MapApi 类型定义(所有方法返回 Promise)
10
+ * MapApi type definition (all methods return Promise)
11
+ */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ray-js/robot-map",
3
- "version": "0.0.8-beta.5",
3
+ "version": "0.0.8-beta.7",
4
4
  "description": "机器人地图组件",
5
5
  "main": "lib/index",
6
6
  "files": [
@@ -33,7 +33,7 @@
33
33
  "@ray-js/ray": "^1.7.39"
34
34
  },
35
35
  "dependencies": {
36
- "@ray-js/robot-map-sdk": "0.0.14-beta.5",
36
+ "@ray-js/robot-map-sdk": "^0.0.14",
37
37
  "clsx": "^1.2.1",
38
38
  "nanoid": "^5.1.6"
39
39
  },