@karta.io/utils 1.0.0-alpha.9 → 1.0.0-beta.10
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/dist/index.cjs +71 -43
- package/dist/index.d.cts +350 -0
- package/dist/index.d.mts +350 -0
- package/dist/index.d.ts +9 -8
- package/dist/index.mjs +71 -43
- package/package.json +21 -20
package/dist/index.cjs
CHANGED
|
@@ -77,18 +77,25 @@ function convertEnumToOptions(obj, options) {
|
|
|
77
77
|
}
|
|
78
78
|
|
|
79
79
|
function formatMoney(value, currency = commonData.CURRENCY_DEFAULT, options = {}) {
|
|
80
|
-
const
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
80
|
+
const { locale = "en-US", defaultValue = 0, ...otherOptions } = options;
|
|
81
|
+
try {
|
|
82
|
+
let convertedValue = Number(value);
|
|
83
|
+
if (value === null || Number.isNaN(convertedValue)) {
|
|
84
|
+
if (defaultValue === "")
|
|
85
|
+
return defaultValue;
|
|
86
|
+
convertedValue = Number(defaultValue);
|
|
87
|
+
}
|
|
88
|
+
const formatter = new Intl.NumberFormat(locale, {
|
|
89
|
+
style: "currency",
|
|
90
|
+
currency,
|
|
91
|
+
minimumFractionDigits: 2,
|
|
92
|
+
maximumFractionDigits: 2,
|
|
93
|
+
...otherOptions
|
|
94
|
+
});
|
|
95
|
+
return formatter.format(convertedValue);
|
|
96
|
+
} catch (error) {
|
|
97
|
+
return defaultValue;
|
|
98
|
+
}
|
|
92
99
|
}
|
|
93
100
|
|
|
94
101
|
function genHash(hashLength) {
|
|
@@ -415,7 +422,7 @@ function useAsyncMultiselect({
|
|
|
415
422
|
const { call, abort } = useAbortController(apiMethod);
|
|
416
423
|
const loadWAC = () => {
|
|
417
424
|
const includedIdsBySelectedValues = reactiveData.selectedValues ?? [];
|
|
418
|
-
const includedIdsByParams = JSON.parse(reactiveData.params || {})?.includedIds ?? [];
|
|
425
|
+
const includedIdsByParams = (Boolean(reactiveData.params) && JSON.parse(reactiveData.params || {})?.includedIds) ?? [];
|
|
419
426
|
const includedIds = union__default(includedIdsBySelectedValues, includedIdsByParams);
|
|
420
427
|
return call({
|
|
421
428
|
page: reactiveData.page,
|
|
@@ -499,7 +506,7 @@ function useAsyncMultiselect({
|
|
|
499
506
|
if (!items.value.length)
|
|
500
507
|
return [];
|
|
501
508
|
if (!mapOptionCallback)
|
|
502
|
-
return
|
|
509
|
+
return items.value;
|
|
503
510
|
return items.value.map(mapOptionCallback);
|
|
504
511
|
});
|
|
505
512
|
const hasNextPage = vue.computed(() => count.value > items.value.length);
|
|
@@ -649,7 +656,7 @@ function useAsyncSelect({
|
|
|
649
656
|
if (!items.value.length)
|
|
650
657
|
return [];
|
|
651
658
|
if (!mapOptionCallback)
|
|
652
|
-
return
|
|
659
|
+
return items.value;
|
|
653
660
|
return items.value.map(mapOptionCallback);
|
|
654
661
|
});
|
|
655
662
|
const hasNextPage = vue.computed(() => count.value > items.value.length);
|
|
@@ -838,6 +845,35 @@ function useDialog() {
|
|
|
838
845
|
} = useGlobalScroll();
|
|
839
846
|
const route = vueRouter.useRoute();
|
|
840
847
|
const router = vueRouter.useRouter();
|
|
848
|
+
const HASH_PREFIX = "#ud_";
|
|
849
|
+
const parseHash = (hash, componentName) => {
|
|
850
|
+
if (!hash)
|
|
851
|
+
return void 0;
|
|
852
|
+
if (!hash.includes(HASH_PREFIX))
|
|
853
|
+
return void 0;
|
|
854
|
+
let dataFromHash;
|
|
855
|
+
try {
|
|
856
|
+
dataFromHash = JSON.parse(window.atob(hash.slice(HASH_PREFIX.length)));
|
|
857
|
+
} catch (error) {
|
|
858
|
+
logger.warn("*parseHash* cant parse hash");
|
|
859
|
+
}
|
|
860
|
+
if (typeof dataFromHash !== "object")
|
|
861
|
+
return void 0;
|
|
862
|
+
if (!dataFromHash.name) {
|
|
863
|
+
logger.warn("*parseHash* cant find component name in hash");
|
|
864
|
+
return void 0;
|
|
865
|
+
}
|
|
866
|
+
if (dataFromHash.name !== componentName)
|
|
867
|
+
return void 0;
|
|
868
|
+
return dataFromHash;
|
|
869
|
+
};
|
|
870
|
+
const clearHash = () => {
|
|
871
|
+
router.push({
|
|
872
|
+
name: route.name || void 0,
|
|
873
|
+
query: route.query,
|
|
874
|
+
hash: void 0
|
|
875
|
+
});
|
|
876
|
+
};
|
|
841
877
|
vue.onMounted(() => {
|
|
842
878
|
appContext = vue.getCurrentInstance()?.appContext;
|
|
843
879
|
});
|
|
@@ -863,16 +899,26 @@ function useDialog() {
|
|
|
863
899
|
vnode2.props["onUpdate:modelValue"] = (value) => {
|
|
864
900
|
if (vnode2 && vnode2.component) {
|
|
865
901
|
vnode2.component.props.modelValue = value;
|
|
866
|
-
if (!value &&
|
|
902
|
+
if (!value && route?.hash) {
|
|
903
|
+
const dataFromHash = parseHash(route.hash, component.name);
|
|
904
|
+
if (dataFromHash)
|
|
905
|
+
clearHash();
|
|
906
|
+
}
|
|
907
|
+
if (!value && (dialogs.length === 1 || layer === 0) && isGlobalScrollLocked.value) {
|
|
867
908
|
unlockGlobalScroll();
|
|
868
909
|
}
|
|
869
910
|
}
|
|
870
911
|
};
|
|
871
912
|
}
|
|
872
913
|
vnode2.close = () => {
|
|
873
|
-
if (vnode2
|
|
874
|
-
|
|
875
|
-
|
|
914
|
+
if (!vnode2 || !vnode2.component)
|
|
915
|
+
return;
|
|
916
|
+
vnode2.component.props.modelValue = false;
|
|
917
|
+
if (!route?.hash)
|
|
918
|
+
return;
|
|
919
|
+
const dataFromHash = parseHash(route.hash, component.name);
|
|
920
|
+
if (dataFromHash)
|
|
921
|
+
clearHash();
|
|
876
922
|
};
|
|
877
923
|
vnode2.props.onDestroy = () => {
|
|
878
924
|
vue.render(null, el2);
|
|
@@ -929,7 +975,7 @@ function useDialog() {
|
|
|
929
975
|
const close = (uuid) => {
|
|
930
976
|
const dialog = dialogs.find((item) => item.uuid === uuid);
|
|
931
977
|
logger.log(`Close dialog: "${uuid}"`);
|
|
932
|
-
if (dialogs.length === 1 && isGlobalScrollLocked.value) {
|
|
978
|
+
if ((dialogs.length === 1 || dialog.layer === 0) && isGlobalScrollLocked.value) {
|
|
933
979
|
unlockGlobalScroll();
|
|
934
980
|
}
|
|
935
981
|
dialog?.vnode.close();
|
|
@@ -967,7 +1013,7 @@ function useDialog() {
|
|
|
967
1013
|
router.push({
|
|
968
1014
|
name: route.name || void 0,
|
|
969
1015
|
query: route.query,
|
|
970
|
-
hash:
|
|
1016
|
+
hash: `${HASH_PREFIX}${window.btoa(JSON.stringify(data))}`
|
|
971
1017
|
});
|
|
972
1018
|
};
|
|
973
1019
|
const watchHash = ({
|
|
@@ -979,22 +1025,13 @@ function useDialog() {
|
|
|
979
1025
|
() => route.hash,
|
|
980
1026
|
async (newHash) => {
|
|
981
1027
|
if (!newHash) {
|
|
1028
|
+
if (!dialogs.length)
|
|
1029
|
+
return;
|
|
982
1030
|
closeAll();
|
|
983
1031
|
return;
|
|
984
1032
|
}
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
dataFromHash = JSON.parse(window.atob(newHash.slice(1)));
|
|
988
|
-
} catch (error) {
|
|
989
|
-
logger.error("*watchHash* cant parse hash");
|
|
990
|
-
}
|
|
991
|
-
if (typeof dataFromHash !== "object")
|
|
992
|
-
return;
|
|
993
|
-
if (!dataFromHash.name) {
|
|
994
|
-
logger.error("*watchHash* cant find component name in hash");
|
|
995
|
-
return;
|
|
996
|
-
}
|
|
997
|
-
if (dataFromHash.name !== component.name)
|
|
1033
|
+
const dataFromHash = parseHash(newHash, component.name);
|
|
1034
|
+
if (!dataFromHash)
|
|
998
1035
|
return;
|
|
999
1036
|
logger.info("*watchHash* data from hash", dataFromHash);
|
|
1000
1037
|
await vue.nextTick();
|
|
@@ -1002,15 +1039,6 @@ function useDialog() {
|
|
|
1002
1039
|
component,
|
|
1003
1040
|
layer: dataFromHash.layer || 0,
|
|
1004
1041
|
props: {
|
|
1005
|
-
"onUpdate:modelValue": (value) => {
|
|
1006
|
-
if (value)
|
|
1007
|
-
return;
|
|
1008
|
-
router.push({
|
|
1009
|
-
name: route.name || void 0,
|
|
1010
|
-
query: route.query,
|
|
1011
|
-
hash: void 0
|
|
1012
|
-
});
|
|
1013
|
-
},
|
|
1014
1042
|
...dataFromHash.props,
|
|
1015
1043
|
...events
|
|
1016
1044
|
}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,350 @@
|
|
|
1
|
+
import * as vue from 'vue';
|
|
2
|
+
import { MaybeRef, Component, EmitsOptions, VNode, Ref } from 'vue';
|
|
3
|
+
import { AxiosRequestConfig } from 'axios';
|
|
4
|
+
export { AxiosError as HttpError, AxiosPromise as HttpPromise, AxiosRequestConfig as HttpRequestConfig, AxiosResponse as HttpResponse } from 'axios';
|
|
5
|
+
import { MaybeRef as MaybeRef$1 } from '@vueuse/core';
|
|
6
|
+
import dayjs from 'dayjs';
|
|
7
|
+
import { Browser } from 'detect-browser';
|
|
8
|
+
import logdown from 'logdown';
|
|
9
|
+
import { RuleItem } from 'async-validator';
|
|
10
|
+
|
|
11
|
+
interface AppComponentsResolverOptions {
|
|
12
|
+
prefix?: string;
|
|
13
|
+
}
|
|
14
|
+
declare function AppComponentsResolver(options?: AppComponentsResolverOptions): any;
|
|
15
|
+
|
|
16
|
+
interface Dictionary {
|
|
17
|
+
[keys: string | number]: any;
|
|
18
|
+
}
|
|
19
|
+
interface ResponseError {
|
|
20
|
+
status: number;
|
|
21
|
+
statusMessage: string;
|
|
22
|
+
message: string;
|
|
23
|
+
data: Record<string, string | string[]> | null;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
declare function camelizeKeys(object: Dictionary): Dictionary;
|
|
27
|
+
|
|
28
|
+
interface Options$3 {
|
|
29
|
+
labelType: 'key' | 'value';
|
|
30
|
+
}
|
|
31
|
+
declare function convertEnumToOptions(obj: any, options?: Options$3): {
|
|
32
|
+
value: unknown;
|
|
33
|
+
label: unknown;
|
|
34
|
+
}[];
|
|
35
|
+
|
|
36
|
+
interface Options$2 extends Intl.NumberFormatOptions {
|
|
37
|
+
locale?: string;
|
|
38
|
+
defaultValue?: string | number;
|
|
39
|
+
}
|
|
40
|
+
declare function formatMoney(value: string | number | null | undefined, currency?: string, options?: Options$2): string | number;
|
|
41
|
+
|
|
42
|
+
declare function genHash(hashLength: number): string;
|
|
43
|
+
|
|
44
|
+
declare function genRandomNumber(min: number, max: number): number;
|
|
45
|
+
|
|
46
|
+
declare function genUUID(): string;
|
|
47
|
+
|
|
48
|
+
interface Options$1 {
|
|
49
|
+
hasOnlyLast4: boolean;
|
|
50
|
+
isHidden: boolean;
|
|
51
|
+
dot: string;
|
|
52
|
+
}
|
|
53
|
+
declare function getCardNumber(number: string, options?: Partial<Options$1>): string;
|
|
54
|
+
|
|
55
|
+
declare function getCountryFromPhone(phone: string): string;
|
|
56
|
+
|
|
57
|
+
declare function isElementIgnored({ ignoredClasses, event, }?: {
|
|
58
|
+
ignoredClasses?: string[];
|
|
59
|
+
event?: Event;
|
|
60
|
+
}): boolean;
|
|
61
|
+
|
|
62
|
+
declare function isEmptyObject(object: object): boolean;
|
|
63
|
+
|
|
64
|
+
interface MapOptions {
|
|
65
|
+
labelKey?: string;
|
|
66
|
+
valueKey?: string;
|
|
67
|
+
excludedItems?: any[];
|
|
68
|
+
}
|
|
69
|
+
declare function mapDataObjectForFilters<T extends Record<string, any>>(data: T, options?: MapOptions): {
|
|
70
|
+
label: string;
|
|
71
|
+
value: any;
|
|
72
|
+
}[];
|
|
73
|
+
|
|
74
|
+
declare function getPaginationParams({ page, limit, }: {
|
|
75
|
+
page: string | number;
|
|
76
|
+
limit: string | number;
|
|
77
|
+
}): {
|
|
78
|
+
limit: number;
|
|
79
|
+
offset: number;
|
|
80
|
+
};
|
|
81
|
+
declare function getPaginationLimit({ limit }: {
|
|
82
|
+
limit: string | number;
|
|
83
|
+
}): number;
|
|
84
|
+
declare function getPaginationOffset({ page, limit, }: {
|
|
85
|
+
page: string | number;
|
|
86
|
+
limit: string | number;
|
|
87
|
+
}): number;
|
|
88
|
+
declare function getPaginationPages({ count, limit, }: {
|
|
89
|
+
count: number;
|
|
90
|
+
limit: string | number;
|
|
91
|
+
}): number;
|
|
92
|
+
|
|
93
|
+
declare function parsePhone(phone: string | null | undefined): string;
|
|
94
|
+
|
|
95
|
+
type SnakelizeKeysProp = Record<string | number, any>;
|
|
96
|
+
declare function snakelizeKeys(prop: SnakelizeKeysProp): SnakelizeKeysProp;
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Принимает на вход число в виде строки или числа,
|
|
100
|
+
* возвращает корректное значение типа Number (убирает лишние пробелы и запятые)
|
|
101
|
+
* @example
|
|
102
|
+
* // returns 1000
|
|
103
|
+
* unformatNumber('1 000');
|
|
104
|
+
* @example
|
|
105
|
+
* // returns 1000
|
|
106
|
+
* unformatNumber('1,000')
|
|
107
|
+
* @example
|
|
108
|
+
* // returns 1000.123
|
|
109
|
+
* unformatNummber('1 000,123')
|
|
110
|
+
* @example
|
|
111
|
+
* // returns 1000.123
|
|
112
|
+
* unformatNummber('1,000.123')
|
|
113
|
+
* @param value
|
|
114
|
+
* @return number
|
|
115
|
+
*/
|
|
116
|
+
declare function unformatNumber(value: string | number): string | number;
|
|
117
|
+
|
|
118
|
+
declare function validateNumber(value: string | number, defaultValue: number): number;
|
|
119
|
+
|
|
120
|
+
interface UiComponentsResolverOptions {
|
|
121
|
+
prefix?: string;
|
|
122
|
+
}
|
|
123
|
+
declare function UiComponentsResolver(options?: UiComponentsResolverOptions): any;
|
|
124
|
+
|
|
125
|
+
declare function useAbortController<T extends (...args: any[]) => any>(callback: T): {
|
|
126
|
+
call(...args: Parameters<T>): Promise<Awaited<ReturnType<T>>>;
|
|
127
|
+
abort(): void;
|
|
128
|
+
isAborted(error: ResponseError): boolean;
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
declare function useAsyncItems<T extends (...args: any[]) => any>({ apiMethod, queryKey, params, config, }: {
|
|
132
|
+
apiMethod: T;
|
|
133
|
+
queryKey: string;
|
|
134
|
+
params: MaybeRef<Parameters<T>[0]>;
|
|
135
|
+
config?: AxiosRequestConfig;
|
|
136
|
+
}): {
|
|
137
|
+
isLoading: vue.Ref<boolean> | vue.Ref<true> | vue.Ref<false>;
|
|
138
|
+
isFetching: vue.Ref<boolean>;
|
|
139
|
+
isError: vue.Ref<true> | vue.Ref<false>;
|
|
140
|
+
data: vue.Ref<any>;
|
|
141
|
+
error: vue.Ref<Error>;
|
|
142
|
+
items: vue.ComputedRef<Awaited<ReturnType<T>>["results"]>;
|
|
143
|
+
count: vue.Ref<number>;
|
|
144
|
+
refetch: () => void;
|
|
145
|
+
reload: () => void;
|
|
146
|
+
abort: () => void;
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
interface ReactiveData$1 {
|
|
150
|
+
search: string;
|
|
151
|
+
page: number;
|
|
152
|
+
selectedValues?: any[];
|
|
153
|
+
params?: any;
|
|
154
|
+
}
|
|
155
|
+
declare function useAsyncMultiselect<T extends (...args: any[]) => any, K extends (params: any) => any>({ apiMethod, mapOptionCallback, selectedValues, params, queryKey, dataItemsKey, dataItemIdKey, dataCountKey, delay, onUpdated, }: {
|
|
156
|
+
apiMethod: T;
|
|
157
|
+
mapOptionCallback?: K;
|
|
158
|
+
selectedValues?: MaybeRef$1<Parameters<T>[0]['includedIds']>;
|
|
159
|
+
params?: MaybeRef$1<Partial<Parameters<T>[0]>>;
|
|
160
|
+
queryKey: string;
|
|
161
|
+
dataItemsKey?: string;
|
|
162
|
+
dataItemIdKey?: string;
|
|
163
|
+
dataCountKey?: string;
|
|
164
|
+
delay?: number;
|
|
165
|
+
onUpdated?: (data: ReactiveData$1) => void;
|
|
166
|
+
}): {
|
|
167
|
+
items: vue.ComputedRef<any[]>;
|
|
168
|
+
options: vue.ComputedRef<ReturnType<K>[]>;
|
|
169
|
+
search: vue.Ref<string>;
|
|
170
|
+
hasNextPage: vue.ComputedRef<boolean>;
|
|
171
|
+
isFetching: vue.Ref<boolean>;
|
|
172
|
+
isLoading: vue.Ref<boolean> | vue.Ref<true> | vue.Ref<false>;
|
|
173
|
+
loadPage: (newPage?: number) => void;
|
|
174
|
+
updateSearch: (value: string) => void;
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
interface ReactiveData {
|
|
178
|
+
search: string;
|
|
179
|
+
page: number;
|
|
180
|
+
selectedValue?: any[];
|
|
181
|
+
params?: any;
|
|
182
|
+
}
|
|
183
|
+
declare function useAsyncSelect<T extends (...args: any[]) => any, K extends (params: any) => any>({ apiMethod, mapOptionCallback, selectedValue, params, queryKey, dataItemsKey, dataCountKey, delay, onUpdated, }: {
|
|
184
|
+
apiMethod: T;
|
|
185
|
+
mapOptionCallback?: K;
|
|
186
|
+
selectedValue?: MaybeRef$1<Parameters<T>[0]['includedIds']>;
|
|
187
|
+
params?: MaybeRef$1<Partial<Parameters<T>[0]>>;
|
|
188
|
+
queryKey: string;
|
|
189
|
+
dataItemsKey?: string;
|
|
190
|
+
dataCountKey?: string;
|
|
191
|
+
delay?: number;
|
|
192
|
+
onUpdated?: (data: ReactiveData) => void;
|
|
193
|
+
}): {
|
|
194
|
+
items: vue.ComputedRef<any[]>;
|
|
195
|
+
options: vue.ComputedRef<ReturnType<K>[]>;
|
|
196
|
+
search: vue.Ref<string>;
|
|
197
|
+
hasNextPage: vue.ComputedRef<boolean>;
|
|
198
|
+
isFetching: vue.Ref<boolean>;
|
|
199
|
+
isLoading: vue.Ref<boolean> | vue.Ref<true> | vue.Ref<false>;
|
|
200
|
+
loadPage: (newPage?: number) => void;
|
|
201
|
+
updateSearch: (value: string) => void;
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
declare function useBreakpoint(): {
|
|
205
|
+
isMobile: vue.Ref<boolean>;
|
|
206
|
+
isDesktop: vue.Ref<boolean>;
|
|
207
|
+
isGreaterXxs: vue.Ref<boolean>;
|
|
208
|
+
isGreaterXs: vue.Ref<boolean>;
|
|
209
|
+
isGreaterSm: vue.Ref<boolean>;
|
|
210
|
+
isGreaterMd: vue.Ref<boolean>;
|
|
211
|
+
isGreaterLg: vue.Ref<boolean>;
|
|
212
|
+
isGreaterXl: vue.Ref<boolean>;
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
declare function useClassName(block: string): {
|
|
216
|
+
b: (blockSuffix?: string) => string;
|
|
217
|
+
e: (element?: string) => string;
|
|
218
|
+
m: (modifier?: string, condition?: boolean) => string;
|
|
219
|
+
em: (element?: string, modifier?: string, condition?: boolean) => string;
|
|
220
|
+
mv: (modifier: string, modifierValue: string, condition?: boolean) => string;
|
|
221
|
+
cssVar: (object: Record<string, string | number>) => Record<string, string | number>;
|
|
222
|
+
cssVarName: (name: string) => string;
|
|
223
|
+
};
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* Обертка над dayjs, позволяющая задавать timezone
|
|
227
|
+
* @see https://day.js.org/en/
|
|
228
|
+
*
|
|
229
|
+
* Использовать параметр timezone нужно крайне аккуратно,
|
|
230
|
+
* может привести к утечкам памяти
|
|
231
|
+
* @todo Подумать как сделать оптимальнее
|
|
232
|
+
*/
|
|
233
|
+
declare function useDayjs(timezone?: string): (date?: dayjs.ConfigType, format?: dayjs.OptionType, locale?: string, strict?: boolean) => dayjs.Dayjs;
|
|
234
|
+
|
|
235
|
+
interface BrowserInfo {
|
|
236
|
+
isDeprecated?: boolean;
|
|
237
|
+
name?: string;
|
|
238
|
+
version?: string;
|
|
239
|
+
os?: string;
|
|
240
|
+
type?: string;
|
|
241
|
+
options?: any;
|
|
242
|
+
}
|
|
243
|
+
type VersionsList = {
|
|
244
|
+
[key in Browser]?: string | boolean;
|
|
245
|
+
};
|
|
246
|
+
declare function useDetectBrowser(versions: VersionsList, userAgent?: any): BrowserInfo;
|
|
247
|
+
|
|
248
|
+
interface VNodeCustom$1 extends VNode {
|
|
249
|
+
close(): void;
|
|
250
|
+
}
|
|
251
|
+
declare function useDialog(): {
|
|
252
|
+
open: ({ layer, component, props, }: {
|
|
253
|
+
component: Component;
|
|
254
|
+
props?: any;
|
|
255
|
+
layer?: number;
|
|
256
|
+
}) => string;
|
|
257
|
+
getInstance: (uuid: string) => VNodeCustom$1;
|
|
258
|
+
close: (uuid: string) => void;
|
|
259
|
+
closeAll: () => void;
|
|
260
|
+
showConfirm: (text?: string) => boolean;
|
|
261
|
+
isOnTop: (uuid: string) => boolean;
|
|
262
|
+
openByHash: ({ layer, component, props, }: {
|
|
263
|
+
component: Component;
|
|
264
|
+
props?: any;
|
|
265
|
+
layer?: number;
|
|
266
|
+
}) => void;
|
|
267
|
+
watchHash: ({ component, events, }: {
|
|
268
|
+
component: Component;
|
|
269
|
+
events?: EmitsOptions;
|
|
270
|
+
}) => any;
|
|
271
|
+
};
|
|
272
|
+
|
|
273
|
+
declare function useGlobalScroll(): {
|
|
274
|
+
isLocked: vue.Ref<boolean>;
|
|
275
|
+
lock: () => void;
|
|
276
|
+
unlock: () => void;
|
|
277
|
+
};
|
|
278
|
+
|
|
279
|
+
declare function useFilters<T extends Record<string, any>, K extends Record<string, any>>({ config, initialFilters, }: {
|
|
280
|
+
config: T;
|
|
281
|
+
initialFilters: K;
|
|
282
|
+
}): {
|
|
283
|
+
isOpen: Ref<boolean>;
|
|
284
|
+
filtersModel: Ref<K>;
|
|
285
|
+
filtersFromQuery: vue.ComputedRef<{}>;
|
|
286
|
+
filtersCount: vue.ComputedRef<number>;
|
|
287
|
+
updateOne: (key: keyof K, value: any) => void;
|
|
288
|
+
updateMany: (filters: Record<string, any>) => void;
|
|
289
|
+
open: () => void;
|
|
290
|
+
clear: () => void;
|
|
291
|
+
setQueryFromFilters: (filters: Record<string, any>) => void;
|
|
292
|
+
getValidatedParams: (query: Record<string, any>) => {
|
|
293
|
+
filters: any;
|
|
294
|
+
};
|
|
295
|
+
};
|
|
296
|
+
|
|
297
|
+
/**
|
|
298
|
+
* @see https://github.com/caiogondim/logdown.js#readme
|
|
299
|
+
*/
|
|
300
|
+
|
|
301
|
+
interface Options {
|
|
302
|
+
tag?: string;
|
|
303
|
+
color?: string;
|
|
304
|
+
debug?: boolean;
|
|
305
|
+
}
|
|
306
|
+
declare function useLogger(scope: string, options?: Options): logdown.Logger;
|
|
307
|
+
|
|
308
|
+
interface VNodeCustom extends VNode {
|
|
309
|
+
close(): void;
|
|
310
|
+
}
|
|
311
|
+
/**
|
|
312
|
+
* @deprecated use useDialog
|
|
313
|
+
*/
|
|
314
|
+
declare function usePanel(): {
|
|
315
|
+
open: ({ layer, component, props, }: {
|
|
316
|
+
component: Component;
|
|
317
|
+
props?: any;
|
|
318
|
+
layer?: number;
|
|
319
|
+
}) => string;
|
|
320
|
+
getInstance: (uuid: string) => VNodeCustom;
|
|
321
|
+
close: (uuid: string) => void;
|
|
322
|
+
closeAll: () => void;
|
|
323
|
+
openByHash: ({ layer, component, props, }: {
|
|
324
|
+
component: Component;
|
|
325
|
+
props?: any;
|
|
326
|
+
layer?: number;
|
|
327
|
+
}) => void;
|
|
328
|
+
watchHash: ({ component, events, }: {
|
|
329
|
+
component: Component;
|
|
330
|
+
events?: EmitsOptions;
|
|
331
|
+
}) => any;
|
|
332
|
+
};
|
|
333
|
+
|
|
334
|
+
declare function validatePhone(rule: string, value: string): boolean;
|
|
335
|
+
|
|
336
|
+
declare function isRequired(value?: boolean, message?: string): RuleItem;
|
|
337
|
+
declare function isMax(value?: number, message?: string): {
|
|
338
|
+
max: number;
|
|
339
|
+
message: string;
|
|
340
|
+
};
|
|
341
|
+
declare function isMin(value?: number, message?: string): {
|
|
342
|
+
min: number;
|
|
343
|
+
message: string;
|
|
344
|
+
};
|
|
345
|
+
declare function isTypeEmail(message?: string): RuleItem;
|
|
346
|
+
declare function isTypeUrl(message?: string): RuleItem;
|
|
347
|
+
declare function isTypeNumber(value?: number, message?: string): RuleItem;
|
|
348
|
+
declare function isStrictLength(value?: number, message?: string): RuleItem;
|
|
349
|
+
|
|
350
|
+
export { AppComponentsResolver, type BrowserInfo, type Dictionary, type ResponseError, UiComponentsResolver, type VersionsList, camelizeKeys, convertEnumToOptions, formatMoney, genHash, genRandomNumber, genUUID, getCardNumber, getCountryFromPhone, getPaginationLimit, getPaginationOffset, getPaginationPages, getPaginationParams, isElementIgnored, isEmptyObject, isMax, isMin, isRequired, isStrictLength, isTypeEmail, isTypeNumber, isTypeUrl, mapDataObjectForFilters, parsePhone, snakelizeKeys, unformatNumber, useAbortController, useAsyncItems, useAsyncMultiselect, useAsyncSelect, useBreakpoint, useClassName, useDayjs, useDetectBrowser, useDialog, useFilters, useGlobalScroll, useLogger, usePanel, validateNumber, validatePhone };
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,350 @@
|
|
|
1
|
+
import * as vue from 'vue';
|
|
2
|
+
import { MaybeRef, Component, EmitsOptions, VNode, Ref } from 'vue';
|
|
3
|
+
import { AxiosRequestConfig } from 'axios';
|
|
4
|
+
export { AxiosError as HttpError, AxiosPromise as HttpPromise, AxiosRequestConfig as HttpRequestConfig, AxiosResponse as HttpResponse } from 'axios';
|
|
5
|
+
import { MaybeRef as MaybeRef$1 } from '@vueuse/core';
|
|
6
|
+
import dayjs from 'dayjs';
|
|
7
|
+
import { Browser } from 'detect-browser';
|
|
8
|
+
import logdown from 'logdown';
|
|
9
|
+
import { RuleItem } from 'async-validator';
|
|
10
|
+
|
|
11
|
+
interface AppComponentsResolverOptions {
|
|
12
|
+
prefix?: string;
|
|
13
|
+
}
|
|
14
|
+
declare function AppComponentsResolver(options?: AppComponentsResolverOptions): any;
|
|
15
|
+
|
|
16
|
+
interface Dictionary {
|
|
17
|
+
[keys: string | number]: any;
|
|
18
|
+
}
|
|
19
|
+
interface ResponseError {
|
|
20
|
+
status: number;
|
|
21
|
+
statusMessage: string;
|
|
22
|
+
message: string;
|
|
23
|
+
data: Record<string, string | string[]> | null;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
declare function camelizeKeys(object: Dictionary): Dictionary;
|
|
27
|
+
|
|
28
|
+
interface Options$3 {
|
|
29
|
+
labelType: 'key' | 'value';
|
|
30
|
+
}
|
|
31
|
+
declare function convertEnumToOptions(obj: any, options?: Options$3): {
|
|
32
|
+
value: unknown;
|
|
33
|
+
label: unknown;
|
|
34
|
+
}[];
|
|
35
|
+
|
|
36
|
+
interface Options$2 extends Intl.NumberFormatOptions {
|
|
37
|
+
locale?: string;
|
|
38
|
+
defaultValue?: string | number;
|
|
39
|
+
}
|
|
40
|
+
declare function formatMoney(value: string | number | null | undefined, currency?: string, options?: Options$2): string | number;
|
|
41
|
+
|
|
42
|
+
declare function genHash(hashLength: number): string;
|
|
43
|
+
|
|
44
|
+
declare function genRandomNumber(min: number, max: number): number;
|
|
45
|
+
|
|
46
|
+
declare function genUUID(): string;
|
|
47
|
+
|
|
48
|
+
interface Options$1 {
|
|
49
|
+
hasOnlyLast4: boolean;
|
|
50
|
+
isHidden: boolean;
|
|
51
|
+
dot: string;
|
|
52
|
+
}
|
|
53
|
+
declare function getCardNumber(number: string, options?: Partial<Options$1>): string;
|
|
54
|
+
|
|
55
|
+
declare function getCountryFromPhone(phone: string): string;
|
|
56
|
+
|
|
57
|
+
declare function isElementIgnored({ ignoredClasses, event, }?: {
|
|
58
|
+
ignoredClasses?: string[];
|
|
59
|
+
event?: Event;
|
|
60
|
+
}): boolean;
|
|
61
|
+
|
|
62
|
+
declare function isEmptyObject(object: object): boolean;
|
|
63
|
+
|
|
64
|
+
interface MapOptions {
|
|
65
|
+
labelKey?: string;
|
|
66
|
+
valueKey?: string;
|
|
67
|
+
excludedItems?: any[];
|
|
68
|
+
}
|
|
69
|
+
declare function mapDataObjectForFilters<T extends Record<string, any>>(data: T, options?: MapOptions): {
|
|
70
|
+
label: string;
|
|
71
|
+
value: any;
|
|
72
|
+
}[];
|
|
73
|
+
|
|
74
|
+
declare function getPaginationParams({ page, limit, }: {
|
|
75
|
+
page: string | number;
|
|
76
|
+
limit: string | number;
|
|
77
|
+
}): {
|
|
78
|
+
limit: number;
|
|
79
|
+
offset: number;
|
|
80
|
+
};
|
|
81
|
+
declare function getPaginationLimit({ limit }: {
|
|
82
|
+
limit: string | number;
|
|
83
|
+
}): number;
|
|
84
|
+
declare function getPaginationOffset({ page, limit, }: {
|
|
85
|
+
page: string | number;
|
|
86
|
+
limit: string | number;
|
|
87
|
+
}): number;
|
|
88
|
+
declare function getPaginationPages({ count, limit, }: {
|
|
89
|
+
count: number;
|
|
90
|
+
limit: string | number;
|
|
91
|
+
}): number;
|
|
92
|
+
|
|
93
|
+
declare function parsePhone(phone: string | null | undefined): string;
|
|
94
|
+
|
|
95
|
+
type SnakelizeKeysProp = Record<string | number, any>;
|
|
96
|
+
declare function snakelizeKeys(prop: SnakelizeKeysProp): SnakelizeKeysProp;
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Принимает на вход число в виде строки или числа,
|
|
100
|
+
* возвращает корректное значение типа Number (убирает лишние пробелы и запятые)
|
|
101
|
+
* @example
|
|
102
|
+
* // returns 1000
|
|
103
|
+
* unformatNumber('1 000');
|
|
104
|
+
* @example
|
|
105
|
+
* // returns 1000
|
|
106
|
+
* unformatNumber('1,000')
|
|
107
|
+
* @example
|
|
108
|
+
* // returns 1000.123
|
|
109
|
+
* unformatNummber('1 000,123')
|
|
110
|
+
* @example
|
|
111
|
+
* // returns 1000.123
|
|
112
|
+
* unformatNummber('1,000.123')
|
|
113
|
+
* @param value
|
|
114
|
+
* @return number
|
|
115
|
+
*/
|
|
116
|
+
declare function unformatNumber(value: string | number): string | number;
|
|
117
|
+
|
|
118
|
+
declare function validateNumber(value: string | number, defaultValue: number): number;
|
|
119
|
+
|
|
120
|
+
interface UiComponentsResolverOptions {
|
|
121
|
+
prefix?: string;
|
|
122
|
+
}
|
|
123
|
+
declare function UiComponentsResolver(options?: UiComponentsResolverOptions): any;
|
|
124
|
+
|
|
125
|
+
declare function useAbortController<T extends (...args: any[]) => any>(callback: T): {
|
|
126
|
+
call(...args: Parameters<T>): Promise<Awaited<ReturnType<T>>>;
|
|
127
|
+
abort(): void;
|
|
128
|
+
isAborted(error: ResponseError): boolean;
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
declare function useAsyncItems<T extends (...args: any[]) => any>({ apiMethod, queryKey, params, config, }: {
|
|
132
|
+
apiMethod: T;
|
|
133
|
+
queryKey: string;
|
|
134
|
+
params: MaybeRef<Parameters<T>[0]>;
|
|
135
|
+
config?: AxiosRequestConfig;
|
|
136
|
+
}): {
|
|
137
|
+
isLoading: vue.Ref<boolean> | vue.Ref<true> | vue.Ref<false>;
|
|
138
|
+
isFetching: vue.Ref<boolean>;
|
|
139
|
+
isError: vue.Ref<true> | vue.Ref<false>;
|
|
140
|
+
data: vue.Ref<any>;
|
|
141
|
+
error: vue.Ref<Error>;
|
|
142
|
+
items: vue.ComputedRef<Awaited<ReturnType<T>>["results"]>;
|
|
143
|
+
count: vue.Ref<number>;
|
|
144
|
+
refetch: () => void;
|
|
145
|
+
reload: () => void;
|
|
146
|
+
abort: () => void;
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
interface ReactiveData$1 {
|
|
150
|
+
search: string;
|
|
151
|
+
page: number;
|
|
152
|
+
selectedValues?: any[];
|
|
153
|
+
params?: any;
|
|
154
|
+
}
|
|
155
|
+
declare function useAsyncMultiselect<T extends (...args: any[]) => any, K extends (params: any) => any>({ apiMethod, mapOptionCallback, selectedValues, params, queryKey, dataItemsKey, dataItemIdKey, dataCountKey, delay, onUpdated, }: {
|
|
156
|
+
apiMethod: T;
|
|
157
|
+
mapOptionCallback?: K;
|
|
158
|
+
selectedValues?: MaybeRef$1<Parameters<T>[0]['includedIds']>;
|
|
159
|
+
params?: MaybeRef$1<Partial<Parameters<T>[0]>>;
|
|
160
|
+
queryKey: string;
|
|
161
|
+
dataItemsKey?: string;
|
|
162
|
+
dataItemIdKey?: string;
|
|
163
|
+
dataCountKey?: string;
|
|
164
|
+
delay?: number;
|
|
165
|
+
onUpdated?: (data: ReactiveData$1) => void;
|
|
166
|
+
}): {
|
|
167
|
+
items: vue.ComputedRef<any[]>;
|
|
168
|
+
options: vue.ComputedRef<ReturnType<K>[]>;
|
|
169
|
+
search: vue.Ref<string>;
|
|
170
|
+
hasNextPage: vue.ComputedRef<boolean>;
|
|
171
|
+
isFetching: vue.Ref<boolean>;
|
|
172
|
+
isLoading: vue.Ref<boolean> | vue.Ref<true> | vue.Ref<false>;
|
|
173
|
+
loadPage: (newPage?: number) => void;
|
|
174
|
+
updateSearch: (value: string) => void;
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
interface ReactiveData {
|
|
178
|
+
search: string;
|
|
179
|
+
page: number;
|
|
180
|
+
selectedValue?: any[];
|
|
181
|
+
params?: any;
|
|
182
|
+
}
|
|
183
|
+
declare function useAsyncSelect<T extends (...args: any[]) => any, K extends (params: any) => any>({ apiMethod, mapOptionCallback, selectedValue, params, queryKey, dataItemsKey, dataCountKey, delay, onUpdated, }: {
|
|
184
|
+
apiMethod: T;
|
|
185
|
+
mapOptionCallback?: K;
|
|
186
|
+
selectedValue?: MaybeRef$1<Parameters<T>[0]['includedIds']>;
|
|
187
|
+
params?: MaybeRef$1<Partial<Parameters<T>[0]>>;
|
|
188
|
+
queryKey: string;
|
|
189
|
+
dataItemsKey?: string;
|
|
190
|
+
dataCountKey?: string;
|
|
191
|
+
delay?: number;
|
|
192
|
+
onUpdated?: (data: ReactiveData) => void;
|
|
193
|
+
}): {
|
|
194
|
+
items: vue.ComputedRef<any[]>;
|
|
195
|
+
options: vue.ComputedRef<ReturnType<K>[]>;
|
|
196
|
+
search: vue.Ref<string>;
|
|
197
|
+
hasNextPage: vue.ComputedRef<boolean>;
|
|
198
|
+
isFetching: vue.Ref<boolean>;
|
|
199
|
+
isLoading: vue.Ref<boolean> | vue.Ref<true> | vue.Ref<false>;
|
|
200
|
+
loadPage: (newPage?: number) => void;
|
|
201
|
+
updateSearch: (value: string) => void;
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
declare function useBreakpoint(): {
|
|
205
|
+
isMobile: vue.Ref<boolean>;
|
|
206
|
+
isDesktop: vue.Ref<boolean>;
|
|
207
|
+
isGreaterXxs: vue.Ref<boolean>;
|
|
208
|
+
isGreaterXs: vue.Ref<boolean>;
|
|
209
|
+
isGreaterSm: vue.Ref<boolean>;
|
|
210
|
+
isGreaterMd: vue.Ref<boolean>;
|
|
211
|
+
isGreaterLg: vue.Ref<boolean>;
|
|
212
|
+
isGreaterXl: vue.Ref<boolean>;
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
declare function useClassName(block: string): {
|
|
216
|
+
b: (blockSuffix?: string) => string;
|
|
217
|
+
e: (element?: string) => string;
|
|
218
|
+
m: (modifier?: string, condition?: boolean) => string;
|
|
219
|
+
em: (element?: string, modifier?: string, condition?: boolean) => string;
|
|
220
|
+
mv: (modifier: string, modifierValue: string, condition?: boolean) => string;
|
|
221
|
+
cssVar: (object: Record<string, string | number>) => Record<string, string | number>;
|
|
222
|
+
cssVarName: (name: string) => string;
|
|
223
|
+
};
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* Обертка над dayjs, позволяющая задавать timezone
|
|
227
|
+
* @see https://day.js.org/en/
|
|
228
|
+
*
|
|
229
|
+
* Использовать параметр timezone нужно крайне аккуратно,
|
|
230
|
+
* может привести к утечкам памяти
|
|
231
|
+
* @todo Подумать как сделать оптимальнее
|
|
232
|
+
*/
|
|
233
|
+
declare function useDayjs(timezone?: string): (date?: dayjs.ConfigType, format?: dayjs.OptionType, locale?: string, strict?: boolean) => dayjs.Dayjs;
|
|
234
|
+
|
|
235
|
+
interface BrowserInfo {
|
|
236
|
+
isDeprecated?: boolean;
|
|
237
|
+
name?: string;
|
|
238
|
+
version?: string;
|
|
239
|
+
os?: string;
|
|
240
|
+
type?: string;
|
|
241
|
+
options?: any;
|
|
242
|
+
}
|
|
243
|
+
type VersionsList = {
|
|
244
|
+
[key in Browser]?: string | boolean;
|
|
245
|
+
};
|
|
246
|
+
declare function useDetectBrowser(versions: VersionsList, userAgent?: any): BrowserInfo;
|
|
247
|
+
|
|
248
|
+
interface VNodeCustom$1 extends VNode {
|
|
249
|
+
close(): void;
|
|
250
|
+
}
|
|
251
|
+
declare function useDialog(): {
|
|
252
|
+
open: ({ layer, component, props, }: {
|
|
253
|
+
component: Component;
|
|
254
|
+
props?: any;
|
|
255
|
+
layer?: number;
|
|
256
|
+
}) => string;
|
|
257
|
+
getInstance: (uuid: string) => VNodeCustom$1;
|
|
258
|
+
close: (uuid: string) => void;
|
|
259
|
+
closeAll: () => void;
|
|
260
|
+
showConfirm: (text?: string) => boolean;
|
|
261
|
+
isOnTop: (uuid: string) => boolean;
|
|
262
|
+
openByHash: ({ layer, component, props, }: {
|
|
263
|
+
component: Component;
|
|
264
|
+
props?: any;
|
|
265
|
+
layer?: number;
|
|
266
|
+
}) => void;
|
|
267
|
+
watchHash: ({ component, events, }: {
|
|
268
|
+
component: Component;
|
|
269
|
+
events?: EmitsOptions;
|
|
270
|
+
}) => any;
|
|
271
|
+
};
|
|
272
|
+
|
|
273
|
+
declare function useGlobalScroll(): {
|
|
274
|
+
isLocked: vue.Ref<boolean>;
|
|
275
|
+
lock: () => void;
|
|
276
|
+
unlock: () => void;
|
|
277
|
+
};
|
|
278
|
+
|
|
279
|
+
declare function useFilters<T extends Record<string, any>, K extends Record<string, any>>({ config, initialFilters, }: {
|
|
280
|
+
config: T;
|
|
281
|
+
initialFilters: K;
|
|
282
|
+
}): {
|
|
283
|
+
isOpen: Ref<boolean>;
|
|
284
|
+
filtersModel: Ref<K>;
|
|
285
|
+
filtersFromQuery: vue.ComputedRef<{}>;
|
|
286
|
+
filtersCount: vue.ComputedRef<number>;
|
|
287
|
+
updateOne: (key: keyof K, value: any) => void;
|
|
288
|
+
updateMany: (filters: Record<string, any>) => void;
|
|
289
|
+
open: () => void;
|
|
290
|
+
clear: () => void;
|
|
291
|
+
setQueryFromFilters: (filters: Record<string, any>) => void;
|
|
292
|
+
getValidatedParams: (query: Record<string, any>) => {
|
|
293
|
+
filters: any;
|
|
294
|
+
};
|
|
295
|
+
};
|
|
296
|
+
|
|
297
|
+
/**
|
|
298
|
+
* @see https://github.com/caiogondim/logdown.js#readme
|
|
299
|
+
*/
|
|
300
|
+
|
|
301
|
+
interface Options {
|
|
302
|
+
tag?: string;
|
|
303
|
+
color?: string;
|
|
304
|
+
debug?: boolean;
|
|
305
|
+
}
|
|
306
|
+
declare function useLogger(scope: string, options?: Options): logdown.Logger;
|
|
307
|
+
|
|
308
|
+
interface VNodeCustom extends VNode {
|
|
309
|
+
close(): void;
|
|
310
|
+
}
|
|
311
|
+
/**
|
|
312
|
+
* @deprecated use useDialog
|
|
313
|
+
*/
|
|
314
|
+
declare function usePanel(): {
|
|
315
|
+
open: ({ layer, component, props, }: {
|
|
316
|
+
component: Component;
|
|
317
|
+
props?: any;
|
|
318
|
+
layer?: number;
|
|
319
|
+
}) => string;
|
|
320
|
+
getInstance: (uuid: string) => VNodeCustom;
|
|
321
|
+
close: (uuid: string) => void;
|
|
322
|
+
closeAll: () => void;
|
|
323
|
+
openByHash: ({ layer, component, props, }: {
|
|
324
|
+
component: Component;
|
|
325
|
+
props?: any;
|
|
326
|
+
layer?: number;
|
|
327
|
+
}) => void;
|
|
328
|
+
watchHash: ({ component, events, }: {
|
|
329
|
+
component: Component;
|
|
330
|
+
events?: EmitsOptions;
|
|
331
|
+
}) => any;
|
|
332
|
+
};
|
|
333
|
+
|
|
334
|
+
declare function validatePhone(rule: string, value: string): boolean;
|
|
335
|
+
|
|
336
|
+
declare function isRequired(value?: boolean, message?: string): RuleItem;
|
|
337
|
+
declare function isMax(value?: number, message?: string): {
|
|
338
|
+
max: number;
|
|
339
|
+
message: string;
|
|
340
|
+
};
|
|
341
|
+
declare function isMin(value?: number, message?: string): {
|
|
342
|
+
min: number;
|
|
343
|
+
message: string;
|
|
344
|
+
};
|
|
345
|
+
declare function isTypeEmail(message?: string): RuleItem;
|
|
346
|
+
declare function isTypeUrl(message?: string): RuleItem;
|
|
347
|
+
declare function isTypeNumber(value?: number, message?: string): RuleItem;
|
|
348
|
+
declare function isStrictLength(value?: number, message?: string): RuleItem;
|
|
349
|
+
|
|
350
|
+
export { AppComponentsResolver, type BrowserInfo, type Dictionary, type ResponseError, UiComponentsResolver, type VersionsList, camelizeKeys, convertEnumToOptions, formatMoney, genHash, genRandomNumber, genUUID, getCardNumber, getCountryFromPhone, getPaginationLimit, getPaginationOffset, getPaginationPages, getPaginationParams, isElementIgnored, isEmptyObject, isMax, isMin, isRequired, isStrictLength, isTypeEmail, isTypeNumber, isTypeUrl, mapDataObjectForFilters, parsePhone, snakelizeKeys, unformatNumber, useAbortController, useAsyncItems, useAsyncMultiselect, useAsyncSelect, useBreakpoint, useClassName, useDayjs, useDetectBrowser, useDialog, useFilters, useGlobalScroll, useLogger, usePanel, validateNumber, validatePhone };
|
package/dist/index.d.ts
CHANGED
|
@@ -35,8 +35,9 @@ declare function convertEnumToOptions(obj: any, options?: Options$3): {
|
|
|
35
35
|
|
|
36
36
|
interface Options$2 extends Intl.NumberFormatOptions {
|
|
37
37
|
locale?: string;
|
|
38
|
+
defaultValue?: string | number;
|
|
38
39
|
}
|
|
39
|
-
declare function formatMoney(value: string | number | null | undefined, currency?: string, options?: Options$2): string;
|
|
40
|
+
declare function formatMoney(value: string | number | null | undefined, currency?: string, options?: Options$2): string | number;
|
|
40
41
|
|
|
41
42
|
declare function genHash(hashLength: number): string;
|
|
42
43
|
|
|
@@ -133,11 +134,11 @@ declare function useAsyncItems<T extends (...args: any[]) => any>({ apiMethod, q
|
|
|
133
134
|
params: MaybeRef<Parameters<T>[0]>;
|
|
134
135
|
config?: AxiosRequestConfig;
|
|
135
136
|
}): {
|
|
136
|
-
isLoading: vue.Ref<
|
|
137
|
+
isLoading: vue.Ref<boolean> | vue.Ref<true> | vue.Ref<false>;
|
|
137
138
|
isFetching: vue.Ref<boolean>;
|
|
138
|
-
isError: vue.Ref<
|
|
139
|
+
isError: vue.Ref<true> | vue.Ref<false>;
|
|
139
140
|
data: vue.Ref<any>;
|
|
140
|
-
error: vue.Ref<
|
|
141
|
+
error: vue.Ref<Error>;
|
|
141
142
|
items: vue.ComputedRef<Awaited<ReturnType<T>>["results"]>;
|
|
142
143
|
count: vue.Ref<number>;
|
|
143
144
|
refetch: () => void;
|
|
@@ -168,7 +169,7 @@ declare function useAsyncMultiselect<T extends (...args: any[]) => any, K extend
|
|
|
168
169
|
search: vue.Ref<string>;
|
|
169
170
|
hasNextPage: vue.ComputedRef<boolean>;
|
|
170
171
|
isFetching: vue.Ref<boolean>;
|
|
171
|
-
isLoading: vue.Ref<
|
|
172
|
+
isLoading: vue.Ref<boolean> | vue.Ref<true> | vue.Ref<false>;
|
|
172
173
|
loadPage: (newPage?: number) => void;
|
|
173
174
|
updateSearch: (value: string) => void;
|
|
174
175
|
};
|
|
@@ -195,7 +196,7 @@ declare function useAsyncSelect<T extends (...args: any[]) => any, K extends (pa
|
|
|
195
196
|
search: vue.Ref<string>;
|
|
196
197
|
hasNextPage: vue.ComputedRef<boolean>;
|
|
197
198
|
isFetching: vue.Ref<boolean>;
|
|
198
|
-
isLoading: vue.Ref<
|
|
199
|
+
isLoading: vue.Ref<boolean> | vue.Ref<true> | vue.Ref<false>;
|
|
199
200
|
loadPage: (newPage?: number) => void;
|
|
200
201
|
updateSearch: (value: string) => void;
|
|
201
202
|
};
|
|
@@ -217,7 +218,7 @@ declare function useClassName(block: string): {
|
|
|
217
218
|
m: (modifier?: string, condition?: boolean) => string;
|
|
218
219
|
em: (element?: string, modifier?: string, condition?: boolean) => string;
|
|
219
220
|
mv: (modifier: string, modifierValue: string, condition?: boolean) => string;
|
|
220
|
-
cssVar: (object: Record<string, string>) => Record<string, string>;
|
|
221
|
+
cssVar: (object: Record<string, string | number>) => Record<string, string | number>;
|
|
221
222
|
cssVarName: (name: string) => string;
|
|
222
223
|
};
|
|
223
224
|
|
|
@@ -346,4 +347,4 @@ declare function isTypeUrl(message?: string): RuleItem;
|
|
|
346
347
|
declare function isTypeNumber(value?: number, message?: string): RuleItem;
|
|
347
348
|
declare function isStrictLength(value?: number, message?: string): RuleItem;
|
|
348
349
|
|
|
349
|
-
export { AppComponentsResolver, BrowserInfo, Dictionary, ResponseError, UiComponentsResolver, VersionsList, camelizeKeys, convertEnumToOptions, formatMoney, genHash, genRandomNumber, genUUID, getCardNumber, getCountryFromPhone, getPaginationLimit, getPaginationOffset, getPaginationPages, getPaginationParams, isElementIgnored, isEmptyObject, isMax, isMin, isRequired, isStrictLength, isTypeEmail, isTypeNumber, isTypeUrl, mapDataObjectForFilters, parsePhone, snakelizeKeys, unformatNumber, useAbortController, useAsyncItems, useAsyncMultiselect, useAsyncSelect, useBreakpoint, useClassName, useDayjs, useDetectBrowser, useDialog, useFilters, useGlobalScroll, useLogger, usePanel, validateNumber, validatePhone };
|
|
350
|
+
export { AppComponentsResolver, type BrowserInfo, type Dictionary, type ResponseError, UiComponentsResolver, type VersionsList, camelizeKeys, convertEnumToOptions, formatMoney, genHash, genRandomNumber, genUUID, getCardNumber, getCountryFromPhone, getPaginationLimit, getPaginationOffset, getPaginationPages, getPaginationParams, isElementIgnored, isEmptyObject, isMax, isMin, isRequired, isStrictLength, isTypeEmail, isTypeNumber, isTypeUrl, mapDataObjectForFilters, parsePhone, snakelizeKeys, unformatNumber, useAbortController, useAsyncItems, useAsyncMultiselect, useAsyncSelect, useBreakpoint, useClassName, useDayjs, useDetectBrowser, useDialog, useFilters, useGlobalScroll, useLogger, usePanel, validateNumber, validatePhone };
|
package/dist/index.mjs
CHANGED
|
@@ -59,18 +59,25 @@ function convertEnumToOptions(obj, options) {
|
|
|
59
59
|
}
|
|
60
60
|
|
|
61
61
|
function formatMoney(value, currency = CURRENCY_DEFAULT, options = {}) {
|
|
62
|
-
const
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
62
|
+
const { locale = "en-US", defaultValue = 0, ...otherOptions } = options;
|
|
63
|
+
try {
|
|
64
|
+
let convertedValue = Number(value);
|
|
65
|
+
if (value === null || Number.isNaN(convertedValue)) {
|
|
66
|
+
if (defaultValue === "")
|
|
67
|
+
return defaultValue;
|
|
68
|
+
convertedValue = Number(defaultValue);
|
|
69
|
+
}
|
|
70
|
+
const formatter = new Intl.NumberFormat(locale, {
|
|
71
|
+
style: "currency",
|
|
72
|
+
currency,
|
|
73
|
+
minimumFractionDigits: 2,
|
|
74
|
+
maximumFractionDigits: 2,
|
|
75
|
+
...otherOptions
|
|
76
|
+
});
|
|
77
|
+
return formatter.format(convertedValue);
|
|
78
|
+
} catch (error) {
|
|
79
|
+
return defaultValue;
|
|
80
|
+
}
|
|
74
81
|
}
|
|
75
82
|
|
|
76
83
|
function genHash(hashLength) {
|
|
@@ -397,7 +404,7 @@ function useAsyncMultiselect({
|
|
|
397
404
|
const { call, abort } = useAbortController(apiMethod);
|
|
398
405
|
const loadWAC = () => {
|
|
399
406
|
const includedIdsBySelectedValues = reactiveData.selectedValues ?? [];
|
|
400
|
-
const includedIdsByParams = JSON.parse(reactiveData.params || {})?.includedIds ?? [];
|
|
407
|
+
const includedIdsByParams = (Boolean(reactiveData.params) && JSON.parse(reactiveData.params || {})?.includedIds) ?? [];
|
|
401
408
|
const includedIds = union(includedIdsBySelectedValues, includedIdsByParams);
|
|
402
409
|
return call({
|
|
403
410
|
page: reactiveData.page,
|
|
@@ -481,7 +488,7 @@ function useAsyncMultiselect({
|
|
|
481
488
|
if (!items.value.length)
|
|
482
489
|
return [];
|
|
483
490
|
if (!mapOptionCallback)
|
|
484
|
-
return
|
|
491
|
+
return items.value;
|
|
485
492
|
return items.value.map(mapOptionCallback);
|
|
486
493
|
});
|
|
487
494
|
const hasNextPage = computed(() => count.value > items.value.length);
|
|
@@ -631,7 +638,7 @@ function useAsyncSelect({
|
|
|
631
638
|
if (!items.value.length)
|
|
632
639
|
return [];
|
|
633
640
|
if (!mapOptionCallback)
|
|
634
|
-
return
|
|
641
|
+
return items.value;
|
|
635
642
|
return items.value.map(mapOptionCallback);
|
|
636
643
|
});
|
|
637
644
|
const hasNextPage = computed(() => count.value > items.value.length);
|
|
@@ -820,6 +827,35 @@ function useDialog() {
|
|
|
820
827
|
} = useGlobalScroll();
|
|
821
828
|
const route = useRoute();
|
|
822
829
|
const router = useRouter();
|
|
830
|
+
const HASH_PREFIX = "#ud_";
|
|
831
|
+
const parseHash = (hash, componentName) => {
|
|
832
|
+
if (!hash)
|
|
833
|
+
return void 0;
|
|
834
|
+
if (!hash.includes(HASH_PREFIX))
|
|
835
|
+
return void 0;
|
|
836
|
+
let dataFromHash;
|
|
837
|
+
try {
|
|
838
|
+
dataFromHash = JSON.parse(window.atob(hash.slice(HASH_PREFIX.length)));
|
|
839
|
+
} catch (error) {
|
|
840
|
+
logger.warn("*parseHash* cant parse hash");
|
|
841
|
+
}
|
|
842
|
+
if (typeof dataFromHash !== "object")
|
|
843
|
+
return void 0;
|
|
844
|
+
if (!dataFromHash.name) {
|
|
845
|
+
logger.warn("*parseHash* cant find component name in hash");
|
|
846
|
+
return void 0;
|
|
847
|
+
}
|
|
848
|
+
if (dataFromHash.name !== componentName)
|
|
849
|
+
return void 0;
|
|
850
|
+
return dataFromHash;
|
|
851
|
+
};
|
|
852
|
+
const clearHash = () => {
|
|
853
|
+
router.push({
|
|
854
|
+
name: route.name || void 0,
|
|
855
|
+
query: route.query,
|
|
856
|
+
hash: void 0
|
|
857
|
+
});
|
|
858
|
+
};
|
|
823
859
|
onMounted(() => {
|
|
824
860
|
appContext = getCurrentInstance()?.appContext;
|
|
825
861
|
});
|
|
@@ -845,16 +881,26 @@ function useDialog() {
|
|
|
845
881
|
vnode2.props["onUpdate:modelValue"] = (value) => {
|
|
846
882
|
if (vnode2 && vnode2.component) {
|
|
847
883
|
vnode2.component.props.modelValue = value;
|
|
848
|
-
if (!value &&
|
|
884
|
+
if (!value && route?.hash) {
|
|
885
|
+
const dataFromHash = parseHash(route.hash, component.name);
|
|
886
|
+
if (dataFromHash)
|
|
887
|
+
clearHash();
|
|
888
|
+
}
|
|
889
|
+
if (!value && (dialogs.length === 1 || layer === 0) && isGlobalScrollLocked.value) {
|
|
849
890
|
unlockGlobalScroll();
|
|
850
891
|
}
|
|
851
892
|
}
|
|
852
893
|
};
|
|
853
894
|
}
|
|
854
895
|
vnode2.close = () => {
|
|
855
|
-
if (vnode2
|
|
856
|
-
|
|
857
|
-
|
|
896
|
+
if (!vnode2 || !vnode2.component)
|
|
897
|
+
return;
|
|
898
|
+
vnode2.component.props.modelValue = false;
|
|
899
|
+
if (!route?.hash)
|
|
900
|
+
return;
|
|
901
|
+
const dataFromHash = parseHash(route.hash, component.name);
|
|
902
|
+
if (dataFromHash)
|
|
903
|
+
clearHash();
|
|
858
904
|
};
|
|
859
905
|
vnode2.props.onDestroy = () => {
|
|
860
906
|
render(null, el2);
|
|
@@ -911,7 +957,7 @@ function useDialog() {
|
|
|
911
957
|
const close = (uuid) => {
|
|
912
958
|
const dialog = dialogs.find((item) => item.uuid === uuid);
|
|
913
959
|
logger.log(`Close dialog: "${uuid}"`);
|
|
914
|
-
if (dialogs.length === 1 && isGlobalScrollLocked.value) {
|
|
960
|
+
if ((dialogs.length === 1 || dialog.layer === 0) && isGlobalScrollLocked.value) {
|
|
915
961
|
unlockGlobalScroll();
|
|
916
962
|
}
|
|
917
963
|
dialog?.vnode.close();
|
|
@@ -949,7 +995,7 @@ function useDialog() {
|
|
|
949
995
|
router.push({
|
|
950
996
|
name: route.name || void 0,
|
|
951
997
|
query: route.query,
|
|
952
|
-
hash:
|
|
998
|
+
hash: `${HASH_PREFIX}${window.btoa(JSON.stringify(data))}`
|
|
953
999
|
});
|
|
954
1000
|
};
|
|
955
1001
|
const watchHash = ({
|
|
@@ -961,22 +1007,13 @@ function useDialog() {
|
|
|
961
1007
|
() => route.hash,
|
|
962
1008
|
async (newHash) => {
|
|
963
1009
|
if (!newHash) {
|
|
1010
|
+
if (!dialogs.length)
|
|
1011
|
+
return;
|
|
964
1012
|
closeAll();
|
|
965
1013
|
return;
|
|
966
1014
|
}
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
dataFromHash = JSON.parse(window.atob(newHash.slice(1)));
|
|
970
|
-
} catch (error) {
|
|
971
|
-
logger.error("*watchHash* cant parse hash");
|
|
972
|
-
}
|
|
973
|
-
if (typeof dataFromHash !== "object")
|
|
974
|
-
return;
|
|
975
|
-
if (!dataFromHash.name) {
|
|
976
|
-
logger.error("*watchHash* cant find component name in hash");
|
|
977
|
-
return;
|
|
978
|
-
}
|
|
979
|
-
if (dataFromHash.name !== component.name)
|
|
1015
|
+
const dataFromHash = parseHash(newHash, component.name);
|
|
1016
|
+
if (!dataFromHash)
|
|
980
1017
|
return;
|
|
981
1018
|
logger.info("*watchHash* data from hash", dataFromHash);
|
|
982
1019
|
await nextTick();
|
|
@@ -984,15 +1021,6 @@ function useDialog() {
|
|
|
984
1021
|
component,
|
|
985
1022
|
layer: dataFromHash.layer || 0,
|
|
986
1023
|
props: {
|
|
987
|
-
"onUpdate:modelValue": (value) => {
|
|
988
|
-
if (value)
|
|
989
|
-
return;
|
|
990
|
-
router.push({
|
|
991
|
-
name: route.name || void 0,
|
|
992
|
-
query: route.query,
|
|
993
|
-
hash: void 0
|
|
994
|
-
});
|
|
995
|
-
},
|
|
996
1024
|
...dataFromHash.props,
|
|
997
1025
|
...events
|
|
998
1026
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@karta.io/utils",
|
|
3
|
-
"version": "1.0.0-
|
|
3
|
+
"version": "1.0.0-beta.10",
|
|
4
4
|
"description": "karta.io utils for admin and application",
|
|
5
5
|
"author": "Vitaly Blokhin <karambafe@gmail.com>",
|
|
6
6
|
"homepage": "",
|
|
@@ -10,7 +10,8 @@
|
|
|
10
10
|
"exports": {
|
|
11
11
|
".": {
|
|
12
12
|
"require": "./dist/index.cjs",
|
|
13
|
-
"import": "./dist/index.mjs"
|
|
13
|
+
"import": "./dist/index.mjs",
|
|
14
|
+
"types": "./dist/index.d.ts"
|
|
14
15
|
},
|
|
15
16
|
"./*": "./*"
|
|
16
17
|
},
|
|
@@ -21,35 +22,35 @@
|
|
|
21
22
|
"dist"
|
|
22
23
|
],
|
|
23
24
|
"peerDependencies": {
|
|
24
|
-
"vue": "3.
|
|
25
|
+
"vue": "3.x"
|
|
25
26
|
},
|
|
26
27
|
"dependencies": {
|
|
27
|
-
"@karta.io/common-data": "^1.0.0-
|
|
28
|
-
"@tanstack/vue-query": "
|
|
29
|
-
"@vueuse/core": "10.
|
|
28
|
+
"@karta.io/common-data": "^1.0.0-beta.10",
|
|
29
|
+
"@tanstack/vue-query": "5.x",
|
|
30
|
+
"@vueuse/core": "10.7.2",
|
|
30
31
|
"async-validator": "4.2.5",
|
|
31
|
-
"axios": "1.
|
|
32
|
-
"dayjs": "1.11.
|
|
32
|
+
"axios": "1.6.7",
|
|
33
|
+
"dayjs": "1.11.10",
|
|
33
34
|
"detect-browser": "5.3.0",
|
|
34
|
-
"libphonenumber-js": "1.10.
|
|
35
|
+
"libphonenumber-js": "1.10.55",
|
|
35
36
|
"lodash": "4.17.21",
|
|
36
37
|
"logdown": "3.3.1",
|
|
37
38
|
"qs": "6.11.2",
|
|
38
|
-
"vue-router": "4.x
|
|
39
|
+
"vue-router": "4.x"
|
|
39
40
|
},
|
|
40
41
|
"devDependencies": {
|
|
41
42
|
"@qvant/prettier-config": "0.1.0",
|
|
42
|
-
"@types/lodash": "4.14.
|
|
43
|
-
"@typescript-eslint/eslint-plugin": "
|
|
44
|
-
"@typescript-eslint/parser": "
|
|
45
|
-
"eslint": "8.
|
|
43
|
+
"@types/lodash": "4.14.202",
|
|
44
|
+
"@typescript-eslint/eslint-plugin": "6.20.0",
|
|
45
|
+
"@typescript-eslint/parser": "6.20.0",
|
|
46
|
+
"eslint": "8.56.0",
|
|
46
47
|
"eslint-config-airbnb-base": "15.0.0",
|
|
47
|
-
"eslint-plugin-import": "2.
|
|
48
|
-
"prettier": "3.
|
|
49
|
-
"typescript": "5.
|
|
50
|
-
"unbuild": "
|
|
51
|
-
"vitest": "
|
|
52
|
-
"vue": "3.
|
|
48
|
+
"eslint-plugin-import": "2.29.1",
|
|
49
|
+
"prettier": "3.2.5",
|
|
50
|
+
"typescript": "5.3.3",
|
|
51
|
+
"unbuild": "2.0.0",
|
|
52
|
+
"vitest": "1.2.2",
|
|
53
|
+
"vue": "3.4.15"
|
|
53
54
|
},
|
|
54
55
|
"scripts": {
|
|
55
56
|
"dev": "vitest",
|