@regle/core 1.26.1 → 1.27.0-beta.1
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/regle-core.d.ts +44 -10
- package/dist/regle-core.js +245 -59
- package/dist/regle-core.min.js +2 -2
- package/package.json +7 -7
package/dist/regle-core.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @regle/core v1.
|
|
2
|
+
* @regle/core v1.27.0-beta.1
|
|
3
3
|
* (c) 2026 Victor Garcia
|
|
4
4
|
* @license MIT
|
|
5
5
|
*/
|
|
@@ -759,7 +759,6 @@ const REGLE_FLAGS = { REGLE_STATIC: "__regle_static" };
|
|
|
759
759
|
function isRegleDevtoolsTestEnv() {
|
|
760
760
|
return Boolean(typeof globalThis !== "undefined" && ("__vitest_worker__" in globalThis || "__JEST_GLOBAL__" in globalThis || typeof window !== "undefined" && "Cypress" in window || typeof process !== "undefined" && process.env && (process.env.VITEST || process.env.JEST_WORKER_ID || process.env.NODE_ENV === "test" || process.env.PLAYWRIGHT_TEST)));
|
|
761
761
|
}
|
|
762
|
-
/*#__PURE__*/
|
|
763
762
|
function useRegleDevtoolsRegistry() {
|
|
764
763
|
const loggedWarning = ref(false);
|
|
765
764
|
const devtoolsApi = shallowRef();
|
|
@@ -834,7 +833,6 @@ function useRegleDevtoolsRegistry() {
|
|
|
834
833
|
loggedWarning
|
|
835
834
|
};
|
|
836
835
|
}
|
|
837
|
-
/*#__PURE__*/
|
|
838
836
|
const regleDevtoolsRegistry = useRegleDevtoolsRegistry();
|
|
839
837
|
/**
|
|
840
838
|
* To be used by `useRegle` like composables.
|
|
@@ -1357,7 +1355,7 @@ function filterInspectorTree(nodes, filter) {
|
|
|
1357
1355
|
}
|
|
1358
1356
|
return filtered;
|
|
1359
1357
|
}
|
|
1360
|
-
var version$1 = "1.
|
|
1358
|
+
var version$1 = "1.27.0-beta.1";
|
|
1361
1359
|
function createDevtools(app) {
|
|
1362
1360
|
setupDevtoolsPlugin({
|
|
1363
1361
|
id: "regle-devtools",
|
|
@@ -1545,15 +1543,18 @@ function useStorage() {
|
|
|
1545
1543
|
};
|
|
1546
1544
|
}
|
|
1547
1545
|
}
|
|
1548
|
-
|
|
1546
|
+
function clearAll() {
|
|
1549
1547
|
ruleDeclStorage.value.clear();
|
|
1550
1548
|
fieldsStorage.value.clear();
|
|
1551
1549
|
collectionsStorage.value.clear();
|
|
1552
1550
|
dirtyStorage.value.clear();
|
|
1553
1551
|
ruleStatusStorage.value.clear();
|
|
1552
|
+
additionalRulesStorage.value.clear();
|
|
1554
1553
|
arrayStatusStorage.value.clear();
|
|
1555
|
-
}
|
|
1554
|
+
}
|
|
1555
|
+
if (getCurrentScope()) onScopeDispose(clearAll);
|
|
1556
1556
|
return {
|
|
1557
|
+
clearAll,
|
|
1557
1558
|
addRuleDeclEntry,
|
|
1558
1559
|
setDirtyEntry,
|
|
1559
1560
|
checkRuleDeclEntry,
|
|
@@ -1590,17 +1591,23 @@ function extractRulesIssues({ field, silent = false }) {
|
|
|
1590
1591
|
})));
|
|
1591
1592
|
return acc;
|
|
1592
1593
|
}, []);
|
|
1593
|
-
const
|
|
1594
|
+
const externalErrorIssues = field.$error && field.$externalErrors && Array.isArray(field.$externalErrors) && !field.$externalIssues?.length ? field.$externalErrors.map((error) => ({
|
|
1594
1595
|
$message: error,
|
|
1595
1596
|
$property: field.fieldName,
|
|
1596
1597
|
$rule: "external",
|
|
1597
1598
|
$type: void 0
|
|
1598
1599
|
})) : [];
|
|
1600
|
+
const externalIssues = field.$error && field.$externalIssues && Array.isArray(field.$externalIssues) ? field.$externalIssues.map((issue) => ({
|
|
1601
|
+
...issue,
|
|
1602
|
+
$property: issue.$property ?? field.fieldName,
|
|
1603
|
+
$rule: issue.$rule ?? "external"
|
|
1604
|
+
})) : [];
|
|
1599
1605
|
let schemaIssues = [];
|
|
1600
1606
|
if (field.$schemaErrors && field.$error) if (!Array.isArray(field.$schemaErrors) && "$self" in field.$schemaErrors) schemaIssues = field.$schemaErrors.$self ?? [];
|
|
1601
1607
|
else schemaIssues = field.$schemaErrors ?? [];
|
|
1602
1608
|
return [
|
|
1603
1609
|
...ruleIssues,
|
|
1610
|
+
...externalErrorIssues,
|
|
1604
1611
|
...externalIssues,
|
|
1605
1612
|
...schemaIssues
|
|
1606
1613
|
];
|
|
@@ -1891,7 +1898,7 @@ function shouldApplyFieldImmediateDirty(mode, value, rootValue, isRootField = fa
|
|
|
1891
1898
|
return false;
|
|
1892
1899
|
}
|
|
1893
1900
|
const DEFAULT_DEBOUNCE_TIME = 200;
|
|
1894
|
-
function createReactiveFieldStatus({ state, rulesDef, customMessages, path, cachePath, fieldName, storage, options, externalErrors, schemaErrors, schemaMode, onUnwatch, $isArray, initialState, rootInitialState, originalState, shortcuts, overrides, onValidate }) {
|
|
1901
|
+
function createReactiveFieldStatus({ state, rulesDef, customMessages, path, cachePath, fieldName, storage, options, externalErrors, externalIssues, schemaErrors, schemaMode, onUnwatch, $isArray, initialState, rootInitialState, originalState, shortcuts, overrides, onValidate }) {
|
|
1895
1902
|
let scope = effectScope();
|
|
1896
1903
|
let scopeState;
|
|
1897
1904
|
let fieldScopes = [];
|
|
@@ -2074,6 +2081,7 @@ function createReactiveFieldStatus({ state, rulesDef, customMessages, path, cach
|
|
|
2074
2081
|
$rules: $rules.value,
|
|
2075
2082
|
$error: $error.value,
|
|
2076
2083
|
$externalErrors: externalErrors?.value,
|
|
2084
|
+
$externalIssues: externalIssues?.value,
|
|
2077
2085
|
$schemaErrors: schemaErrors?.value,
|
|
2078
2086
|
fieldName: $name.value
|
|
2079
2087
|
} });
|
|
@@ -2084,6 +2092,7 @@ function createReactiveFieldStatus({ state, rulesDef, customMessages, path, cach
|
|
|
2084
2092
|
$rules: $rules.value,
|
|
2085
2093
|
$error: $error.value,
|
|
2086
2094
|
$externalErrors: externalErrors?.value,
|
|
2095
|
+
$externalIssues: externalIssues?.value,
|
|
2087
2096
|
$schemaErrors: schemaErrors?.value,
|
|
2088
2097
|
fieldName: $name.value
|
|
2089
2098
|
},
|
|
@@ -2122,7 +2131,7 @@ function createReactiveFieldStatus({ state, rulesDef, customMessages, path, cach
|
|
|
2122
2131
|
return false;
|
|
2123
2132
|
});
|
|
2124
2133
|
const $invalid = computed(() => {
|
|
2125
|
-
if (externalErrors?.value?.length || schemaErrors?.value?.length) return true;
|
|
2134
|
+
if (externalErrors?.value?.length || externalIssues?.value?.length || schemaErrors?.value?.length) return true;
|
|
2126
2135
|
else if ($inactive.value) return false;
|
|
2127
2136
|
else return Object.values($rules.value).some((ruleResult) => !ruleResult.$valid || ruleResult.$maybePending);
|
|
2128
2137
|
});
|
|
@@ -2131,7 +2140,7 @@ function createReactiveFieldStatus({ state, rulesDef, customMessages, path, cach
|
|
|
2131
2140
|
return !schemaMode && !Object.keys($rules.value).some((key) => !key.startsWith("$"));
|
|
2132
2141
|
});
|
|
2133
2142
|
const $correct = computed(() => {
|
|
2134
|
-
if (externalErrors?.value?.length) return false;
|
|
2143
|
+
if (externalErrors?.value?.length || externalIssues?.value?.length) return false;
|
|
2135
2144
|
else if ($inactive.value) return false;
|
|
2136
2145
|
else if ($isDebouncing.value) return false;
|
|
2137
2146
|
else if ($dirty.value && !isEmpty(state.value) && !$validating.value && !$pending.value) if (schemaMode) return !schemaErrors?.value?.length;
|
|
@@ -2170,6 +2179,7 @@ function createReactiveFieldStatus({ state, rulesDef, customMessages, path, cach
|
|
|
2170
2179
|
result.value = value(reactive({
|
|
2171
2180
|
$dirty,
|
|
2172
2181
|
$externalErrors: externalErrors?.value ?? [],
|
|
2182
|
+
$externalIssues: externalIssues?.value ?? [],
|
|
2173
2183
|
$value: state,
|
|
2174
2184
|
$silentValue,
|
|
2175
2185
|
$rules,
|
|
@@ -2258,7 +2268,10 @@ function createReactiveFieldStatus({ state, rulesDef, customMessages, path, cach
|
|
|
2258
2268
|
}
|
|
2259
2269
|
if (rulesDef.value instanceof Function) createReactiveRulesResult();
|
|
2260
2270
|
if (!scopeState.$silent.value || scopeState.$rewardEarly.value && scopeState.$error.value) $commit();
|
|
2261
|
-
if (scopeState.$clearExternalErrorsOnChange.value)
|
|
2271
|
+
if (scopeState.$clearExternalErrorsOnChange.value) {
|
|
2272
|
+
$clearExternalErrors();
|
|
2273
|
+
$clearExternalIssues();
|
|
2274
|
+
}
|
|
2262
2275
|
}, { deep: scopeState.$isArrayOrRegleStatic.value ? true : isVueSuperiorOrEqualTo3dotFive ? 1 : true });
|
|
2263
2276
|
}
|
|
2264
2277
|
async function $commitHandler() {
|
|
@@ -2276,6 +2289,7 @@ function createReactiveFieldStatus({ state, rulesDef, customMessages, path, cach
|
|
|
2276
2289
|
function $reset(options, fromParent) {
|
|
2277
2290
|
abortCommit();
|
|
2278
2291
|
$clearExternalErrors();
|
|
2292
|
+
$clearExternalIssues();
|
|
2279
2293
|
scopeState.$dirty.value = false;
|
|
2280
2294
|
storage.setDirtyEntry(cachePath, false);
|
|
2281
2295
|
if (!fromParent) if (options?.toOriginalState) {
|
|
@@ -2289,7 +2303,10 @@ function createReactiveFieldStatus({ state, rulesDef, customMessages, path, cach
|
|
|
2289
2303
|
initialState.value = cloneDeep(newInitialState);
|
|
2290
2304
|
state.value = cloneDeep(newInitialState);
|
|
2291
2305
|
} else initialState.value = isObject(state.value) && !isStatic(state.value) ? cloneDeep(state.value) : Array.isArray(state.value) ? [...state.value] : state.value;
|
|
2292
|
-
if (options?.clearExternalErrors)
|
|
2306
|
+
if (options?.clearExternalErrors) {
|
|
2307
|
+
$clearExternalErrors();
|
|
2308
|
+
$clearExternalIssues();
|
|
2309
|
+
}
|
|
2293
2310
|
if (!fromParent && !options?.keepValidationState) for (const rule of Object.values($rules.value)) rule.$reset();
|
|
2294
2311
|
if (!scopeState.$lazy.value && !scopeState.$silent.value && !fromParent) for (const rule of Object.values($rules.value)) rule.$parse();
|
|
2295
2312
|
applyImmediateDirty();
|
|
@@ -2337,6 +2354,10 @@ function createReactiveFieldStatus({ state, rulesDef, customMessages, path, cach
|
|
|
2337
2354
|
issues: scopeState.$issues.value
|
|
2338
2355
|
};
|
|
2339
2356
|
const data = state.value;
|
|
2357
|
+
if (scopeState.$clearExternalErrorsOnValidate.value) {
|
|
2358
|
+
$clearExternalErrors();
|
|
2359
|
+
$clearExternalIssues();
|
|
2360
|
+
}
|
|
2340
2361
|
if (scopeState.$autoDirty.value && !scopeState.$silent.value && scopeState.$dirty.value && !scopeState.$validating.value && !scopeState.$pending.value && !$isDebouncing.value && !isEmpty($rules.value)) return {
|
|
2341
2362
|
valid: !scopeState.$invalid.value,
|
|
2342
2363
|
data,
|
|
@@ -2380,6 +2401,10 @@ function createReactiveFieldStatus({ state, rulesDef, customMessages, path, cach
|
|
|
2380
2401
|
if (forceValues) state.value = forceValues;
|
|
2381
2402
|
if (!scopeState.$dirty.value) scopeState.$dirty.value = true;
|
|
2382
2403
|
if (schemaMode) return false;
|
|
2404
|
+
if (scopeState.$clearExternalErrorsOnValidate.value) {
|
|
2405
|
+
$clearExternalErrors();
|
|
2406
|
+
$clearExternalIssues();
|
|
2407
|
+
}
|
|
2383
2408
|
return Object.values($rules.value).map((rule) => rule.$parseSync()).every((result) => !!result);
|
|
2384
2409
|
} catch {
|
|
2385
2410
|
return false;
|
|
@@ -2392,16 +2417,25 @@ function createReactiveFieldStatus({ state, rulesDef, customMessages, path, cach
|
|
|
2392
2417
|
}
|
|
2393
2418
|
function $setExternalErrors(errors) {
|
|
2394
2419
|
if (externalErrors) externalErrors.value = errors;
|
|
2420
|
+
$clearExternalIssues();
|
|
2395
2421
|
}
|
|
2396
2422
|
function $clearExternalErrors() {
|
|
2397
2423
|
if (externalErrors?.value?.length) externalErrors.value = [];
|
|
2398
2424
|
}
|
|
2425
|
+
function $setExternalIssues(issues) {
|
|
2426
|
+
if (externalIssues) externalIssues.value = issues;
|
|
2427
|
+
$clearExternalErrors();
|
|
2428
|
+
}
|
|
2429
|
+
function $clearExternalIssues() {
|
|
2430
|
+
if (externalIssues?.value?.length) externalIssues.value = [];
|
|
2431
|
+
}
|
|
2399
2432
|
if (!scopeState.$lazy.value && !scopeState.$dirty.value && !scopeState.$silent.value) $commitHandler();
|
|
2400
2433
|
applyImmediateDirty();
|
|
2401
2434
|
const { $shortcuts, $validating, $autoDirty, $rewardEarly, $clearExternalErrorsOnChange, $clearExternalErrorsOnValidate, $haveAnyAsyncRule, $debounce, $lazy, ...restScope } = scopeState;
|
|
2402
2435
|
const fullStatus = reactive({
|
|
2403
2436
|
...restScope,
|
|
2404
2437
|
$externalErrors: externalErrors,
|
|
2438
|
+
$externalIssues: externalIssues,
|
|
2405
2439
|
$value: state,
|
|
2406
2440
|
$output: state,
|
|
2407
2441
|
$initialValue: initialState,
|
|
@@ -2419,18 +2453,20 @@ function createReactiveFieldStatus({ state, rulesDef, customMessages, path, cach
|
|
|
2419
2453
|
$watch,
|
|
2420
2454
|
$extractDirtyFields,
|
|
2421
2455
|
$clearExternalErrors,
|
|
2456
|
+
$clearExternalIssues,
|
|
2422
2457
|
$abort,
|
|
2423
2458
|
$addRules,
|
|
2424
2459
|
addRules,
|
|
2425
2460
|
$schemaMode: schemaMode,
|
|
2426
2461
|
"~modifiers": scopeState.$modifiers,
|
|
2427
2462
|
$setExternalErrors,
|
|
2463
|
+
$setExternalIssues,
|
|
2428
2464
|
...createStandardSchema($validate)
|
|
2429
2465
|
});
|
|
2430
2466
|
Object.defineProperty(fullStatus, Symbol.for("regle:instance"), { value: true });
|
|
2431
2467
|
return fullStatus;
|
|
2432
2468
|
}
|
|
2433
|
-
function createCollectionElement({ $id, path, cachePath, index, options, storage, stateValue, customMessages, rules, externalErrors, schemaErrors, initialState, originalState, shortcuts, fieldName, schemaMode, overrides, currentIndexes }) {
|
|
2469
|
+
function createCollectionElement({ $id, path, cachePath, index, options, storage, stateValue, customMessages, rules, externalErrors, externalIssues, schemaErrors, initialState, originalState, shortcuts, fieldName, schemaMode, overrides, currentIndexes }) {
|
|
2434
2470
|
const computedRules = computed(() => toValue(rules));
|
|
2435
2471
|
const $fieldId = stateValue.value?.$id ?? computedRules.value.$key ?? randomId();
|
|
2436
2472
|
let $cachePath = `${cachePath}.${String($fieldId)}`;
|
|
@@ -2455,6 +2491,7 @@ function createCollectionElement({ $id, path, cachePath, index, options, storage
|
|
|
2455
2491
|
storage,
|
|
2456
2492
|
options,
|
|
2457
2493
|
externalErrors: toRef(externalErrors?.value ?? [], index),
|
|
2494
|
+
externalIssues: toRef(externalIssues?.value ?? [], index),
|
|
2458
2495
|
schemaErrors: computed(() => schemaErrors?.value?.[currentIndex.value]),
|
|
2459
2496
|
initialState,
|
|
2460
2497
|
originalState,
|
|
@@ -2471,7 +2508,7 @@ function createCollectionElement({ $id, path, cachePath, index, options, storage
|
|
|
2471
2508
|
if (stateValue.value && (!isObject(stateValue.value) || isStatic(stateValue.value)) && schemaMode) $status?.$touch();
|
|
2472
2509
|
return $status;
|
|
2473
2510
|
}
|
|
2474
|
-
function createReactiveCollectionStatus({ state, rulesDef, customMessages, path, cachePath, storage, options, externalErrors, schemaErrors, schemaMode, initialState, originalState, shortcuts, fieldName, overrides }) {
|
|
2511
|
+
function createReactiveCollectionStatus({ state, rulesDef, customMessages, path, cachePath, storage, options, externalErrors, externalIssues, schemaErrors, schemaMode, initialState, originalState, shortcuts, fieldName, overrides }) {
|
|
2475
2512
|
let scope = effectScope();
|
|
2476
2513
|
let scopeState;
|
|
2477
2514
|
let immediateScope = effectScope();
|
|
@@ -2515,6 +2552,7 @@ function createReactiveCollectionStatus({ state, rulesDef, customMessages, path,
|
|
|
2515
2552
|
if (scope) collectionScopes.push(scope);
|
|
2516
2553
|
const initialStateRef = toRef(initialState.value ?? [], index);
|
|
2517
2554
|
const $externalErrors = toRef(externalErrors?.value ?? {}, `$each`);
|
|
2555
|
+
const $externalIssues = toRef(externalIssues?.value ?? {}, `$each`);
|
|
2518
2556
|
const $schemaErrors = computed(() => schemaErrors?.value?.$each);
|
|
2519
2557
|
const element = createCollectionElement({
|
|
2520
2558
|
$id: $id.value,
|
|
@@ -2527,6 +2565,7 @@ function createReactiveCollectionStatus({ state, rulesDef, customMessages, path,
|
|
|
2527
2565
|
options,
|
|
2528
2566
|
storage,
|
|
2529
2567
|
externalErrors: $externalErrors,
|
|
2568
|
+
externalIssues: $externalIssues,
|
|
2530
2569
|
schemaErrors: $schemaErrors,
|
|
2531
2570
|
initialState: initialStateRef,
|
|
2532
2571
|
originalState,
|
|
@@ -2552,6 +2591,7 @@ function createReactiveCollectionStatus({ state, rulesDef, customMessages, path,
|
|
|
2552
2591
|
storage,
|
|
2553
2592
|
options,
|
|
2554
2593
|
externalErrors: toRef(externalErrors?.value ?? {}, `$self`),
|
|
2594
|
+
externalIssues: toRef(externalIssues?.value ?? {}, `$self`),
|
|
2555
2595
|
schemaErrors: computed(() => schemaErrors?.value?.$self),
|
|
2556
2596
|
$isArray: true,
|
|
2557
2597
|
initialState,
|
|
@@ -2582,6 +2622,7 @@ function createReactiveCollectionStatus({ state, rulesDef, customMessages, path,
|
|
|
2582
2622
|
const { scope, unwrapped } = unwrapGetter(rulesDef.value.$each, currentValue, index);
|
|
2583
2623
|
if (scope) collectionScopes.push(scope);
|
|
2584
2624
|
const $externalErrors = toRef(externalErrors?.value ?? {}, `$each`);
|
|
2625
|
+
const $externalIssues = toRef(externalIssues?.value ?? {}, `$each`);
|
|
2585
2626
|
const $schemaErrors = computed(() => schemaErrors?.value?.$each ?? []);
|
|
2586
2627
|
const element = createCollectionElement({
|
|
2587
2628
|
$id: $id.value,
|
|
@@ -2594,6 +2635,7 @@ function createReactiveCollectionStatus({ state, rulesDef, customMessages, path,
|
|
|
2594
2635
|
options,
|
|
2595
2636
|
storage,
|
|
2596
2637
|
externalErrors: $externalErrors,
|
|
2638
|
+
externalIssues: $externalIssues,
|
|
2597
2639
|
schemaErrors: $schemaErrors,
|
|
2598
2640
|
initialState: toRef(initialState.value ?? [], index),
|
|
2599
2641
|
originalState,
|
|
@@ -2854,7 +2896,10 @@ function createReactiveCollectionStatus({ state, rulesDef, customMessages, path,
|
|
|
2854
2896
|
initialState.value = cloneDeep(newInitialState);
|
|
2855
2897
|
state.value = cloneDeep(newInitialState);
|
|
2856
2898
|
} else initialState.value = cloneDeep(state.value);
|
|
2857
|
-
if (options?.clearExternalErrors)
|
|
2899
|
+
if (options?.clearExternalErrors) {
|
|
2900
|
+
$clearExternalErrors();
|
|
2901
|
+
$clearExternalIssues();
|
|
2902
|
+
}
|
|
2858
2903
|
if (!options?.keepValidationState) {
|
|
2859
2904
|
$selfStatus.value.$reset(options, fromParent);
|
|
2860
2905
|
$eachStatus.value.forEach(($each) => {
|
|
@@ -2915,7 +2960,8 @@ function createReactiveCollectionStatus({ state, rulesDef, customMessages, path,
|
|
|
2915
2960
|
}
|
|
2916
2961
|
}
|
|
2917
2962
|
function $setExternalErrors(errors) {
|
|
2918
|
-
if (externalErrors
|
|
2963
|
+
if (externalErrors) externalErrors.value = errors;
|
|
2964
|
+
$clearExternalIssues();
|
|
2919
2965
|
}
|
|
2920
2966
|
function $clearExternalErrors() {
|
|
2921
2967
|
$selfStatus.value.$clearExternalErrors();
|
|
@@ -2923,6 +2969,16 @@ function createReactiveCollectionStatus({ state, rulesDef, customMessages, path,
|
|
|
2923
2969
|
$each.$clearExternalErrors();
|
|
2924
2970
|
});
|
|
2925
2971
|
}
|
|
2972
|
+
function $setExternalIssues(issues) {
|
|
2973
|
+
if (externalIssues) externalIssues.value = issues;
|
|
2974
|
+
$clearExternalErrors();
|
|
2975
|
+
}
|
|
2976
|
+
function $clearExternalIssues() {
|
|
2977
|
+
$selfStatus.value.$clearExternalIssues();
|
|
2978
|
+
$eachStatus.value.forEach(($each) => {
|
|
2979
|
+
$each.$clearExternalIssues();
|
|
2980
|
+
});
|
|
2981
|
+
}
|
|
2926
2982
|
function $extractDirtyFields(filterNullishValues = true) {
|
|
2927
2983
|
let dirtyFields = $eachStatus.value.map(($each) => {
|
|
2928
2984
|
if (isNestedRulesStatus($each)) return $each.$extractDirtyFields(filterNullishValues);
|
|
@@ -2955,20 +3011,22 @@ function createReactiveCollectionStatus({ state, rulesDef, customMessages, path,
|
|
|
2955
3011
|
$abort,
|
|
2956
3012
|
$extractDirtyFields,
|
|
2957
3013
|
$clearExternalErrors,
|
|
3014
|
+
$clearExternalIssues,
|
|
2958
3015
|
$setExternalErrors,
|
|
3016
|
+
$setExternalIssues,
|
|
2959
3017
|
"~modifiers": scopeState.$modifiers,
|
|
2960
3018
|
...createStandardSchema($validate)
|
|
2961
3019
|
});
|
|
2962
3020
|
}
|
|
2963
|
-
function createReactiveNestedStatus({ rulesDef, state, path = "", cachePath, rootRules, externalErrors, schemaErrors, rootInitialState, rootSchemaErrors, validationGroups, initialState, originalState, fieldName, nestedReactiveRules, ...commonArgs }) {
|
|
3021
|
+
function createReactiveNestedStatus({ rulesDef, state, path = "", cachePath, rootRules, externalErrors, externalIssues, schemaErrors, rootInitialState, rootSchemaErrors, validationGroups, initialState, originalState, fieldName, nestedReactiveRules, ...commonArgs }) {
|
|
2964
3022
|
let scope = effectScope();
|
|
2965
3023
|
let scopeState;
|
|
2966
3024
|
let nestedScopes = [];
|
|
2967
3025
|
let $unwatchRules = null;
|
|
2968
3026
|
let $unwatchSchemaErrors = null;
|
|
2969
3027
|
let $unwatchExternalErrors = null;
|
|
3028
|
+
let $unwatchExternalIssues = null;
|
|
2970
3029
|
let $unwatchState = null;
|
|
2971
|
-
let $unwatchGroups = null;
|
|
2972
3030
|
const $selfStatus = ref(void 0);
|
|
2973
3031
|
async function createReactiveFieldsStatus(watchSources = true) {
|
|
2974
3032
|
const mapOfRulesDef = Object.entries(rulesDef.value).filter(([key]) => key !== "$self");
|
|
@@ -2977,6 +3035,7 @@ function createReactiveNestedStatus({ rulesDef, state, path = "", cachePath, roo
|
|
|
2977
3035
|
const stateRef = toRef(state.value ?? {}, statePropKey);
|
|
2978
3036
|
const statePropRulesRef = toRef(() => statePropRules);
|
|
2979
3037
|
const $externalErrors = toRef(externalErrors?.value ?? {}, statePropKey);
|
|
3038
|
+
const $externalIssues = toRef(externalIssues?.value ?? {}, statePropKey);
|
|
2980
3039
|
const $schemaErrors = computed(() => schemaErrors?.value?.[statePropKey]);
|
|
2981
3040
|
const initialStateRef = toRef(initialState?.value ?? {}, statePropKey);
|
|
2982
3041
|
acc.push([statePropKey, createReactiveChildrenStatus({
|
|
@@ -2985,6 +3044,7 @@ function createReactiveNestedStatus({ rulesDef, state, path = "", cachePath, roo
|
|
|
2985
3044
|
path: path ? `${path}.${statePropKey}` : statePropKey,
|
|
2986
3045
|
cachePath: cachePath ? `${cachePath}.${statePropKey}` : statePropKey,
|
|
2987
3046
|
externalErrors: $externalErrors,
|
|
3047
|
+
externalIssues: $externalIssues,
|
|
2988
3048
|
schemaErrors: $schemaErrors,
|
|
2989
3049
|
initialState: initialStateRef,
|
|
2990
3050
|
originalState: originalState?.[statePropKey],
|
|
@@ -2993,9 +3053,10 @@ function createReactiveNestedStatus({ rulesDef, state, path = "", cachePath, roo
|
|
|
2993
3053
|
})]);
|
|
2994
3054
|
return acc;
|
|
2995
3055
|
}, []));
|
|
2996
|
-
const externalRulesStatus = Object.fromEntries(Object.
|
|
3056
|
+
const externalRulesStatus = Object.fromEntries(Array.from(new Set([...Object.keys(toValue(externalErrors) ?? {}), ...Object.keys(toValue(externalIssues) ?? {})])).filter((key) => !(key in rulesDef.value)).map((key) => {
|
|
2997
3057
|
const stateRef = toRef(state.value ?? {}, key);
|
|
2998
3058
|
const $externalErrors = toRef(externalErrors?.value ?? {}, key);
|
|
3059
|
+
const $externalIssues = toRef(externalIssues?.value ?? {}, key);
|
|
2999
3060
|
const $schemaErrors = computed(() => schemaErrors?.value?.[key]);
|
|
3000
3061
|
const initialStateRef = toRef(initialState?.value ?? {}, key);
|
|
3001
3062
|
const computedPath = path ? `${path}.${key}` : key;
|
|
@@ -3006,6 +3067,7 @@ function createReactiveNestedStatus({ rulesDef, state, path = "", cachePath, roo
|
|
|
3006
3067
|
path: computedPath,
|
|
3007
3068
|
cachePath: computedCachePath,
|
|
3008
3069
|
externalErrors: $externalErrors,
|
|
3070
|
+
externalIssues: $externalIssues,
|
|
3009
3071
|
schemaErrors: $schemaErrors,
|
|
3010
3072
|
initialState: initialStateRef,
|
|
3011
3073
|
originalState: originalState?.[key],
|
|
@@ -3018,6 +3080,7 @@ function createReactiveNestedStatus({ rulesDef, state, path = "", cachePath, roo
|
|
|
3018
3080
|
const computedCachePath = cachePath ? `${cachePath}.${key}` : key;
|
|
3019
3081
|
const stateRef = toRef(state.value ?? {}, key);
|
|
3020
3082
|
const $externalErrors = toRef(externalErrors?.value ?? {}, key);
|
|
3083
|
+
const $externalIssues = toRef(externalIssues?.value ?? {}, key);
|
|
3021
3084
|
const $schemaErrors = computed(() => schemaErrors?.value?.[key]);
|
|
3022
3085
|
const initialStateRef = toRef(initialState?.value ?? {}, key);
|
|
3023
3086
|
return [key, createReactiveChildrenStatus({
|
|
@@ -3026,6 +3089,7 @@ function createReactiveNestedStatus({ rulesDef, state, path = "", cachePath, roo
|
|
|
3026
3089
|
path: computedPath,
|
|
3027
3090
|
cachePath: computedCachePath,
|
|
3028
3091
|
externalErrors: $externalErrors,
|
|
3092
|
+
externalIssues: $externalIssues,
|
|
3029
3093
|
schemaErrors: $schemaErrors,
|
|
3030
3094
|
initialState: initialStateRef,
|
|
3031
3095
|
originalState: originalState?.[key],
|
|
@@ -3036,6 +3100,7 @@ function createReactiveNestedStatus({ rulesDef, state, path = "", cachePath, roo
|
|
|
3036
3100
|
const statesWithNoRules = Object.fromEntries(Object.entries(state.value ?? {}).filter(([key]) => !(key in rulesDef.value) && !(key in (externalRulesStatus ?? {})) && !(key in (schemasRulesStatus ?? {}))).map(([key]) => {
|
|
3037
3101
|
const stateRef = toRef(state.value ?? {}, key);
|
|
3038
3102
|
const $externalErrors = toRef(externalErrors?.value ?? {}, key);
|
|
3103
|
+
const $externalIssues = toRef(externalIssues?.value ?? {}, key);
|
|
3039
3104
|
const $schemaErrors = computed(() => schemaErrors?.value?.[key]);
|
|
3040
3105
|
const initialStateRef = toRef(initialState?.value ?? {}, key);
|
|
3041
3106
|
return [key, createReactiveChildrenStatus({
|
|
@@ -3044,6 +3109,7 @@ function createReactiveNestedStatus({ rulesDef, state, path = "", cachePath, roo
|
|
|
3044
3109
|
path: path ? `${path}.${key}` : key,
|
|
3045
3110
|
cachePath: cachePath ? `${cachePath}.${key}` : key,
|
|
3046
3111
|
externalErrors: $externalErrors,
|
|
3112
|
+
externalIssues: $externalIssues,
|
|
3047
3113
|
schemaErrors: $schemaErrors,
|
|
3048
3114
|
initialState: initialStateRef,
|
|
3049
3115
|
originalState: originalState?.[key],
|
|
@@ -3066,9 +3132,10 @@ function createReactiveNestedStatus({ rulesDef, state, path = "", cachePath, roo
|
|
|
3066
3132
|
path,
|
|
3067
3133
|
cachePath,
|
|
3068
3134
|
externalErrors: ref(void 0),
|
|
3135
|
+
externalIssues: ref(void 0),
|
|
3069
3136
|
schemaErrors: ref(void 0),
|
|
3070
|
-
initialState:
|
|
3071
|
-
originalState
|
|
3137
|
+
initialState: initialState ?? ref(void 0),
|
|
3138
|
+
originalState,
|
|
3072
3139
|
fieldName: `$self`,
|
|
3073
3140
|
...commonArgs
|
|
3074
3141
|
});
|
|
@@ -3082,11 +3149,21 @@ function createReactiveNestedStatus({ rulesDef, state, path = "", cachePath, roo
|
|
|
3082
3149
|
createReactiveFieldsStatus();
|
|
3083
3150
|
}, { deep: true });
|
|
3084
3151
|
}
|
|
3152
|
+
function define$WatchExternalIssues() {
|
|
3153
|
+
if (externalIssues) $unwatchExternalIssues = watch(externalIssues, () => {
|
|
3154
|
+
$unwatch();
|
|
3155
|
+
createReactiveFieldsStatus();
|
|
3156
|
+
}, { deep: true });
|
|
3157
|
+
}
|
|
3085
3158
|
function define$watchState() {
|
|
3086
3159
|
$unwatchState = watch(state, () => {
|
|
3087
3160
|
$unwatch();
|
|
3088
3161
|
createReactiveFieldsStatus();
|
|
3089
3162
|
if (scopeState.$autoDirty.value && !scopeState.$silent.value) $touch(false, true);
|
|
3163
|
+
if (scopeState.$clearExternalErrorsOnChange.value) {
|
|
3164
|
+
$clearExternalErrors();
|
|
3165
|
+
$clearExternalIssues();
|
|
3166
|
+
}
|
|
3090
3167
|
}, { flush: "post" });
|
|
3091
3168
|
}
|
|
3092
3169
|
function $watch() {
|
|
@@ -3100,6 +3177,7 @@ function createReactiveNestedStatus({ rulesDef, state, path = "", cachePath, roo
|
|
|
3100
3177
|
flush: "pre"
|
|
3101
3178
|
});
|
|
3102
3179
|
define$WatchExternalErrors();
|
|
3180
|
+
define$WatchExternalIssues();
|
|
3103
3181
|
}
|
|
3104
3182
|
if (rootSchemaErrors) {
|
|
3105
3183
|
$unwatchSchemaErrors?.();
|
|
@@ -3117,6 +3195,10 @@ function createReactiveNestedStatus({ rulesDef, state, path = "", cachePath, roo
|
|
|
3117
3195
|
state.value = value;
|
|
3118
3196
|
createReactiveFieldsStatus();
|
|
3119
3197
|
if (scopeState.$autoDirty.value && !scopeState.$silent.value) $touch(false, true);
|
|
3198
|
+
if (scopeState.$clearExternalErrorsOnChange.value) {
|
|
3199
|
+
$clearExternalErrors();
|
|
3200
|
+
$clearExternalIssues();
|
|
3201
|
+
}
|
|
3120
3202
|
}
|
|
3121
3203
|
});
|
|
3122
3204
|
const $output = readonly($value);
|
|
@@ -3196,7 +3278,7 @@ function createReactiveNestedStatus({ rulesDef, state, path = "", cachePath, roo
|
|
|
3196
3278
|
});
|
|
3197
3279
|
const $clearExternalErrorsOnChange = computed(() => {
|
|
3198
3280
|
if (toValue(commonArgs.options.clearExternalErrorsOnChange) != null) return toValue(commonArgs.options.clearExternalErrorsOnChange) === true;
|
|
3199
|
-
return
|
|
3281
|
+
return true;
|
|
3200
3282
|
});
|
|
3201
3283
|
const $clearExternalErrorsOnValidate = computed(() => {
|
|
3202
3284
|
if (toValue(commonArgs.options.clearExternalErrorsOnValidate) != null) return toValue(commonArgs.options.clearExternalErrorsOnValidate) === true;
|
|
@@ -3321,6 +3403,7 @@ function createReactiveNestedStatus({ rulesDef, state, path = "", cachePath, roo
|
|
|
3321
3403
|
$errors,
|
|
3322
3404
|
$silentErrors,
|
|
3323
3405
|
$clearExternalErrorsOnValidate,
|
|
3406
|
+
$clearExternalErrorsOnChange,
|
|
3324
3407
|
$ready,
|
|
3325
3408
|
$name,
|
|
3326
3409
|
$shortcuts,
|
|
@@ -3341,19 +3424,28 @@ function createReactiveNestedStatus({ rulesDef, state, path = "", cachePath, roo
|
|
|
3341
3424
|
function $unwatch() {
|
|
3342
3425
|
$unwatchRules?.();
|
|
3343
3426
|
$unwatchExternalErrors?.();
|
|
3427
|
+
$unwatchExternalIssues?.();
|
|
3344
3428
|
$unwatchState?.();
|
|
3345
|
-
$unwatchGroups?.();
|
|
3346
3429
|
$unwatchSchemaErrors?.();
|
|
3430
|
+
nestedScopes.forEach((s) => s.stop());
|
|
3347
3431
|
nestedScopes = [];
|
|
3348
3432
|
scopeState = {};
|
|
3349
3433
|
if ($fields.value) for (const field of Object.values($fields.value)) field?.$unwatch();
|
|
3350
3434
|
}
|
|
3351
3435
|
function $setExternalErrors(errors) {
|
|
3352
3436
|
if (externalErrors) externalErrors.value = errors;
|
|
3437
|
+
$clearExternalIssues();
|
|
3353
3438
|
}
|
|
3354
3439
|
function $clearExternalErrors() {
|
|
3355
3440
|
if (externalErrors && !isEmpty(externalErrors.value)) externalErrors.value = {};
|
|
3356
3441
|
}
|
|
3442
|
+
function $setExternalIssues(issues) {
|
|
3443
|
+
if (externalIssues) externalIssues.value = issues;
|
|
3444
|
+
$clearExternalErrors();
|
|
3445
|
+
}
|
|
3446
|
+
function $clearExternalIssues() {
|
|
3447
|
+
if (externalIssues && !isEmpty(externalIssues.value)) externalIssues.value = {};
|
|
3448
|
+
}
|
|
3357
3449
|
function applyImmediateDirty() {
|
|
3358
3450
|
if (!scopeState) return;
|
|
3359
3451
|
if (scopeState.$immediateDirty.value !== "lazy-non-empty" && shouldApplyImmediateDirty(scopeState.$immediateDirty.value, initialState.value, rootInitialState?.value ?? initialState.value)) $touch(true, false);
|
|
@@ -3376,8 +3468,12 @@ function createReactiveNestedStatus({ rulesDef, state, path = "", cachePath, roo
|
|
|
3376
3468
|
for (const field of Object.values($fields.value)) field?.$reset(options, true);
|
|
3377
3469
|
$selfStatus.value?.$reset(options, true);
|
|
3378
3470
|
}
|
|
3379
|
-
if (options?.clearExternalErrors === false)
|
|
3471
|
+
if (options?.clearExternalErrors === false) {
|
|
3472
|
+
$clearExternalErrors();
|
|
3473
|
+
$clearExternalIssues();
|
|
3474
|
+
}
|
|
3380
3475
|
define$WatchExternalErrors();
|
|
3476
|
+
define$WatchExternalIssues();
|
|
3381
3477
|
if (!fromParent) {
|
|
3382
3478
|
createReactiveFieldsStatus();
|
|
3383
3479
|
applyImmediateDirty();
|
|
@@ -3426,7 +3522,10 @@ function createReactiveNestedStatus({ rulesDef, state, path = "", cachePath, roo
|
|
|
3426
3522
|
else {
|
|
3427
3523
|
const data = state.value;
|
|
3428
3524
|
$abort();
|
|
3429
|
-
if (scopeState.$clearExternalErrorsOnValidate.value)
|
|
3525
|
+
if (scopeState.$clearExternalErrorsOnValidate.value) {
|
|
3526
|
+
$clearExternalErrors();
|
|
3527
|
+
$clearExternalIssues();
|
|
3528
|
+
}
|
|
3430
3529
|
const validatePromises = [...Object.values($fields.value).map((statusOrField) => statusOrField.$validateWithoutRaceconditions()), ...$selfStatus.value ? [$selfStatus.value?.$validateWithoutRaceconditions()] : []];
|
|
3431
3530
|
return {
|
|
3432
3531
|
valid: (await Promise.allSettled(validatePromises)).every((value) => value.status === "fulfilled" && value?.value?.valid === true),
|
|
@@ -3455,7 +3554,10 @@ function createReactiveNestedStatus({ rulesDef, state, path = "", cachePath, roo
|
|
|
3455
3554
|
function $validateSync(forceValues) {
|
|
3456
3555
|
try {
|
|
3457
3556
|
if (forceValues) state.value = forceValues;
|
|
3458
|
-
if (scopeState.$clearExternalErrorsOnValidate.value)
|
|
3557
|
+
if (scopeState.$clearExternalErrorsOnValidate.value) {
|
|
3558
|
+
$clearExternalErrors();
|
|
3559
|
+
$clearExternalIssues();
|
|
3560
|
+
}
|
|
3459
3561
|
return [...Object.values($fields.value).map((statusOrField) => statusOrField.$validateSync()), ...$selfStatus.value ? [$selfStatus.value?.$validateSync()] : []].every((result) => !!result);
|
|
3460
3562
|
} catch {
|
|
3461
3563
|
return false;
|
|
@@ -3471,6 +3573,7 @@ function createReactiveNestedStatus({ rulesDef, state, path = "", cachePath, roo
|
|
|
3471
3573
|
$originalValue: originalState,
|
|
3472
3574
|
$self: $selfStatus,
|
|
3473
3575
|
$externalErrors: externalErrors,
|
|
3576
|
+
$externalIssues: externalIssues,
|
|
3474
3577
|
$fields,
|
|
3475
3578
|
$reset,
|
|
3476
3579
|
$touch,
|
|
@@ -3478,7 +3581,9 @@ function createReactiveNestedStatus({ rulesDef, state, path = "", cachePath, roo
|
|
|
3478
3581
|
$unwatch,
|
|
3479
3582
|
$watch,
|
|
3480
3583
|
$setExternalErrors,
|
|
3584
|
+
$setExternalIssues,
|
|
3481
3585
|
$clearExternalErrors,
|
|
3586
|
+
$clearExternalIssues,
|
|
3482
3587
|
$extractDirtyFields,
|
|
3483
3588
|
$abort,
|
|
3484
3589
|
$validateSync,
|
|
@@ -3528,6 +3633,89 @@ function createReactiveChildrenStatus({ rulesDef, ...properties }) {
|
|
|
3528
3633
|
...properties
|
|
3529
3634
|
});
|
|
3530
3635
|
}
|
|
3636
|
+
function normalizeExternalValue(value) {
|
|
3637
|
+
if (value && isObject(value) && Object.keys(value).some((key) => key.includes("."))) return dotPathObjectToNested(value);
|
|
3638
|
+
return value;
|
|
3639
|
+
}
|
|
3640
|
+
function hasExternalValue(value) {
|
|
3641
|
+
if (Array.isArray(value)) return value.length > 0;
|
|
3642
|
+
return isObject(value) && Object.keys(value).length > 0;
|
|
3643
|
+
}
|
|
3644
|
+
function emptyExternalValue(value) {
|
|
3645
|
+
return Array.isArray(value) ? [] : {};
|
|
3646
|
+
}
|
|
3647
|
+
function createExternalChannels(options) {
|
|
3648
|
+
const externalErrors = ref();
|
|
3649
|
+
const externalIssues = ref();
|
|
3650
|
+
let unwatchOptionErrors;
|
|
3651
|
+
let unwatchInternalErrors;
|
|
3652
|
+
let unwatchOptionIssues;
|
|
3653
|
+
let unwatchInternalIssues;
|
|
3654
|
+
let syncing = false;
|
|
3655
|
+
function clearIssues() {
|
|
3656
|
+
const emptyIssues = emptyExternalValue(externalIssues.value ?? options.externalIssues?.value);
|
|
3657
|
+
externalIssues.value = emptyIssues;
|
|
3658
|
+
if (options.externalIssues) options.externalIssues.value = emptyIssues;
|
|
3659
|
+
}
|
|
3660
|
+
function clearErrors() {
|
|
3661
|
+
const emptyErrors = emptyExternalValue(externalErrors.value ?? options.externalErrors?.value);
|
|
3662
|
+
externalErrors.value = emptyErrors;
|
|
3663
|
+
if (options.externalErrors) options.externalErrors.value = emptyErrors;
|
|
3664
|
+
}
|
|
3665
|
+
function syncErrors(newErrors, updateOptionRef = false) {
|
|
3666
|
+
if (syncing) return;
|
|
3667
|
+
syncing = true;
|
|
3668
|
+
const normalizedErrors = normalizeExternalValue(newErrors);
|
|
3669
|
+
externalErrors.value = normalizedErrors;
|
|
3670
|
+
if (updateOptionRef && options.externalErrors) options.externalErrors.value = normalizedErrors;
|
|
3671
|
+
if (hasExternalValue(normalizedErrors)) clearIssues();
|
|
3672
|
+
syncing = false;
|
|
3673
|
+
}
|
|
3674
|
+
function syncIssues(newIssues, updateOptionRef = false) {
|
|
3675
|
+
if (syncing) return;
|
|
3676
|
+
syncing = true;
|
|
3677
|
+
const normalizedIssues = normalizeExternalValue(newIssues);
|
|
3678
|
+
externalIssues.value = normalizedIssues;
|
|
3679
|
+
if (updateOptionRef && options.externalIssues) options.externalIssues.value = normalizedIssues;
|
|
3680
|
+
if (hasExternalValue(normalizedIssues)) clearErrors();
|
|
3681
|
+
syncing = false;
|
|
3682
|
+
}
|
|
3683
|
+
function watchOptionRefs() {
|
|
3684
|
+
unwatchOptionErrors?.();
|
|
3685
|
+
unwatchOptionIssues?.();
|
|
3686
|
+
unwatchOptionErrors = watch(() => options.externalErrors?.value, (errors) => syncErrors(errors), { deep: true });
|
|
3687
|
+
unwatchOptionIssues = watch(() => options.externalIssues?.value, (issues) => syncIssues(issues), { deep: true });
|
|
3688
|
+
}
|
|
3689
|
+
function watchInternalRefs() {
|
|
3690
|
+
unwatchInternalErrors?.();
|
|
3691
|
+
unwatchInternalIssues?.();
|
|
3692
|
+
unwatchInternalErrors = watch(() => externalErrors.value, (errors) => syncErrors(errors, true), { deep: true });
|
|
3693
|
+
unwatchInternalIssues = watch(() => externalIssues.value, (issues) => syncIssues(issues, true), { deep: true });
|
|
3694
|
+
}
|
|
3695
|
+
function start() {
|
|
3696
|
+
stop();
|
|
3697
|
+
syncErrors(options.externalErrors?.value);
|
|
3698
|
+
syncIssues(options.externalIssues?.value);
|
|
3699
|
+
watchInternalRefs();
|
|
3700
|
+
}
|
|
3701
|
+
function stop() {
|
|
3702
|
+
unwatchInternalErrors?.();
|
|
3703
|
+
unwatchOptionErrors?.();
|
|
3704
|
+
unwatchInternalIssues?.();
|
|
3705
|
+
unwatchOptionIssues?.();
|
|
3706
|
+
unwatchInternalErrors = void 0;
|
|
3707
|
+
unwatchOptionErrors = void 0;
|
|
3708
|
+
unwatchInternalIssues = void 0;
|
|
3709
|
+
unwatchOptionIssues = void 0;
|
|
3710
|
+
}
|
|
3711
|
+
return {
|
|
3712
|
+
externalErrors,
|
|
3713
|
+
externalIssues,
|
|
3714
|
+
start,
|
|
3715
|
+
watchOptionRefs,
|
|
3716
|
+
stop
|
|
3717
|
+
};
|
|
3718
|
+
}
|
|
3531
3719
|
/**
|
|
3532
3720
|
* @internal
|
|
3533
3721
|
* This is the internal function that creates the root storage for the Regle instance.
|
|
@@ -3539,37 +3727,18 @@ function useRootStorage({ initialState, originalState, options, scopeRules, stat
|
|
|
3539
3727
|
const attachedScopes = /* @__PURE__ */ new Set();
|
|
3540
3728
|
let rootScope;
|
|
3541
3729
|
const regle = ref();
|
|
3542
|
-
const
|
|
3543
|
-
let $unwatchExternalErrors;
|
|
3544
|
-
let $unwatchComputedExternalErrors;
|
|
3730
|
+
const externalChannels = createExternalChannels(options);
|
|
3545
3731
|
let $unwatchDisabled;
|
|
3546
3732
|
function defineDisabledWatchSource() {
|
|
3547
3733
|
$unwatchDisabled = watch(() => toValue(options.disabled), async (disabled) => {
|
|
3548
3734
|
if (disabled) unwatchRegle();
|
|
3549
3735
|
else {
|
|
3550
3736
|
createRegleInstance();
|
|
3551
|
-
|
|
3737
|
+
externalChannels.start();
|
|
3738
|
+
externalChannels.watchOptionRefs();
|
|
3552
3739
|
}
|
|
3553
3740
|
});
|
|
3554
3741
|
}
|
|
3555
|
-
function handleExternalErrorsChange(newErrors) {
|
|
3556
|
-
$unwatchComputedExternalErrors?.();
|
|
3557
|
-
if (newErrors) if (isObject(newErrors) && Object.keys(newErrors).some((key) => key.includes("."))) computedExternalErrors.value = dotPathObjectToNested(newErrors);
|
|
3558
|
-
else if (Array.isArray(newErrors)) computedExternalErrors.value = newErrors;
|
|
3559
|
-
else computedExternalErrors.value = newErrors ?? {};
|
|
3560
|
-
defineComputedExternalErrorsWatchSource();
|
|
3561
|
-
}
|
|
3562
|
-
function defineExternalErrorsWatchSource() {
|
|
3563
|
-
$unwatchExternalErrors = watch(() => options.externalErrors?.value, handleExternalErrorsChange, { deep: true });
|
|
3564
|
-
}
|
|
3565
|
-
function defineComputedExternalErrorsWatchSource() {
|
|
3566
|
-
$unwatchComputedExternalErrors = watch(() => computedExternalErrors.value, (newErrors) => {
|
|
3567
|
-
$unwatchExternalErrors?.();
|
|
3568
|
-
if (options.externalErrors?.value) options.externalErrors.value = newErrors;
|
|
3569
|
-
handleExternalErrorsChange(newErrors);
|
|
3570
|
-
defineExternalErrorsWatchSource();
|
|
3571
|
-
}, { deep: true });
|
|
3572
|
-
}
|
|
3573
3742
|
function createRegleInstance() {
|
|
3574
3743
|
if (isNestedRulesDef(state, scopeRules)) regle.value = createReactiveNestedStatus({
|
|
3575
3744
|
rootRules: scopeRules,
|
|
@@ -3579,7 +3748,8 @@ function useRootStorage({ initialState, originalState, options, scopeRules, stat
|
|
|
3579
3748
|
storage,
|
|
3580
3749
|
options,
|
|
3581
3750
|
rootInitialState: initialState,
|
|
3582
|
-
externalErrors:
|
|
3751
|
+
externalErrors: externalChannels.externalErrors,
|
|
3752
|
+
externalIssues: externalChannels.externalIssues,
|
|
3583
3753
|
validationGroups: options.validationGroups,
|
|
3584
3754
|
initialState,
|
|
3585
3755
|
originalState,
|
|
@@ -3600,7 +3770,8 @@ function useRootStorage({ initialState, originalState, options, scopeRules, stat
|
|
|
3600
3770
|
storage,
|
|
3601
3771
|
options,
|
|
3602
3772
|
rootInitialState: initialState,
|
|
3603
|
-
externalErrors:
|
|
3773
|
+
externalErrors: externalChannels.externalErrors,
|
|
3774
|
+
externalIssues: externalChannels.externalIssues,
|
|
3604
3775
|
initialState,
|
|
3605
3776
|
originalState,
|
|
3606
3777
|
shortcuts,
|
|
@@ -3614,26 +3785,23 @@ function useRootStorage({ initialState, originalState, options, scopeRules, stat
|
|
|
3614
3785
|
});
|
|
3615
3786
|
}
|
|
3616
3787
|
function clearWatchHandles() {
|
|
3617
|
-
$unwatchComputedExternalErrors = void 0;
|
|
3618
|
-
$unwatchExternalErrors = void 0;
|
|
3619
3788
|
$unwatchDisabled = void 0;
|
|
3620
3789
|
}
|
|
3621
3790
|
function unwatchRegle() {
|
|
3622
3791
|
regle.value?.$unwatch();
|
|
3623
|
-
|
|
3624
|
-
$unwatchExternalErrors?.();
|
|
3792
|
+
externalChannels.stop();
|
|
3625
3793
|
}
|
|
3626
3794
|
function startRootStorage() {
|
|
3627
3795
|
if (isEnabled.value) return;
|
|
3628
3796
|
isEnabled.value = true;
|
|
3629
3797
|
rootScope = effectScope(true);
|
|
3630
3798
|
rootScope.run(() => {
|
|
3631
|
-
|
|
3799
|
+
externalChannels.start();
|
|
3632
3800
|
createRegleInstance();
|
|
3633
3801
|
if (toValue(options.disabled)) nextTick().then(() => {
|
|
3634
3802
|
regle.value?.$unwatch();
|
|
3635
3803
|
});
|
|
3636
|
-
else
|
|
3804
|
+
else externalChannels.watchOptionRefs();
|
|
3637
3805
|
defineDisabledWatchSource();
|
|
3638
3806
|
});
|
|
3639
3807
|
}
|
|
@@ -3645,6 +3813,8 @@ function useRootStorage({ initialState, originalState, options, scopeRules, stat
|
|
|
3645
3813
|
clearWatchHandles();
|
|
3646
3814
|
rootScope?.stop();
|
|
3647
3815
|
rootScope = void 0;
|
|
3816
|
+
regle.value = void 0;
|
|
3817
|
+
storage.clearAll();
|
|
3648
3818
|
}
|
|
3649
3819
|
function bindToCurrentScope() {
|
|
3650
3820
|
const currentScope = getCurrentScope();
|
|
@@ -3733,7 +3903,9 @@ function createUseRegleComposable(options) {
|
|
|
3733
3903
|
shortcuts,
|
|
3734
3904
|
overrides
|
|
3735
3905
|
});
|
|
3736
|
-
return { r$: toReactive(regle, isDisabled,
|
|
3906
|
+
return { r$: toReactive(regle, isDisabled, () => {
|
|
3907
|
+
if (!regle.value) bindToCurrentScope();
|
|
3908
|
+
}) };
|
|
3737
3909
|
}
|
|
3738
3910
|
return useRegle;
|
|
3739
3911
|
}
|
|
@@ -3908,7 +4080,9 @@ function createUseRulesComposable(options) {
|
|
|
3908
4080
|
shortcuts,
|
|
3909
4081
|
overrides
|
|
3910
4082
|
});
|
|
3911
|
-
return toReactive(regle, isDisabled,
|
|
4083
|
+
return toReactive(regle, isDisabled, () => {
|
|
4084
|
+
if (!regle.value) bindToCurrentScope();
|
|
4085
|
+
});
|
|
3912
4086
|
}
|
|
3913
4087
|
return useRules;
|
|
3914
4088
|
}
|
|
@@ -4275,11 +4449,21 @@ function mergeRegles(regles, _scoped) {
|
|
|
4275
4449
|
regle.$setExternalErrors(errors);
|
|
4276
4450
|
});
|
|
4277
4451
|
}
|
|
4452
|
+
function $setExternalIssues(issues) {
|
|
4453
|
+
Object.values(regles).forEach((regle) => {
|
|
4454
|
+
regle.$setExternalIssues(issues);
|
|
4455
|
+
});
|
|
4456
|
+
}
|
|
4278
4457
|
function $clearExternalErrors() {
|
|
4279
4458
|
Object.values(regles).forEach((regle) => {
|
|
4280
4459
|
regle.$clearExternalErrors();
|
|
4281
4460
|
});
|
|
4282
4461
|
}
|
|
4462
|
+
function $clearExternalIssues() {
|
|
4463
|
+
Object.values(regles).forEach((regle) => {
|
|
4464
|
+
regle.$clearExternalIssues();
|
|
4465
|
+
});
|
|
4466
|
+
}
|
|
4283
4467
|
function $validateSync(forceValues) {
|
|
4284
4468
|
try {
|
|
4285
4469
|
if (forceValues) $value.value = forceValues;
|
|
@@ -4338,7 +4522,9 @@ function mergeRegles(regles, _scoped) {
|
|
|
4338
4522
|
$validateSync,
|
|
4339
4523
|
$extractDirtyFields,
|
|
4340
4524
|
$clearExternalErrors,
|
|
4341
|
-
$
|
|
4525
|
+
$clearExternalIssues,
|
|
4526
|
+
$setExternalErrors,
|
|
4527
|
+
$setExternalIssues
|
|
4342
4528
|
});
|
|
4343
4529
|
watchEffect(() => {
|
|
4344
4530
|
if (scoped) return;
|