@karta.io/utils 1.0.0-alpha.9 → 1.0.0-beta.1
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 +69 -41
- package/dist/index.d.ts +3 -2
- package/dist/index.mjs +69 -41
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -77,18 +77,25 @@ function convertEnumToOptions(obj, options) {
|
|
|
77
77
|
}
|
|
78
78
|
|
|
79
79
|
function formatMoney(value, currency = commonData.CURRENCY_DEFAULT, options = {}) {
|
|
80
|
-
const
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
80
|
+
const { locale = "en-US", defaultValue = 0, ...otherOptions } = options;
|
|
81
|
+
try {
|
|
82
|
+
let convertedValue = Number(value);
|
|
83
|
+
if (value === null || Number.isNaN(convertedValue)) {
|
|
84
|
+
if (defaultValue === "")
|
|
85
|
+
return defaultValue;
|
|
86
|
+
convertedValue = Number(defaultValue);
|
|
87
|
+
}
|
|
88
|
+
const formatter = new Intl.NumberFormat(locale, {
|
|
89
|
+
style: "currency",
|
|
90
|
+
currency,
|
|
91
|
+
minimumFractionDigits: 2,
|
|
92
|
+
maximumFractionDigits: 2,
|
|
93
|
+
...otherOptions
|
|
94
|
+
});
|
|
95
|
+
return formatter.format(convertedValue);
|
|
96
|
+
} catch (error) {
|
|
97
|
+
return defaultValue;
|
|
98
|
+
}
|
|
92
99
|
}
|
|
93
100
|
|
|
94
101
|
function genHash(hashLength) {
|
|
@@ -415,7 +422,7 @@ function useAsyncMultiselect({
|
|
|
415
422
|
const { call, abort } = useAbortController(apiMethod);
|
|
416
423
|
const loadWAC = () => {
|
|
417
424
|
const includedIdsBySelectedValues = reactiveData.selectedValues ?? [];
|
|
418
|
-
const includedIdsByParams = JSON.parse(reactiveData.params || {})?.includedIds ?? [];
|
|
425
|
+
const includedIdsByParams = (Boolean(reactiveData.params) && JSON.parse(reactiveData.params || {})?.includedIds) ?? [];
|
|
419
426
|
const includedIds = union__default(includedIdsBySelectedValues, includedIdsByParams);
|
|
420
427
|
return call({
|
|
421
428
|
page: reactiveData.page,
|
|
@@ -838,6 +845,35 @@ function useDialog() {
|
|
|
838
845
|
} = useGlobalScroll();
|
|
839
846
|
const route = vueRouter.useRoute();
|
|
840
847
|
const router = vueRouter.useRouter();
|
|
848
|
+
const HASH_PREFIX = "#ud_";
|
|
849
|
+
const parseHash = (hash, componentName) => {
|
|
850
|
+
if (!hash)
|
|
851
|
+
return void 0;
|
|
852
|
+
if (!hash.includes(HASH_PREFIX))
|
|
853
|
+
return void 0;
|
|
854
|
+
let dataFromHash;
|
|
855
|
+
try {
|
|
856
|
+
dataFromHash = JSON.parse(window.atob(hash.slice(HASH_PREFIX.length)));
|
|
857
|
+
} catch (error) {
|
|
858
|
+
logger.warn("*parseHash* cant parse hash");
|
|
859
|
+
}
|
|
860
|
+
if (typeof dataFromHash !== "object")
|
|
861
|
+
return void 0;
|
|
862
|
+
if (!dataFromHash.name) {
|
|
863
|
+
logger.warn("*parseHash* cant find component name in hash");
|
|
864
|
+
return void 0;
|
|
865
|
+
}
|
|
866
|
+
if (dataFromHash.name !== componentName)
|
|
867
|
+
return void 0;
|
|
868
|
+
return dataFromHash;
|
|
869
|
+
};
|
|
870
|
+
const clearHash = () => {
|
|
871
|
+
router.push({
|
|
872
|
+
name: route.name || void 0,
|
|
873
|
+
query: route.query,
|
|
874
|
+
hash: void 0
|
|
875
|
+
});
|
|
876
|
+
};
|
|
841
877
|
vue.onMounted(() => {
|
|
842
878
|
appContext = vue.getCurrentInstance()?.appContext;
|
|
843
879
|
});
|
|
@@ -863,16 +899,26 @@ function useDialog() {
|
|
|
863
899
|
vnode2.props["onUpdate:modelValue"] = (value) => {
|
|
864
900
|
if (vnode2 && vnode2.component) {
|
|
865
901
|
vnode2.component.props.modelValue = value;
|
|
866
|
-
if (!value &&
|
|
902
|
+
if (!value && route?.hash) {
|
|
903
|
+
const dataFromHash = parseHash(route.hash, component.name);
|
|
904
|
+
if (dataFromHash)
|
|
905
|
+
clearHash();
|
|
906
|
+
}
|
|
907
|
+
if (!value && (dialogs.length === 1 || layer === 0) && isGlobalScrollLocked.value) {
|
|
867
908
|
unlockGlobalScroll();
|
|
868
909
|
}
|
|
869
910
|
}
|
|
870
911
|
};
|
|
871
912
|
}
|
|
872
913
|
vnode2.close = () => {
|
|
873
|
-
if (vnode2
|
|
874
|
-
|
|
875
|
-
|
|
914
|
+
if (!vnode2 || !vnode2.component)
|
|
915
|
+
return;
|
|
916
|
+
vnode2.component.props.modelValue = false;
|
|
917
|
+
if (!route?.hash)
|
|
918
|
+
return;
|
|
919
|
+
const dataFromHash = parseHash(route.hash, component.name);
|
|
920
|
+
if (dataFromHash)
|
|
921
|
+
clearHash();
|
|
876
922
|
};
|
|
877
923
|
vnode2.props.onDestroy = () => {
|
|
878
924
|
vue.render(null, el2);
|
|
@@ -929,7 +975,7 @@ function useDialog() {
|
|
|
929
975
|
const close = (uuid) => {
|
|
930
976
|
const dialog = dialogs.find((item) => item.uuid === uuid);
|
|
931
977
|
logger.log(`Close dialog: "${uuid}"`);
|
|
932
|
-
if (dialogs.length === 1 && isGlobalScrollLocked.value) {
|
|
978
|
+
if ((dialogs.length === 1 || dialog.layer === 0) && isGlobalScrollLocked.value) {
|
|
933
979
|
unlockGlobalScroll();
|
|
934
980
|
}
|
|
935
981
|
dialog?.vnode.close();
|
|
@@ -967,7 +1013,7 @@ function useDialog() {
|
|
|
967
1013
|
router.push({
|
|
968
1014
|
name: route.name || void 0,
|
|
969
1015
|
query: route.query,
|
|
970
|
-
hash:
|
|
1016
|
+
hash: `${HASH_PREFIX}${window.btoa(JSON.stringify(data))}`
|
|
971
1017
|
});
|
|
972
1018
|
};
|
|
973
1019
|
const watchHash = ({
|
|
@@ -979,22 +1025,13 @@ function useDialog() {
|
|
|
979
1025
|
() => route.hash,
|
|
980
1026
|
async (newHash) => {
|
|
981
1027
|
if (!newHash) {
|
|
1028
|
+
if (!dialogs.length)
|
|
1029
|
+
return;
|
|
982
1030
|
closeAll();
|
|
983
1031
|
return;
|
|
984
1032
|
}
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
dataFromHash = JSON.parse(window.atob(newHash.slice(1)));
|
|
988
|
-
} catch (error) {
|
|
989
|
-
logger.error("*watchHash* cant parse hash");
|
|
990
|
-
}
|
|
991
|
-
if (typeof dataFromHash !== "object")
|
|
992
|
-
return;
|
|
993
|
-
if (!dataFromHash.name) {
|
|
994
|
-
logger.error("*watchHash* cant find component name in hash");
|
|
995
|
-
return;
|
|
996
|
-
}
|
|
997
|
-
if (dataFromHash.name !== component.name)
|
|
1033
|
+
const dataFromHash = parseHash(newHash, component.name);
|
|
1034
|
+
if (!dataFromHash)
|
|
998
1035
|
return;
|
|
999
1036
|
logger.info("*watchHash* data from hash", dataFromHash);
|
|
1000
1037
|
await vue.nextTick();
|
|
@@ -1002,15 +1039,6 @@ function useDialog() {
|
|
|
1002
1039
|
component,
|
|
1003
1040
|
layer: dataFromHash.layer || 0,
|
|
1004
1041
|
props: {
|
|
1005
|
-
"onUpdate:modelValue": (value) => {
|
|
1006
|
-
if (value)
|
|
1007
|
-
return;
|
|
1008
|
-
router.push({
|
|
1009
|
-
name: route.name || void 0,
|
|
1010
|
-
query: route.query,
|
|
1011
|
-
hash: void 0
|
|
1012
|
-
});
|
|
1013
|
-
},
|
|
1014
1042
|
...dataFromHash.props,
|
|
1015
1043
|
...events
|
|
1016
1044
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -35,8 +35,9 @@ declare function convertEnumToOptions(obj: any, options?: Options$3): {
|
|
|
35
35
|
|
|
36
36
|
interface Options$2 extends Intl.NumberFormatOptions {
|
|
37
37
|
locale?: string;
|
|
38
|
+
defaultValue?: string | number;
|
|
38
39
|
}
|
|
39
|
-
declare function formatMoney(value: string | number | null | undefined, currency?: string, options?: Options$2): string;
|
|
40
|
+
declare function formatMoney(value: string | number | null | undefined, currency?: string, options?: Options$2): string | number;
|
|
40
41
|
|
|
41
42
|
declare function genHash(hashLength: number): string;
|
|
42
43
|
|
|
@@ -217,7 +218,7 @@ declare function useClassName(block: string): {
|
|
|
217
218
|
m: (modifier?: string, condition?: boolean) => string;
|
|
218
219
|
em: (element?: string, modifier?: string, condition?: boolean) => string;
|
|
219
220
|
mv: (modifier: string, modifierValue: string, condition?: boolean) => string;
|
|
220
|
-
cssVar: (object: Record<string, string>) => Record<string, string>;
|
|
221
|
+
cssVar: (object: Record<string, string | number>) => Record<string, string | number>;
|
|
221
222
|
cssVarName: (name: string) => string;
|
|
222
223
|
};
|
|
223
224
|
|
package/dist/index.mjs
CHANGED
|
@@ -59,18 +59,25 @@ function convertEnumToOptions(obj, options) {
|
|
|
59
59
|
}
|
|
60
60
|
|
|
61
61
|
function formatMoney(value, currency = CURRENCY_DEFAULT, options = {}) {
|
|
62
|
-
const
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
62
|
+
const { locale = "en-US", defaultValue = 0, ...otherOptions } = options;
|
|
63
|
+
try {
|
|
64
|
+
let convertedValue = Number(value);
|
|
65
|
+
if (value === null || Number.isNaN(convertedValue)) {
|
|
66
|
+
if (defaultValue === "")
|
|
67
|
+
return defaultValue;
|
|
68
|
+
convertedValue = Number(defaultValue);
|
|
69
|
+
}
|
|
70
|
+
const formatter = new Intl.NumberFormat(locale, {
|
|
71
|
+
style: "currency",
|
|
72
|
+
currency,
|
|
73
|
+
minimumFractionDigits: 2,
|
|
74
|
+
maximumFractionDigits: 2,
|
|
75
|
+
...otherOptions
|
|
76
|
+
});
|
|
77
|
+
return formatter.format(convertedValue);
|
|
78
|
+
} catch (error) {
|
|
79
|
+
return defaultValue;
|
|
80
|
+
}
|
|
74
81
|
}
|
|
75
82
|
|
|
76
83
|
function genHash(hashLength) {
|
|
@@ -397,7 +404,7 @@ function useAsyncMultiselect({
|
|
|
397
404
|
const { call, abort } = useAbortController(apiMethod);
|
|
398
405
|
const loadWAC = () => {
|
|
399
406
|
const includedIdsBySelectedValues = reactiveData.selectedValues ?? [];
|
|
400
|
-
const includedIdsByParams = JSON.parse(reactiveData.params || {})?.includedIds ?? [];
|
|
407
|
+
const includedIdsByParams = (Boolean(reactiveData.params) && JSON.parse(reactiveData.params || {})?.includedIds) ?? [];
|
|
401
408
|
const includedIds = union(includedIdsBySelectedValues, includedIdsByParams);
|
|
402
409
|
return call({
|
|
403
410
|
page: reactiveData.page,
|
|
@@ -820,6 +827,35 @@ function useDialog() {
|
|
|
820
827
|
} = useGlobalScroll();
|
|
821
828
|
const route = useRoute();
|
|
822
829
|
const router = useRouter();
|
|
830
|
+
const HASH_PREFIX = "#ud_";
|
|
831
|
+
const parseHash = (hash, componentName) => {
|
|
832
|
+
if (!hash)
|
|
833
|
+
return void 0;
|
|
834
|
+
if (!hash.includes(HASH_PREFIX))
|
|
835
|
+
return void 0;
|
|
836
|
+
let dataFromHash;
|
|
837
|
+
try {
|
|
838
|
+
dataFromHash = JSON.parse(window.atob(hash.slice(HASH_PREFIX.length)));
|
|
839
|
+
} catch (error) {
|
|
840
|
+
logger.warn("*parseHash* cant parse hash");
|
|
841
|
+
}
|
|
842
|
+
if (typeof dataFromHash !== "object")
|
|
843
|
+
return void 0;
|
|
844
|
+
if (!dataFromHash.name) {
|
|
845
|
+
logger.warn("*parseHash* cant find component name in hash");
|
|
846
|
+
return void 0;
|
|
847
|
+
}
|
|
848
|
+
if (dataFromHash.name !== componentName)
|
|
849
|
+
return void 0;
|
|
850
|
+
return dataFromHash;
|
|
851
|
+
};
|
|
852
|
+
const clearHash = () => {
|
|
853
|
+
router.push({
|
|
854
|
+
name: route.name || void 0,
|
|
855
|
+
query: route.query,
|
|
856
|
+
hash: void 0
|
|
857
|
+
});
|
|
858
|
+
};
|
|
823
859
|
onMounted(() => {
|
|
824
860
|
appContext = getCurrentInstance()?.appContext;
|
|
825
861
|
});
|
|
@@ -845,16 +881,26 @@ function useDialog() {
|
|
|
845
881
|
vnode2.props["onUpdate:modelValue"] = (value) => {
|
|
846
882
|
if (vnode2 && vnode2.component) {
|
|
847
883
|
vnode2.component.props.modelValue = value;
|
|
848
|
-
if (!value &&
|
|
884
|
+
if (!value && route?.hash) {
|
|
885
|
+
const dataFromHash = parseHash(route.hash, component.name);
|
|
886
|
+
if (dataFromHash)
|
|
887
|
+
clearHash();
|
|
888
|
+
}
|
|
889
|
+
if (!value && (dialogs.length === 1 || layer === 0) && isGlobalScrollLocked.value) {
|
|
849
890
|
unlockGlobalScroll();
|
|
850
891
|
}
|
|
851
892
|
}
|
|
852
893
|
};
|
|
853
894
|
}
|
|
854
895
|
vnode2.close = () => {
|
|
855
|
-
if (vnode2
|
|
856
|
-
|
|
857
|
-
|
|
896
|
+
if (!vnode2 || !vnode2.component)
|
|
897
|
+
return;
|
|
898
|
+
vnode2.component.props.modelValue = false;
|
|
899
|
+
if (!route?.hash)
|
|
900
|
+
return;
|
|
901
|
+
const dataFromHash = parseHash(route.hash, component.name);
|
|
902
|
+
if (dataFromHash)
|
|
903
|
+
clearHash();
|
|
858
904
|
};
|
|
859
905
|
vnode2.props.onDestroy = () => {
|
|
860
906
|
render(null, el2);
|
|
@@ -911,7 +957,7 @@ function useDialog() {
|
|
|
911
957
|
const close = (uuid) => {
|
|
912
958
|
const dialog = dialogs.find((item) => item.uuid === uuid);
|
|
913
959
|
logger.log(`Close dialog: "${uuid}"`);
|
|
914
|
-
if (dialogs.length === 1 && isGlobalScrollLocked.value) {
|
|
960
|
+
if ((dialogs.length === 1 || dialog.layer === 0) && isGlobalScrollLocked.value) {
|
|
915
961
|
unlockGlobalScroll();
|
|
916
962
|
}
|
|
917
963
|
dialog?.vnode.close();
|
|
@@ -949,7 +995,7 @@ function useDialog() {
|
|
|
949
995
|
router.push({
|
|
950
996
|
name: route.name || void 0,
|
|
951
997
|
query: route.query,
|
|
952
|
-
hash:
|
|
998
|
+
hash: `${HASH_PREFIX}${window.btoa(JSON.stringify(data))}`
|
|
953
999
|
});
|
|
954
1000
|
};
|
|
955
1001
|
const watchHash = ({
|
|
@@ -961,22 +1007,13 @@ function useDialog() {
|
|
|
961
1007
|
() => route.hash,
|
|
962
1008
|
async (newHash) => {
|
|
963
1009
|
if (!newHash) {
|
|
1010
|
+
if (!dialogs.length)
|
|
1011
|
+
return;
|
|
964
1012
|
closeAll();
|
|
965
1013
|
return;
|
|
966
1014
|
}
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
dataFromHash = JSON.parse(window.atob(newHash.slice(1)));
|
|
970
|
-
} catch (error) {
|
|
971
|
-
logger.error("*watchHash* cant parse hash");
|
|
972
|
-
}
|
|
973
|
-
if (typeof dataFromHash !== "object")
|
|
974
|
-
return;
|
|
975
|
-
if (!dataFromHash.name) {
|
|
976
|
-
logger.error("*watchHash* cant find component name in hash");
|
|
977
|
-
return;
|
|
978
|
-
}
|
|
979
|
-
if (dataFromHash.name !== component.name)
|
|
1015
|
+
const dataFromHash = parseHash(newHash, component.name);
|
|
1016
|
+
if (!dataFromHash)
|
|
980
1017
|
return;
|
|
981
1018
|
logger.info("*watchHash* data from hash", dataFromHash);
|
|
982
1019
|
await nextTick();
|
|
@@ -984,15 +1021,6 @@ function useDialog() {
|
|
|
984
1021
|
component,
|
|
985
1022
|
layer: dataFromHash.layer || 0,
|
|
986
1023
|
props: {
|
|
987
|
-
"onUpdate:modelValue": (value) => {
|
|
988
|
-
if (value)
|
|
989
|
-
return;
|
|
990
|
-
router.push({
|
|
991
|
-
name: route.name || void 0,
|
|
992
|
-
query: route.query,
|
|
993
|
-
hash: void 0
|
|
994
|
-
});
|
|
995
|
-
},
|
|
996
1024
|
...dataFromHash.props,
|
|
997
1025
|
...events
|
|
998
1026
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@karta.io/utils",
|
|
3
|
-
"version": "1.0.0-
|
|
3
|
+
"version": "1.0.0-beta.1",
|
|
4
4
|
"description": "karta.io utils for admin and application",
|
|
5
5
|
"author": "Vitaly Blokhin <karambafe@gmail.com>",
|
|
6
6
|
"homepage": "",
|
|
@@ -24,9 +24,9 @@
|
|
|
24
24
|
"vue": "3.3.x"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@karta.io/common-data": "^1.0.0-
|
|
27
|
+
"@karta.io/common-data": "^1.0.0-beta.1",
|
|
28
28
|
"@tanstack/vue-query": "4.33.1",
|
|
29
|
-
"@vueuse/core": "10.
|
|
29
|
+
"@vueuse/core": "10.7.0",
|
|
30
30
|
"async-validator": "4.2.5",
|
|
31
31
|
"axios": "1.4.0",
|
|
32
32
|
"dayjs": "1.11.8",
|