Core DevPre-alpha
SWC widgets and addon entries
Register custom field widgets and views from addons using TypeScript 7 modules.
Manifest
{
"name": "my_module",
"swc_entry": "static/swc/main.js"
}
The kernel serves addon static files under /static/addon/. Compile your entry to the same ES2022 target as the core bundle (make swc in core/swc for reference).
Register a field widget
Full walkthrough: Build a module with SWC.
// static/swc/main.ts — import from the core bundle
const { registry, SwcComponent, html } = window.SumeruSWC;
class MyWidget extends SwcComponent {
setup() {}
template() {
const { field, record, readonly } = this.props;
const val = String(record.get(field.name) ?? "");
return html`<div class="sum-field-widget">
<label class="sum-field-label">${field.string ?? field.name}</label>
<div class="sum-field-control">
<input class="sum-field-input" value=${val}
readonly=${readonly ? "readonly" : undefined}
@input=${(ev: Event) => record.set(field.name, (ev.target as HTMLInputElement).value)} />
</div>
</div>`;
}
}
registry.category("fields").add("my_widget", MyWidget);
Reference in view XML:
<field name="x" widget="my_widget"/>
Use renderFieldShell() from the core bundle for consistent labels and accessibility (see core/swc/src/widgets/field-shell.ts).
Register a view
registry.category("views").add("my_view", MyListView);
Register a service
registry.category("services").add("my_service", myServiceInstance);
Use useService("my_service") inside components with an active SwcEnv.
Conventions
- Target TypeScript 7; run
tsc --noEmitin CI for addon SWC packages. - Use existing
sum-*CSS classes fromcore/engine/assets/css/. - Read/write data via
env.services.rpc— do not POST to removed/web/record/saveroutes. - Field widgets receive
{ field, record, readonly }props (SwcRecordfromRecordStore).
Core services
| Service | Purpose |
|---|---|
rpc | Model CRUD, onchange, read_group |
action | SPA navigation via RouterService |
dialog | Confirm/alert modals |
bus | Local + WebSocket events (record.updated) |
notification | Toast stack — SWC notifications |
Built-in widgets
See the complete SWC widget catalog (25+ registry keys including boolean_toggle, many2many_tags, monetary, progress, …).
Global exports
The IIFE bundle exposes window.SumeruSWC:
export { SwcApp, registry, SwcEnv };