eco-vue-js 0.7.2 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/components/Button/WButtonGroup.vue.d.ts +5 -4
- package/dist/components/Button/WButtonGroup.vue.d.ts.map +1 -1
- package/dist/components/Button/WButtonGroup.vue.js +12 -4
- package/dist/components/Button/types.d.ts +17 -6
- package/dist/components/Button/types.d.ts.map +1 -1
- package/dist/components/Form/WFormValidator.vue.d.ts.map +1 -1
- package/dist/components/Form/WFormValidator.vue.js +3 -4
- package/dist/components/FormAsync/WFormAsyncButtonGroup.vue.d.ts +25 -0
- package/dist/components/FormAsync/WFormAsyncButtonGroup.vue.d.ts.map +1 -0
- package/dist/components/FormAsync/WFormAsyncButtonGroup.vue.js +101 -0
- package/dist/components/FormAsync/WFormAsyncButtonGroup.vue2.js +5 -0
- package/dist/components/FormAsync/WFormAsyncInput.vue.d.ts +26 -0
- package/dist/components/FormAsync/WFormAsyncInput.vue.d.ts.map +1 -0
- package/dist/components/FormAsync/WFormAsyncInput.vue.js +131 -0
- package/dist/components/FormAsync/WFormAsyncInput.vue2.js +5 -0
- package/dist/components/FormAsync/WFormAsyncSelectSingle.vue.d.ts +27 -0
- package/dist/components/FormAsync/WFormAsyncSelectSingle.vue.d.ts.map +1 -0
- package/dist/components/FormAsync/WFormAsyncSelectSingle.vue.js +139 -0
- package/dist/components/FormAsync/WFormAsyncSelectSingle.vue2.js +5 -0
- package/dist/components/FormAsync/WFormAsyncToggle.vue.d.ts +22 -0
- package/dist/components/FormAsync/WFormAsyncToggle.vue.d.ts.map +1 -0
- package/dist/components/FormAsync/WFormAsyncToggle.vue.js +89 -0
- package/dist/components/FormAsync/WFormAsyncToggle.vue2.js +5 -0
- package/dist/components/FormAsync/types.d.ts +85 -0
- package/dist/components/FormAsync/types.d.ts.map +1 -0
- package/dist/components/InfiniteList/WInfiniteList.vue.d.ts +3 -3
- package/dist/components/InfiniteList/WInfiniteList.vue.d.ts.map +1 -1
- package/dist/components/InfiniteList/WInfiniteListPages.vue.d.ts +3 -3
- package/dist/components/InfiniteList/WInfiniteListPages.vue.d.ts.map +1 -1
- package/dist/components/InfiniteList/components/InfiniteListPage.vue.d.ts +6 -6
- package/dist/components/InfiniteList/components/InfiniteListPage.vue.d.ts.map +1 -1
- package/dist/components/List/WList.vue.d.ts +2 -2
- package/dist/components/List/WList.vue.d.ts.map +1 -1
- package/dist/components/List/WList.vue.js +2 -2
- package/dist/components/Select/WSelect.vue.d.ts +12 -13
- package/dist/components/Select/WSelect.vue.d.ts.map +1 -1
- package/dist/components/Select/WSelect.vue.js +44 -33
- package/dist/components/Select/WSelectAsync.vue.d.ts +4 -5
- package/dist/components/Select/WSelectAsync.vue.d.ts.map +1 -1
- package/dist/components/Select/WSelectAsync.vue.js +20 -15
- package/dist/components/Select/WSelectAsyncList.vue.d.ts +3 -3
- package/dist/components/Select/WSelectAsyncList.vue.d.ts.map +1 -1
- package/dist/components/Select/WSelectAsyncSingle.vue.d.ts +2 -5
- package/dist/components/Select/WSelectAsyncSingle.vue.d.ts.map +1 -1
- package/dist/components/Select/WSelectAsyncSingle.vue.js +4 -7
- package/dist/components/Select/WSelectSingle.vue.d.ts +8 -8
- package/dist/components/Select/WSelectSingle.vue.d.ts.map +1 -1
- package/dist/components/Select/WSelectSingle.vue.js +3 -2
- package/dist/components/Select/components/SelectAsyncList.vue.d.ts +3 -3
- package/dist/components/Select/components/SelectAsyncList.vue.d.ts.map +1 -1
- package/dist/components/Select/components/SelectAsyncPrefix.vue.d.ts +4 -2
- package/dist/components/Select/components/SelectAsyncPrefix.vue.d.ts.map +1 -1
- package/dist/components/Select/components/SelectAsyncPrefix.vue.js +2 -1
- package/dist/components/Select/components/SelectAsyncPrefixPage.vue.d.ts +4 -2
- package/dist/components/Select/components/SelectAsyncPrefixPage.vue.d.ts.map +1 -1
- package/dist/components/Select/components/SelectAsyncPrefixPage.vue.js +4 -2
- package/dist/components/Select/components/SelectOptionPrefix.vue.d.ts +2 -2
- package/dist/components/Select/components/SelectOptionPrefix.vue.d.ts.map +1 -1
- package/dist/components/Select/components/SelectOptionPrefix.vue.js +3 -1
- package/dist/components/Select/types.d.ts +22 -20
- package/dist/components/Select/types.d.ts.map +1 -1
- package/dist/components/Tabs/WTabs.vue.d.ts +2 -2
- package/dist/components/Tabs/WTabs.vue.d.ts.map +1 -1
- package/dist/components/Tabs/WTabs.vue.js +3 -3
- package/dist/components/Toggle/WToggle.vue.d.ts +3 -12
- package/dist/components/Toggle/WToggle.vue.d.ts.map +1 -1
- package/dist/components/Toggle/WToggle.vue.js +3 -1
- package/dist/components/Toggle/types.d.ts +13 -0
- package/dist/components/Toggle/types.d.ts.map +1 -0
- package/dist/imports/componentsPlugin.d.ts +5 -1
- package/dist/imports/componentsPlugin.d.ts.map +1 -1
- package/dist/main.d.ts +3 -0
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +8 -1
- package/dist/types/global.d.ts +98 -10
- package/dist/utils/api.d.ts +16 -0
- package/dist/utils/api.d.ts.map +1 -0
- package/dist/utils/api.js +28 -0
- package/dist/utils/useDefaultQuery.d.ts +2 -1
- package/dist/utils/useDefaultQuery.d.ts.map +1 -1
- package/dist/utils/useQueryUpdater.d.ts +12 -0
- package/dist/utils/useQueryUpdater.d.ts.map +1 -0
- package/dist/utils/useQueryUpdater.js +56 -0
- package/dist/utils/utils.d.ts +2 -0
- package/dist/utils/utils.d.ts.map +1 -1
- package/dist/utils/utils.js +13 -1
- package/dist/utils/validate.d.ts +2 -0
- package/dist/utils/validate.d.ts.map +1 -0
- package/dist/utils/validate.js +3 -0
- package/package.json +28 -1
package/dist/types/global.d.ts
CHANGED
@@ -26,7 +26,7 @@ declare type PaginatedResponse<ValueType extends Record<string, unknown> | unkno
|
|
26
26
|
results: ValueType[]
|
27
27
|
}
|
28
28
|
|
29
|
-
declare type ValidateFn = (value: string | number | undefined | string[]) => string | undefined
|
29
|
+
declare type ValidateFn = (value: string | number | undefined | string[] | boolean | null) => string | undefined
|
30
30
|
|
31
31
|
declare type InputType = 'number' | 'text' | 'tel' | 'search' | 'password' | 'email' | 'search' | 'url'
|
32
32
|
|
@@ -36,22 +36,21 @@ declare module 'eco-vue-js/dist/assets/icons/*' {
|
|
36
36
|
export default src
|
37
37
|
}
|
38
38
|
|
39
|
-
declare type DefaultData = {id: number, [key: string]: unknown}
|
39
|
+
declare type DefaultData = {id: number | string, [key: string]: unknown}
|
40
40
|
|
41
41
|
type Params = Parameters<import('@tanstack/vue-query').QueryClient['setQueriesData']>
|
42
42
|
|
43
|
-
declare type UseQueryDefault<TQueryFnData = unknown,
|
44
|
-
typeof import('../utils/useDefaultQuery').useDefaultQuery<TQueryFnData,
|
43
|
+
declare type UseQueryDefault<TQueryFnData = unknown, TData = TQueryFnData, TQueryKey extends import('@tanstack/vue-query').QueryKey = import('@tanstack/vue-query').QueryKey> =
|
44
|
+
typeof import('../utils/useDefaultQuery').useDefaultQuery<TQueryFnData, TData, TQueryKey>
|
45
45
|
|
46
|
-
declare type QueryOptions<Data
|
46
|
+
declare type QueryOptions<Data> = Partial<Parameters<typeof import('../utils/useDefaultQuery').useDefaultQuery<Data>>[0]>
|
47
47
|
|
48
|
-
declare type UseQueryEmpty<Model
|
48
|
+
declare type UseQueryEmpty<Model> = (options?: QueryOptions<Model>) => ReturnType<typeof import('../utils/useDefaultQuery').useDefaultQuery<Model>>
|
49
49
|
|
50
|
-
declare type UseQueryWithParams<Model,
|
51
|
-
(queryParams: import('vue').MaybeRef<QueryParams>, options?: QueryOptions<Model
|
52
|
-
|
53
|
-
declare type UseQueryPaginated<Model, ApiError, QueryParams> = UseQueryWithParams<PaginatedResponse<Model>, ApiError, QueryParams>
|
50
|
+
declare type UseQueryWithParams<Model, QueryParams> =
|
51
|
+
(queryParams: import('vue').MaybeRef<QueryParams>, options?: QueryOptions<Model>) => ReturnType<typeof import('../utils/useDefaultQuery').useDefaultQuery<Model>>
|
54
52
|
|
53
|
+
declare type UseQueryPaginated<Model, QueryParams> = UseQueryWithParams<PaginatedResponse<Model>, QueryParams>
|
55
54
|
|
56
55
|
declare interface SelectedPage<Value> {
|
57
56
|
page: number
|
@@ -64,6 +63,45 @@ declare type SelectedRange<Value> = [
|
|
64
63
|
SelectedPage<Value>,
|
65
64
|
]
|
66
65
|
|
66
|
+
declare type ConfirmProps = Omit<import('../components/Modal/types').ConfirmModalProps, 'onAccept' | 'onCancel' | 'onIntermediate'>
|
67
|
+
|
68
|
+
declare type RequestData = Record<string, unknown> | Record<string, unknown>[] | FormData
|
69
|
+
|
70
|
+
declare type RequestConfig<Data extends RequestData = RequestData> = {
|
71
|
+
data?: Data
|
72
|
+
params?: Record<string, string | number | Record<string, unknown> | number[] | Record<string, unknown>[] | undefined>
|
73
|
+
signal?: AbortSignal
|
74
|
+
noAuth?: boolean
|
75
|
+
updateToken?: boolean
|
76
|
+
}
|
77
|
+
|
78
|
+
declare type RequestResponse<Response, Data extends RequestData = RequestData> = {
|
79
|
+
data: Response
|
80
|
+
status?: number
|
81
|
+
config?: RequestConfig<Data>
|
82
|
+
request: Request
|
83
|
+
}
|
84
|
+
|
85
|
+
/**
|
86
|
+
* UTILITY TYPES
|
87
|
+
*/
|
88
|
+
|
89
|
+
declare type OmitReqursive<Model extends object, Field extends keyof Model | string | number | symbol> = {
|
90
|
+
[Key in Exclude<keyof Model, Field>]: Model[Key] extends object[]
|
91
|
+
? OmitReqursive<Model[Key][number], Field>[]
|
92
|
+
: Model[Key] extends object
|
93
|
+
? OmitReqursive<Model[Key], Field>
|
94
|
+
: Model[Key]
|
95
|
+
} & {[K in Field]: never}
|
96
|
+
|
97
|
+
declare type PickByType<Model, FieldType, IncludeNull = false> = {
|
98
|
+
[
|
99
|
+
Key in keyof Model as IncludeNull extends true
|
100
|
+
? Exclude<Model[Key], null> extends FieldType ? Key : never
|
101
|
+
: Model[Key] extends FieldType ? Key : never
|
102
|
+
]: Model[Key]
|
103
|
+
}
|
104
|
+
|
67
105
|
declare type UnionToIntersection<T> =
|
68
106
|
(T extends T ? (arg: T) => 0 : never) extends
|
69
107
|
(arg: infer I) => 0
|
@@ -89,3 +127,53 @@ declare type UnionToTuple<
|
|
89
127
|
]
|
90
128
|
|
91
129
|
declare type ObjectKeys<O> = UnionToTuple<keyof O>
|
130
|
+
|
131
|
+
declare type PartialNested<T> = {
|
132
|
+
[P in keyof T]?: (T[P] extends object ? PartialNested<T[P]> : T[P]) | undefined
|
133
|
+
}
|
134
|
+
|
135
|
+
declare type Flatten<T> =
|
136
|
+
T extends []
|
137
|
+
? []
|
138
|
+
: T extends [infer Head, ...infer Tail]
|
139
|
+
? [...Flatten<Head>, ...Flatten<Tail>]
|
140
|
+
: [T]
|
141
|
+
|
142
|
+
declare type FilterOut<T, Pred> =
|
143
|
+
T extends [infer Head, ...infer Tail]
|
144
|
+
? [Head] extends [Pred]
|
145
|
+
? FilterOut<Tail, Pred>
|
146
|
+
: [Head, ...FilterOut<Tail, Pred>]
|
147
|
+
: []
|
148
|
+
|
149
|
+
declare type Split<Value extends string, Divider extends string> = Value extends `${ infer Start }${ Divider }${ infer End }`
|
150
|
+
? [...Split<Start, Divider>, ...Split<End, Divider>]
|
151
|
+
: Value extends '' ? [] : [Value]
|
152
|
+
|
153
|
+
declare type Indexes<T> = Readonly<T> extends readonly [unknown, ...infer Tail]
|
154
|
+
? [...Indexes<Tail>, Tail['length']]
|
155
|
+
: []
|
156
|
+
|
157
|
+
type PathsEntries<Model, FieldType, IncludeNull = false, ParentKey extends string = never, FilteredModel = PickByType<Model, FieldType, IncludeNull>> = ObjectKeys<Model> extends [infer Head, ...unknown[]]
|
158
|
+
? Head extends string
|
159
|
+
? Head extends keyof FilteredModel
|
160
|
+
? [
|
161
|
+
[[ParentKey] extends [never] ? Head : `${ ParentKey }.${ Head }`, FilteredModel[Head]],
|
162
|
+
...PathsEntries<Omit<Model, Head>, FieldType, IncludeNull, ParentKey, FilteredModel>
|
163
|
+
]
|
164
|
+
: Head extends keyof Model
|
165
|
+
? Model[Head] extends object
|
166
|
+
? [
|
167
|
+
...PathsEntries<Model[Head], FieldType, IncludeNull, Head>,
|
168
|
+
...PathsEntries<Omit<Model, Head>, FieldType, IncludeNull, ParentKey, FilteredModel>
|
169
|
+
]
|
170
|
+
: PathsEntries<Omit<Model, Head>, FieldType, IncludeNull, ParentKey, FilteredModel>
|
171
|
+
: []
|
172
|
+
: []
|
173
|
+
: []
|
174
|
+
|
175
|
+
declare type ObjectFromEntries<List> = {
|
176
|
+
[KeyValue in List as KeyValue[0]]: KeyValue[1]
|
177
|
+
}
|
178
|
+
|
179
|
+
declare type ObjectPaths<Model, FieldType, IncludeNull = false> = ObjectFromEntries<PathsEntries<Model, FieldType, IncludeNull>[number]>
|
@@ -0,0 +1,16 @@
|
|
1
|
+
import { default as WForm } from '../components/Form/WForm.vue';
|
2
|
+
import { default as WFormValidator } from '../components/Form/WFormValidator.vue';
|
3
|
+
|
4
|
+
export declare class ApiError<Response, Data extends RequestData = RequestData> extends Error {
|
5
|
+
readonly response: RequestResponse<Response, Data>;
|
6
|
+
constructor(response: RequestResponse<Response, Data>);
|
7
|
+
}
|
8
|
+
export declare class ApiErrorCancel<Response, Data extends RequestData = RequestData> extends ApiError<Response, Data> {
|
9
|
+
constructor(response: RequestResponse<Response, Data>);
|
10
|
+
}
|
11
|
+
export declare const handleApiError: <Error>(error: Error, form?: {
|
12
|
+
invalidate: ComponentInstance<typeof WForm>["invalidate"];
|
13
|
+
}, field?: string, formValidator?: {
|
14
|
+
invalidate: ComponentInstance<typeof WFormValidator>["invalidate"];
|
15
|
+
}) => Promise<Error>;
|
16
|
+
//# sourceMappingURL=api.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../src/utils/api.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,6BAA6B,CAAA;AACpD,OAAO,KAAK,cAAc,MAAM,sCAAsC,CAAA;AAItE,qBAAa,QAAQ,CAAC,QAAQ,EAAE,IAAI,SAAS,WAAW,GAAG,WAAW,CAAE,SAAQ,KAAK;aACvD,QAAQ,EAAE,eAAe,CAAC,QAAQ,EAAE,IAAI,CAAC;gBAAzC,QAAQ,EAAE,eAAe,CAAC,QAAQ,EAAE,IAAI,CAAC;CAGtE;AAED,qBAAa,cAAc,CAAC,QAAQ,EAAE,IAAI,SAAS,WAAW,GAAG,WAAW,CAAE,SAAQ,QAAQ,CAAC,QAAQ,EAAE,IAAI,CAAC;gBAChG,QAAQ,EAAE,eAAe,CAAC,QAAQ,EAAE,IAAI,CAAC;CAGtD;AAED,eAAO,MAAM,cAAc,GAAI,KAAK,SAC3B,KAAK,SACL;IAAC,UAAU,EAAE,iBAAiB,CAAC,OAAO,KAAK,CAAC,CAAC,YAAY,CAAC,CAAA;CAAC,UAC1D,MAAM,kBACE;IAAC,UAAU,EAAE,iBAAiB,CAAC,OAAO,cAAc,CAAC,CAAC,YAAY,CAAC,CAAA;CAAC,KACnF,OAAO,CAAC,KAAK,CAgBf,CAAA"}
|
@@ -0,0 +1,28 @@
|
|
1
|
+
import { Notify } from './Notify.js';
|
2
|
+
import { get } from './utils.js';
|
3
|
+
|
4
|
+
class ApiError extends Error {
|
5
|
+
constructor(response) {
|
6
|
+
super();
|
7
|
+
this.response = response;
|
8
|
+
}
|
9
|
+
}
|
10
|
+
class ApiErrorCancel extends ApiError {
|
11
|
+
constructor(response) {
|
12
|
+
super(response);
|
13
|
+
}
|
14
|
+
}
|
15
|
+
const handleApiError = (error, form, field, formValidator) => {
|
16
|
+
if (error instanceof ApiError && !(error instanceof ApiErrorCancel)) {
|
17
|
+
const caption = error.response?.data?.detail ?? error.response?.data?.non_field_errors?.join(", ") ?? (field ? get(error.response?.data, field)?.join(", ") : void 0);
|
18
|
+
Notify.error({
|
19
|
+
title: "Error",
|
20
|
+
caption: typeof caption === "string" && caption.length < 200 ? caption : void 0
|
21
|
+
});
|
22
|
+
if (formValidator && caption.length < 200) formValidator.invalidate(caption);
|
23
|
+
if (error.response?.data instanceof Object) form?.invalidate(error.response.data);
|
24
|
+
}
|
25
|
+
return Promise.reject(error);
|
26
|
+
};
|
27
|
+
|
28
|
+
export { ApiError, ApiErrorCancel, handleApiError };
|
@@ -1,7 +1,8 @@
|
|
1
1
|
import { QueryClient, UseQueryReturnType, QueryKey } from '@tanstack/vue-query';
|
2
|
+
import { ApiError } from './api';
|
2
3
|
|
3
4
|
type Params = Parameters<QueryClient['setQueriesData']>;
|
4
|
-
export declare const useDefaultQuery: <TQueryFnData = unknown,
|
5
|
+
export declare const useDefaultQuery: <TQueryFnData = unknown, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey>(options: import('@tanstack/vue-query').UseQueryOptions<TQueryFnData, ApiError<TQueryFnData, RequestData>, TData, TQueryFnData, TQueryKey>, queryClient?: QueryClient | undefined) => UseQueryReturnType<TData, ApiError<TQueryFnData>> & {
|
5
6
|
setData: (updater: TQueryFnData, options?: Params[2]) => ReturnType<QueryClient["setQueriesData"]>;
|
6
7
|
};
|
7
8
|
export {};
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"useDefaultQuery.d.ts","sourceRoot":"","sources":["../../src/utils/useDefaultQuery.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"useDefaultQuery.d.ts","sourceRoot":"","sources":["../../src/utils/useDefaultQuery.ts"],"names":[],"mappings":"AAAA,OAAO,EAA2B,KAAK,WAAW,EAAE,KAAK,kBAAkB,EAAE,KAAK,QAAQ,EAAC,MAAM,qBAAqB,CAAA;AACtH,OAAO,KAAK,EAAC,QAAQ,EAAC,MAAM,OAAO,CAAA;AAEnC,KAAK,MAAM,GAAG,UAAU,CAAC,WAAW,CAAC,gBAAgB,CAAC,CAAC,CAAA;AAEvD,eAAO,MAAM,eAAe,GAC1B,YAAY,YACZ,KAAK,iBACL,SAAS,SAAS,QAAQ,kMAEsE,kBAAkB,CAAC,KAAK,EAAE,QAAQ,CAAC,YAAY,CAAC,CAAC,GAAG;IAClJ,OAAO,EAAE,CAAC,OAAO,EAAE,YAAY,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,KAAK,UAAU,CAAC,WAAW,CAAC,gBAAgB,CAAC,CAAC,CAAA;CAUrG,CAAA"}
|
@@ -0,0 +1,12 @@
|
|
1
|
+
import { QueryFilters } from '@tanstack/vue-query';
|
2
|
+
|
3
|
+
export declare const paginatedResponseUpdater: <Data extends DefaultData>(oldData: PaginatedResponse<Data> | undefined, newValues: Data[], selected: number[], reverseSelection?: boolean) => PaginatedResponse<Data> | undefined;
|
4
|
+
export declare const useQueryUpdater: () => {
|
5
|
+
update: <Model extends DefaultData>(data: Model, options: {
|
6
|
+
listQueryFilter?: QueryFilters;
|
7
|
+
paginatedQueryFilter?: QueryFilters;
|
8
|
+
}) => void;
|
9
|
+
updateBulk: <Model extends DefaultData>(data: Model[], filter: QueryFilters) => void;
|
10
|
+
delete: <Model extends DefaultData>(filter: QueryFilters, selected: number[], reverse?: boolean) => void;
|
11
|
+
};
|
12
|
+
//# sourceMappingURL=useQueryUpdater.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"useQueryUpdater.d.ts","sourceRoot":"","sources":["../../src/utils/useQueryUpdater.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,KAAK,YAAY,EAAC,MAAM,qBAAqB,CAAA;AAErE,eAAO,MAAM,wBAAwB,GAAI,IAAI,SAAS,WAAW,WAAW,iBAAiB,CAAC,IAAI,CAAC,GAAG,SAAS,aAAa,IAAI,EAAE,YAAY,MAAM,EAAE,iCAA6B,iBAAiB,CAAC,IAAI,CAAC,GAAG,SAuB5M,CAAA;AAED,eAAO,MAAM,eAAe;aAGV,KAAK,SAAS,WAAW,QAAQ,KAAK,WAAW;QAAC,eAAe,CAAC,EAAE,YAAY,CAAC;QAAC,oBAAoB,CAAC,EAAE,YAAY,CAAA;KAAC;iBAwBlH,KAAK,SAAS,WAAW,QAAQ,KAAK,EAAE,UAAU,YAAY;aAM7D,KAAK,SAAS,WAAW,UAAU,YAAY,YAAY,MAAM,EAAE;CAYzF,CAAA"}
|
@@ -0,0 +1,56 @@
|
|
1
|
+
import { useQueryClient } from '@tanstack/vue-query';
|
2
|
+
|
3
|
+
const paginatedResponseUpdater = (oldData, newValues, selected, reverseSelection = false) => {
|
4
|
+
if (!oldData) return void 0;
|
5
|
+
const included = reverseSelection ? oldData.results.filter((item) => !selected.includes(item.id)) : oldData.results.filter((item) => selected.includes(item.id));
|
6
|
+
if (!included.length) return oldData;
|
7
|
+
const newData = { ...oldData, results: oldData.results.slice() };
|
8
|
+
included.forEach((oldItem) => {
|
9
|
+
const index = newData.results.indexOf(oldItem);
|
10
|
+
if (index === -1) return;
|
11
|
+
const finding = newValues.find((item) => item.id === oldItem.id);
|
12
|
+
if (finding) newData.results.splice(index, 1, finding);
|
13
|
+
else newData.results.splice(index, 1);
|
14
|
+
});
|
15
|
+
return newData;
|
16
|
+
};
|
17
|
+
const useQueryUpdater = () => {
|
18
|
+
const queryClient = useQueryClient();
|
19
|
+
const update = (data, options) => {
|
20
|
+
if (options.listQueryFilter) {
|
21
|
+
queryClient.setQueriesData(options.listQueryFilter, (value) => {
|
22
|
+
if (!value) return;
|
23
|
+
const index = value.findIndex((item) => item.id === data.id);
|
24
|
+
if (index === -1) return;
|
25
|
+
const newList = value.slice();
|
26
|
+
newList.splice(index, 1, data);
|
27
|
+
return newList;
|
28
|
+
});
|
29
|
+
}
|
30
|
+
if (options.paginatedQueryFilter) {
|
31
|
+
queryClient.setQueriesData(
|
32
|
+
options.paginatedQueryFilter,
|
33
|
+
(oldData) => paginatedResponseUpdater(oldData, [data], [data.id])
|
34
|
+
);
|
35
|
+
}
|
36
|
+
};
|
37
|
+
const updateBulk = (data, filter) => {
|
38
|
+
queryClient.setQueriesData(
|
39
|
+
filter,
|
40
|
+
(oldData) => paginatedResponseUpdater(oldData, data, data.map((item) => item.id))
|
41
|
+
);
|
42
|
+
};
|
43
|
+
const deleteItems = (filter, selected, reverse = false) => {
|
44
|
+
queryClient.setQueriesData(
|
45
|
+
filter,
|
46
|
+
(oldData) => paginatedResponseUpdater(oldData, [], selected, reverse)
|
47
|
+
);
|
48
|
+
};
|
49
|
+
return {
|
50
|
+
update,
|
51
|
+
updateBulk,
|
52
|
+
delete: deleteItems
|
53
|
+
};
|
54
|
+
};
|
55
|
+
|
56
|
+
export { paginatedResponseUpdater, useQueryUpdater };
|
package/dist/utils/utils.d.ts
CHANGED
@@ -16,5 +16,7 @@ export declare const parseId: (value: unknown) => number;
|
|
16
16
|
export declare const isPage: (value: unknown) => value is number;
|
17
17
|
export declare const isIndex: (value: unknown) => value is number;
|
18
18
|
export declare const parseIndex: (value: unknown) => number;
|
19
|
+
export declare const get: <FieldType, Data extends Record<string, FieldType | Data>>(data: Data, path: keyof ObjectPaths<Data, FieldType>) => FieldType | undefined;
|
20
|
+
export declare const set: <FieldType, Data extends Record<string, FieldType | Data>>(data: Data, path: keyof ObjectPaths<Data, FieldType>, value: FieldType) => Data;
|
19
21
|
export {};
|
20
22
|
//# sourceMappingURL=utils.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils/utils.ts"],"names":[],"mappings":"AAWA,eAAO,MAAM,eAAe,SAAU,OAAO,KAAG,OAAO,GAAG,IAKhD,CAAA;AAEV,eAAO,MAAM,mBAAmB,UAAW,OAAO,mBAAa,KAAK,CAAC,OAAO,CAa3E,CAAA;AAED,eAAO,MAAM,SAAS,WAAY,OAAO,WAAW,OAAO,KAAG,OAI7D,CAAA;AAGD,KAAK,UAAU,GAAG,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,CAAA;AAE1C,wBAAgB,QAAQ,CAAC,CAAC,SAAS,UAAU,EAAE,EAAE,EAAE,CAAC,EAAE,KAAK,SAAM,GAAG,CAAC,CAWpE;AAED,wBAAgB,QAAQ,CAAC,CAAC,SAAS,UAAU,EAAE,EAAE,EAAE,CAAC,EAAE,KAAK,SAAM,GAAG,CAAC,CAYpE;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,KAAG,IAYtJ,CAAA"}
|
package/dist/utils/utils.js
CHANGED
@@ -79,5 +79,17 @@ const parseIndex = (value) => {
|
|
79
79
|
if (isIndex(parsed)) return parsed;
|
80
80
|
return NaN;
|
81
81
|
};
|
82
|
+
const get = (data, path) => path.split(".").reduce((result, current) => result?.[current], data);
|
83
|
+
const set = (data, path, value) => {
|
84
|
+
path.split(".").reduce((acc, current, index, array) => {
|
85
|
+
if (index !== array.length - 1) {
|
86
|
+
if (!acc[current]) acc[current] = {};
|
87
|
+
} else {
|
88
|
+
acc[current] = value;
|
89
|
+
}
|
90
|
+
return acc;
|
91
|
+
}, data);
|
92
|
+
return data;
|
93
|
+
};
|
82
94
|
|
83
|
-
export { debounce, genId, getAllScrollParents, getScrollParent, hasParent, isClientSide, isEqualArr, isEqualObj, isId, isIndex, isPage, numberCompactFormatter, numberFormatter, parseId, parseIndex, percentCompactFormatter, throttle };
|
95
|
+
export { debounce, genId, get, getAllScrollParents, getScrollParent, hasParent, isClientSide, isEqualArr, isEqualObj, isId, isIndex, isPage, numberCompactFormatter, numberFormatter, parseId, parseIndex, percentCompactFormatter, set, throttle };
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../../src/utils/validate.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,gBAAgB,UAAW,OAAO,sCAGsC,CAAA"}
|
package/package.json
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
"type": "git",
|
5
5
|
"url": "https://github.com/rsmple/eco-vue-js.git"
|
6
6
|
},
|
7
|
-
"version": "0.
|
7
|
+
"version": "0.8.0",
|
8
8
|
"scripts": {
|
9
9
|
"dev": "vite",
|
10
10
|
"build": "run-p type-check build-only",
|
@@ -105,6 +105,9 @@
|
|
105
105
|
"./dist/utils/useDefaultQuery": {
|
106
106
|
"import": "./dist/utils/useDefaultQuery.js"
|
107
107
|
},
|
108
|
+
"./dist/utils/useQueryUpdater": {
|
109
|
+
"import": "./dist/utils/useQueryUpdater.js"
|
110
|
+
},
|
108
111
|
"./dist/utils/useCopy": {
|
109
112
|
"import": "./dist/utils/useCopy.js"
|
110
113
|
},
|
@@ -114,6 +117,12 @@
|
|
114
117
|
"./dist/utils/useSelected": {
|
115
118
|
"import": "./dist/utils/useSelected.js"
|
116
119
|
},
|
120
|
+
"./dist/utils/api": {
|
121
|
+
"import": "./dist/utils/api.js"
|
122
|
+
},
|
123
|
+
"./dist/utils/validate": {
|
124
|
+
"import": "./dist/utils/validate.js"
|
125
|
+
},
|
117
126
|
"./dist/components/ActionsBar/WActionsBar.vue": {
|
118
127
|
"import": "./dist/components/ActionsBar/WActionsBar.vue.js"
|
119
128
|
},
|
@@ -204,6 +213,21 @@
|
|
204
213
|
"./dist/components/Form/WFormValidator.vue": {
|
205
214
|
"import": "./dist/components/Form/WFormValidator.vue.js"
|
206
215
|
},
|
216
|
+
"./dist/components/FormAsync/WFormAsyncButtonGroup.vue": {
|
217
|
+
"import": "./dist/components/FormAsync/WFormAsyncButtonGroup.vue.js"
|
218
|
+
},
|
219
|
+
"./dist/components/FormAsync/WFormAsyncInput.vue": {
|
220
|
+
"import": "./dist/components/FormAsync/WFormAsyncInput.vue.js"
|
221
|
+
},
|
222
|
+
"./dist/components/FormAsync/WFormAsyncSelectSingle.vue": {
|
223
|
+
"import": "./dist/components/FormAsync/WFormAsyncSelectSingle.vue.js"
|
224
|
+
},
|
225
|
+
"./dist/components/FormAsync/WFormAsyncToggle.vue": {
|
226
|
+
"import": "./dist/components/FormAsync/WFormAsyncToggle.vue.js"
|
227
|
+
},
|
228
|
+
"./dist/components/FormAsync/types": {
|
229
|
+
"import": "./dist/components/FormAsync/types.d.ts"
|
230
|
+
},
|
207
231
|
"./dist/components/HeaderBar/WHeaderBar.vue": {
|
208
232
|
"import": "./dist/components/HeaderBar/WHeaderBar.vue.js"
|
209
233
|
},
|
@@ -327,6 +351,9 @@
|
|
327
351
|
"./dist/components/Toggle/WToggle.vue": {
|
328
352
|
"import": "./dist/components/Toggle/WToggle.vue.js"
|
329
353
|
},
|
354
|
+
"./dist/components/Toggle/types": {
|
355
|
+
"import": "./dist/components/Toggle/types.d.ts"
|
356
|
+
},
|
330
357
|
"./dist/components/Tooltip/WTooltip.vue": {
|
331
358
|
"import": "./dist/components/Tooltip/WTooltip.vue.js"
|
332
359
|
},
|