{"vsa":"0.9.0","type":"StaticManifest","manifestVersion":"1.0.0","viewId":"docs-v0-2-screens","title":"Screens (preview) · Docs v0.2","requires":[{"name":"zone.text","version":"^1.0.0"}],"optional":[{"name":"render.dom","version":"^1.0.0"},{"name":"projection.slots","version":"^1.0.0"}],"trustDomain":"self","dataClass":"public","zones":[{"zoneId":"l-1","kind":"text","label":"Luxel"},{"zoneId":"l-2","kind":"text","label":"Docs"},{"zoneId":"l-3","kind":"text","label":"Demo"},{"zoneId":"l-4","kind":"text","label":"Numbers"},{"zoneId":"l-5","kind":"text","label":"Security"},{"zoneId":"l-6","kind":"text","label":"Releases"},{"zoneId":"l-7","kind":"text","label":"Roadmap"},{"zoneId":"l-8","kind":"text","label":"Blog"},{"zoneId":"l-9","kind":"text","label":"Español"},{"zoneId":"t-10","kind":"text","label":"Docs v0.2"},{"zoneId":"l-11","kind":"text","label":"Docs v0.1: 0.1.0 betas →"},{"zoneId":"l-12","kind":"text","label":"Search documentation →"},{"zoneId":"t-13","kind":"text","label":"Start"},{"zoneId":"l-14","kind":"text","label":"Overview"},{"zoneId":"l-15","kind":"text","label":"Getting started"},{"zoneId":"l-16","kind":"text","label":"Primeros pasos"},{"zoneId":"l-17","kind":"text","label":"Concepts"},{"zoneId":"t-18","kind":"text","label":"Guide"},{"zoneId":"l-19","kind":"text","label":"Views"},{"zoneId":"l-20","kind":"text","label":"Screens"},{"zoneId":"l-21","kind":"text","label":"Testing screens"},{"zoneId":"l-22","kind":"text","label":"Forms"},{"zoneId":"l-23","kind":"text","label":"Collections"},{"zoneId":"l-24","kind":"text","label":"Charts"},{"zoneId":"l-25","kind":"text","label":"Polling"},{"zoneId":"l-26","kind":"text","label":"Languages"},{"zoneId":"l-27","kind":"text","label":"Server"},{"zoneId":"l-28","kind":"text","label":"Sessions"},{"zoneId":"l-29","kind":"text","label":"Production"},{"zoneId":"l-30","kind":"text","label":"Behind a gateway"},{"zoneId":"l-31","kind":"text","label":"Tooling"},{"zoneId":"l-32","kind":"text","label":"From React or Next.js"},{"zoneId":"t-33","kind":"text","label":"Reference"},{"zoneId":"l-34","kind":"text","label":"Typical React mistakes"},{"zoneId":"l-35","kind":"text","label":"API"},{"zoneId":"l-36","kind":"text","label":"Diagnostics"},{"zoneId":"l-37","kind":"text","label":"Support matrix"},{"zoneId":"t-38","kind":"text","label":"Security"},{"zoneId":"l-39","kind":"text","label":"Security guide"},{"zoneId":"l-40","kind":"text","label":"Threat model"},{"zoneId":"l-41","kind":"text","label":"Claims and evidence"},{"zoneId":"t-42","kind":"text","label":"Project"},{"zoneId":"l-43","kind":"text","label":"Known gaps"},{"zoneId":"l-44","kind":"text","label":"Upgrading to 0.2.0-alpha.1"},{"zoneId":"l-45","kind":"text","label":"Changelog"},{"zoneId":"l-46","kind":"text","label":"Index of all sections"},{"zoneId":"t-47","kind":"text","label":"Luxel v0.2 · Guide"},{"zoneId":"t-48","kind":"text","label":"Screens (preview)"},{"zoneId":"t-49","kind":"text","label":"Status: preview, not frozen. Screen files are Sprint 12.3 work (ADR-061, a draft). Names and shapes can still change before v0.1; a project written with src/views/ + server/contract.ts + server/events.ts keeps working and can live next to "},{"zoneId":"t-50","kind":"text","label":"screens."},{"zoneId":"t-51","kind":"text","label":"A screen file, src/screens/‹view id>.screen.tsx, holds everything one view needs, declared once: its state, its messages, who may load it and send each event, the handlers, and the view. The build generates the contract from it; nothing is "},{"zoneId":"t-52","kind":"text","label":"written twice."},{"zoneId":"t-53","kind":"text","label":"import { allow, collection, input, ref, screen, text } from '@luxel-framework/server/screen';\nimport { Action, Collection, Field, Row, Status, Text, View } from '@luxel-framework/ui';\nimport { contacts } from '../../server/contacts.mjs';\n"},{"zoneId":"t-54","kind":"text","label":"import login from './login.screen.js';\n\nconst s = screen({\n  state: { rows: collection({ key: 'id', fields: { name: text() } }), summary: text() },\n"},{"zoneId":"t-55","kind":"text","label":"  messages: { added: 'Contact {0} added.', nameInvalid: 'Enter a name of 1 to 60 characters.' },\n});\n\nexport default s.define({\n  route: { loginView: login },\n"},{"zoneId":"t-56","kind":"text","label":"  load: s.load(allow(['user']), async (ctx) => ctx.snapshot(1, await contacts.page(ctx.session.userId))),\n  events: {\n    add: s.event({ policy: allow(['user']), inputs: { name: input({ maxLength: 60, required: true }) } }, async ({ name }, "},{"zoneId":"t-57","kind":"text","label":"ctx) => {\n      if (name.trim() === '') return ctx.reject('VALIDATION', ctx.message.nameInvalid());\n      await contacts.add(ctx.session.userId, name.trim());\n"},{"zoneId":"t-58","kind":"text","label":"      return ctx.update(await contacts.page(ctx.session.userId)).success(ctx.message.added(name.trim()));\n    }),\n    remove: s.event({ policy: allow(['user']), param: ref('contact') }, async (_input, ctx) => {\n"},{"zoneId":"t-59","kind":"text","label":"      await contacts.remove(ctx.session.userId, ctx.param);\n      return ctx.update(await contacts.page(ctx.session.userId));\n    }),\n  },\n  view: ({ state, events }) => (\n    ‹View title=\"Contacts\" dataClass=\"internal\">\n"},{"zoneId":"t-60","kind":"text","label":"      ‹Row as=\"form\">\n        ‹Field for={events.add.inputs.name} label=\"Name\" />\n        ‹Action id=\"add\" event={events.add} status=\"result\">Add‹/Action>\n      ‹/Row>\n      ‹Status id=\"result\" />\n      ‹Text bind={state.summary} as=\"p\" />\n"},{"zoneId":"t-61","kind":"text","label":"      ‹Collection bind={state.rows} maxItems={20} label=\"Contacts\">\n        {(c) => ‹Action event={events.remove} param={c.id} status=\"result\">{c.name}‹/Action>}\n      ‹/Collection>\n    ‹/View>\n  ),\n});"},{"zoneId":"t-62","kind":"text","label":"What you declare"},{"zoneId":"t-63","kind":"text","label":"State (screen({ state })): each leaf with a helper of @luxel-framework/server/screen: text(), money(), date(), quantity(), number({ min, max }), numbers({ min, max, length }), status([...]), value(), options({ max }), collection({ key, "},{"zoneId":"t-64","kind":"text","label":"fields }). A short, fixed list that is never paginated (the 12 months of a year) is declared collection({ key, fields, page: false, maxItems: 12 }): it is exempt from policies.pageSize, maxItems still bounds it, and its ‹Collection> may "},{"zoneId":"t-65","kind":"text","label":"leave maxItems out ("},{"zoneId":"l-66","kind":"text","label":"Collections"},{"zoneId":"t-67","kind":"text","label":")."},{"zoneId":"t-68","kind":"text","label":"Messages (screen({ messages })): the texts a handler may show, with {0}, {1}… placeholders; plural({ one, other }) for counts. A handler calls them as functions: ctx.message.added(name)."},{"zoneId":"t-69","kind":"text","label":"Policies: allow(roles) or anyone(), each with an optional { effect: 'read' }. They are part of the declaration, next to the handler they guard."},{"zoneId":"t-70","kind":"text","label":"Events (s.event(spec, handler)): inputs are declared with input({ type, maxLength, required, min, max }) (or choice(kind) for a select whose value is an id); an event sent from a collection item declares its parameter: param: ref('‹kind>') "},{"zoneId":"t-71","kind":"text","label":"for an id your scope function checks, param: local() for a key that names no record (a page number)."},{"zoneId":"t-72","kind":"text","label":"Route (route): what views.‹id> holds in luxel.config.ts for a view file (path, loginView, whenAuthenticated, identity, accountLimit, styles, pollMs…). Another screen is named by importing it: loginView: login. path: '/pricing' gives the "},{"zoneId":"t-73","kind":"text","label":"screen a clean address; without it the screen is served at /‹variant>/‹file name>. The paths of all screens are the app's route table, fixed at build ("},{"zoneId":"l-74","kind":"text","label":"Routes"},{"zoneId":"t-75","kind":"text","label":"); a path with a parameter (/contacts/:id) does not build yet."},{"zoneId":"t-76","kind":"text","label":"Load: s.load(policy, handler), or s.staticLoad(handler?) for a public page that is the same for everyone."},{"zoneId":"t-77","kind":"text","label":"What the view uses"},{"zoneId":"t-78","kind":"text","label":"The view receives { state, events } and names things with them, never with strings: bind={state.summary}, event={events.add}, ‹Field for={events.add.inputs.name}>, onSuccess={{ clear: [events.add.inputs.name], focus: events.add.inputs.name "},{"zoneId":"t-79","kind":"text","label":"}}. A string where a state path, an event or a field's input belongs is a build error (LUXEL-E061), and so is an event or an input that the view and the declaration do not agree on (LUXEL-E062). One string remains: onSuccess.focus also "},{"zoneId":"t-80","kind":"text","label":"takes a string, the id of an action or the name of a field; the build checks that it names one of them. An event's name on the wire is its key with each capital letter written as a dot and its lowercase (signOut is sign.out)."},{"zoneId":"t-81","kind":"text","label":"What runs where"},{"zoneId":"t-82","kind":"text","label":"The handlers import your server modules (a database, a mailer). The view is compiled at build time. So the build treats a screen file in a particular way:"},{"zoneId":"t-83","kind":"text","label":"Imports. At build time only @luxel-framework/ui, @luxel-framework/server/screen and relative .tsx / .json files inside src/ are loaded. Every other import (a .ts or .mjs module, a package, node: modules) is replaced by an inert stand-in: "},{"zoneId":"t-84","kind":"text","label":"its file is not read and its code does not run. Declaring a handler captures the stand-in and runs nothing. Using one outside a handler (calling it, constructing it, writing to it, turning it into text or a number, placing it in the view) "},{"zoneId":"t-85","kind":"text","label":"is LUXEL-E060. Two things report nothing: reading a property of a stand-in gives another stand-in, and a bare test (if (imported)) is true whatever the real value would be. So do not branch on a server import outside a handler."},{"zoneId":"t-86","kind":"text","label":"A separate process. The screens are evaluated in another Node process started with Node's permission model and nothing allowed: no file reads or writes, no child processes, no workers; no network where the Node version's permission model "},{"zoneId":"t-87","kind":"text","label":"covers it (it does not on Node 22). This is a guard against a build that reads server code by mistake. It is not a sandbox: do not build code you do not trust."},{"zoneId":"t-88","kind":"text","label":"On the server. The server bundle (.luxel/events.mjs) has the real imports. It is generated: it registers every screen's load and handlers with screenDefinitions from @luxel-framework/server, which an app does not call itself. A server "},{"zoneId":"t-89","kind":"text","label":"module written in TypeScript is compiled into that bundle, so its text is there (the bundle is never served)."},{"zoneId":"t-90","kind":"text","label":"A view file (src/views/*.view.tsx) and luxel.config.ts cannot import a screen file."},{"zoneId":"t-91","kind":"text","label":"Everything else is as in "},{"zoneId":"l-92","kind":"text","label":"views"},{"zoneId":"t-93","kind":"text","label":", "},{"zoneId":"l-94","kind":"text","label":"the server"},{"zoneId":"t-95","kind":"text","label":" and "},{"zoneId":"l-96","kind":"text","label":"forms"},{"zoneId":"t-97","kind":"text","label":": the browser receives the compiled template and the universal runtime, and no code of the screen."},{"zoneId":"l-98","kind":"text","label":"Previous: Views"},{"zoneId":"l-99","kind":"text","label":"Next: Testing screens"},{"zoneId":"l-100","kind":"text","label":"Edit this page on GitHub"},{"zoneId":"t-101","kind":"text","label":"This page: 7.9 KB of JavaScript (Luxel's shared runtime), 0 KB from your app."},{"zoneId":"t-102","kind":"text","label":"Measured when the site is built: the runtime files this page loads, compressed as they are sent."},{"zoneId":"l-103","kind":"text","label":"GitHub"},{"zoneId":"l-104","kind":"text","label":"Discussions"},{"zoneId":"l-105","kind":"text","label":"Apache-2.0"},{"zoneId":"l-106","kind":"text","label":"Ties and losses"},{"zoneId":"t-107","kind":"text","label":"Made by IntiOps. The Luxel 0.1.0 betas are on npm (0.1.0-beta.1, 0.1.0-beta.2), with an alpha of 0.2 (0.2.0-alpha.1): no external security review yet."}],"events":[],"messages":{"network":"Could not reach the server. Check your connection and try again.","unexpected":"Something went wrong. Reload the page."},"extensions":{"render.dom@1":{"root":{"el":"div","class":"site site--en page--doc","children":[{"el":"header","class":"topbar","children":[{"zone":"l-1","el":"span","class":"brand"},{"el":"div","class":"nav","children":[{"zone":"l-2","el":"span","class":"nav-link"},{"zone":"l-3","el":"span","class":"nav-link"},{"zone":"l-4","el":"span","class":"nav-link"},{"zone":"l-5","el":"span","class":"nav-link"},{"zone":"l-6","el":"span","class":"nav-link"},{"zone":"l-7","el":"span","class":"nav-link"},{"zone":"l-8","el":"span","class":"nav-link"}]},{"zone":"l-9","el":"span","class":"lang"}]},{"el":"main","class":"main main--doc","children":[{"el":"div","class":"sidebar","children":[{"zone":"t-10","el":"p","class":"sidebar-version"},{"zone":"l-11","el":"span","class":"side-link side-link--version"},{"zone":"l-12","el":"span","class":"side-link side-link--search"},{"zone":"t-13","el":"p","class":"sidebar-group"},{"el":"div","class":"sidebar-links","children":[{"zone":"l-14","el":"span","class":"side-link"},{"zone":"l-15","el":"span","class":"side-link"},{"zone":"l-16","el":"span","class":"side-link"},{"zone":"l-17","el":"span","class":"side-link"}]},{"zone":"t-18","el":"p","class":"sidebar-group"},{"el":"div","class":"sidebar-links","children":[{"zone":"l-19","el":"span","class":"side-link"},{"zone":"l-20","el":"span","class":"side-link side-link--current"},{"zone":"l-21","el":"span","class":"side-link"},{"zone":"l-22","el":"span","class":"side-link"},{"zone":"l-23","el":"span","class":"side-link"},{"zone":"l-24","el":"span","class":"side-link"},{"zone":"l-25","el":"span","class":"side-link"},{"zone":"l-26","el":"span","class":"side-link"},{"zone":"l-27","el":"span","class":"side-link"},{"zone":"l-28","el":"span","class":"side-link"},{"zone":"l-29","el":"span","class":"side-link"},{"zone":"l-30","el":"span","class":"side-link"},{"zone":"l-31","el":"span","class":"side-link"},{"zone":"l-32","el":"span","class":"side-link"}]},{"zone":"t-33","el":"p","class":"sidebar-group"},{"el":"div","class":"sidebar-links","children":[{"zone":"l-34","el":"span","class":"side-link"},{"zone":"l-35","el":"span","class":"side-link"},{"zone":"l-36","el":"span","class":"side-link"},{"zone":"l-37","el":"span","class":"side-link"}]},{"zone":"t-38","el":"p","class":"sidebar-group"},{"el":"div","class":"sidebar-links","children":[{"zone":"l-39","el":"span","class":"side-link"},{"zone":"l-40","el":"span","class":"side-link"},{"zone":"l-41","el":"span","class":"side-link"}]},{"zone":"t-42","el":"p","class":"sidebar-group"},{"el":"div","class":"sidebar-links","children":[{"zone":"l-43","el":"span","class":"side-link"},{"zone":"l-44","el":"span","class":"side-link"},{"zone":"l-45","el":"span","class":"side-link"}]},{"zone":"l-46","el":"span","class":"side-link side-link--index"}]},{"el":"section","class":"article","children":[{"zone":"t-47","el":"p","class":"doc-meta"},{"el":"div","class":"block","children":[{"zone":"t-48","el":"h1","class":"page-title"},{"el":"p","class":"note","children":[{"zone":"t-49","el":"span"},{"zone":"t-50","el":"span"}]},{"el":"p","class":"para","children":[{"zone":"t-51","el":"span"},{"zone":"t-52","el":"span"}]},{"el":"p","class":"code","children":[{"zone":"t-53","el":"span"},{"zone":"t-54","el":"span"},{"zone":"t-55","el":"span"},{"zone":"t-56","el":"span"},{"zone":"t-57","el":"span"},{"zone":"t-58","el":"span"},{"zone":"t-59","el":"span"},{"zone":"t-60","el":"span"},{"zone":"t-61","el":"span"}]},{"zone":"t-62","el":"h2","class":"section-title"},{"el":"div","class":"list-wrap","children":[{"el":"ul","class":"list","children":[{"el":"li","children":[{"zone":"t-63","el":"span"},{"zone":"t-64","el":"span"},{"zone":"t-65","el":"span"},{"zone":"l-66","el":"span"},{"zone":"t-67","el":"span"}]},{"zone":"t-68","el":"li"},{"zone":"t-69","el":"li"},{"el":"li","children":[{"zone":"t-70","el":"span"},{"zone":"t-71","el":"span"}]},{"el":"li","children":[{"zone":"t-72","el":"span"},{"zone":"t-73","el":"span"},{"zone":"l-74","el":"span"},{"zone":"t-75","el":"span"}]},{"zone":"t-76","el":"li"}]}]},{"zone":"t-77","el":"h2","class":"section-title"},{"el":"p","class":"para","children":[{"zone":"t-78","el":"span"},{"zone":"t-79","el":"span"},{"zone":"t-80","el":"span"}]},{"zone":"t-81","el":"h2","class":"section-title"},{"zone":"t-82","el":"p","class":"para"},{"el":"div","class":"list-wrap","children":[{"el":"ul","class":"list","children":[{"el":"li","children":[{"zone":"t-83","el":"span"},{"zone":"t-84","el":"span"},{"zone":"t-85","el":"span"}]},{"el":"li","children":[{"zone":"t-86","el":"span"},{"zone":"t-87","el":"span"}]},{"el":"li","children":[{"zone":"t-88","el":"span"},{"zone":"t-89","el":"span"}]},{"zone":"t-90","el":"li"}]}]},{"el":"p","class":"para","children":[{"zone":"t-91","el":"span"},{"zone":"l-92","el":"span"},{"zone":"t-93","el":"span"},{"zone":"l-94","el":"span"},{"zone":"t-95","el":"span"},{"zone":"l-96","el":"span"},{"zone":"t-97","el":"span"}]}]},{"el":"div","class":"pager","children":[{"zone":"l-98","el":"span","class":"pager-link"},{"zone":"l-99","el":"span","class":"pager-link pager-link--next"}]},{"zone":"l-100","el":"span","class":"edit-link"}]}]},{"el":"footer","class":"footer","children":[{"zone":"t-101","el":"p","class":"jsline"},{"zone":"t-102","el":"p","class":"jsnote"},{"el":"div","class":"footer-links","children":[{"zone":"l-103","el":"span","class":"footer-link"},{"zone":"l-104","el":"span","class":"footer-link"},{"zone":"l-105","el":"span","class":"footer-link"},{"zone":"l-106","el":"span","class":"footer-link"}]},{"zone":"t-107","el":"p","class":"made"}]}]}},"projection.slots@1":{"template":"/_luxel/a/docs-v0-2-screens.1cc82b503c22.html","map":"/_luxel/a/docs-v0-2-screens.slots.14db6a8a6ea2.json"}}}