@wordpress/edit-site 4.0.1-next.f435e9e01b.0 → 4.0.3-next.a55ed9455a.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/new-template-part.js +4 -1
- package/build/components/add-new-template/new-template-part.js.map +1 -1
- package/build/components/app/index.js +20 -0
- package/build/components/app/index.js.map +1 -1
- package/build/components/editor/global-styles-renderer.js +7 -3
- package/build/components/editor/global-styles-renderer.js.map +1 -1
- package/build/components/editor/index.js +3 -18
- package/build/components/editor/index.js.map +1 -1
- package/build/components/error-boundary/index.js +11 -27
- package/build/components/error-boundary/index.js.map +1 -1
- package/build/components/error-boundary/warning.js +70 -0
- package/build/components/error-boundary/warning.js.map +1 -0
- package/build/components/global-styles/navigation-button.js +7 -27
- package/build/components/global-styles/navigation-button.js.map +1 -1
- package/build/components/global-styles/screen-block-list.js +31 -1
- package/build/components/global-styles/screen-block-list.js.map +1 -1
- package/build/components/global-styles/screen-typography.js.map +1 -1
- package/build/components/global-styles/typography-panel.js +5 -2
- package/build/components/global-styles/typography-panel.js.map +1 -1
- package/build/components/global-styles/use-global-styles-output.js +21 -4
- package/build/components/global-styles/use-global-styles-output.js.map +1 -1
- package/build/components/global-styles/utils.js +2 -2
- package/build/components/global-styles/utils.js.map +1 -1
- package/build/components/header/index.js +1 -1
- package/build/components/header/index.js.map +1 -1
- package/build/components/header/more-menu/index.js +9 -21
- package/build/components/header/more-menu/index.js.map +1 -1
- package/build/components/header/more-menu/site-export.js +1 -1
- package/build/components/header/more-menu/site-export.js.map +1 -1
- package/build/components/header/more-menu/welcome-guide-menu-item.js +4 -8
- package/build/components/header/more-menu/welcome-guide-menu-item.js.map +1 -1
- package/build/components/keyboard-shortcuts/index.js +1 -1
- package/build/components/keyboard-shortcuts/index.js.map +1 -1
- package/build/components/list/table.js +9 -20
- package/build/components/list/table.js.map +1 -1
- package/build/components/navigation-sidebar/navigation-panel/index.js +9 -3
- package/build/components/navigation-sidebar/navigation-panel/index.js.map +1 -1
- package/build/components/navigation-sidebar/navigation-toggle/index.js +15 -4
- package/build/components/navigation-sidebar/navigation-toggle/index.js.map +1 -1
- package/build/components/secondary-sidebar/list-view-sidebar.js +0 -11
- package/build/components/secondary-sidebar/list-view-sidebar.js.map +1 -1
- package/build/components/sidebar/global-styles-sidebar.js +5 -5
- package/build/components/sidebar/global-styles-sidebar.js.map +1 -1
- package/build/components/template-part-converter/convert-to-template-part.js +4 -1
- package/build/components/template-part-converter/convert-to-template-part.js.map +1 -1
- package/build/components/welcome-guide/editor.js +6 -6
- package/build/components/welcome-guide/editor.js.map +1 -1
- package/build/components/welcome-guide/styles.js +6 -4
- package/build/components/welcome-guide/styles.js.map +1 -1
- package/build/index.js +22 -7
- package/build/index.js.map +1 -1
- package/build/store/actions.js +203 -163
- package/build/store/actions.js.map +1 -1
- package/build/store/index.js +3 -9
- package/build/store/index.js.map +1 -1
- package/build/store/reducer.js +0 -44
- package/build/store/reducer.js.map +1 -1
- package/build/store/selectors.js +33 -10
- package/build/store/selectors.js.map +1 -1
- package/build-module/components/add-new-template/new-template-part.js +4 -1
- package/build-module/components/add-new-template/new-template-part.js.map +1 -1
- package/build-module/components/app/index.js +16 -0
- package/build-module/components/app/index.js.map +1 -1
- package/build-module/components/editor/global-styles-renderer.js +6 -3
- package/build-module/components/editor/global-styles-renderer.js.map +1 -1
- package/build-module/components/editor/index.js +4 -17
- package/build-module/components/editor/index.js.map +1 -1
- package/build-module/components/error-boundary/index.js +9 -26
- package/build-module/components/error-boundary/index.js.map +1 -1
- package/build-module/components/error-boundary/warning.js +60 -0
- package/build-module/components/error-boundary/warning.js.map +1 -0
- package/build-module/components/global-styles/navigation-button.js +8 -28
- package/build-module/components/global-styles/navigation-button.js.map +1 -1
- package/build-module/components/global-styles/screen-block-list.js +31 -2
- package/build-module/components/global-styles/screen-block-list.js.map +1 -1
- package/build-module/components/global-styles/screen-typography.js.map +1 -1
- package/build-module/components/global-styles/typography-panel.js +6 -3
- package/build-module/components/global-styles/typography-panel.js.map +1 -1
- package/build-module/components/global-styles/use-global-styles-output.js +20 -4
- package/build-module/components/global-styles/use-global-styles-output.js.map +1 -1
- package/build-module/components/global-styles/utils.js +2 -2
- package/build-module/components/global-styles/utils.js.map +1 -1
- package/build-module/components/header/index.js +1 -1
- package/build-module/components/header/index.js.map +1 -1
- package/build-module/components/header/more-menu/index.js +11 -22
- package/build-module/components/header/more-menu/index.js.map +1 -1
- package/build-module/components/header/more-menu/site-export.js +1 -1
- package/build-module/components/header/more-menu/site-export.js.map +1 -1
- package/build-module/components/header/more-menu/welcome-guide-menu-item.js +4 -8
- package/build-module/components/header/more-menu/welcome-guide-menu-item.js.map +1 -1
- package/build-module/components/keyboard-shortcuts/index.js +1 -1
- package/build-module/components/keyboard-shortcuts/index.js.map +1 -1
- package/build-module/components/list/table.js +9 -21
- package/build-module/components/list/table.js.map +1 -1
- package/build-module/components/navigation-sidebar/navigation-panel/index.js +9 -3
- package/build-module/components/navigation-sidebar/navigation-panel/index.js.map +1 -1
- package/build-module/components/navigation-sidebar/navigation-toggle/index.js +12 -4
- package/build-module/components/navigation-sidebar/navigation-toggle/index.js.map +1 -1
- package/build-module/components/secondary-sidebar/list-view-sidebar.js +1 -12
- package/build-module/components/secondary-sidebar/list-view-sidebar.js.map +1 -1
- package/build-module/components/sidebar/global-styles-sidebar.js +4 -4
- package/build-module/components/sidebar/global-styles-sidebar.js.map +1 -1
- package/build-module/components/template-part-converter/convert-to-template-part.js +4 -1
- package/build-module/components/template-part-converter/convert-to-template-part.js.map +1 -1
- package/build-module/components/welcome-guide/editor.js +5 -5
- package/build-module/components/welcome-guide/editor.js.map +1 -1
- package/build-module/components/welcome-guide/styles.js +5 -4
- package/build-module/components/welcome-guide/styles.js.map +1 -1
- package/build-module/index.js +20 -7
- package/build-module/index.js.map +1 -1
- package/build-module/store/actions.js +181 -154
- package/build-module/store/actions.js.map +1 -1
- package/build-module/store/index.js +4 -9
- package/build-module/store/index.js.map +1 -1
- package/build-module/store/reducer.js +0 -40
- package/build-module/store/reducer.js.map +1 -1
- package/build-module/store/selectors.js +28 -10
- package/build-module/store/selectors.js.map +1 -1
- package/build-style/style-rtl.css +101 -38
- package/build-style/style.css +101 -38
- package/package.json +33 -27
- package/src/components/add-new-template/new-template-part.js +7 -1
- package/src/components/app/index.js +19 -0
- package/src/components/editor/global-styles-renderer.js +7 -1
- package/src/components/editor/index.js +2 -20
- package/src/components/error-boundary/index.js +11 -28
- package/src/components/error-boundary/warning.js +59 -0
- package/src/components/global-styles/navigation-button.js +6 -25
- package/src/components/global-styles/screen-block-list.js +27 -2
- package/src/components/global-styles/screen-typography.js +1 -2
- package/src/components/global-styles/typography-panel.js +12 -5
- package/src/components/global-styles/use-global-styles-output.js +19 -3
- package/src/components/global-styles/utils.js +2 -2
- package/src/components/header/index.js +1 -1
- package/src/components/header/more-menu/index.js +12 -29
- package/src/components/header/more-menu/site-export.js +1 -1
- package/src/components/header/more-menu/welcome-guide-menu-item.js +3 -7
- package/src/components/keyboard-shortcuts/index.js +1 -1
- package/src/components/list/table.js +18 -23
- package/src/components/navigation-sidebar/navigation-panel/index.js +16 -11
- package/src/components/navigation-sidebar/navigation-toggle/index.js +13 -4
- package/src/components/navigation-sidebar/navigation-toggle/style.scss +32 -31
- package/src/components/navigation-sidebar/navigation-toggle/test/index.js +1 -1
- package/src/components/secondary-sidebar/list-view-sidebar.js +1 -11
- package/src/components/sidebar/global-styles-sidebar.js +6 -3
- package/src/components/sidebar/style.scss +1 -1
- package/src/components/template-part-converter/convert-to-template-part.js +6 -1
- package/src/components/welcome-guide/editor.js +8 -4
- package/src/components/welcome-guide/styles.js +5 -3
- package/src/index.js +25 -7
- package/src/store/actions.js +180 -215
- package/src/store/index.js +2 -8
- package/src/store/reducer.js +0 -30
- package/src/store/selectors.js +37 -10
- package/src/store/test/actions.js +203 -92
- package/src/store/test/reducer.js +0 -22
- package/src/store/test/selectors.js +22 -53
- package/src/style.scss +0 -1
- package/build/components/header/feature-toggle/index.js +0 -66
- package/build/components/header/feature-toggle/index.js.map +0 -1
- package/build/components/routes/redirect-to-homepage.js +0 -87
- package/build/components/routes/redirect-to-homepage.js.map +0 -1
- package/build/store/defaults.js +0 -15
- package/build/store/defaults.js.map +0 -1
- package/build-module/components/header/feature-toggle/index.js +0 -52
- package/build-module/components/header/feature-toggle/index.js.map +0 -1
- package/build-module/components/routes/redirect-to-homepage.js +0 -75
- package/build-module/components/routes/redirect-to-homepage.js.map +0 -1
- package/build-module/store/defaults.js +0 -8
- package/build-module/store/defaults.js.map +0 -1
- package/src/components/header/feature-toggle/index.js +0 -55
- package/src/components/header/more-menu/style.scss +0 -29
- package/src/components/routes/redirect-to-homepage.js +0 -71
- package/src/store/defaults.js +0 -7
package/src/store/actions.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* WordPress dependencies
|
|
3
3
|
*/
|
|
4
|
+
import apiFetch from '@wordpress/api-fetch';
|
|
4
5
|
import { parse, __unstableSerializeAndClean } from '@wordpress/blocks';
|
|
5
|
-
import
|
|
6
|
-
import { apiFetch } from '@wordpress/data-controls';
|
|
6
|
+
import deprecated from '@wordpress/deprecated';
|
|
7
7
|
import { addQueryArgs, getPathAndQueryString } from '@wordpress/url';
|
|
8
8
|
import { __, sprintf } from '@wordpress/i18n';
|
|
9
9
|
import { store as noticesStore } from '@wordpress/notices';
|
|
@@ -11,6 +11,7 @@ import { store as coreStore } from '@wordpress/core-data';
|
|
|
11
11
|
import { store as interfaceStore } from '@wordpress/interface';
|
|
12
12
|
import { store as blockEditorStore } from '@wordpress/block-editor';
|
|
13
13
|
import { speak } from '@wordpress/a11y';
|
|
14
|
+
import { store as preferencesStore } from '@wordpress/preferences';
|
|
14
15
|
|
|
15
16
|
/**
|
|
16
17
|
* Internal dependencies
|
|
@@ -19,21 +20,26 @@ import { STORE_NAME as editSiteStoreName } from './constants';
|
|
|
19
20
|
import isTemplateRevertable from '../utils/is-template-revertable';
|
|
20
21
|
|
|
21
22
|
/**
|
|
22
|
-
*
|
|
23
|
+
* Dispatches an action that toggles a feature flag.
|
|
23
24
|
*
|
|
24
|
-
* @param {string}
|
|
25
|
-
*
|
|
26
|
-
* @return {Object} Action object.
|
|
25
|
+
* @param {string} featureName Feature name.
|
|
27
26
|
*/
|
|
28
|
-
export function toggleFeature(
|
|
29
|
-
return {
|
|
30
|
-
|
|
31
|
-
|
|
27
|
+
export function toggleFeature( featureName ) {
|
|
28
|
+
return function ( { registry } ) {
|
|
29
|
+
deprecated( "select( 'core/edit-site' ).toggleFeature( featureName )", {
|
|
30
|
+
since: '6.0',
|
|
31
|
+
alternative:
|
|
32
|
+
"select( 'core/preferences').toggle( 'core/edit-site', featureName )",
|
|
33
|
+
} );
|
|
34
|
+
|
|
35
|
+
registry
|
|
36
|
+
.dispatch( preferencesStore )
|
|
37
|
+
.toggle( 'core/edit-site', featureName );
|
|
32
38
|
};
|
|
33
39
|
}
|
|
34
40
|
|
|
35
41
|
/**
|
|
36
|
-
*
|
|
42
|
+
* Action that changes the width of the editing canvas.
|
|
37
43
|
*
|
|
38
44
|
* @param {string} deviceType
|
|
39
45
|
*
|
|
@@ -47,97 +53,83 @@ export function __experimentalSetPreviewDeviceType( deviceType ) {
|
|
|
47
53
|
}
|
|
48
54
|
|
|
49
55
|
/**
|
|
50
|
-
*
|
|
56
|
+
* Action that sets a template, optionally fetching it from REST API.
|
|
51
57
|
*
|
|
52
58
|
* @param {number} templateId The template ID.
|
|
53
59
|
* @param {string} templateSlug The template slug.
|
|
54
60
|
* @return {Object} Action object.
|
|
55
61
|
*/
|
|
56
|
-
export
|
|
57
|
-
|
|
62
|
+
export const setTemplate = ( templateId, templateSlug ) => async ( {
|
|
63
|
+
dispatch,
|
|
64
|
+
registry,
|
|
65
|
+
} ) => {
|
|
58
66
|
if ( ! templateSlug ) {
|
|
59
|
-
const template =
|
|
60
|
-
coreStore
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
'wp_template',
|
|
64
|
-
templateId
|
|
65
|
-
);
|
|
66
|
-
pageContext.templateSlug = template?.slug;
|
|
67
|
+
const template = await registry
|
|
68
|
+
.resolveSelect( coreStore )
|
|
69
|
+
.getEntityRecord( 'postType', 'wp_template', templateId );
|
|
70
|
+
templateSlug = template?.slug;
|
|
67
71
|
}
|
|
68
|
-
|
|
72
|
+
|
|
73
|
+
dispatch( {
|
|
69
74
|
type: 'SET_TEMPLATE',
|
|
70
75
|
templateId,
|
|
71
|
-
page: { context:
|
|
72
|
-
};
|
|
73
|
-
}
|
|
76
|
+
page: { context: { templateSlug } },
|
|
77
|
+
} );
|
|
78
|
+
};
|
|
74
79
|
|
|
75
80
|
/**
|
|
76
|
-
*
|
|
81
|
+
* Action that adds a new template and sets it as the current template.
|
|
77
82
|
*
|
|
78
83
|
* @param {Object} template The template.
|
|
79
84
|
*
|
|
80
85
|
* @return {Object} Action object used to set the current template.
|
|
81
86
|
*/
|
|
82
|
-
export
|
|
83
|
-
const newTemplate =
|
|
84
|
-
coreStore
|
|
85
|
-
|
|
86
|
-
'postType',
|
|
87
|
-
'wp_template',
|
|
88
|
-
template
|
|
89
|
-
);
|
|
87
|
+
export const addTemplate = ( template ) => async ( { dispatch, registry } ) => {
|
|
88
|
+
const newTemplate = await registry
|
|
89
|
+
.dispatch( coreStore )
|
|
90
|
+
.saveEntityRecord( 'postType', 'wp_template', template );
|
|
90
91
|
|
|
91
92
|
if ( template.content ) {
|
|
92
|
-
|
|
93
|
-
coreStore
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
93
|
+
registry
|
|
94
|
+
.dispatch( coreStore )
|
|
95
|
+
.editEntityRecord(
|
|
96
|
+
'postType',
|
|
97
|
+
'wp_template',
|
|
98
|
+
newTemplate.id,
|
|
99
|
+
{ blocks: parse( template.content ) },
|
|
100
|
+
{ undoIgnore: true }
|
|
101
|
+
);
|
|
101
102
|
}
|
|
102
103
|
|
|
103
|
-
|
|
104
|
+
dispatch( {
|
|
104
105
|
type: 'SET_TEMPLATE',
|
|
105
106
|
templateId: newTemplate.id,
|
|
106
107
|
page: { context: { templateSlug: newTemplate.slug } },
|
|
107
|
-
};
|
|
108
|
-
}
|
|
108
|
+
} );
|
|
109
|
+
};
|
|
109
110
|
|
|
110
111
|
/**
|
|
111
|
-
*
|
|
112
|
+
* Action that removes a template.
|
|
112
113
|
*
|
|
113
114
|
* @param {Object} template The template object.
|
|
114
115
|
*/
|
|
115
|
-
export
|
|
116
|
+
export const removeTemplate = ( template ) => async ( { registry } ) => {
|
|
116
117
|
try {
|
|
117
|
-
|
|
118
|
-
coreStore
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
template.id,
|
|
123
|
-
{ force: true }
|
|
124
|
-
);
|
|
118
|
+
await registry
|
|
119
|
+
.dispatch( coreStore )
|
|
120
|
+
.deleteEntityRecord( 'postType', template.type, template.id, {
|
|
121
|
+
force: true,
|
|
122
|
+
} );
|
|
125
123
|
|
|
126
|
-
const lastError =
|
|
127
|
-
coreStore
|
|
128
|
-
|
|
129
|
-
'postType',
|
|
130
|
-
template.type,
|
|
131
|
-
template.id
|
|
132
|
-
);
|
|
124
|
+
const lastError = registry
|
|
125
|
+
.select( coreStore )
|
|
126
|
+
.getLastEntityDeleteError( 'postType', template.type, template.id );
|
|
133
127
|
|
|
134
128
|
if ( lastError ) {
|
|
135
129
|
throw lastError;
|
|
136
130
|
}
|
|
137
131
|
|
|
138
|
-
|
|
139
|
-
noticesStore,
|
|
140
|
-
'createSuccessNotice',
|
|
132
|
+
registry.dispatch( noticesStore ).createSuccessNotice(
|
|
141
133
|
sprintf(
|
|
142
134
|
/* translators: The template/part's name. */
|
|
143
135
|
__( '"%s" deleted.' ),
|
|
@@ -151,17 +143,14 @@ export function* removeTemplate( template ) {
|
|
|
151
143
|
? error.message
|
|
152
144
|
: __( 'An error occurred while deleting the template.' );
|
|
153
145
|
|
|
154
|
-
|
|
155
|
-
noticesStore
|
|
156
|
-
|
|
157
|
-
errorMessage,
|
|
158
|
-
{ type: 'snackbar' }
|
|
159
|
-
);
|
|
146
|
+
registry
|
|
147
|
+
.dispatch( noticesStore )
|
|
148
|
+
.createErrorNotice( errorMessage, { type: 'snackbar' } );
|
|
160
149
|
}
|
|
161
|
-
}
|
|
150
|
+
};
|
|
162
151
|
|
|
163
152
|
/**
|
|
164
|
-
*
|
|
153
|
+
* Action that sets a template part.
|
|
165
154
|
*
|
|
166
155
|
* @param {string} templatePartId The template part ID.
|
|
167
156
|
*
|
|
@@ -175,8 +164,8 @@ export function setTemplatePart( templatePartId ) {
|
|
|
175
164
|
}
|
|
176
165
|
|
|
177
166
|
/**
|
|
178
|
-
*
|
|
179
|
-
* from
|
|
167
|
+
* Action that sets the home template ID to the template ID of the page resolved
|
|
168
|
+
* from a given path.
|
|
180
169
|
*
|
|
181
170
|
* @param {number} homeTemplateId The template ID for the homepage.
|
|
182
171
|
*/
|
|
@@ -199,41 +188,46 @@ export function setHomeTemplateId( homeTemplateId ) {
|
|
|
199
188
|
*
|
|
200
189
|
* @return {number} The resolved template ID for the page route.
|
|
201
190
|
*/
|
|
202
|
-
export
|
|
191
|
+
export const setPage = ( page ) => async ( { dispatch, registry } ) => {
|
|
203
192
|
if ( ! page.path && page.context?.postId ) {
|
|
204
|
-
const entity =
|
|
205
|
-
coreStore
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
193
|
+
const entity = await registry
|
|
194
|
+
.resolveSelect( coreStore )
|
|
195
|
+
.getEntityRecord(
|
|
196
|
+
'postType',
|
|
197
|
+
page.context.postType || 'post',
|
|
198
|
+
page.context.postId
|
|
199
|
+
);
|
|
211
200
|
// If the entity is undefined for some reason, path will resolve to "/"
|
|
212
201
|
page.path = getPathAndQueryString( entity?.link );
|
|
213
202
|
}
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
page.path
|
|
218
|
-
|
|
219
|
-
|
|
203
|
+
|
|
204
|
+
const template = await registry
|
|
205
|
+
.resolveSelect( coreStore )
|
|
206
|
+
.__experimentalGetTemplateForLink( page.path );
|
|
207
|
+
|
|
208
|
+
if ( ! template ) {
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
dispatch( {
|
|
220
213
|
type: 'SET_PAGE',
|
|
221
|
-
page:
|
|
222
|
-
?
|
|
223
|
-
: {
|
|
214
|
+
page: template.slug
|
|
215
|
+
? {
|
|
224
216
|
...page,
|
|
225
217
|
context: {
|
|
226
218
|
...page.context,
|
|
227
|
-
templateSlug,
|
|
219
|
+
templateSlug: template.slug,
|
|
228
220
|
},
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
221
|
+
}
|
|
222
|
+
: page,
|
|
223
|
+
templateId: template.id,
|
|
224
|
+
} );
|
|
225
|
+
|
|
226
|
+
return template.id;
|
|
227
|
+
};
|
|
234
228
|
|
|
235
229
|
/**
|
|
236
|
-
*
|
|
230
|
+
* Action that sets the active navigation panel menu.
|
|
237
231
|
*
|
|
238
232
|
* @param {string} menu Menu prop of active menu.
|
|
239
233
|
*
|
|
@@ -272,7 +266,7 @@ export function setIsNavigationPanelOpened( isOpen ) {
|
|
|
272
266
|
}
|
|
273
267
|
|
|
274
268
|
/**
|
|
275
|
-
*
|
|
269
|
+
* Opens or closes the inserter.
|
|
276
270
|
*
|
|
277
271
|
* @param {boolean|Object} value Whether the inserter should be
|
|
278
272
|
* opened (true) or closed (false).
|
|
@@ -325,33 +319,33 @@ export function setIsListViewOpened( isOpen ) {
|
|
|
325
319
|
* @param {boolean} [options.allowUndo] Whether to allow the user to undo
|
|
326
320
|
* reverting the template. Default true.
|
|
327
321
|
*/
|
|
328
|
-
export
|
|
322
|
+
export const revertTemplate = (
|
|
323
|
+
template,
|
|
324
|
+
{ allowUndo = true } = {}
|
|
325
|
+
) => async ( { registry } ) => {
|
|
329
326
|
if ( ! isTemplateRevertable( template ) ) {
|
|
330
|
-
|
|
331
|
-
noticesStore
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
);
|
|
327
|
+
registry
|
|
328
|
+
.dispatch( noticesStore )
|
|
329
|
+
.createErrorNotice( __( 'This template is not revertable.' ), {
|
|
330
|
+
type: 'snackbar',
|
|
331
|
+
} );
|
|
336
332
|
return;
|
|
337
333
|
}
|
|
338
334
|
|
|
339
335
|
try {
|
|
340
|
-
const templateEntity =
|
|
341
|
-
coreStore
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
template.type
|
|
345
|
-
);
|
|
336
|
+
const templateEntity = registry
|
|
337
|
+
.select( coreStore )
|
|
338
|
+
.getEntity( 'postType', template.type );
|
|
339
|
+
|
|
346
340
|
if ( ! templateEntity ) {
|
|
347
|
-
|
|
348
|
-
noticesStore
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
341
|
+
registry
|
|
342
|
+
.dispatch( noticesStore )
|
|
343
|
+
.createErrorNotice(
|
|
344
|
+
__(
|
|
345
|
+
'The editor has encountered an unexpected error. Please reload.'
|
|
346
|
+
),
|
|
347
|
+
{ type: 'snackbar' }
|
|
348
|
+
);
|
|
355
349
|
return;
|
|
356
350
|
}
|
|
357
351
|
|
|
@@ -359,78 +353,66 @@ export function* revertTemplate( template, { allowUndo = true } = {} ) {
|
|
|
359
353
|
`${ templateEntity.baseURL }/${ template.id }`,
|
|
360
354
|
{ context: 'edit', source: 'theme' }
|
|
361
355
|
);
|
|
362
|
-
|
|
356
|
+
|
|
357
|
+
const fileTemplate = await apiFetch( { path: fileTemplatePath } );
|
|
363
358
|
if ( ! fileTemplate ) {
|
|
364
|
-
|
|
365
|
-
noticesStore
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
359
|
+
registry
|
|
360
|
+
.dispatch( noticesStore )
|
|
361
|
+
.createErrorNotice(
|
|
362
|
+
__(
|
|
363
|
+
'The editor has encountered an unexpected error. Please reload.'
|
|
364
|
+
),
|
|
365
|
+
{ type: 'snackbar' }
|
|
366
|
+
);
|
|
372
367
|
return;
|
|
373
368
|
}
|
|
374
369
|
|
|
375
370
|
const serializeBlocks = ( { blocks: blocksForSerialization = [] } ) =>
|
|
376
371
|
__unstableSerializeAndClean( blocksForSerialization );
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
'postType',
|
|
381
|
-
|
|
382
|
-
template.id
|
|
383
|
-
);
|
|
372
|
+
|
|
373
|
+
const edited = registry
|
|
374
|
+
.select( coreStore )
|
|
375
|
+
.getEditedEntityRecord( 'postType', template.type, template.id );
|
|
376
|
+
|
|
384
377
|
// We are fixing up the undo level here to make sure we can undo
|
|
385
378
|
// the revert in the header toolbar correctly.
|
|
386
|
-
|
|
387
|
-
coreStore,
|
|
388
|
-
'editEntityRecord',
|
|
379
|
+
registry.dispatch( coreStore ).editEntityRecord(
|
|
389
380
|
'postType',
|
|
390
381
|
template.type,
|
|
391
382
|
template.id,
|
|
392
383
|
{
|
|
393
|
-
content: serializeBlocks, //
|
|
394
|
-
blocks: edited.blocks, //
|
|
384
|
+
content: serializeBlocks, // Required to make the `undo` behave correctly.
|
|
385
|
+
blocks: edited.blocks, // Required to revert the blocks in the editor.
|
|
395
386
|
source: 'custom', // required to avoid turning the editor into a dirty state
|
|
396
387
|
},
|
|
397
388
|
{
|
|
398
|
-
undoIgnore: true, //
|
|
389
|
+
undoIgnore: true, // Required to merge this edit with the last undo level.
|
|
399
390
|
}
|
|
400
391
|
);
|
|
401
392
|
|
|
402
393
|
const blocks = parse( fileTemplate?.content?.raw );
|
|
403
|
-
|
|
404
|
-
coreStore
|
|
405
|
-
|
|
406
|
-
'postType',
|
|
407
|
-
template.type,
|
|
408
|
-
fileTemplate.id,
|
|
409
|
-
{
|
|
394
|
+
registry
|
|
395
|
+
.dispatch( coreStore )
|
|
396
|
+
.editEntityRecord( 'postType', template.type, fileTemplate.id, {
|
|
410
397
|
content: serializeBlocks,
|
|
411
398
|
blocks,
|
|
412
399
|
source: 'theme',
|
|
413
|
-
}
|
|
414
|
-
);
|
|
400
|
+
} );
|
|
415
401
|
|
|
416
402
|
if ( allowUndo ) {
|
|
417
|
-
const undoRevert =
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
template.type,
|
|
421
|
-
edited.id,
|
|
422
|
-
{
|
|
403
|
+
const undoRevert = () => {
|
|
404
|
+
registry
|
|
405
|
+
.dispatch( coreStore )
|
|
406
|
+
.editEntityRecord( 'postType', template.type, edited.id, {
|
|
423
407
|
content: serializeBlocks,
|
|
424
408
|
blocks: edited.blocks,
|
|
425
409
|
source: 'custom',
|
|
426
|
-
}
|
|
427
|
-
);
|
|
410
|
+
} );
|
|
428
411
|
};
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
__( 'Template reverted.' ),
|
|
433
|
-
{
|
|
412
|
+
|
|
413
|
+
registry
|
|
414
|
+
.dispatch( noticesStore )
|
|
415
|
+
.createSuccessNotice( __( 'Template reverted.' ), {
|
|
434
416
|
type: 'snackbar',
|
|
435
417
|
actions: [
|
|
436
418
|
{
|
|
@@ -438,72 +420,55 @@ export function* revertTemplate( template, { allowUndo = true } = {} ) {
|
|
|
438
420
|
onClick: undoRevert,
|
|
439
421
|
},
|
|
440
422
|
],
|
|
441
|
-
}
|
|
442
|
-
);
|
|
423
|
+
} );
|
|
443
424
|
} else {
|
|
444
|
-
|
|
445
|
-
noticesStore
|
|
446
|
-
|
|
447
|
-
__( 'Template reverted.' )
|
|
448
|
-
);
|
|
425
|
+
registry
|
|
426
|
+
.dispatch( noticesStore )
|
|
427
|
+
.createSuccessNotice( __( 'Template reverted.' ) );
|
|
449
428
|
}
|
|
450
429
|
} catch ( error ) {
|
|
451
430
|
const errorMessage =
|
|
452
431
|
error.message && error.code !== 'unknown_error'
|
|
453
432
|
? error.message
|
|
454
433
|
: __( 'Template revert failed. Please reload.' );
|
|
455
|
-
|
|
456
|
-
noticesStore
|
|
457
|
-
|
|
458
|
-
errorMessage,
|
|
459
|
-
{ type: 'snackbar' }
|
|
460
|
-
);
|
|
434
|
+
registry
|
|
435
|
+
.dispatch( noticesStore )
|
|
436
|
+
.createErrorNotice( errorMessage, { type: 'snackbar' } );
|
|
461
437
|
}
|
|
462
|
-
}
|
|
438
|
+
};
|
|
463
439
|
/**
|
|
464
|
-
*
|
|
440
|
+
* Action that opens an editor sidebar.
|
|
465
441
|
*
|
|
466
442
|
* @param {?string} name Sidebar name to be opened.
|
|
467
|
-
*
|
|
468
|
-
* @yield {Object} Action object.
|
|
469
443
|
*/
|
|
470
|
-
export
|
|
471
|
-
|
|
472
|
-
interfaceStore
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
name
|
|
476
|
-
);
|
|
477
|
-
}
|
|
444
|
+
export const openGeneralSidebar = ( name ) => ( { registry } ) => {
|
|
445
|
+
registry
|
|
446
|
+
.dispatch( interfaceStore )
|
|
447
|
+
.enableComplementaryArea( editSiteStoreName, name );
|
|
448
|
+
};
|
|
478
449
|
|
|
479
450
|
/**
|
|
480
|
-
*
|
|
481
|
-
*
|
|
482
|
-
* @yield {Object} Action object.
|
|
451
|
+
* Action that closes the sidebar.
|
|
483
452
|
*/
|
|
484
|
-
export
|
|
485
|
-
|
|
486
|
-
interfaceStore
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
);
|
|
490
|
-
}
|
|
453
|
+
export const closeGeneralSidebar = () => ( { registry } ) => {
|
|
454
|
+
registry
|
|
455
|
+
.dispatch( interfaceStore )
|
|
456
|
+
.disableComplementaryArea( editSiteStoreName );
|
|
457
|
+
};
|
|
491
458
|
|
|
492
|
-
export
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
mode
|
|
496
|
-
};
|
|
459
|
+
export const switchEditorMode = ( mode ) => ( { registry } ) => {
|
|
460
|
+
registry
|
|
461
|
+
.dispatch( 'core/preferences' )
|
|
462
|
+
.set( 'core/edit-site', 'editorMode', mode );
|
|
497
463
|
|
|
498
464
|
// Unselect blocks when we switch to a non visual mode.
|
|
499
465
|
if ( mode !== 'visual' ) {
|
|
500
|
-
|
|
466
|
+
registry.dispatch( blockEditorStore ).clearSelectedBlock();
|
|
501
467
|
}
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
}
|
|
506
|
-
|
|
507
|
-
speak( messages[ mode ], 'assertive' );
|
|
468
|
+
|
|
469
|
+
if ( mode === 'visual' ) {
|
|
470
|
+
speak( __( 'Visual editor selected' ), 'assertive' );
|
|
471
|
+
} else if ( mode === 'mosaic' ) {
|
|
472
|
+
speak( __( 'Mosaic view selected' ), 'assertive' );
|
|
508
473
|
}
|
|
509
|
-
}
|
|
474
|
+
};
|
package/src/store/index.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* WordPress dependencies
|
|
3
3
|
*/
|
|
4
|
-
import { createReduxStore,
|
|
5
|
-
import { controls } from '@wordpress/data-controls';
|
|
4
|
+
import { createReduxStore, register } from '@wordpress/data';
|
|
6
5
|
|
|
7
6
|
/**
|
|
8
7
|
* Internal dependencies
|
|
@@ -16,12 +15,7 @@ export const storeConfig = {
|
|
|
16
15
|
reducer,
|
|
17
16
|
actions,
|
|
18
17
|
selectors,
|
|
19
|
-
controls,
|
|
20
|
-
persist: [ 'preferences' ],
|
|
21
18
|
};
|
|
22
19
|
|
|
23
20
|
export const store = createReduxStore( STORE_NAME, storeConfig );
|
|
24
|
-
|
|
25
|
-
// Once we build a more generic persistence plugin that works across types of stores
|
|
26
|
-
// we'd be able to replace this with a register call.
|
|
27
|
-
registerStore( STORE_NAME, storeConfig );
|
|
21
|
+
register( store );
|
package/src/store/reducer.js
CHANGED
|
@@ -6,37 +6,8 @@ import { combineReducers } from '@wordpress/data';
|
|
|
6
6
|
/**
|
|
7
7
|
* Internal dependencies
|
|
8
8
|
*/
|
|
9
|
-
import { PREFERENCES_DEFAULTS } from './defaults';
|
|
10
9
|
import { MENU_ROOT } from '../components/navigation-sidebar/navigation-panel/constants';
|
|
11
10
|
|
|
12
|
-
/**
|
|
13
|
-
* Reducer returning the user preferences.
|
|
14
|
-
*
|
|
15
|
-
* @param {Object} state Current state.
|
|
16
|
-
* @param {Object} action Dispatched action.
|
|
17
|
-
* @return {Object} Updated state.
|
|
18
|
-
*/
|
|
19
|
-
export const preferences = combineReducers( {
|
|
20
|
-
features( state = PREFERENCES_DEFAULTS.features, action ) {
|
|
21
|
-
switch ( action.type ) {
|
|
22
|
-
case 'TOGGLE_FEATURE': {
|
|
23
|
-
return {
|
|
24
|
-
...state,
|
|
25
|
-
[ action.feature ]: ! state[ action.feature ],
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
default:
|
|
29
|
-
return state;
|
|
30
|
-
}
|
|
31
|
-
},
|
|
32
|
-
editorMode( state = PREFERENCES_DEFAULTS.editorMode, action ) {
|
|
33
|
-
if ( action.type === 'SWITCH_MODE' ) {
|
|
34
|
-
return action.mode;
|
|
35
|
-
}
|
|
36
|
-
return state;
|
|
37
|
-
},
|
|
38
|
-
} );
|
|
39
|
-
|
|
40
11
|
/**
|
|
41
12
|
* Reducer returning the editing canvas device type.
|
|
42
13
|
*
|
|
@@ -213,7 +184,6 @@ export function listViewPanel( state = false, action ) {
|
|
|
213
184
|
}
|
|
214
185
|
|
|
215
186
|
export default combineReducers( {
|
|
216
|
-
preferences,
|
|
217
187
|
deviceType,
|
|
218
188
|
settings,
|
|
219
189
|
editedPost,
|