@formisch/preact 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -0
- package/dist/index.d.ts +7 -7
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
Formisch is a schema-based, headless form library for Preact. It manages form state and validation. It is type-safe, fast by default and its bundle size is small due to its modular design. Try it out in our [playground](https://stackblitz.com/edit/formisch-playground-preact)!
|
|
4
4
|
|
|
5
|
+
Formisch is also available for [Qwik][formisch-qwik], [SolidJS][formisch-solid], and [Vue][formisch-vue]. Svelte will follow soon.
|
|
6
|
+
|
|
5
7
|
## Highlights
|
|
6
8
|
|
|
7
9
|
- Small bundle size starting at 2.5 kB
|
|
@@ -55,6 +57,16 @@ export default function LoginPage() {
|
|
|
55
57
|
|
|
56
58
|
In addition, Formisch offers several functions (we call them "methods") that can be used to read and manipulate the form state. These include `focus`, `getErrors`, `getAllErrors`, `getInput`, `insert`, `move`, `remove`, `replace`, `reset`, `setErrors`, `setInput`, `submit`, `swap` and `validate`. These methods allow you to control the form programmatically.
|
|
57
59
|
|
|
60
|
+
## Comparison
|
|
61
|
+
|
|
62
|
+
What makes Formisch unique is its framework-agnostic core, which is fully native to the framework you are using. It works by inserting framework-specific reactivity blocks when the core package is built. The result is a small bundle size and native performance for any UI update. This feature, along with a few others, distinguishes Formisch from other form libraries. My vision for Formisch is to create a framework-agnostic platform similar to [Vite](https://vite.dev/), but for forms.
|
|
63
|
+
|
|
64
|
+
## Partners
|
|
65
|
+
|
|
66
|
+
Thanks to our partners who support the development! [Join them](https://github.com/sponsors/fabian-hiller) and contribute to the sustainability of open source software!
|
|
67
|
+
|
|
68
|
+

|
|
69
|
+
|
|
58
70
|
## Feedback
|
|
59
71
|
|
|
60
72
|
Find a bug or have an idea how to improve the library? Please fill out an [issue](https://github.com/fabian-hiller/formisch/issues/new). Together we can make forms even better!
|
|
@@ -62,3 +74,7 @@ Find a bug or have an idea how to improve the library? Please fill out an [issue
|
|
|
62
74
|
## License
|
|
63
75
|
|
|
64
76
|
This project is available free of charge and licensed under the [MIT license](https://github.com/fabian-hiller/formisch/blob/main/LICENSE.md).
|
|
77
|
+
|
|
78
|
+
[formisch-qwik]: https://github.com/fabian-hiller/formisch/tree/main/frameworks/qwik
|
|
79
|
+
[formisch-solid]: https://github.com/fabian-hiller/formisch/tree/main/frameworks/solid
|
|
80
|
+
[formisch-vue]: https://github.com/fabian-hiller/formisch/tree/main/frameworks/vue
|
package/dist/index.d.ts
CHANGED
|
@@ -93,7 +93,7 @@ interface InternalFormStore<TSchema extends Schema = Schema> extends InternalObj
|
|
|
93
93
|
interface BaseFormStore<TSchema extends Schema = Schema> {
|
|
94
94
|
[INTERNAL]: InternalFormStore<TSchema>;
|
|
95
95
|
}
|
|
96
|
-
type SubmitHandler<TSchema extends Schema> = (output: v.InferOutput<TSchema>, event: SubmitEvent) => MaybePromise<
|
|
96
|
+
type SubmitHandler<TSchema extends Schema> = (output: v.InferOutput<TSchema>, event: SubmitEvent) => MaybePromise<unknown>;
|
|
97
97
|
//#endregion
|
|
98
98
|
//#region src/types/path.d.ts
|
|
99
99
|
/**
|
|
@@ -123,16 +123,16 @@ type MergeUnion<T> = { [K in KeyOf<T>]: T extends Record<K, infer V> ? V : never
|
|
|
123
123
|
/**
|
|
124
124
|
* Lazily evaluate only the first valid path segment based on the given value.
|
|
125
125
|
*/
|
|
126
|
-
type LazyPath<TValue, TPathToCheck extends Path, TValidPath extends Path = readonly []> = TPathToCheck extends readonly [] ? TValidPath : TPathToCheck extends readonly [infer TFirstKey extends KeyOf<TValue>, ...infer TPathRest extends Path] ? LazyPath<MergeUnion<TValue>[TFirstKey]
|
|
126
|
+
type LazyPath<TValue, TPathToCheck extends Path, TValidPath extends Path = readonly []> = TPathToCheck extends readonly [] ? TValidPath : TPathToCheck extends readonly [infer TFirstKey extends KeyOf<TValue>, ...infer TPathRest extends Path] ? LazyPath<Required<MergeUnion<TValue>[TFirstKey]>, TPathRest, readonly [...TValidPath, TFirstKey]> : IsNever<KeyOf<TValue>> extends false ? readonly [...TValidPath, KeyOf<TValue>] : TValidPath;
|
|
127
127
|
/**
|
|
128
128
|
* Returns the path if valid, otherwise the first possible valid path based on
|
|
129
129
|
* the given value.
|
|
130
130
|
*/
|
|
131
|
-
type ValidPath<TValue, TPath extends RequiredPath> = TPath extends LazyPath<TValue
|
|
131
|
+
type ValidPath<TValue, TPath extends RequiredPath> = TPath extends LazyPath<Required<TValue>, TPath> ? TPath : LazyPath<Required<TValue>, TPath>;
|
|
132
132
|
/**
|
|
133
133
|
* Extracts the value type at the given path.
|
|
134
134
|
*/
|
|
135
|
-
type PathValue<TValue, TPath extends Path> = TPath extends readonly [infer TKey, ...infer TRest extends Path] ? TKey extends KeyOf<TValue
|
|
135
|
+
type PathValue<TValue, TPath extends Path> = TPath extends readonly [infer TKey, ...infer TRest extends Path] ? TKey extends KeyOf<Required<TValue>> ? PathValue<MergeUnion<Required<TValue>>[TKey], TRest> : unknown : TValue;
|
|
136
136
|
/**
|
|
137
137
|
* Checks if a value is an array or contains one.
|
|
138
138
|
*/
|
|
@@ -140,16 +140,16 @@ type IsOrHasArray<TValue> = IsAny<TValue> extends true ? false : TValue extends
|
|
|
140
140
|
/**
|
|
141
141
|
* Extracts the exact keys of a tuple, array or object that contain arrays.
|
|
142
142
|
*/
|
|
143
|
-
type KeyOfArrayPath<TValue> = IsAny<TValue> extends true ? never : TValue extends readonly (infer TItem)[] ? number extends TValue["length"] ? IsOrHasArray<TItem> extends true ? number : never : { [TKey in keyof TValue]: TKey extends `${infer TIndex extends number}` ? IsOrHasArray<TValue[TKey]
|
|
143
|
+
type KeyOfArrayPath<TValue> = IsAny<TValue> extends true ? never : TValue extends readonly (infer TItem)[] ? number extends TValue["length"] ? IsOrHasArray<TItem> extends true ? number : never : { [TKey in keyof TValue]: TKey extends `${infer TIndex extends number}` ? IsOrHasArray<NonNullable<TValue[TKey]>> extends true ? TIndex : never : never }[number] : TValue extends Record<string, unknown> ? { [TKey in keyof TValue]: IsOrHasArray<NonNullable<TValue[TKey]>> extends true ? TKey : never }[keyof TValue] & PathKey : never;
|
|
144
144
|
/**
|
|
145
145
|
* Lazily evaluate only the first valid array path segment based on the given value.
|
|
146
146
|
*/
|
|
147
|
-
type LazyArrayPath<TValue, TPathToCheck extends Path, TValidPath extends Path = readonly []> = TPathToCheck extends readonly [] ? TValue extends readonly unknown[] ? TValidPath : readonly [...TValidPath, KeyOfArrayPath<TValue>] : TPathToCheck extends readonly [infer TFirstKey extends KeyOfArrayPath<TValue>, ...infer TPathRest extends Path] ? LazyArrayPath<MergeUnion<TValue>[TFirstKey]
|
|
147
|
+
type LazyArrayPath<TValue, TPathToCheck extends Path, TValidPath extends Path = readonly []> = TPathToCheck extends readonly [] ? TValue extends readonly unknown[] ? TValidPath : readonly [...TValidPath, KeyOfArrayPath<TValue>] : TPathToCheck extends readonly [infer TFirstKey extends KeyOfArrayPath<TValue>, ...infer TPathRest extends Path] ? LazyArrayPath<Required<MergeUnion<TValue>[TFirstKey]>, TPathRest, readonly [...TValidPath, TFirstKey]> : IsNever<KeyOfArrayPath<TValue>> extends false ? readonly [...TValidPath, KeyOfArrayPath<TValue>] : never;
|
|
148
148
|
/**
|
|
149
149
|
* Returns the path if valid, otherwise the first possible valid array path based on
|
|
150
150
|
* the given value.
|
|
151
151
|
*/
|
|
152
|
-
type ValidArrayPath<TValue, TPath extends RequiredPath> = TPath extends LazyArrayPath<TValue
|
|
152
|
+
type ValidArrayPath<TValue, TPath extends RequiredPath> = TPath extends LazyArrayPath<Required<TValue>, TPath> ? TPath : LazyArrayPath<Required<TValue>, TPath>;
|
|
153
153
|
//#endregion
|
|
154
154
|
//#region src/array/copyItemState/copyItemState.d.ts
|
|
155
155
|
/**
|
package/dist/index.js
CHANGED
|
@@ -294,6 +294,7 @@ function setFieldInput(internalFieldStore, input) {
|
|
|
294
294
|
} else if (internalFieldStore.kind === "object") for (const key in internalFieldStore.children) setFieldInput(internalFieldStore.children[key], input[key]);
|
|
295
295
|
else {
|
|
296
296
|
internalFieldStore.input.value = input;
|
|
297
|
+
internalFieldStore.isTouched.value = true;
|
|
297
298
|
const startInput = untrack(() => internalFieldStore.startInput.value);
|
|
298
299
|
internalFieldStore.isDirty.value = startInput !== input && (startInput !== void 0 || input !== "" && !Number.isNaN(input));
|
|
299
300
|
}
|
|
@@ -519,7 +520,6 @@ function setInput(form, config) {
|
|
|
519
520
|
batch(() => {
|
|
520
521
|
const internalFormStore = form[INTERNAL];
|
|
521
522
|
const internalFieldStore = config.path ? getFieldStore(internalFormStore, config.path) : internalFormStore;
|
|
522
|
-
setFieldBool(internalFieldStore, "isTouched", true);
|
|
523
523
|
setFieldInput(internalFieldStore, config.input);
|
|
524
524
|
validateIfRequired(internalFormStore, internalFieldStore, "input");
|
|
525
525
|
});
|