@karta.io/utils 0.35.4 → 1.0.0-alpha.0
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/README.md +1 -3
- package/dist/index.cjs +361 -17
- package/dist/index.d.ts +62 -10
- package/dist/index.mjs +360 -19
- package/package.json +10 -12
package/README.md
CHANGED
|
@@ -5,9 +5,7 @@
|
|
|
5
5
|
## Хелперы:
|
|
6
6
|
|
|
7
7
|
- camelizeKeys
|
|
8
|
-
- createClassName
|
|
9
8
|
- formatMoney
|
|
10
|
-
- genLoadingTableRows
|
|
11
9
|
- genRandomNumber
|
|
12
10
|
- genUUID
|
|
13
11
|
- getCardNumber
|
|
@@ -19,7 +17,7 @@
|
|
|
19
17
|
- snakelizeKeys
|
|
20
18
|
- unformatNumber
|
|
21
19
|
- validateNumber
|
|
22
|
-
-
|
|
20
|
+
- AppComponentsResolver
|
|
23
21
|
- UiComponentsResolver
|
|
24
22
|
|
|
25
23
|
## Хуки:
|
package/dist/index.cjs
CHANGED
|
@@ -17,6 +17,8 @@ const updateLocale = require('dayjs/plugin/updateLocale.js');
|
|
|
17
17
|
const isToday = require('dayjs/plugin/isToday.js');
|
|
18
18
|
const customParseFormat = require('dayjs/plugin/customParseFormat.js');
|
|
19
19
|
const detectBrowser = require('detect-browser');
|
|
20
|
+
const vueRouter = require('vue-router');
|
|
21
|
+
const qs = require('qs');
|
|
20
22
|
|
|
21
23
|
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
|
|
22
24
|
|
|
@@ -31,6 +33,17 @@ const tz__default = /*#__PURE__*/_interopDefaultCompat(tz);
|
|
|
31
33
|
const updateLocale__default = /*#__PURE__*/_interopDefaultCompat(updateLocale);
|
|
32
34
|
const isToday__default = /*#__PURE__*/_interopDefaultCompat(isToday);
|
|
33
35
|
const customParseFormat__default = /*#__PURE__*/_interopDefaultCompat(customParseFormat);
|
|
36
|
+
const qs__default = /*#__PURE__*/_interopDefaultCompat(qs);
|
|
37
|
+
|
|
38
|
+
function AppComponentsResolver(options = {}) {
|
|
39
|
+
const { prefix = "" } = options;
|
|
40
|
+
return (name) => {
|
|
41
|
+
const componentName = prefix && name.startsWith(prefix) ? name.substring(prefix.length) : name;
|
|
42
|
+
const isAppComponent = componentName.startsWith("App");
|
|
43
|
+
if (isAppComponent)
|
|
44
|
+
return { name: componentName, from: "@karta.io/app-components" };
|
|
45
|
+
};
|
|
46
|
+
}
|
|
34
47
|
|
|
35
48
|
function camelizeKeys(object) {
|
|
36
49
|
if (Array.isArray(object))
|
|
@@ -47,14 +60,6 @@ function camelizeKeys(object) {
|
|
|
47
60
|
return object;
|
|
48
61
|
}
|
|
49
62
|
|
|
50
|
-
function createClassName(className) {
|
|
51
|
-
return function f(...classNames) {
|
|
52
|
-
const result = classNames.join("");
|
|
53
|
-
const create = (...args) => args.length ? f.apply(null, [result, ...args])() : result;
|
|
54
|
-
return create;
|
|
55
|
-
}(className);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
63
|
function formatMoney(value, currency = commonData.CURRENCY_DEFAULT, options = {}) {
|
|
59
64
|
const convertedValue = Number(value);
|
|
60
65
|
if (value === null || Number.isNaN(convertedValue))
|
|
@@ -70,11 +75,6 @@ function formatMoney(value, currency = commonData.CURRENCY_DEFAULT, options = {}
|
|
|
70
75
|
return formatter.format(convertedValue);
|
|
71
76
|
}
|
|
72
77
|
|
|
73
|
-
function genLoadingTableRows(columns, limit) {
|
|
74
|
-
const row = columns.reduce((acc, curr) => ({ ...acc, [curr.key]: void 0 }), {});
|
|
75
|
-
return Array.from(Array(limit).keys()).map((item) => ({ id: item, ...row }));
|
|
76
|
-
}
|
|
77
|
-
|
|
78
78
|
function genRandomNumber(min, max) {
|
|
79
79
|
return Math.floor(Math.random() * (max - min + 1)) + min;
|
|
80
80
|
}
|
|
@@ -325,6 +325,7 @@ function useAsyncMultiselect({
|
|
|
325
325
|
selectedValues: core.toValue(selectedValues),
|
|
326
326
|
params: JSON.stringify(core.toValue(params))
|
|
327
327
|
});
|
|
328
|
+
const search = vue.ref("");
|
|
328
329
|
const { call, abort } = useAbortController(apiMethod);
|
|
329
330
|
const loadWAC = () => call({
|
|
330
331
|
page: reactiveData.page,
|
|
@@ -423,6 +424,7 @@ function useAsyncMultiselect({
|
|
|
423
424
|
reactiveData.selectedValues = core.toValue(selectedValues);
|
|
424
425
|
}, delay);
|
|
425
426
|
const updateSearch = (value) => {
|
|
427
|
+
search.value = value;
|
|
426
428
|
updateSearchWithDebounce(value);
|
|
427
429
|
};
|
|
428
430
|
if (vue.isRef(selectedValues)) {
|
|
@@ -460,7 +462,7 @@ function useAsyncMultiselect({
|
|
|
460
462
|
return {
|
|
461
463
|
items,
|
|
462
464
|
options,
|
|
463
|
-
search
|
|
465
|
+
search,
|
|
464
466
|
hasNextPage,
|
|
465
467
|
isFetching,
|
|
466
468
|
isLoading,
|
|
@@ -492,6 +494,7 @@ function useAsyncSelect({
|
|
|
492
494
|
selectedValue: core.toValue(selectedValue),
|
|
493
495
|
params: JSON.stringify(core.toValue(params))
|
|
494
496
|
});
|
|
497
|
+
const search = vue.ref("");
|
|
495
498
|
const { call, abort } = useAbortController(apiMethod);
|
|
496
499
|
const loadWAC = () => call({
|
|
497
500
|
page: reactiveData.page,
|
|
@@ -567,6 +570,7 @@ function useAsyncSelect({
|
|
|
567
570
|
reactiveData.page = 1;
|
|
568
571
|
}, delay);
|
|
569
572
|
const updateSearch = (value) => {
|
|
573
|
+
search.value = value;
|
|
570
574
|
updateSearchWithDebounce(value);
|
|
571
575
|
};
|
|
572
576
|
if (vue.isRef(selectedValue)) {
|
|
@@ -587,7 +591,7 @@ function useAsyncSelect({
|
|
|
587
591
|
return {
|
|
588
592
|
items,
|
|
589
593
|
options,
|
|
590
|
-
search
|
|
594
|
+
search,
|
|
591
595
|
hasNextPage,
|
|
592
596
|
isFetching,
|
|
593
597
|
isLoading,
|
|
@@ -596,6 +600,28 @@ function useAsyncSelect({
|
|
|
596
600
|
};
|
|
597
601
|
}
|
|
598
602
|
|
|
603
|
+
function useBreakpoint() {
|
|
604
|
+
const breakpoints = core.useBreakpoints(commonData.BREAKPOINTS);
|
|
605
|
+
const isMobile = breakpoints.smaller("sm");
|
|
606
|
+
const isDesktop = breakpoints.greater("md");
|
|
607
|
+
const isGreaterXxs = breakpoints.greater("xxs");
|
|
608
|
+
const isGreaterXs = breakpoints.greater("xs");
|
|
609
|
+
const isGreaterSm = breakpoints.greater("sm");
|
|
610
|
+
const isGreaterMd = breakpoints.greater("md");
|
|
611
|
+
const isGreaterLg = breakpoints.greater("lg");
|
|
612
|
+
const isGreaterXl = breakpoints.greater("xl");
|
|
613
|
+
return {
|
|
614
|
+
isMobile,
|
|
615
|
+
isDesktop,
|
|
616
|
+
isGreaterXxs,
|
|
617
|
+
isGreaterXs,
|
|
618
|
+
isGreaterSm,
|
|
619
|
+
isGreaterMd,
|
|
620
|
+
isGreaterLg,
|
|
621
|
+
isGreaterXl
|
|
622
|
+
};
|
|
623
|
+
}
|
|
624
|
+
|
|
599
625
|
function _bem(block, blockSuffix, element, modifier, modifierValue) {
|
|
600
626
|
let cls = block;
|
|
601
627
|
if (blockSuffix)
|
|
@@ -709,6 +735,322 @@ function useGlobalScroll() {
|
|
|
709
735
|
};
|
|
710
736
|
}
|
|
711
737
|
|
|
738
|
+
const QS_STRINGIFY_PARAMS = {
|
|
739
|
+
arrayFormat: "comma",
|
|
740
|
+
encode: false,
|
|
741
|
+
skipNulls: true,
|
|
742
|
+
addQueryPrefix: true
|
|
743
|
+
};
|
|
744
|
+
const isOpen = vue.ref(false);
|
|
745
|
+
function useFilters({
|
|
746
|
+
config,
|
|
747
|
+
initialFilters
|
|
748
|
+
}) {
|
|
749
|
+
const router = vueRouter.useRouter();
|
|
750
|
+
const route = vueRouter.useRoute();
|
|
751
|
+
const parseRouteQuery = (query) => qs__default.parse(query ?? route.query);
|
|
752
|
+
const filtersFromQuery = vue.computed(() => {
|
|
753
|
+
const parsedRouteQuery = parseRouteQuery();
|
|
754
|
+
if (!parsedRouteQuery.filters)
|
|
755
|
+
return void 0;
|
|
756
|
+
return Object.entries(config).reduce((accum, [currentKey, currentValue]) => {
|
|
757
|
+
if (!parsedRouteQuery.filters[currentKey])
|
|
758
|
+
return accum;
|
|
759
|
+
if (currentValue.type === "ARRAY" /* Array */) {
|
|
760
|
+
const splitValues = parsedRouteQuery.filters[currentKey].split(",");
|
|
761
|
+
const checkedValue = currentValue?.possibleValues ? splitValues.filter((k) => currentValue?.possibleValues?.includes(k)) : splitValues;
|
|
762
|
+
if (!checkedValue?.length)
|
|
763
|
+
return accum;
|
|
764
|
+
return {
|
|
765
|
+
...accum,
|
|
766
|
+
[currentKey]: checkedValue
|
|
767
|
+
};
|
|
768
|
+
}
|
|
769
|
+
return {
|
|
770
|
+
...accum,
|
|
771
|
+
[currentKey]: parsedRouteQuery.filters[currentKey]
|
|
772
|
+
};
|
|
773
|
+
}, {});
|
|
774
|
+
});
|
|
775
|
+
const filtersCount = vue.computed(
|
|
776
|
+
() => filtersFromQuery.value ? Object.keys(filtersFromQuery.value).length : 0
|
|
777
|
+
);
|
|
778
|
+
const setQueryFromFilters = (filters) => {
|
|
779
|
+
const parsedRouteQuery = parseRouteQuery();
|
|
780
|
+
const filteredValue = Object.entries(filters).reduce((accum, [currentKey, currentValue]) => {
|
|
781
|
+
if (!currentValue?.length)
|
|
782
|
+
return accum;
|
|
783
|
+
return { ...accum, [currentKey]: currentValue };
|
|
784
|
+
}, {});
|
|
785
|
+
const query = qs__default.stringify(
|
|
786
|
+
{
|
|
787
|
+
...parsedRouteQuery,
|
|
788
|
+
filters: filteredValue,
|
|
789
|
+
page: void 0
|
|
790
|
+
},
|
|
791
|
+
QS_STRINGIFY_PARAMS
|
|
792
|
+
);
|
|
793
|
+
router.push(query);
|
|
794
|
+
};
|
|
795
|
+
const getValidatedParams = (query) => {
|
|
796
|
+
const parsedRouteQuery = parseRouteQuery(query);
|
|
797
|
+
if (query?.filters) {
|
|
798
|
+
const filters = {
|
|
799
|
+
...query.filters,
|
|
800
|
+
...filtersFromQuery.value
|
|
801
|
+
};
|
|
802
|
+
return { ...parsedRouteQuery, filters };
|
|
803
|
+
}
|
|
804
|
+
return { ...parsedRouteQuery, filters: filtersFromQuery.value };
|
|
805
|
+
};
|
|
806
|
+
const open = () => {
|
|
807
|
+
isOpen.value = true;
|
|
808
|
+
};
|
|
809
|
+
const clear = () => setQueryFromFilters({});
|
|
810
|
+
const filtersModel = vue.ref({
|
|
811
|
+
...initialFilters,
|
|
812
|
+
...filtersFromQuery.value
|
|
813
|
+
});
|
|
814
|
+
const updateOne = (key, value) => {
|
|
815
|
+
setQueryFromFilters({
|
|
816
|
+
...filtersModel.value,
|
|
817
|
+
[key]: value ? String(value) : void 0
|
|
818
|
+
});
|
|
819
|
+
};
|
|
820
|
+
const updateMany = (filters) => {
|
|
821
|
+
const newFilters = Object.entries(filters).reduce((accum, [currentKey, currentValue]) => {
|
|
822
|
+
return {
|
|
823
|
+
...accum,
|
|
824
|
+
[currentKey]: currentValue ? String(currentValue) : void 0
|
|
825
|
+
};
|
|
826
|
+
}, {});
|
|
827
|
+
setQueryFromFilters({
|
|
828
|
+
...filtersModel.value,
|
|
829
|
+
...newFilters
|
|
830
|
+
});
|
|
831
|
+
};
|
|
832
|
+
vue.watch(filtersFromQuery, (newFilters) => {
|
|
833
|
+
if (!newFilters) {
|
|
834
|
+
filtersModel.value = { ...initialFilters };
|
|
835
|
+
return;
|
|
836
|
+
}
|
|
837
|
+
filtersModel.value = { ...initialFilters, ...newFilters };
|
|
838
|
+
});
|
|
839
|
+
return {
|
|
840
|
+
isOpen,
|
|
841
|
+
filtersModel,
|
|
842
|
+
filtersFromQuery,
|
|
843
|
+
filtersCount,
|
|
844
|
+
updateOne,
|
|
845
|
+
updateMany,
|
|
846
|
+
open,
|
|
847
|
+
clear,
|
|
848
|
+
setQueryFromFilters,
|
|
849
|
+
getValidatedParams
|
|
850
|
+
};
|
|
851
|
+
}
|
|
852
|
+
|
|
853
|
+
let panels = [];
|
|
854
|
+
function usePanel() {
|
|
855
|
+
let appContext;
|
|
856
|
+
const logger = useLogger("use-panel");
|
|
857
|
+
const {
|
|
858
|
+
isLocked: isGlobalScrollLocked,
|
|
859
|
+
lock: lockGlobalScroll,
|
|
860
|
+
unlock: unlockGlobalScroll
|
|
861
|
+
} = useGlobalScroll();
|
|
862
|
+
const route = vueRouter.useRoute();
|
|
863
|
+
const router = vueRouter.useRouter();
|
|
864
|
+
vue.onMounted(() => {
|
|
865
|
+
appContext = vue.getCurrentInstance()?.appContext;
|
|
866
|
+
});
|
|
867
|
+
const open = ({
|
|
868
|
+
layer = 0,
|
|
869
|
+
component,
|
|
870
|
+
props
|
|
871
|
+
}) => {
|
|
872
|
+
const uuid = genUUID();
|
|
873
|
+
const createComponent = () => {
|
|
874
|
+
const newProps = {
|
|
875
|
+
...props,
|
|
876
|
+
layer
|
|
877
|
+
};
|
|
878
|
+
const el2 = document.createElement("div");
|
|
879
|
+
const vnode2 = vue.createVNode(component, {
|
|
880
|
+
...newProps,
|
|
881
|
+
modelValue: true,
|
|
882
|
+
uuid
|
|
883
|
+
});
|
|
884
|
+
vnode2.appContext = { ...appContext };
|
|
885
|
+
if (!vnode2?.props?.["onUpdate:modelValue"]) {
|
|
886
|
+
vnode2.props["onUpdate:modelValue"] = (value) => {
|
|
887
|
+
if (vnode2 && vnode2.component) {
|
|
888
|
+
vnode2.component.props.modelValue = value;
|
|
889
|
+
if (!value && panels.length === 1 && isGlobalScrollLocked.value) {
|
|
890
|
+
unlockGlobalScroll();
|
|
891
|
+
}
|
|
892
|
+
}
|
|
893
|
+
};
|
|
894
|
+
}
|
|
895
|
+
vnode2.close = () => {
|
|
896
|
+
if (vnode2 && vnode2.component) {
|
|
897
|
+
vnode2.component.props.modelValue = false;
|
|
898
|
+
}
|
|
899
|
+
};
|
|
900
|
+
vnode2.props.onDestroy = () => {
|
|
901
|
+
vue.render(null, el2);
|
|
902
|
+
panels = panels.filter((panel) => panel.uuid !== uuid);
|
|
903
|
+
logger.info("Panels after destroy", panels);
|
|
904
|
+
};
|
|
905
|
+
const name = vnode2?.type?.name ?? "Unknown component";
|
|
906
|
+
const newPanel2 = {
|
|
907
|
+
uuid,
|
|
908
|
+
name,
|
|
909
|
+
vnode: vnode2,
|
|
910
|
+
layer
|
|
911
|
+
};
|
|
912
|
+
logger.log(`Open new panel: "${name}"`);
|
|
913
|
+
if (!isGlobalScrollLocked.value) {
|
|
914
|
+
lockGlobalScroll();
|
|
915
|
+
}
|
|
916
|
+
return {
|
|
917
|
+
vnode: vnode2,
|
|
918
|
+
el: el2,
|
|
919
|
+
newPanel: newPanel2
|
|
920
|
+
};
|
|
921
|
+
};
|
|
922
|
+
if (!panels.length) {
|
|
923
|
+
const { vnode: vnode2, el: el2, newPanel: newPanel2 } = createComponent();
|
|
924
|
+
vue.render(vnode2, el2);
|
|
925
|
+
panels = [newPanel2];
|
|
926
|
+
logger.info("Panels after open", panels);
|
|
927
|
+
return uuid;
|
|
928
|
+
}
|
|
929
|
+
if (layer === 0) {
|
|
930
|
+
closeAll();
|
|
931
|
+
const { vnode: vnode2, el: el2, newPanel: newPanel2 } = createComponent();
|
|
932
|
+
vue.render(vnode2, el2);
|
|
933
|
+
panels = [newPanel2];
|
|
934
|
+
logger.info("Panels after open", panels);
|
|
935
|
+
return uuid;
|
|
936
|
+
}
|
|
937
|
+
if (!panels.some((panel) => panel.layer === layer)) {
|
|
938
|
+
const { vnode: vnode2, el: el2, newPanel: newPanel2 } = createComponent();
|
|
939
|
+
vue.render(vnode2, el2);
|
|
940
|
+
panels = [...panels, newPanel2];
|
|
941
|
+
logger.info("Panels after open", panels);
|
|
942
|
+
return uuid;
|
|
943
|
+
}
|
|
944
|
+
const panelOnCurrentLayer = panels.find((panel) => panel.layer === layer);
|
|
945
|
+
close(panelOnCurrentLayer?.uuid || "");
|
|
946
|
+
const { vnode, el, newPanel } = createComponent();
|
|
947
|
+
vue.render(vnode, el);
|
|
948
|
+
panels = [...panels, newPanel];
|
|
949
|
+
logger.info("Panels after open", panels);
|
|
950
|
+
return uuid;
|
|
951
|
+
};
|
|
952
|
+
const close = (uuid) => {
|
|
953
|
+
const panel = panels.find((item) => item.uuid === uuid);
|
|
954
|
+
logger.log(`Close panel: "${uuid}"`);
|
|
955
|
+
if (panels.length === 1 && isGlobalScrollLocked.value) {
|
|
956
|
+
unlockGlobalScroll();
|
|
957
|
+
}
|
|
958
|
+
panel?.vnode.close();
|
|
959
|
+
};
|
|
960
|
+
const closeAll = () => {
|
|
961
|
+
panels.forEach((panel) => {
|
|
962
|
+
panel?.vnode.close();
|
|
963
|
+
});
|
|
964
|
+
if (isGlobalScrollLocked.value) {
|
|
965
|
+
unlockGlobalScroll();
|
|
966
|
+
}
|
|
967
|
+
};
|
|
968
|
+
const getInstance = (uuid) => {
|
|
969
|
+
return panels.find((item) => item.uuid === uuid)?.vnode;
|
|
970
|
+
};
|
|
971
|
+
const openByHash = ({
|
|
972
|
+
layer = 0,
|
|
973
|
+
component,
|
|
974
|
+
props
|
|
975
|
+
}) => {
|
|
976
|
+
const data = {
|
|
977
|
+
name: component.name,
|
|
978
|
+
layer,
|
|
979
|
+
props
|
|
980
|
+
};
|
|
981
|
+
router.push({
|
|
982
|
+
name: route.name || void 0,
|
|
983
|
+
query: route.query,
|
|
984
|
+
hash: `#${window.btoa(JSON.stringify(data))}`
|
|
985
|
+
});
|
|
986
|
+
};
|
|
987
|
+
const watchHash = ({
|
|
988
|
+
component,
|
|
989
|
+
events
|
|
990
|
+
}) => {
|
|
991
|
+
logger.info(`start watching route.hash for panel *${component.name}*`);
|
|
992
|
+
const stopWatch = vue.watch(
|
|
993
|
+
() => route.hash,
|
|
994
|
+
async (newHash) => {
|
|
995
|
+
if (!newHash) {
|
|
996
|
+
closeAll();
|
|
997
|
+
return;
|
|
998
|
+
}
|
|
999
|
+
let dataFromHash;
|
|
1000
|
+
try {
|
|
1001
|
+
dataFromHash = JSON.parse(window.atob(newHash.slice(1)));
|
|
1002
|
+
} catch (error) {
|
|
1003
|
+
logger.error("*watchHash* cant parse hash");
|
|
1004
|
+
}
|
|
1005
|
+
if (typeof dataFromHash !== "object")
|
|
1006
|
+
return;
|
|
1007
|
+
if (!dataFromHash.name) {
|
|
1008
|
+
logger.error("*watchHash* cant find component name in hash");
|
|
1009
|
+
return;
|
|
1010
|
+
}
|
|
1011
|
+
if (dataFromHash.name !== component.name)
|
|
1012
|
+
return;
|
|
1013
|
+
logger.info("*watchHash* data from hash", dataFromHash);
|
|
1014
|
+
await vue.nextTick();
|
|
1015
|
+
open({
|
|
1016
|
+
component,
|
|
1017
|
+
layer: dataFromHash.layer || 0,
|
|
1018
|
+
props: {
|
|
1019
|
+
"onUpdate:modelValue": (value) => {
|
|
1020
|
+
if (value)
|
|
1021
|
+
return;
|
|
1022
|
+
router.push({
|
|
1023
|
+
name: route.name || void 0,
|
|
1024
|
+
query: route.query,
|
|
1025
|
+
hash: void 0
|
|
1026
|
+
});
|
|
1027
|
+
},
|
|
1028
|
+
...dataFromHash.props,
|
|
1029
|
+
...events
|
|
1030
|
+
}
|
|
1031
|
+
});
|
|
1032
|
+
},
|
|
1033
|
+
{ immediate: true }
|
|
1034
|
+
);
|
|
1035
|
+
const stopWatchHash = () => {
|
|
1036
|
+
logger.info(`stop watching route.hash for panel *${component.name}*`);
|
|
1037
|
+
stopWatch();
|
|
1038
|
+
};
|
|
1039
|
+
vue.onBeforeUnmount(() => {
|
|
1040
|
+
stopWatchHash();
|
|
1041
|
+
});
|
|
1042
|
+
return stopWatchHash;
|
|
1043
|
+
};
|
|
1044
|
+
return {
|
|
1045
|
+
open,
|
|
1046
|
+
getInstance,
|
|
1047
|
+
close,
|
|
1048
|
+
closeAll,
|
|
1049
|
+
openByHash,
|
|
1050
|
+
watchHash
|
|
1051
|
+
};
|
|
1052
|
+
}
|
|
1053
|
+
|
|
712
1054
|
function validatePhone(rule, value) {
|
|
713
1055
|
if (!value)
|
|
714
1056
|
return true;
|
|
@@ -760,11 +1102,10 @@ function isStrictLength(value = 3, message) {
|
|
|
760
1102
|
};
|
|
761
1103
|
}
|
|
762
1104
|
|
|
1105
|
+
exports.AppComponentsResolver = AppComponentsResolver;
|
|
763
1106
|
exports.UiComponentsResolver = UiComponentsResolver;
|
|
764
1107
|
exports.camelizeKeys = camelizeKeys;
|
|
765
|
-
exports.createClassName = createClassName;
|
|
766
1108
|
exports.formatMoney = formatMoney;
|
|
767
|
-
exports.genLoadingTableRows = genLoadingTableRows;
|
|
768
1109
|
exports.genRandomNumber = genRandomNumber;
|
|
769
1110
|
exports.genUUID = genUUID;
|
|
770
1111
|
exports.getCardNumber = getCardNumber;
|
|
@@ -788,10 +1129,13 @@ exports.unformatNumber = unformatNumber;
|
|
|
788
1129
|
exports.useAbortController = useAbortController;
|
|
789
1130
|
exports.useAsyncMultiselect = useAsyncMultiselect;
|
|
790
1131
|
exports.useAsyncSelect = useAsyncSelect;
|
|
1132
|
+
exports.useBreakpoint = useBreakpoint;
|
|
791
1133
|
exports.useClassName = useClassName;
|
|
792
1134
|
exports.useDayjs = useDayjs;
|
|
793
1135
|
exports.useDetectBrowser = useDetectBrowser;
|
|
1136
|
+
exports.useFilters = useFilters;
|
|
794
1137
|
exports.useGlobalScroll = useGlobalScroll;
|
|
795
1138
|
exports.useLogger = useLogger;
|
|
1139
|
+
exports.usePanel = usePanel;
|
|
796
1140
|
exports.validateNumber = validateNumber;
|
|
797
1141
|
exports.validatePhone = validatePhone;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
import * as vue from 'vue';
|
|
2
|
+
import { Ref, Component, EmitsOptions, VNode } from 'vue';
|
|
2
3
|
import { MaybeRef } from '@vueuse/core';
|
|
3
4
|
import dayjs from 'dayjs';
|
|
4
5
|
import { Browser } from 'detect-browser';
|
|
5
6
|
import logdown from 'logdown';
|
|
6
7
|
import { RuleItem } from 'async-validator';
|
|
8
|
+
export { AxiosError as HttpError, AxiosPromise as HttpPromise, AxiosRequestConfig as HttpRequestConfig, AxiosResponse as HttpResponse } from 'axios';
|
|
9
|
+
|
|
10
|
+
interface AppComponentsResolverOptions {
|
|
11
|
+
prefix?: string;
|
|
12
|
+
}
|
|
13
|
+
declare function AppComponentsResolver(options?: AppComponentsResolverOptions): any;
|
|
7
14
|
|
|
8
15
|
interface Dictionary {
|
|
9
16
|
[keys: string | number]: any;
|
|
@@ -17,18 +24,11 @@ interface ResponseError {
|
|
|
17
24
|
|
|
18
25
|
declare function camelizeKeys(object: Dictionary): Dictionary;
|
|
19
26
|
|
|
20
|
-
declare function createClassName(className: string): (...classNames: string[]) => string;
|
|
21
|
-
|
|
22
27
|
interface Options$2 extends Intl.NumberFormatOptions {
|
|
23
28
|
locale?: string;
|
|
24
29
|
}
|
|
25
30
|
declare function formatMoney(value: string | number | null | undefined, currency?: string, options?: Options$2): string;
|
|
26
31
|
|
|
27
|
-
declare function genLoadingTableRows(columns: Dictionary[], limit: number): {
|
|
28
|
-
id: number | undefined;
|
|
29
|
-
key?: undefined;
|
|
30
|
-
}[];
|
|
31
|
-
|
|
32
32
|
declare function genRandomNumber(min: number, max: number): number;
|
|
33
33
|
|
|
34
34
|
declare function genUUID(): string;
|
|
@@ -126,7 +126,7 @@ declare function useAsyncMultiselect<T extends (...args: any[]) => any, K extend
|
|
|
126
126
|
}): {
|
|
127
127
|
items: vue.ComputedRef<any[]>;
|
|
128
128
|
options: vue.ComputedRef<ReturnType<K>[]>;
|
|
129
|
-
search: vue.
|
|
129
|
+
search: vue.Ref<string>;
|
|
130
130
|
hasNextPage: vue.ComputedRef<boolean>;
|
|
131
131
|
isFetching: vue.Ref<boolean>;
|
|
132
132
|
isLoading: vue.Ref<false> | vue.Ref<true>;
|
|
@@ -153,7 +153,7 @@ declare function useAsyncSelect<T extends (...args: any[]) => any, K extends (pa
|
|
|
153
153
|
}): {
|
|
154
154
|
items: vue.ComputedRef<any[]>;
|
|
155
155
|
options: vue.ComputedRef<ReturnType<K>[]>;
|
|
156
|
-
search: vue.
|
|
156
|
+
search: vue.Ref<string>;
|
|
157
157
|
hasNextPage: vue.ComputedRef<boolean>;
|
|
158
158
|
isFetching: vue.Ref<boolean>;
|
|
159
159
|
isLoading: vue.Ref<false> | vue.Ref<true>;
|
|
@@ -161,6 +161,17 @@ declare function useAsyncSelect<T extends (...args: any[]) => any, K extends (pa
|
|
|
161
161
|
updateSearch: (value: string) => void;
|
|
162
162
|
};
|
|
163
163
|
|
|
164
|
+
declare function useBreakpoint(): {
|
|
165
|
+
isMobile: vue.Ref<boolean>;
|
|
166
|
+
isDesktop: vue.Ref<boolean>;
|
|
167
|
+
isGreaterXxs: vue.Ref<boolean>;
|
|
168
|
+
isGreaterXs: vue.Ref<boolean>;
|
|
169
|
+
isGreaterSm: vue.Ref<boolean>;
|
|
170
|
+
isGreaterMd: vue.Ref<boolean>;
|
|
171
|
+
isGreaterLg: vue.Ref<boolean>;
|
|
172
|
+
isGreaterXl: vue.Ref<boolean>;
|
|
173
|
+
};
|
|
174
|
+
|
|
164
175
|
declare function useClassName(block: string): {
|
|
165
176
|
b: (blockSuffix?: string) => string;
|
|
166
177
|
e: (element?: string) => string;
|
|
@@ -200,6 +211,24 @@ declare function useGlobalScroll(): {
|
|
|
200
211
|
unlock: () => void;
|
|
201
212
|
};
|
|
202
213
|
|
|
214
|
+
declare function useFilters<T extends Record<string, any>, K extends Record<string, any>>({ config, initialFilters, }: {
|
|
215
|
+
config: T;
|
|
216
|
+
initialFilters: K;
|
|
217
|
+
}): {
|
|
218
|
+
isOpen: Ref<boolean>;
|
|
219
|
+
filtersModel: Ref<K>;
|
|
220
|
+
filtersFromQuery: vue.ComputedRef<{}>;
|
|
221
|
+
filtersCount: vue.ComputedRef<number>;
|
|
222
|
+
updateOne: (key: keyof K, value: any) => void;
|
|
223
|
+
updateMany: (filters: Record<string, any>) => void;
|
|
224
|
+
open: () => void;
|
|
225
|
+
clear: () => void;
|
|
226
|
+
setQueryFromFilters: (filters: Record<string, any>) => void;
|
|
227
|
+
getValidatedParams: (query: Record<string, any>) => {
|
|
228
|
+
filters: any;
|
|
229
|
+
};
|
|
230
|
+
};
|
|
231
|
+
|
|
203
232
|
/**
|
|
204
233
|
* @see https://github.com/caiogondim/logdown.js#readme
|
|
205
234
|
*/
|
|
@@ -211,6 +240,29 @@ interface Options {
|
|
|
211
240
|
}
|
|
212
241
|
declare function useLogger(scope: string, options?: Options): logdown.Logger;
|
|
213
242
|
|
|
243
|
+
interface VNodeCustom extends VNode {
|
|
244
|
+
close(): void;
|
|
245
|
+
}
|
|
246
|
+
declare function usePanel(): {
|
|
247
|
+
open: ({ layer, component, props, }: {
|
|
248
|
+
component: Component;
|
|
249
|
+
props?: any;
|
|
250
|
+
layer?: number;
|
|
251
|
+
}) => string;
|
|
252
|
+
getInstance: (uuid: string) => VNodeCustom;
|
|
253
|
+
close: (uuid: string) => void;
|
|
254
|
+
closeAll: () => void;
|
|
255
|
+
openByHash: ({ layer, component, props, }: {
|
|
256
|
+
component: Component;
|
|
257
|
+
props?: any;
|
|
258
|
+
layer?: number;
|
|
259
|
+
}) => void;
|
|
260
|
+
watchHash: ({ component, events, }: {
|
|
261
|
+
component: Component;
|
|
262
|
+
events?: EmitsOptions;
|
|
263
|
+
}) => any;
|
|
264
|
+
};
|
|
265
|
+
|
|
214
266
|
declare function validatePhone(rule: string, value: string): boolean;
|
|
215
267
|
|
|
216
268
|
declare function isRequired(value?: boolean, message?: string): RuleItem;
|
|
@@ -227,4 +279,4 @@ declare function isTypeUrl(message?: string): RuleItem;
|
|
|
227
279
|
declare function isTypeNumber(value?: number, message?: string): RuleItem;
|
|
228
280
|
declare function isStrictLength(value?: number, message?: string): RuleItem;
|
|
229
281
|
|
|
230
|
-
export { BrowserInfo, Dictionary, ResponseError, UiComponentsResolver, VersionsList, camelizeKeys,
|
|
282
|
+
export { AppComponentsResolver, BrowserInfo, Dictionary, ResponseError, UiComponentsResolver, VersionsList, camelizeKeys, formatMoney, genRandomNumber, genUUID, getCardNumber, getCountryFromPhone, getPaginationLimit, getPaginationOffset, getPaginationPages, getPaginationParams, isElementIgnored, isEmptyObject, isMax, isMin, isRequired, isStrictLength, isTypeEmail, isTypeNumber, isTypeUrl, parsePhone, snakelizeKeys, unformatNumber, useAbortController, useAsyncMultiselect, useAsyncSelect, useBreakpoint, useClassName, useDayjs, useDetectBrowser, useFilters, useGlobalScroll, useLogger, usePanel, validateNumber, validatePhone };
|
package/dist/index.mjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import camelCase from 'lodash/camelCase.js';
|
|
2
|
-
import { CURRENCY_DEFAULT } from '@karta.io/common-data';
|
|
2
|
+
import { CURRENCY_DEFAULT, BREAKPOINTS } from '@karta.io/common-data';
|
|
3
3
|
import { parsePhoneNumberFromString } from 'libphonenumber-js';
|
|
4
4
|
import snakeCase from 'lodash/snakeCase.js';
|
|
5
|
-
import { reactive, ref, watch, computed, isRef, nextTick, onBeforeUnmount } from 'vue';
|
|
5
|
+
import { reactive, ref, watch, computed, isRef, nextTick, onBeforeUnmount, onMounted, getCurrentInstance, render, createVNode } from 'vue';
|
|
6
6
|
import { useQuery } from '@tanstack/vue-query';
|
|
7
|
-
import { toValue, useDebounceFn } from '@vueuse/core';
|
|
7
|
+
import { toValue, useDebounceFn, useBreakpoints } from '@vueuse/core';
|
|
8
8
|
import get from 'lodash/get.js';
|
|
9
9
|
import has from 'lodash/has.js';
|
|
10
10
|
import logdown from 'logdown';
|
|
@@ -15,6 +15,18 @@ import updateLocale from 'dayjs/plugin/updateLocale.js';
|
|
|
15
15
|
import isToday from 'dayjs/plugin/isToday.js';
|
|
16
16
|
import customParseFormat from 'dayjs/plugin/customParseFormat.js';
|
|
17
17
|
import { detect } from 'detect-browser';
|
|
18
|
+
import { useRouter, useRoute } from 'vue-router';
|
|
19
|
+
import qs from 'qs';
|
|
20
|
+
|
|
21
|
+
function AppComponentsResolver(options = {}) {
|
|
22
|
+
const { prefix = "" } = options;
|
|
23
|
+
return (name) => {
|
|
24
|
+
const componentName = prefix && name.startsWith(prefix) ? name.substring(prefix.length) : name;
|
|
25
|
+
const isAppComponent = componentName.startsWith("App");
|
|
26
|
+
if (isAppComponent)
|
|
27
|
+
return { name: componentName, from: "@karta.io/app-components" };
|
|
28
|
+
};
|
|
29
|
+
}
|
|
18
30
|
|
|
19
31
|
function camelizeKeys(object) {
|
|
20
32
|
if (Array.isArray(object))
|
|
@@ -31,14 +43,6 @@ function camelizeKeys(object) {
|
|
|
31
43
|
return object;
|
|
32
44
|
}
|
|
33
45
|
|
|
34
|
-
function createClassName(className) {
|
|
35
|
-
return function f(...classNames) {
|
|
36
|
-
const result = classNames.join("");
|
|
37
|
-
const create = (...args) => args.length ? f.apply(null, [result, ...args])() : result;
|
|
38
|
-
return create;
|
|
39
|
-
}(className);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
46
|
function formatMoney(value, currency = CURRENCY_DEFAULT, options = {}) {
|
|
43
47
|
const convertedValue = Number(value);
|
|
44
48
|
if (value === null || Number.isNaN(convertedValue))
|
|
@@ -54,11 +58,6 @@ function formatMoney(value, currency = CURRENCY_DEFAULT, options = {}) {
|
|
|
54
58
|
return formatter.format(convertedValue);
|
|
55
59
|
}
|
|
56
60
|
|
|
57
|
-
function genLoadingTableRows(columns, limit) {
|
|
58
|
-
const row = columns.reduce((acc, curr) => ({ ...acc, [curr.key]: void 0 }), {});
|
|
59
|
-
return Array.from(Array(limit).keys()).map((item) => ({ id: item, ...row }));
|
|
60
|
-
}
|
|
61
|
-
|
|
62
61
|
function genRandomNumber(min, max) {
|
|
63
62
|
return Math.floor(Math.random() * (max - min + 1)) + min;
|
|
64
63
|
}
|
|
@@ -309,6 +308,7 @@ function useAsyncMultiselect({
|
|
|
309
308
|
selectedValues: toValue(selectedValues),
|
|
310
309
|
params: JSON.stringify(toValue(params))
|
|
311
310
|
});
|
|
311
|
+
const search = ref("");
|
|
312
312
|
const { call, abort } = useAbortController(apiMethod);
|
|
313
313
|
const loadWAC = () => call({
|
|
314
314
|
page: reactiveData.page,
|
|
@@ -407,6 +407,7 @@ function useAsyncMultiselect({
|
|
|
407
407
|
reactiveData.selectedValues = toValue(selectedValues);
|
|
408
408
|
}, delay);
|
|
409
409
|
const updateSearch = (value) => {
|
|
410
|
+
search.value = value;
|
|
410
411
|
updateSearchWithDebounce(value);
|
|
411
412
|
};
|
|
412
413
|
if (isRef(selectedValues)) {
|
|
@@ -444,7 +445,7 @@ function useAsyncMultiselect({
|
|
|
444
445
|
return {
|
|
445
446
|
items,
|
|
446
447
|
options,
|
|
447
|
-
search
|
|
448
|
+
search,
|
|
448
449
|
hasNextPage,
|
|
449
450
|
isFetching,
|
|
450
451
|
isLoading,
|
|
@@ -476,6 +477,7 @@ function useAsyncSelect({
|
|
|
476
477
|
selectedValue: toValue(selectedValue),
|
|
477
478
|
params: JSON.stringify(toValue(params))
|
|
478
479
|
});
|
|
480
|
+
const search = ref("");
|
|
479
481
|
const { call, abort } = useAbortController(apiMethod);
|
|
480
482
|
const loadWAC = () => call({
|
|
481
483
|
page: reactiveData.page,
|
|
@@ -551,6 +553,7 @@ function useAsyncSelect({
|
|
|
551
553
|
reactiveData.page = 1;
|
|
552
554
|
}, delay);
|
|
553
555
|
const updateSearch = (value) => {
|
|
556
|
+
search.value = value;
|
|
554
557
|
updateSearchWithDebounce(value);
|
|
555
558
|
};
|
|
556
559
|
if (isRef(selectedValue)) {
|
|
@@ -571,7 +574,7 @@ function useAsyncSelect({
|
|
|
571
574
|
return {
|
|
572
575
|
items,
|
|
573
576
|
options,
|
|
574
|
-
search
|
|
577
|
+
search,
|
|
575
578
|
hasNextPage,
|
|
576
579
|
isFetching,
|
|
577
580
|
isLoading,
|
|
@@ -580,6 +583,28 @@ function useAsyncSelect({
|
|
|
580
583
|
};
|
|
581
584
|
}
|
|
582
585
|
|
|
586
|
+
function useBreakpoint() {
|
|
587
|
+
const breakpoints = useBreakpoints(BREAKPOINTS);
|
|
588
|
+
const isMobile = breakpoints.smaller("sm");
|
|
589
|
+
const isDesktop = breakpoints.greater("md");
|
|
590
|
+
const isGreaterXxs = breakpoints.greater("xxs");
|
|
591
|
+
const isGreaterXs = breakpoints.greater("xs");
|
|
592
|
+
const isGreaterSm = breakpoints.greater("sm");
|
|
593
|
+
const isGreaterMd = breakpoints.greater("md");
|
|
594
|
+
const isGreaterLg = breakpoints.greater("lg");
|
|
595
|
+
const isGreaterXl = breakpoints.greater("xl");
|
|
596
|
+
return {
|
|
597
|
+
isMobile,
|
|
598
|
+
isDesktop,
|
|
599
|
+
isGreaterXxs,
|
|
600
|
+
isGreaterXs,
|
|
601
|
+
isGreaterSm,
|
|
602
|
+
isGreaterMd,
|
|
603
|
+
isGreaterLg,
|
|
604
|
+
isGreaterXl
|
|
605
|
+
};
|
|
606
|
+
}
|
|
607
|
+
|
|
583
608
|
function _bem(block, blockSuffix, element, modifier, modifierValue) {
|
|
584
609
|
let cls = block;
|
|
585
610
|
if (blockSuffix)
|
|
@@ -693,6 +718,322 @@ function useGlobalScroll() {
|
|
|
693
718
|
};
|
|
694
719
|
}
|
|
695
720
|
|
|
721
|
+
const QS_STRINGIFY_PARAMS = {
|
|
722
|
+
arrayFormat: "comma",
|
|
723
|
+
encode: false,
|
|
724
|
+
skipNulls: true,
|
|
725
|
+
addQueryPrefix: true
|
|
726
|
+
};
|
|
727
|
+
const isOpen = ref(false);
|
|
728
|
+
function useFilters({
|
|
729
|
+
config,
|
|
730
|
+
initialFilters
|
|
731
|
+
}) {
|
|
732
|
+
const router = useRouter();
|
|
733
|
+
const route = useRoute();
|
|
734
|
+
const parseRouteQuery = (query) => qs.parse(query ?? route.query);
|
|
735
|
+
const filtersFromQuery = computed(() => {
|
|
736
|
+
const parsedRouteQuery = parseRouteQuery();
|
|
737
|
+
if (!parsedRouteQuery.filters)
|
|
738
|
+
return void 0;
|
|
739
|
+
return Object.entries(config).reduce((accum, [currentKey, currentValue]) => {
|
|
740
|
+
if (!parsedRouteQuery.filters[currentKey])
|
|
741
|
+
return accum;
|
|
742
|
+
if (currentValue.type === "ARRAY" /* Array */) {
|
|
743
|
+
const splitValues = parsedRouteQuery.filters[currentKey].split(",");
|
|
744
|
+
const checkedValue = currentValue?.possibleValues ? splitValues.filter((k) => currentValue?.possibleValues?.includes(k)) : splitValues;
|
|
745
|
+
if (!checkedValue?.length)
|
|
746
|
+
return accum;
|
|
747
|
+
return {
|
|
748
|
+
...accum,
|
|
749
|
+
[currentKey]: checkedValue
|
|
750
|
+
};
|
|
751
|
+
}
|
|
752
|
+
return {
|
|
753
|
+
...accum,
|
|
754
|
+
[currentKey]: parsedRouteQuery.filters[currentKey]
|
|
755
|
+
};
|
|
756
|
+
}, {});
|
|
757
|
+
});
|
|
758
|
+
const filtersCount = computed(
|
|
759
|
+
() => filtersFromQuery.value ? Object.keys(filtersFromQuery.value).length : 0
|
|
760
|
+
);
|
|
761
|
+
const setQueryFromFilters = (filters) => {
|
|
762
|
+
const parsedRouteQuery = parseRouteQuery();
|
|
763
|
+
const filteredValue = Object.entries(filters).reduce((accum, [currentKey, currentValue]) => {
|
|
764
|
+
if (!currentValue?.length)
|
|
765
|
+
return accum;
|
|
766
|
+
return { ...accum, [currentKey]: currentValue };
|
|
767
|
+
}, {});
|
|
768
|
+
const query = qs.stringify(
|
|
769
|
+
{
|
|
770
|
+
...parsedRouteQuery,
|
|
771
|
+
filters: filteredValue,
|
|
772
|
+
page: void 0
|
|
773
|
+
},
|
|
774
|
+
QS_STRINGIFY_PARAMS
|
|
775
|
+
);
|
|
776
|
+
router.push(query);
|
|
777
|
+
};
|
|
778
|
+
const getValidatedParams = (query) => {
|
|
779
|
+
const parsedRouteQuery = parseRouteQuery(query);
|
|
780
|
+
if (query?.filters) {
|
|
781
|
+
const filters = {
|
|
782
|
+
...query.filters,
|
|
783
|
+
...filtersFromQuery.value
|
|
784
|
+
};
|
|
785
|
+
return { ...parsedRouteQuery, filters };
|
|
786
|
+
}
|
|
787
|
+
return { ...parsedRouteQuery, filters: filtersFromQuery.value };
|
|
788
|
+
};
|
|
789
|
+
const open = () => {
|
|
790
|
+
isOpen.value = true;
|
|
791
|
+
};
|
|
792
|
+
const clear = () => setQueryFromFilters({});
|
|
793
|
+
const filtersModel = ref({
|
|
794
|
+
...initialFilters,
|
|
795
|
+
...filtersFromQuery.value
|
|
796
|
+
});
|
|
797
|
+
const updateOne = (key, value) => {
|
|
798
|
+
setQueryFromFilters({
|
|
799
|
+
...filtersModel.value,
|
|
800
|
+
[key]: value ? String(value) : void 0
|
|
801
|
+
});
|
|
802
|
+
};
|
|
803
|
+
const updateMany = (filters) => {
|
|
804
|
+
const newFilters = Object.entries(filters).reduce((accum, [currentKey, currentValue]) => {
|
|
805
|
+
return {
|
|
806
|
+
...accum,
|
|
807
|
+
[currentKey]: currentValue ? String(currentValue) : void 0
|
|
808
|
+
};
|
|
809
|
+
}, {});
|
|
810
|
+
setQueryFromFilters({
|
|
811
|
+
...filtersModel.value,
|
|
812
|
+
...newFilters
|
|
813
|
+
});
|
|
814
|
+
};
|
|
815
|
+
watch(filtersFromQuery, (newFilters) => {
|
|
816
|
+
if (!newFilters) {
|
|
817
|
+
filtersModel.value = { ...initialFilters };
|
|
818
|
+
return;
|
|
819
|
+
}
|
|
820
|
+
filtersModel.value = { ...initialFilters, ...newFilters };
|
|
821
|
+
});
|
|
822
|
+
return {
|
|
823
|
+
isOpen,
|
|
824
|
+
filtersModel,
|
|
825
|
+
filtersFromQuery,
|
|
826
|
+
filtersCount,
|
|
827
|
+
updateOne,
|
|
828
|
+
updateMany,
|
|
829
|
+
open,
|
|
830
|
+
clear,
|
|
831
|
+
setQueryFromFilters,
|
|
832
|
+
getValidatedParams
|
|
833
|
+
};
|
|
834
|
+
}
|
|
835
|
+
|
|
836
|
+
let panels = [];
|
|
837
|
+
function usePanel() {
|
|
838
|
+
let appContext;
|
|
839
|
+
const logger = useLogger("use-panel");
|
|
840
|
+
const {
|
|
841
|
+
isLocked: isGlobalScrollLocked,
|
|
842
|
+
lock: lockGlobalScroll,
|
|
843
|
+
unlock: unlockGlobalScroll
|
|
844
|
+
} = useGlobalScroll();
|
|
845
|
+
const route = useRoute();
|
|
846
|
+
const router = useRouter();
|
|
847
|
+
onMounted(() => {
|
|
848
|
+
appContext = getCurrentInstance()?.appContext;
|
|
849
|
+
});
|
|
850
|
+
const open = ({
|
|
851
|
+
layer = 0,
|
|
852
|
+
component,
|
|
853
|
+
props
|
|
854
|
+
}) => {
|
|
855
|
+
const uuid = genUUID();
|
|
856
|
+
const createComponent = () => {
|
|
857
|
+
const newProps = {
|
|
858
|
+
...props,
|
|
859
|
+
layer
|
|
860
|
+
};
|
|
861
|
+
const el2 = document.createElement("div");
|
|
862
|
+
const vnode2 = createVNode(component, {
|
|
863
|
+
...newProps,
|
|
864
|
+
modelValue: true,
|
|
865
|
+
uuid
|
|
866
|
+
});
|
|
867
|
+
vnode2.appContext = { ...appContext };
|
|
868
|
+
if (!vnode2?.props?.["onUpdate:modelValue"]) {
|
|
869
|
+
vnode2.props["onUpdate:modelValue"] = (value) => {
|
|
870
|
+
if (vnode2 && vnode2.component) {
|
|
871
|
+
vnode2.component.props.modelValue = value;
|
|
872
|
+
if (!value && panels.length === 1 && isGlobalScrollLocked.value) {
|
|
873
|
+
unlockGlobalScroll();
|
|
874
|
+
}
|
|
875
|
+
}
|
|
876
|
+
};
|
|
877
|
+
}
|
|
878
|
+
vnode2.close = () => {
|
|
879
|
+
if (vnode2 && vnode2.component) {
|
|
880
|
+
vnode2.component.props.modelValue = false;
|
|
881
|
+
}
|
|
882
|
+
};
|
|
883
|
+
vnode2.props.onDestroy = () => {
|
|
884
|
+
render(null, el2);
|
|
885
|
+
panels = panels.filter((panel) => panel.uuid !== uuid);
|
|
886
|
+
logger.info("Panels after destroy", panels);
|
|
887
|
+
};
|
|
888
|
+
const name = vnode2?.type?.name ?? "Unknown component";
|
|
889
|
+
const newPanel2 = {
|
|
890
|
+
uuid,
|
|
891
|
+
name,
|
|
892
|
+
vnode: vnode2,
|
|
893
|
+
layer
|
|
894
|
+
};
|
|
895
|
+
logger.log(`Open new panel: "${name}"`);
|
|
896
|
+
if (!isGlobalScrollLocked.value) {
|
|
897
|
+
lockGlobalScroll();
|
|
898
|
+
}
|
|
899
|
+
return {
|
|
900
|
+
vnode: vnode2,
|
|
901
|
+
el: el2,
|
|
902
|
+
newPanel: newPanel2
|
|
903
|
+
};
|
|
904
|
+
};
|
|
905
|
+
if (!panels.length) {
|
|
906
|
+
const { vnode: vnode2, el: el2, newPanel: newPanel2 } = createComponent();
|
|
907
|
+
render(vnode2, el2);
|
|
908
|
+
panels = [newPanel2];
|
|
909
|
+
logger.info("Panels after open", panels);
|
|
910
|
+
return uuid;
|
|
911
|
+
}
|
|
912
|
+
if (layer === 0) {
|
|
913
|
+
closeAll();
|
|
914
|
+
const { vnode: vnode2, el: el2, newPanel: newPanel2 } = createComponent();
|
|
915
|
+
render(vnode2, el2);
|
|
916
|
+
panels = [newPanel2];
|
|
917
|
+
logger.info("Panels after open", panels);
|
|
918
|
+
return uuid;
|
|
919
|
+
}
|
|
920
|
+
if (!panels.some((panel) => panel.layer === layer)) {
|
|
921
|
+
const { vnode: vnode2, el: el2, newPanel: newPanel2 } = createComponent();
|
|
922
|
+
render(vnode2, el2);
|
|
923
|
+
panels = [...panels, newPanel2];
|
|
924
|
+
logger.info("Panels after open", panels);
|
|
925
|
+
return uuid;
|
|
926
|
+
}
|
|
927
|
+
const panelOnCurrentLayer = panels.find((panel) => panel.layer === layer);
|
|
928
|
+
close(panelOnCurrentLayer?.uuid || "");
|
|
929
|
+
const { vnode, el, newPanel } = createComponent();
|
|
930
|
+
render(vnode, el);
|
|
931
|
+
panels = [...panels, newPanel];
|
|
932
|
+
logger.info("Panels after open", panels);
|
|
933
|
+
return uuid;
|
|
934
|
+
};
|
|
935
|
+
const close = (uuid) => {
|
|
936
|
+
const panel = panels.find((item) => item.uuid === uuid);
|
|
937
|
+
logger.log(`Close panel: "${uuid}"`);
|
|
938
|
+
if (panels.length === 1 && isGlobalScrollLocked.value) {
|
|
939
|
+
unlockGlobalScroll();
|
|
940
|
+
}
|
|
941
|
+
panel?.vnode.close();
|
|
942
|
+
};
|
|
943
|
+
const closeAll = () => {
|
|
944
|
+
panels.forEach((panel) => {
|
|
945
|
+
panel?.vnode.close();
|
|
946
|
+
});
|
|
947
|
+
if (isGlobalScrollLocked.value) {
|
|
948
|
+
unlockGlobalScroll();
|
|
949
|
+
}
|
|
950
|
+
};
|
|
951
|
+
const getInstance = (uuid) => {
|
|
952
|
+
return panels.find((item) => item.uuid === uuid)?.vnode;
|
|
953
|
+
};
|
|
954
|
+
const openByHash = ({
|
|
955
|
+
layer = 0,
|
|
956
|
+
component,
|
|
957
|
+
props
|
|
958
|
+
}) => {
|
|
959
|
+
const data = {
|
|
960
|
+
name: component.name,
|
|
961
|
+
layer,
|
|
962
|
+
props
|
|
963
|
+
};
|
|
964
|
+
router.push({
|
|
965
|
+
name: route.name || void 0,
|
|
966
|
+
query: route.query,
|
|
967
|
+
hash: `#${window.btoa(JSON.stringify(data))}`
|
|
968
|
+
});
|
|
969
|
+
};
|
|
970
|
+
const watchHash = ({
|
|
971
|
+
component,
|
|
972
|
+
events
|
|
973
|
+
}) => {
|
|
974
|
+
logger.info(`start watching route.hash for panel *${component.name}*`);
|
|
975
|
+
const stopWatch = watch(
|
|
976
|
+
() => route.hash,
|
|
977
|
+
async (newHash) => {
|
|
978
|
+
if (!newHash) {
|
|
979
|
+
closeAll();
|
|
980
|
+
return;
|
|
981
|
+
}
|
|
982
|
+
let dataFromHash;
|
|
983
|
+
try {
|
|
984
|
+
dataFromHash = JSON.parse(window.atob(newHash.slice(1)));
|
|
985
|
+
} catch (error) {
|
|
986
|
+
logger.error("*watchHash* cant parse hash");
|
|
987
|
+
}
|
|
988
|
+
if (typeof dataFromHash !== "object")
|
|
989
|
+
return;
|
|
990
|
+
if (!dataFromHash.name) {
|
|
991
|
+
logger.error("*watchHash* cant find component name in hash");
|
|
992
|
+
return;
|
|
993
|
+
}
|
|
994
|
+
if (dataFromHash.name !== component.name)
|
|
995
|
+
return;
|
|
996
|
+
logger.info("*watchHash* data from hash", dataFromHash);
|
|
997
|
+
await nextTick();
|
|
998
|
+
open({
|
|
999
|
+
component,
|
|
1000
|
+
layer: dataFromHash.layer || 0,
|
|
1001
|
+
props: {
|
|
1002
|
+
"onUpdate:modelValue": (value) => {
|
|
1003
|
+
if (value)
|
|
1004
|
+
return;
|
|
1005
|
+
router.push({
|
|
1006
|
+
name: route.name || void 0,
|
|
1007
|
+
query: route.query,
|
|
1008
|
+
hash: void 0
|
|
1009
|
+
});
|
|
1010
|
+
},
|
|
1011
|
+
...dataFromHash.props,
|
|
1012
|
+
...events
|
|
1013
|
+
}
|
|
1014
|
+
});
|
|
1015
|
+
},
|
|
1016
|
+
{ immediate: true }
|
|
1017
|
+
);
|
|
1018
|
+
const stopWatchHash = () => {
|
|
1019
|
+
logger.info(`stop watching route.hash for panel *${component.name}*`);
|
|
1020
|
+
stopWatch();
|
|
1021
|
+
};
|
|
1022
|
+
onBeforeUnmount(() => {
|
|
1023
|
+
stopWatchHash();
|
|
1024
|
+
});
|
|
1025
|
+
return stopWatchHash;
|
|
1026
|
+
};
|
|
1027
|
+
return {
|
|
1028
|
+
open,
|
|
1029
|
+
getInstance,
|
|
1030
|
+
close,
|
|
1031
|
+
closeAll,
|
|
1032
|
+
openByHash,
|
|
1033
|
+
watchHash
|
|
1034
|
+
};
|
|
1035
|
+
}
|
|
1036
|
+
|
|
696
1037
|
function validatePhone(rule, value) {
|
|
697
1038
|
if (!value)
|
|
698
1039
|
return true;
|
|
@@ -744,4 +1085,4 @@ function isStrictLength(value = 3, message) {
|
|
|
744
1085
|
};
|
|
745
1086
|
}
|
|
746
1087
|
|
|
747
|
-
export { UiComponentsResolver, camelizeKeys,
|
|
1088
|
+
export { AppComponentsResolver, UiComponentsResolver, camelizeKeys, formatMoney, genRandomNumber, genUUID, getCardNumber, getCountryFromPhone, getPaginationLimit, getPaginationOffset, getPaginationPages, getPaginationParams, isElementIgnored, isEmptyObject, isMax, isMin, isRequired, isStrictLength, isTypeEmail, isTypeNumber, isTypeUrl, parsePhone, snakelizeKeys, unformatNumber, useAbortController, useAsyncMultiselect, useAsyncSelect, useBreakpoint, useClassName, useDayjs, useDetectBrowser, useFilters, useGlobalScroll, useLogger, usePanel, validateNumber, validatePhone };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@karta.io/utils",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0-alpha.0",
|
|
4
4
|
"description": "karta.io utils for admin and application",
|
|
5
5
|
"author": "Vitaly Blokhin <karambafe@gmail.com>",
|
|
6
6
|
"homepage": "",
|
|
@@ -21,23 +21,21 @@
|
|
|
21
21
|
"dist"
|
|
22
22
|
],
|
|
23
23
|
"peerDependencies": {
|
|
24
|
-
"@tanstack/vue-query": "4.x.x",
|
|
25
24
|
"vue": "3.3.x"
|
|
26
25
|
},
|
|
27
|
-
"peerDependenciesMeta": {
|
|
28
|
-
"@tanstack/vue-query": {
|
|
29
|
-
"optional": true
|
|
30
|
-
}
|
|
31
|
-
},
|
|
32
26
|
"dependencies": {
|
|
33
|
-
"@karta.io/common-data": "^0.
|
|
34
|
-
"@
|
|
27
|
+
"@karta.io/common-data": "^1.0.0-alpha.0",
|
|
28
|
+
"@tanstack/vue-query": "4.33.1",
|
|
29
|
+
"@vueuse/core": "10.3.0",
|
|
35
30
|
"async-validator": "4.2.5",
|
|
31
|
+
"axios": "1.4.0",
|
|
36
32
|
"dayjs": "1.11.8",
|
|
37
33
|
"detect-browser": "5.3.0",
|
|
38
34
|
"libphonenumber-js": "1.10.36",
|
|
39
35
|
"lodash": "4.17.21",
|
|
40
|
-
"logdown": "3.3.1"
|
|
36
|
+
"logdown": "3.3.1",
|
|
37
|
+
"qs": "6.11.2",
|
|
38
|
+
"vue-router": "4.x.x"
|
|
41
39
|
},
|
|
42
40
|
"devDependencies": {
|
|
43
41
|
"@qvant/prettier-config": "0.1.0",
|
|
@@ -47,8 +45,8 @@
|
|
|
47
45
|
"eslint": "8.43.0",
|
|
48
46
|
"eslint-config-airbnb-base": "15.0.0",
|
|
49
47
|
"eslint-plugin-import": "2.27.5",
|
|
50
|
-
"prettier": "
|
|
51
|
-
"typescript": "5.
|
|
48
|
+
"prettier": "3.0.1",
|
|
49
|
+
"typescript": "5.1.6",
|
|
52
50
|
"unbuild": "1.2.1",
|
|
53
51
|
"vitest": "0.32.2",
|
|
54
52
|
"vue": "3.3.4"
|