@open-xamu-co/ui-common-types 4.0.0-next.5 → 4.0.0-next.7
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 +1 -1
- package/src/fetch.ts +2 -1
- package/src/form/class.ts +8 -6
- package/src/form/types.ts +22 -1
- package/src/values.ts +9 -7
package/package.json
CHANGED
package/src/fetch.ts
CHANGED
package/src/form/class.ts
CHANGED
|
@@ -7,11 +7,12 @@ import type {
|
|
|
7
7
|
import type {
|
|
8
8
|
iFormInput,
|
|
9
9
|
iFormInputDefault,
|
|
10
|
+
iFormOption,
|
|
10
11
|
iFormValue,
|
|
11
12
|
tFormAutocomplete,
|
|
12
13
|
tFormIcon,
|
|
14
|
+
tOptionsLoaderFn,
|
|
13
15
|
} from "./types";
|
|
14
|
-
import type { iSelectOption } from "../values.js";
|
|
15
16
|
|
|
16
17
|
export declare abstract class tFormInputDefault<
|
|
17
18
|
T extends eFormTypeBase | eFormTypeSimple | eFormTypeComplex = eFormTypeSimple,
|
|
@@ -44,12 +45,13 @@ export declare abstract class tFormInput<
|
|
|
44
45
|
// public readonly
|
|
45
46
|
public readonly name: string;
|
|
46
47
|
public readonly title?: string;
|
|
47
|
-
public readonly
|
|
48
|
-
public readonly min: number;
|
|
49
|
-
public readonly max: number;
|
|
50
|
-
public readonly meta?: Record<string, any>;
|
|
48
|
+
public readonly optionsFilter?: tOptionsLoaderFn;
|
|
51
49
|
// public
|
|
52
|
-
public
|
|
50
|
+
public multiple: boolean;
|
|
51
|
+
public min: number;
|
|
52
|
+
public max: number;
|
|
53
|
+
public meta?: Record<string, any>;
|
|
54
|
+
public options: iFormOption[];
|
|
53
55
|
public values: V[];
|
|
54
56
|
public defaults?: [
|
|
55
57
|
iFormInputDefault<eFormTypeBase | eFormTypeSimple | eFormTypeComplex>,
|
package/src/form/types.ts
CHANGED
|
@@ -113,15 +113,29 @@ export interface iFormInputDefault<
|
|
|
113
113
|
autocomplete?: tFormAutocomplete;
|
|
114
114
|
}
|
|
115
115
|
|
|
116
|
+
export type tOptionsLoaderFn =
|
|
117
|
+
| ((v?: string | number, signal?: AbortSignal) => iFormOption[])
|
|
118
|
+
| ((v?: string | number, signal?: AbortSignal) => Promise<iFormOption[]>);
|
|
119
|
+
|
|
120
|
+
/** If a function is given, it should be responsible of determining if v is a value or an alias (search) */
|
|
121
|
+
export type iFormInputOptions = (string | number | iFormOption)[] | tOptionsLoaderFn;
|
|
122
|
+
|
|
116
123
|
/**
|
|
117
124
|
* Complex input, sub input support
|
|
125
|
+
* Used as input for the classes
|
|
118
126
|
*/
|
|
119
127
|
export interface iFormInput<
|
|
120
128
|
V extends iFormValue | iFormValue[],
|
|
121
129
|
T extends eFormTypeBase | eFormTypeSimple | eFormTypeComplex,
|
|
122
130
|
> extends iFormInputDefault<T> {
|
|
123
131
|
name: string;
|
|
124
|
-
|
|
132
|
+
/**
|
|
133
|
+
* Options for select, checkbox, radio inputs
|
|
134
|
+
* The usage of a function requires a compatible component (SelectFilter)
|
|
135
|
+
*
|
|
136
|
+
* @values array of options or function that returns options
|
|
137
|
+
*/
|
|
138
|
+
options?: iFormInputOptions;
|
|
125
139
|
/**
|
|
126
140
|
* An array of values to simplify validation
|
|
127
141
|
*
|
|
@@ -189,6 +203,13 @@ export interface iFetchResponse<R = any> {
|
|
|
189
203
|
[x: string]: any;
|
|
190
204
|
}
|
|
191
205
|
|
|
206
|
+
/**
|
|
207
|
+
* Takes the parsed inputs values and perform a request (content creation, update, etc).
|
|
208
|
+
*
|
|
209
|
+
* @param values Values of the input
|
|
210
|
+
* @param fetcher Request function
|
|
211
|
+
* @returns Response with data and errors if any
|
|
212
|
+
*/
|
|
192
213
|
export type tResponseFn<T, V extends Record<string, any> = Record<string, any>> = (
|
|
193
214
|
values: V
|
|
194
215
|
) => Promise<iFetchResponse<T>>;
|
package/src/values.ts
CHANGED
|
@@ -11,11 +11,10 @@ export interface iSelectOption {
|
|
|
11
11
|
*
|
|
12
12
|
* Action result, event and callback
|
|
13
13
|
*/
|
|
14
|
-
export type iNodeFnResponse<
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
];
|
|
14
|
+
export type iNodeFnResponse<
|
|
15
|
+
T extends Record<string, any> = never,
|
|
16
|
+
E extends Record<string, any> = Record<string, any>,
|
|
17
|
+
> = [(boolean | T)?, (Event & Partial<CustomEvent<E>>)?, (() => void)?];
|
|
19
18
|
|
|
20
19
|
/**
|
|
21
20
|
* Stream like response from node functions
|
|
@@ -23,9 +22,12 @@ export type iNodeFnResponse<T extends Record<string, any> = never> = [
|
|
|
23
22
|
* Action result, event and callback
|
|
24
23
|
* Can accept an stream like array for multiple updates (hydration)
|
|
25
24
|
*/
|
|
26
|
-
export type iNodeFnResponseStream<
|
|
25
|
+
export type iNodeFnResponseStream<
|
|
26
|
+
T extends Record<string, any> = never,
|
|
27
|
+
E extends Record<string, any> = Record<string, any>,
|
|
28
|
+
> = [
|
|
27
29
|
(boolean | T | [boolean | T, ...Promise<boolean | T>[]])?,
|
|
28
|
-
Event?,
|
|
30
|
+
(Event & Partial<CustomEvent<E>>)?,
|
|
29
31
|
(() => void)?,
|
|
30
32
|
];
|
|
31
33
|
|