@widget-js/core 0.0.6 → 0.0.7
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/cjs/api/ElectronApi.js +118 -1
- package/dist/cjs/api/Keys.js +14 -0
- package/dist/cjs/index.js +3 -0
- package/dist/cjs/model/BroadcastEvent.js +12 -0
- package/dist/cjs/model/SocialInfo.js +11 -0
- package/dist/cjs/model/Widget.js +54 -22
- package/dist/cjs/model/WidgetData.js +13 -0
- package/dist/esm/api/ElectronApi.js +118 -1
- package/dist/esm/api/Keys.js +11 -0
- package/dist/esm/index.js +3 -0
- package/dist/esm/model/BroadcastEvent.js +9 -0
- package/dist/esm/model/SocialInfo.js +8 -0
- package/dist/esm/model/Widget.js +54 -22
- package/dist/esm/model/WidgetData.js +11 -0
- package/dist/types/api/ElectronApi.d.ts +8 -0
- package/dist/types/api/Keys.d.ts +7 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/model/BroadcastEvent.d.ts +6 -0
- package/dist/types/model/SocialInfo.d.ts +6 -0
- package/dist/types/model/Widget.d.ts +47 -5
- package/dist/types/model/WidgetData.d.ts +18 -0
- package/dist/umd/index.js +1 -1
- package/package.json +4 -3
|
@@ -37,6 +37,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
39
|
exports.ElectronApi = void 0;
|
|
40
|
+
var Keys_1 = require("./Keys");
|
|
40
41
|
var ElectronApi = /** @class */ (function () {
|
|
41
42
|
function ElectronApi() {
|
|
42
43
|
}
|
|
@@ -53,7 +54,7 @@ var ElectronApi = /** @class */ (function () {
|
|
|
53
54
|
switch (_a.label) {
|
|
54
55
|
case 0:
|
|
55
56
|
if (!this.hasElectronApi()) return [3 /*break*/, 2];
|
|
56
|
-
data = JSON.parse(JSON.stringify(widgets.map(function (item) { return
|
|
57
|
+
data = JSON.parse(JSON.stringify(widgets.map(function (item) { return JSON.stringify(item); })));
|
|
57
58
|
// @ts-ignore
|
|
58
59
|
return [4 /*yield*/, window.electronAPI.invokeIpc("registerWidgets", data)];
|
|
59
60
|
case 1:
|
|
@@ -65,6 +66,122 @@ var ElectronApi = /** @class */ (function () {
|
|
|
65
66
|
});
|
|
66
67
|
});
|
|
67
68
|
};
|
|
69
|
+
ElectronApi.setConfig = function (key, value) {
|
|
70
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
71
|
+
return __generator(this, function (_a) {
|
|
72
|
+
switch (_a.label) {
|
|
73
|
+
case 0:
|
|
74
|
+
if (!this.hasElectronApi()) return [3 /*break*/, 2];
|
|
75
|
+
// @ts-ignore
|
|
76
|
+
return [4 /*yield*/, window.electronAPI.invokeIpc("setConfig", { key: key, value: value })];
|
|
77
|
+
case 1:
|
|
78
|
+
// @ts-ignore
|
|
79
|
+
_a.sent();
|
|
80
|
+
_a.label = 2;
|
|
81
|
+
case 2: return [2 /*return*/];
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
};
|
|
86
|
+
ElectronApi.sendBroadcastEvent = function (event) {
|
|
87
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
88
|
+
return __generator(this, function (_a) {
|
|
89
|
+
switch (_a.label) {
|
|
90
|
+
case 0:
|
|
91
|
+
if (!this.hasElectronApi()) return [3 /*break*/, 2];
|
|
92
|
+
// @ts-ignore
|
|
93
|
+
return [4 /*yield*/, window.electronAPI.invokeIpc(Keys_1.Keys.BROADCAST_EVENT, JSON.stringify(event))];
|
|
94
|
+
case 1:
|
|
95
|
+
// @ts-ignore
|
|
96
|
+
_a.sent();
|
|
97
|
+
_a.label = 2;
|
|
98
|
+
case 2: return [2 /*return*/];
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
};
|
|
103
|
+
ElectronApi.registerBroadcast = function (callback) {
|
|
104
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
105
|
+
return __generator(this, function (_a) {
|
|
106
|
+
switch (_a.label) {
|
|
107
|
+
case 0: return [4 /*yield*/, this.addIpcListener(Keys_1.Keys.BROADCAST_EVENT, function (json) {
|
|
108
|
+
callback(JSON.parse(json));
|
|
109
|
+
})];
|
|
110
|
+
case 1:
|
|
111
|
+
_a.sent();
|
|
112
|
+
return [2 /*return*/];
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
};
|
|
117
|
+
ElectronApi.unregisterBroadcast = function () {
|
|
118
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
119
|
+
return __generator(this, function (_a) {
|
|
120
|
+
switch (_a.label) {
|
|
121
|
+
case 0: return [4 /*yield*/, this.removeIpcListener(Keys_1.Keys.BROADCAST_EVENT)];
|
|
122
|
+
case 1:
|
|
123
|
+
_a.sent();
|
|
124
|
+
return [2 /*return*/];
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
};
|
|
129
|
+
ElectronApi.addIpcListener = function (key, f) {
|
|
130
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
131
|
+
return __generator(this, function (_a) {
|
|
132
|
+
switch (_a.label) {
|
|
133
|
+
case 0:
|
|
134
|
+
if (!this.hasElectronApi()) return [3 /*break*/, 2];
|
|
135
|
+
// @ts-ignore
|
|
136
|
+
return [4 /*yield*/, window.electronAPI.addIpcListener(key, f)];
|
|
137
|
+
case 1:
|
|
138
|
+
// @ts-ignore
|
|
139
|
+
_a.sent();
|
|
140
|
+
_a.label = 2;
|
|
141
|
+
case 2: return [2 /*return*/];
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
};
|
|
146
|
+
ElectronApi.removeIpcListener = function (key) {
|
|
147
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
148
|
+
return __generator(this, function (_a) {
|
|
149
|
+
switch (_a.label) {
|
|
150
|
+
case 0:
|
|
151
|
+
if (!this.hasElectronApi()) return [3 /*break*/, 2];
|
|
152
|
+
// @ts-ignore
|
|
153
|
+
return [4 /*yield*/, window.electronAPI.removeIpcListener(key)];
|
|
154
|
+
case 1:
|
|
155
|
+
// @ts-ignore
|
|
156
|
+
_a.sent();
|
|
157
|
+
_a.label = 2;
|
|
158
|
+
case 2: return [2 /*return*/];
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
});
|
|
162
|
+
};
|
|
163
|
+
ElectronApi.getConfig = function (key, defaultValue) {
|
|
164
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
165
|
+
var value;
|
|
166
|
+
return __generator(this, function (_a) {
|
|
167
|
+
switch (_a.label) {
|
|
168
|
+
case 0:
|
|
169
|
+
if (!this.hasElectronApi()) return [3 /*break*/, 2];
|
|
170
|
+
return [4 /*yield*/, window.electronAPI.invokeIpc("getConfig", key)];
|
|
171
|
+
case 1:
|
|
172
|
+
value = _a.sent();
|
|
173
|
+
if (value === null || value === undefined) {
|
|
174
|
+
return [2 /*return*/, defaultValue];
|
|
175
|
+
}
|
|
176
|
+
if (typeof defaultValue == "boolean") {
|
|
177
|
+
return [2 /*return*/, value === "true"];
|
|
178
|
+
}
|
|
179
|
+
return [2 /*return*/, value];
|
|
180
|
+
case 2: return [2 /*return*/];
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
});
|
|
184
|
+
};
|
|
68
185
|
ElectronApi.hasElectronApi = function () {
|
|
69
186
|
return Reflect.has(window, "electronAPI");
|
|
70
187
|
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Keys = void 0;
|
|
4
|
+
var Keys = /** @class */ (function () {
|
|
5
|
+
function Keys() {
|
|
6
|
+
}
|
|
7
|
+
Keys.CONFIG_LAUNCH_AT_STARTUP = "LAUNCH_AT_STARTUP";
|
|
8
|
+
Keys.CONFIG_WIDGET_SHADOW = "WIDGET_SHADOW";
|
|
9
|
+
Keys.CHANNEL_MAIN = "WeiZ5kaKijae";
|
|
10
|
+
Keys.EVENT_WIDGET_UPDATED = "WIDGET_SHADOW";
|
|
11
|
+
Keys.BROADCAST_EVENT = "sendBroadcastEvent";
|
|
12
|
+
return Keys;
|
|
13
|
+
}());
|
|
14
|
+
exports.Keys = Keys;
|
package/dist/cjs/index.js
CHANGED
|
@@ -15,4 +15,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./model/Widget"), exports);
|
|
18
|
+
__exportStar(require("./model/BroadcastEvent"), exports);
|
|
19
|
+
__exportStar(require("./model/WidgetData"), exports);
|
|
18
20
|
__exportStar(require("./api/ElectronApi"), exports);
|
|
21
|
+
__exportStar(require("./api/Keys"), exports);
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BroadcastEvent = void 0;
|
|
4
|
+
var BroadcastEvent = /** @class */ (function () {
|
|
5
|
+
function BroadcastEvent(type, from, payload) {
|
|
6
|
+
this.type = type;
|
|
7
|
+
this.from = from;
|
|
8
|
+
this.payload = payload;
|
|
9
|
+
}
|
|
10
|
+
return BroadcastEvent;
|
|
11
|
+
}());
|
|
12
|
+
exports.BroadcastEvent = BroadcastEvent;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SocialInfo = void 0;
|
|
4
|
+
var SocialInfo = /** @class */ (function () {
|
|
5
|
+
function SocialInfo(name, url) {
|
|
6
|
+
this.name = name;
|
|
7
|
+
this.content = url;
|
|
8
|
+
}
|
|
9
|
+
return SocialInfo;
|
|
10
|
+
}());
|
|
11
|
+
exports.SocialInfo = SocialInfo;
|
package/dist/cjs/model/Widget.js
CHANGED
|
@@ -2,25 +2,26 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.WidgetKeyword = exports.Widget = void 0;
|
|
4
4
|
var Widget = /** @class */ (function () {
|
|
5
|
-
function Widget(
|
|
5
|
+
function Widget(options) {
|
|
6
|
+
var _a, _b, _c, _d, _e;
|
|
6
7
|
/**
|
|
7
8
|
* 组件默认语言
|
|
8
9
|
*/
|
|
9
10
|
this.lang = "zh";
|
|
10
|
-
this.name = name;
|
|
11
|
-
this.title = title;
|
|
12
|
-
this.
|
|
13
|
-
this.keywords = keywords;
|
|
14
|
-
this.lang = lang;
|
|
15
|
-
this.w = w;
|
|
16
|
-
this.h = h;
|
|
17
|
-
this.maxW = maxW;
|
|
18
|
-
this.maxH = maxH;
|
|
19
|
-
this.minW = minW;
|
|
20
|
-
this.minH = minH;
|
|
21
|
-
this.url = url;
|
|
22
|
-
this.configUrl = configUrl;
|
|
23
|
-
this.
|
|
11
|
+
this.name = options.name;
|
|
12
|
+
this.title = options.title;
|
|
13
|
+
this.description = options.description;
|
|
14
|
+
this.keywords = options.keywords;
|
|
15
|
+
this.lang = options.lang;
|
|
16
|
+
this.w = options.w;
|
|
17
|
+
this.h = options.h;
|
|
18
|
+
this.maxW = (_a = options.maxW) !== null && _a !== void 0 ? _a : options.w;
|
|
19
|
+
this.maxH = (_b = options.maxH) !== null && _b !== void 0 ? _b : options.h;
|
|
20
|
+
this.minW = (_c = options.minW) !== null && _c !== void 0 ? _c : options.w;
|
|
21
|
+
this.minH = (_d = options.minH) !== null && _d !== void 0 ? _d : options.h;
|
|
22
|
+
this.url = options.url;
|
|
23
|
+
this.configUrl = options.configUrl;
|
|
24
|
+
this.extraUrl = (_e = options.extraUrl) !== null && _e !== void 0 ? _e : new Map();
|
|
24
25
|
}
|
|
25
26
|
/**
|
|
26
27
|
* 获取组件标题
|
|
@@ -33,14 +34,45 @@ var Widget = /** @class */ (function () {
|
|
|
33
34
|
* 获取组件标描述
|
|
34
35
|
* @param lang 语言环境,不传则获取默认标题
|
|
35
36
|
*/
|
|
36
|
-
Widget.prototype.
|
|
37
|
-
return lang ? this.
|
|
37
|
+
Widget.prototype.getDescription = function (lang) {
|
|
38
|
+
return lang ? this.description.get(lang) : this.description.get(this.lang);
|
|
38
39
|
};
|
|
39
|
-
Widget.prototype.
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
40
|
+
Widget.prototype.toJSON = function () {
|
|
41
|
+
return {
|
|
42
|
+
name: this.name,
|
|
43
|
+
title: Object.fromEntries(this.title),
|
|
44
|
+
description: Object.fromEntries(this.description),
|
|
45
|
+
keywords: this.keywords,
|
|
46
|
+
lang: this.lang,
|
|
47
|
+
w: this.w,
|
|
48
|
+
h: this.h,
|
|
49
|
+
maxW: this.maxW,
|
|
50
|
+
maxH: this.maxH,
|
|
51
|
+
minW: this.minW,
|
|
52
|
+
minH: this.minH,
|
|
53
|
+
url: this.url,
|
|
54
|
+
configUrl: this.configUrl,
|
|
55
|
+
extraUrl: Object.fromEntries(this.extraUrl),
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
Widget.parse = function (json) {
|
|
59
|
+
var object = JSON.parse(json);
|
|
60
|
+
return new Widget({
|
|
61
|
+
configUrl: object["configUrl"],
|
|
62
|
+
description: new Map(Object.entries(object["description"])),
|
|
63
|
+
extraUrl: new Map(Object.entries(object["extraUrl"])),
|
|
64
|
+
h: object["h"],
|
|
65
|
+
keywords: object["keywords"],
|
|
66
|
+
lang: object["lang"],
|
|
67
|
+
maxH: object["maxH"],
|
|
68
|
+
maxW: object["maxW"],
|
|
69
|
+
minH: object["minH"],
|
|
70
|
+
minW: object["minW"],
|
|
71
|
+
name: object["name"],
|
|
72
|
+
title: new Map(Object.entries(object["title"])),
|
|
73
|
+
url: object["url"],
|
|
74
|
+
w: object["w"]
|
|
75
|
+
});
|
|
44
76
|
};
|
|
45
77
|
return Widget;
|
|
46
78
|
}());
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
/**
|
|
4
|
+
* 组件配置数据,用于存储组件自定义页面所设置的数据
|
|
5
|
+
*/
|
|
6
|
+
var WidgetData = /** @class */ (function () {
|
|
7
|
+
function WidgetData(name, id) {
|
|
8
|
+
this.id = id;
|
|
9
|
+
this.name = name;
|
|
10
|
+
}
|
|
11
|
+
return WidgetData;
|
|
12
|
+
}());
|
|
13
|
+
exports.default = WidgetData;
|
|
@@ -34,6 +34,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
34
34
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
35
35
|
}
|
|
36
36
|
};
|
|
37
|
+
import { Keys } from "./Keys";
|
|
37
38
|
var ElectronApi = /** @class */ (function () {
|
|
38
39
|
function ElectronApi() {
|
|
39
40
|
}
|
|
@@ -50,7 +51,7 @@ var ElectronApi = /** @class */ (function () {
|
|
|
50
51
|
switch (_a.label) {
|
|
51
52
|
case 0:
|
|
52
53
|
if (!this.hasElectronApi()) return [3 /*break*/, 2];
|
|
53
|
-
data = JSON.parse(JSON.stringify(widgets.map(function (item) { return
|
|
54
|
+
data = JSON.parse(JSON.stringify(widgets.map(function (item) { return JSON.stringify(item); })));
|
|
54
55
|
// @ts-ignore
|
|
55
56
|
return [4 /*yield*/, window.electronAPI.invokeIpc("registerWidgets", data)];
|
|
56
57
|
case 1:
|
|
@@ -62,6 +63,122 @@ var ElectronApi = /** @class */ (function () {
|
|
|
62
63
|
});
|
|
63
64
|
});
|
|
64
65
|
};
|
|
66
|
+
ElectronApi.setConfig = function (key, value) {
|
|
67
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
68
|
+
return __generator(this, function (_a) {
|
|
69
|
+
switch (_a.label) {
|
|
70
|
+
case 0:
|
|
71
|
+
if (!this.hasElectronApi()) return [3 /*break*/, 2];
|
|
72
|
+
// @ts-ignore
|
|
73
|
+
return [4 /*yield*/, window.electronAPI.invokeIpc("setConfig", { key: key, value: value })];
|
|
74
|
+
case 1:
|
|
75
|
+
// @ts-ignore
|
|
76
|
+
_a.sent();
|
|
77
|
+
_a.label = 2;
|
|
78
|
+
case 2: return [2 /*return*/];
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
};
|
|
83
|
+
ElectronApi.sendBroadcastEvent = function (event) {
|
|
84
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
85
|
+
return __generator(this, function (_a) {
|
|
86
|
+
switch (_a.label) {
|
|
87
|
+
case 0:
|
|
88
|
+
if (!this.hasElectronApi()) return [3 /*break*/, 2];
|
|
89
|
+
// @ts-ignore
|
|
90
|
+
return [4 /*yield*/, window.electronAPI.invokeIpc(Keys.BROADCAST_EVENT, JSON.stringify(event))];
|
|
91
|
+
case 1:
|
|
92
|
+
// @ts-ignore
|
|
93
|
+
_a.sent();
|
|
94
|
+
_a.label = 2;
|
|
95
|
+
case 2: return [2 /*return*/];
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
};
|
|
100
|
+
ElectronApi.registerBroadcast = function (callback) {
|
|
101
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
102
|
+
return __generator(this, function (_a) {
|
|
103
|
+
switch (_a.label) {
|
|
104
|
+
case 0: return [4 /*yield*/, this.addIpcListener(Keys.BROADCAST_EVENT, function (json) {
|
|
105
|
+
callback(JSON.parse(json));
|
|
106
|
+
})];
|
|
107
|
+
case 1:
|
|
108
|
+
_a.sent();
|
|
109
|
+
return [2 /*return*/];
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
};
|
|
114
|
+
ElectronApi.unregisterBroadcast = function () {
|
|
115
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
116
|
+
return __generator(this, function (_a) {
|
|
117
|
+
switch (_a.label) {
|
|
118
|
+
case 0: return [4 /*yield*/, this.removeIpcListener(Keys.BROADCAST_EVENT)];
|
|
119
|
+
case 1:
|
|
120
|
+
_a.sent();
|
|
121
|
+
return [2 /*return*/];
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
};
|
|
126
|
+
ElectronApi.addIpcListener = function (key, f) {
|
|
127
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
128
|
+
return __generator(this, function (_a) {
|
|
129
|
+
switch (_a.label) {
|
|
130
|
+
case 0:
|
|
131
|
+
if (!this.hasElectronApi()) return [3 /*break*/, 2];
|
|
132
|
+
// @ts-ignore
|
|
133
|
+
return [4 /*yield*/, window.electronAPI.addIpcListener(key, f)];
|
|
134
|
+
case 1:
|
|
135
|
+
// @ts-ignore
|
|
136
|
+
_a.sent();
|
|
137
|
+
_a.label = 2;
|
|
138
|
+
case 2: return [2 /*return*/];
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
};
|
|
143
|
+
ElectronApi.removeIpcListener = function (key) {
|
|
144
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
145
|
+
return __generator(this, function (_a) {
|
|
146
|
+
switch (_a.label) {
|
|
147
|
+
case 0:
|
|
148
|
+
if (!this.hasElectronApi()) return [3 /*break*/, 2];
|
|
149
|
+
// @ts-ignore
|
|
150
|
+
return [4 /*yield*/, window.electronAPI.removeIpcListener(key)];
|
|
151
|
+
case 1:
|
|
152
|
+
// @ts-ignore
|
|
153
|
+
_a.sent();
|
|
154
|
+
_a.label = 2;
|
|
155
|
+
case 2: return [2 /*return*/];
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
});
|
|
159
|
+
};
|
|
160
|
+
ElectronApi.getConfig = function (key, defaultValue) {
|
|
161
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
162
|
+
var value;
|
|
163
|
+
return __generator(this, function (_a) {
|
|
164
|
+
switch (_a.label) {
|
|
165
|
+
case 0:
|
|
166
|
+
if (!this.hasElectronApi()) return [3 /*break*/, 2];
|
|
167
|
+
return [4 /*yield*/, window.electronAPI.invokeIpc("getConfig", key)];
|
|
168
|
+
case 1:
|
|
169
|
+
value = _a.sent();
|
|
170
|
+
if (value === null || value === undefined) {
|
|
171
|
+
return [2 /*return*/, defaultValue];
|
|
172
|
+
}
|
|
173
|
+
if (typeof defaultValue == "boolean") {
|
|
174
|
+
return [2 /*return*/, value === "true"];
|
|
175
|
+
}
|
|
176
|
+
return [2 /*return*/, value];
|
|
177
|
+
case 2: return [2 /*return*/];
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
});
|
|
181
|
+
};
|
|
65
182
|
ElectronApi.hasElectronApi = function () {
|
|
66
183
|
return Reflect.has(window, "electronAPI");
|
|
67
184
|
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
var Keys = /** @class */ (function () {
|
|
2
|
+
function Keys() {
|
|
3
|
+
}
|
|
4
|
+
Keys.CONFIG_LAUNCH_AT_STARTUP = "LAUNCH_AT_STARTUP";
|
|
5
|
+
Keys.CONFIG_WIDGET_SHADOW = "WIDGET_SHADOW";
|
|
6
|
+
Keys.CHANNEL_MAIN = "WeiZ5kaKijae";
|
|
7
|
+
Keys.EVENT_WIDGET_UPDATED = "WIDGET_SHADOW";
|
|
8
|
+
Keys.BROADCAST_EVENT = "sendBroadcastEvent";
|
|
9
|
+
return Keys;
|
|
10
|
+
}());
|
|
11
|
+
export { Keys };
|
package/dist/esm/index.js
CHANGED
package/dist/esm/model/Widget.js
CHANGED
|
@@ -1,23 +1,24 @@
|
|
|
1
1
|
var Widget = /** @class */ (function () {
|
|
2
|
-
function Widget(
|
|
2
|
+
function Widget(options) {
|
|
3
|
+
var _a, _b, _c, _d, _e;
|
|
3
4
|
/**
|
|
4
5
|
* 组件默认语言
|
|
5
6
|
*/
|
|
6
7
|
this.lang = "zh";
|
|
7
|
-
this.name = name;
|
|
8
|
-
this.title = title;
|
|
9
|
-
this.
|
|
10
|
-
this.keywords = keywords;
|
|
11
|
-
this.lang = lang;
|
|
12
|
-
this.w = w;
|
|
13
|
-
this.h = h;
|
|
14
|
-
this.maxW = maxW;
|
|
15
|
-
this.maxH = maxH;
|
|
16
|
-
this.minW = minW;
|
|
17
|
-
this.minH = minH;
|
|
18
|
-
this.url = url;
|
|
19
|
-
this.configUrl = configUrl;
|
|
20
|
-
this.
|
|
8
|
+
this.name = options.name;
|
|
9
|
+
this.title = options.title;
|
|
10
|
+
this.description = options.description;
|
|
11
|
+
this.keywords = options.keywords;
|
|
12
|
+
this.lang = options.lang;
|
|
13
|
+
this.w = options.w;
|
|
14
|
+
this.h = options.h;
|
|
15
|
+
this.maxW = (_a = options.maxW) !== null && _a !== void 0 ? _a : options.w;
|
|
16
|
+
this.maxH = (_b = options.maxH) !== null && _b !== void 0 ? _b : options.h;
|
|
17
|
+
this.minW = (_c = options.minW) !== null && _c !== void 0 ? _c : options.w;
|
|
18
|
+
this.minH = (_d = options.minH) !== null && _d !== void 0 ? _d : options.h;
|
|
19
|
+
this.url = options.url;
|
|
20
|
+
this.configUrl = options.configUrl;
|
|
21
|
+
this.extraUrl = (_e = options.extraUrl) !== null && _e !== void 0 ? _e : new Map();
|
|
21
22
|
}
|
|
22
23
|
/**
|
|
23
24
|
* 获取组件标题
|
|
@@ -30,14 +31,45 @@ var Widget = /** @class */ (function () {
|
|
|
30
31
|
* 获取组件标描述
|
|
31
32
|
* @param lang 语言环境,不传则获取默认标题
|
|
32
33
|
*/
|
|
33
|
-
Widget.prototype.
|
|
34
|
-
return lang ? this.
|
|
34
|
+
Widget.prototype.getDescription = function (lang) {
|
|
35
|
+
return lang ? this.description.get(lang) : this.description.get(this.lang);
|
|
35
36
|
};
|
|
36
|
-
Widget.prototype.
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
37
|
+
Widget.prototype.toJSON = function () {
|
|
38
|
+
return {
|
|
39
|
+
name: this.name,
|
|
40
|
+
title: Object.fromEntries(this.title),
|
|
41
|
+
description: Object.fromEntries(this.description),
|
|
42
|
+
keywords: this.keywords,
|
|
43
|
+
lang: this.lang,
|
|
44
|
+
w: this.w,
|
|
45
|
+
h: this.h,
|
|
46
|
+
maxW: this.maxW,
|
|
47
|
+
maxH: this.maxH,
|
|
48
|
+
minW: this.minW,
|
|
49
|
+
minH: this.minH,
|
|
50
|
+
url: this.url,
|
|
51
|
+
configUrl: this.configUrl,
|
|
52
|
+
extraUrl: Object.fromEntries(this.extraUrl),
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
Widget.parse = function (json) {
|
|
56
|
+
var object = JSON.parse(json);
|
|
57
|
+
return new Widget({
|
|
58
|
+
configUrl: object["configUrl"],
|
|
59
|
+
description: new Map(Object.entries(object["description"])),
|
|
60
|
+
extraUrl: new Map(Object.entries(object["extraUrl"])),
|
|
61
|
+
h: object["h"],
|
|
62
|
+
keywords: object["keywords"],
|
|
63
|
+
lang: object["lang"],
|
|
64
|
+
maxH: object["maxH"],
|
|
65
|
+
maxW: object["maxW"],
|
|
66
|
+
minH: object["minH"],
|
|
67
|
+
minW: object["minW"],
|
|
68
|
+
name: object["name"],
|
|
69
|
+
title: new Map(Object.entries(object["title"])),
|
|
70
|
+
url: object["url"],
|
|
71
|
+
w: object["w"]
|
|
72
|
+
});
|
|
41
73
|
};
|
|
42
74
|
return Widget;
|
|
43
75
|
}());
|
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
import { Widget } from "../model/Widget";
|
|
2
|
+
import { BroadcastEvent } from "../model/BroadcastEvent";
|
|
2
3
|
export declare class ElectronApi {
|
|
3
4
|
static openAddWidgetWindow(): void;
|
|
4
5
|
static registerWidgets(widgets: Widget[]): Promise<void>;
|
|
6
|
+
static setConfig(key: string, value: string | number | boolean): Promise<void>;
|
|
7
|
+
static sendBroadcastEvent(event: BroadcastEvent): Promise<void>;
|
|
8
|
+
static registerBroadcast(callback: (event: BroadcastEvent) => void): Promise<void>;
|
|
9
|
+
static unregisterBroadcast(): Promise<void>;
|
|
10
|
+
static addIpcListener(key: String, f: Function): Promise<void>;
|
|
11
|
+
static removeIpcListener(key: String): Promise<void>;
|
|
12
|
+
static getConfig(key: string, defaultValue: string | number | boolean): Promise<any>;
|
|
5
13
|
static hasElectronApi(): boolean;
|
|
6
14
|
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare class Keys {
|
|
2
|
+
static readonly CONFIG_LAUNCH_AT_STARTUP = "LAUNCH_AT_STARTUP";
|
|
3
|
+
static readonly CONFIG_WIDGET_SHADOW = "WIDGET_SHADOW";
|
|
4
|
+
static readonly CHANNEL_MAIN = "WeiZ5kaKijae";
|
|
5
|
+
static readonly EVENT_WIDGET_UPDATED = "WIDGET_SHADOW";
|
|
6
|
+
static readonly BROADCAST_EVENT = "sendBroadcastEvent";
|
|
7
|
+
}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export type SocialInfoType = "qq" | "wechat" | "qq-group" | "discord" | "telegram" | "tiktok" | "douyin" | "youtube" | "instagram" | "twitter" | "facebook" | "kuaishou" | "bilibili" | "github" | "email" | "gitee" | "homepage";
|
|
2
|
+
export declare class SocialInfo {
|
|
3
|
+
name: SocialInfoType;
|
|
4
|
+
content: string;
|
|
5
|
+
constructor(name: SocialInfoType, url: string);
|
|
6
|
+
}
|
|
@@ -1,3 +1,19 @@
|
|
|
1
|
+
type WidgetOptions = {
|
|
2
|
+
name: string;
|
|
3
|
+
title: Map<string, string>;
|
|
4
|
+
description: Map<string, string>;
|
|
5
|
+
keywords: WidgetKeyword[];
|
|
6
|
+
lang: string;
|
|
7
|
+
w: number;
|
|
8
|
+
h: number;
|
|
9
|
+
maxW?: number;
|
|
10
|
+
maxH?: number;
|
|
11
|
+
minW?: number;
|
|
12
|
+
minH?: number;
|
|
13
|
+
url: string;
|
|
14
|
+
configUrl?: string;
|
|
15
|
+
extraUrl?: Map<string, string>;
|
|
16
|
+
};
|
|
1
17
|
export declare class Widget {
|
|
2
18
|
readonly name: string;
|
|
3
19
|
/**
|
|
@@ -8,7 +24,7 @@ export declare class Widget {
|
|
|
8
24
|
/**
|
|
9
25
|
* 组件介绍
|
|
10
26
|
*/
|
|
11
|
-
readonly
|
|
27
|
+
readonly description: Map<string, string>;
|
|
12
28
|
readonly keywords: WidgetKeyword[];
|
|
13
29
|
/**
|
|
14
30
|
* 组件默认语言
|
|
@@ -22,8 +38,11 @@ export declare class Widget {
|
|
|
22
38
|
readonly minH: number;
|
|
23
39
|
readonly url: string;
|
|
24
40
|
readonly configUrl?: string | null;
|
|
25
|
-
|
|
26
|
-
|
|
41
|
+
/**
|
|
42
|
+
* 组件其他页面的url在这注册
|
|
43
|
+
*/
|
|
44
|
+
readonly extraUrl: Map<string, string>;
|
|
45
|
+
constructor(options: WidgetOptions);
|
|
27
46
|
/**
|
|
28
47
|
* 获取组件标题
|
|
29
48
|
* @param lang 语言环境,不传则获取默认语言
|
|
@@ -33,8 +52,30 @@ export declare class Widget {
|
|
|
33
52
|
* 获取组件标描述
|
|
34
53
|
* @param lang 语言环境,不传则获取默认标题
|
|
35
54
|
*/
|
|
36
|
-
|
|
37
|
-
|
|
55
|
+
getDescription(lang?: string): string | undefined;
|
|
56
|
+
toJSON(): {
|
|
57
|
+
name: string;
|
|
58
|
+
title: {
|
|
59
|
+
[k: string]: string;
|
|
60
|
+
};
|
|
61
|
+
description: {
|
|
62
|
+
[k: string]: string;
|
|
63
|
+
};
|
|
64
|
+
keywords: WidgetKeyword[];
|
|
65
|
+
lang: string;
|
|
66
|
+
w: number;
|
|
67
|
+
h: number;
|
|
68
|
+
maxW: number;
|
|
69
|
+
maxH: number;
|
|
70
|
+
minW: number;
|
|
71
|
+
minH: number;
|
|
72
|
+
url: string;
|
|
73
|
+
configUrl: string | null | undefined;
|
|
74
|
+
extraUrl: {
|
|
75
|
+
[k: string]: string;
|
|
76
|
+
};
|
|
77
|
+
};
|
|
78
|
+
static parse(json: string): Widget;
|
|
38
79
|
}
|
|
39
80
|
export declare enum WidgetKeyword {
|
|
40
81
|
RECOMMEND = "recommend",
|
|
@@ -48,3 +89,4 @@ export declare enum WidgetKeyword {
|
|
|
48
89
|
INFO = "info",
|
|
49
90
|
DASHBOARD = "dashboard"
|
|
50
91
|
}
|
|
92
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 组件配置数据,用于存储组件自定义页面所设置的数据
|
|
3
|
+
*/
|
|
4
|
+
export default class WidgetData {
|
|
5
|
+
id: string;
|
|
6
|
+
name: string;
|
|
7
|
+
title?: string;
|
|
8
|
+
backgroundColor?: string;
|
|
9
|
+
color?: string;
|
|
10
|
+
fontSize?: number;
|
|
11
|
+
borderRadius?: number;
|
|
12
|
+
date?: string;
|
|
13
|
+
/**
|
|
14
|
+
* 其他数据,以JSON格式放在这里
|
|
15
|
+
*/
|
|
16
|
+
extraJSON?: any;
|
|
17
|
+
constructor(name: string, id: string);
|
|
18
|
+
}
|
package/dist/umd/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(t
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.exampleTypescriptPackage=t():e.exampleTypescriptPackage=t()}(this,(()=>(()=>{"use strict";var e={991:function(e,t,n){var i=this&&this.__awaiter||function(e,t,n,i){return new(n||(n=Promise))((function(r,o){function s(e){try{a(i.next(e))}catch(e){o(e)}}function c(e){try{a(i.throw(e))}catch(e){o(e)}}function a(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,c)}a((i=i.apply(e,t||[])).next())}))},r=this&&this.__generator||function(e,t){var n,i,r,o,s={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return o={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function c(c){return function(a){return function(c){if(n)throw new TypeError("Generator is already executing.");for(;o&&(o=0,c[0]&&(s=0)),s;)try{if(n=1,i&&(r=2&c[0]?i.return:c[0]?i.throw||((r=i.return)&&r.call(i),0):i.next)&&!(r=r.call(i,c[1])).done)return r;switch(i=0,r&&(c=[2&c[0],r.value]),c[0]){case 0:case 1:r=c;break;case 4:return s.label++,{value:c[1],done:!1};case 5:s.label++,i=c[1],c=[0];continue;case 7:c=s.ops.pop(),s.trys.pop();continue;default:if(!((r=(r=s.trys).length>0&&r[r.length-1])||6!==c[0]&&2!==c[0])){s=0;continue}if(3===c[0]&&(!r||c[1]>r[0]&&c[1]<r[3])){s.label=c[1];break}if(6===c[0]&&s.label<r[1]){s.label=r[1],r=c;break}if(r&&s.label<r[2]){s.label=r[2],s.ops.push(c);break}r[2]&&s.ops.pop(),s.trys.pop();continue}c=t.call(e,s)}catch(e){c=[6,e],i=0}finally{n=r=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}([c,a])}}};Object.defineProperty(t,"__esModule",{value:!0}),t.ElectronApi=void 0;var o=n(873),s=function(){function e(){}return e.openAddWidgetWindow=function(){this.hasElectronApi()&&window.electronAPI.invokeIpc("openAddWidgetWindow")},e.registerWidgets=function(e){return i(this,void 0,void 0,(function(){var t;return r(this,(function(n){switch(n.label){case 0:return this.hasElectronApi()?(t=JSON.parse(JSON.stringify(e.map((function(e){return JSON.stringify(e)})))),[4,window.electronAPI.invokeIpc("registerWidgets",t)]):[3,2];case 1:n.sent(),n.label=2;case 2:return[2]}}))}))},e.setConfig=function(e,t){return i(this,void 0,void 0,(function(){return r(this,(function(n){switch(n.label){case 0:return this.hasElectronApi()?[4,window.electronAPI.invokeIpc("setConfig",{key:e,value:t})]:[3,2];case 1:n.sent(),n.label=2;case 2:return[2]}}))}))},e.sendBroadcastEvent=function(e){return i(this,void 0,void 0,(function(){return r(this,(function(t){switch(t.label){case 0:return this.hasElectronApi()?[4,window.electronAPI.invokeIpc(o.Keys.BROADCAST_EVENT,JSON.stringify(e))]:[3,2];case 1:t.sent(),t.label=2;case 2:return[2]}}))}))},e.registerBroadcast=function(e){return i(this,void 0,void 0,(function(){return r(this,(function(t){switch(t.label){case 0:return[4,this.addIpcListener(o.Keys.BROADCAST_EVENT,(function(t){e(JSON.parse(t))}))];case 1:return t.sent(),[2]}}))}))},e.unregisterBroadcast=function(){return i(this,void 0,void 0,(function(){return r(this,(function(e){switch(e.label){case 0:return[4,this.removeIpcListener(o.Keys.BROADCAST_EVENT)];case 1:return e.sent(),[2]}}))}))},e.addIpcListener=function(e,t){return i(this,void 0,void 0,(function(){return r(this,(function(n){switch(n.label){case 0:return this.hasElectronApi()?[4,window.electronAPI.addIpcListener(e,t)]:[3,2];case 1:n.sent(),n.label=2;case 2:return[2]}}))}))},e.removeIpcListener=function(e){return i(this,void 0,void 0,(function(){return r(this,(function(t){switch(t.label){case 0:return this.hasElectronApi()?[4,window.electronAPI.removeIpcListener(e)]:[3,2];case 1:t.sent(),t.label=2;case 2:return[2]}}))}))},e.getConfig=function(e,t){return i(this,void 0,void 0,(function(){var n;return r(this,(function(i){switch(i.label){case 0:return this.hasElectronApi()?[4,window.electronAPI.invokeIpc("getConfig",e)]:[3,2];case 1:return null==(n=i.sent())?[2,t]:"boolean"==typeof t?[2,"true"===n]:[2,n];case 2:return[2]}}))}))},e.hasElectronApi=function(){return Reflect.has(window,"electronAPI")},e}();t.ElectronApi=s},873:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Keys=void 0;var n=function(){function e(){}return e.CONFIG_LAUNCH_AT_STARTUP="LAUNCH_AT_STARTUP",e.CONFIG_WIDGET_SHADOW="WIDGET_SHADOW",e.CHANNEL_MAIN="WeiZ5kaKijae",e.EVENT_WIDGET_UPDATED="WIDGET_SHADOW",e.BROADCAST_EVENT="sendBroadcastEvent",e}();t.Keys=n},432:function(e,t,n){var i=this&&this.__createBinding||(Object.create?function(e,t,n,i){void 0===i&&(i=n);var r=Object.getOwnPropertyDescriptor(t,n);r&&!("get"in r?!t.__esModule:r.writable||r.configurable)||(r={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,i,r)}:function(e,t,n,i){void 0===i&&(i=n),e[i]=t[n]}),r=this&&this.__exportStar||function(e,t){for(var n in e)"default"===n||Object.prototype.hasOwnProperty.call(t,n)||i(t,e,n)};Object.defineProperty(t,"__esModule",{value:!0}),r(n(203),t),r(n(982),t),r(n(791),t),r(n(991),t),r(n(873),t)},982:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.BroadcastEvent=void 0;t.BroadcastEvent=function(e,t,n){this.type=e,this.from=t,this.payload=n}},203:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.WidgetKeyword=t.Widget=void 0;var n,i=function(){function e(e){var t,n,i,r,o;this.lang="zh",this.name=e.name,this.title=e.title,this.description=e.description,this.keywords=e.keywords,this.lang=e.lang,this.w=e.w,this.h=e.h,this.maxW=null!==(t=e.maxW)&&void 0!==t?t:e.w,this.maxH=null!==(n=e.maxH)&&void 0!==n?n:e.h,this.minW=null!==(i=e.minW)&&void 0!==i?i:e.w,this.minH=null!==(r=e.minH)&&void 0!==r?r:e.h,this.url=e.url,this.configUrl=e.configUrl,this.extraUrl=null!==(o=e.extraUrl)&&void 0!==o?o:new Map}return e.prototype.getTitle=function(e){return e?this.title.get(e):this.title.get(this.lang)},e.prototype.getDescription=function(e){return e?this.description.get(e):this.description.get(this.lang)},e.prototype.toJSON=function(){return{name:this.name,title:Object.fromEntries(this.title),description:Object.fromEntries(this.description),keywords:this.keywords,lang:this.lang,w:this.w,h:this.h,maxW:this.maxW,maxH:this.maxH,minW:this.minW,minH:this.minH,url:this.url,configUrl:this.configUrl,extraUrl:Object.fromEntries(this.extraUrl)}},e.parse=function(t){var n=JSON.parse(t);return new e({configUrl:n.configUrl,description:new Map(Object.entries(n.description)),extraUrl:new Map(Object.entries(n.extraUrl)),h:n.h,keywords:n.keywords,lang:n.lang,maxH:n.maxH,maxW:n.maxW,minH:n.minH,minW:n.minW,name:n.name,title:new Map(Object.entries(n.title)),url:n.url,w:n.w})},e}();t.Widget=i,(n=t.WidgetKeyword||(t.WidgetKeyword={})).RECOMMEND="recommend",n.TOOLS="tools",n.EFFICIENCY="efficiency",n.PICTURE="picture",n.LIFE="life",n.SHORTCUT="shortcut",n.COUNTDOWN="countdown",n.TIMER="timer",n.INFO="info",n.DASHBOARD="dashboard"},791:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0});t.default=function(e,t){this.id=t,this.name=e}}},t={};return function n(i){var r=t[i];if(void 0!==r)return r.exports;var o=t[i]={exports:{}};return e[i].call(o.exports,o,o.exports,n),o.exports}(432)})()));
|
package/package.json
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@widget-js/core",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.7",
|
|
4
4
|
"description": "",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
8
8
|
"types": "./dist/types/index.d.ts",
|
|
9
|
-
"exports": "./dist/
|
|
9
|
+
"exports": "./dist/umd/index.js",
|
|
10
10
|
"scripts": {
|
|
11
11
|
"prepublishOnly": "pinst --disable",
|
|
12
12
|
"test": "jest --no-cache --runInBand",
|
|
13
13
|
"test:cov": "jest --coverage --no-cache --runInBand",
|
|
14
|
-
"build": "npm run build:
|
|
14
|
+
"build": "npm run build:esm && npm run build:types && npm run build:cjs && npm run build:umd",
|
|
15
|
+
"build:update": "npm run build && yarn --cwd ../../../ upgrade @widget-js/core && yarn --cwd ../../../electron upgrade @widget-js/core",
|
|
15
16
|
"build:cjs": "node tools/cleanup cjs && tsc -p config/tsconfig.cjs.json",
|
|
16
17
|
"build:esm": "node tools/cleanup esm && tsc -p config/tsconfig.esm.json",
|
|
17
18
|
"build:umd": "node tools/cleanup umd && webpack --config config/webpack.config.js",
|