@open-xamu-co/ui-common-types 2.1.0 → 3.0.0-next.10
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 +2 -4
- package/src/fetch.ts +20 -17
- package/src/form.ts +48 -14
- package/src/index.ts +2 -0
- package/src/locale.ts +44 -29
- package/src/plugin.ts +11 -0
- package/src/props.ts +2 -0
- package/src/styles.ts +6 -1
- package/src/swal.ts +20 -0
- package/src/values.ts +37 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@open-xamu-co/ui-common-types",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0-next.10",
|
|
4
4
|
"description": "Xamu shared types",
|
|
5
5
|
"author": "@xamu-co",
|
|
6
6
|
"main": "src/index.ts",
|
|
@@ -31,10 +31,8 @@
|
|
|
31
31
|
"build:legacy": "rimraf dist && tsc --outDir dist --declaration --emitDeclarationOnly"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@open-xamu-co/ui-common-enums": "^2.0.0"
|
|
35
|
-
},
|
|
36
|
-
"devDependencies": {
|
|
37
34
|
"@fortawesome/fontawesome-common-types": "^6.4.0",
|
|
35
|
+
"@open-xamu-co/ui-common-enums": "^3.0.0-next.2",
|
|
38
36
|
"sweetalert2": "^11.7.5"
|
|
39
37
|
},
|
|
40
38
|
"engines": {
|
package/src/fetch.ts
CHANGED
|
@@ -1,19 +1,29 @@
|
|
|
1
|
-
export type
|
|
1
|
+
export type tOrder = "desc" | "asc";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Order using column or property
|
|
5
|
+
*
|
|
6
|
+
* @example [["id", "asc" ]], order ascendente de id
|
|
7
|
+
* @example [["id", "desc" ]] or [["id"]], order descendente de id
|
|
8
|
+
*/
|
|
9
|
+
export type tOrderBy = [string, tOrder?];
|
|
2
10
|
|
|
3
11
|
export interface iPageEdge<T, C extends string | number = string> {
|
|
4
12
|
cursor: C;
|
|
5
13
|
node: T;
|
|
6
14
|
}
|
|
7
15
|
|
|
16
|
+
export interface iPageInfo<C extends string | number = string> {
|
|
17
|
+
nextCursor?: C;
|
|
18
|
+
previousCursor?: C;
|
|
19
|
+
hasNextPage: boolean;
|
|
20
|
+
hasPreviousPage: boolean;
|
|
21
|
+
path?: string;
|
|
22
|
+
}
|
|
23
|
+
|
|
8
24
|
export interface iPage<T, C extends string | number = string> {
|
|
9
25
|
edges: iPageEdge<T, C>[];
|
|
10
|
-
pageInfo:
|
|
11
|
-
nextCursor?: C;
|
|
12
|
-
previousCursor?: C;
|
|
13
|
-
hasNextPage: boolean;
|
|
14
|
-
hasPreviousPage: boolean;
|
|
15
|
-
path?: string;
|
|
16
|
-
};
|
|
26
|
+
pageInfo: iPageInfo<C>;
|
|
17
27
|
totalCount: number;
|
|
18
28
|
}
|
|
19
29
|
|
|
@@ -28,13 +38,7 @@ export interface iPagination {
|
|
|
28
38
|
* Cantidad de elementos (limite)
|
|
29
39
|
*/
|
|
30
40
|
first?: number;
|
|
31
|
-
|
|
32
|
-
* JSON string
|
|
33
|
-
* aplica a cualquiera columna
|
|
34
|
-
* ej: ["id", "asc" ], order ascendente de id
|
|
35
|
-
* ej: ["id", "desc" ], order descendente de id
|
|
36
|
-
*/
|
|
37
|
-
orderBy?: tOrderBy;
|
|
41
|
+
orderBy?: tOrderBy[];
|
|
38
42
|
}
|
|
39
43
|
|
|
40
44
|
/**
|
|
@@ -43,6 +47,5 @@ export interface iPagination {
|
|
|
43
47
|
export type tHydrate<T> = (c: T, e?: unknown) => void;
|
|
44
48
|
|
|
45
49
|
export type iGetPage<T, C extends string | number = string> = (
|
|
46
|
-
hydrate: tHydrate<iPage<T, C> | null>,
|
|
47
50
|
params?: iPagination
|
|
48
|
-
) => Promise<iPage<T, C
|
|
51
|
+
) => Promise<iPage<T, C> | undefined>;
|
package/src/form.ts
CHANGED
|
@@ -2,10 +2,9 @@ import type { IconName } from "@fortawesome/fontawesome-common-types";
|
|
|
2
2
|
|
|
3
3
|
import { eFormTypeComplex, eFormTypeSimple } from "@open-xamu-co/ui-common-enums";
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
selected?: boolean;
|
|
5
|
+
import type { iSelectOption } from "./values.js";
|
|
6
|
+
|
|
7
|
+
export interface iFormOption extends iSelectOption {
|
|
9
8
|
/**
|
|
10
9
|
* Font awesome icon
|
|
11
10
|
*/
|
|
@@ -17,7 +16,7 @@ export interface iSelectOption {
|
|
|
17
16
|
placeholder?: string;
|
|
18
17
|
}
|
|
19
18
|
|
|
20
|
-
export interface iIndicative extends
|
|
19
|
+
export interface iIndicative extends iFormOption {
|
|
21
20
|
code: string;
|
|
22
21
|
number: number;
|
|
23
22
|
}
|
|
@@ -104,21 +103,12 @@ export type iFormValue = string | number | boolean | File;
|
|
|
104
103
|
export interface iFormInputDefault<T extends eFormTypeSimple | eFormTypeComplex = eFormTypeSimple> {
|
|
105
104
|
required?: boolean;
|
|
106
105
|
type?: T;
|
|
107
|
-
options?: (string | number | iSelectOption)[];
|
|
108
106
|
/**
|
|
109
107
|
* String without the dots
|
|
110
108
|
*/
|
|
111
109
|
placeholder?: string;
|
|
112
110
|
icon?: IconName | tFormIcon;
|
|
113
111
|
autocomplete?: tFormAutocomplete;
|
|
114
|
-
/**
|
|
115
|
-
* if muliple is set to true this optional value would be the required minimun amount of values
|
|
116
|
-
*/
|
|
117
|
-
min?: number;
|
|
118
|
-
/**
|
|
119
|
-
* if multiple is set to true this optional value would be the mandatory maximun amount of values
|
|
120
|
-
*/
|
|
121
|
-
max?: number;
|
|
122
112
|
}
|
|
123
113
|
|
|
124
114
|
/**
|
|
@@ -127,6 +117,7 @@ export interface iFormInputDefault<T extends eFormTypeSimple | eFormTypeComplex
|
|
|
127
117
|
export interface iFormInput<V extends iFormValue = iFormValue>
|
|
128
118
|
extends iFormInputDefault<eFormTypeSimple | eFormTypeComplex> {
|
|
129
119
|
name: string;
|
|
120
|
+
options?: (string | number | iFormOption)[];
|
|
130
121
|
/**
|
|
131
122
|
* An array of values to simplify validation
|
|
132
123
|
*
|
|
@@ -145,4 +136,47 @@ export interface iFormInput<V extends iFormValue = iFormValue>
|
|
|
145
136
|
* Ex: { multiple: true, min:3, max:3 } would make 3 values a requirement
|
|
146
137
|
*/
|
|
147
138
|
multiple?: boolean;
|
|
139
|
+
/**
|
|
140
|
+
* if muliple is set to true this optional value would be the required minimun amount of values
|
|
141
|
+
*/
|
|
142
|
+
min?: number;
|
|
143
|
+
/**
|
|
144
|
+
* if multiple is set to true this optional value would be the mandatory maximun amount of values
|
|
145
|
+
*/
|
|
146
|
+
max?: number;
|
|
148
147
|
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Sended form values
|
|
151
|
+
*/
|
|
152
|
+
export interface iFormResponse<R = any> {
|
|
153
|
+
response?: R;
|
|
154
|
+
invalidInputs: iInvalidInput[];
|
|
155
|
+
/**
|
|
156
|
+
* If the request had any error (validation/request itself).
|
|
157
|
+
*/
|
|
158
|
+
withErrors: boolean;
|
|
159
|
+
/**
|
|
160
|
+
* If the request had any error.
|
|
161
|
+
*/
|
|
162
|
+
requestHadErrors: boolean;
|
|
163
|
+
/**
|
|
164
|
+
* If the validation had any error.
|
|
165
|
+
*/
|
|
166
|
+
validationHadErrors: boolean;
|
|
167
|
+
/**
|
|
168
|
+
* Errors payload,
|
|
169
|
+
* 401 will be reported but not failed
|
|
170
|
+
*/
|
|
171
|
+
errors?: any;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
export interface iFetchResponse<R = any> {
|
|
175
|
+
data?: R;
|
|
176
|
+
errors?: any;
|
|
177
|
+
[x: string]: any;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
export type tResponseFn<T, V extends Record<string, any> = Record<string, any>> = (
|
|
181
|
+
values: V
|
|
182
|
+
) => Promise<iFetchResponse<T>>;
|
package/src/index.ts
CHANGED
package/src/locale.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @localeType
|
|
5
5
|
*/
|
|
6
|
-
export
|
|
6
|
+
export type tLocaleBase = {
|
|
7
7
|
/** @example "Yes" */
|
|
8
8
|
yes: string;
|
|
9
9
|
/** @example "No" */
|
|
@@ -46,12 +46,18 @@ export interface iLocaleBase {
|
|
|
46
46
|
pick: string;
|
|
47
47
|
/** @example "Refresh" */
|
|
48
48
|
refresh: string;
|
|
49
|
+
/** @example "Couldn't render the contents due to an unknown error" */
|
|
50
|
+
render_error: string;
|
|
49
51
|
swal: {
|
|
50
52
|
/** @example "Cancel" */
|
|
51
53
|
cancel: string;
|
|
52
54
|
/** @example "Continue" */
|
|
53
55
|
continue: string;
|
|
54
|
-
/** @example "
|
|
56
|
+
/** @example "Error!" */
|
|
57
|
+
error: string;
|
|
58
|
+
/** @example "Something went wrong!" */
|
|
59
|
+
error_message: string;
|
|
60
|
+
/** @example "Connection error!" */
|
|
55
61
|
connection_error: string;
|
|
56
62
|
/** @example "The server is not responding. Please check your network or try again later" */
|
|
57
63
|
connection_error_message: string;
|
|
@@ -64,14 +70,16 @@ export interface iLocaleBase {
|
|
|
64
70
|
/** @example "Don't close this window while we finish the task" */
|
|
65
71
|
dont_close_window: string;
|
|
66
72
|
};
|
|
67
|
-
}
|
|
73
|
+
};
|
|
68
74
|
|
|
69
75
|
/**
|
|
70
76
|
* Input locale
|
|
71
77
|
*
|
|
72
78
|
* @localeType
|
|
73
79
|
*/
|
|
74
|
-
export
|
|
80
|
+
export type tLocaleInput = {
|
|
81
|
+
/** @example "Selected" */
|
|
82
|
+
select_selected: string;
|
|
75
83
|
/** @example "--SELECT--" */
|
|
76
84
|
select_placeholder: string;
|
|
77
85
|
/** @example "Restablish field" */
|
|
@@ -114,14 +122,14 @@ export interface iLocaleInput {
|
|
|
114
122
|
/** @example "There was an error uploding the files, try again later" */
|
|
115
123
|
file_unknown_error_text: string;
|
|
116
124
|
};
|
|
117
|
-
}
|
|
125
|
+
};
|
|
118
126
|
|
|
119
127
|
/**
|
|
120
128
|
* Modal locale
|
|
121
129
|
*
|
|
122
130
|
* @localeType
|
|
123
131
|
*/
|
|
124
|
-
export
|
|
132
|
+
export type tLocaleModal = {
|
|
125
133
|
/** @example "Taking too long?" */
|
|
126
134
|
modal_taking_too_long: string;
|
|
127
135
|
swal: {
|
|
@@ -130,18 +138,20 @@ export interface iLocaleModal {
|
|
|
130
138
|
/** @example "You are not allowed to perform this action" */
|
|
131
139
|
modal_unauthorized_text: string;
|
|
132
140
|
};
|
|
133
|
-
}
|
|
141
|
+
};
|
|
134
142
|
|
|
135
143
|
/**
|
|
136
144
|
* Form locale
|
|
137
145
|
*
|
|
138
146
|
* @localeType
|
|
139
147
|
*/
|
|
140
|
-
export
|
|
148
|
+
export type tLocaleForm = {
|
|
141
149
|
/** @example "Options are required" */
|
|
142
150
|
form_required_options: string;
|
|
143
151
|
/** @example "No values are required | A value is required | {count} values are required" */
|
|
144
152
|
form_requires_n_values: string;
|
|
153
|
+
/** @example "Loading countries..." */
|
|
154
|
+
form_loading_countries: string;
|
|
145
155
|
/** @example "Look for country" */
|
|
146
156
|
form_country: string;
|
|
147
157
|
/** @example "Look for state" */
|
|
@@ -168,7 +178,9 @@ export interface iLocaleForm {
|
|
|
168
178
|
form_complete_the_field: string;
|
|
169
179
|
/** @example "Location" */
|
|
170
180
|
form_location: string;
|
|
171
|
-
/** @example "This field is
|
|
181
|
+
/** @example "This field is invalid, fill it properly" */
|
|
182
|
+
form_invalid_field: string;
|
|
183
|
+
/** @example "This field is required and can't be empty" */
|
|
172
184
|
form_required_field: string;
|
|
173
185
|
/** @example "You should use a valid E-mail address" */
|
|
174
186
|
form_use_valid_email: string;
|
|
@@ -180,15 +192,19 @@ export interface iLocaleForm {
|
|
|
180
192
|
form_unmatching_passwords: string;
|
|
181
193
|
/** @example "Invalid data" */
|
|
182
194
|
form_invalid_data: string;
|
|
195
|
+
/** @example "No values" */
|
|
196
|
+
form_no_values: string;
|
|
197
|
+
/** @example "New value" */
|
|
198
|
+
form_new_value: string;
|
|
183
199
|
// swal: {};
|
|
184
|
-
}
|
|
200
|
+
};
|
|
185
201
|
|
|
186
202
|
/**
|
|
187
203
|
* Table locale
|
|
188
204
|
*
|
|
189
205
|
* @localeType
|
|
190
206
|
*/
|
|
191
|
-
export
|
|
207
|
+
export type tLocaleTable = {
|
|
192
208
|
/** @example "See {name}" */
|
|
193
209
|
table_see_values: string;
|
|
194
210
|
/** @example "See: \"{name}\"" */
|
|
@@ -221,6 +237,10 @@ export interface iLocaleTable {
|
|
|
221
237
|
table_options: string;
|
|
222
238
|
/** @example "Open URL" */
|
|
223
239
|
table_open_url: string;
|
|
240
|
+
/** @example "Hide all" */
|
|
241
|
+
table_hide_all: string;
|
|
242
|
+
/** @example "Show all" */
|
|
243
|
+
table_show_all: string;
|
|
224
244
|
swal: {
|
|
225
245
|
/** @example "Are you sure you want to delete this element?" */
|
|
226
246
|
table_delete_node_title: string;
|
|
@@ -238,19 +258,23 @@ export interface iLocaleTable {
|
|
|
238
258
|
table_updated: string;
|
|
239
259
|
/** @example "The item may not have been updated | The items may not have been updated" */
|
|
240
260
|
table_possibly_not_updated: string;
|
|
261
|
+
/** @example "Successfull update" */
|
|
262
|
+
table_created: string;
|
|
263
|
+
/** @example "The item may not have been created | The items may not have been created" */
|
|
264
|
+
table_possibly_not_created: string;
|
|
241
265
|
/** @example "Successfull cloning" */
|
|
242
266
|
table_cloned: string;
|
|
243
267
|
/** @example "The item may not have been cloned | The items may not have been cloned" */
|
|
244
268
|
table_possibly_not_cloned: string;
|
|
245
269
|
};
|
|
246
|
-
}
|
|
270
|
+
};
|
|
247
271
|
|
|
248
272
|
/**
|
|
249
273
|
* Pagination locale
|
|
250
274
|
*
|
|
251
275
|
* @localeType
|
|
252
276
|
*/
|
|
253
|
-
export
|
|
277
|
+
export type tLocalePagination = {
|
|
254
278
|
/** @example "No items | Single item | {count} items" */
|
|
255
279
|
pagination_items: string;
|
|
256
280
|
/** @example "No pages | Single page | {count} pages" */
|
|
@@ -272,25 +296,16 @@ export interface iLocalePagination {
|
|
|
272
296
|
/** @example "Filter by:" */
|
|
273
297
|
pagination_filter_by: string;
|
|
274
298
|
// swal: {};
|
|
275
|
-
}
|
|
299
|
+
};
|
|
276
300
|
|
|
277
301
|
/**
|
|
278
302
|
* Plugin locale
|
|
279
303
|
*
|
|
280
304
|
* @localeType
|
|
281
305
|
*/
|
|
282
|
-
export type tPluginLocale =
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
/**
|
|
290
|
-
* Plugin locale key union
|
|
291
|
-
*
|
|
292
|
-
* @localeType
|
|
293
|
-
*/
|
|
294
|
-
export type tPluginLocaleKey =
|
|
295
|
-
| Exclude<keyof tPluginLocale, "swal">
|
|
296
|
-
| `swal.${keyof Required<tPluginLocale>["swal"]}`;
|
|
306
|
+
export type tPluginLocale = tLocaleBase &
|
|
307
|
+
tLocaleInput &
|
|
308
|
+
tLocaleModal &
|
|
309
|
+
tLocaleForm &
|
|
310
|
+
tLocaleTable &
|
|
311
|
+
tLocalePagination;
|
package/src/plugin.ts
CHANGED
|
@@ -105,6 +105,17 @@ export interface iPluginOptions<ComponentType = unknown> {
|
|
|
105
105
|
* When a country is provided forms will omit that field
|
|
106
106
|
*/
|
|
107
107
|
country?: string;
|
|
108
|
+
/**
|
|
109
|
+
* Countries API base endpoint
|
|
110
|
+
*
|
|
111
|
+
* If using nuxt, get better performance with the module
|
|
112
|
+
* @see https://www.npmjs.com/package/nuxt-countries-api
|
|
113
|
+
*
|
|
114
|
+
* Using an absolute path will enable the module
|
|
115
|
+
*
|
|
116
|
+
* @default "https://countries.xamu.com.co/api/v1"
|
|
117
|
+
*/
|
|
118
|
+
countriesUrl?: string;
|
|
108
119
|
/**
|
|
109
120
|
* Disable automatic animations
|
|
110
121
|
*
|
package/src/props.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
export type tProp<T extends string = string> = T | Record<T, boolean>;
|
|
2
2
|
export type tProps<T extends string = string> = tProp<T> | tProp<T>[];
|
|
3
3
|
export type tPropsModifier<T extends string = string> = boolean | tProps<T>;
|
|
4
|
+
|
|
5
|
+
export type tIndicative = `${string}+${number}`;
|
package/src/styles.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { eColors } from "@open-xamu-co/ui-common-enums";
|
|
1
|
+
import { eSizes, eColors } from "@open-xamu-co/ui-common-enums";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Union of supported colors.
|
|
@@ -6,3 +6,8 @@ import { eColors } from "@open-xamu-co/ui-common-enums";
|
|
|
6
6
|
*/
|
|
7
7
|
export type tThemeModifier = (typeof eColors)[keyof typeof eColors]; // to union
|
|
8
8
|
export type tThemeTuple = [tThemeModifier, tThemeModifier?];
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Allowed sizes
|
|
12
|
+
*/
|
|
13
|
+
export type tSizeModifier = (typeof eSizes)[keyof typeof eSizes]; // to union
|
package/src/swal.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import DefaultSwal, { type SweetAlertOptions, type SweetAlertResult } from "sweetalert2";
|
|
2
|
+
|
|
3
|
+
export type tSwalOptions = Omit<SweetAlertOptions, "target"> & {
|
|
4
|
+
target?: SweetAlertOptions["target"] | Event;
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Extended SweetAlert2 class
|
|
9
|
+
*
|
|
10
|
+
* Defaults should use Event as target
|
|
11
|
+
*
|
|
12
|
+
* Do not deestructure this
|
|
13
|
+
*/
|
|
14
|
+
export type tSwal = Omit<typeof DefaultSwal, "fire"> & {
|
|
15
|
+
fire: <T = any>(options?: tSwalOptions) => Promise<SweetAlertResult<Awaited<T>>>;
|
|
16
|
+
firePrevent: <T = any>(options?: tSwalOptions) => Promise<SweetAlertResult<Awaited<T>>>;
|
|
17
|
+
fireLoader: <T = any>(options?: tSwalOptions) => Promise<SweetAlertResult<Awaited<T>>>;
|
|
18
|
+
firePreventDefaults: SweetAlertOptions;
|
|
19
|
+
fireLoaderDefaults: SweetAlertOptions;
|
|
20
|
+
};
|
package/src/values.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export interface iSelectOption {
|
|
2
|
+
value: string | number;
|
|
3
|
+
alias?: string;
|
|
4
|
+
selected?: boolean;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Funtions that uses a node and perform some action
|
|
9
|
+
*
|
|
10
|
+
* Useful for table actions like creating, updating and deleting nodes
|
|
11
|
+
*/
|
|
12
|
+
export type iNodeFn<T extends Record<string, any>, Ta extends [T?] = [T]> = (
|
|
13
|
+
...args: Ta
|
|
14
|
+
) => boolean | undefined | Promise<boolean | undefined>;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* used on FactoryTable and related components
|
|
18
|
+
*/
|
|
19
|
+
export interface iProperty<T extends Record<string, any> = Record<string, any>>
|
|
20
|
+
extends iSelectOption {
|
|
21
|
+
/**
|
|
22
|
+
* Function to create a node within the relation
|
|
23
|
+
*/
|
|
24
|
+
createNode?: iNodeFn<T, [T?]>;
|
|
25
|
+
/**
|
|
26
|
+
* Function to clone a node within the relation
|
|
27
|
+
*/
|
|
28
|
+
cloneNode?: iNodeFn<T, [T?]>;
|
|
29
|
+
/**
|
|
30
|
+
* Function to update a node within the relation
|
|
31
|
+
*/
|
|
32
|
+
updateNode?: iNodeFn<T, [T?]>;
|
|
33
|
+
/**
|
|
34
|
+
* Function to delete a node within the relation
|
|
35
|
+
*/
|
|
36
|
+
deleteNode?: iNodeFn<T, [T?]>;
|
|
37
|
+
}
|