@wordpress/editor 12.4.0 → 12.5.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 (50) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/build/components/entities-saved-states/entity-type-list.js +11 -5
  3. package/build/components/entities-saved-states/entity-type-list.js.map +1 -1
  4. package/build/components/post-excerpt/index.js +1 -1
  5. package/build/components/post-excerpt/index.js.map +1 -1
  6. package/build/components/provider/use-block-editor-settings.js +15 -2
  7. package/build/components/provider/use-block-editor-settings.js.map +1 -1
  8. package/build/store/actions.js +27 -26
  9. package/build/store/actions.js.map +1 -1
  10. package/build/store/defaults.js +2 -8
  11. package/build/store/defaults.js.map +1 -1
  12. package/build/store/index.js +3 -8
  13. package/build/store/index.js.map +1 -1
  14. package/build/store/reducer.js +0 -30
  15. package/build/store/reducer.js.map +1 -1
  16. package/build/store/reducer.native.js +0 -1
  17. package/build/store/reducer.native.js.map +1 -1
  18. package/build/store/selectors.js +4 -11
  19. package/build/store/selectors.js.map +1 -1
  20. package/build-module/components/entities-saved-states/entity-type-list.js +12 -6
  21. package/build-module/components/entities-saved-states/entity-type-list.js.map +1 -1
  22. package/build-module/components/post-excerpt/index.js +1 -1
  23. package/build-module/components/post-excerpt/index.js.map +1 -1
  24. package/build-module/components/provider/use-block-editor-settings.js +15 -2
  25. package/build-module/components/provider/use-block-editor-settings.js.map +1 -1
  26. package/build-module/store/actions.js +21 -22
  27. package/build-module/store/actions.js.map +1 -1
  28. package/build-module/store/defaults.js +0 -5
  29. package/build-module/store/defaults.js.map +1 -1
  30. package/build-module/store/index.js +3 -8
  31. package/build-module/store/index.js.map +1 -1
  32. package/build-module/store/reducer.js +1 -29
  33. package/build-module/store/reducer.js.map +1 -1
  34. package/build-module/store/reducer.native.js +1 -2
  35. package/build-module/store/reducer.native.js.map +1 -1
  36. package/build-module/store/selectors.js +2 -10
  37. package/build-module/store/selectors.js.map +1 -1
  38. package/package.json +27 -26
  39. package/src/components/entities-saved-states/entity-type-list.js +15 -16
  40. package/src/components/post-excerpt/index.js +3 -1
  41. package/src/components/provider/use-block-editor-settings.js +22 -3
  42. package/src/store/actions.js +13 -16
  43. package/src/store/defaults.js +0 -5
  44. package/src/store/index.js +2 -8
  45. package/src/store/reducer.js +1 -28
  46. package/src/store/reducer.native.js +0 -2
  47. package/src/store/selectors.js +8 -9
  48. package/src/store/test/actions.js +37 -0
  49. package/src/store/test/reducer.js +0 -31
  50. package/src/store/test/selectors.js +0 -35
@@ -61,6 +61,22 @@ function useBlockEditorSettings( settings, hasTemplate ) {
61
61
  };
62
62
  }, [] );
63
63
 
64
+ const {
65
+ __experimentalBlockPatterns: settingsBlockPatterns,
66
+ __experimentalBlockPatternCategories: settingsBlockPatternCategories,
67
+ } = settings;
68
+
69
+ const { blockPatterns, blockPatternCategories } = useSelect(
70
+ ( select ) => ( {
71
+ blockPatterns:
72
+ settingsBlockPatterns ?? select( coreStore ).getBlockPatterns(),
73
+ blockPatternCategories:
74
+ settingsBlockPatternCategories ??
75
+ select( coreStore ).getBlockPatternCategories(),
76
+ } ),
77
+ [ settingsBlockPatterns, settingsBlockPatternCategories ]
78
+ );
79
+
64
80
  const { undo } = useDispatch( editorStore );
65
81
 
66
82
  const { saveEntityRecord } = useDispatch( coreStore );
@@ -85,17 +101,15 @@ function useBlockEditorSettings( settings, hasTemplate ) {
85
101
  () => ( {
86
102
  ...pick( settings, [
87
103
  '__experimentalBlockDirectory',
88
- '__experimentalBlockPatternCategories',
89
- '__experimentalBlockPatterns',
90
104
  '__experimentalDiscussionSettings',
91
105
  '__experimentalFeatures',
92
106
  '__experimentalPreferredStyleVariations',
93
107
  '__experimentalSetIsInserterOpened',
94
- '__experimentalGenerateAnchors',
95
108
  '__unstableGalleryWithImageBlocks',
96
109
  'alignWide',
97
110
  'allowedBlockTypes',
98
111
  'bodyPlaceholder',
112
+ 'canLockBlocks',
99
113
  'codeEditingEnabled',
100
114
  'colors',
101
115
  'disableCustomColors',
@@ -107,6 +121,7 @@ function useBlockEditorSettings( settings, hasTemplate ) {
107
121
  'focusMode',
108
122
  'fontSizes',
109
123
  'gradients',
124
+ 'generateAnchors',
110
125
  'hasFixedToolbar',
111
126
  'hasReducedUI',
112
127
  'imageDefaultSize',
@@ -127,6 +142,8 @@ function useBlockEditorSettings( settings, hasTemplate ) {
127
142
  ] ),
128
143
  mediaUpload: hasUploadPermissions ? mediaUpload : undefined,
129
144
  __experimentalReusableBlocks: reusableBlocks,
145
+ __experimentalBlockPatterns: blockPatterns,
146
+ __experimentalBlockPatternCategories: blockPatternCategories,
130
147
  __experimentalFetchLinkSuggestions: ( search, searchOptions ) =>
131
148
  fetchLinkSuggestions( search, searchOptions, settings ),
132
149
  __experimentalFetchRichUrlData: fetchUrlData,
@@ -142,6 +159,8 @@ function useBlockEditorSettings( settings, hasTemplate ) {
142
159
  settings,
143
160
  hasUploadPermissions,
144
161
  reusableBlocks,
162
+ blockPatterns,
163
+ blockPatternCategories,
145
164
  canUseUnfilteredHTML,
146
165
  undo,
147
166
  hasTemplate,
@@ -16,6 +16,7 @@ import {
16
16
  import { store as noticesStore } from '@wordpress/notices';
17
17
  import { store as coreStore } from '@wordpress/core-data';
18
18
  import { store as blockEditorStore } from '@wordpress/block-editor';
19
+ import { store as preferencesStore } from '@wordpress/preferences';
19
20
 
20
21
  /**
21
22
  * Internal dependencies
@@ -320,26 +321,22 @@ export function updatePostLock( lock ) {
320
321
  }
321
322
 
322
323
  /**
323
- * Action that enables the publish sidebar.
324
- *
325
- * @return {Object} Action object
324
+ * Enable the publish sidebar.
326
325
  */
327
- export function enablePublishSidebar() {
328
- return {
329
- type: 'ENABLE_PUBLISH_SIDEBAR',
330
- };
331
- }
326
+ export const enablePublishSidebar = () => ( { registry } ) => {
327
+ registry
328
+ .dispatch( preferencesStore )
329
+ .set( 'core/edit-post', 'isPublishSidebarEnabled', true );
330
+ };
332
331
 
333
332
  /**
334
- * Action that disables the publish sidebar.
335
- *
336
- * @return {Object} Action object
333
+ * Disables the publish sidebar.
337
334
  */
338
- export function disablePublishSidebar() {
339
- return {
340
- type: 'DISABLE_PUBLISH_SIDEBAR',
341
- };
342
- }
335
+ export const disablePublishSidebar = () => ( { registry } ) => {
336
+ registry
337
+ .dispatch( preferencesStore )
338
+ .set( 'core/edit-post', 'isPublishSidebarEnabled', false );
339
+ };
343
340
 
344
341
  /**
345
342
  * Action that locks post saving.
@@ -3,11 +3,6 @@
3
3
  */
4
4
  import { SETTINGS_DEFAULTS } from '@wordpress/block-editor';
5
5
 
6
- export const PREFERENCES_DEFAULTS = {
7
- insertUsage: {}, // Should be kept for backward compatibility, see: https://github.com/WordPress/gutenberg/issues/14580.
8
- isPublishSidebarEnabled: true,
9
- };
10
-
11
6
  /**
12
7
  * The default post editor settings.
13
8
  *
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * WordPress dependencies
3
3
  */
4
- import { createReduxStore, registerStore } from '@wordpress/data';
4
+ import { createReduxStore, register } from '@wordpress/data';
5
5
 
6
6
  /**
7
7
  * Internal dependencies
@@ -33,12 +33,6 @@ export const storeConfig = {
33
33
  */
34
34
  export const store = createReduxStore( STORE_NAME, {
35
35
  ...storeConfig,
36
- persist: [ 'preferences' ],
37
36
  } );
38
37
 
39
- // Once we build a more generic persistence plugin that works across types of stores
40
- // we'd be able to replace this with a register call.
41
- registerStore( STORE_NAME, {
42
- ...storeConfig,
43
- persist: [ 'preferences' ],
44
- } );
38
+ register( store );
@@ -11,7 +11,7 @@ import { combineReducers } from '@wordpress/data';
11
11
  /**
12
12
  * Internal dependencies
13
13
  */
14
- import { PREFERENCES_DEFAULTS, EDITOR_SETTINGS_DEFAULTS } from './defaults';
14
+ import { EDITOR_SETTINGS_DEFAULTS } from './defaults';
15
15
 
16
16
  /**
17
17
  * Returns a post attribute value, flattening nested rendered content using its
@@ -119,32 +119,6 @@ export function template( state = { isValid: true }, action ) {
119
119
  return state;
120
120
  }
121
121
 
122
- /**
123
- * Reducer returning the user preferences.
124
- *
125
- * @param {Object} state Current state.
126
- * @param {Object} action Dispatched action.
127
- *
128
- * @return {string} Updated state.
129
- */
130
- export function preferences( state = PREFERENCES_DEFAULTS, action ) {
131
- switch ( action.type ) {
132
- case 'ENABLE_PUBLISH_SIDEBAR':
133
- return {
134
- ...state,
135
- isPublishSidebarEnabled: true,
136
- };
137
-
138
- case 'DISABLE_PUBLISH_SIDEBAR':
139
- return {
140
- ...state,
141
- isPublishSidebarEnabled: false,
142
- };
143
- }
144
-
145
- return state;
146
- }
147
-
148
122
  /**
149
123
  * Reducer returning current network request state (whether a request to
150
124
  * the WP REST API is in progress, successful, or failed).
@@ -282,7 +256,6 @@ export function editorSettings( state = EDITOR_SETTINGS_DEFAULTS, action ) {
282
256
  export default combineReducers( {
283
257
  postId,
284
258
  postType,
285
- preferences,
286
259
  saving,
287
260
  postLock,
288
261
  template,
@@ -9,7 +9,6 @@ import { combineReducers } from '@wordpress/data';
9
9
  import {
10
10
  postId,
11
11
  postType,
12
- preferences,
13
12
  saving,
14
13
  postLock,
15
14
  postSavingLock,
@@ -84,7 +83,6 @@ export default combineReducers( {
84
83
  postId,
85
84
  postType,
86
85
  postTitle,
87
- preferences,
88
86
  saving,
89
87
  postLock,
90
88
  postSavingLock,
@@ -20,11 +20,11 @@ import { Platform } from '@wordpress/element';
20
20
  import { layout } from '@wordpress/icons';
21
21
  import { store as blockEditorStore } from '@wordpress/block-editor';
22
22
  import { store as coreStore } from '@wordpress/core-data';
23
+ import { store as preferencesStore } from '@wordpress/preferences';
23
24
 
24
25
  /**
25
26
  * Internal dependencies
26
27
  */
27
- import { PREFERENCES_DEFAULTS } from './defaults';
28
28
  import {
29
29
  EDIT_MERGE_PROPERTIES,
30
30
  PERMALINK_POSTNAME_REGEX,
@@ -1093,16 +1093,15 @@ export function canUserUseUnfilteredHTML( state ) {
1093
1093
  * Returns whether the pre-publish panel should be shown
1094
1094
  * or skipped when the user clicks the "publish" button.
1095
1095
  *
1096
- * @param {Object} state Global application state.
1097
- *
1098
1096
  * @return {boolean} Whether the pre-publish panel should be shown or not.
1099
1097
  */
1100
- export function isPublishSidebarEnabled( state ) {
1101
- if ( state.preferences.hasOwnProperty( 'isPublishSidebarEnabled' ) ) {
1102
- return state.preferences.isPublishSidebarEnabled;
1103
- }
1104
- return PREFERENCES_DEFAULTS.isPublishSidebarEnabled;
1105
- }
1098
+ export const isPublishSidebarEnabled = createRegistrySelector(
1099
+ ( select ) => () =>
1100
+ !! select( preferencesStore ).get(
1101
+ 'core/edit-post',
1102
+ 'isPublishSidebarEnabled'
1103
+ )
1104
+ );
1106
1105
 
1107
1106
  /**
1108
1107
  * Return the current block list.
@@ -6,6 +6,7 @@ import { store as blockEditorStore } from '@wordpress/block-editor';
6
6
  import { store as coreStore } from '@wordpress/core-data';
7
7
  import { createRegistry } from '@wordpress/data';
8
8
  import { store as noticesStore } from '@wordpress/notices';
9
+ import { store as preferencesStore } from '@wordpress/preferences';
9
10
 
10
11
  /**
11
12
  * Internal dependencies
@@ -46,6 +47,7 @@ function createRegistryWithStores() {
46
47
  registry.register( coreStore );
47
48
  registry.register( editorStore );
48
49
  registry.register( noticesStore );
50
+ registry.register( preferencesStore );
49
51
 
50
52
  // Register post type entity.
51
53
  registry.dispatch( coreStore ).addEntities( [ postTypeConfig ] );
@@ -349,4 +351,39 @@ describe( 'Editor actions', () => {
349
351
  } );
350
352
  } );
351
353
  } );
354
+
355
+ describe( 'enablePublishSidebar', () => {
356
+ it( 'enables the publish sidebar', () => {
357
+ const registry = createRegistryWithStores();
358
+
359
+ // Starts off as `undefined` as a default hasn't been set.
360
+ expect(
361
+ registry.select( editorStore ).isPublishSidebarEnabled()
362
+ ).toBe( false );
363
+
364
+ registry.dispatch( editorStore ).enablePublishSidebar();
365
+
366
+ expect(
367
+ registry.select( editorStore ).isPublishSidebarEnabled()
368
+ ).toBe( true );
369
+ } );
370
+ } );
371
+
372
+ describe( 'disablePublishSidebar', () => {
373
+ it( 'disables the publish sidebar', () => {
374
+ const registry = createRegistryWithStores();
375
+
376
+ // Enable it to start with so that can test it flipping from `true` to `false`.
377
+ registry.dispatch( editorStore ).enablePublishSidebar();
378
+ expect(
379
+ registry.select( editorStore ).isPublishSidebarEnabled()
380
+ ).toBe( true );
381
+
382
+ registry.dispatch( editorStore ).disablePublishSidebar();
383
+
384
+ expect(
385
+ registry.select( editorStore ).isPublishSidebarEnabled()
386
+ ).toBe( false );
387
+ } );
388
+ } );
352
389
  } );
@@ -11,7 +11,6 @@ import {
11
11
  isUpdatingSamePostProperty,
12
12
  shouldOverwriteState,
13
13
  getPostRawValue,
14
- preferences,
15
14
  saving,
16
15
  postSavingLock,
17
16
  postAutosavingLock,
@@ -163,36 +162,6 @@ describe( 'state', () => {
163
162
  } );
164
163
  } );
165
164
 
166
- describe( 'preferences()', () => {
167
- it( 'should apply all defaults', () => {
168
- const state = preferences( undefined, {} );
169
- expect( state ).toEqual( {
170
- insertUsage: {},
171
- isPublishSidebarEnabled: true,
172
- } );
173
- } );
174
-
175
- it( 'should disable the publish sidebar', () => {
176
- const original = deepFreeze( preferences( undefined, {} ) );
177
- const state = preferences( original, {
178
- type: 'DISABLE_PUBLISH_SIDEBAR',
179
- } );
180
-
181
- expect( state.isPublishSidebarEnabled ).toBe( false );
182
- } );
183
-
184
- it( 'should enable the publish sidebar', () => {
185
- const original = deepFreeze(
186
- preferences( { isPublishSidebarEnabled: false }, {} )
187
- );
188
- const state = preferences( original, {
189
- type: 'ENABLE_PUBLISH_SIDEBAR',
190
- } );
191
-
192
- expect( state.isPublishSidebarEnabled ).toBe( true );
193
- } );
194
- } );
195
-
196
165
  describe( 'saving()', () => {
197
166
  it( 'should update when a request is started', () => {
198
167
  const state = saving( null, {
@@ -22,7 +22,6 @@ import { layout, footer, header } from '@wordpress/icons';
22
22
  * Internal dependencies
23
23
  */
24
24
  import * as _selectors from '../selectors';
25
- import { PREFERENCES_DEFAULTS } from '../defaults';
26
25
 
27
26
  const selectors = { ..._selectors };
28
27
  const selectorNames = Object.keys( selectors );
@@ -182,7 +181,6 @@ const {
182
181
  didPostSaveRequestFail,
183
182
  getSuggestedPostFormat,
184
183
  getEditedPostContent,
185
- isPublishSidebarEnabled,
186
184
  isPermalinkEditable,
187
185
  getPermalink,
188
186
  getPermalinkParts,
@@ -2570,39 +2568,6 @@ describe( 'selectors', () => {
2570
2568
  } );
2571
2569
  } );
2572
2570
 
2573
- describe( 'isPublishSidebarEnabled', () => {
2574
- it( 'should return the value on state if it is thruthy', () => {
2575
- const state = {
2576
- preferences: {
2577
- isPublishSidebarEnabled: true,
2578
- },
2579
- };
2580
- expect( isPublishSidebarEnabled( state ) ).toBe(
2581
- state.preferences.isPublishSidebarEnabled
2582
- );
2583
- } );
2584
-
2585
- it( 'should return the value on state if it is falsy', () => {
2586
- const state = {
2587
- preferences: {
2588
- isPublishSidebarEnabled: false,
2589
- },
2590
- };
2591
- expect( isPublishSidebarEnabled( state ) ).toBe(
2592
- state.preferences.isPublishSidebarEnabled
2593
- );
2594
- } );
2595
-
2596
- it( 'should return the default value if there is no isPublishSidebarEnabled key on state', () => {
2597
- const state = {
2598
- preferences: {},
2599
- };
2600
- expect( isPublishSidebarEnabled( state ) ).toBe(
2601
- PREFERENCES_DEFAULTS.isPublishSidebarEnabled
2602
- );
2603
- } );
2604
- } );
2605
-
2606
2571
  describe( 'isPermalinkEditable', () => {
2607
2572
  it( 'should be false if there is no permalink', () => {
2608
2573
  const state = {