@ray-js/robot-map 0.0.8 → 0.0.9-beta.10

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.
@@ -115,6 +115,14 @@ const componentOptions = {
115
115
  }
116
116
  }
117
117
  },
118
+ customCarpets: {
119
+ type: Array,
120
+ observer: function (newValue, oldValue) {
121
+ if (!isEqual(newValue, oldValue) && this.data.initialized && this.render) {
122
+ this.render.onReceiveCustomCarpets(newValue);
123
+ }
124
+ }
125
+ },
118
126
  furnitures: {
119
127
  type: Array,
120
128
  observer: function (newValue, oldValue) {
@@ -193,6 +201,9 @@ const componentOptions = {
193
201
  if (this.data.customElements) {
194
202
  this.render.onReceiveCustomElements(this.data.customElements);
195
203
  }
204
+ if (this.data.customCarpets) {
205
+ this.render.onReceiveCustomCarpets(this.data.customCarpets);
206
+ }
196
207
  if (this.data.furnitures) {
197
208
  this.render.onReceiveFurnitures(this.data.furnitures);
198
209
  }
@@ -137,6 +137,12 @@ export default Render({
137
137
  this.mapInstance.drawCustomElements(elements)
138
138
  },
139
139
 
140
+ // 接收自定义地毯
141
+ onReceiveCustomCarpets(carpets) {
142
+ if (!this.mapInstance || !carpets) return
143
+ this.mapInstance.drawCustomCarpets(carpets)
144
+ },
145
+
140
146
  // 接收家具
141
147
  onReceiveFurnitures(furnitures) {
142
148
  if (!this.mapInstance || !furnitures) 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", "customZones", "virtualWalls", "spots", "wayPoints", "detectedObjects", "customElements", "furnitures", "config", "runtime", "onMapReady"];
3
+ const _excluded = ["map", "path", "roomProperties", "forbiddenSweepZones", "forbiddenMopZones", "cleanZones", "customZones", "virtualWalls", "spots", "wayPoints", "detectedObjects", "customElements", "customCarpets", "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";
@@ -29,6 +29,7 @@ const RjsRobotMap = _ref => {
29
29
  wayPoints = [],
30
30
  detectedObjects = [],
31
31
  customElements = [],
32
+ customCarpets = [],
32
33
  furnitures = [],
33
34
  config,
34
35
  runtime,
@@ -156,6 +157,7 @@ const RjsRobotMap = _ref => {
156
157
  wayPoints: wayPoints,
157
158
  detectedObjects: detectedObjects,
158
159
  customElements: customElements,
160
+ customCarpets: customCarpets,
159
161
  furnitures: furnitures,
160
162
  config: config,
161
163
  runtime: runtime,
package/lib/RobotMap.js CHANGED
@@ -15,6 +15,7 @@ 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
17
  import { EXCLUDED_API_METHODS } from './types';
18
+ import { createAppLoggerBridge } from './appLoggerBridge';
18
19
 
19
20
  // 回调名到事件名的映射
20
21
  const CALLBACK_TO_EVENT_MAP = _objectSpread({
@@ -49,6 +50,7 @@ const RobotMap = _ref => {
49
50
  const prevConfigRef = useRef(null);
50
51
  const prevRuntimeRef = useRef(null);
51
52
  const hasSkippedInitialConfigUpdateRef = useRef(false);
53
+ const appLoggerBridgeRef = useRef(createAppLoggerBridge());
52
54
  const webviewId = useRef(nanoid()).current;
53
55
  const webviewContext = useRef(null);
54
56
  const invoke = useRef(null);
@@ -144,6 +146,9 @@ const RobotMap = _ref => {
144
146
  eventDispatcher(eventName, ...args);
145
147
  });
146
148
  });
149
+ invoke.current.define('onAppLogger', payload => {
150
+ appLoggerBridgeRef.current(payload);
151
+ });
147
152
  }, []);
148
153
  useEffect(() => {
149
154
  if (mapApi && map) {
@@ -0,0 +1,2 @@
1
+ import type { LoggerPayload } from './props';
2
+ export declare function createAppLoggerBridge(): (payload: LoggerPayload) => void;
@@ -0,0 +1,86 @@
1
+ import "core-js/modules/es.json.stringify.js";
2
+ import "core-js/modules/esnext.iterator.constructor.js";
3
+ import "core-js/modules/esnext.iterator.filter.js";
4
+ import "core-js/modules/esnext.iterator.map.js";
5
+ import "core-js/modules/web.dom-collections.iterator.js";
6
+ const APP_LOG_TAG = 'ray-robot-map';
7
+ const MAX_MESSAGE_LENGTH = 10 * 1024;
8
+ function stringifyDatum(value) {
9
+ if (typeof value === 'string') {
10
+ return value;
11
+ }
12
+ try {
13
+ var _JSON$stringify;
14
+ return (_JSON$stringify = JSON.stringify(value)) !== null && _JSON$stringify !== void 0 ? _JSON$stringify : String(value);
15
+ } catch (_unused) {
16
+ return String(value);
17
+ }
18
+ }
19
+ function buildMessage(payload) {
20
+ const detail = payload.data.map(stringifyDatum).filter(part => part.length > 0).join(', ');
21
+ const text = "\u3010".concat(APP_LOG_TAG, "\u3011: [MapSDK][").concat(payload.tag, "] ").concat(payload.message).concat(detail ? ", ".concat(detail) : '');
22
+ return text.length > MAX_MESSAGE_LENGTH ? text.slice(0, MAX_MESSAGE_LENGTH) : text;
23
+ }
24
+ export function createAppLoggerBridge() {
25
+ const managerCache = new Map();
26
+ let warned = false;
27
+ let isDevtools;
28
+ const warnOnce = error => {
29
+ if (warned) {
30
+ return;
31
+ }
32
+ warned = true;
33
+ console.warn('[ray-robot-map] app logger bridge failed', error);
34
+ };
35
+ const resolveDevtools = () => {
36
+ if (isDevtools !== undefined) {
37
+ return isDevtools;
38
+ }
39
+ try {
40
+ var _ty, _ty$getSystemInfoSync;
41
+ isDevtools = ((_ty = globalThis.ty) === null || _ty === void 0 || (_ty$getSystemInfoSync = _ty.getSystemInfoSync) === null || _ty$getSystemInfoSync === void 0 ? void 0 : _ty$getSystemInfoSync.call(_ty).brand) === 'devtools';
42
+ } catch (_unused2) {
43
+ isDevtools = false;
44
+ }
45
+ return isDevtools;
46
+ };
47
+ const resolveManager = tag => {
48
+ if (managerCache.has(tag)) {
49
+ var _managerCache$get;
50
+ return (_managerCache$get = managerCache.get(tag)) !== null && _managerCache$get !== void 0 ? _managerCache$get : null;
51
+ }
52
+ try {
53
+ var _ty$getLogManager, _ty2, _ty2$getLogManager;
54
+ if (resolveDevtools()) {
55
+ managerCache.set(tag, null);
56
+ return null;
57
+ }
58
+ const manager = (_ty$getLogManager = (_ty2 = globalThis.ty) === null || _ty2 === void 0 || (_ty2$getLogManager = _ty2.getLogManager) === null || _ty2$getLogManager === void 0 ? void 0 : _ty2$getLogManager.call(_ty2, {
59
+ tag
60
+ })) !== null && _ty$getLogManager !== void 0 ? _ty$getLogManager : null;
61
+ managerCache.set(tag, manager);
62
+ return manager;
63
+ } catch (error) {
64
+ warnOnce(error);
65
+ managerCache.set(tag, null);
66
+ return null;
67
+ }
68
+ };
69
+ return payload => {
70
+ const manager = resolveManager(APP_LOG_TAG);
71
+ if (!manager) {
72
+ return;
73
+ }
74
+ const method = manager.log;
75
+ if (typeof method !== 'function') {
76
+ return;
77
+ }
78
+ try {
79
+ method.call(manager, {
80
+ message: buildMessage(payload)
81
+ });
82
+ } catch (error) {
83
+ warnOnce(error);
84
+ }
85
+ };
86
+ }
package/lib/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export { RobotMap } from './RobotMap';
2
2
  export { RjsRobotMap } from './RjsRobotMap';
3
3
  export type { MapApi } from './types';
4
+ export type { LoggerPayload, RobotMapProps } from './props';
4
5
  export * from '@ray-js/robot-map-sdk';
package/lib/props.d.ts CHANGED
@@ -1,5 +1,13 @@
1
1
  import { DeepPartialAppConfig, DeepPartialRuntimeConfig, RoomProperty, ZoneParam, VirtualWallParam, SpotParam, WayPointParam, DetectedObjectParam, CustomElementParam, CustomCarpetParam, FurnitureParam, MapCallbacks } from '@ray-js/robot-map-sdk';
2
2
  import { MapApi } from './types';
3
+ export type LoggerLevel = 'info' | 'warn' | 'error' | 'debug';
4
+ export type LoggerPayload = {
5
+ level: LoggerLevel;
6
+ message: string;
7
+ data: unknown[];
8
+ tag: string;
9
+ ts: number;
10
+ };
3
11
  /**
4
12
  * 机器人地图组件属性接口
5
13
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ray-js/robot-map",
3
- "version": "0.0.8",
3
+ "version": "0.0.9-beta.10",
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.15-beta.2",
36
+ "@ray-js/robot-map-sdk": "0.0.15-beta.10",
37
37
  "clsx": "^1.2.1",
38
38
  "nanoid": "^5.1.6"
39
39
  },