@open-xamu-co/ui-common-types 4.0.0-next.1 → 4.0.0-next.11
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 +4 -4
- package/src/fetch.ts +26 -3
- package/src/files.ts +19 -0
- package/src/form/class.ts +10 -9
- package/src/form/types.ts +37 -2
- package/src/locale.ts +27 -3
- package/src/plugin.ts +1 -13
- package/src/values.ts +42 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@open-xamu-co/ui-common-types",
|
|
3
|
-
"version": "4.0.0-next.
|
|
3
|
+
"version": "4.0.0-next.11",
|
|
4
4
|
"description": "Xamu shared types",
|
|
5
5
|
"author": "@xamu-co",
|
|
6
6
|
"main": "src/index.ts",
|
|
@@ -31,13 +31,13 @@
|
|
|
31
31
|
"build:legacy": "rimraf dist && tsc --outDir dist --declaration --emitDeclarationOnly"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@open-xamu-co/ui-common-enums": "^
|
|
34
|
+
"@open-xamu-co/ui-common-enums": "^4.0.0-next.4",
|
|
35
35
|
"@fortawesome/fontawesome-common-types": "^6.4.0",
|
|
36
36
|
"sweetalert2": "^11.11.1"
|
|
37
37
|
},
|
|
38
38
|
"engines": {
|
|
39
|
-
"node": ">=
|
|
40
|
-
"yarn": ">=1.22.
|
|
39
|
+
"node": ">=22.22.2",
|
|
40
|
+
"yarn": ">=1.22.22"
|
|
41
41
|
},
|
|
42
42
|
"browserslist": [
|
|
43
43
|
"defaults"
|
package/src/fetch.ts
CHANGED
|
@@ -3,28 +3,44 @@ export type tOrder = "desc" | "asc";
|
|
|
3
3
|
/**
|
|
4
4
|
* Order using column or property
|
|
5
5
|
*
|
|
6
|
-
* @example [
|
|
7
|
-
* @example [
|
|
6
|
+
* @example ["id", "asc" ], order ascendente de id
|
|
7
|
+
* @example ["id", "desc" ] or ["id"], order descendente de id
|
|
8
8
|
*/
|
|
9
9
|
export type tOrderBy = [string, tOrder?];
|
|
10
10
|
|
|
11
11
|
export interface iPageEdge<T, C extends string | number = string> {
|
|
12
12
|
cursor: C;
|
|
13
|
+
/** Node data */
|
|
13
14
|
node: T;
|
|
14
15
|
}
|
|
15
16
|
|
|
16
17
|
export interface iPageInfo<C extends string | number = string> {
|
|
17
18
|
nextCursor?: C;
|
|
18
19
|
previousCursor?: C;
|
|
20
|
+
/**
|
|
21
|
+
* Current page number
|
|
22
|
+
* According to the "at" and "first" parameters
|
|
23
|
+
*/
|
|
19
24
|
pageNumber?: number;
|
|
25
|
+
/** There is a next page */
|
|
20
26
|
hasNextPage: boolean;
|
|
27
|
+
/** There is a previous page */
|
|
21
28
|
hasPreviousPage: boolean;
|
|
29
|
+
/** Current page path */
|
|
22
30
|
path?: string;
|
|
23
31
|
}
|
|
24
32
|
|
|
25
33
|
export interface iPage<T, C extends string | number = string> {
|
|
34
|
+
/**
|
|
35
|
+
* List of nodes with cursor data for the current page
|
|
36
|
+
* Amount of nodes is limited by the "first" parameter
|
|
37
|
+
*/
|
|
26
38
|
edges: iPageEdge<T, C>[];
|
|
27
39
|
pageInfo: iPageInfo<C>;
|
|
40
|
+
/**
|
|
41
|
+
* Count of nodes matching the path
|
|
42
|
+
* Independent of pagination
|
|
43
|
+
*/
|
|
28
44
|
totalCount: number;
|
|
29
45
|
}
|
|
30
46
|
|
|
@@ -39,9 +55,16 @@ export interface iPagination {
|
|
|
39
55
|
* Cantidad de elementos por pagina (limite)
|
|
40
56
|
*/
|
|
41
57
|
first?: number;
|
|
58
|
+
/**
|
|
59
|
+
* Order using column or property
|
|
60
|
+
*
|
|
61
|
+
* @example [["id", "asc" ]], order ascendente de id
|
|
62
|
+
* @example [["id", "desc" ]] or [["id"]], order descendente de id
|
|
63
|
+
*/
|
|
42
64
|
orderBy?: tOrderBy[];
|
|
43
65
|
}
|
|
44
66
|
|
|
45
67
|
export type iGetPage<T, C extends string | number = string> = (
|
|
46
|
-
params?: iPagination
|
|
68
|
+
params?: iPagination,
|
|
69
|
+
signal?: AbortSignal
|
|
47
70
|
) => Promise<iPage<T, C> | undefined>;
|
package/src/files.ts
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
|
+
import type { eMimeType } from "@open-xamu-co/ui-common-enums";
|
|
2
|
+
|
|
1
3
|
export interface iMime {
|
|
4
|
+
/**
|
|
5
|
+
* Mime type
|
|
6
|
+
* @example image/jpeg
|
|
7
|
+
*/
|
|
2
8
|
mime: string;
|
|
9
|
+
/**
|
|
10
|
+
* Pattern to match
|
|
11
|
+
* @example [0xff, 0xd8, 0xff]
|
|
12
|
+
*/
|
|
3
13
|
pattern: number[];
|
|
14
|
+
/**
|
|
15
|
+
* Mask to match
|
|
16
|
+
* @example [0xff, 0xff, 0xff]
|
|
17
|
+
*/
|
|
4
18
|
mask: number[];
|
|
19
|
+
/**
|
|
20
|
+
* Mime type range
|
|
21
|
+
* @example eMimeType.IMAGE
|
|
22
|
+
*/
|
|
23
|
+
type: eMimeType;
|
|
5
24
|
}
|
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,
|
|
@@ -31,12 +32,10 @@ export declare abstract class tFormInputDefault<
|
|
|
31
32
|
public setRerender(rerender: (fi?: Partial<iFormInputDefault<T>>) => void): this;
|
|
32
33
|
}
|
|
33
34
|
|
|
34
|
-
export declare class tFormInput<
|
|
35
|
+
export declare abstract class tFormInput<
|
|
35
36
|
V extends iFormValue | iFormValue[] = iFormValue | iFormValue[],
|
|
36
37
|
T extends eFormTypeBase | eFormTypeSimple | eFormTypeComplex =
|
|
37
|
-
|
|
|
38
|
-
| eFormTypeSimple
|
|
39
|
-
| eFormTypeComplex,
|
|
38
|
+
eFormTypeBase | eFormTypeSimple | eFormTypeComplex,
|
|
40
39
|
>
|
|
41
40
|
extends tFormInputDefault<T>
|
|
42
41
|
implements iFormInput<V, T>
|
|
@@ -44,11 +43,13 @@ export declare class tFormInput<
|
|
|
44
43
|
// public readonly
|
|
45
44
|
public readonly name: string;
|
|
46
45
|
public readonly title?: string;
|
|
47
|
-
public readonly
|
|
48
|
-
public readonly min: number;
|
|
49
|
-
public readonly max: number;
|
|
46
|
+
public readonly optionsFilter?: tOptionsLoaderFn;
|
|
50
47
|
// public
|
|
51
|
-
public
|
|
48
|
+
public multiple: boolean;
|
|
49
|
+
public min: number;
|
|
50
|
+
public max: number;
|
|
51
|
+
public meta?: Record<string, any>;
|
|
52
|
+
public options: iFormOption[];
|
|
52
53
|
public values: V[];
|
|
53
54
|
public defaults?: [
|
|
54
55
|
iFormInputDefault<eFormTypeBase | eFormTypeSimple | eFormTypeComplex>,
|
package/src/form/types.ts
CHANGED
|
@@ -34,7 +34,17 @@ export interface iFormResults<T = Record<string, unknown>> {
|
|
|
34
34
|
invalidInputs: iInvalidInput[];
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
export type tTextInputType =
|
|
37
|
+
export type tTextInputType =
|
|
38
|
+
| "text"
|
|
39
|
+
| "email"
|
|
40
|
+
| "password"
|
|
41
|
+
| "search"
|
|
42
|
+
| "url"
|
|
43
|
+
| "number"
|
|
44
|
+
| "tel"
|
|
45
|
+
| "date"
|
|
46
|
+
| "datetime-local"
|
|
47
|
+
| "time";
|
|
38
48
|
|
|
39
49
|
export type tFormAutocomplete =
|
|
40
50
|
| "off"
|
|
@@ -113,15 +123,29 @@ export interface iFormInputDefault<
|
|
|
113
123
|
autocomplete?: tFormAutocomplete;
|
|
114
124
|
}
|
|
115
125
|
|
|
126
|
+
export type tOptionsLoaderFn =
|
|
127
|
+
| ((v?: string | number, signal?: AbortSignal) => iFormOption[])
|
|
128
|
+
| ((v?: string | number, signal?: AbortSignal) => Promise<iFormOption[]>);
|
|
129
|
+
|
|
130
|
+
/** If a function is given, it should be responsible of determining if v is a value or an alias (search) */
|
|
131
|
+
export type iFormInputOptions = (string | number | iFormOption)[] | tOptionsLoaderFn;
|
|
132
|
+
|
|
116
133
|
/**
|
|
117
134
|
* Complex input, sub input support
|
|
135
|
+
* Used as input for the classes
|
|
118
136
|
*/
|
|
119
137
|
export interface iFormInput<
|
|
120
138
|
V extends iFormValue | iFormValue[],
|
|
121
139
|
T extends eFormTypeBase | eFormTypeSimple | eFormTypeComplex,
|
|
122
140
|
> extends iFormInputDefault<T> {
|
|
123
141
|
name: string;
|
|
124
|
-
|
|
142
|
+
/**
|
|
143
|
+
* Options for select, checkbox, radio inputs
|
|
144
|
+
* The usage of a function requires a compatible component (SelectFilter)
|
|
145
|
+
*
|
|
146
|
+
* @values array of options or function that returns options
|
|
147
|
+
*/
|
|
148
|
+
options?: iFormInputOptions;
|
|
125
149
|
/**
|
|
126
150
|
* An array of values to simplify validation
|
|
127
151
|
*
|
|
@@ -152,6 +176,10 @@ export interface iFormInput<
|
|
|
152
176
|
* if multiple is set to true this optional value would be the mandatory maximun amount of values
|
|
153
177
|
*/
|
|
154
178
|
max?: number;
|
|
179
|
+
/**
|
|
180
|
+
* Additional input metadata
|
|
181
|
+
*/
|
|
182
|
+
meta?: Record<string, any>;
|
|
155
183
|
}
|
|
156
184
|
|
|
157
185
|
/**
|
|
@@ -185,6 +213,13 @@ export interface iFetchResponse<R = any> {
|
|
|
185
213
|
[x: string]: any;
|
|
186
214
|
}
|
|
187
215
|
|
|
216
|
+
/**
|
|
217
|
+
* Takes the parsed inputs values and perform a request (content creation, update, etc).
|
|
218
|
+
*
|
|
219
|
+
* @param values Values of the input
|
|
220
|
+
* @param fetcher Request function
|
|
221
|
+
* @returns Response with data and errors if any
|
|
222
|
+
*/
|
|
188
223
|
export type tResponseFn<T, V extends Record<string, any> = Record<string, any>> = (
|
|
189
224
|
values: V
|
|
190
225
|
) => Promise<iFetchResponse<T>>;
|
package/src/locale.ts
CHANGED
|
@@ -90,6 +90,8 @@ export type tLocaleInput = {
|
|
|
90
90
|
file_one_of_amount: string;
|
|
91
91
|
/** @example "Delete file | Delete files" */
|
|
92
92
|
file_delete_files: string;
|
|
93
|
+
/** @example "Delete file (> {maxSize}MB)" */
|
|
94
|
+
file_delete_heavy_file: string;
|
|
93
95
|
/** @example "Thumbnail" */
|
|
94
96
|
file_thumb: string;
|
|
95
97
|
/** @example "Choose a file | Choose files" */
|
|
@@ -109,10 +111,14 @@ export type tLocaleInput = {
|
|
|
109
111
|
file_limit: string;
|
|
110
112
|
/** @example "This field only allows {amount} file | This field only allows {amount} files" */
|
|
111
113
|
file_limit_text: string;
|
|
114
|
+
/** @example "Unsupported format" */
|
|
115
|
+
file_unsupported_format: string;
|
|
116
|
+
/** @example "This field only does not allow that file type" */
|
|
117
|
+
file_unsupported_format_text: string;
|
|
112
118
|
/** @example "Wrong format" */
|
|
113
|
-
|
|
114
|
-
/** @example "This field only allows
|
|
115
|
-
|
|
119
|
+
file_wrong_format: string;
|
|
120
|
+
/** @example "This field only allows "{types}" files" */
|
|
121
|
+
file_wrong_format_text: string;
|
|
116
122
|
/** @example "File too big" */
|
|
117
123
|
file_too_big: string;
|
|
118
124
|
/** @example "The file exceeds the allowed size" */
|
|
@@ -176,6 +182,12 @@ export type tLocaleForm = {
|
|
|
176
182
|
form_cellphone: string;
|
|
177
183
|
/** @example "ID number" */
|
|
178
184
|
form_id_number: string;
|
|
185
|
+
/** @example "Date" */
|
|
186
|
+
form_date: string;
|
|
187
|
+
/** @example "Date & time" */
|
|
188
|
+
form_datetime: string;
|
|
189
|
+
/** @example "Time" */
|
|
190
|
+
form_time: string;
|
|
179
191
|
/** @example "Complete the field" */
|
|
180
192
|
form_complete_the_field: string;
|
|
181
193
|
/** @example "Location" */
|
|
@@ -198,6 +210,18 @@ export type tLocaleForm = {
|
|
|
198
210
|
form_no_values: string;
|
|
199
211
|
/** @example "New value" */
|
|
200
212
|
form_new_value: string;
|
|
213
|
+
/** @example "Rendered text" */
|
|
214
|
+
form_editor_preview: string;
|
|
215
|
+
/** @example "See rendered text" */
|
|
216
|
+
form_editor_see_preview: string;
|
|
217
|
+
/** @example "Bold" */
|
|
218
|
+
form_editor_bold: string;
|
|
219
|
+
/** @example "Italic" */
|
|
220
|
+
form_editor_italic: string;
|
|
221
|
+
/** @example "Link" */
|
|
222
|
+
form_editor_link: string;
|
|
223
|
+
/** @example "Add URL" */
|
|
224
|
+
form_editor_link_add_url: string;
|
|
201
225
|
// swal: {};
|
|
202
226
|
};
|
|
203
227
|
|
package/src/plugin.ts
CHANGED
|
@@ -7,19 +7,7 @@ export type tComponent = (typeof componentNames)[number];
|
|
|
7
7
|
export type tLogger = (at: string, ...logs: unknown[]) => any;
|
|
8
8
|
|
|
9
9
|
export type tSupportedLangs =
|
|
10
|
-
| "
|
|
11
|
-
| "pt"
|
|
12
|
-
| "nl"
|
|
13
|
-
| "hr"
|
|
14
|
-
| "fa"
|
|
15
|
-
| "de"
|
|
16
|
-
| "es"
|
|
17
|
-
| "en"
|
|
18
|
-
| "fr"
|
|
19
|
-
| "ja"
|
|
20
|
-
| "it"
|
|
21
|
-
| "cn"
|
|
22
|
-
| "tr";
|
|
10
|
+
"kr" | "pt" | "nl" | "hr" | "fa" | "de" | "es" | "en" | "fr" | "ja" | "it" | "cn" | "tr";
|
|
23
11
|
|
|
24
12
|
export interface iPluginOptions<ComponentType = unknown> {
|
|
25
13
|
/**
|
package/src/values.ts
CHANGED
|
@@ -11,9 +11,23 @@ export interface iSelectOption {
|
|
|
11
11
|
*
|
|
12
12
|
* Action result, event and callback
|
|
13
13
|
*/
|
|
14
|
-
export type iNodeFnResponse<
|
|
15
|
-
|
|
16
|
-
|
|
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)?];
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Stream like response from node functions
|
|
21
|
+
*
|
|
22
|
+
* Action result, event and callback
|
|
23
|
+
* Can accept an stream like array for multiple updates (hydration)
|
|
24
|
+
*/
|
|
25
|
+
export type iNodeFnResponseStream<
|
|
26
|
+
T extends Record<string, any> = never,
|
|
27
|
+
E extends Record<string, any> = Record<string, any>,
|
|
28
|
+
> = [
|
|
29
|
+
(boolean | T | [boolean | T, ...Promise<boolean | T>[]])?,
|
|
30
|
+
(Event & Partial<CustomEvent<E>>)?,
|
|
17
31
|
(() => void)?,
|
|
18
32
|
];
|
|
19
33
|
|
|
@@ -30,6 +44,23 @@ export type iNodeFn<T extends Record<string, any>, Ta extends [T?, ...any[]] = [
|
|
|
30
44
|
...args: Ta
|
|
31
45
|
) => boolean | undefined | iNodeFnResponse<T> | Promise<boolean | undefined | iNodeFnResponse<T>>;
|
|
32
46
|
|
|
47
|
+
/**
|
|
48
|
+
* Funtions that uses a node and perform some action
|
|
49
|
+
*
|
|
50
|
+
* Useful for table actions like creating, updating and deleting nodes
|
|
51
|
+
*
|
|
52
|
+
* Undefined would mean no action was performed
|
|
53
|
+
* True or an T type object would mean action was performed successfully
|
|
54
|
+
* False would mean action failed
|
|
55
|
+
*/
|
|
56
|
+
export type iNodeStreamFn<T extends Record<string, any>, Ta extends [T?, ...any[]] = [T]> = (
|
|
57
|
+
...args: Ta
|
|
58
|
+
) =>
|
|
59
|
+
| boolean
|
|
60
|
+
| undefined
|
|
61
|
+
| iNodeFnResponseStream<T>
|
|
62
|
+
| Promise<boolean | undefined | iNodeFnResponseStream<T>>;
|
|
63
|
+
|
|
33
64
|
/**
|
|
34
65
|
* Used on Table and related components
|
|
35
66
|
*
|
|
@@ -41,6 +72,11 @@ export interface iProperty<
|
|
|
41
72
|
P extends Record<string, any> = Record<string, any>,
|
|
42
73
|
ComponentType = unknown,
|
|
43
74
|
> extends iSelectOption {
|
|
75
|
+
/**
|
|
76
|
+
* Prefer to use the node's id instead of the value
|
|
77
|
+
* Useful for object like properties
|
|
78
|
+
*/
|
|
79
|
+
preferId?: boolean;
|
|
44
80
|
/**
|
|
45
81
|
* Function to create a node within the relation
|
|
46
82
|
* The parent is given since the node doesn't exist yet
|
|
@@ -88,4 +124,7 @@ export interface iProperty<
|
|
|
88
124
|
onImageError?: (data?: any) => void;
|
|
89
125
|
}
|
|
90
126
|
|
|
127
|
+
/**
|
|
128
|
+
* Function to order properties
|
|
129
|
+
*/
|
|
91
130
|
export type tPropertyOrderFn = (a: [string, any], b: [string, any]) => -1 | 0 | 1;
|