core
Drawer
Addressable modal panel — declared once, opened from any xref on the page
Source
import Markdoc from '@markdoc/markdoc';
import type { Node, RenderableTreeNode } from '@markdoc/markdoc';
const { Tag } = Markdoc;
import {
createContentModelSchema,
bodyOnly,
createComponentRenderable,
asNodes,
} from '../lib/index.js';
import { RenderableNodeCursor } from '../lib/renderable.js';
export const DRAWER_TITLE_AUTO_MARKER = 'data-drawer-title-auto';
const drawerSides = ['right', 'left', 'top', 'bottom'] as const;
const drawerSizes = ['sm', 'md', 'lg', 'full'] as const;
function splitDrawerBodyZones(nodes: Node[]): { body: Node[]; footer: Node[] | null } {
const hrIndex = nodes.findIndex((n) => n.type === 'hr');
if (hrIndex < 0) return { body: nodes, footer: null };
return {
body: nodes.slice(0, hrIndex),
footer: nodes.slice(hrIndex + 1),
};
}
export const drawerSections = { header: 'header', body: 'body', footer: 'footer' } as const;
export const drawer = createContentModelSchema({
sections: drawerSections,
provides: ['prose'],
attributes: {
id: {
type: String,
required: true,
description:
'Stable id for the drawer. Used in entity registration and as the `id="drawer-{value}"` on the rendered element so xref triggers can target it via fragment.',
},
title: {
type: String,
required: false,
description:
'Panel heading text. Rendered in the drawer header (or as a heading in the no-JS in-flow rendering).',
},
headingLevel: {
type: Number,
required: false,
description:
'Heading level (1-6) for the title. When omitted, the level is auto-detected from outline position (one deeper than the nearest preceding heading). Out-of-range values are clamped to the 1-6 range.',
},
shortcut: {
type: String,
required: false,
description:
'Keyboard shortcut that opens the drawer when behaviors are loaded (e.g. ".", "cmd+k"). Surfaces as `data-shortcut`; the progressive-enhancement layer wires the listener.',
},
side: {
type: String,
required: false,
matches: drawerSides.slice(),
description: 'Edge the panel slides from when enhanced. Defaults to "right".',
},
size: {
type: String,
required: false,
matches: drawerSizes.slice(),
description:
'Panel size: "sm", "md" (default), "lg" (wide enough for code), or "full" (the whole screen inside the gutter). Width for left/right sides, height for top/bottom.',
},
},
contentModel: bodyOnly(),
transform(resolved, attrs, config) {
const drawerId = attrs.id;
const titleText = attrs.title;
const side = attrs.side ?? 'right';
const size = attrs.size ?? 'md';
// Without a level, `h3` is a placeholder the postProcess walk sets from the outline.
const clampedLevel =
typeof attrs.headingLevel === 'number'
? Math.min(6, Math.max(1, Math.trunc(attrs.headingLevel)))
: undefined;
const titleTag = titleText
? clampedLevel
? new Tag(`h${clampedLevel}`, {}, [titleText])
: new Tag('h3', { [DRAWER_TITLE_AUTO_MARKER]: 'true' }, [titleText])
: undefined;
const closeButton = new Tag(
'button',
{
type: 'button',
'aria-label': 'Close',
hidden: true,
},
['×'],
);
const headerChildren: RenderableTreeNode[] = [];
if (titleTag) headerChildren.push(titleTag);
headerChildren.push(closeButton);
const header = new Tag('header', {}, headerChildren);
const zones = splitDrawerBodyZones(asNodes(resolved.body));
const body = new RenderableNodeCursor(
Markdoc.transform(zones.body, config) as RenderableTreeNode[],
).wrap('div');
const footer =
zones.footer !== null
? new RenderableNodeCursor(
Markdoc.transform(zones.footer, config) as RenderableTreeNode[],
).wrap('footer')
: null;
const properties: Record<string, Markdoc.Tag> = {
side: new Tag('meta', { content: side }),
size: new Tag('meta', { content: size }),
};
if (attrs.shortcut) {
properties.shortcut = new Tag('meta', { content: attrs.shortcut });
}
const renderable = createComponentRenderable({
rune: 'drawer',
tag: 'section',
id: `drawer-${drawerId}`,
properties,
refs: {
header,
title: titleTag,
close: closeButton,
body: body.tag('div'),
...(footer ? { footer: footer.tag('footer') } : {}),
},
children: [header, body.next(), ...(footer ? [footer.next()] : [])],
});
(renderable.attributes as Record<string, unknown>)['data-drawer-id'] = drawerId;
return renderable;
},
});
A panel for detail that is too much for a tooltip and too little for a page of its own. You write it once, give it an id, and any reference or link to that id on the page opens it as a side panel. To link to an entity without showing its content, use xref; to place an entity's content in the flow of the page, use expand; to link to a project file, use file-ref.
Basic usage
A drawer has no trigger of its own: you write its content and give it an id, and links to that id open it. Until a link opens it, it renders in place, as it does here:
{% drawer id="auth-system" title="Auth system" %}
Sign-in issues a short-lived access token and a long-lived refresh token, both in HttpOnly cookies.
- Access tokens expire after 15 minutes.
- Refresh tokens last 30 days and rotate on every use.
- Signing out revokes the refresh token on the server.
{% /drawer %}<section id="drawer-auth-system" data-rune="drawer" data-rune-fields="{"side":"right","size":"md"}" data-drawer-id="auth-system">
<header data-name="header">
<h3 data-drawer-title-auto="true" data-name="title">Auth system</h3>
<button type="button" aria-label="Close" hidden data-name="close">×</button>
</header>
<div data-name="body">
<p>Sign-in issues a short-lived access token and a long-lived refresh token, both in HttpOnly cookies.</p>
<ul>
<li>Access tokens expire after 15 minutes.</li>
<li>Refresh tokens last 30 days and rotate on every use.</li>
<li>Signing out revokes the refresh token on the server.</li>
</ul>
</div>
</section>Auth system
Sign-in issues a short-lived access token and a long-lived refresh token, both in HttpOnly cookies.
- Access tokens expire after 15 minutes.
- Refresh tokens last 30 days and rotate on every use.
- Signing out revokes the refresh token on the server.
<section id="drawer-auth-system" class="rf-drawer rf-drawer--right rf-drawer--md" data-drawer-id="auth-system" data-side="right" data-size="md" data-rune="drawer" data-density="compact">
<header data-name="header" class="rf-drawer__header" data-section="header">
<h3 data-name="title" class="rf-drawer__title">Auth system</h3>
<button type="button" aria-label="Close" hidden data-name="close" class="rf-drawer__close">×</button>
</header>
<div data-name="body" class="rf-drawer__body" data-section="body">
<p>Sign-in issues a short-lived access token and a long-lived refresh token, both in HttpOnly cookies.</p>
<ul>
<li>Access tokens expire after 15 minutes.</li>
<li>Refresh tokens last 30 days and rotate on every use.</li>
<li>Signing out revokes the refresh token on the server.</li>
</ul>
</div>
</section>The id needs to be unique only on its own page. side sets the edge the panel slides in from, and size how large it is: sm, md (the default), lg, which is wide enough for code, or full, the whole screen. The title's heading sits one level below the heading before the drawer; set headingLevel to choose it yourself.
How Markdown is read
The title comes from the title attribute, not from a heading.
| You write | It becomes |
|---|---|
Content with no --- | The drawer's body |
A top-level --- | Splits the content into the body (before) and a footer (after) that stays in view (Body and footer zones) |
Open it from a reference
A {% ref %} to the drawer's id opens it. Any number of references can open the same drawer.
Sessions follow the rules of {% ref "auth-system" label="the auth system" /%}, so a stolen access token is useful for 15 minutes at most.<p>
Sessions follow the rules of
<span data-rune="xref" data-xref-id="auth-system" data-xref-label="the auth system">the auth system</span>
, so a stolen access token is useful for 15 minutes at most.
</p>Sessions follow the rules of the auth system, so a stolen access token is useful for 15 minutes at most.
<p>
Sessions follow the rules of
<a class="rf-xref rf-xref--drawer" href="#drawer-auth-system" data-xref-id="auth-system" data-xref-source="registry" data-target-type="drawer">the auth system</a>
, so a stolen access token is useful for 15 minutes at most.
</p>The panel closes with Esc, a click outside it, or its close button. The page's URL carries the drawer's anchor, #drawer-{id}, while it is open, so a link to that URL opens the drawer, and the browser's back button closes it. Without JavaScript, the drawer stays in place and a reference scrolls to it.
Triggering from a link
A link whose target is a drawer on the same page opens it too: a Markdown link, a {% link %}, or an item in actions. Because a link's text takes inline tags, a trigger can carry an icon.
{% actions %}
- [{% icon name="shield" /%} Auth system](#auth-system)
- [{% icon name="code" /%} View source](#page-source)
{% /actions %}<div data-rune="actions">
<ul data-name="list">
<li data-rank="primary" data-name="action">
<a href="#auth-system">
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="rf-icon" data-icon="shield">
<path d="M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z"></path>
</svg>
<span> Auth system</span>
</a>
</li>
<li data-rank="secondary" data-name="action">
<a href="#page-source">
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="rf-icon" data-icon="code">
<path d="m16 18 6-6-6-6"></path>
<path d="m8 6-6 6 6 6"></path>
</svg>
<span> View source</span>
</a>
</li>
</ul>
</div><div class="rf-actions" data-rune="actions" data-density="full">
<ul data-name="list" class="rf-actions__list">
<li data-rank="primary" data-name="action" class="rf-actions__action">
<a href="#drawer-auth-system" data-target-type="drawer">
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="rf-icon" data-icon="shield">
<path d="M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z"></path>
</svg>
<span> Auth system</span>
</a>
</li>
<li data-rank="secondary" data-name="action" class="rf-actions__action">
<a href="#drawer-page-source" data-target-type="drawer">
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="rf-icon" data-icon="code">
<path d="m16 18 6-6-6-6"></path>
<path d="m8 6-6 6 6 6"></path>
</svg>
<span> View source</span>
</a>
</li>
</ul>
</div>The target is the drawer's id, or its anchor #drawer-{id}. When a drawer and a heading share an id, the link opens the drawer; a link to an id no drawer has is an ordinary same-page link.
Open it with a key
shortcut opens the drawer from the keyboard, unless the reader is typing in a field:
| Form | Example |
|---|---|
| Bare key | shortcut="." |
| Primary modifier (Cmd on macOS, Ctrl elsewhere) | shortcut="cmd+k" |
| Several modifiers | shortcut="ctrl+shift+/" |
cmd+ and ctrl+ both mean the platform's primary modifier. Give each drawer on a page its own shortcut; when two share one, the last wins and the dev server warns.
Body and footer zones
A top-level --- splits the drawer into a body and a footer, as in a {% card %}. The header and footer stay in view while the body scrolls, so a long embed keeps its onward links one tap away:
Counting entities per group is the job of the {% ref "aggregate-spec" label="aggregate rune" /%}.
{% drawer id="aggregate-spec" title="Aggregate rune" %}
{% expand "SPEC-076" /%}
---
The {% ref "Aggregate" /%} page shows it at work.
{% /drawer %}<p>
Counting entities per group is the job of the
<span data-rune="xref" data-xref-id="aggregate-spec" data-xref-label="aggregate rune">aggregate rune</span>
.
</p>
<section id="drawer-aggregate-spec" data-rune="drawer" data-rune-fields="{"side":"right","size":"md"}" data-drawer-id="aggregate-spec">
<header data-name="header">
<h3 data-drawer-title-auto="true" data-name="title">Aggregate rune</h3>
<button type="button" aria-label="Close" hidden data-name="close">×</button>
</header>
<div data-name="body">
<div data-rune="expand-pending" data-expand-id="SPEC-076"></div>
</div>
<footer data-name="footer">
<p>
The
<span data-rune="xref" data-xref-id="Aggregate">Aggregate</span>
page shows it at work.
</p>
</footer>
</section>Counting entities per group is the job of the aggregate rune.
Aggregate rune
<p>
Counting entities per group is the job of the
<a class="rf-xref rf-xref--drawer" href="#drawer-aggregate-spec" data-xref-id="aggregate-spec" data-xref-source="registry" data-target-type="drawer">aggregate rune</a>
.
</p>
<section id="drawer-aggregate-spec" class="rf-drawer rf-drawer--right rf-drawer--md" data-drawer-id="aggregate-spec" data-side="right" data-size="md" data-rune="drawer" data-density="compact">
<header data-name="header" class="rf-drawer__header" data-section="header">
<h3 data-name="title" class="rf-drawer__title">Aggregate rune</h3>
<button type="button" aria-label="Close" hidden data-name="close" class="rf-drawer__close">×</button>
</header>
<div data-name="body" class="rf-drawer__body" data-section="body">
<section data-entity-id="SPEC-076" data-entity-type="spec" data-source="registry" data-outline-scope="SPEC-076" class="rf-expand" data-rune="expand" data-density="full">
<article class="rf-spec rf-spec--SPEC-076 rf-spec--accepted" data-id="SPEC-076" data-status="accepted" data-version="" data-supersedes="" data-released-in="" data-tags="aggregate, collection, registry, postprocess, counts, runes" data-created="" data-modified="" data-rune="spec" data-density="full">
<div data-name="eyebrow" data-zone="eyebrow" data-zone-layout="bar" class="rf-spec__eyebrow">
<span data-meta-type="id" data-field="id">SPEC-076</span>
<span data-meta-type="status" data-meta-sentiment="positive" data-align="end" data-field="status">accepted</span>
</div>
<header data-name="title" class="rf-spec__title" data-section="title">
<h1 id="SPEC-076--aggregate-rune-counts-and-per-group-breakdowns-from-the-registry">Aggregate rune — counts and per-group breakdowns from the registry</h1>
</header>
<div data-name="blurb" class="rf-spec__blurb" data-section="description">
<p>
A third post-process-resolved query rune that sits beside
<code>collection</code>
(
<span class="rf-xref rf-xref--unresolved" data-xref-id="SPEC-070">SPEC-070</span>
) and
<code>relationships</code>
(
<span class="rf-xref rf-xref--unresolved" data-xref-id="SPEC-072">SPEC-072</span>
). Where
<code>collection</code>
projects entities and
<code>relationships</code>
projects edges,
<strong marker="**">
<code>aggregate</code>
projects numbers
</strong>
— counts (and, later, sums / averages) over the same field-match query, optionally broken down by group. Two modes from the same rune: a no-body
<strong marker="**">single-number</strong>
form (subsuming the small
<code>count</code>
rune we considered), and a body-zoned
<strong marker="**">per-group iteration</strong>
form whose template binds a group projection to
<code>$item</code>
. Replaces a one-off
<code>count</code>
rune, absorbs the per-group iteration we held under
<code>collection</code>
, and is what
<code>plan-progress</code>
decomposes onto.
</p>
</div>
<div data-name="tags" data-zone="tags" data-zone-layout="bar" class="rf-spec__tags">
<span data-meta-type="tag" data-field="tags">aggregate</span>
<span data-meta-type="tag" data-field="tags">collection</span>
<span data-meta-type="tag" data-field="tags">registry</span>
<span data-meta-type="tag" data-field="tags">postprocess</span>
<span data-meta-type="tag" data-field="tags">counts</span>
<span data-meta-type="tag" data-field="tags">runes</span>
</div>
<div data-name="body" class="rf-spec__body" data-section="body">
<h2 id="SPEC-076--problem">Problem</h2>
<p>Three threads converge on the same missing piece:</p>
<ol>
<li>
<strong marker="**">No primitive for "how many".</strong>
<code>collection</code>
knows how to count but only exposes it through the
<code>$count</code>
/
<code>$shown</code>
variables inside its preamble — i.e. coupled to rendering a list. Nothing renders just an integer. Authors who want "we have N items" or per-status counts have to lean on a full collection.
</li>
<li>
<strong marker="**">
Per-group iteration was held under
<code>collection</code>
.
</strong>
<span class="rf-xref rf-xref--unresolved" data-xref-id="SPEC-072">SPEC-072</span>
explored a
<code>{% items /%}</code>
slot for per-group templates inside
<code>collection</code>
and held it as SPEC-sized — the slot machinery is heavy when the group's body has to splice an
<em marker="*">item list</em>
into chrome. The same iteration idea is much lighter if each group renders a single template bound to a group projection, with no nested item splice — which is exactly what an aggregation rune needs.
</li>
<li>
<strong marker="**">
<code>plan-progress</code>
can't decompose cleanly today.
</strong>
A row of status badges + a progress bar is conceptually
<code>count × N + total</code>
, but you can't feed counts into
<code>progress.value</code>
/
<code>max</code>
from a Markdoc function — functions evaluate during per-page Schema Transform,
<em marker="*">before</em>
the cross-page registry is built (
<span class="rf-xref rf-xref--unresolved" data-xref-id="SPEC-075">SPEC-075</span>
frames the timing). Precomputed
<code>$item.data.*</code>
variables only work on dynamic entity routes, not file-backed pages.
</li>
</ol>
<p>
These all want the same thing: a post-process-resolved rune (like
<code>collection</code>
/
<code>relationships</code>
) whose output is numbers, with a body template that binds the aggregate result.
</p>
<h2 id="SPEC-076--goals">Goals</h2>
<ul>
<li>
A generic
<strong marker="**">
<code>{% aggregate %}</code>
rune
</strong>
that queries the registry by
<code>type</code>
+
<code>filter</code>
, optionally
<code>group</code>
s, and emits a single number (no body) or iterates groups (with body zones).
</li>
<li>
Composes cleanly with
<code>progress</code>
,
<code>badge</code>
, and
<code>humanize</code>
via
<code>$item</code>
bindings inside the body — no deferred-function feature required for the common case.
</li>
<li>
Works on
<strong marker="**">both file-backed and dynamic routes</strong>
, since the rune resolves in post-process with the full registry — same coverage as
<code>collection</code>
/
<code>relationships</code>
.
</li>
<li>
<strong marker="**">
Subsumes the proposed
<code>count</code>
rune
</strong>
outright.
</li>
<li>
Establishes the foundation for
<strong marker="**">
<code>plan-progress</code>
to become thin sugar
</strong>
, the way decision-log / plan-activity now wrap
<code>collection</code>
.
</li>
</ul>
<h2 id="SPEC-076--non-goals">Non-goals</h2>
<ul>
<li>
Replacing
<code>collection</code>
for per-entity rendering —
<code>aggregate</code>
renders
<em marker="*">numbers</em>
, not the items themselves; the two are complementary.
</li>
<li>
A deferred-function
<code>count(…)</code>
mechanism for arbitrary attribute slots anywhere on the page (
<span class="rf-xref rf-xref--unresolved" data-xref-id="SPEC-075">SPEC-075</span>
discussion) —
<code>aggregate</code>
's body template covers the plan-progress case via
<code>$item.*</code>
, so the deferred-function story can stay deferred.
</li>
<li>
Sums / averages of numeric fields in v1 — reserved by the rune's shape and listed under
<a href="#future-extensions">Future extensions</a>
; only
<code>count</code>
ships first.
</li>
</ul>
<h2 id="SPEC-076--capability-1-single-number-form">Capability 1 — single-number form</h2>
<p>The no-body form emits one integer: the count of entities matching the query.</p>
<div class="rf-codeblock">
<pre data-language="markdoc"><code data-language="markdoc">{% aggregate type="work" filter="status:done" /%}
</code></pre>
</div>
<p>
Renders as a small inline element carrying the count and query metadata (exact markup follows the post-process pattern — sentinel during transform, real
<code><span></code>
substituted in phase 4). This is the form that absorbs the
<code>count</code>
rune proposal: same attributes (
<code>type</code>
,
<code>filter</code>
), inline number output, post-process-resolved.
</p>
<h2 id="SPEC-076--capability-2-body-zoned-per-group-iteration">Capability 2 — body-zoned per-group iteration</h2>
<p>
With a body, the source splits on top-level
<code>hr</code>
into the same
<strong marker="**">preamble / template / fallback</strong>
zones as
<code>collection</code>
, but
<code>$item</code>
is bound
<em marker="*">differently per zone</em>
:
</p>
<div class="rf-codeblock">
<pre data-language="markdoc"><code data-language="markdoc">{% aggregate type="work" value="status:done" group="status" %}
{% progress value=$item.value max=$item.count %}Progress{% /progress %}
---
{% badge data-status=$item.key %}{% $item.count %} of {% $item.total %} {% humanize($item.key) %}{% /badge %}
---
Nothing to report.
{% /aggregate %}
</code></pre>
</div>
<div class="rf-table-wrapper">
<table>
<thead>
<tr>
<th>Zone</th>
<th>When rendered</th>
<th>
<code>$item</code>
shape
</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<strong marker="**">preamble</strong>
</td>
<td>
once, only when the query is non-empty,
<em marker="*">above</em>
the per-group output
</td>
<td>
<code>{ count, value, percent, total }</code>
—
<code>count</code>
and
<code>total</code>
are equal in this zone
</td>
</tr>
<tr>
<td>
<strong marker="**">template</strong>
</td>
<td>
once
<strong marker="**">per group</strong>
; this is the rune's main output
</td>
<td>
<code>{ key, count, value, percent, total, shown }</code>
—
<code>count</code>
is
<em marker="*">this</em>
group's count;
<code>total</code>
is the all-groups total
</td>
</tr>
<tr>
<td>
<strong marker="**">fallback</strong>
</td>
<td>
once, only when the query matches no entities,
<em marker="*">in place of</em>
the template
</td>
<td>all zeros</td>
</tr>
</tbody>
</table>
</div>
<p>The two count-shaped fields:</p>
<ul>
<li>
<strong marker="**">
<code>$item.count</code>
</strong>
is the count
<strong marker="**">in this zone's context</strong>
— the entire primary set in the preamble; the current group's count in the template. This is the progress-bar denominator.
</li>
<li>
<strong marker="**">
<code>$item.total</code>
</strong>
is the
<strong marker="**">all-groups total</strong>
, constant across every template iteration. Equal to
<code>count</code>
in the preamble (no in-context vs global distinction when you're not iterating); useful in the template for share-of-total ratios (e.g.
<code>"3 of 12"</code>
).
</li>
</ul>
<p>And the other fields:</p>
<ul>
<li>
<strong marker="**">
<code>$item.value</code>
</strong>
is the count matching both
<code>filter</code>
and the
<code>value</code>
sub-filter (see below). Falls back to
<code>$item.count</code>
when no
<code>value</code>
attribute is set, so it carries the count without progress-bar semantics.
</li>
<li>
<strong marker="**">
<code>$item.percent</code>
</strong>
is
<code>(value / count) × 100</code>
, rounded to an integer in
<code>0–100</code>
. With no
<code>value</code>
attribute, it's
<code>100</code>
.
</li>
<li>
<strong marker="**">
<code>$item.key</code>
</strong>
is the group value (template only);
<strong marker="**">
<code>$item.shown</code>
</strong>
is the post-limit count (template only, when
<code>limit</code>
applies).
</li>
</ul>
<p>
<code>group</code>
is optional. Without it, the body renders once with the in-context projection on
<code>$item</code>
— useful for a single composed element from a totals-only query (e.g. just a
<code>progress</code>
bar driven by
<code>$item.value</code>
/
<code>$item.count</code>
).
</p>
<p>
Other attributes mirror
<code>collection</code>
, with one rune-specific addition (
<code>value</code>
):
</p>
<div class="rf-table-wrapper">
<table>
<thead>
<tr>
<th>Attribute</th>
<th>Meaning</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<code>type</code>
</td>
<td>Entity type(s), comma-separated.</td>
</tr>
<tr>
<td>
<code>filter</code>
</td>
<td>
<code>field:value</code>
clauses (
<span class="rf-xref rf-xref--unresolved" data-xref-id="SPEC-070">SPEC-070</span>
grammar) — defines the
<strong marker="**">primary set</strong>
being measured (the
<code>max</code>
).
</td>
</tr>
<tr>
<td>
<code>value</code>
</td>
<td>
Optional secondary
<code>field:value</code>
clause defining the
<strong marker="**">achieved subset</strong>
within
<code>filter</code>
(e.g.
<code>value="status:done"</code>
). When set,
<code>$item.value</code>
is the count matching both;
<code>$item.percent</code>
is the ratio. Without it, the rune is a pure count + breakdown — no progress-bar semantics.
</td>
</tr>
<tr>
<td>
<code>group</code>
</td>
<td>Group-by field; omit to render once with totals.</td>
</tr>
<tr>
<td>
<code>sort</code>
</td>
<td>
Sort groups (group key, count, or any group-projection field); honors
<span class="rf-xref rf-xref--unresolved" data-xref-id="SPEC-072">SPEC-072</span>
domain-aware ordering when the group field has one.
</td>
</tr>
<tr>
<td>
<code>limit</code>
</td>
<td>Cap the number of groups (after sort).</td>
</tr>
<tr>
<td>
<code>empty</code>
</td>
<td>
Self-closing string fallback (same as
<code>collection</code>
); body fallback zone wins when both are present.
</td>
</tr>
</tbody>
</table>
</div>
<h2 id="SPEC-076--capability-3-chart-layout-deferred">Capability 3 — chart layout (deferred)</h2>
<p>
With
<code>layout="chart"</code>
, the rune renders an SVG instead of a per-group body —
composing with the
<code>chart</code>
rune's renderer the same way
<code>progress</code>
/
<code>badge</code>
compose inside the default body. The body reuses the
<strong marker="**">heading-as-columns</strong>
format already used by
<code>collection</code>
's
<code>layout="table"</code>
(
<span class="rf-xref rf-xref--unresolved" data-xref-id="SPEC-070">SPEC-070</span>
),
so authors don't learn new grammar:
</p>
<div class="rf-codeblock">
<pre data-language="markdoc"><code data-language="markdoc">{% aggregate type="work" value="status:done" group="status" layout="chart" chart-type="bar" %}
# Work breakdown
## Status
{% humanize($item.key) %}
## Total
{% $item.count %}
## Done
{% $item.value %}
{% /aggregate %}
</code></pre>
</div>
<ul>
<li>
<strong marker="**">Headings as columns</strong>
—
<code>## …</code>
declares a column label; the content under
it is the per-group cell template with
<code>$item</code>
bound to the group projection.
First column is the label series; subsequent columns are numeric series that
<code>chart</code>
consumes as bars / lines / slices. Same machinery
<code>collection</code>
's
table layout uses —
<code>splitColumns</code>
lifts to
<code>collection-helpers</code>
for shared
use.
</li>
<li>
<strong marker="**">Title</strong>
— an
<code># H1</code>
in the body becomes the chart title; the
<code>chart-title="…"</code>
attribute is the fallback for the no-body form. Same
precedence as the body fallback zone vs the
<code>empty</code>
attribute.
</li>
<li>
<strong marker="**">No body</strong>
— defaults to a
<code>{label, count}</code>
series (or
<code>{label, count, value}</code>
when
<code>value</code>
is set). The common case stays a
one-liner:
<code>{% aggregate type="work" group="status" layout="chart" chart-type="bar" /%}</code>
.
</li>
<li>
<strong marker="**">Chart attributes</strong>
—
<code>chart-type</code>
,
<code>chart-title</code>
, etc., pass through to
the chart renderer. Other layouts (
<code>list</code>
, the default body-zoned form)
ignore them.
</li>
</ul>
<p>
Composition with
<code>chart</code>
means lifting its SVG-building code out of
<code>postTransform</code>
into a helper both runes can call — small refactor, but it's
what keeps the rune coupling at the
<em marker="*">layout</em>
level (the same level
<code>collection</code>
's
<code>layout="table"</code>
sits at) rather than synthesising and
re-parsing markdoc tables behind the scenes.
</p>
<p>
Deferred — held until
<span class="rf-xref rf-xref--unresolved" data-xref-id="WORK-294">WORK-294</span>
and
<span class="rf-xref rf-xref--unresolved" data-xref-id="WORK-295">WORK-295</span>
land.
New work items will be filed once the base aggregate rune and its Lumina
styling are done.
</p>
<h2 id="SPEC-076--what-this-absorbs">What this absorbs</h2>
<ul>
<li>
<strong marker="**">The "count rune"</strong>
— Capability 1
<em marker="*">is</em>
the count rune. Withdraw the separate proposal.
</li>
<li>
<strong marker="**">
Per-group iteration held in
<span class="rf-xref rf-xref--unresolved" data-xref-id="SPEC-072">SPEC-072</span>
</strong>
— held under
<code>collection</code>
because per-group iteration there has to splice an
<em marker="*">item list</em>
inside the group's chrome (a two-level deferred transform plus a slot-substitution primitive). Aggregate sidesteps that entirely: each group renders one template bound to a group projection, no items-list slot. The loop machinery collapses to "reparse body source per group, bind
<code>$item</code>
, splice" — the exact mechanism
<code>collection</code>
's per-item template already uses, just at group granularity.
</li>
<li>
<strong marker="**">
Feeding counts to
<code>progress</code>
</strong>
without a deferred-function mechanism (
<span class="rf-xref rf-xref--unresolved" data-xref-id="SPEC-075">SPEC-075</span>
) — inside the aggregate body,
<code>$item.value</code>
/
<code>$item.count</code>
/
<code>$item.total</code>
are real numbers at post-process time, so
<code>progress</code>
's
<code>value</code>
/
<code>max</code>
attributes can read them as plain Markdoc variables. The deferred-function path is no longer required for plan-progress.
</li>
<li>
<strong marker="**">plan-progress's decomposition</strong>
— becomes thin sugar emitting the same aggregate composition (preamble = progress bar; template = badge per status; fallback = empty line), with plan-specific defaults baked in (type set, status enum, sentiment mapping). Same pattern as decision-log / plan-activity wrapping
<code>collection</code>
.
</li>
</ul>
<h2 id="SPEC-076--future-extensions">Future extensions</h2>
<p>Not in scope for v1, but reserved by the rune's shape:</p>
<ul>
<li>
<strong marker="**">Sums / averages / max / min</strong>
of a numeric field —
<code>sum="hours"</code>
,
<code>avg="priority-rank"</code>
. The group projection gains corresponding fields (
<code>$item.sum</code>
,
<code>$item.avg</code>
, …); preamble totals likewise.
</li>
<li>
<strong marker="**">
Per-group
<code>sentiment</code>
projected onto
<code>$item</code>
</strong>
— derived from the rune's domain ordering (
<span class="rf-xref rf-xref--unresolved" data-xref-id="SPEC-072">SPEC-072</span>
) when the group field has a sentiment-mapped enum, so badges pick up sentiment without authoring it per status.
</li>
</ul>
<h2 id="SPEC-076--implementation-note">Implementation note</h2>
<p>
<code>aggregate</code>
reuses the existing post-process plumbing: it emits a sentinel during transform, and a resolver in
<code>@refrakt-md/runes</code>
(parallel to
<code>resolveCollections</code>
/
<code>resolveRelationships</code>
) walks the rendered tree at phase 4, queries the registry, computes counts and groupings, and substitutes the rendered output. The body source is captured via
<code>deferBody</code>
(same as
<code>collection</code>
) and re-transformed per group (and once for the preamble totals) with
<code>$item</code>
bound — reusing
<code>transformDeferredTemplate</code>
from
<code>@refrakt-md/runes/deferred-body</code>
.
</p>
<h2 id="SPEC-076--acceptance-criteria">Acceptance Criteria</h2>
<ul>
<li data-checked="unchecked">
<code>{% aggregate type=… filter=… /%}</code>
(no body) emits a single integer — the count of entities matching the query — usable inline.
</li>
<li data-checked="unchecked">
With a body, the source splits on top-level
<code>hr</code>
into
<strong marker="**">preamble / template / fallback</strong>
zones; semantics match
<code>collection</code>
(preamble once when non-empty; template per group; fallback when empty).
</li>
<li data-checked="unchecked">
In the preamble,
<code>$item</code>
is bound to the in-context projection (
<code>count</code>
,
<code>value</code>
,
<code>percent</code>
,
<code>total</code>
);
<code>count</code>
and
<code>total</code>
are equal in this zone. Without a
<code>value</code>
attribute,
<code>$item.value</code>
falls back to
<code>$item.count</code>
and
<code>$item.percent</code>
is
<code>100</code>
.
</li>
<li data-checked="unchecked">
In the template,
<code>$item</code>
is bound to the group projection (
<code>key</code>
,
<code>count</code>
,
<code>value</code>
,
<code>percent</code>
,
<code>total</code>
,
<code>shown</code>
); the template is reparsed per group.
<code>$item.count</code>
is this group's count;
<code>$item.total</code>
is the all-groups total (lets a per-group template render share-of-total ratios without a second query).
</li>
<li data-checked="unchecked">
When a
<code>value</code>
attribute is set,
<code>$item.value</code>
is the count of entities matching both
<code>filter</code>
and
<code>value</code>
;
<code>$item.percent</code>
is
<code>(value / count) × 100</code>
, rounded to an integer in
<code>0–100</code>
.
</li>
<li data-checked="unchecked">
In the fallback, all numeric fields are
<code>0</code>
.
</li>
<li data-checked="unchecked">
<code>group</code>
is optional — omit to render the body once with the totals projection.
</li>
<li data-checked="unchecked">
<code>sort</code>
and
<code>limit</code>
apply over groups;
<code>sort</code>
honors
<span class="rf-xref rf-xref--unresolved" data-xref-id="SPEC-072">SPEC-072</span>
domain-aware ordering when the group field has one.
</li>
<li data-checked="unchecked">
Self-closing
<code>empty="…"</code>
attribute works as a string fallback (same as
<code>collection</code>
); the fallback zone wins when both are present.
</li>
<li data-checked="unchecked">Resolves in post-process with the full registry; works on file-backed and dynamic routes alike.</li>
<li data-checked="unchecked">
The proposed standalone
<code>count</code>
rune is withdrawn — Capability 1 replaces it.
</li>
</ul>
<h2 id="SPEC-076--references">References</h2>
<ul>
<li>
<span class="rf-xref rf-xref--unresolved" data-xref-id="SPEC-070">SPEC-070</span>
—
<code>collection</code>
, the family this joins; shares query grammar and zone semantics.
</li>
<li>
<span class="rf-xref rf-xref--unresolved" data-xref-id="SPEC-072">SPEC-072</span>
— domain-aware ordering used for
<code>sort</code>
; the per-group iteration held there is delivered here at a lower cost.
</li>
<li>
<span class="rf-xref rf-xref--unresolved" data-xref-id="SPEC-075">SPEC-075</span>
— comparable attribute types; this rune sidesteps the deferred-function ergonomic question via
<code>$item</code>
bindings inside the body.
</li>
</ul>
</div>
</article>
</section>
</div>
<footer data-name="footer" class="rf-drawer__footer" data-section="footer">
<p>
The
<a class="rf-xref rf-xref--page" href="/runes/aggregate" data-xref-id="/runes/aggregate" data-xref-source="registry" data-target-type="page">Aggregate</a>
page shows it at work.
</p>
</footer>
</section>Preview a reference without writing a drawer
xref and file-ref accept preview="drawer", which keeps the inline link and builds the drawer for you, with a footer link to the entity's page or the file's source:
See {% file-ref path="packages/types/src/config.ts" symbol="SiteConfig" label="SiteConfig" preview="drawer" /%} for the shape of a site's configuration.<p>
See
<span data-rune="file-ref">
<meta data-field="file-ref-path" content="packages/types/src/config.ts">
<meta data-field="file-ref-lines" content="">
<meta data-field="file-ref-label" content="SiteConfig">
<meta data-field="file-ref-preview" content="drawer">
<meta data-field="file-ref-symbol" content="SiteConfig">
<meta data-field="file-ref-match" content="">
<meta data-field="file-ref-occurrence" content="">
<meta data-field="file-ref-extent" content="">
<meta data-field="file-ref-until" content="">
<meta data-field="file-ref-through" content="">
<meta data-field="file-ref-doc" content="">
<meta data-field="file-ref-reindent" content="">
<meta data-field="__file-ref-sentinel" content="true">
<a data-name="link">SiteConfig</a>
</span>
for the shape of a site's configuration.
</p>See SiteConfig for the shape of a site's configuration.
<p>
See
<span class="rf-file-ref" data-rune="file-ref" data-density="full">
<a href="#drawer-packages-types-src-config.ts" aria-controls="drawer-packages-types-src-config.ts" aria-expanded="false" data-target-type="drawer">SiteConfig</a>
</span>
for the shape of a site's configuration.
</p>To change what such a drawer shows, write a {% drawer %} with the same id on the page; the reference opens yours instead.
Put any content in it
A drawer holds any block content: embeds, code blocks, other runes. A snippet makes a "view source" drawer; click view this page's source (or press .) to open the one below.
{% drawer id="page-source" title="View source" shortcut="." size="lg" %}
{% snippet path=$file.path lang="markdoc" /%}
{% /drawer %}<section id="drawer-page-source" data-rune="drawer" data-rune-fields="{"side":"right","size":"lg","shortcut":"."}" data-drawer-id="page-source">
<header data-name="header">
<h3 data-drawer-title-auto="true" data-name="title">View source</h3>
<button type="button" aria-label="Close" hidden data-name="close">×</button>
</header>
<div data-name="body">
<div class="rf-codeblock">
<pre data-language="markdoc" data-source="site/content/runes/drawer.md">
<code data-language="markdoc" data-source="site/content/runes/drawer.md">---
title: Drawer
description: Addressable modal panel — declared once, opened from any xref on the page
category: Arrangement
plugin: core
status: stable
type: rune
---
{% include file="rune-intro.md" variables={r: "rune:drawer"} /%}
A panel for detail that is too much for a tooltip and too little for a page of its own. You write it once, give it an `id`, and any reference or link to that id on the page opens it as a side panel. To link to an entity without showing its content, use [xref](/runes/xref); to place an entity's content in the flow of the page, use [expand](/runes/expand); to link to a project file, use [file-ref](/runes/file-ref).
## Basic usage
A drawer has no trigger of its own: you write its content and give it an `id`, and links to that id open it. Until a link opens it, it renders in place, as it does here:
{% preview source=true %}
{% drawer id="auth-system" title="Auth system" %}
Sign-in issues a short-lived access token and a long-lived refresh token, both in HttpOnly cookies.
- Access tokens expire after 15 minutes.
- Refresh tokens last 30 days and rotate on every use.
- Signing out revokes the refresh token on the server.
{% /drawer %}
{% /preview %}
The id needs to be unique only on its own page. `side` sets the edge the panel slides in from, and `size` how large it is: `sm`, `md` (the default), `lg`, which is wide enough for code, or `full`, the whole screen. The title's heading sits one level below the heading before the drawer; set `headingLevel` to choose it yourself.
## How Markdown is read
The title comes from the `title` attribute, not from a heading.
| You write | It becomes |
|-----------|------------|
| Content with no `---` | The drawer's body |
| A top-level `---` | Splits the content into the body (before) and a footer (after) that stays in view ([Body and footer zones](#body-and-footer-zones)) |
## Open it from a reference
A `{% ref %}` to the drawer's id opens it. Any number of references can open the same drawer.
{% preview source=true %}
Sessions follow the rules of {% ref "auth-system" label="the auth system" /%}, so a stolen access token is useful for 15 minutes at most.
{% /preview %}
The panel closes with Esc, a click outside it, or its close button. The page's URL carries the drawer's anchor, `#drawer-{id}`, while it is open, so a link to that URL opens the drawer, and the browser's back button closes it. Without JavaScript, the drawer stays in place and a reference scrolls to it.
## Triggering from a link
A link whose target is a drawer on the same page opens it too: a Markdown link, a `{% link %}`, or an item in [`actions`](/runes/actions). Because a link's text takes inline tags, a trigger can carry an [icon](/runes/icon).
{% preview source=true %}
{% actions %}
- [{% icon name="shield" /%} Auth system](#auth-system)
- [{% icon name="code" /%} View source](#page-source)
{% /actions %}
{% /preview %}
The target is the drawer's `id`, or its anchor `#drawer-{id}`. When a drawer and a heading share an id, the link opens the drawer; a link to an id no drawer has is an ordinary same-page link.
## Open it with a key
`shortcut` opens the drawer from the keyboard, unless the reader is typing in a field:
| Form | Example |
|------|---------|
| Bare key | `shortcut="."` |
| Primary modifier (Cmd on macOS, Ctrl elsewhere) | `shortcut="cmd+k"` |
| Several modifiers | `shortcut="ctrl+shift+/"` |
`cmd+` and `ctrl+` both mean the platform's primary modifier. Give each drawer on a page its own shortcut; when two share one, the last wins and the dev server warns.
## Body and footer zones
A top-level `---` splits the drawer into a body and a footer, as in a `{% card %}`. The header and footer stay in view while the body scrolls, so a long embed keeps its onward links one tap away:
{% preview source=true %}
Counting entities per group is the job of the {% ref "aggregate-spec" label="aggregate rune" /%}.
{% drawer id="aggregate-spec" title="Aggregate rune" %}
{% expand "SPEC-076" /%}
---
The {% ref "Aggregate" /%} page shows it at work.
{% /drawer %}
{% /preview %}
## Preview a reference without writing a drawer
[xref](/runes/xref) and [file-ref](/runes/file-ref) accept `preview="drawer"`, which keeps the inline link and builds the drawer for you, with a footer link to the entity's page or the file's source:
{% preview source=true %}
See {% file-ref path="packages/types/src/config.ts" symbol="SiteConfig" label="SiteConfig" preview="drawer" /%} for the shape of a site's configuration.
{% /preview %}
To change what such a drawer shows, write a `{% drawer %}` with the same id on the page; the reference opens yours instead.
## Put any content in it
A drawer holds any block content: embeds, code blocks, other runes. A [snippet](/runes/snippet) makes a "view source" drawer; click {% ref "page-source" label="view this page's source" /%} (or press `.`) to open the one below.
{% preview source=true %}
{% drawer id="page-source" title="View source" shortcut="." size="lg" %}
{% snippet path=$file.path lang="markdoc" /%}
{% /drawer %}
{% /preview %}
One drawer is open at a time.
## Attributes
{% include file="rune-attributes.md" variables={r: "rune:drawer"} /%}
## See also
- [xref](/runes/xref) — references that open a drawer, or build one with `preview="drawer"`.
- [file-ref](/runes/file-ref) — links a project file; `preview="drawer"` shows the file in a drawer.
- [snippet](/runes/snippet) — embeds a project file as a code block, for a "view source" drawer.
</code>
</pre>
</div>
</div>
</section>View source
---
title: Drawer
description: Addressable modal panel — declared once, opened from any xref on the page
category: Arrangement
plugin: core
status: stable
type: rune
---
{% include file="rune-intro.md" variables={r: "rune:drawer"} /%}
A panel for detail that is too much for a tooltip and too little for a page of its own. You write it once, give it an `id`, and any reference or link to that id on the page opens it as a side panel. To link to an entity without showing its content, use [xref](/runes/xref); to place an entity's content in the flow of the page, use [expand](/runes/expand); to link to a project file, use [file-ref](/runes/file-ref).
## Basic usage
A drawer has no trigger of its own: you write its content and give it an `id`, and links to that id open it. Until a link opens it, it renders in place, as it does here:
{% preview source=true %}
{% drawer id="auth-system" title="Auth system" %}
Sign-in issues a short-lived access token and a long-lived refresh token, both in HttpOnly cookies.
- Access tokens expire after 15 minutes.
- Refresh tokens last 30 days and rotate on every use.
- Signing out revokes the refresh token on the server.
{% /drawer %}
{% /preview %}
The id needs to be unique only on its own page. `side` sets the edge the panel slides in from, and `size` how large it is: `sm`, `md` (the default), `lg`, which is wide enough for code, or `full`, the whole screen. The title's heading sits one level below the heading before the drawer; set `headingLevel` to choose it yourself.
## How Markdown is read
The title comes from the `title` attribute, not from a heading.
| You write | It becomes |
|-----------|------------|
| Content with no `---` | The drawer's body |
| A top-level `---` | Splits the content into the body (before) and a footer (after) that stays in view ([Body and footer zones](#body-and-footer-zones)) |
## Open it from a reference
A `{% ref %}` to the drawer's id opens it. Any number of references can open the same drawer.
{% preview source=true %}
Sessions follow the rules of {% ref "auth-system" label="the auth system" /%}, so a stolen access token is useful for 15 minutes at most.
{% /preview %}
The panel closes with Esc, a click outside it, or its close button. The page's URL carries the drawer's anchor, `#drawer-{id}`, while it is open, so a link to that URL opens the drawer, and the browser's back button closes it. Without JavaScript, the drawer stays in place and a reference scrolls to it.
## Triggering from a link
A link whose target is a drawer on the same page opens it too: a Markdown link, a `{% link %}`, or an item in [`actions`](/runes/actions). Because a link's text takes inline tags, a trigger can carry an [icon](/runes/icon).
{% preview source=true %}
{% actions %}
- [{% icon name="shield" /%} Auth system](#auth-system)
- [{% icon name="code" /%} View source](#page-source)
{% /actions %}
{% /preview %}
The target is the drawer's `id`, or its anchor `#drawer-{id}`. When a drawer and a heading share an id, the link opens the drawer; a link to an id no drawer has is an ordinary same-page link.
## Open it with a key
`shortcut` opens the drawer from the keyboard, unless the reader is typing in a field:
| Form | Example |
|------|---------|
| Bare key | `shortcut="."` |
| Primary modifier (Cmd on macOS, Ctrl elsewhere) | `shortcut="cmd+k"` |
| Several modifiers | `shortcut="ctrl+shift+/"` |
`cmd+` and `ctrl+` both mean the platform's primary modifier. Give each drawer on a page its own shortcut; when two share one, the last wins and the dev server warns.
## Body and footer zones
A top-level `---` splits the drawer into a body and a footer, as in a `{% card %}`. The header and footer stay in view while the body scrolls, so a long embed keeps its onward links one tap away:
{% preview source=true %}
Counting entities per group is the job of the {% ref "aggregate-spec" label="aggregate rune" /%}.
{% drawer id="aggregate-spec" title="Aggregate rune" %}
{% expand "SPEC-076" /%}
---
The {% ref "Aggregate" /%} page shows it at work.
{% /drawer %}
{% /preview %}
## Preview a reference without writing a drawer
[xref](/runes/xref) and [file-ref](/runes/file-ref) accept `preview="drawer"`, which keeps the inline link and builds the drawer for you, with a footer link to the entity's page or the file's source:
{% preview source=true %}
See {% file-ref path="packages/types/src/config.ts" symbol="SiteConfig" label="SiteConfig" preview="drawer" /%} for the shape of a site's configuration.
{% /preview %}
To change what such a drawer shows, write a `{% drawer %}` with the same id on the page; the reference opens yours instead.
## Put any content in it
A drawer holds any block content: embeds, code blocks, other runes. A [snippet](/runes/snippet) makes a "view source" drawer; click {% ref "page-source" label="view this page's source" /%} (or press `.`) to open the one below.
{% preview source=true %}
{% drawer id="page-source" title="View source" shortcut="." size="lg" %}
{% snippet path=$file.path lang="markdoc" /%}
{% /drawer %}
{% /preview %}
One drawer is open at a time.
## Attributes
{% include file="rune-attributes.md" variables={r: "rune:drawer"} /%}
## See also
- [xref](/runes/xref) — references that open a drawer, or build one with `preview="drawer"`.
- [file-ref](/runes/file-ref) — links a project file; `preview="drawer"` shows the file in a drawer.
- [snippet](/runes/snippet) — embeds a project file as a code block, for a "view source" drawer.
<section id="drawer-page-source" class="rf-drawer rf-drawer--right rf-drawer--lg" data-drawer-id="page-source" data-side="right" data-size="lg" data-shortcut="." data-rune="drawer" data-density="compact">
<header data-name="header" class="rf-drawer__header" data-section="header">
<h3 data-name="title" class="rf-drawer__title">View source</h3>
<button type="button" aria-label="Close" hidden data-name="close" class="rf-drawer__close">×</button>
</header>
<div data-name="body" class="rf-drawer__body" data-section="body">
<div class="rf-codeblock">
<pre data-language="markdoc" data-source="site/content/runes/drawer.md"><code data-language="markdoc" data-source="site/content/runes/drawer.md">---
title: Drawer
description: Addressable modal panel — declared once, opened from any xref on the page
category: Arrangement
plugin: core
status: stable
type: rune
---
{% include file="rune-intro.md" variables={r: "rune:drawer"} /%}
A panel for detail that is too much for a tooltip and too little for a page of its own. You write it once, give it an `id`, and any reference or link to that id on the page opens it as a side panel. To link to an entity without showing its content, use [xref](/runes/xref); to place an entity's content in the flow of the page, use [expand](/runes/expand); to link to a project file, use [file-ref](/runes/file-ref).
## Basic usage
A drawer has no trigger of its own: you write its content and give it an `id`, and links to that id open it. Until a link opens it, it renders in place, as it does here:
{% preview source=true %}
{% drawer id="auth-system" title="Auth system" %}
Sign-in issues a short-lived access token and a long-lived refresh token, both in HttpOnly cookies.
- Access tokens expire after 15 minutes.
- Refresh tokens last 30 days and rotate on every use.
- Signing out revokes the refresh token on the server.
{% /drawer %}
{% /preview %}
The id needs to be unique only on its own page. `side` sets the edge the panel slides in from, and `size` how large it is: `sm`, `md` (the default), `lg`, which is wide enough for code, or `full`, the whole screen. The title's heading sits one level below the heading before the drawer; set `headingLevel` to choose it yourself.
## How Markdown is read
The title comes from the `title` attribute, not from a heading.
| You write | It becomes |
|-----------|------------|
| Content with no `---` | The drawer's body |
| A top-level `---` | Splits the content into the body (before) and a footer (after) that stays in view ([Body and footer zones](#body-and-footer-zones)) |
## Open it from a reference
A `{% ref %}` to the drawer's id opens it. Any number of references can open the same drawer.
{% preview source=true %}
Sessions follow the rules of {% ref "auth-system" label="the auth system" /%}, so a stolen access token is useful for 15 minutes at most.
{% /preview %}
The panel closes with Esc, a click outside it, or its close button. The page's URL carries the drawer's anchor, `#drawer-{id}`, while it is open, so a link to that URL opens the drawer, and the browser's back button closes it. Without JavaScript, the drawer stays in place and a reference scrolls to it.
## Triggering from a link
A link whose target is a drawer on the same page opens it too: a Markdown link, a `{% link %}`, or an item in [`actions`](/runes/actions). Because a link's text takes inline tags, a trigger can carry an [icon](/runes/icon).
{% preview source=true %}
{% actions %}
- [{% icon name="shield" /%} Auth system](#auth-system)
- [{% icon name="code" /%} View source](#page-source)
{% /actions %}
{% /preview %}
The target is the drawer's `id`, or its anchor `#drawer-{id}`. When a drawer and a heading share an id, the link opens the drawer; a link to an id no drawer has is an ordinary same-page link.
## Open it with a key
`shortcut` opens the drawer from the keyboard, unless the reader is typing in a field:
| Form | Example |
|------|---------|
| Bare key | `shortcut="."` |
| Primary modifier (Cmd on macOS, Ctrl elsewhere) | `shortcut="cmd+k"` |
| Several modifiers | `shortcut="ctrl+shift+/"` |
`cmd+` and `ctrl+` both mean the platform's primary modifier. Give each drawer on a page its own shortcut; when two share one, the last wins and the dev server warns.
## Body and footer zones
A top-level `---` splits the drawer into a body and a footer, as in a `{% card %}`. The header and footer stay in view while the body scrolls, so a long embed keeps its onward links one tap away:
{% preview source=true %}
Counting entities per group is the job of the {% ref "aggregate-spec" label="aggregate rune" /%}.
{% drawer id="aggregate-spec" title="Aggregate rune" %}
{% expand "SPEC-076" /%}
---
The {% ref "Aggregate" /%} page shows it at work.
{% /drawer %}
{% /preview %}
## Preview a reference without writing a drawer
[xref](/runes/xref) and [file-ref](/runes/file-ref) accept `preview="drawer"`, which keeps the inline link and builds the drawer for you, with a footer link to the entity's page or the file's source:
{% preview source=true %}
See {% file-ref path="packages/types/src/config.ts" symbol="SiteConfig" label="SiteConfig" preview="drawer" /%} for the shape of a site's configuration.
{% /preview %}
To change what such a drawer shows, write a `{% drawer %}` with the same id on the page; the reference opens yours instead.
## Put any content in it
A drawer holds any block content: embeds, code blocks, other runes. A [snippet](/runes/snippet) makes a "view source" drawer; click {% ref "page-source" label="view this page's source" /%} (or press `.`) to open the one below.
{% preview source=true %}
{% drawer id="page-source" title="View source" shortcut="." size="lg" %}
{% snippet path=$file.path lang="markdoc" /%}
{% /drawer %}
{% /preview %}
One drawer is open at a time.
## Attributes
{% include file="rune-attributes.md" variables={r: "rune:drawer"} /%}
## See also
- [xref](/runes/xref) — references that open a drawer, or build one with `preview="drawer"`.
- [file-ref](/runes/file-ref) — links a project file; `preview="drawer"` shows the file in a drawer.
- [snippet](/runes/snippet) — embeds a project file as a code block, for a "view source" drawer.
</code></pre>
</div>
</div>
</section>One drawer is open at a time.
Attributes
| Attribute | Type | Required | Description |
|---|---|---|---|
id | string | ✓ | Stable id for the drawer. Used in entity registration and as the `id="drawer-{value}"` on the rendered element so xref triggers can target it via fragment. |
title | string | — | Panel heading text. Rendered in the drawer header (or as a heading in the no-JS in-flow rendering). |
headingLevel | number | — | Heading level (1-6) for the title. When omitted, the level is auto-detected from outline position (one deeper than the nearest preceding heading). Out-of-range values are clamped to the 1-6 range. |
shortcut | string | — | Keyboard shortcut that opens the drawer when behaviors are loaded (e.g. ".", "cmd+k"). Surfaces as `data-shortcut`; the progressive-enhancement layer wires the listener. |
side | "right" | "left" | "top" | "bottom" | — | Edge the panel slides from when enhanced. Defaults to "right". |
size | "sm" | "md" | "lg" | "full" | — | Panel size: "sm", "md" (default), "lg" (wide enough for code), or "full" (the whole screen inside the gutter). Width for left/right sides, height for top/bottom. |
Universal attributes
bg
The background layer: image, video, gradient, flat overlay wash and legibility scrim, in a single injected layer behind the rune's content.
| Attribute | Type | Required | Description |
|---|---|---|---|
bg | string | — | Background preset applied to this block |
bg-from | string | — | Gradient start colour — a semantic token name (→ var(--rf-color-*)) |
bg-gradient | "to-t" | "to-b" | "to-l" | "to-r" | "to-tr" | "to-br" | "to-bl" | "to-tl" | — | Gradient direction (bounded named set) |
bg-gradient-type | "linear" | "radial" | "conic" | — | Gradient type |
bg-to | string | — | Gradient end colour — a semantic token name |
bg-via | string | — | Optional middle gradient stop — a semantic token name |
scrim | "top" | "bottom" | "left" | "right" | "none" | — | Scrim direction (heaviest edge); presence turns the scrim on, "none" opts out of the default cover scrim |
scrim-blur | "none" | "sm" | "md" | "lg" | — | Frost scrim blur amount |
scrim-strength | "sm" | "md" | "lg" | — | Gradient scrim strength |
scrim-tone | "dark" | "light" | — | Whether the scrim darkens (for light text) or lightens (for dark text) |
scrim-type | "gradient" | "frost" | — | Scrim treatment: gradient (default) or frost (backdrop blur) |
dropcap
Per-instance drop-cap opt-in.
| Attribute | Type | Required | Description |
|---|---|---|---|
dropcap | boolean | — | Style the opening letter of a prose body as a drop cap. Honoured only when the body reads as prose; ignored otherwise. |
elevation
How far the rune sits off the page, from sunken to overlay. The theme decides what each step looks like.
| Attribute | Type | Required | Description |
|---|---|---|---|
elevation | "sunken" | "flush" | "flat" | "raised" | "floating" | "overlay" | "none" | "sm" | "md" | "lg" | — | Surface depth, from sunken to overlay. Deprecated: none, sm, md and lg (read as flat, raised, raised and floating) |
inset
Internal padding override.
| Attribute | Type | Required | Description |
|---|---|---|---|
inset | "flush" | "tight" | "default" | "loose" | "breathe" | — | Inner padding of this block |
motion
Scroll-reveal entrance. You choose its character; the theme decides how it moves.
| Attribute | Type | Required | Description |
|---|---|---|---|
reveal | "none" | "fade" | "slide" | "scale" | "blur" | — | Scroll-reveal entrance character (none|fade|slide|scale|blur); the theme owns the choreography |
stagger | boolean | — | Cascade this block's items in as it reveals (no-op on single-child runes) |
prominence
Header emphasis. Scales a rune's header, or its featured quotation; the theme decides the type size for each step.
| Attribute | Type | Required | Description |
|---|---|---|---|
prominence | "quiet" | "normal" | "prominent" | "display" | "marquee" | — | Emphasis of a page-section header or a featured quotation (only on runes that have one) |
reading
Editorial register for body text. You pick the register; the theme decides how it looks.
| Attribute | Type | Required | Description |
|---|---|---|---|
reading | "fine" | "ui" | "prose" | — | Reading register for this block’s body: fine | ui | prose. The theme sets how each one looks. |
spacing
Block-level rhythm override.
| Attribute | Type | Required | Description |
|---|---|---|---|
spacing | "flush" | "tight" | "default" | "loose" | "breathe" | — | Vertical spacing above and below this block |
substrate
Generated pattern fills behind the content, drawn by the theme.
| Attribute | Type | Required | Description |
|---|---|---|---|
substrate | "dots" | "grid" | "lines" | "cross" | "checker" | "none" | — | Generated surface pattern |
substrate-fill | "inherit" | "inset" | — | Surface fill the pattern sits on (full colour stays with tint) |
substrate-opacity | "sm" | "md" | "lg" | — | Pattern ink strength |
substrate-size | "sm" | "md" | "lg" | — | Pattern cell size |
substrate-target | "self" | "media" | — | Which surface the pattern fills (overrides the rune/theme default) |
tint
Per-rune colour override: a named tint from the theme registry, with inline per-token overrides layered on top.
| Attribute | Type | Required | Description |
|---|---|---|---|
tint | string | — | Color tint preset applied to this block |
tint-mode | "auto" | "dark" | "light" | — | Whether the tint adapts to auto, dark, or light mode |
width
The track a block rune occupies.
| Attribute | Type | Required | Description |
|---|---|---|---|
width | "compact" | "narrow" | "content" | "wide" | "full" | — | Maximum width constraint for this block |
| Not available | Why |
|---|---|
| frame | this rune declares neither a `frameTarget` nor a media section |
See also
- xref — references that open a drawer, or build one with
preview="drawer". - file-ref — links a project file;
preview="drawer"shows the file in a drawer. - snippet — embeds a project file as a code block, for a "view source" drawer.
SiteConfig
/** Per-site configuration. A project may declare a single site (via `site`) or
* multiple named sites (via `sites: { name: SiteConfig }`).
* Only `contentDir` and `theme` are strictly required for the site to load. */
export interface SiteConfig {
/** Path to content directory, relative to project root */
contentDir: string;
/** Active theme — accepts either a package name string (legacy shorthand)
* or a full {@link SiteThemeConfig} with presets, token overrides, mode
* overlays, and `colorScheme`. */
theme: string | SiteThemeConfig;
/** Documentation-only adapter hint (`svelte`, `astro`, `next`, `nuxt`, `eleventy`, `html`).
* No adapter reads or validates this field today; it serves as an in-config record of
* which adapter the site is intended for. Slated for removal in v1.0. */
target?: string;
/** Component overrides — maps typeof names to relative paths of replacement components */
overrides?: Record<string, string>;
/** Route-to-layout mapping rules, evaluated in order (first match wins) */
routeRules?: RouteRule[];
/** Declarative entity → page routes (SPEC-069). Each rule generates one page
* per registered entity matching `type` + optional `filter`. */
entityRoutes?: EntityRoute[];
/** Whether to render the site-wide search UI — the header search button
* plus the Cmd/Ctrl+K dialog, powered by Pagefind. Defaults to `true`.
*
* Set to `false` to omit the search chrome entirely: the `search` client
* behavior is never initialized and the trigger button is not rendered in
* any layout. Leave it enabled (the default) to keep the button; note that
* results only appear once a Pagefind index has been built and served at
* `/pagefind/` — see the "Setting up search" guide. Until then the button
* opens to a graceful "Search is not available." message. */
search?: boolean;
/** Syntax highlighting options */
highlight?: {
theme?: string | { light: string; dark: string };
};
/** Custom icon SVGs — merged into the theme's global icon group */
icons?: Record<string, string>;
/** Plugins to merge into this site's ThemeConfig (runes, layouts, hooks, etc.) */
plugins?: string[];
/** SPEC-035 — active locale (BCP 47, e.g. `'de'`). Selects first-party and
* plugin translation bundles and drives locale-aware formatting. Defaults to
* `'en'` (zero-config English). */
locale?: string;
/** SPEC-035 — site-level translation overrides, keyed by the auto-derived
* i18n key (`{scope}.{block}.{ref}`). Highest precedence — these win over
* first-party and plugin bundles (Decision D5). Values are `string` or a
* CLDR plural-category map. */
strings?: Record<string, string | Record<string, string>>;
/** Project-level tint presets — merged after theme tints (last wins).
* Field shape matches `TintDefinition` from `@refrakt-md/transform` per
* SPEC-053; `Record<string, unknown>` is used here to avoid a cross-package
* type dependency in `@refrakt-md/types`. */
tints?: Record<string, Record<string, unknown>>;
/** Project-level background presets — merged after theme backgrounds (last wins) */
backgrounds?: Record<string, Record<string, unknown>>;
/** Sandbox configuration. The runtime program-source directory (SPEC-104). */
sandbox?: {
/** Directory of sandbox program sources, scanned at build time
* (ADR-022). Relative to the project root. */
dir?: string;
/** @deprecated Renamed to `dir` (ADR-022). Still accepted as input — the
* config normalizer coalesces it into `dir` and emits a deprecation
* warning — but will be removed in a future release. */
examplesDir?: string;
};
/** Content validation (SPEC-132). The build runs `Markdoc.validate()` over
* every page and reports findings as pipeline warnings; nothing is rendered
* into the page. Omit for the documented defaults.
*
* `critical` findings are reported whatever is set here — they mean the
* document could not be understood, which is not a matter of preference
* (D11). Suppression is per-site and per-error-id only: there is
* deliberately no per-page or per-tag switch, because that granularity
* silences the one call site that revealed a real bug (D5). */
validation?: {
/** `false` stops reporting every suppressible finding for this site. */
enabled?: boolean;
/** Replace the default error ids entirely. Adding `variable-undefined`
* is a mistake the framework will let you make — see D4. */
ids?: string[];
/** Error ids to stop treating as problems. Demoted to `info` rather than
* dropped, so they stay visible without adding build-summary noise. */
disableIds?: string[];
};
/** Base URL for canonical links and og:url */
baseUrl?: string;
/** Human-readable site name for og:site_name */
siteName?: string;
/** Default og:image for pages without their own image */
defaultImage?: string;
/** Site logo for Organization JSON-LD schema */
logo?: string;
/** Canonical GitHub (or compatible) repository URL — e.g.
* `"https://github.com/owner/repo"`. Used by file-ref (SPEC-078) to
* build deep-link "View source" URLs of the form
* `{repoUrl}/blob/{repoBranch}/{path}#L{start}-L{end}`. When absent,
* `file-ref` falls back to a no-href link / in-page anchor with a
* build warning. */
repoUrl?: string;
/** Git ref appended to GitHub source URLs (branch / tag / commit SHA).
* Defaults to `"main"` when omitted. Use a commit SHA for archival
* URLs that won't drift when the file is edited later. */
repoBranch?: string;
/** Rune resolution configuration */
runes?: {
/** Which provider wins a rune name more than one provides: a plugin's
* short name, `"__core__"` to keep a core rune, or `"__project__"` to
* let a project rune shadow a plugin's (SPEC-153 D8). */
prefer?: Record<string, string>;
aliases?: Record<string, string>;
/** Unpublished plugin development: rune name → a JS module exporting a
* rune entry with a `transform`. Not for composed rune definitions,
* which go in `dir` (SPEC-153 D7). */
local?: Record<string, string>;
/** SPEC-153 D4 — the project's directory of composed rune definitions,
* relative to the project root. Every `<rune>.md` in it is a composed
* rune named after the file, read through `ProjectFiles` (D5). Defaults
* to `runes`; an absent directory defines no runes. */
dir?: string;
/** Whether a definition in `dir` may declare a `schema` table (SPEC-145
* D25). `deny` by default: a project's own row publishes with no reviewer.
* `allow` asserts this project's definitions are reviewed like
* first-party code (SPEC-181). */
schema?: 'deny' | 'allow';
};
}