@widget-js/core 0.1.31 → 0.5.12

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 (71) hide show
  1. package/dist/cjs/api/AppApi.js +24 -21
  2. package/dist/cjs/api/BaseApi.js +13 -0
  3. package/dist/cjs/api/BroadcastApi.js +14 -13
  4. package/dist/cjs/api/BrowserWindowApi.js +55 -72
  5. package/dist/cjs/api/Channel.js +1 -1
  6. package/dist/cjs/api/ClipboardApi.js +16 -11
  7. package/dist/cjs/api/DeviceApi.js +12 -9
  8. package/dist/cjs/api/DialogApi.js +8 -6
  9. package/dist/cjs/api/HostedWidgetApi.js +27 -36
  10. package/dist/cjs/api/LogApi.js +14 -10
  11. package/dist/cjs/api/NotificationApi.js +52 -74
  12. package/dist/cjs/api/ShortcutApi.js +23 -0
  13. package/dist/cjs/api/WidgetApi.js +29 -69
  14. package/dist/cjs/{repository/WidgetDataRepository.js → api/WidgetDataApi.js} +19 -10
  15. package/dist/cjs/index.js +3 -2
  16. package/dist/cjs/lang/LanguageCode.js +34 -0
  17. package/dist/cjs/model/Widget.js +4 -4
  18. package/dist/cjs/model/WidgetPackage.js +49 -2
  19. package/dist/cjs/model/event/BroadcastEvent.js +4 -8
  20. package/dist/cjs/model/msic/graphics.js +2 -0
  21. package/dist/cjs/utils/ElectronUtils.js +5 -1
  22. package/dist/cjs/utils/LanguageUtils.js +36 -0
  23. package/dist/esm/api/AppApi.js +23 -20
  24. package/dist/esm/api/BaseApi.js +9 -0
  25. package/dist/esm/api/BroadcastApi.js +13 -12
  26. package/dist/esm/api/BrowserWindowApi.js +53 -71
  27. package/dist/esm/api/Channel.js +1 -1
  28. package/dist/esm/api/ClipboardApi.js +15 -10
  29. package/dist/esm/api/DeviceApi.js +11 -8
  30. package/dist/esm/api/DialogApi.js +9 -6
  31. package/dist/esm/api/HostedWidgetApi.js +26 -35
  32. package/dist/esm/api/LogApi.js +15 -10
  33. package/dist/esm/api/NotificationApi.js +51 -73
  34. package/dist/esm/api/ShortcutApi.js +19 -0
  35. package/dist/esm/api/WidgetApi.js +28 -65
  36. package/dist/esm/{repository/WidgetDataRepository.js → api/WidgetDataApi.js} +17 -8
  37. package/dist/esm/index.js +3 -2
  38. package/dist/esm/lang/LanguageCode.js +33 -0
  39. package/dist/esm/model/Widget.js +4 -4
  40. package/dist/esm/model/WidgetPackage.js +49 -2
  41. package/dist/esm/model/event/BroadcastEvent.js +4 -8
  42. package/dist/esm/model/msic/graphics.js +1 -0
  43. package/dist/esm/utils/ElectronUtils.js +5 -1
  44. package/dist/esm/utils/LanguageUtils.js +32 -0
  45. package/dist/types/api/AppApi.d.ts +23 -13
  46. package/dist/types/api/BaseApi.d.ts +5 -0
  47. package/dist/types/api/BroadcastApi.d.ts +19 -4
  48. package/dist/types/api/BrowserWindowApi.d.ts +56 -52
  49. package/dist/types/api/Channel.d.ts +1 -1
  50. package/dist/types/api/ClipboardApi.d.ts +9 -5
  51. package/dist/types/api/DeviceApi.d.ts +13 -9
  52. package/dist/types/api/DialogApi.d.ts +5 -7
  53. package/dist/types/api/HostedWidgetApi.d.ts +28 -18
  54. package/dist/types/api/LogApi.d.ts +8 -5
  55. package/dist/types/api/NotificationApi.d.ts +26 -16
  56. package/dist/types/api/ShortcutApi.d.ts +10 -0
  57. package/dist/types/api/WidgetApi.d.ts +31 -33
  58. package/dist/types/{repository/WidgetDataRepository.d.ts → api/WidgetDataApi.d.ts} +7 -2
  59. package/dist/types/index.d.ts +3 -2
  60. package/dist/types/lang/LanguageCode.d.ts +40 -0
  61. package/dist/types/model/Widget.d.ts +7 -9
  62. package/dist/types/model/WidgetPackage.d.ts +55 -12
  63. package/dist/types/model/event/BroadcastEvent.d.ts +14 -10
  64. package/dist/types/model/msic/graphics.d.ts +8 -0
  65. package/dist/types/utils/ElectronUtils.d.ts +2 -1
  66. package/dist/types/utils/LanguageUtils.d.ts +8 -0
  67. package/dist/umd/index.js +1 -1
  68. package/package.json +4 -2
  69. package/dist/cjs/api/GlobalShortcutApi.js +0 -29
  70. package/dist/esm/api/GlobalShortcutApi.js +0 -25
  71. package/dist/types/api/GlobalShortcutApi.d.ts +0 -14
@@ -1,6 +1,21 @@
1
1
  import { BroadcastEvent } from "../model/event/BroadcastEvent";
2
- export declare class BroadcastApi {
3
- static sendBroadcastEvent(event: BroadcastEvent): Promise<void>;
4
- static registerBroadcast(callback: (event: BroadcastEvent) => void): Promise<void>;
5
- static unregisterBroadcast(): Promise<void>;
2
+ import { BaseApi } from "./BaseApi";
3
+ import { WidgetApiEvent } from "./WidgetApi";
4
+ import { ShortcutApiEvent } from "./ShortcutApi";
5
+ import { ClipboardApiEvent } from "./ClipboardApi";
6
+ import { BrowserWindowApiEvent } from "./BrowserWindowApi";
7
+ type BroadcastEventType = WidgetApiEvent | BrowserWindowApiEvent | ShortcutApiEvent | ClipboardApiEvent | string;
8
+ interface IBroadcastApi {
9
+ send(event: BroadcastEvent): Promise<void>;
10
+ register(...event: BroadcastEventType[]): Promise<void>;
11
+ unregister(...event: BroadcastEventType[]): Promise<void>;
6
12
  }
13
+ type BroadcastApiMethods = keyof IBroadcastApi;
14
+ export declare class BroadcastApiImpl extends BaseApi<BroadcastApiMethods> implements IBroadcastApi {
15
+ send(event: BroadcastEvent): Promise<void>;
16
+ register(...event: BroadcastEventType[]): Promise<void>;
17
+ unregister(...event: BroadcastEventType[]): Promise<void>;
18
+ getChannel(): string;
19
+ }
20
+ declare const BroadcastApi: IBroadcastApi;
21
+ export { BroadcastApi, BroadcastApiMethods, BroadcastEventType };
@@ -1,68 +1,72 @@
1
1
  import { Rectangle } from "../model/interface/Rectangle";
2
- export type Position = {
3
- x: number;
4
- y: number;
5
- };
6
- export declare class BrowserWindowApi {
7
- static readonly IGNORE_MOUSE_EVENT = "ignore-mouse-event";
8
- static readonly WINDOW_VISIBILITY = "window-visibility";
9
- static readonly CENTER = "center";
10
- static readonly ALWAYS_ON_TOP = "always-on-top";
11
- static readonly IS_ALWAYS_ON_TOP = "is-always-on-top";
12
- static readonly OPEN_URL = "open-url";
13
- static readonly MOVE_TOP = "move-top";
14
- static readonly OPEN_DEV_TOOLS = "open-dev-tools";
15
- static readonly SET_POSITION = "set-position";
16
- static readonly GET_POSITION = "get-position";
17
- static readonly BLUR = "blur";
18
- static readonly FOCUS = "focus";
19
- static readonly SET_RESIZABLE = "set-resizable";
20
- static readonly GET_BOUNDS = "get-bounds";
21
- static readonly SET_BOUNDS = "set-bounds";
22
- static readonly ALIGN_TO_SCREEN = "align-to-screen";
23
- static readonly START_DRAGGING_WINDOW = "start-dragging-window";
24
- static readonly STOP_DRAGGING_WINDOW = "stop-dragging-window";
25
- static readonly EXISTS_BY_URL = "exists-by-url";
26
- static readonly SHOW_INACTIVE = "show-inactive";
27
- static readonly SHOW = "show";
28
- static setIgnoreMouseEvent(ignore: boolean): Promise<void>;
29
- static show(): Promise<void>;
30
- static showInactive(): Promise<void>;
31
- static hide(): Promise<void>;
32
- static center(): Promise<void>;
33
- /**
34
- * @deprecated
35
- * @param show
36
- */
37
- static setWindowVisibility(show: boolean): Promise<void>;
38
- static setAlwaysOnTop(alwaysOnTop: boolean): Promise<void>;
39
- static isAlwaysOnTop(): Promise<boolean>;
40
- static openUrl(url: string): Promise<void>;
41
- static moveTop(): Promise<void>;
42
- static openDevTools(): Promise<void>;
2
+ import { Position } from "../model/msic/graphics";
3
+ import { BaseApi } from "./BaseApi";
4
+ interface IBrowserWindowApi {
5
+ setIgnoreMouseEvent(ignore: boolean): Promise<void>;
6
+ show(): Promise<void>;
7
+ hide(): Promise<void>;
8
+ showInactive(): Promise<void>;
9
+ center(): Promise<void>;
10
+ startDraggingWindow(): Promise<void>;
11
+ stopDraggingWindow(): Promise<void>;
12
+ setAlwaysOnTop(alwaysOnTop: boolean): Promise<void>;
13
+ isAlwaysOnTop(): Promise<boolean>;
14
+ openUrl(url: string): Promise<void>;
15
+ moveTop(): Promise<void>;
16
+ openDevTools(): Promise<void>;
17
+ setPosition(x: number, y: number, animation: boolean): Promise<void>;
18
+ getPosition(): Promise<Position>;
19
+ blur(): Promise<void>;
20
+ focus(): Promise<void>;
21
+ setResizable(resizable: boolean): Promise<void>;
22
+ getBounds(): Promise<Rectangle>;
23
+ setBounds(bounds: Partial<Rectangle>, animate: boolean): Promise<void>;
24
+ alignToScreen(align: AlignPosition): Promise<void>;
25
+ existsByUrl(url: string): Promise<boolean>;
26
+ }
27
+ type BrowserWindowApiMethods = keyof IBrowserWindowApi;
28
+ type AlignPosition = 'top-left' | 'top-center' | 'top-right' | 'bottom-left' | 'bottom-center' | 'bottom-right';
29
+ declare enum BrowserWindowApiEvent {
30
+ BLUR = "event::cn.widgetjs.core.browser-window.blur",
31
+ FOCUS = "event::cn.widgetjs.core.browser-window.focus"
32
+ }
33
+ export declare class BrowserWindowApiImpl extends BaseApi<BrowserWindowApiMethods> implements IBrowserWindowApi {
34
+ getChannel(): string;
35
+ setIgnoreMouseEvent(ignore: boolean): Promise<void>;
36
+ show(): Promise<void>;
37
+ showInactive(): Promise<void>;
38
+ hide(): Promise<void>;
39
+ center(): Promise<void>;
40
+ setAlwaysOnTop(alwaysOnTop: boolean): Promise<void>;
41
+ isAlwaysOnTop(): Promise<boolean>;
42
+ openUrl(url: string): Promise<void>;
43
+ moveTop(): Promise<void>;
44
+ openDevTools(): Promise<void>;
43
45
  /**
44
46
  * 设置窗口位置
45
47
  * @param x
46
48
  * @param y
47
49
  * @param animation 动画只在mac系统有效
48
50
  */
49
- static setPosition(x: number, y: number, animation: boolean): Promise<void>;
50
- static getPosition(): Promise<Position>;
51
- static blur(): Promise<any>;
52
- static focus(): Promise<any>;
51
+ setPosition(x: number, y: number, animation: boolean): Promise<void>;
52
+ getPosition(): Promise<Position>;
53
+ blur(): Promise<any>;
54
+ focus(): Promise<any>;
53
55
  /**
54
56
  * 设置窗口是否可以拉伸
55
57
  * @param resizable
56
58
  */
57
- static setResizable(resizable: boolean): Promise<any>;
58
- static getBounds(): Promise<Rectangle>;
59
- static setBounds(bounds: Partial<Rectangle>, animate?: boolean): Promise<Rectangle>;
60
- static alignToScreen(align: "top" | "bottom"): Promise<any>;
61
- static startDraggingWindow(): Promise<any>;
62
- static stopDraggingWindow(): Promise<any>;
59
+ setResizable(resizable: boolean): Promise<any>;
60
+ getBounds(): Promise<Rectangle>;
61
+ setBounds(bounds: Partial<Rectangle>, animate?: boolean): Promise<void>;
62
+ alignToScreen(align: AlignPosition): Promise<any>;
63
+ startDraggingWindow(): Promise<any>;
64
+ stopDraggingWindow(): Promise<any>;
63
65
  /**
64
66
  * 通过url检测窗口是否存在
65
67
  * @param url
66
68
  */
67
- static existsByUrl(url: string): Promise<boolean>;
69
+ existsByUrl(url: string): Promise<boolean>;
68
70
  }
71
+ declare const BrowserWindowApi: BrowserWindowApiImpl;
72
+ export { BrowserWindowApi, BrowserWindowApiMethods, BrowserWindowApiEvent, AlignPosition };
@@ -11,6 +11,6 @@ export declare enum Channel {
11
11
  SHORTCUT = "channel::cn.widgetjs.core.shortcut",
12
12
  LOG = "channel::cn.widgetjs.core.log",
13
13
  DEVICE = "channel::cn.widgetjs.core.device",
14
- MOUSE_EVENT = "channel::cn.widgetjs.core.mouse_event",
14
+ MOUSE = "channel::cn.widgetjs.core.mouse",
15
15
  KEYBOARD = "channel::cn.widgetjs.core.keyboard"
16
16
  }
@@ -1,6 +1,10 @@
1
- export declare class ClipboardApi {
2
- static readonly GET_SELECTED_TEXT = "get-selected-text";
3
- static readonly GET_TEXT = "get-text";
4
- static getSelectedText(): Promise<string | undefined>;
5
- static getText(): Promise<string | undefined>;
1
+ interface IClipboardApi {
2
+ getSelectedText(): Promise<string | undefined>;
3
+ getText(): Promise<string | undefined>;
6
4
  }
5
+ type ClipboardApiMethods = keyof IClipboardApi;
6
+ declare enum ClipboardApiEvent {
7
+ CHANGED = "clipboard-changed"
8
+ }
9
+ declare const ClipboardApi: IClipboardApi;
10
+ export { ClipboardApi, ClipboardApiMethods, ClipboardApiEvent };
@@ -1,16 +1,20 @@
1
- export declare class DeviceApi {
2
- static readonly GET_CURSOR_SCREEN_POINT = "get-cursor-screen-point";
3
- static readonly IS_ALL_KEY_RELEASED = "is-all-key-released";
1
+ import { BaseApi } from "./BaseApi";
2
+ import { Point } from "../model/msic/graphics";
3
+ interface IDeviceApi {
4
+ getCursorScreenPoint(): Promise<Point>;
5
+ isAllKeyReleased(): Promise<boolean>;
6
+ }
7
+ type DeviceApiMethods = keyof IDeviceApi;
8
+ export declare class DeviceApiImpl extends BaseApi<DeviceApiMethods> implements IDeviceApi {
4
9
  /**
5
10
  * 获取当前鼠标位置
6
11
  */
7
- static getCursorScreenPoint(): Promise<Point>;
12
+ getCursorScreenPoint(): Promise<Point>;
8
13
  /**
9
14
  * 判断是否所有按键都已经释放
10
15
  */
11
- static isAllKeyReleased(): Promise<boolean>;
12
- }
13
- export interface Point {
14
- x: number;
15
- y: number;
16
+ isAllKeyReleased(): Promise<boolean>;
17
+ getChannel(): string;
16
18
  }
19
+ declare const DeviceApi: IDeviceApi;
20
+ export { DeviceApi, DeviceApiMethods };
@@ -1,8 +1,6 @@
1
- export declare class DialogApi {
2
- static readonly PICK_FILE = "pick-file";
3
- /**
4
- * 选取单个文件
5
- * @param extensions 允许的文件后缀格式,如:["txt","docx","gif"]
6
- */
7
- static pickFile(extensions?: string[]): Promise<string | undefined>;
1
+ interface IDialogApi {
2
+ pickFile(extensions?: string[]): Promise<string | undefined>;
8
3
  }
4
+ type DialogApiMethods = keyof IDialogApi;
5
+ declare const DialogApi: IDialogApi;
6
+ export { DialogApiMethods, DialogApi, };
@@ -1,45 +1,55 @@
1
1
  import { HostedWidget } from "../model/HostedWidget";
2
2
  import { WidgetParams } from "../model/WidgetParams";
3
- export declare class HostedWidgetApi {
4
- static readonly REMOVE_HOSTED_WIDGET = "remove-hosted-widget";
5
- static readonly REMOVE_HOSTED_WIDGET_BY_NAME = "remove-hosted-widget-by-name";
6
- static readonly GET_HOSTED_WIDGETS = "get-hosted-widgets";
7
- static readonly GET_HOSTED_WIDGET = "get-hosted-widget";
8
- static readonly OPEN_DEV_TOOLS = "open-dev-tools";
9
- static readonly REGISTER_ACTIVE_SHORTCUT = "register-active-shortcut";
10
- static readonly SET_PROXY = "SET_PROXY";
11
- static readonly UPDATE = "UPDATE";
12
- static readonly OPEN_CONFIG_ROUTE = "open-config-route";
3
+ import { BaseApi } from "./BaseApi";
4
+ import { HostedMode } from '../model/HostedMode';
5
+ import { Widget } from '../model/Widget';
6
+ interface IHostedWidgetApi {
7
+ removeHostedWidget(id: string): Promise<void>;
8
+ removeHostedWidgetByName(name: string): Promise<HostedWidget[]>;
9
+ getHostedWidgets(): Promise<HostedWidget[]>;
10
+ openDevTools(id: string): Promise<void>;
11
+ openConfigRoute(id: string): Promise<void>;
12
+ registerActiveShortcut(id: string, shortcut: string): Promise<boolean>;
13
+ setProxy(id: string, proxy: string): Promise<boolean>;
14
+ getHostedWidget(id: string): Promise<HostedWidget>;
15
+ addWidget(widgetName: string, hostMode: HostedMode): Promise<Widget[]>;
16
+ }
17
+ type HostedWidgetApiMethods = keyof IHostedWidgetApi;
18
+ export declare class HostedWidgetApiImpl extends BaseApi<HostedWidgetApiMethods> implements IHostedWidgetApi {
19
+ getChannel(): string;
13
20
  /**
14
21
  * 移除组件
15
22
  * @param id
16
23
  */
17
- static removeHostedWidget(id: string): Promise<any>;
24
+ removeHostedWidget(id: string): Promise<any>;
25
+ addWidget(widgetName: string, hostMode: HostedMode): Promise<Widget[]>;
18
26
  /**
19
27
  * 通过组件名移除已添加的组件
20
28
  * @param name 组件名
21
29
  */
22
- static removeHostedWidgetByName(name: string): Promise<HostedWidget[]>;
30
+ removeHostedWidgetByName(name: string): Promise<HostedWidget[]>;
23
31
  /**
24
32
  * 获取已添加的组件
25
33
  * @param name 组件名,可以不传
26
34
  */
27
- static getHostedWidgets(name?: string): Promise<HostedWidget[]>;
28
- static getHostedWidget(id: string): Promise<HostedWidget>;
35
+ getHostedWidgets(name?: string): Promise<HostedWidget[]>;
36
+ getHostedWidget(id: string): Promise<HostedWidget>;
29
37
  /**
30
38
  * Opens the dev tools for a widget with the specified ID.
31
39
  *
32
40
  * @param {string} widgetId - The ID of the widget to open the dev tools for.
33
41
  * @return {Promise} A Promise that resolves when the dev tools are opened.
34
42
  */
35
- static openDevTools(widgetId: string): Promise<any>;
36
- static openConfigRoute(widgetId: string, params?: WidgetParams): Promise<any>;
43
+ openDevTools(widgetId: string): Promise<any>;
44
+ openConfigRoute(widgetId: string, params?: WidgetParams): Promise<any>;
37
45
  /**
38
46
  * 注册激活、呼出、置顶组件快捷键
39
47
  * @param widgetId 组件id
40
48
  * @param shortcut 如果传空或者不传,则会取消快捷键。更多快捷键配置,请查看Accelerator用法
41
49
  * https://www.electronjs.org/docs/latest/api/accelerator
42
50
  */
43
- static registerActiveShortcut(widgetId: string, shortcut?: string): Promise<boolean>;
44
- static setProxy(widgetId: string, proxy: string): Promise<boolean>;
51
+ registerActiveShortcut(widgetId: string, shortcut?: string): Promise<boolean>;
52
+ setProxy(widgetId: string, proxy: string): Promise<boolean>;
45
53
  }
54
+ declare const HostedWidgetApi: HostedWidgetApiImpl;
55
+ export { HostedWidgetApi, HostedWidgetApiMethods };
@@ -1,6 +1,9 @@
1
- export declare class LogApi {
2
- static info(name: string, ...data: any[]): void;
3
- static error(name: string, ...data: any[]): void;
4
- static warn(name: string, ...data: any[]): void;
5
- static log(name: string, ...data: any[]): void;
1
+ interface ILogApi {
2
+ info(...data: any[]): void;
3
+ error(...data: any[]): void;
4
+ warn(...data: any[]): void;
5
+ log(...data: any[]): void;
6
6
  }
7
+ type LogApiMethods = keyof ILogApi;
8
+ declare const LogApi: ILogApi;
9
+ export { LogApi, LogApiMethods };
@@ -1,6 +1,16 @@
1
- import { AppNotification, NotificationType } from "../model/AppNotification";
2
- type NotificationCallback = (type: NotificationType, message: string, duration: number) => void;
3
- export declare class NotificationApi {
1
+ import { AppNotification } from "../model/AppNotification";
2
+ import { BaseApi } from "./BaseApi";
3
+ interface INotificationApi {
4
+ send(notification: AppNotification): Promise<void>;
5
+ hide(): Promise<void>;
6
+ }
7
+ type NotificationApiMethods = keyof INotificationApi;
8
+ declare enum NotificationApiEvent {
9
+ CONFIRM = "event::cn.widgetjs.core.notification.confirm",
10
+ CANCEL = "event::cn.widgetjs.core.notification.cancel",
11
+ HIDE = "event::cn.widgetjs.core.notification.hide"
12
+ }
13
+ declare class NotificationApiImpl extends BaseApi<NotificationApiMethods> implements INotificationApi {
4
14
  /**
5
15
  * 来电
6
16
  * @param avatar 头像地址
@@ -9,20 +19,20 @@ export declare class NotificationApi {
9
19
  * @param message 初始消息
10
20
  * @param lyric 歌词字符串
11
21
  */
12
- static call(avatar: string, audio: string, title: string, message: string, lyric: string): Promise<void>;
13
- static send(notification: AppNotification): Promise<any>;
14
- static reminder(title: string, message: string, icon: string, cancelButtonText: string, confirmButtonText: string, cancelBroadcast: string, confirmBroadcast: string, duration?: number): Promise<any>;
15
- static advanceCountdown(message: string, targetTime: string, title?: string): Promise<any>;
16
- static countdown(message: string, targetTime: string): Promise<void>;
17
- static success(message: string, duration?: number): Promise<void>;
18
- static error(message: string, duration?: number): Promise<void>;
19
- static warning(message: string, duration?: number): Promise<void>;
20
- static info(message: string, duration?: number): Promise<void>;
22
+ call(avatar: string, audio: string, title: string, message: string, lyric: string): Promise<void>;
23
+ send(notification: AppNotification): Promise<any>;
24
+ reminder(title: string, message: string, icon: string, cancelButtonText: string, confirmButtonText: string, cancelBroadcast: string, confirmBroadcast: string, duration?: number): Promise<any>;
25
+ advanceCountdown(message: string, targetTime: string, title?: string): Promise<any>;
26
+ countdown(message: string, targetTime: string): Promise<void>;
27
+ success(message: string, duration?: number): Promise<void>;
28
+ error(message: string, duration?: number): Promise<void>;
29
+ warning(message: string, duration?: number): Promise<void>;
30
+ info(message: string, duration?: number): Promise<void>;
21
31
  /**
22
32
  * 隐藏通知
23
33
  */
24
- static hide(): Promise<void>;
25
- private static callback;
26
- static setDebugNotification(callback: NotificationCallback): void;
34
+ hide(): Promise<void>;
35
+ getChannel(): string;
27
36
  }
28
- export {};
37
+ declare const NotificationApi: NotificationApiImpl;
38
+ export { NotificationApi, NotificationApiMethods, NotificationApiEvent };
@@ -0,0 +1,10 @@
1
+ interface IShortcutApi {
2
+ register(shortcut: string): void;
3
+ unregister(shortcut: string): void;
4
+ }
5
+ type ShortcutApiMethods = keyof IShortcutApi;
6
+ declare enum ShortcutApiEvent {
7
+ TRIGGERED = "channel::cn.widgetjs.core.shortcut.triggered"
8
+ }
9
+ declare const ShortcutApi: IShortcutApi;
10
+ export { ShortcutApi, ShortcutApiMethods, ShortcutApiEvent };
@@ -1,50 +1,48 @@
1
1
  import { Widget } from "../model/Widget";
2
2
  import { WidgetPackage } from "../model/WidgetPackage";
3
3
  import { WidgetParams } from "../model/WidgetParams";
4
- import { WidgetData } from "../model/WidgetData";
5
- export interface SaveWidgetOption {
6
- sendBroadcast?: boolean;
7
- id?: string;
4
+ import { BaseApi } from "./BaseApi";
5
+ interface IWidgetApi {
6
+ registerWidgets(widgets: Widget[]): Promise<void>;
7
+ registerWidgetPackage(widgetPackage: WidgetPackage): Promise<void>;
8
+ getWidgets(): Promise<Widget[]>;
9
+ getWidget(name: string): Promise<Widget>;
10
+ getWidgetPackage(name: string): Promise<WidgetPackage>;
11
+ getWidgetPackages(): Promise<WidgetPackage[]>;
12
+ getWidgetUrl(widgetName: string, widgetParams: WidgetParams): Promise<string | null>;
13
+ getWidgetPackageIndexUrl(packageName: string, hash?: boolean): Promise<string | null>;
14
+ getWidgetConfigUrl(widgetName: string, widgetParams: WidgetParams): Promise<string | null>;
15
+ getWidgetPackageUrl(packageName: string): Promise<string | null>;
8
16
  }
9
- export declare class WidgetApi {
10
- static readonly REGISTER_WIDGETS = "register-widgets";
11
- static readonly REGISTER_WIDGET_PACKAGE = "register-widget-package";
12
- static readonly GET_WIDGETS = "get-widgets";
13
- static readonly GET_WIDGET = "get-widget";
14
- static readonly GET_WIDGET_PACKAGE = "get-widget-package";
15
- static readonly GET_WIDGET_PACKAGES = "get-widget-packages";
16
- static registerWidgets(widgets: Widget[]): Promise<void>;
17
- static registerWidgetPackage(widgetPackage: WidgetPackage): Promise<void>;
18
- static getWidgets(): Promise<Widget[]>;
19
- static getWidgetPackages(): Promise<WidgetPackage>;
17
+ type WidgetApiMethods = keyof IWidgetApi;
18
+ declare enum WidgetApiEvent {
19
+ DATA_CHANGED = "event::cn.widgetjs.core.widget.data-changed",
20
+ EDIT_DESKTOP_WIDGETS = "event::cn.widgetjs.core.widget.desktop.edit"
21
+ }
22
+ declare class WidgetApiImpl extends BaseApi<WidgetApiMethods> implements IWidgetApi {
23
+ getChannel(): string;
24
+ registerWidgets(widgets: Widget[]): Promise<any>;
25
+ registerWidgetPackage(widgetPackage: WidgetPackage): Promise<any>;
26
+ getWidgets(): Promise<Widget[]>;
27
+ getWidgetPackages(): Promise<WidgetPackage[]>;
20
28
  /**
21
29
  *
22
30
  * @param name package name
23
31
  */
24
- static getWidget(name: string): Promise<Widget>;
32
+ getWidget(name: string): Promise<Widget>;
25
33
  /**
26
34
  *
27
35
  * @param name package name
28
36
  */
29
- static getWidgetPackage(name: string): Promise<WidgetPackage>;
37
+ getWidgetPackage(name: string): Promise<WidgetPackage>;
30
38
  /**
31
39
  * 获取组件配置地址
32
40
  * @param widgetName
33
41
  */
34
- static getWidgetConfigUrl(widgetName: string, widgetParams: WidgetParams): Promise<string | null>;
35
- static getWidgetUrl(widgetName: string, widgetParams: WidgetParams): Promise<string | null>;
36
- static getWidgetPackageIndexUrl(packageName: string, hash?: boolean): Promise<string | null>;
37
- static getWidgetPackageUrl(packageName: string): Promise<string | null>;
38
- /**
39
- * 通过组件名保存组件信息,通常用于存储可以在同类组件中共用的数据
40
- * @param data
41
- * @param options
42
- */
43
- static saveDataByName<T extends WidgetData>(data: T, options?: SaveWidgetOption): Promise<string>;
44
- private static stores;
45
- /**
46
- * 获取组件 LocalForage 存储实例
47
- * @param name
48
- */
49
- static getStore(name: string): LocalForage;
42
+ getWidgetConfigUrl(widgetName: string, widgetParams: WidgetParams): Promise<string | null>;
43
+ getWidgetUrl(widgetName: string, widgetParams: WidgetParams): Promise<string | null>;
44
+ getWidgetPackageIndexUrl(packageName: string, hash?: boolean): Promise<string | null>;
45
+ getWidgetPackageUrl(packageName: string): Promise<string | null>;
50
46
  }
47
+ declare const WidgetApi: WidgetApiImpl;
48
+ export { WidgetApi, WidgetApiEvent, WidgetApiMethods };
@@ -1,5 +1,9 @@
1
1
  import { WidgetData } from "../model/WidgetData";
2
- export declare class WidgetDataRepository {
2
+ export interface SaveWidgetOption {
3
+ sendBroadcast?: boolean;
4
+ id?: string;
5
+ }
6
+ export declare class WidgetDataApi {
3
7
  private static stores;
4
8
  /**
5
9
  * 保存组件数据
@@ -14,8 +18,9 @@ export declare class WidgetDataRepository {
14
18
  /**
15
19
  * 通过组件名保存组件信息,通常用于存储可以在同类组件中共用的数据
16
20
  * @param data
21
+ * @param options
17
22
  */
18
- static saveByName<T extends WidgetData>(data: T): Promise<string>;
23
+ static saveByName<T extends WidgetData>(data: T, options?: SaveWidgetOption): Promise<string>;
19
24
  static findByName<T extends WidgetData>(name: string, type: {
20
25
  new (name: string, id?: string): T;
21
26
  }): Promise<T | undefined>;
@@ -11,9 +11,9 @@ export * from "./model/event/NativeKeyboardEvent";
11
11
  export * from "./model/event/AppMouseEvent";
12
12
  export * from "./model/WidgetPackage";
13
13
  export * from "./api/ElectronApi";
14
- export * from "./repository/WidgetDataRepository";
14
+ export * from "./api/WidgetDataApi";
15
15
  export * from "./api/BrowserWindowApi";
16
- export * from "./api/GlobalShortcutApi";
16
+ export * from "./lang/LanguageCode";
17
17
  export * from "./api/NotificationApi";
18
18
  export * from "./api/HostedWidgetApi";
19
19
  export * from "./api/DeviceApi";
@@ -21,6 +21,7 @@ export * from "./api/Channel";
21
21
  export * from "./api/ClipboardApi";
22
22
  export * from "./api/WidgetApi";
23
23
  export * from "./api/ApiConstants";
24
+ export * from "./api/ShortcutApi";
24
25
  export * from "./api/BroadcastApi";
25
26
  export * from "./api/AppApi";
26
27
  export * from "./api/DialogApi";
@@ -0,0 +1,40 @@
1
+ interface Language {
2
+ locale: string;
3
+ language: string;
4
+ code: string;
5
+ }
6
+ interface ILanguageMap {
7
+ 'ar-SA': Language;
8
+ 'bn-BD': Language;
9
+ 'en-US': Language;
10
+ 'de-DE': Language;
11
+ 'el-GR': Language;
12
+ 'es-ES': Language;
13
+ 'fi-FI': Language;
14
+ 'fil-PH': Language;
15
+ 'fr-FR': Language;
16
+ 'hi-IN': Language;
17
+ 'hu-HU': Language;
18
+ 'id-ID': Language;
19
+ 'it-IT': Language;
20
+ 'ja-JP': Language;
21
+ 'ko-KR': Language;
22
+ 'nl-NL': Language;
23
+ 'pl-PL': Language;
24
+ 'pt-BR': Language;
25
+ 'pt-PT': Language;
26
+ 'ro-RO': Language;
27
+ 'ru-RU': Language;
28
+ 'sv-SE': Language;
29
+ 'ta-IN': Language;
30
+ 'tr-TR': Language;
31
+ 'uk-UA': Language;
32
+ 'vi-VN': Language;
33
+ 'zh-CN': Language;
34
+ 'zh-TW': Language;
35
+ }
36
+ export type LanguageCode = keyof ILanguageMap;
37
+ export type LanguageTextMap = {
38
+ [key in LanguageCode]?: string;
39
+ };
40
+ export {};
@@ -1,5 +1,6 @@
1
1
  import { HostedMode } from "./HostedMode";
2
2
  import { WidgetPermission } from "../permission/permission";
3
+ import { LanguageCode, LanguageTextMap } from "../lang/LanguageCode";
3
4
  type WidgetOptions = {
4
5
  name: string;
5
6
  title: {
@@ -32,6 +33,7 @@ type WidgetOptions = {
32
33
  hideWhenBlur?: boolean;
33
34
  routes: WidgetRoute[];
34
35
  permissions?: WidgetPermission[];
36
+ broadcastChannels?: string[];
35
37
  };
36
38
  export declare class Widget {
37
39
  readonly name: string;
@@ -39,15 +41,11 @@ export declare class Widget {
39
41
  * 组件标题,显示在界面上的,
40
42
  * https://zh.m.wikipedia.org/zh-hans/ISO_639-1
41
43
  */
42
- readonly title: {
43
- [key: string]: string;
44
- };
44
+ readonly title: LanguageTextMap;
45
45
  /**
46
46
  * 组件介绍
47
47
  */
48
- readonly description: {
49
- [key: string]: string;
50
- };
48
+ readonly description: LanguageTextMap;
51
49
  readonly keywords: WidgetKeyword[];
52
50
  /**
53
51
  * 组件默认语言
@@ -86,12 +84,12 @@ export declare class Widget {
86
84
  * 获取组件标题
87
85
  * @param lang 语言环境,不传则获取默认语言
88
86
  */
89
- getTitle(lang?: string): string | undefined;
87
+ getTitle(lang?: LanguageCode): string | undefined;
90
88
  /**
91
- * 获取组件标描述
89
+ * 获取组件描述
92
90
  * @param lang 语言环境,不传则获取默认标题
93
91
  */
94
- getDescription(lang?: string): string | undefined;
92
+ getDescription(lang?: LanguageCode): string | undefined;
95
93
  static parseJSON(json: string): Widget;
96
94
  static parseObject(obj: any): Widget;
97
95
  /**