@gunubin/vorm-react 0.1.0 → 0.2.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 +2 -0
- package/dist/index.cjs +11 -11
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# @gunubin/vorm-react
|
|
2
2
|
|
|
3
|
+
[](https://www.npmjs.com/package/@gunubin/vorm-react)
|
|
4
|
+
|
|
3
5
|
React hooks for vorm — `useForm` and `useField` with per-field subscriptions via `useSyncExternalStore`.
|
|
4
6
|
|
|
5
7
|
Part of the [vorm](https://github.com/gunubin/vorm) monorepo.
|
package/dist/index.cjs
CHANGED
|
@@ -28,7 +28,7 @@ module.exports = __toCommonJS(index_exports);
|
|
|
28
28
|
|
|
29
29
|
// src/use-form.ts
|
|
30
30
|
var import_react = require("react");
|
|
31
|
-
var
|
|
31
|
+
var import_vorm_form = require("@gunubin/vorm-form");
|
|
32
32
|
|
|
33
33
|
// src/form-store.ts
|
|
34
34
|
function createFormStore(initialState) {
|
|
@@ -216,7 +216,7 @@ function useForm(schema, options) {
|
|
|
216
216
|
const fieldSchema = schema.fields[name];
|
|
217
217
|
if (fieldSchema) {
|
|
218
218
|
const formMessages = schema.messages?.[name];
|
|
219
|
-
const syncError = (0,
|
|
219
|
+
const syncError = (0, import_vorm_form.validateField)(value, fieldSchema, formMessages);
|
|
220
220
|
if (syncError) return;
|
|
221
221
|
}
|
|
222
222
|
const existingTimer = debounceTimersRef.current.get(name);
|
|
@@ -239,7 +239,7 @@ function useForm(schema, options) {
|
|
|
239
239
|
const fieldSchema = schema.fields[name];
|
|
240
240
|
if (!fieldSchema) return;
|
|
241
241
|
const formMessages = schema.messages?.[name];
|
|
242
|
-
const error = (0,
|
|
242
|
+
const error = (0, import_vorm_form.validateField)(value, fieldSchema, formMessages);
|
|
243
243
|
if (error) {
|
|
244
244
|
store.setFieldError(name, error);
|
|
245
245
|
} else {
|
|
@@ -273,7 +273,7 @@ function useForm(schema, options) {
|
|
|
273
273
|
const fieldSchema = schema.fields[name];
|
|
274
274
|
if (fieldSchema) {
|
|
275
275
|
const formMessages = schema.messages?.[name];
|
|
276
|
-
const syncError = (0,
|
|
276
|
+
const syncError = (0, import_vorm_form.validateField)(currentValue, fieldSchema, formMessages);
|
|
277
277
|
if (!syncError) {
|
|
278
278
|
scheduleAsyncValidation(name, currentValue, "blur");
|
|
279
279
|
}
|
|
@@ -301,7 +301,7 @@ function useForm(schema, options) {
|
|
|
301
301
|
const fieldSchema = schema.fields[name];
|
|
302
302
|
if (!fieldSchema) return true;
|
|
303
303
|
const formMessages = schema.messages?.[name];
|
|
304
|
-
const error = (0,
|
|
304
|
+
const error = (0, import_vorm_form.validateField)(
|
|
305
305
|
currentValues[name],
|
|
306
306
|
fieldSchema,
|
|
307
307
|
formMessages
|
|
@@ -313,7 +313,7 @@ function useForm(schema, options) {
|
|
|
313
313
|
}
|
|
314
314
|
return !error;
|
|
315
315
|
}
|
|
316
|
-
const formErrors = (0,
|
|
316
|
+
const formErrors = (0, import_vorm_form.validateForm)(currentValues, schema);
|
|
317
317
|
store.setErrors(formErrors);
|
|
318
318
|
return Object.keys(formErrors).length === 0;
|
|
319
319
|
},
|
|
@@ -326,7 +326,7 @@ function useForm(schema, options) {
|
|
|
326
326
|
const fieldSchema = schema.fields[name];
|
|
327
327
|
if (!fieldSchema) return true;
|
|
328
328
|
const formMessages = schema.messages?.[name];
|
|
329
|
-
const syncError = (0,
|
|
329
|
+
const syncError = (0, import_vorm_form.validateField)(
|
|
330
330
|
currentValues[name],
|
|
331
331
|
fieldSchema,
|
|
332
332
|
formMessages
|
|
@@ -340,7 +340,7 @@ function useForm(schema, options) {
|
|
|
340
340
|
const asyncError = await runAsyncValidation(name, currentValues[name]);
|
|
341
341
|
return !asyncError;
|
|
342
342
|
}
|
|
343
|
-
const formErrors = (0,
|
|
343
|
+
const formErrors = (0, import_vorm_form.validateForm)(currentValues, schema);
|
|
344
344
|
store.setErrors(formErrors);
|
|
345
345
|
if (Object.keys(formErrors).length > 0) return false;
|
|
346
346
|
const asyncEntries = Object.entries(asyncValidatorsRef.current ?? {});
|
|
@@ -360,7 +360,7 @@ function useForm(schema, options) {
|
|
|
360
360
|
return async (e) => {
|
|
361
361
|
e?.preventDefault?.();
|
|
362
362
|
const currentValues = store.getState().values;
|
|
363
|
-
const formErrors = (0,
|
|
363
|
+
const formErrors = (0, import_vorm_form.validateForm)(currentValues, schema);
|
|
364
364
|
store.setErrors(formErrors);
|
|
365
365
|
if (Object.keys(formErrors).length > 0) {
|
|
366
366
|
return;
|
|
@@ -373,7 +373,7 @@ function useForm(schema, options) {
|
|
|
373
373
|
const fieldSchema = schema.fields[fieldName];
|
|
374
374
|
if (fieldSchema) {
|
|
375
375
|
const formMessages = schema.messages?.[fieldName];
|
|
376
|
-
const syncError = (0,
|
|
376
|
+
const syncError = (0, import_vorm_form.validateField)(value, fieldSchema, formMessages);
|
|
377
377
|
if (syncError) return null;
|
|
378
378
|
}
|
|
379
379
|
return runAsyncValidation(fieldName, value);
|
|
@@ -384,7 +384,7 @@ function useForm(schema, options) {
|
|
|
384
384
|
}
|
|
385
385
|
store.setIsSubmitting(true);
|
|
386
386
|
try {
|
|
387
|
-
const outputValues = (0,
|
|
387
|
+
const outputValues = (0, import_vorm_form.buildOutputValues)(
|
|
388
388
|
currentValues,
|
|
389
389
|
schema.fields
|
|
390
390
|
);
|
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FieldError, FieldSchema, FormInputValues, FormErrors, FormOutputValues, FormSchema } from '@gunubin/vorm-
|
|
1
|
+
import { FieldError, FieldSchema, FormInputValues, FormErrors, FormOutputValues, FormSchema } from '@gunubin/vorm-form';
|
|
2
2
|
|
|
3
3
|
type FieldState<TValue> = {
|
|
4
4
|
value: TValue;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FieldError, FieldSchema, FormInputValues, FormErrors, FormOutputValues, FormSchema } from '@gunubin/vorm-
|
|
1
|
+
import { FieldError, FieldSchema, FormInputValues, FormErrors, FormOutputValues, FormSchema } from '@gunubin/vorm-form';
|
|
2
2
|
|
|
3
3
|
type FieldState<TValue> = {
|
|
4
4
|
value: TValue;
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// src/use-form.ts
|
|
2
2
|
import { useRef, useCallback, useEffect, useSyncExternalStore } from "react";
|
|
3
|
-
import { validateField, validateForm, buildOutputValues } from "@gunubin/vorm-
|
|
3
|
+
import { validateField, validateForm, buildOutputValues } from "@gunubin/vorm-form";
|
|
4
4
|
|
|
5
5
|
// src/form-store.ts
|
|
6
6
|
function createFormStore(initialState) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gunubin/vorm-react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "VO-first React form hooks with per-field subscriptions via useSyncExternalStore",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"form",
|
|
@@ -43,7 +43,8 @@
|
|
|
43
43
|
"react": "^18.0.0 || ^19.0.0"
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@gunubin/vorm-
|
|
46
|
+
"@gunubin/vorm-form": "0.1.0",
|
|
47
|
+
"@gunubin/vorm-core": "0.2.0"
|
|
47
48
|
},
|
|
48
49
|
"devDependencies": {
|
|
49
50
|
"@testing-library/react": "^16.3.0",
|