@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.cjs
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const camelCase = require('lodash/camelCase.js');
|
|
4
|
-
const flatMap = require('lodash/flatMap.js');
|
|
5
4
|
const commonData = require('@karta.io/common-data');
|
|
6
5
|
const libphonenumberJs = require('libphonenumber-js');
|
|
7
6
|
const snakeCase = require('lodash/snakeCase.js');
|
|
@@ -25,7 +24,6 @@ const qs = require('qs');
|
|
|
25
24
|
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
|
|
26
25
|
|
|
27
26
|
const camelCase__default = /*#__PURE__*/_interopDefaultCompat(camelCase);
|
|
28
|
-
const flatMap__default = /*#__PURE__*/_interopDefaultCompat(flatMap);
|
|
29
27
|
const snakeCase__default = /*#__PURE__*/_interopDefaultCompat(snakeCase);
|
|
30
28
|
const get__default = /*#__PURE__*/_interopDefaultCompat(get);
|
|
31
29
|
const has__default = /*#__PURE__*/_interopDefaultCompat(has);
|
|
@@ -44,16 +42,14 @@ function AppComponentsResolver(options = {}) {
|
|
|
44
42
|
return (name) => {
|
|
45
43
|
const componentName = prefix && name.startsWith(prefix) ? name.substring(prefix.length) : name;
|
|
46
44
|
const isAppComponent = componentName.startsWith("App");
|
|
47
|
-
if (isAppComponent)
|
|
45
|
+
if (isAppComponent)
|
|
48
46
|
return { name: componentName, from: "@karta.io/app-components" };
|
|
49
|
-
}
|
|
50
47
|
};
|
|
51
48
|
}
|
|
52
49
|
|
|
53
50
|
function camelizeKeys(object) {
|
|
54
|
-
if (Array.isArray(object))
|
|
51
|
+
if (Array.isArray(object))
|
|
55
52
|
return object.map((v) => camelizeKeys(v));
|
|
56
|
-
}
|
|
57
53
|
if (object !== null && object.constructor === Object) {
|
|
58
54
|
return Object.keys(object).reduce(
|
|
59
55
|
(result, key) => ({
|
|
@@ -80,109 +76,6 @@ function convertEnumToOptions(obj, options) {
|
|
|
80
76
|
}));
|
|
81
77
|
}
|
|
82
78
|
|
|
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
|
-
|
|
186
79
|
function formatMoney(value, currency = commonData.CURRENCY_DEFAULT, options = {}) {
|
|
187
80
|
const { locale = "en-US", defaultValue = 0, ...otherOptions } = options;
|
|
188
81
|
try {
|
|
@@ -200,7 +93,7 @@ function formatMoney(value, currency = commonData.CURRENCY_DEFAULT, options = {}
|
|
|
200
93
|
...otherOptions
|
|
201
94
|
});
|
|
202
95
|
return formatter.format(convertedValue);
|
|
203
|
-
} catch (
|
|
96
|
+
} catch (error) {
|
|
204
97
|
return defaultValue;
|
|
205
98
|
}
|
|
206
99
|
}
|
|
@@ -230,7 +123,7 @@ function genUUID() {
|
|
|
230
123
|
r = (d2 + r) % 16 | 0;
|
|
231
124
|
d2 = Math.floor(d2 / 16);
|
|
232
125
|
}
|
|
233
|
-
return (c
|
|
126
|
+
return (c == "x" ? r : r & 7 | 8).toString(16);
|
|
234
127
|
});
|
|
235
128
|
}
|
|
236
129
|
|
|
@@ -310,9 +203,7 @@ function getPaginationParams({
|
|
|
310
203
|
offset: validatedPage * validatedLimit - validatedLimit
|
|
311
204
|
};
|
|
312
205
|
}
|
|
313
|
-
function getPaginationLimit({
|
|
314
|
-
limit
|
|
315
|
-
}) {
|
|
206
|
+
function getPaginationLimit({ limit }) {
|
|
316
207
|
return validateNumber(limit, LIMIT_DEFAULT);
|
|
317
208
|
}
|
|
318
209
|
function getPaginationOffset({
|
|
@@ -334,17 +225,15 @@ function parsePhone(phone) {
|
|
|
334
225
|
if (!phone || typeof phone !== "string")
|
|
335
226
|
return "";
|
|
336
227
|
const replacedPhone = phone.replace(/[a-zA-Z]/g, "");
|
|
337
|
-
if (replacedPhone.length === 1 && replacedPhone !== "+")
|
|
228
|
+
if (replacedPhone.length === 1 && replacedPhone !== "+")
|
|
338
229
|
return `+${replacedPhone}`;
|
|
339
|
-
}
|
|
340
230
|
const phoneNumber = libphonenumberJs.parsePhoneNumberFromString(replacedPhone);
|
|
341
231
|
return phoneNumber ? phoneNumber.formatInternational() : replacedPhone;
|
|
342
232
|
}
|
|
343
233
|
|
|
344
234
|
function snakelizeKeys(prop) {
|
|
345
|
-
if (Array.isArray(prop))
|
|
235
|
+
if (Array.isArray(prop))
|
|
346
236
|
return prop.map((item) => snakelizeKeys(item));
|
|
347
|
-
}
|
|
348
237
|
if (prop !== null && prop !== void 0 && prop.constructor === Object) {
|
|
349
238
|
return Object.keys(prop).reduce(
|
|
350
239
|
(accum, current) => ({
|
|
@@ -384,9 +273,8 @@ function unformatNumber(value) {
|
|
|
384
273
|
if (commasCount === 1 && !hasSpace && !hasDot) {
|
|
385
274
|
locale = string.length - 1 - commaIndex === 3 ? LOCALE_EN : LOCALE_RU;
|
|
386
275
|
}
|
|
387
|
-
if (locale === LOCALE_RU)
|
|
276
|
+
if (locale === LOCALE_RU)
|
|
388
277
|
return Number(string.replaceAll(" ", "").replace(",", "."));
|
|
389
|
-
}
|
|
390
278
|
if (locale === LOCALE_EN)
|
|
391
279
|
return Number(string.replaceAll(",", ""));
|
|
392
280
|
return value;
|
|
@@ -397,9 +285,8 @@ function UiComponentsResolver(options = {}) {
|
|
|
397
285
|
return (name) => {
|
|
398
286
|
const componentName = prefix && name.startsWith(prefix) ? name.substring(prefix.length) : name;
|
|
399
287
|
const isUiComponent = componentName.startsWith("Ui");
|
|
400
|
-
if (isUiComponent)
|
|
288
|
+
if (isUiComponent)
|
|
401
289
|
return { name: componentName, from: "@karta.io/ui-components" };
|
|
402
|
-
}
|
|
403
290
|
};
|
|
404
291
|
}
|
|
405
292
|
|
|
@@ -447,9 +334,7 @@ function useAsyncItems({
|
|
|
447
334
|
queryKey: getQueryKey(),
|
|
448
335
|
queryFn: () => call(core.toValue(params), config)
|
|
449
336
|
});
|
|
450
|
-
const items = vue.computed(
|
|
451
|
-
() => data.value?.results || []
|
|
452
|
-
);
|
|
337
|
+
const items = vue.computed(() => data.value?.results || []);
|
|
453
338
|
const count = vue.ref(0);
|
|
454
339
|
vue.watch(
|
|
455
340
|
data,
|
|
@@ -526,12 +411,7 @@ function useAsyncMultiselect({
|
|
|
526
411
|
color: "#b54708",
|
|
527
412
|
debug: true
|
|
528
413
|
});
|
|
529
|
-
const paramsForLogger = {
|
|
530
|
-
queryKey,
|
|
531
|
-
dataItemsKey,
|
|
532
|
-
dataItemIdKey,
|
|
533
|
-
dataCountKey
|
|
534
|
-
};
|
|
414
|
+
const paramsForLogger = { queryKey, dataItemsKey, dataItemIdKey, dataCountKey };
|
|
535
415
|
const reactiveData = vue.reactive({
|
|
536
416
|
search: "",
|
|
537
417
|
page: 1,
|
|
@@ -577,9 +457,8 @@ function useAsyncMultiselect({
|
|
|
577
457
|
);
|
|
578
458
|
return;
|
|
579
459
|
}
|
|
580
|
-
if (!get__default(newValue, dataItemsKey) || get__default(newValue, dataCountKey) === void 0)
|
|
460
|
+
if (!get__default(newValue, dataItemsKey) || get__default(newValue, dataCountKey) === void 0)
|
|
581
461
|
return;
|
|
582
|
-
}
|
|
583
462
|
count.value = get__default(newValue, dataCountKey, 0);
|
|
584
463
|
const newItems = get__default(newValue, dataItemsKey);
|
|
585
464
|
itemsByPages.value = {
|
|
@@ -610,9 +489,8 @@ function useAsyncMultiselect({
|
|
|
610
489
|
const items = vue.computed(() => {
|
|
611
490
|
if (!itemsByPages.value)
|
|
612
491
|
return selectedItemsCached.value;
|
|
613
|
-
if (!Object.keys(itemsByPages.value).length)
|
|
492
|
+
if (!Object.keys(itemsByPages.value).length)
|
|
614
493
|
return selectedItemsCached.value;
|
|
615
|
-
}
|
|
616
494
|
const itemsByPagesAsArray = Object.values(itemsByPages.value).reduce(
|
|
617
495
|
(acc, item) => [...acc, ...item],
|
|
618
496
|
[]
|
|
@@ -628,7 +506,7 @@ function useAsyncMultiselect({
|
|
|
628
506
|
if (!items.value.length)
|
|
629
507
|
return [];
|
|
630
508
|
if (!mapOptionCallback)
|
|
631
|
-
return items.value;
|
|
509
|
+
return this.items.value;
|
|
632
510
|
return items.value.map(mapOptionCallback);
|
|
633
511
|
});
|
|
634
512
|
const hasNextPage = vue.computed(() => count.value > items.value.length);
|
|
@@ -647,28 +525,6 @@ function useAsyncMultiselect({
|
|
|
647
525
|
search.value = value;
|
|
648
526
|
updateSearchWithDebounce(value);
|
|
649
527
|
};
|
|
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
|
-
};
|
|
672
528
|
if (vue.isRef(selectedValues)) {
|
|
673
529
|
vue.watch(selectedValues, async (newSelectedValues) => {
|
|
674
530
|
if (!newSelectedValues.length) {
|
|
@@ -709,9 +565,7 @@ function useAsyncMultiselect({
|
|
|
709
565
|
isFetching,
|
|
710
566
|
isLoading,
|
|
711
567
|
loadPage,
|
|
712
|
-
updateSearch
|
|
713
|
-
refetch,
|
|
714
|
-
reload
|
|
568
|
+
updateSearch
|
|
715
569
|
};
|
|
716
570
|
}
|
|
717
571
|
|
|
@@ -743,9 +597,7 @@ function useAsyncSelect({
|
|
|
743
597
|
const loadWAC = () => call({
|
|
744
598
|
page: reactiveData.page,
|
|
745
599
|
search: reactiveData.search,
|
|
746
|
-
...reactiveData.selectedValue && {
|
|
747
|
-
includedIds: [reactiveData.selectedValue]
|
|
748
|
-
},
|
|
600
|
+
...reactiveData.selectedValue && { includedIds: [reactiveData.selectedValue] },
|
|
749
601
|
...reactiveData.params && { ...JSON.parse(reactiveData.params) }
|
|
750
602
|
});
|
|
751
603
|
const { data, isFetching, isLoading } = vueQuery.useQuery({
|
|
@@ -773,9 +625,8 @@ function useAsyncSelect({
|
|
|
773
625
|
);
|
|
774
626
|
return;
|
|
775
627
|
}
|
|
776
|
-
if (!get__default(newValue, dataItemsKey) || get__default(newValue, dataCountKey) === void 0)
|
|
628
|
+
if (!get__default(newValue, dataItemsKey) || get__default(newValue, dataCountKey) === void 0)
|
|
777
629
|
return;
|
|
778
|
-
}
|
|
779
630
|
count.value = get__default(newValue, dataCountKey, 0);
|
|
780
631
|
const newItems = get__default(newValue, dataItemsKey);
|
|
781
632
|
itemsByPages.value = {
|
|
@@ -805,7 +656,7 @@ function useAsyncSelect({
|
|
|
805
656
|
if (!items.value.length)
|
|
806
657
|
return [];
|
|
807
658
|
if (!mapOptionCallback)
|
|
808
|
-
return items.value;
|
|
659
|
+
return this.items.value;
|
|
809
660
|
return items.value.map(mapOptionCallback);
|
|
810
661
|
});
|
|
811
662
|
const hasNextPage = vue.computed(() => count.value > items.value.length);
|
|
@@ -820,28 +671,6 @@ function useAsyncSelect({
|
|
|
820
671
|
search.value = value;
|
|
821
672
|
updateSearchWithDebounce(value);
|
|
822
673
|
};
|
|
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
|
-
};
|
|
845
674
|
if (vue.isRef(selectedValue)) {
|
|
846
675
|
vue.watch(selectedValue, (newSelectedValue) => {
|
|
847
676
|
reactiveData.page = 1;
|
|
@@ -865,22 +694,20 @@ function useAsyncSelect({
|
|
|
865
694
|
isFetching,
|
|
866
695
|
isLoading,
|
|
867
696
|
loadPage,
|
|
868
|
-
updateSearch
|
|
869
|
-
refetch,
|
|
870
|
-
reload
|
|
697
|
+
updateSearch
|
|
871
698
|
};
|
|
872
699
|
}
|
|
873
700
|
|
|
874
701
|
function useBreakpoint() {
|
|
875
702
|
const breakpoints = core.useBreakpoints(commonData.BREAKPOINTS);
|
|
876
703
|
const isMobile = breakpoints.smaller("sm");
|
|
877
|
-
const isDesktop = breakpoints.
|
|
878
|
-
const isGreaterXxs = breakpoints.
|
|
879
|
-
const isGreaterXs = breakpoints.
|
|
880
|
-
const isGreaterSm = breakpoints.
|
|
881
|
-
const isGreaterMd = breakpoints.
|
|
882
|
-
const isGreaterLg = breakpoints.
|
|
883
|
-
const isGreaterXl = breakpoints.
|
|
704
|
+
const isDesktop = breakpoints.greater("md");
|
|
705
|
+
const isGreaterXxs = breakpoints.greater("xxs");
|
|
706
|
+
const isGreaterXs = breakpoints.greater("xs");
|
|
707
|
+
const isGreaterSm = breakpoints.greater("sm");
|
|
708
|
+
const isGreaterMd = breakpoints.greater("md");
|
|
709
|
+
const isGreaterLg = breakpoints.greater("lg");
|
|
710
|
+
const isGreaterXl = breakpoints.greater("xl");
|
|
884
711
|
return {
|
|
885
712
|
isMobile,
|
|
886
713
|
isDesktop,
|
|
@@ -947,9 +774,7 @@ function useDayjs(timezone) {
|
|
|
947
774
|
|
|
948
775
|
function parseVersion(version) {
|
|
949
776
|
if (typeof version !== "string" && typeof version !== "number") {
|
|
950
|
-
throw new TypeError(
|
|
951
|
-
"Browser version must be type of string, number or negative boolean"
|
|
952
|
-
);
|
|
777
|
+
throw new TypeError("Browser version must be type of string, number or negative boolean");
|
|
953
778
|
}
|
|
954
779
|
const [major, minor = 0, patch = 0, build = 0] = typeof version === "string" ? version.split(".").map(Number) : [version];
|
|
955
780
|
return {
|
|
@@ -1010,20 +835,9 @@ function useGlobalScroll() {
|
|
|
1010
835
|
|
|
1011
836
|
const CONFIRM_TEXT = "Are you sure you want to close? \nAll changes will be lost.";
|
|
1012
837
|
let dialogs = [];
|
|
1013
|
-
|
|
1014
|
-
function useDialog(options) {
|
|
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
|
-
}
|
|
838
|
+
function useDialog() {
|
|
1026
839
|
let appContext;
|
|
840
|
+
const logger = useLogger("use-dialog");
|
|
1027
841
|
const {
|
|
1028
842
|
isLocked: isGlobalScrollLocked,
|
|
1029
843
|
lock: lockGlobalScroll,
|
|
@@ -1031,27 +845,16 @@ function useDialog(options) {
|
|
|
1031
845
|
} = useGlobalScroll();
|
|
1032
846
|
const route = vueRouter.useRoute();
|
|
1033
847
|
const router = vueRouter.useRouter();
|
|
1034
|
-
const
|
|
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
|
-
};
|
|
848
|
+
const HASH_PREFIX = "#ud_";
|
|
1046
849
|
const parseHash = (hash, componentName) => {
|
|
1047
850
|
if (!hash)
|
|
1048
851
|
return void 0;
|
|
1049
|
-
if (!hash.includes(
|
|
852
|
+
if (!hash.includes(HASH_PREFIX))
|
|
1050
853
|
return void 0;
|
|
1051
854
|
let dataFromHash;
|
|
1052
855
|
try {
|
|
1053
|
-
dataFromHash = JSON.parse(window.atob(hash.slice(
|
|
1054
|
-
} catch (
|
|
856
|
+
dataFromHash = JSON.parse(window.atob(hash.slice(HASH_PREFIX.length)));
|
|
857
|
+
} catch (error) {
|
|
1055
858
|
logger.warn("*parseHash* cant parse hash");
|
|
1056
859
|
}
|
|
1057
860
|
if (typeof dataFromHash !== "object")
|
|
@@ -1098,7 +901,7 @@ function useDialog(options) {
|
|
|
1098
901
|
vnode2.component.props.modelValue = value;
|
|
1099
902
|
if (!value && route?.hash) {
|
|
1100
903
|
const dataFromHash = parseHash(route.hash, component.name);
|
|
1101
|
-
if (dataFromHash
|
|
904
|
+
if (dataFromHash)
|
|
1102
905
|
clearHash();
|
|
1103
906
|
}
|
|
1104
907
|
if (!value && (dialogs.length === 1 || layer === 0) && isGlobalScrollLocked.value) {
|
|
@@ -1114,7 +917,7 @@ function useDialog(options) {
|
|
|
1114
917
|
if (!route?.hash)
|
|
1115
918
|
return;
|
|
1116
919
|
const dataFromHash = parseHash(route.hash, component.name);
|
|
1117
|
-
if (dataFromHash
|
|
920
|
+
if (dataFromHash)
|
|
1118
921
|
clearHash();
|
|
1119
922
|
};
|
|
1120
923
|
vnode2.props.onDestroy = () => {
|
|
@@ -1188,11 +991,6 @@ function useDialog(options) {
|
|
|
1188
991
|
const getInstance = (uuid) => {
|
|
1189
992
|
return dialogs.find((item) => item.uuid === uuid)?.vnode;
|
|
1190
993
|
};
|
|
1191
|
-
const getLayer = (uuid) => {
|
|
1192
|
-
if (!dialogs.length)
|
|
1193
|
-
return 0;
|
|
1194
|
-
return dialogs.find((dialog) => dialog.uuid === uuid)?.layer || 0;
|
|
1195
|
-
};
|
|
1196
994
|
const isOnTop = (uuid) => {
|
|
1197
995
|
if (!dialogs.length)
|
|
1198
996
|
return false;
|
|
@@ -1207,10 +1005,15 @@ function useDialog(options) {
|
|
|
1207
1005
|
component,
|
|
1208
1006
|
props
|
|
1209
1007
|
}) => {
|
|
1008
|
+
const data = {
|
|
1009
|
+
name: component.name,
|
|
1010
|
+
layer,
|
|
1011
|
+
props
|
|
1012
|
+
};
|
|
1210
1013
|
router.push({
|
|
1211
1014
|
name: route.name || void 0,
|
|
1212
1015
|
query: route.query,
|
|
1213
|
-
hash:
|
|
1016
|
+
hash: `${HASH_PREFIX}${window.btoa(JSON.stringify(data))}`
|
|
1214
1017
|
});
|
|
1215
1018
|
};
|
|
1216
1019
|
const watchHash = ({
|
|
@@ -1255,14 +1058,10 @@ function useDialog(options) {
|
|
|
1255
1058
|
return {
|
|
1256
1059
|
open,
|
|
1257
1060
|
getInstance,
|
|
1258
|
-
getLayer,
|
|
1259
1061
|
close,
|
|
1260
1062
|
closeAll,
|
|
1261
1063
|
showConfirm,
|
|
1262
1064
|
isOnTop,
|
|
1263
|
-
genHash,
|
|
1264
|
-
parseHash,
|
|
1265
|
-
clearHash,
|
|
1266
1065
|
openByHash,
|
|
1267
1066
|
watchHash
|
|
1268
1067
|
};
|
|
@@ -1275,7 +1074,10 @@ const QS_STRINGIFY_PARAMS = {
|
|
|
1275
1074
|
addQueryPrefix: true
|
|
1276
1075
|
};
|
|
1277
1076
|
const isOpen = vue.ref(false);
|
|
1278
|
-
function useFilters({
|
|
1077
|
+
function useFilters({
|
|
1078
|
+
config,
|
|
1079
|
+
initialFilters
|
|
1080
|
+
}) {
|
|
1279
1081
|
const router = vueRouter.useRouter();
|
|
1280
1082
|
const route = vueRouter.useRoute();
|
|
1281
1083
|
const parseRouteQuery = (query) => qs__default.parse(query ?? route.query);
|
|
@@ -1283,43 +1085,35 @@ function useFilters({ config, initialFilters }) {
|
|
|
1283
1085
|
const parsedRouteQuery = parseRouteQuery();
|
|
1284
1086
|
if (!parsedRouteQuery.filters)
|
|
1285
1087
|
return void 0;
|
|
1286
|
-
return Object.entries(config).reduce(
|
|
1287
|
-
(
|
|
1288
|
-
|
|
1088
|
+
return Object.entries(config).reduce((accum, [currentKey, currentValue]) => {
|
|
1089
|
+
if (!parsedRouteQuery.filters[currentKey])
|
|
1090
|
+
return accum;
|
|
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)
|
|
1289
1095
|
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
|
-
}
|
|
1302
1096
|
return {
|
|
1303
1097
|
...accum,
|
|
1304
|
-
[currentKey]:
|
|
1098
|
+
[currentKey]: checkedValue
|
|
1305
1099
|
};
|
|
1306
|
-
}
|
|
1307
|
-
{
|
|
1308
|
-
|
|
1100
|
+
}
|
|
1101
|
+
return {
|
|
1102
|
+
...accum,
|
|
1103
|
+
[currentKey]: parsedRouteQuery.filters[currentKey]
|
|
1104
|
+
};
|
|
1105
|
+
}, {});
|
|
1309
1106
|
});
|
|
1310
1107
|
const filtersCount = vue.computed(
|
|
1311
1108
|
() => filtersFromQuery.value ? Object.keys(filtersFromQuery.value).length : 0
|
|
1312
1109
|
);
|
|
1313
1110
|
const setQueryFromFilters = (filters) => {
|
|
1314
1111
|
const parsedRouteQuery = parseRouteQuery();
|
|
1315
|
-
const filteredValue = Object.entries(filters).reduce(
|
|
1316
|
-
(
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
},
|
|
1321
|
-
{}
|
|
1322
|
-
);
|
|
1112
|
+
const filteredValue = Object.entries(filters).reduce((accum, [currentKey, currentValue]) => {
|
|
1113
|
+
if (!currentValue?.length)
|
|
1114
|
+
return accum;
|
|
1115
|
+
return { ...accum, [currentKey]: currentValue };
|
|
1116
|
+
}, {});
|
|
1323
1117
|
const query = qs__default.stringify(
|
|
1324
1118
|
{
|
|
1325
1119
|
...parsedRouteQuery,
|
|
@@ -1328,7 +1122,7 @@ function useFilters({ config, initialFilters }) {
|
|
|
1328
1122
|
},
|
|
1329
1123
|
QS_STRINGIFY_PARAMS
|
|
1330
1124
|
);
|
|
1331
|
-
router.push(query
|
|
1125
|
+
router.push(query);
|
|
1332
1126
|
};
|
|
1333
1127
|
const getValidatedParams = (query) => {
|
|
1334
1128
|
const parsedRouteQuery = parseRouteQuery(query);
|
|
@@ -1356,15 +1150,12 @@ function useFilters({ config, initialFilters }) {
|
|
|
1356
1150
|
});
|
|
1357
1151
|
};
|
|
1358
1152
|
const updateMany = (filters) => {
|
|
1359
|
-
const newFilters = Object.entries(filters).reduce(
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
},
|
|
1366
|
-
{}
|
|
1367
|
-
);
|
|
1153
|
+
const newFilters = Object.entries(filters).reduce((accum, [currentKey, currentValue]) => {
|
|
1154
|
+
return {
|
|
1155
|
+
...accum,
|
|
1156
|
+
[currentKey]: currentValue ? String(currentValue) : void 0
|
|
1157
|
+
};
|
|
1158
|
+
}, {});
|
|
1368
1159
|
setQueryFromFilters({
|
|
1369
1160
|
...filtersModel.value,
|
|
1370
1161
|
...newFilters
|
|
@@ -1540,7 +1331,7 @@ function usePanel() {
|
|
|
1540
1331
|
let dataFromHash;
|
|
1541
1332
|
try {
|
|
1542
1333
|
dataFromHash = JSON.parse(window.atob(newHash.slice(1)));
|
|
1543
|
-
} catch (
|
|
1334
|
+
} catch (error) {
|
|
1544
1335
|
logger.error("*watchHash* cant parse hash");
|
|
1545
1336
|
}
|
|
1546
1337
|
if (typeof dataFromHash !== "object")
|
|
@@ -1644,12 +1435,9 @@ function isStrictLength(value = 3, message) {
|
|
|
1644
1435
|
}
|
|
1645
1436
|
|
|
1646
1437
|
exports.AppComponentsResolver = AppComponentsResolver;
|
|
1647
|
-
exports.EnrichError = EnrichError;
|
|
1648
1438
|
exports.UiComponentsResolver = UiComponentsResolver;
|
|
1649
1439
|
exports.camelizeKeys = camelizeKeys;
|
|
1650
1440
|
exports.convertEnumToOptions = convertEnumToOptions;
|
|
1651
|
-
exports.formatErrorDataMessage = formatErrorDataMessage;
|
|
1652
|
-
exports.formatErrorForNotify = formatErrorForNotify;
|
|
1653
1441
|
exports.formatMoney = formatMoney;
|
|
1654
1442
|
exports.genHash = genHash;
|
|
1655
1443
|
exports.genRandomNumber = genRandomNumber;
|
|
@@ -1660,10 +1448,8 @@ exports.getPaginationLimit = getPaginationLimit;
|
|
|
1660
1448
|
exports.getPaginationOffset = getPaginationOffset;
|
|
1661
1449
|
exports.getPaginationPages = getPaginationPages;
|
|
1662
1450
|
exports.getPaginationParams = getPaginationParams;
|
|
1663
|
-
exports.getStatusMessage = getStatusMessage;
|
|
1664
1451
|
exports.isElementIgnored = isElementIgnored;
|
|
1665
1452
|
exports.isEmptyObject = isEmptyObject;
|
|
1666
|
-
exports.isHtml = isHtml;
|
|
1667
1453
|
exports.isMax = isMax;
|
|
1668
1454
|
exports.isMin = isMin;
|
|
1669
1455
|
exports.isRequired = isRequired;
|