@open-xamu-co/ui-common-types 3.0.0-next.1 → 3.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-xamu-co/ui-common-types",
3
- "version": "3.0.0-next.1",
3
+ "version": "3.0.0-next.11",
4
4
  "description": "Xamu shared types",
5
5
  "author": "@xamu-co",
6
6
  "main": "src/index.ts",
@@ -31,11 +31,9 @@
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",
38
- "sweetalert2": "^11.7.5"
35
+ "@open-xamu-co/ui-common-enums": "^3.0.0-next.4",
36
+ "sweetalert2": "^11.11.1"
39
37
  },
40
38
  "engines": {
41
39
  "node": ">=18",
package/src/fetch.ts CHANGED
@@ -1,6 +1,12 @@
1
- import type { eOrders } from "@open-xamu-co/ui-common-enums";
1
+ export type tOrder = "desc" | "asc";
2
2
 
3
- export type tOrderBy = [string, ("desc" | "asc")?];
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?];
4
10
 
5
11
  export interface iPageEdge<T, C extends string | number = string> {
6
12
  cursor: C;
@@ -21,7 +27,7 @@ export interface iPage<T, C extends string | number = string> {
21
27
  totalCount: number;
22
28
  }
23
29
 
24
- export interface iPagination<O extends tOrderBy | Record<string, eOrders> = tOrderBy> {
30
+ export interface iPagination {
25
31
  /**
26
32
  * Identificador del elemento donde empieza la paginacion
27
33
  *
@@ -32,13 +38,7 @@ export interface iPagination<O extends tOrderBy | Record<string, eOrders> = tOrd
32
38
  * Cantidad de elementos (limite)
33
39
  */
34
40
  first?: number;
35
- /**
36
- * JSON string
37
- * aplica a cualquiera columna
38
- * ej: ["id", "asc" ], order ascendente de id
39
- * ej: ["id", "desc" ], order descendente de id
40
- */
41
- orderBy?: O;
41
+ orderBy?: tOrderBy[];
42
42
  }
43
43
 
44
44
  /**
@@ -47,6 +47,5 @@ export interface iPagination<O extends tOrderBy | Record<string, eOrders> = tOrd
47
47
  export type tHydrate<T> = (c: T, e?: unknown) => void;
48
48
 
49
49
  export type iGetPage<T, C extends string | number = string> = (
50
- hydrate: tHydrate<iPage<T, C> | null>,
51
50
  params?: iPagination
52
- ) => Promise<iPage<T, C>>;
51
+ ) => Promise<iPage<T, C> | undefined>;
package/src/form.ts CHANGED
@@ -103,21 +103,12 @@ export type iFormValue = string | number | boolean | File;
103
103
  export interface iFormInputDefault<T extends eFormTypeSimple | eFormTypeComplex = eFormTypeSimple> {
104
104
  required?: boolean;
105
105
  type?: T;
106
- options?: (string | number | iFormOption)[];
107
106
  /**
108
107
  * String without the dots
109
108
  */
110
109
  placeholder?: string;
111
110
  icon?: IconName | tFormIcon;
112
111
  autocomplete?: tFormAutocomplete;
113
- /**
114
- * if muliple is set to true this optional value would be the required minimun amount of values
115
- */
116
- min?: number;
117
- /**
118
- * if multiple is set to true this optional value would be the mandatory maximun amount of values
119
- */
120
- max?: number;
121
112
  }
122
113
 
123
114
  /**
@@ -126,6 +117,7 @@ export interface iFormInputDefault<T extends eFormTypeSimple | eFormTypeComplex
126
117
  export interface iFormInput<V extends iFormValue = iFormValue>
127
118
  extends iFormInputDefault<eFormTypeSimple | eFormTypeComplex> {
128
119
  name: string;
120
+ options?: (string | number | iFormOption)[];
129
121
  /**
130
122
  * An array of values to simplify validation
131
123
  *
@@ -144,12 +136,20 @@ export interface iFormInput<V extends iFormValue = iFormValue>
144
136
  * Ex: { multiple: true, min:3, max:3 } would make 3 values a requirement
145
137
  */
146
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;
147
147
  }
148
148
 
149
149
  /**
150
150
  * Sended form values
151
151
  */
152
- export interface iFormResponse<R = any, T = any> {
152
+ export interface iFormResponse<R = any> {
153
153
  response?: R;
154
154
  invalidInputs: iInvalidInput[];
155
155
  /**
@@ -169,10 +169,6 @@ export interface iFormResponse<R = any, T = any> {
169
169
  * 401 will be reported but not failed
170
170
  */
171
171
  errors?: any;
172
- /**
173
- * Swal target
174
- */
175
- modalTarget?: T;
176
172
  }
177
173
 
178
174
  export interface iFetchResponse<R = any> {
package/src/locale.ts CHANGED
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * @localeType
5
5
  */
6
- export interface iLocaleBase {
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 "¡Connection error!" */
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 interface iLocaleInput {
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 interface iLocaleModal {
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 interface iLocaleForm {
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 required" */
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 interface iLocaleTable {
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;
@@ -247,54 +267,29 @@ export interface iLocaleTable {
247
267
  /** @example "The item may not have been cloned | The items may not have been cloned" */
248
268
  table_possibly_not_cloned: string;
249
269
  };
250
- }
270
+ };
251
271
 
252
272
  /**
253
273
  * Pagination locale
254
274
  *
255
275
  * @localeType
256
276
  */
257
- export interface iLocalePagination {
277
+ export type tLocalePagination = {
258
278
  /** @example "No items | Single item | {count} items" */
259
279
  pagination_items: string;
260
280
  /** @example "No pages | Single page | {count} pages" */
261
281
  pagination_pages: string;
262
- /** @example "Order: relevance" */
263
- pagination_order_relevance: string;
264
- /** @example "Order: more recent" */
265
- pagination_order_recent: string;
266
- /** @example "Order: more older" */
267
- pagination_order_older: string;
268
- /** @example "Order: lower price" */
269
- pagination_order_expensive: string;
270
- /** @example "Order: high price" */
271
- pagination_order_cheaper: string;
272
- /** @example "Order: alphabetically (Asc.)" */
273
- pagination_order_az: string;
274
- /** @example "Order: alphabetically (Desc.)" */
275
- pagination_order_za: string;
276
- /** @example "Filter by:" */
277
- pagination_filter_by: string;
278
282
  // swal: {};
279
- }
283
+ };
280
284
 
281
285
  /**
282
286
  * Plugin locale
283
287
  *
284
288
  * @localeType
285
289
  */
286
- export type tPluginLocale = iLocaleBase &
287
- iLocaleInput &
288
- iLocaleModal &
289
- iLocaleForm &
290
- iLocaleTable &
291
- iLocalePagination;
292
-
293
- /**
294
- * Plugin locale key union
295
- *
296
- * @localeType
297
- */
298
- export type tPluginLocaleKey =
299
- | Exclude<keyof tPluginLocale, "swal">
300
- | `swal.${keyof Required<tPluginLocale>["swal"]}`;
290
+ export type tPluginLocale = tLocaleBase &
291
+ tLocaleInput &
292
+ tLocaleModal &
293
+ tLocaleForm &
294
+ tLocaleTable &
295
+ 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/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 CHANGED
@@ -1,18 +1,20 @@
1
- import DefaultSwal, {
2
- type SweetAlertOptions,
3
- type SweetAlertResult,
4
- } from "sweetalert2/dist/sweetalert2.js";
1
+ import DefaultSwal, { type SweetAlertOptions, type SweetAlertResult } from "sweetalert2";
2
+
3
+ export type tSwalOptions = Omit<SweetAlertOptions, "target"> & {
4
+ target?: SweetAlertOptions["target"] | Event;
5
+ };
5
6
 
6
7
  /**
7
8
  * Extended SweetAlert2 class
8
9
  *
10
+ * Defaults should use Event as target
11
+ *
9
12
  * Do not deestructure this
10
13
  */
11
- export type tSwal = typeof DefaultSwal & {
12
- firePrevent: <T = unknown>(
13
- options?: SweetAlertOptions
14
- ) => Promise<SweetAlertResult<Awaited<T>>>;
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>>>;
15
18
  firePreventDefaults: SweetAlertOptions;
16
- fireLoader: <T = unknown>(options?: SweetAlertOptions) => Promise<SweetAlertResult<Awaited<T>>>;
17
19
  fireLoaderDefaults: SweetAlertOptions;
18
20
  };
package/src/values.ts CHANGED
@@ -9,16 +9,29 @@ export interface iSelectOption {
9
9
  *
10
10
  * Useful for table actions like creating, updating and deleting nodes
11
11
  */
12
- export type iNodeFn<T extends Record<string, any>> = (
13
- n: T
12
+ export type iNodeFn<T extends Record<string, any>, Ta extends [T?] = [T]> = (
13
+ ...args: Ta
14
14
  ) => boolean | undefined | Promise<boolean | undefined>;
15
15
 
16
16
  /**
17
17
  * used on FactoryTable and related components
18
18
  */
19
- export interface iProperty<T extends Record<string, any>> extends iSelectOption {
19
+ export interface iProperty<T extends Record<string, any> = Record<string, any>>
20
+ extends iSelectOption {
20
21
  /**
21
22
  * Function to create a node within the relation
22
23
  */
23
- createNode?: (n?: T) => boolean | undefined | Promise<boolean | undefined>;
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?]>;
24
37
  }