Skip to content

Commit 2a04efe

Browse files
authored
feat(hub): add a command kind for message-panel actions (#189)
1 parent 6ca3e6f commit 2a04efe

4 files changed

Lines changed: 34 additions & 7 deletions

File tree

packages/hub/src/types/messages.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,23 @@ export interface DevframeMessageActivateAction {
4040
activate: { dockId: string, params?: Record<string, unknown> }
4141
}
4242

43-
export type DevframeMessageAction = DevframeMessageActivateAction
43+
/**
44+
* `'command'` invokes a command from the hub's command registry (the same
45+
* registry backing the command palette) by `command.id`, spreading
46+
* `command.params` as its positional arguments, via the hub's
47+
* `hub:commands:execute` RPC.
48+
*/
49+
export interface DevframeMessageCommandAction {
50+
/** Stable id for the action within its entry. */
51+
id: string
52+
/** Button label shown in the messages panel. */
53+
label: string
54+
kind: 'command'
55+
/** The command to invoke, plus an optional list of positional arguments. */
56+
command: { id: string, params?: unknown[] }
57+
}
58+
59+
export type DevframeMessageAction = DevframeMessageActivateAction | DevframeMessageCommandAction
4460

4561
export interface DevframeMessageEntry {
4662
/**

plugins/messages/src/client/App.vue

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,13 @@ onMounted(() => {
6969
})
7070
7171
async function onActivate(action: DevframeMessageAction): Promise<void> {
72-
if (action.kind !== 'activate')
72+
const callOptional = props.rpc.callOptional as (name: string, ...args: unknown[]) => Promise<unknown>
73+
if (action.kind === 'activate') {
74+
await callOptional('hub:docks:activate', action.activate)
7375
return
74-
await (props.rpc.callOptional as (name: string, ...args: unknown[]) => Promise<unknown>)(
75-
'hub:docks:activate',
76-
action.activate,
77-
)
76+
}
77+
if (action.kind === 'command')
78+
await callOptional('hub:commands:execute', action.command.id, ...(action.command.params ?? []))
7879
}
7980
8081
async function onDismiss(id: string): Promise<void> {

tests/__snapshots__/tsnapi/@devframes/hub/index.snapshot.d.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,15 @@ export interface DevframeMessageActivateAction {
141141
params?: Record<string, unknown>;
142142
};
143143
}
144+
export interface DevframeMessageCommandAction {
145+
id: string;
146+
label: string;
147+
kind: 'command';
148+
command: {
149+
id: string;
150+
params?: unknown[];
151+
};
152+
}
144153
export interface DevframeMessageElementPosition {
145154
selector?: string;
146155
boundingBox?: {
@@ -337,7 +346,7 @@ export type DevframeDockEntryIcon = string | {
337346
dark: string;
338347
};
339348
export type DevframeDockUserEntry = DevframeDockEntryRegistry[keyof DevframeDockEntryRegistry];
340-
export type DevframeMessageAction = DevframeMessageActivateAction;
349+
export type DevframeMessageAction = DevframeMessageActivateAction | DevframeMessageCommandAction;
341350
export type DevframeMessageEntryFrom = 'server' | 'browser';
342351
export type DevframeMessageEntryInput = Omit<DevframeMessageEntry, 'id' | 'timestamp' | 'from'> & {
343352
id?: string;

tests/__snapshots__/tsnapi/@devframes/hub/types.snapshot.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export { DevframeHost }
3737
export { DevframeHubContext }
3838
export { DevframeMessageAction }
3939
export { DevframeMessageActivateAction }
40+
export { DevframeMessageCommandAction }
4041
export { DevframeMessageElementPosition }
4142
export { DevframeMessageEntry }
4243
export { DevframeMessageEntryFrom }

0 commit comments

Comments
 (0)