@widget-js/core 0.1.6 → 0.1.12
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/LICENSE +21 -21
- package/dist/cjs/api/ApiConstants.js +8 -8
- package/dist/cjs/api/AppApi.js +31 -31
- package/dist/cjs/api/BroadcastApi.js +20 -20
- package/dist/cjs/api/BrowserWindowApi.js +58 -24
- package/dist/cjs/api/Channel.js +12 -11
- package/dist/cjs/api/DialogApi.js +16 -0
- package/dist/cjs/api/ElectronApi.js +13 -13
- package/dist/cjs/api/NotificationApi.js +83 -83
- package/dist/cjs/api/WidgetApi.js +58 -49
- package/dist/cjs/index.js +36 -34
- package/dist/cjs/model/HostedMode.js +14 -0
- package/dist/cjs/model/Notification.js +15 -15
- package/dist/cjs/model/SocialInfo.js +10 -10
- package/dist/cjs/model/Widget.js +79 -79
- package/dist/cjs/model/WidgetData.js +16 -16
- package/dist/cjs/model/WidgetPackage.js +21 -6
- package/dist/cjs/model/WidgetParams.js +139 -144
- package/dist/cjs/model/event/BroadcastEvent.js +14 -14
- package/dist/cjs/model/event/WebSocketEvent.js +14 -14
- package/dist/cjs/model/interface/IHostedWidget.js +2 -0
- package/dist/cjs/repository/WidgetDataRepository.js +71 -71
- package/dist/cjs/router/encoding.js +144 -144
- package/dist/cjs/router/query.js +84 -84
- package/dist/cjs/utils/ElectronUtils.js +24 -24
- package/dist/esm/api/ApiConstants.js +4 -4
- package/dist/esm/api/AppApi.js +27 -27
- package/dist/esm/api/BroadcastApi.js +16 -16
- package/dist/esm/api/BrowserWindowApi.js +54 -20
- package/dist/esm/api/Channel.js +9 -8
- package/dist/esm/api/DialogApi.js +12 -0
- package/dist/esm/api/ElectronApi.js +9 -9
- package/dist/esm/api/NotificationApi.js +79 -79
- package/dist/esm/api/WidgetApi.js +54 -45
- package/dist/esm/index.js +20 -18
- package/dist/esm/model/HostedMode.js +11 -0
- package/dist/esm/model/Notification.js +11 -11
- package/dist/esm/model/SocialInfo.js +6 -6
- package/dist/esm/model/Widget.js +75 -75
- package/dist/esm/model/WidgetData.js +12 -12
- package/dist/esm/model/WidgetPackage.js +17 -2
- package/dist/esm/model/WidgetParams.js +135 -140
- package/dist/esm/model/event/BroadcastEvent.js +10 -10
- package/dist/esm/model/event/WebSocketEvent.js +10 -10
- package/dist/esm/model/interface/IHostedWidget.js +1 -0
- package/dist/esm/repository/WidgetDataRepository.js +64 -64
- package/dist/esm/router/encoding.js +135 -135
- package/dist/esm/router/query.js +79 -79
- package/dist/esm/utils/ElectronUtils.js +20 -20
- package/dist/types/api/ApiConstants.d.ts +4 -4
- package/dist/types/api/AppApi.d.ts +10 -10
- package/dist/types/api/BroadcastApi.d.ts +6 -6
- package/dist/types/api/BrowserWindowApi.d.ts +37 -10
- package/dist/types/api/Channel.d.ts +8 -7
- package/dist/types/api/DialogApi.d.ts +8 -0
- package/dist/types/api/ElectronApi.d.ts +4 -4
- package/dist/types/api/NotificationApi.d.ts +14 -14
- package/dist/types/api/WidgetApi.d.ts +30 -24
- package/dist/types/index.d.ts +20 -18
- package/dist/types/model/HostedMode.d.ts +10 -0
- package/dist/types/model/Notification.d.ts +16 -16
- package/dist/types/model/SocialInfo.d.ts +6 -6
- package/dist/types/model/Widget.d.ts +96 -85
- package/dist/types/model/WidgetData.d.ts +35 -35
- package/dist/types/model/WidgetPackage.d.ts +43 -41
- package/dist/types/model/WidgetParams.d.ts +60 -63
- package/dist/types/model/event/BroadcastEvent.d.ts +12 -12
- package/dist/types/model/event/WebSocketEvent.d.ts +8 -8
- package/dist/types/model/interface/IHostedWidget.d.ts +13 -0
- package/dist/types/repository/WidgetDataRepository.d.ts +26 -26
- package/dist/types/router/encoding.d.ts +62 -62
- package/dist/types/router/query.d.ts +53 -53
- package/dist/types/utils/ElectronUtils.d.ts +8 -8
- package/dist/umd/index.js +1 -1
- package/package.json +15 -16
|
@@ -1,45 +1,54 @@
|
|
|
1
|
-
import { Widget } from "../model/Widget";
|
|
2
|
-
import { ElectronUtils } from "../utils/ElectronUtils";
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
*
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
*
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
1
|
+
import { Widget } from "../model/Widget";
|
|
2
|
+
import { ElectronUtils } from "../utils/ElectronUtils";
|
|
3
|
+
import { WidgetPackage } from "../model/WidgetPackage";
|
|
4
|
+
import { Channel } from "./Channel";
|
|
5
|
+
export class WidgetApi {
|
|
6
|
+
static async registerWidgets(widgets) {
|
|
7
|
+
await ElectronUtils.getAPI().invoke(Channel.WIDGET, this.REGISTER_WIDGETS, JSON.stringify(widgets));
|
|
8
|
+
}
|
|
9
|
+
static async registerWidgetPackage(widgetPackage) {
|
|
10
|
+
await ElectronUtils.getAPI().invoke(Channel.WIDGET, this.REGISTER_WIDGET_PACKAGE, JSON.stringify(widgetPackage));
|
|
11
|
+
}
|
|
12
|
+
static async getWidgets() {
|
|
13
|
+
const data = await ElectronUtils.getAPI().invoke(Channel.WIDGET, this.GET_WIDGETS);
|
|
14
|
+
const widgets = [];
|
|
15
|
+
if (data) {
|
|
16
|
+
const arr = JSON.parse(data);
|
|
17
|
+
for (const i in arr) {
|
|
18
|
+
widgets.push(Widget.parseObject(arr[i]));
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return widgets;
|
|
22
|
+
}
|
|
23
|
+
static async getWidgetPackages() {
|
|
24
|
+
return await ElectronUtils.getAPI().invoke(Channel.WIDGET, this.GET_WIDGET_PACKAGES);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
*
|
|
28
|
+
* @param name package name
|
|
29
|
+
*/
|
|
30
|
+
static async getWidget(name) {
|
|
31
|
+
return Widget.parseObject(await ElectronUtils.getAPI().invoke(Channel.WIDGET, this.GET_WIDGET, name));
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
*
|
|
35
|
+
* @param name package name
|
|
36
|
+
*/
|
|
37
|
+
static async getWidgetPackage(name) {
|
|
38
|
+
return WidgetPackage.parseObject(await ElectronUtils.getAPI().invoke(Channel.WIDGET, this.GET_WIDGET_PACKAGE, name));
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* 移除组件
|
|
42
|
+
* @param id
|
|
43
|
+
*/
|
|
44
|
+
static async removeHostedWidget(id) {
|
|
45
|
+
return ElectronUtils.getAPI().invoke(Channel.WIDGET, this.REMOVE_HOSTED_WIDGET, id);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
WidgetApi.REGISTER_WIDGETS = "register-widgets";
|
|
49
|
+
WidgetApi.REGISTER_WIDGET_PACKAGE = "register-widget-package";
|
|
50
|
+
WidgetApi.GET_WIDGETS = "get-widgets";
|
|
51
|
+
WidgetApi.GET_WIDGET = "get-widget";
|
|
52
|
+
WidgetApi.GET_WIDGET_PACKAGE = "get-widget-package";
|
|
53
|
+
WidgetApi.GET_WIDGET_PACKAGES = "get-widget-packages";
|
|
54
|
+
WidgetApi.REMOVE_HOSTED_WIDGET = "remove-hosted-widget";
|
package/dist/esm/index.js
CHANGED
|
@@ -1,18 +1,20 @@
|
|
|
1
|
-
export * from "./model/Widget";
|
|
2
|
-
export * from "./model/event/BroadcastEvent";
|
|
3
|
-
export * from "./model/event/WebSocketEvent";
|
|
4
|
-
export * from "./model/WidgetData";
|
|
5
|
-
export * from "./model/WidgetParams";
|
|
6
|
-
export * from "./model/Notification";
|
|
7
|
-
export * from "./model/
|
|
8
|
-
export * from "./
|
|
9
|
-
export * from "./
|
|
10
|
-
export * from "./
|
|
11
|
-
export * from "./api/
|
|
12
|
-
export * from "./api/
|
|
13
|
-
export * from "./api/
|
|
14
|
-
export * from "./api/
|
|
15
|
-
export * from "./api/
|
|
16
|
-
export * from "./api/
|
|
17
|
-
export * from "./
|
|
18
|
-
export * from "./
|
|
1
|
+
export * from "./model/Widget";
|
|
2
|
+
export * from "./model/event/BroadcastEvent";
|
|
3
|
+
export * from "./model/event/WebSocketEvent";
|
|
4
|
+
export * from "./model/WidgetData";
|
|
5
|
+
export * from "./model/WidgetParams";
|
|
6
|
+
export * from "./model/Notification";
|
|
7
|
+
export * from "./model/HostedMode";
|
|
8
|
+
export * from "./model/WidgetPackage";
|
|
9
|
+
export * from "./api/ElectronApi";
|
|
10
|
+
export * from "./repository/WidgetDataRepository";
|
|
11
|
+
export * from "./api/BrowserWindowApi";
|
|
12
|
+
export * from "./api/NotificationApi";
|
|
13
|
+
export * from "./api/Channel";
|
|
14
|
+
export * from "./api/WidgetApi";
|
|
15
|
+
export * from "./api/ApiConstants";
|
|
16
|
+
export * from "./api/BroadcastApi";
|
|
17
|
+
export * from "./api/AppApi";
|
|
18
|
+
export * from "./api/DialogApi";
|
|
19
|
+
export * from "./utils/ElectronUtils";
|
|
20
|
+
export * from "./router/query";
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export var HostedMode;
|
|
2
|
+
(function (HostedMode) {
|
|
3
|
+
HostedMode[HostedMode["NORMAL"] = 1] = "NORMAL";
|
|
4
|
+
/**
|
|
5
|
+
* 悬浮窗
|
|
6
|
+
*/
|
|
7
|
+
HostedMode[HostedMode["OVERLAP"] = 16] = "OVERLAP";
|
|
8
|
+
HostedMode[HostedMode["WALLPAPER"] = 256] = "WALLPAPER";
|
|
9
|
+
HostedMode[HostedMode["SCREEN"] = 4096] = "SCREEN";
|
|
10
|
+
HostedMode[HostedMode["ALL"] = 4369] = "ALL";
|
|
11
|
+
})(HostedMode || (HostedMode = {}));
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
export class Notification {
|
|
2
|
-
constructor(option) {
|
|
3
|
-
var _a, _b;
|
|
4
|
-
this.type = "message";
|
|
5
|
-
this.type = (_a = option.type) !== null && _a !== void 0 ? _a : "message";
|
|
6
|
-
this.title = option.title;
|
|
7
|
-
this.message = option.message;
|
|
8
|
-
this.targetTime = option.targetTime;
|
|
9
|
-
this.duration = (_b = option.duration) !== null && _b !== void 0 ? _b : 5000;
|
|
10
|
-
}
|
|
11
|
-
}
|
|
1
|
+
export class Notification {
|
|
2
|
+
constructor(option) {
|
|
3
|
+
var _a, _b;
|
|
4
|
+
this.type = "message";
|
|
5
|
+
this.type = (_a = option.type) !== null && _a !== void 0 ? _a : "message";
|
|
6
|
+
this.title = option.title;
|
|
7
|
+
this.message = option.message;
|
|
8
|
+
this.targetTime = option.targetTime;
|
|
9
|
+
this.duration = (_b = option.duration) !== null && _b !== void 0 ? _b : 5000;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export class SocialInfo {
|
|
2
|
-
constructor(name, url) {
|
|
3
|
-
this.name = name;
|
|
4
|
-
this.content = url;
|
|
5
|
-
}
|
|
6
|
-
}
|
|
1
|
+
export class SocialInfo {
|
|
2
|
+
constructor(name, url) {
|
|
3
|
+
this.name = name;
|
|
4
|
+
this.content = url;
|
|
5
|
+
}
|
|
6
|
+
}
|
package/dist/esm/model/Widget.js
CHANGED
|
@@ -1,75 +1,75 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
this.
|
|
9
|
-
this.
|
|
10
|
-
this.
|
|
11
|
-
this.
|
|
12
|
-
this.
|
|
13
|
-
this.
|
|
14
|
-
this.
|
|
15
|
-
this.
|
|
16
|
-
this.
|
|
17
|
-
this.
|
|
18
|
-
this.
|
|
19
|
-
this.
|
|
20
|
-
this.
|
|
21
|
-
this.
|
|
22
|
-
this.
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
export var WidgetKeyword;
|
|
64
|
-
(function (WidgetKeyword) {
|
|
65
|
-
WidgetKeyword["RECOMMEND"] = "recommend";
|
|
66
|
-
WidgetKeyword["TOOLS"] = "tools";
|
|
67
|
-
WidgetKeyword["EFFICIENCY"] = "efficiency";
|
|
68
|
-
WidgetKeyword["PICTURE"] = "picture";
|
|
69
|
-
WidgetKeyword["LIFE"] = "life";
|
|
70
|
-
WidgetKeyword["SHORTCUT"] = "shortcut";
|
|
71
|
-
WidgetKeyword["COUNTDOWN"] = "countdown";
|
|
72
|
-
WidgetKeyword["TIMER"] = "timer";
|
|
73
|
-
WidgetKeyword["INFO"] = "info";
|
|
74
|
-
WidgetKeyword["DASHBOARD"] = "dashboard";
|
|
75
|
-
})(WidgetKeyword || (WidgetKeyword = {}));
|
|
1
|
+
import { HostedMode } from "./HostedMode";
|
|
2
|
+
export class Widget {
|
|
3
|
+
constructor(options) {
|
|
4
|
+
var _a, _b, _c, _d, _e, _f;
|
|
5
|
+
/**
|
|
6
|
+
* 组件默认语言
|
|
7
|
+
*/
|
|
8
|
+
this.lang = "zh";
|
|
9
|
+
this.name = options.name;
|
|
10
|
+
this.title = options.title;
|
|
11
|
+
this.description = options.description;
|
|
12
|
+
this.keywords = options.keywords;
|
|
13
|
+
this.lang = options.lang;
|
|
14
|
+
this.width = options.width;
|
|
15
|
+
this.height = options.height;
|
|
16
|
+
this.maxWidth = (_a = options.maxWidth) !== null && _a !== void 0 ? _a : options.width;
|
|
17
|
+
this.maxHeight = (_b = options.maxHeight) !== null && _b !== void 0 ? _b : options.height;
|
|
18
|
+
this.minWidth = (_c = options.minWidth) !== null && _c !== void 0 ? _c : options.width;
|
|
19
|
+
this.minHeight = (_d = options.minHeight) !== null && _d !== void 0 ? _d : options.height;
|
|
20
|
+
this.url = options.url;
|
|
21
|
+
this.packageName = options.packageName;
|
|
22
|
+
this.configUrl = options.configUrl;
|
|
23
|
+
this.extraUrl = (_e = options.extraUrl) !== null && _e !== void 0 ? _e : {};
|
|
24
|
+
this.supportHostedMode = (_f = options.supportHostedMode) !== null && _f !== void 0 ? _f : HostedMode.NORMAL | HostedMode.OVERLAP;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* 获取组件标题
|
|
28
|
+
* @param lang 语言环境,不传则获取默认语言
|
|
29
|
+
*/
|
|
30
|
+
getTitle(lang) {
|
|
31
|
+
var _a;
|
|
32
|
+
return lang ? (_a = this.title[lang]) !== null && _a !== void 0 ? _a : this.title[this.lang] : this.title[this.lang];
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* 获取组件标描述
|
|
36
|
+
* @param lang 语言环境,不传则获取默认标题
|
|
37
|
+
*/
|
|
38
|
+
getDescription(lang) {
|
|
39
|
+
return lang ? this.description[lang] : this.description[this.lang];
|
|
40
|
+
}
|
|
41
|
+
static parseJSON(json) {
|
|
42
|
+
const object = JSON.parse(json);
|
|
43
|
+
return this.parseObject(object);
|
|
44
|
+
}
|
|
45
|
+
static parseObject(obj) {
|
|
46
|
+
return new Widget({
|
|
47
|
+
...obj
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* 是否支持悬浮窗
|
|
52
|
+
*/
|
|
53
|
+
isSupportOverlap() {
|
|
54
|
+
return (this.supportHostedMode & HostedMode.OVERLAP) > 0;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* 是否支持普通模式
|
|
58
|
+
*/
|
|
59
|
+
isSupportNormal() {
|
|
60
|
+
return (this.supportHostedMode & HostedMode.NORMAL) > 0;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
export var WidgetKeyword;
|
|
64
|
+
(function (WidgetKeyword) {
|
|
65
|
+
WidgetKeyword["RECOMMEND"] = "recommend";
|
|
66
|
+
WidgetKeyword["TOOLS"] = "tools";
|
|
67
|
+
WidgetKeyword["EFFICIENCY"] = "efficiency";
|
|
68
|
+
WidgetKeyword["PICTURE"] = "picture";
|
|
69
|
+
WidgetKeyword["LIFE"] = "life";
|
|
70
|
+
WidgetKeyword["SHORTCUT"] = "shortcut";
|
|
71
|
+
WidgetKeyword["COUNTDOWN"] = "countdown";
|
|
72
|
+
WidgetKeyword["TIMER"] = "timer";
|
|
73
|
+
WidgetKeyword["INFO"] = "info";
|
|
74
|
+
WidgetKeyword["DASHBOARD"] = "dashboard";
|
|
75
|
+
})(WidgetKeyword || (WidgetKeyword = {}));
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 组件配置数据,用于存储组件自定义页面所设置的数据
|
|
3
|
-
*/
|
|
4
|
-
export class WidgetData {
|
|
5
|
-
constructor(name, id) {
|
|
6
|
-
this.id = id;
|
|
7
|
-
this.name = name;
|
|
8
|
-
}
|
|
9
|
-
parseJSON(json) {
|
|
10
|
-
Object.assign(this, json);
|
|
11
|
-
}
|
|
12
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* 组件配置数据,用于存储组件自定义页面所设置的数据
|
|
3
|
+
*/
|
|
4
|
+
export class WidgetData {
|
|
5
|
+
constructor(name, id) {
|
|
6
|
+
this.id = id;
|
|
7
|
+
this.name = name;
|
|
8
|
+
}
|
|
9
|
+
parseJSON(json) {
|
|
10
|
+
Object.assign(this, json);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -1,2 +1,17 @@
|
|
|
1
|
-
export class WidgetPackage {
|
|
2
|
-
|
|
1
|
+
export class WidgetPackage {
|
|
2
|
+
static parseJSON(json) {
|
|
3
|
+
const object = JSON.parse(json);
|
|
4
|
+
return this.parseObject(object);
|
|
5
|
+
}
|
|
6
|
+
static parseObject(obj) {
|
|
7
|
+
let widgetPackage = new WidgetPackage();
|
|
8
|
+
Object.assign(widgetPackage, obj);
|
|
9
|
+
return widgetPackage;
|
|
10
|
+
}
|
|
11
|
+
getFullUrl() {
|
|
12
|
+
if (this.url.startsWith("http")) {
|
|
13
|
+
return this.url;
|
|
14
|
+
}
|
|
15
|
+
return this.url + (this.entry.startsWith("/") ? this.entry : `/${this.entry}`);
|
|
16
|
+
}
|
|
17
|
+
}
|