UI Dashboard
The full fragment protocol in one shot: an app declares slots, mods contribute fragments, and everything binds to live host data.
What It Shows
Section titled “What It Shows”- Host app with three slots (
sidebar.left,header.status,main.overlay) - Health panel mod using
data-bindfor values anddata-iffor conditional warnings - Inventory panel mod using the sandbox fragment API for iteration
- Fragment lifecycle with
hooks.fragment.updatehandlers - Cross-validation ensuring mods target valid slots
Running the Demo
Section titled “Running the Demo”node examples/ui-dashboard/src/demo.jsThe demo loads two mods, simulates game state changes (health decreasing, items being added), and prints the fragment HTML at each step.
App Manifest
Section titled “App Manifest”The host declares three slots:
{ "slots": [ { "id": "sidebar.left", "accepts": ["text/html"], "multiple": true, "style": "isolated" }, { "id": "header.status", "accepts": ["text/html"], "multiple": false, "style": "inherit" }, { "id": "main.overlay", "accepts": ["text/html"], "capability": "ui-mount", "multiple": true, "style": "scoped" } ]}Health Panel Fragment
Section titled “Health Panel Fragment”The fragment uses data-bind to display values and data-if for conditional warnings:
<div class="health-panel"> <div class="player-name" data-bind="name">Unknown</div> <div class="health-bar"> <span data-bind="health">0</span>/<span data-bind="maxHealth">0</span> </div> <div data-if="health < 50" class="warning">Low health!</div> <div data-if="health < 20" class="critical">Critical — find a healer!</div></div>The mod script uses the sandbox fragment API for more complex updates:
hooks.fragment.update("health-display", function (bindings, fragment) { var pct = (bindings.health / bindings.maxHealth) * 100; var color = pct > 60 ? "green" : pct > 30 ? "yellow" : "red"; fragment.setAttr(".health-bar", "data-color", color); fragment.toggle(".warning", bindings.health < 50); fragment.toggle(".critical", bindings.health < 20);});Inventory Panel — Sandbox Iteration
Section titled “Inventory Panel — Sandbox Iteration”Since data-bind handles values and data-if handles visibility, iteration over arrays uses the sandbox fragment API:
hooks.fragment.update("inventory-list", function (bindings, fragment) { var items = bindings.inventory || []; var html = items.map(function (item) { return "<li>" + item.name + " (x" + item.count + ")</li>"; }); fragment.replaceChildren(".item-list", html); fragment.toggle(".empty-message", items.length === 0);});Loading Mods
Section titled “Loading Mods”The host loads mods using runtime.loadMod():
const healthMod = runtime.loadMod(modManifest, { fragmentSources: { "fragments/panel.html": panelHtml, "src/mod.js": modScript, },});Fragment sources are provided as a Record<string, string>; the runtime sanitizes them on load.
What Happens at Each Step
Section titled “What Happens at Each Step”- Full health (80/100):
data-if="health < 50"evaluates tofalse— warnings hidden. Fragment API sets color to green. - After damage (40/100):
data-if="health < 50"flips totrue— warning shows. Color becomes yellow. - Critical (15/100): Both warnings visible. Color becomes red. New item appears in inventory via
replaceChildren.
See the source code for the complete example.