@formisch/preact 0.3.0 → 0.3.1
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 +2 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +18 -16
- package/package.json +12 -12
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
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].
|
|
5
|
+
Formisch is also available for [Qwik][formisch-qwik], [SolidJS][formisch-solid], [Svelte][formisch-svelte] and [Vue][formisch-vue].
|
|
6
6
|
|
|
7
7
|
## Highlights
|
|
8
8
|
|
|
@@ -77,4 +77,5 @@ This project is available free of charge and licensed under the [MIT license](ht
|
|
|
77
77
|
|
|
78
78
|
[formisch-qwik]: https://github.com/fabian-hiller/formisch/tree/main/frameworks/qwik
|
|
79
79
|
[formisch-solid]: https://github.com/fabian-hiller/formisch/tree/main/frameworks/solid
|
|
80
|
+
[formisch-svelte]: https://github.com/fabian-hiller/formisch/tree/main/frameworks/svelte
|
|
80
81
|
[formisch-vue]: https://github.com/fabian-hiller/formisch/tree/main/frameworks/vue
|
package/dist/index.d.ts
CHANGED
|
@@ -372,7 +372,7 @@ declare function FieldArray<TSchema extends Schema, TFieldArrayPath extends Requ
|
|
|
372
372
|
}: FieldArrayProps<TSchema, TFieldArrayPath>): JSX.Element;
|
|
373
373
|
//#endregion
|
|
374
374
|
//#region src/components/Form/Form.d.ts
|
|
375
|
-
type FormProps<TSchema extends Schema = Schema> = Omit<JSX.FormHTMLAttributes<HTMLFormElement>, "onSubmit"> & {
|
|
375
|
+
type FormProps<TSchema extends Schema = Schema> = Omit<JSX.FormHTMLAttributes<HTMLFormElement>, "onSubmit" | "novalidate" | "noValidate"> & {
|
|
376
376
|
of: FormStore<TSchema>;
|
|
377
377
|
onSubmit: SubmitHandler<TSchema>;
|
|
378
378
|
};
|
package/dist/index.js
CHANGED
|
@@ -37,7 +37,7 @@ function initializeFieldStore(internalFieldStore, schema, initialInput, path) {
|
|
|
37
37
|
} else for (let index = 0; index < schema.items; index++) {
|
|
38
38
|
internalFieldStore.children[index] = {};
|
|
39
39
|
path.push(index);
|
|
40
|
-
initializeFieldStore(internalFieldStore.children[index], schema.items[index], initialInput
|
|
40
|
+
initializeFieldStore(internalFieldStore.children[index], schema.items[index], initialInput?.[index], path);
|
|
41
41
|
path.pop();
|
|
42
42
|
}
|
|
43
43
|
const initialItems = internalFieldStore.children.map(createId);
|
|
@@ -55,7 +55,7 @@ function initializeFieldStore(internalFieldStore, schema, initialInput, path) {
|
|
|
55
55
|
for (const key in schema.entries) {
|
|
56
56
|
internalFieldStore.children[key] = {};
|
|
57
57
|
path.push(key);
|
|
58
|
-
initializeFieldStore(internalFieldStore.children[key], schema.entries[key], initialInput
|
|
58
|
+
initializeFieldStore(internalFieldStore.children[key], schema.entries[key], initialInput?.[key], path);
|
|
59
59
|
path.pop();
|
|
60
60
|
}
|
|
61
61
|
}
|
|
@@ -275,23 +275,24 @@ function setFieldBool(internalFieldStore, type, bool) {
|
|
|
275
275
|
function setFieldInput(internalFieldStore, input) {
|
|
276
276
|
batch(() => {
|
|
277
277
|
if (internalFieldStore.kind === "array") {
|
|
278
|
+
const arrayInput = input ?? [];
|
|
278
279
|
const items = untrack(() => internalFieldStore.items.value);
|
|
279
|
-
if (
|
|
280
|
-
else if (
|
|
281
|
-
if (
|
|
280
|
+
if (arrayInput.length < items.length) internalFieldStore.items.value = items.slice(0, arrayInput.length);
|
|
281
|
+
else if (arrayInput.length > items.length) {
|
|
282
|
+
if (arrayInput.length > internalFieldStore.children.length) {
|
|
282
283
|
const path = JSON.parse(internalFieldStore.name);
|
|
283
|
-
for (let index = internalFieldStore.children.length; index <
|
|
284
|
+
for (let index = internalFieldStore.children.length; index < arrayInput.length; index++) {
|
|
284
285
|
internalFieldStore.children[index] = {};
|
|
285
286
|
path.push(index);
|
|
286
|
-
initializeFieldStore(internalFieldStore.children[index], internalFieldStore.schema.item,
|
|
287
|
+
initializeFieldStore(internalFieldStore.children[index], internalFieldStore.schema.item, arrayInput[index], path);
|
|
287
288
|
path.pop();
|
|
288
289
|
}
|
|
289
290
|
}
|
|
290
|
-
internalFieldStore.items.value = [...items, ...
|
|
291
|
+
internalFieldStore.items.value = [...items, ...arrayInput.slice(items.length).map(createId)];
|
|
291
292
|
}
|
|
292
|
-
for (let index = 0; index < items.length; index++) setFieldInput(internalFieldStore.children[index],
|
|
293
|
+
for (let index = 0; index < items.length; index++) setFieldInput(internalFieldStore.children[index], arrayInput[index]);
|
|
293
294
|
internalFieldStore.isDirty.value = untrack(() => internalFieldStore.startItems.value).length !== items.length;
|
|
294
|
-
} else if (internalFieldStore.kind === "object") for (const key in internalFieldStore.children) setFieldInput(internalFieldStore.children[key], input[key]);
|
|
295
|
+
} else if (internalFieldStore.kind === "object") for (const key in internalFieldStore.children) setFieldInput(internalFieldStore.children[key], input?.[key]);
|
|
295
296
|
else {
|
|
296
297
|
internalFieldStore.input.value = input;
|
|
297
298
|
internalFieldStore.isTouched.value = true;
|
|
@@ -303,17 +304,18 @@ function setFieldInput(internalFieldStore, input) {
|
|
|
303
304
|
function setInitialFieldInput(internalFieldStore, initialInput) {
|
|
304
305
|
batch(() => {
|
|
305
306
|
if (internalFieldStore.kind === "array") {
|
|
306
|
-
|
|
307
|
+
const initialArrayInput = initialInput ?? [];
|
|
308
|
+
if (initialArrayInput.length > internalFieldStore.children.length) {
|
|
307
309
|
const path = JSON.parse(internalFieldStore.name);
|
|
308
|
-
for (let index = internalFieldStore.children.length; index <
|
|
310
|
+
for (let index = internalFieldStore.children.length; index < initialArrayInput.length; index++) {
|
|
309
311
|
internalFieldStore.children[index] = {};
|
|
310
312
|
path.push(index);
|
|
311
|
-
initializeFieldStore(internalFieldStore.children[index], internalFieldStore.schema.item,
|
|
313
|
+
initializeFieldStore(internalFieldStore.children[index], internalFieldStore.schema.item, initialArrayInput[index], path);
|
|
312
314
|
path.pop();
|
|
313
315
|
}
|
|
314
316
|
}
|
|
315
|
-
internalFieldStore.initialItems.value =
|
|
316
|
-
for (let index = 0; index < internalFieldStore.children.length; index++) setInitialFieldInput(internalFieldStore.children[index],
|
|
317
|
+
internalFieldStore.initialItems.value = initialArrayInput.map(createId);
|
|
318
|
+
for (let index = 0; index < internalFieldStore.children.length; index++) setInitialFieldInput(internalFieldStore.children[index], initialArrayInput[index]);
|
|
317
319
|
} else if (internalFieldStore.kind === "object") for (const key in internalFieldStore.children) setInitialFieldInput(internalFieldStore.children[key], initialInput?.[key]);
|
|
318
320
|
else internalFieldStore.initialInput.value = initialInput;
|
|
319
321
|
});
|
|
@@ -622,7 +624,7 @@ function useFieldArray(form, config) {
|
|
|
622
624
|
//#region src/hooks/useForm/useForm.ts
|
|
623
625
|
function useForm(config) {
|
|
624
626
|
const form = useMemo(() => {
|
|
625
|
-
const internalFormStore = createFormStore(config,
|
|
627
|
+
const internalFormStore = createFormStore(config, (input) => v.safeParseAsync(config.schema, input));
|
|
626
628
|
return {
|
|
627
629
|
[INTERNAL]: internalFormStore,
|
|
628
630
|
isSubmitting: internalFormStore.isSubmitting,
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@formisch/preact",
|
|
3
3
|
"description": "The modular and type-safe form library for Preact",
|
|
4
|
-
"version": "0.3.
|
|
4
|
+
"version": "0.3.1",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Fabian Hiller",
|
|
7
7
|
"homepage": "https://formisch.dev",
|
|
@@ -32,17 +32,8 @@
|
|
|
32
32
|
"publishConfig": {
|
|
33
33
|
"access": "public"
|
|
34
34
|
},
|
|
35
|
-
"scripts": {
|
|
36
|
-
"build": "tsdown",
|
|
37
|
-
"lint": "eslint \"src/**/*.ts*\" && tsc --noEmit",
|
|
38
|
-
"lint.fix": "eslint \"src/**/*.ts*\" --fix",
|
|
39
|
-
"format": "prettier --write ./src",
|
|
40
|
-
"format.check": "prettier --check ./src"
|
|
41
|
-
},
|
|
42
35
|
"devDependencies": {
|
|
43
36
|
"@eslint/js": "^9.31.0",
|
|
44
|
-
"@formisch/core": "workspace:*",
|
|
45
|
-
"@formisch/methods": "workspace:*",
|
|
46
37
|
"@preact/preset-vite": "^2.9.3",
|
|
47
38
|
"@preact/signals": "^2.2.1",
|
|
48
39
|
"eslint": "^9.31.0",
|
|
@@ -51,7 +42,9 @@
|
|
|
51
42
|
"tsdown": "^0.12.9",
|
|
52
43
|
"typescript": "^5.8.3",
|
|
53
44
|
"typescript-eslint": "^8.37.0",
|
|
54
|
-
"vite": "^6.0.4"
|
|
45
|
+
"vite": "^6.0.4",
|
|
46
|
+
"@formisch/core": "0.3.1",
|
|
47
|
+
"@formisch/methods": "0.2.0"
|
|
55
48
|
},
|
|
56
49
|
"peerDependencies": {
|
|
57
50
|
"@preact/signals": "^2.0.0",
|
|
@@ -63,5 +56,12 @@
|
|
|
63
56
|
"typescript": {
|
|
64
57
|
"optional": true
|
|
65
58
|
}
|
|
59
|
+
},
|
|
60
|
+
"scripts": {
|
|
61
|
+
"build": "tsdown",
|
|
62
|
+
"lint": "eslint \"src/**/*.ts*\" && tsc --noEmit",
|
|
63
|
+
"lint.fix": "eslint \"src/**/*.ts*\" --fix",
|
|
64
|
+
"format": "prettier --write ./src",
|
|
65
|
+
"format.check": "prettier --check ./src"
|
|
66
66
|
}
|
|
67
|
-
}
|
|
67
|
+
}
|