@karta.io/utils 1.0.0-beta.4 → 1.0.0-beta.41
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 +286 -72
- package/dist/index.d.cts +393 -0
- package/dist/index.d.mts +393 -0
- package/dist/index.d.ts +74 -31
- package/dist/index.mjs +281 -73
- package/package.json +33 -34
package/dist/index.cjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const camelCase = require('lodash/camelCase.js');
|
|
4
|
+
const flatMap = require('lodash/flatMap.js');
|
|
4
5
|
const commonData = require('@karta.io/common-data');
|
|
5
6
|
const libphonenumberJs = require('libphonenumber-js');
|
|
6
7
|
const snakeCase = require('lodash/snakeCase.js');
|
|
@@ -24,6 +25,7 @@ const qs = require('qs');
|
|
|
24
25
|
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
|
|
25
26
|
|
|
26
27
|
const camelCase__default = /*#__PURE__*/_interopDefaultCompat(camelCase);
|
|
28
|
+
const flatMap__default = /*#__PURE__*/_interopDefaultCompat(flatMap);
|
|
27
29
|
const snakeCase__default = /*#__PURE__*/_interopDefaultCompat(snakeCase);
|
|
28
30
|
const get__default = /*#__PURE__*/_interopDefaultCompat(get);
|
|
29
31
|
const has__default = /*#__PURE__*/_interopDefaultCompat(has);
|
|
@@ -42,14 +44,16 @@ function AppComponentsResolver(options = {}) {
|
|
|
42
44
|
return (name) => {
|
|
43
45
|
const componentName = prefix && name.startsWith(prefix) ? name.substring(prefix.length) : name;
|
|
44
46
|
const isAppComponent = componentName.startsWith("App");
|
|
45
|
-
if (isAppComponent)
|
|
47
|
+
if (isAppComponent) {
|
|
46
48
|
return { name: componentName, from: "@karta.io/app-components" };
|
|
49
|
+
}
|
|
47
50
|
};
|
|
48
51
|
}
|
|
49
52
|
|
|
50
53
|
function camelizeKeys(object) {
|
|
51
|
-
if (Array.isArray(object))
|
|
54
|
+
if (Array.isArray(object)) {
|
|
52
55
|
return object.map((v) => camelizeKeys(v));
|
|
56
|
+
}
|
|
53
57
|
if (object !== null && object.constructor === Object) {
|
|
54
58
|
return Object.keys(object).reduce(
|
|
55
59
|
(result, key) => ({
|
|
@@ -76,6 +80,109 @@ function convertEnumToOptions(obj, options) {
|
|
|
76
80
|
}));
|
|
77
81
|
}
|
|
78
82
|
|
|
83
|
+
class EnrichError extends Error {
|
|
84
|
+
constructor(data) {
|
|
85
|
+
super(data.message);
|
|
86
|
+
Object.assign(this, data);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function isHtml(data) {
|
|
91
|
+
try {
|
|
92
|
+
if (typeof DOMParser !== "undefined") {
|
|
93
|
+
const parser = new DOMParser();
|
|
94
|
+
const doc = parser.parseFromString(data, "text/html");
|
|
95
|
+
return Array.from(doc.body.childNodes).some(
|
|
96
|
+
(node) => node.nodeType === Node.ELEMENT_NODE
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
const htmlPattern = /<\/?[a-z][\s\S]*>/i;
|
|
100
|
+
return htmlPattern.test(data);
|
|
101
|
+
} catch (_) {
|
|
102
|
+
return false;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function getStatusMessage(status) {
|
|
107
|
+
let message = "";
|
|
108
|
+
switch (status) {
|
|
109
|
+
case 200:
|
|
110
|
+
message = "All done. Request successfully executed";
|
|
111
|
+
break;
|
|
112
|
+
case 201:
|
|
113
|
+
message = "Data successfully created";
|
|
114
|
+
break;
|
|
115
|
+
case 400:
|
|
116
|
+
message = "Bad request";
|
|
117
|
+
break;
|
|
118
|
+
case 401:
|
|
119
|
+
message = "Need auth";
|
|
120
|
+
break;
|
|
121
|
+
case 404:
|
|
122
|
+
message = "Not found";
|
|
123
|
+
break;
|
|
124
|
+
case 500:
|
|
125
|
+
message = "Something wrong. Internal server error";
|
|
126
|
+
break;
|
|
127
|
+
case 501:
|
|
128
|
+
message = "501: Not implemented";
|
|
129
|
+
break;
|
|
130
|
+
case 502:
|
|
131
|
+
message = "502: Bad gateway";
|
|
132
|
+
break;
|
|
133
|
+
case 503:
|
|
134
|
+
message = "Service unavailable. Try again later";
|
|
135
|
+
break;
|
|
136
|
+
default:
|
|
137
|
+
message = "Something wrong. Client default error message";
|
|
138
|
+
break;
|
|
139
|
+
}
|
|
140
|
+
return message;
|
|
141
|
+
}
|
|
142
|
+
function formatErrorDataMessage(data) {
|
|
143
|
+
if (!data)
|
|
144
|
+
return "";
|
|
145
|
+
return Object.values(data).reduce((accum, current) => {
|
|
146
|
+
if (current && typeof current === "string")
|
|
147
|
+
return accum ? `${accum} | ${current}` : current;
|
|
148
|
+
if (Array.isArray(current) && current.length) {
|
|
149
|
+
const value = `${flatMap__default(current).join(" | ")}`;
|
|
150
|
+
return accum ? `${accum} | ${value}` : value;
|
|
151
|
+
}
|
|
152
|
+
return accum;
|
|
153
|
+
}, "");
|
|
154
|
+
}
|
|
155
|
+
function formatErrorForNotify(error) {
|
|
156
|
+
if (!error)
|
|
157
|
+
return;
|
|
158
|
+
if (error.status >= 400 && error.status < 500) {
|
|
159
|
+
let message = "";
|
|
160
|
+
if (!error.data || typeof error.data === "string" && isHtml(error.data)) {
|
|
161
|
+
message = error.statusMessage || error.message || getStatusMessage(error.status);
|
|
162
|
+
} else if (typeof error.data === "string" && !isHtml(error.data)) {
|
|
163
|
+
message = error.data;
|
|
164
|
+
} else {
|
|
165
|
+
message = formatErrorDataMessage(error.data);
|
|
166
|
+
}
|
|
167
|
+
return {
|
|
168
|
+
title: "Request error",
|
|
169
|
+
message
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
if (error.status >= 500) {
|
|
173
|
+
return {
|
|
174
|
+
title: "Internal server error",
|
|
175
|
+
message: error.statusMessage || error.message || getStatusMessage(error.status)
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
if (error instanceof Error) {
|
|
179
|
+
return {
|
|
180
|
+
title: "Internal client error",
|
|
181
|
+
message: error.message
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
79
186
|
function formatMoney(value, currency = commonData.CURRENCY_DEFAULT, options = {}) {
|
|
80
187
|
const { locale = "en-US", defaultValue = 0, ...otherOptions } = options;
|
|
81
188
|
try {
|
|
@@ -93,7 +200,7 @@ function formatMoney(value, currency = commonData.CURRENCY_DEFAULT, options = {}
|
|
|
93
200
|
...otherOptions
|
|
94
201
|
});
|
|
95
202
|
return formatter.format(convertedValue);
|
|
96
|
-
} catch (
|
|
203
|
+
} catch (_error) {
|
|
97
204
|
return defaultValue;
|
|
98
205
|
}
|
|
99
206
|
}
|
|
@@ -123,7 +230,7 @@ function genUUID() {
|
|
|
123
230
|
r = (d2 + r) % 16 | 0;
|
|
124
231
|
d2 = Math.floor(d2 / 16);
|
|
125
232
|
}
|
|
126
|
-
return (c
|
|
233
|
+
return (c === "x" ? r : r & 7 | 8).toString(16);
|
|
127
234
|
});
|
|
128
235
|
}
|
|
129
236
|
|
|
@@ -203,7 +310,9 @@ function getPaginationParams({
|
|
|
203
310
|
offset: validatedPage * validatedLimit - validatedLimit
|
|
204
311
|
};
|
|
205
312
|
}
|
|
206
|
-
function getPaginationLimit({
|
|
313
|
+
function getPaginationLimit({
|
|
314
|
+
limit
|
|
315
|
+
}) {
|
|
207
316
|
return validateNumber(limit, LIMIT_DEFAULT);
|
|
208
317
|
}
|
|
209
318
|
function getPaginationOffset({
|
|
@@ -225,15 +334,17 @@ function parsePhone(phone) {
|
|
|
225
334
|
if (!phone || typeof phone !== "string")
|
|
226
335
|
return "";
|
|
227
336
|
const replacedPhone = phone.replace(/[a-zA-Z]/g, "");
|
|
228
|
-
if (replacedPhone.length === 1 && replacedPhone !== "+")
|
|
337
|
+
if (replacedPhone.length === 1 && replacedPhone !== "+") {
|
|
229
338
|
return `+${replacedPhone}`;
|
|
339
|
+
}
|
|
230
340
|
const phoneNumber = libphonenumberJs.parsePhoneNumberFromString(replacedPhone);
|
|
231
341
|
return phoneNumber ? phoneNumber.formatInternational() : replacedPhone;
|
|
232
342
|
}
|
|
233
343
|
|
|
234
344
|
function snakelizeKeys(prop) {
|
|
235
|
-
if (Array.isArray(prop))
|
|
345
|
+
if (Array.isArray(prop)) {
|
|
236
346
|
return prop.map((item) => snakelizeKeys(item));
|
|
347
|
+
}
|
|
237
348
|
if (prop !== null && prop !== void 0 && prop.constructor === Object) {
|
|
238
349
|
return Object.keys(prop).reduce(
|
|
239
350
|
(accum, current) => ({
|
|
@@ -273,8 +384,9 @@ function unformatNumber(value) {
|
|
|
273
384
|
if (commasCount === 1 && !hasSpace && !hasDot) {
|
|
274
385
|
locale = string.length - 1 - commaIndex === 3 ? LOCALE_EN : LOCALE_RU;
|
|
275
386
|
}
|
|
276
|
-
if (locale === LOCALE_RU)
|
|
387
|
+
if (locale === LOCALE_RU) {
|
|
277
388
|
return Number(string.replaceAll(" ", "").replace(",", "."));
|
|
389
|
+
}
|
|
278
390
|
if (locale === LOCALE_EN)
|
|
279
391
|
return Number(string.replaceAll(",", ""));
|
|
280
392
|
return value;
|
|
@@ -285,8 +397,9 @@ function UiComponentsResolver(options = {}) {
|
|
|
285
397
|
return (name) => {
|
|
286
398
|
const componentName = prefix && name.startsWith(prefix) ? name.substring(prefix.length) : name;
|
|
287
399
|
const isUiComponent = componentName.startsWith("Ui");
|
|
288
|
-
if (isUiComponent)
|
|
400
|
+
if (isUiComponent) {
|
|
289
401
|
return { name: componentName, from: "@karta.io/ui-components" };
|
|
402
|
+
}
|
|
290
403
|
};
|
|
291
404
|
}
|
|
292
405
|
|
|
@@ -334,7 +447,9 @@ function useAsyncItems({
|
|
|
334
447
|
queryKey: getQueryKey(),
|
|
335
448
|
queryFn: () => call(core.toValue(params), config)
|
|
336
449
|
});
|
|
337
|
-
const items = vue.computed(
|
|
450
|
+
const items = vue.computed(
|
|
451
|
+
() => data.value?.results || []
|
|
452
|
+
);
|
|
338
453
|
const count = vue.ref(0);
|
|
339
454
|
vue.watch(
|
|
340
455
|
data,
|
|
@@ -411,7 +526,12 @@ function useAsyncMultiselect({
|
|
|
411
526
|
color: "#b54708",
|
|
412
527
|
debug: true
|
|
413
528
|
});
|
|
414
|
-
const paramsForLogger = {
|
|
529
|
+
const paramsForLogger = {
|
|
530
|
+
queryKey,
|
|
531
|
+
dataItemsKey,
|
|
532
|
+
dataItemIdKey,
|
|
533
|
+
dataCountKey
|
|
534
|
+
};
|
|
415
535
|
const reactiveData = vue.reactive({
|
|
416
536
|
search: "",
|
|
417
537
|
page: 1,
|
|
@@ -457,8 +577,9 @@ function useAsyncMultiselect({
|
|
|
457
577
|
);
|
|
458
578
|
return;
|
|
459
579
|
}
|
|
460
|
-
if (!get__default(newValue, dataItemsKey) || get__default(newValue, dataCountKey) === void 0)
|
|
580
|
+
if (!get__default(newValue, dataItemsKey) || get__default(newValue, dataCountKey) === void 0) {
|
|
461
581
|
return;
|
|
582
|
+
}
|
|
462
583
|
count.value = get__default(newValue, dataCountKey, 0);
|
|
463
584
|
const newItems = get__default(newValue, dataItemsKey);
|
|
464
585
|
itemsByPages.value = {
|
|
@@ -489,8 +610,9 @@ function useAsyncMultiselect({
|
|
|
489
610
|
const items = vue.computed(() => {
|
|
490
611
|
if (!itemsByPages.value)
|
|
491
612
|
return selectedItemsCached.value;
|
|
492
|
-
if (!Object.keys(itemsByPages.value).length)
|
|
613
|
+
if (!Object.keys(itemsByPages.value).length) {
|
|
493
614
|
return selectedItemsCached.value;
|
|
615
|
+
}
|
|
494
616
|
const itemsByPagesAsArray = Object.values(itemsByPages.value).reduce(
|
|
495
617
|
(acc, item) => [...acc, ...item],
|
|
496
618
|
[]
|
|
@@ -506,7 +628,7 @@ function useAsyncMultiselect({
|
|
|
506
628
|
if (!items.value.length)
|
|
507
629
|
return [];
|
|
508
630
|
if (!mapOptionCallback)
|
|
509
|
-
return
|
|
631
|
+
return items.value;
|
|
510
632
|
return items.value.map(mapOptionCallback);
|
|
511
633
|
});
|
|
512
634
|
const hasNextPage = vue.computed(() => count.value > items.value.length);
|
|
@@ -525,6 +647,28 @@ function useAsyncMultiselect({
|
|
|
525
647
|
search.value = value;
|
|
526
648
|
updateSearchWithDebounce(value);
|
|
527
649
|
};
|
|
650
|
+
const queryClient = vueQuery.useQueryClient();
|
|
651
|
+
const refetch = () => {
|
|
652
|
+
if (reactiveData.page !== 1) {
|
|
653
|
+
queryClient.invalidateQueries({
|
|
654
|
+
queryKey: [queryKey],
|
|
655
|
+
refetchType: "none"
|
|
656
|
+
});
|
|
657
|
+
loadPage(1);
|
|
658
|
+
} else {
|
|
659
|
+
queryClient.invalidateQueries({
|
|
660
|
+
queryKey: [queryKey]
|
|
661
|
+
});
|
|
662
|
+
}
|
|
663
|
+
};
|
|
664
|
+
const reload = () => {
|
|
665
|
+
if (reactiveData.page !== 1) {
|
|
666
|
+
queryClient.removeQueries({ queryKey: [queryKey] });
|
|
667
|
+
loadPage(1);
|
|
668
|
+
} else {
|
|
669
|
+
queryClient.resetQueries({ queryKey: [queryKey] });
|
|
670
|
+
}
|
|
671
|
+
};
|
|
528
672
|
if (vue.isRef(selectedValues)) {
|
|
529
673
|
vue.watch(selectedValues, async (newSelectedValues) => {
|
|
530
674
|
if (!newSelectedValues.length) {
|
|
@@ -565,7 +709,9 @@ function useAsyncMultiselect({
|
|
|
565
709
|
isFetching,
|
|
566
710
|
isLoading,
|
|
567
711
|
loadPage,
|
|
568
|
-
updateSearch
|
|
712
|
+
updateSearch,
|
|
713
|
+
refetch,
|
|
714
|
+
reload
|
|
569
715
|
};
|
|
570
716
|
}
|
|
571
717
|
|
|
@@ -597,7 +743,9 @@ function useAsyncSelect({
|
|
|
597
743
|
const loadWAC = () => call({
|
|
598
744
|
page: reactiveData.page,
|
|
599
745
|
search: reactiveData.search,
|
|
600
|
-
...reactiveData.selectedValue && {
|
|
746
|
+
...reactiveData.selectedValue && {
|
|
747
|
+
includedIds: [reactiveData.selectedValue]
|
|
748
|
+
},
|
|
601
749
|
...reactiveData.params && { ...JSON.parse(reactiveData.params) }
|
|
602
750
|
});
|
|
603
751
|
const { data, isFetching, isLoading } = vueQuery.useQuery({
|
|
@@ -625,8 +773,9 @@ function useAsyncSelect({
|
|
|
625
773
|
);
|
|
626
774
|
return;
|
|
627
775
|
}
|
|
628
|
-
if (!get__default(newValue, dataItemsKey) || get__default(newValue, dataCountKey) === void 0)
|
|
776
|
+
if (!get__default(newValue, dataItemsKey) || get__default(newValue, dataCountKey) === void 0) {
|
|
629
777
|
return;
|
|
778
|
+
}
|
|
630
779
|
count.value = get__default(newValue, dataCountKey, 0);
|
|
631
780
|
const newItems = get__default(newValue, dataItemsKey);
|
|
632
781
|
itemsByPages.value = {
|
|
@@ -656,7 +805,7 @@ function useAsyncSelect({
|
|
|
656
805
|
if (!items.value.length)
|
|
657
806
|
return [];
|
|
658
807
|
if (!mapOptionCallback)
|
|
659
|
-
return
|
|
808
|
+
return items.value;
|
|
660
809
|
return items.value.map(mapOptionCallback);
|
|
661
810
|
});
|
|
662
811
|
const hasNextPage = vue.computed(() => count.value > items.value.length);
|
|
@@ -671,6 +820,28 @@ function useAsyncSelect({
|
|
|
671
820
|
search.value = value;
|
|
672
821
|
updateSearchWithDebounce(value);
|
|
673
822
|
};
|
|
823
|
+
const queryClient = vueQuery.useQueryClient();
|
|
824
|
+
const refetch = () => {
|
|
825
|
+
if (reactiveData.page !== 1) {
|
|
826
|
+
queryClient.invalidateQueries({
|
|
827
|
+
queryKey: [queryKey],
|
|
828
|
+
refetchType: "none"
|
|
829
|
+
});
|
|
830
|
+
loadPage(1);
|
|
831
|
+
} else {
|
|
832
|
+
queryClient.invalidateQueries({
|
|
833
|
+
queryKey: [queryKey]
|
|
834
|
+
});
|
|
835
|
+
}
|
|
836
|
+
};
|
|
837
|
+
const reload = () => {
|
|
838
|
+
if (reactiveData.page !== 1) {
|
|
839
|
+
queryClient.removeQueries({ queryKey: [queryKey] });
|
|
840
|
+
loadPage(1);
|
|
841
|
+
} else {
|
|
842
|
+
queryClient.resetQueries({ queryKey: [queryKey] });
|
|
843
|
+
}
|
|
844
|
+
};
|
|
674
845
|
if (vue.isRef(selectedValue)) {
|
|
675
846
|
vue.watch(selectedValue, (newSelectedValue) => {
|
|
676
847
|
reactiveData.page = 1;
|
|
@@ -694,20 +865,22 @@ function useAsyncSelect({
|
|
|
694
865
|
isFetching,
|
|
695
866
|
isLoading,
|
|
696
867
|
loadPage,
|
|
697
|
-
updateSearch
|
|
868
|
+
updateSearch,
|
|
869
|
+
refetch,
|
|
870
|
+
reload
|
|
698
871
|
};
|
|
699
872
|
}
|
|
700
873
|
|
|
701
874
|
function useBreakpoint() {
|
|
702
875
|
const breakpoints = core.useBreakpoints(commonData.BREAKPOINTS);
|
|
703
876
|
const isMobile = breakpoints.smaller("sm");
|
|
704
|
-
const isDesktop = breakpoints.
|
|
705
|
-
const isGreaterXxs = breakpoints.
|
|
706
|
-
const isGreaterXs = breakpoints.
|
|
707
|
-
const isGreaterSm = breakpoints.
|
|
708
|
-
const isGreaterMd = breakpoints.
|
|
709
|
-
const isGreaterLg = breakpoints.
|
|
710
|
-
const isGreaterXl = breakpoints.
|
|
877
|
+
const isDesktop = breakpoints.greaterOrEqual("md");
|
|
878
|
+
const isGreaterXxs = breakpoints.greaterOrEqual("xxs");
|
|
879
|
+
const isGreaterXs = breakpoints.greaterOrEqual("xs");
|
|
880
|
+
const isGreaterSm = breakpoints.greaterOrEqual("sm");
|
|
881
|
+
const isGreaterMd = breakpoints.greaterOrEqual("md");
|
|
882
|
+
const isGreaterLg = breakpoints.greaterOrEqual("lg");
|
|
883
|
+
const isGreaterXl = breakpoints.greaterOrEqual("xl");
|
|
711
884
|
return {
|
|
712
885
|
isMobile,
|
|
713
886
|
isDesktop,
|
|
@@ -774,7 +947,9 @@ function useDayjs(timezone) {
|
|
|
774
947
|
|
|
775
948
|
function parseVersion(version) {
|
|
776
949
|
if (typeof version !== "string" && typeof version !== "number") {
|
|
777
|
-
throw new TypeError(
|
|
950
|
+
throw new TypeError(
|
|
951
|
+
"Browser version must be type of string, number or negative boolean"
|
|
952
|
+
);
|
|
778
953
|
}
|
|
779
954
|
const [major, minor = 0, patch = 0, build = 0] = typeof version === "string" ? version.split(".").map(Number) : [version];
|
|
780
955
|
return {
|
|
@@ -835,9 +1010,20 @@ function useGlobalScroll() {
|
|
|
835
1010
|
|
|
836
1011
|
const CONFIRM_TEXT = "Are you sure you want to close? \nAll changes will be lost.";
|
|
837
1012
|
let dialogs = [];
|
|
838
|
-
|
|
839
|
-
|
|
1013
|
+
const HASH_PREFIX = "#ud_";
|
|
1014
|
+
function useDialog(options) {
|
|
840
1015
|
const logger = useLogger("use-dialog");
|
|
1016
|
+
let hashPrefix = HASH_PREFIX;
|
|
1017
|
+
if (options?.hashPrefix) {
|
|
1018
|
+
if (options.hashPrefix.charAt(0) === "#") {
|
|
1019
|
+
hashPrefix = options?.hashPrefix;
|
|
1020
|
+
} else {
|
|
1021
|
+
logger.warn(
|
|
1022
|
+
`*hashPrefix* must start with "#". The default prefix "${HASH_PREFIX}" will be used`
|
|
1023
|
+
);
|
|
1024
|
+
}
|
|
1025
|
+
}
|
|
1026
|
+
let appContext;
|
|
841
1027
|
const {
|
|
842
1028
|
isLocked: isGlobalScrollLocked,
|
|
843
1029
|
lock: lockGlobalScroll,
|
|
@@ -845,16 +1031,27 @@ function useDialog() {
|
|
|
845
1031
|
} = useGlobalScroll();
|
|
846
1032
|
const route = vueRouter.useRoute();
|
|
847
1033
|
const router = vueRouter.useRouter();
|
|
848
|
-
const
|
|
1034
|
+
const genHash = ({
|
|
1035
|
+
layer = 0,
|
|
1036
|
+
componentName,
|
|
1037
|
+
props
|
|
1038
|
+
}) => {
|
|
1039
|
+
const data = {
|
|
1040
|
+
name: componentName,
|
|
1041
|
+
layer,
|
|
1042
|
+
props
|
|
1043
|
+
};
|
|
1044
|
+
return `${hashPrefix}${window.btoa(JSON.stringify(data))}`;
|
|
1045
|
+
};
|
|
849
1046
|
const parseHash = (hash, componentName) => {
|
|
850
1047
|
if (!hash)
|
|
851
1048
|
return void 0;
|
|
852
|
-
if (!hash.includes(
|
|
1049
|
+
if (!hash.includes(hashPrefix))
|
|
853
1050
|
return void 0;
|
|
854
1051
|
let dataFromHash;
|
|
855
1052
|
try {
|
|
856
|
-
dataFromHash = JSON.parse(window.atob(hash.slice(
|
|
857
|
-
} catch (
|
|
1053
|
+
dataFromHash = JSON.parse(window.atob(hash.slice(hashPrefix.length)));
|
|
1054
|
+
} catch (_error) {
|
|
858
1055
|
logger.warn("*parseHash* cant parse hash");
|
|
859
1056
|
}
|
|
860
1057
|
if (typeof dataFromHash !== "object")
|
|
@@ -901,7 +1098,7 @@ function useDialog() {
|
|
|
901
1098
|
vnode2.component.props.modelValue = value;
|
|
902
1099
|
if (!value && route?.hash) {
|
|
903
1100
|
const dataFromHash = parseHash(route.hash, component.name);
|
|
904
|
-
if (dataFromHash)
|
|
1101
|
+
if (dataFromHash?.layer === layer)
|
|
905
1102
|
clearHash();
|
|
906
1103
|
}
|
|
907
1104
|
if (!value && (dialogs.length === 1 || layer === 0) && isGlobalScrollLocked.value) {
|
|
@@ -917,7 +1114,7 @@ function useDialog() {
|
|
|
917
1114
|
if (!route?.hash)
|
|
918
1115
|
return;
|
|
919
1116
|
const dataFromHash = parseHash(route.hash, component.name);
|
|
920
|
-
if (dataFromHash)
|
|
1117
|
+
if (dataFromHash?.layer === layer)
|
|
921
1118
|
clearHash();
|
|
922
1119
|
};
|
|
923
1120
|
vnode2.props.onDestroy = () => {
|
|
@@ -991,6 +1188,11 @@ function useDialog() {
|
|
|
991
1188
|
const getInstance = (uuid) => {
|
|
992
1189
|
return dialogs.find((item) => item.uuid === uuid)?.vnode;
|
|
993
1190
|
};
|
|
1191
|
+
const getLayer = (uuid) => {
|
|
1192
|
+
if (!dialogs.length)
|
|
1193
|
+
return 0;
|
|
1194
|
+
return dialogs.find((dialog) => dialog.uuid === uuid)?.layer || 0;
|
|
1195
|
+
};
|
|
994
1196
|
const isOnTop = (uuid) => {
|
|
995
1197
|
if (!dialogs.length)
|
|
996
1198
|
return false;
|
|
@@ -1005,15 +1207,10 @@ function useDialog() {
|
|
|
1005
1207
|
component,
|
|
1006
1208
|
props
|
|
1007
1209
|
}) => {
|
|
1008
|
-
const data = {
|
|
1009
|
-
name: component.name,
|
|
1010
|
-
layer,
|
|
1011
|
-
props
|
|
1012
|
-
};
|
|
1013
1210
|
router.push({
|
|
1014
1211
|
name: route.name || void 0,
|
|
1015
1212
|
query: route.query,
|
|
1016
|
-
hash:
|
|
1213
|
+
hash: genHash({ layer, props, componentName: component.name })
|
|
1017
1214
|
});
|
|
1018
1215
|
};
|
|
1019
1216
|
const watchHash = ({
|
|
@@ -1058,10 +1255,14 @@ function useDialog() {
|
|
|
1058
1255
|
return {
|
|
1059
1256
|
open,
|
|
1060
1257
|
getInstance,
|
|
1258
|
+
getLayer,
|
|
1061
1259
|
close,
|
|
1062
1260
|
closeAll,
|
|
1063
1261
|
showConfirm,
|
|
1064
1262
|
isOnTop,
|
|
1263
|
+
genHash,
|
|
1264
|
+
parseHash,
|
|
1265
|
+
clearHash,
|
|
1065
1266
|
openByHash,
|
|
1066
1267
|
watchHash
|
|
1067
1268
|
};
|
|
@@ -1074,10 +1275,7 @@ const QS_STRINGIFY_PARAMS = {
|
|
|
1074
1275
|
addQueryPrefix: true
|
|
1075
1276
|
};
|
|
1076
1277
|
const isOpen = vue.ref(false);
|
|
1077
|
-
function useFilters({
|
|
1078
|
-
config,
|
|
1079
|
-
initialFilters
|
|
1080
|
-
}) {
|
|
1278
|
+
function useFilters({ config, initialFilters }) {
|
|
1081
1279
|
const router = vueRouter.useRouter();
|
|
1082
1280
|
const route = vueRouter.useRoute();
|
|
1083
1281
|
const parseRouteQuery = (query) => qs__default.parse(query ?? route.query);
|
|
@@ -1085,35 +1283,43 @@ function useFilters({
|
|
|
1085
1283
|
const parsedRouteQuery = parseRouteQuery();
|
|
1086
1284
|
if (!parsedRouteQuery.filters)
|
|
1087
1285
|
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)
|
|
1286
|
+
return Object.entries(config).reduce(
|
|
1287
|
+
(accum, [currentKey, currentValue]) => {
|
|
1288
|
+
if (!parsedRouteQuery.filters[currentKey])
|
|
1095
1289
|
return accum;
|
|
1290
|
+
if (currentValue.type === "ARRAY" /* Array */) {
|
|
1291
|
+
const splitValues = parsedRouteQuery.filters[currentKey].split(",");
|
|
1292
|
+
const checkedValue = currentValue?.possibleValues ? splitValues.filter(
|
|
1293
|
+
(k) => currentValue?.possibleValues?.includes(k)
|
|
1294
|
+
) : splitValues;
|
|
1295
|
+
if (!checkedValue?.length)
|
|
1296
|
+
return accum;
|
|
1297
|
+
return {
|
|
1298
|
+
...accum,
|
|
1299
|
+
[currentKey]: checkedValue
|
|
1300
|
+
};
|
|
1301
|
+
}
|
|
1096
1302
|
return {
|
|
1097
1303
|
...accum,
|
|
1098
|
-
[currentKey]:
|
|
1304
|
+
[currentKey]: parsedRouteQuery.filters[currentKey]
|
|
1099
1305
|
};
|
|
1100
|
-
}
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
[currentKey]: parsedRouteQuery.filters[currentKey]
|
|
1104
|
-
};
|
|
1105
|
-
}, {});
|
|
1306
|
+
},
|
|
1307
|
+
{}
|
|
1308
|
+
);
|
|
1106
1309
|
});
|
|
1107
1310
|
const filtersCount = vue.computed(
|
|
1108
1311
|
() => filtersFromQuery.value ? Object.keys(filtersFromQuery.value).length : 0
|
|
1109
1312
|
);
|
|
1110
1313
|
const setQueryFromFilters = (filters) => {
|
|
1111
1314
|
const parsedRouteQuery = parseRouteQuery();
|
|
1112
|
-
const filteredValue = Object.entries(filters).reduce(
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1315
|
+
const filteredValue = Object.entries(filters).reduce(
|
|
1316
|
+
(accum, [currentKey, currentValue]) => {
|
|
1317
|
+
if (!currentValue?.length)
|
|
1318
|
+
return accum;
|
|
1319
|
+
return { ...accum, [currentKey]: currentValue };
|
|
1320
|
+
},
|
|
1321
|
+
{}
|
|
1322
|
+
);
|
|
1117
1323
|
const query = qs__default.stringify(
|
|
1118
1324
|
{
|
|
1119
1325
|
...parsedRouteQuery,
|
|
@@ -1122,7 +1328,7 @@ function useFilters({
|
|
|
1122
1328
|
},
|
|
1123
1329
|
QS_STRINGIFY_PARAMS
|
|
1124
1330
|
);
|
|
1125
|
-
router.push(query);
|
|
1331
|
+
router.push(query.replaceAll("#", ""));
|
|
1126
1332
|
};
|
|
1127
1333
|
const getValidatedParams = (query) => {
|
|
1128
1334
|
const parsedRouteQuery = parseRouteQuery(query);
|
|
@@ -1150,12 +1356,15 @@ function useFilters({
|
|
|
1150
1356
|
});
|
|
1151
1357
|
};
|
|
1152
1358
|
const updateMany = (filters) => {
|
|
1153
|
-
const newFilters = Object.entries(filters).reduce(
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1359
|
+
const newFilters = Object.entries(filters).reduce(
|
|
1360
|
+
(accum, [currentKey, currentValue]) => {
|
|
1361
|
+
return {
|
|
1362
|
+
...accum,
|
|
1363
|
+
[currentKey]: currentValue ? String(currentValue) : void 0
|
|
1364
|
+
};
|
|
1365
|
+
},
|
|
1366
|
+
{}
|
|
1367
|
+
);
|
|
1159
1368
|
setQueryFromFilters({
|
|
1160
1369
|
...filtersModel.value,
|
|
1161
1370
|
...newFilters
|
|
@@ -1331,7 +1540,7 @@ function usePanel() {
|
|
|
1331
1540
|
let dataFromHash;
|
|
1332
1541
|
try {
|
|
1333
1542
|
dataFromHash = JSON.parse(window.atob(newHash.slice(1)));
|
|
1334
|
-
} catch (
|
|
1543
|
+
} catch (_error) {
|
|
1335
1544
|
logger.error("*watchHash* cant parse hash");
|
|
1336
1545
|
}
|
|
1337
1546
|
if (typeof dataFromHash !== "object")
|
|
@@ -1435,9 +1644,12 @@ function isStrictLength(value = 3, message) {
|
|
|
1435
1644
|
}
|
|
1436
1645
|
|
|
1437
1646
|
exports.AppComponentsResolver = AppComponentsResolver;
|
|
1647
|
+
exports.EnrichError = EnrichError;
|
|
1438
1648
|
exports.UiComponentsResolver = UiComponentsResolver;
|
|
1439
1649
|
exports.camelizeKeys = camelizeKeys;
|
|
1440
1650
|
exports.convertEnumToOptions = convertEnumToOptions;
|
|
1651
|
+
exports.formatErrorDataMessage = formatErrorDataMessage;
|
|
1652
|
+
exports.formatErrorForNotify = formatErrorForNotify;
|
|
1441
1653
|
exports.formatMoney = formatMoney;
|
|
1442
1654
|
exports.genHash = genHash;
|
|
1443
1655
|
exports.genRandomNumber = genRandomNumber;
|
|
@@ -1448,8 +1660,10 @@ exports.getPaginationLimit = getPaginationLimit;
|
|
|
1448
1660
|
exports.getPaginationOffset = getPaginationOffset;
|
|
1449
1661
|
exports.getPaginationPages = getPaginationPages;
|
|
1450
1662
|
exports.getPaginationParams = getPaginationParams;
|
|
1663
|
+
exports.getStatusMessage = getStatusMessage;
|
|
1451
1664
|
exports.isElementIgnored = isElementIgnored;
|
|
1452
1665
|
exports.isEmptyObject = isEmptyObject;
|
|
1666
|
+
exports.isHtml = isHtml;
|
|
1453
1667
|
exports.isMax = isMax;
|
|
1454
1668
|
exports.isMin = isMin;
|
|
1455
1669
|
exports.isRequired = isRequired;
|