5htp-core 0.3.3-4 → 0.3.4-2
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/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "5htp-core",
|
|
3
3
|
"description": "Convenient TypeScript framework designed for Performance and Productivity.",
|
|
4
|
-
"version": "0.3.
|
|
4
|
+
"version": "0.3.4-2",
|
|
5
5
|
"author": "Gaetan Le Gac (https://github.com/gaetanlegac)",
|
|
6
6
|
"repository": "git://github.com/gaetanlegac/5htp-core.git",
|
|
7
7
|
"license": "MIT",
|
|
@@ -181,15 +181,16 @@ export default function useForm<TFormData extends {}>(
|
|
|
181
181
|
|
|
182
182
|
// Submit on press enter
|
|
183
183
|
onKeyDown: e => {
|
|
184
|
-
if (e.key === 'Enter') {
|
|
184
|
+
if (e.key === 'Enter' || (e.keyCode || e.which) === 13) {
|
|
185
185
|
submit({ [fieldName]: e.target.value } as Partial<TFormData>);
|
|
186
186
|
}
|
|
187
187
|
},
|
|
188
188
|
|
|
189
189
|
// Error
|
|
190
190
|
errors: state.errors[fieldName],
|
|
191
|
-
|
|
192
|
-
|
|
191
|
+
|
|
192
|
+
// Component attributes
|
|
193
|
+
...validator.componentAttributes
|
|
193
194
|
}
|
|
194
195
|
}
|
|
195
196
|
}
|
|
@@ -10,6 +10,7 @@ import { InputError } from '@common/errors';
|
|
|
10
10
|
|
|
11
11
|
// Specific
|
|
12
12
|
import type { TValidateOptions } from './schema';
|
|
13
|
+
import type { InputBaseProps } from '@client/components/inputv3/base';
|
|
13
14
|
|
|
14
15
|
/*----------------------------------
|
|
15
16
|
- TYPES
|
|
@@ -64,14 +65,23 @@ export const EXCLUDE_VALUE = "action:exclure" as const;
|
|
|
64
65
|
/*----------------------------------
|
|
65
66
|
- CLASS
|
|
66
67
|
----------------------------------*/
|
|
67
|
-
export default class Validator<
|
|
68
|
+
export default class Validator<
|
|
69
|
+
TValue,
|
|
70
|
+
TOptions extends TValidator<TValue> = TValidator<TValue>,
|
|
71
|
+
TComponent = React.FunctionComponent< InputBaseProps< TValue > >
|
|
72
|
+
> {
|
|
68
73
|
|
|
69
74
|
public constructor(
|
|
70
75
|
public type: string,
|
|
71
76
|
public validateType: TValidationFunction<TValue>,
|
|
72
|
-
public options: TOptions
|
|
77
|
+
public options: TOptions,
|
|
78
|
+
public componentAttributes: Partial<InputBaseProps<TValue>> = {}
|
|
73
79
|
) {
|
|
74
80
|
|
|
81
|
+
// Basic component attriutes
|
|
82
|
+
this.componentAttributes.required = options?.opt !== true;
|
|
83
|
+
//this.componentAttributes.validator = this;
|
|
84
|
+
|
|
75
85
|
}
|
|
76
86
|
|
|
77
87
|
public isEmpty = (val: any) => val === undefined || val === '' || val === null
|
|
@@ -111,22 +111,22 @@ export default class SchemaValidators {
|
|
|
111
111
|
})
|
|
112
112
|
}
|
|
113
113
|
|
|
114
|
-
public choice = (
|
|
114
|
+
public choice = (choices?: any[], opts: TValidator<any> & {} = {}) =>
|
|
115
115
|
new Validator<any>('choice', (val, input, output) => {
|
|
116
116
|
|
|
117
117
|
// Choice object
|
|
118
118
|
if (typeof val === 'object' && ('value' in val) && typeof val.value !== 'object')
|
|
119
119
|
val = val.value;
|
|
120
120
|
|
|
121
|
-
if (
|
|
122
|
-
const isValid =
|
|
121
|
+
if (choices !== undefined) {
|
|
122
|
+
const isValid = choices.some(v => v.value === val);
|
|
123
123
|
if (!isValid)
|
|
124
|
-
throw new InputError("Invalid value. Must be: " +
|
|
124
|
+
throw new InputError("Invalid value. Must be: " + choices.map(v => v.value).join(', '));
|
|
125
125
|
}
|
|
126
126
|
|
|
127
127
|
return val;
|
|
128
128
|
|
|
129
|
-
}, opts)
|
|
129
|
+
}, opts, { choices })
|
|
130
130
|
|
|
131
131
|
/*----------------------------------
|
|
132
132
|
- CHAINES
|
|
@@ -137,8 +137,6 @@ export default class Console extends Service<Config, Hooks, Application, Service
|
|
|
137
137
|
|
|
138
138
|
protected async start() {
|
|
139
139
|
|
|
140
|
-
return;
|
|
141
|
-
|
|
142
140
|
const origLog = console.log
|
|
143
141
|
|
|
144
142
|
this.logger = new Logger({
|
|
@@ -352,10 +350,10 @@ export default class Console extends Service<Config, Hooks, Application, Service
|
|
|
352
350
|
|
|
353
351
|
public printHtml( logs: TJsonLog[], full: boolean = false ): string {
|
|
354
352
|
|
|
355
|
-
let html = logs.map( logEntry => logToHTML( logEntry, this )).join('
|
|
353
|
+
let html = logs.map( logEntry => logToHTML( logEntry, this )).join('<br />');
|
|
356
354
|
|
|
357
355
|
if (full) {
|
|
358
|
-
const consoleCss = `background: #000; padding: 20px; font-family: 'Fira Mono', 'monospace', 'Monaco'; font-size: 12px; line-height: 20px;`
|
|
356
|
+
const consoleCss = `background: #000; padding: 20px; font-family: 'Fira Mono', 'monospace', 'Monaco'; font-size: 12px; line-height: 20px;color: #aaa;`
|
|
359
357
|
html = '<div style="' + consoleCss + '">' + html + '</div>';
|
|
360
358
|
}
|
|
361
359
|
|