@foxglove/embed 0.1.4 → 0.1.6
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/cjs/FoxgloveViewer.d.ts +41 -2
- package/dist/cjs/FoxgloveViewer.d.ts.map +1 -1
- package/dist/cjs/FoxgloveViewer.js +55 -7
- package/dist/cjs/FoxgloveViewer.js.map +1 -1
- package/dist/cjs/commands.d.ts +7 -2
- package/dist/cjs/commands.d.ts.map +1 -1
- package/dist/cjs/types.d.ts +15 -0
- package/dist/cjs/types.d.ts.map +1 -1
- package/dist/esm/FoxgloveViewer.d.ts +41 -2
- package/dist/esm/FoxgloveViewer.d.ts.map +1 -1
- package/dist/esm/FoxgloveViewer.js +55 -7
- package/dist/esm/FoxgloveViewer.js.map +1 -1
- package/dist/esm/commands.d.ts +7 -2
- package/dist/esm/commands.d.ts.map +1 -1
- package/dist/esm/types.d.ts +15 -0
- package/dist/esm/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/FoxgloveViewer.ts +67 -7
- package/src/commands.ts +8 -1
- package/src/types.ts +16 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { DataSource, OpaqueLayoutData, FoxgloveViewerEventMap } from "./types";
|
|
1
|
+
import type { DataSource, OpaqueLayoutData, FoxgloveViewerEventMap, SelectLayoutParams } from "./types";
|
|
2
2
|
interface FoxgloveEventTarget extends EventTarget {
|
|
3
3
|
addEventListener<K extends keyof FoxgloveViewerEventMap>(type: K, listener: (ev: FoxgloveViewerEventMap[K]) => void, options?: boolean | AddEventListenerOptions): void;
|
|
4
4
|
removeEventListener<K extends keyof FoxgloveViewerEventMap>(type: K, listener: (ev: FoxgloveViewerEventMap[K]) => void, options?: boolean | EventListenerOptions): void;
|
|
@@ -19,8 +19,14 @@ export type FoxgloveViewerOptions = {
|
|
|
19
19
|
orgSlug: string | undefined;
|
|
20
20
|
/** The initial data source to set when the frame is ready. */
|
|
21
21
|
initialDataSource?: DataSource;
|
|
22
|
-
/**
|
|
22
|
+
/**
|
|
23
|
+
* The initial layout to set when the frame is ready.
|
|
24
|
+
*
|
|
25
|
+
* @deprecated Use `layout` instead
|
|
26
|
+
*/
|
|
23
27
|
initialLayout?: OpaqueLayoutData;
|
|
28
|
+
/** The initial selected layout to set when the frame is ready. */
|
|
29
|
+
initialLayoutParams?: SelectLayoutParams;
|
|
24
30
|
/**
|
|
25
31
|
* The initial extensions to install when the frame is ready.
|
|
26
32
|
* This parameter is not supported by all Foxglove versions and plans, so it may result in an `error` event.
|
|
@@ -40,6 +46,38 @@ export declare class FoxgloveViewer extends TypedEventTarget {
|
|
|
40
46
|
constructor(options: FoxgloveViewerOptions);
|
|
41
47
|
/** Set the data source of the Foxglove app. */
|
|
42
48
|
setDataSource(dataSource: DataSource): void;
|
|
49
|
+
/**
|
|
50
|
+
* Load a layout from the local storage or create a new layout and save it to the local storage if
|
|
51
|
+
* no layout with the same storage key is found or if the `force` parameter is true. If no layout is provided,
|
|
52
|
+
* the default layout will be used.
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```
|
|
56
|
+
* // Load a layout stored using "layout-a" storage key. If no layout with the same storage key is found,
|
|
57
|
+
* //a new layout will be created and saved to the local storage.
|
|
58
|
+
* window
|
|
59
|
+
* .showOpenFilePicker({
|
|
60
|
+
* multiple: false,
|
|
61
|
+
* types: [
|
|
62
|
+
* {
|
|
63
|
+
* description: ".json",
|
|
64
|
+
* accept: {
|
|
65
|
+
* "application/json": [".json"],
|
|
66
|
+
* },
|
|
67
|
+
* },
|
|
68
|
+
* ],
|
|
69
|
+
* })
|
|
70
|
+
* .then(async (handles) => {
|
|
71
|
+
* const file = await handles[0]!.getFile();
|
|
72
|
+
* const layoutData = JSON.parse(await file.text());
|
|
73
|
+
* viewer.selectLayout({
|
|
74
|
+
* storageKey: "layout-a",
|
|
75
|
+
* opaqueLayout: layoutData,
|
|
76
|
+
* });
|
|
77
|
+
* });
|
|
78
|
+
* ```
|
|
79
|
+
*/
|
|
80
|
+
selectLayout(params: SelectLayoutParams): void;
|
|
43
81
|
/**
|
|
44
82
|
* Set the layout of the embedded viewer. The layout data is an opaque JavaScript object, which
|
|
45
83
|
* should be parsed from a JSON layout file that was exported from the Foxglove app.
|
|
@@ -65,6 +103,7 @@ export declare class FoxgloveViewer extends TypedEventTarget {
|
|
|
65
103
|
* viewer.setLayoutData(layoutData);
|
|
66
104
|
* });
|
|
67
105
|
* ```
|
|
106
|
+
* @deprecated Use `selectLayout` instead
|
|
68
107
|
*/
|
|
69
108
|
setLayoutData(layout: OpaqueLayoutData): void;
|
|
70
109
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FoxgloveViewer.d.ts","sourceRoot":"","sources":["../../src/FoxgloveViewer.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"FoxgloveViewer.d.ts","sourceRoot":"","sources":["../../src/FoxgloveViewer.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EACV,UAAU,EACV,gBAAgB,EAChB,sBAAsB,EAEtB,kBAAkB,EACnB,MAAM,SAAS,CAAC;AAEjB,UAAU,mBAAoB,SAAQ,WAAW;IAE/C,gBAAgB,CAAC,CAAC,SAAS,MAAM,sBAAsB,EACrD,IAAI,EAAE,CAAC,EACP,QAAQ,EAAE,CAAC,EAAE,EAAE,sBAAsB,CAAC,CAAC,CAAC,KAAK,IAAI,EACjD,OAAO,CAAC,EAAE,OAAO,GAAG,uBAAuB,GAC1C,IAAI,CAAC;IAER,mBAAmB,CAAC,CAAC,SAAS,MAAM,sBAAsB,EACxD,IAAI,EAAE,CAAC,EACP,QAAQ,EAAE,CAAC,EAAE,EAAE,sBAAsB,CAAC,CAAC,CAAC,KAAK,IAAI,EACjD,OAAO,CAAC,EAAE,OAAO,GAAG,oBAAoB,GACvC,IAAI,CAAC;CACT;AAED;;GAEG;AACH,QAAA,MAAM,gBAAgB,EAA6B,UAAU,mBAAmB,CAAC;AAMjF,MAAM,M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edEventTarget = EventTarget;
|
|
9
9
|
const DEFAULT_SERVER = "https://embed.foxglove.dev/";
|
|
10
|
+
const DEFAULT_LAYOUT_STORAGE_KEY = "foxglove.default-layout";
|
|
10
11
|
/**
|
|
11
12
|
* A class that manages an iframe that contains the Foxglove app.
|
|
12
13
|
*/
|
|
@@ -22,13 +23,14 @@ class FoxgloveViewer extends TypedEventTarget {
|
|
|
22
23
|
#latestCommands = {
|
|
23
24
|
dataSource: undefined,
|
|
24
25
|
layout: undefined,
|
|
26
|
+
selectLayout: undefined,
|
|
25
27
|
extension: [],
|
|
26
28
|
};
|
|
27
29
|
/** Whether the frame has been destroyed. */
|
|
28
30
|
#isDestroyed = false;
|
|
29
31
|
constructor(options) {
|
|
30
32
|
super();
|
|
31
|
-
const { parent, src, orgSlug, initialDataSource, initialLayout, initialExtensions, colorScheme = "auto", } = options;
|
|
33
|
+
const { parent, src, orgSlug, initialDataSource, initialLayout, initialLayoutParams, initialExtensions, colorScheme = "auto", } = options;
|
|
32
34
|
this.#orgSlug = orgSlug;
|
|
33
35
|
const srcUrl = src ?? DEFAULT_SERVER;
|
|
34
36
|
// Validate the server URL.
|
|
@@ -43,9 +45,12 @@ class FoxgloveViewer extends TypedEventTarget {
|
|
|
43
45
|
if (initialDataSource) {
|
|
44
46
|
this.setDataSource(initialDataSource);
|
|
45
47
|
}
|
|
46
|
-
if (initialLayout != undefined) {
|
|
48
|
+
if (initialLayout != undefined && initialLayoutParams == undefined) {
|
|
47
49
|
this.setLayoutData(initialLayout);
|
|
48
50
|
}
|
|
51
|
+
if (initialLayoutParams != undefined) {
|
|
52
|
+
this.selectLayout(initialLayoutParams);
|
|
53
|
+
}
|
|
49
54
|
if (initialExtensions) {
|
|
50
55
|
this.installExtensions(initialExtensions);
|
|
51
56
|
}
|
|
@@ -67,6 +72,43 @@ class FoxgloveViewer extends TypedEventTarget {
|
|
|
67
72
|
payload: dataSource,
|
|
68
73
|
});
|
|
69
74
|
}
|
|
75
|
+
/**
|
|
76
|
+
* Load a layout from the local storage or create a new layout and save it to the local storage if
|
|
77
|
+
* no layout with the same storage key is found or if the `force` parameter is true. If no layout is provided,
|
|
78
|
+
* the default layout will be used.
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* ```
|
|
82
|
+
* // Load a layout stored using "layout-a" storage key. If no layout with the same storage key is found,
|
|
83
|
+
* //a new layout will be created and saved to the local storage.
|
|
84
|
+
* window
|
|
85
|
+
* .showOpenFilePicker({
|
|
86
|
+
* multiple: false,
|
|
87
|
+
* types: [
|
|
88
|
+
* {
|
|
89
|
+
* description: ".json",
|
|
90
|
+
* accept: {
|
|
91
|
+
* "application/json": [".json"],
|
|
92
|
+
* },
|
|
93
|
+
* },
|
|
94
|
+
* ],
|
|
95
|
+
* })
|
|
96
|
+
* .then(async (handles) => {
|
|
97
|
+
* const file = await handles[0]!.getFile();
|
|
98
|
+
* const layoutData = JSON.parse(await file.text());
|
|
99
|
+
* viewer.selectLayout({
|
|
100
|
+
* storageKey: "layout-a",
|
|
101
|
+
* opaqueLayout: layoutData,
|
|
102
|
+
* });
|
|
103
|
+
* });
|
|
104
|
+
* ```
|
|
105
|
+
*/
|
|
106
|
+
selectLayout(params) {
|
|
107
|
+
this.#queueCommand({
|
|
108
|
+
type: "select-layout",
|
|
109
|
+
payload: params,
|
|
110
|
+
});
|
|
111
|
+
}
|
|
70
112
|
/**
|
|
71
113
|
* Set the layout of the embedded viewer. The layout data is an opaque JavaScript object, which
|
|
72
114
|
* should be parsed from a JSON layout file that was exported from the Foxglove app.
|
|
@@ -92,11 +134,13 @@ class FoxgloveViewer extends TypedEventTarget {
|
|
|
92
134
|
* viewer.setLayoutData(layoutData);
|
|
93
135
|
* });
|
|
94
136
|
* ```
|
|
137
|
+
* @deprecated Use `selectLayout` instead
|
|
95
138
|
*/
|
|
96
139
|
setLayoutData(layout) {
|
|
97
|
-
this
|
|
98
|
-
|
|
99
|
-
|
|
140
|
+
this.selectLayout({
|
|
141
|
+
storageKey: DEFAULT_LAYOUT_STORAGE_KEY,
|
|
142
|
+
opaqueLayout: layout,
|
|
143
|
+
force: true,
|
|
100
144
|
});
|
|
101
145
|
}
|
|
102
146
|
/**
|
|
@@ -144,9 +188,13 @@ class FoxgloveViewer extends TypedEventTarget {
|
|
|
144
188
|
else if (command.type === "set-data-source") {
|
|
145
189
|
this.#latestCommands.dataSource = command;
|
|
146
190
|
}
|
|
147
|
-
else {
|
|
191
|
+
else if (command.type === "set-layout" && !this.#latestCommands.selectLayout) {
|
|
148
192
|
this.#latestCommands.layout = command;
|
|
149
193
|
}
|
|
194
|
+
else if (command.type === "select-layout") {
|
|
195
|
+
this.#latestCommands.layout = undefined;
|
|
196
|
+
this.#latestCommands.selectLayout = command;
|
|
197
|
+
}
|
|
150
198
|
if (this.#isReady) {
|
|
151
199
|
this.#postCommand(command);
|
|
152
200
|
}
|
|
@@ -182,7 +230,7 @@ class FoxgloveViewer extends TypedEventTarget {
|
|
|
182
230
|
payload: {
|
|
183
231
|
orgSlug: this.#orgSlug,
|
|
184
232
|
initialDataSource: this.#latestCommands.dataSource?.payload,
|
|
185
|
-
|
|
233
|
+
initialLayoutParams: this.#latestCommands.selectLayout?.payload,
|
|
186
234
|
initialExtensions: this.#latestCommands.extension.flatMap((command) => command.payload),
|
|
187
235
|
},
|
|
188
236
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FoxgloveViewer.js","sourceRoot":"","sources":["../../src/FoxgloveViewer.ts"],"names":[],"mappings":";AAAA,gCAAgC;;;
|
|
1
|
+
{"version":3,"file":"FoxgloveViewer.js","sourceRoot":"","sources":["../../src/FoxgloveViewer.ts"],"names":[],"mappings":";AAAA,gCAAgC;;;AAmChC;;GAEG;AACH,MAAM,gBAAgB,GAAG,WAAuD,CAAC;AAEjF,MAAM,cAAc,GAAG,6BAA6B,CAAC;AAErD,MAAM,0BAA0B,GAAG,yBAAyB,CAAC;AAkC7D;;GAEG;AACH,MAAa,cAAe,SAAQ,gBA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,IAAI,EAAE,eAAe;oBACrB,OAAO,EAAE;wBACP,OAAO,EAAE,IAAI,CAAC,QAAQ;wBACtB,iBAAiB,EAAE,IAAI,CAAC,eAAe,CAAC,UAAU,EAAE,OAAO;wBAC3D,mBAAmB,EAAE,IAAI,CAAC,eAAe,CAAC,YAAY,EAAE,OAAO;wBAC/D,iBAAiB,EAAE,IAAI,CAAC,eAAe,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC;qBACxF;iBACF,CAAC,CAAC;gBAEH,MAAM;YACR,CAAC;YACD,KAAK,6BAA6B,CAAC,CAAC,CAAC;gBACnC,IAAI,CAAC,aAAa,CAAC,IAAI,KAAK,CAAC,OAAyC,CAAC,CAAC,CAAC;gBACzE,MAAM;YACR,CAAC;YACD,KAAK,gBAAgB,CAAC,CAAC,CAAC;gBACtB,IAAI,CAAC,aAAa,CAChB,IAAI,WAAW,CAAC,OAAyC,EAAE;oBACzD,MAAM,EAAE,OAAO,CAAC,IAAI,CAAC,OAAO;iBAC7B,CAAC,CACH,CAAC;gBACF,MAAM;YACR,CAAC;YACD,OAAO,CAAC,CAAC,CAAC;gBACR,OAAO,CAAC,IAAI,CAAC,0CAA0C,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC;gBACvE,MAAM;YACR,CAAC;QACH,CAAC;IACH,CAAC,CAAC;CACH;AA7RD,wCA6RC;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/cjs/commands.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { DataSource, OpaqueLayoutData } from "./types";
|
|
1
|
+
import type { DataSource, OpaqueLayoutData, SelectLayoutParams } from "./types";
|
|
2
2
|
export type IframeOriginAckCommand = {
|
|
3
3
|
type: "origin-ack";
|
|
4
4
|
};
|
|
@@ -10,6 +10,10 @@ export type IframeSetLayoutCommand = {
|
|
|
10
10
|
type: "set-layout";
|
|
11
11
|
payload: OpaqueLayoutData;
|
|
12
12
|
};
|
|
13
|
+
export type IframeSelectLayoutCommand = {
|
|
14
|
+
type: "select-layout";
|
|
15
|
+
payload: SelectLayoutParams;
|
|
16
|
+
};
|
|
13
17
|
export type IframeInstallExtensionCommand = {
|
|
14
18
|
type: "install-extension";
|
|
15
19
|
payload: Array<string | File>;
|
|
@@ -20,10 +24,11 @@ export type IframeHandshakeAckCommand = {
|
|
|
20
24
|
orgSlug?: string;
|
|
21
25
|
initialDataSource?: DataSource;
|
|
22
26
|
initialLayout?: OpaqueLayoutData;
|
|
27
|
+
initialLayoutParams?: SelectLayoutParams;
|
|
23
28
|
initialExtensions: Array<string | File>;
|
|
24
29
|
};
|
|
25
30
|
};
|
|
26
|
-
export type IframeCommand = IframeOriginAckCommand | IframeSetDatasourceCommand | IframeSetLayoutCommand | IframeInstallExtensionCommand | IframeHandshakeAckCommand;
|
|
31
|
+
export type IframeCommand = IframeOriginAckCommand | IframeSetDatasourceCommand | IframeSetLayoutCommand | IframeSelectLayoutCommand | IframeInstallExtensionCommand | IframeHandshakeAckCommand;
|
|
27
32
|
export type IframeEvent = {
|
|
28
33
|
type: "foxglove-origin-request";
|
|
29
34
|
} | {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"commands.d.ts","sourceRoot":"","sources":["../../src/commands.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"commands.d.ts","sourceRoot":"","sources":["../../src/commands.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAEhF,MAAM,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@ -24,4 +24,19 @@ export type FoxgloveViewerEventMap = {
|
|
|
24
24
|
error: CustomEvent<string>;
|
|
25
25
|
};
|
|
26
26
|
export type FoxgloveViewerEventType = keyof FoxgloveViewerEventMap;
|
|
27
|
+
export type SelectLayoutParams = {
|
|
28
|
+
/**
|
|
29
|
+
* The storage key to identify the layout in local storage. When reusing the same storage key,
|
|
30
|
+
* any modifications made by the user will be restored unless `force` is true.
|
|
31
|
+
* */
|
|
32
|
+
storageKey: string;
|
|
33
|
+
/**
|
|
34
|
+
* The layout data to load if this layout did not already exist, or if `force` is true.
|
|
35
|
+
* This is an opaque JavaScript object, which should be parsed from a JSON layout file
|
|
36
|
+
* that was exported from the Foxglove app. If not provided, the default layout will be used.
|
|
37
|
+
* */
|
|
38
|
+
opaqueLayout?: OpaqueLayoutData;
|
|
39
|
+
/** If true, opaqueLayout will override the layout if it already exists. Default: false */
|
|
40
|
+
force?: boolean;
|
|
41
|
+
};
|
|
27
42
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/cjs/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,MAAM,gBAAgB,GAAG,OAAO,CAAC;AAEvC,MAAM,MAAM,eAAe,GAAG;IAC5B,IAAI,EAAE,WAAW,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG,oBAAoB,GAAG,qBAAqB,GAAG,aAAa,CAAC;AAE9F,MAAM,MAAM,UAAU,GAAG;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,kBAAkB,CAAC;IAC7B,GAAG,EAAE,MAAM,CAAC;CACb,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,IAAI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AAE,gBAAgB,CAAC;IAChC,0FAA0F;IAC1F,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { DataSource, OpaqueLayoutData, FoxgloveViewerEventMap } from "./types";
|
|
1
|
+
import type { DataSource, OpaqueLayoutData, FoxgloveViewerEventMap, SelectLayoutParams } from "./types";
|
|
2
2
|
interface FoxgloveEventTarget extends EventTarget {
|
|
3
3
|
addEventListener<K extends keyof FoxgloveViewerEventMap>(type: K, listener: (ev: FoxgloveViewerEventMap[K]) => void, options?: boolean | AddEventListenerOptions): void;
|
|
4
4
|
removeEventListener<K extends keyof FoxgloveViewerEventMap>(type: K, listener: (ev: FoxgloveViewerEventMap[K]) => void, options?: boolean | EventListenerOptions): void;
|
|
@@ -19,8 +19,14 @@ export type FoxgloveViewerOptions = {
|
|
|
19
19
|
orgSlug: string | undefined;
|
|
20
20
|
/** The initial data source to set when the frame is ready. */
|
|
21
21
|
initialDataSource?: DataSource;
|
|
22
|
-
/**
|
|
22
|
+
/**
|
|
23
|
+
* The initial layout to set when the frame is ready.
|
|
24
|
+
*
|
|
25
|
+
* @deprecated Use `layout` instead
|
|
26
|
+
*/
|
|
23
27
|
initialLayout?: OpaqueLayoutData;
|
|
28
|
+
/** The initial selected layout to set when the frame is ready. */
|
|
29
|
+
initialLayoutParams?: SelectLayoutParams;
|
|
24
30
|
/**
|
|
25
31
|
* The initial extensions to install when the frame is ready.
|
|
26
32
|
* This parameter is not supported by all Foxglove versions and plans, so it may result in an `error` event.
|
|
@@ -40,6 +46,38 @@ export declare class FoxgloveViewer extends TypedEventTarget {
|
|
|
40
46
|
constructor(options: FoxgloveViewerOptions);
|
|
41
47
|
/** Set the data source of the Foxglove app. */
|
|
42
48
|
setDataSource(dataSource: DataSource): void;
|
|
49
|
+
/**
|
|
50
|
+
* Load a layout from the local storage or create a new layout and save it to the local storage if
|
|
51
|
+
* no layout with the same storage key is found or if the `force` parameter is true. If no layout is provided,
|
|
52
|
+
* the default layout will be used.
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```
|
|
56
|
+
* // Load a layout stored using "layout-a" storage key. If no layout with the same storage key is found,
|
|
57
|
+
* //a new layout will be created and saved to the local storage.
|
|
58
|
+
* window
|
|
59
|
+
* .showOpenFilePicker({
|
|
60
|
+
* multiple: false,
|
|
61
|
+
* types: [
|
|
62
|
+
* {
|
|
63
|
+
* description: ".json",
|
|
64
|
+
* accept: {
|
|
65
|
+
* "application/json": [".json"],
|
|
66
|
+
* },
|
|
67
|
+
* },
|
|
68
|
+
* ],
|
|
69
|
+
* })
|
|
70
|
+
* .then(async (handles) => {
|
|
71
|
+
* const file = await handles[0]!.getFile();
|
|
72
|
+
* const layoutData = JSON.parse(await file.text());
|
|
73
|
+
* viewer.selectLayout({
|
|
74
|
+
* storageKey: "layout-a",
|
|
75
|
+
* opaqueLayout: layoutData,
|
|
76
|
+
* });
|
|
77
|
+
* });
|
|
78
|
+
* ```
|
|
79
|
+
*/
|
|
80
|
+
selectLayout(params: SelectLayoutParams): void;
|
|
43
81
|
/**
|
|
44
82
|
* Set the layout of the embedded viewer. The layout data is an opaque JavaScript object, which
|
|
45
83
|
* should be parsed from a JSON layout file that was exported from the Foxglove app.
|
|
@@ -65,6 +103,7 @@ export declare class FoxgloveViewer extends TypedEventTarget {
|
|
|
65
103
|
* viewer.setLayoutData(layoutData);
|
|
66
104
|
* });
|
|
67
105
|
* ```
|
|
106
|
+
* @deprecated Use `selectLayout` instead
|
|
68
107
|
*/
|
|
69
108
|
setLayoutData(layout: OpaqueLayoutData): void;
|
|
70
109
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FoxgloveViewer.d.ts","sourceRoot":"","sources":["../../src/FoxgloveViewer.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"FoxgloveViewer.d.ts","sourceRoot":"","sources":["../../src/FoxgloveViewer.ts"],"names":[],"mappings":"AAY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aAAa,CAAC,UAAU,EAAE,UAAU,GAAG,IAAI;IAOlD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA8BG;IACI,YAAY,CAAC,MAAM,EAAE,kBAAkB,GAAG,IAAI;IAOrD;;;;;;;;;;;;;;;;;;;;;;;;;;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,sDAAsD;IAC/C,OAAO,IAAI,OAAO;IAIzB,mGAAmG;IAC5F,OAAO,IAAI,IAAI;IAMtB,4CAA4C;IACrC,WAAW,IAAI,OAAO;IAI7B;;OAEG;IACI,cAAc,CAAC,WAAW,EAAE,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,IAAI;CA4FpE"}
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
const TypedEventTarget = EventTarget;
|
|
6
6
|
const DEFAULT_SERVER = "https://embed.foxglove.dev/";
|
|
7
|
+
const DEFAULT_LAYOUT_STORAGE_KEY = "foxglove.default-layout";
|
|
7
8
|
/**
|
|
8
9
|
* A class that manages an iframe that contains the Foxglove app.
|
|
9
10
|
*/
|
|
@@ -19,13 +20,14 @@ export class FoxgloveViewer extends TypedEventTarget {
|
|
|
19
20
|
#latestCommands = {
|
|
20
21
|
dataSource: undefined,
|
|
21
22
|
layout: undefined,
|
|
23
|
+
selectLayout: undefined,
|
|
22
24
|
extension: [],
|
|
23
25
|
};
|
|
24
26
|
/** Whether the frame has been destroyed. */
|
|
25
27
|
#isDestroyed = false;
|
|
26
28
|
constructor(options) {
|
|
27
29
|
super();
|
|
28
|
-
const { parent, src, orgSlug, initialDataSource, initialLayout, initialExtensions, colorScheme = "auto", } = options;
|
|
30
|
+
const { parent, src, orgSlug, initialDataSource, initialLayout, initialLayoutParams, initialExtensions, colorScheme = "auto", } = options;
|
|
29
31
|
this.#orgSlug = orgSlug;
|
|
30
32
|
const srcUrl = src ?? DEFAULT_SERVER;
|
|
31
33
|
// Validate the server URL.
|
|
@@ -40,9 +42,12 @@ export class FoxgloveViewer extends TypedEventTarget {
|
|
|
40
42
|
if (initialDataSource) {
|
|
41
43
|
this.setDataSource(initialDataSource);
|
|
42
44
|
}
|
|
43
|
-
if (initialLayout != undefined) {
|
|
45
|
+
if (initialLayout != undefined && initialLayoutParams == undefined) {
|
|
44
46
|
this.setLayoutData(initialLayout);
|
|
45
47
|
}
|
|
48
|
+
if (initialLayoutParams != undefined) {
|
|
49
|
+
this.selectLayout(initialLayoutParams);
|
|
50
|
+
}
|
|
46
51
|
if (initialExtensions) {
|
|
47
52
|
this.installExtensions(initialExtensions);
|
|
48
53
|
}
|
|
@@ -64,6 +69,43 @@ export class FoxgloveViewer extends TypedEventTarget {
|
|
|
64
69
|
payload: dataSource,
|
|
65
70
|
});
|
|
66
71
|
}
|
|
72
|
+
/**
|
|
73
|
+
* Load a layout from the local storage or create a new layout and save it to the local storage if
|
|
74
|
+
* no layout with the same storage key is found or if the `force` parameter is true. If no layout is provided,
|
|
75
|
+
* the default layout will be used.
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* ```
|
|
79
|
+
* // Load a layout stored using "layout-a" storage key. If no layout with the same storage key is found,
|
|
80
|
+
* //a new layout will be created and saved to the local storage.
|
|
81
|
+
* window
|
|
82
|
+
* .showOpenFilePicker({
|
|
83
|
+
* multiple: false,
|
|
84
|
+
* types: [
|
|
85
|
+
* {
|
|
86
|
+
* description: ".json",
|
|
87
|
+
* accept: {
|
|
88
|
+
* "application/json": [".json"],
|
|
89
|
+
* },
|
|
90
|
+
* },
|
|
91
|
+
* ],
|
|
92
|
+
* })
|
|
93
|
+
* .then(async (handles) => {
|
|
94
|
+
* const file = await handles[0]!.getFile();
|
|
95
|
+
* const layoutData = JSON.parse(await file.text());
|
|
96
|
+
* viewer.selectLayout({
|
|
97
|
+
* storageKey: "layout-a",
|
|
98
|
+
* opaqueLayout: layoutData,
|
|
99
|
+
* });
|
|
100
|
+
* });
|
|
101
|
+
* ```
|
|
102
|
+
*/
|
|
103
|
+
selectLayout(params) {
|
|
104
|
+
this.#queueCommand({
|
|
105
|
+
type: "select-layout",
|
|
106
|
+
payload: params,
|
|
107
|
+
});
|
|
108
|
+
}
|
|
67
109
|
/**
|
|
68
110
|
* Set the layout of the embedded viewer. The layout data is an opaque JavaScript object, which
|
|
69
111
|
* should be parsed from a JSON layout file that was exported from the Foxglove app.
|
|
@@ -89,11 +131,13 @@ export class FoxgloveViewer extends TypedEventTarget {
|
|
|
89
131
|
* viewer.setLayoutData(layoutData);
|
|
90
132
|
* });
|
|
91
133
|
* ```
|
|
134
|
+
* @deprecated Use `selectLayout` instead
|
|
92
135
|
*/
|
|
93
136
|
setLayoutData(layout) {
|
|
94
|
-
this
|
|
95
|
-
|
|
96
|
-
|
|
137
|
+
this.selectLayout({
|
|
138
|
+
storageKey: DEFAULT_LAYOUT_STORAGE_KEY,
|
|
139
|
+
opaqueLayout: layout,
|
|
140
|
+
force: true,
|
|
97
141
|
});
|
|
98
142
|
}
|
|
99
143
|
/**
|
|
@@ -141,9 +185,13 @@ export class FoxgloveViewer extends TypedEventTarget {
|
|
|
141
185
|
else if (command.type === "set-data-source") {
|
|
142
186
|
this.#latestCommands.dataSource = command;
|
|
143
187
|
}
|
|
144
|
-
else {
|
|
188
|
+
else if (command.type === "set-layout" && !this.#latestCommands.selectLayout) {
|
|
145
189
|
this.#latestCommands.layout = command;
|
|
146
190
|
}
|
|
191
|
+
else if (command.type === "select-layout") {
|
|
192
|
+
this.#latestCommands.layout = undefined;
|
|
193
|
+
this.#latestCommands.selectLayout = command;
|
|
194
|
+
}
|
|
147
195
|
if (this.#isReady) {
|
|
148
196
|
this.#postCommand(command);
|
|
149
197
|
}
|
|
@@ -179,7 +227,7 @@ export class FoxgloveViewer extends TypedEventTarget {
|
|
|
179
227
|
payload: {
|
|
180
228
|
orgSlug: this.#orgSlug,
|
|
181
229
|
initialDataSource: this.#latestCommands.dataSource?.payload,
|
|
182
|
-
|
|
230
|
+
initialLayoutParams: this.#latestCommands.selectLayout?.payload,
|
|
183
231
|
initialExtensions: this.#latestCommands.extension.flatMap((command) => command.payload),
|
|
184
232
|
},
|
|
185
233
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FoxgloveViewer.js","sourceRoot":"","sources":["../../src/FoxgloveViewer.ts"],"names":[],"mappings":"AAAA,gCAAgC;
|
|
1
|
+
{"version":3,"file":"FoxgloveViewer.js","sourceRoot":"","sources":["../../src/FoxgloveViewer.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAmChC;;GAEG;AACH,MAAM,gBAAgB,GAAG,WAAuD,CAAC;AAEjF,MAAM,cAAc,GAAG,6BAA6B,CAAC;AAErD,MAAM,0BAA0B,GAAG,yBAAyB,CAAC;AAkC7D;;GAEG;AACH,MAAM,OAAO,cAAe,SAAQ,gBAAgB;IAClD,yDAAyD;IACzD,OAAO,CAAoB;IAC3B,gDAAgD;IAChD,OAAO,CAAM;IACb,QAAQ,CAAqB;IAC7B,sDAAsD;IACtD,QAAQ,GAAG,KAAK,CAAC;IACjB,oFAAoF;IACpF,eAAe,GAKX;QACF,UAAU,EAAE,SAAS;QACrB,MAAM,EAAE,SAAS;QACjB,YAAY,EAAE,SAAS;QACvB,SAAS,EAAE,EAAE;KACd,CAAC;IACF,4CAA4C;IAC5C,YAAY,GAAG,KAAK,CAAC;IAErB,YAAmB,OAA8B;QAC/C,KAAK,EAAE,CAAC;QACR,MAAM,EACJ,MAAM,EACN,GAAG,EACH,OAAO,EACP,iBAAiB,EACjB,aAAa,EACb,mBAAmB,EACnB,iBAAiB,EACjB,WAAW,GAAG,MAAM,GACrB,GAAG,OAAO,CAAC;QAEZ,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;QAExB,MAAM,MAAM,GAAG,GAAG,IAAI,cAAc,CAAC;QAErC,2BAA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BACzD,MAAM,EAAE,OAAO,CAAC,IAAI,CAAC,OAAO;iBAC7B,CAAC,CACH,CAAC;gBACF,MAAM;YACR,CAAC;YACD,OAAO,CAAC,CAAC,CAAC;gBACR,OAAO,CAAC,IAAI,CAAC,0CAA0C,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC;gBACvE,MAAM;YACR,CAAC;QACH,CAAC;IACH,CAAC,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/esm/commands.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { DataSource, OpaqueLayoutData } from "./types";
|
|
1
|
+
import type { DataSource, OpaqueLayoutData, SelectLayoutParams } from "./types";
|
|
2
2
|
export type IframeOriginAckCommand = {
|
|
3
3
|
type: "origin-ack";
|
|
4
4
|
};
|
|
@@ -10,6 +10,10 @@ export type IframeSetLayoutCommand = {
|
|
|
10
10
|
type: "set-layout";
|
|
11
11
|
payload: OpaqueLayoutData;
|
|
12
12
|
};
|
|
13
|
+
export type IframeSelectLayoutCommand = {
|
|
14
|
+
type: "select-layout";
|
|
15
|
+
payload: SelectLayoutParams;
|
|
16
|
+
};
|
|
13
17
|
export type IframeInstallExtensionCommand = {
|
|
14
18
|
type: "install-extension";
|
|
15
19
|
payload: Array<string | File>;
|
|
@@ -20,10 +24,11 @@ export type IframeHandshakeAckCommand = {
|
|
|
20
24
|
orgSlug?: string;
|
|
21
25
|
initialDataSource?: DataSource;
|
|
22
26
|
initialLayout?: OpaqueLayoutData;
|
|
27
|
+
initialLayoutParams?: SelectLayoutParams;
|
|
23
28
|
initialExtensions: Array<string | File>;
|
|
24
29
|
};
|
|
25
30
|
};
|
|
26
|
-
export type IframeCommand = IframeOriginAckCommand | IframeSetDatasourceCommand | IframeSetLayoutCommand | IframeInstallExtensionCommand | IframeHandshakeAckCommand;
|
|
31
|
+
export type IframeCommand = IframeOriginAckCommand | IframeSetDatasourceCommand | IframeSetLayoutCommand | IframeSelectLayoutCommand | IframeInstallExtensionCommand | IframeHandshakeAckCommand;
|
|
27
32
|
export type IframeEvent = {
|
|
28
33
|
type: "foxglove-origin-request";
|
|
29
34
|
} | {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"commands.d.ts","sourceRoot":"","sources":["../../src/commands.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"commands.d.ts","sourceRoot":"","sources":["../../src/commands.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAEhF,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,CAAC;IACtB,OAAO,EAAE,kBAAkB,CAAC;CAC7B,CAAC;AAEF,MAAM,MAAM,6BAA6B,GAAG;IAC1C,IAAI,EAAE,mBAAmB,CAAC;IAC1B,OAAO,EAAE,KAAK,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;CAC/B,CAAC;AAEF,MAAM,MAAM,yBAAyB,GAAG;IACtC,IAAI,EAAE,eAAe,CAAC;IACtB,OAAO,EAAE;QACP,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,iBAAiB,CAAC,EAAE,UAAU,CAAC;QAC/B,aAAa,CAAC,EAAE,gBAAgB,CAAC;QACjC,mBAAmB,CAAC,EAAE,kBAAkB,CAAC;QACzC,iBAAiB,EAAE,KAAK,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;KACzC,CAAC;CACH,CAAC;AAEF,MAAM,MAAM,aAAa,GACrB,sBAAsB,GACtB,0BAA0B,GAC1B,sBAAsB,GACtB,yBAAyB,GACzB,6BAA6B,GAC7B,yBAAyB,CAAC;AAE9B,MAAM,MAAM,WAAW,GACnB;IACE,IAAI,EAAE,yBAAyB,CAAC;CACjC,GACD;IACE,IAAI,EAAE,4BAA4B,CAAC;CACpC,GACD;IACE,IAAI,EAAE,6BAA6B,CAAC;CACrC,GACD;IACE,IAAI,EAAE,gBAAgB,CAAC;IACvB,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC"}
|
package/dist/esm/types.d.ts
CHANGED
|
@@ -24,4 +24,19 @@ export type FoxgloveViewerEventMap = {
|
|
|
24
24
|
error: CustomEvent<string>;
|
|
25
25
|
};
|
|
26
26
|
export type FoxgloveViewerEventType = keyof FoxgloveViewerEventMap;
|
|
27
|
+
export type SelectLayoutParams = {
|
|
28
|
+
/**
|
|
29
|
+
* The storage key to identify the layout in local storage. When reusing the same storage key,
|
|
30
|
+
* any modifications made by the user will be restored unless `force` is true.
|
|
31
|
+
* */
|
|
32
|
+
storageKey: string;
|
|
33
|
+
/**
|
|
34
|
+
* The layout data to load if this layout did not already exist, or if `force` is true.
|
|
35
|
+
* This is an opaque JavaScript object, which should be parsed from a JSON layout file
|
|
36
|
+
* that was exported from the Foxglove app. If not provided, the default layout will be used.
|
|
37
|
+
* */
|
|
38
|
+
opaqueLayout?: OpaqueLayoutData;
|
|
39
|
+
/** If true, opaqueLayout will override the layout if it already exists. Default: false */
|
|
40
|
+
force?: boolean;
|
|
41
|
+
};
|
|
27
42
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/esm/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,MAAM,gBAAgB,GAAG,OAAO,CAAC;AAEvC,MAAM,MAAM,eAAe,GAAG;IAC5B,IAAI,EAAE,WAAW,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG,oBAAoB,GAAG,qBAAqB,GAAG,aAAa,CAAC;AAE9F,MAAM,MAAM,UAAU,GAAG;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,kBAAkB,CAAC;IAC7B,GAAG,EAAE,MAAM,CAAC;CACb,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,IAAI,GAAG,IAAI,EAAE,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG,eAAe,GAAG,UAAU,GAAG,UAAU,CAAC;AAEnE,MAAM,MAAM,sBAAsB,GAAG;IACnC,KAAK,EAAE,KAAK,CAAC;IACb,KAAK,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;CAC5B,CAAC;AAEF,MAAM,MAAM,uBAAuB,GAAG,MAAM,sBAAsB,CAAC"}
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,MAAM,gBAAgB,GAAG,OAAO,CAAC;AAEvC,MAAM,MAAM,eAAe,GAAG;IAC5B,IAAI,EAAE,WAAW,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG,oBAAoB,GAAG,qBAAqB,GAAG,aAAa,CAAC;AAE9F,MAAM,MAAM,UAAU,GAAG;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,kBAAkB,CAAC;IAC7B,GAAG,EAAE,MAAM,CAAC;CACb,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,IAAI,GAAG,IAAI,EAAE,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG,eAAe,GAAG,UAAU,GAAG,UAAU,CAAC;AAEnE,MAAM,MAAM,sBAAsB,GAAG;IACnC,KAAK,EAAE,KAAK,CAAC;IACb,KAAK,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;CAC5B,CAAC;AAEF,MAAM,MAAM,uBAAuB,GAAG,MAAM,sBAAsB,CAAC;AAEnE,MAAM,MAAM,kBAAkB,GAAG;IAC/B;;;SAGK;IACL,UAAU,EAAE,MAAM,CAAC;IACnB;;;;SAIK;IACL,YAAY,CAAC,EAAE,gBAAgB,CAAC;IAChC,0FAA0F;IAC1F,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB,CAAC"}
|
package/package.json
CHANGED
package/src/FoxgloveViewer.ts
CHANGED
|
@@ -8,12 +8,14 @@ import type {
|
|
|
8
8
|
IframeInstallExtensionCommand,
|
|
9
9
|
IframeHandshakeAckCommand,
|
|
10
10
|
IframeOriginAckCommand,
|
|
11
|
+
IframeSelectLayoutCommand,
|
|
11
12
|
} from "./commands";
|
|
12
13
|
import type {
|
|
13
14
|
DataSource,
|
|
14
15
|
OpaqueLayoutData,
|
|
15
16
|
FoxgloveViewerEventMap,
|
|
16
17
|
FoxgloveViewerEventType,
|
|
18
|
+
SelectLayoutParams,
|
|
17
19
|
} from "./types";
|
|
18
20
|
|
|
19
21
|
interface FoxgloveEventTarget extends EventTarget {
|
|
@@ -38,6 +40,8 @@ const TypedEventTarget = EventTarget as unknown as new () => FoxgloveEventTarget
|
|
|
38
40
|
|
|
39
41
|
const DEFAULT_SERVER = "https://embed.foxglove.dev/";
|
|
40
42
|
|
|
43
|
+
const DEFAULT_LAYOUT_STORAGE_KEY = "foxglove.default-layout";
|
|
44
|
+
|
|
41
45
|
export type FoxgloveViewerOptions = {
|
|
42
46
|
/** The parent element to append the iframe to. This is required if `iframe` is not provided. */
|
|
43
47
|
parent: HTMLElement;
|
|
@@ -50,8 +54,14 @@ export type FoxgloveViewerOptions = {
|
|
|
50
54
|
orgSlug: string | undefined;
|
|
51
55
|
/** The initial data source to set when the frame is ready. */
|
|
52
56
|
initialDataSource?: DataSource;
|
|
53
|
-
/**
|
|
57
|
+
/**
|
|
58
|
+
* The initial layout to set when the frame is ready.
|
|
59
|
+
*
|
|
60
|
+
* @deprecated Use `layout` instead
|
|
61
|
+
*/
|
|
54
62
|
initialLayout?: OpaqueLayoutData;
|
|
63
|
+
/** The initial selected layout to set when the frame is ready. */
|
|
64
|
+
initialLayoutParams?: SelectLayoutParams;
|
|
55
65
|
/**
|
|
56
66
|
* The initial extensions to install when the frame is ready.
|
|
57
67
|
* This parameter is not supported by all Foxglove versions and plans, so it may result in an `error` event.
|
|
@@ -79,10 +89,12 @@ export class FoxgloveViewer extends TypedEventTarget {
|
|
|
79
89
|
#latestCommands: {
|
|
80
90
|
dataSource: IframeSetDatasourceCommand | undefined;
|
|
81
91
|
layout: IframeSetLayoutCommand | undefined;
|
|
92
|
+
selectLayout: IframeSelectLayoutCommand | undefined;
|
|
82
93
|
extension: Array<IframeInstallExtensionCommand>;
|
|
83
94
|
} = {
|
|
84
95
|
dataSource: undefined,
|
|
85
96
|
layout: undefined,
|
|
97
|
+
selectLayout: undefined,
|
|
86
98
|
extension: [],
|
|
87
99
|
};
|
|
88
100
|
/** Whether the frame has been destroyed. */
|
|
@@ -96,6 +108,7 @@ export class FoxgloveViewer extends TypedEventTarget {
|
|
|
96
108
|
orgSlug,
|
|
97
109
|
initialDataSource,
|
|
98
110
|
initialLayout,
|
|
111
|
+
initialLayoutParams,
|
|
99
112
|
initialExtensions,
|
|
100
113
|
colorScheme = "auto",
|
|
101
114
|
} = options;
|
|
@@ -118,10 +131,14 @@ export class FoxgloveViewer extends TypedEventTarget {
|
|
|
118
131
|
this.setDataSource(initialDataSource);
|
|
119
132
|
}
|
|
120
133
|
|
|
121
|
-
if (initialLayout != undefined) {
|
|
134
|
+
if (initialLayout != undefined && initialLayoutParams == undefined) {
|
|
122
135
|
this.setLayoutData(initialLayout);
|
|
123
136
|
}
|
|
124
137
|
|
|
138
|
+
if (initialLayoutParams != undefined) {
|
|
139
|
+
this.selectLayout(initialLayoutParams);
|
|
140
|
+
}
|
|
141
|
+
|
|
125
142
|
if (initialExtensions) {
|
|
126
143
|
this.installExtensions(initialExtensions);
|
|
127
144
|
}
|
|
@@ -147,6 +164,44 @@ export class FoxgloveViewer extends TypedEventTarget {
|
|
|
147
164
|
});
|
|
148
165
|
}
|
|
149
166
|
|
|
167
|
+
/**
|
|
168
|
+
* Load a layout from the local storage or create a new layout and save it to the local storage if
|
|
169
|
+
* no layout with the same storage key is found or if the `force` parameter is true. If no layout is provided,
|
|
170
|
+
* the default layout will be used.
|
|
171
|
+
*
|
|
172
|
+
* @example
|
|
173
|
+
* ```
|
|
174
|
+
* // Load a layout stored using "layout-a" storage key. If no layout with the same storage key is found,
|
|
175
|
+
* //a new layout will be created and saved to the local storage.
|
|
176
|
+
* window
|
|
177
|
+
* .showOpenFilePicker({
|
|
178
|
+
* multiple: false,
|
|
179
|
+
* types: [
|
|
180
|
+
* {
|
|
181
|
+
* description: ".json",
|
|
182
|
+
* accept: {
|
|
183
|
+
* "application/json": [".json"],
|
|
184
|
+
* },
|
|
185
|
+
* },
|
|
186
|
+
* ],
|
|
187
|
+
* })
|
|
188
|
+
* .then(async (handles) => {
|
|
189
|
+
* const file = await handles[0]!.getFile();
|
|
190
|
+
* const layoutData = JSON.parse(await file.text());
|
|
191
|
+
* viewer.selectLayout({
|
|
192
|
+
* storageKey: "layout-a",
|
|
193
|
+
* opaqueLayout: layoutData,
|
|
194
|
+
* });
|
|
195
|
+
* });
|
|
196
|
+
* ```
|
|
197
|
+
*/
|
|
198
|
+
public selectLayout(params: SelectLayoutParams): void {
|
|
199
|
+
this.#queueCommand({
|
|
200
|
+
type: "select-layout",
|
|
201
|
+
payload: params,
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
|
|
150
205
|
/**
|
|
151
206
|
* Set the layout of the embedded viewer. The layout data is an opaque JavaScript object, which
|
|
152
207
|
* should be parsed from a JSON layout file that was exported from the Foxglove app.
|
|
@@ -172,11 +227,13 @@ export class FoxgloveViewer extends TypedEventTarget {
|
|
|
172
227
|
* viewer.setLayoutData(layoutData);
|
|
173
228
|
* });
|
|
174
229
|
* ```
|
|
230
|
+
* @deprecated Use `selectLayout` instead
|
|
175
231
|
*/
|
|
176
232
|
public setLayoutData(layout: OpaqueLayoutData): void {
|
|
177
|
-
this
|
|
178
|
-
|
|
179
|
-
|
|
233
|
+
this.selectLayout({
|
|
234
|
+
storageKey: DEFAULT_LAYOUT_STORAGE_KEY,
|
|
235
|
+
opaqueLayout: layout,
|
|
236
|
+
force: true,
|
|
180
237
|
});
|
|
181
238
|
}
|
|
182
239
|
|
|
@@ -230,8 +287,11 @@ export class FoxgloveViewer extends TypedEventTarget {
|
|
|
230
287
|
this.#latestCommands.extension.push(command);
|
|
231
288
|
} else if (command.type === "set-data-source") {
|
|
232
289
|
this.#latestCommands.dataSource = command;
|
|
233
|
-
} else {
|
|
290
|
+
} else if (command.type === "set-layout" && !this.#latestCommands.selectLayout) {
|
|
234
291
|
this.#latestCommands.layout = command;
|
|
292
|
+
} else if (command.type === "select-layout") {
|
|
293
|
+
this.#latestCommands.layout = undefined;
|
|
294
|
+
this.#latestCommands.selectLayout = command;
|
|
235
295
|
}
|
|
236
296
|
|
|
237
297
|
if (this.#isReady) {
|
|
@@ -277,7 +337,7 @@ export class FoxgloveViewer extends TypedEventTarget {
|
|
|
277
337
|
payload: {
|
|
278
338
|
orgSlug: this.#orgSlug,
|
|
279
339
|
initialDataSource: this.#latestCommands.dataSource?.payload,
|
|
280
|
-
|
|
340
|
+
initialLayoutParams: this.#latestCommands.selectLayout?.payload,
|
|
281
341
|
initialExtensions: this.#latestCommands.extension.flatMap((command) => command.payload),
|
|
282
342
|
},
|
|
283
343
|
});
|
package/src/commands.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { DataSource, OpaqueLayoutData } from "./types";
|
|
1
|
+
import type { DataSource, OpaqueLayoutData, SelectLayoutParams } from "./types";
|
|
2
2
|
|
|
3
3
|
export type IframeOriginAckCommand = {
|
|
4
4
|
type: "origin-ack";
|
|
@@ -14,6 +14,11 @@ export type IframeSetLayoutCommand = {
|
|
|
14
14
|
payload: OpaqueLayoutData;
|
|
15
15
|
};
|
|
16
16
|
|
|
17
|
+
export type IframeSelectLayoutCommand = {
|
|
18
|
+
type: "select-layout";
|
|
19
|
+
payload: SelectLayoutParams;
|
|
20
|
+
};
|
|
21
|
+
|
|
17
22
|
export type IframeInstallExtensionCommand = {
|
|
18
23
|
type: "install-extension";
|
|
19
24
|
payload: Array<string | File>;
|
|
@@ -25,6 +30,7 @@ export type IframeHandshakeAckCommand = {
|
|
|
25
30
|
orgSlug?: string;
|
|
26
31
|
initialDataSource?: DataSource;
|
|
27
32
|
initialLayout?: OpaqueLayoutData;
|
|
33
|
+
initialLayoutParams?: SelectLayoutParams;
|
|
28
34
|
initialExtensions: Array<string | File>;
|
|
29
35
|
};
|
|
30
36
|
};
|
|
@@ -33,6 +39,7 @@ export type IframeCommand =
|
|
|
33
39
|
| IframeOriginAckCommand
|
|
34
40
|
| IframeSetDatasourceCommand
|
|
35
41
|
| IframeSetLayoutCommand
|
|
42
|
+
| IframeSelectLayoutCommand
|
|
36
43
|
| IframeInstallExtensionCommand
|
|
37
44
|
| IframeHandshakeAckCommand;
|
|
38
45
|
|
package/src/types.ts
CHANGED
|
@@ -31,3 +31,19 @@ export type FoxgloveViewerEventMap = {
|
|
|
31
31
|
};
|
|
32
32
|
|
|
33
33
|
export type FoxgloveViewerEventType = keyof FoxgloveViewerEventMap;
|
|
34
|
+
|
|
35
|
+
export type SelectLayoutParams = {
|
|
36
|
+
/**
|
|
37
|
+
* The storage key to identify the layout in local storage. When reusing the same storage key,
|
|
38
|
+
* any modifications made by the user will be restored unless `force` is true.
|
|
39
|
+
* */
|
|
40
|
+
storageKey: string;
|
|
41
|
+
/**
|
|
42
|
+
* The layout data to load if this layout did not already exist, or if `force` is true.
|
|
43
|
+
* This is an opaque JavaScript object, which should be parsed from a JSON layout file
|
|
44
|
+
* that was exported from the Foxglove app. If not provided, the default layout will be used.
|
|
45
|
+
* */
|
|
46
|
+
opaqueLayout?: OpaqueLayoutData;
|
|
47
|
+
/** If true, opaqueLayout will override the layout if it already exists. Default: false */
|
|
48
|
+
force?: boolean;
|
|
49
|
+
};
|