1.3 KiB
1.3 KiB
Custom Canvas & Widget Extension
Overview
This document describes the mechanism for extending the playground canvas with custom widgets loaded on-demand.
Widget Library Structure
External widget libraries are defined in a library.json file.
Example: public/widgets/email/library.json
{
"root": "./body.html",
"name": "email",
"description": "Email widgets",
"widgets": [
{
"name": "HR",
"template": "./hr.html"
},
...
]
}
HtmlWidget Proxy
To render HTML templates within the React-based canvas, we use a generic HtmlWidget component.
This component:
- Accepts a
templateUrlprop. - Fetches the HTML content from the given URL.
- Renders the content using
dangerouslySetInnerHTML. - Wraps the content in a container that preserves styles/layout.
Runtime Registration
Widgets are registered dynamically using widgetRegistry.register().
When a context (e.g., "Email") is loaded:
- The
library.jsonis fetched and parsed. - For each widget, a wrapper component is created using
HtmlWidget. - The component is registered via
widgetRegistry.register()with a unique ID (e.g.,email.hr). - The
WidgetPalettewill automatically reflect these new widgets upon next render (open).