@karta.io/utils 1.0.0-beta.44 → 1.0.0-beta.46
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 +66 -123
- package/dist/index.d.cts +11 -10
- package/dist/index.d.mts +11 -10
- package/dist/index.d.ts +11 -10
- package/dist/index.mjs +59 -116
- package/package.json +12 -12
package/dist/index.cjs
CHANGED
|
@@ -6,8 +6,8 @@ const commonData = require('@karta.io/common-data');
|
|
|
6
6
|
const libphonenumberJs = require('libphonenumber-js');
|
|
7
7
|
const snakeCase = require('lodash/snakeCase.js');
|
|
8
8
|
const vue = require('vue');
|
|
9
|
-
const core = require('@vueuse/core');
|
|
10
9
|
const vueQuery = require('@tanstack/vue-query');
|
|
10
|
+
const core = require('@vueuse/core');
|
|
11
11
|
const get = require('lodash/get.js');
|
|
12
12
|
const has = require('lodash/has.js');
|
|
13
13
|
const union = require('lodash/union.js');
|
|
@@ -140,8 +140,7 @@ function getStatusMessage(status) {
|
|
|
140
140
|
return message;
|
|
141
141
|
}
|
|
142
142
|
function formatErrorDataMessage(data) {
|
|
143
|
-
if (!data)
|
|
144
|
-
return "";
|
|
143
|
+
if (!data) return "";
|
|
145
144
|
return Object.values(data).reduce((accum, current) => {
|
|
146
145
|
if (current && typeof current === "string")
|
|
147
146
|
return accum ? `${accum} | ${current}` : current;
|
|
@@ -153,8 +152,7 @@ function formatErrorDataMessage(data) {
|
|
|
153
152
|
}, "");
|
|
154
153
|
}
|
|
155
154
|
function formatErrorForNotify(error) {
|
|
156
|
-
if (!error)
|
|
157
|
-
return;
|
|
155
|
+
if (!error) return;
|
|
158
156
|
if (error.status >= 400 && error.status < 500) {
|
|
159
157
|
let message = "";
|
|
160
158
|
if (!error.data || typeof error.data === "string" && isHtml(error.data)) {
|
|
@@ -188,8 +186,7 @@ function formatMoney(value, currency = commonData.CURRENCY_DEFAULT, options = {}
|
|
|
188
186
|
try {
|
|
189
187
|
let convertedValue = Number(value);
|
|
190
188
|
if (value === null || Number.isNaN(convertedValue)) {
|
|
191
|
-
if (defaultValue === "")
|
|
192
|
-
return defaultValue;
|
|
189
|
+
if (defaultValue === "") return defaultValue;
|
|
193
190
|
convertedValue = Number(defaultValue);
|
|
194
191
|
}
|
|
195
192
|
const formatter = new Intl.NumberFormat(locale, {
|
|
@@ -249,8 +246,7 @@ function getCardNumber(number, options) {
|
|
|
249
246
|
}
|
|
250
247
|
|
|
251
248
|
function getCountryFromPhone(phone) {
|
|
252
|
-
if (!phone)
|
|
253
|
-
return "";
|
|
249
|
+
if (!phone) return "";
|
|
254
250
|
const replacedPhone = phone.replace(/[a-zA-Z]/g, "");
|
|
255
251
|
const phoneNumber = libphonenumberJs.parsePhoneNumberFromString(replacedPhone);
|
|
256
252
|
return phoneNumber?.country ?? "";
|
|
@@ -292,8 +288,7 @@ function mapDataObjectForFilters(data, options) {
|
|
|
292
288
|
}
|
|
293
289
|
|
|
294
290
|
function validateNumber(value, defaultValue) {
|
|
295
|
-
if (value === "")
|
|
296
|
-
return defaultValue;
|
|
291
|
+
if (value === "") return defaultValue;
|
|
297
292
|
return Number.isNaN(Number(value)) ? defaultValue : Number(value);
|
|
298
293
|
}
|
|
299
294
|
|
|
@@ -331,8 +326,7 @@ function getPaginationPages({
|
|
|
331
326
|
}
|
|
332
327
|
|
|
333
328
|
function parsePhone(phone) {
|
|
334
|
-
if (!phone || typeof phone !== "string")
|
|
335
|
-
return "";
|
|
329
|
+
if (!phone || typeof phone !== "string") return "";
|
|
336
330
|
const replacedPhone = phone.replace(/[a-zA-Z]/g, "");
|
|
337
331
|
if (replacedPhone.length === 1 && replacedPhone !== "+") {
|
|
338
332
|
return `+${replacedPhone}`;
|
|
@@ -360,8 +354,7 @@ function snakelizeKeys(prop) {
|
|
|
360
354
|
const LOCALE_RU = "ru-RU";
|
|
361
355
|
const LOCALE_EN = "en-US";
|
|
362
356
|
function unformatNumber(value) {
|
|
363
|
-
if (!value || typeof value !== "string")
|
|
364
|
-
return value;
|
|
357
|
+
if (!value || typeof value !== "string") return value;
|
|
365
358
|
const string = value.trim();
|
|
366
359
|
let locale;
|
|
367
360
|
const spaceIndex = string.lastIndexOf(" ");
|
|
@@ -371,24 +364,18 @@ function unformatNumber(value) {
|
|
|
371
364
|
const hasComma = commaIndex !== -1;
|
|
372
365
|
const hasDot = dotIndex !== -1;
|
|
373
366
|
const commasCount = (string.match(/,/g) || []).length;
|
|
374
|
-
if (!Number.isNaN(Number(string)))
|
|
375
|
-
|
|
376
|
-
if (hasSpace && hasComma &&
|
|
377
|
-
|
|
378
|
-
if (
|
|
379
|
-
locale = LOCALE_RU;
|
|
380
|
-
if (hasComma && hasDot && dotIndex > commaIndex)
|
|
381
|
-
locale = LOCALE_EN;
|
|
382
|
-
if (hasComma && !hasSpace && !hasDot && commasCount > 1)
|
|
383
|
-
locale = LOCALE_EN;
|
|
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;
|
|
384
372
|
if (commasCount === 1 && !hasSpace && !hasDot) {
|
|
385
373
|
locale = string.length - 1 - commaIndex === 3 ? LOCALE_EN : LOCALE_RU;
|
|
386
374
|
}
|
|
387
375
|
if (locale === LOCALE_RU) {
|
|
388
376
|
return Number(string.replaceAll(" ", "").replace(",", "."));
|
|
389
377
|
}
|
|
390
|
-
if (locale === LOCALE_EN)
|
|
391
|
-
return Number(string.replaceAll(",", ""));
|
|
378
|
+
if (locale === LOCALE_EN) return Number(string.replaceAll(",", ""));
|
|
392
379
|
return value;
|
|
393
380
|
}
|
|
394
381
|
|
|
@@ -407,8 +394,7 @@ function useAbortController(callback) {
|
|
|
407
394
|
let controller = null;
|
|
408
395
|
return {
|
|
409
396
|
async call(...args) {
|
|
410
|
-
if (controller)
|
|
411
|
-
controller.abort();
|
|
397
|
+
if (controller) controller.abort();
|
|
412
398
|
controller = new AbortController();
|
|
413
399
|
let response;
|
|
414
400
|
if (args.length > 0) {
|
|
@@ -424,8 +410,7 @@ function useAbortController(callback) {
|
|
|
424
410
|
return response;
|
|
425
411
|
},
|
|
426
412
|
abort() {
|
|
427
|
-
if (!controller)
|
|
428
|
-
return;
|
|
413
|
+
if (!controller) return;
|
|
429
414
|
controller.abort();
|
|
430
415
|
controller = null;
|
|
431
416
|
},
|
|
@@ -445,7 +430,7 @@ function useAsyncItems({
|
|
|
445
430
|
const { call, abort } = useAbortController(apiMethod);
|
|
446
431
|
const { isLoading, isFetching, isError, data, error } = vueQuery.useQuery({
|
|
447
432
|
queryKey: getQueryKey(),
|
|
448
|
-
queryFn: () => call(
|
|
433
|
+
queryFn: () => call(vue.toValue(params), config)
|
|
449
434
|
});
|
|
450
435
|
const items = vue.computed(
|
|
451
436
|
() => data.value?.results || []
|
|
@@ -454,8 +439,7 @@ function useAsyncItems({
|
|
|
454
439
|
vue.watch(
|
|
455
440
|
data,
|
|
456
441
|
(newValue) => {
|
|
457
|
-
if (newValue === void 0 || newValue.count === void 0)
|
|
458
|
-
return;
|
|
442
|
+
if (newValue === void 0 || newValue.count === void 0) return;
|
|
459
443
|
count.value = newValue.count;
|
|
460
444
|
},
|
|
461
445
|
{ immediate: true }
|
|
@@ -482,23 +466,18 @@ function useAsyncItems({
|
|
|
482
466
|
}
|
|
483
467
|
|
|
484
468
|
function isEnabled(options) {
|
|
485
|
-
if (options?.debug !== void 0)
|
|
486
|
-
return options.debug;
|
|
469
|
+
if (options?.debug !== void 0) return options.debug;
|
|
487
470
|
const isBrowser = typeof window !== "undefined" && typeof window.document !== "undefined";
|
|
488
471
|
if (isBrowser) {
|
|
489
472
|
const debug = localStorage.getItem("debug");
|
|
490
|
-
if (debug === "true")
|
|
491
|
-
|
|
492
|
-
if (debug === "false")
|
|
493
|
-
return false;
|
|
473
|
+
if (debug === "true") return true;
|
|
474
|
+
if (debug === "false") return false;
|
|
494
475
|
}
|
|
495
476
|
const isNode = typeof process !== "undefined" && process.versions != null && process.versions.node != null;
|
|
496
477
|
if (isNode) {
|
|
497
478
|
const debug = process.env.NODE_DEBUG;
|
|
498
|
-
if (debug === "true")
|
|
499
|
-
|
|
500
|
-
if (debug === "false")
|
|
501
|
-
return false;
|
|
479
|
+
if (debug === "true") return true;
|
|
480
|
+
if (debug === "false") return false;
|
|
502
481
|
}
|
|
503
482
|
return false;
|
|
504
483
|
}
|
|
@@ -535,8 +514,8 @@ function useAsyncMultiselect({
|
|
|
535
514
|
const reactiveData = vue.reactive({
|
|
536
515
|
search: "",
|
|
537
516
|
page: 1,
|
|
538
|
-
selectedValues:
|
|
539
|
-
params: JSON.stringify(
|
|
517
|
+
selectedValues: vue.toValue(selectedValues),
|
|
518
|
+
params: JSON.stringify(vue.toValue(params))
|
|
540
519
|
});
|
|
541
520
|
const search = vue.ref("");
|
|
542
521
|
const { call, abort } = useAbortController(apiMethod);
|
|
@@ -561,8 +540,7 @@ function useAsyncMultiselect({
|
|
|
561
540
|
vue.watch(
|
|
562
541
|
data,
|
|
563
542
|
(newValue) => {
|
|
564
|
-
if (!newValue)
|
|
565
|
-
return;
|
|
543
|
+
if (!newValue) return;
|
|
566
544
|
if (!has__default(newValue, dataItemsKey)) {
|
|
567
545
|
logger.warn(
|
|
568
546
|
`Unable to find key *"${dataItemsKey}"* (property "dataItemsKey") in data object from API.`,
|
|
@@ -608,8 +586,7 @@ function useAsyncMultiselect({
|
|
|
608
586
|
{ immediate: true }
|
|
609
587
|
);
|
|
610
588
|
const items = vue.computed(() => {
|
|
611
|
-
if (!itemsByPages.value)
|
|
612
|
-
return selectedItemsCached.value;
|
|
589
|
+
if (!itemsByPages.value) return selectedItemsCached.value;
|
|
613
590
|
if (!Object.keys(itemsByPages.value).length) {
|
|
614
591
|
return selectedItemsCached.value;
|
|
615
592
|
}
|
|
@@ -625,23 +602,21 @@ function useAsyncMultiselect({
|
|
|
625
602
|
return [...itemsAsMap.values()];
|
|
626
603
|
});
|
|
627
604
|
const options = vue.computed(() => {
|
|
628
|
-
if (!items.value.length)
|
|
629
|
-
|
|
630
|
-
if (!mapOptionCallback)
|
|
631
|
-
return items.value;
|
|
605
|
+
if (!items.value.length) return [];
|
|
606
|
+
if (!mapOptionCallback) return items.value;
|
|
632
607
|
return items.value.map(mapOptionCallback);
|
|
633
608
|
});
|
|
634
609
|
const hasNextPage = vue.computed(() => count.value > items.value.length);
|
|
635
610
|
const loadPage = (newPage = 1) => {
|
|
636
611
|
reactiveData.page = newPage;
|
|
637
612
|
if (newPage === 1) {
|
|
638
|
-
reactiveData.selectedValues =
|
|
613
|
+
reactiveData.selectedValues = vue.toValue(selectedValues);
|
|
639
614
|
}
|
|
640
615
|
};
|
|
641
616
|
const updateSearchWithDebounce = core.useDebounceFn((value) => {
|
|
642
617
|
reactiveData.search = value;
|
|
643
618
|
reactiveData.page = 1;
|
|
644
|
-
reactiveData.selectedValues =
|
|
619
|
+
reactiveData.selectedValues = vue.toValue(selectedValues);
|
|
645
620
|
}, delay);
|
|
646
621
|
const updateSearch = (value) => {
|
|
647
622
|
search.value = value;
|
|
@@ -695,7 +670,7 @@ function useAsyncMultiselect({
|
|
|
695
670
|
vue.watch(params, (newParams) => {
|
|
696
671
|
reactiveData.page = 1;
|
|
697
672
|
reactiveData.params = JSON.stringify(newParams);
|
|
698
|
-
reactiveData.selectedValues =
|
|
673
|
+
reactiveData.selectedValues = vue.toValue(selectedValues);
|
|
699
674
|
});
|
|
700
675
|
}
|
|
701
676
|
vue.onBeforeUnmount(() => {
|
|
@@ -735,8 +710,8 @@ function useAsyncSelect({
|
|
|
735
710
|
const reactiveData = vue.reactive({
|
|
736
711
|
search: "",
|
|
737
712
|
page: 1,
|
|
738
|
-
selectedValue:
|
|
739
|
-
params: JSON.stringify(
|
|
713
|
+
selectedValue: vue.toValue(selectedValue),
|
|
714
|
+
params: JSON.stringify(vue.toValue(params))
|
|
740
715
|
});
|
|
741
716
|
const search = vue.ref("");
|
|
742
717
|
const { call, abort } = useAbortController(apiMethod);
|
|
@@ -757,8 +732,7 @@ function useAsyncSelect({
|
|
|
757
732
|
vue.watch(
|
|
758
733
|
data,
|
|
759
734
|
(newValue) => {
|
|
760
|
-
if (!newValue)
|
|
761
|
-
return;
|
|
735
|
+
if (!newValue) return;
|
|
762
736
|
if (!has__default(newValue, dataItemsKey)) {
|
|
763
737
|
logger.warn(
|
|
764
738
|
`Unable to find key *"${dataItemsKey}"* (property "dataItemsKey") in data object from API.`,
|
|
@@ -792,20 +766,16 @@ function useAsyncSelect({
|
|
|
792
766
|
{ immediate: true }
|
|
793
767
|
);
|
|
794
768
|
const items = vue.computed(() => {
|
|
795
|
-
if (!itemsByPages.value)
|
|
796
|
-
|
|
797
|
-
if (!Object.keys(itemsByPages.value).length)
|
|
798
|
-
return [];
|
|
769
|
+
if (!itemsByPages.value) return [];
|
|
770
|
+
if (!Object.keys(itemsByPages.value).length) return [];
|
|
799
771
|
return Object.values(itemsByPages.value).reduce(
|
|
800
772
|
(acc, item) => [...acc, ...item],
|
|
801
773
|
[]
|
|
802
774
|
);
|
|
803
775
|
});
|
|
804
776
|
const options = vue.computed(() => {
|
|
805
|
-
if (!items.value.length)
|
|
806
|
-
|
|
807
|
-
if (!mapOptionCallback)
|
|
808
|
-
return items.value;
|
|
777
|
+
if (!items.value.length) return [];
|
|
778
|
+
if (!mapOptionCallback) return items.value;
|
|
809
779
|
return items.value.map(mapOptionCallback);
|
|
810
780
|
});
|
|
811
781
|
const hasNextPage = vue.computed(() => count.value > items.value.length);
|
|
@@ -895,14 +865,10 @@ function useBreakpoint() {
|
|
|
895
865
|
|
|
896
866
|
function _bem(block, blockSuffix, element, modifier, modifierValue) {
|
|
897
867
|
let cls = block;
|
|
898
|
-
if (blockSuffix)
|
|
899
|
-
|
|
900
|
-
if (
|
|
901
|
-
|
|
902
|
-
if (modifier)
|
|
903
|
-
cls += `_${modifier}`;
|
|
904
|
-
if (modifierValue)
|
|
905
|
-
cls += `_${modifierValue}`;
|
|
868
|
+
if (blockSuffix) cls += `-${blockSuffix}`;
|
|
869
|
+
if (element) cls += `__${element}`;
|
|
870
|
+
if (modifier) cls += `_${modifier}`;
|
|
871
|
+
if (modifierValue) cls += `_${modifierValue}`;
|
|
906
872
|
return cls;
|
|
907
873
|
}
|
|
908
874
|
function useClassName(block) {
|
|
@@ -913,8 +879,7 @@ function useClassName(block) {
|
|
|
913
879
|
const mv = (modifier, modifierValue, condition = true) => modifier && modifierValue && condition ? _bem(block, "", "", modifier, modifierValue) : "";
|
|
914
880
|
const cssVar = (object) => {
|
|
915
881
|
const styles = {};
|
|
916
|
-
for (const key in object)
|
|
917
|
-
styles[`--${block}-${key}`] = object[key];
|
|
882
|
+
for (const key in object) styles[`--${block}-${key}`] = object[key];
|
|
918
883
|
return styles;
|
|
919
884
|
};
|
|
920
885
|
const cssVarName = (name) => `--${block}-${name}`;
|
|
@@ -939,8 +904,7 @@ function useDayjs(timezone) {
|
|
|
939
904
|
dayjs__default.updateLocale("en", {
|
|
940
905
|
weekStart: 1
|
|
941
906
|
});
|
|
942
|
-
if (!timezone)
|
|
943
|
-
return dayjs__default;
|
|
907
|
+
if (!timezone) return dayjs__default;
|
|
944
908
|
const dayjsExtended = (date, format, locale, strict) => dayjs__default(date, format, locale, strict).tz(timezone);
|
|
945
909
|
return dayjsExtended;
|
|
946
910
|
}
|
|
@@ -961,8 +925,7 @@ function parseVersion(version) {
|
|
|
961
925
|
}
|
|
962
926
|
function isVersionLower(minimum, target) {
|
|
963
927
|
for (const k of ["major", "minor", "patch"]) {
|
|
964
|
-
if (minimum[k] !== target[k])
|
|
965
|
-
return minimum[k] > target[k];
|
|
928
|
+
if (minimum[k] !== target[k]) return minimum[k] > target[k];
|
|
966
929
|
}
|
|
967
930
|
return minimum.build > target.build;
|
|
968
931
|
}
|
|
@@ -1044,24 +1007,20 @@ function useDialog(options) {
|
|
|
1044
1007
|
return `${hashPrefix}${window.btoa(JSON.stringify(data))}`;
|
|
1045
1008
|
};
|
|
1046
1009
|
const parseHash = (hash, componentName) => {
|
|
1047
|
-
if (!hash)
|
|
1048
|
-
|
|
1049
|
-
if (!hash.includes(hashPrefix))
|
|
1050
|
-
return void 0;
|
|
1010
|
+
if (!hash) return void 0;
|
|
1011
|
+
if (!hash.includes(hashPrefix)) return void 0;
|
|
1051
1012
|
let dataFromHash;
|
|
1052
1013
|
try {
|
|
1053
1014
|
dataFromHash = JSON.parse(window.atob(hash.slice(hashPrefix.length)));
|
|
1054
1015
|
} catch (_error) {
|
|
1055
1016
|
logger.warn("*parseHash* cant parse hash");
|
|
1056
1017
|
}
|
|
1057
|
-
if (typeof dataFromHash !== "object")
|
|
1058
|
-
return void 0;
|
|
1018
|
+
if (typeof dataFromHash !== "object") return void 0;
|
|
1059
1019
|
if (!dataFromHash.name) {
|
|
1060
1020
|
logger.warn("*parseHash* cant find component name in hash");
|
|
1061
1021
|
return void 0;
|
|
1062
1022
|
}
|
|
1063
|
-
if (dataFromHash.name !== componentName)
|
|
1064
|
-
return void 0;
|
|
1023
|
+
if (dataFromHash.name !== componentName) return void 0;
|
|
1065
1024
|
return dataFromHash;
|
|
1066
1025
|
};
|
|
1067
1026
|
const clearHash = () => {
|
|
@@ -1098,8 +1057,7 @@ function useDialog(options) {
|
|
|
1098
1057
|
vnode2.component.props.modelValue = value;
|
|
1099
1058
|
if (!value && route?.hash) {
|
|
1100
1059
|
const dataFromHash = parseHash(route.hash, component.name);
|
|
1101
|
-
if (dataFromHash?.layer === layer)
|
|
1102
|
-
clearHash();
|
|
1060
|
+
if (dataFromHash?.layer === layer) clearHash();
|
|
1103
1061
|
}
|
|
1104
1062
|
if (!value && (dialogs.length === 1 || layer === 0) && isGlobalScrollLocked.value) {
|
|
1105
1063
|
unlockGlobalScroll();
|
|
@@ -1108,14 +1066,11 @@ function useDialog(options) {
|
|
|
1108
1066
|
};
|
|
1109
1067
|
}
|
|
1110
1068
|
vnode2.close = () => {
|
|
1111
|
-
if (!vnode2 || !vnode2.component)
|
|
1112
|
-
return;
|
|
1069
|
+
if (!vnode2 || !vnode2.component) return;
|
|
1113
1070
|
vnode2.component.props.modelValue = false;
|
|
1114
|
-
if (!route?.hash)
|
|
1115
|
-
return;
|
|
1071
|
+
if (!route?.hash) return;
|
|
1116
1072
|
const dataFromHash = parseHash(route.hash, component.name);
|
|
1117
|
-
if (dataFromHash?.layer === layer)
|
|
1118
|
-
clearHash();
|
|
1073
|
+
if (dataFromHash?.layer === layer) clearHash();
|
|
1119
1074
|
};
|
|
1120
1075
|
vnode2.props.onDestroy = () => {
|
|
1121
1076
|
vue.render(null, el2);
|
|
@@ -1189,13 +1144,11 @@ function useDialog(options) {
|
|
|
1189
1144
|
return dialogs.find((item) => item.uuid === uuid)?.vnode;
|
|
1190
1145
|
};
|
|
1191
1146
|
const getLayer = (uuid) => {
|
|
1192
|
-
if (!dialogs.length)
|
|
1193
|
-
return 0;
|
|
1147
|
+
if (!dialogs.length) return 0;
|
|
1194
1148
|
return dialogs.find((dialog) => dialog.uuid === uuid)?.layer || 0;
|
|
1195
1149
|
};
|
|
1196
1150
|
const isOnTop = (uuid) => {
|
|
1197
|
-
if (!dialogs.length)
|
|
1198
|
-
return false;
|
|
1151
|
+
if (!dialogs.length) return false;
|
|
1199
1152
|
const dialogsSorted = [...dialogs].sort((a, b) => b.layer - a.layer);
|
|
1200
1153
|
return dialogsSorted[0].uuid === uuid;
|
|
1201
1154
|
};
|
|
@@ -1222,14 +1175,12 @@ function useDialog(options) {
|
|
|
1222
1175
|
() => route.hash,
|
|
1223
1176
|
async (newHash) => {
|
|
1224
1177
|
if (!newHash) {
|
|
1225
|
-
if (!dialogs.length)
|
|
1226
|
-
return;
|
|
1178
|
+
if (!dialogs.length) return;
|
|
1227
1179
|
closeAll();
|
|
1228
1180
|
return;
|
|
1229
1181
|
}
|
|
1230
1182
|
const dataFromHash = parseHash(newHash, component.name);
|
|
1231
|
-
if (!dataFromHash)
|
|
1232
|
-
return;
|
|
1183
|
+
if (!dataFromHash) return;
|
|
1233
1184
|
logger.info("*watchHash* data from hash", dataFromHash);
|
|
1234
1185
|
await vue.nextTick();
|
|
1235
1186
|
open({
|
|
@@ -1281,19 +1232,16 @@ function useFilters({ config, initialFilters }) {
|
|
|
1281
1232
|
const parseRouteQuery = (query) => qs__default.parse(query ?? route.query);
|
|
1282
1233
|
const filtersFromQuery = vue.computed(() => {
|
|
1283
1234
|
const parsedRouteQuery = parseRouteQuery();
|
|
1284
|
-
if (!parsedRouteQuery.filters)
|
|
1285
|
-
return void 0;
|
|
1235
|
+
if (!parsedRouteQuery.filters) return void 0;
|
|
1286
1236
|
return Object.entries(config).reduce(
|
|
1287
1237
|
(accum, [currentKey, currentValue]) => {
|
|
1288
|
-
if (!parsedRouteQuery.filters[currentKey])
|
|
1289
|
-
return accum;
|
|
1238
|
+
if (!parsedRouteQuery.filters[currentKey]) return accum;
|
|
1290
1239
|
if (currentValue.type === "ARRAY" /* Array */) {
|
|
1291
1240
|
const splitValues = parsedRouteQuery.filters[currentKey].split(",");
|
|
1292
1241
|
const checkedValue = currentValue?.possibleValues ? splitValues.filter(
|
|
1293
1242
|
(k) => currentValue?.possibleValues?.includes(k)
|
|
1294
1243
|
) : splitValues;
|
|
1295
|
-
if (!checkedValue?.length)
|
|
1296
|
-
return accum;
|
|
1244
|
+
if (!checkedValue?.length) return accum;
|
|
1297
1245
|
return {
|
|
1298
1246
|
...accum,
|
|
1299
1247
|
[currentKey]: checkedValue
|
|
@@ -1314,8 +1262,7 @@ function useFilters({ config, initialFilters }) {
|
|
|
1314
1262
|
const parsedRouteQuery = parseRouteQuery();
|
|
1315
1263
|
const filteredValue = Object.entries(filters).reduce(
|
|
1316
1264
|
(accum, [currentKey, currentValue]) => {
|
|
1317
|
-
if (!currentValue?.length)
|
|
1318
|
-
return accum;
|
|
1265
|
+
if (!currentValue?.length) return accum;
|
|
1319
1266
|
return { ...accum, [currentKey]: currentValue };
|
|
1320
1267
|
},
|
|
1321
1268
|
{}
|
|
@@ -1543,14 +1490,12 @@ function usePanel() {
|
|
|
1543
1490
|
} catch (_error) {
|
|
1544
1491
|
logger.error("*watchHash* cant parse hash");
|
|
1545
1492
|
}
|
|
1546
|
-
if (typeof dataFromHash !== "object")
|
|
1547
|
-
return;
|
|
1493
|
+
if (typeof dataFromHash !== "object") return;
|
|
1548
1494
|
if (!dataFromHash.name) {
|
|
1549
1495
|
logger.error("*watchHash* cant find component name in hash");
|
|
1550
1496
|
return;
|
|
1551
1497
|
}
|
|
1552
|
-
if (dataFromHash.name !== component.name)
|
|
1553
|
-
return;
|
|
1498
|
+
if (dataFromHash.name !== component.name) return;
|
|
1554
1499
|
logger.info("*watchHash* data from hash", dataFromHash);
|
|
1555
1500
|
await vue.nextTick();
|
|
1556
1501
|
open({
|
|
@@ -1558,8 +1503,7 @@ function usePanel() {
|
|
|
1558
1503
|
layer: dataFromHash.layer || 0,
|
|
1559
1504
|
props: {
|
|
1560
1505
|
"onUpdate:modelValue": (value) => {
|
|
1561
|
-
if (value)
|
|
1562
|
-
return;
|
|
1506
|
+
if (value) return;
|
|
1563
1507
|
router.push({
|
|
1564
1508
|
name: route.name || void 0,
|
|
1565
1509
|
query: route.query,
|
|
@@ -1593,8 +1537,7 @@ function usePanel() {
|
|
|
1593
1537
|
}
|
|
1594
1538
|
|
|
1595
1539
|
function validatePhone(rule, value) {
|
|
1596
|
-
if (!value)
|
|
1597
|
-
return true;
|
|
1540
|
+
if (!value) return true;
|
|
1598
1541
|
const phoneNumber = libphonenumberJs.parsePhoneNumberFromString(value);
|
|
1599
1542
|
return phoneNumber ? phoneNumber.isValid() : false;
|
|
1600
1543
|
}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as vue from 'vue';
|
|
2
|
-
import { MaybeRef, Component, EmitsOptions,
|
|
2
|
+
import { MaybeRef, VNode, Component, EmitsOptions, Ref } from 'vue';
|
|
3
3
|
import { AxiosRequestConfig } from 'axios';
|
|
4
4
|
export { AxiosError as HttpError, AxiosPromise as HttpPromise, AxiosRequestConfig as HttpRequestConfig, AxiosResponse as HttpResponse } from 'axios';
|
|
5
5
|
import { MaybeRef as MaybeRef$1 } from '@vueuse/core';
|
|
@@ -223,14 +223,14 @@ declare function useAsyncSelect<T extends (...args: any[]) => any, K extends (pa
|
|
|
223
223
|
};
|
|
224
224
|
|
|
225
225
|
declare function useBreakpoint(): {
|
|
226
|
-
isMobile: vue.
|
|
227
|
-
isDesktop: vue.
|
|
228
|
-
isGreaterXxs: vue.
|
|
229
|
-
isGreaterXs: vue.
|
|
230
|
-
isGreaterSm: vue.
|
|
231
|
-
isGreaterMd: vue.
|
|
232
|
-
isGreaterLg: vue.
|
|
233
|
-
isGreaterXl: vue.
|
|
226
|
+
isMobile: vue.ComputedRef<boolean>;
|
|
227
|
+
isDesktop: vue.ComputedRef<boolean>;
|
|
228
|
+
isGreaterXxs: vue.ComputedRef<boolean>;
|
|
229
|
+
isGreaterXs: vue.ComputedRef<boolean>;
|
|
230
|
+
isGreaterSm: vue.ComputedRef<boolean>;
|
|
231
|
+
isGreaterMd: vue.ComputedRef<boolean>;
|
|
232
|
+
isGreaterLg: vue.ComputedRef<boolean>;
|
|
233
|
+
isGreaterXl: vue.ComputedRef<boolean>;
|
|
234
234
|
};
|
|
235
235
|
|
|
236
236
|
declare function useClassName(block: string): {
|
|
@@ -390,4 +390,5 @@ declare function isTypeUrl(message?: string): RuleItem;
|
|
|
390
390
|
declare function isTypeNumber(value?: number, message?: string): RuleItem;
|
|
391
391
|
declare function isStrictLength(value?: number, message?: string): RuleItem;
|
|
392
392
|
|
|
393
|
-
export { AppComponentsResolver,
|
|
393
|
+
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 };
|
|
394
|
+
export type { BrowserInfo, Dialog, DialogOptions, DialogParseHashResult, Dictionary, ResponseError, VersionsList };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as vue from 'vue';
|
|
2
|
-
import { MaybeRef, Component, EmitsOptions,
|
|
2
|
+
import { MaybeRef, VNode, Component, EmitsOptions, Ref } from 'vue';
|
|
3
3
|
import { AxiosRequestConfig } from 'axios';
|
|
4
4
|
export { AxiosError as HttpError, AxiosPromise as HttpPromise, AxiosRequestConfig as HttpRequestConfig, AxiosResponse as HttpResponse } from 'axios';
|
|
5
5
|
import { MaybeRef as MaybeRef$1 } from '@vueuse/core';
|
|
@@ -223,14 +223,14 @@ declare function useAsyncSelect<T extends (...args: any[]) => any, K extends (pa
|
|
|
223
223
|
};
|
|
224
224
|
|
|
225
225
|
declare function useBreakpoint(): {
|
|
226
|
-
isMobile: vue.
|
|
227
|
-
isDesktop: vue.
|
|
228
|
-
isGreaterXxs: vue.
|
|
229
|
-
isGreaterXs: vue.
|
|
230
|
-
isGreaterSm: vue.
|
|
231
|
-
isGreaterMd: vue.
|
|
232
|
-
isGreaterLg: vue.
|
|
233
|
-
isGreaterXl: vue.
|
|
226
|
+
isMobile: vue.ComputedRef<boolean>;
|
|
227
|
+
isDesktop: vue.ComputedRef<boolean>;
|
|
228
|
+
isGreaterXxs: vue.ComputedRef<boolean>;
|
|
229
|
+
isGreaterXs: vue.ComputedRef<boolean>;
|
|
230
|
+
isGreaterSm: vue.ComputedRef<boolean>;
|
|
231
|
+
isGreaterMd: vue.ComputedRef<boolean>;
|
|
232
|
+
isGreaterLg: vue.ComputedRef<boolean>;
|
|
233
|
+
isGreaterXl: vue.ComputedRef<boolean>;
|
|
234
234
|
};
|
|
235
235
|
|
|
236
236
|
declare function useClassName(block: string): {
|
|
@@ -390,4 +390,5 @@ declare function isTypeUrl(message?: string): RuleItem;
|
|
|
390
390
|
declare function isTypeNumber(value?: number, message?: string): RuleItem;
|
|
391
391
|
declare function isStrictLength(value?: number, message?: string): RuleItem;
|
|
392
392
|
|
|
393
|
-
export { AppComponentsResolver,
|
|
393
|
+
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 };
|
|
394
|
+
export type { BrowserInfo, Dialog, DialogOptions, DialogParseHashResult, Dictionary, ResponseError, VersionsList };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as vue from 'vue';
|
|
2
|
-
import { MaybeRef, Component, EmitsOptions,
|
|
2
|
+
import { MaybeRef, VNode, Component, EmitsOptions, Ref } from 'vue';
|
|
3
3
|
import { AxiosRequestConfig } from 'axios';
|
|
4
4
|
export { AxiosError as HttpError, AxiosPromise as HttpPromise, AxiosRequestConfig as HttpRequestConfig, AxiosResponse as HttpResponse } from 'axios';
|
|
5
5
|
import { MaybeRef as MaybeRef$1 } from '@vueuse/core';
|
|
@@ -223,14 +223,14 @@ declare function useAsyncSelect<T extends (...args: any[]) => any, K extends (pa
|
|
|
223
223
|
};
|
|
224
224
|
|
|
225
225
|
declare function useBreakpoint(): {
|
|
226
|
-
isMobile: vue.
|
|
227
|
-
isDesktop: vue.
|
|
228
|
-
isGreaterXxs: vue.
|
|
229
|
-
isGreaterXs: vue.
|
|
230
|
-
isGreaterSm: vue.
|
|
231
|
-
isGreaterMd: vue.
|
|
232
|
-
isGreaterLg: vue.
|
|
233
|
-
isGreaterXl: vue.
|
|
226
|
+
isMobile: vue.ComputedRef<boolean>;
|
|
227
|
+
isDesktop: vue.ComputedRef<boolean>;
|
|
228
|
+
isGreaterXxs: vue.ComputedRef<boolean>;
|
|
229
|
+
isGreaterXs: vue.ComputedRef<boolean>;
|
|
230
|
+
isGreaterSm: vue.ComputedRef<boolean>;
|
|
231
|
+
isGreaterMd: vue.ComputedRef<boolean>;
|
|
232
|
+
isGreaterLg: vue.ComputedRef<boolean>;
|
|
233
|
+
isGreaterXl: vue.ComputedRef<boolean>;
|
|
234
234
|
};
|
|
235
235
|
|
|
236
236
|
declare function useClassName(block: string): {
|
|
@@ -390,4 +390,5 @@ declare function isTypeUrl(message?: string): RuleItem;
|
|
|
390
390
|
declare function isTypeNumber(value?: number, message?: string): RuleItem;
|
|
391
391
|
declare function isStrictLength(value?: number, message?: string): RuleItem;
|
|
392
392
|
|
|
393
|
-
export { AppComponentsResolver,
|
|
393
|
+
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 };
|
|
394
|
+
export type { BrowserInfo, Dialog, DialogOptions, DialogParseHashResult, Dictionary, ResponseError, VersionsList };
|
package/dist/index.mjs
CHANGED
|
@@ -3,9 +3,9 @@ import flatMap from 'lodash/flatMap.js';
|
|
|
3
3
|
import { CURRENCY_DEFAULT, BREAKPOINTS } from '@karta.io/common-data';
|
|
4
4
|
import { parsePhoneNumberFromString } from 'libphonenumber-js';
|
|
5
5
|
import snakeCase from 'lodash/snakeCase.js';
|
|
6
|
-
import { computed, ref, watch, reactive, isRef, nextTick, onBeforeUnmount, onMounted, getCurrentInstance, render, createVNode } from 'vue';
|
|
7
|
-
import { toValue, useDebounceFn, useBreakpoints } from '@vueuse/core';
|
|
6
|
+
import { toValue, computed, ref, watch, reactive, isRef, nextTick, onBeforeUnmount, onMounted, getCurrentInstance, render, createVNode } from 'vue';
|
|
8
7
|
import { useQuery, useQueryClient } from '@tanstack/vue-query';
|
|
8
|
+
import { useDebounceFn, useBreakpoints } from '@vueuse/core';
|
|
9
9
|
import get from 'lodash/get.js';
|
|
10
10
|
import has from 'lodash/has.js';
|
|
11
11
|
import union from 'lodash/union.js';
|
|
@@ -121,8 +121,7 @@ function getStatusMessage(status) {
|
|
|
121
121
|
return message;
|
|
122
122
|
}
|
|
123
123
|
function formatErrorDataMessage(data) {
|
|
124
|
-
if (!data)
|
|
125
|
-
return "";
|
|
124
|
+
if (!data) return "";
|
|
126
125
|
return Object.values(data).reduce((accum, current) => {
|
|
127
126
|
if (current && typeof current === "string")
|
|
128
127
|
return accum ? `${accum} | ${current}` : current;
|
|
@@ -134,8 +133,7 @@ function formatErrorDataMessage(data) {
|
|
|
134
133
|
}, "");
|
|
135
134
|
}
|
|
136
135
|
function formatErrorForNotify(error) {
|
|
137
|
-
if (!error)
|
|
138
|
-
return;
|
|
136
|
+
if (!error) return;
|
|
139
137
|
if (error.status >= 400 && error.status < 500) {
|
|
140
138
|
let message = "";
|
|
141
139
|
if (!error.data || typeof error.data === "string" && isHtml(error.data)) {
|
|
@@ -169,8 +167,7 @@ function formatMoney(value, currency = CURRENCY_DEFAULT, options = {}) {
|
|
|
169
167
|
try {
|
|
170
168
|
let convertedValue = Number(value);
|
|
171
169
|
if (value === null || Number.isNaN(convertedValue)) {
|
|
172
|
-
if (defaultValue === "")
|
|
173
|
-
return defaultValue;
|
|
170
|
+
if (defaultValue === "") return defaultValue;
|
|
174
171
|
convertedValue = Number(defaultValue);
|
|
175
172
|
}
|
|
176
173
|
const formatter = new Intl.NumberFormat(locale, {
|
|
@@ -230,8 +227,7 @@ function getCardNumber(number, options) {
|
|
|
230
227
|
}
|
|
231
228
|
|
|
232
229
|
function getCountryFromPhone(phone) {
|
|
233
|
-
if (!phone)
|
|
234
|
-
return "";
|
|
230
|
+
if (!phone) return "";
|
|
235
231
|
const replacedPhone = phone.replace(/[a-zA-Z]/g, "");
|
|
236
232
|
const phoneNumber = parsePhoneNumberFromString(replacedPhone);
|
|
237
233
|
return phoneNumber?.country ?? "";
|
|
@@ -273,8 +269,7 @@ function mapDataObjectForFilters(data, options) {
|
|
|
273
269
|
}
|
|
274
270
|
|
|
275
271
|
function validateNumber(value, defaultValue) {
|
|
276
|
-
if (value === "")
|
|
277
|
-
return defaultValue;
|
|
272
|
+
if (value === "") return defaultValue;
|
|
278
273
|
return Number.isNaN(Number(value)) ? defaultValue : Number(value);
|
|
279
274
|
}
|
|
280
275
|
|
|
@@ -312,8 +307,7 @@ function getPaginationPages({
|
|
|
312
307
|
}
|
|
313
308
|
|
|
314
309
|
function parsePhone(phone) {
|
|
315
|
-
if (!phone || typeof phone !== "string")
|
|
316
|
-
return "";
|
|
310
|
+
if (!phone || typeof phone !== "string") return "";
|
|
317
311
|
const replacedPhone = phone.replace(/[a-zA-Z]/g, "");
|
|
318
312
|
if (replacedPhone.length === 1 && replacedPhone !== "+") {
|
|
319
313
|
return `+${replacedPhone}`;
|
|
@@ -341,8 +335,7 @@ function snakelizeKeys(prop) {
|
|
|
341
335
|
const LOCALE_RU = "ru-RU";
|
|
342
336
|
const LOCALE_EN = "en-US";
|
|
343
337
|
function unformatNumber(value) {
|
|
344
|
-
if (!value || typeof value !== "string")
|
|
345
|
-
return value;
|
|
338
|
+
if (!value || typeof value !== "string") return value;
|
|
346
339
|
const string = value.trim();
|
|
347
340
|
let locale;
|
|
348
341
|
const spaceIndex = string.lastIndexOf(" ");
|
|
@@ -352,24 +345,18 @@ function unformatNumber(value) {
|
|
|
352
345
|
const hasComma = commaIndex !== -1;
|
|
353
346
|
const hasDot = dotIndex !== -1;
|
|
354
347
|
const commasCount = (string.match(/,/g) || []).length;
|
|
355
|
-
if (!Number.isNaN(Number(string)))
|
|
356
|
-
|
|
357
|
-
if (hasSpace && hasComma &&
|
|
358
|
-
|
|
359
|
-
if (
|
|
360
|
-
locale = LOCALE_RU;
|
|
361
|
-
if (hasComma && hasDot && dotIndex > commaIndex)
|
|
362
|
-
locale = LOCALE_EN;
|
|
363
|
-
if (hasComma && !hasSpace && !hasDot && commasCount > 1)
|
|
364
|
-
locale = LOCALE_EN;
|
|
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;
|
|
365
353
|
if (commasCount === 1 && !hasSpace && !hasDot) {
|
|
366
354
|
locale = string.length - 1 - commaIndex === 3 ? LOCALE_EN : LOCALE_RU;
|
|
367
355
|
}
|
|
368
356
|
if (locale === LOCALE_RU) {
|
|
369
357
|
return Number(string.replaceAll(" ", "").replace(",", "."));
|
|
370
358
|
}
|
|
371
|
-
if (locale === LOCALE_EN)
|
|
372
|
-
return Number(string.replaceAll(",", ""));
|
|
359
|
+
if (locale === LOCALE_EN) return Number(string.replaceAll(",", ""));
|
|
373
360
|
return value;
|
|
374
361
|
}
|
|
375
362
|
|
|
@@ -388,8 +375,7 @@ function useAbortController(callback) {
|
|
|
388
375
|
let controller = null;
|
|
389
376
|
return {
|
|
390
377
|
async call(...args) {
|
|
391
|
-
if (controller)
|
|
392
|
-
controller.abort();
|
|
378
|
+
if (controller) controller.abort();
|
|
393
379
|
controller = new AbortController();
|
|
394
380
|
let response;
|
|
395
381
|
if (args.length > 0) {
|
|
@@ -405,8 +391,7 @@ function useAbortController(callback) {
|
|
|
405
391
|
return response;
|
|
406
392
|
},
|
|
407
393
|
abort() {
|
|
408
|
-
if (!controller)
|
|
409
|
-
return;
|
|
394
|
+
if (!controller) return;
|
|
410
395
|
controller.abort();
|
|
411
396
|
controller = null;
|
|
412
397
|
},
|
|
@@ -435,8 +420,7 @@ function useAsyncItems({
|
|
|
435
420
|
watch(
|
|
436
421
|
data,
|
|
437
422
|
(newValue) => {
|
|
438
|
-
if (newValue === void 0 || newValue.count === void 0)
|
|
439
|
-
return;
|
|
423
|
+
if (newValue === void 0 || newValue.count === void 0) return;
|
|
440
424
|
count.value = newValue.count;
|
|
441
425
|
},
|
|
442
426
|
{ immediate: true }
|
|
@@ -463,23 +447,18 @@ function useAsyncItems({
|
|
|
463
447
|
}
|
|
464
448
|
|
|
465
449
|
function isEnabled(options) {
|
|
466
|
-
if (options?.debug !== void 0)
|
|
467
|
-
return options.debug;
|
|
450
|
+
if (options?.debug !== void 0) return options.debug;
|
|
468
451
|
const isBrowser = typeof window !== "undefined" && typeof window.document !== "undefined";
|
|
469
452
|
if (isBrowser) {
|
|
470
453
|
const debug = localStorage.getItem("debug");
|
|
471
|
-
if (debug === "true")
|
|
472
|
-
|
|
473
|
-
if (debug === "false")
|
|
474
|
-
return false;
|
|
454
|
+
if (debug === "true") return true;
|
|
455
|
+
if (debug === "false") return false;
|
|
475
456
|
}
|
|
476
457
|
const isNode = typeof process !== "undefined" && process.versions != null && process.versions.node != null;
|
|
477
458
|
if (isNode) {
|
|
478
459
|
const debug = process.env.NODE_DEBUG;
|
|
479
|
-
if (debug === "true")
|
|
480
|
-
|
|
481
|
-
if (debug === "false")
|
|
482
|
-
return false;
|
|
460
|
+
if (debug === "true") return true;
|
|
461
|
+
if (debug === "false") return false;
|
|
483
462
|
}
|
|
484
463
|
return false;
|
|
485
464
|
}
|
|
@@ -542,8 +521,7 @@ function useAsyncMultiselect({
|
|
|
542
521
|
watch(
|
|
543
522
|
data,
|
|
544
523
|
(newValue) => {
|
|
545
|
-
if (!newValue)
|
|
546
|
-
return;
|
|
524
|
+
if (!newValue) return;
|
|
547
525
|
if (!has(newValue, dataItemsKey)) {
|
|
548
526
|
logger.warn(
|
|
549
527
|
`Unable to find key *"${dataItemsKey}"* (property "dataItemsKey") in data object from API.`,
|
|
@@ -589,8 +567,7 @@ function useAsyncMultiselect({
|
|
|
589
567
|
{ immediate: true }
|
|
590
568
|
);
|
|
591
569
|
const items = computed(() => {
|
|
592
|
-
if (!itemsByPages.value)
|
|
593
|
-
return selectedItemsCached.value;
|
|
570
|
+
if (!itemsByPages.value) return selectedItemsCached.value;
|
|
594
571
|
if (!Object.keys(itemsByPages.value).length) {
|
|
595
572
|
return selectedItemsCached.value;
|
|
596
573
|
}
|
|
@@ -606,10 +583,8 @@ function useAsyncMultiselect({
|
|
|
606
583
|
return [...itemsAsMap.values()];
|
|
607
584
|
});
|
|
608
585
|
const options = computed(() => {
|
|
609
|
-
if (!items.value.length)
|
|
610
|
-
|
|
611
|
-
if (!mapOptionCallback)
|
|
612
|
-
return items.value;
|
|
586
|
+
if (!items.value.length) return [];
|
|
587
|
+
if (!mapOptionCallback) return items.value;
|
|
613
588
|
return items.value.map(mapOptionCallback);
|
|
614
589
|
});
|
|
615
590
|
const hasNextPage = computed(() => count.value > items.value.length);
|
|
@@ -738,8 +713,7 @@ function useAsyncSelect({
|
|
|
738
713
|
watch(
|
|
739
714
|
data,
|
|
740
715
|
(newValue) => {
|
|
741
|
-
if (!newValue)
|
|
742
|
-
return;
|
|
716
|
+
if (!newValue) return;
|
|
743
717
|
if (!has(newValue, dataItemsKey)) {
|
|
744
718
|
logger.warn(
|
|
745
719
|
`Unable to find key *"${dataItemsKey}"* (property "dataItemsKey") in data object from API.`,
|
|
@@ -773,20 +747,16 @@ function useAsyncSelect({
|
|
|
773
747
|
{ immediate: true }
|
|
774
748
|
);
|
|
775
749
|
const items = computed(() => {
|
|
776
|
-
if (!itemsByPages.value)
|
|
777
|
-
|
|
778
|
-
if (!Object.keys(itemsByPages.value).length)
|
|
779
|
-
return [];
|
|
750
|
+
if (!itemsByPages.value) return [];
|
|
751
|
+
if (!Object.keys(itemsByPages.value).length) return [];
|
|
780
752
|
return Object.values(itemsByPages.value).reduce(
|
|
781
753
|
(acc, item) => [...acc, ...item],
|
|
782
754
|
[]
|
|
783
755
|
);
|
|
784
756
|
});
|
|
785
757
|
const options = computed(() => {
|
|
786
|
-
if (!items.value.length)
|
|
787
|
-
|
|
788
|
-
if (!mapOptionCallback)
|
|
789
|
-
return items.value;
|
|
758
|
+
if (!items.value.length) return [];
|
|
759
|
+
if (!mapOptionCallback) return items.value;
|
|
790
760
|
return items.value.map(mapOptionCallback);
|
|
791
761
|
});
|
|
792
762
|
const hasNextPage = computed(() => count.value > items.value.length);
|
|
@@ -876,14 +846,10 @@ function useBreakpoint() {
|
|
|
876
846
|
|
|
877
847
|
function _bem(block, blockSuffix, element, modifier, modifierValue) {
|
|
878
848
|
let cls = block;
|
|
879
|
-
if (blockSuffix)
|
|
880
|
-
|
|
881
|
-
if (
|
|
882
|
-
|
|
883
|
-
if (modifier)
|
|
884
|
-
cls += `_${modifier}`;
|
|
885
|
-
if (modifierValue)
|
|
886
|
-
cls += `_${modifierValue}`;
|
|
849
|
+
if (blockSuffix) cls += `-${blockSuffix}`;
|
|
850
|
+
if (element) cls += `__${element}`;
|
|
851
|
+
if (modifier) cls += `_${modifier}`;
|
|
852
|
+
if (modifierValue) cls += `_${modifierValue}`;
|
|
887
853
|
return cls;
|
|
888
854
|
}
|
|
889
855
|
function useClassName(block) {
|
|
@@ -894,8 +860,7 @@ function useClassName(block) {
|
|
|
894
860
|
const mv = (modifier, modifierValue, condition = true) => modifier && modifierValue && condition ? _bem(block, "", "", modifier, modifierValue) : "";
|
|
895
861
|
const cssVar = (object) => {
|
|
896
862
|
const styles = {};
|
|
897
|
-
for (const key in object)
|
|
898
|
-
styles[`--${block}-${key}`] = object[key];
|
|
863
|
+
for (const key in object) styles[`--${block}-${key}`] = object[key];
|
|
899
864
|
return styles;
|
|
900
865
|
};
|
|
901
866
|
const cssVarName = (name) => `--${block}-${name}`;
|
|
@@ -920,8 +885,7 @@ function useDayjs(timezone) {
|
|
|
920
885
|
dayjs.updateLocale("en", {
|
|
921
886
|
weekStart: 1
|
|
922
887
|
});
|
|
923
|
-
if (!timezone)
|
|
924
|
-
return dayjs;
|
|
888
|
+
if (!timezone) return dayjs;
|
|
925
889
|
const dayjsExtended = (date, format, locale, strict) => dayjs(date, format, locale, strict).tz(timezone);
|
|
926
890
|
return dayjsExtended;
|
|
927
891
|
}
|
|
@@ -942,8 +906,7 @@ function parseVersion(version) {
|
|
|
942
906
|
}
|
|
943
907
|
function isVersionLower(minimum, target) {
|
|
944
908
|
for (const k of ["major", "minor", "patch"]) {
|
|
945
|
-
if (minimum[k] !== target[k])
|
|
946
|
-
return minimum[k] > target[k];
|
|
909
|
+
if (minimum[k] !== target[k]) return minimum[k] > target[k];
|
|
947
910
|
}
|
|
948
911
|
return minimum.build > target.build;
|
|
949
912
|
}
|
|
@@ -1025,24 +988,20 @@ function useDialog(options) {
|
|
|
1025
988
|
return `${hashPrefix}${window.btoa(JSON.stringify(data))}`;
|
|
1026
989
|
};
|
|
1027
990
|
const parseHash = (hash, componentName) => {
|
|
1028
|
-
if (!hash)
|
|
1029
|
-
|
|
1030
|
-
if (!hash.includes(hashPrefix))
|
|
1031
|
-
return void 0;
|
|
991
|
+
if (!hash) return void 0;
|
|
992
|
+
if (!hash.includes(hashPrefix)) return void 0;
|
|
1032
993
|
let dataFromHash;
|
|
1033
994
|
try {
|
|
1034
995
|
dataFromHash = JSON.parse(window.atob(hash.slice(hashPrefix.length)));
|
|
1035
996
|
} catch (_error) {
|
|
1036
997
|
logger.warn("*parseHash* cant parse hash");
|
|
1037
998
|
}
|
|
1038
|
-
if (typeof dataFromHash !== "object")
|
|
1039
|
-
return void 0;
|
|
999
|
+
if (typeof dataFromHash !== "object") return void 0;
|
|
1040
1000
|
if (!dataFromHash.name) {
|
|
1041
1001
|
logger.warn("*parseHash* cant find component name in hash");
|
|
1042
1002
|
return void 0;
|
|
1043
1003
|
}
|
|
1044
|
-
if (dataFromHash.name !== componentName)
|
|
1045
|
-
return void 0;
|
|
1004
|
+
if (dataFromHash.name !== componentName) return void 0;
|
|
1046
1005
|
return dataFromHash;
|
|
1047
1006
|
};
|
|
1048
1007
|
const clearHash = () => {
|
|
@@ -1079,8 +1038,7 @@ function useDialog(options) {
|
|
|
1079
1038
|
vnode2.component.props.modelValue = value;
|
|
1080
1039
|
if (!value && route?.hash) {
|
|
1081
1040
|
const dataFromHash = parseHash(route.hash, component.name);
|
|
1082
|
-
if (dataFromHash?.layer === layer)
|
|
1083
|
-
clearHash();
|
|
1041
|
+
if (dataFromHash?.layer === layer) clearHash();
|
|
1084
1042
|
}
|
|
1085
1043
|
if (!value && (dialogs.length === 1 || layer === 0) && isGlobalScrollLocked.value) {
|
|
1086
1044
|
unlockGlobalScroll();
|
|
@@ -1089,14 +1047,11 @@ function useDialog(options) {
|
|
|
1089
1047
|
};
|
|
1090
1048
|
}
|
|
1091
1049
|
vnode2.close = () => {
|
|
1092
|
-
if (!vnode2 || !vnode2.component)
|
|
1093
|
-
return;
|
|
1050
|
+
if (!vnode2 || !vnode2.component) return;
|
|
1094
1051
|
vnode2.component.props.modelValue = false;
|
|
1095
|
-
if (!route?.hash)
|
|
1096
|
-
return;
|
|
1052
|
+
if (!route?.hash) return;
|
|
1097
1053
|
const dataFromHash = parseHash(route.hash, component.name);
|
|
1098
|
-
if (dataFromHash?.layer === layer)
|
|
1099
|
-
clearHash();
|
|
1054
|
+
if (dataFromHash?.layer === layer) clearHash();
|
|
1100
1055
|
};
|
|
1101
1056
|
vnode2.props.onDestroy = () => {
|
|
1102
1057
|
render(null, el2);
|
|
@@ -1170,13 +1125,11 @@ function useDialog(options) {
|
|
|
1170
1125
|
return dialogs.find((item) => item.uuid === uuid)?.vnode;
|
|
1171
1126
|
};
|
|
1172
1127
|
const getLayer = (uuid) => {
|
|
1173
|
-
if (!dialogs.length)
|
|
1174
|
-
return 0;
|
|
1128
|
+
if (!dialogs.length) return 0;
|
|
1175
1129
|
return dialogs.find((dialog) => dialog.uuid === uuid)?.layer || 0;
|
|
1176
1130
|
};
|
|
1177
1131
|
const isOnTop = (uuid) => {
|
|
1178
|
-
if (!dialogs.length)
|
|
1179
|
-
return false;
|
|
1132
|
+
if (!dialogs.length) return false;
|
|
1180
1133
|
const dialogsSorted = [...dialogs].sort((a, b) => b.layer - a.layer);
|
|
1181
1134
|
return dialogsSorted[0].uuid === uuid;
|
|
1182
1135
|
};
|
|
@@ -1203,14 +1156,12 @@ function useDialog(options) {
|
|
|
1203
1156
|
() => route.hash,
|
|
1204
1157
|
async (newHash) => {
|
|
1205
1158
|
if (!newHash) {
|
|
1206
|
-
if (!dialogs.length)
|
|
1207
|
-
return;
|
|
1159
|
+
if (!dialogs.length) return;
|
|
1208
1160
|
closeAll();
|
|
1209
1161
|
return;
|
|
1210
1162
|
}
|
|
1211
1163
|
const dataFromHash = parseHash(newHash, component.name);
|
|
1212
|
-
if (!dataFromHash)
|
|
1213
|
-
return;
|
|
1164
|
+
if (!dataFromHash) return;
|
|
1214
1165
|
logger.info("*watchHash* data from hash", dataFromHash);
|
|
1215
1166
|
await nextTick();
|
|
1216
1167
|
open({
|
|
@@ -1262,19 +1213,16 @@ function useFilters({ config, initialFilters }) {
|
|
|
1262
1213
|
const parseRouteQuery = (query) => qs.parse(query ?? route.query);
|
|
1263
1214
|
const filtersFromQuery = computed(() => {
|
|
1264
1215
|
const parsedRouteQuery = parseRouteQuery();
|
|
1265
|
-
if (!parsedRouteQuery.filters)
|
|
1266
|
-
return void 0;
|
|
1216
|
+
if (!parsedRouteQuery.filters) return void 0;
|
|
1267
1217
|
return Object.entries(config).reduce(
|
|
1268
1218
|
(accum, [currentKey, currentValue]) => {
|
|
1269
|
-
if (!parsedRouteQuery.filters[currentKey])
|
|
1270
|
-
return accum;
|
|
1219
|
+
if (!parsedRouteQuery.filters[currentKey]) return accum;
|
|
1271
1220
|
if (currentValue.type === "ARRAY" /* Array */) {
|
|
1272
1221
|
const splitValues = parsedRouteQuery.filters[currentKey].split(",");
|
|
1273
1222
|
const checkedValue = currentValue?.possibleValues ? splitValues.filter(
|
|
1274
1223
|
(k) => currentValue?.possibleValues?.includes(k)
|
|
1275
1224
|
) : splitValues;
|
|
1276
|
-
if (!checkedValue?.length)
|
|
1277
|
-
return accum;
|
|
1225
|
+
if (!checkedValue?.length) return accum;
|
|
1278
1226
|
return {
|
|
1279
1227
|
...accum,
|
|
1280
1228
|
[currentKey]: checkedValue
|
|
@@ -1295,8 +1243,7 @@ function useFilters({ config, initialFilters }) {
|
|
|
1295
1243
|
const parsedRouteQuery = parseRouteQuery();
|
|
1296
1244
|
const filteredValue = Object.entries(filters).reduce(
|
|
1297
1245
|
(accum, [currentKey, currentValue]) => {
|
|
1298
|
-
if (!currentValue?.length)
|
|
1299
|
-
return accum;
|
|
1246
|
+
if (!currentValue?.length) return accum;
|
|
1300
1247
|
return { ...accum, [currentKey]: currentValue };
|
|
1301
1248
|
},
|
|
1302
1249
|
{}
|
|
@@ -1524,14 +1471,12 @@ function usePanel() {
|
|
|
1524
1471
|
} catch (_error) {
|
|
1525
1472
|
logger.error("*watchHash* cant parse hash");
|
|
1526
1473
|
}
|
|
1527
|
-
if (typeof dataFromHash !== "object")
|
|
1528
|
-
return;
|
|
1474
|
+
if (typeof dataFromHash !== "object") return;
|
|
1529
1475
|
if (!dataFromHash.name) {
|
|
1530
1476
|
logger.error("*watchHash* cant find component name in hash");
|
|
1531
1477
|
return;
|
|
1532
1478
|
}
|
|
1533
|
-
if (dataFromHash.name !== component.name)
|
|
1534
|
-
return;
|
|
1479
|
+
if (dataFromHash.name !== component.name) return;
|
|
1535
1480
|
logger.info("*watchHash* data from hash", dataFromHash);
|
|
1536
1481
|
await nextTick();
|
|
1537
1482
|
open({
|
|
@@ -1539,8 +1484,7 @@ function usePanel() {
|
|
|
1539
1484
|
layer: dataFromHash.layer || 0,
|
|
1540
1485
|
props: {
|
|
1541
1486
|
"onUpdate:modelValue": (value) => {
|
|
1542
|
-
if (value)
|
|
1543
|
-
return;
|
|
1487
|
+
if (value) return;
|
|
1544
1488
|
router.push({
|
|
1545
1489
|
name: route.name || void 0,
|
|
1546
1490
|
query: route.query,
|
|
@@ -1574,8 +1518,7 @@ function usePanel() {
|
|
|
1574
1518
|
}
|
|
1575
1519
|
|
|
1576
1520
|
function validatePhone(rule, value) {
|
|
1577
|
-
if (!value)
|
|
1578
|
-
return true;
|
|
1521
|
+
if (!value) return true;
|
|
1579
1522
|
const phoneNumber = parsePhoneNumberFromString(value);
|
|
1580
1523
|
return phoneNumber ? phoneNumber.isValid() : false;
|
|
1581
1524
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@karta.io/utils",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.46",
|
|
4
4
|
"description": "karta.io utils for admin and application",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -25,18 +25,18 @@
|
|
|
25
25
|
"vue": "3.x"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@karta.io/common-data": "^1.0.0-beta.
|
|
29
|
-
"@tanstack/vue-query": "5.
|
|
30
|
-
"@vueuse/core": "
|
|
28
|
+
"@karta.io/common-data": "^1.0.0-beta.46",
|
|
29
|
+
"@tanstack/vue-query": "5.83.1",
|
|
30
|
+
"@vueuse/core": "13.6.0",
|
|
31
31
|
"async-validator": "4.2.5",
|
|
32
|
-
"axios": "1.
|
|
32
|
+
"axios": "1.11.0",
|
|
33
33
|
"dayjs": "1.11.13",
|
|
34
34
|
"detect-browser": "5.3.0",
|
|
35
|
-
"libphonenumber-js": "1.
|
|
35
|
+
"libphonenumber-js": "1.12.10",
|
|
36
36
|
"lodash": "4.17.21",
|
|
37
37
|
"logdown": "3.3.1",
|
|
38
|
-
"qs": "6.
|
|
39
|
-
"vue-router": "4.5.
|
|
38
|
+
"qs": "6.14.0",
|
|
39
|
+
"vue-router": "4.5.1"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@karta.io/eslint-config": "1.2.1",
|
|
@@ -45,9 +45,9 @@
|
|
|
45
45
|
"eslint": "9.9.1",
|
|
46
46
|
"prettier": "3.3.3",
|
|
47
47
|
"typescript": "5.5.4",
|
|
48
|
-
"unbuild": "
|
|
49
|
-
"vitest": "2.
|
|
50
|
-
"vue": "3.5.
|
|
48
|
+
"unbuild": "3.6.0",
|
|
49
|
+
"vitest": "3.2.4",
|
|
50
|
+
"vue": "3.5.18"
|
|
51
51
|
},
|
|
52
52
|
"prettier": "@karta.io/prettier-config",
|
|
53
53
|
"scripts": {
|
|
@@ -60,6 +60,6 @@
|
|
|
60
60
|
"prettier:fix": "prettier --write --ignore-unknown \"**/*\"",
|
|
61
61
|
"fix": "pnpm lint:fix && pnpm prettier:fix",
|
|
62
62
|
"prepush": "pnpm run lint && pnpm run prettier",
|
|
63
|
-
"pub": "pnpm build && pnpm publish --no-git-checks"
|
|
63
|
+
"pub": "pnpm build && pnpm publish --no-git-checks --tag beta"
|
|
64
64
|
}
|
|
65
65
|
}
|