@ray-js/api 1.4.0-alpha.0 → 1.4.0-alpha.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.
Files changed (81) hide show
  1. package/@types/P2PKit.d.ts +402 -0
  2. package/@types/all-kits.d.ts +1 -0
  3. package/lib/BaseKit-3.3.10.js +85 -83
  4. package/lib/BizKit-3.2.7.js +48 -47
  5. package/lib/DeviceKit-3.3.1.js +194 -193
  6. package/lib/HomeKit-3.1.4.js +2 -1
  7. package/lib/MapKit-3.0.7.js +4 -2
  8. package/lib/MiniKit-3.1.0.js +65 -64
  9. package/lib/P2PKit-2.0.3.d.ts +27 -0
  10. package/lib/P2PKit-2.0.3.js +79 -0
  11. package/lib/PlayNetKit-1.1.3.js +2 -1
  12. package/lib/all-kits.d.ts +1 -0
  13. package/lib/all-kits.js +1 -0
  14. package/lib/cloud/alarm.js +4 -7
  15. package/lib/cloud/core.js +2 -3
  16. package/lib/cloud/device.js +20 -31
  17. package/lib/cloud/interface.d.ts +7 -7
  18. package/lib/cloud/linkage.js +43 -41
  19. package/lib/cloud/statistic.js +21 -33
  20. package/lib/cloud/timer.js +31 -48
  21. package/lib/constants.js +1 -1
  22. package/lib/core/promisify/index.js +5 -9
  23. package/lib/getBoundingClientRect/index.js +16 -17
  24. package/lib/getBoundingClientRect/index.thing.js +16 -17
  25. package/lib/getBoundingClientRect/index.wechat.js +16 -17
  26. package/lib/getCdnUrl/index.d.ts +1 -0
  27. package/lib/getCdnUrl/index.js +4 -0
  28. package/lib/getCdnUrl/index.thing.d.ts +3 -1
  29. package/lib/getCdnUrl/index.thing.js +54 -19
  30. package/lib/getCdnUrl/index.wechat.d.ts +1 -0
  31. package/lib/getCdnUrl/index.wechat.js +4 -0
  32. package/lib/getElementById/index.js +1 -3
  33. package/lib/getElementById/index.thing.js +2 -4
  34. package/lib/getElementById/index.wechat.js +2 -4
  35. package/lib/index.d.ts +1 -1
  36. package/lib/index.js +4 -3
  37. package/lib/lifecycles/offAppEvent/index.js +2 -2
  38. package/lib/lifecycles/offAppHide/index.js +2 -2
  39. package/lib/lifecycles/offAppShow/index.js +2 -2
  40. package/lib/lifecycles/offError/index.js +2 -2
  41. package/lib/lifecycles/offThemeChange/index.js +2 -2
  42. package/lib/lifecycles/offWindowResize/index.js +2 -2
  43. package/lib/lifecycles/onAppEvent/index.js +2 -2
  44. package/lib/lifecycles/onAppHide/index.js +2 -2
  45. package/lib/lifecycles/onAppShow/index.js +2 -2
  46. package/lib/lifecycles/onError/index.js +2 -2
  47. package/lib/lifecycles/onPageNotFound/index.js +2 -2
  48. package/lib/lifecycles/onThemeChange/index.js +2 -2
  49. package/lib/lifecycles/onWindowResize/index.js +2 -2
  50. package/lib/navigateBack/index.js +3 -6
  51. package/lib/navigateTo/index.js +2 -5
  52. package/lib/onNavigationBarBack/index.js +1 -2
  53. package/lib/onNavigationBarBack/index.wechat.js +1 -2
  54. package/lib/panel/devInfo/index.js +84 -121
  55. package/lib/panel/i18n/index.d.ts +1 -1
  56. package/lib/panel/i18n/index.js +180 -262
  57. package/lib/panel/i18n/index.wechat.d.ts +1 -1
  58. package/lib/panel/i18n/index.wechat.js +184 -267
  59. package/lib/panel/normalizeNetwork.d.ts +2 -2
  60. package/lib/panel/normalizeNetwork.js +2 -7
  61. package/lib/panel/publishDps.d.ts +1 -1
  62. package/lib/panel/publishDps.js +13 -18
  63. package/lib/panel/types/devInfo.d.ts +3 -3
  64. package/lib/panel/types/utilities.d.ts +8 -8
  65. package/lib/panel/utils.js +1 -3
  66. package/lib/reLaunch/index.js +2 -5
  67. package/lib/redirectTo/index.js +2 -6
  68. package/lib/requestCloud/index.js +2 -2
  69. package/lib/requestCloud/index.wechat.js +0 -1
  70. package/lib/setNavigationBarBack/index.js +1 -2
  71. package/lib/setNavigationBarBack/index.wechat.js +1 -2
  72. package/lib/setNavigationBarColor/index.js +3 -6
  73. package/lib/setNavigationBarTitle/index.js +5 -6
  74. package/lib/switchTab/index.js +2 -5
  75. package/lib/utils.d.ts +1 -1
  76. package/lib/utils.js +5 -14
  77. package/lib/utils.wechat.d.ts +1 -1
  78. package/lib/utils.wechat.js +9 -21
  79. package/lib/viewAPI.js +13 -12
  80. package/package.json +25 -25
  81. package/LICENSE.md +0 -9
@@ -1,13 +1,8 @@
1
- import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
2
1
  import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
3
- import _regeneratorRuntime from "@babel/runtime/regenerator";
4
- import "core-js/modules/es.object.to-string.js";
5
- import "core-js/modules/web.dom-collections.for-each.js";
6
- import "core-js/modules/es.promise.js";
7
2
  import { getDeviceInfo, getLaunchOptionsSync, getGroupInfo, getApp, registerDeviceListListener, registerGroupChange, exitMiniProgram, subscribeDeviceRemoved, onDeviceRemoved } from '@ray-js/api';
8
3
  // 本地化缓存 deviceInfo 方便随时调用
9
- var __deviceInfo = null;
10
- var defaultPanelEnvironmentOptions = {
4
+ let __deviceInfo = null;
5
+ const defaultPanelEnvironmentOptions = {
11
6
  useDefaultOffline: true,
12
7
  bleCover: false,
13
8
  customTop: null,
@@ -15,17 +10,20 @@ var defaultPanelEnvironmentOptions = {
15
10
  showBLEToast: true
16
11
  };
17
12
  export function parseDevice(dev) {
18
- if (!dev) return null; // @ts-ignore
19
-
20
- var deviceInfo = _objectSpread({}, dev);
21
-
22
- var schema = dev.schema;
23
- var idCodes = {};
24
- var codeIds = {};
25
- schema.forEach(function (item) {
13
+ if (!dev) return null;
14
+ // @ts-ignore
15
+ const deviceInfo = _objectSpread({}, dev);
16
+ const {
17
+ schema
18
+ } = dev;
19
+ const idCodes = {};
20
+ const codeIds = {};
21
+ schema.forEach(item => {
26
22
  // @ts-ignore
27
- var id = item.id,
28
- code = item.code;
23
+ const {
24
+ id,
25
+ code
26
+ } = item;
29
27
  idCodes[id] = code;
30
28
  codeIds[code] = id;
31
29
  });
@@ -33,35 +31,33 @@ export function parseDevice(dev) {
33
31
  deviceInfo.codeIds = codeIds;
34
32
  return deviceInfo;
35
33
  }
34
+
36
35
  /**
37
36
  * 初始化面板环境下使用到的设备信息
38
37
  * @returns Promise<DevInfo>
39
38
  */
40
-
41
- export var initDevInfo = function (option) {
42
- return new Promise(function (resolve, reject) {
39
+ export const initDevInfo = option => {
40
+ return new Promise((resolve, reject) => {
43
41
  if (__deviceInfo) {
44
42
  resolve(__deviceInfo);
45
43
  }
46
-
47
- var data = getLaunchOptionsSync();
48
-
49
- var _ref = option || data.query,
50
- deviceId = _ref.deviceId,
51
- groupId = _ref.groupId;
52
-
44
+ const data = getLaunchOptionsSync();
45
+ const {
46
+ deviceId,
47
+ groupId
48
+ } = option || data.query;
53
49
  if (groupId) {
54
50
  getGroupInfo({
55
- groupId: groupId,
56
- success: function success(groupInfo) {
51
+ groupId,
52
+ success: groupInfo => {
57
53
  __deviceInfo = groupInfo;
58
54
  resolve(__deviceInfo);
59
55
  }
60
56
  });
61
57
  } else {
62
58
  getDeviceInfo({
63
- deviceId: deviceId,
64
- success: function success(deviceInfo) {
59
+ deviceId,
60
+ success: deviceInfo => {
65
61
  __deviceInfo = parseDevice(deviceInfo);
66
62
  resolve(__deviceInfo);
67
63
  },
@@ -70,108 +66,75 @@ export var initDevInfo = function (option) {
70
66
  }
71
67
  });
72
68
  };
73
- export var getDevInfo = function () {
69
+ export const getDevInfo = () => {
74
70
  return __deviceInfo;
75
71
  };
76
- export var updateDevInfo = function (devInfo) {
72
+ export const updateDevInfo = devInfo => {
77
73
  __deviceInfo = devInfo;
78
74
  };
75
+
79
76
  /**
80
77
  * 监听设备移除
81
78
  */
82
-
83
- var handleDeviceRemoved = function () {
79
+ const handleDeviceRemoved = () => {
84
80
  exitMiniProgram();
85
81
  };
82
+
86
83
  /**
87
84
  * 绑定当前设备或群组基础事件
88
85
  * @param config: InitPanelEnvironmentOptions 配置项
89
86
  */
90
-
91
-
92
- export function initPanelEnvironment() {
93
- return _initPanelEnvironment.apply(this, arguments);
94
- }
95
-
96
- function _initPanelEnvironment() {
97
- _initPanelEnvironment = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
98
- var options,
99
- App,
100
- _args = arguments;
101
- return _regeneratorRuntime.wrap(function (_context) {
102
- while (1) {
103
- switch (_context.prev = _context.next) {
104
- case 0:
105
- options = _args.length > 0 && _args[0] !== undefined ? _args[0] : defaultPanelEnvironmentOptions;
106
-
107
- if (getApp()) {
108
- _context.next = 5;
109
- break;
110
- }
111
-
112
- _context.next = 4;
113
- return new Promise(function (resolve) {
114
- setTimeout(function () {
115
- resolve(initPanelEnvironment(options));
116
- }, 0);
117
- });
118
-
119
- case 4:
120
- return _context.abrupt("return");
121
-
122
- case 5:
123
- App = getApp(); // 基础库版本需要大于 2.6.0
124
- // @ts-ignore
125
-
126
- App.onReady = function (event) {
127
- var _options$deviceId, _options$groupId;
128
-
129
- var deviceId = (_options$deviceId = options.deviceId) !== null && _options$deviceId !== void 0 ? _options$deviceId : event.query.deviceId;
130
- var groupId = (_options$groupId = options.groupId) !== null && _options$groupId !== void 0 ? _options$groupId : event.query.groupId;
131
- var useDefaultOffline = options.useDefaultOffline; // @ts-ignore
132
-
133
- if (ty.panel && ty.panel.initPanelKit && useDefaultOffline) {
134
- // @ts-ignore
135
- ty.panel.initPanelKit(_objectSpread({
136
- deviceId: deviceId,
137
- groupId: groupId
138
- }, options));
139
- } else {
140
- // 否则使用 registerDeviceListListener 注册,删除上述条件方法
141
- // 若需要能用离线逻辑,则需要在 global.config.ts 中添加 pageWrapper: ['@ray-js/ray-panel-wrapper/lib/page'],
142
- if (deviceId) {
143
- registerDeviceListListener({
144
- deviceIdList: [deviceId]
145
- });
146
- }
147
-
148
- if (groupId) {
149
- registerGroupChange({
150
- groupIdList: [groupId]
151
- });
152
- }
153
- }
154
-
155
- if (deviceId) {
156
- subscribeDeviceRemoved({
157
- deviceId: deviceId,
158
- success: function success() {
159
- onDeviceRemoved(handleDeviceRemoved);
160
- }
161
- });
162
- }
163
- }; // 使用 Promise 确保业务可以通过 initPanelEnvironment 的正常调用明确设备信息初始化完成
164
-
165
-
166
- _context.next = 9;
167
- return initDevInfo(options.deviceId || options.groupId ? options : undefined);
168
-
169
- case 9:
170
- case "end":
171
- return _context.stop();
172
- }
87
+ export async function initPanelEnvironment() {
88
+ let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : defaultPanelEnvironmentOptions;
89
+ if (!getApp()) {
90
+ await new Promise(resolve => {
91
+ setTimeout(() => {
92
+ resolve(initPanelEnvironment(options));
93
+ }, 0);
94
+ });
95
+ return;
96
+ }
97
+ const App = getApp();
98
+
99
+ // 基础库版本需要大于 2.6.0
100
+ // @ts-ignore
101
+ App.onReady = event => {
102
+ var _options$deviceId, _options$groupId;
103
+ const deviceId = (_options$deviceId = options.deviceId) !== null && _options$deviceId !== void 0 ? _options$deviceId : event.query.deviceId;
104
+ const groupId = (_options$groupId = options.groupId) !== null && _options$groupId !== void 0 ? _options$groupId : event.query.groupId;
105
+ const {
106
+ useDefaultOffline
107
+ } = options;
108
+ // @ts-ignore
109
+ if (ty.panel && ty.panel.initPanelKit && useDefaultOffline) {
110
+ // @ts-ignore
111
+ ty.panel.initPanelKit(_objectSpread({
112
+ deviceId,
113
+ groupId
114
+ }, options));
115
+ } else {
116
+ // 否则使用 registerDeviceListListener 注册,删除上述条件方法
117
+ // 若需要能用离线逻辑,则需要在 global.config.ts 中添加 pageWrapper: ['@ray-js/ray-panel-wrapper/lib/page'],
118
+ if (deviceId) {
119
+ registerDeviceListListener({
120
+ deviceIdList: [deviceId]
121
+ });
122
+ }
123
+ if (groupId) {
124
+ registerGroupChange({
125
+ groupIdList: [groupId]
126
+ });
173
127
  }
174
- }, _callee);
175
- }));
176
- return _initPanelEnvironment.apply(this, arguments);
128
+ }
129
+ if (deviceId) {
130
+ subscribeDeviceRemoved({
131
+ deviceId,
132
+ success: () => {
133
+ onDeviceRemoved(handleDeviceRemoved);
134
+ }
135
+ });
136
+ }
137
+ };
138
+ // 使用 Promise 确保业务可以通过 initPanelEnvironment 的正常调用明确设备信息初始化完成
139
+ await initDevInfo(options.deviceId || options.groupId ? options : undefined);
177
140
  }
@@ -1,4 +1,4 @@
1
- declare type LanguageMap = {
1
+ type LanguageMap = {
2
2
  [key: string]: Record<string, string>;
3
3
  };
4
4
  export default class I18N {