Files
WRNexusJSDoc/app/pages/language.wrn
T
2026-07-12 16:14:06 +05:30

91 lines
8.2 KiB
Plaintext

page Languageanddirectives {
seo {
title = "Language and directives"
description = "Complete WRNexusJS language reference for events, directives, loops, conditionals, data, components, forms, realtime, and native behavior."
}
view {
<div class="docs-shell">
<header class="topbar">
<a class="brand" href="/"><span>W</span> WRNexusJS</a>
<nav><a href="/getting-started">Get started</a><a href="/packages">Packages</a><a href="/language">Language</a><a href="/architecture">Architecture</a></nav>
<button data-wire-theme-toggle class="theme-button" aria-label="Toggle theme">Theme</button>
</header>
<main class="page"><article class="documentation prose standalone language-reference"><span class="eyebrow">Complete reference</span><h1>Language and directives</h1><p>This page documents the .wrn language and declarative browser features that span multiple packages.</p>
<h2 id="file-anatomy">File anatomy</h2><p>A file declares a <code>page</code> or <code>component</code> and can contain metadata, props, state, data, view, style, server functions, APIs, and realtime handlers.</p><pre><code>page Dashboard &#123;
layout = &quot;default&quot;
seo &#123; title = &quot;Dashboard&quot; &#125;
state count = 0
view &#123; &lt;button @click=&quot;count++&quot;&gt;&#123;count&#125;&lt;/button&gt; &#125;
style &#123; button &#123; padding: 12px; &#125; &#125;
&#125;</code></pre>
<h2 id="state">State and interpolation</h2><p>State is scoped to the nearest generated <code>data-scope</code>. Text expressions update reactively after hydration.</p><pre><code>state count = 0
state user = &#123; name: &quot;Ada&quot; &#125;
view &#123;
&lt;p&gt;Count: &#123;count&#125;&lt;/p&gt;
&lt;p&gt;&#123;user.name&#125;&lt;/p&gt;
&#125;</code></pre>
<h2 id="events">Events</h2><p>Any DOM event can use <code>@event="statement"</code>. The compiler emits <code>data-on-event</code>. The expression receives <code>event</code> and can mutate state.</p><div class="table-wrap"><table><thead><tr><th>Syntax</th><th>Purpose</th></tr></thead><tbody><tr><td><code>@click</code></td><td>Pointer or keyboard activation.</td></tr><tr><td><code>@input</code></td><td>Read live field values.</td></tr><tr><td><code>@change</code></td><td>React to committed field changes.</td></tr><tr><td><code>@submit</code></td><td>Handle form submission behavior.</td></tr><tr><td><code>@browser-click</code></td><td>Run only in a browser target.</td></tr><tr><td><code>@mobile-click</code></td><td>Run only in a native/mobile target.</td></tr></tbody></table></div><pre><code>&lt;input @input=&quot;name = event.target.value&quot;&gt;
&lt;button @click=&quot;count++&quot;&gt;Add&lt;/button&gt;
&lt;form @submit=&quot;submitted = true&quot;&gt;...&lt;/form&gt;</code></pre>
<h2 id="directives">Reactive data attributes</h2><div class="table-wrap"><table><thead><tr><th>Directive</th><th>Behavior</th></tr></thead><tbody><tr><td><code>data-scope</code></td><td>Declares reactive state for a subtree.</td></tr><tr><td><code>data-text</code></td><td>Synchronizes textContent with an expression.</td></tr><tr><td><code>data-show</code></td><td>Shows or hides an element by truthiness.</td></tr><tr><td><code>data-for</code></td><td>Repeats an element for a client-side list.</td></tr><tr><td><code>data-on-&lt;event&gt;</code></td><td>Compiled form of an event binding.</td></tr><tr><td><code>data-component</code></td><td>Mounts a server-rendered component.</td></tr><tr><td><code>data-slot</code></td><td>Fills a named component or layout slot.</td></tr><tr><td><code>data-wrnexus-csr</code></td><td>Connects generated client data fetching.</td></tr></tbody></table></div>
<h2 id="conditionals">Conditional rendering</h2><h3>Server conditionals</h3><p>Server blocks render only the selected branch into the response.</p><pre><code>&#123;#if user.isAdmin&#125;
&lt;a href=&quot;/admin&quot;&gt;Admin&lt;/a&gt;
&#123;:else if user&#125;
&lt;p&gt;Welcome &#123;user.name&#125;&lt;/p&gt;
&#123;:else&#125;
&lt;a href=&quot;/login&quot;&gt;Sign in&lt;/a&gt;
&#123;/if&#125;</code></pre><h3>Client visibility</h3><pre><code>&lt;section data-show=&quot;open&quot;&gt;Visible while open is true&lt;/section&gt;</code></pre>
<h2 id="loops">Loops and lists</h2><h3>Server each block</h3><pre><code>&#123;#each users as user, i&#125;
&lt;p&gt;&#123;i + 1&#125;. &#123;user.name&#125;&lt;/p&gt;
&#123;:empty&#125;
&lt;p&gt;No users&lt;/p&gt;
&#123;/each&#125;</code></pre><h3>Reactive client loop</h3><pre><code>&lt;li data-for=&quot;item, i in items&quot;&gt;
&lt;span data-text=&quot;item.name&quot;&gt;&lt;/span&gt;
&lt;button data-on-click=&quot;items = items.filter(x =&gt; x !== item)&quot;&gt;Remove&lt;/button&gt;
&lt;/li&gt;</code></pre>
<h2 id="components">Components, props, and slots</h2><pre><code>component Card &#123;
props &#123; title = &quot;Card&quot; &#125;
view &#123;
&lt;article&gt;&lt;h2&gt;&#123;title&#125;&lt;/h2&gt;&lt;slot&gt;&lt;/slot&gt;&lt;/article&gt;
&#125;
&#125;
&lt;div data-component=&quot;card&quot; title=&quot;Profile&quot;&gt;
&lt;p&gt;Card content&lt;/p&gt;
&lt;/div&gt;</code></pre>
<h2 id="data">Server and client data</h2><p>Use named data bindings for SSR data or client hydration. Secrets and database work stay on the server.</p><pre><code>data users &#123;
ssr GET &quot;/api/users&quot;
&#125;
view &#123;
&#123;#each users as user&#125;&lt;p&gt;&#123;user.name&#125;&lt;/p&gt;&#123;/each&#125;
&#125;</code></pre>
<h2 id="forms">Forms and validation</h2><p>Schema-backed forms validate in the browser and on the server with the same descriptor.</p><pre><code>&lt;form data-schema=&quot;login&quot; method=&quot;post&quot; action=&quot;/api/login&quot; data-redirect=&quot;/dashboard&quot;&gt;
&lt;input name=&quot;email&quot; type=&quot;email&quot;&gt;
&lt;span data-error=&quot;email&quot;&gt;&lt;/span&gt;
&lt;button&gt;Sign in&lt;/button&gt;
&lt;p data-success=&quot;Signed in&quot; hidden&gt;&lt;/p&gt;
&lt;/form&gt;</code></pre>
<h2 id="i18n">Internationalization and themes</h2><pre><code>&lt;h1&gt;&#123;t:home.title&#125;&lt;/h1&gt;
&lt;button data-wire-lang-set=&quot;fr&quot;&gt;Français&lt;/button&gt;
&lt;button data-wire-theme-toggle&gt;Toggle theme&lt;/button&gt;
&lt;button data-wire-theme-set=&quot;dark&quot;&gt;Dark&lt;/button&gt;</code></pre>
<h2 id="realtime">Realtime rooms</h2><pre><code>&lt;div data-room=&quot;chat&quot; data-room-user=&quot;Ada&quot;&gt;
&lt;span data-room-status&gt;&lt;/span&gt;
&lt;div data-room-log&gt;&lt;/div&gt;
&lt;template data-room-item=&quot;message&quot;&gt;&lt;p&gt;%user%: %text%&lt;/p&gt;&lt;/template&gt;
&lt;form data-room-send&gt;&lt;input name=&quot;text&quot; data-room-reset&gt;&lt;/form&gt;
&lt;/div&gt;</code></pre>
<h2 id="native">Browser and native directives</h2><pre><code>&lt;button data-native-browser=&quot;share&quot; data-native-mobile=&quot;share&quot;
data-native-options='&#123;&quot;title&quot;:&quot;WRNexusJS&quot;&#125;'&gt;Share&lt;/button&gt;
&lt;nav data-native-only=&quot;mobile&quot;&gt;Mobile navigation&lt;/nav&gt;
&lt;p data-native-only=&quot;browser&quot;&gt;Browser instructions&lt;/p&gt;
&lt;button data-native-requires=&quot;haptics&quot;&gt;Haptic action&lt;/button&gt;</code></pre>
<h2 id="other">Other framework attributes</h2><div class="table-wrap"><table><thead><tr><th>Attribute</th><th>Purpose</th></tr></thead><tbody><tr><td><code>data-error</code></td><td>Field validation error destination.</td></tr><tr><td><code>data-success</code></td><td>Successful form message.</td></tr><tr><td><code>data-redirect</code></td><td>Navigation after form success.</td></tr><tr><td><code>data-room-*</code></td><td>Realtime status, templates, sending, and reset behavior.</td></tr><tr><td><code>data-uploader</code></td><td>Config-driven upload widget.</td></tr><tr><td><code>data-wire-theme-*</code></td><td>Theme selection and toggling.</td></tr><tr><td><code>data-wire-lang*</code></td><td>Language selection.</td></tr><tr><td><code>data-native-*</code></td><td>Cross-platform capability and visibility behavior.</td></tr></tbody></table></div></article></main>
<footer>WRNexusJS 0.2.12 · SSR-first · Bun-native · Documentation generated from published package APIs.</footer>
</div>
}
}