@open-xamu-co/ui-common-types 4.0.0-next.5 → 4.0.0-next.7

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": "4.0.0-next.5",
3
+ "version": "4.0.0-next.7",
4
4
  "description": "Xamu shared types",
5
5
  "author": "@xamu-co",
6
6
  "main": "src/index.ts",
package/src/fetch.ts CHANGED
@@ -65,5 +65,6 @@ export interface iPagination {
65
65
  }
66
66
 
67
67
  export type iGetPage<T, C extends string | number = string> = (
68
- params?: iPagination
68
+ params?: iPagination,
69
+ signal?: AbortSignal
69
70
  ) => Promise<iPage<T, C> | undefined>;
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,
@@ -44,12 +45,13 @@ export declare abstract class tFormInput<
44
45
  // public readonly
45
46
  public readonly name: string;
46
47
  public readonly title?: string;
47
- public readonly multiple: boolean;
48
- public readonly min: number;
49
- public readonly max: number;
50
- public readonly meta?: Record<string, any>;
48
+ public readonly optionsFilter?: tOptionsLoaderFn;
51
49
  // public
52
- public options: iSelectOption[];
50
+ public multiple: boolean;
51
+ public min: number;
52
+ public max: number;
53
+ public meta?: Record<string, any>;
54
+ public options: iFormOption[];
53
55
  public values: V[];
54
56
  public defaults?: [
55
57
  iFormInputDefault<eFormTypeBase | eFormTypeSimple | eFormTypeComplex>,
package/src/form/types.ts CHANGED
@@ -113,15 +113,29 @@ export interface iFormInputDefault<
113
113
  autocomplete?: tFormAutocomplete;
114
114
  }
115
115
 
116
+ export type tOptionsLoaderFn =
117
+ | ((v?: string | number, signal?: AbortSignal) => iFormOption[])
118
+ | ((v?: string | number, signal?: AbortSignal) => Promise<iFormOption[]>);
119
+
120
+ /** If a function is given, it should be responsible of determining if v is a value or an alias (search) */
121
+ export type iFormInputOptions = (string | number | iFormOption)[] | tOptionsLoaderFn;
122
+
116
123
  /**
117
124
  * Complex input, sub input support
125
+ * Used as input for the classes
118
126
  */
119
127
  export interface iFormInput<
120
128
  V extends iFormValue | iFormValue[],
121
129
  T extends eFormTypeBase | eFormTypeSimple | eFormTypeComplex,
122
130
  > extends iFormInputDefault<T> {
123
131
  name: string;
124
- options?: (string | number | iFormOption)[];
132
+ /**
133
+ * Options for select, checkbox, radio inputs
134
+ * The usage of a function requires a compatible component (SelectFilter)
135
+ *
136
+ * @values array of options or function that returns options
137
+ */
138
+ options?: iFormInputOptions;
125
139
  /**
126
140
  * An array of values to simplify validation
127
141
  *
@@ -189,6 +203,13 @@ export interface iFetchResponse<R = any> {
189
203
  [x: string]: any;
190
204
  }
191
205
 
206
+ /**
207
+ * Takes the parsed inputs values and perform a request (content creation, update, etc).
208
+ *
209
+ * @param values Values of the input
210
+ * @param fetcher Request function
211
+ * @returns Response with data and errors if any
212
+ */
192
213
  export type tResponseFn<T, V extends Record<string, any> = Record<string, any>> = (
193
214
  values: V
194
215
  ) => Promise<iFetchResponse<T>>;
package/src/values.ts CHANGED
@@ -11,11 +11,10 @@ export interface iSelectOption {
11
11
  *
12
12
  * Action result, event and callback
13
13
  */
14
- export type iNodeFnResponse<T extends Record<string, any> = never> = [
15
- (boolean | T)?,
16
- Event?,
17
- (() => void)?,
18
- ];
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)?];
19
18
 
20
19
  /**
21
20
  * Stream like response from node functions
@@ -23,9 +22,12 @@ export type iNodeFnResponse<T extends Record<string, any> = never> = [
23
22
  * Action result, event and callback
24
23
  * Can accept an stream like array for multiple updates (hydration)
25
24
  */
26
- export type iNodeFnResponseStream<T extends Record<string, any> = never> = [
25
+ export type iNodeFnResponseStream<
26
+ T extends Record<string, any> = never,
27
+ E extends Record<string, any> = Record<string, any>,
28
+ > = [
27
29
  (boolean | T | [boolean | T, ...Promise<boolean | T>[]])?,
28
- Event?,
30
+ (Event & Partial<CustomEvent<E>>)?,
29
31
  (() => void)?,
30
32
  ];
31
33