@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.
Files changed (81) hide show
  1. package/build/components/add-new-template/new-template-part.js +4 -1
  2. package/build/components/add-new-template/new-template-part.js.map +1 -1
  3. package/build/components/error-boundary/index.js +11 -27
  4. package/build/components/error-boundary/index.js.map +1 -1
  5. package/build/components/error-boundary/warning.js +70 -0
  6. package/build/components/error-boundary/warning.js.map +1 -0
  7. package/build/components/global-styles/navigation-button.js +7 -27
  8. package/build/components/global-styles/navigation-button.js.map +1 -1
  9. package/build/components/global-styles/typography-panel.js +5 -2
  10. package/build/components/global-styles/typography-panel.js.map +1 -1
  11. package/build/components/global-styles/use-global-styles-output.js +21 -4
  12. package/build/components/global-styles/use-global-styles-output.js.map +1 -1
  13. package/build/components/list/table.js +3 -1
  14. package/build/components/list/table.js.map +1 -1
  15. package/build/components/navigation-sidebar/navigation-toggle/index.js +15 -4
  16. package/build/components/navigation-sidebar/navigation-toggle/index.js.map +1 -1
  17. package/build/components/routes/redirect-to-homepage.js +22 -3
  18. package/build/components/routes/redirect-to-homepage.js.map +1 -1
  19. package/build/components/secondary-sidebar/list-view-sidebar.js +0 -11
  20. package/build/components/secondary-sidebar/list-view-sidebar.js.map +1 -1
  21. package/build/components/template-part-converter/convert-to-template-part.js +4 -1
  22. package/build/components/template-part-converter/convert-to-template-part.js.map +1 -1
  23. package/build/index.js +15 -1
  24. package/build/index.js.map +1 -1
  25. package/build/store/actions.js +191 -155
  26. package/build/store/actions.js.map +1 -1
  27. package/build/store/index.js +0 -3
  28. package/build/store/index.js.map +1 -1
  29. package/build/store/selectors.js +3 -2
  30. package/build/store/selectors.js.map +1 -1
  31. package/build-module/components/add-new-template/new-template-part.js +4 -1
  32. package/build-module/components/add-new-template/new-template-part.js.map +1 -1
  33. package/build-module/components/error-boundary/index.js +9 -26
  34. package/build-module/components/error-boundary/index.js.map +1 -1
  35. package/build-module/components/error-boundary/warning.js +60 -0
  36. package/build-module/components/error-boundary/warning.js.map +1 -0
  37. package/build-module/components/global-styles/navigation-button.js +8 -28
  38. package/build-module/components/global-styles/navigation-button.js.map +1 -1
  39. package/build-module/components/global-styles/typography-panel.js +6 -3
  40. package/build-module/components/global-styles/typography-panel.js.map +1 -1
  41. package/build-module/components/global-styles/use-global-styles-output.js +20 -4
  42. package/build-module/components/global-styles/use-global-styles-output.js.map +1 -1
  43. package/build-module/components/list/table.js +2 -1
  44. package/build-module/components/list/table.js.map +1 -1
  45. package/build-module/components/navigation-sidebar/navigation-toggle/index.js +12 -4
  46. package/build-module/components/navigation-sidebar/navigation-toggle/index.js.map +1 -1
  47. package/build-module/components/routes/redirect-to-homepage.js +22 -3
  48. package/build-module/components/routes/redirect-to-homepage.js.map +1 -1
  49. package/build-module/components/secondary-sidebar/list-view-sidebar.js +1 -12
  50. package/build-module/components/secondary-sidebar/list-view-sidebar.js.map +1 -1
  51. package/build-module/components/template-part-converter/convert-to-template-part.js +4 -1
  52. package/build-module/components/template-part-converter/convert-to-template-part.js.map +1 -1
  53. package/build-module/index.js +13 -1
  54. package/build-module/index.js.map +1 -1
  55. package/build-module/store/actions.js +170 -145
  56. package/build-module/store/actions.js.map +1 -1
  57. package/build-module/store/index.js +0 -2
  58. package/build-module/store/index.js.map +1 -1
  59. package/build-module/store/selectors.js +3 -2
  60. package/build-module/store/selectors.js.map +1 -1
  61. package/build-style/style-rtl.css +11 -10
  62. package/build-style/style.css +11 -10
  63. package/package.json +18 -18
  64. package/src/components/add-new-template/new-template-part.js +7 -1
  65. package/src/components/error-boundary/index.js +11 -28
  66. package/src/components/error-boundary/warning.js +59 -0
  67. package/src/components/global-styles/navigation-button.js +6 -25
  68. package/src/components/global-styles/typography-panel.js +12 -5
  69. package/src/components/global-styles/use-global-styles-output.js +19 -3
  70. package/src/components/list/table.js +5 -2
  71. package/src/components/navigation-sidebar/navigation-toggle/index.js +13 -4
  72. package/src/components/navigation-sidebar/navigation-toggle/style.scss +32 -31
  73. package/src/components/routes/redirect-to-homepage.js +27 -4
  74. package/src/components/secondary-sidebar/list-view-sidebar.js +1 -11
  75. package/src/components/template-part-converter/convert-to-template-part.js +6 -1
  76. package/src/index.js +17 -1
  77. package/src/store/actions.js +161 -205
  78. package/src/store/index.js +0 -2
  79. package/src/store/selectors.js +3 -0
  80. package/src/store/test/actions.js +186 -92
  81. package/src/store/test/selectors.js +8 -1
@@ -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
 
@@ -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
- toggleFeature,
6
- setTemplate,
7
- addTemplate,
8
- setTemplatePart,
9
- setPage,
10
- setHomeTemplateId,
11
- setIsListViewOpened,
12
- } from '../actions';
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 return TOGGLE_FEATURE action', () => {
17
- const feature = 'name';
18
- expect( toggleFeature( feature ) ).toEqual( {
19
- type: 'TOGGLE_FEATURE',
20
- feature,
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
- it( 'should return the SET_TEMPLATE action when slug is provided', () => {
27
- const templateId = 1;
28
- const templateSlug = 'archive';
29
- const it = setTemplate( templateId, templateSlug );
30
- expect( it.next().value ).toEqual( {
31
- type: 'SET_TEMPLATE',
32
- templateId,
33
- page: { context: { templateSlug } },
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
- it( 'should return the SET_TEMPLATE by getting the template slug', () => {
37
- const templateId = 1;
38
- const template = { slug: 'index' };
39
- const it = setTemplate( templateId );
40
- expect( it.next().value ).toEqual( {
41
- type: '@@data/RESOLVE_SELECT',
42
- storeKey: 'core',
43
- selectorName: 'getEntityRecord',
44
- args: [ 'postType', 'wp_template', templateId ],
45
- } );
46
- expect( it.next( template ).value ).toEqual( {
47
- type: 'SET_TEMPLATE',
48
- templateId,
49
- page: { context: { templateSlug: template.slug } },
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 yield the DISPATCH control to create the template and return the SET_TEMPLATE action', () => {
56
- const template = { slug: 'index' };
57
- const newTemplate = { id: 1, slug: 'index' };
58
-
59
- const it = addTemplate( template );
60
- expect( it.next().value ).toEqual( {
61
- type: '@@data/DISPATCH',
62
- storeKey: 'core',
63
- actionName: 'saveEntityRecord',
64
- args: [ 'postType', 'wp_template', template ],
65
- } );
66
- expect( it.next( newTemplate ) ).toEqual( {
67
- value: {
68
- type: 'SET_TEMPLATE',
69
- templateId: newTemplate.id,
70
- page: { context: { templateSlug: newTemplate.slug } },
71
- },
72
- done: true,
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 return the SET_TEMPLATE_PART action', () => {
79
- const templatePartId = 1;
80
- expect( setTemplatePart( templatePartId ) ).toEqual( {
81
- type: 'SET_TEMPLATE_PART',
82
- templatePartId,
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 yield the FIND_TEMPLATE control and return the SET_PAGE action', () => {
89
- const page = { path: '/' };
90
-
91
- const it = setPage( page );
92
- expect( it.next().value ).toEqual( {
93
- type: '@@data/RESOLVE_SELECT',
94
- storeKey: 'core',
95
- selectorName: '__experimentalGetTemplateForLink',
96
- args: [ page.path ],
97
- } );
98
- expect( it.next( { id: 'emptytheme//single' } ).value ).toEqual( {
99
- type: 'SET_PAGE',
100
- page,
101
- templateId: 'emptytheme//single',
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
- expect( it.next().done ).toBe( true );
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 return the SET_HOME_TEMPLATE action', () => {
109
- const homeTemplateId = 90;
110
- expect( setHomeTemplateId( homeTemplateId ) ).toEqual( {
111
- type: 'SET_HOME_TEMPLATE',
112
- homeTemplateId,
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 return the SET_IS_LIST_VIEW_OPENED action', () => {
119
- expect( setIsListViewOpened( true ) ).toEqual( {
120
- type: 'SET_IS_LIST_VIEW_OPENED',
121
- isOpen: true,
122
- } );
123
- expect( setIsListViewOpened( false ) ).toEqual( {
124
- type: 'SET_IS_LIST_VIEW_OPENED',
125
- isOpen: false,
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 = { settings: {}, preferences: {} };
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
  } );