@m4l/core 0.0.26 → 0.0.29
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/contexts/ModuleDictionaryContext/index.js +1 -1
- package/dist/contexts/ModuleDictionaryContext/types.d.ts +1 -1
- package/dist/external/axios.js +9 -4
- package/dist/external/qs.js +633 -0
- package/dist/external/side-channel.js +105 -0
- package/dist/hooks/index.d.ts +6 -3
- package/dist/hooks/usePaginate/index.d.ts +15 -0
- package/dist/hooks/usePaginate/index.js +72 -0
- package/dist/hooks/usePaginate/types.d.ts +6 -0
- package/dist/index.js +6 -4
- package/dist/node_modules.js +927 -90
- package/dist/types/index.d.ts +1 -0
- package/dist/utils/index.js +1 -1
- package/dist/vendor.js +13 -6
- package/package.json +3 -1
- package/dist/external/snakecase-keys.js +0 -18
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { g as getIntrinsic, c as callBound$1, o as objectInspect } from "../node_modules.js";
|
|
2
|
+
var GetIntrinsic = getIntrinsic;
|
|
3
|
+
var callBound = callBound$1;
|
|
4
|
+
var inspect = objectInspect;
|
|
5
|
+
var $TypeError = GetIntrinsic("%TypeError%");
|
|
6
|
+
var $WeakMap = GetIntrinsic("%WeakMap%", true);
|
|
7
|
+
var $Map = GetIntrinsic("%Map%", true);
|
|
8
|
+
var $weakMapGet = callBound("WeakMap.prototype.get", true);
|
|
9
|
+
var $weakMapSet = callBound("WeakMap.prototype.set", true);
|
|
10
|
+
var $weakMapHas = callBound("WeakMap.prototype.has", true);
|
|
11
|
+
var $mapGet = callBound("Map.prototype.get", true);
|
|
12
|
+
var $mapSet = callBound("Map.prototype.set", true);
|
|
13
|
+
var $mapHas = callBound("Map.prototype.has", true);
|
|
14
|
+
var listGetNode = function(list, key) {
|
|
15
|
+
for (var prev = list, curr; (curr = prev.next) !== null; prev = curr) {
|
|
16
|
+
if (curr.key === key) {
|
|
17
|
+
prev.next = curr.next;
|
|
18
|
+
curr.next = list.next;
|
|
19
|
+
list.next = curr;
|
|
20
|
+
return curr;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
var listGet = function(objects, key) {
|
|
25
|
+
var node = listGetNode(objects, key);
|
|
26
|
+
return node && node.value;
|
|
27
|
+
};
|
|
28
|
+
var listSet = function(objects, key, value) {
|
|
29
|
+
var node = listGetNode(objects, key);
|
|
30
|
+
if (node) {
|
|
31
|
+
node.value = value;
|
|
32
|
+
} else {
|
|
33
|
+
objects.next = {
|
|
34
|
+
key,
|
|
35
|
+
next: objects.next,
|
|
36
|
+
value
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
var listHas = function(objects, key) {
|
|
41
|
+
return !!listGetNode(objects, key);
|
|
42
|
+
};
|
|
43
|
+
var sideChannel = function getSideChannel() {
|
|
44
|
+
var $wm;
|
|
45
|
+
var $m;
|
|
46
|
+
var $o;
|
|
47
|
+
var channel = {
|
|
48
|
+
assert: function(key) {
|
|
49
|
+
if (!channel.has(key)) {
|
|
50
|
+
throw new $TypeError("Side channel does not contain " + inspect(key));
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
get: function(key) {
|
|
54
|
+
if ($WeakMap && key && (typeof key === "object" || typeof key === "function")) {
|
|
55
|
+
if ($wm) {
|
|
56
|
+
return $weakMapGet($wm, key);
|
|
57
|
+
}
|
|
58
|
+
} else if ($Map) {
|
|
59
|
+
if ($m) {
|
|
60
|
+
return $mapGet($m, key);
|
|
61
|
+
}
|
|
62
|
+
} else {
|
|
63
|
+
if ($o) {
|
|
64
|
+
return listGet($o, key);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
has: function(key) {
|
|
69
|
+
if ($WeakMap && key && (typeof key === "object" || typeof key === "function")) {
|
|
70
|
+
if ($wm) {
|
|
71
|
+
return $weakMapHas($wm, key);
|
|
72
|
+
}
|
|
73
|
+
} else if ($Map) {
|
|
74
|
+
if ($m) {
|
|
75
|
+
return $mapHas($m, key);
|
|
76
|
+
}
|
|
77
|
+
} else {
|
|
78
|
+
if ($o) {
|
|
79
|
+
return listHas($o, key);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return false;
|
|
83
|
+
},
|
|
84
|
+
set: function(key, value) {
|
|
85
|
+
if ($WeakMap && key && (typeof key === "object" || typeof key === "function")) {
|
|
86
|
+
if (!$wm) {
|
|
87
|
+
$wm = new $WeakMap();
|
|
88
|
+
}
|
|
89
|
+
$weakMapSet($wm, key, value);
|
|
90
|
+
} else if ($Map) {
|
|
91
|
+
if (!$m) {
|
|
92
|
+
$m = new $Map();
|
|
93
|
+
}
|
|
94
|
+
$mapSet($m, key, value);
|
|
95
|
+
} else {
|
|
96
|
+
if (!$o) {
|
|
97
|
+
$o = { key: {}, next: null };
|
|
98
|
+
}
|
|
99
|
+
listSet($o, key, value);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
return channel;
|
|
104
|
+
};
|
|
105
|
+
export { sideChannel as s };
|
package/dist/hooks/index.d.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { useFlags, useFlagsPresent } from './useFlags';
|
|
2
2
|
export { useHostTools } from './useHostTools';
|
|
3
|
+
export { useLocalStorage } from './useLocalStorage';
|
|
4
|
+
export { useModuleDictionary } from './useModuleDictionary';
|
|
3
5
|
export { useNetwork } from './useNetwork';
|
|
4
6
|
export { useEnvironment } from './useEnvironment';
|
|
5
|
-
export {
|
|
6
|
-
export {
|
|
7
|
+
export { usePaginate } from './usePaginate';
|
|
8
|
+
export type { PagerState } from './usePaginate/types';
|
|
9
|
+
export { initialPagerState } from './usePaginate/types';
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { PagerState } from './types';
|
|
2
|
+
export interface propsUsePaginate {
|
|
3
|
+
endPoint: string;
|
|
4
|
+
timeout?: number;
|
|
5
|
+
fireOnEnter?: boolean;
|
|
6
|
+
queryParams?: Record<string, unknown>;
|
|
7
|
+
}
|
|
8
|
+
export declare const usePaginate: <TRow>(props: propsUsePaginate) => {
|
|
9
|
+
onPageChange: (newPage: number) => void;
|
|
10
|
+
onRowsPerPageChange: (newRowsPerPage: number) => void;
|
|
11
|
+
pagerState: PagerState;
|
|
12
|
+
rows: TRow[];
|
|
13
|
+
clearRows: () => void;
|
|
14
|
+
Refresh: () => void;
|
|
15
|
+
};
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { useState, useRef, useCallback, useEffect } from "react";
|
|
2
|
+
import { u as useHostTools } from "../useHostTools/index.js";
|
|
3
|
+
import { u as useNetwork } from "../useNetwork/index.js";
|
|
4
|
+
const initialPagerState = {
|
|
5
|
+
page: 0,
|
|
6
|
+
rowsPerPage: 25,
|
|
7
|
+
totalRecords: 0
|
|
8
|
+
};
|
|
9
|
+
const usePaginate = (props) => {
|
|
10
|
+
const { endPoint, timeout = 5e3, queryParams = {}, fireOnEnter = true } = props;
|
|
11
|
+
const [refresh, setRefresh] = useState(0);
|
|
12
|
+
const [rows, setRows] = useState([]);
|
|
13
|
+
const [pagerState, setPagerState] = useState(initialPagerState);
|
|
14
|
+
const refPagerState = useRef(initialPagerState);
|
|
15
|
+
const [fire, setFire] = useState(fireOnEnter);
|
|
16
|
+
const { startProgress, stopProgress } = useHostTools();
|
|
17
|
+
const { networkOperation } = useNetwork();
|
|
18
|
+
const Refresh = useCallback(() => {
|
|
19
|
+
setRefresh((oldValue) => oldValue + 1);
|
|
20
|
+
}, []);
|
|
21
|
+
useEffect(() => {
|
|
22
|
+
let mounted = true;
|
|
23
|
+
if (!fire) {
|
|
24
|
+
setFire(true);
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
startProgress();
|
|
28
|
+
networkOperation({
|
|
29
|
+
method: "GET",
|
|
30
|
+
endPoint,
|
|
31
|
+
timeout,
|
|
32
|
+
parms: {
|
|
33
|
+
...queryParams,
|
|
34
|
+
page: refPagerState.current.page,
|
|
35
|
+
limit: refPagerState.current.rowsPerPage
|
|
36
|
+
}
|
|
37
|
+
}).then((response) => {
|
|
38
|
+
if (mounted) {
|
|
39
|
+
setRows(response.data);
|
|
40
|
+
refPagerState.current.page = response.pager.page;
|
|
41
|
+
setPagerState((oldPagerState) => ({
|
|
42
|
+
...oldPagerState,
|
|
43
|
+
page: response.pager.page,
|
|
44
|
+
totalRecords: response.pager.total
|
|
45
|
+
}));
|
|
46
|
+
}
|
|
47
|
+
}).finally(() => {
|
|
48
|
+
if (mounted) {
|
|
49
|
+
stopProgress();
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
return function cleanUp() {
|
|
53
|
+
stopProgress();
|
|
54
|
+
mounted = false;
|
|
55
|
+
};
|
|
56
|
+
}, [refresh, queryParams]);
|
|
57
|
+
const onPageChange = (newPage) => {
|
|
58
|
+
refPagerState.current.page = newPage;
|
|
59
|
+
setRefresh((oldValue) => oldValue + 1);
|
|
60
|
+
};
|
|
61
|
+
const onRowsPerPageChange = (newRowsPerPage) => {
|
|
62
|
+
refPagerState.current.rowsPerPage = newRowsPerPage;
|
|
63
|
+
setPagerState((oldPagerState) => ({ ...oldPagerState, rowsPerPage: newRowsPerPage }));
|
|
64
|
+
setRefresh((oldValue) => oldValue + 1);
|
|
65
|
+
};
|
|
66
|
+
const clearRows = () => {
|
|
67
|
+
setRows([]);
|
|
68
|
+
setPagerState(initialPagerState);
|
|
69
|
+
};
|
|
70
|
+
return { onPageChange, onRowsPerPageChange, pagerState, rows, clearRows, Refresh };
|
|
71
|
+
};
|
|
72
|
+
export { initialPagerState as i, usePaginate as u };
|
package/dist/index.js
CHANGED
|
@@ -3,17 +3,19 @@ export { H as HostToolsContext, a as HostToolsProvider } from "./contexts/HostTo
|
|
|
3
3
|
export { N as NetworkContext, a as NetworkProvider } from "./contexts/NetworkContext/index.js";
|
|
4
4
|
export { F as FlagsContext, a as FlagsProvider } from "./contexts/FlagsContext/index.js";
|
|
5
5
|
export { M as ModuleDictionaryContext, a as ModuleDictionaryProvider } from "./contexts/ModuleDictionaryContext/index.js";
|
|
6
|
-
export { u as
|
|
6
|
+
export { u as useFlags, a as useFlagsPresent } from "./hooks/useFlags/index.js";
|
|
7
7
|
export { u as useHostTools } from "./hooks/useHostTools/index.js";
|
|
8
|
+
export { u as useLocalStorage } from "./hooks/useLocalStorage/index.js";
|
|
9
|
+
export { u as useModuleDictionary } from "./hooks/useModuleDictionary/index.js";
|
|
8
10
|
export { u as useNetwork } from "./hooks/useNetwork/index.js";
|
|
9
11
|
export { u as useEnvironment } from "./hooks/useEnvironment/index.js";
|
|
10
|
-
export {
|
|
11
|
-
export { u as useModuleDictionary } from "./hooks/useModuleDictionary/index.js";
|
|
12
|
+
export { i as initialPagerState, u as usePaginate } from "./hooks/usePaginate/index.js";
|
|
12
13
|
export { E as EmitEvents } from "./types/index.js";
|
|
13
14
|
export { a as getLocalStorage, g as getPropertyByString, s as setLocalStorage, v as voidFunction } from "./utils/index.js";
|
|
14
15
|
export { a as axiosOperation } from "./external/axios.js";
|
|
15
16
|
import "react";
|
|
16
17
|
import "react/jsx-runtime";
|
|
18
|
+
import "./external/qs.js";
|
|
19
|
+
import "./external/side-channel.js";
|
|
17
20
|
import "./node_modules.js";
|
|
18
21
|
import "./vendor.js";
|
|
19
|
-
import "./external/snakecase-keys.js";
|