@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.
Files changed (75) hide show
  1. package/LICENSE +21 -21
  2. package/dist/cjs/api/ApiConstants.js +8 -8
  3. package/dist/cjs/api/AppApi.js +31 -31
  4. package/dist/cjs/api/BroadcastApi.js +20 -20
  5. package/dist/cjs/api/BrowserWindowApi.js +58 -24
  6. package/dist/cjs/api/Channel.js +12 -11
  7. package/dist/cjs/api/DialogApi.js +16 -0
  8. package/dist/cjs/api/ElectronApi.js +13 -13
  9. package/dist/cjs/api/NotificationApi.js +83 -83
  10. package/dist/cjs/api/WidgetApi.js +58 -49
  11. package/dist/cjs/index.js +36 -34
  12. package/dist/cjs/model/HostedMode.js +14 -0
  13. package/dist/cjs/model/Notification.js +15 -15
  14. package/dist/cjs/model/SocialInfo.js +10 -10
  15. package/dist/cjs/model/Widget.js +79 -79
  16. package/dist/cjs/model/WidgetData.js +16 -16
  17. package/dist/cjs/model/WidgetPackage.js +21 -6
  18. package/dist/cjs/model/WidgetParams.js +139 -144
  19. package/dist/cjs/model/event/BroadcastEvent.js +14 -14
  20. package/dist/cjs/model/event/WebSocketEvent.js +14 -14
  21. package/dist/cjs/model/interface/IHostedWidget.js +2 -0
  22. package/dist/cjs/repository/WidgetDataRepository.js +71 -71
  23. package/dist/cjs/router/encoding.js +144 -144
  24. package/dist/cjs/router/query.js +84 -84
  25. package/dist/cjs/utils/ElectronUtils.js +24 -24
  26. package/dist/esm/api/ApiConstants.js +4 -4
  27. package/dist/esm/api/AppApi.js +27 -27
  28. package/dist/esm/api/BroadcastApi.js +16 -16
  29. package/dist/esm/api/BrowserWindowApi.js +54 -20
  30. package/dist/esm/api/Channel.js +9 -8
  31. package/dist/esm/api/DialogApi.js +12 -0
  32. package/dist/esm/api/ElectronApi.js +9 -9
  33. package/dist/esm/api/NotificationApi.js +79 -79
  34. package/dist/esm/api/WidgetApi.js +54 -45
  35. package/dist/esm/index.js +20 -18
  36. package/dist/esm/model/HostedMode.js +11 -0
  37. package/dist/esm/model/Notification.js +11 -11
  38. package/dist/esm/model/SocialInfo.js +6 -6
  39. package/dist/esm/model/Widget.js +75 -75
  40. package/dist/esm/model/WidgetData.js +12 -12
  41. package/dist/esm/model/WidgetPackage.js +17 -2
  42. package/dist/esm/model/WidgetParams.js +135 -140
  43. package/dist/esm/model/event/BroadcastEvent.js +10 -10
  44. package/dist/esm/model/event/WebSocketEvent.js +10 -10
  45. package/dist/esm/model/interface/IHostedWidget.js +1 -0
  46. package/dist/esm/repository/WidgetDataRepository.js +64 -64
  47. package/dist/esm/router/encoding.js +135 -135
  48. package/dist/esm/router/query.js +79 -79
  49. package/dist/esm/utils/ElectronUtils.js +20 -20
  50. package/dist/types/api/ApiConstants.d.ts +4 -4
  51. package/dist/types/api/AppApi.d.ts +10 -10
  52. package/dist/types/api/BroadcastApi.d.ts +6 -6
  53. package/dist/types/api/BrowserWindowApi.d.ts +37 -10
  54. package/dist/types/api/Channel.d.ts +8 -7
  55. package/dist/types/api/DialogApi.d.ts +8 -0
  56. package/dist/types/api/ElectronApi.d.ts +4 -4
  57. package/dist/types/api/NotificationApi.d.ts +14 -14
  58. package/dist/types/api/WidgetApi.d.ts +30 -24
  59. package/dist/types/index.d.ts +20 -18
  60. package/dist/types/model/HostedMode.d.ts +10 -0
  61. package/dist/types/model/Notification.d.ts +16 -16
  62. package/dist/types/model/SocialInfo.d.ts +6 -6
  63. package/dist/types/model/Widget.d.ts +96 -85
  64. package/dist/types/model/WidgetData.d.ts +35 -35
  65. package/dist/types/model/WidgetPackage.d.ts +43 -41
  66. package/dist/types/model/WidgetParams.d.ts +60 -63
  67. package/dist/types/model/event/BroadcastEvent.d.ts +12 -12
  68. package/dist/types/model/event/WebSocketEvent.d.ts +8 -8
  69. package/dist/types/model/interface/IHostedWidget.d.ts +13 -0
  70. package/dist/types/repository/WidgetDataRepository.d.ts +26 -26
  71. package/dist/types/router/encoding.d.ts +62 -62
  72. package/dist/types/router/query.d.ts +53 -53
  73. package/dist/types/utils/ElectronUtils.d.ts +8 -8
  74. package/dist/umd/index.js +1 -1
  75. package/package.json +15 -16
@@ -1,45 +1,54 @@
1
- import { Widget } from "../model/Widget";
2
- import { ElectronUtils } from "../utils/ElectronUtils";
3
- import { Channel } from "./Channel";
4
- export class WidgetApi {
5
- static async registerWidgets(widgets) {
6
- await ElectronUtils.getAPI().invoke(Channel.WIDGET, this.REGISTER_WIDGETS, JSON.stringify(widgets));
7
- }
8
- static async registerWidgetPackage(widgetPackage) {
9
- await ElectronUtils.getAPI().invoke(Channel.WIDGET, this.REGISTER_WIDGET_PACKAGE, JSON.stringify(widgetPackage));
10
- }
11
- static async getWidgets() {
12
- const data = await ElectronUtils.getAPI().invoke(Channel.WIDGET, this.GET_WIDGETS);
13
- const widgets = [];
14
- if (data) {
15
- const arr = JSON.parse(data);
16
- for (const i in arr) {
17
- widgets.push(Widget.parseObject(arr[i]));
18
- }
19
- }
20
- return widgets;
21
- }
22
- static async getWidgetPackages() {
23
- return await ElectronUtils.getAPI().invoke(Channel.WIDGET, this.GET_WIDGET_PACKAGES);
24
- }
25
- /**
26
- *
27
- * @param name package name
28
- */
29
- static async getWidget(name) {
30
- return await ElectronUtils.getAPI().invoke(Channel.WIDGET, this.GET_WIDGET, name);
31
- }
32
- /**
33
- *
34
- * @param name package name
35
- */
36
- static async getWidgetPackage(name) {
37
- return await ElectronUtils.getAPI().invoke(Channel.WIDGET, this.GET_WIDGET_PACKAGE, name);
38
- }
39
- }
40
- WidgetApi.REGISTER_WIDGETS = "register-widgets";
41
- WidgetApi.REGISTER_WIDGET_PACKAGE = "register-widget-package";
42
- WidgetApi.GET_WIDGETS = "get-widgets";
43
- WidgetApi.GET_WIDGET = "get-widget";
44
- WidgetApi.GET_WIDGET_PACKAGE = "get-widget-package";
45
- WidgetApi.GET_WIDGET_PACKAGES = "get-widget-packages";
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/WidgetPackage";
8
- export * from "./api/ElectronApi";
9
- export * from "./repository/WidgetDataRepository";
10
- export * from "./api/BrowserWindowApi";
11
- export * from "./api/NotificationApi";
12
- export * from "./api/Channel";
13
- export * from "./api/WidgetApi";
14
- export * from "./api/ApiConstants";
15
- export * from "./api/BroadcastApi";
16
- export * from "./api/AppApi";
17
- export * from "./utils/ElectronUtils";
18
- export * from "./router/query";
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
+ }
@@ -1,75 +1,75 @@
1
- export class Widget {
2
- constructor(options) {
3
- var _a, _b, _c, _d, _e;
4
- /**
5
- * 组件默认语言
6
- */
7
- this.lang = "zh";
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.width = options.width;
14
- this.height = options.height;
15
- this.maxWidth = (_a = options.maxWidth) !== null && _a !== void 0 ? _a : options.width;
16
- this.maxHeight = (_b = options.maxHeight) !== null && _b !== void 0 ? _b : options.height;
17
- this.minWidth = (_c = options.minWidth) !== null && _c !== void 0 ? _c : options.width;
18
- this.minHeight = (_d = options.minHeight) !== null && _d !== void 0 ? _d : options.height;
19
- this.url = options.url;
20
- this.packageName = options.packageName;
21
- this.configUrl = options.configUrl;
22
- this.extraUrl = (_e = options.extraUrl) !== null && _e !== void 0 ? _e : {};
23
- }
24
- /**
25
- * 获取组件标题
26
- * @param lang 语言环境,不传则获取默认语言
27
- */
28
- getTitle(lang) {
29
- var _a;
30
- return lang ? (_a = this.title[lang]) !== null && _a !== void 0 ? _a : this.title[this.lang] : this.title[this.lang];
31
- }
32
- /**
33
- * 获取组件标描述
34
- * @param lang 语言环境,不传则获取默认标题
35
- */
36
- getDescription(lang) {
37
- return lang ? this.description[lang] : this.description[this.lang];
38
- }
39
- static parseJSON(json) {
40
- const object = JSON.parse(json);
41
- return this.parseObject(object);
42
- }
43
- static parseObject(obj) {
44
- return new Widget({
45
- configUrl: obj["configUrl"],
46
- description: obj["description"],
47
- extraUrl: obj["extraUrl"],
48
- width: obj["width"],
49
- keywords: obj["keywords"],
50
- lang: obj["lang"],
51
- maxHeight: obj["maxHeight"],
52
- maxWidth: obj["maxWidth"],
53
- height: obj["height"],
54
- packageName: obj["packageName"],
55
- minHeight: obj["minHeight"],
56
- minWidth: obj["minWidth"],
57
- name: obj["name"],
58
- title: obj["title"],
59
- url: obj["url"]
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
+ }