@widget-js/core 0.0.7 → 0.0.8

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.
@@ -0,0 +1,144 @@
1
+ "use strict";
2
+ /**
3
+ * Encoding Rules ␣ = Space Path: ␣ " < > # ? { } Query: ␣ " < > # & = Hash: ␣ "
4
+ * < > `
5
+ *
6
+ * On top of that, the RFC3986 (https://tools.ietf.org/html/rfc3986#section-2.2)
7
+ * defines some extra characters to be encoded. Most browsers do not encode them
8
+ * in encodeURI https://github.com/whatwg/url/issues/369, so it may be safer to
9
+ * also encode `!'()*`. Leaving un-encoded only ASCII alphanumeric(`a-zA-Z0-9`)
10
+ * plus `-._~`. This extra safety should be applied to query by patching the
11
+ * string returned by encodeURIComponent encodeURI also encodes `[\]^`. `\`
12
+ * should be encoded to avoid ambiguity. Browsers (IE, FF, C) transform a `\`
13
+ * into a `/` if directly typed in. The _backtick_ (`````) should also be
14
+ * encoded everywhere because some browsers like FF encode it when directly
15
+ * written while others don't. Safari and IE don't encode ``"<>{}``` in hash.
16
+ */
17
+ // const EXTRA_RESERVED_RE = /[!'()*]/g
18
+ // const encodeReservedReplacer = (c: string) => '%' + c.charCodeAt(0).toString(16)
19
+ Object.defineProperty(exports, "__esModule", { value: true });
20
+ exports.decode = exports.encodeParam = exports.encodePath = exports.encodeQueryKey = exports.encodeQueryValue = exports.encodeHash = exports.PLUS_RE = void 0;
21
+ const HASH_RE = /#/g; // %23
22
+ const AMPERSAND_RE = /&/g; // %26
23
+ const SLASH_RE = /\//g; // %2F
24
+ const EQUAL_RE = /=/g; // %3D
25
+ const IM_RE = /\?/g; // %3F
26
+ exports.PLUS_RE = /\+/g; // %2B
27
+ /**
28
+ * NOTE: It's not clear to me if we should encode the + symbol in queries, it
29
+ * seems to be less flexible than not doing so and I can't find out the legacy
30
+ * systems requiring this for regular requests like text/html. In the standard,
31
+ * the encoding of the plus character is only mentioned for
32
+ * application/x-www-form-urlencoded
33
+ * (https://url.spec.whatwg.org/#urlencoded-parsing) and most browsers seems lo
34
+ * leave the plus character as is in queries. To be more flexible, we allow the
35
+ * plus character on the query, but it can also be manually encoded by the user.
36
+ *
37
+ * Resources:
38
+ * - https://url.spec.whatwg.org/#urlencoded-parsing
39
+ * - https://stackoverflow.com/questions/1634271/url-encoding-the-space-character-or-20
40
+ */
41
+ const ENC_BRACKET_OPEN_RE = /%5B/g; // [
42
+ const ENC_BRACKET_CLOSE_RE = /%5D/g; // ]
43
+ const ENC_CARET_RE = /%5E/g; // ^
44
+ const ENC_BACKTICK_RE = /%60/g; // `
45
+ const ENC_CURLY_OPEN_RE = /%7B/g; // {
46
+ const ENC_PIPE_RE = /%7C/g; // |
47
+ const ENC_CURLY_CLOSE_RE = /%7D/g; // }
48
+ const ENC_SPACE_RE = /%20/g; // }
49
+ /**
50
+ * Encode characters that need to be encoded on the path, search and hash
51
+ * sections of the URL.
52
+ *
53
+ * @internal
54
+ * @param text - string to encode
55
+ * @returns encoded string
56
+ */
57
+ function commonEncode(text) {
58
+ return encodeURI('' + text)
59
+ .replace(ENC_PIPE_RE, '|')
60
+ .replace(ENC_BRACKET_OPEN_RE, '[')
61
+ .replace(ENC_BRACKET_CLOSE_RE, ']');
62
+ }
63
+ /**
64
+ * Encode characters that need to be encoded on the hash section of the URL.
65
+ *
66
+ * @param text - string to encode
67
+ * @returns encoded string
68
+ */
69
+ function encodeHash(text) {
70
+ return commonEncode(text)
71
+ .replace(ENC_CURLY_OPEN_RE, '{')
72
+ .replace(ENC_CURLY_CLOSE_RE, '}')
73
+ .replace(ENC_CARET_RE, '^');
74
+ }
75
+ exports.encodeHash = encodeHash;
76
+ /**
77
+ * Encode characters that need to be encoded query values on the query
78
+ * section of the URL.
79
+ *
80
+ * @param text - string to encode
81
+ * @returns encoded string
82
+ */
83
+ function encodeQueryValue(text) {
84
+ return (commonEncode(text)
85
+ // Encode the space as +, encode the + to differentiate it from the space
86
+ .replace(exports.PLUS_RE, '%2B')
87
+ .replace(ENC_SPACE_RE, '+')
88
+ .replace(HASH_RE, '%23')
89
+ .replace(AMPERSAND_RE, '%26')
90
+ .replace(ENC_BACKTICK_RE, '`')
91
+ .replace(ENC_CURLY_OPEN_RE, '{')
92
+ .replace(ENC_CURLY_CLOSE_RE, '}')
93
+ .replace(ENC_CARET_RE, '^'));
94
+ }
95
+ exports.encodeQueryValue = encodeQueryValue;
96
+ /**
97
+ * Like `encodeQueryValue` but also encodes the `=` character.
98
+ *
99
+ * @param text - string to encode
100
+ */
101
+ function encodeQueryKey(text) {
102
+ return encodeQueryValue(text).replace(EQUAL_RE, '%3D');
103
+ }
104
+ exports.encodeQueryKey = encodeQueryKey;
105
+ /**
106
+ * Encode characters that need to be encoded on the path section of the URL.
107
+ *
108
+ * @param text - string to encode
109
+ * @returns encoded string
110
+ */
111
+ function encodePath(text) {
112
+ return commonEncode(text).replace(HASH_RE, '%23').replace(IM_RE, '%3F');
113
+ }
114
+ exports.encodePath = encodePath;
115
+ /**
116
+ * Encode characters that need to be encoded on the path section of the URL as a
117
+ * param. This function encodes everything {@link encodePath} does plus the
118
+ * slash (`/`) character. If `text` is `null` or `undefined`, returns an empty
119
+ * string instead.
120
+ *
121
+ * @param text - string to encode
122
+ * @returns encoded string
123
+ */
124
+ function encodeParam(text) {
125
+ return text == null ? '' : encodePath(text).replace(SLASH_RE, '%2F');
126
+ }
127
+ exports.encodeParam = encodeParam;
128
+ /**
129
+ * Decode text using `decodeURIComponent`. Returns the original text if it
130
+ * fails.
131
+ *
132
+ * @param text - string to decode
133
+ * @returns decoded string
134
+ */
135
+ function decode(text) {
136
+ try {
137
+ return decodeURIComponent('' + text);
138
+ }
139
+ catch (err) {
140
+ // __DEV__ && warn(`Error decoding "${text}". Using original value`)
141
+ }
142
+ return '' + text;
143
+ }
144
+ exports.decode = decode;
@@ -0,0 +1,107 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.normalizeQuery = exports.stringifyQuery = exports.parseQuery = void 0;
4
+ const encoding_1 = require("./encoding");
5
+ const isArray = Array.isArray;
6
+ /**
7
+ * Transforms a queryString into a {@link LocationQuery} object. Accept both, a
8
+ * version with the leading `?` and without Should work as URLSearchParams
9
+ * @internal
10
+ *
11
+ * @param search - search string to parse
12
+ * @returns a query object
13
+ */
14
+ function parseQuery(search) {
15
+ const query = {};
16
+ // avoid creating an object with an empty key and empty value
17
+ // because of split('&')
18
+ if (search === '' || search === '?')
19
+ return query;
20
+ const hasLeadingIM = search[0] === '?';
21
+ const searchParams = (hasLeadingIM ? search.slice(1) : search).split('&');
22
+ for (let i = 0; i < searchParams.length; ++i) {
23
+ // pre decode the + into space
24
+ const searchParam = searchParams[i].replace(encoding_1.PLUS_RE, ' ');
25
+ // allow the = character
26
+ const eqPos = searchParam.indexOf('=');
27
+ const key = (0, encoding_1.decode)(eqPos < 0 ? searchParam : searchParam.slice(0, eqPos));
28
+ const value = eqPos < 0 ? null : (0, encoding_1.decode)(searchParam.slice(eqPos + 1));
29
+ if (key in query) {
30
+ // an extra variable for ts types
31
+ let currentValue = query[key];
32
+ if (!isArray(currentValue)) {
33
+ currentValue = query[key] = [currentValue];
34
+ }
35
+ // we force the modification
36
+ ;
37
+ currentValue.push(value);
38
+ }
39
+ else {
40
+ query[key] = value;
41
+ }
42
+ }
43
+ return query;
44
+ }
45
+ exports.parseQuery = parseQuery;
46
+ /**
47
+ * Stringifies a {@link LocationQueryRaw} object. Like `URLSearchParams`, it
48
+ * doesn't prepend a `?`
49
+ *
50
+ * @internal
51
+ *
52
+ * @param query - query object to stringify
53
+ * @returns string version of the query without the leading `?`
54
+ */
55
+ function stringifyQuery(query) {
56
+ let search = '';
57
+ for (let key in query) {
58
+ const value = query[key];
59
+ key = (0, encoding_1.encodeQueryKey)(key);
60
+ if (value == null) {
61
+ // only null adds the value
62
+ if (value !== undefined) {
63
+ search += (search.length ? '&' : '') + key;
64
+ }
65
+ continue;
66
+ }
67
+ // keep null values
68
+ const values = isArray(value)
69
+ ? value.map(v => v && (0, encoding_1.encodeQueryValue)(v))
70
+ : [value && (0, encoding_1.encodeQueryValue)(value)];
71
+ values.forEach(value => {
72
+ // skip undefined values in arrays as if they were not present
73
+ // smaller code than using filter
74
+ if (value !== undefined) {
75
+ // only append & with non-empty search
76
+ search += (search.length ? '&' : '') + key;
77
+ if (value != null)
78
+ search += '=' + value;
79
+ }
80
+ });
81
+ }
82
+ return search;
83
+ }
84
+ exports.stringifyQuery = stringifyQuery;
85
+ /**
86
+ * Transforms a {@link LocationQueryRaw} into a {@link LocationQuery} by casting
87
+ * numbers into strings, removing keys with an undefined value and replacing
88
+ * undefined with null in arrays
89
+ *
90
+ * @param query - query object to normalize
91
+ * @returns a normalized query object
92
+ */
93
+ function normalizeQuery(query) {
94
+ const normalizedQuery = {};
95
+ for (const key in query) {
96
+ const value = query[key];
97
+ if (value !== undefined) {
98
+ normalizedQuery[key] = isArray(value)
99
+ ? value.map(v => (v == null ? null : '' + v))
100
+ : value == null
101
+ ? value
102
+ : '' + value;
103
+ }
104
+ }
105
+ return normalizedQuery;
106
+ }
107
+ exports.normalizeQuery = normalizeQuery;
@@ -7,181 +7,83 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
- var __generator = (this && this.__generator) || function (thisArg, body) {
11
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
12
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
13
- function verb(n) { return function (v) { return step([n, v]); }; }
14
- function step(op) {
15
- if (f) throw new TypeError("Generator is already executing.");
16
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
17
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
18
- if (y = 0, t) op = [op[0] & 2, t.value];
19
- switch (op[0]) {
20
- case 0: case 1: t = op; break;
21
- case 4: _.label++; return { value: op[1], done: false };
22
- case 5: _.label++; y = op[1]; op = [0]; continue;
23
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
24
- default:
25
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
26
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
27
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
28
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
29
- if (t[2]) _.ops.pop();
30
- _.trys.pop(); continue;
31
- }
32
- op = body.call(thisArg, _);
33
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
34
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
- }
36
- };
37
10
  import { Keys } from "./Keys";
38
- var ElectronApi = /** @class */ (function () {
39
- function ElectronApi() {
40
- }
41
- ElectronApi.openAddWidgetWindow = function () {
11
+ export class ElectronApi {
12
+ static openAddWidgetWindow() {
42
13
  if (this.hasElectronApi()) {
43
14
  // @ts-ignore
44
15
  window.electronAPI.invokeIpc("openAddWidgetWindow");
45
16
  }
46
- };
47
- ElectronApi.registerWidgets = function (widgets) {
48
- return __awaiter(this, void 0, void 0, function () {
49
- var data;
50
- return __generator(this, function (_a) {
51
- switch (_a.label) {
52
- case 0:
53
- if (!this.hasElectronApi()) return [3 /*break*/, 2];
54
- data = JSON.parse(JSON.stringify(widgets.map(function (item) { return JSON.stringify(item); })));
55
- // @ts-ignore
56
- return [4 /*yield*/, window.electronAPI.invokeIpc("registerWidgets", data)];
57
- case 1:
58
- // @ts-ignore
59
- _a.sent();
60
- _a.label = 2;
61
- case 2: return [2 /*return*/];
62
- }
63
- });
17
+ }
18
+ static registerWidgets(widgets) {
19
+ return __awaiter(this, void 0, void 0, function* () {
20
+ if (this.hasElectronApi()) {
21
+ const data = JSON.parse(JSON.stringify(widgets.map(item => JSON.stringify(item))));
22
+ // @ts-ignore
23
+ yield window.electronAPI.invokeIpc("registerWidgets", data);
24
+ }
64
25
  });
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
- });
26
+ }
27
+ static setConfig(key, value) {
28
+ return __awaiter(this, void 0, void 0, function* () {
29
+ if (this.hasElectronApi()) {
30
+ // @ts-ignore
31
+ yield window.electronAPI.invokeIpc("setConfig", { key, value });
32
+ }
81
33
  });
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
- });
34
+ }
35
+ static sendBroadcastEvent(event) {
36
+ return __awaiter(this, void 0, void 0, function* () {
37
+ if (this.hasElectronApi()) {
38
+ // @ts-ignore
39
+ yield window.electronAPI.invokeIpc(Keys.BROADCAST_EVENT, JSON.stringify(event));
40
+ }
98
41
  });
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
- }
42
+ }
43
+ static registerBroadcast(callback) {
44
+ return __awaiter(this, void 0, void 0, function* () {
45
+ yield this.addIpcListener(Keys.BROADCAST_EVENT, (json) => {
46
+ callback(JSON.parse(json));
111
47
  });
112
48
  });
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
- });
49
+ }
50
+ static unregisterBroadcast() {
51
+ return __awaiter(this, void 0, void 0, function* () {
52
+ yield this.removeIpcListener(Keys.BROADCAST_EVENT);
124
53
  });
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
- });
54
+ }
55
+ static addIpcListener(key, f) {
56
+ return __awaiter(this, void 0, void 0, function* () {
57
+ if (this.hasElectronApi()) {
58
+ // @ts-ignore
59
+ yield window.electronAPI.addIpcListener(key, f);
60
+ }
141
61
  });
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
- });
62
+ }
63
+ static removeIpcListener(key) {
64
+ return __awaiter(this, void 0, void 0, function* () {
65
+ if (this.hasElectronApi()) {
66
+ // @ts-ignore
67
+ yield window.electronAPI.removeIpcListener(key);
68
+ }
158
69
  });
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*/];
70
+ }
71
+ static getConfig(key, defaultValue) {
72
+ return __awaiter(this, void 0, void 0, function* () {
73
+ if (this.hasElectronApi()) {
74
+ // @ts-ignore
75
+ const value = yield window.electronAPI.invokeIpc("getConfig", key);
76
+ if (value === null || value === undefined) {
77
+ return defaultValue;
178
78
  }
179
- });
79
+ if (typeof defaultValue == "boolean") {
80
+ return value === "true";
81
+ }
82
+ return value;
83
+ }
180
84
  });
181
- };
182
- ElectronApi.hasElectronApi = function () {
85
+ }
86
+ static hasElectronApi() {
183
87
  return Reflect.has(window, "electronAPI");
184
- };
185
- return ElectronApi;
186
- }());
187
- export { ElectronApi };
88
+ }
89
+ }
@@ -1,11 +1,7 @@
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 };
1
+ export class Keys {
2
+ }
3
+ Keys.CONFIG_LAUNCH_AT_STARTUP = "LAUNCH_AT_STARTUP";
4
+ Keys.CONFIG_WIDGET_SHADOW = "WIDGET_SHADOW";
5
+ Keys.CHANNEL_MAIN = "WeiZ5kaKijae";
6
+ Keys.EVENT_WIDGET_UPDATED = "WIDGET_SHADOW";
7
+ Keys.BROADCAST_EVENT = "sendBroadcastEvent";
package/dist/esm/index.js CHANGED
@@ -1,5 +1,7 @@
1
1
  export * from "./model/Widget";
2
2
  export * from "./model/BroadcastEvent";
3
3
  export * from "./model/WidgetData";
4
+ export * from "./model/WidgetParams";
4
5
  export * from "./api/ElectronApi";
5
6
  export * from "./api/Keys";
7
+ export * from "./repository/WidgetDataRepository";
@@ -1,9 +1,8 @@
1
- var BroadcastEvent = /** @class */ (function () {
2
- function BroadcastEvent(type, from, payload) {
1
+ export class BroadcastEvent {
2
+ constructor(type, from, payload) {
3
3
  this.type = type;
4
4
  this.from = from;
5
5
  this.payload = payload;
6
6
  }
7
- return BroadcastEvent;
8
- }());
9
- export { BroadcastEvent };
7
+ }
8
+ BroadcastEvent.TYPE_WIDGET_UPDATED = "BROADCAST:WIDGET_UPDATED";
@@ -1,8 +1,6 @@
1
- var SocialInfo = /** @class */ (function () {
2
- function SocialInfo(name, url) {
1
+ export class SocialInfo {
2
+ constructor(name, url) {
3
3
  this.name = name;
4
4
  this.content = url;
5
5
  }
6
- return SocialInfo;
7
- }());
8
- export { SocialInfo };
6
+ }
@@ -1,5 +1,5 @@
1
- var Widget = /** @class */ (function () {
2
- function Widget(options) {
1
+ export class Widget {
2
+ constructor(options) {
3
3
  var _a, _b, _c, _d, _e;
4
4
  /**
5
5
  * 组件默认语言
@@ -24,17 +24,17 @@ var Widget = /** @class */ (function () {
24
24
  * 获取组件标题
25
25
  * @param lang 语言环境,不传则获取默认语言
26
26
  */
27
- Widget.prototype.getTitle = function (lang) {
27
+ getTitle(lang) {
28
28
  return lang ? this.title.get(lang) : this.title.get(this.lang);
29
- };
29
+ }
30
30
  /**
31
31
  * 获取组件标描述
32
32
  * @param lang 语言环境,不传则获取默认标题
33
33
  */
34
- Widget.prototype.getDescription = function (lang) {
34
+ getDescription(lang) {
35
35
  return lang ? this.description.get(lang) : this.description.get(this.lang);
36
- };
37
- Widget.prototype.toJSON = function () {
36
+ }
37
+ toJSON() {
38
38
  return {
39
39
  name: this.name,
40
40
  title: Object.fromEntries(this.title),
@@ -51,9 +51,9 @@ var Widget = /** @class */ (function () {
51
51
  configUrl: this.configUrl,
52
52
  extraUrl: Object.fromEntries(this.extraUrl),
53
53
  };
54
- };
55
- Widget.parse = function (json) {
56
- var object = JSON.parse(json);
54
+ }
55
+ static parse(json) {
56
+ const object = JSON.parse(json);
57
57
  return new Widget({
58
58
  configUrl: object["configUrl"],
59
59
  description: new Map(Object.entries(object["description"])),
@@ -70,10 +70,8 @@ var Widget = /** @class */ (function () {
70
70
  url: object["url"],
71
71
  w: object["w"]
72
72
  });
73
- };
74
- return Widget;
75
- }());
76
- export { Widget };
73
+ }
74
+ }
77
75
  export var WidgetKeyword;
78
76
  (function (WidgetKeyword) {
79
77
  WidgetKeyword["RECOMMEND"] = "recommend";
@@ -1,11 +1,12 @@
1
1
  /**
2
2
  * 组件配置数据,用于存储组件自定义页面所设置的数据
3
3
  */
4
- var WidgetData = /** @class */ (function () {
5
- function WidgetData(name, id) {
4
+ export class WidgetData {
5
+ constructor(name, id) {
6
6
  this.id = id;
7
7
  this.name = name;
8
8
  }
9
- return WidgetData;
10
- }());
11
- export default WidgetData;
9
+ parseJSON(json) {
10
+ Object.assign(this, json);
11
+ }
12
+ }