-
Notifications
You must be signed in to change notification settings - Fork 4.3k
/
Copy pathindex.js
122 lines (113 loc) · 4.01 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/**
* External dependencies
*/
import classNames from 'classnames';
/**
* WordPress dependencies
*/
import { memo, useRef } from '@wordpress/element';
import {
__experimentalNavigatorProvider as NavigatorProvider,
__experimentalNavigatorScreen as NavigatorScreen,
} from '@wordpress/components';
import { privateApis as routerPrivateApis } from '@wordpress/router';
import { useViewportMatch } from '@wordpress/compose';
import { __ } from '@wordpress/i18n';
/**
* Internal dependencies
*/
import SidebarNavigationScreenMain from '../sidebar-navigation-screen-main';
import SidebarNavigationScreenTemplates from '../sidebar-navigation-screen-templates';
import SidebarNavigationScreenTemplate from '../sidebar-navigation-screen-template';
import SidebarNavigationScreenPatterns from '../sidebar-navigation-screen-patterns';
import SidebarNavigationScreenPattern from '../sidebar-navigation-screen-pattern';
import useSyncPathWithURL, {
getPathFromURL,
} from '../sync-state-with-url/use-sync-path-with-url';
import SidebarNavigationScreenNavigationMenus from '../sidebar-navigation-screen-navigation-menus';
import SidebarNavigationScreenNavigationMenu from '../sidebar-navigation-screen-navigation-menu';
import SidebarNavigationScreenGlobalStyles from '../sidebar-navigation-screen-global-styles';
import SidebarNavigationScreenTemplatesBrowse from '../sidebar-navigation-screen-templates-browse';
import SaveHub from '../save-hub';
import { unlock } from '../../lock-unlock';
import SidebarNavigationScreenPages from '../sidebar-navigation-screen-pages';
import SidebarNavigationScreen from '../sidebar-navigation-screen';
import DataViewsSidebarContent from '../sidebar-dataviews';
import SidebarNavigationScreenPage from '../sidebar-navigation-screen-page';
const { useLocation } = unlock( routerPrivateApis );
function SidebarScreenWrapper( { className, ...props } ) {
return (
<NavigatorScreen
className={ classNames(
'edit-site-sidebar__screen-wrapper',
className
) }
{ ...props }
/>
);
}
function SidebarScreens() {
useSyncPathWithURL();
const isMobileViewport = useViewportMatch( 'medium', '<' );
return (
<>
<SidebarScreenWrapper path="/">
<SidebarNavigationScreenMain />
</SidebarScreenWrapper>
<SidebarScreenWrapper path="/navigation">
<SidebarNavigationScreenNavigationMenus />
</SidebarScreenWrapper>
<SidebarScreenWrapper path="/navigation/:postType/:postId">
<SidebarNavigationScreenNavigationMenu />
</SidebarScreenWrapper>
<SidebarScreenWrapper path="/wp_global_styles">
<SidebarNavigationScreenGlobalStyles />
</SidebarScreenWrapper>
<SidebarScreenWrapper path="/page">
<SidebarNavigationScreenPages />
</SidebarScreenWrapper>
<SidebarScreenWrapper path="/pages">
<SidebarNavigationScreen
title={ __( 'Pages' ) }
content={ <DataViewsSidebarContent /> }
/>
</SidebarScreenWrapper>
<SidebarScreenWrapper path="/page/:postId">
<SidebarNavigationScreenPage />
</SidebarScreenWrapper>
<SidebarScreenWrapper path="/:postType(wp_template)">
<SidebarNavigationScreenTemplates />
</SidebarScreenWrapper>
{ ! isMobileViewport && (
<SidebarScreenWrapper path="/patterns">
<SidebarNavigationScreenPatterns />
</SidebarScreenWrapper>
) }
<SidebarScreenWrapper path="/:postType(wp_template|wp_template_part)/all">
<SidebarNavigationScreenTemplatesBrowse />
</SidebarScreenWrapper>
<SidebarScreenWrapper path="/:postType(wp_template_part|wp_block)/:postId">
<SidebarNavigationScreenPattern />
</SidebarScreenWrapper>
<SidebarScreenWrapper path="/:postType(wp_template)/:postId">
<SidebarNavigationScreenTemplate />
</SidebarScreenWrapper>
</>
);
}
function Sidebar() {
const { params: urlParams } = useLocation();
const initialPath = useRef( getPathFromURL( urlParams ) );
return (
<>
<NavigatorProvider
className="edit-site-sidebar__content"
initialPath={ initialPath.current }
>
<SidebarScreens />
</NavigatorProvider>
<SaveHub />
</>
);
}
export default memo( Sidebar );