@fewangsit/wangsvue-fats 1.0.0-alpha.125 → 1.0.0-alpha.127

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.
@@ -11,6 +11,7 @@ import { CalendarProps } from '../calendar/Calendar.vue.d';
11
11
  import { QueryParams } from '../datatable/DataTable.vue.d';
12
12
  import { InputRangeNumberProps } from '../inputrangenumber/InputRangeNumber.vue.d';
13
13
  import { MultiSelectProps } from '../multiselect/MultiSelect.vue.d';
14
+ import { StringKeyOf, TypeError } from '../ts-helpers';
14
15
 
15
16
  export type FilterMatchMode =
16
17
  | 'CONTAINS'
@@ -24,83 +25,79 @@ export type FilterMatchMode =
24
25
  | 'BETWEEN'
25
26
  | 'DATE_BETWEEN';
26
27
 
27
- /**
28
- * Represents a function type for fetching options based on query parameters.
29
- *
30
- * @template T - The type of query parameters, extending `QueryParams`. Defaults to `any`.
31
- *
32
- * This function can have one of the following signatures:
33
- * - A synchronous function that takes query parameters and returns an array of `Option` objects.
34
- * - An asynchronous function that takes query parameters and returns a `Promise` resolving to an array of `Option` objects.
35
- * - An asynchronous function that takes query parameters and returns a `Promise` resolving to an `AxiosResponse` containing a `FetchOptionResponse` object.
36
- *
37
- * @param args - The query parameters of type `T` used to fetch the options.
38
- * @returns One of the following:
39
- * - An array of `Option` objects.
40
- * - A `Promise` resolving to an array of `Option` objects.
41
- * - A `Promise` resolving to an `AxiosResponse` containing a `FetchOptionResponse` object.
42
- */
43
- export type FetchOptionFn<T extends QueryParams = any> =
44
- | ((args: T) => Option[])
45
- | ((args: T) => Promise<Option[]>)
46
- | ((args: T) => Promise<AxiosResponse<FetchOptionResponse<T>>>);
47
-
48
- // More specific filter field types
49
- export interface MultiSelectFilterField extends MultiSelectProps {
50
- type: 'multiselect';
28
+ type BaseSelectField<OptionsQueryParams extends QueryParams> = {
51
29
  /**
52
- * The name of the field this filter applies to.
30
+ * Represents a function type for fetching options based on query parameters.
53
31
  *
54
- * When using a static filter, it also specifies the field in the data to be used for generating unique options.
55
- * For example, if filtering by a user's full name, the field could be 'user.fullName', which will extract
56
- * unique full names from the table data and use them as filter options.
57
- */
58
- field: string;
59
- optionField?: string; // @example - actionOptions
60
- params?: QueryParams; // Additional QueryParams for the fetchOptionFn
61
- fetchOptionFn?: FetchOptionFn;
62
- }
63
-
64
- export interface DropdownFilterField extends DropdownProps {
65
- type: 'dropdown';
66
- /**
67
- * The name of the field this filter applies to.
32
+ * @template T - The type of query parameters, extending `QueryParams`. Defaults to `any`.
68
33
  *
69
- * When using a static filter, it also specifies the field in the data to be used for generating unique options.
70
- * For example, if filtering by a user's full name, the field could be 'user.fullName', which will extract
71
- * unique full names from the table data and use them as filter options.
72
- */
73
- field: string;
74
- optionField?: string; // @example - actionOptions
75
- params?: QueryParams; // Additional QueryParams for the fetchOptionFn
76
- fetchOptionFn?: FetchOptionFn;
77
- }
78
-
79
- export interface RangeNumberFilterField extends InputRangeNumberProps {
80
- type: 'rangenumber';
81
- /**
82
- * Specify min and max field
34
+ * This function can have one of the following signatures:
35
+ * - A synchronous function that takes query parameters and returns an array of `Option` objects.
36
+ * - An asynchronous function that takes query parameters and returns a `Promise` resolving to an array of `Option` objects.
37
+ * - An asynchronous function that takes query parameters and returns a `Promise` resolving to an `AxiosResponse` containing a `FetchOptionResponse` object.
83
38
  *
84
- * @example ['minAge', 'maxAge']
39
+ * @param args - The query parameters of type `T` used to fetch the options.
40
+ * @returns One of the following:
41
+ * - An array of `Option` objects.
42
+ * - A `Promise` resolving to an array of `Option` objects.
43
+ * - A `Promise` resolving to an `AxiosResponse` containing a `FetchOptionResponse` object.
85
44
  */
86
- fields?: string[];
45
+ fetchOptionFn?(
46
+ args: OptionsQueryParams,
47
+ ):
48
+ | Option[]
49
+ | Promise<Option[]>
50
+ | Promise<AxiosResponse<FetchOptionResponse<OptionsQueryParams>>>;
51
+
52
+ optionField?: keyof OptionsQueryParams; // @example - actionOptions
53
+ params?: OptionsQueryParams; // Additional QueryParams for the fetchOptionFn
54
+ };
87
55
 
88
- /**
89
- * Specify single field for both min and max input.
90
- * The value will be a number array.
91
- *
92
- * Prever use this property when you are working with Static Filtering
93
- *
94
- * @example value: [1000,5000] or equal to 'value.0': 1000 & 'value.1': 5000
95
- */
96
- field?: string;
97
- tooltip?: string;
56
+ export interface MultiSelectFilterField<OptionsQueryParams extends QueryParams>
57
+ extends BaseSelectField<OptionsQueryParams>,
58
+ MultiSelectProps {
59
+ type: 'multiselect';
60
+ }
61
+
62
+ export interface DropdownFilterField<OptionsQueryParams extends QueryParams>
63
+ extends BaseSelectField<OptionsQueryParams>,
64
+ DropdownProps {
65
+ type: 'dropdown';
98
66
  }
99
67
 
100
- export interface ButtonSelectTreeFilterField
101
- extends Omit<ButtonSelectTreeProps, 'type' | 'label' | 'fieldLabel'> {
68
+ type RangeNumberFilterField<Field extends string> =
69
+ | (InputRangeNumberProps & {
70
+ type: 'rangenumber';
71
+ /**
72
+ * Specify min and max field
73
+ *
74
+ * @example ['minAge', 'maxAge']
75
+ */
76
+ fields: [Field, Field];
77
+ field?: TypeError<'`field` must not be specified when using `fields` property'>;
78
+ tooltip?: string;
79
+ })
80
+ | (InputRangeNumberProps & {
81
+ type: 'rangenumber';
82
+ /**
83
+ * Specify single field for both min and max input.
84
+ * The value will be a number array.
85
+ *
86
+ * Prefer using this property when working with Static Filtering
87
+ *
88
+ * @example value: [1000, 5000] or equivalent to 'value.0': 1000 & 'value.1': 5000
89
+ */
90
+ field: Field;
91
+ fields?: TypeError<'`fields` must not be specified when using `field` property'>;
92
+ tooltip?: string;
93
+ });
94
+
95
+ export interface ButtonSelectTreeFilterField<
96
+ Field extends string,
97
+ Params = QueryParams,
98
+ > extends Omit<ButtonSelectTreeProps, 'type' | 'label' | 'fieldLabel'> {
102
99
  type: 'group' | 'category';
103
- field: string; // The name of the field this filter applies to
100
+ field: Field; // The name of the field this filter applies to
104
101
  /**
105
102
  * The field label.
106
103
  */
@@ -110,31 +107,47 @@ export interface ButtonSelectTreeFilterField
110
107
  * @default to Select Group|Category
111
108
  */
112
109
  buttonLabel?: string;
113
- params?: QueryParams; // Override QueryParams for the fetchTree
110
+ params?: Params; // Override QueryParams for the fetchTree
114
111
  }
115
112
 
116
113
  export interface CalendarFilterField extends CalendarProps {
117
114
  type: 'calendar';
118
- field: string;
119
115
  }
120
116
 
121
- export type AdditionalFilterField = ButtonSelectTreeFilterField;
117
+ export type AdditionalFilterField<Field extends string = string> =
118
+ ButtonSelectTreeFilterField<Field>;
122
119
 
123
- export type FilterField = (
124
- | AdditionalFilterField
125
- | MultiSelectFilterField
126
- | DropdownFilterField
127
- | RangeNumberFilterField
128
- | CalendarFilterField
129
- ) & {
120
+ export type BaseFilterField<Params extends QueryParams = QueryParams> = {
130
121
  /**
131
122
  * Filter field visibility
132
123
  *
133
124
  * You dont need manually filter, this component already handle it.
134
125
  */
135
126
  visible?: boolean;
127
+ /**
128
+ * The name of the field this filter applies to.
129
+ *
130
+ * When using a static filter, it also specifies the field in the data to be used for generating unique options.
131
+ * For example, if filtering by a user's full name, the field could be 'user.fullName', which will extract
132
+ * unique full names from the table data and use them as filter options.
133
+ */
134
+ field: keyof Params;
136
135
  };
137
136
 
137
+ export type FilterField<
138
+ Params extends QueryParams = QueryParams,
139
+ OptionsQueryParams extends QueryParams = QueryParams,
140
+ > =
141
+ | (BaseFilterField<Params> &
142
+ (
143
+ | AdditionalFilterField<StringKeyOf<Params>>
144
+ | MultiSelectFilterField<OptionsQueryParams>
145
+ | DropdownFilterField<OptionsQueryParams>
146
+ | CalendarFilterField
147
+ ))
148
+ | (Omit<BaseFilterField<Params>, 'field'> &
149
+ RangeNumberFilterField<StringKeyOf<Params>>);
150
+
138
151
  export type FilterOptions<Opt = Record<string, boolean>> = Record<
139
152
  keyof Opt,
140
153
  Option[]
@@ -176,11 +189,6 @@ export interface FilterContainerProps {
176
189
  * Slots for FilterContainer component
177
190
  */
178
191
  export type FilterContainerSlots = {
179
- /**
180
- * @deprecated Please use props.fields instead
181
- */
182
- default: Slot;
183
-
184
192
  /**
185
193
  * Additional template for field.
186
194
  */
@@ -168,6 +168,10 @@ export interface ImageCompressorProps {
168
168
  * @default 'webp'
169
169
  */
170
170
  fileType?: 'webp' | 'jpeg' | 'jpg';
171
+ /**
172
+ * @default normal
173
+ */
174
+ type?: 'inline-table' | 'normal';
171
175
  }
172
176
 
173
177
  export interface ImageCompressorSlots {
@@ -81,3 +81,11 @@ export declare type PresetMethodOptions = {
81
81
  export declare type PresetOptionMethodType<Opt = PresetMethodOptions> = (
82
82
  options: Partial<Opt>,
83
83
  ) => PresetAttributes;
84
+
85
+ export type StringKeyOf<T> = Extract<keyof T, string>;
86
+
87
+ declare const TypeException: unique symbol;
88
+
89
+ export type TypeError<T extends string> = {
90
+ [TypeException]: T;
91
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fewangsit/wangsvue-fats",
3
- "version": "1.0.0-alpha.125",
3
+ "version": "1.0.0-alpha.127",
4
4
  "author": "Wangsit FE Developer",
5
5
  "description": "Fixed Asset Tagsamurai VueJS Component Library",
6
6
  "type": "module",