@etsoo/toolpad 1.0.27 → 1.0.28
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/build/cjs/PageContainer/PageContainer.d.ts +1 -1
- package/build/cjs/PageContainer/PageContainer.js +16 -19
- package/build/mjs/PageContainer/PageContainer.d.ts +1 -1
- package/build/mjs/PageContainer/PageContainer.js +16 -19
- package/package.json +1 -1
- package/src/PageContainer/PageContainer.tsx +18 -20
|
@@ -28,7 +28,7 @@ export type PageData = {
|
|
|
28
28
|
noBreadcrumbs?: boolean;
|
|
29
29
|
noPageHeader?: boolean;
|
|
30
30
|
};
|
|
31
|
-
type PageDataAction = PageData
|
|
31
|
+
type PageDataAction = PageData;
|
|
32
32
|
export declare const PageDataContext: React.Context<{
|
|
33
33
|
state: PageData;
|
|
34
34
|
dispatch: React.Dispatch<PageDataAction>;
|
|
@@ -60,19 +60,18 @@ const PageContentHeader = (0, styles_1.styled)("div")(({ theme }) => ({
|
|
|
60
60
|
}));
|
|
61
61
|
exports.PageDataContext = React.createContext({ state: {}, dispatch: (value) => value });
|
|
62
62
|
function reducer(state, action) {
|
|
63
|
-
if
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
return state;
|
|
71
|
-
}
|
|
72
|
-
else {
|
|
73
|
-
return {};
|
|
63
|
+
// Check if the action is the same as the current state
|
|
64
|
+
let key;
|
|
65
|
+
let isSame = true;
|
|
66
|
+
for (key in action) {
|
|
67
|
+
if (action[key] !== state[key]) {
|
|
68
|
+
isSame = false;
|
|
69
|
+
break;
|
|
74
70
|
}
|
|
75
71
|
}
|
|
72
|
+
if (isSame) {
|
|
73
|
+
return state;
|
|
74
|
+
}
|
|
76
75
|
return { ...state, ...action };
|
|
77
76
|
}
|
|
78
77
|
function PageDataContextProvider(props) {
|
|
@@ -91,17 +90,15 @@ function PageDataContextProvider(props) {
|
|
|
91
90
|
}
|
|
92
91
|
function PageContainerBar(props) {
|
|
93
92
|
const { defaultTitle, slots, slotProps } = props;
|
|
94
|
-
const loaded = React.useRef(false);
|
|
95
93
|
const { state, dispatch } = React.useContext(exports.PageDataContext);
|
|
96
94
|
const activePage = (0, useActivePage_1.useActivePage)();
|
|
97
95
|
React.useLayoutEffect(() => {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
}
|
|
96
|
+
// Reset the state when the active page changes without rerendering
|
|
97
|
+
state.breadcrumbs = undefined;
|
|
98
|
+
state.noBreadcrumbs = undefined;
|
|
99
|
+
state.noPageHeader = undefined;
|
|
100
|
+
state.page = undefined;
|
|
101
|
+
state.title = undefined;
|
|
105
102
|
}, [activePage?.sourcePath]);
|
|
106
103
|
let resolvedBreadcrumbs = state.breadcrumbs ?? activePage?.breadcrumbs ?? [];
|
|
107
104
|
const title = state.title ?? defaultTitle ?? activePage?.title ?? "";
|
|
@@ -28,7 +28,7 @@ export type PageData = {
|
|
|
28
28
|
noBreadcrumbs?: boolean;
|
|
29
29
|
noPageHeader?: boolean;
|
|
30
30
|
};
|
|
31
|
-
type PageDataAction = PageData
|
|
31
|
+
type PageDataAction = PageData;
|
|
32
32
|
export declare const PageDataContext: React.Context<{
|
|
33
33
|
state: PageData;
|
|
34
34
|
dispatch: React.Dispatch<PageDataAction>;
|
|
@@ -19,19 +19,18 @@ const PageContentHeader = styled("div")(({ theme }) => ({
|
|
|
19
19
|
}));
|
|
20
20
|
export const PageDataContext = React.createContext({ state: {}, dispatch: (value) => value });
|
|
21
21
|
function reducer(state, action) {
|
|
22
|
-
if
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
return state;
|
|
30
|
-
}
|
|
31
|
-
else {
|
|
32
|
-
return {};
|
|
22
|
+
// Check if the action is the same as the current state
|
|
23
|
+
let key;
|
|
24
|
+
let isSame = true;
|
|
25
|
+
for (key in action) {
|
|
26
|
+
if (action[key] !== state[key]) {
|
|
27
|
+
isSame = false;
|
|
28
|
+
break;
|
|
33
29
|
}
|
|
34
30
|
}
|
|
31
|
+
if (isSame) {
|
|
32
|
+
return state;
|
|
33
|
+
}
|
|
35
34
|
return { ...state, ...action };
|
|
36
35
|
}
|
|
37
36
|
export function PageDataContextProvider(props) {
|
|
@@ -50,17 +49,15 @@ export function PageDataContextProvider(props) {
|
|
|
50
49
|
}
|
|
51
50
|
function PageContainerBar(props) {
|
|
52
51
|
const { defaultTitle, slots, slotProps } = props;
|
|
53
|
-
const loaded = React.useRef(false);
|
|
54
52
|
const { state, dispatch } = React.useContext(PageDataContext);
|
|
55
53
|
const activePage = useActivePage();
|
|
56
54
|
React.useLayoutEffect(() => {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
}
|
|
55
|
+
// Reset the state when the active page changes without rerendering
|
|
56
|
+
state.breadcrumbs = undefined;
|
|
57
|
+
state.noBreadcrumbs = undefined;
|
|
58
|
+
state.noPageHeader = undefined;
|
|
59
|
+
state.page = undefined;
|
|
60
|
+
state.title = undefined;
|
|
64
61
|
}, [activePage?.sourcePath]);
|
|
65
62
|
let resolvedBreadcrumbs = state.breadcrumbs ?? activePage?.breadcrumbs ?? [];
|
|
66
63
|
const title = state.title ?? defaultTitle ?? activePage?.title ?? "";
|
package/package.json
CHANGED
|
@@ -52,7 +52,7 @@ export type PageData = {
|
|
|
52
52
|
noPageHeader?: boolean;
|
|
53
53
|
};
|
|
54
54
|
|
|
55
|
-
type PageDataAction = PageData
|
|
55
|
+
type PageDataAction = PageData;
|
|
56
56
|
|
|
57
57
|
export const PageDataContext = React.createContext<{
|
|
58
58
|
state: PageData;
|
|
@@ -60,21 +60,20 @@ export const PageDataContext = React.createContext<{
|
|
|
60
60
|
}>({ state: {}, dispatch: (value) => value });
|
|
61
61
|
|
|
62
62
|
function reducer(state: PageData, action: PageDataAction) {
|
|
63
|
-
if
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
state.noPageHeader == null
|
|
71
|
-
) {
|
|
72
|
-
return state;
|
|
73
|
-
} else {
|
|
74
|
-
return {};
|
|
63
|
+
// Check if the action is the same as the current state
|
|
64
|
+
let key: keyof PageDataAction;
|
|
65
|
+
let isSame = true;
|
|
66
|
+
for (key in action) {
|
|
67
|
+
if (action[key] !== state[key]) {
|
|
68
|
+
isSame = false;
|
|
69
|
+
break;
|
|
75
70
|
}
|
|
76
71
|
}
|
|
77
72
|
|
|
73
|
+
if (isSame) {
|
|
74
|
+
return state;
|
|
75
|
+
}
|
|
76
|
+
|
|
78
77
|
return { ...state, ...action };
|
|
79
78
|
}
|
|
80
79
|
|
|
@@ -116,18 +115,17 @@ type PageContainerBarProps = {
|
|
|
116
115
|
function PageContainerBar(props: PageContainerBarProps) {
|
|
117
116
|
const { defaultTitle, slots, slotProps } = props;
|
|
118
117
|
|
|
119
|
-
const loaded = React.useRef(false);
|
|
120
118
|
const { state, dispatch } = React.useContext(PageDataContext);
|
|
121
119
|
|
|
122
120
|
const activePage = useActivePage();
|
|
123
121
|
|
|
124
122
|
React.useLayoutEffect(() => {
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
123
|
+
// Reset the state when the active page changes without rerendering
|
|
124
|
+
state.breadcrumbs = undefined;
|
|
125
|
+
state.noBreadcrumbs = undefined;
|
|
126
|
+
state.noPageHeader = undefined;
|
|
127
|
+
state.page = undefined;
|
|
128
|
+
state.title = undefined;
|
|
131
129
|
}, [activePage?.sourcePath]);
|
|
132
130
|
|
|
133
131
|
let resolvedBreadcrumbs = state.breadcrumbs ?? activePage?.breadcrumbs ?? [];
|