@karta.io/utils 1.0.0-beta.14 → 1.0.0-beta.16
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 +73 -45
- package/dist/index.d.cts +6 -6
- package/dist/index.d.mts +6 -6
- package/dist/index.d.ts +6 -6
- package/dist/index.mjs +73 -45
- package/package.json +21 -23
package/dist/index.cjs
CHANGED
|
@@ -42,8 +42,9 @@ function AppComponentsResolver(options = {}) {
|
|
|
42
42
|
return (name) => {
|
|
43
43
|
const componentName = prefix && name.startsWith(prefix) ? name.substring(prefix.length) : name;
|
|
44
44
|
const isAppComponent = componentName.startsWith("App");
|
|
45
|
-
if (isAppComponent)
|
|
45
|
+
if (isAppComponent) {
|
|
46
46
|
return { name: componentName, from: "@karta.io/app-components" };
|
|
47
|
+
}
|
|
47
48
|
};
|
|
48
49
|
}
|
|
49
50
|
|
|
@@ -94,7 +95,7 @@ function formatMoney(value, currency = commonData.CURRENCY_DEFAULT, options = {}
|
|
|
94
95
|
...otherOptions
|
|
95
96
|
});
|
|
96
97
|
return formatter.format(convertedValue);
|
|
97
|
-
} catch (
|
|
98
|
+
} catch (_error) {
|
|
98
99
|
return defaultValue;
|
|
99
100
|
}
|
|
100
101
|
}
|
|
@@ -124,7 +125,7 @@ function genUUID() {
|
|
|
124
125
|
r = (d2 + r) % 16 | 0;
|
|
125
126
|
d2 = Math.floor(d2 / 16);
|
|
126
127
|
}
|
|
127
|
-
return (c
|
|
128
|
+
return (c === "x" ? r : r & 7 | 8).toString(16);
|
|
128
129
|
});
|
|
129
130
|
}
|
|
130
131
|
|
|
@@ -204,7 +205,9 @@ function getPaginationParams({
|
|
|
204
205
|
offset: validatedPage * validatedLimit - validatedLimit
|
|
205
206
|
};
|
|
206
207
|
}
|
|
207
|
-
function getPaginationLimit({
|
|
208
|
+
function getPaginationLimit({
|
|
209
|
+
limit
|
|
210
|
+
}) {
|
|
208
211
|
return validateNumber(limit, LIMIT_DEFAULT);
|
|
209
212
|
}
|
|
210
213
|
function getPaginationOffset({
|
|
@@ -226,8 +229,9 @@ function parsePhone(phone) {
|
|
|
226
229
|
if (!phone || typeof phone !== "string")
|
|
227
230
|
return "";
|
|
228
231
|
const replacedPhone = phone.replace(/[a-zA-Z]/g, "");
|
|
229
|
-
if (replacedPhone.length === 1 && replacedPhone !== "+")
|
|
232
|
+
if (replacedPhone.length === 1 && replacedPhone !== "+") {
|
|
230
233
|
return `+${replacedPhone}`;
|
|
234
|
+
}
|
|
231
235
|
const phoneNumber = libphonenumberJs.parsePhoneNumberFromString(replacedPhone);
|
|
232
236
|
return phoneNumber ? phoneNumber.formatInternational() : replacedPhone;
|
|
233
237
|
}
|
|
@@ -275,8 +279,9 @@ function unformatNumber(value) {
|
|
|
275
279
|
if (commasCount === 1 && !hasSpace && !hasDot) {
|
|
276
280
|
locale = string.length - 1 - commaIndex === 3 ? LOCALE_EN : LOCALE_RU;
|
|
277
281
|
}
|
|
278
|
-
if (locale === LOCALE_RU)
|
|
282
|
+
if (locale === LOCALE_RU) {
|
|
279
283
|
return Number(string.replaceAll(" ", "").replace(",", "."));
|
|
284
|
+
}
|
|
280
285
|
if (locale === LOCALE_EN)
|
|
281
286
|
return Number(string.replaceAll(",", ""));
|
|
282
287
|
return value;
|
|
@@ -287,8 +292,9 @@ function UiComponentsResolver(options = {}) {
|
|
|
287
292
|
return (name) => {
|
|
288
293
|
const componentName = prefix && name.startsWith(prefix) ? name.substring(prefix.length) : name;
|
|
289
294
|
const isUiComponent = componentName.startsWith("Ui");
|
|
290
|
-
if (isUiComponent)
|
|
295
|
+
if (isUiComponent) {
|
|
291
296
|
return { name: componentName, from: "@karta.io/ui-components" };
|
|
297
|
+
}
|
|
292
298
|
};
|
|
293
299
|
}
|
|
294
300
|
|
|
@@ -336,7 +342,9 @@ function useAsyncItems({
|
|
|
336
342
|
queryKey: getQueryKey(),
|
|
337
343
|
queryFn: () => call(core.toValue(params), config)
|
|
338
344
|
});
|
|
339
|
-
const items = vue.computed(
|
|
345
|
+
const items = vue.computed(
|
|
346
|
+
() => data.value?.results || []
|
|
347
|
+
);
|
|
340
348
|
const count = vue.ref(0);
|
|
341
349
|
vue.watch(
|
|
342
350
|
data,
|
|
@@ -413,7 +421,12 @@ function useAsyncMultiselect({
|
|
|
413
421
|
color: "#b54708",
|
|
414
422
|
debug: true
|
|
415
423
|
});
|
|
416
|
-
const paramsForLogger = {
|
|
424
|
+
const paramsForLogger = {
|
|
425
|
+
queryKey,
|
|
426
|
+
dataItemsKey,
|
|
427
|
+
dataItemIdKey,
|
|
428
|
+
dataCountKey
|
|
429
|
+
};
|
|
417
430
|
const reactiveData = vue.reactive({
|
|
418
431
|
search: "",
|
|
419
432
|
page: 1,
|
|
@@ -459,8 +472,9 @@ function useAsyncMultiselect({
|
|
|
459
472
|
);
|
|
460
473
|
return;
|
|
461
474
|
}
|
|
462
|
-
if (!get__default(newValue, dataItemsKey) || get__default(newValue, dataCountKey) === void 0)
|
|
475
|
+
if (!get__default(newValue, dataItemsKey) || get__default(newValue, dataCountKey) === void 0) {
|
|
463
476
|
return;
|
|
477
|
+
}
|
|
464
478
|
count.value = get__default(newValue, dataCountKey, 0);
|
|
465
479
|
const newItems = get__default(newValue, dataItemsKey);
|
|
466
480
|
itemsByPages.value = {
|
|
@@ -491,8 +505,9 @@ function useAsyncMultiselect({
|
|
|
491
505
|
const items = vue.computed(() => {
|
|
492
506
|
if (!itemsByPages.value)
|
|
493
507
|
return selectedItemsCached.value;
|
|
494
|
-
if (!Object.keys(itemsByPages.value).length)
|
|
508
|
+
if (!Object.keys(itemsByPages.value).length) {
|
|
495
509
|
return selectedItemsCached.value;
|
|
510
|
+
}
|
|
496
511
|
const itemsByPagesAsArray = Object.values(itemsByPages.value).reduce(
|
|
497
512
|
(acc, item) => [...acc, ...item],
|
|
498
513
|
[]
|
|
@@ -599,7 +614,9 @@ function useAsyncSelect({
|
|
|
599
614
|
const loadWAC = () => call({
|
|
600
615
|
page: reactiveData.page,
|
|
601
616
|
search: reactiveData.search,
|
|
602
|
-
...reactiveData.selectedValue && {
|
|
617
|
+
...reactiveData.selectedValue && {
|
|
618
|
+
includedIds: [reactiveData.selectedValue]
|
|
619
|
+
},
|
|
603
620
|
...reactiveData.params && { ...JSON.parse(reactiveData.params) }
|
|
604
621
|
});
|
|
605
622
|
const { data, isFetching, isLoading } = vueQuery.useQuery({
|
|
@@ -627,8 +644,9 @@ function useAsyncSelect({
|
|
|
627
644
|
);
|
|
628
645
|
return;
|
|
629
646
|
}
|
|
630
|
-
if (!get__default(newValue, dataItemsKey) || get__default(newValue, dataCountKey) === void 0)
|
|
647
|
+
if (!get__default(newValue, dataItemsKey) || get__default(newValue, dataCountKey) === void 0) {
|
|
631
648
|
return;
|
|
649
|
+
}
|
|
632
650
|
count.value = get__default(newValue, dataCountKey, 0);
|
|
633
651
|
const newItems = get__default(newValue, dataItemsKey);
|
|
634
652
|
itemsByPages.value = {
|
|
@@ -776,7 +794,9 @@ function useDayjs(timezone) {
|
|
|
776
794
|
|
|
777
795
|
function parseVersion(version) {
|
|
778
796
|
if (typeof version !== "string" && typeof version !== "number") {
|
|
779
|
-
throw new TypeError(
|
|
797
|
+
throw new TypeError(
|
|
798
|
+
"Browser version must be type of string, number or negative boolean"
|
|
799
|
+
);
|
|
780
800
|
}
|
|
781
801
|
const [major, minor = 0, patch = 0, build = 0] = typeof version === "string" ? version.split(".").map(Number) : [version];
|
|
782
802
|
return {
|
|
@@ -856,7 +876,7 @@ function useDialog() {
|
|
|
856
876
|
let dataFromHash;
|
|
857
877
|
try {
|
|
858
878
|
dataFromHash = JSON.parse(window.atob(hash.slice(HASH_PREFIX.length)));
|
|
859
|
-
} catch (
|
|
879
|
+
} catch (_error) {
|
|
860
880
|
logger.warn("*parseHash* cant parse hash");
|
|
861
881
|
}
|
|
862
882
|
if (typeof dataFromHash !== "object")
|
|
@@ -1076,10 +1096,7 @@ const QS_STRINGIFY_PARAMS = {
|
|
|
1076
1096
|
addQueryPrefix: true
|
|
1077
1097
|
};
|
|
1078
1098
|
const isOpen = vue.ref(false);
|
|
1079
|
-
function useFilters({
|
|
1080
|
-
config,
|
|
1081
|
-
initialFilters
|
|
1082
|
-
}) {
|
|
1099
|
+
function useFilters({ config, initialFilters }) {
|
|
1083
1100
|
const router = vueRouter.useRouter();
|
|
1084
1101
|
const route = vueRouter.useRoute();
|
|
1085
1102
|
const parseRouteQuery = (query) => qs__default.parse(query ?? route.query);
|
|
@@ -1087,35 +1104,43 @@ function useFilters({
|
|
|
1087
1104
|
const parsedRouteQuery = parseRouteQuery();
|
|
1088
1105
|
if (!parsedRouteQuery.filters)
|
|
1089
1106
|
return void 0;
|
|
1090
|
-
return Object.entries(config).reduce(
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
if (currentValue.type === "ARRAY" /* Array */) {
|
|
1094
|
-
const splitValues = parsedRouteQuery.filters[currentKey].split(",");
|
|
1095
|
-
const checkedValue = currentValue?.possibleValues ? splitValues.filter((k) => currentValue?.possibleValues?.includes(k)) : splitValues;
|
|
1096
|
-
if (!checkedValue?.length)
|
|
1107
|
+
return Object.entries(config).reduce(
|
|
1108
|
+
(accum, [currentKey, currentValue]) => {
|
|
1109
|
+
if (!parsedRouteQuery.filters[currentKey])
|
|
1097
1110
|
return accum;
|
|
1111
|
+
if (currentValue.type === "ARRAY" /* Array */) {
|
|
1112
|
+
const splitValues = parsedRouteQuery.filters[currentKey].split(",");
|
|
1113
|
+
const checkedValue = currentValue?.possibleValues ? splitValues.filter(
|
|
1114
|
+
(k) => currentValue?.possibleValues?.includes(k)
|
|
1115
|
+
) : splitValues;
|
|
1116
|
+
if (!checkedValue?.length)
|
|
1117
|
+
return accum;
|
|
1118
|
+
return {
|
|
1119
|
+
...accum,
|
|
1120
|
+
[currentKey]: checkedValue
|
|
1121
|
+
};
|
|
1122
|
+
}
|
|
1098
1123
|
return {
|
|
1099
1124
|
...accum,
|
|
1100
|
-
[currentKey]:
|
|
1125
|
+
[currentKey]: parsedRouteQuery.filters[currentKey]
|
|
1101
1126
|
};
|
|
1102
|
-
}
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
[currentKey]: parsedRouteQuery.filters[currentKey]
|
|
1106
|
-
};
|
|
1107
|
-
}, {});
|
|
1127
|
+
},
|
|
1128
|
+
{}
|
|
1129
|
+
);
|
|
1108
1130
|
});
|
|
1109
1131
|
const filtersCount = vue.computed(
|
|
1110
1132
|
() => filtersFromQuery.value ? Object.keys(filtersFromQuery.value).length : 0
|
|
1111
1133
|
);
|
|
1112
1134
|
const setQueryFromFilters = (filters) => {
|
|
1113
1135
|
const parsedRouteQuery = parseRouteQuery();
|
|
1114
|
-
const filteredValue = Object.entries(filters).reduce(
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1136
|
+
const filteredValue = Object.entries(filters).reduce(
|
|
1137
|
+
(accum, [currentKey, currentValue]) => {
|
|
1138
|
+
if (!currentValue?.length)
|
|
1139
|
+
return accum;
|
|
1140
|
+
return { ...accum, [currentKey]: currentValue };
|
|
1141
|
+
},
|
|
1142
|
+
{}
|
|
1143
|
+
);
|
|
1119
1144
|
const query = qs__default.stringify(
|
|
1120
1145
|
{
|
|
1121
1146
|
...parsedRouteQuery,
|
|
@@ -1152,12 +1177,15 @@ function useFilters({
|
|
|
1152
1177
|
});
|
|
1153
1178
|
};
|
|
1154
1179
|
const updateMany = (filters) => {
|
|
1155
|
-
const newFilters = Object.entries(filters).reduce(
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1180
|
+
const newFilters = Object.entries(filters).reduce(
|
|
1181
|
+
(accum, [currentKey, currentValue]) => {
|
|
1182
|
+
return {
|
|
1183
|
+
...accum,
|
|
1184
|
+
[currentKey]: currentValue ? String(currentValue) : void 0
|
|
1185
|
+
};
|
|
1186
|
+
},
|
|
1187
|
+
{}
|
|
1188
|
+
);
|
|
1161
1189
|
setQueryFromFilters({
|
|
1162
1190
|
...filtersModel.value,
|
|
1163
1191
|
...newFilters
|
|
@@ -1333,7 +1361,7 @@ function usePanel() {
|
|
|
1333
1361
|
let dataFromHash;
|
|
1334
1362
|
try {
|
|
1335
1363
|
dataFromHash = JSON.parse(window.atob(newHash.slice(1)));
|
|
1336
|
-
} catch (
|
|
1364
|
+
} catch (_error) {
|
|
1337
1365
|
logger.error("*watchHash* cant parse hash");
|
|
1338
1366
|
}
|
|
1339
1367
|
if (typeof dataFromHash !== "object")
|
package/dist/index.d.cts
CHANGED
|
@@ -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, }: {
|
|
@@ -137,8 +137,8 @@ declare function useAsyncItems<T extends (...args: any[]) => any>({ apiMethod, q
|
|
|
137
137
|
isLoading: vue.Ref<boolean> | vue.Ref<true> | vue.Ref<false>;
|
|
138
138
|
isFetching: vue.Ref<boolean>;
|
|
139
139
|
isError: vue.Ref<true> | vue.Ref<false>;
|
|
140
|
-
data: vue.Ref<any>;
|
|
141
|
-
error: vue.Ref<Error>;
|
|
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;
|
|
@@ -246,7 +246,7 @@ type VersionsList = {
|
|
|
246
246
|
declare function useDetectBrowser(versions: VersionsList, userAgent?: any): BrowserInfo;
|
|
247
247
|
|
|
248
248
|
interface VNodeCustom$1 extends VNode {
|
|
249
|
-
close()
|
|
249
|
+
close: () => void;
|
|
250
250
|
}
|
|
251
251
|
declare function useDialog(): {
|
|
252
252
|
open: ({ layer, component, props, }: {
|
|
@@ -276,7 +276,7 @@ declare function useGlobalScroll(): {
|
|
|
276
276
|
unlock: () => void;
|
|
277
277
|
};
|
|
278
278
|
|
|
279
|
-
declare function useFilters<T extends Record<string, any>, K extends Record<string, any>>({ config, initialFilters
|
|
279
|
+
declare function useFilters<T extends Record<string, any>, K extends Record<string, any>>({ config, initialFilters }: {
|
|
280
280
|
config: T;
|
|
281
281
|
initialFilters: K;
|
|
282
282
|
}): {
|
|
@@ -306,7 +306,7 @@ interface Options {
|
|
|
306
306
|
declare function useLogger(scope: string, options?: Options): logdown.Logger;
|
|
307
307
|
|
|
308
308
|
interface VNodeCustom extends VNode {
|
|
309
|
-
close()
|
|
309
|
+
close: () => void;
|
|
310
310
|
}
|
|
311
311
|
/**
|
|
312
312
|
* @deprecated use useDialog
|
package/dist/index.d.mts
CHANGED
|
@@ -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, }: {
|
|
@@ -137,8 +137,8 @@ declare function useAsyncItems<T extends (...args: any[]) => any>({ apiMethod, q
|
|
|
137
137
|
isLoading: vue.Ref<boolean> | vue.Ref<true> | vue.Ref<false>;
|
|
138
138
|
isFetching: vue.Ref<boolean>;
|
|
139
139
|
isError: vue.Ref<true> | vue.Ref<false>;
|
|
140
|
-
data: vue.Ref<any>;
|
|
141
|
-
error: vue.Ref<Error>;
|
|
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;
|
|
@@ -246,7 +246,7 @@ type VersionsList = {
|
|
|
246
246
|
declare function useDetectBrowser(versions: VersionsList, userAgent?: any): BrowserInfo;
|
|
247
247
|
|
|
248
248
|
interface VNodeCustom$1 extends VNode {
|
|
249
|
-
close()
|
|
249
|
+
close: () => void;
|
|
250
250
|
}
|
|
251
251
|
declare function useDialog(): {
|
|
252
252
|
open: ({ layer, component, props, }: {
|
|
@@ -276,7 +276,7 @@ declare function useGlobalScroll(): {
|
|
|
276
276
|
unlock: () => void;
|
|
277
277
|
};
|
|
278
278
|
|
|
279
|
-
declare function useFilters<T extends Record<string, any>, K extends Record<string, any>>({ config, initialFilters
|
|
279
|
+
declare function useFilters<T extends Record<string, any>, K extends Record<string, any>>({ config, initialFilters }: {
|
|
280
280
|
config: T;
|
|
281
281
|
initialFilters: K;
|
|
282
282
|
}): {
|
|
@@ -306,7 +306,7 @@ interface Options {
|
|
|
306
306
|
declare function useLogger(scope: string, options?: Options): logdown.Logger;
|
|
307
307
|
|
|
308
308
|
interface VNodeCustom extends VNode {
|
|
309
|
-
close()
|
|
309
|
+
close: () => void;
|
|
310
310
|
}
|
|
311
311
|
/**
|
|
312
312
|
* @deprecated use useDialog
|
package/dist/index.d.ts
CHANGED
|
@@ -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, }: {
|
|
@@ -137,8 +137,8 @@ declare function useAsyncItems<T extends (...args: any[]) => any>({ apiMethod, q
|
|
|
137
137
|
isLoading: vue.Ref<boolean> | vue.Ref<true> | vue.Ref<false>;
|
|
138
138
|
isFetching: vue.Ref<boolean>;
|
|
139
139
|
isError: vue.Ref<true> | vue.Ref<false>;
|
|
140
|
-
data: vue.Ref<any>;
|
|
141
|
-
error: vue.Ref<Error>;
|
|
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;
|
|
@@ -246,7 +246,7 @@ type VersionsList = {
|
|
|
246
246
|
declare function useDetectBrowser(versions: VersionsList, userAgent?: any): BrowserInfo;
|
|
247
247
|
|
|
248
248
|
interface VNodeCustom$1 extends VNode {
|
|
249
|
-
close()
|
|
249
|
+
close: () => void;
|
|
250
250
|
}
|
|
251
251
|
declare function useDialog(): {
|
|
252
252
|
open: ({ layer, component, props, }: {
|
|
@@ -276,7 +276,7 @@ declare function useGlobalScroll(): {
|
|
|
276
276
|
unlock: () => void;
|
|
277
277
|
};
|
|
278
278
|
|
|
279
|
-
declare function useFilters<T extends Record<string, any>, K extends Record<string, any>>({ config, initialFilters
|
|
279
|
+
declare function useFilters<T extends Record<string, any>, K extends Record<string, any>>({ config, initialFilters }: {
|
|
280
280
|
config: T;
|
|
281
281
|
initialFilters: K;
|
|
282
282
|
}): {
|
|
@@ -306,7 +306,7 @@ interface Options {
|
|
|
306
306
|
declare function useLogger(scope: string, options?: Options): logdown.Logger;
|
|
307
307
|
|
|
308
308
|
interface VNodeCustom extends VNode {
|
|
309
|
-
close()
|
|
309
|
+
close: () => void;
|
|
310
310
|
}
|
|
311
311
|
/**
|
|
312
312
|
* @deprecated use useDialog
|
package/dist/index.mjs
CHANGED
|
@@ -24,8 +24,9 @@ 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
|
|
|
@@ -76,7 +77,7 @@ function formatMoney(value, currency = CURRENCY_DEFAULT, options = {}) {
|
|
|
76
77
|
...otherOptions
|
|
77
78
|
});
|
|
78
79
|
return formatter.format(convertedValue);
|
|
79
|
-
} catch (
|
|
80
|
+
} catch (_error) {
|
|
80
81
|
return defaultValue;
|
|
81
82
|
}
|
|
82
83
|
}
|
|
@@ -106,7 +107,7 @@ function genUUID() {
|
|
|
106
107
|
r = (d2 + r) % 16 | 0;
|
|
107
108
|
d2 = Math.floor(d2 / 16);
|
|
108
109
|
}
|
|
109
|
-
return (c
|
|
110
|
+
return (c === "x" ? r : r & 7 | 8).toString(16);
|
|
110
111
|
});
|
|
111
112
|
}
|
|
112
113
|
|
|
@@ -186,7 +187,9 @@ function getPaginationParams({
|
|
|
186
187
|
offset: validatedPage * validatedLimit - validatedLimit
|
|
187
188
|
};
|
|
188
189
|
}
|
|
189
|
-
function getPaginationLimit({
|
|
190
|
+
function getPaginationLimit({
|
|
191
|
+
limit
|
|
192
|
+
}) {
|
|
190
193
|
return validateNumber(limit, LIMIT_DEFAULT);
|
|
191
194
|
}
|
|
192
195
|
function getPaginationOffset({
|
|
@@ -208,8 +211,9 @@ function parsePhone(phone) {
|
|
|
208
211
|
if (!phone || typeof phone !== "string")
|
|
209
212
|
return "";
|
|
210
213
|
const replacedPhone = phone.replace(/[a-zA-Z]/g, "");
|
|
211
|
-
if (replacedPhone.length === 1 && replacedPhone !== "+")
|
|
214
|
+
if (replacedPhone.length === 1 && replacedPhone !== "+") {
|
|
212
215
|
return `+${replacedPhone}`;
|
|
216
|
+
}
|
|
213
217
|
const phoneNumber = parsePhoneNumberFromString(replacedPhone);
|
|
214
218
|
return phoneNumber ? phoneNumber.formatInternational() : replacedPhone;
|
|
215
219
|
}
|
|
@@ -257,8 +261,9 @@ function unformatNumber(value) {
|
|
|
257
261
|
if (commasCount === 1 && !hasSpace && !hasDot) {
|
|
258
262
|
locale = string.length - 1 - commaIndex === 3 ? LOCALE_EN : LOCALE_RU;
|
|
259
263
|
}
|
|
260
|
-
if (locale === LOCALE_RU)
|
|
264
|
+
if (locale === LOCALE_RU) {
|
|
261
265
|
return Number(string.replaceAll(" ", "").replace(",", "."));
|
|
266
|
+
}
|
|
262
267
|
if (locale === LOCALE_EN)
|
|
263
268
|
return Number(string.replaceAll(",", ""));
|
|
264
269
|
return value;
|
|
@@ -269,8 +274,9 @@ function UiComponentsResolver(options = {}) {
|
|
|
269
274
|
return (name) => {
|
|
270
275
|
const componentName = prefix && name.startsWith(prefix) ? name.substring(prefix.length) : name;
|
|
271
276
|
const isUiComponent = componentName.startsWith("Ui");
|
|
272
|
-
if (isUiComponent)
|
|
277
|
+
if (isUiComponent) {
|
|
273
278
|
return { name: componentName, from: "@karta.io/ui-components" };
|
|
279
|
+
}
|
|
274
280
|
};
|
|
275
281
|
}
|
|
276
282
|
|
|
@@ -318,7 +324,9 @@ function useAsyncItems({
|
|
|
318
324
|
queryKey: getQueryKey(),
|
|
319
325
|
queryFn: () => call(toValue(params), config)
|
|
320
326
|
});
|
|
321
|
-
const items = computed(
|
|
327
|
+
const items = computed(
|
|
328
|
+
() => data.value?.results || []
|
|
329
|
+
);
|
|
322
330
|
const count = ref(0);
|
|
323
331
|
watch(
|
|
324
332
|
data,
|
|
@@ -395,7 +403,12 @@ function useAsyncMultiselect({
|
|
|
395
403
|
color: "#b54708",
|
|
396
404
|
debug: true
|
|
397
405
|
});
|
|
398
|
-
const paramsForLogger = {
|
|
406
|
+
const paramsForLogger = {
|
|
407
|
+
queryKey,
|
|
408
|
+
dataItemsKey,
|
|
409
|
+
dataItemIdKey,
|
|
410
|
+
dataCountKey
|
|
411
|
+
};
|
|
399
412
|
const reactiveData = reactive({
|
|
400
413
|
search: "",
|
|
401
414
|
page: 1,
|
|
@@ -441,8 +454,9 @@ function useAsyncMultiselect({
|
|
|
441
454
|
);
|
|
442
455
|
return;
|
|
443
456
|
}
|
|
444
|
-
if (!get(newValue, dataItemsKey) || get(newValue, dataCountKey) === void 0)
|
|
457
|
+
if (!get(newValue, dataItemsKey) || get(newValue, dataCountKey) === void 0) {
|
|
445
458
|
return;
|
|
459
|
+
}
|
|
446
460
|
count.value = get(newValue, dataCountKey, 0);
|
|
447
461
|
const newItems = get(newValue, dataItemsKey);
|
|
448
462
|
itemsByPages.value = {
|
|
@@ -473,8 +487,9 @@ function useAsyncMultiselect({
|
|
|
473
487
|
const items = computed(() => {
|
|
474
488
|
if (!itemsByPages.value)
|
|
475
489
|
return selectedItemsCached.value;
|
|
476
|
-
if (!Object.keys(itemsByPages.value).length)
|
|
490
|
+
if (!Object.keys(itemsByPages.value).length) {
|
|
477
491
|
return selectedItemsCached.value;
|
|
492
|
+
}
|
|
478
493
|
const itemsByPagesAsArray = Object.values(itemsByPages.value).reduce(
|
|
479
494
|
(acc, item) => [...acc, ...item],
|
|
480
495
|
[]
|
|
@@ -581,7 +596,9 @@ function useAsyncSelect({
|
|
|
581
596
|
const loadWAC = () => call({
|
|
582
597
|
page: reactiveData.page,
|
|
583
598
|
search: reactiveData.search,
|
|
584
|
-
...reactiveData.selectedValue && {
|
|
599
|
+
...reactiveData.selectedValue && {
|
|
600
|
+
includedIds: [reactiveData.selectedValue]
|
|
601
|
+
},
|
|
585
602
|
...reactiveData.params && { ...JSON.parse(reactiveData.params) }
|
|
586
603
|
});
|
|
587
604
|
const { data, isFetching, isLoading } = useQuery({
|
|
@@ -609,8 +626,9 @@ function useAsyncSelect({
|
|
|
609
626
|
);
|
|
610
627
|
return;
|
|
611
628
|
}
|
|
612
|
-
if (!get(newValue, dataItemsKey) || get(newValue, dataCountKey) === void 0)
|
|
629
|
+
if (!get(newValue, dataItemsKey) || get(newValue, dataCountKey) === void 0) {
|
|
613
630
|
return;
|
|
631
|
+
}
|
|
614
632
|
count.value = get(newValue, dataCountKey, 0);
|
|
615
633
|
const newItems = get(newValue, dataItemsKey);
|
|
616
634
|
itemsByPages.value = {
|
|
@@ -758,7 +776,9 @@ function useDayjs(timezone) {
|
|
|
758
776
|
|
|
759
777
|
function parseVersion(version) {
|
|
760
778
|
if (typeof version !== "string" && typeof version !== "number") {
|
|
761
|
-
throw new TypeError(
|
|
779
|
+
throw new TypeError(
|
|
780
|
+
"Browser version must be type of string, number or negative boolean"
|
|
781
|
+
);
|
|
762
782
|
}
|
|
763
783
|
const [major, minor = 0, patch = 0, build = 0] = typeof version === "string" ? version.split(".").map(Number) : [version];
|
|
764
784
|
return {
|
|
@@ -838,7 +858,7 @@ function useDialog() {
|
|
|
838
858
|
let dataFromHash;
|
|
839
859
|
try {
|
|
840
860
|
dataFromHash = JSON.parse(window.atob(hash.slice(HASH_PREFIX.length)));
|
|
841
|
-
} catch (
|
|
861
|
+
} catch (_error) {
|
|
842
862
|
logger.warn("*parseHash* cant parse hash");
|
|
843
863
|
}
|
|
844
864
|
if (typeof dataFromHash !== "object")
|
|
@@ -1058,10 +1078,7 @@ const QS_STRINGIFY_PARAMS = {
|
|
|
1058
1078
|
addQueryPrefix: true
|
|
1059
1079
|
};
|
|
1060
1080
|
const isOpen = ref(false);
|
|
1061
|
-
function useFilters({
|
|
1062
|
-
config,
|
|
1063
|
-
initialFilters
|
|
1064
|
-
}) {
|
|
1081
|
+
function useFilters({ config, initialFilters }) {
|
|
1065
1082
|
const router = useRouter();
|
|
1066
1083
|
const route = useRoute();
|
|
1067
1084
|
const parseRouteQuery = (query) => qs.parse(query ?? route.query);
|
|
@@ -1069,35 +1086,43 @@ function useFilters({
|
|
|
1069
1086
|
const parsedRouteQuery = parseRouteQuery();
|
|
1070
1087
|
if (!parsedRouteQuery.filters)
|
|
1071
1088
|
return void 0;
|
|
1072
|
-
return Object.entries(config).reduce(
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
if (currentValue.type === "ARRAY" /* Array */) {
|
|
1076
|
-
const splitValues = parsedRouteQuery.filters[currentKey].split(",");
|
|
1077
|
-
const checkedValue = currentValue?.possibleValues ? splitValues.filter((k) => currentValue?.possibleValues?.includes(k)) : splitValues;
|
|
1078
|
-
if (!checkedValue?.length)
|
|
1089
|
+
return Object.entries(config).reduce(
|
|
1090
|
+
(accum, [currentKey, currentValue]) => {
|
|
1091
|
+
if (!parsedRouteQuery.filters[currentKey])
|
|
1079
1092
|
return accum;
|
|
1093
|
+
if (currentValue.type === "ARRAY" /* Array */) {
|
|
1094
|
+
const splitValues = parsedRouteQuery.filters[currentKey].split(",");
|
|
1095
|
+
const checkedValue = currentValue?.possibleValues ? splitValues.filter(
|
|
1096
|
+
(k) => currentValue?.possibleValues?.includes(k)
|
|
1097
|
+
) : splitValues;
|
|
1098
|
+
if (!checkedValue?.length)
|
|
1099
|
+
return accum;
|
|
1100
|
+
return {
|
|
1101
|
+
...accum,
|
|
1102
|
+
[currentKey]: checkedValue
|
|
1103
|
+
};
|
|
1104
|
+
}
|
|
1080
1105
|
return {
|
|
1081
1106
|
...accum,
|
|
1082
|
-
[currentKey]:
|
|
1107
|
+
[currentKey]: parsedRouteQuery.filters[currentKey]
|
|
1083
1108
|
};
|
|
1084
|
-
}
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
[currentKey]: parsedRouteQuery.filters[currentKey]
|
|
1088
|
-
};
|
|
1089
|
-
}, {});
|
|
1109
|
+
},
|
|
1110
|
+
{}
|
|
1111
|
+
);
|
|
1090
1112
|
});
|
|
1091
1113
|
const filtersCount = computed(
|
|
1092
1114
|
() => filtersFromQuery.value ? Object.keys(filtersFromQuery.value).length : 0
|
|
1093
1115
|
);
|
|
1094
1116
|
const setQueryFromFilters = (filters) => {
|
|
1095
1117
|
const parsedRouteQuery = parseRouteQuery();
|
|
1096
|
-
const filteredValue = Object.entries(filters).reduce(
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1118
|
+
const filteredValue = Object.entries(filters).reduce(
|
|
1119
|
+
(accum, [currentKey, currentValue]) => {
|
|
1120
|
+
if (!currentValue?.length)
|
|
1121
|
+
return accum;
|
|
1122
|
+
return { ...accum, [currentKey]: currentValue };
|
|
1123
|
+
},
|
|
1124
|
+
{}
|
|
1125
|
+
);
|
|
1101
1126
|
const query = qs.stringify(
|
|
1102
1127
|
{
|
|
1103
1128
|
...parsedRouteQuery,
|
|
@@ -1134,12 +1159,15 @@ function useFilters({
|
|
|
1134
1159
|
});
|
|
1135
1160
|
};
|
|
1136
1161
|
const updateMany = (filters) => {
|
|
1137
|
-
const newFilters = Object.entries(filters).reduce(
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1162
|
+
const newFilters = Object.entries(filters).reduce(
|
|
1163
|
+
(accum, [currentKey, currentValue]) => {
|
|
1164
|
+
return {
|
|
1165
|
+
...accum,
|
|
1166
|
+
[currentKey]: currentValue ? String(currentValue) : void 0
|
|
1167
|
+
};
|
|
1168
|
+
},
|
|
1169
|
+
{}
|
|
1170
|
+
);
|
|
1143
1171
|
setQueryFromFilters({
|
|
1144
1172
|
...filtersModel.value,
|
|
1145
1173
|
...newFilters
|
|
@@ -1315,7 +1343,7 @@ function usePanel() {
|
|
|
1315
1343
|
let dataFromHash;
|
|
1316
1344
|
try {
|
|
1317
1345
|
dataFromHash = JSON.parse(window.atob(newHash.slice(1)));
|
|
1318
|
-
} catch (
|
|
1346
|
+
} catch (_error) {
|
|
1319
1347
|
logger.error("*watchHash* cant parse hash");
|
|
1320
1348
|
}
|
|
1321
1349
|
if (typeof dataFromHash !== "object")
|
package/package.json
CHANGED
|
@@ -1,31 +1,31 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@karta.io/utils",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.16",
|
|
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
|
-
"import": "./dist/index.mjs"
|
|
14
|
-
"types": "./dist/index.d.ts"
|
|
19
|
+
"import": "./dist/index.mjs"
|
|
15
20
|
},
|
|
16
21
|
"./*": "./*"
|
|
17
22
|
},
|
|
18
|
-
"
|
|
19
|
-
"module": "./dist/index.mjs",
|
|
20
|
-
"types": "./dist/index.d.ts",
|
|
21
|
-
"files": [
|
|
22
|
-
"dist"
|
|
23
|
-
],
|
|
23
|
+
"sideEffects": false,
|
|
24
24
|
"peerDependencies": {
|
|
25
25
|
"vue": "3.x"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@karta.io/common-data": "^1.0.0-beta.
|
|
28
|
+
"@karta.io/common-data": "^1.0.0-beta.16",
|
|
29
29
|
"@tanstack/vue-query": "5.x",
|
|
30
30
|
"@vueuse/core": "10.9.0",
|
|
31
31
|
"async-validator": "4.2.5",
|
|
@@ -39,24 +39,22 @@
|
|
|
39
39
|
"vue-router": "4.x"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"@
|
|
42
|
+
"@karta.io/eslint-config": "1.1.0",
|
|
43
|
+
"@karta.io/prettier-config": "1.0.0",
|
|
43
44
|
"@types/lodash": "4.17.0",
|
|
44
|
-
"
|
|
45
|
-
"@typescript-eslint/parser": "6.20.0",
|
|
46
|
-
"eslint": "8.56.0",
|
|
47
|
-
"eslint-config-airbnb-base": "15.0.0",
|
|
48
|
-
"eslint-plugin-import": "2.29.1",
|
|
45
|
+
"eslint": "9.1.1",
|
|
49
46
|
"prettier": "3.2.5",
|
|
50
|
-
"typescript": "5.4.
|
|
47
|
+
"typescript": "5.4.5",
|
|
51
48
|
"unbuild": "2.0.0",
|
|
52
49
|
"vitest": "1.2.2",
|
|
53
50
|
"vue": "3.4.21"
|
|
54
51
|
},
|
|
52
|
+
"prettier": "@karta.io/prettier-config",
|
|
55
53
|
"scripts": {
|
|
56
54
|
"dev": "vitest",
|
|
57
55
|
"build": "unbuild",
|
|
58
|
-
"lint": "eslint
|
|
59
|
-
"lint:fix": "eslint --fix
|
|
56
|
+
"lint": "eslint .",
|
|
57
|
+
"lint:fix": "eslint . --fix",
|
|
60
58
|
"test": "pnpm lint && vitest run",
|
|
61
59
|
"prettier": "prettier --check --ignore-unknown \"**/*\"",
|
|
62
60
|
"prettier:fix": "prettier --write --ignore-unknown \"**/*\"",
|