@regle/core 0.6.1-beta.1 → 0.7.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.
@@ -4,7 +4,7 @@ var vue = require('vue');
4
4
 
5
5
  // ../shared/utils/isEmpty.ts
6
6
  function isEmpty(value) {
7
- if (value === void 0 || value === null) {
7
+ if (value === undefined || value === null) {
8
8
  return true;
9
9
  }
10
10
  if (value instanceof Date) {
@@ -310,7 +310,7 @@ function useStorage() {
310
310
  }
311
311
  function checkRuleDeclEntry($path, newRules) {
312
312
  const storedRulesDefs = ruleDeclStorage.value.get($path);
313
- if (!storedRulesDefs) return void 0;
313
+ if (!storedRulesDefs) return undefined;
314
314
  const storedRules = storedRulesDefs;
315
315
  const isValidCache = areRulesChanged(newRules, storedRules);
316
316
  if (!isValidCache) return { valid: false };
@@ -405,7 +405,7 @@ function debounce(func, wait, immediate) {
405
405
  const debouncedFn = (...args) => new Promise((resolve) => {
406
406
  clearTimeout(timeout);
407
407
  timeout = setTimeout(() => {
408
- timeout = void 0;
408
+ timeout = undefined;
409
409
  {
410
410
  Promise.resolve(func.apply(this, [...args])).then(resolve);
411
411
  }
@@ -413,7 +413,7 @@ function debounce(func, wait, immediate) {
413
413
  });
414
414
  debouncedFn.cancel = () => {
415
415
  clearTimeout(timeout);
416
- timeout = void 0;
416
+ timeout = undefined;
417
417
  };
418
418
  return debouncedFn;
419
419
  }
@@ -475,10 +475,10 @@ function extractRulesErrors({
475
475
  field,
476
476
  silent = false
477
477
  }) {
478
- return Object.entries(field.$rules ?? {}).map(([ruleKey, rule]) => {
478
+ return Object.entries(field.$rules ?? {}).map(([_, rule]) => {
479
479
  if (silent) {
480
480
  return rule.$message;
481
- } else if (!rule.$valid && field.$dirty && !rule.$validating) {
481
+ } else if (!rule.$valid && field.$error && !rule.$validating) {
482
482
  return rule.$message;
483
483
  }
484
484
  return null;
@@ -488,10 +488,10 @@ function extractRulesErrors({
488
488
  } else {
489
489
  return acc?.concat(value);
490
490
  }
491
- }, []).concat(field.$dirty ? field.$externalErrors ?? [] : []);
491
+ }, []).concat(field.$error ? field.$externalErrors ?? [] : []).concat(field.$error ? field.$schemaErrors ?? [] : []);
492
492
  }
493
493
  function extractRulesTooltips({ field }) {
494
- return Object.entries(field.$rules ?? {}).map(([ruleKey, rule]) => rule.$tooltip).filter((tooltip) => !!tooltip).reduce((acc, value) => {
494
+ return Object.entries(field.$rules ?? {}).map(([_, rule]) => rule.$tooltip).filter((tooltip) => !!tooltip).reduce((acc, value) => {
495
495
  if (typeof value === "string") {
496
496
  return acc?.concat([value]);
497
497
  } else {
@@ -546,7 +546,7 @@ function createReactiveRuleStatus({
546
546
  });
547
547
  function computeRuleProcessor(key) {
548
548
  let result = "";
549
- const customProcessor = customMessages ? customMessages[ruleKey]?.[key] : void 0;
549
+ const customProcessor = customMessages ? customMessages[ruleKey]?.[key] : undefined;
550
550
  if (customProcessor) {
551
551
  if (typeof customProcessor === "function") {
552
552
  result = customProcessor($defaultMetadata.value);
@@ -720,6 +720,8 @@ function createReactiveFieldStatus({
720
720
  storage,
721
721
  options,
722
722
  externalErrors,
723
+ schemaErrors,
724
+ schemaMode,
723
725
  onUnwatch,
724
726
  $isArray,
725
727
  initialState,
@@ -812,7 +814,7 @@ function createReactiveFieldStatus({
812
814
  }
813
815
  scopeState = scope.run(() => {
814
816
  const $dirty = vue.ref(false);
815
- const triggerPunishment = vue.ref(false);
817
+ const triggerPunishment2 = vue.ref(false);
816
818
  const $anyDirty = vue.computed(() => $dirty.value);
817
819
  const $debounce2 = vue.computed(() => {
818
820
  return $localOptions.value.$debounce;
@@ -868,16 +870,25 @@ function createReactiveFieldStatus({
868
870
  return $invalid.value && !$pending.value && $dirty.value;
869
871
  });
870
872
  const $errors = vue.computed(() => {
871
- if ($error.value) {
872
- return extractRulesErrors({
873
- field: {
874
- $dirty: $dirty.value,
875
- $externalErrors: externalErrors?.value,
876
- $rules: $rules.value
877
- }
878
- });
879
- }
880
- return [];
873
+ return extractRulesErrors({
874
+ field: {
875
+ $error: $error.value,
876
+ $externalErrors: externalErrors?.value,
877
+ $schemaErrors: schemaErrors?.value,
878
+ $rules: $rules.value
879
+ }
880
+ });
881
+ });
882
+ const $silentErrors = vue.computed(() => {
883
+ return extractRulesErrors({
884
+ field: {
885
+ $error: true,
886
+ $externalErrors: externalErrors?.value,
887
+ $schemaErrors: schemaErrors?.value,
888
+ $rules: $rules.value
889
+ },
890
+ silent: true
891
+ });
881
892
  });
882
893
  const $edited = vue.computed(() => {
883
894
  if ($dirty.value) {
@@ -902,16 +913,6 @@ function createReactiveFieldStatus({
902
913
  }
903
914
  });
904
915
  });
905
- const $silentErrors = vue.computed(() => {
906
- return extractRulesErrors({
907
- field: {
908
- $dirty: $dirty.value,
909
- $externalErrors: externalErrors?.value,
910
- $rules: $rules.value
911
- },
912
- silent: true
913
- });
914
- });
915
916
  const $ready = vue.computed(() => {
916
917
  if (!$autoDirty2.value) {
917
918
  return !($invalid.value || $pending.value);
@@ -919,7 +920,7 @@ function createReactiveFieldStatus({
919
920
  return $anyDirty.value && !($invalid.value || $pending.value);
920
921
  });
921
922
  const $pending = vue.computed(() => {
922
- if (triggerPunishment.value || !$rewardEarly2.value) {
923
+ if (triggerPunishment2.value || !$rewardEarly2.value) {
923
924
  return Object.entries($rules.value).some(([key, ruleResult]) => {
924
925
  return ruleResult.$pending;
925
926
  });
@@ -927,11 +928,11 @@ function createReactiveFieldStatus({
927
928
  return false;
928
929
  });
929
930
  const $invalid = vue.computed(() => {
930
- if (externalErrors?.value?.length) {
931
+ if (externalErrors?.value?.length || schemaErrors?.value?.length) {
931
932
  return true;
932
- } else if (isEmpty($rules.value)) {
933
+ } else if ($inactive.value) {
933
934
  return false;
934
- } else if (!$rewardEarly2.value || $rewardEarly2.value && triggerPunishment.value) {
935
+ } else if (!$rewardEarly2.value || $rewardEarly2.value && triggerPunishment2.value) {
935
936
  return Object.entries($rules.value).some(([_, ruleResult]) => {
936
937
  return !ruleResult.$valid;
937
938
  });
@@ -940,7 +941,7 @@ function createReactiveFieldStatus({
940
941
  });
941
942
  const $name = vue.computed(() => fieldName);
942
943
  const $inactive = vue.computed(() => {
943
- if (isEmpty($rules.value)) {
944
+ if (isEmpty($rules.value) && !schemaMode) {
944
945
  return true;
945
946
  }
946
947
  return false;
@@ -951,9 +952,13 @@ function createReactiveFieldStatus({
951
952
  } else if ($inactive.value) {
952
953
  return false;
953
954
  } else if ($dirty.value && !isEmpty(state.value) && !$validating2.value) {
954
- return Object.values($rules.value).every((ruleResult) => {
955
- return ruleResult.$valid && ruleResult.$active;
956
- });
955
+ if (schemaMode) {
956
+ return !schemaErrors?.value?.length;
957
+ } else {
958
+ return Object.values($rules.value).every((ruleResult) => {
959
+ return ruleResult.$valid && ruleResult.$active;
960
+ });
961
+ }
957
962
  }
958
963
  return false;
959
964
  });
@@ -1001,7 +1006,7 @@ function createReactiveFieldStatus({
1001
1006
  const $shortcuts2 = {};
1002
1007
  vue.watch($invalid, (value) => {
1003
1008
  if (!value) {
1004
- triggerPunishment.value = false;
1009
+ triggerPunishment2.value = false;
1005
1010
  }
1006
1011
  });
1007
1012
  return {
@@ -1026,7 +1031,7 @@ function createReactiveFieldStatus({
1026
1031
  $validating: $validating2,
1027
1032
  $tooltips,
1028
1033
  $dirty,
1029
- triggerPunishment,
1034
+ triggerPunishment: triggerPunishment2,
1030
1035
  processShortcuts,
1031
1036
  $silentValue,
1032
1037
  $inactive
@@ -1109,7 +1114,9 @@ function createReactiveFieldStatus({
1109
1114
  } else if (scopeState.$autoDirty.value && scopeState.$dirty.value && !scopeState.$pending.value) {
1110
1115
  return { result: !scopeState.$error.value, data };
1111
1116
  }
1112
- if (isEmpty($rules.value)) {
1117
+ if (schemaMode) {
1118
+ return { result: !schemaErrors?.value?.length, data };
1119
+ } else if (isEmpty($rules.value)) {
1113
1120
  return { result: true, data };
1114
1121
  }
1115
1122
  const results = await Promise.allSettled(
@@ -1160,6 +1167,7 @@ function createReactiveFieldStatus({
1160
1167
  $haveAnyAsyncRule,
1161
1168
  $debounce,
1162
1169
  $lazy,
1170
+ triggerPunishment,
1163
1171
  ...restScope
1164
1172
  } = scopeState;
1165
1173
  return vue.reactive({
@@ -1188,9 +1196,11 @@ function createCollectionElement({
1188
1196
  customMessages,
1189
1197
  rules,
1190
1198
  externalErrors,
1199
+ schemaErrors,
1191
1200
  initialState,
1192
1201
  shortcuts,
1193
- fieldName
1202
+ fieldName,
1203
+ schemaMode
1194
1204
  }) {
1195
1205
  const $fieldId = rules.$key ? rules.$key : randomId();
1196
1206
  let $path = `${path}.${String($fieldId)}`;
@@ -1208,6 +1218,8 @@ function createCollectionElement({
1208
1218
  $path = `${path}.${stateValue.value.$id}`;
1209
1219
  }
1210
1220
  }
1221
+ const $externalErrors = vue.toRef(externalErrors?.value ?? [], index);
1222
+ const $schemaErrors = vue.computed(() => schemaErrors?.value?.[index]);
1211
1223
  const $status = createReactiveChildrenStatus({
1212
1224
  state: stateValue,
1213
1225
  rulesDef: vue.toRef(() => rules),
@@ -1215,10 +1227,12 @@ function createCollectionElement({
1215
1227
  path: $path,
1216
1228
  storage,
1217
1229
  options,
1218
- externalErrors: vue.toRef(externalErrors?.value ?? [], index),
1230
+ externalErrors: $externalErrors,
1231
+ schemaErrors: $schemaErrors,
1219
1232
  initialState,
1220
1233
  shortcuts,
1221
- fieldName
1234
+ fieldName,
1235
+ schemaMode
1222
1236
  });
1223
1237
  if ($status) {
1224
1238
  const valueId = stateValue.value?.$id;
@@ -1237,6 +1251,8 @@ function createReactiveCollectionStatus({
1237
1251
  storage,
1238
1252
  options,
1239
1253
  externalErrors,
1254
+ schemaErrors,
1255
+ schemaMode,
1240
1256
  initialState,
1241
1257
  shortcuts,
1242
1258
  fieldName
@@ -1247,7 +1263,7 @@ function createReactiveCollectionStatus({
1247
1263
  let immediateScopeState;
1248
1264
  let collectionScopes = [];
1249
1265
  if (!Array.isArray(state.value) && !rulesDef.value.$each) {
1250
- return void 0;
1266
+ return undefined;
1251
1267
  }
1252
1268
  const $id = vue.ref();
1253
1269
  const $value = vue.ref(state.value);
@@ -1300,6 +1316,8 @@ function createReactiveCollectionStatus({
1300
1316
  collectionScopes.push(scope2);
1301
1317
  }
1302
1318
  const initialStateRef = vue.toRef(initialState.value ?? [], index);
1319
+ const $externalErrors = vue.toRef(externalErrors?.value ?? {}, `$each`);
1320
+ const $schemaErrors = vue.computed(() => schemaErrors?.value?.$each);
1303
1321
  const element = createCollectionElement({
1304
1322
  $id: $id.value,
1305
1323
  path,
@@ -1309,10 +1327,12 @@ function createReactiveCollectionStatus({
1309
1327
  index,
1310
1328
  options,
1311
1329
  storage,
1312
- externalErrors: vue.toRef(externalErrors?.value ?? {}, `$each`),
1330
+ externalErrors: $externalErrors,
1331
+ schemaErrors: $schemaErrors,
1313
1332
  initialState: initialStateRef,
1314
1333
  shortcuts,
1315
- fieldName
1334
+ fieldName,
1335
+ schemaMode
1316
1336
  });
1317
1337
  if (element) {
1318
1338
  return element;
@@ -1330,10 +1350,12 @@ function createReactiveCollectionStatus({
1330
1350
  storage,
1331
1351
  options,
1332
1352
  externalErrors: vue.toRef(externalErrors?.value ?? {}, `$self`),
1353
+ schemaErrors: vue.computed(() => schemaErrors?.value?.$self),
1333
1354
  $isArray: true,
1334
1355
  initialState,
1335
1356
  shortcuts,
1336
- fieldName
1357
+ fieldName,
1358
+ schemaMode
1337
1359
  });
1338
1360
  }
1339
1361
  function updateStatus() {
@@ -1353,29 +1375,31 @@ function createReactiveCollectionStatus({
1353
1375
  if (scope2) {
1354
1376
  collectionScopes.push(scope2);
1355
1377
  }
1356
- if (unwrapped) {
1357
- const element = createCollectionElement({
1358
- $id: $id.value,
1359
- path,
1360
- customMessages,
1361
- rules: unwrapped,
1362
- stateValue: currentValue,
1363
- index,
1364
- options,
1365
- storage,
1366
- externalErrors: vue.toRef(externalErrors?.value ?? {}, `$each`),
1367
- initialState: vue.toRef(initialState.value ?? [], index),
1368
- shortcuts,
1369
- fieldName
1370
- });
1371
- if (element) {
1372
- return element;
1373
- }
1374
- return null;
1378
+ const $externalErrors = vue.toRef(externalErrors?.value ?? {}, `$each`);
1379
+ const $schemaErrors = vue.computed(() => schemaErrors?.value?.$each ?? []);
1380
+ const element = createCollectionElement({
1381
+ $id: $id.value,
1382
+ path,
1383
+ customMessages,
1384
+ rules: unwrapped ?? {},
1385
+ stateValue: currentValue,
1386
+ index,
1387
+ options,
1388
+ storage,
1389
+ externalErrors: $externalErrors,
1390
+ schemaErrors: $schemaErrors,
1391
+ initialState: vue.toRef(initialState.value ?? [], index),
1392
+ shortcuts,
1393
+ fieldName,
1394
+ schemaMode
1395
+ });
1396
+ if (element) {
1397
+ return element;
1375
1398
  }
1399
+ return null;
1376
1400
  }
1377
1401
  }).filter((each) => !!each);
1378
- previousStatus.filter(($each) => !state.value.find((f) => $each.$id === f.$id)).forEach(($each, index) => {
1402
+ previousStatus.filter(($each) => !state.value?.find((f) => $each.$id === f.$id)).forEach((_, index) => {
1379
1403
  storage.deleteArrayStatus($id.value, index.toString());
1380
1404
  });
1381
1405
  } else {
@@ -1628,6 +1652,8 @@ function createReactiveNestedStatus({
1628
1652
  path = "",
1629
1653
  rootRules,
1630
1654
  externalErrors,
1655
+ schemaErrors,
1656
+ rootSchemaErrors,
1631
1657
  validationGroups,
1632
1658
  initialState,
1633
1659
  fieldName,
@@ -1637,6 +1663,7 @@ function createReactiveNestedStatus({
1637
1663
  let scopeState;
1638
1664
  let nestedScopes = [];
1639
1665
  let $unwatchRules = null;
1666
+ let $unwatchSchemaErrors = null;
1640
1667
  let $unwatchExternalErrors = null;
1641
1668
  let $unwatchState = null;
1642
1669
  async function createReactiveFieldsStatus(watchSources = true) {
@@ -1647,6 +1674,7 @@ function createReactiveNestedStatus({
1647
1674
  const stateRef = vue.toRef(state.value ?? {}, statePropKey);
1648
1675
  const statePropRulesRef = vue.toRef(() => statePropRules);
1649
1676
  const $externalErrors = vue.toRef(externalErrors?.value ?? {}, statePropKey);
1677
+ const $schemaErrors = vue.computed(() => schemaErrors?.value?.[statePropKey]);
1650
1678
  const initialStateRef = vue.toRef(initialState?.value ?? {}, statePropKey);
1651
1679
  return [
1652
1680
  statePropKey,
@@ -1655,6 +1683,7 @@ function createReactiveNestedStatus({
1655
1683
  rulesDef: statePropRulesRef,
1656
1684
  path: path ? `${path}.${statePropKey}` : statePropKey,
1657
1685
  externalErrors: $externalErrors,
1686
+ schemaErrors: $schemaErrors,
1658
1687
  initialState: initialStateRef,
1659
1688
  fieldName: statePropKey,
1660
1689
  ...commonArgs
@@ -1667,6 +1696,8 @@ function createReactiveNestedStatus({
1667
1696
  const externalRulesStatus = Object.fromEntries(
1668
1697
  Object.entries(vue.unref(externalErrors) ?? {}).filter(([key, errors]) => !(key in rulesDef.value) && !!errors).map(([key]) => {
1669
1698
  const stateRef = vue.toRef(state.value ?? {}, key);
1699
+ const $externalErrors = vue.toRef(externalErrors?.value ?? {}, key);
1700
+ const $schemaErrors = vue.computed(() => schemaErrors?.value?.[key]);
1670
1701
  const initialStateRef = vue.toRef(initialState?.value ?? {}, key);
1671
1702
  return [
1672
1703
  key,
@@ -1674,7 +1705,29 @@ function createReactiveNestedStatus({
1674
1705
  state: stateRef,
1675
1706
  rulesDef: vue.computed(() => ({})),
1676
1707
  path: path ? `${path}.${key}` : key,
1677
- externalErrors: vue.toRef(externalErrors?.value ?? {}, key),
1708
+ externalErrors: $externalErrors,
1709
+ schemaErrors: $schemaErrors,
1710
+ initialState: initialStateRef,
1711
+ fieldName: key,
1712
+ ...commonArgs
1713
+ })
1714
+ ];
1715
+ })
1716
+ );
1717
+ const schemasRulesStatus = Object.fromEntries(
1718
+ Object.entries(vue.unref(schemaErrors) ?? {}).map(([key]) => {
1719
+ const stateRef = vue.toRef(state.value ?? {}, key);
1720
+ const $externalErrors = vue.toRef(externalErrors?.value ?? {}, key);
1721
+ const $schemaErrors = vue.computed(() => schemaErrors?.value?.[key]);
1722
+ const initialStateRef = vue.toRef(initialState?.value ?? {}, key);
1723
+ return [
1724
+ key,
1725
+ createReactiveChildrenStatus({
1726
+ state: stateRef,
1727
+ rulesDef: vue.computed(() => ({})),
1728
+ path: path ? `${path}.${key}` : key,
1729
+ externalErrors: $externalErrors,
1730
+ schemaErrors: $schemaErrors,
1678
1731
  initialState: initialStateRef,
1679
1732
  fieldName: key,
1680
1733
  ...commonArgs
@@ -1683,8 +1736,12 @@ function createReactiveNestedStatus({
1683
1736
  })
1684
1737
  );
1685
1738
  const statesWithNoRules = Object.fromEntries(
1686
- Object.entries(state.value ?? {}).filter(([key]) => !(key in rulesDef.value) && !(key in (externalRulesStatus.value ?? {}))).map(([key]) => {
1739
+ Object.entries(state.value ?? {}).filter(
1740
+ ([key]) => !(key in rulesDef.value) && !(key in (externalRulesStatus ?? {})) && !(key in (schemasRulesStatus ?? {}))
1741
+ ).map(([key]) => {
1687
1742
  const stateRef = vue.toRef(state.value ?? {}, key);
1743
+ const $externalErrors = vue.toRef(externalErrors?.value ?? {}, key);
1744
+ const $schemaErrors = vue.computed(() => schemaErrors?.value?.[key]);
1688
1745
  const initialStateRef = vue.toRef(initialState?.value ?? {}, key);
1689
1746
  return [
1690
1747
  key,
@@ -1692,7 +1749,8 @@ function createReactiveNestedStatus({
1692
1749
  state: stateRef,
1693
1750
  rulesDef: vue.computed(() => ({})),
1694
1751
  path: path ? `${path}.${key}` : key,
1695
- externalErrors: vue.toRef(externalErrors?.value ?? {}, key),
1752
+ externalErrors: $externalErrors,
1753
+ schemaErrors: $schemaErrors,
1696
1754
  initialState: initialStateRef,
1697
1755
  fieldName: key,
1698
1756
  ...commonArgs
@@ -1703,6 +1761,7 @@ function createReactiveNestedStatus({
1703
1761
  $fields.value = {
1704
1762
  ...scopedRulesStatus,
1705
1763
  ...externalRulesStatus,
1764
+ ...schemasRulesStatus,
1706
1765
  ...statesWithNoRules
1707
1766
  };
1708
1767
  if (watchSources) {
@@ -1725,7 +1784,7 @@ function createReactiveNestedStatus({
1725
1784
  });
1726
1785
  }
1727
1786
  function define$WatchExternalErrors() {
1728
- if (externalErrors?.value) {
1787
+ if (externalErrors) {
1729
1788
  $unwatchExternalErrors = vue.watch(
1730
1789
  externalErrors,
1731
1790
  () => {
@@ -1760,6 +1819,17 @@ function createReactiveNestedStatus({
1760
1819
  );
1761
1820
  define$WatchExternalErrors();
1762
1821
  }
1822
+ if (rootSchemaErrors) {
1823
+ $unwatchSchemaErrors?.();
1824
+ $unwatchSchemaErrors = vue.watch(
1825
+ rootSchemaErrors,
1826
+ () => {
1827
+ $unwatch();
1828
+ createReactiveFieldsStatus();
1829
+ },
1830
+ { deep: true, flush: "post" }
1831
+ );
1832
+ }
1763
1833
  define$watchState();
1764
1834
  scope = vue.effectScope();
1765
1835
  scopeState = scope.run(() => {
@@ -1821,8 +1891,9 @@ function createReactiveNestedStatus({
1821
1891
  }
1822
1892
  return $anyDirty.value && !($invalid.value || $pending.value);
1823
1893
  });
1894
+ const $localPending2 = vue.ref(false);
1824
1895
  const $pending = vue.computed(() => {
1825
- return Object.entries($fields.value).some(([key, statusOrField]) => {
1896
+ return $localPending2.value || Object.entries($fields.value).some(([key, statusOrField]) => {
1826
1897
  return statusOrField?.$pending;
1827
1898
  });
1828
1899
  });
@@ -1934,7 +2005,8 @@ function createReactiveNestedStatus({
1934
2005
  $groups,
1935
2006
  $silentValue,
1936
2007
  $edited,
1937
- $anyEdited
2008
+ $anyEdited,
2009
+ $localPending: $localPending2
1938
2010
  };
1939
2011
  });
1940
2012
  }
@@ -1984,25 +2056,37 @@ function createReactiveNestedStatus({
1984
2056
  }
1985
2057
  async function $validate() {
1986
2058
  try {
1987
- const data = state.value;
1988
- const results = await Promise.allSettled(
1989
- Object.values($fields.value).map((statusOrField) => {
1990
- return statusOrField.$validate();
1991
- })
1992
- );
1993
- const validationResults = results.every((value) => {
1994
- if (value.status === "fulfilled") {
1995
- return value.value.result === true;
2059
+ if (commonArgs.schemaMode) {
2060
+ if (commonArgs.onValidate) {
2061
+ $touch(false);
2062
+ scopeState.$localPending.value = true;
2063
+ return commonArgs.onValidate();
1996
2064
  } else {
1997
- return false;
2065
+ return { result: false, data: state.value };
1998
2066
  }
1999
- });
2000
- return { result: validationResults, data };
2067
+ } else {
2068
+ const data = state.value;
2069
+ const results = await Promise.allSettled(
2070
+ Object.values($fields.value).map((statusOrField) => {
2071
+ return statusOrField.$validate();
2072
+ })
2073
+ );
2074
+ const validationResults = results.every((value) => {
2075
+ if (value.status === "fulfilled") {
2076
+ return value.value.result === true;
2077
+ } else {
2078
+ return false;
2079
+ }
2080
+ });
2081
+ return { result: validationResults, data };
2082
+ }
2001
2083
  } catch (e) {
2002
2084
  return { result: false, data: state.value };
2085
+ } finally {
2086
+ scopeState.$localPending.value = false;
2003
2087
  }
2004
2088
  }
2005
- const { $shortcuts, ...restScopeState } = scopeState;
2089
+ const { $shortcuts, $localPending, ...restScopeState } = scopeState;
2006
2090
  return vue.reactive({
2007
2091
  ...restScopeState,
2008
2092
  ...$shortcuts,
@@ -2020,48 +2104,53 @@ function createReactiveNestedStatus({
2020
2104
  }
2021
2105
  function createReactiveChildrenStatus({
2022
2106
  rulesDef,
2023
- externalErrors,
2024
2107
  ...properties
2025
2108
  }) {
2026
2109
  if (isCollectionRulesDef(rulesDef, properties.state)) {
2027
2110
  return createReactiveCollectionStatus({
2028
2111
  rulesDef,
2029
- externalErrors,
2030
2112
  ...properties
2031
2113
  });
2032
2114
  } else if (isNestedRulesDef(properties.state, rulesDef)) {
2033
2115
  if (isRefObject(properties.state)) {
2034
2116
  return createReactiveNestedStatus({
2035
2117
  rulesDef,
2036
- externalErrors,
2037
2118
  ...properties
2038
2119
  });
2039
2120
  } else {
2040
- const fakeState = vue.ref({});
2041
- const unwatchState = vue.watch(
2042
- fakeState,
2043
- (value) => {
2044
- unwatchState();
2045
- properties.state.value = value;
2046
- },
2047
- { deep: true }
2048
- );
2121
+ const scope = vue.effectScope();
2122
+ const scopeState = scope.run(() => {
2123
+ const fakeState = vue.toRef(properties.state.value ? properties.state : vue.ref({}));
2124
+ vue.watch(
2125
+ () => properties.state.value,
2126
+ (value) => {
2127
+ fakeState.value = value;
2128
+ },
2129
+ { deep: true }
2130
+ );
2131
+ vue.watch(
2132
+ fakeState,
2133
+ (value) => {
2134
+ properties.state.value = value;
2135
+ },
2136
+ { deep: true }
2137
+ );
2138
+ return { fakeState };
2139
+ });
2049
2140
  const { state, ...restProperties } = properties;
2050
2141
  return createReactiveNestedStatus({
2051
2142
  rulesDef,
2052
- externalErrors,
2053
2143
  ...restProperties,
2054
- state: fakeState
2144
+ state: scopeState.fakeState
2055
2145
  });
2056
2146
  }
2057
2147
  } else if (isValidatorRulesDef(rulesDef)) {
2058
2148
  return createReactiveFieldStatus({
2059
2149
  rulesDef,
2060
- externalErrors,
2061
2150
  ...properties
2062
2151
  });
2063
2152
  }
2064
- return void 0;
2153
+ return undefined;
2065
2154
  }
2066
2155
 
2067
2156
  // src/core/useRegle/root/useRootStorage.ts
@@ -2071,7 +2160,10 @@ function useRootStorage({
2071
2160
  scopeRules,
2072
2161
  state,
2073
2162
  customRules,
2074
- shortcuts
2163
+ shortcuts,
2164
+ schemaErrors,
2165
+ schemaMode = false,
2166
+ onValidate
2075
2167
  }) {
2076
2168
  const storage = useStorage();
2077
2169
  const regle = vue.ref();
@@ -2087,7 +2179,11 @@ function useRootStorage({
2087
2179
  initialState,
2088
2180
  shortcuts,
2089
2181
  fieldName: "root",
2090
- path: ""
2182
+ path: "",
2183
+ schemaErrors,
2184
+ rootSchemaErrors: schemaErrors,
2185
+ schemaMode,
2186
+ onValidate
2091
2187
  });
2092
2188
  if (vue.getCurrentScope()) {
2093
2189
  vue.onScopeDispose(() => {