@we-debug/core 0.49.2 → 0.51.0
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.
- package/CHANGELOG.md +30 -0
- package/dist/api/apiview.d.ts +7 -0
- package/dist/api/apiview.js +47 -0
- package/dist/api/cache.js +2 -1
- package/dist/api/init.js +4 -0
- package/dist/api/launcher.d.ts +7 -0
- package/dist/api/launcher.js +55 -0
- package/dist/api/network.js +15 -0
- package/dist/api/networkview.d.ts +7 -0
- package/dist/api/networkview.js +47 -0
- package/dist/api/ui.d.ts +24 -0
- package/dist/api/ui.js +196 -0
- package/dist/base/cache.js +10 -7
- package/dist/index.d.ts +46 -5
- package/dist/index.js +72 -1
- package/dist/model/apiview.d.ts +9 -0
- package/dist/model/apiview.js +44 -0
- package/dist/model/badge.d.ts +2 -1
- package/dist/model/badge.js +1 -0
- package/dist/model/index.d.ts +4 -0
- package/dist/model/index.js +4 -0
- package/dist/model/networkview.d.ts +9 -0
- package/dist/model/networkview.js +44 -0
- package/dist/model/overlay.d.ts +10 -0
- package/dist/model/overlay.js +45 -0
- package/dist/model/panelview.d.ts +13 -0
- package/dist/model/panelview.js +48 -0
- package/dist/store/index.d.ts +4 -1
- package/dist/store/index.js +3 -0
- package/dist/store/sys.js +2 -1
- package/dist/types.d.ts +85 -0
- package/dist/utils/silent.d.ts +2 -0
- package/dist/utils/silent.js +18 -0
- package/dist/version.js +1 -1
- package/package.json +17 -10
- package/test/ui.test.ts +151 -0
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,36 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [0.51.0](https://github.com/dlhandsome/we-debug/compare/v0.50.0...v0.51.0) (2026-12-01)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* **core:** correct custom UI state handling ([749439d](https://github.com/dlhandsome/we-debug/commit/749439ddbf199bdb34f7e25f0e5109038768ba18))
|
|
12
|
+
* **core:** 跳转同步异常不 reject、面板重复添加去重 ([f534662](https://github.com/dlhandsome/we-debug/commit/f534662538cf74d6909a691bfcadf9724bdae8f9))
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
### Features
|
|
16
|
+
|
|
17
|
+
* **core:** 新增自定义 UI 插件运行时 API ([3718755](https://github.com/dlhandsome/we-debug/commit/371875548239361668b3605cb36cd13d94bbb347))
|
|
18
|
+
* **miniprogram:** responsive debug panel and floating launcher ([eb08b8c](https://github.com/dlhandsome/we-debug/commit/eb08b8c6b09faab4ad2cb4aa25ae0141c347c912))
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
# [0.50.0](https://github.com/dlhandsome/we-debug/compare/v0.49.2...v0.50.0) (2026-11-27)
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
### Features
|
|
28
|
+
|
|
29
|
+
* **api:** 新增 wx API 抓包面板 ([da85c30](https://github.com/dlhandsome/we-debug/commit/da85c30bbdd5d40b314b74d64dd22f1137157304))
|
|
30
|
+
* **network:** 新增 Chrome 风格的 Network 抓包面板 ([5e69881](https://github.com/dlhandsome/we-debug/commit/5e69881c74e24f5605fd5ef996f7b66f139d43bb))
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
6
36
|
## [0.49.2](https://github.com/dlhandsome/we-debug/compare/v0.49.1...v0.49.2) (2025-11-12)
|
|
7
37
|
|
|
8
38
|
**Note:** Version bump only for package @we-debug/core
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ApiView } from '../model/index';
|
|
2
|
+
import { IAddApiViewOption } from '../types';
|
|
3
|
+
export { createApiView } from '../model/index';
|
|
4
|
+
export declare function addApiView(apiview: ApiView, options?: IAddApiViewOption): void;
|
|
5
|
+
export declare function updateApiView(apiview: ApiView, options?: IAddApiViewOption): void;
|
|
6
|
+
export declare function removeApiView(apiview: ApiView, options?: IAddApiViewOption): void;
|
|
7
|
+
export declare function getApiView(): ApiView[];
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getApiView = exports.removeApiView = exports.updateApiView = exports.addApiView = exports.createApiView = void 0;
|
|
7
|
+
var index_1 = __importDefault(require("../store/index"));
|
|
8
|
+
var group_1 = require("./group");
|
|
9
|
+
var index_2 = require("../model/index");
|
|
10
|
+
Object.defineProperty(exports, "createApiView", { enumerable: true, get: function () { return index_2.createApiView; } });
|
|
11
|
+
function addApiView(apiview, options) {
|
|
12
|
+
var _a;
|
|
13
|
+
index_1.default.apiviews.add(apiview);
|
|
14
|
+
var group = (_a = options === null || options === void 0 ? void 0 : options.group) === null || _a === void 0 ? void 0 : _a.name;
|
|
15
|
+
if (group) {
|
|
16
|
+
(0, group_1.addViewByGroup)(group, apiview);
|
|
17
|
+
}
|
|
18
|
+
index_1.default.event.emit('apiview:update');
|
|
19
|
+
index_1.default.event.emit('group:update');
|
|
20
|
+
}
|
|
21
|
+
exports.addApiView = addApiView;
|
|
22
|
+
function updateApiView(apiview, options) {
|
|
23
|
+
var _a;
|
|
24
|
+
index_1.default.apiviews.update(apiview);
|
|
25
|
+
var group = (_a = options === null || options === void 0 ? void 0 : options.group) === null || _a === void 0 ? void 0 : _a.name;
|
|
26
|
+
if (group) {
|
|
27
|
+
(0, group_1.updateViewByGroup)(group, apiview);
|
|
28
|
+
}
|
|
29
|
+
index_1.default.event.emit('apiview:update');
|
|
30
|
+
index_1.default.event.emit('group:update');
|
|
31
|
+
}
|
|
32
|
+
exports.updateApiView = updateApiView;
|
|
33
|
+
function removeApiView(apiview, options) {
|
|
34
|
+
var _a;
|
|
35
|
+
index_1.default.apiviews.remove(apiview);
|
|
36
|
+
var group = (_a = options === null || options === void 0 ? void 0 : options.group) === null || _a === void 0 ? void 0 : _a.name;
|
|
37
|
+
if (group) {
|
|
38
|
+
(0, group_1.removeGroupView)(group, apiview);
|
|
39
|
+
}
|
|
40
|
+
index_1.default.event.emit('apiview:update');
|
|
41
|
+
index_1.default.event.emit('group:update');
|
|
42
|
+
}
|
|
43
|
+
exports.removeApiView = removeApiView;
|
|
44
|
+
function getApiView() {
|
|
45
|
+
return index_1.default.apiviews.get();
|
|
46
|
+
}
|
|
47
|
+
exports.getApiView = getApiView;
|
package/dist/api/cache.js
CHANGED
|
@@ -2,10 +2,11 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createCache = void 0;
|
|
4
4
|
var cache_1 = require("../base/cache");
|
|
5
|
+
var silent_1 = require("../utils/silent");
|
|
5
6
|
function createCache(cacheKey) {
|
|
6
7
|
var v = null;
|
|
7
8
|
try {
|
|
8
|
-
v = wx.getStorageSync(cacheKey);
|
|
9
|
+
v = (0, silent_1.silent)(function () { return wx.getStorageSync(cacheKey); });
|
|
9
10
|
}
|
|
10
11
|
catch (e) { }
|
|
11
12
|
return new cache_1.CacheData(cacheKey, v);
|
package/dist/api/init.js
CHANGED
|
@@ -9,6 +9,7 @@ var plugin_error_1 = __importDefault(require("@we-debug/plugin-error"));
|
|
|
9
9
|
var plugin_router_1 = __importDefault(require("@we-debug/plugin-router"));
|
|
10
10
|
var plugin_launcher_1 = __importDefault(require("@we-debug/plugin-launcher"));
|
|
11
11
|
var plugin_network_1 = __importDefault(require("@we-debug/plugin-network"));
|
|
12
|
+
var plugin_api_1 = __importDefault(require("@we-debug/plugin-api"));
|
|
12
13
|
var plugin_1 = __importDefault(require("@we-debug/plugin-ui-check/plugin"));
|
|
13
14
|
var plugin_appdata_1 = __importDefault(require("@we-debug/plugin-appdata"));
|
|
14
15
|
var plugin_storage_1 = __importDefault(require("@we-debug/plugin-storage"));
|
|
@@ -18,6 +19,7 @@ function init(options) {
|
|
|
18
19
|
launcher: true,
|
|
19
20
|
plugin: {
|
|
20
21
|
network: true,
|
|
22
|
+
api: true,
|
|
21
23
|
error: true,
|
|
22
24
|
router: true,
|
|
23
25
|
uiCheck: true,
|
|
@@ -33,6 +35,8 @@ function init(options) {
|
|
|
33
35
|
use_1.use.call(this, plugin_storage_1.default, opt.plugin.storage || {});
|
|
34
36
|
if (opt.plugin.network)
|
|
35
37
|
use_1.use.call(this, plugin_network_1.default, opt.plugin.network || {});
|
|
38
|
+
if (opt.plugin.api)
|
|
39
|
+
use_1.use.call(this, plugin_api_1.default, opt.plugin.api || {});
|
|
36
40
|
if (opt.plugin.error)
|
|
37
41
|
use_1.use.call(this, plugin_error_1.default, opt.plugin.error || {});
|
|
38
42
|
if (opt.plugin.router)
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ILauncherDotOption } from '../types';
|
|
2
|
+
export declare const LAUNCHER_DOT_UPDATE = "launcher:dot:update";
|
|
3
|
+
export declare function hasLauncherDot(): boolean;
|
|
4
|
+
export declare function getLauncherDotGroups(): string[];
|
|
5
|
+
export declare function showLauncherDot(key: string, option?: ILauncherDotOption): void;
|
|
6
|
+
export declare function hideLauncherDot(key: string): void;
|
|
7
|
+
export declare function readLauncherDotGroup(group: string): void;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.readLauncherDotGroup = exports.hideLauncherDot = exports.showLauncherDot = exports.getLauncherDotGroups = exports.hasLauncherDot = exports.LAUNCHER_DOT_UPDATE = void 0;
|
|
7
|
+
var index_1 = __importDefault(require("../store/index"));
|
|
8
|
+
exports.LAUNCHER_DOT_UPDATE = 'launcher:dot:update';
|
|
9
|
+
var sources = {};
|
|
10
|
+
var seq = 0;
|
|
11
|
+
var emitUpdate = function () { return index_1.default.event.emit(exports.LAUNCHER_DOT_UPDATE, hasLauncherDot()); };
|
|
12
|
+
function hasLauncherDot() {
|
|
13
|
+
return Object.keys(sources).length > 0;
|
|
14
|
+
}
|
|
15
|
+
exports.hasLauncherDot = hasLauncherDot;
|
|
16
|
+
function getLauncherDotGroups() {
|
|
17
|
+
var groups = [];
|
|
18
|
+
Object.keys(sources)
|
|
19
|
+
.map(function (key) { return sources[key]; })
|
|
20
|
+
.sort(function (a, b) { return b.time - a.time; })
|
|
21
|
+
.forEach(function (_a) {
|
|
22
|
+
var group = _a.group;
|
|
23
|
+
if (group && groups.indexOf(group) === -1)
|
|
24
|
+
groups.push(group);
|
|
25
|
+
});
|
|
26
|
+
return groups;
|
|
27
|
+
}
|
|
28
|
+
exports.getLauncherDotGroups = getLauncherDotGroups;
|
|
29
|
+
function showLauncherDot(key, option) {
|
|
30
|
+
if (option === void 0) { option = {}; }
|
|
31
|
+
sources[key] = { group: option.group, time: ++seq };
|
|
32
|
+
emitUpdate();
|
|
33
|
+
}
|
|
34
|
+
exports.showLauncherDot = showLauncherDot;
|
|
35
|
+
function hideLauncherDot(key) {
|
|
36
|
+
if (!(key in sources))
|
|
37
|
+
return;
|
|
38
|
+
delete sources[key];
|
|
39
|
+
emitUpdate();
|
|
40
|
+
}
|
|
41
|
+
exports.hideLauncherDot = hideLauncherDot;
|
|
42
|
+
function clearWhere(match) {
|
|
43
|
+
var keys = Object.keys(sources).filter(function (key) { return match(sources[key]); });
|
|
44
|
+
if (!keys.length)
|
|
45
|
+
return;
|
|
46
|
+
keys.forEach(function (key) { return delete sources[key]; });
|
|
47
|
+
emitUpdate();
|
|
48
|
+
}
|
|
49
|
+
function readLauncherDotGroup(group) {
|
|
50
|
+
clearWhere(function (source) { return source.group === group; });
|
|
51
|
+
}
|
|
52
|
+
exports.readLauncherDotGroup = readLauncherDotGroup;
|
|
53
|
+
index_1.default.event.on('debug:mask:show-modal', function () {
|
|
54
|
+
clearWhere(function (source) { return !source.group; });
|
|
55
|
+
});
|
package/dist/api/network.js
CHANGED
|
@@ -7,6 +7,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
7
7
|
var index_1 = __importDefault(require("../store/index"));
|
|
8
8
|
var simple_type_function_1 = require("../utils/simple-type-function");
|
|
9
9
|
var requestApi = ['request', 'downloadFile', 'uploadFile'];
|
|
10
|
+
var requestId = 0;
|
|
10
11
|
requestApi.forEach(function (method) {
|
|
11
12
|
var requestFunc = wx[method];
|
|
12
13
|
Object.defineProperty(wx, method, {
|
|
@@ -14,21 +15,32 @@ requestApi.forEach(function (method) {
|
|
|
14
15
|
return function (opt) {
|
|
15
16
|
if (opt === void 0) { opt = {}; }
|
|
16
17
|
var out = Object.assign({}, opt);
|
|
18
|
+
var id = ++requestId;
|
|
19
|
+
var startTime = Date.now();
|
|
17
20
|
if (!out.header) {
|
|
18
21
|
out.header = {};
|
|
19
22
|
}
|
|
20
23
|
if (!out.data) {
|
|
21
24
|
out.data = {};
|
|
22
25
|
}
|
|
26
|
+
index_1.default.event.emit('network:request-start', {
|
|
27
|
+
id: id,
|
|
28
|
+
method: method,
|
|
29
|
+
option: out,
|
|
30
|
+
startTime: startTime,
|
|
31
|
+
});
|
|
23
32
|
out.success = function () {
|
|
24
33
|
var args = [];
|
|
25
34
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
26
35
|
args[_i] = arguments[_i];
|
|
27
36
|
}
|
|
28
37
|
index_1.default.event.emit('network:request-finished', {
|
|
38
|
+
id: id,
|
|
29
39
|
method: method,
|
|
30
40
|
option: out,
|
|
31
41
|
response: args[0],
|
|
42
|
+
startTime: startTime,
|
|
43
|
+
endTime: Date.now(),
|
|
32
44
|
});
|
|
33
45
|
(0, simple_type_function_1.isFunc)(opt.success) && opt.success.apply(this, args);
|
|
34
46
|
};
|
|
@@ -38,9 +50,12 @@ requestApi.forEach(function (method) {
|
|
|
38
50
|
args[_i] = arguments[_i];
|
|
39
51
|
}
|
|
40
52
|
index_1.default.event.emit('network:request-finished', {
|
|
53
|
+
id: id,
|
|
41
54
|
method: method,
|
|
42
55
|
option: out,
|
|
43
56
|
error: args[0],
|
|
57
|
+
startTime: startTime,
|
|
58
|
+
endTime: Date.now(),
|
|
44
59
|
});
|
|
45
60
|
(0, simple_type_function_1.isFunc)(opt.fail) && opt.fail.apply(this, args);
|
|
46
61
|
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { NetworkView } from '../model/index';
|
|
2
|
+
import { IAddNetworkViewOption } from '../types';
|
|
3
|
+
export { createNetworkView } from '../model/index';
|
|
4
|
+
export declare function addNetworkView(networkview: NetworkView, options?: IAddNetworkViewOption): void;
|
|
5
|
+
export declare function updateNetworkView(networkview: NetworkView, options?: IAddNetworkViewOption): void;
|
|
6
|
+
export declare function removeNetworkView(networkview: NetworkView, options?: IAddNetworkViewOption): void;
|
|
7
|
+
export declare function getNetworkView(): NetworkView[];
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getNetworkView = exports.removeNetworkView = exports.updateNetworkView = exports.addNetworkView = exports.createNetworkView = void 0;
|
|
7
|
+
var index_1 = __importDefault(require("../store/index"));
|
|
8
|
+
var group_1 = require("./group");
|
|
9
|
+
var index_2 = require("../model/index");
|
|
10
|
+
Object.defineProperty(exports, "createNetworkView", { enumerable: true, get: function () { return index_2.createNetworkView; } });
|
|
11
|
+
function addNetworkView(networkview, options) {
|
|
12
|
+
var _a;
|
|
13
|
+
index_1.default.networkviews.add(networkview);
|
|
14
|
+
var group = (_a = options === null || options === void 0 ? void 0 : options.group) === null || _a === void 0 ? void 0 : _a.name;
|
|
15
|
+
if (group) {
|
|
16
|
+
(0, group_1.addViewByGroup)(group, networkview);
|
|
17
|
+
}
|
|
18
|
+
index_1.default.event.emit('networkview:update');
|
|
19
|
+
index_1.default.event.emit('group:update');
|
|
20
|
+
}
|
|
21
|
+
exports.addNetworkView = addNetworkView;
|
|
22
|
+
function updateNetworkView(networkview, options) {
|
|
23
|
+
var _a;
|
|
24
|
+
index_1.default.networkviews.update(networkview);
|
|
25
|
+
var group = (_a = options === null || options === void 0 ? void 0 : options.group) === null || _a === void 0 ? void 0 : _a.name;
|
|
26
|
+
if (group) {
|
|
27
|
+
(0, group_1.updateViewByGroup)(group, networkview);
|
|
28
|
+
}
|
|
29
|
+
index_1.default.event.emit('networkview:update');
|
|
30
|
+
index_1.default.event.emit('group:update');
|
|
31
|
+
}
|
|
32
|
+
exports.updateNetworkView = updateNetworkView;
|
|
33
|
+
function removeNetworkView(networkview, options) {
|
|
34
|
+
var _a;
|
|
35
|
+
index_1.default.networkviews.remove(networkview);
|
|
36
|
+
var group = (_a = options === null || options === void 0 ? void 0 : options.group) === null || _a === void 0 ? void 0 : _a.name;
|
|
37
|
+
if (group) {
|
|
38
|
+
(0, group_1.removeGroupView)(group, networkview);
|
|
39
|
+
}
|
|
40
|
+
index_1.default.event.emit('networkview:update');
|
|
41
|
+
index_1.default.event.emit('group:update');
|
|
42
|
+
}
|
|
43
|
+
exports.removeNetworkView = removeNetworkView;
|
|
44
|
+
function getNetworkView() {
|
|
45
|
+
return index_1.default.networkviews.get();
|
|
46
|
+
}
|
|
47
|
+
exports.getNetworkView = getNetworkView;
|
package/dist/api/ui.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { PanelView, Overlay } from '../model/index';
|
|
2
|
+
import { IAnyObject, IUIManifest, IAddPanelViewOption, IUpdatePanelViewOption, IPageOverlay, IScopePanelOption, IScopeOverlayOption, IScopeNavigateOption } from '../types';
|
|
3
|
+
export declare function registerUIManifest(m: IUIManifest): void;
|
|
4
|
+
export declare function getUIManifest(): IUIManifest | null;
|
|
5
|
+
export declare function getCurrentPageId(): string;
|
|
6
|
+
export declare function addPanelView(panel: PanelView, options?: IAddPanelViewOption): void;
|
|
7
|
+
export declare function updatePanelView(panel: PanelView, patch?: IUpdatePanelViewOption): void;
|
|
8
|
+
export declare function removePanelView(panel: PanelView): void;
|
|
9
|
+
export declare function showOverlay(overlay: Overlay, props?: IAnyObject): Promise<any>;
|
|
10
|
+
export declare function hideOverlay(overlay: Overlay): void;
|
|
11
|
+
export declare function getPageOverlays(pageId: string): IPageOverlay[];
|
|
12
|
+
export declare function closeOverlay(pageId: string, componentId: string, result?: any): void;
|
|
13
|
+
export declare function releasePageOverlays(pageId: string): void;
|
|
14
|
+
export declare function scope(pkg: string): {
|
|
15
|
+
createPanel(opt: IScopePanelOption): PanelView;
|
|
16
|
+
addPanel: typeof addPanelView;
|
|
17
|
+
updatePanel: typeof updatePanelView;
|
|
18
|
+
removePanel: typeof removePanelView;
|
|
19
|
+
createOverlay(opt: IScopeOverlayOption): Overlay;
|
|
20
|
+
showOverlay: typeof showOverlay;
|
|
21
|
+
hideOverlay: typeof hideOverlay;
|
|
22
|
+
navigateTo(page: string, query?: IAnyObject, options?: IScopeNavigateOption): Promise<any>;
|
|
23
|
+
createCache(key: string): import("../base/cache").CacheData;
|
|
24
|
+
};
|
package/dist/api/ui.js
ADDED
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.scope = exports.releasePageOverlays = exports.closeOverlay = exports.getPageOverlays = exports.hideOverlay = exports.showOverlay = exports.removePanelView = exports.updatePanelView = exports.addPanelView = exports.getCurrentPageId = exports.getUIManifest = exports.registerUIManifest = void 0;
|
|
7
|
+
var index_1 = __importDefault(require("../store/index"));
|
|
8
|
+
var group_1 = require("./group");
|
|
9
|
+
var cache_1 = require("./cache");
|
|
10
|
+
var index_2 = require("../model/index");
|
|
11
|
+
var LOG_PREFIX = '[we-debug]';
|
|
12
|
+
var manifest = null;
|
|
13
|
+
var manifestWarned = false;
|
|
14
|
+
var activeOverlays = [];
|
|
15
|
+
function registerUIManifest(m) {
|
|
16
|
+
manifest = m;
|
|
17
|
+
}
|
|
18
|
+
exports.registerUIManifest = registerUIManifest;
|
|
19
|
+
function getUIManifest() {
|
|
20
|
+
return manifest;
|
|
21
|
+
}
|
|
22
|
+
exports.getUIManifest = getUIManifest;
|
|
23
|
+
function ensureManifest() {
|
|
24
|
+
if (!manifest && !manifestWarned) {
|
|
25
|
+
manifestWarned = true;
|
|
26
|
+
console.warn("".concat(LOG_PREFIX, " \u672A\u68C0\u6D4B\u5230 UI \u63D2\u4EF6\u6E05\u5355\uFF0C\u81EA\u5B9A\u4E49 UI \u63D2\u4EF6\u9700\u8981\u901A\u8FC7 @we-debug/cli \u6216 @we-debug/gulp-tool \u7F16\u8BD1\u63A5\u5165"));
|
|
27
|
+
}
|
|
28
|
+
return manifest;
|
|
29
|
+
}
|
|
30
|
+
function resolveComponentId(pkg, name) {
|
|
31
|
+
var m = ensureManifest();
|
|
32
|
+
if (!m)
|
|
33
|
+
return '';
|
|
34
|
+
var p = m.packages[pkg];
|
|
35
|
+
var id = p ? p.components[name] : '';
|
|
36
|
+
if (!id) {
|
|
37
|
+
var declared = p ? Object.keys(p.components).join(', ') || '无' : '该包未被编译工具识别';
|
|
38
|
+
console.error("".concat(LOG_PREFIX, " \u63D2\u4EF6 ").concat(pkg, " \u672A\u58F0\u660E\u7EC4\u4EF6 ").concat(name, "\uFF0C\u5DF2\u58F0\u660E\u7684\u7EC4\u4EF6\uFF1A").concat(declared));
|
|
39
|
+
}
|
|
40
|
+
return id || '';
|
|
41
|
+
}
|
|
42
|
+
function getCurrentPageId() {
|
|
43
|
+
var pages = typeof getCurrentPages === 'function' ? getCurrentPages() : [];
|
|
44
|
+
var top = pages[pages.length - 1];
|
|
45
|
+
return top && typeof top.getPageId === 'function' ? String(top.getPageId()) : '';
|
|
46
|
+
}
|
|
47
|
+
exports.getCurrentPageId = getCurrentPageId;
|
|
48
|
+
function emitPanelUpdate() {
|
|
49
|
+
index_1.default.event.emit('panelview:update');
|
|
50
|
+
index_1.default.event.emit('group:update');
|
|
51
|
+
}
|
|
52
|
+
function addPanelView(panel, options) {
|
|
53
|
+
if (!panel.componentId)
|
|
54
|
+
return;
|
|
55
|
+
var group = (options && options.group && options.group.name) || panel.title;
|
|
56
|
+
if (panel.group && panel.group !== group)
|
|
57
|
+
(0, group_1.removeGroupView)(panel.group, panel);
|
|
58
|
+
panel.group = group;
|
|
59
|
+
if (!index_1.default.panelviews.getById(panel.id))
|
|
60
|
+
index_1.default.panelviews.add(panel);
|
|
61
|
+
(0, group_1.addViewByGroup)(panel.group, panel);
|
|
62
|
+
emitPanelUpdate();
|
|
63
|
+
}
|
|
64
|
+
exports.addPanelView = addPanelView;
|
|
65
|
+
function updatePanelView(panel, patch) {
|
|
66
|
+
if (patch === void 0) { patch = {}; }
|
|
67
|
+
if (patch.title !== undefined)
|
|
68
|
+
panel.title = patch.title;
|
|
69
|
+
if (patch.props !== undefined)
|
|
70
|
+
panel.props = patch.props;
|
|
71
|
+
index_1.default.panelviews.update(panel);
|
|
72
|
+
emitPanelUpdate();
|
|
73
|
+
}
|
|
74
|
+
exports.updatePanelView = updatePanelView;
|
|
75
|
+
function removePanelView(panel) {
|
|
76
|
+
index_1.default.panelviews.remove(panel);
|
|
77
|
+
if (panel.group)
|
|
78
|
+
(0, group_1.removeGroupView)(panel.group, panel);
|
|
79
|
+
emitPanelUpdate();
|
|
80
|
+
}
|
|
81
|
+
exports.removePanelView = removePanelView;
|
|
82
|
+
function settle(entry, result) {
|
|
83
|
+
activeOverlays = activeOverlays.filter(function (o) { return o !== entry; });
|
|
84
|
+
entry.resolve(result);
|
|
85
|
+
}
|
|
86
|
+
function showOverlay(overlay, props) {
|
|
87
|
+
if (!overlay.componentId)
|
|
88
|
+
return Promise.resolve(undefined);
|
|
89
|
+
var pageId = getCurrentPageId();
|
|
90
|
+
var existing = activeOverlays.filter(function (o) { return o.overlay.id === overlay.id && o.pageId === pageId; })[0];
|
|
91
|
+
if (existing) {
|
|
92
|
+
if (props)
|
|
93
|
+
existing.props = props;
|
|
94
|
+
index_1.default.event.emit('overlay:update');
|
|
95
|
+
return existing.promise;
|
|
96
|
+
}
|
|
97
|
+
activeOverlays
|
|
98
|
+
.filter(function (o) { return o.pageId === pageId && o.overlay.componentId === overlay.componentId; })
|
|
99
|
+
.forEach(function (o) { return settle(o, undefined); });
|
|
100
|
+
var resolve = function () { };
|
|
101
|
+
var promise = new Promise(function (r) {
|
|
102
|
+
resolve = r;
|
|
103
|
+
});
|
|
104
|
+
activeOverlays.push({ overlay: overlay, pageId: pageId, props: props || overlay.props, resolve: resolve, promise: promise });
|
|
105
|
+
index_1.default.event.emit('overlay:update');
|
|
106
|
+
return promise;
|
|
107
|
+
}
|
|
108
|
+
exports.showOverlay = showOverlay;
|
|
109
|
+
function hideOverlay(overlay) {
|
|
110
|
+
activeOverlays.filter(function (o) { return o.overlay.id === overlay.id; }).forEach(function (o) { return settle(o, undefined); });
|
|
111
|
+
index_1.default.event.emit('overlay:update');
|
|
112
|
+
}
|
|
113
|
+
exports.hideOverlay = hideOverlay;
|
|
114
|
+
function getPageOverlays(pageId) {
|
|
115
|
+
return activeOverlays
|
|
116
|
+
.filter(function (o) { return o.pageId === pageId; })
|
|
117
|
+
.map(function (o) { return ({ overlayId: o.overlay.id, componentId: o.overlay.componentId, props: o.props }); });
|
|
118
|
+
}
|
|
119
|
+
exports.getPageOverlays = getPageOverlays;
|
|
120
|
+
function closeOverlay(pageId, componentId, result) {
|
|
121
|
+
activeOverlays
|
|
122
|
+
.filter(function (o) { return o.pageId === pageId && o.overlay.componentId === componentId; })
|
|
123
|
+
.forEach(function (o) { return settle(o, result); });
|
|
124
|
+
index_1.default.event.emit('overlay:update');
|
|
125
|
+
}
|
|
126
|
+
exports.closeOverlay = closeOverlay;
|
|
127
|
+
function releasePageOverlays(pageId) {
|
|
128
|
+
activeOverlays.filter(function (o) { return o.pageId === pageId; }).forEach(function (o) { return settle(o, undefined); });
|
|
129
|
+
index_1.default.event.emit('overlay:update');
|
|
130
|
+
}
|
|
131
|
+
exports.releasePageOverlays = releasePageOverlays;
|
|
132
|
+
function navigateToPluginPage(pkg, page, query, options) {
|
|
133
|
+
var m = ensureManifest();
|
|
134
|
+
if (!m)
|
|
135
|
+
return Promise.resolve(undefined);
|
|
136
|
+
var p = m.packages[pkg];
|
|
137
|
+
if (!p || p.pages.indexOf(page) === -1) {
|
|
138
|
+
var declared = p ? p.pages.join(', ') || '无' : '该包未被编译工具识别';
|
|
139
|
+
console.error("".concat(LOG_PREFIX, " \u63D2\u4EF6 ").concat(pkg, " \u672A\u58F0\u660E\u9875\u9762 ").concat(page, "\uFF0C\u5DF2\u58F0\u660E\u7684\u9875\u9762\uFF1A").concat(declared));
|
|
140
|
+
return Promise.resolve(undefined);
|
|
141
|
+
}
|
|
142
|
+
var q = query || {};
|
|
143
|
+
var qs = Object.keys(q)
|
|
144
|
+
.filter(function (k) { return q[k] !== undefined; })
|
|
145
|
+
.map(function (k) { return "".concat(encodeURIComponent(k), "=").concat(encodeURIComponent(String(q[k]))); })
|
|
146
|
+
.join('&');
|
|
147
|
+
var url = "/".concat(m.npmDirname, "/").concat(pkg, "/").concat(page).concat(qs ? "?".concat(qs) : '');
|
|
148
|
+
return new Promise(function (resolve) {
|
|
149
|
+
try {
|
|
150
|
+
wx.navigateTo({
|
|
151
|
+
url: url,
|
|
152
|
+
events: options && options.events,
|
|
153
|
+
success: function (res) { return resolve(res); },
|
|
154
|
+
fail: function (err) {
|
|
155
|
+
console.error("".concat(LOG_PREFIX, " \u8DF3\u8F6C\u63D2\u4EF6\u9875\u9762\u5931\u8D25\uFF1A").concat(url), err);
|
|
156
|
+
resolve(undefined);
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
catch (err) {
|
|
161
|
+
console.error("".concat(LOG_PREFIX, " \u8DF3\u8F6C\u63D2\u4EF6\u9875\u9762\u5931\u8D25\uFF1A").concat(url), err);
|
|
162
|
+
resolve(undefined);
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
function scope(pkg) {
|
|
167
|
+
return {
|
|
168
|
+
createPanel: function (opt) {
|
|
169
|
+
return (0, index_2.createPanelView)({
|
|
170
|
+
key: "".concat(pkg, "/").concat(opt.component),
|
|
171
|
+
componentId: resolveComponentId(pkg, opt.component),
|
|
172
|
+
title: opt.title,
|
|
173
|
+
props: opt.props
|
|
174
|
+
});
|
|
175
|
+
},
|
|
176
|
+
addPanel: addPanelView,
|
|
177
|
+
updatePanel: updatePanelView,
|
|
178
|
+
removePanel: removePanelView,
|
|
179
|
+
createOverlay: function (opt) {
|
|
180
|
+
return (0, index_2.createOverlay)({
|
|
181
|
+
key: "".concat(pkg, "/").concat(opt.component),
|
|
182
|
+
componentId: resolveComponentId(pkg, opt.component),
|
|
183
|
+
props: opt.props
|
|
184
|
+
});
|
|
185
|
+
},
|
|
186
|
+
showOverlay: showOverlay,
|
|
187
|
+
hideOverlay: hideOverlay,
|
|
188
|
+
navigateTo: function (page, query, options) {
|
|
189
|
+
return navigateToPluginPage(pkg, page, query, options);
|
|
190
|
+
},
|
|
191
|
+
createCache: function (key) {
|
|
192
|
+
return (0, cache_1.createCache)("".concat(pkg, ":").concat(key));
|
|
193
|
+
}
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
exports.scope = scope;
|
package/dist/base/cache.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.CacheData = exports.setStorage = exports.getStorage = void 0;
|
|
4
|
+
var silent_1 = require("../utils/silent");
|
|
4
5
|
var getStorage = function (key) {
|
|
5
6
|
if (wx.getStorageSync) {
|
|
6
7
|
var rst = void 0;
|
|
7
8
|
try {
|
|
8
|
-
rst = wx.getStorageSync(key);
|
|
9
|
+
rst = (0, silent_1.silent)(function () { return wx.getStorageSync(key); });
|
|
9
10
|
}
|
|
10
11
|
catch (e) {
|
|
11
12
|
console.error(e);
|
|
@@ -15,12 +16,14 @@ var getStorage = function (key) {
|
|
|
15
16
|
};
|
|
16
17
|
exports.getStorage = getStorage;
|
|
17
18
|
var setStorage = function (key, value) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
19
|
+
(0, silent_1.silent)(function () {
|
|
20
|
+
return wx.setStorage({
|
|
21
|
+
key: key,
|
|
22
|
+
data: value,
|
|
23
|
+
fail: function (e) {
|
|
24
|
+
console.log(e);
|
|
25
|
+
}
|
|
26
|
+
});
|
|
24
27
|
});
|
|
25
28
|
};
|
|
26
29
|
exports.setStorage = setStorage;
|