@foxglove/extension 2.37.0 → 2.38.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@foxglove/extension",
3
- "version": "2.37.0",
3
+ "version": "2.38.0",
4
4
  "license": "MIT",
5
5
  "author": {
6
6
  "name": "Foxglove Technologies",
@@ -72,6 +72,14 @@ export namespace Experimental {
72
72
  initPanel: (context: PanelExtensionContext) => void | (() => void);
73
73
  };
74
74
 
75
+ /**
76
+ * See: {@link ExtensionContext.registerUserScriptUtility}
77
+ */
78
+ export type RegisterUserScriptUtilityArgs = {
79
+ name: `${string}.ts`;
80
+ source: string;
81
+ };
82
+
75
83
  export interface ExtensionContext extends BaseExtensionContext {
76
84
  /**
77
85
  * Register a data loader to add support for additional file formats.
@@ -99,6 +107,44 @@ export namespace Experimental {
99
107
  * optional cleanup function to run when the extension `panelElement` unmounts.
100
108
  */
101
109
  registerPanel(params: ExtensionPanelRegistration): void;
110
+
111
+ /**
112
+ * Register a new user-script utility.
113
+ *
114
+ * This utility is available to all user-scripts and imported by its name.
115
+ *
116
+ * Example registration:
117
+ *
118
+ * ```
119
+ * registerUserScriptUtility({
120
+ * name: "my_add.ts",
121
+ * source: `
122
+ * export function add(a: number, b: number) {
123
+ * return a + b;
124
+ * }
125
+ * `);
126
+ * ```
127
+ *
128
+ * You can also keep the source code in a file and import it like this:
129
+ *
130
+ * ```
131
+ * import my_add from "./my_add.ts?raw";
132
+ *
133
+ * registerUserScriptUtility({ name: "my_add.ts", source: my_add });
134
+ * ```
135
+ *
136
+ * Example usage in a user-script:
137
+ *
138
+ * ```
139
+ * import { add } from "./my_add.ts";
140
+ *
141
+ * // ... call `add` in your script function or wherever needed
142
+ * ```
143
+ *
144
+ * @param name
145
+ * @param source
146
+ */
147
+ registerUserScriptUtility(args: RegisterUserScriptUtilityArgs): void;
102
148
  }
103
149
 
104
150
  export interface ExtensionModule {