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/README.md +3 -3
- package/dist/CogsState.d.ts +1 -0
- package/dist/CogsState.d.ts.map +1 -1
- package/dist/CogsState.jsx +1011 -1270
- package/dist/CogsState.jsx.map +1 -1
- package/dist/Components.d.ts +39 -0
- package/dist/Components.d.ts.map +1 -0
- package/dist/Components.jsx +281 -0
- package/dist/Components.jsx.map +1 -0
- package/dist/index.js +11 -12
- package/dist/store.d.ts +2 -5
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +261 -219
- package/dist/store.js.map +1 -1
- package/package.json +1 -1
- package/src/CogsState.tsx +151 -707
- package/src/Components.tsx +541 -0
- package/src/store.ts +178 -141
- package/dist/Functions.d.ts +0 -11
- package/dist/Functions.d.ts.map +0 -1
- package/dist/Functions.jsx +0 -29
- package/dist/Functions.jsx.map +0 -1
- package/src/Functions.tsx +0 -66
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
|
-
}
|