@wordpress/edit-site 6.35.2-next.dc3f6d3c1.0 → 6.36.1-next.6deb34194.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 +1 -1
- package/build/components/add-new-template-legacy/add-custom-generic-template-modal-content.js +109 -0
- package/build/components/add-new-template-legacy/add-custom-generic-template-modal-content.js.map +7 -0
- package/build/components/add-new-template-legacy/add-custom-template-modal-content.js +328 -0
- package/build/components/add-new-template-legacy/add-custom-template-modal-content.js.map +7 -0
- package/build/components/add-new-template-legacy/index.js +389 -0
- package/build/components/add-new-template-legacy/index.js.map +7 -0
- package/build/components/add-new-template-legacy/utils.js +620 -0
- package/build/components/add-new-template-legacy/utils.js.map +7 -0
- package/build/components/block-editor/use-site-editor-settings.js +3 -3
- package/build/components/block-editor/use-site-editor-settings.js.map +2 -2
- package/build/components/page-templates/fields.js +3 -1
- package/build/components/page-templates/fields.js.map +2 -2
- package/build/components/page-templates/index-legacy.js +185 -0
- package/build/components/page-templates/index-legacy.js.map +7 -0
- package/build/components/post-list/index.js +27 -4
- package/build/components/post-list/index.js.map +3 -3
- package/build/components/post-list/use-notes-count.js +56 -0
- package/build/components/post-list/use-notes-count.js.map +7 -0
- package/build/components/sidebar-navigation-screen-patterns/use-template-part-areas.js +2 -1
- package/build/components/sidebar-navigation-screen-patterns/use-template-part-areas.js.map +2 -2
- package/build/components/sidebar-navigation-screen-templates-browse/content-legacy.js +101 -0
- package/build/components/sidebar-navigation-screen-templates-browse/content-legacy.js.map +7 -0
- package/build/components/sidebar-navigation-screen-templates-browse/index.js +2 -1
- package/build/components/sidebar-navigation-screen-templates-browse/index.js.map +3 -3
- package/build/components/site-editor-routes/templates.js +10 -2
- package/build/components/site-editor-routes/templates.js.map +3 -3
- package/build/components/site-hub/index.js +1 -1
- package/build/components/site-hub/index.js.map +2 -2
- package/build/utils/constants.js +6 -0
- package/build/utils/constants.js.map +2 -2
- package/build-module/components/add-new-template-legacy/add-custom-generic-template-modal-content.js +93 -0
- package/build-module/components/add-new-template-legacy/add-custom-generic-template-modal-content.js.map +7 -0
- package/build-module/components/add-new-template-legacy/add-custom-template-modal-content.js +316 -0
- package/build-module/components/add-new-template-legacy/add-custom-template-modal-content.js.map +7 -0
- package/build-module/components/add-new-template-legacy/index.js +390 -0
- package/build-module/components/add-new-template-legacy/index.js.map +7 -0
- package/build-module/components/add-new-template-legacy/utils.js +589 -0
- package/build-module/components/add-new-template-legacy/utils.js.map +7 -0
- package/build-module/components/block-editor/use-site-editor-settings.js +3 -3
- package/build-module/components/block-editor/use-site-editor-settings.js.map +2 -2
- package/build-module/components/page-templates/fields.js +3 -1
- package/build-module/components/page-templates/fields.js.map +2 -2
- package/build-module/components/page-templates/index-legacy.js +154 -0
- package/build-module/components/page-templates/index-legacy.js.map +7 -0
- package/build-module/components/post-list/index.js +29 -4
- package/build-module/components/post-list/index.js.map +2 -2
- package/build-module/components/post-list/use-notes-count.js +35 -0
- package/build-module/components/post-list/use-notes-count.js.map +7 -0
- package/build-module/components/sidebar-navigation-screen-patterns/use-template-part-areas.js +2 -1
- package/build-module/components/sidebar-navigation-screen-patterns/use-template-part-areas.js.map +2 -2
- package/build-module/components/sidebar-navigation-screen-templates-browse/content-legacy.js +70 -0
- package/build-module/components/sidebar-navigation-screen-templates-browse/content-legacy.js.map +7 -0
- package/build-module/components/sidebar-navigation-screen-templates-browse/index.js +2 -1
- package/build-module/components/sidebar-navigation-screen-templates-browse/index.js.map +2 -2
- package/build-module/components/site-editor-routes/templates.js +10 -2
- package/build-module/components/site-editor-routes/templates.js.map +2 -2
- package/build-module/components/site-hub/index.js +1 -1
- package/build-module/components/site-hub/index.js.map +2 -2
- package/build-module/utils/constants.js +4 -0
- package/build-module/utils/constants.js.map +2 -2
- package/build-style/style-rtl.css +294 -147
- package/build-style/style.css +294 -147
- package/package.json +46 -46
- package/src/components/add-new-template-legacy/add-custom-generic-template-modal-content.js +94 -0
- package/src/components/add-new-template-legacy/add-custom-template-modal-content.js +314 -0
- package/src/components/add-new-template-legacy/index.js +454 -0
- package/src/components/add-new-template-legacy/utils.js +760 -0
- package/src/components/block-editor/use-site-editor-settings.js +3 -7
- package/src/components/page-templates/fields.js +13 -9
- package/src/components/page-templates/index-legacy.js +166 -0
- package/src/components/post-list/index.js +34 -4
- package/src/components/post-list/use-notes-count.js +48 -0
- package/src/components/sidebar-global-styles/style.scss +0 -8
- package/src/components/sidebar-navigation-screen-patterns/use-template-part-areas.js +1 -0
- package/src/components/sidebar-navigation-screen-templates-browse/content-legacy.js +79 -0
- package/src/components/sidebar-navigation-screen-templates-browse/index.js +8 -1
- package/src/components/site-editor-routes/templates.js +22 -3
- package/src/components/site-hub/index.js +1 -1
- package/src/utils/constants.js +2 -0
|
@@ -19,21 +19,17 @@ const { useLocation, useHistory } = unlock( routerPrivateApis );
|
|
|
19
19
|
|
|
20
20
|
function useNavigateToPreviousEntityRecord() {
|
|
21
21
|
const location = useLocation();
|
|
22
|
-
const
|
|
22
|
+
const previousCanvas = usePrevious( location.query.canvas );
|
|
23
23
|
const history = useHistory();
|
|
24
24
|
const goBack = useMemo( () => {
|
|
25
25
|
const isFocusMode =
|
|
26
26
|
location.query.focusMode ||
|
|
27
27
|
( location?.params?.postId &&
|
|
28
28
|
FOCUSABLE_ENTITIES.includes( location?.params?.postType ) );
|
|
29
|
-
const didComeFromEditorCanvas =
|
|
30
|
-
previousLocation?.query.canvas === 'edit';
|
|
29
|
+
const didComeFromEditorCanvas = previousCanvas === 'edit';
|
|
31
30
|
const showBackButton = isFocusMode && didComeFromEditorCanvas;
|
|
32
31
|
return showBackButton ? () => history.back() : undefined;
|
|
33
|
-
|
|
34
|
-
// just when location changes. Until this is fixed we can't add it to deps. See
|
|
35
|
-
// https://github.com/WordPress/gutenberg/pull/58710#discussion_r1479219465.
|
|
36
|
-
}, [ location, history ] );
|
|
32
|
+
}, [ location, history, previousCanvas ] );
|
|
37
33
|
return goBack;
|
|
38
34
|
}
|
|
39
35
|
|
|
@@ -100,15 +100,19 @@ export const previewField = {
|
|
|
100
100
|
export const descriptionField = {
|
|
101
101
|
label: __( 'Description' ),
|
|
102
102
|
id: 'description',
|
|
103
|
-
render:
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
103
|
+
render: window?.__experimentalTemplateActivate
|
|
104
|
+
? function RenderDescription( { item } ) {
|
|
105
|
+
const defaultTemplateTypes = useAllDefaultTemplateTypes();
|
|
106
|
+
const defaultTemplateType = defaultTemplateTypes.find(
|
|
107
|
+
( type ) => type.slug === item.slug
|
|
108
|
+
);
|
|
109
|
+
return item.description
|
|
110
|
+
? decodeEntities( item.description )
|
|
111
|
+
: defaultTemplateType?.description;
|
|
112
|
+
}
|
|
113
|
+
: ( { item } ) => {
|
|
114
|
+
return item.description && decodeEntities( item.description );
|
|
115
|
+
},
|
|
112
116
|
enableSorting: false,
|
|
113
117
|
enableGlobalSearch: true,
|
|
114
118
|
};
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { Page } from '@wordpress/admin-ui';
|
|
5
|
+
import { __ } from '@wordpress/i18n';
|
|
6
|
+
import { useState, useMemo, useCallback } from '@wordpress/element';
|
|
7
|
+
import { privateApis as corePrivateApis } from '@wordpress/core-data';
|
|
8
|
+
import { DataViews, filterSortAndPaginate } from '@wordpress/dataviews';
|
|
9
|
+
import { privateApis as routerPrivateApis } from '@wordpress/router';
|
|
10
|
+
import { privateApis as editorPrivateApis } from '@wordpress/editor';
|
|
11
|
+
import { addQueryArgs } from '@wordpress/url';
|
|
12
|
+
import { useEvent } from '@wordpress/compose';
|
|
13
|
+
import { useView } from '@wordpress/views';
|
|
14
|
+
import { Button } from '@wordpress/components';
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Internal dependencies
|
|
18
|
+
*/
|
|
19
|
+
import AddNewTemplate from '../add-new-template-legacy';
|
|
20
|
+
import { TEMPLATE_POST_TYPE } from '../../utils/constants';
|
|
21
|
+
import { unlock } from '../../lock-unlock';
|
|
22
|
+
import { useEditPostAction } from '../dataviews-actions';
|
|
23
|
+
import { authorField, descriptionField, previewField } from './fields';
|
|
24
|
+
import { defaultLayouts, getDefaultView } from './view-utils';
|
|
25
|
+
|
|
26
|
+
const { usePostActions, templateTitleField } = unlock( editorPrivateApis );
|
|
27
|
+
const { useHistory, useLocation } = unlock( routerPrivateApis );
|
|
28
|
+
const { useEntityRecordsWithPermissions } = unlock( corePrivateApis );
|
|
29
|
+
|
|
30
|
+
export default function PageTemplates() {
|
|
31
|
+
const { path, query } = useLocation();
|
|
32
|
+
const { activeView = 'active', postId } = query;
|
|
33
|
+
const [ selection, setSelection ] = useState( [ postId ] );
|
|
34
|
+
|
|
35
|
+
const defaultView = useMemo( () => {
|
|
36
|
+
return getDefaultView( activeView );
|
|
37
|
+
}, [ activeView ] );
|
|
38
|
+
const { view, updateView, isModified, resetToDefault } = useView( {
|
|
39
|
+
kind: 'postType',
|
|
40
|
+
name: TEMPLATE_POST_TYPE,
|
|
41
|
+
slug: activeView,
|
|
42
|
+
defaultView,
|
|
43
|
+
queryParams: {
|
|
44
|
+
page: query.pageNumber,
|
|
45
|
+
search: query.search,
|
|
46
|
+
},
|
|
47
|
+
onChangeQueryParams: ( newQueryParams ) => {
|
|
48
|
+
history.navigate(
|
|
49
|
+
addQueryArgs( path, {
|
|
50
|
+
...query,
|
|
51
|
+
pageNumber: newQueryParams.page,
|
|
52
|
+
search: newQueryParams.search || undefined,
|
|
53
|
+
} )
|
|
54
|
+
);
|
|
55
|
+
},
|
|
56
|
+
} );
|
|
57
|
+
|
|
58
|
+
const { records, isResolving: isLoadingData } =
|
|
59
|
+
useEntityRecordsWithPermissions( 'postType', TEMPLATE_POST_TYPE, {
|
|
60
|
+
per_page: -1,
|
|
61
|
+
} );
|
|
62
|
+
const history = useHistory();
|
|
63
|
+
const onChangeSelection = useCallback(
|
|
64
|
+
( items ) => {
|
|
65
|
+
setSelection( items );
|
|
66
|
+
if ( view?.type === 'list' ) {
|
|
67
|
+
history.navigate(
|
|
68
|
+
addQueryArgs( path, {
|
|
69
|
+
postId: items.length === 1 ? items[ 0 ] : undefined,
|
|
70
|
+
} )
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
[ history, path, view?.type ]
|
|
75
|
+
);
|
|
76
|
+
|
|
77
|
+
const authors = useMemo( () => {
|
|
78
|
+
if ( ! records ) {
|
|
79
|
+
return [];
|
|
80
|
+
}
|
|
81
|
+
const authorsSet = new Set();
|
|
82
|
+
records.forEach( ( template ) => {
|
|
83
|
+
authorsSet.add( template.author_text );
|
|
84
|
+
} );
|
|
85
|
+
return Array.from( authorsSet ).map( ( author ) => ( {
|
|
86
|
+
value: author,
|
|
87
|
+
label: author,
|
|
88
|
+
} ) );
|
|
89
|
+
}, [ records ] );
|
|
90
|
+
|
|
91
|
+
const fields = useMemo(
|
|
92
|
+
() => [
|
|
93
|
+
previewField,
|
|
94
|
+
templateTitleField,
|
|
95
|
+
descriptionField,
|
|
96
|
+
{
|
|
97
|
+
...authorField,
|
|
98
|
+
elements: authors,
|
|
99
|
+
},
|
|
100
|
+
],
|
|
101
|
+
[ authors ]
|
|
102
|
+
);
|
|
103
|
+
|
|
104
|
+
const { data, paginationInfo } = useMemo( () => {
|
|
105
|
+
return filterSortAndPaginate( records, view, fields );
|
|
106
|
+
}, [ records, view, fields ] );
|
|
107
|
+
|
|
108
|
+
const postTypeActions = usePostActions( {
|
|
109
|
+
postType: TEMPLATE_POST_TYPE,
|
|
110
|
+
context: 'list',
|
|
111
|
+
} );
|
|
112
|
+
const editAction = useEditPostAction();
|
|
113
|
+
const actions = useMemo(
|
|
114
|
+
() => [ editAction, ...postTypeActions ],
|
|
115
|
+
[ postTypeActions, editAction ]
|
|
116
|
+
);
|
|
117
|
+
|
|
118
|
+
const onChangeView = useEvent( ( newView ) => {
|
|
119
|
+
if ( newView.type !== view.type ) {
|
|
120
|
+
// Retrigger the routing areas resolution.
|
|
121
|
+
history.invalidate();
|
|
122
|
+
}
|
|
123
|
+
updateView( newView );
|
|
124
|
+
} );
|
|
125
|
+
|
|
126
|
+
return (
|
|
127
|
+
<Page
|
|
128
|
+
className="edit-site-page-templates"
|
|
129
|
+
title={ __( 'Templates' ) }
|
|
130
|
+
actions={
|
|
131
|
+
<>
|
|
132
|
+
{ isModified && (
|
|
133
|
+
<Button
|
|
134
|
+
__next40pxDefaultSize
|
|
135
|
+
onClick={ () => {
|
|
136
|
+
resetToDefault();
|
|
137
|
+
history.invalidate();
|
|
138
|
+
} }
|
|
139
|
+
>
|
|
140
|
+
{ __( 'Reset view' ) }
|
|
141
|
+
</Button>
|
|
142
|
+
) }
|
|
143
|
+
<AddNewTemplate />
|
|
144
|
+
</>
|
|
145
|
+
}
|
|
146
|
+
>
|
|
147
|
+
<DataViews
|
|
148
|
+
key={ activeView }
|
|
149
|
+
paginationInfo={ paginationInfo }
|
|
150
|
+
fields={ fields }
|
|
151
|
+
actions={ actions }
|
|
152
|
+
data={ data }
|
|
153
|
+
isLoading={ isLoadingData }
|
|
154
|
+
view={ view }
|
|
155
|
+
onChangeView={ onChangeView }
|
|
156
|
+
onChangeSelection={ onChangeSelection }
|
|
157
|
+
isItemClickable={ () => true }
|
|
158
|
+
onClickItem={ ( { id } ) => {
|
|
159
|
+
history.navigate( `/wp_template/${ id }?canvas=edit` );
|
|
160
|
+
} }
|
|
161
|
+
selection={ selection }
|
|
162
|
+
defaultLayouts={ defaultLayouts }
|
|
163
|
+
/>
|
|
164
|
+
</Page>
|
|
165
|
+
);
|
|
166
|
+
}
|
|
@@ -24,6 +24,8 @@ import { useView } from '@wordpress/views';
|
|
|
24
24
|
import {
|
|
25
25
|
OPERATOR_IS_ANY,
|
|
26
26
|
OPERATOR_IS_NONE,
|
|
27
|
+
OPERATOR_BEFORE,
|
|
28
|
+
OPERATOR_AFTER,
|
|
27
29
|
LAYOUT_LIST,
|
|
28
30
|
} from '../../utils/constants';
|
|
29
31
|
|
|
@@ -31,6 +33,7 @@ import AddNewPostModal from '../add-new-post';
|
|
|
31
33
|
import { unlock } from '../../lock-unlock';
|
|
32
34
|
import { useEditPostAction } from '../dataviews-actions';
|
|
33
35
|
import { defaultLayouts, getDefaultView } from './view-utils';
|
|
36
|
+
import useNotesCount from './use-notes-count';
|
|
34
37
|
|
|
35
38
|
const { usePostActions, usePostFields } = unlock( editorPrivateApis );
|
|
36
39
|
const { useLocation, useHistory } = unlock( routerPrivateApis );
|
|
@@ -123,6 +126,17 @@ export default function PostList( { postType } ) {
|
|
|
123
126
|
) {
|
|
124
127
|
filters.author_exclude = filter.value;
|
|
125
128
|
}
|
|
129
|
+
if ( filter.field === 'date' ) {
|
|
130
|
+
// Skip if no value is set yet
|
|
131
|
+
if ( ! filter.value ) {
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
if ( filter.operator === OPERATOR_BEFORE ) {
|
|
135
|
+
filters.before = filter.value;
|
|
136
|
+
} else if ( filter.operator === OPERATOR_AFTER ) {
|
|
137
|
+
filters.after = filter.value;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
126
140
|
} );
|
|
127
141
|
|
|
128
142
|
// We want to provide a different default item for the status filter
|
|
@@ -149,18 +163,34 @@ export default function PostList( { postType } ) {
|
|
|
149
163
|
totalPages,
|
|
150
164
|
} = useEntityRecordsWithPermissions( 'postType', postType, queryArgs );
|
|
151
165
|
|
|
166
|
+
const postIds = useMemo(
|
|
167
|
+
() => records?.map( ( record ) => record.id ) ?? [],
|
|
168
|
+
[ records ]
|
|
169
|
+
);
|
|
170
|
+
const { notesCount, isLoading: isLoadingNotesCount } =
|
|
171
|
+
useNotesCount( postIds );
|
|
172
|
+
|
|
152
173
|
// The REST API sort the authors by ID, but we want to sort them by name.
|
|
153
174
|
const data = useMemo( () => {
|
|
175
|
+
let processedRecords = records;
|
|
176
|
+
|
|
154
177
|
if ( view?.sort?.field === 'author' ) {
|
|
155
|
-
|
|
178
|
+
processedRecords = filterSortAndPaginate(
|
|
156
179
|
records,
|
|
157
180
|
{ sort: { ...view.sort } },
|
|
158
181
|
fields
|
|
159
182
|
).data;
|
|
160
183
|
}
|
|
161
184
|
|
|
162
|
-
|
|
163
|
-
|
|
185
|
+
if ( processedRecords ) {
|
|
186
|
+
return processedRecords.map( ( record ) => ( {
|
|
187
|
+
...record,
|
|
188
|
+
notesCount: notesCount[ record.id ] ?? 0,
|
|
189
|
+
} ) );
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
return processedRecords;
|
|
193
|
+
}, [ records, fields, view?.sort, notesCount ] );
|
|
164
194
|
|
|
165
195
|
const ids = data?.map( ( record ) => getItemId( record ) ) ?? [];
|
|
166
196
|
const prevIds = usePrevious( ids ) ?? [];
|
|
@@ -261,7 +291,7 @@ export default function PostList( { postType } ) {
|
|
|
261
291
|
fields={ fields }
|
|
262
292
|
actions={ actions }
|
|
263
293
|
data={ data || EMPTY_ARRAY }
|
|
264
|
-
isLoading={ isLoadingData }
|
|
294
|
+
isLoading={ isLoadingData || isLoadingNotesCount }
|
|
265
295
|
view={ view }
|
|
266
296
|
onChangeView={ onChangeView }
|
|
267
297
|
selection={ selection }
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { useMemo } from '@wordpress/element';
|
|
5
|
+
import { useEntityRecords } from '@wordpress/core-data';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Hook to fetch notes counts for a list of post IDs.
|
|
9
|
+
*
|
|
10
|
+
* Notes are stored as comments with type 'note'.
|
|
11
|
+
* This hook fetches all notes for the given posts and returns
|
|
12
|
+
* a map of post ID to notes count.
|
|
13
|
+
*
|
|
14
|
+
* @param {number[]} postIds - Array of post IDs to fetch notes for.
|
|
15
|
+
* @return {{ notesCount: Object, isResolving: boolean }} Object with notesCount map and loading state.
|
|
16
|
+
*/
|
|
17
|
+
export default function useNotesCount( postIds ) {
|
|
18
|
+
const { records: notes, isResolving } = useEntityRecords(
|
|
19
|
+
'root',
|
|
20
|
+
'comment',
|
|
21
|
+
{
|
|
22
|
+
post: postIds,
|
|
23
|
+
type: 'note',
|
|
24
|
+
status: 'all',
|
|
25
|
+
per_page: -1,
|
|
26
|
+
_fields: 'id,post',
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
enabled: postIds?.length > 0,
|
|
30
|
+
}
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
const notesCount = useMemo( () => {
|
|
34
|
+
if ( ! notes || notes.length === 0 ) {
|
|
35
|
+
return {};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const counts = {};
|
|
39
|
+
notes.forEach( ( note ) => {
|
|
40
|
+
const postId = note.post;
|
|
41
|
+
counts[ postId ] = ( counts[ postId ] || 0 ) + 1;
|
|
42
|
+
} );
|
|
43
|
+
|
|
44
|
+
return counts;
|
|
45
|
+
}, [ notes ] );
|
|
46
|
+
|
|
47
|
+
return { notesCount, isResolving };
|
|
48
|
+
}
|
|
@@ -15,14 +15,6 @@
|
|
|
15
15
|
overflow-y: auto;
|
|
16
16
|
padding-left: 0;
|
|
17
17
|
padding-right: 0;
|
|
18
|
-
|
|
19
|
-
.global-styles-ui-sidebar__navigator-screen {
|
|
20
|
-
padding-top: $grid-unit-15;
|
|
21
|
-
padding-left: $grid-unit-15;
|
|
22
|
-
padding-right: $grid-unit-15;
|
|
23
|
-
padding-bottom: $grid-unit-15;
|
|
24
|
-
outline: none;
|
|
25
|
-
}
|
|
26
18
|
}
|
|
27
19
|
.edit-site-sidebar-button {
|
|
28
20
|
color: $gray-900;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { useEntityRecords } from '@wordpress/core-data';
|
|
5
|
+
import { useMemo } from '@wordpress/element';
|
|
6
|
+
import { __experimentalItemGroup as ItemGroup } from '@wordpress/components';
|
|
7
|
+
import { __ } from '@wordpress/i18n';
|
|
8
|
+
import { privateApis as routerPrivateApis } from '@wordpress/router';
|
|
9
|
+
import { addQueryArgs } from '@wordpress/url';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Internal dependencies
|
|
13
|
+
*/
|
|
14
|
+
import SidebarNavigationItem from '../sidebar-navigation-item';
|
|
15
|
+
import { useAddedBy } from '../page-templates/hooks';
|
|
16
|
+
import { layout } from '@wordpress/icons';
|
|
17
|
+
import { TEMPLATE_POST_TYPE } from '../../utils/constants';
|
|
18
|
+
import { unlock } from '../../lock-unlock';
|
|
19
|
+
|
|
20
|
+
const { useLocation } = unlock( routerPrivateApis );
|
|
21
|
+
|
|
22
|
+
const EMPTY_ARRAY = [];
|
|
23
|
+
|
|
24
|
+
function TemplateDataviewItem( { template, isActive } ) {
|
|
25
|
+
const { text, icon } = useAddedBy( template.type, template.id );
|
|
26
|
+
|
|
27
|
+
return (
|
|
28
|
+
<SidebarNavigationItem
|
|
29
|
+
to={ addQueryArgs( '/template', { activeView: text } ) }
|
|
30
|
+
icon={ icon }
|
|
31
|
+
aria-current={ isActive }
|
|
32
|
+
>
|
|
33
|
+
{ text }
|
|
34
|
+
</SidebarNavigationItem>
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export default function DataviewsTemplatesSidebarContent() {
|
|
39
|
+
const {
|
|
40
|
+
query: { activeView = 'all' },
|
|
41
|
+
} = useLocation();
|
|
42
|
+
const { records } = useEntityRecords( 'postType', TEMPLATE_POST_TYPE, {
|
|
43
|
+
per_page: -1,
|
|
44
|
+
} );
|
|
45
|
+
const firstItemPerAuthorText = useMemo( () => {
|
|
46
|
+
const firstItemPerAuthor = records?.reduce( ( acc, template ) => {
|
|
47
|
+
const author = template.author_text;
|
|
48
|
+
if ( author && ! acc[ author ] ) {
|
|
49
|
+
acc[ author ] = template;
|
|
50
|
+
}
|
|
51
|
+
return acc;
|
|
52
|
+
}, {} );
|
|
53
|
+
return (
|
|
54
|
+
( firstItemPerAuthor && Object.values( firstItemPerAuthor ) ) ??
|
|
55
|
+
EMPTY_ARRAY
|
|
56
|
+
);
|
|
57
|
+
}, [ records ] );
|
|
58
|
+
|
|
59
|
+
return (
|
|
60
|
+
<ItemGroup className="edit-site-sidebar-navigation-screen-templates-browse">
|
|
61
|
+
<SidebarNavigationItem
|
|
62
|
+
to="/template"
|
|
63
|
+
icon={ layout }
|
|
64
|
+
aria-current={ activeView === 'all' }
|
|
65
|
+
>
|
|
66
|
+
{ __( 'All templates' ) }
|
|
67
|
+
</SidebarNavigationItem>
|
|
68
|
+
{ firstItemPerAuthorText.map( ( template ) => {
|
|
69
|
+
return (
|
|
70
|
+
<TemplateDataviewItem
|
|
71
|
+
key={ template.author_text }
|
|
72
|
+
template={ template }
|
|
73
|
+
isActive={ activeView === template.author_text }
|
|
74
|
+
/>
|
|
75
|
+
);
|
|
76
|
+
} ) }
|
|
77
|
+
</ItemGroup>
|
|
78
|
+
);
|
|
79
|
+
}
|
|
@@ -8,6 +8,7 @@ import { __ } from '@wordpress/i18n';
|
|
|
8
8
|
*/
|
|
9
9
|
import SidebarNavigationScreen from '../sidebar-navigation-screen';
|
|
10
10
|
import DataviewsTemplatesSidebarContent from './content';
|
|
11
|
+
import DataviewsTemplatesSidebarContentLegacy from './content-legacy';
|
|
11
12
|
|
|
12
13
|
export default function SidebarNavigationScreenTemplatesBrowse( { backPath } ) {
|
|
13
14
|
return (
|
|
@@ -17,7 +18,13 @@ export default function SidebarNavigationScreenTemplatesBrowse( { backPath } ) {
|
|
|
17
18
|
'Create new templates, or reset any customizations made to the templates supplied by your theme.'
|
|
18
19
|
) }
|
|
19
20
|
backPath={ backPath }
|
|
20
|
-
content={
|
|
21
|
+
content={
|
|
22
|
+
window?.__experimentalTemplateActivate ? (
|
|
23
|
+
<DataviewsTemplatesSidebarContent />
|
|
24
|
+
) : (
|
|
25
|
+
<DataviewsTemplatesSidebarContentLegacy />
|
|
26
|
+
)
|
|
27
|
+
}
|
|
21
28
|
/>
|
|
22
29
|
);
|
|
23
30
|
}
|
|
@@ -10,6 +10,7 @@ import Editor from '../editor';
|
|
|
10
10
|
import SidebarNavigationScreenTemplatesBrowse from '../sidebar-navigation-screen-templates-browse';
|
|
11
11
|
import SidebarNavigationScreenUnsupported from '../sidebar-navigation-screen-unsupported';
|
|
12
12
|
import PageTemplates from '../page-templates';
|
|
13
|
+
import PageTemplatesLegacy from '../page-templates/index-legacy';
|
|
13
14
|
import { getDefaultView } from '../page-templates/view-utils';
|
|
14
15
|
|
|
15
16
|
async function isTemplateListView( query ) {
|
|
@@ -37,7 +38,16 @@ export const templatesRoute = {
|
|
|
37
38
|
},
|
|
38
39
|
content( { siteData } ) {
|
|
39
40
|
const isBlockTheme = siteData.currentTheme?.is_block_theme;
|
|
40
|
-
|
|
41
|
+
if ( ! isBlockTheme ) {
|
|
42
|
+
return undefined;
|
|
43
|
+
}
|
|
44
|
+
// Use the new template activation system if experiment is enabled,
|
|
45
|
+
// otherwise use the legacy simple template list.
|
|
46
|
+
return window?.__experimentalTemplateActivate ? (
|
|
47
|
+
<PageTemplates />
|
|
48
|
+
) : (
|
|
49
|
+
<PageTemplatesLegacy />
|
|
50
|
+
);
|
|
41
51
|
},
|
|
42
52
|
async preview( { query, siteData } ) {
|
|
43
53
|
const isBlockTheme = siteData.currentTheme?.is_block_theme;
|
|
@@ -49,10 +59,19 @@ export const templatesRoute = {
|
|
|
49
59
|
},
|
|
50
60
|
mobile( { siteData } ) {
|
|
51
61
|
const isBlockTheme = siteData.currentTheme?.is_block_theme;
|
|
52
|
-
|
|
62
|
+
if ( ! isBlockTheme ) {
|
|
63
|
+
return <SidebarNavigationScreenUnsupported />;
|
|
64
|
+
}
|
|
65
|
+
// Check if the template activation experiment is enabled.
|
|
66
|
+
const isTemplateActivateEnabled =
|
|
67
|
+
typeof window !== 'undefined' &&
|
|
68
|
+
window.__experimentalTemplateActivate;
|
|
69
|
+
// Use the new template activation system if experiment is enabled,
|
|
70
|
+
// otherwise use the legacy simple template list.
|
|
71
|
+
return isTemplateActivateEnabled ? (
|
|
53
72
|
<PageTemplates />
|
|
54
73
|
) : (
|
|
55
|
-
<
|
|
74
|
+
<PageTemplatesLegacy />
|
|
56
75
|
);
|
|
57
76
|
},
|
|
58
77
|
},
|
|
@@ -134,7 +134,7 @@ export const SiteHubMobile = memo(
|
|
|
134
134
|
const currentTheme = getCurrentTheme();
|
|
135
135
|
const settings = getSettings();
|
|
136
136
|
const supportsEditorStyles =
|
|
137
|
-
currentTheme
|
|
137
|
+
currentTheme?.theme_supports[ 'editor-styles' ];
|
|
138
138
|
// This is a temp solution until the has_theme_json value is available for the current theme.
|
|
139
139
|
const hasThemeJson = settings.supportsLayout;
|
|
140
140
|
|
package/src/utils/constants.js
CHANGED