@formisch/preact 0.7.4 → 0.8.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/dist/index.d.ts +4 -0
- package/dist/index.js +7 -3
- package/package.json +4 -5
package/dist/index.d.ts
CHANGED
|
@@ -853,6 +853,10 @@ interface FieldStore<TSchema extends Schema = Schema, TFieldPath extends Require
|
|
|
853
853
|
*/
|
|
854
854
|
readonly isValid: ReadonlySignal<boolean>;
|
|
855
855
|
/**
|
|
856
|
+
* Sets the field input value programmatically.
|
|
857
|
+
*/
|
|
858
|
+
readonly onInput: (value: PartialValues<PathValue<v.InferInput<TSchema>, TFieldPath>>) => void;
|
|
859
|
+
/**
|
|
856
860
|
* The props to spread onto the field element for integration.
|
|
857
861
|
*/
|
|
858
862
|
readonly props: FieldElementProps;
|
package/dist/index.js
CHANGED
|
@@ -31,7 +31,7 @@ function createId() {
|
|
|
31
31
|
function initializeFieldStore(internalFieldStore, schema, initialInput, path, nullish = false) {
|
|
32
32
|
if (framework === "qwik" && schema.type === "lazy" || schema.type === "object_with_rest" || schema.type === "record" || schema.type === "tuple_with_rest" || schema.type === "promise") throw new Error(`"${schema.type}" schema is not supported`);
|
|
33
33
|
else if (schema.type === "lazy") initializeFieldStore(internalFieldStore, schema.getter(void 0), initialInput, path);
|
|
34
|
-
else if (schema.type === "exact_optional" || schema.type === "nullable" || schema.type === "nullish" || schema.type === "optional" || schema.type === "undefinedable") initializeFieldStore(internalFieldStore, schema.wrapped, initialInput
|
|
34
|
+
else if (schema.type === "exact_optional" || schema.type === "nullable" || schema.type === "nullish" || schema.type === "optional" || schema.type === "undefinedable") initializeFieldStore(internalFieldStore, schema.wrapped, initialInput === void 0 ? v.getDefault(schema) : initialInput, path, true);
|
|
35
35
|
else if (schema.type === "non_nullable" || schema.type === "non_nullish" || schema.type === "non_optional") initializeFieldStore(internalFieldStore, schema.wrapped, initialInput, path);
|
|
36
36
|
else if (schema.type === "intersect" || schema.type === "union" || schema.type === "variant") for (const schemaOption of schema.options) initializeFieldStore(internalFieldStore, schemaOption, initialInput, path);
|
|
37
37
|
else {
|
|
@@ -55,7 +55,7 @@ function initializeFieldStore(internalFieldStore, schema, initialInput, path, nu
|
|
|
55
55
|
initializeFieldStore(internalFieldStore.children[index], schema.item, initialInput[index], path);
|
|
56
56
|
path.pop();
|
|
57
57
|
}
|
|
58
|
-
} else for (let index = 0; index < schema.items; index++) {
|
|
58
|
+
} else for (let index = 0; index < schema.items.length; index++) {
|
|
59
59
|
internalFieldStore.children[index] = {};
|
|
60
60
|
path.push(index);
|
|
61
61
|
initializeFieldStore(internalFieldStore.children[index], schema.items[index], initialInput?.[index], path);
|
|
@@ -368,7 +368,7 @@ function setNestedInput(internalFieldStore, input) {
|
|
|
368
368
|
}
|
|
369
369
|
for (let index = 0; index < arrayInput.length; index++) setNestedInput(internalFieldStore.children[index], arrayInput[index]);
|
|
370
370
|
internalFieldStore.input.value = input == null ? input : true;
|
|
371
|
-
internalFieldStore.isDirty.value = internalFieldStore.startInput.value !== internalFieldStore.input.value || internalFieldStore.startItems.value.length !== items.length;
|
|
371
|
+
internalFieldStore.isDirty.value = internalFieldStore.startInput.value !== internalFieldStore.input.value || internalFieldStore.startItems.value.length !== internalFieldStore.items.value.length;
|
|
372
372
|
} else if (internalFieldStore.kind === "object") {
|
|
373
373
|
for (const key in internalFieldStore.children) setNestedInput(internalFieldStore.children[key], input?.[key]);
|
|
374
374
|
internalFieldStore.input.value = input == null ? input : true;
|
|
@@ -825,6 +825,10 @@ function useField(form, config) {
|
|
|
825
825
|
isTouched: computed(() => getFieldBool(internalFieldStore.value, "isTouched")),
|
|
826
826
|
isDirty: computed(() => getFieldBool(internalFieldStore.value, "isDirty")),
|
|
827
827
|
isValid: computed(() => !getFieldBool(internalFieldStore.value, "errors")),
|
|
828
|
+
onInput(value) {
|
|
829
|
+
setFieldInput(internalFormStore, pathSignal.value, value);
|
|
830
|
+
validateIfRequired(internalFormStore, internalFieldStore.value, "input");
|
|
831
|
+
},
|
|
828
832
|
props: {
|
|
829
833
|
get name() {
|
|
830
834
|
return internalFieldStore.value.name;
|
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.
|
|
4
|
+
"version": "0.8.0",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Fabian Hiller",
|
|
7
7
|
"homepage": "https://formisch.dev",
|
|
@@ -33,7 +33,6 @@
|
|
|
33
33
|
"access": "public"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
|
-
"@eslint/js": "^9.31.0",
|
|
37
36
|
"@preact/preset-vite": "^2.9.3",
|
|
38
37
|
"@preact/signals": "^2.2.1",
|
|
39
38
|
"eslint": "^9.31.0",
|
|
@@ -41,11 +40,11 @@
|
|
|
41
40
|
"preact": "^10.25.3",
|
|
42
41
|
"tsdown": "^0.16.8",
|
|
43
42
|
"typescript": "^5.8.3",
|
|
44
|
-
"typescript-eslint": "^8.37.0",
|
|
45
43
|
"valibot": "^1.2.0",
|
|
46
44
|
"vite": "^6.0.4",
|
|
47
|
-
"@formisch/
|
|
48
|
-
"@formisch/
|
|
45
|
+
"@formisch/methods": "0.6.0",
|
|
46
|
+
"@formisch/eslint-config": "0.1.0",
|
|
47
|
+
"@formisch/core": "0.5.0"
|
|
49
48
|
},
|
|
50
49
|
"peerDependencies": {
|
|
51
50
|
"@preact/signals": "^2.0.0",
|