@widget-js/core 0.1.6 → 0.1.9

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 (72) 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 +42 -24
  6. package/dist/cjs/api/Channel.js +11 -11
  7. package/dist/cjs/api/ElectronApi.js +13 -13
  8. package/dist/cjs/api/NotificationApi.js +83 -83
  9. package/dist/cjs/api/WidgetApi.js +58 -49
  10. package/dist/cjs/index.js +35 -34
  11. package/dist/cjs/model/HostedMode.js +14 -0
  12. package/dist/cjs/model/Notification.js +15 -15
  13. package/dist/cjs/model/SocialInfo.js +10 -10
  14. package/dist/cjs/model/Widget.js +79 -79
  15. package/dist/cjs/model/WidgetData.js +16 -16
  16. package/dist/cjs/model/WidgetPackage.js +21 -6
  17. package/dist/cjs/model/WidgetParams.js +139 -144
  18. package/dist/cjs/model/event/BroadcastEvent.js +14 -14
  19. package/dist/cjs/model/event/WebSocketEvent.js +14 -14
  20. package/dist/cjs/model/interface/IHostedWidget.js +2 -0
  21. package/dist/cjs/repository/WidgetDataRepository.js +71 -71
  22. package/dist/cjs/router/encoding.js +144 -144
  23. package/dist/cjs/router/query.js +84 -84
  24. package/dist/cjs/utils/ElectronUtils.js +24 -24
  25. package/dist/esm/api/ApiConstants.js +4 -4
  26. package/dist/esm/api/AppApi.js +27 -27
  27. package/dist/esm/api/BroadcastApi.js +16 -16
  28. package/dist/esm/api/BrowserWindowApi.js +38 -20
  29. package/dist/esm/api/Channel.js +8 -8
  30. package/dist/esm/api/ElectronApi.js +9 -9
  31. package/dist/esm/api/NotificationApi.js +79 -79
  32. package/dist/esm/api/WidgetApi.js +54 -45
  33. package/dist/esm/index.js +19 -18
  34. package/dist/esm/model/HostedMode.js +11 -0
  35. package/dist/esm/model/Notification.js +11 -11
  36. package/dist/esm/model/SocialInfo.js +6 -6
  37. package/dist/esm/model/Widget.js +75 -75
  38. package/dist/esm/model/WidgetData.js +12 -12
  39. package/dist/esm/model/WidgetPackage.js +17 -2
  40. package/dist/esm/model/WidgetParams.js +135 -140
  41. package/dist/esm/model/event/BroadcastEvent.js +10 -10
  42. package/dist/esm/model/event/WebSocketEvent.js +10 -10
  43. package/dist/esm/model/interface/IHostedWidget.js +1 -0
  44. package/dist/esm/repository/WidgetDataRepository.js +64 -64
  45. package/dist/esm/router/encoding.js +135 -135
  46. package/dist/esm/router/query.js +79 -79
  47. package/dist/esm/utils/ElectronUtils.js +20 -20
  48. package/dist/types/api/ApiConstants.d.ts +4 -4
  49. package/dist/types/api/AppApi.d.ts +10 -10
  50. package/dist/types/api/BroadcastApi.d.ts +6 -6
  51. package/dist/types/api/BrowserWindowApi.d.ts +27 -10
  52. package/dist/types/api/Channel.d.ts +7 -7
  53. package/dist/types/api/ElectronApi.d.ts +4 -4
  54. package/dist/types/api/NotificationApi.d.ts +14 -14
  55. package/dist/types/api/WidgetApi.d.ts +30 -24
  56. package/dist/types/index.d.ts +19 -18
  57. package/dist/types/model/HostedMode.d.ts +10 -0
  58. package/dist/types/model/Notification.d.ts +16 -16
  59. package/dist/types/model/SocialInfo.d.ts +6 -6
  60. package/dist/types/model/Widget.d.ts +96 -85
  61. package/dist/types/model/WidgetData.d.ts +35 -35
  62. package/dist/types/model/WidgetPackage.d.ts +43 -41
  63. package/dist/types/model/WidgetParams.d.ts +60 -63
  64. package/dist/types/model/event/BroadcastEvent.d.ts +12 -12
  65. package/dist/types/model/event/WebSocketEvent.d.ts +8 -8
  66. package/dist/types/model/interface/IHostedWidget.d.ts +13 -0
  67. package/dist/types/repository/WidgetDataRepository.d.ts +26 -26
  68. package/dist/types/router/encoding.d.ts +62 -62
  69. package/dist/types/router/query.d.ts +53 -53
  70. package/dist/types/utils/ElectronUtils.d.ts +8 -8
  71. package/dist/umd/index.js +1 -1
  72. package/package.json +2 -2
@@ -1,71 +1,71 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.WidgetDataRepository = void 0;
7
- const localforage_1 = __importDefault(require("localforage"));
8
- const BroadcastEvent_1 = require("../model/event/BroadcastEvent");
9
- const BroadcastApi_1 = require("../api/BroadcastApi");
10
- class WidgetDataRepository {
11
- /**
12
- * 保存组件数据
13
- * @param data
14
- */
15
- static async save(data) {
16
- let store = this.getStore(data.name);
17
- const result = await store.setItem(this.getKey(data.name, data.id), JSON.stringify(data));
18
- const broadcastEvent = new BroadcastEvent_1.BroadcastEvent(BroadcastEvent_1.BroadcastEvent.TYPE_WIDGET_UPDATED, "", data);
19
- await BroadcastApi_1.BroadcastApi.sendBroadcastEvent(broadcastEvent);
20
- return result;
21
- }
22
- /**
23
- * 获取组件 LocalForage 存储实例
24
- * @param name
25
- */
26
- static getStore(name) {
27
- if (this.stores.has(name)) {
28
- return this.stores.get(name);
29
- }
30
- const store = localforage_1.default.createInstance({ name: name });
31
- this.stores.set(name, store);
32
- return store;
33
- }
34
- /**
35
- * 通过组件名保存组件信息,通常用于存储可以在同类组件中共用的数据
36
- * @param data
37
- */
38
- static async saveByName(data) {
39
- const store = this.getStore(data.name);
40
- const json = JSON.stringify(data);
41
- const result = await store.setItem(data.name, json);
42
- const broadcastEvent = new BroadcastEvent_1.BroadcastEvent(BroadcastEvent_1.BroadcastEvent.TYPE_WIDGET_UPDATED, "", { name: data.name, json });
43
- await BroadcastApi_1.BroadcastApi.sendBroadcastEvent(broadcastEvent);
44
- return result;
45
- }
46
- static async findByName(name, type) {
47
- let store = this.getStore(name);
48
- let result = await store.getItem(name);
49
- if (result) {
50
- const widgetData = new type(name);
51
- widgetData.parseJSON(JSON.parse(result));
52
- return widgetData;
53
- }
54
- return undefined;
55
- }
56
- static async find(name, id, type) {
57
- let store = this.getStore(name);
58
- let result = await store.getItem(this.getKey(name, id));
59
- if (result) {
60
- const widgetData = new type(name, id);
61
- widgetData.parseJSON(JSON.parse(result));
62
- return widgetData;
63
- }
64
- return undefined;
65
- }
66
- static getKey(name, id) {
67
- return `${name}@${id}`;
68
- }
69
- }
70
- exports.WidgetDataRepository = WidgetDataRepository;
71
- WidgetDataRepository.stores = new Map();
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.WidgetDataRepository = void 0;
7
+ const localforage_1 = __importDefault(require("localforage"));
8
+ const BroadcastEvent_1 = require("../model/event/BroadcastEvent");
9
+ const BroadcastApi_1 = require("../api/BroadcastApi");
10
+ class WidgetDataRepository {
11
+ /**
12
+ * 保存组件数据
13
+ * @param data
14
+ */
15
+ static async save(data) {
16
+ let store = this.getStore(data.name);
17
+ const result = await store.setItem(this.getKey(data.name, data.id), JSON.stringify(data));
18
+ const broadcastEvent = new BroadcastEvent_1.BroadcastEvent(BroadcastEvent_1.BroadcastEvent.TYPE_WIDGET_UPDATED, "", data);
19
+ await BroadcastApi_1.BroadcastApi.sendBroadcastEvent(broadcastEvent);
20
+ return result;
21
+ }
22
+ /**
23
+ * 获取组件 LocalForage 存储实例
24
+ * @param name
25
+ */
26
+ static getStore(name) {
27
+ if (this.stores.has(name)) {
28
+ return this.stores.get(name);
29
+ }
30
+ const store = localforage_1.default.createInstance({ name: name });
31
+ this.stores.set(name, store);
32
+ return store;
33
+ }
34
+ /**
35
+ * 通过组件名保存组件信息,通常用于存储可以在同类组件中共用的数据
36
+ * @param data
37
+ */
38
+ static async saveByName(data) {
39
+ const store = this.getStore(data.name);
40
+ const json = JSON.stringify(data);
41
+ const result = await store.setItem(data.name, json);
42
+ const broadcastEvent = new BroadcastEvent_1.BroadcastEvent(BroadcastEvent_1.BroadcastEvent.TYPE_WIDGET_UPDATED, "", { name: data.name, json });
43
+ await BroadcastApi_1.BroadcastApi.sendBroadcastEvent(broadcastEvent);
44
+ return result;
45
+ }
46
+ static async findByName(name, type) {
47
+ let store = this.getStore(name);
48
+ let result = await store.getItem(name);
49
+ if (result) {
50
+ const widgetData = new type(name);
51
+ widgetData.parseJSON(JSON.parse(result));
52
+ return widgetData;
53
+ }
54
+ return undefined;
55
+ }
56
+ static async find(name, id, type) {
57
+ let store = this.getStore(name);
58
+ let result = await store.getItem(this.getKey(name, id));
59
+ if (result) {
60
+ const widgetData = new type(name, id);
61
+ widgetData.parseJSON(JSON.parse(result));
62
+ return widgetData;
63
+ }
64
+ return undefined;
65
+ }
66
+ static getKey(name, id) {
67
+ return `${name}@${id}`;
68
+ }
69
+ }
70
+ exports.WidgetDataRepository = WidgetDataRepository;
71
+ WidgetDataRepository.stores = new Map();
@@ -1,144 +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;
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;
@@ -1,84 +1,84 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- 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;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ 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;
@@ -1,24 +1,24 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ElectronUtils = void 0;
4
- class ElectronUtils {
5
- static hasElectronApi() {
6
- return this.getAPI() != null;
7
- }
8
- /**
9
- * 获取ElectronAPI
10
- * windows api
11
- */
12
- static getAPI() {
13
- if (Reflect.has(window, "electronAPI")) {
14
- //@ts-ignore
15
- return window.electronAPI;
16
- }
17
- else if (Reflect.has(window.parent, "electronAPI")) {
18
- //@ts-ignore
19
- return window.parent.electronAPI;
20
- }
21
- return null;
22
- }
23
- }
24
- exports.ElectronUtils = ElectronUtils;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ElectronUtils = void 0;
4
+ class ElectronUtils {
5
+ static hasElectronApi() {
6
+ return this.getAPI() != null;
7
+ }
8
+ /**
9
+ * 获取ElectronAPI
10
+ * windows api
11
+ */
12
+ static getAPI() {
13
+ if (Reflect.has(window, "electronAPI")) {
14
+ //@ts-ignore
15
+ return window.electronAPI;
16
+ }
17
+ else if (Reflect.has(window.parent, "electronAPI")) {
18
+ //@ts-ignore
19
+ return window.parent.electronAPI;
20
+ }
21
+ return null;
22
+ }
23
+ }
24
+ exports.ElectronUtils = ElectronUtils;
@@ -1,4 +1,4 @@
1
- export class ApiConstants {
2
- }
3
- ApiConstants.CONFIG_LAUNCH_AT_STARTUP = "CONFIG_LAUNCH_AT_STARTUP";
4
- ApiConstants.CONFIG_WIDGET_TITLE_COLOR = "CONFIG_WIDGET_TITLE_COLOR";
1
+ export class ApiConstants {
2
+ }
3
+ ApiConstants.CONFIG_LAUNCH_AT_STARTUP = "CONFIG_LAUNCH_AT_STARTUP";
4
+ ApiConstants.CONFIG_WIDGET_TITLE_COLOR = "CONFIG_WIDGET_TITLE_COLOR";