Host API
In the running environment of host.js
, we provide a global variable hostApi
, which encapsulates and implements the corresponding API on hostApi
to enable interaction with Pixso. The details are as follows:
Event
hostApi provides three interfaces: on
, once
, and off
to register and remove event listeners. The currently supported event types are as follows:
mounted
: Triggered afterhost.js
is loaded;beforeunmount
:host.js
is triggered before unmounting, such as:- Close the plug-in configured with
host.js
;
- Close the plug-in configured with
- Pixso exits design mode;
type HostArgFreeEventType = "mounted" | "beforeunmount";
on
- type:
on(type: HostArgFreeEventType, callback: () => void): void;
The on
method allows you to register a handler function for a specific event, and the callback function will be executed when the event occurs.
once
- type:
once(type: HostArgFreeEventType, callback: () => void): void;
The once
method allows you to register a handler function for a specific event, and the callback function will be executed when the event occurs. The difference from the on
method is that the event handler registered through the once
method will only be executed once.
off
- type:
off(type: HostArgFreeEventType, callback: () => void): void;
Remove event handlers bound via hostApi.on
or hostApi.once
.
Sandbox-related
The interfaces under this category are only valid in host.js
running under the plug-in, and are mainly used to communicate with the sandbox.js
of the plugin.
sandbox.postMessage
- type:
postMessage: (message: any) => void
Messages are sent from host.js
to sandbox.js
.
sandbox.onmessage
- type:
Function | undefined
Listen for messages sent by sandbox.js
to host.js
.
sandbox.on
- type:
on: (event: 'message', cb: (event: any) => void) => void
Listen for messages sent by sandbox.js
to host.js
.
sandbox.once
- type:
once: (event: 'message', cb: (event: any) => void) => void
Listen for messages sent by sandbox.js
to host.js
, and remove the listener after the callback function runs once.
sandbox.off
- type:
off: (event: 'message', cb: (event: any) => void) => void
Removes a listener bound via the sandbox.on
or sandbox.once
interface.
Others
showPluginDockAsync
- type:
showPluginDockAsync(): Promise<void>
Show the plugin dock.
setLibraryConfig
- type:
setLibraryConfig(config: Partial<LibraryConfig>): void
Set the UI of the resource library to be visible and hidden
interface LibraryConfig {
enabled_team_library: boolean; // 一键关闭团队资源库
enabled_ent_library: boolean; // 一键关闭企业资源库
enabled_team_left_component_panel: boolean; // 是否启用团队左侧组件面板
enabled_ent_left_component_panel: boolean; // 是否启用企业左侧组件面板
enabled_team_instance_replace: boolean; // 是否启用团队实例替换
enabled_ent_instance_replace: boolean; // 是否启用企业实例替换
enabled_team_style_replace: boolean; // 是否启用团队样式替换
enabled_ent_style_replace: boolean; // 是否启用企业样式替换
enabled_team_library_tab: boolean; // 是否启用团队资源库发布页
enabled_ent_library_tab: boolean; // 是否启用企业资源库发布页
enabled_team_library_publish: boolean; // 是否启用团队资源库发布
enabled_ent_library_publish: boolean; // 是否启用企业资源库发布
enabled_team_library_replace: boolean; // 是否启用团队资源库替换
enabled_ent_library_replace: boolean; // 是否启用企业资源库替换
enabled_library_missing_replace: boolean; // 是否启用缺失资源库替换功能
}