cogsbox-state 0.5.465 → 0.5.466

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/src/Functions.tsx DELETED
@@ -1,66 +0,0 @@
1
- import { type FormOptsType } from './CogsState';
2
- import React from 'react';
3
- import { getGlobalStore, ValidationError } from './store';
4
- import { get } from 'http';
5
-
6
- export type ValidationWrapperProps = {
7
- formOpts?: FormOptsType;
8
- path: string[];
9
- stateKey: string;
10
- children: React.ReactNode;
11
- };
12
-
13
- export function ValidationWrapper({
14
- formOpts,
15
- path,
16
- stateKey,
17
- children,
18
- }: ValidationWrapperProps) {
19
- const { getInitialOptions, getShadowMetadata, getShadowValue } =
20
- getGlobalStore.getState();
21
- const thisStateOpts = getInitialOptions(stateKey!);
22
-
23
- const shadowMeta = getShadowMetadata(stateKey!, path);
24
- const validationState = shadowMeta?.validation;
25
-
26
- const status = validationState?.status || 'NOT_VALIDATED';
27
-
28
- const errors = (validationState?.errors || []).map((err) => ({
29
- ...err,
30
- path: path,
31
- })) as ValidationError[];
32
- const errorMessages = errors
33
- .filter((err) => err.severity === 'error')
34
- .map((err) => err.message);
35
- const warningMessages = errors
36
- .filter((err) => err.severity === 'warning')
37
- .map((err) => err.message);
38
-
39
- // Use first error, or first warning if no errors
40
- const message = errorMessages[0] || warningMessages[0];
41
-
42
- return (
43
- <>
44
- {thisStateOpts?.formElements?.validation &&
45
- !formOpts?.validation?.disable ? (
46
- thisStateOpts.formElements!.validation!({
47
- children: (
48
- <React.Fragment key={path.toString()}>{children}</React.Fragment>
49
- ),
50
- status, // Now passes the new ValidationStatus type
51
- message: formOpts?.validation?.hideMessage
52
- ? ''
53
- : formOpts?.validation?.message || message || '',
54
-
55
- hasErrors: errorMessages.length > 0,
56
- hasWarnings: warningMessages.length > 0,
57
- allErrors: errors,
58
- path: path,
59
- getData: () => getShadowValue(stateKey!, path),
60
- })
61
- ) : (
62
- <React.Fragment key={path.toString()}>{children}</React.Fragment>
63
- )}
64
- </>
65
- );
66
- }