Repository navigation
Releases
v0.2.0
Minor Changes
-
#190
ce5885dThanks @tristendillon! - Lists moved into a newarrays()plugin. It brings item keys that follow the items and the array commandspush,insert,removeandmove.Items,useItemsandcreateItemstake only array handles of forms that have it. A form with no lists no longer ships any of this, which saves about 550 B brotli. A form with a list pays about 150 B more than before.form.Itemsandscope.Itemsare gone. ImportItemsfrom the adapter and pass it the array's handle:// Before <form.Items name="tasks">{(task, index) => ...}</form.Items> // After import { Items } from "@lunarhue/forms-react"; // or "@lunarhue/forms-solid" <Items handle={form.root.at("tasks")}>{(task, index) => ...}</Items>
To migrate, add
arrays()to every form that renders or changes a list:import { arrays } from "@lunarhue/forms-react/plugins"; // or "@lunarhue/forms-solid/plugins" const forms = createForms({ plugins: [arrays()] });
You can also put it in a single definition's
plugins. Without it, passing an array handle toItems,useItemsorcreateItems, or calling a command, is a type error that says "Add arrays() to this form's plugins". Code without types that calls a command throwsarrays:missingin development, and the command does nothing in production.A component that takes an array field and renders or changes it says so in its type, as
ArrayHandle<string[], typeof arrays>. It then fits only forms witharrays(). A plugin whose setup calls the commands should listarraysinrequires.PluginContext.storeis now typed with the names of the plugin'srequires, so such a plugin gets the commands in its types.A form without
arrays()can still hold an array and replace it whole withsetValue. Its rows are then keyed by position (k0,k1, ...), so a row's state, such as touched, belongs to the position. IfsetValueshortens the list and a later write lengthens it again, the rows past the old end come back under their old keys with their old state. Witharrays()they stay gone and new rows get new keys, as before. -
#203
5638f90Thanks @tristendillon! -errorsByKind(handle), a new core function the adapters re-export, returns a field's validation errors grouped by the kind of validator that set them:{ schema, form, field }.schemaholds the definition's schema errors,formthe errors fromvalidate.form, andfieldthose fromvalidate.fieldsandregisterValidator, in the order they were added. A thrown validator's error goes under its validator's kind. Errors fromsetErrorsaren't included, since the snapshot'suserErrorshas them. It is a read, not a subscription, and a standalone function rather than a store method, so a form that never calls it doesn't ship it. The newErrorsByKind<E>andValidatorKindtypes name the result and its keys. -
#200
bcc99bbThanks @tristendillon! - Errors fromsetErrorsnow make a field invalid, and core can list every invalid field.invalidFields(store), a new core function, returns every field with an error, in form order, as{ field, name, errors }. The root comes first, with name"".subscribeInvalid(store, listener)fires when that list may change. Both are standalone functions rather than store methods, so a form that never lists its errors doesn't ship them.useInvalidFields(form)in React andcreateInvalidFields(form)in Solid follow the list, so an error summary is a few lines. The newInvalidField<E>type names an entry.The field snapshot has a new
userErrorsmember, the errorssetErrorsput there. They come last inerrors, so the validation errors areerrors.slice(0, errors.length - userErrors.length).Breaking changes:
snapshot.invalidis true for a field with onlysetErrorserrors. Before, it counted validation errors only. Code that readinvalidto mean "a validator failed" should checkerrors.length > userErrors.lengthinstead. The form'svalidhasn't changed, so server errors still don't block the next submit.store.firstInvalid()andstore.disabledInvalid()now include fields with onlysetErrorserrors. After a server refuses a save,firstInvalid()returns the field it named, so the app can focus it. The adapters still don't move focus afteronSubmitsets errors, because that submit succeeded.DisabledInvalid<E>is now an alias ofInvalidField<E>. Its shape is unchanged.
-
#230
23b8befThanks @tristendillon! - A definition's validators go through two functions:validate.fieldstakesfieldValidators({...})andvalidate.formtakesformValidator(check). Core and both adapters export them. A form that uses neither doesn't ship the code that walks a validator tree or reads anErrorMap.validate.onis gone: wrap a check invalidateOn(check, timing), or setvalidateoncreateFormsfor every form.// Before validate: { on: "input", fields: { username: checkName }, form: checkOrder, } // After validate: { fields: fieldValidators({ username: validateOn(checkName, "input") }), form: formValidator(validateOn(checkOrder, "input")), }
Written inline in
define, both take the form's value type, with a schema plugin'sDraftwhere there is one. Defined on their own, they need it as a type argument:fieldValidators<Order>({...}). A schema passed toformValidatoralone types the set by its input. -
#284
c8a59a2Thanks @tristendillon! -definein/minitakes a function of per-form options, as the main entry's does:forms.define((options: { q: string }) => ({ defaultValues: { q: options.q } })). The function runs once per store.createStore(options, instance?)anduseForm(definition, options, settings?)take the options first, and a plain config still takes none.useFormreads the options on the first render only. Mini'sdefinetype parameters are now<V, S, O, R>, soOsits where it does on the main entry. -
#262
2ee8b18Thanks @tristendillon! - New experimental entries,@lunarhue/forms-core/miniand@lunarhue/forms-react/mini, for small forms such as a search box or a login. A search form on/miniis about 2.6 kB brotli with React external, against about 11 kB on the main entry. Expect breaking changes in minor releases while it is experimental./minikeepscreateForms().define(),useForm,form.Form,form.Field,form.State,inputProps,fieldValidators, Standard Schema validation,setErrors,resetand thetransform,textandobserveparts, pinned at a field withforms.fieldset(...parts).at(name). Every member has the same name and call as in the main entry, and its types are a subset of the main entry's, so a form moves up by changing the import. Validators run sync, on blur and on submit, then on each change once the field was blurred, has an error, or the form was submitted.It leaves out async validation, plugins, arrays, object fields in
form.Field, dirty state, meta, native mode and devtools. Passing a plugin or a plugin's part to itsdefineis a type error.By default a
/miniform wakes every listener on each change, which is the least code.createForms({ subscribe: perField() })wakes only the fields that changed, for about 220 B more. The main entry takes the same option and ignores it, since it always wakes per field. -
#182
d6b2008Thanks @tristendillon! -dirtyandchanges()exist in the types only on forms withdirty(). Readingdirtyfrom a form or field snapshot, fromuseField,useFormState, aField,form.Stateor the Solid readers, or callingstore.changes(), is a type error without it, and so is givingequals. The snapshots still holddirty: falseat runtime. In developmentchanges()withoutdirty()now throwsdirty:missinginstead of loggingdirty:untracked, and in production it returns an empty list.Stores and snapshots take the installed plugin names as a new last type parameter. Handles and the adapters' field types take the plugins by factory, before the error type. A component that reads
dirtyfrom its field types it asFieldApi<string, typeof dirty>and then fits only forms withdirty().AnyFormStore<E, "dirty">is a store of any form that has it.One
Plugin<A, N, M, F, S>type replacesPlugin,HookPlugin,SchemaPlugin,DirtyPlugin,AnyPluginandAnyHookPlugin. UsePluginsfor a list of any plugins.defineSchemaPlugin(adapter)is gone. WritedefinePlugin({ name, schema: adapter }).A plugin with field or form meta must give
initialMetaor `initialFormMe...
v0.1.1
The first patch. It moves the Solid adapter to the stable Solid 2 release and fixes the bugs people hit first.
Install
npm install @lunarhue/forms-react # React 16.8 and later
npm install @lunarhue/forms-solid # Solid 2Changes
@lunarhue/forms-solid,@lunarhue/forms-bind: the adapter and the Solid binding now ask for the stable Solid 2 release. Thesolid-jsand@solidjs/webpeer ranges start at2.0.0, so the 2.0 release candidates no longer satisfy them. (#147)@lunarhue/forms-solid: an input shows the form's value after hydration even when the browser filled it back in first. Firefox restores typed text on a reload, and on Solid 2.0.0 the input kept that text while the form held something else. (#161)@lunarhue/forms-core:defineaccepts a value type that refers to itself, such as a tree node with achildrenarray of tree nodes. Before, TypeScript rejected these with TS2615. (#152)@lunarhue/forms-core: you can write a value you read from a field straight back.setValue,push,insertand the rebase plugin take the readonly values thatpeek()and field objects return, sotags.setValue(tags.peek().value)compiles without a spread or a cast. (#154)@lunarhue/forms-core: in a form without a schema,onSubmitgets a copy of the form value that it may change. Sorting or pushing to an array inonSubmitno longer throws in development. (#150)@lunarhue/forms-core: a plugin can write from the cleanup itsonActivereturns. Before, that write waited for the next write to the store, which might never come. (#148)@lunarhue/forms-bind: the zustand binding is built and tested against zustand 5.1. The peer range is still^5.0.0. (#113)
Docs
- The READMEs said Solid 1.8 works through
@lunarhue/forms-solid/v1. That entry only re-exports core for now, so they now say the adapter needs Solid 2. #124 tracks the Solid 1 adapter. (#149) docs/plugins.mdexplains the TS2353 errordefinegives inside a function that is generic over the schema type, and shows the helper that works. (#153)
Known issue
- On Solid in Safari, moving an array row takes focus off the row's input. (#157)
All five packages share one version. Each has its own CHANGELOG.md.
v0.1.0
The first release of forms: forms for React and Solid, with the form logic in one small core that knows nothing about either.
Install
npm install @lunarhue/forms-react # React 16.8 and later
npm install @lunarhue/forms-solid # Solid 2, and Solid 1 at ./v1The adapter brings the core and the plugins that need no other library. Add these when you want them:
npm install @lunarhue/forms-schema zod # or valibot
npm install @lunarhue/forms-bind # Zustand or a Solid signalPackages
All five share one version.
| Package | What it is |
|---|---|
@lunarhue/forms-react |
Type-safe forms for React, with features as plugins |
@lunarhue/forms-solid |
Type-safe forms for Solid, with features as plugins |
@lunarhue/forms-schema |
Zod and Valibot plugins |
@lunarhue/forms-bind |
Binds a form to a Zustand store or a Solid signal |
@lunarhue/forms-core |
The framework-free core: values, arrays, submit and plugins. The adapters depend on it, so you rarely install it yourself |
Changes
- First release. (#119)
@lunarhue/forms-core: a write that a plugin queues fromonSubmittedis now applied when the hook returns, with one notification. Before, it waited for the next write from anywhere else. (#118)
Each package has its own CHANGELOG.md.