@foxglove/embed 0.9.0 → 0.10.0
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/FoxgloveViewer.d.ts +68 -2
- package/dist/FoxgloveViewer.d.ts.map +1 -1
- package/dist/FoxgloveViewer.js +99 -2
- package/dist/FoxgloveViewer.js.map +1 -1
- package/dist/commands.d.ts +49 -2
- package/dist/commands.d.ts.map +1 -1
- package/dist/commands.js +5 -0
- package/dist/commands.js.map +1 -1
- package/dist/types.d.ts +78 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/FoxgloveViewer.ts +143 -2
- package/src/commands.ts +57 -2
- package/src/types.ts +300 -0
package/dist/FoxgloveViewer.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { EmbeddedViewer } from "@foxglove/common";
|
|
2
|
-
import type { DataSource, FoxgloveViewerEventMap, OpaqueLayoutData, SelectLayoutParams } from "./types.ts";
|
|
2
|
+
import type { DataSource, FoxgloveViewerEventMap, Keybinding, OpaqueLayoutData, SelectLayoutParams } from "./types.ts";
|
|
3
3
|
interface FoxgloveEventTarget extends EventTarget {
|
|
4
4
|
addEventListener<K extends keyof FoxgloveViewerEventMap>(type: K, listener: (ev: FoxgloveViewerEventMap[K]) => void, options?: boolean | AddEventListenerOptions): void;
|
|
5
5
|
removeEventListener<K extends keyof FoxgloveViewerEventMap>(type: K, listener: (ev: FoxgloveViewerEventMap[K]) => void, options?: boolean | EventListenerOptions): void;
|
|
@@ -40,9 +40,40 @@ export type FoxgloveViewerOptions = {
|
|
|
40
40
|
colorScheme?: "light" | "dark" | "auto";
|
|
41
41
|
/**
|
|
42
42
|
* Identifies the embedding SDK client for analytics purposes. This should be set by SDK
|
|
43
|
-
* libraries (
|
|
43
|
+
* libraries (such as the Python SDK) to identify the embedding context.
|
|
44
44
|
*/
|
|
45
45
|
embeddedViewer?: EmbeddedViewer;
|
|
46
|
+
/**
|
|
47
|
+
* Custom keybindings for the embedded viewer.
|
|
48
|
+
*
|
|
49
|
+
* Overrides default keybindings and registers custom handlers.
|
|
50
|
+
*
|
|
51
|
+
* Custom keybindings take priority over the viewer's default bindings. If multiple keybindings
|
|
52
|
+
* share the same key + modifiers, the first one in the list wins and the rest are ignored.
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* [
|
|
56
|
+
* // Register a custom keybinding
|
|
57
|
+
* {
|
|
58
|
+
* key: "s",
|
|
59
|
+
* modifiers: ["Control", "Shift"],
|
|
60
|
+
* handler: () => {
|
|
61
|
+
* console.log("Custom keybinding triggered: take-snapshot");
|
|
62
|
+
* },
|
|
63
|
+
* },
|
|
64
|
+
* // Configure the "p" key to trigger the "player.togglePlayback" command
|
|
65
|
+
* {
|
|
66
|
+
* key: "p",
|
|
67
|
+
* command: "player.togglePlayback",
|
|
68
|
+
* },
|
|
69
|
+
* // Suppress a built-in keybinding
|
|
70
|
+
* {
|
|
71
|
+
* key: "[",
|
|
72
|
+
* command: "noop",
|
|
73
|
+
* },
|
|
74
|
+
* ]
|
|
75
|
+
*/
|
|
76
|
+
keybindings?: Keybinding[];
|
|
46
77
|
};
|
|
47
78
|
/**
|
|
48
79
|
* A class that manages an iframe that contains the Foxglove app.
|
|
@@ -126,6 +157,41 @@ export declare class FoxgloveViewer extends TypedEventTarget {
|
|
|
126
157
|
* This method is not supported by all Foxglove versions and plans, so it may result in an `error` event.
|
|
127
158
|
*/
|
|
128
159
|
installExtensions(extensions: Array<string | File>): void;
|
|
160
|
+
/**
|
|
161
|
+
* Customize keybinding configuration for this viewer instance.
|
|
162
|
+
*
|
|
163
|
+
* Custom keybindings take priority over the viewer's default bindings. If multiple keybindings
|
|
164
|
+
* share the same key, the first one in the list wins and the rest are ignored. Each call fully
|
|
165
|
+
* replaces the previous configuration. Calling with an empty array restores the viewer's default
|
|
166
|
+
* keybindings and clears all custom keybindings.
|
|
167
|
+
*
|
|
168
|
+
* @example
|
|
169
|
+
* viewer.setKeybindings([
|
|
170
|
+
* // Register a keybinding to trigger a custom function
|
|
171
|
+
* {
|
|
172
|
+
* key: "s",
|
|
173
|
+
* modifiers: ["Control", "Shift"],
|
|
174
|
+
* handler: () => {
|
|
175
|
+
* console.log("Custom keybinding triggered: take-snapshot");
|
|
176
|
+
* },
|
|
177
|
+
* },
|
|
178
|
+
* // Configure the "p" key to trigger the "player.togglePlayback" command
|
|
179
|
+
* {
|
|
180
|
+
* key: "p",
|
|
181
|
+
* command: "player.togglePlayback",
|
|
182
|
+
* },
|
|
183
|
+
* // Suppress a built-in keybinding
|
|
184
|
+
* {
|
|
185
|
+
* key: "[",
|
|
186
|
+
* command: "noop",
|
|
187
|
+
* },
|
|
188
|
+
* ]);
|
|
189
|
+
*
|
|
190
|
+
* // Restore the viewer's default keybindings
|
|
191
|
+
* viewer.setKeybindings([]);
|
|
192
|
+
*
|
|
193
|
+
*/
|
|
194
|
+
setKeybindings(keybindings: Keybinding[]): void;
|
|
129
195
|
/** Whether the frame is ready to receive commands. */
|
|
130
196
|
isReady(): boolean;
|
|
131
197
|
/** Destroy the frame. This will remove the iframe from the DOM and stop listening for messages. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FoxgloveViewer.d.ts","sourceRoot":"","sources":["../src/FoxgloveViewer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"FoxgloveViewer.d.ts","sourceRoot":"","sources":["../src/FoxgloveViewer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAevD,OAAO,KAAK,EACV,UAAU,EACV,sBAAsB,EAEtB,UAAU,EACV,gBAAgB,EAChB,kBAAkB,EAEnB,MAAM,YAAY,CAAC;AAEpB,UAAU,mBAAoB,SAAQ,WAAW;IAE/C,gBAAgB,CAAC,CAAC,SAAS,MAAM,sBAAsB,EACrD,I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IAOlD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA8BG;IACI,YAAY,CAAC,MAAM,EAAE,kBAAkB,GAAG,IAAI;IAOrD;;;;;OAKG;IACU,SAAS,IAAI,OAAO,CAAC,gBAAgB,CAAC;IAUnD;;;;;;;;;;;;;;;;;;;;;;;;;;OA0BG;IACI,aAAa,CAAC,MAAM,EAAE,gBAAgB,GAAG,IAAI;IAQpD;;;;;OAKG;IACI,iBAAiB,CAAC,UAAU,EAAE,KAAK,CAAC,MAAM,GAAG,IAAI,CAAC,GAAG,IAAI;IAOhE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAiCG;IACI,cAAc,CAAC,WAAW,EAAE,UAAU,EAAE,GAAG,IAAI;IAQtD,sDAAsD;IAC/C,OAAO,IAAI,OAAO;IAIzB,mGAAmG;IAC5F,OAAO,IAAI,IAAI;IAMtB,4CAA4C;IACrC,WAAW,IAAI,OAAO;IAI7B;;;OAGG;IACI,cAAc,CAAC,WAAW,EAAE,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,IAAI;CAkKpE"}
|
package/dist/FoxgloveViewer.js
CHANGED
|
@@ -34,17 +34,20 @@ export class FoxgloveViewer extends TypedEventTarget {
|
|
|
34
34
|
dataSource: undefined,
|
|
35
35
|
selectLayout: undefined,
|
|
36
36
|
extension: [],
|
|
37
|
+
keybindings: undefined,
|
|
37
38
|
};
|
|
38
39
|
/**
|
|
39
40
|
* If a layout export request has been made, this holds the promise that will be resolved when a
|
|
40
41
|
* response is received from the embed
|
|
41
42
|
*/
|
|
42
43
|
#getLayoutPromise;
|
|
44
|
+
/** Maps auto-generated custom keybinding IDs to user-provided handlers. */
|
|
45
|
+
#customKeybindingHandlers = new Map();
|
|
43
46
|
/** Whether the frame has been destroyed. */
|
|
44
47
|
#isDestroyed = false;
|
|
45
48
|
constructor(options) {
|
|
46
49
|
super();
|
|
47
|
-
const { parent, src, orgSlug, initialDataSource, initialLayout, initialLayoutParams, initialExtensions, colorScheme = "auto", embeddedViewer, } = options;
|
|
50
|
+
const { parent, src, orgSlug, initialDataSource, initialLayout, initialLayoutParams, initialExtensions, colorScheme = "auto", embeddedViewer, keybindings, } = options;
|
|
48
51
|
this.#orgSlug = orgSlug;
|
|
49
52
|
this.#isReadyPromise = promiseWithResolvers();
|
|
50
53
|
const srcUrl = src ?? DEFAULT_SERVER;
|
|
@@ -73,11 +76,16 @@ export class FoxgloveViewer extends TypedEventTarget {
|
|
|
73
76
|
if (initialExtensions) {
|
|
74
77
|
this.installExtensions(initialExtensions);
|
|
75
78
|
}
|
|
79
|
+
if (keybindings != undefined) {
|
|
80
|
+
this.setKeybindings(keybindings);
|
|
81
|
+
}
|
|
76
82
|
// Create the iframe element.
|
|
77
83
|
this.#iframe = document.createElement("iframe");
|
|
78
84
|
this.#iframe.src = this.#server.href;
|
|
79
85
|
this.#iframe.title = "Foxglove";
|
|
80
|
-
|
|
86
|
+
// keyboard-map is required so the iframe can use navigator.keyboard.getLayoutMap()
|
|
87
|
+
// to detect the user's keyboard layout for correct shortcut handling.
|
|
88
|
+
this.#iframe.allow = "cross-origin-isolated; keyboard-map *";
|
|
81
89
|
this.#iframe.style.width = "100%";
|
|
82
90
|
this.#iframe.style.height = "100%";
|
|
83
91
|
this.#iframe.style.border = "none";
|
|
@@ -189,6 +197,47 @@ export class FoxgloveViewer extends TypedEventTarget {
|
|
|
189
197
|
payload: extensions,
|
|
190
198
|
});
|
|
191
199
|
}
|
|
200
|
+
/**
|
|
201
|
+
* Customize keybinding configuration for this viewer instance.
|
|
202
|
+
*
|
|
203
|
+
* Custom keybindings take priority over the viewer's default bindings. If multiple keybindings
|
|
204
|
+
* share the same key, the first one in the list wins and the rest are ignored. Each call fully
|
|
205
|
+
* replaces the previous configuration. Calling with an empty array restores the viewer's default
|
|
206
|
+
* keybindings and clears all custom keybindings.
|
|
207
|
+
*
|
|
208
|
+
* @example
|
|
209
|
+
* viewer.setKeybindings([
|
|
210
|
+
* // Register a keybinding to trigger a custom function
|
|
211
|
+
* {
|
|
212
|
+
* key: "s",
|
|
213
|
+
* modifiers: ["Control", "Shift"],
|
|
214
|
+
* handler: () => {
|
|
215
|
+
* console.log("Custom keybinding triggered: take-snapshot");
|
|
216
|
+
* },
|
|
217
|
+
* },
|
|
218
|
+
* // Configure the "p" key to trigger the "player.togglePlayback" command
|
|
219
|
+
* {
|
|
220
|
+
* key: "p",
|
|
221
|
+
* command: "player.togglePlayback",
|
|
222
|
+
* },
|
|
223
|
+
* // Suppress a built-in keybinding
|
|
224
|
+
* {
|
|
225
|
+
* key: "[",
|
|
226
|
+
* command: "noop",
|
|
227
|
+
* },
|
|
228
|
+
* ]);
|
|
229
|
+
*
|
|
230
|
+
* // Restore the viewer's default keybindings
|
|
231
|
+
* viewer.setKeybindings([]);
|
|
232
|
+
*
|
|
233
|
+
*/
|
|
234
|
+
setKeybindings(keybindings) {
|
|
235
|
+
const serialized = this.#serializeKeybindings(keybindings);
|
|
236
|
+
this.#queueCommand({
|
|
237
|
+
type: "set-keybinding-config",
|
|
238
|
+
payload: serialized,
|
|
239
|
+
});
|
|
240
|
+
}
|
|
192
241
|
/** Whether the frame is ready to receive commands. */
|
|
193
242
|
isReady() {
|
|
194
243
|
return this.#isReady;
|
|
@@ -210,6 +259,45 @@ export class FoxgloveViewer extends TypedEventTarget {
|
|
|
210
259
|
setColorScheme(colorScheme) {
|
|
211
260
|
this.#iframe.style.colorScheme = colorScheme === "auto" ? "inherit" : colorScheme;
|
|
212
261
|
}
|
|
262
|
+
/**
|
|
263
|
+
* Converts the public flat `Keybinding[]` into the internal wire format
|
|
264
|
+
* (`SerializedKeybindingConfig`) for postMessage, decomposing keybindings
|
|
265
|
+
* into overrides and custom shortcuts.
|
|
266
|
+
*
|
|
267
|
+
* - `CommandKeybinding` (non-noop) becomes a `ShortcutOverride`
|
|
268
|
+
* - `HandlerKeybinding` becomes a `SerializedCustomShortcut` with a stored handler
|
|
269
|
+
* - `CommandKeybinding` with `"noop"` becomes a `SerializedCustomShortcut` with
|
|
270
|
+
* no stored handler — it claims the key slot to suppress defaults
|
|
271
|
+
*
|
|
272
|
+
* Handler keybindings are serialized before noop keybindings so that handlers
|
|
273
|
+
* win conflicts over noop suppressions.
|
|
274
|
+
*/
|
|
275
|
+
#serializeKeybindings(keybindings) {
|
|
276
|
+
this.#customKeybindingHandlers.clear();
|
|
277
|
+
const overrides = [];
|
|
278
|
+
const handlerCustom = [];
|
|
279
|
+
const noopCustom = [];
|
|
280
|
+
for (const kb of keybindings) {
|
|
281
|
+
const binding = { key: kb.key, modifiers: kb.modifiers };
|
|
282
|
+
const prefix = [...(kb.modifiers ?? []), kb.key].join("+");
|
|
283
|
+
if ("handler" in kb) {
|
|
284
|
+
const id = `${prefix}-${crypto.randomUUID()}`;
|
|
285
|
+
this.#customKeybindingHandlers.set(id, kb.handler);
|
|
286
|
+
handlerCustom.push({ id, binding });
|
|
287
|
+
}
|
|
288
|
+
else if (kb.command === "noop") {
|
|
289
|
+
const id = `noop-${prefix}-${crypto.randomUUID()}`;
|
|
290
|
+
noopCustom.push({ id, binding });
|
|
291
|
+
}
|
|
292
|
+
else {
|
|
293
|
+
overrides.push({ id: kb.command, binding });
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
return {
|
|
297
|
+
overrides,
|
|
298
|
+
custom: [...handlerCustom, ...noopCustom],
|
|
299
|
+
};
|
|
300
|
+
}
|
|
213
301
|
/**
|
|
214
302
|
* Queue a command to be executed when the frame is ready.
|
|
215
303
|
*
|
|
@@ -229,6 +317,9 @@ export class FoxgloveViewer extends TypedEventTarget {
|
|
|
229
317
|
case "select-layout":
|
|
230
318
|
this.#latestCommands.selectLayout = command;
|
|
231
319
|
break;
|
|
320
|
+
case "set-keybinding-config":
|
|
321
|
+
this.#latestCommands.keybindings = command;
|
|
322
|
+
break;
|
|
232
323
|
}
|
|
233
324
|
if (this.#isReady) {
|
|
234
325
|
this.#postCommand(command);
|
|
@@ -268,6 +359,7 @@ export class FoxgloveViewer extends TypedEventTarget {
|
|
|
268
359
|
initialDataSource: this.#latestCommands.dataSource?.payload,
|
|
269
360
|
initialLayoutParams: this.#latestCommands.selectLayout?.payload,
|
|
270
361
|
initialExtensions: this.#latestCommands.extension.flatMap((command) => command.payload),
|
|
362
|
+
initialKeybindingsConfig: this.#latestCommands.keybindings?.payload,
|
|
271
363
|
},
|
|
272
364
|
});
|
|
273
365
|
break;
|
|
@@ -288,6 +380,11 @@ export class FoxgloveViewer extends TypedEventTarget {
|
|
|
288
380
|
console.warn("[FoxgloveViewer] Received layout but getLayout was not called.");
|
|
289
381
|
}
|
|
290
382
|
break;
|
|
383
|
+
case "foxglove-keybinding-triggered": {
|
|
384
|
+
const handler = this.#customKeybindingHandlers.get(message.data.payload.keybindingId);
|
|
385
|
+
handler?.();
|
|
386
|
+
break;
|
|
387
|
+
}
|
|
291
388
|
default:
|
|
292
389
|
console.warn("[FoxgloveViewer] Unhandled message type:", message.data);
|
|
293
390
|
break;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FoxgloveViewer.js","sourceRoot":"","sources":["../src/FoxgloveViewer.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"FoxgloveViewer.js","sourceRoot":"","sources":["../src/FoxgloveViewer.ts"],"names":[],"mappings":"AAwCA;;GAEG;AACH,MAAM,gBAAgB,GAAG,WAAuD,CAAC;AAEjF,MAAM,cAAc,GAAG,6BAA6B,CAAC;AAErD,MAAM,0BAA0B,GAAG,yBAAyB,CAAC;AAQ7D;;;GAGG;AACH,SAAS,oBAAoB;IAC3B,IAAI,OAA2B,CAAC;IAChC,IAAI,MAAkC,CAAC;IACvC,MAAM,OAAO,GAAG,IAAI,OAAO,CAAI,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE;QAC1C,OAAO,GAAG,GAAG,CAAC;QACd,MAAM,GAAG,GAAG,CAAC;IACf,CAAC,CAAC,CAAC;IACH,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,OAAQ,EAAE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AAC,CAAC;CACH;AAED,SAAS,MAAM,CACb,SAAkB,EAClB,UAAkB,6BAA6B;IAE/C,yEAAyE;IACzE,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,MAAM,IAAI,KAAK,CAAC,mBAAmB,GAAG,OAAO,CAAC,CAAC;IACjD,CAAC;AACH,CAAC"}
|
package/dist/commands.d.ts
CHANGED
|
@@ -1,4 +1,40 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* This file contains type definitions to define the communication protocol between the parent page and the embedded iframe.
|
|
3
|
+
*
|
|
4
|
+
* These type are only meant for internal usage and are bound to change without notice.
|
|
5
|
+
*/
|
|
6
|
+
import type { DataSource, FoxgloveCommandId, OpaqueLayoutData, SelectLayoutParams, KeybindingBase } from "./types.ts";
|
|
7
|
+
/**
|
|
8
|
+
* Override or disable a built-in viewer shortcut.
|
|
9
|
+
*
|
|
10
|
+
* Provide a `binding` to remap the shortcut, or `null` to disable it.
|
|
11
|
+
*
|
|
12
|
+
* When multiple overrides share the same binding, the first one in the list wins
|
|
13
|
+
* and the rest are cleared.
|
|
14
|
+
*/
|
|
15
|
+
type ShortcutOverride = {
|
|
16
|
+
/** The built-in shortcut to override. */
|
|
17
|
+
id: FoxgloveCommandId;
|
|
18
|
+
/** The new key combination, or `null` to disable the shortcut. */
|
|
19
|
+
binding: KeybindingBase | null;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Serializable representation of a custom shortcut used for postMessage communication
|
|
23
|
+
* between the parent page and the embedded iframe.
|
|
24
|
+
*/
|
|
25
|
+
type SerializedCustomShortcut = {
|
|
26
|
+
/** Auto-generated identifier used to correlate iframe events back to handlers. */
|
|
27
|
+
id: string;
|
|
28
|
+
/** The key combination to listen for. */
|
|
29
|
+
binding: KeybindingBase;
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Serializable keybinding configuration sent over postMessage to the iframe.
|
|
33
|
+
*/
|
|
34
|
+
export type SerializedKeybindingConfig = {
|
|
35
|
+
overrides?: ShortcutOverride[];
|
|
36
|
+
custom?: SerializedCustomShortcut[];
|
|
37
|
+
};
|
|
2
38
|
export type IframeOriginAckCommand = {
|
|
3
39
|
type: "origin-ack";
|
|
4
40
|
};
|
|
@@ -21,6 +57,10 @@ export type IframeInstallExtensionCommand = {
|
|
|
21
57
|
type: "install-extension";
|
|
22
58
|
payload: Array<string | File>;
|
|
23
59
|
};
|
|
60
|
+
export type IframeSetKeybindingConfigCommand = {
|
|
61
|
+
type: "set-keybinding-config";
|
|
62
|
+
payload: SerializedKeybindingConfig;
|
|
63
|
+
};
|
|
24
64
|
export type IframeHandshakeAckCommand = {
|
|
25
65
|
type: "handshake-ack";
|
|
26
66
|
payload: {
|
|
@@ -29,9 +69,10 @@ export type IframeHandshakeAckCommand = {
|
|
|
29
69
|
initialLayout?: OpaqueLayoutData;
|
|
30
70
|
initialLayoutParams?: SelectLayoutParams;
|
|
31
71
|
initialExtensions: Array<string | File>;
|
|
72
|
+
initialKeybindingsConfig?: SerializedKeybindingConfig;
|
|
32
73
|
};
|
|
33
74
|
};
|
|
34
|
-
export type IframeCommand = IframeOriginAckCommand | IframeSetDatasourceCommand | IframeSetLayoutCommand | IframeSelectLayoutCommand | IframeGetLayoutCommand | IframeInstallExtensionCommand | IframeHandshakeAckCommand;
|
|
75
|
+
export type IframeCommand = IframeOriginAckCommand | IframeSetDatasourceCommand | IframeSetLayoutCommand | IframeSelectLayoutCommand | IframeGetLayoutCommand | IframeInstallExtensionCommand | IframeSetKeybindingConfigCommand | IframeHandshakeAckCommand;
|
|
35
76
|
export type IframeEvent = {
|
|
36
77
|
type: "foxglove-origin-request";
|
|
37
78
|
} | {
|
|
@@ -44,5 +85,11 @@ export type IframeEvent = {
|
|
|
44
85
|
} | {
|
|
45
86
|
type: "foxglove-layout-data";
|
|
46
87
|
payload: OpaqueLayoutData;
|
|
88
|
+
} | {
|
|
89
|
+
type: "foxglove-keybinding-triggered";
|
|
90
|
+
payload: {
|
|
91
|
+
keybindingId: string;
|
|
92
|
+
};
|
|
47
93
|
};
|
|
94
|
+
export {};
|
|
48
95
|
//# sourceMappingURL=commands.d.ts.map
|
package/dist/commands.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"commands.d.ts","sourceRoot":"","sources":["../src/commands.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"commands.d.ts","sourceRoot":"","sources":["../src/commands.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EACV,UAAU,EACV,iBAAiB,EACjB,gBAAgB,EAChB,kBAAkB,EAClB,cAAc,EACf,MAAM,YAAY,CAAC;AAEpB;;;;;;;GAOG;AACH,KAAK,gBAAgB,GAAG;IACtB,yCAAyC;IACzC,EAAE,EAAE,iBAAiB,CAAC;IACtB,kEAAkE;IAElE,OAAO,EAAE,cAAc,GAAG,IAAI,CAAC;CAChC,CAAC;AAEF;;;GAGG;AACH,KAAK,wBAAwB,GAAG;IAC9B,kFAAkF;IAClF,EAAE,EAAE,MAAM,CAAC;IACX,yCAAyC;IACzC,OAAO,EAAE,cAAc,CAAC;CACzB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,0BAA0B,GAAG;IACvC,SAAS,CAAC,EAAE,gBAAgB,EAAE,CAAC;IAC/B,MAAM,CAAC,EAAE,wBAAwB,EAAE,CAAC;CACrC,CAAC;AAEF,MAAM,MAAM,sBAAsB,GAAG;IACnC,IAAI,EAAE,YAAY,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,0BAA0B,GAAG;IACvC,IAAI,EAAE,iBAAiB,CAAC;IACxB,OAAO,EAAE,UAAU,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,sBAAsB,GAAG;IACnC,IAAI,EAAE,YAAY,CAAC;IACnB,OAAO,EAAE,gBAAgB,CAAC;CAC3B,CAAC;AAEF,MAAM,MAAM,yBAAyB,GAAG;IACtC,IAAI,EAAE,eAAe,CAA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AC;IAAC,OAAO,EAAE;QAAE,YAAY,EAAE,MAAM,CAAA;KAAE,CAAA;CAAE,CAAC"}
|
package/dist/commands.js
CHANGED
package/dist/commands.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"commands.js","sourceRoot":"","sources":["../src/commands.ts"],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"file":"commands.js","sourceRoot":"","sources":["../src/commands.ts"],"names":[],"mappings":"AAAA;;;;GAIG"}
|
package/dist/types.d.ts
CHANGED
|
@@ -56,6 +56,84 @@ export type FoxgloveViewerEventMap = {
|
|
|
56
56
|
ready: Event;
|
|
57
57
|
error: CustomEvent<string>;
|
|
58
58
|
};
|
|
59
|
+
/**
|
|
60
|
+
* A modifier key that must be held alongside the primary key.
|
|
61
|
+
*
|
|
62
|
+
* `"PrimaryModifier"` resolves to Command on macOS and Control on other platforms.
|
|
63
|
+
*/
|
|
64
|
+
export type ShortcutModifier = "Meta" | "Control" | "Alt" | "Shift" | "PrimaryModifier";
|
|
65
|
+
/**
|
|
66
|
+
* Valid `event.key` values for key bindings matched by logical key.
|
|
67
|
+
*
|
|
68
|
+
* Only unmodified key values are allowed — these are the values produced
|
|
69
|
+
* without holding Shift or AltGr. This ensures the browser's Keyboard API
|
|
70
|
+
* (`navigator.keyboard.getLayoutMap()`) can resolve them across layouts.
|
|
71
|
+
*
|
|
72
|
+
* @see https://www.w3.org/TR/uievents-key/
|
|
73
|
+
*/
|
|
74
|
+
export type EventKeyValue = "a" | "b" | "c" | "d" | "e" | "f" | "g" | "h" | "i" | "j" | "k" | "l" | "m" | "n" | "o" | "p" | "q" | "r" | "s" | "t" | "u" | "v" | "w" | "x" | "y" | "z" | "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" | "-" | "=" | "[" | "]" | "\\" | ";" | "'" | "`" | "," | "." | "/" | "Enter" | "Escape" | "Backspace" | "Tab" | " " | "Delete" | "Insert" | "Home" | "End" | "PageUp" | "PageDown" | "ArrowUp" | "ArrowDown" | "ArrowLeft" | "ArrowRight" | "CapsLock" | "F1" | "F2" | "F3" | "F4" | "F5" | "F6" | "F7" | "F8" | "F9" | "F10" | "F11" | "F12" | "F13" | "F14" | "F15" | "F16" | "F17" | "F18" | "F19" | "F20" | "F21" | "F22" | "F23" | "F24";
|
|
75
|
+
/**
|
|
76
|
+
* Valid `event.code` values for key bindings matched by physical key code.
|
|
77
|
+
*
|
|
78
|
+
* @see https://www.w3.org/TR/uievents-code/
|
|
79
|
+
*/
|
|
80
|
+
export type EventCodeValue = "KeyA" | "KeyB" | "KeyC" | "KeyD" | "KeyE" | "KeyF" | "KeyG" | "KeyH" | "KeyI" | "KeyJ" | "KeyK" | "KeyL" | "KeyM" | "KeyN" | "KeyO" | "KeyP" | "KeyQ" | "KeyR" | "KeyS" | "KeyT" | "KeyU" | "KeyV" | "KeyW" | "KeyX" | "KeyY" | "KeyZ" | "Digit0" | "Digit1" | "Digit2" | "Digit3" | "Digit4" | "Digit5" | "Digit6" | "Digit7" | "Digit8" | "Digit9" | "Minus" | "Equal" | "BracketLeft" | "BracketRight" | "Backslash" | "Semicolon" | "Quote" | "Backquote" | "Comma" | "Period" | "Slash" | "Enter" | "Escape" | "Backspace" | "Tab" | "Space" | "Delete" | "Insert" | "Home" | "End" | "PageUp" | "PageDown" | "ArrowUp" | "ArrowDown" | "ArrowLeft" | "ArrowRight" | "CapsLock" | "F1" | "F2" | "F3" | "F4" | "F5" | "F6" | "F7" | "F8" | "F9" | "F10" | "F11" | "F12" | "F13" | "F14" | "F15" | "F16" | "F17" | "F18" | "F19" | "F20" | "F21" | "F22" | "F23" | "F24";
|
|
81
|
+
export type FoxgloveCommandId = "player.togglePlayback" | "player.seekBackwardMedium" | "player.seekForwardMedium" | "player.seekBackwardSmall" | "player.seekForwardSmall" | "player.seekBackwardLarge" | "player.seekForwardLarge" | "player.seekStart" | "player.seekEnd" | "player.speedUp" | "player.speedDown" | "player.createEvent" | "panel.threeDee.togglePerspective" | "panel.threeDee.resetCamera" | "panel.threeDee.toggleInspector" | "panel.threeDee.moveForward" | "panel.threeDee.moveLeft" | "panel.threeDee.moveBackward" | "panel.threeDee.moveRight" | "panel.threeDee.rotateUp" | "panel.threeDee.rotateDown" | "panel.threeDee.rotateLeft" | "panel.threeDee.rotateRight" | "sidebar.left.toggleVisibility" | "sidebar.right.toggleVisibility";
|
|
82
|
+
/**
|
|
83
|
+
* A key that triggers a keybinding.
|
|
84
|
+
*
|
|
85
|
+
* Physical key codes like `"KeyW"` match by physical position (layout-independent).
|
|
86
|
+
*
|
|
87
|
+
* Character keys like `"p"` match by the character produced (layout-dependent).
|
|
88
|
+
*
|
|
89
|
+
* Named keys like `"Escape"` are unambiguous — identical in both modes.
|
|
90
|
+
*/
|
|
91
|
+
export type ShortcutKey = EventKeyValue | EventCodeValue;
|
|
92
|
+
/**
|
|
93
|
+
* A key combination consisting of a {@link ShortcutKey} plus optional modifier keys.
|
|
94
|
+
*
|
|
95
|
+
* Physical key codes like `"KeyW"`, `"Space"` match by `event.code` (physical position).
|
|
96
|
+
*
|
|
97
|
+
* Character keys like `"p"`, `" "` match by `event.key` (logical key).
|
|
98
|
+
*
|
|
99
|
+
* Named keys like `"Escape"`, `"Enter"` are layout-independent and matched by `event.key`.
|
|
100
|
+
* `"PrimaryModifier"` resolves to Command on macOS and Control elsewhere.
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
* // Match by character `a` and modifier `PrimaryModifier` (Command on macOS, Control elsewhere)
|
|
104
|
+
* // The key will depend on the keyboard layout. On a QWERTY layout, this will match the key to the left of the S key.
|
|
105
|
+
* // On an AZERTY layout, this will match the key to the left of the Z key.
|
|
106
|
+
* { key: "a", modifiers: ["PrimaryModifier"] }
|
|
107
|
+
*
|
|
108
|
+
* // Match by physical key code `KeyA` and modifier `PrimaryModifier` (Command on macOS, Control elsewhere)
|
|
109
|
+
* // The key won't depend on the keyboard layout. On a QWERTY layout, this will match the key to the left of the A key.
|
|
110
|
+
* // On an AZERTY layout, this will match the key to the left of the S key.
|
|
111
|
+
* { key: "KeyA", modifiers: ["PrimaryModifier"] }
|
|
112
|
+
*
|
|
113
|
+
* // Match by named key `Escape`. This is layout-independent and will match the same key regardless of the keyboard layout.
|
|
114
|
+
* { key: "Escape" }
|
|
115
|
+
*
|
|
116
|
+
* @see ShortcutKey
|
|
117
|
+
*/
|
|
118
|
+
export interface KeybindingBase {
|
|
119
|
+
/** The key that triggers this keybinding. */
|
|
120
|
+
key: ShortcutKey;
|
|
121
|
+
/** Modifier keys required alongside the primary key. Defaults to no modifiers if omitted. */
|
|
122
|
+
modifiers?: ShortcutModifier[];
|
|
123
|
+
}
|
|
124
|
+
export interface CommandKeybinding extends KeybindingBase {
|
|
125
|
+
/** A built-in viewer command to invoke, or `"noop"` to suppress the key without action. */
|
|
126
|
+
command: FoxgloveCommandId | "noop";
|
|
127
|
+
}
|
|
128
|
+
export interface HandlerKeybinding extends KeybindingBase {
|
|
129
|
+
/** A function to call when the key combination is pressed. */
|
|
130
|
+
handler: () => void;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* A keybinding defines a key combination that triggers a built-in
|
|
134
|
+
* viewer command or a custom handler function.
|
|
135
|
+
*/
|
|
136
|
+
export type Keybinding = CommandKeybinding | HandlerKeybinding;
|
|
59
137
|
export type FoxgloveViewerEventType = keyof FoxgloveViewerEventMap;
|
|
60
138
|
export type SelectLayoutParams = {
|
|
61
139
|
/**
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAEpD,cAAc,uBAAuB,CAAC;AAEtC;;;GAGG;AACH,MAAM,MAAM,gBAAgB,GAAG,OAAO,CAAC;AAEvC,MAAM,MAAM,eAAe,GAAG;IAC5B,IAAI,EAAE,WAAW,CAAC;IA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EAAE,gBAAgB,EAAE,CAAC;CAChC;AAED,MAAM,WAAW,iBAAkB,SAAQ,cAAc;IACvD,2FAA2F;IAC3F,OAAO,EAAE,iBAAiB,GAAG,MAAM,CAAC;CACrC;AAED,MAAM,WAAW,iBAAkB,SAAQ,cAAc;IACvD,8DAA8D;IAC9D,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB;AAED;;;GAGG;AACH,MAAM,MAAM,UAAU,GAAG,iBAAiB,GAAG,iBAAiB,CAAC;AAE/D,MAAM,MAAM,uBAAuB,GAAG,MAAM,sBAAsB,CAAC;AAEnE,MAAM,MAAM,kBAAkB,GAC1B;IACE;;;SAGK;IACL,UAAU,EAAE,MAAM,CAAC;IACnB;;;;SAIK;IACL,YAAY,CAAC,EAAE,gBAAgB,CAAC;IAChC,4FAA4F;IAC5F,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB,GACD;IACE;;;SAGK;IACL,UAAU,EAAE,MAAM,CAAC;IACnB;;;SAGK;IACL,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,sFAAsF;IACtF,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB,CAAC"}
|
package/package.json
CHANGED
package/src/FoxgloveViewer.ts
CHANGED
|
@@ -9,14 +9,18 @@ import type {
|
|
|
9
9
|
IframeOriginAckCommand,
|
|
10
10
|
IframeSelectLayoutCommand,
|
|
11
11
|
IframeSetDatasourceCommand,
|
|
12
|
+
IframeSetKeybindingConfigCommand,
|
|
12
13
|
IframeSetLayoutCommand,
|
|
14
|
+
SerializedKeybindingConfig,
|
|
13
15
|
} from "./commands.ts";
|
|
14
16
|
import type {
|
|
15
17
|
DataSource,
|
|
16
18
|
FoxgloveViewerEventMap,
|
|
17
19
|
FoxgloveViewerEventType,
|
|
20
|
+
Keybinding,
|
|
18
21
|
OpaqueLayoutData,
|
|
19
22
|
SelectLayoutParams,
|
|
23
|
+
KeybindingBase,
|
|
20
24
|
} from "./types.ts";
|
|
21
25
|
|
|
22
26
|
interface FoxgloveEventTarget extends EventTarget {
|
|
@@ -96,9 +100,41 @@ export type FoxgloveViewerOptions = {
|
|
|
96
100
|
|
|
97
101
|
/**
|
|
98
102
|
* Identifies the embedding SDK client for analytics purposes. This should be set by SDK
|
|
99
|
-
* libraries (
|
|
103
|
+
* libraries (such as the Python SDK) to identify the embedding context.
|
|
100
104
|
*/
|
|
101
105
|
embeddedViewer?: EmbeddedViewer;
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Custom keybindings for the embedded viewer.
|
|
109
|
+
*
|
|
110
|
+
* Overrides default keybindings and registers custom handlers.
|
|
111
|
+
*
|
|
112
|
+
* Custom keybindings take priority over the viewer's default bindings. If multiple keybindings
|
|
113
|
+
* share the same key + modifiers, the first one in the list wins and the rest are ignored.
|
|
114
|
+
*
|
|
115
|
+
* @example
|
|
116
|
+
* [
|
|
117
|
+
* // Register a custom keybinding
|
|
118
|
+
* {
|
|
119
|
+
* key: "s",
|
|
120
|
+
* modifiers: ["Control", "Shift"],
|
|
121
|
+
* handler: () => {
|
|
122
|
+
* console.log("Custom keybinding triggered: take-snapshot");
|
|
123
|
+
* },
|
|
124
|
+
* },
|
|
125
|
+
* // Configure the "p" key to trigger the "player.togglePlayback" command
|
|
126
|
+
* {
|
|
127
|
+
* key: "p",
|
|
128
|
+
* command: "player.togglePlayback",
|
|
129
|
+
* },
|
|
130
|
+
* // Suppress a built-in keybinding
|
|
131
|
+
* {
|
|
132
|
+
* key: "[",
|
|
133
|
+
* command: "noop",
|
|
134
|
+
* },
|
|
135
|
+
* ]
|
|
136
|
+
*/
|
|
137
|
+
keybindings?: Keybinding[];
|
|
102
138
|
};
|
|
103
139
|
|
|
104
140
|
/**
|
|
@@ -118,16 +154,20 @@ export class FoxgloveViewer extends TypedEventTarget {
|
|
|
118
154
|
dataSource: IframeSetDatasourceCommand | undefined;
|
|
119
155
|
selectLayout: IframeSelectLayoutCommand | undefined;
|
|
120
156
|
extension: Array<IframeInstallExtensionCommand>;
|
|
157
|
+
keybindings: IframeSetKeybindingConfigCommand | undefined;
|
|
121
158
|
} = {
|
|
122
159
|
dataSource: undefined,
|
|
123
160
|
selectLayout: undefined,
|
|
124
161
|
extension: [],
|
|
162
|
+
keybindings: undefined,
|
|
125
163
|
};
|
|
126
164
|
/**
|
|
127
165
|
* If a layout export request has been made, this holds the promise that will be resolved when a
|
|
128
166
|
* response is received from the embed
|
|
129
167
|
*/
|
|
130
168
|
#getLayoutPromise?: PromiseWithResolvers<OpaqueLayoutData>;
|
|
169
|
+
/** Maps auto-generated custom keybinding IDs to user-provided handlers. */
|
|
170
|
+
#customKeybindingHandlers = new Map<string, () => void>();
|
|
131
171
|
/** Whether the frame has been destroyed. */
|
|
132
172
|
#isDestroyed = false;
|
|
133
173
|
|
|
@@ -143,6 +183,7 @@ export class FoxgloveViewer extends TypedEventTarget {
|
|
|
143
183
|
initialExtensions,
|
|
144
184
|
colorScheme = "auto",
|
|
145
185
|
embeddedViewer,
|
|
186
|
+
keybindings,
|
|
146
187
|
} = options;
|
|
147
188
|
|
|
148
189
|
this.#orgSlug = orgSlug;
|
|
@@ -181,11 +222,17 @@ export class FoxgloveViewer extends TypedEventTarget {
|
|
|
181
222
|
this.installExtensions(initialExtensions);
|
|
182
223
|
}
|
|
183
224
|
|
|
225
|
+
if (keybindings != undefined) {
|
|
226
|
+
this.setKeybindings(keybindings);
|
|
227
|
+
}
|
|
228
|
+
|
|
184
229
|
// Create the iframe element.
|
|
185
230
|
this.#iframe = document.createElement("iframe");
|
|
186
231
|
this.#iframe.src = this.#server.href;
|
|
187
232
|
this.#iframe.title = "Foxglove";
|
|
188
|
-
|
|
233
|
+
// keyboard-map is required so the iframe can use navigator.keyboard.getLayoutMap()
|
|
234
|
+
// to detect the user's keyboard layout for correct shortcut handling.
|
|
235
|
+
this.#iframe.allow = "cross-origin-isolated; keyboard-map *";
|
|
189
236
|
this.#iframe.style.width = "100%";
|
|
190
237
|
this.#iframe.style.height = "100%";
|
|
191
238
|
this.#iframe.style.border = "none";
|
|
@@ -304,6 +351,48 @@ export class FoxgloveViewer extends TypedEventTarget {
|
|
|
304
351
|
});
|
|
305
352
|
}
|
|
306
353
|
|
|
354
|
+
/**
|
|
355
|
+
* Customize keybinding configuration for this viewer instance.
|
|
356
|
+
*
|
|
357
|
+
* Custom keybindings take priority over the viewer's default bindings. If multiple keybindings
|
|
358
|
+
* share the same key, the first one in the list wins and the rest are ignored. Each call fully
|
|
359
|
+
* replaces the previous configuration. Calling with an empty array restores the viewer's default
|
|
360
|
+
* keybindings and clears all custom keybindings.
|
|
361
|
+
*
|
|
362
|
+
* @example
|
|
363
|
+
* viewer.setKeybindings([
|
|
364
|
+
* // Register a keybinding to trigger a custom function
|
|
365
|
+
* {
|
|
366
|
+
* key: "s",
|
|
367
|
+
* modifiers: ["Control", "Shift"],
|
|
368
|
+
* handler: () => {
|
|
369
|
+
* console.log("Custom keybinding triggered: take-snapshot");
|
|
370
|
+
* },
|
|
371
|
+
* },
|
|
372
|
+
* // Configure the "p" key to trigger the "player.togglePlayback" command
|
|
373
|
+
* {
|
|
374
|
+
* key: "p",
|
|
375
|
+
* command: "player.togglePlayback",
|
|
376
|
+
* },
|
|
377
|
+
* // Suppress a built-in keybinding
|
|
378
|
+
* {
|
|
379
|
+
* key: "[",
|
|
380
|
+
* command: "noop",
|
|
381
|
+
* },
|
|
382
|
+
* ]);
|
|
383
|
+
*
|
|
384
|
+
* // Restore the viewer's default keybindings
|
|
385
|
+
* viewer.setKeybindings([]);
|
|
386
|
+
*
|
|
387
|
+
*/
|
|
388
|
+
public setKeybindings(keybindings: Keybinding[]): void {
|
|
389
|
+
const serialized = this.#serializeKeybindings(keybindings);
|
|
390
|
+
this.#queueCommand({
|
|
391
|
+
type: "set-keybinding-config",
|
|
392
|
+
payload: serialized,
|
|
393
|
+
});
|
|
394
|
+
}
|
|
395
|
+
|
|
307
396
|
/** Whether the frame is ready to receive commands. */
|
|
308
397
|
public isReady(): boolean {
|
|
309
398
|
return this.#isReady;
|
|
@@ -329,6 +418,48 @@ export class FoxgloveViewer extends TypedEventTarget {
|
|
|
329
418
|
this.#iframe.style.colorScheme = colorScheme === "auto" ? "inherit" : colorScheme;
|
|
330
419
|
}
|
|
331
420
|
|
|
421
|
+
/**
|
|
422
|
+
* Converts the public flat `Keybinding[]` into the internal wire format
|
|
423
|
+
* (`SerializedKeybindingConfig`) for postMessage, decomposing keybindings
|
|
424
|
+
* into overrides and custom shortcuts.
|
|
425
|
+
*
|
|
426
|
+
* - `CommandKeybinding` (non-noop) becomes a `ShortcutOverride`
|
|
427
|
+
* - `HandlerKeybinding` becomes a `SerializedCustomShortcut` with a stored handler
|
|
428
|
+
* - `CommandKeybinding` with `"noop"` becomes a `SerializedCustomShortcut` with
|
|
429
|
+
* no stored handler — it claims the key slot to suppress defaults
|
|
430
|
+
*
|
|
431
|
+
* Handler keybindings are serialized before noop keybindings so that handlers
|
|
432
|
+
* win conflicts over noop suppressions.
|
|
433
|
+
*/
|
|
434
|
+
#serializeKeybindings(keybindings: Keybinding[]): SerializedKeybindingConfig {
|
|
435
|
+
this.#customKeybindingHandlers.clear();
|
|
436
|
+
|
|
437
|
+
const overrides: Required<SerializedKeybindingConfig>["overrides"] = [];
|
|
438
|
+
const handlerCustom: Required<SerializedKeybindingConfig>["custom"] = [];
|
|
439
|
+
const noopCustom: Required<SerializedKeybindingConfig>["custom"] = [];
|
|
440
|
+
|
|
441
|
+
for (const kb of keybindings) {
|
|
442
|
+
const binding: KeybindingBase = { key: kb.key, modifiers: kb.modifiers };
|
|
443
|
+
|
|
444
|
+
const prefix = [...(kb.modifiers ?? []), kb.key].join("+");
|
|
445
|
+
if ("handler" in kb) {
|
|
446
|
+
const id = `${prefix}-${crypto.randomUUID()}`;
|
|
447
|
+
this.#customKeybindingHandlers.set(id, kb.handler);
|
|
448
|
+
handlerCustom.push({ id, binding });
|
|
449
|
+
} else if (kb.command === "noop") {
|
|
450
|
+
const id = `noop-${prefix}-${crypto.randomUUID()}`;
|
|
451
|
+
noopCustom.push({ id, binding });
|
|
452
|
+
} else {
|
|
453
|
+
overrides.push({ id: kb.command, binding });
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
return {
|
|
458
|
+
overrides,
|
|
459
|
+
custom: [...handlerCustom, ...noopCustom],
|
|
460
|
+
};
|
|
461
|
+
}
|
|
462
|
+
|
|
332
463
|
/**
|
|
333
464
|
* Queue a command to be executed when the frame is ready.
|
|
334
465
|
*
|
|
@@ -356,6 +487,9 @@ export class FoxgloveViewer extends TypedEventTarget {
|
|
|
356
487
|
case "select-layout":
|
|
357
488
|
this.#latestCommands.selectLayout = command;
|
|
358
489
|
break;
|
|
490
|
+
case "set-keybinding-config":
|
|
491
|
+
this.#latestCommands.keybindings = command;
|
|
492
|
+
break;
|
|
359
493
|
}
|
|
360
494
|
|
|
361
495
|
if (this.#isReady) {
|
|
@@ -404,6 +538,7 @@ export class FoxgloveViewer extends TypedEventTarget {
|
|
|
404
538
|
initialDataSource: this.#latestCommands.dataSource?.payload,
|
|
405
539
|
initialLayoutParams: this.#latestCommands.selectLayout?.payload,
|
|
406
540
|
initialExtensions: this.#latestCommands.extension.flatMap((command) => command.payload),
|
|
541
|
+
initialKeybindingsConfig: this.#latestCommands.keybindings?.payload,
|
|
407
542
|
},
|
|
408
543
|
});
|
|
409
544
|
|
|
@@ -430,6 +565,12 @@ export class FoxgloveViewer extends TypedEventTarget {
|
|
|
430
565
|
}
|
|
431
566
|
break;
|
|
432
567
|
|
|
568
|
+
case "foxglove-keybinding-triggered": {
|
|
569
|
+
const handler = this.#customKeybindingHandlers.get(message.data.payload.keybindingId);
|
|
570
|
+
handler?.();
|
|
571
|
+
break;
|
|
572
|
+
}
|
|
573
|
+
|
|
433
574
|
default:
|
|
434
575
|
console.warn("[FoxgloveViewer] Unhandled message type:", message.data);
|
|
435
576
|
break;
|
package/src/commands.ts
CHANGED
|
@@ -1,4 +1,51 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* This file contains type definitions to define the communication protocol between the parent page and the embedded iframe.
|
|
3
|
+
*
|
|
4
|
+
* These type are only meant for internal usage and are bound to change without notice.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import type {
|
|
8
|
+
DataSource,
|
|
9
|
+
FoxgloveCommandId,
|
|
10
|
+
OpaqueLayoutData,
|
|
11
|
+
SelectLayoutParams,
|
|
12
|
+
KeybindingBase,
|
|
13
|
+
} from "./types.ts";
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Override or disable a built-in viewer shortcut.
|
|
17
|
+
*
|
|
18
|
+
* Provide a `binding` to remap the shortcut, or `null` to disable it.
|
|
19
|
+
*
|
|
20
|
+
* When multiple overrides share the same binding, the first one in the list wins
|
|
21
|
+
* and the rest are cleared.
|
|
22
|
+
*/
|
|
23
|
+
type ShortcutOverride = {
|
|
24
|
+
/** The built-in shortcut to override. */
|
|
25
|
+
id: FoxgloveCommandId;
|
|
26
|
+
/** The new key combination, or `null` to disable the shortcut. */
|
|
27
|
+
// eslint-disable-next-line no-restricted-syntax -- Use null to clear a shortcut
|
|
28
|
+
binding: KeybindingBase | null;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Serializable representation of a custom shortcut used for postMessage communication
|
|
33
|
+
* between the parent page and the embedded iframe.
|
|
34
|
+
*/
|
|
35
|
+
type SerializedCustomShortcut = {
|
|
36
|
+
/** Auto-generated identifier used to correlate iframe events back to handlers. */
|
|
37
|
+
id: string;
|
|
38
|
+
/** The key combination to listen for. */
|
|
39
|
+
binding: KeybindingBase;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Serializable keybinding configuration sent over postMessage to the iframe.
|
|
44
|
+
*/
|
|
45
|
+
export type SerializedKeybindingConfig = {
|
|
46
|
+
overrides?: ShortcutOverride[];
|
|
47
|
+
custom?: SerializedCustomShortcut[];
|
|
48
|
+
};
|
|
2
49
|
|
|
3
50
|
export type IframeOriginAckCommand = {
|
|
4
51
|
type: "origin-ack";
|
|
@@ -28,6 +75,11 @@ export type IframeInstallExtensionCommand = {
|
|
|
28
75
|
payload: Array<string | File>;
|
|
29
76
|
};
|
|
30
77
|
|
|
78
|
+
export type IframeSetKeybindingConfigCommand = {
|
|
79
|
+
type: "set-keybinding-config";
|
|
80
|
+
payload: SerializedKeybindingConfig;
|
|
81
|
+
};
|
|
82
|
+
|
|
31
83
|
export type IframeHandshakeAckCommand = {
|
|
32
84
|
type: "handshake-ack";
|
|
33
85
|
payload: {
|
|
@@ -36,6 +88,7 @@ export type IframeHandshakeAckCommand = {
|
|
|
36
88
|
initialLayout?: OpaqueLayoutData;
|
|
37
89
|
initialLayoutParams?: SelectLayoutParams;
|
|
38
90
|
initialExtensions: Array<string | File>;
|
|
91
|
+
initialKeybindingsConfig?: SerializedKeybindingConfig;
|
|
39
92
|
};
|
|
40
93
|
};
|
|
41
94
|
|
|
@@ -46,6 +99,7 @@ export type IframeCommand =
|
|
|
46
99
|
| IframeSelectLayoutCommand
|
|
47
100
|
| IframeGetLayoutCommand
|
|
48
101
|
| IframeInstallExtensionCommand
|
|
102
|
+
| IframeSetKeybindingConfigCommand
|
|
49
103
|
| IframeHandshakeAckCommand;
|
|
50
104
|
|
|
51
105
|
export type IframeEvent =
|
|
@@ -53,4 +107,5 @@ export type IframeEvent =
|
|
|
53
107
|
| { type: "foxglove-handshake-request" }
|
|
54
108
|
| { type: "foxglove-handshake-complete" }
|
|
55
109
|
| { type: "foxglove-error"; payload: string }
|
|
56
|
-
| { type: "foxglove-layout-data"; payload: OpaqueLayoutData }
|
|
110
|
+
| { type: "foxglove-layout-data"; payload: OpaqueLayoutData }
|
|
111
|
+
| { type: "foxglove-keybinding-triggered"; payload: { keybindingId: string } };
|
package/src/types.ts
CHANGED
|
@@ -74,6 +74,306 @@ export type FoxgloveViewerEventMap = {
|
|
|
74
74
|
error: CustomEvent<string>;
|
|
75
75
|
};
|
|
76
76
|
|
|
77
|
+
/**
|
|
78
|
+
* A modifier key that must be held alongside the primary key.
|
|
79
|
+
*
|
|
80
|
+
* `"PrimaryModifier"` resolves to Command on macOS and Control on other platforms.
|
|
81
|
+
*/
|
|
82
|
+
export type ShortcutModifier = "Meta" | "Control" | "Alt" | "Shift" | "PrimaryModifier";
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Valid `event.key` values for key bindings matched by logical key.
|
|
86
|
+
*
|
|
87
|
+
* Only unmodified key values are allowed — these are the values produced
|
|
88
|
+
* without holding Shift or AltGr. This ensures the browser's Keyboard API
|
|
89
|
+
* (`navigator.keyboard.getLayoutMap()`) can resolve them across layouts.
|
|
90
|
+
*
|
|
91
|
+
* @see https://www.w3.org/TR/uievents-key/
|
|
92
|
+
*/
|
|
93
|
+
export type EventKeyValue =
|
|
94
|
+
// Letters (lowercase only — normalizeKey lowercases uppercase)
|
|
95
|
+
| "a"
|
|
96
|
+
| "b"
|
|
97
|
+
| "c"
|
|
98
|
+
| "d"
|
|
99
|
+
| "e"
|
|
100
|
+
| "f"
|
|
101
|
+
| "g"
|
|
102
|
+
| "h"
|
|
103
|
+
| "i"
|
|
104
|
+
| "j"
|
|
105
|
+
| "k"
|
|
106
|
+
| "l"
|
|
107
|
+
| "m"
|
|
108
|
+
| "n"
|
|
109
|
+
| "o"
|
|
110
|
+
| "p"
|
|
111
|
+
| "q"
|
|
112
|
+
| "r"
|
|
113
|
+
| "s"
|
|
114
|
+
| "t"
|
|
115
|
+
| "u"
|
|
116
|
+
| "v"
|
|
117
|
+
| "w"
|
|
118
|
+
| "x"
|
|
119
|
+
| "y"
|
|
120
|
+
| "z"
|
|
121
|
+
// Digits
|
|
122
|
+
| "0"
|
|
123
|
+
| "1"
|
|
124
|
+
| "2"
|
|
125
|
+
| "3"
|
|
126
|
+
| "4"
|
|
127
|
+
| "5"
|
|
128
|
+
| "6"
|
|
129
|
+
| "7"
|
|
130
|
+
| "8"
|
|
131
|
+
| "9"
|
|
132
|
+
// Punctuation (US QWERTY unmodified)
|
|
133
|
+
| "-"
|
|
134
|
+
| "="
|
|
135
|
+
| "["
|
|
136
|
+
| "]"
|
|
137
|
+
| "\\"
|
|
138
|
+
| ";"
|
|
139
|
+
| "'"
|
|
140
|
+
| "`"
|
|
141
|
+
| ","
|
|
142
|
+
| "."
|
|
143
|
+
| "/"
|
|
144
|
+
// Editing & whitespace
|
|
145
|
+
| "Enter"
|
|
146
|
+
| "Escape"
|
|
147
|
+
| "Backspace"
|
|
148
|
+
| "Tab"
|
|
149
|
+
| " "
|
|
150
|
+
| "Delete"
|
|
151
|
+
| "Insert"
|
|
152
|
+
// Navigation
|
|
153
|
+
| "Home"
|
|
154
|
+
| "End"
|
|
155
|
+
| "PageUp"
|
|
156
|
+
| "PageDown"
|
|
157
|
+
| "ArrowUp"
|
|
158
|
+
| "ArrowDown"
|
|
159
|
+
| "ArrowLeft"
|
|
160
|
+
| "ArrowRight"
|
|
161
|
+
// Lock keys
|
|
162
|
+
| "CapsLock"
|
|
163
|
+
// Function keys
|
|
164
|
+
| "F1"
|
|
165
|
+
| "F2"
|
|
166
|
+
| "F3"
|
|
167
|
+
| "F4"
|
|
168
|
+
| "F5"
|
|
169
|
+
| "F6"
|
|
170
|
+
| "F7"
|
|
171
|
+
| "F8"
|
|
172
|
+
| "F9"
|
|
173
|
+
| "F10"
|
|
174
|
+
| "F11"
|
|
175
|
+
| "F12"
|
|
176
|
+
| "F13"
|
|
177
|
+
| "F14"
|
|
178
|
+
| "F15"
|
|
179
|
+
| "F16"
|
|
180
|
+
| "F17"
|
|
181
|
+
| "F18"
|
|
182
|
+
| "F19"
|
|
183
|
+
| "F20"
|
|
184
|
+
| "F21"
|
|
185
|
+
| "F22"
|
|
186
|
+
| "F23"
|
|
187
|
+
| "F24";
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Valid `event.code` values for key bindings matched by physical key code.
|
|
191
|
+
*
|
|
192
|
+
* @see https://www.w3.org/TR/uievents-code/
|
|
193
|
+
*/
|
|
194
|
+
export type EventCodeValue =
|
|
195
|
+
// Layout-dependent (letters)
|
|
196
|
+
| "KeyA"
|
|
197
|
+
| "KeyB"
|
|
198
|
+
| "KeyC"
|
|
199
|
+
| "KeyD"
|
|
200
|
+
| "KeyE"
|
|
201
|
+
| "KeyF"
|
|
202
|
+
| "KeyG"
|
|
203
|
+
| "KeyH"
|
|
204
|
+
| "KeyI"
|
|
205
|
+
| "KeyJ"
|
|
206
|
+
| "KeyK"
|
|
207
|
+
| "KeyL"
|
|
208
|
+
| "KeyM"
|
|
209
|
+
| "KeyN"
|
|
210
|
+
| "KeyO"
|
|
211
|
+
| "KeyP"
|
|
212
|
+
| "KeyQ"
|
|
213
|
+
| "KeyR"
|
|
214
|
+
| "KeyS"
|
|
215
|
+
| "KeyT"
|
|
216
|
+
| "KeyU"
|
|
217
|
+
| "KeyV"
|
|
218
|
+
| "KeyW"
|
|
219
|
+
| "KeyX"
|
|
220
|
+
| "KeyY"
|
|
221
|
+
| "KeyZ"
|
|
222
|
+
// Layout-dependent (digits)
|
|
223
|
+
| "Digit0"
|
|
224
|
+
| "Digit1"
|
|
225
|
+
| "Digit2"
|
|
226
|
+
| "Digit3"
|
|
227
|
+
| "Digit4"
|
|
228
|
+
| "Digit5"
|
|
229
|
+
| "Digit6"
|
|
230
|
+
| "Digit7"
|
|
231
|
+
| "Digit8"
|
|
232
|
+
| "Digit9"
|
|
233
|
+
// Layout-dependent (punctuation)
|
|
234
|
+
| "Minus"
|
|
235
|
+
| "Equal"
|
|
236
|
+
| "BracketLeft"
|
|
237
|
+
| "BracketRight"
|
|
238
|
+
| "Backslash"
|
|
239
|
+
| "Semicolon"
|
|
240
|
+
| "Quote"
|
|
241
|
+
| "Backquote"
|
|
242
|
+
| "Comma"
|
|
243
|
+
| "Period"
|
|
244
|
+
| "Slash"
|
|
245
|
+
// Editing & whitespace
|
|
246
|
+
| "Enter"
|
|
247
|
+
| "Escape"
|
|
248
|
+
| "Backspace"
|
|
249
|
+
| "Tab"
|
|
250
|
+
| "Space"
|
|
251
|
+
| "Delete"
|
|
252
|
+
| "Insert"
|
|
253
|
+
// Navigation
|
|
254
|
+
| "Home"
|
|
255
|
+
| "End"
|
|
256
|
+
| "PageUp"
|
|
257
|
+
| "PageDown"
|
|
258
|
+
| "ArrowUp"
|
|
259
|
+
| "ArrowDown"
|
|
260
|
+
| "ArrowLeft"
|
|
261
|
+
| "ArrowRight"
|
|
262
|
+
// Lock keys
|
|
263
|
+
| "CapsLock"
|
|
264
|
+
// Function keys
|
|
265
|
+
| "F1"
|
|
266
|
+
| "F2"
|
|
267
|
+
| "F3"
|
|
268
|
+
| "F4"
|
|
269
|
+
| "F5"
|
|
270
|
+
| "F6"
|
|
271
|
+
| "F7"
|
|
272
|
+
| "F8"
|
|
273
|
+
| "F9"
|
|
274
|
+
| "F10"
|
|
275
|
+
| "F11"
|
|
276
|
+
| "F12"
|
|
277
|
+
| "F13"
|
|
278
|
+
| "F14"
|
|
279
|
+
| "F15"
|
|
280
|
+
| "F16"
|
|
281
|
+
| "F17"
|
|
282
|
+
| "F18"
|
|
283
|
+
| "F19"
|
|
284
|
+
| "F20"
|
|
285
|
+
| "F21"
|
|
286
|
+
| "F22"
|
|
287
|
+
| "F23"
|
|
288
|
+
| "F24";
|
|
289
|
+
|
|
290
|
+
export type FoxgloveCommandId =
|
|
291
|
+
| "player.togglePlayback"
|
|
292
|
+
| "player.seekBackwardMedium"
|
|
293
|
+
| "player.seekForwardMedium"
|
|
294
|
+
| "player.seekBackwardSmall"
|
|
295
|
+
| "player.seekForwardSmall"
|
|
296
|
+
| "player.seekBackwardLarge"
|
|
297
|
+
| "player.seekForwardLarge"
|
|
298
|
+
| "player.seekStart"
|
|
299
|
+
| "player.seekEnd"
|
|
300
|
+
| "player.speedUp"
|
|
301
|
+
| "player.speedDown"
|
|
302
|
+
| "player.createEvent"
|
|
303
|
+
| "panel.threeDee.togglePerspective"
|
|
304
|
+
| "panel.threeDee.resetCamera"
|
|
305
|
+
| "panel.threeDee.toggleInspector"
|
|
306
|
+
| "panel.threeDee.moveForward"
|
|
307
|
+
| "panel.threeDee.moveLeft"
|
|
308
|
+
| "panel.threeDee.moveBackward"
|
|
309
|
+
| "panel.threeDee.moveRight"
|
|
310
|
+
| "panel.threeDee.rotateUp"
|
|
311
|
+
| "panel.threeDee.rotateDown"
|
|
312
|
+
| "panel.threeDee.rotateLeft"
|
|
313
|
+
| "panel.threeDee.rotateRight"
|
|
314
|
+
| "sidebar.left.toggleVisibility"
|
|
315
|
+
| "sidebar.right.toggleVisibility";
|
|
316
|
+
|
|
317
|
+
/**
|
|
318
|
+
* A key that triggers a keybinding.
|
|
319
|
+
*
|
|
320
|
+
* Physical key codes like `"KeyW"` match by physical position (layout-independent).
|
|
321
|
+
*
|
|
322
|
+
* Character keys like `"p"` match by the character produced (layout-dependent).
|
|
323
|
+
*
|
|
324
|
+
* Named keys like `"Escape"` are unambiguous — identical in both modes.
|
|
325
|
+
*/
|
|
326
|
+
export type ShortcutKey = EventKeyValue | EventCodeValue;
|
|
327
|
+
|
|
328
|
+
/**
|
|
329
|
+
* A key combination consisting of a {@link ShortcutKey} plus optional modifier keys.
|
|
330
|
+
*
|
|
331
|
+
* Physical key codes like `"KeyW"`, `"Space"` match by `event.code` (physical position).
|
|
332
|
+
*
|
|
333
|
+
* Character keys like `"p"`, `" "` match by `event.key` (logical key).
|
|
334
|
+
*
|
|
335
|
+
* Named keys like `"Escape"`, `"Enter"` are layout-independent and matched by `event.key`.
|
|
336
|
+
* `"PrimaryModifier"` resolves to Command on macOS and Control elsewhere.
|
|
337
|
+
*
|
|
338
|
+
* @example
|
|
339
|
+
* // Match by character `a` and modifier `PrimaryModifier` (Command on macOS, Control elsewhere)
|
|
340
|
+
* // The key will depend on the keyboard layout. On a QWERTY layout, this will match the key to the left of the S key.
|
|
341
|
+
* // On an AZERTY layout, this will match the key to the left of the Z key.
|
|
342
|
+
* { key: "a", modifiers: ["PrimaryModifier"] }
|
|
343
|
+
*
|
|
344
|
+
* // Match by physical key code `KeyA` and modifier `PrimaryModifier` (Command on macOS, Control elsewhere)
|
|
345
|
+
* // The key won't depend on the keyboard layout. On a QWERTY layout, this will match the key to the left of the A key.
|
|
346
|
+
* // On an AZERTY layout, this will match the key to the left of the S key.
|
|
347
|
+
* { key: "KeyA", modifiers: ["PrimaryModifier"] }
|
|
348
|
+
*
|
|
349
|
+
* // Match by named key `Escape`. This is layout-independent and will match the same key regardless of the keyboard layout.
|
|
350
|
+
* { key: "Escape" }
|
|
351
|
+
*
|
|
352
|
+
* @see ShortcutKey
|
|
353
|
+
*/
|
|
354
|
+
export interface KeybindingBase {
|
|
355
|
+
/** The key that triggers this keybinding. */
|
|
356
|
+
key: ShortcutKey;
|
|
357
|
+
/** Modifier keys required alongside the primary key. Defaults to no modifiers if omitted. */
|
|
358
|
+
modifiers?: ShortcutModifier[];
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
export interface CommandKeybinding extends KeybindingBase {
|
|
362
|
+
/** A built-in viewer command to invoke, or `"noop"` to suppress the key without action. */
|
|
363
|
+
command: FoxgloveCommandId | "noop";
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
export interface HandlerKeybinding extends KeybindingBase {
|
|
367
|
+
/** A function to call when the key combination is pressed. */
|
|
368
|
+
handler: () => void;
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
/**
|
|
372
|
+
* A keybinding defines a key combination that triggers a built-in
|
|
373
|
+
* viewer command or a custom handler function.
|
|
374
|
+
*/
|
|
375
|
+
export type Keybinding = CommandKeybinding | HandlerKeybinding;
|
|
376
|
+
|
|
77
377
|
export type FoxgloveViewerEventType = keyof FoxgloveViewerEventMap;
|
|
78
378
|
|
|
79
379
|
export type SelectLayoutParams =
|