@juantroconisf/lib 11.1.0 → 11.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/dist/index.d.mts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +33 -8
- package/dist/index.mjs +33 -8
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -86,6 +86,7 @@ type ValueChangeFunc<O extends StateType, K extends keyof O> = (id: K, value: O[
|
|
|
86
86
|
type BlurFunc<O extends StateType> = (id: keyof O) => void;
|
|
87
87
|
interface ComponentInputProps {
|
|
88
88
|
id: string;
|
|
89
|
+
name: string;
|
|
89
90
|
onBlur: () => void;
|
|
90
91
|
isInvalid: boolean;
|
|
91
92
|
errorMessage: string;
|
package/dist/index.d.ts
CHANGED
|
@@ -86,6 +86,7 @@ type ValueChangeFunc<O extends StateType, K extends keyof O> = (id: K, value: O[
|
|
|
86
86
|
type BlurFunc<O extends StateType> = (id: keyof O) => void;
|
|
87
87
|
interface ComponentInputProps {
|
|
88
88
|
id: string;
|
|
89
|
+
name: string;
|
|
89
90
|
onBlur: () => void;
|
|
90
91
|
isInvalid: boolean;
|
|
91
92
|
errorMessage: string;
|
package/dist/index.js
CHANGED
|
@@ -539,6 +539,30 @@ function useForm(schema, {
|
|
|
539
539
|
finalValue = rule.cast(newValue);
|
|
540
540
|
} catch {
|
|
541
541
|
}
|
|
542
|
+
} else if (rule && rule.type === "number") {
|
|
543
|
+
try {
|
|
544
|
+
if (newValue === "") {
|
|
545
|
+
finalValue = null;
|
|
546
|
+
} else if (newValue === null || newValue === void 0) {
|
|
547
|
+
finalValue = newValue;
|
|
548
|
+
} else if (Array.isArray(newValue)) {
|
|
549
|
+
finalValue = newValue.map(
|
|
550
|
+
(v) => v === "" ? null : v === null || v === void 0 ? v : Number(v)
|
|
551
|
+
);
|
|
552
|
+
} else {
|
|
553
|
+
finalValue = Number(newValue);
|
|
554
|
+
if (isNaN(finalValue)) finalValue = newValue;
|
|
555
|
+
}
|
|
556
|
+
} catch {
|
|
557
|
+
}
|
|
558
|
+
} else if (rule && rule.type === "array" && rule.innerType && rule.innerType.type === "number") {
|
|
559
|
+
if (Array.isArray(newValue)) {
|
|
560
|
+
finalValue = newValue.map((v) => {
|
|
561
|
+
if (v === "" || v === null || v === void 0) return v;
|
|
562
|
+
const num = Number(v);
|
|
563
|
+
return isNaN(num) ? v : num;
|
|
564
|
+
});
|
|
565
|
+
}
|
|
542
566
|
}
|
|
543
567
|
let nextState = stateRef.current;
|
|
544
568
|
if (type === "scalar" /* Scalar */) {
|
|
@@ -600,6 +624,7 @@ function useForm(schema, {
|
|
|
600
624
|
}
|
|
601
625
|
return {
|
|
602
626
|
id: compositeKey,
|
|
627
|
+
name: compositeKey,
|
|
603
628
|
isInvalid: Boolean(isTouched && meta?.isInvalid),
|
|
604
629
|
errorMessage: isTouched ? meta?.errorMessage || "" : "",
|
|
605
630
|
isRequired,
|
|
@@ -639,7 +664,7 @@ function useForm(schema, {
|
|
|
639
664
|
if (!data) return {};
|
|
640
665
|
return {
|
|
641
666
|
...createHandlers(data),
|
|
642
|
-
value: data.value,
|
|
667
|
+
value: data.value === null || data.value === void 0 ? "" : typeof data.value === "boolean" ? data.value : String(data.value),
|
|
643
668
|
onValueChange: (v) => handleFieldChange(data, v)
|
|
644
669
|
};
|
|
645
670
|
},
|
|
@@ -651,12 +676,12 @@ function useForm(schema, {
|
|
|
651
676
|
getNestedValue
|
|
652
677
|
);
|
|
653
678
|
if (!data) return {};
|
|
654
|
-
const
|
|
679
|
+
const isArray = Array.isArray(data.value);
|
|
655
680
|
return {
|
|
656
681
|
...createHandlers(data),
|
|
657
|
-
selectedKeys: data.value === null ? [] :
|
|
682
|
+
selectedKeys: data.value === null || data.value === void 0 ? [] : isArray ? data.value.map(String) : [String(data.value)],
|
|
658
683
|
onSelectionChange: (v) => {
|
|
659
|
-
const fixed = typeof v === "string" || v === null ? v :
|
|
684
|
+
const fixed = typeof v === "string" || v === null ? v : isArray ? Array.from(v) : Array.from(v)[0] ?? null;
|
|
660
685
|
handleFieldChange(data, fixed);
|
|
661
686
|
}
|
|
662
687
|
};
|
|
@@ -671,9 +696,9 @@ function useForm(schema, {
|
|
|
671
696
|
if (!data) return {};
|
|
672
697
|
return {
|
|
673
698
|
...createHandlers(data),
|
|
674
|
-
selectedKey: data.value,
|
|
699
|
+
selectedKey: data.value === null || data.value === void 0 ? null : String(data.value),
|
|
675
700
|
onSelectionChange: (v) => {
|
|
676
|
-
const fixed = typeof v === "string" || v === null ? v : String(v);
|
|
701
|
+
const fixed = typeof v === "string" || v === null || v === void 0 ? v : String(v);
|
|
677
702
|
handleFieldChange(data, fixed);
|
|
678
703
|
}
|
|
679
704
|
};
|
|
@@ -688,7 +713,7 @@ function useForm(schema, {
|
|
|
688
713
|
if (!data) return {};
|
|
689
714
|
return {
|
|
690
715
|
...createHandlers(data),
|
|
691
|
-
value: data.value
|
|
716
|
+
value: data.value === null || data.value === void 0 ? "" : String(data.value),
|
|
692
717
|
onValueChange: (v) => handleFieldChange(data, v)
|
|
693
718
|
};
|
|
694
719
|
},
|
|
@@ -730,7 +755,7 @@ function useForm(schema, {
|
|
|
730
755
|
if (!data) return {};
|
|
731
756
|
return {
|
|
732
757
|
...createHandlers(data),
|
|
733
|
-
value: data.value
|
|
758
|
+
value: data.value === null || data.value === void 0 ? "" : String(data.value),
|
|
734
759
|
onValueChange: (v) => handleFieldChange(data, v)
|
|
735
760
|
};
|
|
736
761
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -513,6 +513,30 @@ function useForm(schema, {
|
|
|
513
513
|
finalValue = rule.cast(newValue);
|
|
514
514
|
} catch {
|
|
515
515
|
}
|
|
516
|
+
} else if (rule && rule.type === "number") {
|
|
517
|
+
try {
|
|
518
|
+
if (newValue === "") {
|
|
519
|
+
finalValue = null;
|
|
520
|
+
} else if (newValue === null || newValue === void 0) {
|
|
521
|
+
finalValue = newValue;
|
|
522
|
+
} else if (Array.isArray(newValue)) {
|
|
523
|
+
finalValue = newValue.map(
|
|
524
|
+
(v) => v === "" ? null : v === null || v === void 0 ? v : Number(v)
|
|
525
|
+
);
|
|
526
|
+
} else {
|
|
527
|
+
finalValue = Number(newValue);
|
|
528
|
+
if (isNaN(finalValue)) finalValue = newValue;
|
|
529
|
+
}
|
|
530
|
+
} catch {
|
|
531
|
+
}
|
|
532
|
+
} else if (rule && rule.type === "array" && rule.innerType && rule.innerType.type === "number") {
|
|
533
|
+
if (Array.isArray(newValue)) {
|
|
534
|
+
finalValue = newValue.map((v) => {
|
|
535
|
+
if (v === "" || v === null || v === void 0) return v;
|
|
536
|
+
const num = Number(v);
|
|
537
|
+
return isNaN(num) ? v : num;
|
|
538
|
+
});
|
|
539
|
+
}
|
|
516
540
|
}
|
|
517
541
|
let nextState = stateRef.current;
|
|
518
542
|
if (type === "scalar" /* Scalar */) {
|
|
@@ -574,6 +598,7 @@ function useForm(schema, {
|
|
|
574
598
|
}
|
|
575
599
|
return {
|
|
576
600
|
id: compositeKey,
|
|
601
|
+
name: compositeKey,
|
|
577
602
|
isInvalid: Boolean(isTouched && meta?.isInvalid),
|
|
578
603
|
errorMessage: isTouched ? meta?.errorMessage || "" : "",
|
|
579
604
|
isRequired,
|
|
@@ -613,7 +638,7 @@ function useForm(schema, {
|
|
|
613
638
|
if (!data) return {};
|
|
614
639
|
return {
|
|
615
640
|
...createHandlers(data),
|
|
616
|
-
value: data.value,
|
|
641
|
+
value: data.value === null || data.value === void 0 ? "" : typeof data.value === "boolean" ? data.value : String(data.value),
|
|
617
642
|
onValueChange: (v) => handleFieldChange(data, v)
|
|
618
643
|
};
|
|
619
644
|
},
|
|
@@ -625,12 +650,12 @@ function useForm(schema, {
|
|
|
625
650
|
getNestedValue
|
|
626
651
|
);
|
|
627
652
|
if (!data) return {};
|
|
628
|
-
const
|
|
653
|
+
const isArray = Array.isArray(data.value);
|
|
629
654
|
return {
|
|
630
655
|
...createHandlers(data),
|
|
631
|
-
selectedKeys: data.value === null ? [] :
|
|
656
|
+
selectedKeys: data.value === null || data.value === void 0 ? [] : isArray ? data.value.map(String) : [String(data.value)],
|
|
632
657
|
onSelectionChange: (v) => {
|
|
633
|
-
const fixed = typeof v === "string" || v === null ? v :
|
|
658
|
+
const fixed = typeof v === "string" || v === null ? v : isArray ? Array.from(v) : Array.from(v)[0] ?? null;
|
|
634
659
|
handleFieldChange(data, fixed);
|
|
635
660
|
}
|
|
636
661
|
};
|
|
@@ -645,9 +670,9 @@ function useForm(schema, {
|
|
|
645
670
|
if (!data) return {};
|
|
646
671
|
return {
|
|
647
672
|
...createHandlers(data),
|
|
648
|
-
selectedKey: data.value,
|
|
673
|
+
selectedKey: data.value === null || data.value === void 0 ? null : String(data.value),
|
|
649
674
|
onSelectionChange: (v) => {
|
|
650
|
-
const fixed = typeof v === "string" || v === null ? v : String(v);
|
|
675
|
+
const fixed = typeof v === "string" || v === null || v === void 0 ? v : String(v);
|
|
651
676
|
handleFieldChange(data, fixed);
|
|
652
677
|
}
|
|
653
678
|
};
|
|
@@ -662,7 +687,7 @@ function useForm(schema, {
|
|
|
662
687
|
if (!data) return {};
|
|
663
688
|
return {
|
|
664
689
|
...createHandlers(data),
|
|
665
|
-
value: data.value
|
|
690
|
+
value: data.value === null || data.value === void 0 ? "" : String(data.value),
|
|
666
691
|
onValueChange: (v) => handleFieldChange(data, v)
|
|
667
692
|
};
|
|
668
693
|
},
|
|
@@ -704,7 +729,7 @@ function useForm(schema, {
|
|
|
704
729
|
if (!data) return {};
|
|
705
730
|
return {
|
|
706
731
|
...createHandlers(data),
|
|
707
|
-
value: data.value
|
|
732
|
+
value: data.value === null || data.value === void 0 ? "" : String(data.value),
|
|
708
733
|
onValueChange: (v) => handleFieldChange(data, v)
|
|
709
734
|
};
|
|
710
735
|
}
|