@wordpress/edit-site 4.0.0 → 4.0.2
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/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/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/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/list/table.js +3 -1
- package/build/components/list/table.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/routes/redirect-to-homepage.js +22 -3
- package/build/components/routes/redirect-to-homepage.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/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/index.js +15 -1
- package/build/index.js.map +1 -1
- package/build/store/actions.js +191 -155
- package/build/store/actions.js.map +1 -1
- package/build/store/index.js +0 -3
- package/build/store/index.js.map +1 -1
- package/build/store/selectors.js +3 -2
- 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/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/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/list/table.js +2 -1
- package/build-module/components/list/table.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/routes/redirect-to-homepage.js +22 -3
- package/build-module/components/routes/redirect-to-homepage.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/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/index.js +13 -1
- package/build-module/index.js.map +1 -1
- package/build-module/store/actions.js +170 -145
- package/build-module/store/actions.js.map +1 -1
- package/build-module/store/index.js +0 -2
- package/build-module/store/index.js.map +1 -1
- package/build-module/store/selectors.js +3 -2
- package/build-module/store/selectors.js.map +1 -1
- package/build-style/style-rtl.css +11 -10
- package/build-style/style.css +11 -10
- package/package.json +18 -18
- package/src/components/add-new-template/new-template-part.js +7 -1
- 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/typography-panel.js +12 -5
- package/src/components/global-styles/use-global-styles-output.js +19 -3
- package/src/components/list/table.js +5 -2
- 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/routes/redirect-to-homepage.js +27 -4
- package/src/components/secondary-sidebar/list-view-sidebar.js +1 -11
- package/src/components/template-part-converter/convert-to-template-part.js +6 -1
- package/src/index.js +17 -1
- package/src/store/actions.js +161 -205
- package/src/store/index.js +0 -2
- package/src/store/selectors.js +3 -0
- package/src/store/test/actions.js +186 -92
- package/src/store/test/selectors.js +8 -1
package/src/store/index.js
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
* WordPress dependencies
|
|
3
3
|
*/
|
|
4
4
|
import { createReduxStore, registerStore } from '@wordpress/data';
|
|
5
|
-
import { controls } from '@wordpress/data-controls';
|
|
6
5
|
|
|
7
6
|
/**
|
|
8
7
|
* Internal dependencies
|
|
@@ -16,7 +15,6 @@ export const storeConfig = {
|
|
|
16
15
|
reducer,
|
|
17
16
|
actions,
|
|
18
17
|
selectors,
|
|
19
|
-
controls,
|
|
20
18
|
persist: [ 'preferences' ],
|
|
21
19
|
};
|
|
22
20
|
|
package/src/store/selectors.js
CHANGED
|
@@ -98,6 +98,8 @@ export const getSettings = createSelector(
|
|
|
98
98
|
hasFixedToolbar: isFeatureActive( state, 'fixedToolbar' ),
|
|
99
99
|
__experimentalSetIsInserterOpened: setIsInserterOpen,
|
|
100
100
|
__experimentalReusableBlocks: getReusableBlocks( state ),
|
|
101
|
+
__experimentalPreferPatternsOnRoot:
|
|
102
|
+
'wp_template' === getEditedPostType( state ),
|
|
101
103
|
};
|
|
102
104
|
|
|
103
105
|
const canUserCreateMedia = getCanUserCreateMedia( state );
|
|
@@ -120,6 +122,7 @@ export const getSettings = createSelector(
|
|
|
120
122
|
isFeatureActive( state, 'focusMode' ),
|
|
121
123
|
isFeatureActive( state, 'fixedToolbar' ),
|
|
122
124
|
getReusableBlocks( state ),
|
|
125
|
+
getEditedPostType( state ),
|
|
123
126
|
]
|
|
124
127
|
);
|
|
125
128
|
|
|
@@ -1,129 +1,223 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import apiFetch from '@wordpress/api-fetch';
|
|
5
|
+
import { store as blockEditorStore } from '@wordpress/block-editor';
|
|
6
|
+
import { store as coreStore } from '@wordpress/core-data';
|
|
7
|
+
import { createRegistry } from '@wordpress/data';
|
|
8
|
+
import { store as interfaceStore } from '@wordpress/interface';
|
|
9
|
+
import { store as noticesStore } from '@wordpress/notices';
|
|
10
|
+
|
|
1
11
|
/**
|
|
2
12
|
* Internal dependencies
|
|
3
13
|
*/
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
14
|
+
import { store as editSiteStore } from '..';
|
|
15
|
+
|
|
16
|
+
jest.useRealTimers();
|
|
17
|
+
|
|
18
|
+
const ENTITY_TYPES = {
|
|
19
|
+
wp_template: {
|
|
20
|
+
description: 'Templates to include in your theme.',
|
|
21
|
+
hierarchical: false,
|
|
22
|
+
name: 'Templates',
|
|
23
|
+
rest_base: 'templates',
|
|
24
|
+
rest_namespace: 'wp/v2',
|
|
25
|
+
slug: 'wp_template',
|
|
26
|
+
taxonomies: [],
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
function createRegistryWithStores() {
|
|
31
|
+
// create a registry
|
|
32
|
+
const registry = createRegistry();
|
|
33
|
+
|
|
34
|
+
// register stores
|
|
35
|
+
registry.register( blockEditorStore );
|
|
36
|
+
registry.register( coreStore );
|
|
37
|
+
registry.register( editSiteStore );
|
|
38
|
+
registry.register( interfaceStore );
|
|
39
|
+
registry.register( noticesStore );
|
|
40
|
+
|
|
41
|
+
return registry;
|
|
42
|
+
}
|
|
13
43
|
|
|
14
44
|
describe( 'actions', () => {
|
|
15
45
|
describe( 'toggleFeature', () => {
|
|
16
|
-
it( 'should
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
46
|
+
it( 'should toggle a feature flag', () => {
|
|
47
|
+
const registry = createRegistryWithStores();
|
|
48
|
+
|
|
49
|
+
registry.dispatch( editSiteStore ).toggleFeature( 'name' );
|
|
50
|
+
expect(
|
|
51
|
+
registry.select( editSiteStore ).isFeatureActive( 'name' )
|
|
52
|
+
).toBe( true );
|
|
22
53
|
} );
|
|
23
54
|
} );
|
|
24
55
|
|
|
25
56
|
describe( 'setTemplate', () => {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
57
|
+
const ID = 1;
|
|
58
|
+
const SLUG = 'archive';
|
|
59
|
+
|
|
60
|
+
it( 'should set the template when slug is provided', async () => {
|
|
61
|
+
const registry = createRegistryWithStores();
|
|
62
|
+
|
|
63
|
+
await registry.dispatch( editSiteStore ).setTemplate( ID, SLUG );
|
|
64
|
+
|
|
65
|
+
const select = registry.select( editSiteStore );
|
|
66
|
+
expect( select.getEditedPostId() ).toBe( ID );
|
|
67
|
+
expect( select.getPage().context.templateSlug ).toBe( SLUG );
|
|
35
68
|
} );
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
69
|
+
|
|
70
|
+
it( 'should set the template by fetching the template slug', async () => {
|
|
71
|
+
const registry = createRegistryWithStores();
|
|
72
|
+
|
|
73
|
+
apiFetch.setFetchHandler( async ( options ) => {
|
|
74
|
+
const { method = 'GET', path } = options;
|
|
75
|
+
if ( method === 'GET' ) {
|
|
76
|
+
if ( path.startsWith( '/wp/v2/types' ) ) {
|
|
77
|
+
return ENTITY_TYPES;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if ( path.startsWith( `/wp/v2/templates/${ ID }` ) ) {
|
|
81
|
+
return { id: ID, slug: SLUG };
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
throw {
|
|
86
|
+
code: 'unknown_path',
|
|
87
|
+
message: `Unknown path: ${ method } ${ path }`,
|
|
88
|
+
};
|
|
50
89
|
} );
|
|
90
|
+
|
|
91
|
+
await registry.dispatch( editSiteStore ).setTemplate( ID );
|
|
92
|
+
|
|
93
|
+
const select = registry.select( editSiteStore );
|
|
94
|
+
expect( select.getEditedPostId() ).toBe( ID );
|
|
95
|
+
expect( select.getPage().context.templateSlug ).toBe( SLUG );
|
|
51
96
|
} );
|
|
52
97
|
} );
|
|
53
98
|
|
|
54
99
|
describe( 'addTemplate', () => {
|
|
55
|
-
it( 'should
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
const
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
100
|
+
it( 'should issue a REST request to create the template and then set it', async () => {
|
|
101
|
+
const registry = createRegistryWithStores();
|
|
102
|
+
|
|
103
|
+
const ID = 1;
|
|
104
|
+
const SLUG = 'index';
|
|
105
|
+
|
|
106
|
+
apiFetch.setFetchHandler( async ( options ) => {
|
|
107
|
+
const { method = 'GET', path, data } = options;
|
|
108
|
+
|
|
109
|
+
if ( method === 'GET' && path.startsWith( '/wp/v2/types' ) ) {
|
|
110
|
+
return ENTITY_TYPES;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
if (
|
|
114
|
+
method === 'POST' &&
|
|
115
|
+
path.startsWith( '/wp/v2/templates' )
|
|
116
|
+
) {
|
|
117
|
+
return { id: ID, slug: data.slug };
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
throw {
|
|
121
|
+
code: 'unknown_path',
|
|
122
|
+
message: `Unknown path: ${ method } ${ path }`,
|
|
123
|
+
};
|
|
73
124
|
} );
|
|
125
|
+
|
|
126
|
+
await registry
|
|
127
|
+
.dispatch( editSiteStore )
|
|
128
|
+
.addTemplate( { slug: SLUG } );
|
|
129
|
+
|
|
130
|
+
const select = registry.select( editSiteStore );
|
|
131
|
+
expect( select.getEditedPostId() ).toBe( ID );
|
|
132
|
+
expect( select.getPage().context.templateSlug ).toBe( SLUG );
|
|
74
133
|
} );
|
|
75
134
|
} );
|
|
76
135
|
|
|
77
136
|
describe( 'setTemplatePart', () => {
|
|
78
|
-
it( 'should
|
|
79
|
-
const
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
137
|
+
it( 'should set template part', () => {
|
|
138
|
+
const registry = createRegistryWithStores();
|
|
139
|
+
|
|
140
|
+
const ID = 1;
|
|
141
|
+
registry.dispatch( editSiteStore ).setTemplatePart( ID );
|
|
142
|
+
|
|
143
|
+
const select = registry.select( editSiteStore );
|
|
144
|
+
expect( select.getEditedPostId() ).toBe( ID );
|
|
145
|
+
expect( select.getEditedPostType() ).toBe( 'wp_template_part' );
|
|
84
146
|
} );
|
|
85
147
|
} );
|
|
86
148
|
|
|
87
149
|
describe( 'setPage', () => {
|
|
88
|
-
it( 'should
|
|
89
|
-
const
|
|
90
|
-
|
|
91
|
-
const
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
150
|
+
it( 'should find the template and then set the page', async () => {
|
|
151
|
+
const registry = createRegistryWithStores();
|
|
152
|
+
|
|
153
|
+
const ID = 'emptytheme//single';
|
|
154
|
+
const SLUG = 'single';
|
|
155
|
+
|
|
156
|
+
window.fetch = async ( path ) => {
|
|
157
|
+
if ( path === '/?_wp-find-template=true' ) {
|
|
158
|
+
return {
|
|
159
|
+
json: async () => ( { data: { id: ID, slug: SLUG } } ),
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
throw {
|
|
164
|
+
code: 'unknown_path',
|
|
165
|
+
message: `Unknown path: ${ path }`,
|
|
166
|
+
};
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
apiFetch.setFetchHandler( async ( options ) => {
|
|
170
|
+
const { method = 'GET', path } = options;
|
|
171
|
+
|
|
172
|
+
if ( method === 'GET' ) {
|
|
173
|
+
if ( path.startsWith( '/wp/v2/types' ) ) {
|
|
174
|
+
return ENTITY_TYPES;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
if ( path.startsWith( `/wp/v2/templates/${ ID }` ) ) {
|
|
178
|
+
return { id: ID, slug: SLUG };
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
throw {
|
|
183
|
+
code: 'unknown_path',
|
|
184
|
+
message: `Unknown path: ${ method } ${ path }`,
|
|
185
|
+
};
|
|
102
186
|
} );
|
|
103
|
-
|
|
187
|
+
|
|
188
|
+
await registry.dispatch( editSiteStore ).setPage( { path: '/' } );
|
|
189
|
+
|
|
190
|
+
const select = registry.select( editSiteStore );
|
|
191
|
+
expect( select.getEditedPostId() ).toBe( 'emptytheme//single' );
|
|
192
|
+
expect( select.getEditedPostType() ).toBe( 'wp_template' );
|
|
193
|
+
expect( select.getPage().path ).toBe( '/' );
|
|
104
194
|
} );
|
|
105
195
|
} );
|
|
106
196
|
|
|
107
197
|
describe( 'setHomeTemplateId', () => {
|
|
108
|
-
it( 'should
|
|
109
|
-
const
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
198
|
+
it( 'should set the home template ID', () => {
|
|
199
|
+
const registry = createRegistryWithStores();
|
|
200
|
+
|
|
201
|
+
registry.dispatch( editSiteStore ).setHomeTemplateId( 90 );
|
|
202
|
+
expect( registry.select( editSiteStore ).getHomeTemplateId() ).toBe(
|
|
203
|
+
90
|
|
204
|
+
);
|
|
114
205
|
} );
|
|
115
206
|
} );
|
|
116
207
|
|
|
117
208
|
describe( 'setIsListViewOpened', () => {
|
|
118
|
-
it( 'should
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
209
|
+
it( 'should set the list view opened state', () => {
|
|
210
|
+
const registry = createRegistryWithStores();
|
|
211
|
+
|
|
212
|
+
registry.dispatch( editSiteStore ).setIsListViewOpened( true );
|
|
213
|
+
expect( registry.select( editSiteStore ).isListViewOpened() ).toBe(
|
|
214
|
+
true
|
|
215
|
+
);
|
|
216
|
+
|
|
217
|
+
registry.dispatch( editSiteStore ).setIsListViewOpened( false );
|
|
218
|
+
expect( registry.select( editSiteStore ).isListViewOpened() ).toBe(
|
|
219
|
+
false
|
|
220
|
+
);
|
|
127
221
|
} );
|
|
128
222
|
} );
|
|
129
223
|
} );
|
|
@@ -106,7 +106,11 @@ describe( 'selectors', () => {
|
|
|
106
106
|
it( "returns the settings when the user can't create media", () => {
|
|
107
107
|
canUser.mockReturnValueOnce( false );
|
|
108
108
|
canUser.mockReturnValueOnce( false );
|
|
109
|
-
const state = {
|
|
109
|
+
const state = {
|
|
110
|
+
settings: {},
|
|
111
|
+
preferences: {},
|
|
112
|
+
editedPost: { type: 'wp_template' },
|
|
113
|
+
};
|
|
110
114
|
const setInserterOpened = () => {};
|
|
111
115
|
expect( getSettings( state, setInserterOpened ) ).toEqual( {
|
|
112
116
|
outlineMode: true,
|
|
@@ -114,6 +118,7 @@ describe( 'selectors', () => {
|
|
|
114
118
|
hasFixedToolbar: false,
|
|
115
119
|
__experimentalSetIsInserterOpened: setInserterOpened,
|
|
116
120
|
__experimentalReusableBlocks: [],
|
|
121
|
+
__experimentalPreferPatternsOnRoot: true,
|
|
117
122
|
} );
|
|
118
123
|
} );
|
|
119
124
|
|
|
@@ -126,6 +131,7 @@ describe( 'selectors', () => {
|
|
|
126
131
|
fixedToolbar: true,
|
|
127
132
|
},
|
|
128
133
|
},
|
|
134
|
+
editedPost: { type: 'wp_template_part' },
|
|
129
135
|
};
|
|
130
136
|
const setInserterOpened = () => {};
|
|
131
137
|
|
|
@@ -137,6 +143,7 @@ describe( 'selectors', () => {
|
|
|
137
143
|
__experimentalSetIsInserterOpened: setInserterOpened,
|
|
138
144
|
__experimentalReusableBlocks: [],
|
|
139
145
|
mediaUpload: expect.any( Function ),
|
|
146
|
+
__experimentalPreferPatternsOnRoot: false,
|
|
140
147
|
} );
|
|
141
148
|
} );
|
|
142
149
|
} );
|