@wordpress/edit-post 5.0.1 → 5.0.5

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 (162) hide show
  1. package/README.md +2 -5
  2. package/build/components/header/fullscreen-mode-close/index.js +19 -3
  3. package/build/components/header/fullscreen-mode-close/index.js.map +1 -1
  4. package/build/components/header/header-toolbar/index.native.js +10 -3
  5. package/build/components/header/header-toolbar/index.native.js.map +1 -1
  6. package/build/components/header/more-menu/index.js +3 -14
  7. package/build/components/header/more-menu/index.js.map +1 -1
  8. package/build/components/header/template-title/index.js +1 -1
  9. package/build/components/header/template-title/index.js.map +1 -1
  10. package/build/components/header/writing-menu/index.js +7 -10
  11. package/build/components/header/writing-menu/index.js.map +1 -1
  12. package/build/components/keyboard-shortcut-help-modal/dynamic-shortcut.js +1 -1
  13. package/build/components/keyboard-shortcut-help-modal/dynamic-shortcut.js.map +1 -1
  14. package/build/components/keyboard-shortcut-help-modal/index.js +1 -3
  15. package/build/components/keyboard-shortcut-help-modal/index.js.map +1 -1
  16. package/build/components/keyboard-shortcuts/index.js +1 -8
  17. package/build/components/keyboard-shortcuts/index.js.map +1 -1
  18. package/build/components/layout/index.js +3 -5
  19. package/build/components/layout/index.js.map +1 -1
  20. package/build/components/layout/index.native.js +5 -1
  21. package/build/components/layout/index.native.js.map +1 -1
  22. package/build/components/meta-boxes/index.js +37 -20
  23. package/build/components/meta-boxes/index.js.map +1 -1
  24. package/build/components/preferences-modal/index.js +56 -18
  25. package/build/components/preferences-modal/index.js.map +1 -1
  26. package/build/components/secondary-sidebar/inserter-sidebar.js +2 -1
  27. package/build/components/secondary-sidebar/inserter-sidebar.js.map +1 -1
  28. package/build/components/secondary-sidebar/list-view-sidebar.js +1 -0
  29. package/build/components/secondary-sidebar/list-view-sidebar.js.map +1 -1
  30. package/build/components/sidebar/plugin-sidebar/index.js +1 -1
  31. package/build/components/sidebar/plugin-sidebar/index.js.map +1 -1
  32. package/build/components/sidebar/post-link/index.js +1 -1
  33. package/build/components/sidebar/post-link/index.js.map +1 -1
  34. package/build/components/sidebar/template/actions.js +6 -1
  35. package/build/components/sidebar/template/actions.js.map +1 -1
  36. package/build/components/sidebar/template/index.js +5 -2
  37. package/build/components/sidebar/template/index.js.map +1 -1
  38. package/build/components/sidebar/template-summary/index.js +2 -1
  39. package/build/components/sidebar/template-summary/index.js.map +1 -1
  40. package/build/components/visual-editor/index.js +6 -4
  41. package/build/components/visual-editor/index.js.map +1 -1
  42. package/build/editor.js +17 -5
  43. package/build/editor.js.map +1 -1
  44. package/build/hooks/validate-multiple-use/index.js +1 -1
  45. package/build/hooks/validate-multiple-use/index.js.map +1 -1
  46. package/build/index.js +28 -12
  47. package/build/index.js.map +1 -1
  48. package/build/plugins/welcome-guide-menu-item/index.js +6 -7
  49. package/build/plugins/welcome-guide-menu-item/index.js.map +1 -1
  50. package/build/store/actions.js +68 -59
  51. package/build/store/actions.js.map +1 -1
  52. package/build/store/defaults.js +0 -9
  53. package/build/store/defaults.js.map +1 -1
  54. package/build/store/reducer.js +20 -11
  55. package/build/store/reducer.js.map +1 -1
  56. package/build/store/selectors.js +24 -10
  57. package/build/store/selectors.js.map +1 -1
  58. package/build-module/components/header/fullscreen-mode-close/index.js +19 -4
  59. package/build-module/components/header/fullscreen-mode-close/index.js.map +1 -1
  60. package/build-module/components/header/header-toolbar/index.native.js +11 -4
  61. package/build-module/components/header/header-toolbar/index.native.js.map +1 -1
  62. package/build-module/components/header/more-menu/index.js +5 -15
  63. package/build-module/components/header/more-menu/index.js.map +1 -1
  64. package/build-module/components/header/template-title/index.js +1 -1
  65. package/build-module/components/header/template-title/index.js.map +1 -1
  66. package/build-module/components/header/writing-menu/index.js +7 -8
  67. package/build-module/components/header/writing-menu/index.js.map +1 -1
  68. package/build-module/components/keyboard-shortcut-help-modal/dynamic-shortcut.js +1 -1
  69. package/build-module/components/keyboard-shortcut-help-modal/dynamic-shortcut.js.map +1 -1
  70. package/build-module/components/keyboard-shortcut-help-modal/index.js +1 -3
  71. package/build-module/components/keyboard-shortcut-help-modal/index.js.map +1 -1
  72. package/build-module/components/keyboard-shortcuts/index.js +1 -8
  73. package/build-module/components/keyboard-shortcuts/index.js.map +1 -1
  74. package/build-module/components/layout/index.js +4 -6
  75. package/build-module/components/layout/index.js.map +1 -1
  76. package/build-module/components/layout/index.native.js +5 -1
  77. package/build-module/components/layout/index.native.js.map +1 -1
  78. package/build-module/components/meta-boxes/index.js +38 -20
  79. package/build-module/components/meta-boxes/index.js.map +1 -1
  80. package/build-module/components/preferences-modal/index.js +57 -20
  81. package/build-module/components/preferences-modal/index.js.map +1 -1
  82. package/build-module/components/secondary-sidebar/inserter-sidebar.js +2 -1
  83. package/build-module/components/secondary-sidebar/inserter-sidebar.js.map +1 -1
  84. package/build-module/components/secondary-sidebar/list-view-sidebar.js +1 -0
  85. package/build-module/components/secondary-sidebar/list-view-sidebar.js.map +1 -1
  86. package/build-module/components/sidebar/plugin-sidebar/index.js +1 -1
  87. package/build-module/components/sidebar/plugin-sidebar/index.js.map +1 -1
  88. package/build-module/components/sidebar/post-link/index.js +1 -1
  89. package/build-module/components/sidebar/post-link/index.js.map +1 -1
  90. package/build-module/components/sidebar/template/actions.js +6 -1
  91. package/build-module/components/sidebar/template/actions.js.map +1 -1
  92. package/build-module/components/sidebar/template/index.js +5 -2
  93. package/build-module/components/sidebar/template/index.js.map +1 -1
  94. package/build-module/components/sidebar/template-summary/index.js +2 -1
  95. package/build-module/components/sidebar/template-summary/index.js.map +1 -1
  96. package/build-module/components/visual-editor/index.js +6 -4
  97. package/build-module/components/visual-editor/index.js.map +1 -1
  98. package/build-module/editor.js +17 -6
  99. package/build-module/editor.js.map +1 -1
  100. package/build-module/hooks/validate-multiple-use/index.js +1 -1
  101. package/build-module/hooks/validate-multiple-use/index.js.map +1 -1
  102. package/build-module/index.js +18 -5
  103. package/build-module/index.js.map +1 -1
  104. package/build-module/plugins/welcome-guide-menu-item/index.js +7 -8
  105. package/build-module/plugins/welcome-guide-menu-item/index.js.map +1 -1
  106. package/build-module/store/actions.js +66 -59
  107. package/build-module/store/actions.js.map +1 -1
  108. package/build-module/store/defaults.js +0 -9
  109. package/build-module/store/defaults.js.map +1 -1
  110. package/build-module/store/reducer.js +20 -11
  111. package/build-module/store/reducer.js.map +1 -1
  112. package/build-module/store/selectors.js +20 -7
  113. package/build-module/store/selectors.js.map +1 -1
  114. package/build-style/style-rtl.css +68 -69
  115. package/build-style/style.css +68 -69
  116. package/package.json +27 -27
  117. package/src/components/header/fullscreen-mode-close/index.js +37 -15
  118. package/src/components/header/fullscreen-mode-close/style.scss +2 -2
  119. package/src/components/header/header-toolbar/index.native.js +8 -2
  120. package/src/components/header/more-menu/index.js +8 -13
  121. package/src/components/header/template-title/index.js +3 -1
  122. package/src/components/header/writing-menu/index.js +7 -8
  123. package/src/components/keyboard-shortcut-help-modal/dynamic-shortcut.js +15 -12
  124. package/src/components/keyboard-shortcut-help-modal/index.js +1 -3
  125. package/src/components/keyboard-shortcut-help-modal/test/__snapshots__/index.js.snap +2 -2
  126. package/src/components/keyboard-shortcuts/index.js +19 -32
  127. package/src/components/layout/index.js +4 -10
  128. package/src/components/layout/index.native.js +7 -1
  129. package/src/components/meta-boxes/index.js +35 -14
  130. package/src/components/preferences-modal/index.js +93 -30
  131. package/src/components/preferences-modal/style.scss +6 -56
  132. package/src/components/preferences-modal/test/__snapshots__/index.js.snap +334 -136
  133. package/src/components/secondary-sidebar/inserter-sidebar.js +1 -0
  134. package/src/components/secondary-sidebar/list-view-sidebar.js +1 -0
  135. package/src/components/sidebar/plugin-sidebar/index.js +1 -1
  136. package/src/components/sidebar/post-link/index.js +5 -1
  137. package/src/components/sidebar/template/actions.js +6 -1
  138. package/src/components/sidebar/template/index.js +5 -3
  139. package/src/components/sidebar/template-summary/index.js +1 -1
  140. package/src/components/sidebar/template-summary/style.scss +2 -1
  141. package/src/components/text-editor/style.scss +12 -22
  142. package/src/components/visual-editor/index.js +16 -10
  143. package/src/components/visual-editor/style.scss +4 -7
  144. package/src/components/welcome-guide/style.scss +5 -0
  145. package/src/editor.js +101 -79
  146. package/src/hooks/validate-multiple-use/index.js +1 -1
  147. package/src/index.js +18 -5
  148. package/src/plugins/welcome-guide-menu-item/index.js +7 -12
  149. package/src/store/actions.js +99 -80
  150. package/src/store/defaults.js +0 -9
  151. package/src/store/reducer.js +17 -10
  152. package/src/store/selectors.js +27 -7
  153. package/src/store/test/actions.js +0 -11
  154. package/src/store/test/reducer.js +0 -12
  155. package/src/store/test/selectors.js +0 -46
  156. package/build/components/header/feature-toggle/index.js +0 -76
  157. package/build/components/header/feature-toggle/index.js.map +0 -1
  158. package/build-module/components/header/feature-toggle/index.js +0 -60
  159. package/build-module/components/header/feature-toggle/index.js.map +0 -1
  160. package/src/components/header/feature-toggle/index.js +0 -61
  161. package/src/components/header/more-menu/test/__snapshots__/index.js.snap +0 -129
  162. package/src/components/header/more-menu/test/index.js +0 -17
@@ -9,7 +9,7 @@ import { castArray, reduce } from 'lodash';
9
9
  import { __ } from '@wordpress/i18n';
10
10
  import { apiFetch } from '@wordpress/data-controls';
11
11
  import { store as interfaceStore } from '@wordpress/interface';
12
- import { controls, dispatch, select, subscribe } from '@wordpress/data';
12
+ import { controls, select, subscribe, dispatch } from '@wordpress/data';
13
13
  import { speak } from '@wordpress/a11y';
14
14
  import { store as noticesStore } from '@wordpress/notices';
15
15
  import { store as coreStore } from '@wordpress/core-data';
@@ -30,7 +30,7 @@ import { store as editPostStore } from '.';
30
30
  */
31
31
  export function* openGeneralSidebar( name ) {
32
32
  yield controls.dispatch(
33
- interfaceStore.name,
33
+ interfaceStore,
34
34
  'enableComplementaryArea',
35
35
  editPostStore.name,
36
36
  name
@@ -44,7 +44,7 @@ export function* openGeneralSidebar( name ) {
44
44
  */
45
45
  export function* closeGeneralSidebar() {
46
46
  yield controls.dispatch(
47
- interfaceStore.name,
47
+ interfaceStore,
48
48
  'disableComplementaryArea',
49
49
  editPostStore.name
50
50
  );
@@ -153,17 +153,17 @@ export function removeEditorPanel( panelName ) {
153
153
  }
154
154
 
155
155
  /**
156
- * Returns an action object used to toggle a feature flag.
156
+ * Triggers an action used to toggle a feature flag.
157
157
  *
158
158
  * @param {string} feature Feature name.
159
- *
160
- * @return {Object} Action object.
161
159
  */
162
- export function toggleFeature( feature ) {
163
- return {
164
- type: 'TOGGLE_FEATURE',
165
- feature,
166
- };
160
+ export function* toggleFeature( feature ) {
161
+ yield controls.dispatch(
162
+ interfaceStore.name,
163
+ 'toggleFeature',
164
+ 'core/edit-post',
165
+ feature
166
+ );
167
167
  }
168
168
 
169
169
  export function* switchEditorMode( mode ) {
@@ -174,7 +174,7 @@ export function* switchEditorMode( mode ) {
174
174
 
175
175
  // Unselect blocks when we switch to the code editor.
176
176
  if ( mode !== 'visual' ) {
177
- yield controls.dispatch( blockEditorStore.name, 'clearSelectedBlock' );
177
+ yield controls.dispatch( blockEditorStore, 'clearSelectedBlock' );
178
178
  }
179
179
 
180
180
  const message =
@@ -185,17 +185,24 @@ export function* switchEditorMode( mode ) {
185
185
  }
186
186
 
187
187
  /**
188
- * Returns an action object used to toggle a plugin name flag.
188
+ * Triggers an action object used to toggle a plugin name flag.
189
189
  *
190
190
  * @param {string} pluginName Plugin name.
191
- *
192
- * @return {Object} Action object.
193
191
  */
194
- export function togglePinnedPluginItem( pluginName ) {
195
- return {
196
- type: 'TOGGLE_PINNED_PLUGIN_ITEM',
197
- pluginName,
198
- };
192
+ export function* togglePinnedPluginItem( pluginName ) {
193
+ const isPinned = yield controls.select(
194
+ interfaceStore,
195
+ 'isItemPinned',
196
+ 'core/edit-post',
197
+ pluginName
198
+ );
199
+
200
+ yield controls.dispatch(
201
+ interfaceStore,
202
+ isPinned ? 'unpinItem' : 'pinItem',
203
+ 'core/edit-post',
204
+ pluginName
205
+ );
199
206
  }
200
207
 
201
208
  /**
@@ -258,8 +265,6 @@ export function showBlockTypes( blockNames ) {
258
265
  };
259
266
  }
260
267
 
261
- let saveMetaboxUnsubscribe;
262
-
263
268
  /**
264
269
  * Returns an action object used in signaling
265
270
  * what Meta boxes are available in which location.
@@ -273,58 +278,6 @@ export function* setAvailableMetaBoxesPerLocation( metaBoxesPerLocation ) {
273
278
  type: 'SET_META_BOXES_PER_LOCATIONS',
274
279
  metaBoxesPerLocation,
275
280
  };
276
-
277
- const postType = yield controls.select(
278
- editorStore.name,
279
- 'getCurrentPostType'
280
- );
281
- if ( window.postboxes.page !== postType ) {
282
- window.postboxes.add_postbox_toggles( postType );
283
- }
284
-
285
- let wasSavingPost = yield controls.select(
286
- editorStore.name,
287
- 'isSavingPost'
288
- );
289
- let wasAutosavingPost = yield controls.select(
290
- editorStore.name,
291
- 'isAutosavingPost'
292
- );
293
-
294
- // Meta boxes are initialized once at page load. It is not necessary to
295
- // account for updates on each state change.
296
- //
297
- // See: https://github.com/WordPress/WordPress/blob/5.1.1/wp-admin/includes/post.php#L2307-L2309
298
- const hasActiveMetaBoxes = yield controls.select(
299
- editPostStore.name,
300
- 'hasMetaBoxes'
301
- );
302
-
303
- // First remove any existing subscription in order to prevent multiple saves
304
- if ( !! saveMetaboxUnsubscribe ) {
305
- saveMetaboxUnsubscribe();
306
- }
307
-
308
- // Save metaboxes when performing a full save on the post.
309
- saveMetaboxUnsubscribe = subscribe( () => {
310
- const isSavingPost = select( editorStore.name ).isSavingPost();
311
- const isAutosavingPost = select( editorStore.name ).isAutosavingPost();
312
-
313
- // Save metaboxes on save completion, except for autosaves that are not a post preview.
314
- const shouldTriggerMetaboxesSave =
315
- hasActiveMetaBoxes &&
316
- wasSavingPost &&
317
- ! isSavingPost &&
318
- ! wasAutosavingPost;
319
-
320
- // Save current state for next inspection.
321
- wasSavingPost = isSavingPost;
322
- wasAutosavingPost = isAutosavingPost;
323
-
324
- if ( shouldTriggerMetaboxesSave ) {
325
- dispatch( editPostStore.name ).requestMetaBoxUpdates();
326
- }
327
- } );
328
281
  }
329
282
 
330
283
  /**
@@ -344,7 +297,7 @@ export function* requestMetaBoxUpdates() {
344
297
 
345
298
  // Additional data needed for backward compatibility.
346
299
  // If we do not provide this data, the post will be overridden with the default values.
347
- const post = yield controls.select( editorStore.name, 'getCurrentPost' );
300
+ const post = yield controls.select( editorStore, 'getCurrentPost' );
348
301
  const additionalData = [
349
302
  post.comment_status ? [ 'comment_status', post.comment_status ] : false,
350
303
  post.ping_status ? [ 'ping_status', post.ping_status ] : false,
@@ -357,7 +310,7 @@ export function* requestMetaBoxUpdates() {
357
310
  document.querySelector( '.metabox-base-form' )
358
311
  );
359
312
  const activeMetaBoxLocations = yield controls.select(
360
- editPostStore.name,
313
+ editPostStore,
361
314
  'getActiveMetaBoxLocations'
362
315
  );
363
316
  const formDataToMerge = [
@@ -391,9 +344,9 @@ export function* requestMetaBoxUpdates() {
391
344
  body: formData,
392
345
  parse: false,
393
346
  } );
394
- yield controls.dispatch( editPostStore.name, 'metaBoxUpdatesSuccess' );
347
+ yield controls.dispatch( editPostStore, 'metaBoxUpdatesSuccess' );
395
348
  } catch {
396
- yield controls.dispatch( editPostStore.name, 'metaBoxUpdatesFailure' );
349
+ yield controls.dispatch( editPostStore, 'metaBoxUpdatesFailure' );
397
350
  }
398
351
  }
399
352
 
@@ -487,7 +440,7 @@ export function* __unstableSwitchToTemplateMode( newTemplate = false ) {
487
440
  yield setIsEditingTemplate( true );
488
441
 
489
442
  const isWelcomeGuideActive = yield controls.select(
490
- editPostStore.name,
443
+ editPostStore,
491
444
  'isFeatureActive',
492
445
  'welcomeGuideTemplate'
493
446
  );
@@ -517,7 +470,7 @@ export function* __unstableCreateTemplate( template ) {
517
470
  'wp_template',
518
471
  template
519
472
  );
520
- const post = yield controls.select( editorStore.name, 'getCurrentPost' );
473
+ const post = yield controls.select( editorStore, 'getCurrentPost' );
521
474
 
522
475
  yield controls.dispatch(
523
476
  coreStore,
@@ -530,3 +483,69 @@ export function* __unstableCreateTemplate( template ) {
530
483
  }
531
484
  );
532
485
  }
486
+
487
+ let metaBoxesInitialized = false;
488
+
489
+ /**
490
+ * Initializes WordPress `postboxes` script and the logic for saving meta boxes.
491
+ */
492
+ export function* initializeMetaBoxes() {
493
+ const isEditorReady = yield controls.select(
494
+ editorStore,
495
+ '__unstableIsEditorReady'
496
+ );
497
+
498
+ if ( ! isEditorReady ) {
499
+ return;
500
+ }
501
+
502
+ const postType = yield controls.select( editorStore, 'getCurrentPostType' );
503
+
504
+ // Only initialize once.
505
+ if ( metaBoxesInitialized ) {
506
+ return;
507
+ }
508
+
509
+ if ( window.postboxes.page !== postType ) {
510
+ window.postboxes.add_postbox_toggles( postType );
511
+ }
512
+
513
+ metaBoxesInitialized = true;
514
+
515
+ let wasSavingPost = yield controls.select( editorStore, 'isSavingPost' );
516
+ let wasAutosavingPost = yield controls.select(
517
+ editorStore,
518
+ 'isAutosavingPost'
519
+ );
520
+ const hasMetaBoxes = yield controls.select( editPostStore, 'hasMetaBoxes' );
521
+
522
+ // Save metaboxes when performing a full save on the post.
523
+ subscribe( () => {
524
+ const isSavingPost = select( editorStore ).isSavingPost();
525
+ const isAutosavingPost = select( editorStore ).isAutosavingPost();
526
+
527
+ // Save metaboxes on save completion, except for autosaves that are not a post preview.
528
+ //
529
+ // Meta boxes are initialized once at page load. It is not necessary to
530
+ // account for updates on each state change.
531
+ //
532
+ // See: https://github.com/WordPress/WordPress/blob/5.1.1/wp-admin/includes/post.php#L2307-L2309
533
+ const shouldTriggerMetaboxesSave =
534
+ hasMetaBoxes &&
535
+ wasSavingPost &&
536
+ ! isSavingPost &&
537
+ ! wasAutosavingPost;
538
+
539
+ // Save current state for next inspection.
540
+ wasSavingPost = isSavingPost;
541
+ wasAutosavingPost = isAutosavingPost;
542
+
543
+ if ( shouldTriggerMetaboxesSave ) {
544
+ dispatch( editPostStore ).requestMetaBoxUpdates();
545
+ }
546
+ } );
547
+
548
+ return {
549
+ type: 'META_BOXES_INITIALIZED',
550
+ };
551
+ }
@@ -5,15 +5,6 @@ export const PREFERENCES_DEFAULTS = {
5
5
  opened: true,
6
6
  },
7
7
  },
8
- features: {
9
- fixedToolbar: false,
10
- welcomeGuide: true,
11
- fullscreenMode: true,
12
- showIconLabels: false,
13
- themeStyles: true,
14
- showBlockBreadcrumbs: true,
15
- welcomeGuideTemplate: true,
16
- },
17
8
  hiddenBlockTypes: [],
18
9
  preferredStyleVariations: {},
19
10
  localAutosaveInterval: 15,
@@ -78,16 +78,6 @@ export const preferences = flow( [
78
78
 
79
79
  return state;
80
80
  },
81
- features( state, action ) {
82
- if ( action.type === 'TOGGLE_FEATURE' ) {
83
- return {
84
- ...state,
85
- [ action.feature ]: ! state[ action.feature ],
86
- };
87
- }
88
-
89
- return state;
90
- },
91
81
  editorMode( state, action ) {
92
82
  if ( action.type === 'SWITCH_MODE' ) {
93
83
  return action.mode;
@@ -291,9 +281,26 @@ function isEditingTemplate( state = false, action ) {
291
281
  return state;
292
282
  }
293
283
 
284
+ /**
285
+ * Reducer tracking whether meta boxes are initialized.
286
+ *
287
+ * @param {boolean} state
288
+ * @param {Object} action
289
+ *
290
+ * @return {boolean} Updated state.
291
+ */
292
+ function metaBoxesInitialized( state = false, action ) {
293
+ switch ( action.type ) {
294
+ case 'META_BOXES_INITIALIZED':
295
+ return true;
296
+ }
297
+ return state;
298
+ }
299
+
294
300
  const metaBoxes = combineReducers( {
295
301
  isSaving: isSavingMetaBoxes,
296
302
  locations: metaBoxLocations,
303
+ initialized: metaBoxesInitialized,
297
304
  } );
298
305
 
299
306
  export default combineReducers( {
@@ -189,9 +189,14 @@ export function isModalActive( state, modalName ) {
189
189
  *
190
190
  * @return {boolean} Is active.
191
191
  */
192
- export function isFeatureActive( state, feature ) {
193
- return get( state.preferences.features, [ feature ], false );
194
- }
192
+ export const isFeatureActive = createRegistrySelector(
193
+ ( select ) => ( state, feature ) => {
194
+ return select( interfaceStore ).isFeatureActive(
195
+ 'core/edit-post',
196
+ feature
197
+ );
198
+ }
199
+ );
195
200
 
196
201
  /**
197
202
  * Returns true if the plugin item is pinned to the header.
@@ -203,7 +208,7 @@ export function isFeatureActive( state, feature ) {
203
208
  * @return {boolean} Whether the plugin item is pinned.
204
209
  */
205
210
  export const isPluginItemPinned = createRegistrySelector(
206
- ( select ) => ( pluginName ) => {
211
+ ( select ) => ( state, pluginName ) => {
207
212
  return select( interfaceStore ).isItemPinned(
208
213
  'core/edit-post',
209
214
  pluginName
@@ -333,11 +338,15 @@ export function isInserterOpened( state ) {
333
338
  *
334
339
  * @param {Object} state Global application state.
335
340
  *
336
- * @return {Object} The root client ID and index to insert at.
341
+ * @return {Object} The root client ID, index to insert at and starting filter value.
337
342
  */
338
343
  export function __experimentalGetInsertionPoint( state ) {
339
- const { rootClientId, insertionIndex } = state.blockInserterPanel;
340
- return { rootClientId, insertionIndex };
344
+ const {
345
+ rootClientId,
346
+ insertionIndex,
347
+ filterValue,
348
+ } = state.blockInserterPanel;
349
+ return { rootClientId, insertionIndex, filterValue };
341
350
  }
342
351
 
343
352
  /**
@@ -362,6 +371,17 @@ export function isEditingTemplate( state ) {
362
371
  return state.isEditingTemplate;
363
372
  }
364
373
 
374
+ /**
375
+ * Returns true if meta boxes are initialized.
376
+ *
377
+ * @param {Object} state Global application state.
378
+ *
379
+ * @return {boolean} Whether meta boxes are initialized.
380
+ */
381
+ export function areMetaBoxesInitialized( state ) {
382
+ return state.metaBoxes.initialized;
383
+ }
384
+
365
385
  /**
366
386
  * Retrieves the template of the currently edited post.
367
387
  *
@@ -15,7 +15,6 @@ import {
15
15
  togglePublishSidebar,
16
16
  openModal,
17
17
  closeModal,
18
- toggleFeature,
19
18
  requestMetaBoxUpdates,
20
19
  setIsListViewOpened,
21
20
  } from '../actions';
@@ -90,16 +89,6 @@ describe( 'actions', () => {
90
89
  } );
91
90
  } );
92
91
 
93
- describe( 'toggleFeature', () => {
94
- it( 'should return TOGGLE_FEATURE action', () => {
95
- const feature = 'name';
96
- expect( toggleFeature( feature ) ).toEqual( {
97
- type: 'TOGGLE_FEATURE',
98
- feature,
99
- } );
100
- } );
101
- } );
102
-
103
92
  describe( 'requestMetaBoxUpdates', () => {
104
93
  it( 'should yield the REQUEST_META_BOX_UPDATES action', () => {
105
94
  const fulfillment = requestMetaBoxUpdates();
@@ -152,18 +152,6 @@ describe( 'state', () => {
152
152
  expect( state.editorMode ).toBe( 'text' );
153
153
  } );
154
154
 
155
- it( 'should toggle a feature flag', () => {
156
- const state = preferences(
157
- deepFreeze( { features: { chicken: true } } ),
158
- {
159
- type: 'TOGGLE_FEATURE',
160
- feature: 'chicken',
161
- }
162
- );
163
-
164
- expect( state.features ).toEqual( { chicken: false } );
165
- } );
166
-
167
155
  describe( 'hiddenBlockTypes', () => {
168
156
  it( 'concatenates unique names on disable', () => {
169
157
  const original = deepFreeze( {
@@ -11,7 +11,6 @@ import {
11
11
  getPreference,
12
12
  isEditorPanelOpened,
13
13
  isModalActive,
14
- isFeatureActive,
15
14
  hasMetaBoxes,
16
15
  isSavingMetaBoxes,
17
16
  getActiveMetaBoxLocations,
@@ -239,51 +238,6 @@ describe( 'selectors', () => {
239
238
  } );
240
239
  } );
241
240
 
242
- describe( 'isFeatureActive', () => {
243
- it( 'is tolerant to an undefined features preference', () => {
244
- // See: https://github.com/WordPress/gutenberg/issues/14580
245
- const state = {
246
- preferences: {},
247
- };
248
-
249
- expect( isFeatureActive( state, 'chicken' ) ).toBe( false );
250
- } );
251
-
252
- it( 'should return true if feature is active', () => {
253
- const state = {
254
- preferences: {
255
- features: {
256
- chicken: true,
257
- },
258
- },
259
- };
260
-
261
- expect( isFeatureActive( state, 'chicken' ) ).toBe( true );
262
- } );
263
-
264
- it( 'should return false if feature is not active', () => {
265
- const state = {
266
- preferences: {
267
- features: {
268
- chicken: false,
269
- },
270
- },
271
- };
272
-
273
- expect( isFeatureActive( state, 'chicken' ) ).toBe( false );
274
- } );
275
-
276
- it( 'should return false if feature is not referred', () => {
277
- const state = {
278
- preferences: {
279
- features: {},
280
- },
281
- };
282
-
283
- expect( isFeatureActive( state, 'chicken' ) ).toBe( false );
284
- } );
285
- } );
286
-
287
241
  describe( 'hasMetaBoxes', () => {
288
242
  it( 'should return true if there are active meta boxes', () => {
289
243
  const state = {
@@ -1,76 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- var _element = require("@wordpress/element");
9
-
10
- var _lodash = require("lodash");
11
-
12
- var _data = require("@wordpress/data");
13
-
14
- var _compose = require("@wordpress/compose");
15
-
16
- var _components = require("@wordpress/components");
17
-
18
- var _i18n = require("@wordpress/i18n");
19
-
20
- var _icons = require("@wordpress/icons");
21
-
22
- var _a11y = require("@wordpress/a11y");
23
-
24
- var _store = require("../../../store");
25
-
26
- /**
27
- * External dependencies
28
- */
29
-
30
- /**
31
- * WordPress dependencies
32
- */
33
-
34
- /**
35
- * Internal dependencies
36
- */
37
- function FeatureToggle({
38
- onToggle,
39
- isActive,
40
- label,
41
- info,
42
- messageActivated,
43
- messageDeactivated,
44
- shortcut
45
- }) {
46
- const speakMessage = () => {
47
- if (isActive) {
48
- (0, _a11y.speak)(messageDeactivated || (0, _i18n.__)('Feature deactivated'));
49
- } else {
50
- (0, _a11y.speak)(messageActivated || (0, _i18n.__)('Feature activated'));
51
- }
52
- };
53
-
54
- return (0, _element.createElement)(_components.MenuItem, {
55
- icon: isActive && _icons.check,
56
- isSelected: isActive,
57
- onClick: (0, _lodash.flow)(onToggle, speakMessage),
58
- role: "menuitemcheckbox",
59
- info: info,
60
- shortcut: shortcut
61
- }, label);
62
- }
63
-
64
- var _default = (0, _compose.compose)([(0, _data.withSelect)((select, {
65
- feature
66
- }) => ({
67
- isActive: select(_store.store).isFeatureActive(feature)
68
- })), (0, _data.withDispatch)((dispatch, ownProps) => ({
69
- onToggle() {
70
- dispatch(_store.store).toggleFeature(ownProps.feature);
71
- }
72
-
73
- }))])(FeatureToggle);
74
-
75
- exports.default = _default;
76
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["@wordpress/edit-post/src/components/header/feature-toggle/index.js"],"names":["FeatureToggle","onToggle","isActive","label","info","messageActivated","messageDeactivated","shortcut","speakMessage","check","select","feature","editPostStore","isFeatureActive","dispatch","ownProps","toggleFeature"],"mappings":";;;;;;;;;AAGA;;AAKA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAKA;;AAlBA;AACA;AACA;;AAGA;AACA;AACA;;AAQA;AACA;AACA;AAGA,SAASA,aAAT,CAAwB;AACvBC,EAAAA,QADuB;AAEvBC,EAAAA,QAFuB;AAGvBC,EAAAA,KAHuB;AAIvBC,EAAAA,IAJuB;AAKvBC,EAAAA,gBALuB;AAMvBC,EAAAA,kBANuB;AAOvBC,EAAAA;AAPuB,CAAxB,EAQI;AACH,QAAMC,YAAY,GAAG,MAAM;AAC1B,QAAKN,QAAL,EAAgB;AACf,uBAAOI,kBAAkB,IAAI,cAAI,qBAAJ,CAA7B;AACA,KAFD,MAEO;AACN,uBAAOD,gBAAgB,IAAI,cAAI,mBAAJ,CAA3B;AACA;AACD,GAND;;AAQA,SACC,4BAAC,oBAAD;AACC,IAAA,IAAI,EAAGH,QAAQ,IAAIO,YADpB;AAEC,IAAA,UAAU,EAAGP,QAFd;AAGC,IAAA,OAAO,EAAG,kBAAMD,QAAN,EAAgBO,YAAhB,CAHX;AAIC,IAAA,IAAI,EAAC,kBAJN;AAKC,IAAA,IAAI,EAAGJ,IALR;AAMC,IAAA,QAAQ,EAAGG;AANZ,KAQGJ,KARH,CADD;AAYA;;eAEc,sBAAS,CACvB,sBAAY,CAAEO,MAAF,EAAU;AAAEC,EAAAA;AAAF,CAAV,MAA6B;AACxCT,EAAAA,QAAQ,EAAEQ,MAAM,CAAEE,YAAF,CAAN,CAAwBC,eAAxB,CAAyCF,OAAzC;AAD8B,CAA7B,CAAZ,CADuB,EAIvB,wBAAc,CAAEG,QAAF,EAAYC,QAAZ,MAA4B;AACzCd,EAAAA,QAAQ,GAAG;AACVa,IAAAA,QAAQ,CAAEF,YAAF,CAAR,CAA0BI,aAA1B,CAAyCD,QAAQ,CAACJ,OAAlD;AACA;;AAHwC,CAA5B,CAAd,CAJuB,CAAT,EASVX,aATU,C","sourcesContent":["/**\n * External dependencies\n */\nimport { flow } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport { withSelect, withDispatch } from '@wordpress/data';\nimport { compose } from '@wordpress/compose';\nimport { MenuItem } from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport { check } from '@wordpress/icons';\nimport { speak } from '@wordpress/a11y';\n\n/**\n * Internal dependencies\n */\nimport { store as editPostStore } from '../../../store';\n\nfunction FeatureToggle( {\n\tonToggle,\n\tisActive,\n\tlabel,\n\tinfo,\n\tmessageActivated,\n\tmessageDeactivated,\n\tshortcut,\n} ) {\n\tconst speakMessage = () => {\n\t\tif ( isActive ) {\n\t\t\tspeak( messageDeactivated || __( 'Feature deactivated' ) );\n\t\t} else {\n\t\t\tspeak( messageActivated || __( 'Feature activated' ) );\n\t\t}\n\t};\n\n\treturn (\n\t\t<MenuItem\n\t\t\ticon={ isActive && check }\n\t\t\tisSelected={ isActive }\n\t\t\tonClick={ flow( onToggle, speakMessage ) }\n\t\t\trole=\"menuitemcheckbox\"\n\t\t\tinfo={ info }\n\t\t\tshortcut={ shortcut }\n\t\t>\n\t\t\t{ label }\n\t\t</MenuItem>\n\t);\n}\n\nexport default compose( [\n\twithSelect( ( select, { feature } ) => ( {\n\t\tisActive: select( editPostStore ).isFeatureActive( feature ),\n\t} ) ),\n\twithDispatch( ( dispatch, ownProps ) => ( {\n\t\tonToggle() {\n\t\t\tdispatch( editPostStore ).toggleFeature( ownProps.feature );\n\t\t},\n\t} ) ),\n] )( FeatureToggle );\n"]}
@@ -1,60 +0,0 @@
1
- import { createElement } from "@wordpress/element";
2
-
3
- /**
4
- * External dependencies
5
- */
6
- import { flow } from 'lodash';
7
- /**
8
- * WordPress dependencies
9
- */
10
-
11
- import { withSelect, withDispatch } from '@wordpress/data';
12
- import { compose } from '@wordpress/compose';
13
- import { MenuItem } from '@wordpress/components';
14
- import { __ } from '@wordpress/i18n';
15
- import { check } from '@wordpress/icons';
16
- import { speak } from '@wordpress/a11y';
17
- /**
18
- * Internal dependencies
19
- */
20
-
21
- import { store as editPostStore } from '../../../store';
22
-
23
- function FeatureToggle({
24
- onToggle,
25
- isActive,
26
- label,
27
- info,
28
- messageActivated,
29
- messageDeactivated,
30
- shortcut
31
- }) {
32
- const speakMessage = () => {
33
- if (isActive) {
34
- speak(messageDeactivated || __('Feature deactivated'));
35
- } else {
36
- speak(messageActivated || __('Feature activated'));
37
- }
38
- };
39
-
40
- return createElement(MenuItem, {
41
- icon: isActive && check,
42
- isSelected: isActive,
43
- onClick: flow(onToggle, speakMessage),
44
- role: "menuitemcheckbox",
45
- info: info,
46
- shortcut: shortcut
47
- }, label);
48
- }
49
-
50
- export default compose([withSelect((select, {
51
- feature
52
- }) => ({
53
- isActive: select(editPostStore).isFeatureActive(feature)
54
- })), withDispatch((dispatch, ownProps) => ({
55
- onToggle() {
56
- dispatch(editPostStore).toggleFeature(ownProps.feature);
57
- }
58
-
59
- }))])(FeatureToggle);
60
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["@wordpress/edit-post/src/components/header/feature-toggle/index.js"],"names":["flow","withSelect","withDispatch","compose","MenuItem","__","check","speak","store","editPostStore","FeatureToggle","onToggle","isActive","label","info","messageActivated","messageDeactivated","shortcut","speakMessage","select","feature","isFeatureActive","dispatch","ownProps","toggleFeature"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,IAAT,QAAqB,QAArB;AAEA;AACA;AACA;;AACA,SAASC,UAAT,EAAqBC,YAArB,QAAyC,iBAAzC;AACA,SAASC,OAAT,QAAwB,oBAAxB;AACA,SAASC,QAAT,QAAyB,uBAAzB;AACA,SAASC,EAAT,QAAmB,iBAAnB;AACA,SAASC,KAAT,QAAsB,kBAAtB;AACA,SAASC,KAAT,QAAsB,iBAAtB;AAEA;AACA;AACA;;AACA,SAASC,KAAK,IAAIC,aAAlB,QAAuC,gBAAvC;;AAEA,SAASC,aAAT,CAAwB;AACvBC,EAAAA,QADuB;AAEvBC,EAAAA,QAFuB;AAGvBC,EAAAA,KAHuB;AAIvBC,EAAAA,IAJuB;AAKvBC,EAAAA,gBALuB;AAMvBC,EAAAA,kBANuB;AAOvBC,EAAAA;AAPuB,CAAxB,EAQI;AACH,QAAMC,YAAY,GAAG,MAAM;AAC1B,QAAKN,QAAL,EAAgB;AACfL,MAAAA,KAAK,CAAES,kBAAkB,IAAIX,EAAE,CAAE,qBAAF,CAA1B,CAAL;AACA,KAFD,MAEO;AACNE,MAAAA,KAAK,CAAEQ,gBAAgB,IAAIV,EAAE,CAAE,mBAAF,CAAxB,CAAL;AACA;AACD,GAND;;AAQA,SACC,cAAC,QAAD;AACC,IAAA,IAAI,EAAGO,QAAQ,IAAIN,KADpB;AAEC,IAAA,UAAU,EAAGM,QAFd;AAGC,IAAA,OAAO,EAAGZ,IAAI,CAAEW,QAAF,EAAYO,YAAZ,CAHf;AAIC,IAAA,IAAI,EAAC,kBAJN;AAKC,IAAA,IAAI,EAAGJ,IALR;AAMC,IAAA,QAAQ,EAAGG;AANZ,KAQGJ,KARH,CADD;AAYA;;AAED,eAAeV,OAAO,CAAE,CACvBF,UAAU,CAAE,CAAEkB,MAAF,EAAU;AAAEC,EAAAA;AAAF,CAAV,MAA6B;AACxCR,EAAAA,QAAQ,EAAEO,MAAM,CAAEV,aAAF,CAAN,CAAwBY,eAAxB,CAAyCD,OAAzC;AAD8B,CAA7B,CAAF,CADa,EAIvBlB,YAAY,CAAE,CAAEoB,QAAF,EAAYC,QAAZ,MAA4B;AACzCZ,EAAAA,QAAQ,GAAG;AACVW,IAAAA,QAAQ,CAAEb,aAAF,CAAR,CAA0Be,aAA1B,CAAyCD,QAAQ,CAACH,OAAlD;AACA;;AAHwC,CAA5B,CAAF,CAJW,CAAF,CAAP,CASVV,aATU,CAAf","sourcesContent":["/**\n * External dependencies\n */\nimport { flow } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport { withSelect, withDispatch } from '@wordpress/data';\nimport { compose } from '@wordpress/compose';\nimport { MenuItem } from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport { check } from '@wordpress/icons';\nimport { speak } from '@wordpress/a11y';\n\n/**\n * Internal dependencies\n */\nimport { store as editPostStore } from '../../../store';\n\nfunction FeatureToggle( {\n\tonToggle,\n\tisActive,\n\tlabel,\n\tinfo,\n\tmessageActivated,\n\tmessageDeactivated,\n\tshortcut,\n} ) {\n\tconst speakMessage = () => {\n\t\tif ( isActive ) {\n\t\t\tspeak( messageDeactivated || __( 'Feature deactivated' ) );\n\t\t} else {\n\t\t\tspeak( messageActivated || __( 'Feature activated' ) );\n\t\t}\n\t};\n\n\treturn (\n\t\t<MenuItem\n\t\t\ticon={ isActive && check }\n\t\t\tisSelected={ isActive }\n\t\t\tonClick={ flow( onToggle, speakMessage ) }\n\t\t\trole=\"menuitemcheckbox\"\n\t\t\tinfo={ info }\n\t\t\tshortcut={ shortcut }\n\t\t>\n\t\t\t{ label }\n\t\t</MenuItem>\n\t);\n}\n\nexport default compose( [\n\twithSelect( ( select, { feature } ) => ( {\n\t\tisActive: select( editPostStore ).isFeatureActive( feature ),\n\t} ) ),\n\twithDispatch( ( dispatch, ownProps ) => ( {\n\t\tonToggle() {\n\t\t\tdispatch( editPostStore ).toggleFeature( ownProps.feature );\n\t\t},\n\t} ) ),\n] )( FeatureToggle );\n"]}