@open-xamu-co/ui-common-types 3.0.0-next.2 → 3.0.0-next.21

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.2",
3
+ "version": "3.0.0-next.21",
4
4
  "description": "Xamu shared types",
5
5
  "author": "@xamu-co",
6
6
  "main": "src/index.ts",
@@ -32,8 +32,8 @@
32
32
  },
33
33
  "dependencies": {
34
34
  "@fortawesome/fontawesome-common-types": "^6.4.0",
35
- "@open-xamu-co/ui-common-enums": "^2.0.1-next.1",
36
- "sweetalert2": "^11.7.5"
35
+ "@open-xamu-co/ui-common-enums": "^3.0.0-next.6",
36
+ "sweetalert2": "^11.11.1"
37
37
  },
38
38
  "engines": {
39
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,21 +38,9 @@ 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
- /**
45
- * Hydrate fetch ref (no refresh)
46
- */
47
- export type tHydrate<T> = (c: T, e?: unknown) => void;
48
-
49
44
  export type iGetPage<T, C extends string | number = string> = (
50
- hydrate: tHydrate<iPage<T, C> | null>,
51
45
  params?: iPagination
52
- ) => Promise<iPage<T, C>>;
46
+ ) => Promise<iPage<T, C> | undefined>;
package/src/form.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import type { IconName } from "@fortawesome/fontawesome-common-types";
2
2
 
3
- import { eFormTypeComplex, eFormTypeSimple } from "@open-xamu-co/ui-common-enums";
3
+ import { eFormTypeBase, eFormTypeComplex, eFormTypeSimple } from "@open-xamu-co/ui-common-enums";
4
4
 
5
5
  import type { iSelectOption } from "./values.js";
6
6
 
@@ -95,43 +95,37 @@ export type iFormIconProps = { brand?: boolean; regular?: boolean };
95
95
 
96
96
  export type tFormIcon = [IconName | undefined, iFormIconProps];
97
97
 
98
- export type iFormValue = string | number | boolean | File;
98
+ export type iFormValue = string | number | boolean | File | Date;
99
99
 
100
100
  /**
101
101
  * Simple input
102
102
  */
103
- export interface iFormInputDefault<T extends eFormTypeSimple | eFormTypeComplex = eFormTypeSimple> {
103
+ export interface iFormInputDefault<
104
+ T extends eFormTypeBase | eFormTypeSimple | eFormTypeComplex = eFormTypeSimple,
105
+ > {
104
106
  required?: boolean;
105
107
  type?: T;
106
- options?: (string | number | iFormOption)[];
107
108
  /**
108
109
  * String without the dots
109
110
  */
110
111
  placeholder?: string;
111
112
  icon?: IconName | tFormIcon;
112
113
  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
114
  }
122
115
 
123
116
  /**
124
117
  * Complex input, sub input support
125
118
  */
126
- export interface iFormInput<V extends iFormValue = iFormValue>
127
- extends iFormInputDefault<eFormTypeSimple | eFormTypeComplex> {
119
+ export interface iFormInput<V extends iFormValue = iFormValue, Vk extends V | V[] = V | V[]>
120
+ extends iFormInputDefault<eFormTypeBase | eFormTypeSimple | eFormTypeComplex> {
128
121
  name: string;
122
+ options?: (string | number | iFormOption)[];
129
123
  /**
130
124
  * An array of values to simplify validation
131
125
  *
132
126
  * @old value
133
127
  */
134
- values?: (V | V[])[];
128
+ values?: Vk[];
135
129
  defaults?: [iFormInputDefault, iFormInputDefault, ...iFormInputDefault[]];
136
130
  /**
137
131
  * Visible over the field, should describe it
@@ -144,12 +138,20 @@ export interface iFormInput<V extends iFormValue = iFormValue>
144
138
  * Ex: { multiple: true, min:3, max:3 } would make 3 values a requirement
145
139
  */
146
140
  multiple?: boolean;
141
+ /**
142
+ * if muliple is set to true this optional value would be the required minimun amount of values
143
+ */
144
+ min?: number;
145
+ /**
146
+ * if multiple is set to true this optional value would be the mandatory maximun amount of values
147
+ */
148
+ max?: number;
147
149
  }
148
150
 
149
151
  /**
150
152
  * Sended form values
151
153
  */
152
- export interface iFormResponse<R = any, T = any> {
154
+ export interface iFormResponse<R = any> {
153
155
  response?: R;
154
156
  invalidInputs: iInvalidInput[];
155
157
  /**
@@ -169,10 +171,6 @@ export interface iFormResponse<R = any, T = any> {
169
171
  * 401 will be reported but not failed
170
172
  */
171
173
  errors?: any;
172
- /**
173
- * Swal target
174
- */
175
- modalTarget?: T;
176
174
  }
177
175
 
178
176
  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,21 +192,27 @@ 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}\"" */
195
211
  table_see_name: string;
196
212
  /** @example "Create new" */
197
213
  table_create_new: string;
214
+ /** @example "Crear nuevo" */
215
+ table_create_new_name: string;
198
216
  /** @example "Quantity: {count} */
199
217
  table_quantity: string;
200
218
  /** @example "Modify" */
@@ -221,6 +239,10 @@ export interface iLocaleTable {
221
239
  table_options: string;
222
240
  /** @example "Open URL" */
223
241
  table_open_url: string;
242
+ /** @example "Hide all" */
243
+ table_hide_all: string;
244
+ /** @example "Show all" */
245
+ table_show_all: string;
224
246
  swal: {
225
247
  /** @example "Are you sure you want to delete this element?" */
226
248
  table_delete_node_title: string;
@@ -247,54 +269,29 @@ export interface iLocaleTable {
247
269
  /** @example "The item may not have been cloned | The items may not have been cloned" */
248
270
  table_possibly_not_cloned: string;
249
271
  };
250
- }
272
+ };
251
273
 
252
274
  /**
253
275
  * Pagination locale
254
276
  *
255
277
  * @localeType
256
278
  */
257
- export interface iLocalePagination {
279
+ export type tLocalePagination = {
258
280
  /** @example "No items | Single item | {count} items" */
259
281
  pagination_items: string;
260
282
  /** @example "No pages | Single page | {count} pages" */
261
283
  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
284
  // swal: {};
279
- }
285
+ };
280
286
 
281
287
  /**
282
288
  * Plugin locale
283
289
  *
284
290
  * @localeType
285
291
  */
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"]}`;
292
+ export type tPluginLocale = tLocaleBase &
293
+ tLocaleInput &
294
+ tLocaleModal &
295
+ tLocaleForm &
296
+ tLocaleTable &
297
+ tLocalePagination;
package/src/plugin.ts CHANGED
@@ -4,6 +4,7 @@ import type { tPluginLocale } from "./locale.js";
4
4
  import type { SweetAlertOptions } from "sweetalert2";
5
5
 
6
6
  export type tComponent = (typeof componentNames)[number];
7
+ export type tLogger = (at: string, ...logs: unknown[]) => any;
7
8
 
8
9
  export type tSupportedLangs =
9
10
  | "kr"
@@ -98,6 +99,7 @@ export interface iPluginOptions<ComponentType = unknown> {
98
99
  overrides?: SweetAlertOptions;
99
100
  preventOverrides?: SweetAlertOptions;
100
101
  loaderOverrides?: SweetAlertOptions;
102
+ toastOverrides?: SweetAlertOptions;
101
103
  };
102
104
  /**
103
105
  * Iso2 code for the default country
@@ -105,6 +107,15 @@ export interface iPluginOptions<ComponentType = unknown> {
105
107
  * When a country is provided forms will omit that field
106
108
  */
107
109
  country?: string;
110
+ /**
111
+ * Countries API base endpoint (full URL)
112
+ *
113
+ * If using nuxt, get better performance with the module
114
+ * @see https://www.npmjs.com/package/nuxt-countries-api
115
+ *
116
+ * @default "https://countries.xamu.com.co/api/v1"
117
+ */
118
+ countriesUrl?: string;
108
119
  /**
109
120
  * Disable automatic animations
110
121
  *
@@ -123,4 +134,10 @@ export interface iPluginOptions<ComponentType = unknown> {
123
134
  * @default 10
124
135
  */
125
136
  first?: number;
137
+ /**
138
+ * Logger function for debugging purposes
139
+ *
140
+ * @default console.log
141
+ */
142
+ logger?: tLogger;
126
143
  }
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,15 +1,22 @@
1
1
  import DefaultSwal, { type SweetAlertOptions, type SweetAlertResult } from "sweetalert2";
2
2
 
3
+ export type tSwalOptions = Omit<SweetAlertOptions, "target"> & {
4
+ target?: SweetAlertOptions["target"] | Event;
5
+ };
6
+
3
7
  /**
4
8
  * Extended SweetAlert2 class
5
9
  *
10
+ * Defaults should use Event as target
11
+ *
6
12
  * Do not deestructure this
7
13
  */
8
- export type tSwal = typeof DefaultSwal & {
9
- firePrevent: <T = unknown>(
10
- options?: SweetAlertOptions
11
- ) => 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>>>;
18
+ fireToast: <T = any>(options?: tSwalOptions) => Promise<SweetAlertResult<Awaited<T>>>;
12
19
  firePreventDefaults: SweetAlertOptions;
13
- fireLoader: <T = unknown>(options?: SweetAlertOptions) => Promise<SweetAlertResult<Awaited<T>>>;
14
20
  fireLoaderDefaults: SweetAlertOptions;
21
+ fireToastDefaults: SweetAlertOptions;
15
22
  };
package/src/values.ts CHANGED
@@ -2,23 +2,53 @@ export interface iSelectOption {
2
2
  value: string | number;
3
3
  alias?: string;
4
4
  selected?: boolean;
5
+ disabled?: boolean;
5
6
  }
6
7
 
8
+ export type iNodeFnResponse = [boolean?, Event?, (() => void)?];
9
+
7
10
  /**
8
11
  * Funtions that uses a node and perform some action
9
12
  *
10
13
  * Useful for table actions like creating, updating and deleting nodes
11
14
  */
12
- export type iNodeFn<T extends Record<string, any>> = (
13
- n: T
14
- ) => boolean | undefined | Promise<boolean | undefined>;
15
+ export type iNodeFn<T extends Record<string, any>, Ta extends [T?, ...any[]] = [T]> = (
16
+ ...args: Ta
17
+ ) => boolean | undefined | iNodeFnResponse | Promise<boolean | undefined | iNodeFnResponse>;
15
18
 
16
19
  /**
17
20
  * used on FactoryTable and related components
18
21
  */
19
- export interface iProperty<T extends Record<string, any>> extends iSelectOption {
22
+ export interface iProperty<
23
+ T extends Record<string, any> = Record<string, any>,
24
+ P extends Record<string, any> = Record<string, any>,
25
+ ComponentType = unknown,
26
+ > extends iSelectOption {
20
27
  /**
21
28
  * Function to create a node within the relation
29
+ * The parent is given since the node doesn't exist yet
30
+ */
31
+ createNode?: iNodeFn<P, [P?]>;
32
+ /**
33
+ * Conditionally disable creating children for this particular property
34
+ */
35
+ disableCreateNode?: (p: P) => boolean;
36
+ /**
37
+ * Function to clone a node within the relation
38
+ */
39
+ cloneNode?: iNodeFn<T, [T?]>;
40
+ /**
41
+ * Function to update a node within the relation
42
+ */
43
+ updateNode?: iNodeFn<T, [T?, P?]>;
44
+ /**
45
+ * Function to delete a node within the relation
22
46
  */
23
- createNode?: (n?: T) => boolean | undefined | Promise<boolean | undefined>;
47
+ deleteNode?: iNodeFn<T, [T?]>;
48
+ /**
49
+ * Render using this component instead
50
+ */
51
+ component?: ComponentType;
24
52
  }
53
+
54
+ export type tPropertyOrderFn = (a: [string, any], b: [string, any]) => -1 | 0 | 1;