Skip to content

Commit 4c735d8

Browse files
committed
Update doc, comments
1 parent 366cc20 commit 4c735d8

3 files changed

Lines changed: 26 additions & 17 deletions

File tree

packages/app-utils/src/plugins/PluginUtils.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ export async function loadJson(jsonUrl: string): Promise<PluginManifest> {
5050
/**
5151
* Load all plugin modules available based on the manifest file at the provided base URL.
5252
* Plugins are loaded sequentially so that each plugin's exports are registered
53-
* in the module resolve map before subsequent plugins load. This allows plugins
54-
* to depend on other plugins via standard require() calls.
53+
* in the module resolve map before subsequent plugins load. This enables
54+
* cross-plugin imports via standard import statements.
5555
* @param modulePluginsUrl The base URL of the module plugins to load
5656
* @returns A map from the name of the plugin to the plugin module that was loaded
5757
*/
@@ -73,7 +73,7 @@ export async function loadModulePlugins(
7373
const pluginMap: PluginModuleMap = new Map();
7474

7575
// Load plugins sequentially so each plugin's exports are available
76-
// to subsequently loaded plugins via require()
76+
// to subsequently loaded plugins via import
7777
for (let i = 0; i < sortedPlugins.length; i += 1) {
7878
const { name, main, version, package: packageName } = sortedPlugins[i];
7979
const pluginMainUrl = `${modulePluginsUrl}/${name}/${main}`;

packages/plugin/MIDDLEWARE_ARCHITECTURE.md renamed to packages/plugin/docs/middleware-architecture.md

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,15 @@ interface WidgetMiddlewareComponentProps<T = unknown> extends WidgetComponentPro
5050
}
5151
```
5252

53+
### `WidgetMiddlewarePanelProps`
54+
55+
```tsx
56+
interface WidgetMiddlewarePanelProps<T = unknown> extends WidgetPanelProps<T> {
57+
// The next panel component in the chain — render this to continue
58+
Component: React.ComponentType<WidgetPanelProps<T>>;
59+
}
60+
```
61+
5362
## Rendering Paths
5463

5564
The middleware is applied in two different contexts:
@@ -91,15 +100,15 @@ const myToolbarPlugin = {
91100
### Intercepting Props
92101

93102
```tsx
94-
function PropsInterceptor({ Component, ...props }: WidgetMiddlewareComponentProps) {
103+
function PropsInterceptor({ Component, fetch, ...rest }: WidgetMiddlewareComponentProps) {
95104
// Modify or augment props before passing them to the wrapped component
96105
const enhancedFetch = useCallback(async () => {
97-
const widget = await props.fetch();
106+
const widget = await fetch();
98107
// Transform or cache the widget data
99108
return widget;
100-
}, [props.fetch]);
109+
}, [fetch]);
101110

102-
return <Component {...props} fetch={enhancedFetch} />;
111+
return <Component {...rest} fetch={enhancedFetch} />;
103112
}
104113
```
105114

@@ -169,31 +178,31 @@ const plugins = new Map([
169178
2. **Last base plugin wins.** If multiple non-middleware plugins register for the same type, the last one replaces earlier ones (with a warning).
170179
3. **Middleware must render `Component`.** If a middleware doesn't render the `Component` prop, the rest of the chain (including the base widget) will not appear.
171180
4. **Middleware must spread props.** Pass all received props to `Component` to ensure the base widget and other middleware receive them.
172-
5. **`panelComponent` middleware is separate.** If the base plugin defines a `panelComponent`, middleware targeting the panel layer must also define `panelComponent`.
181+
5. **`panelComponent` middleware is separate.** When the base plugin defines a `panelComponent`, only middleware that also defines `panelComponent` is applied. Middleware with only `component` is silently skipped in the panel path — it will have no effect for that widget type.
173182

174183
## Cross-Plugin Dependencies
175184

176-
Plugins load sequentially in manifest order. A plugin can expose its exports for later plugins to import at runtime by declaring a `package` field in the manifest.
185+
Plugins load sequentially in dependency order (topologically sorted by the `dependencies` field, with manifest order preserved among independent plugins). A plugin can expose its exports for later plugins to import at runtime by declaring a `package` field in the manifest.
177186

178187
```
179-
1. pivot loads → resolve["@deephaven/js-plugin-pivot"] = exports
188+
1. pivot loads → exports registered under "@deephaven/js-plugin-pivot"
180189
2. grid-toolbar loads → import "@deephaven/js-plugin-pivot" ✓
181190
```
182191

183192
### Optional Manifest `package` Field
184193

185-
When present, the plugin's exports are registered in the resolve map under this key.
194+
When present, the plugin's exports are made available to other plugins under this key, so they can be imported via standard `import` statements.
186195

187196
```json
188197
{
189198
"plugins": [
190-
{ "name": "pivot", "main": "src/js/dist/index.js", "package": "@deephaven/js-plugin-pivot" },
191-
{ "name": "grid-toolbar", "main": "src/js/dist/bundle/index.js" }
199+
{ "name": "pivot", "main": "src/js/dist/index.js", "version": "0.0.0", "package": "@deephaven/js-plugin-pivot" },
200+
{ "name": "grid-toolbar", "main": "src/js/dist/bundle/index.js", "version": "0.0.0", "dependencies": ["@deephaven/js-plugin-pivot"] }
192201
]
193202
}
194203
```
195204

196-
Here `pivot` is importable (has `package`); `grid-toolbar` only consumes.
205+
Here `pivot` is importable (has `package`); `grid-toolbar` declares it as a dependency and only consumes.
197206

198207
### Consuming Another Plugin
199208

@@ -236,6 +245,6 @@ Here `pivot` is importable (has `package`); `grid-toolbar` only consumes.
236245

237246
- Plugins are topologically sorted by their `dependencies` before loading.
238247
Circular dependencies throw an error at load time.
239-
- Only plugins with a `package` field are registered in the resolve map.
248+
- Only plugins with a `package` field are importable by other plugins.
240249
- The `package` value must exactly match the `import` string.
241250
- Dependency values in `dependencies` must match a `package` field of another plugin.

packages/plugin/src/PluginUtils.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,8 @@ export type PluginManifestPluginInfo = {
214214
/**
215215
* The npm package name for this plugin (e.g. `@deephaven/js-plugin-pivot`).
216216
* When provided, the plugin's exports are registered in the module resolve
217-
* map under this key, enabling other plugins to `require()` this plugin at
218-
* runtime. If omitted, the plugin is not registered for cross-plugin imports.
217+
* map under this key, making this plugin importable by other plugins at
218+
* runtime. If omitted, the plugin is not available for cross-plugin imports.
219219
*/
220220
package?: string;
221221
/**

0 commit comments

Comments
 (0)