@ray-js/robot-map 0.0.9-beta.1 → 0.0.9-beta.11

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
@@ -9,17 +9,17 @@ import "core-js/modules/web.dom-collections.iterator.js";
9
9
  /* eslint-disable @typescript-eslint/no-empty-function */
10
10
  import React, { useCallback, useEffect, useRef, useState } from 'react';
11
11
  import createInvoke from '@ray-js/webview-invoke/native';
12
- import { createWebviewContext, WebView } from '@ray-js/ray';
12
+ import { createWebviewContext, usePageEvent, WebView } from '@ray-js/ray';
13
13
  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
17
  import { EXCLUDED_API_METHODS } from './types';
18
+ import { createAppLoggerBridge } from './appLoggerBridge';
18
19
 
19
20
  // 回调名到事件名的映射
20
21
  const CALLBACK_TO_EVENT_MAP = _objectSpread({
21
- onInitialized: 'onInitialized',
22
- onLogger: 'onLogger'
22
+ onInitialized: 'onInitialized'
23
23
  }, MAP_CALLBACK_METHODS.reduce((acc, methodName) => {
24
24
  acc[methodName] = methodName;
25
25
  return acc;
@@ -50,6 +50,7 @@ const RobotMap = _ref => {
50
50
  const prevConfigRef = useRef(null);
51
51
  const prevRuntimeRef = useRef(null);
52
52
  const hasSkippedInitialConfigUpdateRef = useRef(false);
53
+ const appLoggerBridgeRef = useRef(createAppLoggerBridge());
53
54
  const webviewId = useRef(nanoid()).current;
54
55
  const webviewContext = useRef(null);
55
56
  const invoke = useRef(null);
@@ -78,6 +79,14 @@ const RobotMap = _ref => {
78
79
  invoke.current.listener(event);
79
80
  }
80
81
  }, []);
82
+ const destroyApp = useCallback(trigger => {
83
+ try {
84
+ var _invoke$current;
85
+ (_invoke$current = invoke.current) === null || _invoke$current === void 0 || _invoke$current.bind('destroyApp')(trigger);
86
+ } catch (error) {
87
+ // Ignore teardown bridge failures during page exit.
88
+ }
89
+ }, []);
81
90
 
82
91
  // 事件分发函数 - 这个函数是稳定的,不会随渲染变化
83
92
  const eventDispatcher = useCallback(function (eventName) {
@@ -94,6 +103,9 @@ const RobotMap = _ref => {
94
103
  // 更新回调引用
95
104
  callbacksRef.current = callbacks;
96
105
  });
106
+ usePageEvent('onUnload', () => {
107
+ destroyApp('page.onUnload');
108
+ });
97
109
  useEffect(() => {
98
110
  webviewContext.current = createWebviewContext(webviewId);
99
111
  Object.defineProperty(webviewContext.current, 'platform', {
@@ -145,7 +157,17 @@ const RobotMap = _ref => {
145
157
  eventDispatcher(eventName, ...args);
146
158
  });
147
159
  });
160
+ invoke.current.define('onAppLogger', payload => {
161
+ appLoggerBridgeRef.current(payload);
162
+ });
148
163
  }, []);
164
+ useEffect(() => {
165
+ return () => {
166
+ destroyApp('component.unmount');
167
+ invoke.current = null;
168
+ webviewContext.current = null;
169
+ };
170
+ }, [destroyApp]);
149
171
  useEffect(() => {
150
172
  if (mapApi && map) {
151
173
  triggersRef.current.onReceiveMap(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/props.d.ts CHANGED
@@ -142,12 +142,5 @@ export interface RobotMapProps extends MapCallbacks {
142
142
  * @param mapApi - 可供使用的地图 API 函数对象,所有方法返回 Promise / Available map API functions object, all methods return Promise
143
143
  */
144
144
  onMapReady?: (mapApi: MapApi) => void;
145
- /**
146
- * @description.zh SDK 日志回调
147
- * @description.en Callback for SDK log payloads
148
- * @description.zh 当 webview 内部 SDK 转发结构化日志时触发。默认仅转发 warn 和 error,可通过 `config.logger.hostLevels` 扩展到 info 和 debug。
149
- * @description.en Triggered when the webview SDK forwards structured logs. By default only warn and error are forwarded, and you can extend this to info and debug through `config.logger.hostLevels`.
150
- */
151
- onLogger?: (payload: LoggerPayload) => void;
152
145
  }
153
146
  export declare const robotMapDefaultProps: RobotMapProps;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ray-js/robot-map",
3
- "version": "0.0.9-beta.1",
3
+ "version": "0.0.9-beta.11",
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.3",
36
+ "@ray-js/robot-map-sdk": "0.0.15-beta.11",
37
37
  "clsx": "^1.2.1",
38
38
  "nanoid": "^5.1.6"
39
39
  },