@we-debug/plugin-appdata 0.40.0 → 0.40.2
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 +22 -0
- package/dist/index.d.ts +3 -0
- package/dist/types.d.ts +24 -0
- package/dist/types.js +17 -0
- package/dist/utils.d.ts +4 -0
- package/dist/utils.js +42 -0
- package/package.json +2 -9
- package/src/index.ts +159 -0
- package/src/types.ts +33 -0
- package/src/utils.ts +39 -0
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,28 @@
|
|
|
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.40.2](https://github.com/dlhandsome/we-debug/compare/v0.40.1...v0.40.2) (2025-03-07)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* remove file pkg.json ([07c9166](https://github.com/dlhandsome/we-debug/commit/07c916616a6950802ae36837b114f7d89b6ff3d2))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
## [0.40.1](https://github.com/dlhandsome/we-debug/compare/v0.40.0...v0.40.1) (2025-03-07)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
### Bug Fixes
|
|
21
|
+
|
|
22
|
+
* fixed eslint ([c058f87](https://github.com/dlhandsome/we-debug/commit/c058f8743961cac8cdae38b8fe72c12fd78139c7))
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
6
28
|
# [0.40.0](https://github.com/dlhandsome/we-debug/compare/v0.39.0...v0.40.0) (2025-03-07)
|
|
7
29
|
|
|
8
30
|
**Note:** Version bump only for package @we-debug/plugin-appdata
|
package/dist/index.d.ts
ADDED
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/// <reference types="miniprogram-api-typings" />
|
|
2
|
+
import { IPluginInstance } from '@we-debug/core';
|
|
3
|
+
export * from '@we-debug/core';
|
|
4
|
+
export interface IPlugin extends IPluginInstance {
|
|
5
|
+
installed?: boolean;
|
|
6
|
+
}
|
|
7
|
+
export interface IPluginInitOption {
|
|
8
|
+
title: string;
|
|
9
|
+
name?: string;
|
|
10
|
+
desc?: string;
|
|
11
|
+
url: string;
|
|
12
|
+
}
|
|
13
|
+
export type IPluginInitOptions = IPluginInitOption | IPluginInitOption[];
|
|
14
|
+
export type IActionMetaData = {
|
|
15
|
+
page: WechatMiniprogram.Page.Instance<any, any>;
|
|
16
|
+
key: string;
|
|
17
|
+
value: string;
|
|
18
|
+
};
|
|
19
|
+
export interface ActionHandler {
|
|
20
|
+
(data: IActionMetaData): Promise<boolean>;
|
|
21
|
+
}
|
|
22
|
+
export interface ActionHandlers {
|
|
23
|
+
[key: string]: ActionHandler;
|
|
24
|
+
}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("@we-debug/core"), exports);
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare const showToast: (options: WechatMiniprogram.ShowToastOption) => Promise<void>;
|
|
2
|
+
export declare const showModal: (options: WechatMiniprogram.ShowModalOption) => Promise<WechatMiniprogram.ShowModalSuccessCallbackResult>;
|
|
3
|
+
export declare const showActionSheet: (options: WechatMiniprogram.ShowActionSheetOption) => Promise<WechatMiniprogram.ShowActionSheetSuccessCallbackResult>;
|
|
4
|
+
export declare const setClipboardData: (data: string) => Promise<void>;
|
package/dist/utils.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.setClipboardData = exports.showActionSheet = exports.showModal = exports.showToast = void 0;
|
|
15
|
+
var showToast = function (options) {
|
|
16
|
+
return new Promise(function (resolve, reject) {
|
|
17
|
+
wx.showToast(__assign(__assign({}, options), { success: function () { return resolve(); }, fail: reject }));
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
exports.showToast = showToast;
|
|
21
|
+
var showModal = function (options) {
|
|
22
|
+
return new Promise(function (resolve, reject) {
|
|
23
|
+
wx.showModal(__assign(__assign({}, options), { success: resolve, fail: reject }));
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
exports.showModal = showModal;
|
|
27
|
+
var showActionSheet = function (options) {
|
|
28
|
+
return new Promise(function (resolve, reject) {
|
|
29
|
+
wx.showActionSheet(__assign(__assign({}, options), { success: resolve, fail: reject }));
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
exports.showActionSheet = showActionSheet;
|
|
33
|
+
var setClipboardData = function (data) {
|
|
34
|
+
return new Promise(function (resolve, reject) {
|
|
35
|
+
wx.setClipboardData({
|
|
36
|
+
data: data,
|
|
37
|
+
success: function () { return resolve(); },
|
|
38
|
+
fail: reject,
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
};
|
|
42
|
+
exports.setClipboardData = setClipboardData;
|
package/package.json
CHANGED
|
@@ -1,19 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@we-debug/plugin-appdata",
|
|
3
|
-
"version": "0.40.
|
|
3
|
+
"version": "0.40.2",
|
|
4
4
|
"description": "> TODO: description",
|
|
5
5
|
"author": "Sail <505441575@qq.com>",
|
|
6
6
|
"homepage": "https://github.com/dlhandsome/we-debug/tree/master/packages/runtime/plugin-appdata#readme",
|
|
7
7
|
"license": "ISC",
|
|
8
8
|
"main": "dist/index.js",
|
|
9
9
|
"types": "dist/types.d.ts",
|
|
10
|
-
"directories": {
|
|
11
|
-
"lib": "lib",
|
|
12
|
-
"test": "__tests__"
|
|
13
|
-
},
|
|
14
|
-
"files": [
|
|
15
|
-
"lib"
|
|
16
|
-
],
|
|
17
10
|
"publishConfig": {
|
|
18
11
|
"access": "public"
|
|
19
12
|
},
|
|
@@ -27,5 +20,5 @@
|
|
|
27
20
|
"bugs": {
|
|
28
21
|
"url": "https://github.com/dlhandsome/we-debug/issues"
|
|
29
22
|
},
|
|
30
|
-
"gitHead": "
|
|
23
|
+
"gitHead": "037dc7e1905d7f804dfe81b63b03191c074df859"
|
|
31
24
|
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import {
|
|
2
|
+
showToast,
|
|
3
|
+
showModal,
|
|
4
|
+
showActionSheet,
|
|
5
|
+
setClipboardData } from './utils';
|
|
6
|
+
import {
|
|
7
|
+
IPlugin,
|
|
8
|
+
IPluginInitOptions,
|
|
9
|
+
ActionHandlers
|
|
10
|
+
} from './types';
|
|
11
|
+
|
|
12
|
+
const AppDataPlugin: IPlugin = {
|
|
13
|
+
install () {}
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
// 定义操作类型
|
|
17
|
+
enum ActionType {
|
|
18
|
+
COPY = '复制',
|
|
19
|
+
EDIT = '编辑',
|
|
20
|
+
CLEAR = '清空',
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// 获取当前页面实例
|
|
24
|
+
function getCurrentPage(): WechatMiniprogram.Page.Instance<any, any> | null {
|
|
25
|
+
const pages = getCurrentPages();
|
|
26
|
+
return pages.length > 0 ? pages[pages.length - 1] : null;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// 处理数据操作的动作映射
|
|
30
|
+
const actionHandlers: ActionHandlers = {
|
|
31
|
+
[ActionType.COPY]: async (data) => {
|
|
32
|
+
try {
|
|
33
|
+
await setClipboardData(data.value);
|
|
34
|
+
await showToast({ title: '复制成功', icon: 'none' });
|
|
35
|
+
} catch (error) {
|
|
36
|
+
console.error('Copy failed:', error);
|
|
37
|
+
}
|
|
38
|
+
return false;
|
|
39
|
+
},
|
|
40
|
+
[ActionType.EDIT]: async ({ page, key }) => {
|
|
41
|
+
try {
|
|
42
|
+
const res = await showModal({
|
|
43
|
+
title: '编辑',
|
|
44
|
+
editable: true,
|
|
45
|
+
placeholderText: '请输入新的值',
|
|
46
|
+
confirmText: '确定',
|
|
47
|
+
cancelText: '取消',
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
if (res.confirm && res.content) {
|
|
51
|
+
const newValue = typeof page.data[key] === 'number'
|
|
52
|
+
? Number(res.content)
|
|
53
|
+
: res.content;
|
|
54
|
+
|
|
55
|
+
await page.setData({ [key]: newValue });
|
|
56
|
+
return true; // 表示数据已更新
|
|
57
|
+
}
|
|
58
|
+
} catch (error) {
|
|
59
|
+
console.error('Edit failed:', error);
|
|
60
|
+
}
|
|
61
|
+
return false;
|
|
62
|
+
},
|
|
63
|
+
[ActionType.CLEAR]: async ({ page, key }) => {
|
|
64
|
+
try {
|
|
65
|
+
await page.setData({ [key]: undefined });
|
|
66
|
+
return true; // 表示数据已更新
|
|
67
|
+
} catch (error) {
|
|
68
|
+
console.error('Clear failed:', error);
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
// 获取可用的操作列表
|
|
75
|
+
function getAvailableActions(value: any): ActionType[] {
|
|
76
|
+
return typeof value === 'string' || typeof value === 'number'
|
|
77
|
+
? [ActionType.COPY, ActionType.EDIT, ActionType.CLEAR]
|
|
78
|
+
: [ActionType.COPY, ActionType.CLEAR];
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// 创建调试规则
|
|
82
|
+
function createDebugRule(weDebug: any, key: string, value: any, page: WechatMiniprogram.Page.Instance<any, any>) {
|
|
83
|
+
const itemList = getAvailableActions(value);
|
|
84
|
+
const stringValue = JSON.stringify(value);
|
|
85
|
+
|
|
86
|
+
return weDebug.createFormRule({
|
|
87
|
+
title: key || '',
|
|
88
|
+
desc: stringValue,
|
|
89
|
+
state: { name: '操作' },
|
|
90
|
+
handler: {
|
|
91
|
+
bindTap: async () => {
|
|
92
|
+
try {
|
|
93
|
+
const res = await showActionSheet({
|
|
94
|
+
itemList,
|
|
95
|
+
alertText: '缓存操作',
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
const actionType = itemList[res.tapIndex] as ActionType;
|
|
99
|
+
const handler = actionHandlers[actionType];
|
|
100
|
+
|
|
101
|
+
if (handler) {
|
|
102
|
+
const needsRefresh = await handler({
|
|
103
|
+
page,
|
|
104
|
+
key,
|
|
105
|
+
value: stringValue
|
|
106
|
+
});
|
|
107
|
+
if (needsRefresh) {
|
|
108
|
+
refreshRules(weDebug);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
} catch (error) {
|
|
112
|
+
console.error('Action failed:', error);
|
|
113
|
+
}
|
|
114
|
+
},
|
|
115
|
+
},
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// 获取当前页面的所有调试规则
|
|
120
|
+
function getCurrentRules(weDebug: any): any[] {
|
|
121
|
+
const page = getCurrentPage();
|
|
122
|
+
if (!page) return [];
|
|
123
|
+
|
|
124
|
+
const data = page.data || {};
|
|
125
|
+
return Object.keys(data).map(key =>
|
|
126
|
+
createDebugRule(weDebug, key, data[key], page)
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// 存储当前规则列表
|
|
131
|
+
let currentRules: any[] = [];
|
|
132
|
+
|
|
133
|
+
// 刷新调试规则
|
|
134
|
+
function refreshRules(weDebug: any): void {
|
|
135
|
+
// 移除旧规则
|
|
136
|
+
currentRules.forEach(rule => {
|
|
137
|
+
weDebug.removeGroupRule('AppData', rule);
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
// 添加新规则
|
|
141
|
+
currentRules = getCurrentRules(weDebug);
|
|
142
|
+
weDebug.addFormRule(currentRules, {
|
|
143
|
+
group: {
|
|
144
|
+
name: 'AppData',
|
|
145
|
+
private: true,
|
|
146
|
+
},
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
AppDataPlugin.install = function (weDebug, options:IPluginInitOptions) {
|
|
151
|
+
if (!Array.isArray(options)) options = [options];
|
|
152
|
+
|
|
153
|
+
// 调试面板弹出时,触发规则更新
|
|
154
|
+
weDebug.event.on('debug:mask:show-modal', () => {
|
|
155
|
+
refreshRules(weDebug);
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
export default AppDataPlugin;
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import {
|
|
2
|
+
IPluginInstance,
|
|
3
|
+
} from '@we-debug/core';
|
|
4
|
+
|
|
5
|
+
export * from '@we-debug/core';
|
|
6
|
+
|
|
7
|
+
export interface IPlugin extends IPluginInstance {
|
|
8
|
+
installed?: boolean;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface IPluginInitOption {
|
|
12
|
+
title: string;
|
|
13
|
+
name?: string;
|
|
14
|
+
desc?: string;
|
|
15
|
+
url: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export type IPluginInitOptions = IPluginInitOption | IPluginInitOption[];
|
|
19
|
+
|
|
20
|
+
export type IActionMetaData = {
|
|
21
|
+
page: WechatMiniprogram.Page.Instance<any, any>;
|
|
22
|
+
key: string;
|
|
23
|
+
value: string;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface ActionHandler {
|
|
27
|
+
(data: IActionMetaData): Promise<boolean>;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface ActionHandlers {
|
|
31
|
+
[key: string]: ActionHandler;
|
|
32
|
+
}
|
|
33
|
+
|
package/src/utils.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export const showToast = (options: WechatMiniprogram.ShowToastOption) => {
|
|
2
|
+
return new Promise<void>((resolve, reject) => {
|
|
3
|
+
wx.showToast({
|
|
4
|
+
...options,
|
|
5
|
+
success: () => resolve(),
|
|
6
|
+
fail: reject,
|
|
7
|
+
});
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export const showModal = (options: WechatMiniprogram.ShowModalOption) => {
|
|
12
|
+
return new Promise<WechatMiniprogram.ShowModalSuccessCallbackResult>((resolve, reject) => {
|
|
13
|
+
wx.showModal({
|
|
14
|
+
...options,
|
|
15
|
+
success: resolve,
|
|
16
|
+
fail: reject,
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export const showActionSheet = (options: WechatMiniprogram.ShowActionSheetOption) => {
|
|
22
|
+
return new Promise<WechatMiniprogram.ShowActionSheetSuccessCallbackResult>((resolve, reject) => {
|
|
23
|
+
wx.showActionSheet({
|
|
24
|
+
...options,
|
|
25
|
+
success: resolve,
|
|
26
|
+
fail: reject,
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export const setClipboardData = (data: string) => {
|
|
32
|
+
return new Promise<void>((resolve, reject) => {
|
|
33
|
+
wx.setClipboardData({
|
|
34
|
+
data,
|
|
35
|
+
success: () => resolve(),
|
|
36
|
+
fail: reject,
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
};
|