@whitesev/utils 2.9.10 → 2.9.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.
- package/dist/index.amd.js +46 -27
- package/dist/index.amd.js.map +1 -1
- package/dist/index.amd.min.js +1 -1
- package/dist/index.amd.min.js.map +1 -1
- package/dist/index.cjs.js +46 -27
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.cjs.min.js +1 -1
- package/dist/index.cjs.min.js.map +1 -1
- package/dist/index.esm.js +46 -27
- package/dist/index.esm.js.map +1 -1
- package/dist/index.esm.min.js +1 -1
- package/dist/index.esm.min.js.map +1 -1
- package/dist/index.iife.js +46 -27
- package/dist/index.iife.js.map +1 -1
- package/dist/index.iife.min.js +1 -1
- package/dist/index.iife.min.js.map +1 -1
- package/dist/index.system.js +46 -27
- package/dist/index.system.js.map +1 -1
- package/dist/index.system.min.js +1 -1
- package/dist/index.system.min.js.map +1 -1
- package/dist/index.umd.js +46 -27
- package/dist/index.umd.js.map +1 -1
- package/dist/index.umd.min.js +1 -1
- package/dist/index.umd.min.js.map +1 -1
- package/dist/types/src/UtilsGMMenu.d.ts +9 -7
- package/package.json +2 -2
- package/src/UtilsGMMenu.ts +47 -28
|
@@ -3,21 +3,23 @@ export declare class GMMenu {
|
|
|
3
3
|
private GM_Api;
|
|
4
4
|
private MenuHandle;
|
|
5
5
|
/**
|
|
6
|
-
* @param
|
|
6
|
+
* @param constructOptions 菜单配置
|
|
7
7
|
*/
|
|
8
|
-
constructor(
|
|
8
|
+
constructor(constructOptions: UtilsGMMenuConstructorOptions);
|
|
9
9
|
/**
|
|
10
10
|
* 新增菜单数据
|
|
11
|
-
* @param
|
|
11
|
+
* @param options
|
|
12
12
|
*/
|
|
13
13
|
private __add;
|
|
14
14
|
/**
|
|
15
15
|
* 新增菜单数据
|
|
16
16
|
*
|
|
17
17
|
* 自动调用.update()
|
|
18
|
-
* @param
|
|
18
|
+
* @param options
|
|
19
19
|
*/
|
|
20
|
-
add(
|
|
20
|
+
add(options: UtilsGMMenuOption[] | UtilsGMMenuOption): {
|
|
21
|
+
destory: () => void;
|
|
22
|
+
};
|
|
21
23
|
/**
|
|
22
24
|
* 更新菜单数据
|
|
23
25
|
*
|
|
@@ -31,9 +33,9 @@ export declare class GMMenu {
|
|
|
31
33
|
update(options?: UtilsGMMenuOption[] | UtilsGMMenuOption): void;
|
|
32
34
|
/**
|
|
33
35
|
* 卸载菜单
|
|
34
|
-
* @param menuId 已注册的菜单id
|
|
36
|
+
* @param menuId 已注册的菜单id或者键名
|
|
35
37
|
*/
|
|
36
|
-
delete(menuId: number): void;
|
|
38
|
+
delete(menuId: number | string): void;
|
|
37
39
|
/**
|
|
38
40
|
* 根据键值获取enable值
|
|
39
41
|
* @param menuKey 菜单-键key
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/package.json",
|
|
3
3
|
"name": "@whitesev/utils",
|
|
4
|
-
"version": "2.9.
|
|
4
|
+
"version": "2.9.11",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "一个常用的工具库",
|
|
7
7
|
"main": "dist/index.cjs.js",
|
|
@@ -64,7 +64,7 @@
|
|
|
64
64
|
"lint": "eslint .",
|
|
65
65
|
"lint:fix": "eslint . --fix",
|
|
66
66
|
"format": "prettier . --write",
|
|
67
|
-
"dev": "
|
|
67
|
+
"dev": "vue-tsc --noEmit && vite --force",
|
|
68
68
|
"build": "pnpm run format && pnpm run lint && rollup -c"
|
|
69
69
|
}
|
|
70
70
|
}
|
package/src/UtilsGMMenu.ts
CHANGED
|
@@ -223,29 +223,30 @@ export class GMMenu {
|
|
|
223
223
|
},
|
|
224
224
|
};
|
|
225
225
|
/**
|
|
226
|
-
* @param
|
|
226
|
+
* @param constructOptions 菜单配置
|
|
227
227
|
*/
|
|
228
|
-
constructor(
|
|
229
|
-
this.GM_Api.getValue =
|
|
230
|
-
this.GM_Api.setValue =
|
|
231
|
-
this.GM_Api.registerMenuCommand =
|
|
232
|
-
this.GM_Api.unregisterMenuCommand =
|
|
233
|
-
this.MenuHandle.$default.autoReload =
|
|
228
|
+
constructor(constructOptions: UtilsGMMenuConstructorOptions) {
|
|
229
|
+
this.GM_Api.getValue = constructOptions.GM_getValue;
|
|
230
|
+
this.GM_Api.setValue = constructOptions.GM_setValue;
|
|
231
|
+
this.GM_Api.registerMenuCommand = constructOptions.GM_registerMenuCommand;
|
|
232
|
+
this.GM_Api.unregisterMenuCommand = constructOptions.GM_unregisterMenuCommand;
|
|
233
|
+
this.MenuHandle.$default.autoReload =
|
|
234
|
+
typeof constructOptions.autoReload === "boolean" ? constructOptions.autoReload : true;
|
|
234
235
|
for (const keyName of Object.keys(this.GM_Api)) {
|
|
235
236
|
if (typeof (this.GM_Api as any)[keyName] !== "function") {
|
|
236
237
|
throw new Error(`Utils.GM_Menu 请在脚本开头加上 @grant ${keyName},且传入该对象`);
|
|
237
238
|
}
|
|
238
239
|
}
|
|
239
|
-
this.add(
|
|
240
|
+
this.add(constructOptions?.data || []);
|
|
240
241
|
}
|
|
241
242
|
/**
|
|
242
243
|
* 新增菜单数据
|
|
243
|
-
* @param
|
|
244
|
+
* @param options
|
|
244
245
|
*/
|
|
245
|
-
private __add(
|
|
246
|
-
if (Array.isArray(
|
|
247
|
-
for (let index = 0; index <
|
|
248
|
-
const option =
|
|
246
|
+
private __add(options: UtilsGMMenuOption[] | UtilsGMMenuOption) {
|
|
247
|
+
if (Array.isArray(options)) {
|
|
248
|
+
for (let index = 0; index < options.length; index++) {
|
|
249
|
+
const option = options[index];
|
|
249
250
|
this.MenuHandle.$data.data.push({
|
|
250
251
|
data: option,
|
|
251
252
|
id: void 0,
|
|
@@ -253,7 +254,7 @@ export class GMMenu {
|
|
|
253
254
|
}
|
|
254
255
|
} else {
|
|
255
256
|
this.MenuHandle.$data.data.push({
|
|
256
|
-
data:
|
|
257
|
+
data: options,
|
|
257
258
|
id: void 0,
|
|
258
259
|
});
|
|
259
260
|
}
|
|
@@ -262,11 +263,21 @@ export class GMMenu {
|
|
|
262
263
|
* 新增菜单数据
|
|
263
264
|
*
|
|
264
265
|
* 自动调用.update()
|
|
265
|
-
* @param
|
|
266
|
+
* @param options
|
|
266
267
|
*/
|
|
267
|
-
add(
|
|
268
|
-
this.__add(
|
|
268
|
+
add(options: UtilsGMMenuOption[] | UtilsGMMenuOption) {
|
|
269
|
+
this.__add(options);
|
|
269
270
|
this.update();
|
|
271
|
+
return {
|
|
272
|
+
destory: () => {
|
|
273
|
+
if (!Array.isArray(options)) {
|
|
274
|
+
options = [options];
|
|
275
|
+
}
|
|
276
|
+
options.forEach((option) => {
|
|
277
|
+
this.delete(option.key);
|
|
278
|
+
});
|
|
279
|
+
},
|
|
280
|
+
};
|
|
270
281
|
}
|
|
271
282
|
/**
|
|
272
283
|
* 更新菜单数据
|
|
@@ -285,13 +296,13 @@ export class GMMenu {
|
|
|
285
296
|
} else if (options != null) {
|
|
286
297
|
menuOptionList = [...menuOptionList, options];
|
|
287
298
|
}
|
|
288
|
-
menuOptionList.forEach((
|
|
289
|
-
const oldMenuOption = this.MenuHandle.getMenuOption(
|
|
299
|
+
menuOptionList.forEach((option) => {
|
|
300
|
+
const oldMenuOption = this.MenuHandle.getMenuOption(option.key);
|
|
290
301
|
if (oldMenuOption) {
|
|
291
302
|
// 覆盖
|
|
292
|
-
Object.assign(oldMenuOption,
|
|
303
|
+
Object.assign(oldMenuOption, option);
|
|
293
304
|
} else {
|
|
294
|
-
this.__add(
|
|
305
|
+
this.__add(option);
|
|
295
306
|
}
|
|
296
307
|
});
|
|
297
308
|
this.MenuHandle.$data.data.forEach((value) => {
|
|
@@ -304,9 +315,15 @@ export class GMMenu {
|
|
|
304
315
|
}
|
|
305
316
|
/**
|
|
306
317
|
* 卸载菜单
|
|
307
|
-
* @param menuId 已注册的菜单id
|
|
318
|
+
* @param menuId 已注册的菜单id或者键名
|
|
308
319
|
*/
|
|
309
|
-
delete(menuId: number) {
|
|
320
|
+
delete(menuId: number | string) {
|
|
321
|
+
if (typeof menuId === "string") {
|
|
322
|
+
const __menuId = this.getMenuId(menuId);
|
|
323
|
+
if (__menuId != null) {
|
|
324
|
+
menuId = __menuId;
|
|
325
|
+
}
|
|
326
|
+
}
|
|
310
327
|
this.GM_Api.unregisterMenuCommand(menuId);
|
|
311
328
|
}
|
|
312
329
|
/**
|
|
@@ -328,18 +345,20 @@ export class GMMenu {
|
|
|
328
345
|
* @param menuKey 菜单-键key
|
|
329
346
|
*/
|
|
330
347
|
getShowTextValue(menuKey: string): string {
|
|
331
|
-
|
|
348
|
+
const text = this.getText(menuKey);
|
|
349
|
+
const enable = this.getEnable(menuKey);
|
|
350
|
+
return this.MenuHandle.getMenuHandledOption(menuKey)!.showText(text, enable);
|
|
332
351
|
}
|
|
333
352
|
/**
|
|
334
353
|
* 获取当前已注册菜单的id
|
|
335
354
|
* @param menuKey
|
|
336
355
|
*/
|
|
337
356
|
getMenuId(menuKey: string): number | undefined | null {
|
|
338
|
-
let result = null;
|
|
357
|
+
let result: number | undefined | null = null;
|
|
339
358
|
for (let index = 0; index < this.MenuHandle.$data.data.length; index++) {
|
|
340
|
-
const
|
|
341
|
-
if (
|
|
342
|
-
result =
|
|
359
|
+
const option = this.MenuHandle.$data.data[index];
|
|
360
|
+
if (option.handleData?.key === menuKey) {
|
|
361
|
+
result = option.id;
|
|
343
362
|
break;
|
|
344
363
|
}
|
|
345
364
|
}
|