@foxglove/embed 0.1.4 → 0.1.5
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 +40 -2
- package/dist/cjs/FoxgloveViewer.d.ts.map +1 -1
- package/dist/cjs/FoxgloveViewer.js +54 -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 +40 -2
- package/dist/esm/FoxgloveViewer.d.ts.map +1 -1
- package/dist/esm/FoxgloveViewer.js +54 -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 +66 -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,37 @@ 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.
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```
|
|
55
|
+
* // Load a layout from stored using "layout-a" storage key. If no layout with the same storage key is found,
|
|
56
|
+
* //a new layout will be created and saved to the local storage.
|
|
57
|
+
* window
|
|
58
|
+
* .showOpenFilePicker({
|
|
59
|
+
* multiple: false,
|
|
60
|
+
* types: [
|
|
61
|
+
* {
|
|
62
|
+
* description: ".json",
|
|
63
|
+
* accept: {
|
|
64
|
+
* "application/json": [".json"],
|
|
65
|
+
* },
|
|
66
|
+
* },
|
|
67
|
+
* ],
|
|
68
|
+
* })
|
|
69
|
+
* .then(async (handles) => {
|
|
70
|
+
* const file = await handles[0]!.getFile();
|
|
71
|
+
* const layoutData = JSON.parse(await file.text());
|
|
72
|
+
* viewer.selectLayout({
|
|
73
|
+
* storageKey: "layout-a",
|
|
74
|
+
* opaqueLayout: layoutData,
|
|
75
|
+
* });
|
|
76
|
+
* });
|
|
77
|
+
* ```
|
|
78
|
+
*/
|
|
79
|
+
selectLayout(params: SelectLayoutParams): void;
|
|
43
80
|
/**
|
|
44
81
|
* Set the layout of the embedded viewer. The layout data is an opaque JavaScript object, which
|
|
45
82
|
* should be parsed from a JSON layout file that was exported from the Foxglove app.
|
|
@@ -65,6 +102,7 @@ export declare class FoxgloveViewer extends TypedEventTarget {
|
|
|
65
102
|
* viewer.setLayoutData(layoutData);
|
|
66
103
|
* });
|
|
67
104
|
* ```
|
|
105
|
+
* @deprecated Use `selectLayout` instead
|
|
68
106
|
*/
|
|
69
107
|
setLayoutData(layout: OpaqueLayoutData): void;
|
|
70
108
|
/**
|
|
@@ -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,MAAM,qBAAqB,GAAG;IAClC,gGAAgG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AULT_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,42 @@ 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.
|
|
78
|
+
*
|
|
79
|
+
* @example
|
|
80
|
+
* ```
|
|
81
|
+
* // Load a layout from stored using "layout-a" storage key. If no layout with the same storage key is found,
|
|
82
|
+
* //a new layout will be created and saved to the local storage.
|
|
83
|
+
* window
|
|
84
|
+
* .showOpenFilePicker({
|
|
85
|
+
* multiple: false,
|
|
86
|
+
* types: [
|
|
87
|
+
* {
|
|
88
|
+
* description: ".json",
|
|
89
|
+
* accept: {
|
|
90
|
+
* "application/json": [".json"],
|
|
91
|
+
* },
|
|
92
|
+
* },
|
|
93
|
+
* ],
|
|
94
|
+
* })
|
|
95
|
+
* .then(async (handles) => {
|
|
96
|
+
* const file = await handles[0]!.getFile();
|
|
97
|
+
* const layoutData = JSON.parse(await file.text());
|
|
98
|
+
* viewer.selectLayout({
|
|
99
|
+
* storageKey: "layout-a",
|
|
100
|
+
* opaqueLayout: layoutData,
|
|
101
|
+
* });
|
|
102
|
+
* });
|
|
103
|
+
* ```
|
|
104
|
+
*/
|
|
105
|
+
selectLayout(params) {
|
|
106
|
+
this.#queueCommand({
|
|
107
|
+
type: "select-layout",
|
|
108
|
+
payload: params,
|
|
109
|
+
});
|
|
110
|
+
}
|
|
70
111
|
/**
|
|
71
112
|
* Set the layout of the embedded viewer. The layout data is an opaque JavaScript object, which
|
|
72
113
|
* should be parsed from a JSON layout file that was exported from the Foxglove app.
|
|
@@ -92,11 +133,13 @@ class FoxgloveViewer extends TypedEventTarget {
|
|
|
92
133
|
* viewer.setLayoutData(layoutData);
|
|
93
134
|
* });
|
|
94
135
|
* ```
|
|
136
|
+
* @deprecated Use `selectLayout` instead
|
|
95
137
|
*/
|
|
96
138
|
setLayoutData(layout) {
|
|
97
|
-
this
|
|
98
|
-
|
|
99
|
-
|
|
139
|
+
this.selectLayout({
|
|
140
|
+
storageKey: DEFAULT_LAYOUT_STORAGE_KEY,
|
|
141
|
+
opaqueLayout: layout,
|
|
142
|
+
force: true,
|
|
100
143
|
});
|
|
101
144
|
}
|
|
102
145
|
/**
|
|
@@ -144,9 +187,13 @@ class FoxgloveViewer extends TypedEventTarget {
|
|
|
144
187
|
else if (command.type === "set-data-source") {
|
|
145
188
|
this.#latestCommands.dataSource = command;
|
|
146
189
|
}
|
|
147
|
-
else {
|
|
190
|
+
else if (command.type === "set-layout" && !this.#latestCommands.selectLayout) {
|
|
148
191
|
this.#latestCommands.layout = command;
|
|
149
192
|
}
|
|
193
|
+
else if (command.type === "select-layout") {
|
|
194
|
+
this.#latestCommands.layout = undefined;
|
|
195
|
+
this.#latestCommands.selectLayout = command;
|
|
196
|
+
}
|
|
150
197
|
if (this.#isReady) {
|
|
151
198
|
this.#postCommand(command);
|
|
152
199
|
}
|
|
@@ -182,7 +229,7 @@ class FoxgloveViewer extends TypedEventTarget {
|
|
|
182
229
|
payload: {
|
|
183
230
|
orgSlug: this.#orgSlug,
|
|
184
231
|
initialDataSource: this.#latestCommands.dataSource?.payload,
|
|
185
|
-
|
|
232
|
+
initialLayoutParams: this.#latestCommands.selectLayout?.payload,
|
|
186
233
|
initialExtensions: this.#latestCommands.extension.flatMap((command) => command.payload),
|
|
187
234
|
},
|
|
188
235
|
});
|
|
@@ -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,gBAAgB;IAClD,yDAAyD;IACzD,OAAO,CAAoB;IAC3B,gDAAgD;IAChD,OAAO,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,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;AA5RD,wCA4RC;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,MAAM,sBAAsB,GAAG;IACnC,IAAI,EAAE,YAAY,CAAC;CACpB,CAAC;AAEF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;
|
|
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.
|
|
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,GAAG,IAAI,EAAE,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG,eAAe,GAAG,UAAU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
@@ -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,37 @@ 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.
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```
|
|
55
|
+
* // Load a layout from stored using "layout-a" storage key. If no layout with the same storage key is found,
|
|
56
|
+
* //a new layout will be created and saved to the local storage.
|
|
57
|
+
* window
|
|
58
|
+
* .showOpenFilePicker({
|
|
59
|
+
* multiple: false,
|
|
60
|
+
* types: [
|
|
61
|
+
* {
|
|
62
|
+
* description: ".json",
|
|
63
|
+
* accept: {
|
|
64
|
+
* "application/json": [".json"],
|
|
65
|
+
* },
|
|
66
|
+
* },
|
|
67
|
+
* ],
|
|
68
|
+
* })
|
|
69
|
+
* .then(async (handles) => {
|
|
70
|
+
* const file = await handles[0]!.getFile();
|
|
71
|
+
* const layoutData = JSON.parse(await file.text());
|
|
72
|
+
* viewer.selectLayout({
|
|
73
|
+
* storageKey: "layout-a",
|
|
74
|
+
* opaqueLayout: layoutData,
|
|
75
|
+
* });
|
|
76
|
+
* });
|
|
77
|
+
* ```
|
|
78
|
+
*/
|
|
79
|
+
selectLayout(params: SelectLayoutParams): void;
|
|
43
80
|
/**
|
|
44
81
|
* Set the layout of the embedded viewer. The layout data is an opaque JavaScript object, which
|
|
45
82
|
* should be parsed from a JSON layout file that was exported from the Foxglove app.
|
|
@@ -65,6 +102,7 @@ export declare class FoxgloveViewer extends TypedEventTarget {
|
|
|
65
102
|
* viewer.setLayoutData(layoutData);
|
|
66
103
|
* });
|
|
67
104
|
* ```
|
|
105
|
+
* @deprecated Use `selectLayout` instead
|
|
68
106
|
*/
|
|
69
107
|
setLayoutData(layout: OpaqueLayoutData): void;
|
|
70
108
|
/**
|
|
@@ -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,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AAkB,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,42 @@ 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.
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* ```
|
|
78
|
+
* // Load a layout from stored using "layout-a" storage key. If no layout with the same storage key is found,
|
|
79
|
+
* //a new layout will be created and saved to the local storage.
|
|
80
|
+
* window
|
|
81
|
+
* .showOpenFilePicker({
|
|
82
|
+
* multiple: false,
|
|
83
|
+
* types: [
|
|
84
|
+
* {
|
|
85
|
+
* description: ".json",
|
|
86
|
+
* accept: {
|
|
87
|
+
* "application/json": [".json"],
|
|
88
|
+
* },
|
|
89
|
+
* },
|
|
90
|
+
* ],
|
|
91
|
+
* })
|
|
92
|
+
* .then(async (handles) => {
|
|
93
|
+
* const file = await handles[0]!.getFile();
|
|
94
|
+
* const layoutData = JSON.parse(await file.text());
|
|
95
|
+
* viewer.selectLayout({
|
|
96
|
+
* storageKey: "layout-a",
|
|
97
|
+
* opaqueLayout: layoutData,
|
|
98
|
+
* });
|
|
99
|
+
* });
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
102
|
+
selectLayout(params) {
|
|
103
|
+
this.#queueCommand({
|
|
104
|
+
type: "select-layout",
|
|
105
|
+
payload: params,
|
|
106
|
+
});
|
|
107
|
+
}
|
|
67
108
|
/**
|
|
68
109
|
* Set the layout of the embedded viewer. The layout data is an opaque JavaScript object, which
|
|
69
110
|
* should be parsed from a JSON layout file that was exported from the Foxglove app.
|
|
@@ -89,11 +130,13 @@ export class FoxgloveViewer extends TypedEventTarget {
|
|
|
89
130
|
* viewer.setLayoutData(layoutData);
|
|
90
131
|
* });
|
|
91
132
|
* ```
|
|
133
|
+
* @deprecated Use `selectLayout` instead
|
|
92
134
|
*/
|
|
93
135
|
setLayoutData(layout) {
|
|
94
|
-
this
|
|
95
|
-
|
|
96
|
-
|
|
136
|
+
this.selectLayout({
|
|
137
|
+
storageKey: DEFAULT_LAYOUT_STORAGE_KEY,
|
|
138
|
+
opaqueLayout: layout,
|
|
139
|
+
force: true,
|
|
97
140
|
});
|
|
98
141
|
}
|
|
99
142
|
/**
|
|
@@ -141,9 +184,13 @@ export class FoxgloveViewer extends TypedEventTarget {
|
|
|
141
184
|
else if (command.type === "set-data-source") {
|
|
142
185
|
this.#latestCommands.dataSource = command;
|
|
143
186
|
}
|
|
144
|
-
else {
|
|
187
|
+
else if (command.type === "set-layout" && !this.#latestCommands.selectLayout) {
|
|
145
188
|
this.#latestCommands.layout = command;
|
|
146
189
|
}
|
|
190
|
+
else if (command.type === "select-layout") {
|
|
191
|
+
this.#latestCommands.layout = undefined;
|
|
192
|
+
this.#latestCommands.selectLayout = command;
|
|
193
|
+
}
|
|
147
194
|
if (this.#isReady) {
|
|
148
195
|
this.#postCommand(command);
|
|
149
196
|
}
|
|
@@ -179,7 +226,7 @@ export class FoxgloveViewer extends TypedEventTarget {
|
|
|
179
226
|
payload: {
|
|
180
227
|
orgSlug: this.#orgSlug,
|
|
181
228
|
initialDataSource: this.#latestCommands.dataSource?.payload,
|
|
182
|
-
|
|
229
|
+
initialLayoutParams: this.#latestCommands.selectLayout?.payload,
|
|
183
230
|
initialExtensions: this.#latestCommands.extension.flatMap((command) => command.payload),
|
|
184
231
|
},
|
|
185
232
|
});
|
|
@@ -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,2BAA2B;QAC3B,IAAI,CAAC;YACH,IAAI,CAAC,OAAO,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,CAAC;QACjC,CAAC;QAAC,MAAM,CAAC;YACP,MAAM,IAAI,KAAK,CAAC,wCAAwC,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CAA0C,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.
|
|
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;AA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AM,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,EAAE,gBAAgB,CAAC;IAC/B,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,43 @@ 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.
|
|
170
|
+
*
|
|
171
|
+
* @example
|
|
172
|
+
* ```
|
|
173
|
+
* // Load a layout from stored using "layout-a" storage key. If no layout with the same storage key is found,
|
|
174
|
+
* //a new layout will be created and saved to the local storage.
|
|
175
|
+
* window
|
|
176
|
+
* .showOpenFilePicker({
|
|
177
|
+
* multiple: false,
|
|
178
|
+
* types: [
|
|
179
|
+
* {
|
|
180
|
+
* description: ".json",
|
|
181
|
+
* accept: {
|
|
182
|
+
* "application/json": [".json"],
|
|
183
|
+
* },
|
|
184
|
+
* },
|
|
185
|
+
* ],
|
|
186
|
+
* })
|
|
187
|
+
* .then(async (handles) => {
|
|
188
|
+
* const file = await handles[0]!.getFile();
|
|
189
|
+
* const layoutData = JSON.parse(await file.text());
|
|
190
|
+
* viewer.selectLayout({
|
|
191
|
+
* storageKey: "layout-a",
|
|
192
|
+
* opaqueLayout: layoutData,
|
|
193
|
+
* });
|
|
194
|
+
* });
|
|
195
|
+
* ```
|
|
196
|
+
*/
|
|
197
|
+
public selectLayout(params: SelectLayoutParams): void {
|
|
198
|
+
this.#queueCommand({
|
|
199
|
+
type: "select-layout",
|
|
200
|
+
payload: params,
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
|
|
150
204
|
/**
|
|
151
205
|
* Set the layout of the embedded viewer. The layout data is an opaque JavaScript object, which
|
|
152
206
|
* should be parsed from a JSON layout file that was exported from the Foxglove app.
|
|
@@ -172,11 +226,13 @@ export class FoxgloveViewer extends TypedEventTarget {
|
|
|
172
226
|
* viewer.setLayoutData(layoutData);
|
|
173
227
|
* });
|
|
174
228
|
* ```
|
|
229
|
+
* @deprecated Use `selectLayout` instead
|
|
175
230
|
*/
|
|
176
231
|
public setLayoutData(layout: OpaqueLayoutData): void {
|
|
177
|
-
this
|
|
178
|
-
|
|
179
|
-
|
|
232
|
+
this.selectLayout({
|
|
233
|
+
storageKey: DEFAULT_LAYOUT_STORAGE_KEY,
|
|
234
|
+
opaqueLayout: layout,
|
|
235
|
+
force: true,
|
|
180
236
|
});
|
|
181
237
|
}
|
|
182
238
|
|
|
@@ -230,8 +286,11 @@ export class FoxgloveViewer extends TypedEventTarget {
|
|
|
230
286
|
this.#latestCommands.extension.push(command);
|
|
231
287
|
} else if (command.type === "set-data-source") {
|
|
232
288
|
this.#latestCommands.dataSource = command;
|
|
233
|
-
} else {
|
|
289
|
+
} else if (command.type === "set-layout" && !this.#latestCommands.selectLayout) {
|
|
234
290
|
this.#latestCommands.layout = command;
|
|
291
|
+
} else if (command.type === "select-layout") {
|
|
292
|
+
this.#latestCommands.layout = undefined;
|
|
293
|
+
this.#latestCommands.selectLayout = command;
|
|
235
294
|
}
|
|
236
295
|
|
|
237
296
|
if (this.#isReady) {
|
|
@@ -277,7 +336,7 @@ export class FoxgloveViewer extends TypedEventTarget {
|
|
|
277
336
|
payload: {
|
|
278
337
|
orgSlug: this.#orgSlug,
|
|
279
338
|
initialDataSource: this.#latestCommands.dataSource?.payload,
|
|
280
|
-
|
|
339
|
+
initialLayoutParams: this.#latestCommands.selectLayout?.payload,
|
|
281
340
|
initialExtensions: this.#latestCommands.extension.flatMap((command) => command.payload),
|
|
282
341
|
},
|
|
283
342
|
});
|
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.
|
|
45
|
+
* */
|
|
46
|
+
opaqueLayout: OpaqueLayoutData;
|
|
47
|
+
/** If true, opaqueLayout will override the layout if it already exists. Default: false */
|
|
48
|
+
force?: boolean;
|
|
49
|
+
};
|