@bigbinary/neeto-commons-frontend 4.1.4 → 4.3.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/cjs/react-utils/AppContainer/AppContainer.js +53 -0
- package/cjs/react-utils/AppContainer/AppContainer.js.map +1 -0
- package/cjs/react-utils/AppContainer/index.js +14 -0
- package/cjs/react-utils/AppContainer/index.js.map +1 -0
- package/cjs/react-utils/QueryClientProvider/QueryClientProvider.js +21 -0
- package/cjs/react-utils/QueryClientProvider/QueryClientProvider.js.map +1 -0
- package/cjs/react-utils/QueryClientProvider/index.js +21 -0
- package/cjs/react-utils/QueryClientProvider/index.js.map +1 -0
- package/cjs/react-utils/QueryClientProvider/queryClient.js +23 -0
- package/cjs/react-utils/QueryClientProvider/queryClient.js.map +1 -0
- package/cjs/react-utils/index.js +47 -1
- package/cjs/react-utils/index.js.map +1 -1
- package/cjs/react-utils/useRestoreScrollPosition/index.js +28 -0
- package/cjs/react-utils/useRestoreScrollPosition/index.js.map +1 -0
- package/cjs/react-utils/useRestoreScrollPosition/useRestoreScrollPosition.js +72 -0
- package/cjs/react-utils/useRestoreScrollPosition/useRestoreScrollPosition.js.map +1 -0
- package/package.json +3 -1
- package/react-utils/AppContainer/AppContainer.js +43 -0
- package/react-utils/AppContainer/AppContainer.js.map +1 -0
- package/react-utils/AppContainer/index.js +1 -0
- package/react-utils/AppContainer/index.js.map +1 -0
- package/react-utils/QueryClientProvider/QueryClientProvider.js +13 -0
- package/react-utils/QueryClientProvider/QueryClientProvider.js.map +1 -0
- package/react-utils/QueryClientProvider/index.js +3 -0
- package/react-utils/QueryClientProvider/index.js.map +1 -0
- package/react-utils/QueryClientProvider/queryClient.js +16 -0
- package/react-utils/QueryClientProvider/queryClient.js.map +1 -0
- package/react-utils/index.js +5 -0
- package/react-utils/index.js.map +1 -1
- package/react-utils/useRestoreScrollPosition/index.js +3 -0
- package/react-utils/useRestoreScrollPosition/index.js.map +1 -0
- package/react-utils/useRestoreScrollPosition/useRestoreScrollPosition.js +62 -0
- package/react-utils/useRestoreScrollPosition/useRestoreScrollPosition.js.map +1 -0
- package/react-utils.d.ts +180 -1602
- package/utils.d.ts +95 -570
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["default"],"sources":["../../../src/react-utils/useRestoreScrollPosition/index.js"],"sourcesContent":["export { default } from \"./useRestoreScrollPosition\";\nexport * from \"./useRestoreScrollPosition\";\n"],"mappings":"AAAA,SAASA,OAAO;AAChB"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { useEffect } from "react";
|
|
2
|
+
import { assoc, dissoc, prop } from "ramda";
|
|
3
|
+
import useFuncDebounce from "../useFuncDebounce";
|
|
4
|
+
import withImmutableActions from "../withImmutableActions";
|
|
5
|
+
import { create } from "zustand";
|
|
6
|
+
|
|
7
|
+
/** @type {import("neetocommons/react-utils").ZustandStoreHook} */
|
|
8
|
+
var useScrollStore = create(withImmutableActions(function (set, get) {
|
|
9
|
+
return {
|
|
10
|
+
scrollPositions: {},
|
|
11
|
+
setScrollPosition: function setScrollPosition(key, value) {
|
|
12
|
+
return set(function (state) {
|
|
13
|
+
return {
|
|
14
|
+
scrollPositions: assoc(key, value, state.scrollPositions)
|
|
15
|
+
};
|
|
16
|
+
});
|
|
17
|
+
},
|
|
18
|
+
removeScrollPosition: function removeScrollPosition(key) {
|
|
19
|
+
return set(function (state) {
|
|
20
|
+
return {
|
|
21
|
+
scrollPositions: dissoc(key, state.scrollPositions)
|
|
22
|
+
};
|
|
23
|
+
});
|
|
24
|
+
},
|
|
25
|
+
getScrollPosition: function getScrollPosition(key) {
|
|
26
|
+
return get().scrollPositions[key];
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
}));
|
|
30
|
+
var useRestoreScrollPosition = function useRestoreScrollPosition(key, ref) {
|
|
31
|
+
var setScrollPosition = useScrollStore(prop("setScrollPosition"));
|
|
32
|
+
var getScrollPosition = useScrollStore(prop("getScrollPosition"));
|
|
33
|
+
var handleScroll = useFuncDebounce(function () {
|
|
34
|
+
if (!ref.current) return;
|
|
35
|
+
setScrollPosition(key, ref.current.scrollTop);
|
|
36
|
+
}, 500);
|
|
37
|
+
useEffect(function () {
|
|
38
|
+
if (ref.current) {
|
|
39
|
+
var savedScrollPosition = getScrollPosition(key);
|
|
40
|
+
if (savedScrollPosition !== undefined) {
|
|
41
|
+
ref.current.scrollTop = savedScrollPosition;
|
|
42
|
+
}
|
|
43
|
+
ref.current.addEventListener("scroll", handleScroll);
|
|
44
|
+
}
|
|
45
|
+
return function () {
|
|
46
|
+
if (ref.current) {
|
|
47
|
+
ref.current.removeEventListener("scroll", handleScroll);
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
}, [key]);
|
|
51
|
+
};
|
|
52
|
+
export var useSetScrollPosition = function useSetScrollPosition() {
|
|
53
|
+
return useScrollStore(prop("setScrollPosition"));
|
|
54
|
+
};
|
|
55
|
+
export var useGetScrollPosition = function useGetScrollPosition() {
|
|
56
|
+
return useScrollStore(prop("getScrollPosition"));
|
|
57
|
+
};
|
|
58
|
+
export var useRemoveScrollPosition = function useRemoveScrollPosition() {
|
|
59
|
+
return useScrollStore(prop("removeScrollPosition"));
|
|
60
|
+
};
|
|
61
|
+
export default useRestoreScrollPosition;
|
|
62
|
+
//# sourceMappingURL=useRestoreScrollPosition.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useRestoreScrollPosition.js","names":["useEffect","assoc","dissoc","prop","useFuncDebounce","withImmutableActions","create","useScrollStore","set","get","scrollPositions","setScrollPosition","key","value","state","removeScrollPosition","getScrollPosition","useRestoreScrollPosition","ref","handleScroll","current","scrollTop","savedScrollPosition","undefined","addEventListener","removeEventListener","useSetScrollPosition","useGetScrollPosition","useRemoveScrollPosition"],"sources":["../../../src/react-utils/useRestoreScrollPosition/useRestoreScrollPosition.js"],"sourcesContent":["import { useEffect } from \"react\";\n\nimport { assoc, dissoc, prop } from \"ramda\";\nimport useFuncDebounce from \"react-utils/useFuncDebounce\";\nimport withImmutableActions from \"react-utils/withImmutableActions\";\nimport { create } from \"zustand\";\n\n/** @type {import(\"neetocommons/react-utils\").ZustandStoreHook} */\nconst useScrollStore = create(\n withImmutableActions((set, get) => ({\n scrollPositions: {},\n setScrollPosition: (key, value) =>\n set(state => ({\n scrollPositions: assoc(key, value, state.scrollPositions),\n })),\n removeScrollPosition: key =>\n set(state => ({ scrollPositions: dissoc(key, state.scrollPositions) })),\n getScrollPosition: key => get().scrollPositions[key],\n }))\n);\n\nconst useRestoreScrollPosition = (key, ref) => {\n const setScrollPosition = useScrollStore(prop(\"setScrollPosition\"));\n const getScrollPosition = useScrollStore(prop(\"getScrollPosition\"));\n\n const handleScroll = useFuncDebounce(() => {\n if (!ref.current) return;\n setScrollPosition(key, ref.current.scrollTop);\n }, 500);\n\n useEffect(() => {\n if (ref.current) {\n const savedScrollPosition = getScrollPosition(key);\n if (savedScrollPosition !== undefined) {\n ref.current.scrollTop = savedScrollPosition;\n }\n ref.current.addEventListener(\"scroll\", handleScroll);\n }\n\n return () => {\n if (ref.current) {\n ref.current.removeEventListener(\"scroll\", handleScroll);\n }\n };\n }, [key]);\n};\n\nexport const useSetScrollPosition = () =>\n useScrollStore(prop(\"setScrollPosition\"));\n\nexport const useGetScrollPosition = () =>\n useScrollStore(prop(\"getScrollPosition\"));\n\nexport const useRemoveScrollPosition = () =>\n useScrollStore(prop(\"removeScrollPosition\"));\n\nexport default useRestoreScrollPosition;\n"],"mappings":"AAAA,SAASA,SAAS,QAAQ,OAAO;AAEjC,SAASC,KAAK,EAAEC,MAAM,EAAEC,IAAI,QAAQ,OAAO;AAC3C,OAAOC,eAAe;AACtB,OAAOC,oBAAoB;AAC3B,SAASC,MAAM,QAAQ,SAAS;;AAEhC;AACA,IAAMC,cAAc,GAAGD,MAAM,CAC3BD,oBAAoB,CAAC,UAACG,GAAG,EAAEC,GAAG;EAAA,OAAM;IAClCC,eA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