@karta.io/utils 1.0.0-beta.2 → 1.0.0-beta.20
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.cjs
CHANGED
|
@@ -42,14 +42,16 @@ 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
|
|
|
50
51
|
function camelizeKeys(object) {
|
|
51
|
-
if (Array.isArray(object))
|
|
52
|
+
if (Array.isArray(object)) {
|
|
52
53
|
return object.map((v) => camelizeKeys(v));
|
|
54
|
+
}
|
|
53
55
|
if (object !== null && object.constructor === Object) {
|
|
54
56
|
return Object.keys(object).reduce(
|
|
55
57
|
(result, key) => ({
|
|
@@ -93,7 +95,7 @@ function formatMoney(value, currency = commonData.CURRENCY_DEFAULT, options = {}
|
|
|
93
95
|
...otherOptions
|
|
94
96
|
});
|
|
95
97
|
return formatter.format(convertedValue);
|
|
96
|
-
} catch (
|
|
98
|
+
} catch (_error) {
|
|
97
99
|
return defaultValue;
|
|
98
100
|
}
|
|
99
101
|
}
|
|
@@ -123,7 +125,7 @@ function genUUID() {
|
|
|
123
125
|
r = (d2 + r) % 16 | 0;
|
|
124
126
|
d2 = Math.floor(d2 / 16);
|
|
125
127
|
}
|
|
126
|
-
return (c
|
|
128
|
+
return (c === "x" ? r : r & 7 | 8).toString(16);
|
|
127
129
|
});
|
|
128
130
|
}
|
|
129
131
|
|
|
@@ -203,7 +205,9 @@ function getPaginationParams({
|
|
|
203
205
|
offset: validatedPage * validatedLimit - validatedLimit
|
|
204
206
|
};
|
|
205
207
|
}
|
|
206
|
-
function getPaginationLimit({
|
|
208
|
+
function getPaginationLimit({
|
|
209
|
+
limit
|
|
210
|
+
}) {
|
|
207
211
|
return validateNumber(limit, LIMIT_DEFAULT);
|
|
208
212
|
}
|
|
209
213
|
function getPaginationOffset({
|
|
@@ -225,15 +229,17 @@ function parsePhone(phone) {
|
|
|
225
229
|
if (!phone || typeof phone !== "string")
|
|
226
230
|
return "";
|
|
227
231
|
const replacedPhone = phone.replace(/[a-zA-Z]/g, "");
|
|
228
|
-
if (replacedPhone.length === 1 && replacedPhone !== "+")
|
|
232
|
+
if (replacedPhone.length === 1 && replacedPhone !== "+") {
|
|
229
233
|
return `+${replacedPhone}`;
|
|
234
|
+
}
|
|
230
235
|
const phoneNumber = libphonenumberJs.parsePhoneNumberFromString(replacedPhone);
|
|
231
236
|
return phoneNumber ? phoneNumber.formatInternational() : replacedPhone;
|
|
232
237
|
}
|
|
233
238
|
|
|
234
239
|
function snakelizeKeys(prop) {
|
|
235
|
-
if (Array.isArray(prop))
|
|
240
|
+
if (Array.isArray(prop)) {
|
|
236
241
|
return prop.map((item) => snakelizeKeys(item));
|
|
242
|
+
}
|
|
237
243
|
if (prop !== null && prop !== void 0 && prop.constructor === Object) {
|
|
238
244
|
return Object.keys(prop).reduce(
|
|
239
245
|
(accum, current) => ({
|
|
@@ -273,8 +279,9 @@ function unformatNumber(value) {
|
|
|
273
279
|
if (commasCount === 1 && !hasSpace && !hasDot) {
|
|
274
280
|
locale = string.length - 1 - commaIndex === 3 ? LOCALE_EN : LOCALE_RU;
|
|
275
281
|
}
|
|
276
|
-
if (locale === LOCALE_RU)
|
|
282
|
+
if (locale === LOCALE_RU) {
|
|
277
283
|
return Number(string.replaceAll(" ", "").replace(",", "."));
|
|
284
|
+
}
|
|
278
285
|
if (locale === LOCALE_EN)
|
|
279
286
|
return Number(string.replaceAll(",", ""));
|
|
280
287
|
return value;
|
|
@@ -285,8 +292,9 @@ function UiComponentsResolver(options = {}) {
|
|
|
285
292
|
return (name) => {
|
|
286
293
|
const componentName = prefix && name.startsWith(prefix) ? name.substring(prefix.length) : name;
|
|
287
294
|
const isUiComponent = componentName.startsWith("Ui");
|
|
288
|
-
if (isUiComponent)
|
|
295
|
+
if (isUiComponent) {
|
|
289
296
|
return { name: componentName, from: "@karta.io/ui-components" };
|
|
297
|
+
}
|
|
290
298
|
};
|
|
291
299
|
}
|
|
292
300
|
|
|
@@ -334,7 +342,9 @@ function useAsyncItems({
|
|
|
334
342
|
queryKey: getQueryKey(),
|
|
335
343
|
queryFn: () => call(core.toValue(params), config)
|
|
336
344
|
});
|
|
337
|
-
const items = vue.computed(
|
|
345
|
+
const items = vue.computed(
|
|
346
|
+
() => data.value?.results || []
|
|
347
|
+
);
|
|
338
348
|
const count = vue.ref(0);
|
|
339
349
|
vue.watch(
|
|
340
350
|
data,
|
|
@@ -411,7 +421,12 @@ function useAsyncMultiselect({
|
|
|
411
421
|
color: "#b54708",
|
|
412
422
|
debug: true
|
|
413
423
|
});
|
|
414
|
-
const paramsForLogger = {
|
|
424
|
+
const paramsForLogger = {
|
|
425
|
+
queryKey,
|
|
426
|
+
dataItemsKey,
|
|
427
|
+
dataItemIdKey,
|
|
428
|
+
dataCountKey
|
|
429
|
+
};
|
|
415
430
|
const reactiveData = vue.reactive({
|
|
416
431
|
search: "",
|
|
417
432
|
page: 1,
|
|
@@ -457,8 +472,9 @@ function useAsyncMultiselect({
|
|
|
457
472
|
);
|
|
458
473
|
return;
|
|
459
474
|
}
|
|
460
|
-
if (!get__default(newValue, dataItemsKey) || get__default(newValue, dataCountKey) === void 0)
|
|
475
|
+
if (!get__default(newValue, dataItemsKey) || get__default(newValue, dataCountKey) === void 0) {
|
|
461
476
|
return;
|
|
477
|
+
}
|
|
462
478
|
count.value = get__default(newValue, dataCountKey, 0);
|
|
463
479
|
const newItems = get__default(newValue, dataItemsKey);
|
|
464
480
|
itemsByPages.value = {
|
|
@@ -489,8 +505,9 @@ function useAsyncMultiselect({
|
|
|
489
505
|
const items = vue.computed(() => {
|
|
490
506
|
if (!itemsByPages.value)
|
|
491
507
|
return selectedItemsCached.value;
|
|
492
|
-
if (!Object.keys(itemsByPages.value).length)
|
|
508
|
+
if (!Object.keys(itemsByPages.value).length) {
|
|
493
509
|
return selectedItemsCached.value;
|
|
510
|
+
}
|
|
494
511
|
const itemsByPagesAsArray = Object.values(itemsByPages.value).reduce(
|
|
495
512
|
(acc, item) => [...acc, ...item],
|
|
496
513
|
[]
|
|
@@ -506,7 +523,7 @@ function useAsyncMultiselect({
|
|
|
506
523
|
if (!items.value.length)
|
|
507
524
|
return [];
|
|
508
525
|
if (!mapOptionCallback)
|
|
509
|
-
return
|
|
526
|
+
return items.value;
|
|
510
527
|
return items.value.map(mapOptionCallback);
|
|
511
528
|
});
|
|
512
529
|
const hasNextPage = vue.computed(() => count.value > items.value.length);
|
|
@@ -525,6 +542,28 @@ function useAsyncMultiselect({
|
|
|
525
542
|
search.value = value;
|
|
526
543
|
updateSearchWithDebounce(value);
|
|
527
544
|
};
|
|
545
|
+
const queryClient = vueQuery.useQueryClient();
|
|
546
|
+
const refetch = () => {
|
|
547
|
+
if (reactiveData.page !== 1) {
|
|
548
|
+
queryClient.invalidateQueries({
|
|
549
|
+
queryKey: [queryKey],
|
|
550
|
+
refetchType: "none"
|
|
551
|
+
});
|
|
552
|
+
loadPage(1);
|
|
553
|
+
} else {
|
|
554
|
+
queryClient.invalidateQueries({
|
|
555
|
+
queryKey: [queryKey]
|
|
556
|
+
});
|
|
557
|
+
}
|
|
558
|
+
};
|
|
559
|
+
const reload = () => {
|
|
560
|
+
if (reactiveData.page !== 1) {
|
|
561
|
+
queryClient.removeQueries({ queryKey: [queryKey] });
|
|
562
|
+
loadPage(1);
|
|
563
|
+
} else {
|
|
564
|
+
queryClient.resetQueries({ queryKey: [queryKey] });
|
|
565
|
+
}
|
|
566
|
+
};
|
|
528
567
|
if (vue.isRef(selectedValues)) {
|
|
529
568
|
vue.watch(selectedValues, async (newSelectedValues) => {
|
|
530
569
|
if (!newSelectedValues.length) {
|
|
@@ -565,7 +604,9 @@ function useAsyncMultiselect({
|
|
|
565
604
|
isFetching,
|
|
566
605
|
isLoading,
|
|
567
606
|
loadPage,
|
|
568
|
-
updateSearch
|
|
607
|
+
updateSearch,
|
|
608
|
+
refetch,
|
|
609
|
+
reload
|
|
569
610
|
};
|
|
570
611
|
}
|
|
571
612
|
|
|
@@ -597,7 +638,9 @@ function useAsyncSelect({
|
|
|
597
638
|
const loadWAC = () => call({
|
|
598
639
|
page: reactiveData.page,
|
|
599
640
|
search: reactiveData.search,
|
|
600
|
-
...reactiveData.selectedValue && {
|
|
641
|
+
...reactiveData.selectedValue && {
|
|
642
|
+
includedIds: [reactiveData.selectedValue]
|
|
643
|
+
},
|
|
601
644
|
...reactiveData.params && { ...JSON.parse(reactiveData.params) }
|
|
602
645
|
});
|
|
603
646
|
const { data, isFetching, isLoading } = vueQuery.useQuery({
|
|
@@ -625,8 +668,9 @@ function useAsyncSelect({
|
|
|
625
668
|
);
|
|
626
669
|
return;
|
|
627
670
|
}
|
|
628
|
-
if (!get__default(newValue, dataItemsKey) || get__default(newValue, dataCountKey) === void 0)
|
|
671
|
+
if (!get__default(newValue, dataItemsKey) || get__default(newValue, dataCountKey) === void 0) {
|
|
629
672
|
return;
|
|
673
|
+
}
|
|
630
674
|
count.value = get__default(newValue, dataCountKey, 0);
|
|
631
675
|
const newItems = get__default(newValue, dataItemsKey);
|
|
632
676
|
itemsByPages.value = {
|
|
@@ -656,7 +700,7 @@ function useAsyncSelect({
|
|
|
656
700
|
if (!items.value.length)
|
|
657
701
|
return [];
|
|
658
702
|
if (!mapOptionCallback)
|
|
659
|
-
return
|
|
703
|
+
return items.value;
|
|
660
704
|
return items.value.map(mapOptionCallback);
|
|
661
705
|
});
|
|
662
706
|
const hasNextPage = vue.computed(() => count.value > items.value.length);
|
|
@@ -671,6 +715,28 @@ function useAsyncSelect({
|
|
|
671
715
|
search.value = value;
|
|
672
716
|
updateSearchWithDebounce(value);
|
|
673
717
|
};
|
|
718
|
+
const queryClient = vueQuery.useQueryClient();
|
|
719
|
+
const refetch = () => {
|
|
720
|
+
if (reactiveData.page !== 1) {
|
|
721
|
+
queryClient.invalidateQueries({
|
|
722
|
+
queryKey: [queryKey],
|
|
723
|
+
refetchType: "none"
|
|
724
|
+
});
|
|
725
|
+
loadPage(1);
|
|
726
|
+
} else {
|
|
727
|
+
queryClient.invalidateQueries({
|
|
728
|
+
queryKey: [queryKey]
|
|
729
|
+
});
|
|
730
|
+
}
|
|
731
|
+
};
|
|
732
|
+
const reload = () => {
|
|
733
|
+
if (reactiveData.page !== 1) {
|
|
734
|
+
queryClient.removeQueries({ queryKey: [queryKey] });
|
|
735
|
+
loadPage(1);
|
|
736
|
+
} else {
|
|
737
|
+
queryClient.resetQueries({ queryKey: [queryKey] });
|
|
738
|
+
}
|
|
739
|
+
};
|
|
674
740
|
if (vue.isRef(selectedValue)) {
|
|
675
741
|
vue.watch(selectedValue, (newSelectedValue) => {
|
|
676
742
|
reactiveData.page = 1;
|
|
@@ -694,7 +760,9 @@ function useAsyncSelect({
|
|
|
694
760
|
isFetching,
|
|
695
761
|
isLoading,
|
|
696
762
|
loadPage,
|
|
697
|
-
updateSearch
|
|
763
|
+
updateSearch,
|
|
764
|
+
refetch,
|
|
765
|
+
reload
|
|
698
766
|
};
|
|
699
767
|
}
|
|
700
768
|
|
|
@@ -774,7 +842,9 @@ function useDayjs(timezone) {
|
|
|
774
842
|
|
|
775
843
|
function parseVersion(version) {
|
|
776
844
|
if (typeof version !== "string" && typeof version !== "number") {
|
|
777
|
-
throw new TypeError(
|
|
845
|
+
throw new TypeError(
|
|
846
|
+
"Browser version must be type of string, number or negative boolean"
|
|
847
|
+
);
|
|
778
848
|
}
|
|
779
849
|
const [major, minor = 0, patch = 0, build = 0] = typeof version === "string" ? version.split(".").map(Number) : [version];
|
|
780
850
|
return {
|
|
@@ -854,7 +924,7 @@ function useDialog() {
|
|
|
854
924
|
let dataFromHash;
|
|
855
925
|
try {
|
|
856
926
|
dataFromHash = JSON.parse(window.atob(hash.slice(HASH_PREFIX.length)));
|
|
857
|
-
} catch (
|
|
927
|
+
} catch (_error) {
|
|
858
928
|
logger.warn("*parseHash* cant parse hash");
|
|
859
929
|
}
|
|
860
930
|
if (typeof dataFromHash !== "object")
|
|
@@ -1074,10 +1144,7 @@ const QS_STRINGIFY_PARAMS = {
|
|
|
1074
1144
|
addQueryPrefix: true
|
|
1075
1145
|
};
|
|
1076
1146
|
const isOpen = vue.ref(false);
|
|
1077
|
-
function useFilters({
|
|
1078
|
-
config,
|
|
1079
|
-
initialFilters
|
|
1080
|
-
}) {
|
|
1147
|
+
function useFilters({ config, initialFilters }) {
|
|
1081
1148
|
const router = vueRouter.useRouter();
|
|
1082
1149
|
const route = vueRouter.useRoute();
|
|
1083
1150
|
const parseRouteQuery = (query) => qs__default.parse(query ?? route.query);
|
|
@@ -1085,35 +1152,43 @@ function useFilters({
|
|
|
1085
1152
|
const parsedRouteQuery = parseRouteQuery();
|
|
1086
1153
|
if (!parsedRouteQuery.filters)
|
|
1087
1154
|
return void 0;
|
|
1088
|
-
return Object.entries(config).reduce(
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
if (currentValue.type === "ARRAY" /* Array */) {
|
|
1092
|
-
const splitValues = parsedRouteQuery.filters[currentKey].split(",");
|
|
1093
|
-
const checkedValue = currentValue?.possibleValues ? splitValues.filter((k) => currentValue?.possibleValues?.includes(k)) : splitValues;
|
|
1094
|
-
if (!checkedValue?.length)
|
|
1155
|
+
return Object.entries(config).reduce(
|
|
1156
|
+
(accum, [currentKey, currentValue]) => {
|
|
1157
|
+
if (!parsedRouteQuery.filters[currentKey])
|
|
1095
1158
|
return accum;
|
|
1159
|
+
if (currentValue.type === "ARRAY" /* Array */) {
|
|
1160
|
+
const splitValues = parsedRouteQuery.filters[currentKey].split(",");
|
|
1161
|
+
const checkedValue = currentValue?.possibleValues ? splitValues.filter(
|
|
1162
|
+
(k) => currentValue?.possibleValues?.includes(k)
|
|
1163
|
+
) : splitValues;
|
|
1164
|
+
if (!checkedValue?.length)
|
|
1165
|
+
return accum;
|
|
1166
|
+
return {
|
|
1167
|
+
...accum,
|
|
1168
|
+
[currentKey]: checkedValue
|
|
1169
|
+
};
|
|
1170
|
+
}
|
|
1096
1171
|
return {
|
|
1097
1172
|
...accum,
|
|
1098
|
-
[currentKey]:
|
|
1173
|
+
[currentKey]: parsedRouteQuery.filters[currentKey]
|
|
1099
1174
|
};
|
|
1100
|
-
}
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
[currentKey]: parsedRouteQuery.filters[currentKey]
|
|
1104
|
-
};
|
|
1105
|
-
}, {});
|
|
1175
|
+
},
|
|
1176
|
+
{}
|
|
1177
|
+
);
|
|
1106
1178
|
});
|
|
1107
1179
|
const filtersCount = vue.computed(
|
|
1108
1180
|
() => filtersFromQuery.value ? Object.keys(filtersFromQuery.value).length : 0
|
|
1109
1181
|
);
|
|
1110
1182
|
const setQueryFromFilters = (filters) => {
|
|
1111
1183
|
const parsedRouteQuery = parseRouteQuery();
|
|
1112
|
-
const filteredValue = Object.entries(filters).reduce(
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1184
|
+
const filteredValue = Object.entries(filters).reduce(
|
|
1185
|
+
(accum, [currentKey, currentValue]) => {
|
|
1186
|
+
if (!currentValue?.length)
|
|
1187
|
+
return accum;
|
|
1188
|
+
return { ...accum, [currentKey]: currentValue };
|
|
1189
|
+
},
|
|
1190
|
+
{}
|
|
1191
|
+
);
|
|
1117
1192
|
const query = qs__default.stringify(
|
|
1118
1193
|
{
|
|
1119
1194
|
...parsedRouteQuery,
|
|
@@ -1150,12 +1225,15 @@ function useFilters({
|
|
|
1150
1225
|
});
|
|
1151
1226
|
};
|
|
1152
1227
|
const updateMany = (filters) => {
|
|
1153
|
-
const newFilters = Object.entries(filters).reduce(
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1228
|
+
const newFilters = Object.entries(filters).reduce(
|
|
1229
|
+
(accum, [currentKey, currentValue]) => {
|
|
1230
|
+
return {
|
|
1231
|
+
...accum,
|
|
1232
|
+
[currentKey]: currentValue ? String(currentValue) : void 0
|
|
1233
|
+
};
|
|
1234
|
+
},
|
|
1235
|
+
{}
|
|
1236
|
+
);
|
|
1159
1237
|
setQueryFromFilters({
|
|
1160
1238
|
...filtersModel.value,
|
|
1161
1239
|
...newFilters
|
|
@@ -1331,7 +1409,7 @@ function usePanel() {
|
|
|
1331
1409
|
let dataFromHash;
|
|
1332
1410
|
try {
|
|
1333
1411
|
dataFromHash = JSON.parse(window.atob(newHash.slice(1)));
|
|
1334
|
-
} catch (
|
|
1412
|
+
} catch (_error) {
|
|
1335
1413
|
logger.error("*watchHash* cant parse hash");
|
|
1336
1414
|
}
|
|
1337
1415
|
if (typeof dataFromHash !== "object")
|