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

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,45 +1,45 @@
1
1
  {
2
- "name": "@open-xamu-co/ui-common-types",
3
- "version": "3.0.0-next.9",
4
- "description": "Xamu shared types",
5
2
  "author": "@xamu-co",
6
- "main": "src/index.ts",
7
- "types": "src/index.ts",
8
- "type": "module",
3
+ "browserslist": [
4
+ "defaults"
5
+ ],
6
+ "bugs": {
7
+ "url": "https://github.com/xamu-co/ui/issues"
8
+ },
9
+ "dependencies": {
10
+ "@fortawesome/fontawesome-common-types": "^6.4.0",
11
+ "@open-xamu-co/ui-common-enums": "^3.0.0",
12
+ "sweetalert2": "^11.11.1"
13
+ },
14
+ "description": "Xamu shared types",
15
+ "engines": {
16
+ "node": ">=18",
17
+ "yarn": ">=1.22.4"
18
+ },
9
19
  "files": [
10
20
  "src/*"
11
21
  ],
12
- "repository": {
13
- "type": "git",
14
- "url": "git+https://github.com/xamu-co/ui.git"
15
- },
22
+ "homepage": "https://github.com/xamu-co/ui#readme",
16
23
  "keywords": [
17
24
  "ts",
18
25
  "js",
19
26
  "types"
20
27
  ],
21
28
  "license": "MIT",
22
- "bugs": {
23
- "url": "https://github.com/xamu-co/ui/issues"
24
- },
25
- "homepage": "https://github.com/xamu-co/ui#readme",
29
+ "main": "src/index.ts",
30
+ "name": "@open-xamu-co/ui-common-types",
26
31
  "publishConfig": {
27
32
  "access": "public"
28
33
  },
34
+ "repository": {
35
+ "type": "git",
36
+ "url": "git+https://github.com/xamu-co/ui.git"
37
+ },
29
38
  "scripts": {
30
39
  "build": "node -e \"console.log('Build step not required')\"",
31
40
  "build:legacy": "rimraf dist && tsc --outDir dist --declaration --emitDeclarationOnly"
32
41
  },
33
- "dependencies": {
34
- "@fortawesome/fontawesome-common-types": "^6.4.0",
35
- "@open-xamu-co/ui-common-enums": "^3.0.0-next.1",
36
- "sweetalert2": "^11.7.5"
37
- },
38
- "engines": {
39
- "node": ">=18",
40
- "yarn": ">=1.22.4"
41
- },
42
- "browserslist": [
43
- "defaults"
44
- ]
42
+ "type": "module",
43
+ "types": "src/index.ts",
44
+ "version": "3.0.0"
45
45
  }
package/src/fetch.ts CHANGED
@@ -1,4 +1,12 @@
1
- export type tOrderBy = [string, ("desc" | "asc")?];
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;
@@ -19,7 +27,7 @@ export interface iPage<T, C extends string | number = string> {
19
27
  totalCount: number;
20
28
  }
21
29
 
22
- export interface iPagination<O = tOrderBy> {
30
+ export interface iPagination {
23
31
  /**
24
32
  * Identificador del elemento donde empieza la paginacion
25
33
  *
@@ -30,19 +38,9 @@ export interface iPagination<O = tOrderBy> {
30
38
  * Cantidad de elementos (limite)
31
39
  */
32
40
  first?: number;
33
- /**
34
- * Ordenar segun columna o propiedad
35
- * ej: ["id", "asc" ], order ascendente de id
36
- * ej: ["id", "desc" ], order descendente de id
37
- */
38
- orderBy?: O;
41
+ orderBy?: tOrderBy[];
39
42
  }
40
43
 
41
- /**
42
- * Hydrate fetch ref (no refresh)
43
- */
44
- export type tHydrate<T> = (c: T, e?: unknown) => void;
45
-
46
44
  export type iGetPage<T, C extends string | number = string> = (
47
45
  params?: iPagination
48
46
  ) => Promise<iPage<T, C> | undefined>;
@@ -0,0 +1,93 @@
1
+ import type {
2
+ eFormTypeBase,
3
+ eFormTypeSimple,
4
+ eFormTypeComplex,
5
+ } from "@open-xamu-co/ui-common-enums";
6
+
7
+ import type {
8
+ iFormInput,
9
+ iFormInputDefault,
10
+ iFormValue,
11
+ tFormAutocomplete,
12
+ tFormIcon,
13
+ } from "./types";
14
+ import type { iSelectOption } from "../values.js";
15
+
16
+ export declare abstract class tFormInputDefault<
17
+ T extends eFormTypeBase | eFormTypeSimple | eFormTypeComplex = eFormTypeSimple.TEXT,
18
+ > implements iFormInputDefault<T>
19
+ {
20
+ // public
21
+ public type: T;
22
+ // public readonly
23
+ public readonly required: boolean;
24
+ public readonly placeholder: string;
25
+ public readonly icon?: tFormIcon;
26
+ public readonly autocomplete?: tFormAutocomplete;
27
+
28
+ /** Rerender component */
29
+ public rerender(): void;
30
+
31
+ /** Set rerender function */
32
+ public setRerender(rerender: (fi?: Partial<iFormInputDefault<T>>) => void): this;
33
+ }
34
+
35
+ export declare class tFormInput<V extends iFormValue = iFormValue, Vk extends V | V[] = V | V[]>
36
+ extends tFormInputDefault<eFormTypeBase | eFormTypeSimple | eFormTypeComplex>
37
+ implements iFormInput<V, Vk>
38
+ {
39
+ // public readonly
40
+ public readonly name: string;
41
+ public readonly title?: string;
42
+ public readonly multiple: boolean;
43
+ public readonly min: number;
44
+ public readonly max: number;
45
+ // public
46
+ public options: iSelectOption[];
47
+ public values: Vk[];
48
+ public defaults?: [iFormInputDefault, iFormInputDefault, ...iFormInputDefault[]];
49
+ /**
50
+ * set rerender function
51
+ *
52
+ * @override
53
+ */
54
+ public setRerender(rerender: (fi?: Partial<iFormInput<V>>) => void): this;
55
+ /**
56
+ * add new model to the models
57
+ */
58
+ public addValue(newValue?: Vk): this;
59
+ /**
60
+ * remove the given value from the values
61
+ */
62
+ public removeValue(index: number): this;
63
+
64
+ /**
65
+ * Clone this object
66
+ */
67
+ public clone(
68
+ overrides?: Omit<iFormInput<V, Vk>, "name"> & { name?: string },
69
+ onUpdatedValues?: (updatedValues: Vk[]) => Vk[] | undefined | void
70
+ ): tFormInput<V, Vk>;
71
+ /**
72
+ * Get simple object
73
+ */
74
+ public getObject<Vi extends iFormValue = iFormValue, Vik extends Vi | Vi[] = Vi>(
75
+ input: iFormInput<Vi, Vik>
76
+ ): iFormInput<Vi, Vik>;
77
+
78
+ public isEqual(other: tFormInput): boolean;
79
+ }
80
+
81
+ export interface iForm {
82
+ /**
83
+ * Optional form key
84
+ */
85
+ key?: string;
86
+ title?: string;
87
+ inputs: tFormInput[];
88
+ listen?: boolean;
89
+ /** Make all inputs read only by disabling them */
90
+ readonly?: boolean;
91
+ /** Message when no valid inputs are rendered */
92
+ emptyMessage?: string;
93
+ }
@@ -0,0 +1,2 @@
1
+ export * from "./class";
2
+ export * from "./types";
@@ -1,8 +1,8 @@
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
- import type { iSelectOption } from "./values.js";
5
+ import type { iSelectOption } from "../values.js";
6
6
 
7
7
  export interface iFormOption extends iSelectOption {
8
8
  /**
@@ -95,14 +95,16 @@ 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> {
104
- required?: boolean;
103
+ export interface iFormInputDefault<
104
+ T extends eFormTypeBase | eFormTypeSimple | eFormTypeComplex = eFormTypeSimple.TEXT,
105
+ > {
105
106
  type?: T;
107
+ required?: boolean;
106
108
  /**
107
109
  * String without the dots
108
110
  */
@@ -114,8 +116,8 @@ export interface iFormInputDefault<T extends eFormTypeSimple | eFormTypeComplex
114
116
  /**
115
117
  * Complex input, sub input support
116
118
  */
117
- export interface iFormInput<V extends iFormValue = iFormValue>
118
- extends iFormInputDefault<eFormTypeSimple | eFormTypeComplex> {
119
+ export interface iFormInput<V extends iFormValue = iFormValue, Vk extends V | V[] = V | V[]>
120
+ extends iFormInputDefault<eFormTypeBase | eFormTypeSimple | eFormTypeComplex> {
119
121
  name: string;
120
122
  options?: (string | number | iFormOption)[];
121
123
  /**
@@ -123,7 +125,7 @@ export interface iFormInput<V extends iFormValue = iFormValue>
123
125
  *
124
126
  * @old value
125
127
  */
126
- values?: (V | V[])[];
128
+ values?: Vk[];
127
129
  defaults?: [iFormInputDefault, iFormInputDefault, ...iFormInputDefault[]];
128
130
  /**
129
131
  * Visible over the field, should describe it
@@ -149,7 +151,7 @@ export interface iFormInput<V extends iFormValue = iFormValue>
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,12 +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
- * If the swal was triggered from a modal, then use it as render target
176
- */
177
- modalTarget?: T;
178
174
  }
179
175
 
180
176
  export interface iFetchResponse<R = any> {
package/src/index.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export * from "./files.js";
2
- export * from "./form.js";
2
+ export * from "./form/index.js";
3
3
  export * from "./transform.js";
4
4
  export * from "./styles.js";
5
5
  export * from "./props.js";
package/src/locale.ts CHANGED
@@ -192,6 +192,10 @@ export type tLocaleForm = {
192
192
  form_unmatching_passwords: string;
193
193
  /** @example "Invalid data" */
194
194
  form_invalid_data: string;
195
+ /** @example "No values" */
196
+ form_no_values: string;
197
+ /** @example "New value" */
198
+ form_new_value: string;
195
199
  // swal: {};
196
200
  };
197
201
 
@@ -205,8 +209,12 @@ export type tLocaleTable = {
205
209
  table_see_values: string;
206
210
  /** @example "See: \"{name}\"" */
207
211
  table_see_name: string;
212
+ /** @example "Hide: \"{name}\"" */
213
+ table_hide_name: string;
208
214
  /** @example "Create new" */
209
215
  table_create_new: string;
216
+ /** @example "Crear nuevo" */
217
+ table_create_new_name: string;
210
218
  /** @example "Quantity: {count} */
211
219
  table_quantity: string;
212
220
  /** @example "Modify" */
@@ -275,22 +283,6 @@ export type tLocalePagination = {
275
283
  pagination_items: string;
276
284
  /** @example "No pages | Single page | {count} pages" */
277
285
  pagination_pages: string;
278
- /** @example "Order: relevance" */
279
- pagination_order_relevance: string;
280
- /** @example "Order: more recent" */
281
- pagination_order_recent: string;
282
- /** @example "Order: more older" */
283
- pagination_order_older: string;
284
- /** @example "Order: lower price" */
285
- pagination_order_expensive: string;
286
- /** @example "Order: high price" */
287
- pagination_order_cheaper: string;
288
- /** @example "Order: alphabetically (Asc.)" */
289
- pagination_order_az: string;
290
- /** @example "Order: alphabetically (Desc.)" */
291
- pagination_order_za: string;
292
- /** @example "Filter by:" */
293
- pagination_filter_by: string;
294
286
  // swal: {};
295
287
  };
296
288
 
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
@@ -106,13 +108,11 @@ export interface iPluginOptions<ComponentType = unknown> {
106
108
  */
107
109
  country?: string;
108
110
  /**
109
- * Countries API base endpoint
111
+ * Countries API base endpoint (full URL)
110
112
  *
111
113
  * If using nuxt, get better performance with the module
112
114
  * @see https://www.npmjs.com/package/nuxt-countries-api
113
115
  *
114
- * Using an absolute path will enable the module
115
- *
116
116
  * @default "https://countries.xamu.com.co/api/v1"
117
117
  */
118
118
  countriesUrl?: string;
@@ -134,4 +134,10 @@ export interface iPluginOptions<ComponentType = unknown> {
134
134
  * @default 10
135
135
  */
136
136
  first?: number;
137
+ /**
138
+ * Logger function for debugging purposes
139
+ *
140
+ * @default console.log
141
+ */
142
+ logger?: tLogger;
137
143
  }
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,24 +2,54 @@ export interface iSelectOption {
2
2
  value: string | number;
3
3
  alias?: string;
4
4
  selected?: boolean;
5
+ disabled?: boolean;
6
+ hidden?: boolean;
5
7
  }
6
8
 
9
+ export type iNodeFnResponse = [boolean?, Event?, (() => void)?];
10
+
7
11
  /**
8
12
  * Funtions that uses a node and perform some action
9
13
  *
10
14
  * Useful for table actions like creating, updating and deleting nodes
11
15
  */
12
- export type iNodeFn<T extends Record<string, any>> = (
13
- n: T
14
- ) => boolean | undefined | Promise<boolean | undefined>;
16
+ export type iNodeFn<T extends Record<string, any>, Ta extends [T?, ...any[]] = [T]> = (
17
+ ...args: Ta
18
+ ) => boolean | undefined | iNodeFnResponse | Promise<boolean | undefined | iNodeFnResponse>;
15
19
 
16
20
  /**
17
21
  * used on FactoryTable and related components
18
22
  */
19
- export interface iProperty<T extends Record<string, any> = Record<string, any>>
20
- extends iSelectOption {
23
+ export interface iProperty<
24
+ T extends Record<string, any> = Record<string, any>,
25
+ P extends Record<string, any> = Record<string, any>,
26
+ ComponentType = unknown,
27
+ > extends iSelectOption {
21
28
  /**
22
29
  * Function to create a node within the relation
30
+ * The parent is given since the node doesn't exist yet
31
+ */
32
+ createNode?: iNodeFn<P, [P?]>;
33
+ /**
34
+ * Conditionally disable creating children for this particular property
35
+ */
36
+ disableCreateNode?: (p: P) => boolean;
37
+ /**
38
+ * Function to clone a node within the relation
39
+ */
40
+ cloneNode?: iNodeFn<T, [T?]>;
41
+ /**
42
+ * Function to update a node within the relation
43
+ */
44
+ updateNode?: iNodeFn<T, [T?, P?]>;
45
+ /**
46
+ * Function to delete a node within the relation
23
47
  */
24
- createNode?: (n?: T) => boolean | undefined | Promise<boolean | undefined>;
48
+ deleteNode?: iNodeFn<T, [T?]>;
49
+ /**
50
+ * Render using this component instead
51
+ */
52
+ component?: ComponentType;
25
53
  }
54
+
55
+ export type tPropertyOrderFn = (a: [string, any], b: [string, any]) => -1 | 0 | 1;