@juantroconisf/lib 11.3.0 → 11.5.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 +18 -8
- package/dist/index.d.mts +14 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.js +86 -12
- package/dist/index.mjs +86 -12
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -131,6 +131,16 @@ Arrays of objects are tracked by item `id` (configurable via `arrayIdentifiers`)
|
|
|
131
131
|
</Button>;
|
|
132
132
|
```
|
|
133
133
|
|
|
134
|
+
### Deeply Nested Arrays (N-Level Depth)
|
|
135
|
+
|
|
136
|
+
If your schema contains arrays inside objects inside arrays (infinite depth), you can pass a variadic sequence of arguments alternating between structural paths and array IDs (or indexes).
|
|
137
|
+
|
|
138
|
+
```tsx
|
|
139
|
+
// Schema: items[].form_response.input_values[].value
|
|
140
|
+
<Input {...on.input("items", itemId, "form_response.input_values", inputId, "value")} label="Deep Value" />
|
|
141
|
+
```
|
|
142
|
+
The library dynamically traverses your state, mapping IDs securely to their array indices natively, regardless of depth.
|
|
143
|
+
|
|
134
144
|
---
|
|
135
145
|
|
|
136
146
|
## The `on` API — Component Bindings
|
|
@@ -142,17 +152,17 @@ Each `on.*` method returns a set of props that you spread directly onto a HeroUI
|
|
|
142
152
|
- **Error display** — `isInvalid` and `errorMessage` from the schema
|
|
143
153
|
- **Required indicator** — `isRequired` derived from `.required()` in your schema
|
|
144
154
|
|
|
145
|
-
All methods support
|
|
155
|
+
All methods support **scalar/nested** paths, standard **array item** paths (composite `"array.field"` + `itemId`), and **variadic sequences** for N-level deep structures.
|
|
146
156
|
|
|
147
157
|
| Method | HeroUI Component | Key props returned |
|
|
148
158
|
| --------------------------------- | ------------------- | ----------------------------------------------- |
|
|
149
|
-
| `on.input(
|
|
150
|
-
| `on.numberInput(
|
|
151
|
-
| `on.select(
|
|
152
|
-
| `on.autocomplete(
|
|
153
|
-
| `on.checkbox(
|
|
154
|
-
| `on.switch(
|
|
155
|
-
| `on.radio(
|
|
159
|
+
| `on.input(...args)` | `Input`, `Textarea` | `value: string`, `onValueChange(string)` |
|
|
160
|
+
| `on.numberInput(...args)` | `NumberInput` | `value: number`, `onValueChange(number)` |
|
|
161
|
+
| `on.select(...args)` | `Select` | `selectedKeys`, `onSelectionChange` |
|
|
162
|
+
| `on.autocomplete(...args)` | `Autocomplete` | `selectedKey`, `onSelectionChange` |
|
|
163
|
+
| `on.checkbox(...args)` | `Checkbox` | `isSelected: boolean`, `onValueChange(boolean)` |
|
|
164
|
+
| `on.switch(...args)` | `Switch` | `isSelected: boolean`, `onValueChange(boolean)` |
|
|
165
|
+
| `on.radio(...args)` | `RadioGroup` | `value: string`, `onValueChange(string)` |
|
|
156
166
|
|
|
157
167
|
> **Why separate methods?** Each HeroUI component has a different prop contract (e.g. `isSelected` vs `value`, `onSelectionChange` vs `onValueChange`). Separate methods give accurate intellisense for each component.
|
|
158
168
|
|
package/dist/index.d.mts
CHANGED
|
@@ -133,10 +133,14 @@ interface OnMethods<O extends StateType> {
|
|
|
133
133
|
input<P extends ObjectArrayFieldPaths<O>>(compositePath: P, itemId: string | number): ItemInputProps<any>;
|
|
134
134
|
/** Registers a primitive array element by index. */
|
|
135
135
|
input<K extends ArrayPaths<O>>(arrayKey: K, index: number): ItemInputProps<any>;
|
|
136
|
+
/** Registers a deeply nested field using variadic path segments. */
|
|
137
|
+
input(...args: any[]): ItemInputProps<any>;
|
|
136
138
|
/** Registers a numeric field for NumberInput. */
|
|
137
139
|
numberInput<P extends AllPaths<O>>(id: P): ItemNumberInputProps;
|
|
138
140
|
/** Registers a numeric field within an object array element. */
|
|
139
141
|
numberInput<P extends ObjectArrayFieldPaths<O>>(compositePath: P, itemId: string | number): ItemNumberInputProps;
|
|
142
|
+
/** Registers a deeply nested numeric field using variadic path segments. */
|
|
143
|
+
numberInput(...args: any[]): ItemNumberInputProps;
|
|
140
144
|
/** Registers a scalar or nested object field. */
|
|
141
145
|
select<P extends AllPaths<O>>(id: P): ItemSelectProps;
|
|
142
146
|
/** Registers a complete array field for multi-selection. */
|
|
@@ -145,24 +149,34 @@ interface OnMethods<O extends StateType> {
|
|
|
145
149
|
select<P extends ObjectArrayFieldPaths<O>>(compositePath: P, itemId: string | number): ItemSelectProps;
|
|
146
150
|
/** Registers a primitive array element by index. */
|
|
147
151
|
select<K extends ArrayPaths<O>>(arrayKey: K, index: number): ItemSelectProps;
|
|
152
|
+
/** Registers a deeply nested field using variadic path segments. */
|
|
153
|
+
select(...args: any[]): ItemSelectProps;
|
|
148
154
|
/** Registers a scalar or nested object field. */
|
|
149
155
|
autocomplete<P extends AllPaths<O>>(id: P): ItemAutocompleteProps;
|
|
150
156
|
/** Registers an object array element's field using composite syntax "array.field". */
|
|
151
157
|
autocomplete<P extends ObjectArrayFieldPaths<O>>(compositePath: P, itemId: string | number): ItemAutocompleteProps;
|
|
152
158
|
/** Registers a primitive array element by index. */
|
|
153
159
|
autocomplete<K extends ArrayPaths<O>>(arrayKey: K, index: number): ItemAutocompleteProps;
|
|
160
|
+
/** Registers a deeply nested field using variadic path segments. */
|
|
161
|
+
autocomplete(...args: any[]): ItemAutocompleteProps;
|
|
154
162
|
/** Registers a boolean field for Checkbox. */
|
|
155
163
|
checkbox<P extends AllPaths<O>>(id: P): ItemToggleProps;
|
|
156
164
|
/** Registers a boolean field within an object array element for Checkbox. */
|
|
157
165
|
checkbox<P extends ObjectArrayFieldPaths<O>>(compositePath: P, itemId: string | number): ItemToggleProps;
|
|
166
|
+
/** Registers a deeply nested boolean field using variadic path segments. */
|
|
167
|
+
checkbox(...args: any[]): ItemToggleProps;
|
|
158
168
|
/** Registers a boolean field for Switch. */
|
|
159
169
|
switch<P extends AllPaths<O>>(id: P): ItemToggleProps;
|
|
160
170
|
/** Registers a boolean field within an object array element for Switch. */
|
|
161
171
|
switch<P extends ObjectArrayFieldPaths<O>>(compositePath: P, itemId: string | number): ItemToggleProps;
|
|
172
|
+
/** Registers a deeply nested boolean field using variadic path segments. */
|
|
173
|
+
switch(...args: any[]): ItemToggleProps;
|
|
162
174
|
/** Registers a string field for RadioGroup. */
|
|
163
175
|
radio<P extends AllPaths<O>>(id: P): ItemRadioGroupProps;
|
|
164
176
|
/** Registers a string field within an object array element for RadioGroup. */
|
|
165
177
|
radio<P extends ObjectArrayFieldPaths<O>>(compositePath: P, itemId: string | number): ItemRadioGroupProps;
|
|
178
|
+
/** Registers a deeply nested string field using variadic path segments. */
|
|
179
|
+
radio(...args: any[]): ItemRadioGroupProps;
|
|
166
180
|
}
|
|
167
181
|
/**
|
|
168
182
|
* Recursive type to find all paths to arrays in the state.
|
package/dist/index.d.ts
CHANGED
|
@@ -133,10 +133,14 @@ interface OnMethods<O extends StateType> {
|
|
|
133
133
|
input<P extends ObjectArrayFieldPaths<O>>(compositePath: P, itemId: string | number): ItemInputProps<any>;
|
|
134
134
|
/** Registers a primitive array element by index. */
|
|
135
135
|
input<K extends ArrayPaths<O>>(arrayKey: K, index: number): ItemInputProps<any>;
|
|
136
|
+
/** Registers a deeply nested field using variadic path segments. */
|
|
137
|
+
input(...args: any[]): ItemInputProps<any>;
|
|
136
138
|
/** Registers a numeric field for NumberInput. */
|
|
137
139
|
numberInput<P extends AllPaths<O>>(id: P): ItemNumberInputProps;
|
|
138
140
|
/** Registers a numeric field within an object array element. */
|
|
139
141
|
numberInput<P extends ObjectArrayFieldPaths<O>>(compositePath: P, itemId: string | number): ItemNumberInputProps;
|
|
142
|
+
/** Registers a deeply nested numeric field using variadic path segments. */
|
|
143
|
+
numberInput(...args: any[]): ItemNumberInputProps;
|
|
140
144
|
/** Registers a scalar or nested object field. */
|
|
141
145
|
select<P extends AllPaths<O>>(id: P): ItemSelectProps;
|
|
142
146
|
/** Registers a complete array field for multi-selection. */
|
|
@@ -145,24 +149,34 @@ interface OnMethods<O extends StateType> {
|
|
|
145
149
|
select<P extends ObjectArrayFieldPaths<O>>(compositePath: P, itemId: string | number): ItemSelectProps;
|
|
146
150
|
/** Registers a primitive array element by index. */
|
|
147
151
|
select<K extends ArrayPaths<O>>(arrayKey: K, index: number): ItemSelectProps;
|
|
152
|
+
/** Registers a deeply nested field using variadic path segments. */
|
|
153
|
+
select(...args: any[]): ItemSelectProps;
|
|
148
154
|
/** Registers a scalar or nested object field. */
|
|
149
155
|
autocomplete<P extends AllPaths<O>>(id: P): ItemAutocompleteProps;
|
|
150
156
|
/** Registers an object array element's field using composite syntax "array.field". */
|
|
151
157
|
autocomplete<P extends ObjectArrayFieldPaths<O>>(compositePath: P, itemId: string | number): ItemAutocompleteProps;
|
|
152
158
|
/** Registers a primitive array element by index. */
|
|
153
159
|
autocomplete<K extends ArrayPaths<O>>(arrayKey: K, index: number): ItemAutocompleteProps;
|
|
160
|
+
/** Registers a deeply nested field using variadic path segments. */
|
|
161
|
+
autocomplete(...args: any[]): ItemAutocompleteProps;
|
|
154
162
|
/** Registers a boolean field for Checkbox. */
|
|
155
163
|
checkbox<P extends AllPaths<O>>(id: P): ItemToggleProps;
|
|
156
164
|
/** Registers a boolean field within an object array element for Checkbox. */
|
|
157
165
|
checkbox<P extends ObjectArrayFieldPaths<O>>(compositePath: P, itemId: string | number): ItemToggleProps;
|
|
166
|
+
/** Registers a deeply nested boolean field using variadic path segments. */
|
|
167
|
+
checkbox(...args: any[]): ItemToggleProps;
|
|
158
168
|
/** Registers a boolean field for Switch. */
|
|
159
169
|
switch<P extends AllPaths<O>>(id: P): ItemToggleProps;
|
|
160
170
|
/** Registers a boolean field within an object array element for Switch. */
|
|
161
171
|
switch<P extends ObjectArrayFieldPaths<O>>(compositePath: P, itemId: string | number): ItemToggleProps;
|
|
172
|
+
/** Registers a deeply nested boolean field using variadic path segments. */
|
|
173
|
+
switch(...args: any[]): ItemToggleProps;
|
|
162
174
|
/** Registers a string field for RadioGroup. */
|
|
163
175
|
radio<P extends AllPaths<O>>(id: P): ItemRadioGroupProps;
|
|
164
176
|
/** Registers a string field within an object array element for RadioGroup. */
|
|
165
177
|
radio<P extends ObjectArrayFieldPaths<O>>(compositePath: P, itemId: string | number): ItemRadioGroupProps;
|
|
178
|
+
/** Registers a deeply nested string field using variadic path segments. */
|
|
179
|
+
radio(...args: any[]): ItemRadioGroupProps;
|
|
166
180
|
}
|
|
167
181
|
/**
|
|
168
182
|
* Recursive type to find all paths to arrays in the state.
|
package/dist/index.js
CHANGED
|
@@ -98,6 +98,21 @@ function removeCompositeKeysByPrefix(map, prefix) {
|
|
|
98
98
|
}
|
|
99
99
|
return result;
|
|
100
100
|
}
|
|
101
|
+
function setNestedValue(state, dotPath, value) {
|
|
102
|
+
const keys = dotPath.split(".");
|
|
103
|
+
const copy = { ...state };
|
|
104
|
+
let current = copy;
|
|
105
|
+
for (let i = 0; i < keys.length - 1; i++) {
|
|
106
|
+
if (Array.isArray(current[keys[i]])) {
|
|
107
|
+
current[keys[i]] = [...current[keys[i]]];
|
|
108
|
+
} else {
|
|
109
|
+
current[keys[i]] = { ...current[keys[i]] };
|
|
110
|
+
}
|
|
111
|
+
current = current[keys[i]];
|
|
112
|
+
}
|
|
113
|
+
current[keys[keys.length - 1]] = value;
|
|
114
|
+
return copy;
|
|
115
|
+
}
|
|
101
116
|
|
|
102
117
|
// src/hooks/useForm.tsx
|
|
103
118
|
var import_react3 = require("@heroui/react");
|
|
@@ -219,7 +234,7 @@ function useComponentLanguage() {
|
|
|
219
234
|
}
|
|
220
235
|
|
|
221
236
|
// src/hooks/useForm.utils.ts
|
|
222
|
-
function resolveFieldData(args, state, getIndex, getNestedValue2) {
|
|
237
|
+
function resolveFieldData(args, state, getIndex, getNestedValue2, getRule, validationSchema) {
|
|
223
238
|
const argCount = args.length;
|
|
224
239
|
if (argCount === 1) {
|
|
225
240
|
const id = args[0];
|
|
@@ -314,6 +329,49 @@ function resolveFieldData(args, state, getIndex, getNestedValue2) {
|
|
|
314
329
|
nestedField: field
|
|
315
330
|
};
|
|
316
331
|
}
|
|
332
|
+
if (argCount >= 5) {
|
|
333
|
+
let current = state;
|
|
334
|
+
const compositeKeyParts = [];
|
|
335
|
+
const fieldPathParts = [];
|
|
336
|
+
const realPathParts = [];
|
|
337
|
+
let currentPath = "";
|
|
338
|
+
const parts = args.flatMap(
|
|
339
|
+
(arg) => typeof arg === "string" ? arg.split(".") : [arg]
|
|
340
|
+
);
|
|
341
|
+
for (const part of parts) {
|
|
342
|
+
let isArrayContext = Array.isArray(current);
|
|
343
|
+
if (!isArrayContext && getRule && validationSchema) {
|
|
344
|
+
const currentFieldPath = fieldPathParts.filter(Boolean).join(".");
|
|
345
|
+
const rule = getRule(currentFieldPath, validationSchema);
|
|
346
|
+
if (rule && rule.type === "array") {
|
|
347
|
+
isArrayContext = true;
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
if (isArrayContext) {
|
|
351
|
+
let indexNum = getIndex(currentPath, part);
|
|
352
|
+
if (indexNum === void 0 && typeof part === "number") {
|
|
353
|
+
indexNum = part;
|
|
354
|
+
}
|
|
355
|
+
if (indexNum === void 0) return null;
|
|
356
|
+
compositeKeyParts.push(String(part));
|
|
357
|
+
realPathParts.push(String(indexNum));
|
|
358
|
+
current = current?.[indexNum];
|
|
359
|
+
} else {
|
|
360
|
+
compositeKeyParts.push(String(part));
|
|
361
|
+
fieldPathParts.push(String(part));
|
|
362
|
+
realPathParts.push(String(part));
|
|
363
|
+
currentPath = realPathParts.join(".");
|
|
364
|
+
current = current?.[part];
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
return {
|
|
368
|
+
type: "deep" /* Deep */,
|
|
369
|
+
compositeKey: compositeKeyParts.join(".").replace(/\.\./g, "."),
|
|
370
|
+
fieldPath: fieldPathParts.filter(Boolean).join("."),
|
|
371
|
+
realPath: realPathParts.join("."),
|
|
372
|
+
value: current
|
|
373
|
+
};
|
|
374
|
+
}
|
|
317
375
|
return null;
|
|
318
376
|
}
|
|
319
377
|
|
|
@@ -598,6 +656,8 @@ function useForm(schema, {
|
|
|
598
656
|
parentArr[pIndex] = pItem;
|
|
599
657
|
nextState = { ...nextState, [parentKey]: parentArr };
|
|
600
658
|
}
|
|
659
|
+
} else if (type === "deep" /* Deep */) {
|
|
660
|
+
nextState = setNestedValue(nextState, resolution.realPath, finalValue);
|
|
601
661
|
}
|
|
602
662
|
setState(nextState);
|
|
603
663
|
validateField(
|
|
@@ -659,7 +719,9 @@ function useForm(schema, {
|
|
|
659
719
|
args,
|
|
660
720
|
stateRef.current,
|
|
661
721
|
getIndex,
|
|
662
|
-
getNestedValue
|
|
722
|
+
getNestedValue,
|
|
723
|
+
getRule,
|
|
724
|
+
validationSchema
|
|
663
725
|
);
|
|
664
726
|
if (!data) return {};
|
|
665
727
|
return {
|
|
@@ -673,7 +735,9 @@ function useForm(schema, {
|
|
|
673
735
|
args,
|
|
674
736
|
stateRef.current,
|
|
675
737
|
getIndex,
|
|
676
|
-
getNestedValue
|
|
738
|
+
getNestedValue,
|
|
739
|
+
getRule,
|
|
740
|
+
validationSchema
|
|
677
741
|
);
|
|
678
742
|
if (!data) return {};
|
|
679
743
|
const isArray = Array.isArray(data.value);
|
|
@@ -691,7 +755,9 @@ function useForm(schema, {
|
|
|
691
755
|
args,
|
|
692
756
|
stateRef.current,
|
|
693
757
|
getIndex,
|
|
694
|
-
getNestedValue
|
|
758
|
+
getNestedValue,
|
|
759
|
+
getRule,
|
|
760
|
+
validationSchema
|
|
695
761
|
);
|
|
696
762
|
if (!data) return {};
|
|
697
763
|
return {
|
|
@@ -708,7 +774,9 @@ function useForm(schema, {
|
|
|
708
774
|
args,
|
|
709
775
|
stateRef.current,
|
|
710
776
|
getIndex,
|
|
711
|
-
getNestedValue
|
|
777
|
+
getNestedValue,
|
|
778
|
+
getRule,
|
|
779
|
+
validationSchema
|
|
712
780
|
);
|
|
713
781
|
if (!data) return {};
|
|
714
782
|
return {
|
|
@@ -722,7 +790,9 @@ function useForm(schema, {
|
|
|
722
790
|
args,
|
|
723
791
|
stateRef.current,
|
|
724
792
|
getIndex,
|
|
725
|
-
getNestedValue
|
|
793
|
+
getNestedValue,
|
|
794
|
+
getRule,
|
|
795
|
+
validationSchema
|
|
726
796
|
);
|
|
727
797
|
if (!data) return {};
|
|
728
798
|
return {
|
|
@@ -736,7 +806,9 @@ function useForm(schema, {
|
|
|
736
806
|
args,
|
|
737
807
|
stateRef.current,
|
|
738
808
|
getIndex,
|
|
739
|
-
getNestedValue
|
|
809
|
+
getNestedValue,
|
|
810
|
+
getRule,
|
|
811
|
+
validationSchema
|
|
740
812
|
);
|
|
741
813
|
if (!data) return {};
|
|
742
814
|
return {
|
|
@@ -750,7 +822,9 @@ function useForm(schema, {
|
|
|
750
822
|
args,
|
|
751
823
|
stateRef.current,
|
|
752
824
|
getIndex,
|
|
753
|
-
getNestedValue
|
|
825
|
+
getNestedValue,
|
|
826
|
+
getRule,
|
|
827
|
+
validationSchema
|
|
754
828
|
);
|
|
755
829
|
if (!data) return {};
|
|
756
830
|
return {
|
|
@@ -760,7 +834,7 @@ function useForm(schema, {
|
|
|
760
834
|
};
|
|
761
835
|
}
|
|
762
836
|
}),
|
|
763
|
-
[createHandlers, getIndex, handleFieldChange]
|
|
837
|
+
[createHandlers, getIndex, handleFieldChange, getRule, validationSchema]
|
|
764
838
|
);
|
|
765
839
|
const helpers = (0, import_react2.useMemo)(
|
|
766
840
|
() => ({
|
|
@@ -911,7 +985,7 @@ function useForm(schema, {
|
|
|
911
985
|
);
|
|
912
986
|
if (data) handleFieldChange(data, value);
|
|
913
987
|
},
|
|
914
|
-
[getIndex, handleFieldChange]
|
|
988
|
+
[getIndex, handleFieldChange, getRule, validationSchema]
|
|
915
989
|
);
|
|
916
990
|
const arrayItemChange = (0, import_react2.useCallback)(
|
|
917
991
|
({
|
|
@@ -927,7 +1001,7 @@ function useForm(schema, {
|
|
|
927
1001
|
);
|
|
928
1002
|
if (data) handleFieldChange(data, value);
|
|
929
1003
|
},
|
|
930
|
-
[getIndex, handleFieldChange]
|
|
1004
|
+
[getIndex, handleFieldChange, getRule, validationSchema]
|
|
931
1005
|
);
|
|
932
1006
|
const scalarOnSelectionChange = (0, import_react2.useCallback)(
|
|
933
1007
|
(id, val) => {
|
|
@@ -958,7 +1032,7 @@ function useForm(schema, {
|
|
|
958
1032
|
);
|
|
959
1033
|
if (data) handleFieldChange(data, fixed);
|
|
960
1034
|
},
|
|
961
|
-
[getIndex, handleFieldChange]
|
|
1035
|
+
[getIndex, handleFieldChange, getRule, validationSchema]
|
|
962
1036
|
);
|
|
963
1037
|
const onFormSubmit = (0, import_react2.useCallback)(
|
|
964
1038
|
(fn) => (e) => {
|
package/dist/index.mjs
CHANGED
|
@@ -72,6 +72,21 @@ function removeCompositeKeysByPrefix(map, prefix) {
|
|
|
72
72
|
}
|
|
73
73
|
return result;
|
|
74
74
|
}
|
|
75
|
+
function setNestedValue(state, dotPath, value) {
|
|
76
|
+
const keys = dotPath.split(".");
|
|
77
|
+
const copy = { ...state };
|
|
78
|
+
let current = copy;
|
|
79
|
+
for (let i = 0; i < keys.length - 1; i++) {
|
|
80
|
+
if (Array.isArray(current[keys[i]])) {
|
|
81
|
+
current[keys[i]] = [...current[keys[i]]];
|
|
82
|
+
} else {
|
|
83
|
+
current[keys[i]] = { ...current[keys[i]] };
|
|
84
|
+
}
|
|
85
|
+
current = current[keys[i]];
|
|
86
|
+
}
|
|
87
|
+
current[keys[keys.length - 1]] = value;
|
|
88
|
+
return copy;
|
|
89
|
+
}
|
|
75
90
|
|
|
76
91
|
// src/hooks/useForm.tsx
|
|
77
92
|
import { Form } from "@heroui/react";
|
|
@@ -193,7 +208,7 @@ function useComponentLanguage() {
|
|
|
193
208
|
}
|
|
194
209
|
|
|
195
210
|
// src/hooks/useForm.utils.ts
|
|
196
|
-
function resolveFieldData(args, state, getIndex, getNestedValue2) {
|
|
211
|
+
function resolveFieldData(args, state, getIndex, getNestedValue2, getRule, validationSchema) {
|
|
197
212
|
const argCount = args.length;
|
|
198
213
|
if (argCount === 1) {
|
|
199
214
|
const id = args[0];
|
|
@@ -288,6 +303,49 @@ function resolveFieldData(args, state, getIndex, getNestedValue2) {
|
|
|
288
303
|
nestedField: field
|
|
289
304
|
};
|
|
290
305
|
}
|
|
306
|
+
if (argCount >= 5) {
|
|
307
|
+
let current = state;
|
|
308
|
+
const compositeKeyParts = [];
|
|
309
|
+
const fieldPathParts = [];
|
|
310
|
+
const realPathParts = [];
|
|
311
|
+
let currentPath = "";
|
|
312
|
+
const parts = args.flatMap(
|
|
313
|
+
(arg) => typeof arg === "string" ? arg.split(".") : [arg]
|
|
314
|
+
);
|
|
315
|
+
for (const part of parts) {
|
|
316
|
+
let isArrayContext = Array.isArray(current);
|
|
317
|
+
if (!isArrayContext && getRule && validationSchema) {
|
|
318
|
+
const currentFieldPath = fieldPathParts.filter(Boolean).join(".");
|
|
319
|
+
const rule = getRule(currentFieldPath, validationSchema);
|
|
320
|
+
if (rule && rule.type === "array") {
|
|
321
|
+
isArrayContext = true;
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
if (isArrayContext) {
|
|
325
|
+
let indexNum = getIndex(currentPath, part);
|
|
326
|
+
if (indexNum === void 0 && typeof part === "number") {
|
|
327
|
+
indexNum = part;
|
|
328
|
+
}
|
|
329
|
+
if (indexNum === void 0) return null;
|
|
330
|
+
compositeKeyParts.push(String(part));
|
|
331
|
+
realPathParts.push(String(indexNum));
|
|
332
|
+
current = current?.[indexNum];
|
|
333
|
+
} else {
|
|
334
|
+
compositeKeyParts.push(String(part));
|
|
335
|
+
fieldPathParts.push(String(part));
|
|
336
|
+
realPathParts.push(String(part));
|
|
337
|
+
currentPath = realPathParts.join(".");
|
|
338
|
+
current = current?.[part];
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
return {
|
|
342
|
+
type: "deep" /* Deep */,
|
|
343
|
+
compositeKey: compositeKeyParts.join(".").replace(/\.\./g, "."),
|
|
344
|
+
fieldPath: fieldPathParts.filter(Boolean).join("."),
|
|
345
|
+
realPath: realPathParts.join("."),
|
|
346
|
+
value: current
|
|
347
|
+
};
|
|
348
|
+
}
|
|
291
349
|
return null;
|
|
292
350
|
}
|
|
293
351
|
|
|
@@ -572,6 +630,8 @@ function useForm(schema, {
|
|
|
572
630
|
parentArr[pIndex] = pItem;
|
|
573
631
|
nextState = { ...nextState, [parentKey]: parentArr };
|
|
574
632
|
}
|
|
633
|
+
} else if (type === "deep" /* Deep */) {
|
|
634
|
+
nextState = setNestedValue(nextState, resolution.realPath, finalValue);
|
|
575
635
|
}
|
|
576
636
|
setState(nextState);
|
|
577
637
|
validateField(
|
|
@@ -633,7 +693,9 @@ function useForm(schema, {
|
|
|
633
693
|
args,
|
|
634
694
|
stateRef.current,
|
|
635
695
|
getIndex,
|
|
636
|
-
getNestedValue
|
|
696
|
+
getNestedValue,
|
|
697
|
+
getRule,
|
|
698
|
+
validationSchema
|
|
637
699
|
);
|
|
638
700
|
if (!data) return {};
|
|
639
701
|
return {
|
|
@@ -647,7 +709,9 @@ function useForm(schema, {
|
|
|
647
709
|
args,
|
|
648
710
|
stateRef.current,
|
|
649
711
|
getIndex,
|
|
650
|
-
getNestedValue
|
|
712
|
+
getNestedValue,
|
|
713
|
+
getRule,
|
|
714
|
+
validationSchema
|
|
651
715
|
);
|
|
652
716
|
if (!data) return {};
|
|
653
717
|
const isArray = Array.isArray(data.value);
|
|
@@ -665,7 +729,9 @@ function useForm(schema, {
|
|
|
665
729
|
args,
|
|
666
730
|
stateRef.current,
|
|
667
731
|
getIndex,
|
|
668
|
-
getNestedValue
|
|
732
|
+
getNestedValue,
|
|
733
|
+
getRule,
|
|
734
|
+
validationSchema
|
|
669
735
|
);
|
|
670
736
|
if (!data) return {};
|
|
671
737
|
return {
|
|
@@ -682,7 +748,9 @@ function useForm(schema, {
|
|
|
682
748
|
args,
|
|
683
749
|
stateRef.current,
|
|
684
750
|
getIndex,
|
|
685
|
-
getNestedValue
|
|
751
|
+
getNestedValue,
|
|
752
|
+
getRule,
|
|
753
|
+
validationSchema
|
|
686
754
|
);
|
|
687
755
|
if (!data) return {};
|
|
688
756
|
return {
|
|
@@ -696,7 +764,9 @@ function useForm(schema, {
|
|
|
696
764
|
args,
|
|
697
765
|
stateRef.current,
|
|
698
766
|
getIndex,
|
|
699
|
-
getNestedValue
|
|
767
|
+
getNestedValue,
|
|
768
|
+
getRule,
|
|
769
|
+
validationSchema
|
|
700
770
|
);
|
|
701
771
|
if (!data) return {};
|
|
702
772
|
return {
|
|
@@ -710,7 +780,9 @@ function useForm(schema, {
|
|
|
710
780
|
args,
|
|
711
781
|
stateRef.current,
|
|
712
782
|
getIndex,
|
|
713
|
-
getNestedValue
|
|
783
|
+
getNestedValue,
|
|
784
|
+
getRule,
|
|
785
|
+
validationSchema
|
|
714
786
|
);
|
|
715
787
|
if (!data) return {};
|
|
716
788
|
return {
|
|
@@ -724,7 +796,9 @@ function useForm(schema, {
|
|
|
724
796
|
args,
|
|
725
797
|
stateRef.current,
|
|
726
798
|
getIndex,
|
|
727
|
-
getNestedValue
|
|
799
|
+
getNestedValue,
|
|
800
|
+
getRule,
|
|
801
|
+
validationSchema
|
|
728
802
|
);
|
|
729
803
|
if (!data) return {};
|
|
730
804
|
return {
|
|
@@ -734,7 +808,7 @@ function useForm(schema, {
|
|
|
734
808
|
};
|
|
735
809
|
}
|
|
736
810
|
}),
|
|
737
|
-
[createHandlers, getIndex, handleFieldChange]
|
|
811
|
+
[createHandlers, getIndex, handleFieldChange, getRule, validationSchema]
|
|
738
812
|
);
|
|
739
813
|
const helpers = useMemo(
|
|
740
814
|
() => ({
|
|
@@ -885,7 +959,7 @@ function useForm(schema, {
|
|
|
885
959
|
);
|
|
886
960
|
if (data) handleFieldChange(data, value);
|
|
887
961
|
},
|
|
888
|
-
[getIndex, handleFieldChange]
|
|
962
|
+
[getIndex, handleFieldChange, getRule, validationSchema]
|
|
889
963
|
);
|
|
890
964
|
const arrayItemChange = useCallback(
|
|
891
965
|
({
|
|
@@ -901,7 +975,7 @@ function useForm(schema, {
|
|
|
901
975
|
);
|
|
902
976
|
if (data) handleFieldChange(data, value);
|
|
903
977
|
},
|
|
904
|
-
[getIndex, handleFieldChange]
|
|
978
|
+
[getIndex, handleFieldChange, getRule, validationSchema]
|
|
905
979
|
);
|
|
906
980
|
const scalarOnSelectionChange = useCallback(
|
|
907
981
|
(id, val) => {
|
|
@@ -932,7 +1006,7 @@ function useForm(schema, {
|
|
|
932
1006
|
);
|
|
933
1007
|
if (data) handleFieldChange(data, fixed);
|
|
934
1008
|
},
|
|
935
|
-
[getIndex, handleFieldChange]
|
|
1009
|
+
[getIndex, handleFieldChange, getRule, validationSchema]
|
|
936
1010
|
);
|
|
937
1011
|
const onFormSubmit = useCallback(
|
|
938
1012
|
(fn) => (e) => {
|