@karta.io/utils 1.0.0-beta.39 → 1.0.0-beta.4
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 +72 -286
- package/dist/index.d.ts +13 -56
- package/dist/index.mjs +73 -281
- package/package.json +34 -33
- package/dist/index.d.cts +0 -393
- package/dist/index.d.mts +0 -393
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import camelCase from 'lodash/camelCase.js';
|
|
2
|
-
import flatMap from 'lodash/flatMap.js';
|
|
3
2
|
import { CURRENCY_DEFAULT, BREAKPOINTS } from '@karta.io/common-data';
|
|
4
3
|
import { parsePhoneNumberFromString } from 'libphonenumber-js';
|
|
5
4
|
import snakeCase from 'lodash/snakeCase.js';
|
|
@@ -25,16 +24,14 @@ function AppComponentsResolver(options = {}) {
|
|
|
25
24
|
return (name) => {
|
|
26
25
|
const componentName = prefix && name.startsWith(prefix) ? name.substring(prefix.length) : name;
|
|
27
26
|
const isAppComponent = componentName.startsWith("App");
|
|
28
|
-
if (isAppComponent)
|
|
27
|
+
if (isAppComponent)
|
|
29
28
|
return { name: componentName, from: "@karta.io/app-components" };
|
|
30
|
-
}
|
|
31
29
|
};
|
|
32
30
|
}
|
|
33
31
|
|
|
34
32
|
function camelizeKeys(object) {
|
|
35
|
-
if (Array.isArray(object))
|
|
33
|
+
if (Array.isArray(object))
|
|
36
34
|
return object.map((v) => camelizeKeys(v));
|
|
37
|
-
}
|
|
38
35
|
if (object !== null && object.constructor === Object) {
|
|
39
36
|
return Object.keys(object).reduce(
|
|
40
37
|
(result, key) => ({
|
|
@@ -61,109 +58,6 @@ function convertEnumToOptions(obj, options) {
|
|
|
61
58
|
}));
|
|
62
59
|
}
|
|
63
60
|
|
|
64
|
-
class EnrichError extends Error {
|
|
65
|
-
constructor(data) {
|
|
66
|
-
super(data.message);
|
|
67
|
-
Object.assign(this, data);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
function isHtml(data) {
|
|
72
|
-
try {
|
|
73
|
-
if (typeof DOMParser !== "undefined") {
|
|
74
|
-
const parser = new DOMParser();
|
|
75
|
-
const doc = parser.parseFromString(data, "text/html");
|
|
76
|
-
return Array.from(doc.body.childNodes).some(
|
|
77
|
-
(node) => node.nodeType === Node.ELEMENT_NODE
|
|
78
|
-
);
|
|
79
|
-
}
|
|
80
|
-
const htmlPattern = /<\/?[a-z][\s\S]*>/i;
|
|
81
|
-
return htmlPattern.test(data);
|
|
82
|
-
} catch (_) {
|
|
83
|
-
return false;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
function getStatusMessage(status) {
|
|
88
|
-
let message = "";
|
|
89
|
-
switch (status) {
|
|
90
|
-
case 200:
|
|
91
|
-
message = "All done. Request successfully executed";
|
|
92
|
-
break;
|
|
93
|
-
case 201:
|
|
94
|
-
message = "Data successfully created";
|
|
95
|
-
break;
|
|
96
|
-
case 400:
|
|
97
|
-
message = "Bad request";
|
|
98
|
-
break;
|
|
99
|
-
case 401:
|
|
100
|
-
message = "Need auth";
|
|
101
|
-
break;
|
|
102
|
-
case 404:
|
|
103
|
-
message = "Not found";
|
|
104
|
-
break;
|
|
105
|
-
case 500:
|
|
106
|
-
message = "Something wrong. Internal server error";
|
|
107
|
-
break;
|
|
108
|
-
case 501:
|
|
109
|
-
message = "501: Not implemented";
|
|
110
|
-
break;
|
|
111
|
-
case 502:
|
|
112
|
-
message = "502: Bad gateway";
|
|
113
|
-
break;
|
|
114
|
-
case 503:
|
|
115
|
-
message = "Service unavailable. Try again later";
|
|
116
|
-
break;
|
|
117
|
-
default:
|
|
118
|
-
message = "Something wrong. Client default error message";
|
|
119
|
-
break;
|
|
120
|
-
}
|
|
121
|
-
return message;
|
|
122
|
-
}
|
|
123
|
-
function formatErrorDataMessage(data) {
|
|
124
|
-
if (!data)
|
|
125
|
-
return "";
|
|
126
|
-
return Object.values(data).reduce((accum, current) => {
|
|
127
|
-
if (current && typeof current === "string")
|
|
128
|
-
return accum ? `${accum} | ${current}` : current;
|
|
129
|
-
if (Array.isArray(current) && current.length) {
|
|
130
|
-
const value = `${flatMap(current).join(" | ")}`;
|
|
131
|
-
return accum ? `${accum} | ${value}` : value;
|
|
132
|
-
}
|
|
133
|
-
return accum;
|
|
134
|
-
}, "");
|
|
135
|
-
}
|
|
136
|
-
function formatErrorForNotify(error) {
|
|
137
|
-
if (!error)
|
|
138
|
-
return;
|
|
139
|
-
if (error.status >= 400 && error.status < 500) {
|
|
140
|
-
let message = "";
|
|
141
|
-
if (!error.data || typeof error.data === "string" && isHtml(error.data)) {
|
|
142
|
-
message = error.statusMessage || error.message || getStatusMessage(error.status);
|
|
143
|
-
} else if (typeof error.data === "string" && !isHtml(error.data)) {
|
|
144
|
-
message = error.data;
|
|
145
|
-
} else {
|
|
146
|
-
message = formatErrorDataMessage(error.data);
|
|
147
|
-
}
|
|
148
|
-
return {
|
|
149
|
-
title: "Request error",
|
|
150
|
-
message
|
|
151
|
-
};
|
|
152
|
-
}
|
|
153
|
-
if (error.status >= 500) {
|
|
154
|
-
return {
|
|
155
|
-
title: "Internal server error",
|
|
156
|
-
message: error.statusMessage || error.message || getStatusMessage(error.status)
|
|
157
|
-
};
|
|
158
|
-
}
|
|
159
|
-
if (error instanceof Error) {
|
|
160
|
-
return {
|
|
161
|
-
title: "Internal client error",
|
|
162
|
-
message: error.message
|
|
163
|
-
};
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
|
|
167
61
|
function formatMoney(value, currency = CURRENCY_DEFAULT, options = {}) {
|
|
168
62
|
const { locale = "en-US", defaultValue = 0, ...otherOptions } = options;
|
|
169
63
|
try {
|
|
@@ -181,7 +75,7 @@ function formatMoney(value, currency = CURRENCY_DEFAULT, options = {}) {
|
|
|
181
75
|
...otherOptions
|
|
182
76
|
});
|
|
183
77
|
return formatter.format(convertedValue);
|
|
184
|
-
} catch (
|
|
78
|
+
} catch (error) {
|
|
185
79
|
return defaultValue;
|
|
186
80
|
}
|
|
187
81
|
}
|
|
@@ -211,7 +105,7 @@ function genUUID() {
|
|
|
211
105
|
r = (d2 + r) % 16 | 0;
|
|
212
106
|
d2 = Math.floor(d2 / 16);
|
|
213
107
|
}
|
|
214
|
-
return (c
|
|
108
|
+
return (c == "x" ? r : r & 7 | 8).toString(16);
|
|
215
109
|
});
|
|
216
110
|
}
|
|
217
111
|
|
|
@@ -291,9 +185,7 @@ function getPaginationParams({
|
|
|
291
185
|
offset: validatedPage * validatedLimit - validatedLimit
|
|
292
186
|
};
|
|
293
187
|
}
|
|
294
|
-
function getPaginationLimit({
|
|
295
|
-
limit
|
|
296
|
-
}) {
|
|
188
|
+
function getPaginationLimit({ limit }) {
|
|
297
189
|
return validateNumber(limit, LIMIT_DEFAULT);
|
|
298
190
|
}
|
|
299
191
|
function getPaginationOffset({
|
|
@@ -315,17 +207,15 @@ function parsePhone(phone) {
|
|
|
315
207
|
if (!phone || typeof phone !== "string")
|
|
316
208
|
return "";
|
|
317
209
|
const replacedPhone = phone.replace(/[a-zA-Z]/g, "");
|
|
318
|
-
if (replacedPhone.length === 1 && replacedPhone !== "+")
|
|
210
|
+
if (replacedPhone.length === 1 && replacedPhone !== "+")
|
|
319
211
|
return `+${replacedPhone}`;
|
|
320
|
-
}
|
|
321
212
|
const phoneNumber = parsePhoneNumberFromString(replacedPhone);
|
|
322
213
|
return phoneNumber ? phoneNumber.formatInternational() : replacedPhone;
|
|
323
214
|
}
|
|
324
215
|
|
|
325
216
|
function snakelizeKeys(prop) {
|
|
326
|
-
if (Array.isArray(prop))
|
|
217
|
+
if (Array.isArray(prop))
|
|
327
218
|
return prop.map((item) => snakelizeKeys(item));
|
|
328
|
-
}
|
|
329
219
|
if (prop !== null && prop !== void 0 && prop.constructor === Object) {
|
|
330
220
|
return Object.keys(prop).reduce(
|
|
331
221
|
(accum, current) => ({
|
|
@@ -365,9 +255,8 @@ function unformatNumber(value) {
|
|
|
365
255
|
if (commasCount === 1 && !hasSpace && !hasDot) {
|
|
366
256
|
locale = string.length - 1 - commaIndex === 3 ? LOCALE_EN : LOCALE_RU;
|
|
367
257
|
}
|
|
368
|
-
if (locale === LOCALE_RU)
|
|
258
|
+
if (locale === LOCALE_RU)
|
|
369
259
|
return Number(string.replaceAll(" ", "").replace(",", "."));
|
|
370
|
-
}
|
|
371
260
|
if (locale === LOCALE_EN)
|
|
372
261
|
return Number(string.replaceAll(",", ""));
|
|
373
262
|
return value;
|
|
@@ -378,9 +267,8 @@ function UiComponentsResolver(options = {}) {
|
|
|
378
267
|
return (name) => {
|
|
379
268
|
const componentName = prefix && name.startsWith(prefix) ? name.substring(prefix.length) : name;
|
|
380
269
|
const isUiComponent = componentName.startsWith("Ui");
|
|
381
|
-
if (isUiComponent)
|
|
270
|
+
if (isUiComponent)
|
|
382
271
|
return { name: componentName, from: "@karta.io/ui-components" };
|
|
383
|
-
}
|
|
384
272
|
};
|
|
385
273
|
}
|
|
386
274
|
|
|
@@ -428,9 +316,7 @@ function useAsyncItems({
|
|
|
428
316
|
queryKey: getQueryKey(),
|
|
429
317
|
queryFn: () => call(toValue(params), config)
|
|
430
318
|
});
|
|
431
|
-
const items = computed(
|
|
432
|
-
() => data.value?.results || []
|
|
433
|
-
);
|
|
319
|
+
const items = computed(() => data.value?.results || []);
|
|
434
320
|
const count = ref(0);
|
|
435
321
|
watch(
|
|
436
322
|
data,
|
|
@@ -507,12 +393,7 @@ function useAsyncMultiselect({
|
|
|
507
393
|
color: "#b54708",
|
|
508
394
|
debug: true
|
|
509
395
|
});
|
|
510
|
-
const paramsForLogger = {
|
|
511
|
-
queryKey,
|
|
512
|
-
dataItemsKey,
|
|
513
|
-
dataItemIdKey,
|
|
514
|
-
dataCountKey
|
|
515
|
-
};
|
|
396
|
+
const paramsForLogger = { queryKey, dataItemsKey, dataItemIdKey, dataCountKey };
|
|
516
397
|
const reactiveData = reactive({
|
|
517
398
|
search: "",
|
|
518
399
|
page: 1,
|
|
@@ -558,9 +439,8 @@ function useAsyncMultiselect({
|
|
|
558
439
|
);
|
|
559
440
|
return;
|
|
560
441
|
}
|
|
561
|
-
if (!get(newValue, dataItemsKey) || get(newValue, dataCountKey) === void 0)
|
|
442
|
+
if (!get(newValue, dataItemsKey) || get(newValue, dataCountKey) === void 0)
|
|
562
443
|
return;
|
|
563
|
-
}
|
|
564
444
|
count.value = get(newValue, dataCountKey, 0);
|
|
565
445
|
const newItems = get(newValue, dataItemsKey);
|
|
566
446
|
itemsByPages.value = {
|
|
@@ -591,9 +471,8 @@ function useAsyncMultiselect({
|
|
|
591
471
|
const items = computed(() => {
|
|
592
472
|
if (!itemsByPages.value)
|
|
593
473
|
return selectedItemsCached.value;
|
|
594
|
-
if (!Object.keys(itemsByPages.value).length)
|
|
474
|
+
if (!Object.keys(itemsByPages.value).length)
|
|
595
475
|
return selectedItemsCached.value;
|
|
596
|
-
}
|
|
597
476
|
const itemsByPagesAsArray = Object.values(itemsByPages.value).reduce(
|
|
598
477
|
(acc, item) => [...acc, ...item],
|
|
599
478
|
[]
|
|
@@ -609,7 +488,7 @@ function useAsyncMultiselect({
|
|
|
609
488
|
if (!items.value.length)
|
|
610
489
|
return [];
|
|
611
490
|
if (!mapOptionCallback)
|
|
612
|
-
return items.value;
|
|
491
|
+
return this.items.value;
|
|
613
492
|
return items.value.map(mapOptionCallback);
|
|
614
493
|
});
|
|
615
494
|
const hasNextPage = computed(() => count.value > items.value.length);
|
|
@@ -628,28 +507,6 @@ function useAsyncMultiselect({
|
|
|
628
507
|
search.value = value;
|
|
629
508
|
updateSearchWithDebounce(value);
|
|
630
509
|
};
|
|
631
|
-
const queryClient = useQueryClient();
|
|
632
|
-
const refetch = () => {
|
|
633
|
-
if (reactiveData.page !== 1) {
|
|
634
|
-
queryClient.invalidateQueries({
|
|
635
|
-
queryKey: [queryKey],
|
|
636
|
-
refetchType: "none"
|
|
637
|
-
});
|
|
638
|
-
loadPage(1);
|
|
639
|
-
} else {
|
|
640
|
-
queryClient.invalidateQueries({
|
|
641
|
-
queryKey: [queryKey]
|
|
642
|
-
});
|
|
643
|
-
}
|
|
644
|
-
};
|
|
645
|
-
const reload = () => {
|
|
646
|
-
if (reactiveData.page !== 1) {
|
|
647
|
-
queryClient.removeQueries({ queryKey: [queryKey] });
|
|
648
|
-
loadPage(1);
|
|
649
|
-
} else {
|
|
650
|
-
queryClient.resetQueries({ queryKey: [queryKey] });
|
|
651
|
-
}
|
|
652
|
-
};
|
|
653
510
|
if (isRef(selectedValues)) {
|
|
654
511
|
watch(selectedValues, async (newSelectedValues) => {
|
|
655
512
|
if (!newSelectedValues.length) {
|
|
@@ -690,9 +547,7 @@ function useAsyncMultiselect({
|
|
|
690
547
|
isFetching,
|
|
691
548
|
isLoading,
|
|
692
549
|
loadPage,
|
|
693
|
-
updateSearch
|
|
694
|
-
refetch,
|
|
695
|
-
reload
|
|
550
|
+
updateSearch
|
|
696
551
|
};
|
|
697
552
|
}
|
|
698
553
|
|
|
@@ -724,9 +579,7 @@ function useAsyncSelect({
|
|
|
724
579
|
const loadWAC = () => call({
|
|
725
580
|
page: reactiveData.page,
|
|
726
581
|
search: reactiveData.search,
|
|
727
|
-
...reactiveData.selectedValue && {
|
|
728
|
-
includedIds: [reactiveData.selectedValue]
|
|
729
|
-
},
|
|
582
|
+
...reactiveData.selectedValue && { includedIds: [reactiveData.selectedValue] },
|
|
730
583
|
...reactiveData.params && { ...JSON.parse(reactiveData.params) }
|
|
731
584
|
});
|
|
732
585
|
const { data, isFetching, isLoading } = useQuery({
|
|
@@ -754,9 +607,8 @@ function useAsyncSelect({
|
|
|
754
607
|
);
|
|
755
608
|
return;
|
|
756
609
|
}
|
|
757
|
-
if (!get(newValue, dataItemsKey) || get(newValue, dataCountKey) === void 0)
|
|
610
|
+
if (!get(newValue, dataItemsKey) || get(newValue, dataCountKey) === void 0)
|
|
758
611
|
return;
|
|
759
|
-
}
|
|
760
612
|
count.value = get(newValue, dataCountKey, 0);
|
|
761
613
|
const newItems = get(newValue, dataItemsKey);
|
|
762
614
|
itemsByPages.value = {
|
|
@@ -786,7 +638,7 @@ function useAsyncSelect({
|
|
|
786
638
|
if (!items.value.length)
|
|
787
639
|
return [];
|
|
788
640
|
if (!mapOptionCallback)
|
|
789
|
-
return items.value;
|
|
641
|
+
return this.items.value;
|
|
790
642
|
return items.value.map(mapOptionCallback);
|
|
791
643
|
});
|
|
792
644
|
const hasNextPage = computed(() => count.value > items.value.length);
|
|
@@ -801,28 +653,6 @@ function useAsyncSelect({
|
|
|
801
653
|
search.value = value;
|
|
802
654
|
updateSearchWithDebounce(value);
|
|
803
655
|
};
|
|
804
|
-
const queryClient = useQueryClient();
|
|
805
|
-
const refetch = () => {
|
|
806
|
-
if (reactiveData.page !== 1) {
|
|
807
|
-
queryClient.invalidateQueries({
|
|
808
|
-
queryKey: [queryKey],
|
|
809
|
-
refetchType: "none"
|
|
810
|
-
});
|
|
811
|
-
loadPage(1);
|
|
812
|
-
} else {
|
|
813
|
-
queryClient.invalidateQueries({
|
|
814
|
-
queryKey: [queryKey]
|
|
815
|
-
});
|
|
816
|
-
}
|
|
817
|
-
};
|
|
818
|
-
const reload = () => {
|
|
819
|
-
if (reactiveData.page !== 1) {
|
|
820
|
-
queryClient.removeQueries({ queryKey: [queryKey] });
|
|
821
|
-
loadPage(1);
|
|
822
|
-
} else {
|
|
823
|
-
queryClient.resetQueries({ queryKey: [queryKey] });
|
|
824
|
-
}
|
|
825
|
-
};
|
|
826
656
|
if (isRef(selectedValue)) {
|
|
827
657
|
watch(selectedValue, (newSelectedValue) => {
|
|
828
658
|
reactiveData.page = 1;
|
|
@@ -846,22 +676,20 @@ function useAsyncSelect({
|
|
|
846
676
|
isFetching,
|
|
847
677
|
isLoading,
|
|
848
678
|
loadPage,
|
|
849
|
-
updateSearch
|
|
850
|
-
refetch,
|
|
851
|
-
reload
|
|
679
|
+
updateSearch
|
|
852
680
|
};
|
|
853
681
|
}
|
|
854
682
|
|
|
855
683
|
function useBreakpoint() {
|
|
856
684
|
const breakpoints = useBreakpoints(BREAKPOINTS);
|
|
857
685
|
const isMobile = breakpoints.smaller("sm");
|
|
858
|
-
const isDesktop = breakpoints.
|
|
859
|
-
const isGreaterXxs = breakpoints.
|
|
860
|
-
const isGreaterXs = breakpoints.
|
|
861
|
-
const isGreaterSm = breakpoints.
|
|
862
|
-
const isGreaterMd = breakpoints.
|
|
863
|
-
const isGreaterLg = breakpoints.
|
|
864
|
-
const isGreaterXl = breakpoints.
|
|
686
|
+
const isDesktop = breakpoints.greater("md");
|
|
687
|
+
const isGreaterXxs = breakpoints.greater("xxs");
|
|
688
|
+
const isGreaterXs = breakpoints.greater("xs");
|
|
689
|
+
const isGreaterSm = breakpoints.greater("sm");
|
|
690
|
+
const isGreaterMd = breakpoints.greater("md");
|
|
691
|
+
const isGreaterLg = breakpoints.greater("lg");
|
|
692
|
+
const isGreaterXl = breakpoints.greater("xl");
|
|
865
693
|
return {
|
|
866
694
|
isMobile,
|
|
867
695
|
isDesktop,
|
|
@@ -928,9 +756,7 @@ function useDayjs(timezone) {
|
|
|
928
756
|
|
|
929
757
|
function parseVersion(version) {
|
|
930
758
|
if (typeof version !== "string" && typeof version !== "number") {
|
|
931
|
-
throw new TypeError(
|
|
932
|
-
"Browser version must be type of string, number or negative boolean"
|
|
933
|
-
);
|
|
759
|
+
throw new TypeError("Browser version must be type of string, number or negative boolean");
|
|
934
760
|
}
|
|
935
761
|
const [major, minor = 0, patch = 0, build = 0] = typeof version === "string" ? version.split(".").map(Number) : [version];
|
|
936
762
|
return {
|
|
@@ -991,20 +817,9 @@ function useGlobalScroll() {
|
|
|
991
817
|
|
|
992
818
|
const CONFIRM_TEXT = "Are you sure you want to close? \nAll changes will be lost.";
|
|
993
819
|
let dialogs = [];
|
|
994
|
-
|
|
995
|
-
function useDialog(options) {
|
|
996
|
-
const logger = useLogger("use-dialog");
|
|
997
|
-
let hashPrefix = HASH_PREFIX;
|
|
998
|
-
if (options?.hashPrefix) {
|
|
999
|
-
if (options.hashPrefix.charAt(0) === "#") {
|
|
1000
|
-
hashPrefix = options?.hashPrefix;
|
|
1001
|
-
} else {
|
|
1002
|
-
logger.warn(
|
|
1003
|
-
`*hashPrefix* must start with "#". The default prefix "${HASH_PREFIX}" will be used`
|
|
1004
|
-
);
|
|
1005
|
-
}
|
|
1006
|
-
}
|
|
820
|
+
function useDialog() {
|
|
1007
821
|
let appContext;
|
|
822
|
+
const logger = useLogger("use-dialog");
|
|
1008
823
|
const {
|
|
1009
824
|
isLocked: isGlobalScrollLocked,
|
|
1010
825
|
lock: lockGlobalScroll,
|
|
@@ -1012,27 +827,16 @@ function useDialog(options) {
|
|
|
1012
827
|
} = useGlobalScroll();
|
|
1013
828
|
const route = useRoute();
|
|
1014
829
|
const router = useRouter();
|
|
1015
|
-
const
|
|
1016
|
-
layer = 0,
|
|
1017
|
-
componentName,
|
|
1018
|
-
props
|
|
1019
|
-
}) => {
|
|
1020
|
-
const data = {
|
|
1021
|
-
name: componentName,
|
|
1022
|
-
layer,
|
|
1023
|
-
props
|
|
1024
|
-
};
|
|
1025
|
-
return `${hashPrefix}${window.btoa(JSON.stringify(data))}`;
|
|
1026
|
-
};
|
|
830
|
+
const HASH_PREFIX = "#ud_";
|
|
1027
831
|
const parseHash = (hash, componentName) => {
|
|
1028
832
|
if (!hash)
|
|
1029
833
|
return void 0;
|
|
1030
|
-
if (!hash.includes(
|
|
834
|
+
if (!hash.includes(HASH_PREFIX))
|
|
1031
835
|
return void 0;
|
|
1032
836
|
let dataFromHash;
|
|
1033
837
|
try {
|
|
1034
|
-
dataFromHash = JSON.parse(window.atob(hash.slice(
|
|
1035
|
-
} catch (
|
|
838
|
+
dataFromHash = JSON.parse(window.atob(hash.slice(HASH_PREFIX.length)));
|
|
839
|
+
} catch (error) {
|
|
1036
840
|
logger.warn("*parseHash* cant parse hash");
|
|
1037
841
|
}
|
|
1038
842
|
if (typeof dataFromHash !== "object")
|
|
@@ -1079,7 +883,7 @@ function useDialog(options) {
|
|
|
1079
883
|
vnode2.component.props.modelValue = value;
|
|
1080
884
|
if (!value && route?.hash) {
|
|
1081
885
|
const dataFromHash = parseHash(route.hash, component.name);
|
|
1082
|
-
if (dataFromHash
|
|
886
|
+
if (dataFromHash)
|
|
1083
887
|
clearHash();
|
|
1084
888
|
}
|
|
1085
889
|
if (!value && (dialogs.length === 1 || layer === 0) && isGlobalScrollLocked.value) {
|
|
@@ -1095,7 +899,7 @@ function useDialog(options) {
|
|
|
1095
899
|
if (!route?.hash)
|
|
1096
900
|
return;
|
|
1097
901
|
const dataFromHash = parseHash(route.hash, component.name);
|
|
1098
|
-
if (dataFromHash
|
|
902
|
+
if (dataFromHash)
|
|
1099
903
|
clearHash();
|
|
1100
904
|
};
|
|
1101
905
|
vnode2.props.onDestroy = () => {
|
|
@@ -1169,11 +973,6 @@ function useDialog(options) {
|
|
|
1169
973
|
const getInstance = (uuid) => {
|
|
1170
974
|
return dialogs.find((item) => item.uuid === uuid)?.vnode;
|
|
1171
975
|
};
|
|
1172
|
-
const getLayer = (uuid) => {
|
|
1173
|
-
if (!dialogs.length)
|
|
1174
|
-
return 0;
|
|
1175
|
-
return dialogs.find((dialog) => dialog.uuid === uuid)?.layer || 0;
|
|
1176
|
-
};
|
|
1177
976
|
const isOnTop = (uuid) => {
|
|
1178
977
|
if (!dialogs.length)
|
|
1179
978
|
return false;
|
|
@@ -1188,10 +987,15 @@ function useDialog(options) {
|
|
|
1188
987
|
component,
|
|
1189
988
|
props
|
|
1190
989
|
}) => {
|
|
990
|
+
const data = {
|
|
991
|
+
name: component.name,
|
|
992
|
+
layer,
|
|
993
|
+
props
|
|
994
|
+
};
|
|
1191
995
|
router.push({
|
|
1192
996
|
name: route.name || void 0,
|
|
1193
997
|
query: route.query,
|
|
1194
|
-
hash:
|
|
998
|
+
hash: `${HASH_PREFIX}${window.btoa(JSON.stringify(data))}`
|
|
1195
999
|
});
|
|
1196
1000
|
};
|
|
1197
1001
|
const watchHash = ({
|
|
@@ -1236,14 +1040,10 @@ function useDialog(options) {
|
|
|
1236
1040
|
return {
|
|
1237
1041
|
open,
|
|
1238
1042
|
getInstance,
|
|
1239
|
-
getLayer,
|
|
1240
1043
|
close,
|
|
1241
1044
|
closeAll,
|
|
1242
1045
|
showConfirm,
|
|
1243
1046
|
isOnTop,
|
|
1244
|
-
genHash,
|
|
1245
|
-
parseHash,
|
|
1246
|
-
clearHash,
|
|
1247
1047
|
openByHash,
|
|
1248
1048
|
watchHash
|
|
1249
1049
|
};
|
|
@@ -1256,7 +1056,10 @@ const QS_STRINGIFY_PARAMS = {
|
|
|
1256
1056
|
addQueryPrefix: true
|
|
1257
1057
|
};
|
|
1258
1058
|
const isOpen = ref(false);
|
|
1259
|
-
function useFilters({
|
|
1059
|
+
function useFilters({
|
|
1060
|
+
config,
|
|
1061
|
+
initialFilters
|
|
1062
|
+
}) {
|
|
1260
1063
|
const router = useRouter();
|
|
1261
1064
|
const route = useRoute();
|
|
1262
1065
|
const parseRouteQuery = (query) => qs.parse(query ?? route.query);
|
|
@@ -1264,43 +1067,35 @@ function useFilters({ config, initialFilters }) {
|
|
|
1264
1067
|
const parsedRouteQuery = parseRouteQuery();
|
|
1265
1068
|
if (!parsedRouteQuery.filters)
|
|
1266
1069
|
return void 0;
|
|
1267
|
-
return Object.entries(config).reduce(
|
|
1268
|
-
(
|
|
1269
|
-
|
|
1070
|
+
return Object.entries(config).reduce((accum, [currentKey, currentValue]) => {
|
|
1071
|
+
if (!parsedRouteQuery.filters[currentKey])
|
|
1072
|
+
return accum;
|
|
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)
|
|
1270
1077
|
return accum;
|
|
1271
|
-
if (currentValue.type === "ARRAY" /* Array */) {
|
|
1272
|
-
const splitValues = parsedRouteQuery.filters[currentKey].split(",");
|
|
1273
|
-
const checkedValue = currentValue?.possibleValues ? splitValues.filter(
|
|
1274
|
-
(k) => currentValue?.possibleValues?.includes(k)
|
|
1275
|
-
) : splitValues;
|
|
1276
|
-
if (!checkedValue?.length)
|
|
1277
|
-
return accum;
|
|
1278
|
-
return {
|
|
1279
|
-
...accum,
|
|
1280
|
-
[currentKey]: checkedValue
|
|
1281
|
-
};
|
|
1282
|
-
}
|
|
1283
1078
|
return {
|
|
1284
1079
|
...accum,
|
|
1285
|
-
[currentKey]:
|
|
1080
|
+
[currentKey]: checkedValue
|
|
1286
1081
|
};
|
|
1287
|
-
}
|
|
1288
|
-
{
|
|
1289
|
-
|
|
1082
|
+
}
|
|
1083
|
+
return {
|
|
1084
|
+
...accum,
|
|
1085
|
+
[currentKey]: parsedRouteQuery.filters[currentKey]
|
|
1086
|
+
};
|
|
1087
|
+
}, {});
|
|
1290
1088
|
});
|
|
1291
1089
|
const filtersCount = computed(
|
|
1292
1090
|
() => filtersFromQuery.value ? Object.keys(filtersFromQuery.value).length : 0
|
|
1293
1091
|
);
|
|
1294
1092
|
const setQueryFromFilters = (filters) => {
|
|
1295
1093
|
const parsedRouteQuery = parseRouteQuery();
|
|
1296
|
-
const filteredValue = Object.entries(filters).reduce(
|
|
1297
|
-
(
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
},
|
|
1302
|
-
{}
|
|
1303
|
-
);
|
|
1094
|
+
const filteredValue = Object.entries(filters).reduce((accum, [currentKey, currentValue]) => {
|
|
1095
|
+
if (!currentValue?.length)
|
|
1096
|
+
return accum;
|
|
1097
|
+
return { ...accum, [currentKey]: currentValue };
|
|
1098
|
+
}, {});
|
|
1304
1099
|
const query = qs.stringify(
|
|
1305
1100
|
{
|
|
1306
1101
|
...parsedRouteQuery,
|
|
@@ -1309,7 +1104,7 @@ function useFilters({ config, initialFilters }) {
|
|
|
1309
1104
|
},
|
|
1310
1105
|
QS_STRINGIFY_PARAMS
|
|
1311
1106
|
);
|
|
1312
|
-
router.push(query
|
|
1107
|
+
router.push(query);
|
|
1313
1108
|
};
|
|
1314
1109
|
const getValidatedParams = (query) => {
|
|
1315
1110
|
const parsedRouteQuery = parseRouteQuery(query);
|
|
@@ -1337,15 +1132,12 @@ function useFilters({ config, initialFilters }) {
|
|
|
1337
1132
|
});
|
|
1338
1133
|
};
|
|
1339
1134
|
const updateMany = (filters) => {
|
|
1340
|
-
const newFilters = Object.entries(filters).reduce(
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
},
|
|
1347
|
-
{}
|
|
1348
|
-
);
|
|
1135
|
+
const newFilters = Object.entries(filters).reduce((accum, [currentKey, currentValue]) => {
|
|
1136
|
+
return {
|
|
1137
|
+
...accum,
|
|
1138
|
+
[currentKey]: currentValue ? String(currentValue) : void 0
|
|
1139
|
+
};
|
|
1140
|
+
}, {});
|
|
1349
1141
|
setQueryFromFilters({
|
|
1350
1142
|
...filtersModel.value,
|
|
1351
1143
|
...newFilters
|
|
@@ -1521,7 +1313,7 @@ function usePanel() {
|
|
|
1521
1313
|
let dataFromHash;
|
|
1522
1314
|
try {
|
|
1523
1315
|
dataFromHash = JSON.parse(window.atob(newHash.slice(1)));
|
|
1524
|
-
} catch (
|
|
1316
|
+
} catch (error) {
|
|
1525
1317
|
logger.error("*watchHash* cant parse hash");
|
|
1526
1318
|
}
|
|
1527
1319
|
if (typeof dataFromHash !== "object")
|
|
@@ -1624,4 +1416,4 @@ function isStrictLength(value = 3, message) {
|
|
|
1624
1416
|
};
|
|
1625
1417
|
}
|
|
1626
1418
|
|
|
1627
|
-
export { AppComponentsResolver,
|
|
1419
|
+
export { AppComponentsResolver, UiComponentsResolver, 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 };
|