Reference › Project
clarusjs 0.15.0
All releases · [email protected] on npm
Minor Changes
- Attributes on a component land on its root element ([#463](https://github.com/forinda/clarusjs/issues/463)).
<item-list id="steps" aria-label="Steps" data-test="x" [aria-controls]="panel" />renders them on the component's single top-level element (or passes them on to a component there). Attribute-like names only (id,role,tabindex,hidden,lang,dir,style,data-*,aria-*) that the component doesn't declare as inputs; the root's own attribute wins, exceptstyleand ARIA id lists (aria-describedby,aria-labelledby,aria-controls,aria-owns), which merge. Server HTML only: no JavaScript ships.clarusjs checkaccepts these names on a component tag and still reports others. Also:name="text {{ expr }}"on a component tag passes the text as a prop. #474 - Automatic component imports ([#458](https://github.com/forinda/clarusjs/issues/458)). Kebab-case components in
src/components/andsrc/layouts/are used by name without@import: the full name is the folders and file joined (forms/text-field.tscl→<forms-text-field>), the short name the file alone (<text-field>) when no other component has it (two is a located error). Only names with a hyphen, only the components a template uses, and an explicit@importstill works. Other hyphenated tags stay HTML (web components).clarusjs check, the content mapper and the language server (completion, hover, go to definition) know the same names.clarusjs({ components: { dirs, auto } })changes the folders or turns it off; non-kebab files get a warning.clarusjs/compilerexportscomponentIndex(). #470 - Context ([#465](https://github.com/forinda/clarusjs/issues/465)): a component's script calls
provide('key', value), and components rendered inside it, in its template or in content passed to it at any depth, read it with@context key: Type(with an optional default). It's passed with each render as thecxrender option, so it works in async renders and in an island's browser re-renders. Content for a slot is now compiled as a function of the context where it's placed.clarusjs check, Prettier, the language server and the VS Code grammar know@context. #474 - Component events ([#442](https://github.com/forinda/clarusjs/issues/442)). A component declares what it sends its parent with
@event change: number(@event closefor none) and sends it from its script withemit('change', value, { reason, event }). The parent island handles it on the tag,<stepper (change)="total = $event" />:$eventis the value,$infohasreason,eventandcancel(), and cancelling makes the child'semit()return false, so a parent can veto a change without taking the value over. Events stop at the parent.clarusjs checktypes both sides (the valueemit()gets,$eventin the handler, and a misspelled event name). No HTML contract change: acl:eventDOM event travels like@modelwrites. #474 - Folder guards ([#457](https://github.com/forinda/clarusjs/issues/457)). A
+guard.tsin a folder ofsrc/pagesexportsguard(context), which runs before every page and endpoint under it (and before theirload()), outer folders first. Returning aResponse(such asredirect()) answers instead; returning nothing goes on, and it may setlocals. It getsload()'s context plusurl(typedGuardContextfromclarusjs/server), with the same rules: on a static route it runs at build and can't read cookies; for a client route it runs when the route's data is asked for.+guard.tsis never an endpoint. #469 - Folder and config layouts ([#456](https://github.com/forinda/clarusjs/issues/456)). A
+layout.tsclin a folder ofsrc/pageswraps every page in it and below it (deeper folders inside), and the plugin'slayoutsoption wraps pages by route pattern ({ layout, include, exclude }, patterns as inroutes; outermost, in order). The page's content fills the layout's default slot and its top-level@slot('name') { }fills the nearest layout's named slots; layouts getpathandparams, on the server and from the client router.@layout noneopts a page out.+files undersrc/pagesare never routes. Not yet: a page with a<script>of its own (a located error),+layout.load.ts, and Markdown pages. #468 - Islands pass content to islands ([#465](https://github.com/forinda/clarusjs/issues/465)): content written inside an island can go to another island's
<slot />, with its holes, handlers, blocks and[use]; each island wires only its own. An island's slot content now sits between<!--[s-->and<!--]s-->(a new marker in the HTML contract), and the runtime decides which island owns a node across those ranges. The "can't take content from inside another island yet" error is gone. Forms paths of fields in slot content come from the island that wrote them. Tabs'[(value)]and(change)work inside islands. #486 - Islands take content at
<slot />([#465](https://github.com/forinda/clarusjs/issues/465)). The server renders it in the parent's scope and the browser never re-renders it, so in an island a slot sits outside@if,@forand@awaitblocks and component content, passes no data and has no fallback. Content from inside another island is a render error for now. #474 - Scoped slots ([#455](https://github.com/forinda/clarusjs/issues/455)): a component passes data to the content filling a slot,
<slot name="row" [item]="item" [index]="$index">fallback</slot>, and the fill names it like a function parameter,@slot('row', { item, index }) { … }(renames, defaults and@slot('default', …)work too). Rendered on the server;clarusjs checkchecks the values where they're passed (the names a fill receives are typedanyfor now). A fill that receives data inside an island is a located error, for now. #461 @clarusjs/ui-primitives([#464](https://github.com/forinda/clarusjs/issues/464)), a new package: accessible behaviours as small DOM functions, each(element, options) → stop:rovingFocus(one Tab stop, arrow keys by orientation and RTL, Home/End, disabled items skipped),typeahead(a repeated key cycles),dismiss(Escape and outside press, stacked layers, a cancelablecl:dismissevent),enter/exit(Base UI'sdata-open,data-starting-style,data-ending-stylefor CSS transitions),focusReturnandposition(data-sideand the--anchor-width,--available-height,--transform-originvariables). Each is its own module, no dependencies, about 2.3 KB gzip for all six. clarusjs:[use]="fn"on an element in an island callsfn(element)in the browser when the island attaches, and the function it returns when the element's branch, row or island goes (a list runs several). The server renders adata-cl-umarker only;clarusjs checktypes the element by its tag. #474
Patch Changes
- Review fixes for context and island content ([#465](https://github.com/forinda/clarusjs/issues/465)):
providemay only be called (a bare reference is a located error in the build and incheck), an import may rename it (import { provide as register }) and any import binding the nameprovideis rejected, comments or not,@contextnames likeObjectwork, a provided__proto__key reaches re-rendered content, an island's markers never include those of an island in its slot content, a@modelfield in a component inside another island's slot takes the right path, and an island whose content reads a nested provider that failed to load is retried with it instead of failing for good. Menu items name their menu (data-menu), so arrow keys and typeahead skip a nested menu's items; a radio group follows its value after a reset of the form it is in now (also after a fragment swap moved it); a focused tooltip trigger keeps its tooltip open when the pointer leaves. #485 - Context fixes ([#465](https://github.com/forinda/clarusjs/issues/465)):
@contextreads only what was provided (a name liketoStringno longer reads the object's own); aprovidekey must be a name@contextcan read;clarusjs checkreports a script's ownprovideas the build does. The Tabs docs no longer suggest[(value)]and(change), which need a parent island that can pass content to the tabs. #485