@widget-js/core 0.0.6 → 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.
- package/dist/cjs/api/ElectronApi.js +73 -53
- package/dist/cjs/api/Keys.js +11 -0
- package/dist/cjs/index.js +5 -0
- package/dist/cjs/model/BroadcastEvent.js +12 -0
- package/dist/cjs/model/SocialInfo.js +10 -0
- package/dist/cjs/model/Widget.js +60 -29
- package/dist/cjs/model/WidgetData.js +16 -0
- package/dist/cjs/model/WidgetParams.js +143 -0
- package/dist/cjs/repository/WidgetDataRepository.js +88 -0
- package/dist/cjs/router/encoding.js +144 -0
- package/dist/cjs/router/query.js +107 -0
- package/dist/esm/api/ElectronApi.js +73 -54
- package/dist/esm/api/Keys.js +7 -0
- package/dist/esm/index.js +5 -0
- package/dist/esm/model/BroadcastEvent.js +8 -0
- package/dist/esm/model/SocialInfo.js +6 -0
- package/dist/esm/model/Widget.js +60 -30
- package/dist/esm/model/WidgetData.js +12 -0
- package/dist/esm/model/WidgetParams.js +139 -0
- package/dist/esm/repository/WidgetDataRepository.js +81 -0
- package/dist/esm/router/encoding.js +135 -0
- package/dist/esm/router/query.js +101 -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 +5 -0
- package/dist/types/model/BroadcastEvent.d.ts +7 -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 +35 -0
- package/dist/types/model/WidgetParams.d.ts +63 -0
- package/dist/types/repository/WidgetDataRepository.d.ts +27 -0
- package/dist/types/router/encoding.d.ts +62 -0
- package/dist/types/router/query.d.ts +62 -0
- package/dist/umd/index.js +2 -1
- package/dist/umd/index.js.LICENSE.txt +6 -0
- package/package.json +7 -4
|
@@ -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,64 +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
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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
|
-
var ElectronApi = /** @class */ (function () {
|
|
38
|
-
function ElectronApi() {
|
|
39
|
-
}
|
|
40
|
-
ElectronApi.openAddWidgetWindow = function () {
|
|
10
|
+
import { Keys } from "./Keys";
|
|
11
|
+
export class ElectronApi {
|
|
12
|
+
static openAddWidgetWindow() {
|
|
41
13
|
if (this.hasElectronApi()) {
|
|
42
14
|
// @ts-ignore
|
|
43
15
|
window.electronAPI.invokeIpc("openAddWidgetWindow");
|
|
44
16
|
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
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
|
+
}
|
|
25
|
+
});
|
|
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
|
+
}
|
|
33
|
+
});
|
|
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
|
+
}
|
|
41
|
+
});
|
|
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));
|
|
62
47
|
});
|
|
63
48
|
});
|
|
64
|
-
}
|
|
65
|
-
|
|
49
|
+
}
|
|
50
|
+
static unregisterBroadcast() {
|
|
51
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
52
|
+
yield this.removeIpcListener(Keys.BROADCAST_EVENT);
|
|
53
|
+
});
|
|
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
|
+
}
|
|
61
|
+
});
|
|
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
|
+
}
|
|
69
|
+
});
|
|
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;
|
|
78
|
+
}
|
|
79
|
+
if (typeof defaultValue == "boolean") {
|
|
80
|
+
return value === "true";
|
|
81
|
+
}
|
|
82
|
+
return value;
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
static hasElectronApi() {
|
|
66
87
|
return Reflect.has(window, "electronAPI");
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
}());
|
|
70
|
-
export { ElectronApi };
|
|
88
|
+
}
|
|
89
|
+
}
|
package/dist/esm/index.js
CHANGED
|
@@ -1,2 +1,7 @@
|
|
|
1
1
|
export * from "./model/Widget";
|
|
2
|
+
export * from "./model/BroadcastEvent";
|
|
3
|
+
export * from "./model/WidgetData";
|
|
4
|
+
export * from "./model/WidgetParams";
|
|
2
5
|
export * from "./api/ElectronApi";
|
|
6
|
+
export * from "./api/Keys";
|
|
7
|
+
export * from "./repository/WidgetDataRepository";
|
package/dist/esm/model/Widget.js
CHANGED
|
@@ -1,47 +1,77 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
export class Widget {
|
|
2
|
+
constructor(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
|
* 获取组件标题
|
|
24
25
|
* @param lang 语言环境,不传则获取默认语言
|
|
25
26
|
*/
|
|
26
|
-
|
|
27
|
+
getTitle(lang) {
|
|
27
28
|
return lang ? this.title.get(lang) : this.title.get(this.lang);
|
|
28
|
-
}
|
|
29
|
+
}
|
|
29
30
|
/**
|
|
30
31
|
* 获取组件标描述
|
|
31
32
|
* @param lang 语言环境,不传则获取默认标题
|
|
32
33
|
*/
|
|
33
|
-
|
|
34
|
-
return lang ? this.
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
34
|
+
getDescription(lang) {
|
|
35
|
+
return lang ? this.description.get(lang) : this.description.get(this.lang);
|
|
36
|
+
}
|
|
37
|
+
toJSON() {
|
|
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
|
+
static parse(json) {
|
|
56
|
+
const 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
|
+
});
|
|
73
|
+
}
|
|
74
|
+
}
|
|
45
75
|
export var WidgetKeyword;
|
|
46
76
|
(function (WidgetKeyword) {
|
|
47
77
|
WidgetKeyword["RECOMMEND"] = "recommend";
|