Component explorer / Application controls
Composition: a JS and YAML workspace
Declare a table, tiles, actions and a lazy editor around one shared model, with application logic in ordinary JavaScript.
The definition is authored in YAML and compiled to JSON at build time. Registered functions execute the behaviour. Mock edits, selection and drafts last for this visit; browser reload does not restore them.
Code for this example
These excerpts come from the code running above, formatted for reading. They focus on the component behaviour; imports, fixtures and page setup are available in Full application source below.
Bind two presentations to one model
The YAML names the children and connects their collection, selection and renderer properties. It is configuration over the same runtime used by JavaScript definitions.
From apps/showcase/src/examples/composition/composition.ui.yaml
table:
type: Grid
props:
ctx: { ref: inputs.ctx }
label: Managed devices table
selectable: true
selectionColumn: true
collection: { ref: model.collection }
selection: { ref: model.selection }
view:
columns:
- { field: name }
- { field: platform, width: 130 }
- { field: owner, width: 140 }
sort: []
filters: {}
frozen: 0
tiles:
type: TileGrid
create: on-demand
retain: true
props:
virtualized: true
label: Managed device tiles
selectable: true
collection: { ref: model.collection }
selection: { ref: model.selection }
renderTile: { renderer: device-card }
presentTile: { renderer: device-description }Connect actions and their PageRules
Command names resolve to exports from the registered model. The Save rule reads published editor state; the executable save function stays in JavaScript.
From apps/showcase/src/examples/composition/composition.ui.yaml
commands:
table: { use: model.commands.table }
tiles: { use: model.commands.tiles }
clear: { use: model.commands.clear }
edit:
use: model.commands.edit
enabledWhen: devices.any
reason: Select a device to edit.
save:
use: model.commands.save
enabledWhen:
op: and
args:
- editor.dirty
- { op: not, arg: editor.busy }
reason: Change a field before saving.
discard: { use: model.commands.discard }Implement queries, commands and cleanup in JavaScript
This is the running model and its save function. The lifetime releases the collection and editor. A single editor survives table/tile switching, and saving updates their shared store.
From apps/showcase/src/examples/composition/composition-model.js
async function saveDevice(editor) {
const saved = await editor.save();
if (!saved)
throw new Error("Review the field errors before saving again.");
return saved;
}
export function createDeviceWorkspace({ ctx, selection: selectionPolicy }, lifetime) {
const query = signal("");
const collection = ctx.collection(computed(() => {
const name = query.value.trim();
return {
set: "Devices", orderBy: [{
field: "name"
}], ...(name ? {
filter: {
op: "contains", field: "name", value: name
}
} : {})
};
}), {
pageSize: 24, keepPages: 3
});
lifetime.defer(() => ctx.release(collection));
const selection = new Selection(ctx.store, collection, selectionPolicy);
const presentation = signal("table");
const editor = signal();
const detailsOpen = computed(() => editor.value !== undefined);
const dirty = computed(() => editor.value?.dirty.value ?? false);
const busy = computed(() => editor.value?.busy.value ?? false);
const message = signal("Select a device, open its editor, then try both presentations.");
const closeEditor = () => { const previous = editor.value; editor.value = undefined; previous?.dispose(); };
lifetime.defer(closeEditor);
const ownCommand = options => lifetime.own(command(options));
const commands = {
table: ownCommand({
label: "Table", run: () => { presentation.value = "table"; }
}),
tiles: ownCommand({
label: "Tiles", run: () => { presentation.value = "tiles"; }
}),
clear: ownCommand({
label: "Clear selection", enabled: () => selection.any.value, run: () => selection.clear()
}),
edit: ownCommand({
label: "Edit selected", enabled: () => selection.any.value && !detailsOpen.value,
reason: () => detailsOpen.value ? "Save or discard the current draft first." : "Select a device to edit.",
run: () => { editor.value = new EditModel(ctx, "Devices", selection.key.value); message.value = "One draft is shared across both presentations. Save also works with Ctrl/⌘ S."; }
}),
save: ownCommand({
label: "Save device", enabled: () => dirty.value && !busy.value,
run: async (signal) => { const edit = editor.value; await saveDevice(edit); signal.throwIfAborted(); message.value = "Saved. The shared store updated both views."; closeEditor(); }
}),
discard: ownCommand({
label: "Discard draft", enabled: () => detailsOpen.value && !busy.value,
run: () => { closeEditor(); message.value = "Draft discarded. The stored record is unchanged."; }
}),
};
return {
values: {
collection, selection, presentation, editor, detailsOpen, dirty, busy, query, message
},
publications: {
selection: selectionPublication(selection), editor: valuesPublication({
dirty, busy
})
},
commands,
};
}
Register a lazy child through ordinary module loading
The registry allowlists the component and supplies its dynamic import. YAML activates the named child; it cannot invent executable code or arbitrary module URLs.
From apps/showcase/src/examples/composition/composition-registry.js
let detailsModule;
for (const [type, factory] of [["DeviceDetails", "createDetails"], ["CompactDetails", "createCompactDetails"]]) {
components[type] = {
props: {
editor: t.optional(t.custom("EditModel", value => !!value?.save))
},
load: async () => { detailsModule = await import("./composition-details.js"); return detailsModule[factory]; },
apply: (element, props) => detailsModule.applyDetails(element, props),
};
}
Full application source Application code & shared presentation
import { metadata, data } from "./composition-mock.js";
import { Composite, deriveComposite } from "@getaster/elements";
import { effect } from "@preact/signals-core";
import { html } from "lit-html";
import { DataContext } from "@getaster/data";
import { createMockService } from "@getaster/mock";
import { authoring, registry } from "./composition-registry.js";
const out = document.querySelector("#workspace");
Object.assign(document.querySelector("#query"), { label: "Find a device", labelled: true, placeholder: "Try ‘012’", keyboard: "search" });
document.querySelector("#reset").label = "Recreate workspace";
const dialog = document.querySelector("#confirm-reset");
let discard = false;
const answer = result => { discard = result; dialog.close(); };
dialog.title = "Discard this draft?";
dialog.content = html`<p>Recreating the workspace clears its selection and unsaved draft.</p>`;
dialog.footer = html`<aster-button .label=${"Keep editing"} @click=${() => answer(false)}></aster-button><aster-button .label=${"Discard and recreate"} @click=${() => answer(true)}></aster-button>`;
try {
const mock = await createMockService({ metadata, data, wasm: new URL("../lib/odata_mock.wasm", import.meta.url) });
const ctx = await DataContext.connect(mock.transport);
const response = await fetch("./composition.ui.json");
if (!response.ok) throw new Error("The workspace definition could not be loaded.");
const { definition: sourceDefinition, sources } = await response.json();
const definition = authoring.validate(sourceDefinition, sources);
let instance;
let stop;
let timer;
let variant = "standard";
const variants = {
standard: definition,
semantic: definition,
single: deriveComposite(definition, { name: "SingleDeviceWorkspace", modelInputs: { selection: { multiple: false, fallback: false } } }),
inspect: deriveComposite(definition, { name: "DisplayOnlyTable", children: { table: { props: { selectable: false, label: "Devices (selection controlled by Tiles)" } } } }),
compact: deriveComposite(definition, { name: "CompactDeviceWorkspace", children: { details: { type: "CompactDetails" } } }),
};
const variantChoice = document.querySelector("#variant");
variantChoice.label = "Workspace variant";
variantChoice.options = [ { value: "standard", label: "Standard" }, { value: "single", label: "Single selection" }, { value: "inspect", label: "Display-only table" }, { value: "compact", label: "Compact inspector" }, { value: "semantic", label: "Semantic layout" } ];
variantChoice.value = variant;
function mount() {
const placement = variant === "semantic" ? authoring.placement(variants[variant], place => html`
<section class="composition-regions" aria-label="Device workspace">
<header>${place("views")}${place("actions")}${place("status")}</header>
<section aria-label="Device views">${place("table")}${place("tiles")}</section>
<aside aria-label="Device inspector">${place("details")}</aside>
</section>`) : undefined;
instance = new Composite(variants[variant], registry, { inputs: { ctx }, ctx, sources, ...(placement ? { placement } : {}) }).mount(out);
stop = effect(() => {
document.querySelector("#status").textContent = instance.model.message.value;
document.querySelector("#rule-status").textContent = instance.commands.save.reason.value ?? "Save is available.";
});
document.querySelector("#query").value = "";
globalThis.compositionDemo = { instance, registry, authoring, definition, variants, sources, ctx, mock };
}
mount();
const schemaLink = document.querySelector("#download-schema");
const schemaUrl = URL.createObjectURL(new Blob([JSON.stringify(authoring.schema(definition), null, 2)], { type: "application/schema+json" }));
schemaLink.href = schemaUrl;
schemaLink.download = "composition.schema.json";
addEventListener("pagehide", event => { if (!event.persisted) URL.revokeObjectURL(schemaUrl); });
document.querySelector("#query").addEventListener("input", event => { clearTimeout(timer); const value = event.target.value; timer = setTimeout(() => { instance.model.query.value = value; }, 160); });
addEventListener("keydown", event => {
if ((event.metaKey || event.ctrlKey) && event.key.toLowerCase() === "s") { event.preventDefault(); void instance.commands.save.execute().catch(() => {}); }
});
function teardown() { clearTimeout(timer); stop(); instance.dispose(); }
document.querySelector("#reset").addEventListener("click", async () => {
const dirty = instance.model.dirty.value;
if (instance.model.busy.value) return;
if (dirty && !await confirmDiscard()) return;
teardown(); mount();
});
let changing = false;
variantChoice.addEventListener("change", async event => {
if (event.target !== variantChoice || changing) return;
const next = variantChoice.value;
if (instance.model.busy.value) { variantChoice.value = variant; return; }
changing = true;
try {
if (instance.model.dirty.value && !await confirmDiscard()) { variantChoice.value = variant; return; }
teardown(); variant = next; mount();
} finally { changing = false; }
});
async function confirmDiscard() {
discard = false;
return new Promise(resolve => {
dialog.addEventListener("close", () => resolve(discard), { once: true });
dialog.show(document.activeElement);
});
}
addEventListener("pagehide", event => { if (!event.persisted) teardown(); });
} catch (error) { out.setAttribute("role", "alert"); out.textContent = error.message; }
<!doctype html>
<html lang="en"><head><script type="importmap">{"imports":{"@getaster/data":"../lib/aster-ui.js","@getaster/elements":"../lib/aster-ui.js","@getaster/elements-preview":"../lib/aster-ui-preview.js","@getaster/elements-preview/rich-text":"../lib/aster-ui-rich-text.js","@getaster/data-navigator/model":"../lib/aster-data-navigator.js","@getaster/data-navigator":"../lib/aster-data-navigator.js","@getaster/mock":"../lib/aster-ui-mock.js","lit-html":"../lib/aster-ui.js","@preact/signals-core":"../lib/aster-ui.js"}}</script><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1">
<title>Declarative device workspace — Aster UI</title>
<link id="identity" rel="stylesheet" href="../lib/themes/lamplight.css"><link rel="stylesheet" href="../lib/aster-ui.css"><link rel="stylesheet" href="./showcase.css">
<style>
body { height:auto; min-height:100dvh; padding:24px; background:var(--aster-surface); }
main { max-width:1120px; margin:auto; } h1 { margin-block-end:8px; } a { color:var(--aster-accent); }
.composition-intro { max-width:75ch; color:var(--aster-text-2); }
.composition-tools { display:flex; flex-wrap:wrap; align-items:end; gap:16px; margin-block:24px; }
.composition-tools #variant { width:13rem; }
.composition-tools #query { flex:1; min-width:180px; }
#workspace { border:1px solid var(--aster-rule); border-radius:var(--aster-r-card); padding:20px; }
#workspace aster-grid { height:390px; min-width:0; }
#workspace aster-tile-grid { display:block; --tile-viewport-height:390px; --tile-min-width:208px; --tile-height:174px; }
.composition-device { display:flex; flex-direction:column; align-items:start; gap:8px; padding:12px; }
.composition-device svg { width:42px; height:42px; fill:none; stroke:var(--aster-accent); stroke-width:2; }
.composition-device span { color:var(--aster-text-2); }
.composition-regions { display:grid; gap:16px; }
.composition-regions > header { display:grid; gap:12px; }
.composition-regions > section,.composition-regions > aside { min-width:0; }
.composition-draft-status { display:flex; align-items:center; gap:8px; margin:0; color:var(--aster-text-2); font-size:.875rem; }
.composition-draft-status > span { color:var(--aster-accent); }
.composition-editor { background:var(--aster-sunk); padding:20px; border:1px solid var(--aster-rule); border-radius:var(--aster-r-card); }
.composition-editor h2 { margin-top:0; } .composition-editor p { color:var(--aster-text-2); }
.composition-status { margin-block:20px; padding:16px; border-inline-start:3px solid var(--aster-accent); background:var(--aster-sunk); }
.composition-status p { margin:4px 0; } #rule-status { color:var(--aster-text-2); }
.composition-sources { display:flex; flex-wrap:wrap; gap:16px; margin-block:20px; }
@media(max-width:600px) { body { padding:12px; } #workspace { padding:12px; } .composition-editor { padding:12px; } }
</style></head><body><main>
<h1>Declaratively compose your layouts with YAML or JS</h1>
<p class="composition-intro">Named children, ordinary JavaScript behaviour, one shared selection and editing session. PageRules controls Save; details load only when opened. Mock changes last for this visit.</p>
<div class="composition-tools">
<div class="showcase-appearance"><span>Variant</span><aster-choice id="variant"></aster-choice></div>
<div class="showcase-appearance"><span>Theme</span><aster-choice id="theme"></aster-choice></div>
<div class="showcase-appearance"><span>Scheme</span><aster-choice id="scheme"></aster-choice></div>
<aster-field id="query"></aster-field>
<aster-button id="reset"></aster-button>
</div>
<div id="workspace" aria-label="Declarative device workspace"></div>
<div class="composition-status"><p id="status" role="status">Connecting to the sample fleet…</p><p id="rule-status"></p></div>
<div class="composition-sources"><a href="./composition.ui.yaml">YAML definition</a><a id="download-schema">Download YAML schema</a><a href="./composition-registry.js">Component registrations & renderers</a><a href="./composition.js">Host & lifecycle</a><a href="./composition-model.js">Model & function bodies</a><a href="./composition-details.js">Lazy details component</a><a href="./composition-status.js">Custom component declaration</a><a href="../guide/declarative-workspace.html">How it works →</a></div>
<aster-dialog id="confirm-reset"></aster-dialog>
</main><script type="module" src="./showcase-nav.js"></script><script type="module" src="./composition.js"></script></body></html>
# Parsed at build time; the browser loads composition.ui.json.
version: 1
name: DeviceWorkspace
model:
type: device-workspace
inputs:
ctx: { ref: inputs.ctx }
selection:
multiple: true
ordered: false
fallback: false
customize:
modelInputs: [selection]
children:
views: { optional: true }
table:
props: [label, selectable, view]
tiles:
props: [label, selectable]
details:
replace: [CompactDetails]
publish:
devices: { ref: model.publications.selection }
editor: { ref: model.publications.editor }
commands:
table: { use: model.commands.table }
tiles: { use: model.commands.tiles }
clear: { use: model.commands.clear }
edit:
use: model.commands.edit
enabledWhen: devices.any
reason: Select a device to edit.
save:
use: model.commands.save
enabledWhen:
op: and
args:
- editor.dirty
- { op: not, arg: editor.busy }
reason: Change a field before saving.
discard: { use: model.commands.discard }
children:
status:
type: DraftStatus
props:
label: Device draft status
dirty: { bind: model.dirty }
busy: { bind: model.busy }
views:
type: CommandBar
props:
label: Presentation
commands:
- { ref: commands.table }
- { ref: commands.tiles }
actions:
type: CommandBar
props:
label: Device actions
commands:
- { ref: commands.edit }
- { ref: commands.save }
- { ref: commands.discard }
- { ref: commands.clear }
table:
type: Grid
props:
ctx: { ref: inputs.ctx }
label: Managed devices table
selectable: true
selectionColumn: true
collection: { ref: model.collection }
selection: { ref: model.selection }
view:
columns:
- { field: name }
- { field: platform, width: 130 }
- { field: owner, width: 140 }
sort: []
filters: {}
frozen: 0
tiles:
type: TileGrid
create: on-demand
retain: true
props:
virtualized: true
label: Managed device tiles
selectable: true
collection: { ref: model.collection }
selection: { ref: model.selection }
renderTile: { renderer: device-card }
presentTile: { renderer: device-description }
details:
type: DeviceDetails
create: on-demand
retain: true
props:
editor: { bind: model.editor }
layout:
type: stack
items:
- { child: views }
- { child: actions }
- { child: status }
- type: deck
active: { bind: model.presentation }
items:
table: { child: table }
tiles: { child: tiles }
- type: outlet
active: { bind: model.detailsOpen }
content: { child: details }
Download composition-registry.js
import { asterComponents, compositeElement, compositeTypes as t, defineCompositeRegistry, defineCompositeRenderer } from "@getaster/elements";
import { DataContext } from "@getaster/data";
import { html } from "lit-html";
import { deviceWorkspaceType } from "./composition-model.js";
import { DraftStatus } from "./composition-status.js";
const models = { "device-workspace": deviceWorkspaceType };
const components = { DraftStatus: compositeElement(DraftStatus), CommandBar: asterComponents.CommandBar, Grid: asterComponents.Grid, TileGrid: asterComponents.TileGrid };
const renderers = {};
// YAML's renderer names resolve to these ordinary functions.
function deviceCard(device) {
return html`<div class="composition-device"><svg viewBox="0 0 48 48" aria-hidden="true"><rect x="5" y="6" width="38" height="28" rx="3"/><path d="M16 42h16M24 34v8"/></svg><strong>${device.name}</strong><span>${device.platform} · ${device.owner}</span></div>`;
}
renderers["device-card"] = defineCompositeRenderer(["renderTile"], deviceCard);
renderers["device-description"] = defineCompositeRenderer(["presentTile"], device => ({ title: device.name, description: `${device.platform}, ${device.owner}` }));
// The allowlisted module loader is code, not a URL supplied by YAML.
let detailsModule;
for (const [type, factory] of [["DeviceDetails", "createDetails"], ["CompactDetails", "createCompactDetails"]]) {
components[type] = {
props: { editor: t.optional(t.custom("EditModel", value => !!value?.save)) },
load: async () => { detailsModule = await import("./composition-details.js"); return detailsModule[factory]; },
apply: (element, props) => detailsModule.applyDetails(element, props),
};
}
export const authoring = defineCompositeRegistry({ inputs: { ctx: t.instance(DataContext) }, models, components, renderers });
export const registry = authoring.registry;
export const metadata = { $Version: "4.01", $EntityContainer: "Demo.Container",
$Reference: {
"https://oasis-tcs.github.io/odata-vocabularies/vocabularies/Org.OData.Core.V1.json": { $Include: [{ $Namespace: "Org.OData.Core.V1", $Alias: "Core" }] },
"https://aster.dev/vocabularies/Aster.Data.V1.json": { $Include: [{ $Namespace: "Aster.Data.V1", $Alias: "AsterData" }] },
}, Demo: {
Device: { $Kind: "EntityType", $Key: ["id"], id: { $Type: "Edm.Int32" }, name: { $Nullable: false, "@Core.Description": "Name", "@AsterData.MinLength": 1 }, platform: { "@Core.Description": "Platform" }, owner: { "@Core.Description": "Owner" } },
Container: { $Kind: "EntityContainer", Devices: { $Collection: true, $Type: "Demo.Device" } },
} };
export const data = { Devices: Array.from({ length: 72 }, (_, i) => ({ id: i + 1, name: `Device ${String(i + 1).padStart(3, "0")}`, platform: ["macOS", "Linux", "Windows"][i % 3], owner: ["Design", "Engineering", "Operations"][i % 3] })) };
import { Command, Collection, DataContext, EditModel, Selection, command, selectionOptionsError, selectionPublication, valuesPublication } from "@getaster/data";
import { compositeTypes as t, defineCompositeModel } from "@getaster/elements";
import { computed, signal } from "@preact/signals-core";
// Ordinary application functions, called by this instance's exported commands.
async function saveDevice(editor) {
const saved = await editor.save();
if (!saved) throw new Error("Review the field errors before saving again.");
return saved;
}
export function createDeviceWorkspace({ ctx, selection: selectionPolicy }, lifetime) {
const query = signal("");
const collection = ctx.collection(computed(() => {
const name = query.value.trim();
return { set: "Devices", orderBy: [{ field: "name" }], ...(name ? { filter: { op: "contains", field: "name", value: name } } : {}) };
}), { pageSize: 24, keepPages: 3 });
lifetime.defer(() => ctx.release(collection));
const selection = new Selection(ctx.store, collection, selectionPolicy);
const presentation = signal("table");
const editor = signal();
const detailsOpen = computed(() => editor.value !== undefined);
const dirty = computed(() => editor.value?.dirty.value ?? false);
const busy = computed(() => editor.value?.busy.value ?? false);
const message = signal("Select a device, open its editor, then try both presentations.");
const closeEditor = () => { const previous = editor.value; editor.value = undefined; previous?.dispose(); };
lifetime.defer(closeEditor);
const ownCommand = options => lifetime.own(command(options));
const commands = {
table: ownCommand({ label: "Table", run: () => { presentation.value = "table"; } }),
tiles: ownCommand({ label: "Tiles", run: () => { presentation.value = "tiles"; } }),
clear: ownCommand({ label: "Clear selection", enabled: () => selection.any.value, run: () => selection.clear() }),
edit: ownCommand({ label: "Edit selected", enabled: () => selection.any.value && !detailsOpen.value,
reason: () => detailsOpen.value ? "Save or discard the current draft first." : "Select a device to edit.",
run: () => { editor.value = new EditModel(ctx, "Devices", selection.key.value); message.value = "One draft is shared across both presentations. Save also works with Ctrl/⌘ S."; } }),
save: ownCommand({ label: "Save device", enabled: () => dirty.value && !busy.value,
run: async signal => { const edit = editor.value; await saveDevice(edit); signal.throwIfAborted(); message.value = "Saved. The shared store updated both views."; closeEditor(); } }),
discard: ownCommand({ label: "Discard draft", enabled: () => detailsOpen.value && !busy.value,
run: () => { closeEditor(); message.value = "Draft discarded. The stored record is unchanged."; } }),
};
return {
values: { collection, selection, presentation, editor, detailsOpen, dirty, busy, query, message },
publications: { selection: selectionPublication(selection), editor: valuesPublication({ dirty, busy }) },
commands,
};
}
export const deviceWorkspaceType = defineCompositeModel({
inputs: {
ctx: t.instance(DataContext),
selection: t.refine(
t.object({ multiple: t.boolean, ordered: t.optional(t.boolean), maxOrdered: t.optional(t.positiveInteger), fallback: t.optional(t.boolean) }),
"selection policy (ordered requires multiple; maxOrdered requires ordered)",
value => selectionOptionsError(value) === undefined,
{ allOf: [
{ if: { properties: { ordered: { const: true } }, required: ["ordered"] }, then: { properties: { multiple: { const: true } }, required: ["multiple"] } },
{ if: { required: ["maxOrdered"] }, then: { properties: { ordered: { const: true } }, required: ["ordered"] } },
] },
),
},
exports: {
collection: t.instance(Collection), selection: t.instance(Selection),
presentation: t.signal(t.string), editor: t.signal(t.optional(t.instance(EditModel))),
detailsOpen: t.signal(t.boolean), dirty: t.signal(t.boolean), busy: t.signal(t.boolean), query: t.signal(t.string), message: t.signal(t.string),
},
commands: Object.fromEntries(["table", "tiles", "clear", "edit", "save", "discard"].map(name => [name, t.instance(Command)])),
publications: {
selection: t.publication({ any: t.boolean, many: t.boolean, count: t.number }),
editor: t.publication({ dirty: t.boolean, busy: t.boolean }),
},
create: createDeviceWorkspace,
});
Download composition-details.js
import { Form } from "@getaster/elements";
// This ES module is fetched only when the details child is first activated.
export function createDetails({ props }) {
const element = document.createElement("section");
element.className = "composition-editor";
element.setAttribute("aria-label", "Device editor");
const title = document.createElement("h2"); title.textContent = "Edit the shared record";
const help = document.createElement("p"); help.textContent = "This panel was loaded on demand. Switching presentation keeps this draft.";
const form = new Form();
form.sections = [{ title: "Device details", columns: 2, items: ["name", "owner"] }];
form.model = props.editor;
element.append(title, help, form);
return { element };
}
export function applyDetails(element, props) {
element.querySelector("aster-form").model = props.editor;
}
export function createCompactDetails(context) {
const session = createDetails(context);
session.element.querySelector("h2").textContent = "Device inspector";
session.element.querySelector("aster-form").sections = [{ title: "Device details", columns: 1, items: ["name", "owner"] }];
return session;
}
Download composition-status.js
import { defineElement, elementProperty, compositeTypes as t } from "@getaster/elements";
import { html } from "lit-html";
// This declaration supplies JS accessors, YAML validation and property metadata.
export const DraftStatus = defineElement({
tag: "demo-draft-status",
properties: {
label: elementProperty(t.string, () => "Draft", "Accessible status label"),
dirty: elementProperty(t.boolean, () => false, "Whether the current draft has unsaved changes"),
busy: elementProperty(t.boolean, () => false, "Whether a save is in progress"),
},
render: ({ label, dirty, busy }) => html`<p class="composition-draft-status" role="status" aria-label=${label}>
<span aria-hidden="true">${busy ? "◷" : dirty ? "●" : "✓"}</span>
${busy ? "Saving changes…" : dirty ? "Unsaved changes" : "All changes saved"}
</p>`,
});
Download showcase-catalogue.ts
export const examples = [
{ id: "formatting", navigationLabel: "Named displays", title: "Display fields and related records", category: "Fields & layouts", file: "formatting.html", action: "Explore named displays", ref: "staticMethod:bindFieldPresentations", description: "Reuse named renderers for compact people and abbreviated commits in a grid and read-only form.", task: "Copy a complete commit from its abbreviated display." },
{ id: "data-navigator", navigationLabel: "Nested views", title: "Explore projects and their related records", category: "Nested data views", file: "data-navigator.html", action: "Explore nested views", ref: "class:NestedGrid", description: "Browse related collections in a nested grid or a custom form, with independent pages and shared selection.", task: "Expand tasks and their assignees, then switch to the form view." },
{ id: "query-calculations", navigationLabel: "Calculated columns", title: "Explore calculated line totals and elapsed hours", category: "Nested data views", file: "query-calculations.html", action: "Explore calculations", ref: "class:NestedGrid", description: "Filter and sort calculated values, with exact totals across every matching page.", task: "Open order lines, change their calculation, then switch to the form view." },
{ id: "foundations", navigationLabel: "Fields & layouts", title: "Fields and layouts for everyday work", category: "Fields & layouts", file: "foundations.html", action: "Explore fields and layouts", ref: "class:CompositeField",
description: "Group related editors, keep numeric values exact, resize nested panes and navigate retained settings and context.",
task: "Edit a budget, revert its group, then resize the workspace and open its settings." },
{ id: "mail", navigationLabel: "Mail workspace", title: "Mail that keeps your draft", category: "Authentication recovery", file: "mail.html", action: "Open the mail workspace", ref: "class:Authentication",
description: "Read messages, keep several drafts open and recover an expired session through a configurable sign-in flow. The entire example uses local mock data.",
task: "Start a draft, expire the session, then send it and complete simulated sign-in." },
{ id: "tiles", navigationLabel: "Tile grids", title: "Folders & device fleets", category: "Tile grids", file: "tiles.html", action: "Explore tile grids", ref: "class:TileGrid",
description: "Browse folders or a virtual fleet of 100,000 devices. Switch between tiles and a table while keeping your selection.",
task: "Try ordered selection, change the tile size, then switch views." },
{ id: "filters", navigationLabel: "Filtering", title: "Queries you can compose", category: "Advanced filtering", file: "filtering.html", action: "Build an expression", ref: "class:FilterBuilder",
description: "Combine nested All, Any and Not groups with typed fields, platform choices, related records and relative dates.",
task: "Open Advanced filter, choose Platform, then try “is one of”." },
{ id: "reports", navigationLabel: "Reporting", title: "From rows to answers", category: "Reporting & grouping", file: "reporting.html", action: "Explore grouped reports", ref: "class:Grid",
description: "Get exact totals across every matching record, expand multiple grouping levels and export the filtered result or ordered picks.",
task: "Group by Platform → Online → Site, then download a CSV." },
{ id: "charts", navigationLabel: "Charts", title: "Charts that work with your data", category: "Component integration", file: "components.html", action: "Connect charts and grids", ref: "class:ComponentHost",
description: "Optional ECharts components share filters and selection with a grid. HTML data views provide the same keyboard and touch actions.",
task: "Choose a platform in the chart, then select a device in either view." },
{ id: "windows", navigationLabel: "Windows", title: "A workspace that keeps your place", category: "Application windows", file: "windows.html", action: "Explore application windows", ref: "class:Window",
description: "Move between device details and editable notes. Minimize, maximize and restore without recreating content, with guarded close and saved layouts.",
task: "Write a note, minimize it, then restore it from the task list." },
{ id: "dashboard", navigationLabel: "Dashboard", title: "Build your own fleet workspace", category: "Dashboard composition", file: "dashboard.html", action: "Compose a dashboard", ref: "class:Dashboard",
description: "Arrange summaries, charts, device grids and notes. Widgets share live filters and selection, with saved layouts and protected edits.",
task: "Filter by platform, add a device, then move or maximize a widget." },
{ id: "dataview", navigationLabel: "DataView", title: "A directory made of custom cards", category: "DataView", file: "dataview.html", action: "Explore DataView", ref: "group:data-view",
description: "Browse a team directory with images, custom templates, live search and server-side sorting. Selection and updates follow the shared data layer.",
task: "Sort Z to A, try compact cards, then open and rename a colleague." },
{ id: "tabs", navigationLabel: "Tabs", title: "A place for every open device", category: "Tabs", file: "tabs.html", action: "Explore tabs", ref: "class:Tabs",
description: "Open data-driven tabs with lazy panels, retained drafts and optional close actions. A scrolling strip works on touch screens and narrow windows.",
task: "Write a note, switch tabs, then try closing your unsaved device." },
{ id: "finance", navigationLabel: "Finance workspace", title: "A ledger that follows every posting", category: "Finance workspace", file: "finance.html", action: "Open the finance workspace", ref: "class:Grid",
description: "Invoices, a chart of accounts and a journal over one dataset. Posting an invoice books its entry and the service recomputes every balance up the tree.",
task: "Post an invoice, then open the chart of accounts and the journal." },
{ id: "toasts", navigationLabel: "Toasts", title: "Messages that say what is happening", category: "Toasts", file: "toasts.html", action: "Explore toasts", ref: "class:Toaster",
description: "Success, warning and error toasts, a loading toast that updates in place with progress, and a small stack that waits while a dialog is open. Errors stay until dismissed.",
task: "Export the rows, then show five messages, open the dialog and press Escape." },
] as const;
export type ExampleId = typeof examples[number]["id"];
/** The standalone editor is also available from each component example. */
export const standaloneExamples: readonly (readonly [string, string])[] = [
...examples.slice(0, 2).map(example => [example.file, example.navigationLabel] as const),
["composition.html", "Composition"],
...examples.slice(2).map(example => [example.file, example.navigationLabel] as const),
];
// Shared navigation for the independent examples; no vendor code is loaded here.
import "@getaster/elements";
import { standaloneExamples } from "../../app/catalogue.ts";
for (const [id, label, values] of [["theme", "Theme", ["lamplight", "harbour"]], ["scheme", "Scheme", ["light", "dark"]]]) {
const choice = document.querySelector(`#${id}`);
choice.label = label;
choice.options = values.map(value => ({ value, label: value[0].toUpperCase() + value.slice(1) }));
choice.value = values[0];
}
const params = new URLSearchParams(location.search);
const themes = ["lamplight", "harbour"];
const schemes = ["light", "dark"];
const theme = params.get("theme");
const scheme = params.get("scheme");
if (themes.includes(theme)) {
document.querySelector("#theme").value = theme;
document.querySelector("#identity").href = `../lib/themes/${theme}.css`;
document.documentElement.dataset.identity = theme;
}
if (schemes.includes(scheme)) {
document.querySelector("#scheme").value = scheme;
document.documentElement.dataset.scheme = scheme;
document.documentElement.style.colorScheme = scheme;
}
const nav = document.createElement("nav");
nav.className = "showcase-nav";
nav.setAttribute("aria-label", "Component examples");
const back = document.createElement("a");
back.textContent = "← Component showcase";
const defaultApp = new URL(document.querySelector('meta[name="aster-site-layout"]') ? "../showcase/" : "../", document.baseURI);
let requestedApp = defaultApp;
try { requestedApp = new URL(params.get("app") ?? defaultApp.href, location.href); } catch { /* Malformed return URLs use the showcase root. */ }
const app = requestedApp.origin === location.origin ? requestedApp : defaultApp;
app.hash = "showcase";
back.href = app.href;
nav.append(back);
const links = document.createElement("div");
links.className = "showcase-nav-links";
nav.append(links);
for (const [file, label] of standaloneExamples) {
const link = document.createElement("a");
link.textContent = label;
link.href = file;
if (location.pathname.endsWith(`/${file}`)) link.setAttribute("aria-current", "page");
links.append(link);
}
function updateLinks() {
for (const link of nav.querySelectorAll("a")) {
const url = new URL(link.href);
if (link !== back) {
url.searchParams.set("theme", document.querySelector("#theme").value);
url.searchParams.set("scheme", document.querySelector("#scheme").value);
url.searchParams.set("showcase", "1");
url.searchParams.set("app", app.pathname);
} else {
url.searchParams.set("identity", document.querySelector("#theme").value);
url.searchParams.set("scheme", document.querySelector("#scheme").value);
}
link.href = url.href;
}
}
function applyAppearance() {
const theme = document.querySelector("#theme").value;
const scheme = document.querySelector("#scheme").value;
const stylesheet = document.querySelector("#identity");
const href = new URL(`../lib/themes/${theme}.css`, document.baseURI).href;
if (stylesheet.href !== href) stylesheet.href = href;
document.documentElement.dataset.identity = theme;
document.documentElement.dataset.scheme = scheme;
document.documentElement.style.colorScheme = scheme;
updateLinks();
}
for (const id of ["theme", "scheme"]) document.querySelector(`#${id}`).addEventListener("change", applyAppearance);
applyAppearance();
const embedded = params.get("embedded") === "1" && parent !== window;
if (!embedded) {
document.querySelector("main").prepend(nav);
requestAnimationFrame(() => {
const current = links.querySelector("[aria-current]");
if (!current || links.scrollWidth <= links.clientWidth) return;
const item = current.getBoundingClientRect();
const viewport = links.getBoundingClientRect();
links.scrollBy({ left: Math.min(0, item.left - viewport.left) + Math.max(0, item.right - viewport.right), behavior: "instant" });
});
const demo = location.pathname.split("/").pop().replace(".html", "");
for (const link of document.querySelectorAll("main a[href]")) {
if (link.hasAttribute("download")) continue;
const target = new URL(link.href);
if (target.origin !== location.origin) continue;
if (["composition", "mail"].includes(demo) && /\.(?:js|yaml|css)$/.test(target.pathname)) {
const viewer = new URL(`../examples/${demo}.html`, location.href);
viewer.searchParams.set("source", target.pathname.split("/").pop());
viewer.searchParams.set("theme", document.querySelector("#theme").value);
viewer.searchParams.set("scheme", document.querySelector("#scheme").value);
viewer.hash = "application-source";
link.href = viewer.href;
} else if (!/\/(?:guide|reference)\//.test(target.pathname)) continue;
link.target = "_blank";
link.rel = "noopener";
link.setAttribute("aria-label", `${link.textContent.trim()} (opens in a new tab)`);
}
}
else {
const demo = location.pathname.split("/").pop().replace(".html", "");
document.documentElement.dataset.embedded = "";
document.documentElement.dataset.demo = demo;
document.querySelector("main").setAttribute("aria-label", document.title);
const state = () => parent.postMessage({ type: "aster-demo-state", state: { theme: document.querySelector("#theme").value, scheme: document.querySelector("#scheme").value } }, location.origin);
const height = () => parent.postMessage({ type: "aster-demo-height", height: Math.ceil(document.body.getBoundingClientRect().height) }, location.origin);
new ResizeObserver(height).observe(document.body);
for (const id of ["theme", "scheme"]) document.querySelector(`#${id}`).addEventListener("change", state);
addEventListener("message", event => {
if (event.origin !== location.origin || event.source !== parent) return;
if (event.data?.type === "aster-example-appearance" && schemes.includes(event.data.scheme)) {
document.querySelector("#scheme").value = event.data.scheme;
if (themes.includes(event.data.theme)) document.querySelector("#theme").value = event.data.theme;
applyAppearance(); state();
}
if (event.data?.type === "aster-demo-request") { state(); height(); }
});
state(); height();
}
main a { color:var(--aster-accent); text-underline-offset:4px; }
.showcase-nav { display: grid; gap: 4px; padding-bottom: 12px; margin-bottom: 20px; border-bottom: 1px solid var(--aster-rule); min-width:0; }
.showcase-nav-links { display:flex; flex-wrap:wrap; gap:4px 16px; min-width:0; }
.showcase-nav a { display: inline-flex; align-items: center; min-height: 44px; color: var(--aster-accent); text-underline-offset: 4px; }
.showcase-nav > a:first-child { margin-right: auto; }
.showcase-nav [aria-current] { font-weight: var(--aster-weight-strong); text-decoration-thickness: 2px; }
.showcase-appearance { display: inline-flex; align-items: center; gap: 8px; }
.showcase-appearance > span { color: var(--aster-text-2); font-weight: var(--aster-weight-label); }
.showcase-appearance aster-choice { width: 9rem; }
.showcase-appearance #scheme { width: 7rem; }
.showcase-grouping aster-choice { width: min(17rem, 65vw); }
/* Match the canvas to the page, including browser rubber-band overscroll. */
html, body { background:var(--showcase-canvas, var(--aster-surface)); }
body { transition:color 300ms ease; }
html:has(.mail-intro) { --showcase-canvas:var(--aster-sunk); }
@media (max-width: 720px), (pointer: coarse) and (max-width: 1024px) {
.showcase-nav-links { flex-wrap:nowrap; overflow-x:auto; scrollbar-width:none; }
.showcase-nav-links::-webkit-scrollbar { display:none; }
.showcase-nav-links a { flex:none; white-space:nowrap; }
.showcase-nav [aria-current] { scroll-margin-inline:16px; }
}
html[data-embedded] body { height:auto; min-height:0!important; padding:20px; }
html[data-embedded] .showcase-appearance:has(#scheme) { display:none; }
html[data-embedded] main > p:last-child:has(a[href="./"]) { display:none; }
html[data-embedded][data-demo="windows"] body { min-height:820px!important; }
@media(max-width:600px) { html[data-embedded] body { padding:12px; } }
.bar select { min-height:var(--aster-ctl); max-width:100%; padding:6px 10px; border:1px solid var(--aster-rule); border-radius:var(--aster-r-ctl); background:var(--aster-sunk); color:var(--aster-text); }
@media(pointer:coarse) { .bar select { min-height:44px; } }
Try the workflow
- Select a device in the table, then choose Edit selected.
- Change its name and switch to Tiles: selection and the draft stay shared.
- Save device and check the new name in both presentations.
- Try a workspace variant or Recreate workspace with an unsaved draft to exercise its guard.
What the example owns
The model owns its collection, selection, editor, commands and cleanup. The YAML definition connects named children, bindings, layout and PageRules. The host registry supplies the JavaScript factories, renderers and lazy module loader.