@widget-js/core 0.7.5 → 0.7.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/index.d.ts CHANGED
@@ -82,14 +82,26 @@ interface IWindowSize {
82
82
  minWidth?: number;
83
83
  minHeight?: number;
84
84
  }
85
- interface IWindowOptions extends IWindowSize {
85
+ interface IPageOptions extends IWindowSize {
86
86
  name: string;
87
+ /**
88
+ * 当showInSearch为true时,此项必填
89
+ */
87
90
  title: LanguageTextMap;
88
- description: LanguageTextMap;
89
- keywords: WidgetKeyword[];
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
- previewImage: string;
101
+ /**
102
+ * 当showInSearch为true时,此项必填
103
+ */
104
+ previewImage?: string;
93
105
  /**
94
106
  * 是否在搜索中显示
95
107
  */
@@ -142,7 +154,7 @@ interface IPage {
142
154
  /**
143
155
  * 预览图片,可以是GIF
144
156
  */
145
- readonly previewImage: string;
157
+ readonly previewImage?: string;
146
158
  }
147
159
  declare class Page implements IPage {
148
160
  readonly name: string;
@@ -178,8 +190,8 @@ declare class Page implements IPage {
178
190
  /**
179
191
  * 预览图片,可以是GIF
180
192
  */
181
- readonly previewImage: string;
182
- constructor(options: IWindowOptions);
193
+ readonly previewImage?: string;
194
+ constructor(options: IPageOptions);
183
195
  /**
184
196
  * 获取组件标题
185
197
  * @param lang 语言环境,不传则获取默认语言
@@ -195,11 +207,15 @@ declare class Page implements IPage {
195
207
  isResizable(): boolean;
196
208
  }
197
209
 
198
- interface IWidgetOptions extends IWindowSize, IWindowOptions {
210
+ interface IWidgetOptions extends IWindowSize, IPageOptions {
199
211
  supportDeployMode?: DeployMode;
200
212
  configPagePath?: string;
213
+ previewImage: string;
214
+ description: LanguageTextMap;
215
+ keywords: WidgetKeyword[];
201
216
  }
202
217
  declare class Widget extends Page {
218
+ readonly previewImage: string;
203
219
  readonly supportDeployMode: number;
204
220
  /**
205
221
  * 配置页面路径,没有则不能修改
@@ -217,6 +233,7 @@ declare class Widget extends Page {
217
233
  * 是否支持普通模式
218
234
  */
219
235
  isSupportNormal(): boolean;
236
+ isConfigurable(): boolean;
220
237
  }
221
238
  declare enum WidgetKeyword {
222
239
  RECOMMEND = "recommend",
@@ -434,6 +451,7 @@ interface IWidgetApi {
434
451
  getWidgetUrl(widgetName: string, widgetParams: WidgetParams): Promise<string | null>;
435
452
  getWidgetPackageIndexUrl(packageName: string, hash?: boolean): Promise<string | null>;
436
453
  getWidgetConfigUrl(widgetName: string, widgetParams: WidgetParams): Promise<string | null>;
454
+ openConfigPage(id: string): Promise<void>;
437
455
  getWidgetPackageUrl(packageName: string): Promise<string | null>;
438
456
  }
439
457
  type WidgetApiMethods = keyof IWidgetApi;
@@ -446,6 +464,7 @@ declare class WidgetApiImpl extends BaseApi<WidgetApiMethods> implements IWidget
446
464
  registerWidgets(widgets: Widget[]): Promise<any>;
447
465
  registerWidgetPackage(widgetPackage: WidgetPackage): Promise<any>;
448
466
  getWidgets(): Promise<Widget[]>;
467
+ openConfigPage(widgetId: string): Promise<any>;
449
468
  getWidgetPackages(): Promise<WidgetPackage[]>;
450
469
  /**
451
470
  *
@@ -480,7 +499,8 @@ interface IAppApi {
480
499
  type AppApiMethods = keyof IAppApi;
481
500
  declare enum AppApiEvent {
482
501
  CONFIG_CHANGED = "event::cn.widgetjs.core.app.config.changed",
483
- MOVING_GRID_WINDOW = "event::cn.widgetjs.core.app.moving.grid.window"
502
+ MOVING_GRID_WINDOW = "event::cn.widgetjs.core.app.moving.grid.window",
503
+ STOP_MOVING_GRID_WINDOW = "event::cn.widgetjs.core.app.moving.grid.window.stop"
484
504
  }
485
505
  declare enum AppApiConstants {
486
506
  CONFIG_GRID_CELL_SIZE = "cn.widgetjs.config.grid.size"
@@ -495,7 +515,7 @@ interface BroadcastEventOptions {
495
515
  sender?: string;
496
516
  /**
497
517
  * 广播事件携带的数据,只支持部分数据类型。
498
- * 情见:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm
518
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm
499
519
  */
500
520
  payload?: any;
501
521
  }
@@ -1134,6 +1154,7 @@ interface IBrowserWindowApi {
1134
1154
  setMaximumSize(width: number, height: number): Promise<void>;
1135
1155
  setMinimumSize(width: number, height: number): Promise<void>;
1136
1156
  setZoomLevel(level: number): Promise<void>;
1157
+ setZoomFactor(factor: number): Promise<void>;
1137
1158
  isFocused(): Promise<boolean>;
1138
1159
  }
1139
1160
  type BrowserWindowApiMethods = keyof IBrowserWindowApi;
@@ -1158,6 +1179,18 @@ declare enum BrowserWindowApiEvent {
1158
1179
  RESIZED = "event::cn.widgetjs.core.browser-window.resized",
1159
1180
  CANCEL_SNAP_TO_EDGE = "event::cn.widgetjs.core.browser-window.cancel_snap_to_edge"
1160
1181
  }
1182
+ interface SetupOptions {
1183
+ width: number;
1184
+ height: number;
1185
+ minWidth?: number;
1186
+ minHeight?: number;
1187
+ maxWidth?: number;
1188
+ maxHeight?: number;
1189
+ resizable?: boolean;
1190
+ movable?: boolean;
1191
+ center?: boolean;
1192
+ alwaysOnTop?: boolean;
1193
+ }
1161
1194
  declare class BrowserWindowApiImpl extends BaseApi<BrowserWindowApiMethods> implements IBrowserWindowApi {
1162
1195
  getChannel(): string;
1163
1196
  setIgnoreMouseEvent(ignore: boolean): Promise<void>;
@@ -1205,6 +1238,8 @@ declare class BrowserWindowApiImpl extends BaseApi<BrowserWindowApiMethods> impl
1205
1238
  setMinimumSize(width: number, height: number): Promise<void>;
1206
1239
  getMinimumSize(): Promise<number[]>;
1207
1240
  close(): Promise<void>;
1241
+ setZoomFactor(factor: number): Promise<void>;
1242
+ setup(options: SetupOptions): Promise<void>;
1208
1243
  }
1209
1244
  declare const BrowserWindowApi: BrowserWindowApiImpl;
1210
1245
 
@@ -1249,7 +1284,7 @@ interface IDeployedWidgetApi {
1249
1284
  removeDeployedWidgetByName(name: string): Promise<DeployedWidget[]>;
1250
1285
  getDeployedWidgets(): Promise<DeployedWidget[]>;
1251
1286
  openDevTools(id: string): Promise<void>;
1252
- openConfigRoute(id: string): Promise<void>;
1287
+ openConfigPage(id: string): Promise<void>;
1253
1288
  registerActiveShortcut(id: string, shortcut: string): Promise<boolean>;
1254
1289
  setProxy(id: string, proxy: string): Promise<boolean>;
1255
1290
  getDeployedWidget(id: string): Promise<DeployedWidget>;
@@ -1282,7 +1317,7 @@ declare class DeployedWidgetApiImpl extends BaseApi<DeployedWidgetApiMethods> im
1282
1317
  * @return {Promise} A Promise that resolves when the dev tools are opened.
1283
1318
  */
1284
1319
  openDevTools(widgetId: string): Promise<any>;
1285
- openConfigRoute(widgetId: string, params?: WidgetParams): Promise<any>;
1320
+ openConfigPage(widgetId: string, params?: WidgetParams): Promise<any>;
1286
1321
  /**
1287
1322
  * 注册激活、呼出、置顶组件快捷键
1288
1323
  * @param widgetId 组件id
@@ -1395,4 +1430,4 @@ interface IFileApi {
1395
1430
  type FileApiMethods = keyof IFileApi;
1396
1431
  declare const FileApi: IFileApi;
1397
1432
 
1398
- 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, IWindowOptions, 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 };
1433
+ 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
@@ -88,8 +88,8 @@ var Page = class {
88
88
  constructor(options) {
89
89
  this.name = options.name;
90
90
  this.title = options.title;
91
- this.description = options.description;
92
- this.keywords = options.keywords;
91
+ this.description = options.description ?? {};
92
+ this.keywords = options.keywords ?? [];
93
93
  this.lang = options.lang;
94
94
  this.width = options.width;
95
95
  this.height = options.height;
@@ -118,6 +118,8 @@ var Page = class {
118
118
  * @param lang 语言环境,不传则获取默认标题
119
119
  */
120
120
  getDescription(lang) {
121
+ if (this.description == void 0)
122
+ return void 0;
121
123
  return getTextByLanguageCode(this.description, lang);
122
124
  }
123
125
  static parseJSON(json) {
@@ -190,6 +192,9 @@ var Widget = class extends Page {
190
192
  isSupportNormal() {
191
193
  return (this.supportDeployMode & 1 /* NORMAL */) > 0;
192
194
  }
195
+ isConfigurable() {
196
+ return this.configPagePath != null && this.configPagePath != "";
197
+ }
193
198
  };
194
199
  var WidgetKeyword = /* @__PURE__ */ ((WidgetKeyword2) => {
195
200
  WidgetKeyword2["RECOMMEND"] = "recommend";
@@ -1197,6 +1202,9 @@ var WidgetApiImpl = class extends BaseApi {
1197
1202
  }
1198
1203
  return widgets;
1199
1204
  }
1205
+ async openConfigPage(widgetId) {
1206
+ return this.invokeMethod("openConfigPage", widgetId);
1207
+ }
1200
1208
  async getWidgetPackages() {
1201
1209
  return await this.invokeMethod("getWidgetPackages");
1202
1210
  }
@@ -1512,6 +1520,28 @@ var BrowserWindowApiImpl = class extends BaseApi {
1512
1520
  close() {
1513
1521
  return this.invokeMethod("close");
1514
1522
  }
1523
+ setZoomFactor(factor) {
1524
+ return this.invokeMethod("setZoomFactor", factor);
1525
+ }
1526
+ async setup(options) {
1527
+ if (options.alwaysOnTop) {
1528
+ await this.setAlwaysOnTop(true);
1529
+ }
1530
+ if (options.center) {
1531
+ await this.center();
1532
+ }
1533
+ await this.setResizable(!!options.resizable);
1534
+ await this.setMovable(!!options.movable);
1535
+ if (options.width && options.height) {
1536
+ await this.setSize(options.width, options.height);
1537
+ }
1538
+ if (options.minWidth && options.minHeight) {
1539
+ await this.setMinimumSize(options.minWidth, options.minHeight);
1540
+ }
1541
+ if (options.maxWidth && options.maxHeight) {
1542
+ await this.setMaximumSize(options.maxWidth, options.maxHeight);
1543
+ }
1544
+ }
1515
1545
  };
1516
1546
  var BrowserWindowApi = new BrowserWindowApiImpl();
1517
1547
 
@@ -1626,7 +1656,7 @@ var NotificationApiImpl = class extends BaseApi {
1626
1656
  };
1627
1657
  var NotificationApi = new NotificationApiImpl();
1628
1658
 
1629
- // src/api/HostedWidgetApi.ts
1659
+ // src/api/DeployedWidgetApi.ts
1630
1660
  var DeployedWidgetApiImpl = class extends BaseApi {
1631
1661
  getChannel() {
1632
1662
  return "channel::cn.widgetjs.core.hosted_widget" /* HOSTED_WIDGET */;
@@ -1667,8 +1697,8 @@ var DeployedWidgetApiImpl = class extends BaseApi {
1667
1697
  async openDevTools(widgetId) {
1668
1698
  return this.invokeMethod("openDevTools", widgetId);
1669
1699
  }
1670
- async openConfigRoute(widgetId, params) {
1671
- return this.invokeMethod("openConfigRoute", widgetId, params);
1700
+ async openConfigPage(widgetId, params) {
1701
+ return this.invokeMethod("openConfigPage", widgetId, params);
1672
1702
  }
1673
1703
  /**
1674
1704
  * 注册激活、呼出、置顶组件快捷键
@@ -1754,6 +1784,7 @@ var ShortcutApi = new ShortcutApiImpl();
1754
1784
  var AppApiEvent = /* @__PURE__ */ ((AppApiEvent2) => {
1755
1785
  AppApiEvent2["CONFIG_CHANGED"] = "event::cn.widgetjs.core.app.config.changed";
1756
1786
  AppApiEvent2["MOVING_GRID_WINDOW"] = "event::cn.widgetjs.core.app.moving.grid.window";
1787
+ AppApiEvent2["STOP_MOVING_GRID_WINDOW"] = "event::cn.widgetjs.core.app.moving.grid.window.stop";
1757
1788
  return AppApiEvent2;
1758
1789
  })(AppApiEvent || {});
1759
1790
  var AppApiConstants = /* @__PURE__ */ ((AppApiConstants2) => {