Reference › Project
clarusjs 0.10.0
All releases · [email protected] on npm
Minor Changes
- Fields and attributes, checked against Vue's exceptions ([#241](https://github.com/forinda/clarusjs/issues/241)): -
falseis now a value on the enumeratedspellcheck,draggableandcontenteditable(andtranslate: yes/no), and on the ARIA statesaria-expanded,aria-pressed,aria-checkedandaria-selected. Before,[aria-expanded]="false"removed the attribute. Other attributes keep "false removes it". - A field'svalueandcheckedare set last, aftertype,min,maxandstep, so a browser doesn't clamp them. -[(value)]: - text fields don't write while an input method composes (IME); - number and range inputs write numbers; - checkboxes with a value bind an array (checked when it includes the value); -<select multiple>(static or[multiple]) binds an array of the selected values; - a bound<select>'s options renderselectedon the server, so the choice shows before any JavaScript (values compare as text); - a number field keeps what's being typed (1.0isn't rewritten to1); - a checkbox group bound to a missing array starts an empty one. Radio, checkbox and number bindings need a statictype; with a bound[type]the field binds as text. - Already right, now tested:form,list,width/height, textareatype, and SVG attributes (case kept) are always attributes;<option [value]>works; anullvalue is an empty field. #301 - At
vite build, each run of whitespace in template text becomes one character (a newline if it had one), so a formatted template's indentation stays out of the HTML.<pre>,<textarea>,<script>,<style>,verbatimcontents and{{ }}values are untouched;clarusjs({ collapseWhitespace: false })turns it off. Also acompile()option,collapseWhitespace. #308 clarusjs/fetchcaches answers by key ([#287](https://github.com/forinda/clarusjs/issues/287)), for paginated lists and other data shown again and again: -resource(fetcher, { key: () => ['items', { page }] })shares one cache entry per key across the page's islands. A key seen before is served without a request until it's invalidated, orstalems old. The previous value stays on screen while a new key loads. Requests for the same key at the same time share one request. -invalidate(['items']): every cached answer whose key starts with that prefix is marked stale. The ones on screen refetch now; the others refetch when next used. -setData(key, value | fn)for optimistic edits, andprefetch(key, fetcher)for the next page. - An answer nothing shows is dropped afterkeepms (default 5 minutes). #290clarusjs/fetch: data an island fetches itself, in the browser ([#258](https://github.com/forinda/clarusjs/issues/258)). -resource(fetcher, options)givesvalue,loading,error,refetch()andmutate(). It re-runs when a signal the fetcher reads changes, so requests chain. The latest run wins, and a disposed island aborts its run. - Options: retry with backoff; refetch on an interval or when the tab regains focus; a starting value fromload(), revalidated in the browser unlessrefetch: { onStart: false }. -batch(load)sends the keys asked of one endpoint at the same moment, from any island, as one request. -json(url)throws on a non-2xx response. Nothing is fetched on the server. The entry stays within 2.5 KB gzip, and a page that doesn't import it ships none of it. See https://clarusjs.com/guide/fetching. #286@forrows have$count,$first,$last,$evenand$oddbesides$index([#249](https://github.com/forinda/clarusjs/issues/249)). In an island they follow the list: add a row, and the old last row isn't$lastany more. Type checking knows them ($counta number, the others booleans). Clearer@forerrors: - an item named like one of those names; - a secondtrack; - a second@empty. An island@forwithouttracknow warns: rows are matched by position, so a row's state can move to another item. Matching by position on purpose? Writetrack $index. A script can't declare a variable named like one of the row names. #301h()inclarusjs/views([#259](https://github.com/forinda/clarusjs/issues/259)) builds HTML in server code from elements and views: for components picked at runtime, wrappers, generated layouts and tests (h('components/card', { title }, [h('p', {}, ['Body'])])). - Text is escaped and attributes are URL-checked, as in templates, andh()results nest. - A template's{{ }}insertsh()output as HTML; every other value is escaped as before. - Onlyh()can make that output (data such as JSON can't). It's for server-rendered pages: sending it in an island's props or a client route's data is an error naming it. -on*attributes,srcdoc, tags that load or run things, and clarusjs's owncl-*tags are refused from code. Take view and tag names from your own list, never from request data. #301- Radio groups bind two ways ([#267](https://github.com/forinda/clarusjs/issues/267)).
[(value)]on<input type="radio" value="pro">is checked when the bound value equals the radio's value, and picking it writes that value:plan: 'free' | 'pro'binds to a group of radios, as Vue'sv-modeldoes. The value can be static or[value]. A bound radio without a value is a compile error. Type checking checks each radio's static value against the bound type. #301 - URLs that load a page, plugin, stylesheet or base URL into the page can't come from data ([#248](https://github.com/forinda/clarusjs/issues/248)). It is a located build error, like
srcdoc: -srcon<iframe>,<frame>and<embed>; -dataandcodebaseon<object>; -hrefon<base>; -hrefon a<link>, unless its staticrelloads nothing (canonical,alternate,prev,next…); -sandbox,allowandreferrerpolicyon<iframe>. Write these as static attributes. Links and images from data are unchanged: they keep the URL check. #283
Patch Changes
- Editor hovers for
clarusjs/compiler(compile(),parse(),ClarusErrorand the syntax-tree types) and@clarusjs/content(markdown(), its options,slugify()): JSDoc with examples, linking new reference pages (https://clarusjs.com/reference/compiler, https://clarusjs.com/reference/content). Every public export of both packages is now documented. #295 - Editor hovers for
clarusjs/forms:form()and its types (Form,FormOptions,FormError,Path,StandardSchema) now have JSDoc with an example and links to the new forms reference (https://clarusjs.com/reference/forms). #295 - Editor hovers for
clarusjs/navigation,clarusjs/viewsandclarusjs/manifest: every function has an example, and every export links to its section in the new navigation reference (https://clarusjs.com/reference/navigation) or the server reference (render(),readManifest()and their types).TransitionandHeadTagare documented too. #295 - Editor hovers for the runtime:
state,derived,shared,effect,batch,untrack,scope,onDispose,browser,SignalandReadSignalnow have JSDoc, each with an example and a link to its section in the reference (https://clarusjs.com/reference/runtime). Helpers only compiled components call are marked@internal. #295 - Editor hovers for
clarusjs/viteandclarusjs/server: the plugin, its options,LinkLevel, the page-source types andredirect()now have JSDoc with examples and links to their reference sections. There's a new Server reference page (https://clarusjs.com/reference/server). Build and server internals are marked@internal. #295 - An
await(orfor await) at the top level of a component's<script>is now a compile error with its place. Before, it compiled into JavaScript that doesn't run, becauserender()andattach()are synchronous. Await inside a function instead, such as a resource's fetcher or an event handler. #289