@regle/core 0.0.5-beta.0 → 0.0.5
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.cjs +46 -22
- package/dist/index.d.cts +15 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +50 -26
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -420,6 +420,9 @@ function createReactiveFieldStatus({
|
|
|
420
420
|
$watch();
|
|
421
421
|
if (storeResult?.valid != null) {
|
|
422
422
|
$dirty.value = storage.getDirtyState(path);
|
|
423
|
+
if ($dirty.value) {
|
|
424
|
+
$commit();
|
|
425
|
+
}
|
|
423
426
|
}
|
|
424
427
|
storage.addRuleDeclEntry(path, declaredRules);
|
|
425
428
|
}
|
|
@@ -553,12 +556,15 @@ function createCollectionElement({
|
|
|
553
556
|
customMessages,
|
|
554
557
|
rules
|
|
555
558
|
}) {
|
|
556
|
-
const $path = `${path}.${index}`;
|
|
557
559
|
const $id = randomId();
|
|
560
|
+
const $path = `${path}.${$id}`;
|
|
558
561
|
if (!value[index].$id) {
|
|
559
562
|
Object.defineProperties(value[index], {
|
|
560
563
|
$id: {
|
|
561
|
-
value: $id
|
|
564
|
+
value: $id,
|
|
565
|
+
enumerable: false,
|
|
566
|
+
configurable: false,
|
|
567
|
+
writable: false
|
|
562
568
|
}
|
|
563
569
|
});
|
|
564
570
|
}
|
|
@@ -605,27 +611,40 @@ function createReactiveCollectionStatus({
|
|
|
605
611
|
});
|
|
606
612
|
if (Array.isArray(state.value) && $each) {
|
|
607
613
|
$eachStatus.value = state.value.map((value, index) => {
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
614
|
+
if (value.$id) {
|
|
615
|
+
const previousStatus = storage.getArrayStatus(value.$id);
|
|
616
|
+
if (previousStatus) {
|
|
617
|
+
return previousStatus;
|
|
618
|
+
}
|
|
619
|
+
} else {
|
|
620
|
+
return createCollectionElement({
|
|
621
|
+
path,
|
|
622
|
+
rules: $each,
|
|
623
|
+
value: state.value,
|
|
624
|
+
index,
|
|
625
|
+
options,
|
|
626
|
+
storage
|
|
627
|
+
});
|
|
628
|
+
}
|
|
616
629
|
}).filter((f) => !!f);
|
|
617
630
|
} else {
|
|
618
631
|
$eachStatus.value = [];
|
|
619
632
|
}
|
|
620
633
|
}
|
|
621
|
-
function updateChildrenStatus() {
|
|
634
|
+
async function updateChildrenStatus() {
|
|
622
635
|
const { $each } = rulesDef.value;
|
|
623
636
|
if (Array.isArray(state.value) && $eachStatus.value && $each) {
|
|
637
|
+
$unwatchState?.();
|
|
624
638
|
state.value.forEach((value, index) => {
|
|
625
639
|
if (value.$id) {
|
|
640
|
+
if (Array.isArray(state.value) && !state.value.find((val) => val.$id === $eachStatus.value[index].$id)) {
|
|
641
|
+
$eachStatus.value[index].$unwatch();
|
|
642
|
+
}
|
|
626
643
|
const previousStatus = storage.getArrayStatus(value.$id);
|
|
627
644
|
if (previousStatus) {
|
|
628
645
|
$eachStatus.value[index] = previousStatus;
|
|
646
|
+
} else {
|
|
647
|
+
$eachStatus.value[index].$unwatch();
|
|
629
648
|
}
|
|
630
649
|
} else {
|
|
631
650
|
const newElement = createCollectionElement({
|
|
@@ -642,12 +661,15 @@ function createReactiveCollectionStatus({
|
|
|
642
661
|
}
|
|
643
662
|
}
|
|
644
663
|
});
|
|
645
|
-
}
|
|
646
|
-
if ($eachStatus.value) {
|
|
647
664
|
const deletedItems = $eachStatus.value.filter(($each2) => {
|
|
648
665
|
return Array.isArray(state.value) && !state.value.find((val) => val.$id === $each2.$id);
|
|
649
666
|
});
|
|
650
|
-
deletedItems.forEach((item) =>
|
|
667
|
+
deletedItems.forEach((item) => {
|
|
668
|
+
storage.deleteArrayStatus(item.$id);
|
|
669
|
+
item.$unwatch();
|
|
670
|
+
});
|
|
671
|
+
$eachStatus.value.length = state.value.length;
|
|
672
|
+
(0, import_vue6.nextTick)($watch);
|
|
651
673
|
}
|
|
652
674
|
}
|
|
653
675
|
function $unwatch() {
|
|
@@ -664,13 +686,9 @@ function createReactiveCollectionStatus({
|
|
|
664
686
|
}
|
|
665
687
|
}
|
|
666
688
|
function $watch() {
|
|
667
|
-
$unwatchState = (0, import_vue6.watch)(
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
updateChildrenStatus();
|
|
671
|
-
},
|
|
672
|
-
{ deep: true, flush: "sync" }
|
|
673
|
-
);
|
|
689
|
+
$unwatchState = (0, import_vue6.watch)(() => state.value.length, updateChildrenStatus, {
|
|
690
|
+
flush: "sync"
|
|
691
|
+
});
|
|
674
692
|
}
|
|
675
693
|
function $touch() {
|
|
676
694
|
$fieldStatus.value.$touch();
|
|
@@ -916,6 +934,11 @@ function useStorage() {
|
|
|
916
934
|
function getArrayStatus($id) {
|
|
917
935
|
return arrayStatusStorage.value.get($id);
|
|
918
936
|
}
|
|
937
|
+
function deleteArrayStatus($id) {
|
|
938
|
+
if ($id) {
|
|
939
|
+
arrayStatusStorage.value.delete($id);
|
|
940
|
+
}
|
|
941
|
+
}
|
|
919
942
|
function setDirtyEntry($path, dirty) {
|
|
920
943
|
dirtyStorage.value.set($path, dirty);
|
|
921
944
|
}
|
|
@@ -977,7 +1000,8 @@ function useStorage() {
|
|
|
977
1000
|
getFieldsEntry,
|
|
978
1001
|
getCollectionsEntry,
|
|
979
1002
|
getArrayStatus,
|
|
980
|
-
addArrayStatus
|
|
1003
|
+
addArrayStatus,
|
|
1004
|
+
deleteArrayStatus
|
|
981
1005
|
};
|
|
982
1006
|
}
|
|
983
1007
|
|
package/dist/index.d.cts
CHANGED
|
@@ -27,6 +27,21 @@ type DefaultValidators = {
|
|
|
27
27
|
maxLength: RegleRuleWithParamsDefinition<string, [count: number]>;
|
|
28
28
|
required: RegleRuleDefinition<unknown, []>;
|
|
29
29
|
requiredIf: RegleRuleWithParamsDefinition<unknown, [condition: boolean]>;
|
|
30
|
+
alpha: RegleRuleDefinition<string>;
|
|
31
|
+
alphaNum: RegleRuleDefinition<string | number>;
|
|
32
|
+
between: RegleRuleWithParamsDefinition<number, [min: number, max: number]>;
|
|
33
|
+
decimal: RegleRuleDefinition<number | string>;
|
|
34
|
+
email: RegleRuleDefinition<string>;
|
|
35
|
+
integer: RegleRuleDefinition<number | string>;
|
|
36
|
+
maxValue: RegleRuleWithParamsDefinition<number, [count: number]>;
|
|
37
|
+
minLength: RegleRuleWithParamsDefinition<string | Record<PropertyKey, any> | any[], [
|
|
38
|
+
count: number
|
|
39
|
+
]>;
|
|
40
|
+
minValue: RegleRuleWithParamsDefinition<number, [count: number]>;
|
|
41
|
+
numeric: RegleRuleDefinition<number | string>;
|
|
42
|
+
requireUnless: RegleRuleWithParamsDefinition<unknown, [condition: boolean]>;
|
|
43
|
+
sameAs: RegleRuleWithParamsDefinition<unknown, [target: unknown]>;
|
|
44
|
+
url: RegleRuleDefinition<string>;
|
|
30
45
|
};
|
|
31
46
|
|
|
32
47
|
type ParamDecl<T = any> = MaybeRef<T> | (() => T);
|
package/dist/index.d.ts
CHANGED
|
@@ -27,6 +27,21 @@ type DefaultValidators = {
|
|
|
27
27
|
maxLength: RegleRuleWithParamsDefinition<string, [count: number]>;
|
|
28
28
|
required: RegleRuleDefinition<unknown, []>;
|
|
29
29
|
requiredIf: RegleRuleWithParamsDefinition<unknown, [condition: boolean]>;
|
|
30
|
+
alpha: RegleRuleDefinition<string>;
|
|
31
|
+
alphaNum: RegleRuleDefinition<string | number>;
|
|
32
|
+
between: RegleRuleWithParamsDefinition<number, [min: number, max: number]>;
|
|
33
|
+
decimal: RegleRuleDefinition<number | string>;
|
|
34
|
+
email: RegleRuleDefinition<string>;
|
|
35
|
+
integer: RegleRuleDefinition<number | string>;
|
|
36
|
+
maxValue: RegleRuleWithParamsDefinition<number, [count: number]>;
|
|
37
|
+
minLength: RegleRuleWithParamsDefinition<string | Record<PropertyKey, any> | any[], [
|
|
38
|
+
count: number
|
|
39
|
+
]>;
|
|
40
|
+
minValue: RegleRuleWithParamsDefinition<number, [count: number]>;
|
|
41
|
+
numeric: RegleRuleDefinition<number | string>;
|
|
42
|
+
requireUnless: RegleRuleWithParamsDefinition<unknown, [condition: boolean]>;
|
|
43
|
+
sameAs: RegleRuleWithParamsDefinition<unknown, [target: unknown]>;
|
|
44
|
+
url: RegleRuleDefinition<string>;
|
|
30
45
|
};
|
|
31
46
|
|
|
32
47
|
type ParamDecl<T = any> = MaybeRef<T> | (() => T);
|
package/dist/index.js
CHANGED
|
@@ -84,7 +84,7 @@ function createRule(definition) {
|
|
|
84
84
|
}
|
|
85
85
|
|
|
86
86
|
// src/core/useRegle/useRegle.ts
|
|
87
|
-
import { computed as computed5, isRef as isRef2, shallowRef as shallowRef2, toRaw } from "vue";
|
|
87
|
+
import { computed as computed5, isRef as isRef2, shallowRef as shallowRef2, toRaw as toRaw2 } from "vue";
|
|
88
88
|
|
|
89
89
|
// src/core/useRegle/useStateProperties/useStateProperties.ts
|
|
90
90
|
import { reactive as reactive5 } from "vue";
|
|
@@ -210,7 +210,7 @@ function useErrors($regle) {
|
|
|
210
210
|
import { computed as computed4, effectScope as effectScope4, reactive as reactive4, toRef as toRef4, watch as watch4 } from "vue";
|
|
211
211
|
|
|
212
212
|
// src/core/useRegle/useStateProperties/createReactiveCollectionStatus.ts
|
|
213
|
-
import { reactive as reactive3, ref as ref3, toRef as toRef3, toRefs, watch as watch3 } from "vue";
|
|
213
|
+
import { nextTick, reactive as reactive3, ref as ref3, toRef as toRef3, toRefs, watch as watch3 } from "vue";
|
|
214
214
|
|
|
215
215
|
// src/core/useRegle/useStateProperties/createReactiveFieldStatus.ts
|
|
216
216
|
import {
|
|
@@ -399,6 +399,9 @@ function createReactiveFieldStatus({
|
|
|
399
399
|
$watch();
|
|
400
400
|
if (storeResult?.valid != null) {
|
|
401
401
|
$dirty.value = storage.getDirtyState(path);
|
|
402
|
+
if ($dirty.value) {
|
|
403
|
+
$commit();
|
|
404
|
+
}
|
|
402
405
|
}
|
|
403
406
|
storage.addRuleDeclEntry(path, declaredRules);
|
|
404
407
|
}
|
|
@@ -532,12 +535,15 @@ function createCollectionElement({
|
|
|
532
535
|
customMessages,
|
|
533
536
|
rules
|
|
534
537
|
}) {
|
|
535
|
-
const $path = `${path}.${index}`;
|
|
536
538
|
const $id = randomId();
|
|
539
|
+
const $path = `${path}.${$id}`;
|
|
537
540
|
if (!value[index].$id) {
|
|
538
541
|
Object.defineProperties(value[index], {
|
|
539
542
|
$id: {
|
|
540
|
-
value: $id
|
|
543
|
+
value: $id,
|
|
544
|
+
enumerable: false,
|
|
545
|
+
configurable: false,
|
|
546
|
+
writable: false
|
|
541
547
|
}
|
|
542
548
|
});
|
|
543
549
|
}
|
|
@@ -584,27 +590,40 @@ function createReactiveCollectionStatus({
|
|
|
584
590
|
});
|
|
585
591
|
if (Array.isArray(state.value) && $each) {
|
|
586
592
|
$eachStatus.value = state.value.map((value, index) => {
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
593
|
+
if (value.$id) {
|
|
594
|
+
const previousStatus = storage.getArrayStatus(value.$id);
|
|
595
|
+
if (previousStatus) {
|
|
596
|
+
return previousStatus;
|
|
597
|
+
}
|
|
598
|
+
} else {
|
|
599
|
+
return createCollectionElement({
|
|
600
|
+
path,
|
|
601
|
+
rules: $each,
|
|
602
|
+
value: state.value,
|
|
603
|
+
index,
|
|
604
|
+
options,
|
|
605
|
+
storage
|
|
606
|
+
});
|
|
607
|
+
}
|
|
595
608
|
}).filter((f) => !!f);
|
|
596
609
|
} else {
|
|
597
610
|
$eachStatus.value = [];
|
|
598
611
|
}
|
|
599
612
|
}
|
|
600
|
-
function updateChildrenStatus() {
|
|
613
|
+
async function updateChildrenStatus() {
|
|
601
614
|
const { $each } = rulesDef.value;
|
|
602
615
|
if (Array.isArray(state.value) && $eachStatus.value && $each) {
|
|
616
|
+
$unwatchState?.();
|
|
603
617
|
state.value.forEach((value, index) => {
|
|
604
618
|
if (value.$id) {
|
|
619
|
+
if (Array.isArray(state.value) && !state.value.find((val) => val.$id === $eachStatus.value[index].$id)) {
|
|
620
|
+
$eachStatus.value[index].$unwatch();
|
|
621
|
+
}
|
|
605
622
|
const previousStatus = storage.getArrayStatus(value.$id);
|
|
606
623
|
if (previousStatus) {
|
|
607
624
|
$eachStatus.value[index] = previousStatus;
|
|
625
|
+
} else {
|
|
626
|
+
$eachStatus.value[index].$unwatch();
|
|
608
627
|
}
|
|
609
628
|
} else {
|
|
610
629
|
const newElement = createCollectionElement({
|
|
@@ -621,12 +640,15 @@ function createReactiveCollectionStatus({
|
|
|
621
640
|
}
|
|
622
641
|
}
|
|
623
642
|
});
|
|
624
|
-
}
|
|
625
|
-
if ($eachStatus.value) {
|
|
626
643
|
const deletedItems = $eachStatus.value.filter(($each2) => {
|
|
627
644
|
return Array.isArray(state.value) && !state.value.find((val) => val.$id === $each2.$id);
|
|
628
645
|
});
|
|
629
|
-
deletedItems.forEach((item) =>
|
|
646
|
+
deletedItems.forEach((item) => {
|
|
647
|
+
storage.deleteArrayStatus(item.$id);
|
|
648
|
+
item.$unwatch();
|
|
649
|
+
});
|
|
650
|
+
$eachStatus.value.length = state.value.length;
|
|
651
|
+
nextTick($watch);
|
|
630
652
|
}
|
|
631
653
|
}
|
|
632
654
|
function $unwatch() {
|
|
@@ -643,13 +665,9 @@ function createReactiveCollectionStatus({
|
|
|
643
665
|
}
|
|
644
666
|
}
|
|
645
667
|
function $watch() {
|
|
646
|
-
$unwatchState = watch3(
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
updateChildrenStatus();
|
|
650
|
-
},
|
|
651
|
-
{ deep: true, flush: "sync" }
|
|
652
|
-
);
|
|
668
|
+
$unwatchState = watch3(() => state.value.length, updateChildrenStatus, {
|
|
669
|
+
flush: "sync"
|
|
670
|
+
});
|
|
653
671
|
}
|
|
654
672
|
function $touch() {
|
|
655
673
|
$fieldStatus.value.$touch();
|
|
@@ -895,6 +913,11 @@ function useStorage() {
|
|
|
895
913
|
function getArrayStatus($id) {
|
|
896
914
|
return arrayStatusStorage.value.get($id);
|
|
897
915
|
}
|
|
916
|
+
function deleteArrayStatus($id) {
|
|
917
|
+
if ($id) {
|
|
918
|
+
arrayStatusStorage.value.delete($id);
|
|
919
|
+
}
|
|
920
|
+
}
|
|
898
921
|
function setDirtyEntry($path, dirty) {
|
|
899
922
|
dirtyStorage.value.set($path, dirty);
|
|
900
923
|
}
|
|
@@ -956,7 +979,8 @@ function useStorage() {
|
|
|
956
979
|
getFieldsEntry,
|
|
957
980
|
getCollectionsEntry,
|
|
958
981
|
getArrayStatus,
|
|
959
|
-
addArrayStatus
|
|
982
|
+
addArrayStatus,
|
|
983
|
+
deleteArrayStatus
|
|
960
984
|
};
|
|
961
985
|
}
|
|
962
986
|
|
|
@@ -990,7 +1014,7 @@ function createUseRegleComposable(customRules, options) {
|
|
|
990
1014
|
...globalOptions,
|
|
991
1015
|
...options2
|
|
992
1016
|
};
|
|
993
|
-
const initialState = shallowRef2(structuredClone(
|
|
1017
|
+
const initialState = shallowRef2(structuredClone(toRaw2(state.value)));
|
|
994
1018
|
const { $regle, errors } = useStateProperties(
|
|
995
1019
|
scopeRules,
|
|
996
1020
|
state,
|
|
@@ -998,7 +1022,7 @@ function createUseRegleComposable(customRules, options) {
|
|
|
998
1022
|
customRules
|
|
999
1023
|
);
|
|
1000
1024
|
function resetForm() {
|
|
1001
|
-
state.value =
|
|
1025
|
+
state.value = toRaw2(initialState.value);
|
|
1002
1026
|
$regle.$reset();
|
|
1003
1027
|
}
|
|
1004
1028
|
async function validateForm() {
|