@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.cjs CHANGED
@@ -1,13 +1,12 @@
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');
8
7
  const vue = require('vue');
9
- const vueQuery = require('@tanstack/vue-query');
10
8
  const core = require('@vueuse/core');
9
+ const vueQuery = require('@tanstack/vue-query');
11
10
  const get = require('lodash/get.js');
12
11
  const has = require('lodash/has.js');
13
12
  const union = require('lodash/union.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,113 +76,13 @@ 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) return "";
144
- return Object.values(data).reduce((accum, current) => {
145
- if (current && typeof current === "string")
146
- return accum ? `${accum} | ${current}` : current;
147
- if (Array.isArray(current) && current.length) {
148
- const value = `${flatMap__default(current).join(" | ")}`;
149
- return accum ? `${accum} | ${value}` : value;
150
- }
151
- return accum;
152
- }, "");
153
- }
154
- function formatErrorForNotify(error) {
155
- if (!error) return;
156
- if (error.status >= 400 && error.status < 500) {
157
- let message = "";
158
- if (!error.data || typeof error.data === "string" && isHtml(error.data)) {
159
- message = error.statusMessage || error.message || getStatusMessage(error.status);
160
- } else if (typeof error.data === "string" && !isHtml(error.data)) {
161
- message = error.data;
162
- } else {
163
- message = formatErrorDataMessage(error.data);
164
- }
165
- return {
166
- title: "Request error",
167
- message
168
- };
169
- }
170
- if (error.status >= 500) {
171
- return {
172
- title: "Internal server error",
173
- message: error.statusMessage || error.message || getStatusMessage(error.status)
174
- };
175
- }
176
- if (error instanceof Error) {
177
- return {
178
- title: "Internal client error",
179
- message: error.message
180
- };
181
- }
182
- }
183
-
184
79
  function formatMoney(value, currency = commonData.CURRENCY_DEFAULT, options = {}) {
185
80
  const { locale = "en-US", defaultValue = 0, ...otherOptions } = options;
186
81
  try {
187
82
  let convertedValue = Number(value);
188
83
  if (value === null || Number.isNaN(convertedValue)) {
189
- if (defaultValue === "") return defaultValue;
84
+ if (defaultValue === "")
85
+ return defaultValue;
190
86
  convertedValue = Number(defaultValue);
191
87
  }
192
88
  const formatter = new Intl.NumberFormat(locale, {
@@ -197,7 +93,7 @@ function formatMoney(value, currency = commonData.CURRENCY_DEFAULT, options = {}
197
93
  ...otherOptions
198
94
  });
199
95
  return formatter.format(convertedValue);
200
- } catch (_error) {
96
+ } catch (error) {
201
97
  return defaultValue;
202
98
  }
203
99
  }
@@ -227,7 +123,7 @@ function genUUID() {
227
123
  r = (d2 + r) % 16 | 0;
228
124
  d2 = Math.floor(d2 / 16);
229
125
  }
230
- return (c === "x" ? r : r & 7 | 8).toString(16);
126
+ return (c == "x" ? r : r & 7 | 8).toString(16);
231
127
  });
232
128
  }
233
129
 
@@ -246,7 +142,8 @@ function getCardNumber(number, options) {
246
142
  }
247
143
 
248
144
  function getCountryFromPhone(phone) {
249
- if (!phone) return "";
145
+ if (!phone)
146
+ return "";
250
147
  const replacedPhone = phone.replace(/[a-zA-Z]/g, "");
251
148
  const phoneNumber = libphonenumberJs.parsePhoneNumberFromString(replacedPhone);
252
149
  return phoneNumber?.country ?? "";
@@ -288,7 +185,8 @@ function mapDataObjectForFilters(data, options) {
288
185
  }
289
186
 
290
187
  function validateNumber(value, defaultValue) {
291
- if (value === "") return defaultValue;
188
+ if (value === "")
189
+ return defaultValue;
292
190
  return Number.isNaN(Number(value)) ? defaultValue : Number(value);
293
191
  }
294
192
 
@@ -305,9 +203,7 @@ function getPaginationParams({
305
203
  offset: validatedPage * validatedLimit - validatedLimit
306
204
  };
307
205
  }
308
- function getPaginationLimit({
309
- limit
310
- }) {
206
+ function getPaginationLimit({ limit }) {
311
207
  return validateNumber(limit, LIMIT_DEFAULT);
312
208
  }
313
209
  function getPaginationOffset({
@@ -326,19 +222,18 @@ function getPaginationPages({
326
222
  }
327
223
 
328
224
  function parsePhone(phone) {
329
- if (!phone || typeof phone !== "string") return "";
225
+ if (!phone || typeof phone !== "string")
226
+ return "";
330
227
  const replacedPhone = phone.replace(/[a-zA-Z]/g, "");
331
- if (replacedPhone.length === 1 && replacedPhone !== "+") {
228
+ if (replacedPhone.length === 1 && replacedPhone !== "+")
332
229
  return `+${replacedPhone}`;
333
- }
334
230
  const phoneNumber = libphonenumberJs.parsePhoneNumberFromString(replacedPhone);
335
231
  return phoneNumber ? phoneNumber.formatInternational() : replacedPhone;
336
232
  }
337
233
 
338
234
  function snakelizeKeys(prop) {
339
- if (Array.isArray(prop)) {
235
+ if (Array.isArray(prop))
340
236
  return prop.map((item) => snakelizeKeys(item));
341
- }
342
237
  if (prop !== null && prop !== void 0 && prop.constructor === Object) {
343
238
  return Object.keys(prop).reduce(
344
239
  (accum, current) => ({
@@ -354,7 +249,8 @@ function snakelizeKeys(prop) {
354
249
  const LOCALE_RU = "ru-RU";
355
250
  const LOCALE_EN = "en-US";
356
251
  function unformatNumber(value) {
357
- if (!value || typeof value !== "string") return value;
252
+ if (!value || typeof value !== "string")
253
+ return value;
358
254
  const string = value.trim();
359
255
  let locale;
360
256
  const spaceIndex = string.lastIndexOf(" ");
@@ -364,18 +260,23 @@ function unformatNumber(value) {
364
260
  const hasComma = commaIndex !== -1;
365
261
  const hasDot = dotIndex !== -1;
366
262
  const commasCount = (string.match(/,/g) || []).length;
367
- if (!Number.isNaN(Number(string))) return Number(string);
368
- if (hasSpace && hasComma && commaIndex > spaceIndex) locale = LOCALE_RU;
369
- if (hasSpace && !hasComma && !hasDot) locale = LOCALE_RU;
370
- if (hasComma && hasDot && dotIndex > commaIndex) locale = LOCALE_EN;
371
- if (hasComma && !hasSpace && !hasDot && commasCount > 1) locale = LOCALE_EN;
263
+ if (!Number.isNaN(Number(string)))
264
+ return Number(string);
265
+ if (hasSpace && hasComma && commaIndex > spaceIndex)
266
+ locale = LOCALE_RU;
267
+ if (hasSpace && !hasComma && !hasDot)
268
+ locale = LOCALE_RU;
269
+ if (hasComma && hasDot && dotIndex > commaIndex)
270
+ locale = LOCALE_EN;
271
+ if (hasComma && !hasSpace && !hasDot && commasCount > 1)
272
+ locale = LOCALE_EN;
372
273
  if (commasCount === 1 && !hasSpace && !hasDot) {
373
274
  locale = string.length - 1 - commaIndex === 3 ? LOCALE_EN : LOCALE_RU;
374
275
  }
375
- if (locale === LOCALE_RU) {
276
+ if (locale === LOCALE_RU)
376
277
  return Number(string.replaceAll(" ", "").replace(",", "."));
377
- }
378
- if (locale === LOCALE_EN) return Number(string.replaceAll(",", ""));
278
+ if (locale === LOCALE_EN)
279
+ return Number(string.replaceAll(",", ""));
379
280
  return value;
380
281
  }
381
282
 
@@ -384,9 +285,8 @@ function UiComponentsResolver(options = {}) {
384
285
  return (name) => {
385
286
  const componentName = prefix && name.startsWith(prefix) ? name.substring(prefix.length) : name;
386
287
  const isUiComponent = componentName.startsWith("Ui");
387
- if (isUiComponent) {
288
+ if (isUiComponent)
388
289
  return { name: componentName, from: "@karta.io/ui-components" };
389
- }
390
290
  };
391
291
  }
392
292
 
@@ -394,7 +294,8 @@ function useAbortController(callback) {
394
294
  let controller = null;
395
295
  return {
396
296
  async call(...args) {
397
- if (controller) controller.abort();
297
+ if (controller)
298
+ controller.abort();
398
299
  controller = new AbortController();
399
300
  let response;
400
301
  if (args.length > 0) {
@@ -410,7 +311,8 @@ function useAbortController(callback) {
410
311
  return response;
411
312
  },
412
313
  abort() {
413
- if (!controller) return;
314
+ if (!controller)
315
+ return;
414
316
  controller.abort();
415
317
  controller = null;
416
318
  },
@@ -430,16 +332,15 @@ function useAsyncItems({
430
332
  const { call, abort } = useAbortController(apiMethod);
431
333
  const { isLoading, isFetching, isError, data, error } = vueQuery.useQuery({
432
334
  queryKey: getQueryKey(),
433
- queryFn: () => call(vue.toValue(params), config)
335
+ queryFn: () => call(core.toValue(params), config)
434
336
  });
435
- const items = vue.computed(
436
- () => data.value?.results || []
437
- );
337
+ const items = vue.computed(() => data.value?.results || []);
438
338
  const count = vue.ref(0);
439
339
  vue.watch(
440
340
  data,
441
341
  (newValue) => {
442
- if (newValue === void 0 || newValue.count === void 0) return;
342
+ if (newValue === void 0 || newValue.count === void 0)
343
+ return;
443
344
  count.value = newValue.count;
444
345
  },
445
346
  { immediate: true }
@@ -466,18 +367,23 @@ function useAsyncItems({
466
367
  }
467
368
 
468
369
  function isEnabled(options) {
469
- if (options?.debug !== void 0) return options.debug;
370
+ if (options?.debug !== void 0)
371
+ return options.debug;
470
372
  const isBrowser = typeof window !== "undefined" && typeof window.document !== "undefined";
471
373
  if (isBrowser) {
472
374
  const debug = localStorage.getItem("debug");
473
- if (debug === "true") return true;
474
- if (debug === "false") return false;
375
+ if (debug === "true")
376
+ return true;
377
+ if (debug === "false")
378
+ return false;
475
379
  }
476
380
  const isNode = typeof process !== "undefined" && process.versions != null && process.versions.node != null;
477
381
  if (isNode) {
478
382
  const debug = process.env.NODE_DEBUG;
479
- if (debug === "true") return true;
480
- if (debug === "false") return false;
383
+ if (debug === "true")
384
+ return true;
385
+ if (debug === "false")
386
+ return false;
481
387
  }
482
388
  return false;
483
389
  }
@@ -505,17 +411,12 @@ function useAsyncMultiselect({
505
411
  color: "#b54708",
506
412
  debug: true
507
413
  });
508
- const paramsForLogger = {
509
- queryKey,
510
- dataItemsKey,
511
- dataItemIdKey,
512
- dataCountKey
513
- };
414
+ const paramsForLogger = { queryKey, dataItemsKey, dataItemIdKey, dataCountKey };
514
415
  const reactiveData = vue.reactive({
515
416
  search: "",
516
417
  page: 1,
517
- selectedValues: vue.toValue(selectedValues),
518
- params: JSON.stringify(vue.toValue(params))
418
+ selectedValues: core.toValue(selectedValues),
419
+ params: JSON.stringify(core.toValue(params))
519
420
  });
520
421
  const search = vue.ref("");
521
422
  const { call, abort } = useAbortController(apiMethod);
@@ -540,7 +441,8 @@ function useAsyncMultiselect({
540
441
  vue.watch(
541
442
  data,
542
443
  (newValue) => {
543
- if (!newValue) return;
444
+ if (!newValue)
445
+ return;
544
446
  if (!has__default(newValue, dataItemsKey)) {
545
447
  logger.warn(
546
448
  `Unable to find key *"${dataItemsKey}"* (property "dataItemsKey") in data object from API.`,
@@ -555,9 +457,8 @@ function useAsyncMultiselect({
555
457
  );
556
458
  return;
557
459
  }
558
- if (!get__default(newValue, dataItemsKey) || get__default(newValue, dataCountKey) === void 0) {
460
+ if (!get__default(newValue, dataItemsKey) || get__default(newValue, dataCountKey) === void 0)
559
461
  return;
560
- }
561
462
  count.value = get__default(newValue, dataCountKey, 0);
562
463
  const newItems = get__default(newValue, dataItemsKey);
563
464
  itemsByPages.value = {
@@ -586,10 +487,10 @@ function useAsyncMultiselect({
586
487
  { immediate: true }
587
488
  );
588
489
  const items = vue.computed(() => {
589
- if (!itemsByPages.value) return selectedItemsCached.value;
590
- if (!Object.keys(itemsByPages.value).length) {
490
+ if (!itemsByPages.value)
491
+ return selectedItemsCached.value;
492
+ if (!Object.keys(itemsByPages.value).length)
591
493
  return selectedItemsCached.value;
592
- }
593
494
  const itemsByPagesAsArray = Object.values(itemsByPages.value).reduce(
594
495
  (acc, item) => [...acc, ...item],
595
496
  []
@@ -602,48 +503,28 @@ function useAsyncMultiselect({
602
503
  return [...itemsAsMap.values()];
603
504
  });
604
505
  const options = vue.computed(() => {
605
- if (!items.value.length) return [];
606
- if (!mapOptionCallback) return items.value;
506
+ if (!items.value.length)
507
+ return [];
508
+ if (!mapOptionCallback)
509
+ return this.items.value;
607
510
  return items.value.map(mapOptionCallback);
608
511
  });
609
512
  const hasNextPage = vue.computed(() => count.value > items.value.length);
610
513
  const loadPage = (newPage = 1) => {
611
514
  reactiveData.page = newPage;
612
515
  if (newPage === 1) {
613
- reactiveData.selectedValues = vue.toValue(selectedValues);
516
+ reactiveData.selectedValues = core.toValue(selectedValues);
614
517
  }
615
518
  };
616
519
  const updateSearchWithDebounce = core.useDebounceFn((value) => {
617
520
  reactiveData.search = value;
618
521
  reactiveData.page = 1;
619
- reactiveData.selectedValues = vue.toValue(selectedValues);
522
+ reactiveData.selectedValues = core.toValue(selectedValues);
620
523
  }, delay);
621
524
  const updateSearch = (value) => {
622
525
  search.value = value;
623
526
  updateSearchWithDebounce(value);
624
527
  };
625
- const queryClient = vueQuery.useQueryClient();
626
- const refetch = () => {
627
- if (reactiveData.page !== 1) {
628
- queryClient.invalidateQueries({
629
- queryKey: [queryKey],
630
- refetchType: "none"
631
- });
632
- loadPage(1);
633
- } else {
634
- queryClient.invalidateQueries({
635
- queryKey: [queryKey]
636
- });
637
- }
638
- };
639
- const reload = () => {
640
- if (reactiveData.page !== 1) {
641
- queryClient.removeQueries({ queryKey: [queryKey] });
642
- loadPage(1);
643
- } else {
644
- queryClient.resetQueries({ queryKey: [queryKey] });
645
- }
646
- };
647
528
  if (vue.isRef(selectedValues)) {
648
529
  vue.watch(selectedValues, async (newSelectedValues) => {
649
530
  if (!newSelectedValues.length) {
@@ -670,7 +551,7 @@ function useAsyncMultiselect({
670
551
  vue.watch(params, (newParams) => {
671
552
  reactiveData.page = 1;
672
553
  reactiveData.params = JSON.stringify(newParams);
673
- reactiveData.selectedValues = vue.toValue(selectedValues);
554
+ reactiveData.selectedValues = core.toValue(selectedValues);
674
555
  });
675
556
  }
676
557
  vue.onBeforeUnmount(() => {
@@ -684,9 +565,7 @@ function useAsyncMultiselect({
684
565
  isFetching,
685
566
  isLoading,
686
567
  loadPage,
687
- updateSearch,
688
- refetch,
689
- reload
568
+ updateSearch
690
569
  };
691
570
  }
692
571
 
@@ -710,17 +589,15 @@ function useAsyncSelect({
710
589
  const reactiveData = vue.reactive({
711
590
  search: "",
712
591
  page: 1,
713
- selectedValue: vue.toValue(selectedValue),
714
- params: JSON.stringify(vue.toValue(params))
592
+ selectedValue: core.toValue(selectedValue),
593
+ params: JSON.stringify(core.toValue(params))
715
594
  });
716
595
  const search = vue.ref("");
717
596
  const { call, abort } = useAbortController(apiMethod);
718
597
  const loadWAC = () => call({
719
598
  page: reactiveData.page,
720
599
  search: reactiveData.search,
721
- ...reactiveData.selectedValue && {
722
- includedIds: [reactiveData.selectedValue]
723
- },
600
+ ...reactiveData.selectedValue && { includedIds: [reactiveData.selectedValue] },
724
601
  ...reactiveData.params && { ...JSON.parse(reactiveData.params) }
725
602
  });
726
603
  const { data, isFetching, isLoading } = vueQuery.useQuery({
@@ -732,7 +609,8 @@ function useAsyncSelect({
732
609
  vue.watch(
733
610
  data,
734
611
  (newValue) => {
735
- if (!newValue) return;
612
+ if (!newValue)
613
+ return;
736
614
  if (!has__default(newValue, dataItemsKey)) {
737
615
  logger.warn(
738
616
  `Unable to find key *"${dataItemsKey}"* (property "dataItemsKey") in data object from API.`,
@@ -747,9 +625,8 @@ function useAsyncSelect({
747
625
  );
748
626
  return;
749
627
  }
750
- if (!get__default(newValue, dataItemsKey) || get__default(newValue, dataCountKey) === void 0) {
628
+ if (!get__default(newValue, dataItemsKey) || get__default(newValue, dataCountKey) === void 0)
751
629
  return;
752
- }
753
630
  count.value = get__default(newValue, dataCountKey, 0);
754
631
  const newItems = get__default(newValue, dataItemsKey);
755
632
  itemsByPages.value = {
@@ -766,16 +643,20 @@ function useAsyncSelect({
766
643
  { immediate: true }
767
644
  );
768
645
  const items = vue.computed(() => {
769
- if (!itemsByPages.value) return [];
770
- if (!Object.keys(itemsByPages.value).length) return [];
646
+ if (!itemsByPages.value)
647
+ return [];
648
+ if (!Object.keys(itemsByPages.value).length)
649
+ return [];
771
650
  return Object.values(itemsByPages.value).reduce(
772
651
  (acc, item) => [...acc, ...item],
773
652
  []
774
653
  );
775
654
  });
776
655
  const options = vue.computed(() => {
777
- if (!items.value.length) return [];
778
- if (!mapOptionCallback) return items.value;
656
+ if (!items.value.length)
657
+ return [];
658
+ if (!mapOptionCallback)
659
+ return this.items.value;
779
660
  return items.value.map(mapOptionCallback);
780
661
  });
781
662
  const hasNextPage = vue.computed(() => count.value > items.value.length);
@@ -790,28 +671,6 @@ function useAsyncSelect({
790
671
  search.value = value;
791
672
  updateSearchWithDebounce(value);
792
673
  };
793
- const queryClient = vueQuery.useQueryClient();
794
- const refetch = () => {
795
- if (reactiveData.page !== 1) {
796
- queryClient.invalidateQueries({
797
- queryKey: [queryKey],
798
- refetchType: "none"
799
- });
800
- loadPage(1);
801
- } else {
802
- queryClient.invalidateQueries({
803
- queryKey: [queryKey]
804
- });
805
- }
806
- };
807
- const reload = () => {
808
- if (reactiveData.page !== 1) {
809
- queryClient.removeQueries({ queryKey: [queryKey] });
810
- loadPage(1);
811
- } else {
812
- queryClient.resetQueries({ queryKey: [queryKey] });
813
- }
814
- };
815
674
  if (vue.isRef(selectedValue)) {
816
675
  vue.watch(selectedValue, (newSelectedValue) => {
817
676
  reactiveData.page = 1;
@@ -835,22 +694,20 @@ function useAsyncSelect({
835
694
  isFetching,
836
695
  isLoading,
837
696
  loadPage,
838
- updateSearch,
839
- refetch,
840
- reload
697
+ updateSearch
841
698
  };
842
699
  }
843
700
 
844
701
  function useBreakpoint() {
845
702
  const breakpoints = core.useBreakpoints(commonData.BREAKPOINTS);
846
703
  const isMobile = breakpoints.smaller("sm");
847
- const isDesktop = breakpoints.greaterOrEqual("md");
848
- const isGreaterXxs = breakpoints.greaterOrEqual("xxs");
849
- const isGreaterXs = breakpoints.greaterOrEqual("xs");
850
- const isGreaterSm = breakpoints.greaterOrEqual("sm");
851
- const isGreaterMd = breakpoints.greaterOrEqual("md");
852
- const isGreaterLg = breakpoints.greaterOrEqual("lg");
853
- const isGreaterXl = breakpoints.greaterOrEqual("xl");
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");
854
711
  return {
855
712
  isMobile,
856
713
  isDesktop,
@@ -865,10 +722,14 @@ function useBreakpoint() {
865
722
 
866
723
  function _bem(block, blockSuffix, element, modifier, modifierValue) {
867
724
  let cls = block;
868
- if (blockSuffix) cls += `-${blockSuffix}`;
869
- if (element) cls += `__${element}`;
870
- if (modifier) cls += `_${modifier}`;
871
- if (modifierValue) cls += `_${modifierValue}`;
725
+ if (blockSuffix)
726
+ cls += `-${blockSuffix}`;
727
+ if (element)
728
+ cls += `__${element}`;
729
+ if (modifier)
730
+ cls += `_${modifier}`;
731
+ if (modifierValue)
732
+ cls += `_${modifierValue}`;
872
733
  return cls;
873
734
  }
874
735
  function useClassName(block) {
@@ -879,7 +740,8 @@ function useClassName(block) {
879
740
  const mv = (modifier, modifierValue, condition = true) => modifier && modifierValue && condition ? _bem(block, "", "", modifier, modifierValue) : "";
880
741
  const cssVar = (object) => {
881
742
  const styles = {};
882
- for (const key in object) styles[`--${block}-${key}`] = object[key];
743
+ for (const key in object)
744
+ styles[`--${block}-${key}`] = object[key];
883
745
  return styles;
884
746
  };
885
747
  const cssVarName = (name) => `--${block}-${name}`;
@@ -904,16 +766,15 @@ function useDayjs(timezone) {
904
766
  dayjs__default.updateLocale("en", {
905
767
  weekStart: 1
906
768
  });
907
- if (!timezone) return dayjs__default;
769
+ if (!timezone)
770
+ return dayjs__default;
908
771
  const dayjsExtended = (date, format, locale, strict) => dayjs__default(date, format, locale, strict).tz(timezone);
909
772
  return dayjsExtended;
910
773
  }
911
774
 
912
775
  function parseVersion(version) {
913
776
  if (typeof version !== "string" && typeof version !== "number") {
914
- throw new TypeError(
915
- "Browser version must be type of string, number or negative boolean"
916
- );
777
+ throw new TypeError("Browser version must be type of string, number or negative boolean");
917
778
  }
918
779
  const [major, minor = 0, patch = 0, build = 0] = typeof version === "string" ? version.split(".").map(Number) : [version];
919
780
  return {
@@ -925,7 +786,8 @@ function parseVersion(version) {
925
786
  }
926
787
  function isVersionLower(minimum, target) {
927
788
  for (const k of ["major", "minor", "patch"]) {
928
- if (minimum[k] !== target[k]) return minimum[k] > target[k];
789
+ if (minimum[k] !== target[k])
790
+ return minimum[k] > target[k];
929
791
  }
930
792
  return minimum.build > target.build;
931
793
  }
@@ -973,20 +835,9 @@ function useGlobalScroll() {
973
835
 
974
836
  const CONFIRM_TEXT = "Are you sure you want to close? \nAll changes will be lost.";
975
837
  let dialogs = [];
976
- const HASH_PREFIX = "#ud_";
977
- function useDialog(options) {
978
- const logger = useLogger("use-dialog");
979
- let hashPrefix = HASH_PREFIX;
980
- if (options?.hashPrefix) {
981
- if (options.hashPrefix.charAt(0) === "#") {
982
- hashPrefix = options?.hashPrefix;
983
- } else {
984
- logger.warn(
985
- `*hashPrefix* must start with "#". The default prefix "${HASH_PREFIX}" will be used`
986
- );
987
- }
988
- }
838
+ function useDialog() {
989
839
  let appContext;
840
+ const logger = useLogger("use-dialog");
990
841
  const {
991
842
  isLocked: isGlobalScrollLocked,
992
843
  lock: lockGlobalScroll,
@@ -994,33 +845,26 @@ function useDialog(options) {
994
845
  } = useGlobalScroll();
995
846
  const route = vueRouter.useRoute();
996
847
  const router = vueRouter.useRouter();
997
- const genHash = ({
998
- layer = 0,
999
- componentName,
1000
- props
1001
- }) => {
1002
- const data = {
1003
- name: componentName,
1004
- layer,
1005
- props
1006
- };
1007
- return `${hashPrefix}${window.btoa(JSON.stringify(data))}`;
1008
- };
848
+ const HASH_PREFIX = "#ud_";
1009
849
  const parseHash = (hash, componentName) => {
1010
- if (!hash) return void 0;
1011
- if (!hash.includes(hashPrefix)) return void 0;
850
+ if (!hash)
851
+ return void 0;
852
+ if (!hash.includes(HASH_PREFIX))
853
+ return void 0;
1012
854
  let dataFromHash;
1013
855
  try {
1014
- dataFromHash = JSON.parse(window.atob(hash.slice(hashPrefix.length)));
1015
- } catch (_error) {
856
+ dataFromHash = JSON.parse(window.atob(hash.slice(HASH_PREFIX.length)));
857
+ } catch (error) {
1016
858
  logger.warn("*parseHash* cant parse hash");
1017
859
  }
1018
- if (typeof dataFromHash !== "object") return void 0;
860
+ if (typeof dataFromHash !== "object")
861
+ return void 0;
1019
862
  if (!dataFromHash.name) {
1020
863
  logger.warn("*parseHash* cant find component name in hash");
1021
864
  return void 0;
1022
865
  }
1023
- if (dataFromHash.name !== componentName) return void 0;
866
+ if (dataFromHash.name !== componentName)
867
+ return void 0;
1024
868
  return dataFromHash;
1025
869
  };
1026
870
  const clearHash = () => {
@@ -1057,7 +901,8 @@ function useDialog(options) {
1057
901
  vnode2.component.props.modelValue = value;
1058
902
  if (!value && route?.hash) {
1059
903
  const dataFromHash = parseHash(route.hash, component.name);
1060
- if (dataFromHash?.layer === layer) clearHash();
904
+ if (dataFromHash)
905
+ clearHash();
1061
906
  }
1062
907
  if (!value && (dialogs.length === 1 || layer === 0) && isGlobalScrollLocked.value) {
1063
908
  unlockGlobalScroll();
@@ -1066,11 +911,14 @@ function useDialog(options) {
1066
911
  };
1067
912
  }
1068
913
  vnode2.close = () => {
1069
- if (!vnode2 || !vnode2.component) return;
914
+ if (!vnode2 || !vnode2.component)
915
+ return;
1070
916
  vnode2.component.props.modelValue = false;
1071
- if (!route?.hash) return;
917
+ if (!route?.hash)
918
+ return;
1072
919
  const dataFromHash = parseHash(route.hash, component.name);
1073
- if (dataFromHash?.layer === layer) clearHash();
920
+ if (dataFromHash)
921
+ clearHash();
1074
922
  };
1075
923
  vnode2.props.onDestroy = () => {
1076
924
  vue.render(null, el2);
@@ -1143,12 +991,9 @@ function useDialog(options) {
1143
991
  const getInstance = (uuid) => {
1144
992
  return dialogs.find((item) => item.uuid === uuid)?.vnode;
1145
993
  };
1146
- const getLayer = (uuid) => {
1147
- if (!dialogs.length) return 0;
1148
- return dialogs.find((dialog) => dialog.uuid === uuid)?.layer || 0;
1149
- };
1150
994
  const isOnTop = (uuid) => {
1151
- if (!dialogs.length) return false;
995
+ if (!dialogs.length)
996
+ return false;
1152
997
  const dialogsSorted = [...dialogs].sort((a, b) => b.layer - a.layer);
1153
998
  return dialogsSorted[0].uuid === uuid;
1154
999
  };
@@ -1160,10 +1005,15 @@ function useDialog(options) {
1160
1005
  component,
1161
1006
  props
1162
1007
  }) => {
1008
+ const data = {
1009
+ name: component.name,
1010
+ layer,
1011
+ props
1012
+ };
1163
1013
  router.push({
1164
1014
  name: route.name || void 0,
1165
1015
  query: route.query,
1166
- hash: genHash({ layer, props, componentName: component.name })
1016
+ hash: `${HASH_PREFIX}${window.btoa(JSON.stringify(data))}`
1167
1017
  });
1168
1018
  };
1169
1019
  const watchHash = ({
@@ -1175,12 +1025,14 @@ function useDialog(options) {
1175
1025
  () => route.hash,
1176
1026
  async (newHash) => {
1177
1027
  if (!newHash) {
1178
- if (!dialogs.length) return;
1028
+ if (!dialogs.length)
1029
+ return;
1179
1030
  closeAll();
1180
1031
  return;
1181
1032
  }
1182
1033
  const dataFromHash = parseHash(newHash, component.name);
1183
- if (!dataFromHash) return;
1034
+ if (!dataFromHash)
1035
+ return;
1184
1036
  logger.info("*watchHash* data from hash", dataFromHash);
1185
1037
  await vue.nextTick();
1186
1038
  open({
@@ -1206,14 +1058,10 @@ function useDialog(options) {
1206
1058
  return {
1207
1059
  open,
1208
1060
  getInstance,
1209
- getLayer,
1210
1061
  close,
1211
1062
  closeAll,
1212
1063
  showConfirm,
1213
1064
  isOnTop,
1214
- genHash,
1215
- parseHash,
1216
- clearHash,
1217
1065
  openByHash,
1218
1066
  watchHash
1219
1067
  };
@@ -1226,47 +1074,46 @@ const QS_STRINGIFY_PARAMS = {
1226
1074
  addQueryPrefix: true
1227
1075
  };
1228
1076
  const isOpen = vue.ref(false);
1229
- function useFilters({ config, initialFilters }) {
1077
+ function useFilters({
1078
+ config,
1079
+ initialFilters
1080
+ }) {
1230
1081
  const router = vueRouter.useRouter();
1231
1082
  const route = vueRouter.useRoute();
1232
1083
  const parseRouteQuery = (query) => qs__default.parse(query ?? route.query);
1233
1084
  const filtersFromQuery = vue.computed(() => {
1234
1085
  const parsedRouteQuery = parseRouteQuery();
1235
- if (!parsedRouteQuery.filters) return void 0;
1236
- return Object.entries(config).reduce(
1237
- (accum, [currentKey, currentValue]) => {
1238
- if (!parsedRouteQuery.filters[currentKey]) return accum;
1239
- if (currentValue.type === "ARRAY" /* Array */) {
1240
- const splitValues = parsedRouteQuery.filters[currentKey].split(",");
1241
- const checkedValue = currentValue?.possibleValues ? splitValues.filter(
1242
- (k) => currentValue?.possibleValues?.includes(k)
1243
- ) : splitValues;
1244
- if (!checkedValue?.length) return accum;
1245
- return {
1246
- ...accum,
1247
- [currentKey]: checkedValue
1248
- };
1249
- }
1086
+ if (!parsedRouteQuery.filters)
1087
+ return void 0;
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)
1095
+ return accum;
1250
1096
  return {
1251
1097
  ...accum,
1252
- [currentKey]: parsedRouteQuery.filters[currentKey]
1098
+ [currentKey]: checkedValue
1253
1099
  };
1254
- },
1255
- {}
1256
- );
1100
+ }
1101
+ return {
1102
+ ...accum,
1103
+ [currentKey]: parsedRouteQuery.filters[currentKey]
1104
+ };
1105
+ }, {});
1257
1106
  });
1258
1107
  const filtersCount = vue.computed(
1259
1108
  () => filtersFromQuery.value ? Object.keys(filtersFromQuery.value).length : 0
1260
1109
  );
1261
1110
  const setQueryFromFilters = (filters) => {
1262
1111
  const parsedRouteQuery = parseRouteQuery();
1263
- const filteredValue = Object.entries(filters).reduce(
1264
- (accum, [currentKey, currentValue]) => {
1265
- if (!currentValue?.length) return accum;
1266
- return { ...accum, [currentKey]: currentValue };
1267
- },
1268
- {}
1269
- );
1112
+ const filteredValue = Object.entries(filters).reduce((accum, [currentKey, currentValue]) => {
1113
+ if (!currentValue?.length)
1114
+ return accum;
1115
+ return { ...accum, [currentKey]: currentValue };
1116
+ }, {});
1270
1117
  const query = qs__default.stringify(
1271
1118
  {
1272
1119
  ...parsedRouteQuery,
@@ -1275,7 +1122,7 @@ function useFilters({ config, initialFilters }) {
1275
1122
  },
1276
1123
  QS_STRINGIFY_PARAMS
1277
1124
  );
1278
- router.push(query.replaceAll("#", ""));
1125
+ router.push(query);
1279
1126
  };
1280
1127
  const getValidatedParams = (query) => {
1281
1128
  const parsedRouteQuery = parseRouteQuery(query);
@@ -1303,15 +1150,12 @@ function useFilters({ config, initialFilters }) {
1303
1150
  });
1304
1151
  };
1305
1152
  const updateMany = (filters) => {
1306
- const newFilters = Object.entries(filters).reduce(
1307
- (accum, [currentKey, currentValue]) => {
1308
- return {
1309
- ...accum,
1310
- [currentKey]: currentValue ? String(currentValue) : void 0
1311
- };
1312
- },
1313
- {}
1314
- );
1153
+ const newFilters = Object.entries(filters).reduce((accum, [currentKey, currentValue]) => {
1154
+ return {
1155
+ ...accum,
1156
+ [currentKey]: currentValue ? String(currentValue) : void 0
1157
+ };
1158
+ }, {});
1315
1159
  setQueryFromFilters({
1316
1160
  ...filtersModel.value,
1317
1161
  ...newFilters
@@ -1487,15 +1331,17 @@ function usePanel() {
1487
1331
  let dataFromHash;
1488
1332
  try {
1489
1333
  dataFromHash = JSON.parse(window.atob(newHash.slice(1)));
1490
- } catch (_error) {
1334
+ } catch (error) {
1491
1335
  logger.error("*watchHash* cant parse hash");
1492
1336
  }
1493
- if (typeof dataFromHash !== "object") return;
1337
+ if (typeof dataFromHash !== "object")
1338
+ return;
1494
1339
  if (!dataFromHash.name) {
1495
1340
  logger.error("*watchHash* cant find component name in hash");
1496
1341
  return;
1497
1342
  }
1498
- if (dataFromHash.name !== component.name) return;
1343
+ if (dataFromHash.name !== component.name)
1344
+ return;
1499
1345
  logger.info("*watchHash* data from hash", dataFromHash);
1500
1346
  await vue.nextTick();
1501
1347
  open({
@@ -1503,7 +1349,8 @@ function usePanel() {
1503
1349
  layer: dataFromHash.layer || 0,
1504
1350
  props: {
1505
1351
  "onUpdate:modelValue": (value) => {
1506
- if (value) return;
1352
+ if (value)
1353
+ return;
1507
1354
  router.push({
1508
1355
  name: route.name || void 0,
1509
1356
  query: route.query,
@@ -1537,7 +1384,8 @@ function usePanel() {
1537
1384
  }
1538
1385
 
1539
1386
  function validatePhone(rule, value) {
1540
- if (!value) return true;
1387
+ if (!value)
1388
+ return true;
1541
1389
  const phoneNumber = libphonenumberJs.parsePhoneNumberFromString(value);
1542
1390
  return phoneNumber ? phoneNumber.isValid() : false;
1543
1391
  }
@@ -1587,12 +1435,9 @@ function isStrictLength(value = 3, message) {
1587
1435
  }
1588
1436
 
1589
1437
  exports.AppComponentsResolver = AppComponentsResolver;
1590
- exports.EnrichError = EnrichError;
1591
1438
  exports.UiComponentsResolver = UiComponentsResolver;
1592
1439
  exports.camelizeKeys = camelizeKeys;
1593
1440
  exports.convertEnumToOptions = convertEnumToOptions;
1594
- exports.formatErrorDataMessage = formatErrorDataMessage;
1595
- exports.formatErrorForNotify = formatErrorForNotify;
1596
1441
  exports.formatMoney = formatMoney;
1597
1442
  exports.genHash = genHash;
1598
1443
  exports.genRandomNumber = genRandomNumber;
@@ -1603,10 +1448,8 @@ exports.getPaginationLimit = getPaginationLimit;
1603
1448
  exports.getPaginationOffset = getPaginationOffset;
1604
1449
  exports.getPaginationPages = getPaginationPages;
1605
1450
  exports.getPaginationParams = getPaginationParams;
1606
- exports.getStatusMessage = getStatusMessage;
1607
1451
  exports.isElementIgnored = isElementIgnored;
1608
1452
  exports.isEmptyObject = isEmptyObject;
1609
- exports.isHtml = isHtml;
1610
1453
  exports.isMax = isMax;
1611
1454
  exports.isMin = isMin;
1612
1455
  exports.isRequired = isRequired;