@etsoo/toolpad 1.0.34 → 1.0.36
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.
|
@@ -58,18 +58,13 @@ const PageContentHeader = (0, styles_1.styled)("div")(({ theme }) => ({
|
|
|
58
58
|
justifyContent: "space-between",
|
|
59
59
|
gap: theme.spacing(2)
|
|
60
60
|
}));
|
|
61
|
+
function jsonSerialize(obj) {
|
|
62
|
+
return JSON.stringify(obj, (_key, value) => value == null ? undefined : value);
|
|
63
|
+
}
|
|
61
64
|
exports.PageDataContext = React.createContext({ state: {}, dispatch: (value) => value });
|
|
62
65
|
function reducer(state, action) {
|
|
63
66
|
// Check if the action is the same as the current state
|
|
64
|
-
|
|
65
|
-
let isSame = true;
|
|
66
|
-
for (key in action) {
|
|
67
|
-
if (action[key] != state[key]) {
|
|
68
|
-
isSame = false;
|
|
69
|
-
break;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
if (isSame) {
|
|
67
|
+
if (jsonSerialize(state) === jsonSerialize(action)) {
|
|
73
68
|
return state;
|
|
74
69
|
}
|
|
75
70
|
return { ...state, ...action };
|
|
@@ -89,16 +84,8 @@ function PageDataContextProvider(props) {
|
|
|
89
84
|
}
|
|
90
85
|
function PageContainerBar(props) {
|
|
91
86
|
const { slots, slotProps, titleBar } = props;
|
|
92
|
-
const { state
|
|
87
|
+
const { state } = React.useContext(exports.PageDataContext);
|
|
93
88
|
const activePage = (0, useActivePage_1.useActivePage)();
|
|
94
|
-
React.useEffect(() => {
|
|
95
|
-
return () => {
|
|
96
|
-
// Reset the state when the component unmounts
|
|
97
|
-
dispatch({});
|
|
98
|
-
console.log("PageContainerBar unmounted", activePage?.sourcePath);
|
|
99
|
-
};
|
|
100
|
-
}, [activePage?.sourcePath]);
|
|
101
|
-
console.log("PageContainerBar", activePage?.sourcePath, state);
|
|
102
89
|
const ToolbarComponent = slots?.toolbar ?? PageContainerToolbar_1.PageContainerToolbar;
|
|
103
90
|
const toolbarSlotProps = (0, useSlotProps_1.default)({
|
|
104
91
|
elementType: ToolbarComponent,
|
|
@@ -109,7 +96,6 @@ function PageContainerBar(props) {
|
|
|
109
96
|
const breadcrumbs = [...(state.breadcrumbs ?? activePage?.breadcrumbs ?? [])];
|
|
110
97
|
const title = state.title ?? activePage?.title ?? "";
|
|
111
98
|
const pageHeader = state.pageHeader ?? activePage?.pageHeader ?? null;
|
|
112
|
-
console.log("PageContainerBar", activePage?.sourcePath, title, breadcrumbs);
|
|
113
99
|
// No page header
|
|
114
100
|
if (pageHeader === false)
|
|
115
101
|
return undefined;
|
|
@@ -17,18 +17,13 @@ const PageContentHeader = styled("div")(({ theme }) => ({
|
|
|
17
17
|
justifyContent: "space-between",
|
|
18
18
|
gap: theme.spacing(2)
|
|
19
19
|
}));
|
|
20
|
+
function jsonSerialize(obj) {
|
|
21
|
+
return JSON.stringify(obj, (_key, value) => value == null ? undefined : value);
|
|
22
|
+
}
|
|
20
23
|
export const PageDataContext = React.createContext({ state: {}, dispatch: (value) => value });
|
|
21
24
|
function reducer(state, action) {
|
|
22
25
|
// Check if the action is the same as the current state
|
|
23
|
-
|
|
24
|
-
let isSame = true;
|
|
25
|
-
for (key in action) {
|
|
26
|
-
if (action[key] != state[key]) {
|
|
27
|
-
isSame = false;
|
|
28
|
-
break;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
if (isSame) {
|
|
26
|
+
if (jsonSerialize(state) === jsonSerialize(action)) {
|
|
32
27
|
return state;
|
|
33
28
|
}
|
|
34
29
|
return { ...state, ...action };
|
|
@@ -48,16 +43,8 @@ export function PageDataContextProvider(props) {
|
|
|
48
43
|
}
|
|
49
44
|
function PageContainerBar(props) {
|
|
50
45
|
const { slots, slotProps, titleBar } = props;
|
|
51
|
-
const { state
|
|
46
|
+
const { state } = React.useContext(PageDataContext);
|
|
52
47
|
const activePage = useActivePage();
|
|
53
|
-
React.useEffect(() => {
|
|
54
|
-
return () => {
|
|
55
|
-
// Reset the state when the component unmounts
|
|
56
|
-
dispatch({});
|
|
57
|
-
console.log("PageContainerBar unmounted", activePage?.sourcePath);
|
|
58
|
-
};
|
|
59
|
-
}, [activePage?.sourcePath]);
|
|
60
|
-
console.log("PageContainerBar", activePage?.sourcePath, state);
|
|
61
48
|
const ToolbarComponent = slots?.toolbar ?? PageContainerToolbar;
|
|
62
49
|
const toolbarSlotProps = useSlotProps({
|
|
63
50
|
elementType: ToolbarComponent,
|
|
@@ -68,7 +55,6 @@ function PageContainerBar(props) {
|
|
|
68
55
|
const breadcrumbs = [...(state.breadcrumbs ?? activePage?.breadcrumbs ?? [])];
|
|
69
56
|
const title = state.title ?? activePage?.title ?? "";
|
|
70
57
|
const pageHeader = state.pageHeader ?? activePage?.pageHeader ?? null;
|
|
71
|
-
console.log("PageContainerBar", activePage?.sourcePath, title, breadcrumbs);
|
|
72
58
|
// No page header
|
|
73
59
|
if (pageHeader === false)
|
|
74
60
|
return undefined;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@etsoo/toolpad",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.36",
|
|
4
4
|
"author": "ETSOO",
|
|
5
5
|
"description": "Dashboard framework extention based on Toolpad Core",
|
|
6
6
|
"main": "build/cjs/index.js",
|
|
@@ -63,7 +63,7 @@
|
|
|
63
63
|
"@testing-library/jest-dom": "^6.6.3",
|
|
64
64
|
"@testing-library/react": "^16.3.0",
|
|
65
65
|
"@types/invariant": "2.2.37",
|
|
66
|
-
"@types/node": "^22.15.
|
|
66
|
+
"@types/node": "^22.15.8",
|
|
67
67
|
"@types/react": "19.1.2",
|
|
68
68
|
"@types/react-dom": "19.1.3",
|
|
69
69
|
"@vitejs/plugin-react": "4.4.1",
|
|
@@ -53,6 +53,12 @@ export type PageData = {
|
|
|
53
53
|
|
|
54
54
|
type PageDataAction = PageData;
|
|
55
55
|
|
|
56
|
+
function jsonSerialize(obj: unknown) {
|
|
57
|
+
return JSON.stringify(obj, (_key, value) =>
|
|
58
|
+
value == null ? undefined : value
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
|
|
56
62
|
export const PageDataContext = React.createContext<{
|
|
57
63
|
state: PageData;
|
|
58
64
|
dispatch: React.Dispatch<PageDataAction>;
|
|
@@ -60,16 +66,7 @@ export const PageDataContext = React.createContext<{
|
|
|
60
66
|
|
|
61
67
|
function reducer(state: PageData, action: PageDataAction) {
|
|
62
68
|
// Check if the action is the same as the current state
|
|
63
|
-
|
|
64
|
-
let isSame = true;
|
|
65
|
-
for (key in action) {
|
|
66
|
-
if (action[key] != state[key]) {
|
|
67
|
-
isSame = false;
|
|
68
|
-
break;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
if (isSame) {
|
|
69
|
+
if (jsonSerialize(state) === jsonSerialize(action)) {
|
|
73
70
|
return state;
|
|
74
71
|
}
|
|
75
72
|
|
|
@@ -114,20 +111,10 @@ type PageContainerBarProps = {
|
|
|
114
111
|
function PageContainerBar(props: PageContainerBarProps) {
|
|
115
112
|
const { slots, slotProps, titleBar } = props;
|
|
116
113
|
|
|
117
|
-
const { state
|
|
114
|
+
const { state } = React.useContext(PageDataContext);
|
|
118
115
|
|
|
119
116
|
const activePage = useActivePage();
|
|
120
117
|
|
|
121
|
-
React.useEffect(() => {
|
|
122
|
-
return () => {
|
|
123
|
-
// Reset the state when the component unmounts
|
|
124
|
-
dispatch({});
|
|
125
|
-
console.log("PageContainerBar unmounted", activePage?.sourcePath);
|
|
126
|
-
};
|
|
127
|
-
}, [activePage?.sourcePath]);
|
|
128
|
-
|
|
129
|
-
console.log("PageContainerBar", activePage?.sourcePath, state);
|
|
130
|
-
|
|
131
118
|
const ToolbarComponent = slots?.toolbar ?? PageContainerToolbar;
|
|
132
119
|
const toolbarSlotProps = useSlotProps({
|
|
133
120
|
elementType: ToolbarComponent,
|
|
@@ -140,8 +127,6 @@ function PageContainerBar(props: PageContainerBarProps) {
|
|
|
140
127
|
const title = state.title ?? activePage?.title ?? "";
|
|
141
128
|
const pageHeader = state.pageHeader ?? activePage?.pageHeader ?? null;
|
|
142
129
|
|
|
143
|
-
console.log("PageContainerBar", activePage?.sourcePath, title, breadcrumbs);
|
|
144
|
-
|
|
145
130
|
// No page header
|
|
146
131
|
if (pageHeader === false) return undefined;
|
|
147
132
|
|