@wordpress/interface 4.7.0 → 4.10.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.
Files changed (37) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/build/components/action-item/index.js +4 -3
  3. package/build/components/action-item/index.js.map +1 -1
  4. package/build/components/complementary-area/index.js.map +1 -1
  5. package/build/components/complementary-area-toggle/index.js.map +1 -1
  6. package/build/store/actions.js +42 -10
  7. package/build/store/actions.js.map +1 -1
  8. package/build/store/index.js +5 -1
  9. package/build/store/index.js.map +1 -1
  10. package/build/store/reducer.js +55 -0
  11. package/build/store/reducer.js.map +1 -0
  12. package/build/store/selectors.js +19 -4
  13. package/build/store/selectors.js.map +1 -1
  14. package/build-module/components/action-item/index.js +3 -1
  15. package/build-module/components/action-item/index.js.map +1 -1
  16. package/build-module/components/complementary-area/index.js.map +1 -1
  17. package/build-module/components/complementary-area-toggle/index.js.map +1 -1
  18. package/build-module/store/actions.js +38 -9
  19. package/build-module/store/actions.js.map +1 -1
  20. package/build-module/store/index.js +2 -1
  21. package/build-module/store/index.js.map +1 -1
  22. package/build-module/store/reducer.js +43 -0
  23. package/build-module/store/reducer.js.map +1 -0
  24. package/build-module/store/selectors.js +19 -4
  25. package/build-module/store/selectors.js.map +1 -1
  26. package/build-style/style-rtl.css +0 -1
  27. package/build-style/style.css +0 -1
  28. package/package.json +13 -13
  29. package/src/components/action-item/index.js +3 -1
  30. package/src/components/complementary-area/index.js +6 -9
  31. package/src/components/complementary-area-toggle/index.js +2 -3
  32. package/src/components/more-menu-dropdown/style.scss +0 -1
  33. package/src/store/actions.js +96 -56
  34. package/src/store/index.js +2 -1
  35. package/src/store/reducer.js +35 -0
  36. package/src/store/selectors.js +21 -4
  37. package/src/store/test/actions.js +1 -1
@@ -0,0 +1,35 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import { combineReducers } from '@wordpress/data';
5
+
6
+ export function complementaryAreas( state = {}, action ) {
7
+ switch ( action.type ) {
8
+ case 'SET_DEFAULT_COMPLEMENTARY_AREA': {
9
+ const { scope, area } = action;
10
+
11
+ // If there's already an area, don't overwrite it.
12
+ if ( state[ scope ] ) {
13
+ return state;
14
+ }
15
+
16
+ return {
17
+ ...state,
18
+ [ scope ]: area,
19
+ };
20
+ }
21
+ case 'ENABLE_COMPLEMENTARY_AREA': {
22
+ const { scope, area } = action;
23
+ return {
24
+ ...state,
25
+ [ scope ]: area,
26
+ };
27
+ }
28
+ }
29
+
30
+ return state;
31
+ }
32
+
33
+ export default combineReducers( {
34
+ complementaryAreas,
35
+ } );
@@ -11,11 +11,28 @@ import { store as preferencesStore } from '@wordpress/preferences';
11
11
  * @param {Object} state Global application state.
12
12
  * @param {string} scope Item scope.
13
13
  *
14
- * @return {string} The complementary area that is active in the given scope.
14
+ * @return {string | null | undefined} The complementary area that is active in the given scope.
15
15
  */
16
16
  export const getActiveComplementaryArea = createRegistrySelector(
17
17
  ( select ) => ( state, scope ) => {
18
- return select( preferencesStore ).get( scope, 'complementaryArea' );
18
+ const isComplementaryAreaVisible = select( preferencesStore ).get(
19
+ scope,
20
+ 'isComplementaryAreaVisible'
21
+ );
22
+
23
+ // Return `undefined` to indicate that the user has never toggled
24
+ // visibility, this is the vanilla default. Other code relies on this
25
+ // nuance in the return value.
26
+ if ( isComplementaryAreaVisible === undefined ) {
27
+ return undefined;
28
+ }
29
+
30
+ // Return `null` to indicate the user hid the complementary area.
31
+ if ( ! isComplementaryAreaVisible ) {
32
+ return null;
33
+ }
34
+
35
+ return state?.complementaryAreas?.[ scope ];
19
36
  }
20
37
  );
21
38
 
@@ -51,10 +68,10 @@ export const isItemPinned = createRegistrySelector(
51
68
  export const isFeatureActive = createRegistrySelector(
52
69
  ( select ) => ( state, scope, featureName ) => {
53
70
  deprecated(
54
- `wp.select( 'core/interface' ).isFeatureActive( scope, featureName )`,
71
+ `select( 'core/interface' ).isFeatureActive( scope, featureName )`,
55
72
  {
56
73
  since: '6.0',
57
- alternative: `!! wp.select( 'core/preferences' ).isFeatureActive( scope, featureName )`,
74
+ alternative: `select( 'core/preferences' ).get( scope, featureName )`,
58
75
  }
59
76
  );
60
77
 
@@ -54,7 +54,7 @@ describe( 'actions', () => {
54
54
  } );
55
55
 
56
56
  describe( 'disableComplementaryArea', () => {
57
- it( 'removes any assignment to a complementary area', () => {
57
+ it( 'results in the complementary area being inactive', () => {
58
58
  registry
59
59
  .dispatch( interfaceStore )
60
60
  .enableComplementaryArea( 'my-plugin', 'custom-sidebar' );