Workspace Mode FAQ
How do I tell whether IDE mode is enabled?
- Use the official API: Check workspace.isActive to see whether IDE mode is active. This official lowcode engine API confirms whether you are in the integrated development environment.
How do I use plugin ctx to detect the current mode?
Whether the plugin is application-level: Use ctx.isPluginRegisteredInWorkspace to tell whether a plugin is application-level. This helps you understand the plugin's scope and usage in the lowcode engine.
Plugin registration level: Use ctx.registerLevel to see which level a plugin is registered at. Possible values:
- Default: Default level. Used in non-IDE mode
- Workspace: Application level
- Resource: Resource level
- EditorView: Editor view level
These levels represent the plugin's scope and help you control and configure plugins more precisely when building and managing lowcode applications.
How do I set the resource list in IDE mode?
- Set resource list API: In IDE mode, use workspace.setResourceList to set or update the resource list in the IDE so resources opened in editor windows are current and accessible.
How do I open an editor view window?
- Recommended approach: Use
openEditorWindow(resource: Resource, sleep?: boolean): Promise<void>;to open an editor window. resource is the specific resource to open; get it from workspace.resourceList. - Deprecated approach (not recommended):
openEditorWindow(resourceName: string, id: string, extra: Object, viewName?: string, sleep?: boolean): Promise<void>;also opens editor windows. It still works but is not recommended and may be removed later because of maintenance and extensibility limits.
How do I get view context in a global plugin?
In a global plugin for the lowcode engine, use ProvideViewPluginContext from @rchh/lowcode-utils so your React component receives pluginContext as props and can access and manipulate the current view's state and properties.
Steps
Import dependencies: Ensure your plugin file imports ProvideViewPluginContext and other required dependencies.
import { ProvideViewPluginContext } from '@rchh/lowcode-utils';
Define a React component: Create a React component that uses pluginContext from ProvideViewPluginContext.
const MyComponent = (props) => {
const { pluginContext } = props;
// Component logic
return <div>/* Component content */</div>;
};
Define the global plugin: Define a function invoked when the plugin is registered. It receives a context object ctx that exposes engine APIs.
const globalPlugin = (ctx) => {
const { skeleton } = ctx;
skeleton.add({
type: 'PanelDock',
name: 'datapool',
content: ProvideViewPluginContext((props) => {
// Component content
return <MyComponent {...props} />;
}),
// Other configuration
contentProps: {
// pluginContext must be passed as a parameter
pluginContext: ctx,
},
});
};
With these steps, React components in your global plugin can access and use view context, enabling richer plugin behavior and interactions.
Notes
- Component re-rendering: Normally, pluginContext is the view context. When the view changes, the component re-renders. To handle re-renders on view switch, use React's key prop.
Example
ProvideViewPluginContext(props => {
return (
<DataPoolPane
{...props}
key={props.pluginContext?.editorWindow?.id}
/>
});
When the view changes, the component re-renders according to the active view, keeping component state aligned with the current view context. This is useful when building complex plugins and interactions on the lowcode platform.
How do I tell whether a plugin is registered in Workspace mode?
Use ctx.isPluginRegisteredInWorkspace():
if (ctx.isPluginRegisteredInWorkspace('pluginName')) {
console.log('Plugin is registered in Workspace mode.');
} else {
console.log('Plugin is not registered in Workspace mode.');
}
Note: This method is currently in beta and TypeScript may report it as removed.
Check ctx.registerLevel:
if (ctx.registerLevel !== IPublicEnumPluginRegisterLevel.Workspace) {
console.log('Plugin is not registered in Workspace mode.');
} else {
console.log('Plugin is registered in Workspace mode.');
}