@karta.io/utils 1.0.0-beta.49 → 1.0.0-beta.5

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.mjs CHANGED
@@ -1,11 +1,10 @@
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';
6
- import { toValue, computed, ref, watch, reactive, isRef, nextTick, onBeforeUnmount, onMounted, getCurrentInstance, render, createVNode } from 'vue';
5
+ import { computed, ref, watch, reactive, isRef, nextTick, onBeforeUnmount, onMounted, getCurrentInstance, render, createVNode } from 'vue';
6
+ import { toValue, useDebounceFn, useBreakpoints } from '@vueuse/core';
7
7
  import { useQuery, useQueryClient } from '@tanstack/vue-query';
8
- import { useDebounceFn, useBreakpoints } from '@vueuse/core';
9
8
  import get from 'lodash/get.js';
10
9
  import has from 'lodash/has.js';
11
10
  import union from 'lodash/union.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,113 +58,13 @@ 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) return "";
125
- return Object.values(data).reduce((accum, current) => {
126
- if (current && typeof current === "string")
127
- return accum ? `${accum} | ${current}` : current;
128
- if (Array.isArray(current) && current.length) {
129
- const value = `${flatMap(current).join(" | ")}`;
130
- return accum ? `${accum} | ${value}` : value;
131
- }
132
- return accum;
133
- }, "");
134
- }
135
- function formatErrorForNotify(error) {
136
- if (!error) return;
137
- if (error.status >= 400 && error.status < 500) {
138
- let message = "";
139
- if (!error.data || typeof error.data === "string" && isHtml(error.data)) {
140
- message = error.statusMessage || error.message || getStatusMessage(error.status);
141
- } else if (typeof error.data === "string" && !isHtml(error.data)) {
142
- message = error.data;
143
- } else {
144
- message = formatErrorDataMessage(error.data);
145
- }
146
- return {
147
- title: "Request error",
148
- message
149
- };
150
- }
151
- if (error.status >= 500) {
152
- return {
153
- title: "Internal server error",
154
- message: error.statusMessage || error.message || getStatusMessage(error.status)
155
- };
156
- }
157
- if (error instanceof Error) {
158
- return {
159
- title: "Internal client error",
160
- message: error.message
161
- };
162
- }
163
- }
164
-
165
61
  function formatMoney(value, currency = CURRENCY_DEFAULT, options = {}) {
166
62
  const { locale = "en-US", defaultValue = 0, ...otherOptions } = options;
167
63
  try {
168
64
  let convertedValue = Number(value);
169
65
  if (value === null || Number.isNaN(convertedValue)) {
170
- if (defaultValue === "") return defaultValue;
66
+ if (defaultValue === "")
67
+ return defaultValue;
171
68
  convertedValue = Number(defaultValue);
172
69
  }
173
70
  const formatter = new Intl.NumberFormat(locale, {
@@ -178,7 +75,7 @@ function formatMoney(value, currency = CURRENCY_DEFAULT, options = {}) {
178
75
  ...otherOptions
179
76
  });
180
77
  return formatter.format(convertedValue);
181
- } catch (_error) {
78
+ } catch (error) {
182
79
  return defaultValue;
183
80
  }
184
81
  }
@@ -208,7 +105,7 @@ function genUUID() {
208
105
  r = (d2 + r) % 16 | 0;
209
106
  d2 = Math.floor(d2 / 16);
210
107
  }
211
- return (c === "x" ? r : r & 7 | 8).toString(16);
108
+ return (c == "x" ? r : r & 7 | 8).toString(16);
212
109
  });
213
110
  }
214
111
 
@@ -227,7 +124,8 @@ function getCardNumber(number, options) {
227
124
  }
228
125
 
229
126
  function getCountryFromPhone(phone) {
230
- if (!phone) return "";
127
+ if (!phone)
128
+ return "";
231
129
  const replacedPhone = phone.replace(/[a-zA-Z]/g, "");
232
130
  const phoneNumber = parsePhoneNumberFromString(replacedPhone);
233
131
  return phoneNumber?.country ?? "";
@@ -269,7 +167,8 @@ function mapDataObjectForFilters(data, options) {
269
167
  }
270
168
 
271
169
  function validateNumber(value, defaultValue) {
272
- if (value === "") return defaultValue;
170
+ if (value === "")
171
+ return defaultValue;
273
172
  return Number.isNaN(Number(value)) ? defaultValue : Number(value);
274
173
  }
275
174
 
@@ -286,9 +185,7 @@ function getPaginationParams({
286
185
  offset: validatedPage * validatedLimit - validatedLimit
287
186
  };
288
187
  }
289
- function getPaginationLimit({
290
- limit
291
- }) {
188
+ function getPaginationLimit({ limit }) {
292
189
  return validateNumber(limit, LIMIT_DEFAULT);
293
190
  }
294
191
  function getPaginationOffset({
@@ -307,19 +204,18 @@ function getPaginationPages({
307
204
  }
308
205
 
309
206
  function parsePhone(phone) {
310
- if (!phone || typeof phone !== "string") return "";
207
+ if (!phone || typeof phone !== "string")
208
+ return "";
311
209
  const replacedPhone = phone.replace(/[a-zA-Z]/g, "");
312
- if (replacedPhone.length === 1 && replacedPhone !== "+") {
210
+ if (replacedPhone.length === 1 && replacedPhone !== "+")
313
211
  return `+${replacedPhone}`;
314
- }
315
212
  const phoneNumber = parsePhoneNumberFromString(replacedPhone);
316
213
  return phoneNumber ? phoneNumber.formatInternational() : replacedPhone;
317
214
  }
318
215
 
319
216
  function snakelizeKeys(prop) {
320
- if (Array.isArray(prop)) {
217
+ if (Array.isArray(prop))
321
218
  return prop.map((item) => snakelizeKeys(item));
322
- }
323
219
  if (prop !== null && prop !== void 0 && prop.constructor === Object) {
324
220
  return Object.keys(prop).reduce(
325
221
  (accum, current) => ({
@@ -335,7 +231,8 @@ function snakelizeKeys(prop) {
335
231
  const LOCALE_RU = "ru-RU";
336
232
  const LOCALE_EN = "en-US";
337
233
  function unformatNumber(value) {
338
- if (!value || typeof value !== "string") return value;
234
+ if (!value || typeof value !== "string")
235
+ return value;
339
236
  const string = value.trim();
340
237
  let locale;
341
238
  const spaceIndex = string.lastIndexOf(" ");
@@ -345,18 +242,23 @@ function unformatNumber(value) {
345
242
  const hasComma = commaIndex !== -1;
346
243
  const hasDot = dotIndex !== -1;
347
244
  const commasCount = (string.match(/,/g) || []).length;
348
- if (!Number.isNaN(Number(string))) return Number(string);
349
- if (hasSpace && hasComma && commaIndex > spaceIndex) locale = LOCALE_RU;
350
- if (hasSpace && !hasComma && !hasDot) locale = LOCALE_RU;
351
- if (hasComma && hasDot && dotIndex > commaIndex) locale = LOCALE_EN;
352
- if (hasComma && !hasSpace && !hasDot && commasCount > 1) locale = LOCALE_EN;
245
+ if (!Number.isNaN(Number(string)))
246
+ return Number(string);
247
+ if (hasSpace && hasComma && commaIndex > spaceIndex)
248
+ locale = LOCALE_RU;
249
+ if (hasSpace && !hasComma && !hasDot)
250
+ locale = LOCALE_RU;
251
+ if (hasComma && hasDot && dotIndex > commaIndex)
252
+ locale = LOCALE_EN;
253
+ if (hasComma && !hasSpace && !hasDot && commasCount > 1)
254
+ locale = LOCALE_EN;
353
255
  if (commasCount === 1 && !hasSpace && !hasDot) {
354
256
  locale = string.length - 1 - commaIndex === 3 ? LOCALE_EN : LOCALE_RU;
355
257
  }
356
- if (locale === LOCALE_RU) {
258
+ if (locale === LOCALE_RU)
357
259
  return Number(string.replaceAll(" ", "").replace(",", "."));
358
- }
359
- if (locale === LOCALE_EN) return Number(string.replaceAll(",", ""));
260
+ if (locale === LOCALE_EN)
261
+ return Number(string.replaceAll(",", ""));
360
262
  return value;
361
263
  }
362
264
 
@@ -365,9 +267,8 @@ function UiComponentsResolver(options = {}) {
365
267
  return (name) => {
366
268
  const componentName = prefix && name.startsWith(prefix) ? name.substring(prefix.length) : name;
367
269
  const isUiComponent = componentName.startsWith("Ui");
368
- if (isUiComponent) {
270
+ if (isUiComponent)
369
271
  return { name: componentName, from: "@karta.io/ui-components" };
370
- }
371
272
  };
372
273
  }
373
274
 
@@ -375,7 +276,8 @@ function useAbortController(callback) {
375
276
  let controller = null;
376
277
  return {
377
278
  async call(...args) {
378
- if (controller) controller.abort();
279
+ if (controller)
280
+ controller.abort();
379
281
  controller = new AbortController();
380
282
  let response;
381
283
  if (args.length > 0) {
@@ -391,7 +293,8 @@ function useAbortController(callback) {
391
293
  return response;
392
294
  },
393
295
  abort() {
394
- if (!controller) return;
296
+ if (!controller)
297
+ return;
395
298
  controller.abort();
396
299
  controller = null;
397
300
  },
@@ -413,14 +316,13 @@ function useAsyncItems({
413
316
  queryKey: getQueryKey(),
414
317
  queryFn: () => call(toValue(params), config)
415
318
  });
416
- const items = computed(
417
- () => data.value?.results || []
418
- );
319
+ const items = computed(() => data.value?.results || []);
419
320
  const count = ref(0);
420
321
  watch(
421
322
  data,
422
323
  (newValue) => {
423
- if (newValue === void 0 || newValue.count === void 0) return;
324
+ if (newValue === void 0 || newValue.count === void 0)
325
+ return;
424
326
  count.value = newValue.count;
425
327
  },
426
328
  { immediate: true }
@@ -447,18 +349,23 @@ function useAsyncItems({
447
349
  }
448
350
 
449
351
  function isEnabled(options) {
450
- if (options?.debug !== void 0) return options.debug;
352
+ if (options?.debug !== void 0)
353
+ return options.debug;
451
354
  const isBrowser = typeof window !== "undefined" && typeof window.document !== "undefined";
452
355
  if (isBrowser) {
453
356
  const debug = localStorage.getItem("debug");
454
- if (debug === "true") return true;
455
- if (debug === "false") return false;
357
+ if (debug === "true")
358
+ return true;
359
+ if (debug === "false")
360
+ return false;
456
361
  }
457
362
  const isNode = typeof process !== "undefined" && process.versions != null && process.versions.node != null;
458
363
  if (isNode) {
459
364
  const debug = process.env.NODE_DEBUG;
460
- if (debug === "true") return true;
461
- if (debug === "false") return false;
365
+ if (debug === "true")
366
+ return true;
367
+ if (debug === "false")
368
+ return false;
462
369
  }
463
370
  return false;
464
371
  }
@@ -486,12 +393,7 @@ function useAsyncMultiselect({
486
393
  color: "#b54708",
487
394
  debug: true
488
395
  });
489
- const paramsForLogger = {
490
- queryKey,
491
- dataItemsKey,
492
- dataItemIdKey,
493
- dataCountKey
494
- };
396
+ const paramsForLogger = { queryKey, dataItemsKey, dataItemIdKey, dataCountKey };
495
397
  const reactiveData = reactive({
496
398
  search: "",
497
399
  page: 1,
@@ -521,7 +423,8 @@ function useAsyncMultiselect({
521
423
  watch(
522
424
  data,
523
425
  (newValue) => {
524
- if (!newValue) return;
426
+ if (!newValue)
427
+ return;
525
428
  if (!has(newValue, dataItemsKey)) {
526
429
  logger.warn(
527
430
  `Unable to find key *"${dataItemsKey}"* (property "dataItemsKey") in data object from API.`,
@@ -536,9 +439,8 @@ function useAsyncMultiselect({
536
439
  );
537
440
  return;
538
441
  }
539
- if (!get(newValue, dataItemsKey) || get(newValue, dataCountKey) === void 0) {
442
+ if (!get(newValue, dataItemsKey) || get(newValue, dataCountKey) === void 0)
540
443
  return;
541
- }
542
444
  count.value = get(newValue, dataCountKey, 0);
543
445
  const newItems = get(newValue, dataItemsKey);
544
446
  itemsByPages.value = {
@@ -567,10 +469,10 @@ function useAsyncMultiselect({
567
469
  { immediate: true }
568
470
  );
569
471
  const items = computed(() => {
570
- if (!itemsByPages.value) return selectedItemsCached.value;
571
- if (!Object.keys(itemsByPages.value).length) {
472
+ if (!itemsByPages.value)
473
+ return selectedItemsCached.value;
474
+ if (!Object.keys(itemsByPages.value).length)
572
475
  return selectedItemsCached.value;
573
- }
574
476
  const itemsByPagesAsArray = Object.values(itemsByPages.value).reduce(
575
477
  (acc, item) => [...acc, ...item],
576
478
  []
@@ -583,8 +485,10 @@ function useAsyncMultiselect({
583
485
  return [...itemsAsMap.values()];
584
486
  });
585
487
  const options = computed(() => {
586
- if (!items.value.length) return [];
587
- if (!mapOptionCallback) return items.value;
488
+ if (!items.value.length)
489
+ return [];
490
+ if (!mapOptionCallback)
491
+ return this.items.value;
588
492
  return items.value.map(mapOptionCallback);
589
493
  });
590
494
  const hasNextPage = computed(() => count.value > items.value.length);
@@ -603,28 +507,6 @@ function useAsyncMultiselect({
603
507
  search.value = value;
604
508
  updateSearchWithDebounce(value);
605
509
  };
606
- const queryClient = useQueryClient();
607
- const refetch = () => {
608
- if (reactiveData.page !== 1) {
609
- queryClient.invalidateQueries({
610
- queryKey: [queryKey],
611
- refetchType: "none"
612
- });
613
- loadPage(1);
614
- } else {
615
- queryClient.invalidateQueries({
616
- queryKey: [queryKey]
617
- });
618
- }
619
- };
620
- const reload = () => {
621
- if (reactiveData.page !== 1) {
622
- queryClient.removeQueries({ queryKey: [queryKey] });
623
- loadPage(1);
624
- } else {
625
- queryClient.resetQueries({ queryKey: [queryKey] });
626
- }
627
- };
628
510
  if (isRef(selectedValues)) {
629
511
  watch(selectedValues, async (newSelectedValues) => {
630
512
  if (!newSelectedValues.length) {
@@ -665,9 +547,7 @@ function useAsyncMultiselect({
665
547
  isFetching,
666
548
  isLoading,
667
549
  loadPage,
668
- updateSearch,
669
- refetch,
670
- reload
550
+ updateSearch
671
551
  };
672
552
  }
673
553
 
@@ -699,9 +579,7 @@ function useAsyncSelect({
699
579
  const loadWAC = () => call({
700
580
  page: reactiveData.page,
701
581
  search: reactiveData.search,
702
- ...reactiveData.selectedValue && {
703
- includedIds: [reactiveData.selectedValue]
704
- },
582
+ ...reactiveData.selectedValue && { includedIds: [reactiveData.selectedValue] },
705
583
  ...reactiveData.params && { ...JSON.parse(reactiveData.params) }
706
584
  });
707
585
  const { data, isFetching, isLoading } = useQuery({
@@ -713,7 +591,8 @@ function useAsyncSelect({
713
591
  watch(
714
592
  data,
715
593
  (newValue) => {
716
- if (!newValue) return;
594
+ if (!newValue)
595
+ return;
717
596
  if (!has(newValue, dataItemsKey)) {
718
597
  logger.warn(
719
598
  `Unable to find key *"${dataItemsKey}"* (property "dataItemsKey") in data object from API.`,
@@ -728,9 +607,8 @@ function useAsyncSelect({
728
607
  );
729
608
  return;
730
609
  }
731
- if (!get(newValue, dataItemsKey) || get(newValue, dataCountKey) === void 0) {
610
+ if (!get(newValue, dataItemsKey) || get(newValue, dataCountKey) === void 0)
732
611
  return;
733
- }
734
612
  count.value = get(newValue, dataCountKey, 0);
735
613
  const newItems = get(newValue, dataItemsKey);
736
614
  itemsByPages.value = {
@@ -747,16 +625,20 @@ function useAsyncSelect({
747
625
  { immediate: true }
748
626
  );
749
627
  const items = computed(() => {
750
- if (!itemsByPages.value) return [];
751
- if (!Object.keys(itemsByPages.value).length) return [];
628
+ if (!itemsByPages.value)
629
+ return [];
630
+ if (!Object.keys(itemsByPages.value).length)
631
+ return [];
752
632
  return Object.values(itemsByPages.value).reduce(
753
633
  (acc, item) => [...acc, ...item],
754
634
  []
755
635
  );
756
636
  });
757
637
  const options = computed(() => {
758
- if (!items.value.length) return [];
759
- if (!mapOptionCallback) return items.value;
638
+ if (!items.value.length)
639
+ return [];
640
+ if (!mapOptionCallback)
641
+ return this.items.value;
760
642
  return items.value.map(mapOptionCallback);
761
643
  });
762
644
  const hasNextPage = computed(() => count.value > items.value.length);
@@ -771,28 +653,6 @@ function useAsyncSelect({
771
653
  search.value = value;
772
654
  updateSearchWithDebounce(value);
773
655
  };
774
- const queryClient = useQueryClient();
775
- const refetch = () => {
776
- if (reactiveData.page !== 1) {
777
- queryClient.invalidateQueries({
778
- queryKey: [queryKey],
779
- refetchType: "none"
780
- });
781
- loadPage(1);
782
- } else {
783
- queryClient.invalidateQueries({
784
- queryKey: [queryKey]
785
- });
786
- }
787
- };
788
- const reload = () => {
789
- if (reactiveData.page !== 1) {
790
- queryClient.removeQueries({ queryKey: [queryKey] });
791
- loadPage(1);
792
- } else {
793
- queryClient.resetQueries({ queryKey: [queryKey] });
794
- }
795
- };
796
656
  if (isRef(selectedValue)) {
797
657
  watch(selectedValue, (newSelectedValue) => {
798
658
  reactiveData.page = 1;
@@ -816,22 +676,20 @@ function useAsyncSelect({
816
676
  isFetching,
817
677
  isLoading,
818
678
  loadPage,
819
- updateSearch,
820
- refetch,
821
- reload
679
+ updateSearch
822
680
  };
823
681
  }
824
682
 
825
683
  function useBreakpoint() {
826
684
  const breakpoints = useBreakpoints(BREAKPOINTS);
827
685
  const isMobile = breakpoints.smaller("sm");
828
- const isDesktop = breakpoints.greaterOrEqual("md");
829
- const isGreaterXxs = breakpoints.greaterOrEqual("xxs");
830
- const isGreaterXs = breakpoints.greaterOrEqual("xs");
831
- const isGreaterSm = breakpoints.greaterOrEqual("sm");
832
- const isGreaterMd = breakpoints.greaterOrEqual("md");
833
- const isGreaterLg = breakpoints.greaterOrEqual("lg");
834
- const isGreaterXl = breakpoints.greaterOrEqual("xl");
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");
835
693
  return {
836
694
  isMobile,
837
695
  isDesktop,
@@ -846,10 +704,14 @@ function useBreakpoint() {
846
704
 
847
705
  function _bem(block, blockSuffix, element, modifier, modifierValue) {
848
706
  let cls = block;
849
- if (blockSuffix) cls += `-${blockSuffix}`;
850
- if (element) cls += `__${element}`;
851
- if (modifier) cls += `_${modifier}`;
852
- if (modifierValue) cls += `_${modifierValue}`;
707
+ if (blockSuffix)
708
+ cls += `-${blockSuffix}`;
709
+ if (element)
710
+ cls += `__${element}`;
711
+ if (modifier)
712
+ cls += `_${modifier}`;
713
+ if (modifierValue)
714
+ cls += `_${modifierValue}`;
853
715
  return cls;
854
716
  }
855
717
  function useClassName(block) {
@@ -860,7 +722,8 @@ function useClassName(block) {
860
722
  const mv = (modifier, modifierValue, condition = true) => modifier && modifierValue && condition ? _bem(block, "", "", modifier, modifierValue) : "";
861
723
  const cssVar = (object) => {
862
724
  const styles = {};
863
- for (const key in object) styles[`--${block}-${key}`] = object[key];
725
+ for (const key in object)
726
+ styles[`--${block}-${key}`] = object[key];
864
727
  return styles;
865
728
  };
866
729
  const cssVarName = (name) => `--${block}-${name}`;
@@ -885,16 +748,15 @@ function useDayjs(timezone) {
885
748
  dayjs.updateLocale("en", {
886
749
  weekStart: 1
887
750
  });
888
- if (!timezone) return dayjs;
751
+ if (!timezone)
752
+ return dayjs;
889
753
  const dayjsExtended = (date, format, locale, strict) => dayjs(date, format, locale, strict).tz(timezone);
890
754
  return dayjsExtended;
891
755
  }
892
756
 
893
757
  function parseVersion(version) {
894
758
  if (typeof version !== "string" && typeof version !== "number") {
895
- throw new TypeError(
896
- "Browser version must be type of string, number or negative boolean"
897
- );
759
+ throw new TypeError("Browser version must be type of string, number or negative boolean");
898
760
  }
899
761
  const [major, minor = 0, patch = 0, build = 0] = typeof version === "string" ? version.split(".").map(Number) : [version];
900
762
  return {
@@ -906,7 +768,8 @@ function parseVersion(version) {
906
768
  }
907
769
  function isVersionLower(minimum, target) {
908
770
  for (const k of ["major", "minor", "patch"]) {
909
- if (minimum[k] !== target[k]) return minimum[k] > target[k];
771
+ if (minimum[k] !== target[k])
772
+ return minimum[k] > target[k];
910
773
  }
911
774
  return minimum.build > target.build;
912
775
  }
@@ -954,20 +817,9 @@ function useGlobalScroll() {
954
817
 
955
818
  const CONFIRM_TEXT = "Are you sure you want to close? \nAll changes will be lost.";
956
819
  let dialogs = [];
957
- const HASH_PREFIX = "#ud_";
958
- function useDialog(options) {
959
- const logger = useLogger("use-dialog");
960
- let hashPrefix = HASH_PREFIX;
961
- if (options?.hashPrefix) {
962
- if (options.hashPrefix.charAt(0) === "#") {
963
- hashPrefix = options?.hashPrefix;
964
- } else {
965
- logger.warn(
966
- `*hashPrefix* must start with "#". The default prefix "${HASH_PREFIX}" will be used`
967
- );
968
- }
969
- }
820
+ function useDialog() {
970
821
  let appContext;
822
+ const logger = useLogger("use-dialog");
971
823
  const {
972
824
  isLocked: isGlobalScrollLocked,
973
825
  lock: lockGlobalScroll,
@@ -975,33 +827,26 @@ function useDialog(options) {
975
827
  } = useGlobalScroll();
976
828
  const route = useRoute();
977
829
  const router = useRouter();
978
- const genHash = ({
979
- layer = 0,
980
- componentName,
981
- props
982
- }) => {
983
- const data = {
984
- name: componentName,
985
- layer,
986
- props
987
- };
988
- return `${hashPrefix}${window.btoa(JSON.stringify(data))}`;
989
- };
830
+ const HASH_PREFIX = "#ud_";
990
831
  const parseHash = (hash, componentName) => {
991
- if (!hash) return void 0;
992
- if (!hash.includes(hashPrefix)) return void 0;
832
+ if (!hash)
833
+ return void 0;
834
+ if (!hash.includes(HASH_PREFIX))
835
+ return void 0;
993
836
  let dataFromHash;
994
837
  try {
995
- dataFromHash = JSON.parse(window.atob(hash.slice(hashPrefix.length)));
996
- } catch (_error) {
838
+ dataFromHash = JSON.parse(window.atob(hash.slice(HASH_PREFIX.length)));
839
+ } catch (error) {
997
840
  logger.warn("*parseHash* cant parse hash");
998
841
  }
999
- if (typeof dataFromHash !== "object") return void 0;
842
+ if (typeof dataFromHash !== "object")
843
+ return void 0;
1000
844
  if (!dataFromHash.name) {
1001
845
  logger.warn("*parseHash* cant find component name in hash");
1002
846
  return void 0;
1003
847
  }
1004
- if (dataFromHash.name !== componentName) return void 0;
848
+ if (dataFromHash.name !== componentName)
849
+ return void 0;
1005
850
  return dataFromHash;
1006
851
  };
1007
852
  const clearHash = () => {
@@ -1038,7 +883,8 @@ function useDialog(options) {
1038
883
  vnode2.component.props.modelValue = value;
1039
884
  if (!value && route?.hash) {
1040
885
  const dataFromHash = parseHash(route.hash, component.name);
1041
- if (dataFromHash?.layer === layer) clearHash();
886
+ if (dataFromHash)
887
+ clearHash();
1042
888
  }
1043
889
  if (!value && (dialogs.length === 1 || layer === 0) && isGlobalScrollLocked.value) {
1044
890
  unlockGlobalScroll();
@@ -1047,11 +893,14 @@ function useDialog(options) {
1047
893
  };
1048
894
  }
1049
895
  vnode2.close = () => {
1050
- if (!vnode2 || !vnode2.component) return;
896
+ if (!vnode2 || !vnode2.component)
897
+ return;
1051
898
  vnode2.component.props.modelValue = false;
1052
- if (!route?.hash) return;
899
+ if (!route?.hash)
900
+ return;
1053
901
  const dataFromHash = parseHash(route.hash, component.name);
1054
- if (dataFromHash?.layer === layer) clearHash();
902
+ if (dataFromHash)
903
+ clearHash();
1055
904
  };
1056
905
  vnode2.props.onDestroy = () => {
1057
906
  render(null, el2);
@@ -1124,12 +973,9 @@ function useDialog(options) {
1124
973
  const getInstance = (uuid) => {
1125
974
  return dialogs.find((item) => item.uuid === uuid)?.vnode;
1126
975
  };
1127
- const getLayer = (uuid) => {
1128
- if (!dialogs.length) return 0;
1129
- return dialogs.find((dialog) => dialog.uuid === uuid)?.layer || 0;
1130
- };
1131
976
  const isOnTop = (uuid) => {
1132
- if (!dialogs.length) return false;
977
+ if (!dialogs.length)
978
+ return false;
1133
979
  const dialogsSorted = [...dialogs].sort((a, b) => b.layer - a.layer);
1134
980
  return dialogsSorted[0].uuid === uuid;
1135
981
  };
@@ -1141,10 +987,15 @@ function useDialog(options) {
1141
987
  component,
1142
988
  props
1143
989
  }) => {
990
+ const data = {
991
+ name: component.name,
992
+ layer,
993
+ props
994
+ };
1144
995
  router.push({
1145
996
  name: route.name || void 0,
1146
997
  query: route.query,
1147
- hash: genHash({ layer, props, componentName: component.name })
998
+ hash: `${HASH_PREFIX}${window.btoa(JSON.stringify(data))}`
1148
999
  });
1149
1000
  };
1150
1001
  const watchHash = ({
@@ -1156,12 +1007,14 @@ function useDialog(options) {
1156
1007
  () => route.hash,
1157
1008
  async (newHash) => {
1158
1009
  if (!newHash) {
1159
- if (!dialogs.length) return;
1010
+ if (!dialogs.length)
1011
+ return;
1160
1012
  closeAll();
1161
1013
  return;
1162
1014
  }
1163
1015
  const dataFromHash = parseHash(newHash, component.name);
1164
- if (!dataFromHash) return;
1016
+ if (!dataFromHash)
1017
+ return;
1165
1018
  logger.info("*watchHash* data from hash", dataFromHash);
1166
1019
  await nextTick();
1167
1020
  open({
@@ -1187,14 +1040,10 @@ function useDialog(options) {
1187
1040
  return {
1188
1041
  open,
1189
1042
  getInstance,
1190
- getLayer,
1191
1043
  close,
1192
1044
  closeAll,
1193
1045
  showConfirm,
1194
1046
  isOnTop,
1195
- genHash,
1196
- parseHash,
1197
- clearHash,
1198
1047
  openByHash,
1199
1048
  watchHash
1200
1049
  };
@@ -1207,47 +1056,46 @@ const QS_STRINGIFY_PARAMS = {
1207
1056
  addQueryPrefix: true
1208
1057
  };
1209
1058
  const isOpen = ref(false);
1210
- function useFilters({ config, initialFilters }) {
1059
+ function useFilters({
1060
+ config,
1061
+ initialFilters
1062
+ }) {
1211
1063
  const router = useRouter();
1212
1064
  const route = useRoute();
1213
1065
  const parseRouteQuery = (query) => qs.parse(query ?? route.query);
1214
1066
  const filtersFromQuery = computed(() => {
1215
1067
  const parsedRouteQuery = parseRouteQuery();
1216
- if (!parsedRouteQuery.filters) return void 0;
1217
- return Object.entries(config).reduce(
1218
- (accum, [currentKey, currentValue]) => {
1219
- if (!parsedRouteQuery.filters[currentKey]) return accum;
1220
- if (currentValue.type === "ARRAY" /* Array */) {
1221
- const splitValues = parsedRouteQuery.filters[currentKey].split(",");
1222
- const checkedValue = currentValue?.possibleValues ? splitValues.filter(
1223
- (k) => currentValue?.possibleValues?.includes(k)
1224
- ) : splitValues;
1225
- if (!checkedValue?.length) return accum;
1226
- return {
1227
- ...accum,
1228
- [currentKey]: checkedValue
1229
- };
1230
- }
1068
+ if (!parsedRouteQuery.filters)
1069
+ return void 0;
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)
1077
+ return accum;
1231
1078
  return {
1232
1079
  ...accum,
1233
- [currentKey]: parsedRouteQuery.filters[currentKey]
1080
+ [currentKey]: checkedValue
1234
1081
  };
1235
- },
1236
- {}
1237
- );
1082
+ }
1083
+ return {
1084
+ ...accum,
1085
+ [currentKey]: parsedRouteQuery.filters[currentKey]
1086
+ };
1087
+ }, {});
1238
1088
  });
1239
1089
  const filtersCount = computed(
1240
1090
  () => filtersFromQuery.value ? Object.keys(filtersFromQuery.value).length : 0
1241
1091
  );
1242
1092
  const setQueryFromFilters = (filters) => {
1243
1093
  const parsedRouteQuery = parseRouteQuery();
1244
- const filteredValue = Object.entries(filters).reduce(
1245
- (accum, [currentKey, currentValue]) => {
1246
- if (!currentValue?.length) return accum;
1247
- return { ...accum, [currentKey]: currentValue };
1248
- },
1249
- {}
1250
- );
1094
+ const filteredValue = Object.entries(filters).reduce((accum, [currentKey, currentValue]) => {
1095
+ if (!currentValue?.length)
1096
+ return accum;
1097
+ return { ...accum, [currentKey]: currentValue };
1098
+ }, {});
1251
1099
  const query = qs.stringify(
1252
1100
  {
1253
1101
  ...parsedRouteQuery,
@@ -1256,7 +1104,7 @@ function useFilters({ config, initialFilters }) {
1256
1104
  },
1257
1105
  QS_STRINGIFY_PARAMS
1258
1106
  );
1259
- router.push(query.replaceAll("#", ""));
1107
+ router.push(query);
1260
1108
  };
1261
1109
  const getValidatedParams = (query) => {
1262
1110
  const parsedRouteQuery = parseRouteQuery(query);
@@ -1284,15 +1132,12 @@ function useFilters({ config, initialFilters }) {
1284
1132
  });
1285
1133
  };
1286
1134
  const updateMany = (filters) => {
1287
- const newFilters = Object.entries(filters).reduce(
1288
- (accum, [currentKey, currentValue]) => {
1289
- return {
1290
- ...accum,
1291
- [currentKey]: currentValue ? String(currentValue) : void 0
1292
- };
1293
- },
1294
- {}
1295
- );
1135
+ const newFilters = Object.entries(filters).reduce((accum, [currentKey, currentValue]) => {
1136
+ return {
1137
+ ...accum,
1138
+ [currentKey]: currentValue ? String(currentValue) : void 0
1139
+ };
1140
+ }, {});
1296
1141
  setQueryFromFilters({
1297
1142
  ...filtersModel.value,
1298
1143
  ...newFilters
@@ -1468,15 +1313,17 @@ function usePanel() {
1468
1313
  let dataFromHash;
1469
1314
  try {
1470
1315
  dataFromHash = JSON.parse(window.atob(newHash.slice(1)));
1471
- } catch (_error) {
1316
+ } catch (error) {
1472
1317
  logger.error("*watchHash* cant parse hash");
1473
1318
  }
1474
- if (typeof dataFromHash !== "object") return;
1319
+ if (typeof dataFromHash !== "object")
1320
+ return;
1475
1321
  if (!dataFromHash.name) {
1476
1322
  logger.error("*watchHash* cant find component name in hash");
1477
1323
  return;
1478
1324
  }
1479
- if (dataFromHash.name !== component.name) return;
1325
+ if (dataFromHash.name !== component.name)
1326
+ return;
1480
1327
  logger.info("*watchHash* data from hash", dataFromHash);
1481
1328
  await nextTick();
1482
1329
  open({
@@ -1484,7 +1331,8 @@ function usePanel() {
1484
1331
  layer: dataFromHash.layer || 0,
1485
1332
  props: {
1486
1333
  "onUpdate:modelValue": (value) => {
1487
- if (value) return;
1334
+ if (value)
1335
+ return;
1488
1336
  router.push({
1489
1337
  name: route.name || void 0,
1490
1338
  query: route.query,
@@ -1518,7 +1366,8 @@ function usePanel() {
1518
1366
  }
1519
1367
 
1520
1368
  function validatePhone(rule, value) {
1521
- if (!value) return true;
1369
+ if (!value)
1370
+ return true;
1522
1371
  const phoneNumber = parsePhoneNumberFromString(value);
1523
1372
  return phoneNumber ? phoneNumber.isValid() : false;
1524
1373
  }
@@ -1567,4 +1416,4 @@ function isStrictLength(value = 3, message) {
1567
1416
  };
1568
1417
  }
1569
1418
 
1570
- export { AppComponentsResolver, EnrichError, UiComponentsResolver, camelizeKeys, convertEnumToOptions, formatErrorDataMessage, formatErrorForNotify, formatMoney, genHash, genRandomNumber, genUUID, getCardNumber, getCountryFromPhone, getPaginationLimit, getPaginationOffset, getPaginationPages, getPaginationParams, getStatusMessage, isElementIgnored, isEmptyObject, isHtml, 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 };
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 };