@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
package/dist/cjs/index.js CHANGED
@@ -1,34 +1,36 @@
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("./model/Widget"), exports);
18
- __exportStar(require("./model/event/BroadcastEvent"), exports);
19
- __exportStar(require("./model/event/WebSocketEvent"), exports);
20
- __exportStar(require("./model/WidgetData"), exports);
21
- __exportStar(require("./model/WidgetParams"), exports);
22
- __exportStar(require("./model/Notification"), exports);
23
- __exportStar(require("./model/WidgetPackage"), exports);
24
- __exportStar(require("./api/ElectronApi"), exports);
25
- __exportStar(require("./repository/WidgetDataRepository"), exports);
26
- __exportStar(require("./api/BrowserWindowApi"), exports);
27
- __exportStar(require("./api/NotificationApi"), exports);
28
- __exportStar(require("./api/Channel"), exports);
29
- __exportStar(require("./api/WidgetApi"), exports);
30
- __exportStar(require("./api/ApiConstants"), exports);
31
- __exportStar(require("./api/BroadcastApi"), exports);
32
- __exportStar(require("./api/AppApi"), exports);
33
- __exportStar(require("./utils/ElectronUtils"), exports);
34
- __exportStar(require("./router/query"), exports);
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("./model/Widget"), exports);
18
+ __exportStar(require("./model/event/BroadcastEvent"), exports);
19
+ __exportStar(require("./model/event/WebSocketEvent"), exports);
20
+ __exportStar(require("./model/WidgetData"), exports);
21
+ __exportStar(require("./model/WidgetParams"), exports);
22
+ __exportStar(require("./model/Notification"), exports);
23
+ __exportStar(require("./model/HostedMode"), exports);
24
+ __exportStar(require("./model/WidgetPackage"), exports);
25
+ __exportStar(require("./api/ElectronApi"), exports);
26
+ __exportStar(require("./repository/WidgetDataRepository"), exports);
27
+ __exportStar(require("./api/BrowserWindowApi"), exports);
28
+ __exportStar(require("./api/NotificationApi"), exports);
29
+ __exportStar(require("./api/Channel"), exports);
30
+ __exportStar(require("./api/WidgetApi"), exports);
31
+ __exportStar(require("./api/ApiConstants"), exports);
32
+ __exportStar(require("./api/BroadcastApi"), exports);
33
+ __exportStar(require("./api/AppApi"), exports);
34
+ __exportStar(require("./api/DialogApi"), exports);
35
+ __exportStar(require("./utils/ElectronUtils"), exports);
36
+ __exportStar(require("./router/query"), exports);
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HostedMode = void 0;
4
+ var HostedMode;
5
+ (function (HostedMode) {
6
+ HostedMode[HostedMode["NORMAL"] = 1] = "NORMAL";
7
+ /**
8
+ * 悬浮窗
9
+ */
10
+ HostedMode[HostedMode["OVERLAP"] = 16] = "OVERLAP";
11
+ HostedMode[HostedMode["WALLPAPER"] = 256] = "WALLPAPER";
12
+ HostedMode[HostedMode["SCREEN"] = 4096] = "SCREEN";
13
+ HostedMode[HostedMode["ALL"] = 4369] = "ALL";
14
+ })(HostedMode = exports.HostedMode || (exports.HostedMode = {}));
@@ -1,15 +1,15 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Notification = void 0;
4
- class Notification {
5
- constructor(option) {
6
- var _a, _b;
7
- this.type = "message";
8
- this.type = (_a = option.type) !== null && _a !== void 0 ? _a : "message";
9
- this.title = option.title;
10
- this.message = option.message;
11
- this.targetTime = option.targetTime;
12
- this.duration = (_b = option.duration) !== null && _b !== void 0 ? _b : 5000;
13
- }
14
- }
15
- exports.Notification = Notification;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Notification = void 0;
4
+ class Notification {
5
+ constructor(option) {
6
+ var _a, _b;
7
+ this.type = "message";
8
+ this.type = (_a = option.type) !== null && _a !== void 0 ? _a : "message";
9
+ this.title = option.title;
10
+ this.message = option.message;
11
+ this.targetTime = option.targetTime;
12
+ this.duration = (_b = option.duration) !== null && _b !== void 0 ? _b : 5000;
13
+ }
14
+ }
15
+ exports.Notification = Notification;
@@ -1,10 +1,10 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SocialInfo = void 0;
4
- class SocialInfo {
5
- constructor(name, url) {
6
- this.name = name;
7
- this.content = url;
8
- }
9
- }
10
- exports.SocialInfo = SocialInfo;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SocialInfo = void 0;
4
+ class SocialInfo {
5
+ constructor(name, url) {
6
+ this.name = name;
7
+ this.content = url;
8
+ }
9
+ }
10
+ exports.SocialInfo = SocialInfo;
@@ -1,79 +1,79 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.WidgetKeyword = exports.Widget = void 0;
4
- class Widget {
5
- constructor(options) {
6
- var _a, _b, _c, _d, _e;
7
- /**
8
- * 组件默认语言
9
- */
10
- this.lang = "zh";
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.width = options.width;
17
- this.height = options.height;
18
- this.maxWidth = (_a = options.maxWidth) !== null && _a !== void 0 ? _a : options.width;
19
- this.maxHeight = (_b = options.maxHeight) !== null && _b !== void 0 ? _b : options.height;
20
- this.minWidth = (_c = options.minWidth) !== null && _c !== void 0 ? _c : options.width;
21
- this.minHeight = (_d = options.minHeight) !== null && _d !== void 0 ? _d : options.height;
22
- this.url = options.url;
23
- this.packageName = options.packageName;
24
- this.configUrl = options.configUrl;
25
- this.extraUrl = (_e = options.extraUrl) !== null && _e !== void 0 ? _e : {};
26
- }
27
- /**
28
- * 获取组件标题
29
- * @param lang 语言环境,不传则获取默认语言
30
- */
31
- getTitle(lang) {
32
- var _a;
33
- return lang ? (_a = this.title[lang]) !== null && _a !== void 0 ? _a : this.title[this.lang] : this.title[this.lang];
34
- }
35
- /**
36
- * 获取组件标描述
37
- * @param lang 语言环境,不传则获取默认标题
38
- */
39
- getDescription(lang) {
40
- return lang ? this.description[lang] : this.description[this.lang];
41
- }
42
- static parseJSON(json) {
43
- const object = JSON.parse(json);
44
- return this.parseObject(object);
45
- }
46
- static parseObject(obj) {
47
- return new Widget({
48
- configUrl: obj["configUrl"],
49
- description: obj["description"],
50
- extraUrl: obj["extraUrl"],
51
- width: obj["width"],
52
- keywords: obj["keywords"],
53
- lang: obj["lang"],
54
- maxHeight: obj["maxHeight"],
55
- maxWidth: obj["maxWidth"],
56
- height: obj["height"],
57
- packageName: obj["packageName"],
58
- minHeight: obj["minHeight"],
59
- minWidth: obj["minWidth"],
60
- name: obj["name"],
61
- title: obj["title"],
62
- url: obj["url"]
63
- });
64
- }
65
- }
66
- exports.Widget = Widget;
67
- var WidgetKeyword;
68
- (function (WidgetKeyword) {
69
- WidgetKeyword["RECOMMEND"] = "recommend";
70
- WidgetKeyword["TOOLS"] = "tools";
71
- WidgetKeyword["EFFICIENCY"] = "efficiency";
72
- WidgetKeyword["PICTURE"] = "picture";
73
- WidgetKeyword["LIFE"] = "life";
74
- WidgetKeyword["SHORTCUT"] = "shortcut";
75
- WidgetKeyword["COUNTDOWN"] = "countdown";
76
- WidgetKeyword["TIMER"] = "timer";
77
- WidgetKeyword["INFO"] = "info";
78
- WidgetKeyword["DASHBOARD"] = "dashboard";
79
- })(WidgetKeyword = exports.WidgetKeyword || (exports.WidgetKeyword = {}));
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.WidgetKeyword = exports.Widget = void 0;
4
+ const HostedMode_1 = require("./HostedMode");
5
+ class Widget {
6
+ constructor(options) {
7
+ var _a, _b, _c, _d, _e, _f;
8
+ /**
9
+ * 组件默认语言
10
+ */
11
+ this.lang = "zh";
12
+ this.name = options.name;
13
+ this.title = options.title;
14
+ this.description = options.description;
15
+ this.keywords = options.keywords;
16
+ this.lang = options.lang;
17
+ this.width = options.width;
18
+ this.height = options.height;
19
+ this.maxWidth = (_a = options.maxWidth) !== null && _a !== void 0 ? _a : options.width;
20
+ this.maxHeight = (_b = options.maxHeight) !== null && _b !== void 0 ? _b : options.height;
21
+ this.minWidth = (_c = options.minWidth) !== null && _c !== void 0 ? _c : options.width;
22
+ this.minHeight = (_d = options.minHeight) !== null && _d !== void 0 ? _d : options.height;
23
+ this.url = options.url;
24
+ this.packageName = options.packageName;
25
+ this.configUrl = options.configUrl;
26
+ this.extraUrl = (_e = options.extraUrl) !== null && _e !== void 0 ? _e : {};
27
+ this.supportHostedMode = (_f = options.supportHostedMode) !== null && _f !== void 0 ? _f : HostedMode_1.HostedMode.NORMAL | HostedMode_1.HostedMode.OVERLAP;
28
+ }
29
+ /**
30
+ * 获取组件标题
31
+ * @param lang 语言环境,不传则获取默认语言
32
+ */
33
+ getTitle(lang) {
34
+ var _a;
35
+ return lang ? (_a = this.title[lang]) !== null && _a !== void 0 ? _a : this.title[this.lang] : this.title[this.lang];
36
+ }
37
+ /**
38
+ * 获取组件标描述
39
+ * @param lang 语言环境,不传则获取默认标题
40
+ */
41
+ getDescription(lang) {
42
+ return lang ? this.description[lang] : this.description[this.lang];
43
+ }
44
+ static parseJSON(json) {
45
+ const object = JSON.parse(json);
46
+ return this.parseObject(object);
47
+ }
48
+ static parseObject(obj) {
49
+ return new Widget({
50
+ ...obj
51
+ });
52
+ }
53
+ /**
54
+ * 是否支持悬浮窗
55
+ */
56
+ isSupportOverlap() {
57
+ return (this.supportHostedMode & HostedMode_1.HostedMode.OVERLAP) > 0;
58
+ }
59
+ /**
60
+ * 是否支持普通模式
61
+ */
62
+ isSupportNormal() {
63
+ return (this.supportHostedMode & HostedMode_1.HostedMode.NORMAL) > 0;
64
+ }
65
+ }
66
+ exports.Widget = Widget;
67
+ var WidgetKeyword;
68
+ (function (WidgetKeyword) {
69
+ WidgetKeyword["RECOMMEND"] = "recommend";
70
+ WidgetKeyword["TOOLS"] = "tools";
71
+ WidgetKeyword["EFFICIENCY"] = "efficiency";
72
+ WidgetKeyword["PICTURE"] = "picture";
73
+ WidgetKeyword["LIFE"] = "life";
74
+ WidgetKeyword["SHORTCUT"] = "shortcut";
75
+ WidgetKeyword["COUNTDOWN"] = "countdown";
76
+ WidgetKeyword["TIMER"] = "timer";
77
+ WidgetKeyword["INFO"] = "info";
78
+ WidgetKeyword["DASHBOARD"] = "dashboard";
79
+ })(WidgetKeyword = exports.WidgetKeyword || (exports.WidgetKeyword = {}));
@@ -1,16 +1,16 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.WidgetData = void 0;
4
- /**
5
- * 组件配置数据,用于存储组件自定义页面所设置的数据
6
- */
7
- class WidgetData {
8
- constructor(name, id) {
9
- this.id = id;
10
- this.name = name;
11
- }
12
- parseJSON(json) {
13
- Object.assign(this, json);
14
- }
15
- }
16
- exports.WidgetData = WidgetData;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.WidgetData = void 0;
4
+ /**
5
+ * 组件配置数据,用于存储组件自定义页面所设置的数据
6
+ */
7
+ class WidgetData {
8
+ constructor(name, id) {
9
+ this.id = id;
10
+ this.name = name;
11
+ }
12
+ parseJSON(json) {
13
+ Object.assign(this, json);
14
+ }
15
+ }
16
+ exports.WidgetData = WidgetData;
@@ -1,6 +1,21 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.WidgetPackage = void 0;
4
- class WidgetPackage {
5
- }
6
- exports.WidgetPackage = WidgetPackage;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.WidgetPackage = void 0;
4
+ class WidgetPackage {
5
+ static parseJSON(json) {
6
+ const object = JSON.parse(json);
7
+ return this.parseObject(object);
8
+ }
9
+ static parseObject(obj) {
10
+ let widgetPackage = new WidgetPackage();
11
+ Object.assign(widgetPackage, obj);
12
+ return widgetPackage;
13
+ }
14
+ getFullUrl() {
15
+ if (this.url.startsWith("http")) {
16
+ return this.url;
17
+ }
18
+ return this.url + (this.entry.startsWith("/") ? this.entry : `/${this.entry}`);
19
+ }
20
+ }
21
+ exports.WidgetPackage = WidgetPackage;
@@ -1,144 +1,139 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.WidgetHostMode = exports.ThemeMode = exports.WidgetParams = void 0;
4
- /**
5
- * 组件参数,如宽,高,id,语言等环境参数
6
- */
7
- const query_1 = require("../router/query");
8
- const change_case_1 = require("change-case");
9
- class WidgetParams {
10
- /**
11
- * 将组件参数转为url参数
12
- * @param object
13
- * @return URLSearchParams w_w=2&w_h=2&w_id=21&w_width=156&w_height=156
14
- */
15
- toUrlParams() {
16
- const urlParams = new URLSearchParams();
17
- const ownPropertyNames = Object.getOwnPropertyNames(this);
18
- for (let ownPropertyName of ownPropertyNames) {
19
- const key = ownPropertyName;
20
- const value = this[key];
21
- if (value) {
22
- urlParams.append(WidgetParams.PARAM_PREFIX + (0, change_case_1.snakeCase)(ownPropertyName), value.toString());
23
- }
24
- }
25
- return urlParams;
26
- }
27
- getPersistKey() {
28
- return `${this.name}-${this.id}`;
29
- }
30
- /**
31
- * 从当前地址解析组件参数:
32
- * http://localhost:8080/#/widget/config/labor_progress?w_w=2&w_h=2&w_width=156&w_height=156
33
- * =>
34
- * {width:2,height:2,id:21,width_px:156,height_px:156}
35
- */
36
- static fromCurrentLocation() {
37
- const href = window.location.href;
38
- let queryString = href.split("?")[1];
39
- return this.fromObject((0, query_1.parseQuery)(queryString));
40
- }
41
- static setValue(widgetEnv, key, value) {
42
- const keyWithoutPrefix = key.replace(this.PARAM_PREFIX, "");
43
- if (keyWithoutPrefix == WidgetParams.PARAM_ID) {
44
- widgetEnv.id = value;
45
- }
46
- else if (keyWithoutPrefix == WidgetParams.PARAM_X) {
47
- widgetEnv.x = parseInt(value);
48
- }
49
- else if (keyWithoutPrefix == WidgetParams.PARAM_Y) {
50
- widgetEnv.y = parseInt(value);
51
- }
52
- else if (keyWithoutPrefix == WidgetParams.PARAM_HEIGHT) {
53
- widgetEnv.height = parseInt(value);
54
- }
55
- else if (keyWithoutPrefix == WidgetParams.PARAM_WIDTH) {
56
- widgetEnv.width = parseInt(value);
57
- }
58
- else if (keyWithoutPrefix == WidgetParams.PARAM_LANG) {
59
- widgetEnv.lang = value;
60
- }
61
- else if (keyWithoutPrefix == WidgetParams.PARAM_THEME) {
62
- widgetEnv.theme = value;
63
- }
64
- else if (keyWithoutPrefix == WidgetParams.PARAM_MODE) {
65
- widgetEnv.mode = parseInt(value);
66
- }
67
- else if (keyWithoutPrefix == WidgetParams.PARAM_RADIUS) {
68
- widgetEnv.radius = parseInt(value);
69
- }
70
- else if (keyWithoutPrefix == WidgetParams.PARAM_WIDTH_PX) {
71
- widgetEnv.widthPx = parseInt(value);
72
- }
73
- else if (keyWithoutPrefix == WidgetParams.PARAM_HEIGHT_PX) {
74
- widgetEnv.heightPx = parseInt(value);
75
- }
76
- else if (keyWithoutPrefix == WidgetParams.PARAM_NAME) {
77
- widgetEnv.name = value;
78
- }
79
- else if (keyWithoutPrefix == WidgetParams.PARAM_TITLE) {
80
- widgetEnv.title = value;
81
- }
82
- else if (keyWithoutPrefix == WidgetParams.PARAM_PREVIEW) {
83
- widgetEnv.preview = (value === 'true');
84
- }
85
- }
86
- /**
87
- * 从对象键值对中初始化组件参数
88
- * {w_width:2,w_height:2,w_id:21,w_width_px:156,w_height_px:156}=>
89
- * {width:2,height:2,id:21,width_px:156,height_px:156}
90
- * @param object
91
- */
92
- static fromObject(object) {
93
- const widgetEnv = new WidgetParams();
94
- const ownPropertyNames = Object.getOwnPropertyNames(object);
95
- for (let ownPropertyName of ownPropertyNames) {
96
- const key = ownPropertyName;
97
- const value = object[key];
98
- this.setValue(widgetEnv, key, value);
99
- }
100
- return widgetEnv;
101
- }
102
- }
103
- exports.WidgetParams = WidgetParams;
104
- WidgetParams.PARAM_PREFIX = "w_";
105
- WidgetParams.PARAM_ID = "id";
106
- WidgetParams.PARAM_WIDTH = "width";
107
- WidgetParams.PARAM_HEIGHT = "height";
108
- WidgetParams.PARAM_WIDTH_PX = "width_px";
109
- WidgetParams.PARAM_HEIGHT_PX = "height_px";
110
- WidgetParams.PARAM_X = "x";
111
- WidgetParams.PARAM_Y = "y";
112
- WidgetParams.PARAM_LANG = "lang";
113
- WidgetParams.PARAM_THEME = "theme";
114
- WidgetParams.PARAM_MODE = "mode";
115
- WidgetParams.PARAM_RADIUS = "radius";
116
- WidgetParams.PARAM_NAME = "name";
117
- WidgetParams.PARAM_TITLE = "title";
118
- WidgetParams.PARAM_PREVIEW = "preview";
119
- WidgetParams.PARAMS = [
120
- WidgetParams.PARAM_ID,
121
- WidgetParams.PARAM_WIDTH,
122
- WidgetParams.PARAM_HEIGHT,
123
- WidgetParams.PARAM_X,
124
- WidgetParams.PARAM_Y,
125
- WidgetParams.PARAM_LANG,
126
- WidgetParams.PARAM_THEME,
127
- WidgetParams.PARAM_MODE,
128
- WidgetParams.PARAM_WIDTH_PX,
129
- WidgetParams.PARAM_HEIGHT_PX,
130
- WidgetParams.PARAM_NAME,
131
- WidgetParams.PARAM_TITLE,
132
- WidgetParams.PARAM_PREVIEW,
133
- ];
134
- var ThemeMode;
135
- (function (ThemeMode) {
136
- ThemeMode["AUTO"] = "auto";
137
- ThemeMode["LIGHT"] = "LIGHT";
138
- ThemeMode["DARK"] = "DARK";
139
- })(ThemeMode = exports.ThemeMode || (exports.ThemeMode = {}));
140
- var WidgetHostMode;
141
- (function (WidgetHostMode) {
142
- WidgetHostMode[WidgetHostMode["DEFAULT"] = 0] = "DEFAULT";
143
- WidgetHostMode[WidgetHostMode["OVERLAP"] = 1] = "OVERLAP";
144
- })(WidgetHostMode = exports.WidgetHostMode || (exports.WidgetHostMode = {}));
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ThemeMode = exports.WidgetParams = void 0;
4
+ /**
5
+ * 组件参数,如宽,高,id,语言等环境参数
6
+ */
7
+ const query_1 = require("../router/query");
8
+ const change_case_1 = require("change-case");
9
+ class WidgetParams {
10
+ /**
11
+ * 将组件参数转为url参数
12
+ * @param object
13
+ * @return URLSearchParams w_w=2&w_h=2&w_id=21&w_width=156&w_height=156
14
+ */
15
+ toUrlParams() {
16
+ const urlParams = new URLSearchParams();
17
+ const ownPropertyNames = Object.getOwnPropertyNames(this);
18
+ for (let ownPropertyName of ownPropertyNames) {
19
+ const key = ownPropertyName;
20
+ const value = this[key];
21
+ if (value) {
22
+ urlParams.append(WidgetParams.PARAM_PREFIX + (0, change_case_1.snakeCase)(ownPropertyName), value.toString());
23
+ }
24
+ }
25
+ return urlParams;
26
+ }
27
+ getPersistKey() {
28
+ return `${this.name}-${this.id}`;
29
+ }
30
+ /**
31
+ * 从当前地址解析组件参数:
32
+ * http://localhost:8080/#/widget/config/labor_progress?w_w=2&w_h=2&w_width=156&w_height=156
33
+ * =>
34
+ * {width:2,height:2,id:21,width_px:156,height_px:156}
35
+ */
36
+ static fromCurrentLocation() {
37
+ const href = window.location.href;
38
+ let queryString = href.split("?")[1];
39
+ return this.fromObject((0, query_1.parseQuery)(queryString));
40
+ }
41
+ static setValue(widgetEnv, key, value) {
42
+ const keyWithoutPrefix = key.replace(this.PARAM_PREFIX, "");
43
+ if (keyWithoutPrefix == WidgetParams.PARAM_ID) {
44
+ widgetEnv.id = value;
45
+ }
46
+ else if (keyWithoutPrefix == WidgetParams.PARAM_X) {
47
+ widgetEnv.x = parseInt(value);
48
+ }
49
+ else if (keyWithoutPrefix == WidgetParams.PARAM_Y) {
50
+ widgetEnv.y = parseInt(value);
51
+ }
52
+ else if (keyWithoutPrefix == WidgetParams.PARAM_HEIGHT) {
53
+ widgetEnv.height = parseInt(value);
54
+ }
55
+ else if (keyWithoutPrefix == WidgetParams.PARAM_WIDTH) {
56
+ widgetEnv.width = parseInt(value);
57
+ }
58
+ else if (keyWithoutPrefix == WidgetParams.PARAM_LANG) {
59
+ widgetEnv.lang = value;
60
+ }
61
+ else if (keyWithoutPrefix == WidgetParams.PARAM_THEME) {
62
+ widgetEnv.theme = value;
63
+ }
64
+ else if (keyWithoutPrefix == WidgetParams.PARAM_MODE) {
65
+ widgetEnv.mode = parseInt(value);
66
+ }
67
+ else if (keyWithoutPrefix == WidgetParams.PARAM_RADIUS) {
68
+ widgetEnv.radius = parseInt(value);
69
+ }
70
+ else if (keyWithoutPrefix == WidgetParams.PARAM_WIDTH_PX) {
71
+ widgetEnv.widthPx = parseInt(value);
72
+ }
73
+ else if (keyWithoutPrefix == WidgetParams.PARAM_HEIGHT_PX) {
74
+ widgetEnv.heightPx = parseInt(value);
75
+ }
76
+ else if (keyWithoutPrefix == WidgetParams.PARAM_NAME) {
77
+ widgetEnv.name = value;
78
+ }
79
+ else if (keyWithoutPrefix == WidgetParams.PARAM_TITLE) {
80
+ widgetEnv.title = value;
81
+ }
82
+ else if (keyWithoutPrefix == WidgetParams.PARAM_PREVIEW) {
83
+ widgetEnv.preview = (value === 'true');
84
+ }
85
+ }
86
+ /**
87
+ * 从对象键值对中初始化组件参数
88
+ * {w_width:2,w_height:2,w_id:21,w_width_px:156,w_height_px:156}=>
89
+ * {width:2,height:2,id:21,width_px:156,height_px:156}
90
+ * @param object
91
+ */
92
+ static fromObject(object) {
93
+ const widgetEnv = new WidgetParams();
94
+ const ownPropertyNames = Object.getOwnPropertyNames(object);
95
+ for (let ownPropertyName of ownPropertyNames) {
96
+ const key = ownPropertyName;
97
+ const value = object[key];
98
+ this.setValue(widgetEnv, key, value);
99
+ }
100
+ return widgetEnv;
101
+ }
102
+ }
103
+ exports.WidgetParams = WidgetParams;
104
+ WidgetParams.PARAM_PREFIX = "w_";
105
+ WidgetParams.PARAM_ID = "id";
106
+ WidgetParams.PARAM_WIDTH = "width";
107
+ WidgetParams.PARAM_HEIGHT = "height";
108
+ WidgetParams.PARAM_WIDTH_PX = "width_px";
109
+ WidgetParams.PARAM_HEIGHT_PX = "height_px";
110
+ WidgetParams.PARAM_X = "x";
111
+ WidgetParams.PARAM_Y = "y";
112
+ WidgetParams.PARAM_LANG = "lang";
113
+ WidgetParams.PARAM_THEME = "theme";
114
+ WidgetParams.PARAM_MODE = "mode";
115
+ WidgetParams.PARAM_RADIUS = "radius";
116
+ WidgetParams.PARAM_NAME = "name";
117
+ WidgetParams.PARAM_TITLE = "title";
118
+ WidgetParams.PARAM_PREVIEW = "preview";
119
+ WidgetParams.PARAMS = [
120
+ WidgetParams.PARAM_ID,
121
+ WidgetParams.PARAM_WIDTH,
122
+ WidgetParams.PARAM_HEIGHT,
123
+ WidgetParams.PARAM_X,
124
+ WidgetParams.PARAM_Y,
125
+ WidgetParams.PARAM_LANG,
126
+ WidgetParams.PARAM_THEME,
127
+ WidgetParams.PARAM_MODE,
128
+ WidgetParams.PARAM_WIDTH_PX,
129
+ WidgetParams.PARAM_HEIGHT_PX,
130
+ WidgetParams.PARAM_NAME,
131
+ WidgetParams.PARAM_TITLE,
132
+ WidgetParams.PARAM_PREVIEW,
133
+ ];
134
+ var ThemeMode;
135
+ (function (ThemeMode) {
136
+ ThemeMode["AUTO"] = "auto";
137
+ ThemeMode["LIGHT"] = "LIGHT";
138
+ ThemeMode["DARK"] = "DARK";
139
+ })(ThemeMode = exports.ThemeMode || (exports.ThemeMode = {}));