@wordpress/edit-site 6.30.1-next.836ecdcae.0 → 6.31.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/CHANGELOG.md +2 -0
- package/build/components/add-new-template/add-custom-template-modal-content.js +1 -1
- package/build/components/add-new-template/add-custom-template-modal-content.js.map +1 -1
- package/build/components/add-new-template/index.js +1 -5
- package/build/components/add-new-template/index.js.map +1 -1
- package/build/components/add-new-template/utils.js +8 -84
- package/build/components/add-new-template/utils.js.map +1 -1
- package/build/components/dataviews-actions/index.js +51 -1
- package/build/components/dataviews-actions/index.js.map +1 -1
- package/build/components/editor/index.js +1 -1
- package/build/components/editor/index.js.map +1 -1
- package/build/components/editor/use-resolve-edited-entity.js +42 -14
- package/build/components/editor/use-resolve-edited-entity.js.map +1 -1
- package/build/components/global-styles/screen-root.js +1 -7
- package/build/components/global-styles/screen-root.js.map +1 -1
- package/build/components/page-templates/fields.js +65 -5
- package/build/components/page-templates/fields.js.map +1 -1
- package/build/components/page-templates/hooks.js +1 -1
- package/build/components/page-templates/hooks.js.map +1 -1
- package/build/components/page-templates/index.js +103 -29
- package/build/components/page-templates/index.js.map +1 -1
- package/build/components/post-list/index.js +1 -4
- package/build/components/post-list/index.js.map +1 -1
- package/build/components/sidebar-navigation-screen-templates-browse/content.js +11 -5
- package/build/components/sidebar-navigation-screen-templates-browse/content.js.map +1 -1
- package/build/components/site-editor-routes/index.js +1 -1
- package/build/components/site-editor-routes/index.js.map +1 -1
- package/build/components/site-editor-routes/template-item.js +29 -23
- package/build/components/site-editor-routes/template-item.js.map +1 -1
- package/build/hooks/commands/use-common-commands.js +3 -118
- package/build/hooks/commands/use-common-commands.js.map +1 -1
- package/build-module/components/add-new-template/add-custom-template-modal-content.js +1 -1
- package/build-module/components/add-new-template/add-custom-template-modal-content.js.map +1 -1
- package/build-module/components/add-new-template/index.js +2 -6
- package/build-module/components/add-new-template/index.js.map +1 -1
- package/build-module/components/add-new-template/utils.js +8 -84
- package/build-module/components/add-new-template/utils.js.map +1 -1
- package/build-module/components/dataviews-actions/index.js +49 -0
- package/build-module/components/dataviews-actions/index.js.map +1 -1
- package/build-module/components/editor/index.js +1 -1
- package/build-module/components/editor/index.js.map +1 -1
- package/build-module/components/editor/use-resolve-edited-entity.js +42 -14
- package/build-module/components/editor/use-resolve-edited-entity.js.map +1 -1
- package/build-module/components/global-styles/screen-root.js +1 -7
- package/build-module/components/global-styles/screen-root.js.map +1 -1
- package/build-module/components/page-templates/fields.js +65 -5
- package/build-module/components/page-templates/fields.js.map +1 -1
- package/build-module/components/page-templates/hooks.js +1 -1
- package/build-module/components/page-templates/hooks.js.map +1 -1
- package/build-module/components/page-templates/index.js +105 -31
- package/build-module/components/page-templates/index.js.map +1 -1
- package/build-module/components/post-list/index.js +1 -4
- package/build-module/components/post-list/index.js.map +1 -1
- package/build-module/components/sidebar-navigation-screen-templates-browse/content.js +11 -5
- package/build-module/components/sidebar-navigation-screen-templates-browse/content.js.map +1 -1
- package/build-module/components/site-editor-routes/index.js +2 -2
- package/build-module/components/site-editor-routes/index.js.map +1 -1
- package/build-module/components/site-editor-routes/template-item.js +28 -22
- package/build-module/components/site-editor-routes/template-item.js.map +1 -1
- package/build-module/hooks/commands/use-common-commands.js +5 -120
- package/build-module/hooks/commands/use-common-commands.js.map +1 -1
- package/build-style/posts-rtl.css +17 -10
- package/build-style/posts.css +17 -10
- package/build-style/style-rtl.css +17 -10
- package/build-style/style.css +17 -10
- package/package.json +41 -41
- package/src/components/add-new-template/add-custom-template-modal-content.js +1 -3
- package/src/components/add-new-template/index.js +1 -8
- package/src/components/add-new-template/utils.js +9 -118
- package/src/components/dataviews-actions/index.js +51 -0
- package/src/components/editor/index.js +1 -0
- package/src/components/editor/use-resolve-edited-entity.js +54 -7
- package/src/components/global-styles/screen-root.js +1 -7
- package/src/components/page-templates/fields.js +70 -4
- package/src/components/page-templates/hooks.js +1 -1
- package/src/components/page-templates/index.js +160 -57
- package/src/components/post-list/index.js +1 -2
- package/src/components/sidebar-navigation-screen-templates-browse/content.js +17 -7
- package/src/components/site-editor-routes/index.js +2 -1
- package/src/components/site-editor-routes/template-item.js +34 -26
- package/src/hooks/commands/use-common-commands.js +6 -135
|
@@ -3,11 +3,16 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { __ } from '@wordpress/i18n';
|
|
5
5
|
import { useState, useMemo, useCallback, useEffect } from '@wordpress/element';
|
|
6
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
privateApis as corePrivateApis,
|
|
8
|
+
store as coreStore,
|
|
9
|
+
} from '@wordpress/core-data';
|
|
7
10
|
import { DataViews, filterSortAndPaginate } from '@wordpress/dataviews';
|
|
8
11
|
import { privateApis as routerPrivateApis } from '@wordpress/router';
|
|
9
12
|
import { privateApis as editorPrivateApis } from '@wordpress/editor';
|
|
10
13
|
import { addQueryArgs } from '@wordpress/url';
|
|
14
|
+
import { useSelect } from '@wordpress/data';
|
|
15
|
+
import { useEvent } from '@wordpress/compose';
|
|
11
16
|
|
|
12
17
|
/**
|
|
13
18
|
* Internal dependencies
|
|
@@ -22,16 +27,22 @@ import {
|
|
|
22
27
|
LAYOUT_LIST,
|
|
23
28
|
} from '../../utils/constants';
|
|
24
29
|
import { unlock } from '../../lock-unlock';
|
|
25
|
-
import {
|
|
26
|
-
|
|
27
|
-
|
|
30
|
+
import {
|
|
31
|
+
useEditPostAction,
|
|
32
|
+
useSetActiveTemplateAction,
|
|
33
|
+
} from '../dataviews-actions';
|
|
34
|
+
import {
|
|
35
|
+
authorField,
|
|
36
|
+
descriptionField,
|
|
37
|
+
previewField,
|
|
38
|
+
activeField,
|
|
39
|
+
slugField,
|
|
40
|
+
} from './fields';
|
|
28
41
|
|
|
29
42
|
const { usePostActions, templateTitleField } = unlock( editorPrivateApis );
|
|
30
43
|
const { useHistory, useLocation } = unlock( routerPrivateApis );
|
|
31
44
|
const { useEntityRecordsWithPermissions } = unlock( corePrivateApis );
|
|
32
45
|
|
|
33
|
-
const EMPTY_ARRAY = [];
|
|
34
|
-
|
|
35
46
|
const defaultLayouts = {
|
|
36
47
|
[ LAYOUT_TABLE ]: {
|
|
37
48
|
showMedia: false,
|
|
@@ -56,31 +67,29 @@ const DEFAULT_VIEW = {
|
|
|
56
67
|
titleField: 'title',
|
|
57
68
|
descriptionField: 'description',
|
|
58
69
|
mediaField: 'preview',
|
|
59
|
-
fields: [ 'author' ],
|
|
70
|
+
fields: [ 'author', 'active', 'slug' ],
|
|
60
71
|
filters: [],
|
|
61
72
|
...defaultLayouts[ LAYOUT_GRID ],
|
|
62
73
|
};
|
|
63
74
|
|
|
64
75
|
export default function PageTemplates() {
|
|
65
76
|
const { path, query } = useLocation();
|
|
66
|
-
const { activeView = '
|
|
77
|
+
const { activeView = 'active', layout, postId } = query;
|
|
67
78
|
const [ selection, setSelection ] = useState( [ postId ] );
|
|
68
|
-
|
|
69
79
|
const defaultView = useMemo( () => {
|
|
70
80
|
const usedType = layout ?? DEFAULT_VIEW.type;
|
|
71
81
|
return {
|
|
72
82
|
...DEFAULT_VIEW,
|
|
73
83
|
type: usedType,
|
|
74
|
-
filters:
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
: [],
|
|
84
|
+
filters: ! [ 'active', 'user' ].includes( activeView )
|
|
85
|
+
? [
|
|
86
|
+
{
|
|
87
|
+
field: 'author',
|
|
88
|
+
operator: 'isAny',
|
|
89
|
+
value: [ activeView ],
|
|
90
|
+
},
|
|
91
|
+
]
|
|
92
|
+
: [],
|
|
84
93
|
...defaultLayouts[ usedType ],
|
|
85
94
|
};
|
|
86
95
|
}, [ layout, activeView ] );
|
|
@@ -98,23 +107,116 @@ export default function PageTemplates() {
|
|
|
98
107
|
useEffect( () => {
|
|
99
108
|
setView( ( currentView ) => ( {
|
|
100
109
|
...currentView,
|
|
101
|
-
filters:
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
: [],
|
|
110
|
+
filters: ! [ 'active', 'user' ].includes( activeView )
|
|
111
|
+
? [
|
|
112
|
+
{
|
|
113
|
+
field: 'author',
|
|
114
|
+
operator: OPERATOR_IS_ANY,
|
|
115
|
+
value: [ activeView ],
|
|
116
|
+
},
|
|
117
|
+
]
|
|
118
|
+
: [],
|
|
111
119
|
} ) );
|
|
112
120
|
}, [ setView, activeView ] );
|
|
113
121
|
|
|
114
|
-
const
|
|
122
|
+
const activeTemplatesOption = useSelect(
|
|
123
|
+
( select ) =>
|
|
124
|
+
select( coreStore ).getEntityRecord( 'root', 'site' )
|
|
125
|
+
?.active_templates
|
|
126
|
+
);
|
|
127
|
+
// Todo: this will have to be better so that we're not fetching all the
|
|
128
|
+
// records all the time. Active templates query will need to move server
|
|
129
|
+
// side.
|
|
130
|
+
const { records: userRecords, isResolving: isLoadingUserRecords } =
|
|
115
131
|
useEntityRecordsWithPermissions( 'postType', TEMPLATE_POST_TYPE, {
|
|
116
132
|
per_page: -1,
|
|
117
133
|
} );
|
|
134
|
+
const { records: staticRecords, isResolving: isLoadingStaticData } =
|
|
135
|
+
useEntityRecordsWithPermissions( 'postType', 'wp_registered_template', {
|
|
136
|
+
per_page: -1,
|
|
137
|
+
} );
|
|
138
|
+
|
|
139
|
+
const activeTemplates = useMemo( () => {
|
|
140
|
+
const _active = [ ...staticRecords ].filter(
|
|
141
|
+
( record ) => ! record.is_custom
|
|
142
|
+
);
|
|
143
|
+
if ( activeTemplatesOption ) {
|
|
144
|
+
for ( const activeSlug in activeTemplatesOption ) {
|
|
145
|
+
const activeId = activeTemplatesOption[ activeSlug ];
|
|
146
|
+
if ( activeId === false ) {
|
|
147
|
+
// Remove the template from the array.
|
|
148
|
+
const index = _active.findIndex(
|
|
149
|
+
( template ) => template.slug === activeSlug
|
|
150
|
+
);
|
|
151
|
+
if ( index !== -1 ) {
|
|
152
|
+
_active.splice( index, 1 );
|
|
153
|
+
}
|
|
154
|
+
} else {
|
|
155
|
+
// Replace the template in the array.
|
|
156
|
+
const template = userRecords.find(
|
|
157
|
+
( { id } ) => id === activeId
|
|
158
|
+
);
|
|
159
|
+
if ( template ) {
|
|
160
|
+
const index = _active.findIndex(
|
|
161
|
+
( { slug } ) => slug === template.slug
|
|
162
|
+
);
|
|
163
|
+
if ( index !== -1 ) {
|
|
164
|
+
_active[ index ] = template;
|
|
165
|
+
} else {
|
|
166
|
+
_active.push( template );
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
return _active;
|
|
173
|
+
}, [ userRecords, staticRecords, activeTemplatesOption ] );
|
|
174
|
+
|
|
175
|
+
let _records;
|
|
176
|
+
let isLoadingData;
|
|
177
|
+
if ( activeView === 'active' ) {
|
|
178
|
+
_records = activeTemplates;
|
|
179
|
+
isLoadingData = isLoadingUserRecords || isLoadingStaticData;
|
|
180
|
+
} else if ( activeView === 'user' ) {
|
|
181
|
+
_records = userRecords;
|
|
182
|
+
isLoadingData = isLoadingUserRecords;
|
|
183
|
+
} else {
|
|
184
|
+
_records = staticRecords;
|
|
185
|
+
isLoadingData = isLoadingStaticData;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
const records = useMemo( () => {
|
|
189
|
+
return _records.map( ( record ) => ( {
|
|
190
|
+
...record,
|
|
191
|
+
_isActive:
|
|
192
|
+
typeof record.id === 'string'
|
|
193
|
+
? activeTemplatesOption[ record.slug ] === record.id ||
|
|
194
|
+
activeTemplatesOption[ record.slug ] === undefined
|
|
195
|
+
: Object.values( activeTemplatesOption ).includes(
|
|
196
|
+
record.id
|
|
197
|
+
),
|
|
198
|
+
} ) );
|
|
199
|
+
}, [ _records, activeTemplatesOption ] );
|
|
200
|
+
|
|
201
|
+
const users = useSelect(
|
|
202
|
+
( select ) => {
|
|
203
|
+
const { getUser } = select( coreStore );
|
|
204
|
+
return records.reduce( ( acc, record ) => {
|
|
205
|
+
if ( record.author_text ) {
|
|
206
|
+
if ( ! acc[ record.author_text ] ) {
|
|
207
|
+
acc[ record.author_text ] = record.author_text;
|
|
208
|
+
}
|
|
209
|
+
} else if ( record.author ) {
|
|
210
|
+
if ( ! acc[ record.author ] ) {
|
|
211
|
+
acc[ record.author ] = getUser( record.author );
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
return acc;
|
|
215
|
+
}, {} );
|
|
216
|
+
},
|
|
217
|
+
[ records ]
|
|
218
|
+
);
|
|
219
|
+
|
|
118
220
|
const history = useHistory();
|
|
119
221
|
const onChangeSelection = useCallback(
|
|
120
222
|
( items ) => {
|
|
@@ -130,32 +232,27 @@ export default function PageTemplates() {
|
|
|
130
232
|
[ history, path, view?.type ]
|
|
131
233
|
);
|
|
132
234
|
|
|
133
|
-
const
|
|
134
|
-
|
|
135
|
-
return EMPTY_ARRAY;
|
|
136
|
-
}
|
|
137
|
-
const authorsSet = new Set();
|
|
138
|
-
records.forEach( ( template ) => {
|
|
139
|
-
authorsSet.add( template.author_text );
|
|
140
|
-
} );
|
|
141
|
-
return Array.from( authorsSet ).map( ( author ) => ( {
|
|
142
|
-
value: author,
|
|
143
|
-
label: author,
|
|
144
|
-
} ) );
|
|
145
|
-
}, [ records ] );
|
|
146
|
-
|
|
147
|
-
const fields = useMemo(
|
|
148
|
-
() => [
|
|
235
|
+
const fields = useMemo( () => {
|
|
236
|
+
const _fields = [
|
|
149
237
|
previewField,
|
|
150
238
|
templateTitleField,
|
|
151
239
|
descriptionField,
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
240
|
+
activeField,
|
|
241
|
+
slugField,
|
|
242
|
+
];
|
|
243
|
+
const elements = [];
|
|
244
|
+
for ( const author in users ) {
|
|
245
|
+
elements.push( {
|
|
246
|
+
value: users[ author ]?.id ?? author,
|
|
247
|
+
label: users[ author ]?.name ?? author,
|
|
248
|
+
} );
|
|
249
|
+
}
|
|
250
|
+
_fields.push( {
|
|
251
|
+
...authorField,
|
|
252
|
+
elements,
|
|
253
|
+
} );
|
|
254
|
+
return _fields;
|
|
255
|
+
}, [ users ] );
|
|
159
256
|
|
|
160
257
|
const { data, paginationInfo } = useMemo( () => {
|
|
161
258
|
return filterSortAndPaginate( records, view, fields );
|
|
@@ -166,9 +263,13 @@ export default function PageTemplates() {
|
|
|
166
263
|
context: 'list',
|
|
167
264
|
} );
|
|
168
265
|
const editAction = useEditPostAction();
|
|
266
|
+
const setActiveTemplateAction = useSetActiveTemplateAction();
|
|
169
267
|
const actions = useMemo(
|
|
170
|
-
() =>
|
|
171
|
-
|
|
268
|
+
() =>
|
|
269
|
+
activeView === 'user'
|
|
270
|
+
? [ setActiveTemplateAction, editAction, ...postTypeActions ]
|
|
271
|
+
: [ setActiveTemplateAction, ...postTypeActions ],
|
|
272
|
+
[ postTypeActions, setActiveTemplateAction, editAction, activeView ]
|
|
172
273
|
);
|
|
173
274
|
|
|
174
275
|
const onChangeView = useEvent( ( newView ) => {
|
|
@@ -199,8 +300,10 @@ export default function PageTemplates() {
|
|
|
199
300
|
onChangeView={ onChangeView }
|
|
200
301
|
onChangeSelection={ onChangeSelection }
|
|
201
302
|
isItemClickable={ () => true }
|
|
202
|
-
onClickItem={ (
|
|
203
|
-
history.navigate(
|
|
303
|
+
onClickItem={ ( item ) => {
|
|
304
|
+
history.navigate(
|
|
305
|
+
`/${ item.type }/${ item.id }?canvas=edit`
|
|
306
|
+
);
|
|
204
307
|
} }
|
|
205
308
|
selection={ selection }
|
|
206
309
|
defaultLayouts={ defaultLayouts }
|
|
@@ -200,7 +200,6 @@ function getItemLevel( item ) {
|
|
|
200
200
|
|
|
201
201
|
export default function PostList( { postType } ) {
|
|
202
202
|
const [ view, setView ] = useView( postType );
|
|
203
|
-
const defaultViews = useDefaultViews( { postType } );
|
|
204
203
|
const history = useHistory();
|
|
205
204
|
const location = useLocation();
|
|
206
205
|
const {
|
|
@@ -266,7 +265,7 @@ export default function PostList( { postType } ) {
|
|
|
266
265
|
search: view.search,
|
|
267
266
|
...filters,
|
|
268
267
|
};
|
|
269
|
-
}, [ view
|
|
268
|
+
}, [ view ] );
|
|
270
269
|
const {
|
|
271
270
|
records,
|
|
272
271
|
isResolving: isLoadingData,
|
|
@@ -14,7 +14,6 @@ import { addQueryArgs } from '@wordpress/url';
|
|
|
14
14
|
import SidebarNavigationItem from '../sidebar-navigation-item';
|
|
15
15
|
import { useAddedBy } from '../page-templates/hooks';
|
|
16
16
|
import { layout } from '@wordpress/icons';
|
|
17
|
-
import { TEMPLATE_POST_TYPE } from '../../utils/constants';
|
|
18
17
|
import { unlock } from '../../lock-unlock';
|
|
19
18
|
|
|
20
19
|
const { useLocation } = unlock( routerPrivateApis );
|
|
@@ -37,11 +36,15 @@ function TemplateDataviewItem( { template, isActive } ) {
|
|
|
37
36
|
|
|
38
37
|
export default function DataviewsTemplatesSidebarContent() {
|
|
39
38
|
const {
|
|
40
|
-
query: { activeView = '
|
|
39
|
+
query: { activeView = 'active' },
|
|
41
40
|
} = useLocation();
|
|
42
|
-
const { records } = useEntityRecords(
|
|
43
|
-
|
|
44
|
-
|
|
41
|
+
const { records } = useEntityRecords(
|
|
42
|
+
'postType',
|
|
43
|
+
'wp_registered_template',
|
|
44
|
+
{
|
|
45
|
+
per_page: -1,
|
|
46
|
+
}
|
|
47
|
+
);
|
|
45
48
|
const firstItemPerAuthorText = useMemo( () => {
|
|
46
49
|
const firstItemPerAuthor = records?.reduce( ( acc, template ) => {
|
|
47
50
|
const author = template.author_text;
|
|
@@ -61,9 +64,16 @@ export default function DataviewsTemplatesSidebarContent() {
|
|
|
61
64
|
<SidebarNavigationItem
|
|
62
65
|
to="/template"
|
|
63
66
|
icon={ layout }
|
|
64
|
-
aria-current={ activeView === '
|
|
67
|
+
aria-current={ activeView === 'active' }
|
|
68
|
+
>
|
|
69
|
+
{ __( 'Active templates' ) }
|
|
70
|
+
</SidebarNavigationItem>
|
|
71
|
+
<SidebarNavigationItem
|
|
72
|
+
to={ addQueryArgs( '/template', { activeView: 'user' } ) }
|
|
73
|
+
icon={ layout }
|
|
74
|
+
aria-current={ activeView === 'user' }
|
|
65
75
|
>
|
|
66
|
-
{ __( '
|
|
76
|
+
{ __( 'Custom templates' ) }
|
|
67
77
|
</SidebarNavigationItem>
|
|
68
78
|
{ firstItemPerAuthorText.map( ( template ) => {
|
|
69
79
|
return (
|
|
@@ -17,7 +17,7 @@ import { patternsRoute } from './patterns';
|
|
|
17
17
|
import { patternItemRoute } from './pattern-item';
|
|
18
18
|
import { templatePartItemRoute } from './template-part-item';
|
|
19
19
|
import { templatesRoute } from './templates';
|
|
20
|
-
import { templateItemRoute } from './template-item';
|
|
20
|
+
import { templateItemRoute, staticTemplateItemRoute } from './template-item';
|
|
21
21
|
import { pagesRoute } from './pages';
|
|
22
22
|
import { pageItemRoute } from './page-item';
|
|
23
23
|
import { stylebookRoute } from './stylebook';
|
|
@@ -27,6 +27,7 @@ const routes = [
|
|
|
27
27
|
pageItemRoute,
|
|
28
28
|
pagesRoute,
|
|
29
29
|
templateItemRoute,
|
|
30
|
+
staticTemplateItemRoute,
|
|
30
31
|
templatesRoute,
|
|
31
32
|
templatePartItemRoute,
|
|
32
33
|
patternItemRoute,
|
|
@@ -5,33 +5,41 @@ import Editor from '../editor';
|
|
|
5
5
|
import SidebarNavigationScreenTemplatesBrowse from '../sidebar-navigation-screen-templates-browse';
|
|
6
6
|
import SidebarNavigationScreenUnsupported from '../sidebar-navigation-screen-unsupported';
|
|
7
7
|
|
|
8
|
+
const areas = {
|
|
9
|
+
sidebar( { siteData } ) {
|
|
10
|
+
const isBlockTheme = siteData.currentTheme?.is_block_theme;
|
|
11
|
+
return isBlockTheme ? (
|
|
12
|
+
<SidebarNavigationScreenTemplatesBrowse backPath="/" />
|
|
13
|
+
) : (
|
|
14
|
+
<SidebarNavigationScreenUnsupported />
|
|
15
|
+
);
|
|
16
|
+
},
|
|
17
|
+
mobile( { siteData } ) {
|
|
18
|
+
const isBlockTheme = siteData.currentTheme?.is_block_theme;
|
|
19
|
+
return isBlockTheme ? (
|
|
20
|
+
<Editor />
|
|
21
|
+
) : (
|
|
22
|
+
<SidebarNavigationScreenUnsupported />
|
|
23
|
+
);
|
|
24
|
+
},
|
|
25
|
+
preview( { siteData } ) {
|
|
26
|
+
const isBlockTheme = siteData.currentTheme?.is_block_theme;
|
|
27
|
+
return isBlockTheme ? (
|
|
28
|
+
<Editor />
|
|
29
|
+
) : (
|
|
30
|
+
<SidebarNavigationScreenUnsupported />
|
|
31
|
+
);
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
|
|
8
35
|
export const templateItemRoute = {
|
|
9
36
|
name: 'template-item',
|
|
10
37
|
path: '/wp_template/*postId',
|
|
11
|
-
areas
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
);
|
|
19
|
-
},
|
|
20
|
-
mobile( { siteData } ) {
|
|
21
|
-
const isBlockTheme = siteData.currentTheme?.is_block_theme;
|
|
22
|
-
return isBlockTheme ? (
|
|
23
|
-
<Editor />
|
|
24
|
-
) : (
|
|
25
|
-
<SidebarNavigationScreenUnsupported />
|
|
26
|
-
);
|
|
27
|
-
},
|
|
28
|
-
preview( { siteData } ) {
|
|
29
|
-
const isBlockTheme = siteData.currentTheme?.is_block_theme;
|
|
30
|
-
return isBlockTheme ? (
|
|
31
|
-
<Editor />
|
|
32
|
-
) : (
|
|
33
|
-
<SidebarNavigationScreenUnsupported />
|
|
34
|
-
);
|
|
35
|
-
},
|
|
36
|
-
},
|
|
38
|
+
areas,
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export const staticTemplateItemRoute = {
|
|
42
|
+
name: 'static-template-item',
|
|
43
|
+
path: '/wp_registered_template/*postId',
|
|
44
|
+
areas,
|
|
37
45
|
};
|
|
@@ -4,16 +4,8 @@
|
|
|
4
4
|
import { useMemo } from '@wordpress/element';
|
|
5
5
|
import { useDispatch, useSelect } from '@wordpress/data';
|
|
6
6
|
import { __, isRTL } from '@wordpress/i18n';
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
rotateRight,
|
|
10
|
-
backup,
|
|
11
|
-
help,
|
|
12
|
-
styles,
|
|
13
|
-
external,
|
|
14
|
-
brush,
|
|
15
|
-
} from '@wordpress/icons';
|
|
16
|
-
import { useCommandLoader, useCommand } from '@wordpress/commands';
|
|
7
|
+
import { rotateLeft, rotateRight, help, backup } from '@wordpress/icons';
|
|
8
|
+
import { useCommandLoader } from '@wordpress/commands';
|
|
17
9
|
import { privateApis as blockEditorPrivateApis } from '@wordpress/block-editor';
|
|
18
10
|
import { privateApis as routerPrivateApis } from '@wordpress/router';
|
|
19
11
|
import { store as preferencesStore } from '@wordpress/preferences';
|
|
@@ -28,45 +20,6 @@ import { store as editSiteStore } from '../../store';
|
|
|
28
20
|
const { useGlobalStylesReset } = unlock( blockEditorPrivateApis );
|
|
29
21
|
const { useHistory, useLocation } = unlock( routerPrivateApis );
|
|
30
22
|
|
|
31
|
-
const getGlobalStylesOpenStylesCommands = () =>
|
|
32
|
-
function useGlobalStylesOpenStylesCommands() {
|
|
33
|
-
const { openGeneralSidebar } = unlock( useDispatch( editSiteStore ) );
|
|
34
|
-
const { params } = useLocation();
|
|
35
|
-
const { canvas = 'view' } = params;
|
|
36
|
-
const history = useHistory();
|
|
37
|
-
const isBlockBasedTheme = useSelect( ( select ) => {
|
|
38
|
-
return select( coreStore ).getCurrentTheme().is_block_theme;
|
|
39
|
-
}, [] );
|
|
40
|
-
|
|
41
|
-
const commands = useMemo( () => {
|
|
42
|
-
if ( ! isBlockBasedTheme ) {
|
|
43
|
-
return [];
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
return [
|
|
47
|
-
{
|
|
48
|
-
name: 'core/edit-site/open-styles',
|
|
49
|
-
label: __( 'Open styles' ),
|
|
50
|
-
callback: ( { close } ) => {
|
|
51
|
-
close();
|
|
52
|
-
if ( canvas !== 'edit' ) {
|
|
53
|
-
history.navigate( '/styles?canvas=edit', {
|
|
54
|
-
transition: 'canvas-mode-edit-transition',
|
|
55
|
-
} );
|
|
56
|
-
}
|
|
57
|
-
openGeneralSidebar( 'edit-site/global-styles' );
|
|
58
|
-
},
|
|
59
|
-
icon: styles,
|
|
60
|
-
},
|
|
61
|
-
];
|
|
62
|
-
}, [ history, openGeneralSidebar, canvas, isBlockBasedTheme ] );
|
|
63
|
-
|
|
64
|
-
return {
|
|
65
|
-
isLoading: false,
|
|
66
|
-
commands,
|
|
67
|
-
};
|
|
68
|
-
};
|
|
69
|
-
|
|
70
23
|
const getGlobalStylesToggleWelcomeGuideCommands = () =>
|
|
71
24
|
function useGlobalStylesToggleWelcomeGuideCommands() {
|
|
72
25
|
const { openGeneralSidebar } = unlock( useDispatch( editSiteStore ) );
|
|
@@ -141,63 +94,6 @@ const getGlobalStylesResetCommands = () =>
|
|
|
141
94
|
};
|
|
142
95
|
};
|
|
143
96
|
|
|
144
|
-
const getGlobalStylesOpenCssCommands = () =>
|
|
145
|
-
function useGlobalStylesOpenCssCommands() {
|
|
146
|
-
const { openGeneralSidebar, setEditorCanvasContainerView } = unlock(
|
|
147
|
-
useDispatch( editSiteStore )
|
|
148
|
-
);
|
|
149
|
-
const { params } = useLocation();
|
|
150
|
-
const { canvas = 'view' } = params;
|
|
151
|
-
const history = useHistory();
|
|
152
|
-
const { canEditCSS } = useSelect( ( select ) => {
|
|
153
|
-
const { getEntityRecord, __experimentalGetCurrentGlobalStylesId } =
|
|
154
|
-
select( coreStore );
|
|
155
|
-
|
|
156
|
-
const globalStylesId = __experimentalGetCurrentGlobalStylesId();
|
|
157
|
-
const globalStyles = globalStylesId
|
|
158
|
-
? getEntityRecord( 'root', 'globalStyles', globalStylesId )
|
|
159
|
-
: undefined;
|
|
160
|
-
|
|
161
|
-
return {
|
|
162
|
-
canEditCSS: !! globalStyles?._links?.[ 'wp:action-edit-css' ],
|
|
163
|
-
};
|
|
164
|
-
}, [] );
|
|
165
|
-
|
|
166
|
-
const commands = useMemo( () => {
|
|
167
|
-
if ( ! canEditCSS ) {
|
|
168
|
-
return [];
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
return [
|
|
172
|
-
{
|
|
173
|
-
name: 'core/edit-site/open-styles-css',
|
|
174
|
-
label: __( 'Customize CSS' ),
|
|
175
|
-
icon: brush,
|
|
176
|
-
callback: ( { close } ) => {
|
|
177
|
-
close();
|
|
178
|
-
if ( canvas !== 'edit' ) {
|
|
179
|
-
history.navigate( '/styles?canvas=edit', {
|
|
180
|
-
transition: 'canvas-mode-edit-transition',
|
|
181
|
-
} );
|
|
182
|
-
}
|
|
183
|
-
openGeneralSidebar( 'edit-site/global-styles' );
|
|
184
|
-
setEditorCanvasContainerView( 'global-styles-css' );
|
|
185
|
-
},
|
|
186
|
-
},
|
|
187
|
-
];
|
|
188
|
-
}, [
|
|
189
|
-
history,
|
|
190
|
-
openGeneralSidebar,
|
|
191
|
-
setEditorCanvasContainerView,
|
|
192
|
-
canEditCSS,
|
|
193
|
-
canvas,
|
|
194
|
-
] );
|
|
195
|
-
return {
|
|
196
|
-
isLoading: false,
|
|
197
|
-
commands,
|
|
198
|
-
};
|
|
199
|
-
};
|
|
200
|
-
|
|
201
97
|
const getGlobalStylesOpenRevisionsCommands = () =>
|
|
202
98
|
function useGlobalStylesOpenRevisionsCommands() {
|
|
203
99
|
const { openGeneralSidebar, setEditorCanvasContainerView } = unlock(
|
|
@@ -213,6 +109,7 @@ const getGlobalStylesOpenRevisionsCommands = () =>
|
|
|
213
109
|
const globalStyles = globalStylesId
|
|
214
110
|
? getEntityRecord( 'root', 'globalStyles', globalStylesId )
|
|
215
111
|
: undefined;
|
|
112
|
+
|
|
216
113
|
return !! globalStyles?._links?.[ 'version-history' ]?.[ 0 ]?.count;
|
|
217
114
|
}, [] );
|
|
218
115
|
|
|
@@ -223,8 +120,8 @@ const getGlobalStylesOpenRevisionsCommands = () =>
|
|
|
223
120
|
|
|
224
121
|
return [
|
|
225
122
|
{
|
|
226
|
-
name: 'core/edit-site/open-
|
|
227
|
-
label: __( '
|
|
123
|
+
name: 'core/edit-site/open-styles-revisions',
|
|
124
|
+
label: __( 'Open style revisions' ),
|
|
228
125
|
icon: backup,
|
|
229
126
|
callback: ( { close } ) => {
|
|
230
127
|
close();
|
|
@@ -241,10 +138,10 @@ const getGlobalStylesOpenRevisionsCommands = () =>
|
|
|
241
138
|
},
|
|
242
139
|
];
|
|
243
140
|
}, [
|
|
244
|
-
hasRevisions,
|
|
245
141
|
history,
|
|
246
142
|
openGeneralSidebar,
|
|
247
143
|
setEditorCanvasContainerView,
|
|
144
|
+
hasRevisions,
|
|
248
145
|
canvas,
|
|
249
146
|
] );
|
|
250
147
|
|
|
@@ -255,27 +152,6 @@ const getGlobalStylesOpenRevisionsCommands = () =>
|
|
|
255
152
|
};
|
|
256
153
|
|
|
257
154
|
export function useCommonCommands() {
|
|
258
|
-
const homeUrl = useSelect( ( select ) => {
|
|
259
|
-
// Site index.
|
|
260
|
-
return select( coreStore ).getEntityRecord( 'root', '__unstableBase' )
|
|
261
|
-
?.home;
|
|
262
|
-
}, [] );
|
|
263
|
-
|
|
264
|
-
useCommand( {
|
|
265
|
-
name: 'core/edit-site/view-site',
|
|
266
|
-
label: __( 'View site' ),
|
|
267
|
-
callback: ( { close } ) => {
|
|
268
|
-
close();
|
|
269
|
-
window.open( homeUrl, '_blank' );
|
|
270
|
-
},
|
|
271
|
-
icon: external,
|
|
272
|
-
} );
|
|
273
|
-
|
|
274
|
-
useCommandLoader( {
|
|
275
|
-
name: 'core/edit-site/open-styles',
|
|
276
|
-
hook: getGlobalStylesOpenStylesCommands(),
|
|
277
|
-
} );
|
|
278
|
-
|
|
279
155
|
useCommandLoader( {
|
|
280
156
|
name: 'core/edit-site/toggle-styles-welcome-guide',
|
|
281
157
|
hook: getGlobalStylesToggleWelcomeGuideCommands(),
|
|
@@ -286,11 +162,6 @@ export function useCommonCommands() {
|
|
|
286
162
|
hook: getGlobalStylesResetCommands(),
|
|
287
163
|
} );
|
|
288
164
|
|
|
289
|
-
useCommandLoader( {
|
|
290
|
-
name: 'core/edit-site/open-styles-css',
|
|
291
|
-
hook: getGlobalStylesOpenCssCommands(),
|
|
292
|
-
} );
|
|
293
|
-
|
|
294
165
|
useCommandLoader( {
|
|
295
166
|
name: 'core/edit-site/open-styles-revisions',
|
|
296
167
|
hook: getGlobalStylesOpenRevisionsCommands(),
|