@we-debug/plugin-appdata 0.40.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 +19 -0
- package/LICENSE +21 -0
- package/README.md +11 -0
- package/dist/index.js +216 -0
- package/package.json +31 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# Change Log
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
|
+
|
|
6
|
+
# [0.40.0](https://github.com/dlhandsome/we-debug/compare/v0.39.0...v0.40.0) (2025-03-07)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @we-debug/plugin-appdata
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
# [0.39.0](https://github.com/dlhandsome/we-debug/compare/v0.38.1...v0.39.0) (2025-03-07)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
### Features
|
|
18
|
+
|
|
19
|
+
* **plugin-appdata:** support appdata ([6df8fe8](https://github.com/dlhandsome/we-debug/commit/6df8fe83cef9f5b4d41859754893697376dd9732))
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020 Sail
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
var _a;
|
|
39
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
40
|
+
var utils_1 = require("./utils");
|
|
41
|
+
var AppDataPlugin = {
|
|
42
|
+
install: function () { }
|
|
43
|
+
};
|
|
44
|
+
var ActionType;
|
|
45
|
+
(function (ActionType) {
|
|
46
|
+
ActionType["COPY"] = "\u590D\u5236";
|
|
47
|
+
ActionType["EDIT"] = "\u7F16\u8F91";
|
|
48
|
+
ActionType["CLEAR"] = "\u6E05\u7A7A";
|
|
49
|
+
})(ActionType || (ActionType = {}));
|
|
50
|
+
function getCurrentPage() {
|
|
51
|
+
var pages = getCurrentPages();
|
|
52
|
+
return pages.length > 0 ? pages[pages.length - 1] : null;
|
|
53
|
+
}
|
|
54
|
+
var actionHandlers = (_a = {},
|
|
55
|
+
_a[ActionType.COPY] = function (data) { return __awaiter(void 0, void 0, void 0, function () {
|
|
56
|
+
var error_1;
|
|
57
|
+
return __generator(this, function (_a) {
|
|
58
|
+
switch (_a.label) {
|
|
59
|
+
case 0:
|
|
60
|
+
_a.trys.push([0, 3, , 4]);
|
|
61
|
+
return [4, (0, utils_1.setClipboardData)(data.value)];
|
|
62
|
+
case 1:
|
|
63
|
+
_a.sent();
|
|
64
|
+
return [4, (0, utils_1.showToast)({ title: '复制成功', icon: 'none' })];
|
|
65
|
+
case 2:
|
|
66
|
+
_a.sent();
|
|
67
|
+
return [3, 4];
|
|
68
|
+
case 3:
|
|
69
|
+
error_1 = _a.sent();
|
|
70
|
+
console.error('Copy failed:', error_1);
|
|
71
|
+
return [3, 4];
|
|
72
|
+
case 4: return [2, false];
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
}); },
|
|
76
|
+
_a[ActionType.EDIT] = function (_a) {
|
|
77
|
+
var page = _a.page, key = _a.key;
|
|
78
|
+
return __awaiter(void 0, void 0, void 0, function () {
|
|
79
|
+
var res, newValue, error_2;
|
|
80
|
+
var _b;
|
|
81
|
+
return __generator(this, function (_c) {
|
|
82
|
+
switch (_c.label) {
|
|
83
|
+
case 0:
|
|
84
|
+
_c.trys.push([0, 4, , 5]);
|
|
85
|
+
return [4, (0, utils_1.showModal)({
|
|
86
|
+
title: '编辑',
|
|
87
|
+
editable: true,
|
|
88
|
+
placeholderText: '请输入新的值',
|
|
89
|
+
confirmText: '确定',
|
|
90
|
+
cancelText: '取消',
|
|
91
|
+
})];
|
|
92
|
+
case 1:
|
|
93
|
+
res = _c.sent();
|
|
94
|
+
if (!(res.confirm && res.content)) return [3, 3];
|
|
95
|
+
newValue = typeof page.data[key] === 'number'
|
|
96
|
+
? Number(res.content)
|
|
97
|
+
: res.content;
|
|
98
|
+
return [4, page.setData((_b = {}, _b[key] = newValue, _b))];
|
|
99
|
+
case 2:
|
|
100
|
+
_c.sent();
|
|
101
|
+
return [2, true];
|
|
102
|
+
case 3: return [3, 5];
|
|
103
|
+
case 4:
|
|
104
|
+
error_2 = _c.sent();
|
|
105
|
+
console.error('Edit failed:', error_2);
|
|
106
|
+
return [3, 5];
|
|
107
|
+
case 5: return [2, false];
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
},
|
|
112
|
+
_a[ActionType.CLEAR] = function (_a) {
|
|
113
|
+
var page = _a.page, key = _a.key;
|
|
114
|
+
return __awaiter(void 0, void 0, void 0, function () {
|
|
115
|
+
var error_3;
|
|
116
|
+
var _b;
|
|
117
|
+
return __generator(this, function (_c) {
|
|
118
|
+
switch (_c.label) {
|
|
119
|
+
case 0:
|
|
120
|
+
_c.trys.push([0, 2, , 3]);
|
|
121
|
+
return [4, page.setData((_b = {}, _b[key] = undefined, _b))];
|
|
122
|
+
case 1:
|
|
123
|
+
_c.sent();
|
|
124
|
+
return [2, true];
|
|
125
|
+
case 2:
|
|
126
|
+
error_3 = _c.sent();
|
|
127
|
+
console.error('Clear failed:', error_3);
|
|
128
|
+
return [2, false];
|
|
129
|
+
case 3: return [2];
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
});
|
|
133
|
+
},
|
|
134
|
+
_a);
|
|
135
|
+
function getAvailableActions(value) {
|
|
136
|
+
return typeof value === 'string' || typeof value === 'number'
|
|
137
|
+
? [ActionType.COPY, ActionType.EDIT, ActionType.CLEAR]
|
|
138
|
+
: [ActionType.COPY, ActionType.CLEAR];
|
|
139
|
+
}
|
|
140
|
+
function createDebugRule(weDebug, key, value, page) {
|
|
141
|
+
var _this = this;
|
|
142
|
+
var itemList = getAvailableActions(value);
|
|
143
|
+
var stringValue = JSON.stringify(value);
|
|
144
|
+
return weDebug.createFormRule({
|
|
145
|
+
title: key || '',
|
|
146
|
+
desc: stringValue,
|
|
147
|
+
state: { name: '操作' },
|
|
148
|
+
handler: {
|
|
149
|
+
bindTap: function () { return __awaiter(_this, void 0, void 0, function () {
|
|
150
|
+
var res, actionType, handler, needsRefresh, error_4;
|
|
151
|
+
return __generator(this, function (_a) {
|
|
152
|
+
switch (_a.label) {
|
|
153
|
+
case 0:
|
|
154
|
+
_a.trys.push([0, 4, , 5]);
|
|
155
|
+
return [4, (0, utils_1.showActionSheet)({
|
|
156
|
+
itemList: itemList,
|
|
157
|
+
alertText: '缓存操作',
|
|
158
|
+
})];
|
|
159
|
+
case 1:
|
|
160
|
+
res = _a.sent();
|
|
161
|
+
actionType = itemList[res.tapIndex];
|
|
162
|
+
handler = actionHandlers[actionType];
|
|
163
|
+
if (!handler) return [3, 3];
|
|
164
|
+
return [4, handler({
|
|
165
|
+
page: page,
|
|
166
|
+
key: key,
|
|
167
|
+
value: stringValue
|
|
168
|
+
})];
|
|
169
|
+
case 2:
|
|
170
|
+
needsRefresh = _a.sent();
|
|
171
|
+
if (needsRefresh) {
|
|
172
|
+
refreshRules(weDebug);
|
|
173
|
+
}
|
|
174
|
+
_a.label = 3;
|
|
175
|
+
case 3: return [3, 5];
|
|
176
|
+
case 4:
|
|
177
|
+
error_4 = _a.sent();
|
|
178
|
+
console.error('Action failed:', error_4);
|
|
179
|
+
return [3, 5];
|
|
180
|
+
case 5: return [2];
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
}); },
|
|
184
|
+
},
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
function getCurrentRules(weDebug) {
|
|
188
|
+
var page = getCurrentPage();
|
|
189
|
+
if (!page)
|
|
190
|
+
return [];
|
|
191
|
+
var data = page.data || {};
|
|
192
|
+
return Object.keys(data).map(function (key) {
|
|
193
|
+
return createDebugRule(weDebug, key, data[key], page);
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
var currentRules = [];
|
|
197
|
+
function refreshRules(weDebug) {
|
|
198
|
+
currentRules.forEach(function (rule) {
|
|
199
|
+
weDebug.removeGroupRule('AppData', rule);
|
|
200
|
+
});
|
|
201
|
+
currentRules = getCurrentRules(weDebug);
|
|
202
|
+
weDebug.addFormRule(currentRules, {
|
|
203
|
+
group: {
|
|
204
|
+
name: 'AppData',
|
|
205
|
+
private: true,
|
|
206
|
+
},
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
AppDataPlugin.install = function (weDebug, options) {
|
|
210
|
+
if (!Array.isArray(options))
|
|
211
|
+
options = [options];
|
|
212
|
+
weDebug.event.on('debug:mask:show-modal', function () {
|
|
213
|
+
refreshRules(weDebug);
|
|
214
|
+
});
|
|
215
|
+
};
|
|
216
|
+
exports.default = AppDataPlugin;
|
package/package.json
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@we-debug/plugin-appdata",
|
|
3
|
+
"version": "0.40.0",
|
|
4
|
+
"description": "> TODO: description",
|
|
5
|
+
"author": "Sail <505441575@qq.com>",
|
|
6
|
+
"homepage": "https://github.com/dlhandsome/we-debug/tree/master/packages/runtime/plugin-appdata#readme",
|
|
7
|
+
"license": "ISC",
|
|
8
|
+
"main": "dist/index.js",
|
|
9
|
+
"types": "dist/types.d.ts",
|
|
10
|
+
"directories": {
|
|
11
|
+
"lib": "lib",
|
|
12
|
+
"test": "__tests__"
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"lib"
|
|
16
|
+
],
|
|
17
|
+
"publishConfig": {
|
|
18
|
+
"access": "public"
|
|
19
|
+
},
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "git+https://github.com/dlhandsome/we-debug.git"
|
|
23
|
+
},
|
|
24
|
+
"scripts": {
|
|
25
|
+
"test": "echo \"Error: run tests from root\" && exit 1"
|
|
26
|
+
},
|
|
27
|
+
"bugs": {
|
|
28
|
+
"url": "https://github.com/dlhandsome/we-debug/issues"
|
|
29
|
+
},
|
|
30
|
+
"gitHead": "ed3faec0025d32e4e91cc281401f9e580430b967"
|
|
31
|
+
}
|