Skip to content

Commit 22845c8

Browse files
committed
add getViewContext, remove viewLoaded notification
1 parent 2ab847c commit 22845c8

File tree

7 files changed

+70
-31
lines changed

7 files changed

+70
-31
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@beekeeperstudio/plugin",
3-
"version": "1.4.0-beta.3",
3+
"version": "1.4.0-beta.4",
44
"description": "A simple TypeScript wrapper to send messages from your Beekeeper Studio plugin to the main app.",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",

src/commonTypes.ts

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,29 @@ export type WindowEventInits =
3535

3636
export type TableFilter = {
3737
field: string;
38-
type: "=" | "!=" | "like" | "not like" | "<" | "<=" | ">" | ">=" | "in" | "is" | "is not";
38+
type:
39+
| "="
40+
| "!="
41+
| "like"
42+
| "not like"
43+
| "<"
44+
| "<="
45+
| ">"
46+
| ">="
47+
| "in"
48+
| "is"
49+
| "is not";
3950
value?: string | string[];
40-
op?: 'AND' | 'OR';
41-
}
51+
op?: "AND" | "OR";
52+
};
4253

43-
export type JsonValue = string | number | boolean | null | JsonValue[] | { [key: string]: JsonValue };
54+
export type JsonValue =
55+
| string
56+
| number
57+
| boolean
58+
| null
59+
| JsonValue[]
60+
| { [key: string]: JsonValue };
4461

4562
export type ActiveRange = {
4663
rows: number[];
@@ -93,4 +110,13 @@ export type CornerMenuParams = {
93110
activeRange: ActiveRange;
94111
};
95112

96-
export type LoadViewParams = CornerMenuParams | RowMenuParams | ColumnMenuParams | CellMenuParams;
113+
export type LoadViewParams =
114+
| CornerMenuParams
115+
| RowMenuParams
116+
| ColumnMenuParams
117+
| CellMenuParams;
118+
119+
export type PluginViewContext = {
120+
command: string;
121+
params?: CellMenuParams | ColumnMenuParams | RowMenuParams | CornerMenuParams;
122+
};

src/comms.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import {
33
BroadcastNotification,
44
PluginErrorNotification,
55
ThemeChangedNotification,
6-
ViewLoadedNotification,
76
WindowEventNotification,
87
} from "./notificationTypes";
98
import type { PluginRequestPayload } from "./requestTypes";
@@ -123,10 +122,6 @@ export function addNotificationListener<Message extends JsonValue = JsonValue>(
123122
name: BroadcastNotification["name"],
124123
handler: (args: BroadcastNotification<Message>["args"]) => void,
125124
): void;
126-
export function addNotificationListener(
127-
name: ViewLoadedNotification["name"],
128-
handler: (args: ViewLoadedNotification["args"]) => void,
129-
): void;
130125
export function addNotificationListener(
131126
name: ThemeChangedNotification["name"],
132127
handler: (args: ThemeChangedNotification["args"]) => void,

src/index.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import type {
3333
GetTableKeysResponse,
3434
GetAppInfoResponse,
3535
CheckForUpdateResponse,
36+
GetViewContextResponse,
3637
} from "./responseTypes";
3738

3839
/**
@@ -111,6 +112,20 @@ export async function setTabTitle(title: string): Promise<SetTabTitleResponse['r
111112
return await request({ name: "setTabTitle", args: { title } as SetTabTitleRequest['args'] });
112113
}
113114

115+
/**
116+
* Get the current view context.
117+
*
118+
* A view context describes how this plugin view was opened and what data is
119+
* available for it. It always includes the static `command` from your
120+
* `manifest.json`, and may also include dynamic `params` depending on where
121+
* the menu was invoked.
122+
*
123+
* @since Beekeeper Studio 5.4.0
124+
**/
125+
export async function getViewContext(): Promise<GetViewContextResponse['result']> {
126+
return await request({ name: "getViewContext", args: void 0 });
127+
}
128+
114129
/**
115130
* Get the current state of your view instance.
116131
*

src/notificationTypes.ts

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@ import {
33
WindowEventInits,
44
WindowEventClass,
55
JsonValue,
6-
CellMenuParams,
7-
CornerMenuParams,
8-
RowMenuParams,
9-
ColumnMenuParams,
106
} from "./commonTypes";
117

128
export type AppTheme = {
@@ -45,21 +41,8 @@ export type BroadcastNotification<Message extends JsonValue = JsonValue> = {
4541
};
4642
};
4743

48-
export type ViewLoadedNotification = {
49-
name: "viewLoaded";
50-
args: {
51-
command: string;
52-
params?:
53-
| CellMenuParams
54-
| ColumnMenuParams
55-
| RowMenuParams
56-
| CornerMenuParams;
57-
};
58-
};
59-
6044
export type PluginNotificationData =
6145
| ThemeChangedNotification
6246
| WindowEventNotification
6347
| PluginErrorNotification
64-
| ViewLoadedNotification
6548
| BroadcastNotification;

src/requestTypes.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ export interface SetTabTitleRequest extends BaseRequest {
5858
};
5959
}
6060

61+
export type GetViewContextRequest = BaseRequest & {
62+
name: "getViewContext";
63+
args: void;
64+
};
65+
6166
export interface GetViewStateRequest extends BaseRequest {
6267
name: "getViewState";
6368
args: void;
@@ -167,6 +172,7 @@ export type PluginRequestData =
167172
| RunQueryRequest
168173
| ExpandTableResultRequest
169174
| SetTabTitleRequest
175+
| GetViewContextRequest
170176
| GetViewStateRequest
171177
| SetViewStateRequest<unknown>
172178
| OpenExternalRequest

src/responseTypes.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1-
import { QueryResult, TableKey } from "./commonTypes";
1+
import {
2+
QueryResult,
3+
TableKey,
4+
CellMenuParams,
5+
CornerMenuParams,
6+
RowMenuParams,
7+
ColumnMenuParams,
8+
PluginViewContext,
9+
} from "./commonTypes";
210
import { AppTheme } from "./notificationTypes";
311

412
type TabType = string;
@@ -45,7 +53,7 @@ export type GetAppInfoResponse = BaseResponse & {
4553
version: string;
4654
theme: AppTheme;
4755
};
48-
}
56+
};
4957

5058
export interface RunQueryResponse extends BaseResponse {
5159
result: {
@@ -62,6 +70,10 @@ export interface SetTabTitleResponse extends BaseResponse {
6270
result: void;
6371
}
6472

73+
export type GetViewContextResponse = BaseResponse & {
74+
result: PluginViewContext;
75+
};
76+
6577
export interface GetViewStateResponse<T extends unknown> extends BaseResponse {
6678
result: T;
6779
}
@@ -82,7 +94,8 @@ export interface SetDataResponse extends BaseResponse {
8294
result: void;
8395
}
8496

85-
export interface GetEncryptedDataResponse<T extends unknown> extends BaseResponse {
97+
export interface GetEncryptedDataResponse<T extends unknown>
98+
extends BaseResponse {
8699
result: T;
87100
}
88101

@@ -114,6 +127,7 @@ export type PluginResponseData =
114127
| RunQueryResponse
115128
| ExpandTableResultResponse
116129
| SetTabTitleResponse
130+
| GetViewContextResponse
117131
| GetViewStateResponse<unknown>
118132
| SetViewStateResponse
119133
| OpenExternalResponse

0 commit comments

Comments
 (0)