@karta.io/utils 1.0.0-beta.2 → 1.0.0-beta.21
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 +129 -51
- package/dist/index.d.cts +354 -0
- package/dist/index.d.mts +354 -0
- package/dist/index.d.ts +16 -12
- package/dist/index.mjs +129 -51
- package/package.json +33 -34
package/dist/index.d.ts
CHANGED
|
@@ -23,7 +23,7 @@ interface ResponseError {
|
|
|
23
23
|
data: Record<string, string | string[]> | null;
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
declare function camelizeKeys(object: Dictionary):
|
|
26
|
+
declare function camelizeKeys<T extends Record<string, any> = Dictionary>(object: Dictionary): T;
|
|
27
27
|
|
|
28
28
|
interface Options$3 {
|
|
29
29
|
labelType: 'key' | 'value';
|
|
@@ -78,7 +78,7 @@ declare function getPaginationParams({ page, limit, }: {
|
|
|
78
78
|
limit: number;
|
|
79
79
|
offset: number;
|
|
80
80
|
};
|
|
81
|
-
declare function getPaginationLimit({ limit }: {
|
|
81
|
+
declare function getPaginationLimit({ limit, }: {
|
|
82
82
|
limit: string | number;
|
|
83
83
|
}): number;
|
|
84
84
|
declare function getPaginationOffset({ page, limit, }: {
|
|
@@ -93,7 +93,7 @@ declare function getPaginationPages({ count, limit, }: {
|
|
|
93
93
|
declare function parsePhone(phone: string | null | undefined): string;
|
|
94
94
|
|
|
95
95
|
type SnakelizeKeysProp = Record<string | number, any>;
|
|
96
|
-
declare function snakelizeKeys(prop: SnakelizeKeysProp):
|
|
96
|
+
declare function snakelizeKeys<T extends Record<string, any> = SnakelizeKeysProp>(prop: SnakelizeKeysProp): T;
|
|
97
97
|
|
|
98
98
|
/**
|
|
99
99
|
* Принимает на вход число в виде строки или числа,
|
|
@@ -134,11 +134,11 @@ declare function useAsyncItems<T extends (...args: any[]) => any>({ apiMethod, q
|
|
|
134
134
|
params: MaybeRef<Parameters<T>[0]>;
|
|
135
135
|
config?: AxiosRequestConfig;
|
|
136
136
|
}): {
|
|
137
|
-
isLoading: vue.Ref<false> | vue.Ref<true>;
|
|
137
|
+
isLoading: vue.Ref<boolean> | vue.Ref<false> | vue.Ref<true>;
|
|
138
138
|
isFetching: vue.Ref<boolean>;
|
|
139
139
|
isError: vue.Ref<false> | vue.Ref<true>;
|
|
140
|
-
data: vue.Ref<any>;
|
|
141
|
-
error: vue.Ref<
|
|
140
|
+
data: vue.Ref<any> | vue.Ref<undefined>;
|
|
141
|
+
error: vue.Ref<Error> | vue.Ref<null>;
|
|
142
142
|
items: vue.ComputedRef<Awaited<ReturnType<T>>["results"]>;
|
|
143
143
|
count: vue.Ref<number>;
|
|
144
144
|
refetch: () => void;
|
|
@@ -169,9 +169,11 @@ declare function useAsyncMultiselect<T extends (...args: any[]) => any, K extend
|
|
|
169
169
|
search: vue.Ref<string>;
|
|
170
170
|
hasNextPage: vue.ComputedRef<boolean>;
|
|
171
171
|
isFetching: vue.Ref<boolean>;
|
|
172
|
-
isLoading: vue.Ref<false> | vue.Ref<true>;
|
|
172
|
+
isLoading: vue.Ref<boolean> | vue.Ref<false> | vue.Ref<true>;
|
|
173
173
|
loadPage: (newPage?: number) => void;
|
|
174
174
|
updateSearch: (value: string) => void;
|
|
175
|
+
refetch: () => void;
|
|
176
|
+
reload: () => void;
|
|
175
177
|
};
|
|
176
178
|
|
|
177
179
|
interface ReactiveData {
|
|
@@ -196,9 +198,11 @@ declare function useAsyncSelect<T extends (...args: any[]) => any, K extends (pa
|
|
|
196
198
|
search: vue.Ref<string>;
|
|
197
199
|
hasNextPage: vue.ComputedRef<boolean>;
|
|
198
200
|
isFetching: vue.Ref<boolean>;
|
|
199
|
-
isLoading: vue.Ref<false> | vue.Ref<true>;
|
|
201
|
+
isLoading: vue.Ref<boolean> | vue.Ref<false> | vue.Ref<true>;
|
|
200
202
|
loadPage: (newPage?: number) => void;
|
|
201
203
|
updateSearch: (value: string) => void;
|
|
204
|
+
refetch: () => void;
|
|
205
|
+
reload: () => void;
|
|
202
206
|
};
|
|
203
207
|
|
|
204
208
|
declare function useBreakpoint(): {
|
|
@@ -246,7 +250,7 @@ type VersionsList = {
|
|
|
246
250
|
declare function useDetectBrowser(versions: VersionsList, userAgent?: any): BrowserInfo;
|
|
247
251
|
|
|
248
252
|
interface VNodeCustom$1 extends VNode {
|
|
249
|
-
close()
|
|
253
|
+
close: () => void;
|
|
250
254
|
}
|
|
251
255
|
declare function useDialog(): {
|
|
252
256
|
open: ({ layer, component, props, }: {
|
|
@@ -276,7 +280,7 @@ declare function useGlobalScroll(): {
|
|
|
276
280
|
unlock: () => void;
|
|
277
281
|
};
|
|
278
282
|
|
|
279
|
-
declare function useFilters<T extends Record<string, any>, K extends Record<string, any>>({ config, initialFilters
|
|
283
|
+
declare function useFilters<T extends Record<string, any>, K extends Record<string, any>>({ config, initialFilters }: {
|
|
280
284
|
config: T;
|
|
281
285
|
initialFilters: K;
|
|
282
286
|
}): {
|
|
@@ -306,7 +310,7 @@ interface Options {
|
|
|
306
310
|
declare function useLogger(scope: string, options?: Options): logdown.Logger;
|
|
307
311
|
|
|
308
312
|
interface VNodeCustom extends VNode {
|
|
309
|
-
close()
|
|
313
|
+
close: () => void;
|
|
310
314
|
}
|
|
311
315
|
/**
|
|
312
316
|
* @deprecated use useDialog
|
|
@@ -347,4 +351,4 @@ declare function isTypeUrl(message?: string): RuleItem;
|
|
|
347
351
|
declare function isTypeNumber(value?: number, message?: string): RuleItem;
|
|
348
352
|
declare function isStrictLength(value?: number, message?: string): RuleItem;
|
|
349
353
|
|
|
350
|
-
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 };
|
|
354
|
+
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
|
@@ -24,14 +24,16 @@ function AppComponentsResolver(options = {}) {
|
|
|
24
24
|
return (name) => {
|
|
25
25
|
const componentName = prefix && name.startsWith(prefix) ? name.substring(prefix.length) : name;
|
|
26
26
|
const isAppComponent = componentName.startsWith("App");
|
|
27
|
-
if (isAppComponent)
|
|
27
|
+
if (isAppComponent) {
|
|
28
28
|
return { name: componentName, from: "@karta.io/app-components" };
|
|
29
|
+
}
|
|
29
30
|
};
|
|
30
31
|
}
|
|
31
32
|
|
|
32
33
|
function camelizeKeys(object) {
|
|
33
|
-
if (Array.isArray(object))
|
|
34
|
+
if (Array.isArray(object)) {
|
|
34
35
|
return object.map((v) => camelizeKeys(v));
|
|
36
|
+
}
|
|
35
37
|
if (object !== null && object.constructor === Object) {
|
|
36
38
|
return Object.keys(object).reduce(
|
|
37
39
|
(result, key) => ({
|
|
@@ -75,7 +77,7 @@ function formatMoney(value, currency = CURRENCY_DEFAULT, options = {}) {
|
|
|
75
77
|
...otherOptions
|
|
76
78
|
});
|
|
77
79
|
return formatter.format(convertedValue);
|
|
78
|
-
} catch (
|
|
80
|
+
} catch (_error) {
|
|
79
81
|
return defaultValue;
|
|
80
82
|
}
|
|
81
83
|
}
|
|
@@ -105,7 +107,7 @@ function genUUID() {
|
|
|
105
107
|
r = (d2 + r) % 16 | 0;
|
|
106
108
|
d2 = Math.floor(d2 / 16);
|
|
107
109
|
}
|
|
108
|
-
return (c
|
|
110
|
+
return (c === "x" ? r : r & 7 | 8).toString(16);
|
|
109
111
|
});
|
|
110
112
|
}
|
|
111
113
|
|
|
@@ -185,7 +187,9 @@ function getPaginationParams({
|
|
|
185
187
|
offset: validatedPage * validatedLimit - validatedLimit
|
|
186
188
|
};
|
|
187
189
|
}
|
|
188
|
-
function getPaginationLimit({
|
|
190
|
+
function getPaginationLimit({
|
|
191
|
+
limit
|
|
192
|
+
}) {
|
|
189
193
|
return validateNumber(limit, LIMIT_DEFAULT);
|
|
190
194
|
}
|
|
191
195
|
function getPaginationOffset({
|
|
@@ -207,15 +211,17 @@ function parsePhone(phone) {
|
|
|
207
211
|
if (!phone || typeof phone !== "string")
|
|
208
212
|
return "";
|
|
209
213
|
const replacedPhone = phone.replace(/[a-zA-Z]/g, "");
|
|
210
|
-
if (replacedPhone.length === 1 && replacedPhone !== "+")
|
|
214
|
+
if (replacedPhone.length === 1 && replacedPhone !== "+") {
|
|
211
215
|
return `+${replacedPhone}`;
|
|
216
|
+
}
|
|
212
217
|
const phoneNumber = parsePhoneNumberFromString(replacedPhone);
|
|
213
218
|
return phoneNumber ? phoneNumber.formatInternational() : replacedPhone;
|
|
214
219
|
}
|
|
215
220
|
|
|
216
221
|
function snakelizeKeys(prop) {
|
|
217
|
-
if (Array.isArray(prop))
|
|
222
|
+
if (Array.isArray(prop)) {
|
|
218
223
|
return prop.map((item) => snakelizeKeys(item));
|
|
224
|
+
}
|
|
219
225
|
if (prop !== null && prop !== void 0 && prop.constructor === Object) {
|
|
220
226
|
return Object.keys(prop).reduce(
|
|
221
227
|
(accum, current) => ({
|
|
@@ -255,8 +261,9 @@ function unformatNumber(value) {
|
|
|
255
261
|
if (commasCount === 1 && !hasSpace && !hasDot) {
|
|
256
262
|
locale = string.length - 1 - commaIndex === 3 ? LOCALE_EN : LOCALE_RU;
|
|
257
263
|
}
|
|
258
|
-
if (locale === LOCALE_RU)
|
|
264
|
+
if (locale === LOCALE_RU) {
|
|
259
265
|
return Number(string.replaceAll(" ", "").replace(",", "."));
|
|
266
|
+
}
|
|
260
267
|
if (locale === LOCALE_EN)
|
|
261
268
|
return Number(string.replaceAll(",", ""));
|
|
262
269
|
return value;
|
|
@@ -267,8 +274,9 @@ function UiComponentsResolver(options = {}) {
|
|
|
267
274
|
return (name) => {
|
|
268
275
|
const componentName = prefix && name.startsWith(prefix) ? name.substring(prefix.length) : name;
|
|
269
276
|
const isUiComponent = componentName.startsWith("Ui");
|
|
270
|
-
if (isUiComponent)
|
|
277
|
+
if (isUiComponent) {
|
|
271
278
|
return { name: componentName, from: "@karta.io/ui-components" };
|
|
279
|
+
}
|
|
272
280
|
};
|
|
273
281
|
}
|
|
274
282
|
|
|
@@ -316,7 +324,9 @@ function useAsyncItems({
|
|
|
316
324
|
queryKey: getQueryKey(),
|
|
317
325
|
queryFn: () => call(toValue(params), config)
|
|
318
326
|
});
|
|
319
|
-
const items = computed(
|
|
327
|
+
const items = computed(
|
|
328
|
+
() => data.value?.results || []
|
|
329
|
+
);
|
|
320
330
|
const count = ref(0);
|
|
321
331
|
watch(
|
|
322
332
|
data,
|
|
@@ -393,7 +403,12 @@ function useAsyncMultiselect({
|
|
|
393
403
|
color: "#b54708",
|
|
394
404
|
debug: true
|
|
395
405
|
});
|
|
396
|
-
const paramsForLogger = {
|
|
406
|
+
const paramsForLogger = {
|
|
407
|
+
queryKey,
|
|
408
|
+
dataItemsKey,
|
|
409
|
+
dataItemIdKey,
|
|
410
|
+
dataCountKey
|
|
411
|
+
};
|
|
397
412
|
const reactiveData = reactive({
|
|
398
413
|
search: "",
|
|
399
414
|
page: 1,
|
|
@@ -439,8 +454,9 @@ function useAsyncMultiselect({
|
|
|
439
454
|
);
|
|
440
455
|
return;
|
|
441
456
|
}
|
|
442
|
-
if (!get(newValue, dataItemsKey) || get(newValue, dataCountKey) === void 0)
|
|
457
|
+
if (!get(newValue, dataItemsKey) || get(newValue, dataCountKey) === void 0) {
|
|
443
458
|
return;
|
|
459
|
+
}
|
|
444
460
|
count.value = get(newValue, dataCountKey, 0);
|
|
445
461
|
const newItems = get(newValue, dataItemsKey);
|
|
446
462
|
itemsByPages.value = {
|
|
@@ -471,8 +487,9 @@ function useAsyncMultiselect({
|
|
|
471
487
|
const items = computed(() => {
|
|
472
488
|
if (!itemsByPages.value)
|
|
473
489
|
return selectedItemsCached.value;
|
|
474
|
-
if (!Object.keys(itemsByPages.value).length)
|
|
490
|
+
if (!Object.keys(itemsByPages.value).length) {
|
|
475
491
|
return selectedItemsCached.value;
|
|
492
|
+
}
|
|
476
493
|
const itemsByPagesAsArray = Object.values(itemsByPages.value).reduce(
|
|
477
494
|
(acc, item) => [...acc, ...item],
|
|
478
495
|
[]
|
|
@@ -488,7 +505,7 @@ function useAsyncMultiselect({
|
|
|
488
505
|
if (!items.value.length)
|
|
489
506
|
return [];
|
|
490
507
|
if (!mapOptionCallback)
|
|
491
|
-
return
|
|
508
|
+
return items.value;
|
|
492
509
|
return items.value.map(mapOptionCallback);
|
|
493
510
|
});
|
|
494
511
|
const hasNextPage = computed(() => count.value > items.value.length);
|
|
@@ -507,6 +524,28 @@ function useAsyncMultiselect({
|
|
|
507
524
|
search.value = value;
|
|
508
525
|
updateSearchWithDebounce(value);
|
|
509
526
|
};
|
|
527
|
+
const queryClient = useQueryClient();
|
|
528
|
+
const refetch = () => {
|
|
529
|
+
if (reactiveData.page !== 1) {
|
|
530
|
+
queryClient.invalidateQueries({
|
|
531
|
+
queryKey: [queryKey],
|
|
532
|
+
refetchType: "none"
|
|
533
|
+
});
|
|
534
|
+
loadPage(1);
|
|
535
|
+
} else {
|
|
536
|
+
queryClient.invalidateQueries({
|
|
537
|
+
queryKey: [queryKey]
|
|
538
|
+
});
|
|
539
|
+
}
|
|
540
|
+
};
|
|
541
|
+
const reload = () => {
|
|
542
|
+
if (reactiveData.page !== 1) {
|
|
543
|
+
queryClient.removeQueries({ queryKey: [queryKey] });
|
|
544
|
+
loadPage(1);
|
|
545
|
+
} else {
|
|
546
|
+
queryClient.resetQueries({ queryKey: [queryKey] });
|
|
547
|
+
}
|
|
548
|
+
};
|
|
510
549
|
if (isRef(selectedValues)) {
|
|
511
550
|
watch(selectedValues, async (newSelectedValues) => {
|
|
512
551
|
if (!newSelectedValues.length) {
|
|
@@ -547,7 +586,9 @@ function useAsyncMultiselect({
|
|
|
547
586
|
isFetching,
|
|
548
587
|
isLoading,
|
|
549
588
|
loadPage,
|
|
550
|
-
updateSearch
|
|
589
|
+
updateSearch,
|
|
590
|
+
refetch,
|
|
591
|
+
reload
|
|
551
592
|
};
|
|
552
593
|
}
|
|
553
594
|
|
|
@@ -579,7 +620,9 @@ function useAsyncSelect({
|
|
|
579
620
|
const loadWAC = () => call({
|
|
580
621
|
page: reactiveData.page,
|
|
581
622
|
search: reactiveData.search,
|
|
582
|
-
...reactiveData.selectedValue && {
|
|
623
|
+
...reactiveData.selectedValue && {
|
|
624
|
+
includedIds: [reactiveData.selectedValue]
|
|
625
|
+
},
|
|
583
626
|
...reactiveData.params && { ...JSON.parse(reactiveData.params) }
|
|
584
627
|
});
|
|
585
628
|
const { data, isFetching, isLoading } = useQuery({
|
|
@@ -607,8 +650,9 @@ function useAsyncSelect({
|
|
|
607
650
|
);
|
|
608
651
|
return;
|
|
609
652
|
}
|
|
610
|
-
if (!get(newValue, dataItemsKey) || get(newValue, dataCountKey) === void 0)
|
|
653
|
+
if (!get(newValue, dataItemsKey) || get(newValue, dataCountKey) === void 0) {
|
|
611
654
|
return;
|
|
655
|
+
}
|
|
612
656
|
count.value = get(newValue, dataCountKey, 0);
|
|
613
657
|
const newItems = get(newValue, dataItemsKey);
|
|
614
658
|
itemsByPages.value = {
|
|
@@ -638,7 +682,7 @@ function useAsyncSelect({
|
|
|
638
682
|
if (!items.value.length)
|
|
639
683
|
return [];
|
|
640
684
|
if (!mapOptionCallback)
|
|
641
|
-
return
|
|
685
|
+
return items.value;
|
|
642
686
|
return items.value.map(mapOptionCallback);
|
|
643
687
|
});
|
|
644
688
|
const hasNextPage = computed(() => count.value > items.value.length);
|
|
@@ -653,6 +697,28 @@ function useAsyncSelect({
|
|
|
653
697
|
search.value = value;
|
|
654
698
|
updateSearchWithDebounce(value);
|
|
655
699
|
};
|
|
700
|
+
const queryClient = useQueryClient();
|
|
701
|
+
const refetch = () => {
|
|
702
|
+
if (reactiveData.page !== 1) {
|
|
703
|
+
queryClient.invalidateQueries({
|
|
704
|
+
queryKey: [queryKey],
|
|
705
|
+
refetchType: "none"
|
|
706
|
+
});
|
|
707
|
+
loadPage(1);
|
|
708
|
+
} else {
|
|
709
|
+
queryClient.invalidateQueries({
|
|
710
|
+
queryKey: [queryKey]
|
|
711
|
+
});
|
|
712
|
+
}
|
|
713
|
+
};
|
|
714
|
+
const reload = () => {
|
|
715
|
+
if (reactiveData.page !== 1) {
|
|
716
|
+
queryClient.removeQueries({ queryKey: [queryKey] });
|
|
717
|
+
loadPage(1);
|
|
718
|
+
} else {
|
|
719
|
+
queryClient.resetQueries({ queryKey: [queryKey] });
|
|
720
|
+
}
|
|
721
|
+
};
|
|
656
722
|
if (isRef(selectedValue)) {
|
|
657
723
|
watch(selectedValue, (newSelectedValue) => {
|
|
658
724
|
reactiveData.page = 1;
|
|
@@ -676,7 +742,9 @@ function useAsyncSelect({
|
|
|
676
742
|
isFetching,
|
|
677
743
|
isLoading,
|
|
678
744
|
loadPage,
|
|
679
|
-
updateSearch
|
|
745
|
+
updateSearch,
|
|
746
|
+
refetch,
|
|
747
|
+
reload
|
|
680
748
|
};
|
|
681
749
|
}
|
|
682
750
|
|
|
@@ -756,7 +824,9 @@ function useDayjs(timezone) {
|
|
|
756
824
|
|
|
757
825
|
function parseVersion(version) {
|
|
758
826
|
if (typeof version !== "string" && typeof version !== "number") {
|
|
759
|
-
throw new TypeError(
|
|
827
|
+
throw new TypeError(
|
|
828
|
+
"Browser version must be type of string, number or negative boolean"
|
|
829
|
+
);
|
|
760
830
|
}
|
|
761
831
|
const [major, minor = 0, patch = 0, build = 0] = typeof version === "string" ? version.split(".").map(Number) : [version];
|
|
762
832
|
return {
|
|
@@ -836,7 +906,7 @@ function useDialog() {
|
|
|
836
906
|
let dataFromHash;
|
|
837
907
|
try {
|
|
838
908
|
dataFromHash = JSON.parse(window.atob(hash.slice(HASH_PREFIX.length)));
|
|
839
|
-
} catch (
|
|
909
|
+
} catch (_error) {
|
|
840
910
|
logger.warn("*parseHash* cant parse hash");
|
|
841
911
|
}
|
|
842
912
|
if (typeof dataFromHash !== "object")
|
|
@@ -1056,10 +1126,7 @@ const QS_STRINGIFY_PARAMS = {
|
|
|
1056
1126
|
addQueryPrefix: true
|
|
1057
1127
|
};
|
|
1058
1128
|
const isOpen = ref(false);
|
|
1059
|
-
function useFilters({
|
|
1060
|
-
config,
|
|
1061
|
-
initialFilters
|
|
1062
|
-
}) {
|
|
1129
|
+
function useFilters({ config, initialFilters }) {
|
|
1063
1130
|
const router = useRouter();
|
|
1064
1131
|
const route = useRoute();
|
|
1065
1132
|
const parseRouteQuery = (query) => qs.parse(query ?? route.query);
|
|
@@ -1067,35 +1134,43 @@ function useFilters({
|
|
|
1067
1134
|
const parsedRouteQuery = parseRouteQuery();
|
|
1068
1135
|
if (!parsedRouteQuery.filters)
|
|
1069
1136
|
return void 0;
|
|
1070
|
-
return Object.entries(config).reduce(
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
if (currentValue.type === "ARRAY" /* Array */) {
|
|
1074
|
-
const splitValues = parsedRouteQuery.filters[currentKey].split(",");
|
|
1075
|
-
const checkedValue = currentValue?.possibleValues ? splitValues.filter((k) => currentValue?.possibleValues?.includes(k)) : splitValues;
|
|
1076
|
-
if (!checkedValue?.length)
|
|
1137
|
+
return Object.entries(config).reduce(
|
|
1138
|
+
(accum, [currentKey, currentValue]) => {
|
|
1139
|
+
if (!parsedRouteQuery.filters[currentKey])
|
|
1077
1140
|
return accum;
|
|
1141
|
+
if (currentValue.type === "ARRAY" /* Array */) {
|
|
1142
|
+
const splitValues = parsedRouteQuery.filters[currentKey].split(",");
|
|
1143
|
+
const checkedValue = currentValue?.possibleValues ? splitValues.filter(
|
|
1144
|
+
(k) => currentValue?.possibleValues?.includes(k)
|
|
1145
|
+
) : splitValues;
|
|
1146
|
+
if (!checkedValue?.length)
|
|
1147
|
+
return accum;
|
|
1148
|
+
return {
|
|
1149
|
+
...accum,
|
|
1150
|
+
[currentKey]: checkedValue
|
|
1151
|
+
};
|
|
1152
|
+
}
|
|
1078
1153
|
return {
|
|
1079
1154
|
...accum,
|
|
1080
|
-
[currentKey]:
|
|
1155
|
+
[currentKey]: parsedRouteQuery.filters[currentKey]
|
|
1081
1156
|
};
|
|
1082
|
-
}
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
[currentKey]: parsedRouteQuery.filters[currentKey]
|
|
1086
|
-
};
|
|
1087
|
-
}, {});
|
|
1157
|
+
},
|
|
1158
|
+
{}
|
|
1159
|
+
);
|
|
1088
1160
|
});
|
|
1089
1161
|
const filtersCount = computed(
|
|
1090
1162
|
() => filtersFromQuery.value ? Object.keys(filtersFromQuery.value).length : 0
|
|
1091
1163
|
);
|
|
1092
1164
|
const setQueryFromFilters = (filters) => {
|
|
1093
1165
|
const parsedRouteQuery = parseRouteQuery();
|
|
1094
|
-
const filteredValue = Object.entries(filters).reduce(
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1166
|
+
const filteredValue = Object.entries(filters).reduce(
|
|
1167
|
+
(accum, [currentKey, currentValue]) => {
|
|
1168
|
+
if (!currentValue?.length)
|
|
1169
|
+
return accum;
|
|
1170
|
+
return { ...accum, [currentKey]: currentValue };
|
|
1171
|
+
},
|
|
1172
|
+
{}
|
|
1173
|
+
);
|
|
1099
1174
|
const query = qs.stringify(
|
|
1100
1175
|
{
|
|
1101
1176
|
...parsedRouteQuery,
|
|
@@ -1132,12 +1207,15 @@ function useFilters({
|
|
|
1132
1207
|
});
|
|
1133
1208
|
};
|
|
1134
1209
|
const updateMany = (filters) => {
|
|
1135
|
-
const newFilters = Object.entries(filters).reduce(
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1210
|
+
const newFilters = Object.entries(filters).reduce(
|
|
1211
|
+
(accum, [currentKey, currentValue]) => {
|
|
1212
|
+
return {
|
|
1213
|
+
...accum,
|
|
1214
|
+
[currentKey]: currentValue ? String(currentValue) : void 0
|
|
1215
|
+
};
|
|
1216
|
+
},
|
|
1217
|
+
{}
|
|
1218
|
+
);
|
|
1141
1219
|
setQueryFromFilters({
|
|
1142
1220
|
...filtersModel.value,
|
|
1143
1221
|
...newFilters
|
|
@@ -1313,7 +1391,7 @@ function usePanel() {
|
|
|
1313
1391
|
let dataFromHash;
|
|
1314
1392
|
try {
|
|
1315
1393
|
dataFromHash = JSON.parse(window.atob(newHash.slice(1)));
|
|
1316
|
-
} catch (
|
|
1394
|
+
} catch (_error) {
|
|
1317
1395
|
logger.error("*watchHash* cant parse hash");
|
|
1318
1396
|
}
|
|
1319
1397
|
if (typeof dataFromHash !== "object")
|
package/package.json
CHANGED
|
@@ -1,61 +1,60 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@karta.io/utils",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.21",
|
|
4
4
|
"description": "karta.io utils for admin and application",
|
|
5
|
-
"author": "Vitaly Blokhin <karambafe@gmail.com>",
|
|
6
|
-
"homepage": "",
|
|
7
|
-
"license": "MIT",
|
|
8
|
-
"sideEffects": false,
|
|
9
5
|
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"homepage": "",
|
|
8
|
+
"author": "Vitaly Blokhin <karambafe@gmail.com>",
|
|
9
|
+
"files": [
|
|
10
|
+
"dist"
|
|
11
|
+
],
|
|
12
|
+
"main": "./dist/index.cjs",
|
|
13
|
+
"module": "./dist/index.mjs",
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
10
15
|
"exports": {
|
|
11
16
|
".": {
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
12
18
|
"require": "./dist/index.cjs",
|
|
13
19
|
"import": "./dist/index.mjs"
|
|
14
20
|
},
|
|
15
21
|
"./*": "./*"
|
|
16
22
|
},
|
|
17
|
-
"
|
|
18
|
-
"module": "./dist/index.mjs",
|
|
19
|
-
"types": "./dist/index.d.ts",
|
|
20
|
-
"files": [
|
|
21
|
-
"dist"
|
|
22
|
-
],
|
|
23
|
+
"sideEffects": false,
|
|
23
24
|
"peerDependencies": {
|
|
24
|
-
"vue": "3.
|
|
25
|
+
"vue": "3.x"
|
|
25
26
|
},
|
|
26
27
|
"dependencies": {
|
|
27
|
-
"@karta.io/common-data": "^1.0.0-beta.
|
|
28
|
-
"@tanstack/vue-query": "
|
|
29
|
-
"@vueuse/core": "10.
|
|
28
|
+
"@karta.io/common-data": "^1.0.0-beta.21",
|
|
29
|
+
"@tanstack/vue-query": "5.36.0",
|
|
30
|
+
"@vueuse/core": "10.9.0",
|
|
30
31
|
"async-validator": "4.2.5",
|
|
31
|
-
"axios": "1.
|
|
32
|
-
"dayjs": "1.11.
|
|
32
|
+
"axios": "1.6.8",
|
|
33
|
+
"dayjs": "1.11.11",
|
|
33
34
|
"detect-browser": "5.3.0",
|
|
34
|
-
"libphonenumber-js": "1.
|
|
35
|
+
"libphonenumber-js": "1.11.1",
|
|
35
36
|
"lodash": "4.17.21",
|
|
36
37
|
"logdown": "3.3.1",
|
|
37
|
-
"qs": "6.
|
|
38
|
-
"vue-router": "4.
|
|
38
|
+
"qs": "6.12.1",
|
|
39
|
+
"vue-router": "4.3.2"
|
|
39
40
|
},
|
|
40
41
|
"devDependencies": {
|
|
41
|
-
"@
|
|
42
|
-
"@
|
|
43
|
-
"@
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
"
|
|
49
|
-
"
|
|
50
|
-
"unbuild": "1.2.1",
|
|
51
|
-
"vitest": "0.32.2",
|
|
52
|
-
"vue": "3.3.4"
|
|
42
|
+
"@karta.io/eslint-config": "1.1.0",
|
|
43
|
+
"@karta.io/prettier-config": "1.0.0",
|
|
44
|
+
"@types/lodash": "4.17.1",
|
|
45
|
+
"eslint": "9.2.0",
|
|
46
|
+
"prettier": "3.2.5",
|
|
47
|
+
"typescript": "5.4.5",
|
|
48
|
+
"unbuild": "2.0.0",
|
|
49
|
+
"vitest": "1.2.2",
|
|
50
|
+
"vue": "3.4.27"
|
|
53
51
|
},
|
|
52
|
+
"prettier": "@karta.io/prettier-config",
|
|
54
53
|
"scripts": {
|
|
55
54
|
"dev": "vitest",
|
|
56
55
|
"build": "unbuild",
|
|
57
|
-
"lint": "eslint
|
|
58
|
-
"lint:fix": "eslint --fix
|
|
56
|
+
"lint": "eslint .",
|
|
57
|
+
"lint:fix": "eslint . --fix",
|
|
59
58
|
"test": "pnpm lint && vitest run",
|
|
60
59
|
"prettier": "prettier --check --ignore-unknown \"**/*\"",
|
|
61
60
|
"prettier:fix": "prettier --write --ignore-unknown \"**/*\"",
|