@widget-js/core 0.7.6 → 0.7.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.
- package/dist/index.cjs +39 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +49 -13
- package/dist/index.js +39 -5
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -82,14 +82,26 @@ interface IWindowSize {
|
|
|
82
82
|
minWidth?: number;
|
|
83
83
|
minHeight?: number;
|
|
84
84
|
}
|
|
85
|
-
interface
|
|
85
|
+
interface IPageOptions extends IWindowSize {
|
|
86
86
|
name: string;
|
|
87
|
+
/**
|
|
88
|
+
* 当showInSearch为true时,此项必填
|
|
89
|
+
*/
|
|
87
90
|
title: LanguageTextMap;
|
|
88
|
-
|
|
89
|
-
|
|
91
|
+
/**
|
|
92
|
+
* 当showInSearch为true时,此项必填
|
|
93
|
+
*/
|
|
94
|
+
description?: LanguageTextMap;
|
|
95
|
+
/**
|
|
96
|
+
* 当showInSearch为true时,此项必填
|
|
97
|
+
*/
|
|
98
|
+
keywords?: WidgetKeyword[];
|
|
90
99
|
lang: LanguageCode;
|
|
91
100
|
packageName?: string;
|
|
92
|
-
|
|
101
|
+
/**
|
|
102
|
+
* 当showInSearch为true时,此项必填
|
|
103
|
+
*/
|
|
104
|
+
previewImage?: string;
|
|
93
105
|
/**
|
|
94
106
|
* 是否在搜索中显示
|
|
95
107
|
*/
|
|
@@ -100,6 +112,7 @@ interface IWindowOptions extends IWindowSize {
|
|
|
100
112
|
movable?: boolean;
|
|
101
113
|
resizable?: boolean;
|
|
102
114
|
backgroundThrottling?: boolean;
|
|
115
|
+
security?: boolean;
|
|
103
116
|
path: string;
|
|
104
117
|
/**
|
|
105
118
|
* 是否只能添加一次
|
|
@@ -142,7 +155,7 @@ interface IPage {
|
|
|
142
155
|
/**
|
|
143
156
|
* 预览图片,可以是GIF
|
|
144
157
|
*/
|
|
145
|
-
readonly previewImage
|
|
158
|
+
readonly previewImage?: string;
|
|
146
159
|
}
|
|
147
160
|
declare class Page implements IPage {
|
|
148
161
|
readonly name: string;
|
|
@@ -156,6 +169,7 @@ declare class Page implements IPage {
|
|
|
156
169
|
*/
|
|
157
170
|
readonly description: LanguageTextMap;
|
|
158
171
|
readonly keywords: WidgetKeyword[];
|
|
172
|
+
readonly security: boolean;
|
|
159
173
|
/**
|
|
160
174
|
* 组件默认语言
|
|
161
175
|
*/
|
|
@@ -178,8 +192,8 @@ declare class Page implements IPage {
|
|
|
178
192
|
/**
|
|
179
193
|
* 预览图片,可以是GIF
|
|
180
194
|
*/
|
|
181
|
-
readonly previewImage
|
|
182
|
-
constructor(options:
|
|
195
|
+
readonly previewImage?: string;
|
|
196
|
+
constructor(options: IPageOptions);
|
|
183
197
|
/**
|
|
184
198
|
* 获取组件标题
|
|
185
199
|
* @param lang 语言环境,不传则获取默认语言
|
|
@@ -195,11 +209,15 @@ declare class Page implements IPage {
|
|
|
195
209
|
isResizable(): boolean;
|
|
196
210
|
}
|
|
197
211
|
|
|
198
|
-
interface IWidgetOptions extends IWindowSize,
|
|
212
|
+
interface IWidgetOptions extends IWindowSize, IPageOptions {
|
|
199
213
|
supportDeployMode?: DeployMode;
|
|
200
214
|
configPagePath?: string;
|
|
215
|
+
previewImage: string;
|
|
216
|
+
description: LanguageTextMap;
|
|
217
|
+
keywords: WidgetKeyword[];
|
|
201
218
|
}
|
|
202
219
|
declare class Widget extends Page {
|
|
220
|
+
readonly previewImage: string;
|
|
203
221
|
readonly supportDeployMode: number;
|
|
204
222
|
/**
|
|
205
223
|
* 配置页面路径,没有则不能修改
|
|
@@ -217,6 +235,7 @@ declare class Widget extends Page {
|
|
|
217
235
|
* 是否支持普通模式
|
|
218
236
|
*/
|
|
219
237
|
isSupportNormal(): boolean;
|
|
238
|
+
isConfigurable(): boolean;
|
|
220
239
|
}
|
|
221
240
|
declare enum WidgetKeyword {
|
|
222
241
|
RECOMMEND = "recommend",
|
|
@@ -434,6 +453,7 @@ interface IWidgetApi {
|
|
|
434
453
|
getWidgetUrl(widgetName: string, widgetParams: WidgetParams): Promise<string | null>;
|
|
435
454
|
getWidgetPackageIndexUrl(packageName: string, hash?: boolean): Promise<string | null>;
|
|
436
455
|
getWidgetConfigUrl(widgetName: string, widgetParams: WidgetParams): Promise<string | null>;
|
|
456
|
+
openConfigPage(id: string): Promise<void>;
|
|
437
457
|
getWidgetPackageUrl(packageName: string): Promise<string | null>;
|
|
438
458
|
}
|
|
439
459
|
type WidgetApiMethods = keyof IWidgetApi;
|
|
@@ -446,6 +466,7 @@ declare class WidgetApiImpl extends BaseApi<WidgetApiMethods> implements IWidget
|
|
|
446
466
|
registerWidgets(widgets: Widget[]): Promise<any>;
|
|
447
467
|
registerWidgetPackage(widgetPackage: WidgetPackage): Promise<any>;
|
|
448
468
|
getWidgets(): Promise<Widget[]>;
|
|
469
|
+
openConfigPage(widgetId: string): Promise<any>;
|
|
449
470
|
getWidgetPackages(): Promise<WidgetPackage[]>;
|
|
450
471
|
/**
|
|
451
472
|
*
|
|
@@ -480,7 +501,8 @@ interface IAppApi {
|
|
|
480
501
|
type AppApiMethods = keyof IAppApi;
|
|
481
502
|
declare enum AppApiEvent {
|
|
482
503
|
CONFIG_CHANGED = "event::cn.widgetjs.core.app.config.changed",
|
|
483
|
-
MOVING_GRID_WINDOW = "event::cn.widgetjs.core.app.moving.grid.window"
|
|
504
|
+
MOVING_GRID_WINDOW = "event::cn.widgetjs.core.app.moving.grid.window",
|
|
505
|
+
STOP_MOVING_GRID_WINDOW = "event::cn.widgetjs.core.app.moving.grid.window.stop"
|
|
484
506
|
}
|
|
485
507
|
declare enum AppApiConstants {
|
|
486
508
|
CONFIG_GRID_CELL_SIZE = "cn.widgetjs.config.grid.size"
|
|
@@ -495,7 +517,7 @@ interface BroadcastEventOptions {
|
|
|
495
517
|
sender?: string;
|
|
496
518
|
/**
|
|
497
519
|
* 广播事件携带的数据,只支持部分数据类型。
|
|
498
|
-
*
|
|
520
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm
|
|
499
521
|
*/
|
|
500
522
|
payload?: any;
|
|
501
523
|
}
|
|
@@ -1159,6 +1181,18 @@ declare enum BrowserWindowApiEvent {
|
|
|
1159
1181
|
RESIZED = "event::cn.widgetjs.core.browser-window.resized",
|
|
1160
1182
|
CANCEL_SNAP_TO_EDGE = "event::cn.widgetjs.core.browser-window.cancel_snap_to_edge"
|
|
1161
1183
|
}
|
|
1184
|
+
interface SetupOptions {
|
|
1185
|
+
width: number;
|
|
1186
|
+
height: number;
|
|
1187
|
+
minWidth?: number;
|
|
1188
|
+
minHeight?: number;
|
|
1189
|
+
maxWidth?: number;
|
|
1190
|
+
maxHeight?: number;
|
|
1191
|
+
resizable?: boolean;
|
|
1192
|
+
movable?: boolean;
|
|
1193
|
+
center?: boolean;
|
|
1194
|
+
alwaysOnTop?: boolean;
|
|
1195
|
+
}
|
|
1162
1196
|
declare class BrowserWindowApiImpl extends BaseApi<BrowserWindowApiMethods> implements IBrowserWindowApi {
|
|
1163
1197
|
getChannel(): string;
|
|
1164
1198
|
setIgnoreMouseEvent(ignore: boolean): Promise<void>;
|
|
@@ -1207,6 +1241,7 @@ declare class BrowserWindowApiImpl extends BaseApi<BrowserWindowApiMethods> impl
|
|
|
1207
1241
|
getMinimumSize(): Promise<number[]>;
|
|
1208
1242
|
close(): Promise<void>;
|
|
1209
1243
|
setZoomFactor(factor: number): Promise<void>;
|
|
1244
|
+
setup(options: SetupOptions): Promise<void>;
|
|
1210
1245
|
}
|
|
1211
1246
|
declare const BrowserWindowApi: BrowserWindowApiImpl;
|
|
1212
1247
|
|
|
@@ -1251,7 +1286,7 @@ interface IDeployedWidgetApi {
|
|
|
1251
1286
|
removeDeployedWidgetByName(name: string): Promise<DeployedWidget[]>;
|
|
1252
1287
|
getDeployedWidgets(): Promise<DeployedWidget[]>;
|
|
1253
1288
|
openDevTools(id: string): Promise<void>;
|
|
1254
|
-
|
|
1289
|
+
openConfigPage(id: string): Promise<void>;
|
|
1255
1290
|
registerActiveShortcut(id: string, shortcut: string): Promise<boolean>;
|
|
1256
1291
|
setProxy(id: string, proxy: string): Promise<boolean>;
|
|
1257
1292
|
getDeployedWidget(id: string): Promise<DeployedWidget>;
|
|
@@ -1284,7 +1319,7 @@ declare class DeployedWidgetApiImpl extends BaseApi<DeployedWidgetApiMethods> im
|
|
|
1284
1319
|
* @return {Promise} A Promise that resolves when the dev tools are opened.
|
|
1285
1320
|
*/
|
|
1286
1321
|
openDevTools(widgetId: string): Promise<any>;
|
|
1287
|
-
|
|
1322
|
+
openConfigPage(widgetId: string, params?: WidgetParams): Promise<any>;
|
|
1288
1323
|
/**
|
|
1289
1324
|
* 注册激活、呼出、置顶组件快捷键
|
|
1290
1325
|
* @param widgetId 组件id
|
|
@@ -1381,6 +1416,7 @@ interface ILogApi {
|
|
|
1381
1416
|
error(...data: any[]): void;
|
|
1382
1417
|
warn(...data: any[]): void;
|
|
1383
1418
|
log(...data: any[]): void;
|
|
1419
|
+
json(data: any): void;
|
|
1384
1420
|
}
|
|
1385
1421
|
type LogApiMethods = keyof ILogApi;
|
|
1386
1422
|
declare const LogApi: ILogApi;
|
|
@@ -1397,4 +1433,4 @@ interface IFileApi {
|
|
|
1397
1433
|
type FileApiMethods = keyof IFileApi;
|
|
1398
1434
|
declare const FileApi: IFileApi;
|
|
1399
1435
|
|
|
1400
|
-
export { AlignPosition, ApiConstants, AppApi, AppApiConstants, AppApiEvent, AppApiMethods, AppMouseEvent, AppNotification, BaseApi, BroadcastApi, BroadcastApiMethods, BroadcastEvent, BroadcastEventType, BrowserWindowApi, BrowserWindowApiEvent, BrowserWindowApiMethods, Channel, ClipboardApi, ClipboardApiEvent, ClipboardApiMethods, DeployMode, DeployedPage, DeployedWidget, DeployedWidgetApi, DeployedWidgetApiMethods, DevOptions, DeviceApi, DeviceApiMethods, DialogApi, DialogApiMethods, ElectronApi, ElectronUtils, FileApi, FileApiMethods, Gravity, GridRect, GridSystem, HostedMode, IGridRect, IPage, IWidgetDataApi, IWidgetOptions,
|
|
1436
|
+
export { AlignPosition, ApiConstants, AppApi, AppApiConstants, AppApiEvent, AppApiMethods, AppMouseEvent, AppNotification, BaseApi, BroadcastApi, BroadcastApiMethods, BroadcastEvent, BroadcastEventType, BrowserWindowApi, BrowserWindowApiEvent, BrowserWindowApiMethods, Channel, ClipboardApi, ClipboardApiEvent, ClipboardApiMethods, DeployMode, DeployedPage, DeployedWidget, DeployedWidgetApi, DeployedWidgetApiMethods, DevOptions, DeviceApi, DeviceApiMethods, DialogApi, DialogApiMethods, ElectronApi, ElectronUtils, FileApi, FileApiMethods, Gravity, GridRect, GridSystem, HostedMode, IGridRect, IPage, IPageOptions, IWidgetDataApi, IWidgetOptions, IWindowSize, LanguageCode, LanguageTextMap, LocalPackageUrlInfo, LocationQuery, LocationQueryRaw, LocationQueryValue, LocationQueryValueRaw, LogApi, LogApiMethods, MetaInfo, NativeKeyboardEvent, NormalizeOptions, NotificationApi, NotificationApiEvent, NotificationApiMethods, NotificationOption, NotificationSize, NotificationType, OpenUrlOptions, Page, Point, Position, ReadDirOptions, Rectangle, RemotePackageUrlInfo, SaveWidgetOption, SetPositionOptions, ShortcutApi, ShortcutApiEvent, ShortcutApiMethods, StoreApi, StoreApiMethods, ThemeMode, WebSocketEvent, WebSocketEventType, Widget, WidgetApi, WidgetApiEvent, WidgetApiMethods, WidgetData, WidgetDataApi, WidgetDataApiMethods, WidgetKeyword, WidgetPackage, WidgetPackageOptions, WidgetParams, WidgetPermission, WidgetUrlUtils, normalizeUrl, parseQuery, stringifyQuery };
|
package/dist/index.js
CHANGED
|
@@ -64,6 +64,7 @@ var Page = class {
|
|
|
64
64
|
*/
|
|
65
65
|
description;
|
|
66
66
|
keywords;
|
|
67
|
+
security;
|
|
67
68
|
/**
|
|
68
69
|
* 组件默认语言
|
|
69
70
|
*/
|
|
@@ -88,8 +89,8 @@ var Page = class {
|
|
|
88
89
|
constructor(options) {
|
|
89
90
|
this.name = options.name;
|
|
90
91
|
this.title = options.title;
|
|
91
|
-
this.description = options.description;
|
|
92
|
-
this.keywords = options.keywords;
|
|
92
|
+
this.description = options.description ?? {};
|
|
93
|
+
this.keywords = options.keywords ?? [];
|
|
93
94
|
this.lang = options.lang;
|
|
94
95
|
this.width = options.width;
|
|
95
96
|
this.height = options.height;
|
|
@@ -105,6 +106,7 @@ var Page = class {
|
|
|
105
106
|
this.previewImage = options.previewImage;
|
|
106
107
|
this.path = options.path;
|
|
107
108
|
this.meta = options.meta ?? {};
|
|
109
|
+
this.security = options.security ?? false;
|
|
108
110
|
}
|
|
109
111
|
/**
|
|
110
112
|
* 获取组件标题
|
|
@@ -118,6 +120,8 @@ var Page = class {
|
|
|
118
120
|
* @param lang 语言环境,不传则获取默认标题
|
|
119
121
|
*/
|
|
120
122
|
getDescription(lang) {
|
|
123
|
+
if (this.description == void 0)
|
|
124
|
+
return void 0;
|
|
121
125
|
return getTextByLanguageCode(this.description, lang);
|
|
122
126
|
}
|
|
123
127
|
static parseJSON(json) {
|
|
@@ -190,6 +194,9 @@ var Widget = class extends Page {
|
|
|
190
194
|
isSupportNormal() {
|
|
191
195
|
return (this.supportDeployMode & 1 /* NORMAL */) > 0;
|
|
192
196
|
}
|
|
197
|
+
isConfigurable() {
|
|
198
|
+
return this.configPagePath != null && this.configPagePath != "";
|
|
199
|
+
}
|
|
193
200
|
};
|
|
194
201
|
var WidgetKeyword = /* @__PURE__ */ ((WidgetKeyword2) => {
|
|
195
202
|
WidgetKeyword2["RECOMMEND"] = "recommend";
|
|
@@ -1197,6 +1204,9 @@ var WidgetApiImpl = class extends BaseApi {
|
|
|
1197
1204
|
}
|
|
1198
1205
|
return widgets;
|
|
1199
1206
|
}
|
|
1207
|
+
async openConfigPage(widgetId) {
|
|
1208
|
+
return this.invokeMethod("openConfigPage", widgetId);
|
|
1209
|
+
}
|
|
1200
1210
|
async getWidgetPackages() {
|
|
1201
1211
|
return await this.invokeMethod("getWidgetPackages");
|
|
1202
1212
|
}
|
|
@@ -1515,6 +1525,25 @@ var BrowserWindowApiImpl = class extends BaseApi {
|
|
|
1515
1525
|
setZoomFactor(factor) {
|
|
1516
1526
|
return this.invokeMethod("setZoomFactor", factor);
|
|
1517
1527
|
}
|
|
1528
|
+
async setup(options) {
|
|
1529
|
+
if (options.alwaysOnTop) {
|
|
1530
|
+
await this.setAlwaysOnTop(true);
|
|
1531
|
+
}
|
|
1532
|
+
if (options.center) {
|
|
1533
|
+
await this.center();
|
|
1534
|
+
}
|
|
1535
|
+
await this.setResizable(!!options.resizable);
|
|
1536
|
+
await this.setMovable(!!options.movable);
|
|
1537
|
+
if (options.width && options.height) {
|
|
1538
|
+
await this.setSize(options.width, options.height);
|
|
1539
|
+
}
|
|
1540
|
+
if (options.minWidth && options.minHeight) {
|
|
1541
|
+
await this.setMinimumSize(options.minWidth, options.minHeight);
|
|
1542
|
+
}
|
|
1543
|
+
if (options.maxWidth && options.maxHeight) {
|
|
1544
|
+
await this.setMaximumSize(options.maxWidth, options.maxHeight);
|
|
1545
|
+
}
|
|
1546
|
+
}
|
|
1518
1547
|
};
|
|
1519
1548
|
var BrowserWindowApi = new BrowserWindowApiImpl();
|
|
1520
1549
|
|
|
@@ -1629,7 +1658,7 @@ var NotificationApiImpl = class extends BaseApi {
|
|
|
1629
1658
|
};
|
|
1630
1659
|
var NotificationApi = new NotificationApiImpl();
|
|
1631
1660
|
|
|
1632
|
-
// src/api/
|
|
1661
|
+
// src/api/DeployedWidgetApi.ts
|
|
1633
1662
|
var DeployedWidgetApiImpl = class extends BaseApi {
|
|
1634
1663
|
getChannel() {
|
|
1635
1664
|
return "channel::cn.widgetjs.core.hosted_widget" /* HOSTED_WIDGET */;
|
|
@@ -1670,8 +1699,8 @@ var DeployedWidgetApiImpl = class extends BaseApi {
|
|
|
1670
1699
|
async openDevTools(widgetId) {
|
|
1671
1700
|
return this.invokeMethod("openDevTools", widgetId);
|
|
1672
1701
|
}
|
|
1673
|
-
async
|
|
1674
|
-
return this.invokeMethod("
|
|
1702
|
+
async openConfigPage(widgetId, params) {
|
|
1703
|
+
return this.invokeMethod("openConfigPage", widgetId, params);
|
|
1675
1704
|
}
|
|
1676
1705
|
/**
|
|
1677
1706
|
* 注册激活、呼出、置顶组件快捷键
|
|
@@ -1757,6 +1786,7 @@ var ShortcutApi = new ShortcutApiImpl();
|
|
|
1757
1786
|
var AppApiEvent = /* @__PURE__ */ ((AppApiEvent2) => {
|
|
1758
1787
|
AppApiEvent2["CONFIG_CHANGED"] = "event::cn.widgetjs.core.app.config.changed";
|
|
1759
1788
|
AppApiEvent2["MOVING_GRID_WINDOW"] = "event::cn.widgetjs.core.app.moving.grid.window";
|
|
1789
|
+
AppApiEvent2["STOP_MOVING_GRID_WINDOW"] = "event::cn.widgetjs.core.app.moving.grid.window.stop";
|
|
1760
1790
|
return AppApiEvent2;
|
|
1761
1791
|
})(AppApiEvent || {});
|
|
1762
1792
|
var AppApiConstants = /* @__PURE__ */ ((AppApiConstants2) => {
|
|
@@ -1877,6 +1907,10 @@ var LogApiImpl = class extends BaseApi {
|
|
|
1877
1907
|
console.log(...data);
|
|
1878
1908
|
this.invokeMethod("log", ...data);
|
|
1879
1909
|
}
|
|
1910
|
+
json(data) {
|
|
1911
|
+
const json = JSON.stringify(data, null, 2);
|
|
1912
|
+
this.invokeMethod("info", json);
|
|
1913
|
+
}
|
|
1880
1914
|
};
|
|
1881
1915
|
var LogApi = new LogApiImpl();
|
|
1882
1916
|
|