@wordpress/interface 4.4.0 → 4.5.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.
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/interface/src/store/actions.js"],"names":["deprecated","store","preferencesStore","setSingleEnableItem","itemType","scope","item","type","enableComplementaryArea","area","disableComplementaryArea","undefined","setMultipleEnableItem","isEnable","pinItem","itemId","unpinItem","toggleFeature","featureName","registry","since","alternative","dispatch","toggle","setFeatureValue","value","set","setFeatureDefaults","defaults","setDefaults"],"mappings":"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","sourcesContent":["/**\n * WordPress dependencies\n */\nimport deprecated from '@wordpress/deprecated';\nimport { store as preferencesStore } from '@wordpress/preferences';\n\n/**\n * Returns an action object used in signalling that an active area should be changed.\n *\n * @param {string} itemType Type of item.\n * @param {string} scope Item scope.\n * @param {string} item Item identifier.\n *\n * @return {Object} Action object.\n */\nfunction setSingleEnableItem( itemType, scope, item ) {\n\treturn {\n\t\ttype: 'SET_SINGLE_ENABLE_ITEM',\n\t\titemType,\n\t\tscope,\n\t\titem,\n\t};\n}\n\n/**\n * Returns an action object used in signalling that a complementary item should be enabled.\n *\n * @param {string} scope Complementary area scope.\n * @param {string} area Area identifier.\n *\n * @return {Object} Action object.\n */\nexport function enableComplementaryArea( scope, area ) {\n\treturn setSingleEnableItem( 'complementaryArea', scope, area );\n}\n\n/**\n * Returns an action object used in signalling that the complementary area of a given scope should be disabled.\n *\n * @param {string} scope Complementary area scope.\n *\n * @return {Object} Action object.\n */\nexport function disableComplementaryArea( scope ) {\n\treturn setSingleEnableItem( 'complementaryArea', scope, undefined );\n}\n\n/**\n * Returns an action object to make an area enabled/disabled.\n *\n * @param {string} itemType Type of item.\n * @param {string} scope Item scope.\n * @param {string} item Item identifier.\n * @param {boolean} isEnable Boolean indicating if an area should be pinned or not.\n *\n * @return {Object} Action object.\n */\nfunction setMultipleEnableItem( itemType, scope, item, isEnable ) {\n\treturn {\n\t\ttype: 'SET_MULTIPLE_ENABLE_ITEM',\n\t\titemType,\n\t\tscope,\n\t\titem,\n\t\tisEnable,\n\t};\n}\n\n/**\n * Returns an action object used in signalling that an item should be pinned.\n *\n * @param {string} scope Item scope.\n * @param {string} itemId Item identifier.\n *\n * @return {Object} Action object.\n */\nexport function pinItem( scope, itemId ) {\n\treturn setMultipleEnableItem( 'pinnedItems', scope, itemId, true );\n}\n\n/**\n * Returns an action object used in signalling that an item should be unpinned.\n *\n * @param {string} scope Item scope.\n * @param {string} itemId Item identifier.\n *\n * @return {Object} Action object.\n */\nexport function unpinItem( scope, itemId ) {\n\treturn setMultipleEnableItem( 'pinnedItems', scope, itemId, false );\n}\n\n/**\n * Returns an action object used in signalling that a feature should be toggled.\n *\n * @param {string} scope The feature scope (e.g. core/edit-post).\n * @param {string} featureName The feature name.\n */\nexport function toggleFeature( scope, featureName ) {\n\treturn function ( { registry } ) {\n\t\tdeprecated( `wp.dispatch( 'core/interface' ).toggleFeature`, {\n\t\t\tsince: '6.0',\n\t\t\talternative: `wp.dispatch( 'core/preferences' ).toggle`,\n\t\t} );\n\n\t\tregistry.dispatch( preferencesStore ).toggle( scope, featureName );\n\t};\n}\n\n/**\n * Returns an action object used in signalling that a feature should be set to\n * a true or false value\n *\n * @param {string} scope The feature scope (e.g. core/edit-post).\n * @param {string} featureName The feature name.\n * @param {boolean} value The value to set.\n *\n * @return {Object} Action object.\n */\nexport function setFeatureValue( scope, featureName, value ) {\n\treturn function ( { registry } ) {\n\t\tdeprecated( `wp.dispatch( 'core/interface' ).setFeatureValue`, {\n\t\t\tsince: '6.0',\n\t\t\talternative: `wp.dispatch( 'core/preferences' ).set`,\n\t\t} );\n\n\t\tregistry\n\t\t\t.dispatch( preferencesStore )\n\t\t\t.set( scope, featureName, !! value );\n\t};\n}\n\n/**\n * Returns an action object used in signalling that defaults should be set for features.\n *\n * @param {string} scope The feature scope (e.g. core/edit-post).\n * @param {Object<string, boolean>} defaults A key/value map of feature names to values.\n *\n * @return {Object} Action object.\n */\nexport function setFeatureDefaults( scope, defaults ) {\n\treturn function ( { registry } ) {\n\t\tdeprecated( `wp.dispatch( 'core/interface' ).setFeatureDefaults`, {\n\t\t\tsince: '6.0',\n\t\t\talternative: `wp.dispatch( 'core/preferences' ).setDefaults`,\n\t\t} );\n\n\t\tregistry.dispatch( preferencesStore ).setDefaults( scope, defaults );\n\t};\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/interface/src/store/actions.js"],"names":["deprecated","store","preferencesStore","enableComplementaryArea","scope","area","registry","dispatch","set","disableComplementaryArea","pinItem","item","pinnedItems","select","get","unpinItem","toggleFeature","featureName","since","alternative","toggle","setFeatureValue","value","setFeatureDefaults","defaults","setDefaults"],"mappings":"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","sourcesContent":["/**\n * WordPress dependencies\n */\nimport deprecated from '@wordpress/deprecated';\nimport { store as preferencesStore } from '@wordpress/preferences';\n\n/**\n * Enable the complementary area.\n *\n * @param {string} scope Complementary area scope.\n * @param {string} area Area identifier.\n */\nexport const enableComplementaryArea = ( scope, area ) => ( { registry } ) => {\n\t// Return early if there's no area.\n\tif ( ! area ) {\n\t\treturn;\n\t}\n\n\tregistry\n\t\t.dispatch( preferencesStore )\n\t\t.set( scope, 'complementaryArea', area );\n};\n\n/**\n * Disable the complementary area.\n *\n * @param {string} scope Complementary area scope.\n */\nexport const disableComplementaryArea = ( scope ) => ( { registry } ) => {\n\tregistry\n\t\t.dispatch( preferencesStore )\n\t\t.set( scope, 'complementaryArea', null );\n};\n\n/**\n * Pins an item.\n *\n * @param {string} scope Item scope.\n * @param {string} item Item identifier.\n *\n * @return {Object} Action object.\n */\nexport const pinItem = ( scope, item ) => ( { registry } ) => {\n\t// Return early if there's no item.\n\tif ( ! item ) {\n\t\treturn;\n\t}\n\n\tconst pinnedItems = registry\n\t\t.select( preferencesStore )\n\t\t.get( scope, 'pinnedItems' );\n\n\t// The item is already pinned, there's nothing to do.\n\tif ( pinnedItems?.[ item ] === true ) {\n\t\treturn;\n\t}\n\n\tregistry.dispatch( preferencesStore ).set( scope, 'pinnedItems', {\n\t\t...pinnedItems,\n\t\t[ item ]: true,\n\t} );\n};\n\n/**\n * Unpins an item.\n *\n * @param {string} scope Item scope.\n * @param {string} item Item identifier.\n */\nexport const unpinItem = ( scope, item ) => ( { registry } ) => {\n\t// Return early if there's no item.\n\tif ( ! item ) {\n\t\treturn;\n\t}\n\n\tconst pinnedItems = registry\n\t\t.select( preferencesStore )\n\t\t.get( scope, 'pinnedItems' );\n\n\tregistry.dispatch( preferencesStore ).set( scope, 'pinnedItems', {\n\t\t...pinnedItems,\n\t\t[ item ]: false,\n\t} );\n};\n\n/**\n * Returns an action object used in signalling that a feature should be toggled.\n *\n * @param {string} scope The feature scope (e.g. core/edit-post).\n * @param {string} featureName The feature name.\n */\nexport function toggleFeature( scope, featureName ) {\n\treturn function ( { registry } ) {\n\t\tdeprecated( `wp.dispatch( 'core/interface' ).toggleFeature`, {\n\t\t\tsince: '6.0',\n\t\t\talternative: `wp.dispatch( 'core/preferences' ).toggle`,\n\t\t} );\n\n\t\tregistry.dispatch( preferencesStore ).toggle( scope, featureName );\n\t};\n}\n\n/**\n * Returns an action object used in signalling that a feature should be set to\n * a true or false value\n *\n * @param {string} scope The feature scope (e.g. core/edit-post).\n * @param {string} featureName The feature name.\n * @param {boolean} value The value to set.\n *\n * @return {Object} Action object.\n */\nexport function setFeatureValue( scope, featureName, value ) {\n\treturn function ( { registry } ) {\n\t\tdeprecated( `wp.dispatch( 'core/interface' ).setFeatureValue`, {\n\t\t\tsince: '6.0',\n\t\t\talternative: `wp.dispatch( 'core/preferences' ).set`,\n\t\t} );\n\n\t\tregistry\n\t\t\t.dispatch( preferencesStore )\n\t\t\t.set( scope, featureName, !! value );\n\t};\n}\n\n/**\n * Returns an action object used in signalling that defaults should be set for features.\n *\n * @param {string} scope The feature scope (e.g. core/edit-post).\n * @param {Object<string, boolean>} defaults A key/value map of feature names to values.\n *\n * @return {Object} Action object.\n */\nexport function setFeatureDefaults( scope, defaults ) {\n\treturn function ( { registry } ) {\n\t\tdeprecated( `wp.dispatch( 'core/interface' ).setFeatureDefaults`, {\n\t\t\tsince: '6.0',\n\t\t\talternative: `wp.dispatch( 'core/preferences' ).setDefaults`,\n\t\t} );\n\n\t\tregistry.dispatch( preferencesStore ).setDefaults( scope, defaults );\n\t};\n}\n"]}
@@ -1,21 +1,14 @@
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
  * Internal dependencies
7
7
  */
8
8
 
9
- import reducer from './reducer';
10
9
  import * as actions from './actions';
11
10
  import * as selectors from './selectors';
12
11
  import { STORE_NAME } from './constants';
13
- const storeConfig = {
14
- reducer,
15
- actions,
16
- selectors,
17
- persist: ['enableItems']
18
- };
19
12
  /**
20
13
  * Store definition for the interface namespace.
21
14
  *
@@ -24,8 +17,12 @@ const storeConfig = {
24
17
  * @type {Object}
25
18
  */
26
19
 
27
- export const store = createReduxStore(STORE_NAME, storeConfig); // Once we build a more generic persistence plugin that works across types of stores
20
+ export const store = createReduxStore(STORE_NAME, {
21
+ reducer: () => {},
22
+ actions,
23
+ selectors
24
+ }); // Once we build a more generic persistence plugin that works across types of stores
28
25
  // we'd be able to replace this with a register call.
29
26
 
30
- registerStore(STORE_NAME, storeConfig);
27
+ register(store);
31
28
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/interface/src/store/index.js"],"names":["createReduxStore","registerStore","reducer","actions","selectors","STORE_NAME","storeConfig","persist","store"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,gBAAT,EAA2BC,aAA3B,QAAgD,iBAAhD;AAEA;AACA;AACA;;AACA,OAAOC,OAAP,MAAoB,WAApB;AACA,OAAO,KAAKC,OAAZ,MAAyB,WAAzB;AACA,OAAO,KAAKC,SAAZ,MAA2B,aAA3B;AACA,SAASC,UAAT,QAA2B,aAA3B;AAEA,MAAMC,WAAW,GAAG;AACnBJ,EAAAA,OADmB;AAEnBC,EAAAA,OAFmB;AAGnBC,EAAAA,SAHmB;AAInBG,EAAAA,OAAO,EAAE,CAAE,aAAF;AAJU,CAApB;AAOA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMC,KAAK,GAAGR,gBAAgB,CAAEK,UAAF,EAAcC,WAAd,CAA9B,C,CAEP;AACA;;AACAL,aAAa,CAAEI,UAAF,EAAcC,WAAd,CAAb","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { createReduxStore, registerStore } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport reducer from './reducer';\nimport * as actions from './actions';\nimport * as selectors from './selectors';\nimport { STORE_NAME } from './constants';\n\nconst storeConfig = {\n\treducer,\n\tactions,\n\tselectors,\n\tpersist: [ 'enableItems' ],\n};\n\n/**\n * Store definition for the interface namespace.\n *\n * @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/data/README.md#createReduxStore\n *\n * @type {Object}\n */\nexport const store = createReduxStore( STORE_NAME, storeConfig );\n\n// Once we build a more generic persistence plugin that works across types of stores\n// we'd be able to replace this with a register call.\nregisterStore( STORE_NAME, storeConfig );\n"]}
1
+ {"version":3,"sources":["@wordpress/interface/src/store/index.js"],"names":["createReduxStore","register","actions","selectors","STORE_NAME","store","reducer"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,gBAAT,EAA2BC,QAA3B,QAA2C,iBAA3C;AAEA;AACA;AACA;;AACA,OAAO,KAAKC,OAAZ,MAAyB,WAAzB;AACA,OAAO,KAAKC,SAAZ,MAA2B,aAA3B;AACA,SAASC,UAAT,QAA2B,aAA3B;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMC,KAAK,GAAGL,gBAAgB,CAAEI,UAAF,EAAc;AAClDE,EAAAA,OAAO,EAAE,MAAM,CAAE,CADiC;AAElDJ,EAAAA,OAFkD;AAGlDC,EAAAA;AAHkD,CAAd,CAA9B,C,CAMP;AACA;;AACAF,QAAQ,CAAEI,KAAF,CAAR","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { createReduxStore, register } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport * as actions from './actions';\nimport * as selectors from './selectors';\nimport { STORE_NAME } from './constants';\n\n/**\n * Store definition for the interface namespace.\n *\n * @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/data/README.md#createReduxStore\n *\n * @type {Object}\n */\nexport const store = createReduxStore( STORE_NAME, {\n\treducer: () => {},\n\tactions,\n\tselectors,\n} );\n\n// Once we build a more generic persistence plugin that works across types of stores\n// we'd be able to replace this with a register call.\nregister( store );\n"]}
@@ -1,27 +1,9 @@
1
- /**
2
- * External dependencies
3
- */
4
- import { get } from 'lodash';
5
1
  /**
6
2
  * WordPress dependencies
7
3
  */
8
-
9
4
  import { createRegistrySelector } from '@wordpress/data';
10
5
  import deprecated from '@wordpress/deprecated';
11
6
  import { store as preferencesStore } from '@wordpress/preferences';
12
- /**
13
- * Returns the item that is enabled in a given scope.
14
- *
15
- * @param {Object} state Global application state.
16
- * @param {string} itemType Type of item.
17
- * @param {string} scope Item scope.
18
- *
19
- * @return {?string|null} The item that is enabled in the passed scope and type.
20
- */
21
-
22
- function getSingleEnableItem(state, itemType, scope) {
23
- return get(state.enableItems.singleEnableItems, [itemType, scope]);
24
- }
25
7
  /**
26
8
  * Returns the complementary area that is active in a given scope.
27
9
  *
@@ -31,24 +13,9 @@ function getSingleEnableItem(state, itemType, scope) {
31
13
  * @return {string} The complementary area that is active in the given scope.
32
14
  */
33
15
 
34
-
35
- export function getActiveComplementaryArea(state, scope) {
36
- return getSingleEnableItem(state, 'complementaryArea', scope);
37
- }
38
- /**
39
- * Returns a boolean indicating if an item is enabled or not in a given scope.
40
- *
41
- * @param {Object} state Global application state.
42
- * @param {string} itemType Type of item.
43
- * @param {string} scope Scope.
44
- * @param {string} item Item to check.
45
- *
46
- * @return {boolean|undefined} True if the item is enabled, false otherwise if the item is explicitly disabled, and undefined if there is no information for that item.
47
- */
48
-
49
- function isMultipleEnabledItemEnabled(state, itemType, scope, item) {
50
- return get(state.enableItems.multipleEnableItems, [itemType, scope, item]);
51
- }
16
+ export const getActiveComplementaryArea = createRegistrySelector(select => (state, scope) => {
17
+ return select(preferencesStore).get(scope, 'complementaryArea');
18
+ });
52
19
  /**
53
20
  * Returns a boolean indicating if an item is pinned or not.
54
21
  *
@@ -59,10 +26,12 @@ function isMultipleEnabledItemEnabled(state, itemType, scope, item) {
59
26
  * @return {boolean} True if the item is pinned and false otherwise.
60
27
  */
61
28
 
29
+ export const isItemPinned = createRegistrySelector(select => (state, scope, item) => {
30
+ var _pinnedItems$item;
62
31
 
63
- export function isItemPinned(state, scope, item) {
64
- return isMultipleEnabledItemEnabled(state, 'pinnedItems', scope, item) !== false;
65
- }
32
+ const pinnedItems = select(preferencesStore).get(scope, 'pinnedItems');
33
+ return (_pinnedItems$item = pinnedItems === null || pinnedItems === void 0 ? void 0 : pinnedItems[item]) !== null && _pinnedItems$item !== void 0 ? _pinnedItems$item : true;
34
+ });
66
35
  /**
67
36
  * Returns a boolean indicating whether a feature is active for a particular
68
37
  * scope.
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/interface/src/store/selectors.js"],"names":["get","createRegistrySelector","deprecated","store","preferencesStore","getSingleEnableItem","state","itemType","scope","enableItems","singleEnableItems","getActiveComplementaryArea","isMultipleEnabledItemEnabled","item","multipleEnableItems","isItemPinned","isFeatureActive","select","featureName","since","alternative"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,GAAT,QAAoB,QAApB;AAEA;AACA;AACA;;AACA,SAASC,sBAAT,QAAuC,iBAAvC;AACA,OAAOC,UAAP,MAAuB,uBAAvB;AACA,SAASC,KAAK,IAAIC,gBAAlB,QAA0C,wBAA1C;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,SAASC,mBAAT,CAA8BC,KAA9B,EAAqCC,QAArC,EAA+CC,KAA/C,EAAuD;AACtD,SAAOR,GAAG,CAAEM,KAAK,CAACG,WAAN,CAAkBC,iBAApB,EAAuC,CAAEH,QAAF,EAAYC,KAAZ,CAAvC,CAAV;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,OAAO,SAASG,0BAAT,CAAqCL,KAArC,EAA4CE,KAA5C,EAAoD;AAC1D,SAAOH,mBAAmB,CAAEC,KAAF,EAAS,mBAAT,EAA8BE,KAA9B,CAA1B;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,SAASI,4BAAT,CAAuCN,KAAvC,EAA8CC,QAA9C,EAAwDC,KAAxD,EAA+DK,IAA/D,EAAsE;AACrE,SAAOb,GAAG,CAAEM,KAAK,CAACG,WAAN,CAAkBK,mBAApB,EAAyC,CAClDP,QADkD,EAElDC,KAFkD,EAGlDK,IAHkD,CAAzC,CAAV;AAKA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,OAAO,SAASE,YAAT,CAAuBT,KAAvB,EAA8BE,KAA9B,EAAqCK,IAArC,EAA4C;AAClD,SACCD,4BAA4B,CAAEN,KAAF,EAAS,aAAT,EAAwBE,KAAxB,EAA+BK,IAA/B,CAA5B,KACA,KAFD;AAIA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMG,eAAe,GAAGf,sBAAsB,CAClDgB,MAAF,IAAc,CAAEX,KAAF,EAASE,KAAT,EAAgBU,WAAhB,KAAiC;AAC9ChB,EAAAA,UAAU,CACR,qEADQ,EAET;AACCiB,IAAAA,KAAK,EAAE,KADR;AAECC,IAAAA,WAAW,EAAG;AAFf,GAFS,CAAV;AAQA,SAAO,CAAC,CAAEH,MAAM,CAAEb,gBAAF,CAAN,CAA2BJ,GAA3B,CAAgCQ,KAAhC,EAAuCU,WAAvC,CAAV;AACA,CAXmD,CAA9C","sourcesContent":["/**\n * External dependencies\n */\nimport { get } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport { createRegistrySelector } from '@wordpress/data';\nimport deprecated from '@wordpress/deprecated';\nimport { store as preferencesStore } from '@wordpress/preferences';\n\n/**\n * Returns the item that is enabled in a given scope.\n *\n * @param {Object} state Global application state.\n * @param {string} itemType Type of item.\n * @param {string} scope Item scope.\n *\n * @return {?string|null} The item that is enabled in the passed scope and type.\n */\nfunction getSingleEnableItem( state, itemType, scope ) {\n\treturn get( state.enableItems.singleEnableItems, [ itemType, scope ] );\n}\n\n/**\n * Returns the complementary area that is active in a given scope.\n *\n * @param {Object} state Global application state.\n * @param {string} scope Item scope.\n *\n * @return {string} The complementary area that is active in the given scope.\n */\nexport function getActiveComplementaryArea( state, scope ) {\n\treturn getSingleEnableItem( state, 'complementaryArea', scope );\n}\n\n/**\n * Returns a boolean indicating if an item is enabled or not in a given scope.\n *\n * @param {Object} state Global application state.\n * @param {string} itemType Type of item.\n * @param {string} scope Scope.\n * @param {string} item Item to check.\n *\n * @return {boolean|undefined} True if the item is enabled, false otherwise if the item is explicitly disabled, and undefined if there is no information for that item.\n */\nfunction isMultipleEnabledItemEnabled( state, itemType, scope, item ) {\n\treturn get( state.enableItems.multipleEnableItems, [\n\t\titemType,\n\t\tscope,\n\t\titem,\n\t] );\n}\n\n/**\n * Returns a boolean indicating if an item is pinned or not.\n *\n * @param {Object} state Global application state.\n * @param {string} scope Scope.\n * @param {string} item Item to check.\n *\n * @return {boolean} True if the item is pinned and false otherwise.\n */\nexport function isItemPinned( state, scope, item ) {\n\treturn (\n\t\tisMultipleEnabledItemEnabled( state, 'pinnedItems', scope, item ) !==\n\t\tfalse\n\t);\n}\n\n/**\n * Returns a boolean indicating whether a feature is active for a particular\n * scope.\n *\n * @param {Object} state The store state.\n * @param {string} scope The scope of the feature (e.g. core/edit-post).\n * @param {string} featureName The name of the feature.\n *\n * @return {boolean} Is the feature enabled?\n */\nexport const isFeatureActive = createRegistrySelector(\n\t( select ) => ( state, scope, featureName ) => {\n\t\tdeprecated(\n\t\t\t`wp.select( 'core/interface' ).isFeatureActive( scope, featureName )`,\n\t\t\t{\n\t\t\t\tsince: '6.0',\n\t\t\t\talternative: `!! wp.select( 'core/preferences' ).isFeatureActive( scope, featureName )`,\n\t\t\t}\n\t\t);\n\n\t\treturn !! select( preferencesStore ).get( scope, featureName );\n\t}\n);\n"]}
1
+ {"version":3,"sources":["@wordpress/interface/src/store/selectors.js"],"names":["createRegistrySelector","deprecated","store","preferencesStore","getActiveComplementaryArea","select","state","scope","get","isItemPinned","item","pinnedItems","isFeatureActive","featureName","since","alternative"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,sBAAT,QAAuC,iBAAvC;AACA,OAAOC,UAAP,MAAuB,uBAAvB;AACA,SAASC,KAAK,IAAIC,gBAAlB,QAA0C,wBAA1C;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMC,0BAA0B,GAAGJ,sBAAsB,CAC7DK,MAAF,IAAc,CAAEC,KAAF,EAASC,KAAT,KAAoB;AACjC,SAAOF,MAAM,CAAEF,gBAAF,CAAN,CAA2BK,GAA3B,CAAgCD,KAAhC,EAAuC,mBAAvC,CAAP;AACA,CAH8D,CAAzD;AAMP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAME,YAAY,GAAGT,sBAAsB,CAC/CK,MAAF,IAAc,CAAEC,KAAF,EAASC,KAAT,EAAgBG,IAAhB,KAA0B;AAAA;;AACvC,QAAMC,WAAW,GAAGN,MAAM,CAAEF,gBAAF,CAAN,CAA2BK,GAA3B,CACnBD,KADmB,EAEnB,aAFmB,CAApB;AAIA,8BAAOI,WAAP,aAAOA,WAAP,uBAAOA,WAAW,CAAID,IAAJ,CAAlB,iEAAgC,IAAhC;AACA,CAPgD,CAA3C;AAUP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAME,eAAe,GAAGZ,sBAAsB,CAClDK,MAAF,IAAc,CAAEC,KAAF,EAASC,KAAT,EAAgBM,WAAhB,KAAiC;AAC9CZ,EAAAA,UAAU,CACR,qEADQ,EAET;AACCa,IAAAA,KAAK,EAAE,KADR;AAECC,IAAAA,WAAW,EAAG;AAFf,GAFS,CAAV;AAQA,SAAO,CAAC,CAAEV,MAAM,CAAEF,gBAAF,CAAN,CAA2BK,GAA3B,CAAgCD,KAAhC,EAAuCM,WAAvC,CAAV;AACA,CAXmD,CAA9C","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { createRegistrySelector } from '@wordpress/data';\nimport deprecated from '@wordpress/deprecated';\nimport { store as preferencesStore } from '@wordpress/preferences';\n\n/**\n * Returns the complementary area that is active in a given scope.\n *\n * @param {Object} state Global application state.\n * @param {string} scope Item scope.\n *\n * @return {string} The complementary area that is active in the given scope.\n */\nexport const getActiveComplementaryArea = createRegistrySelector(\n\t( select ) => ( state, scope ) => {\n\t\treturn select( preferencesStore ).get( scope, 'complementaryArea' );\n\t}\n);\n\n/**\n * Returns a boolean indicating if an item is pinned or not.\n *\n * @param {Object} state Global application state.\n * @param {string} scope Scope.\n * @param {string} item Item to check.\n *\n * @return {boolean} True if the item is pinned and false otherwise.\n */\nexport const isItemPinned = createRegistrySelector(\n\t( select ) => ( state, scope, item ) => {\n\t\tconst pinnedItems = select( preferencesStore ).get(\n\t\t\tscope,\n\t\t\t'pinnedItems'\n\t\t);\n\t\treturn pinnedItems?.[ item ] ?? true;\n\t}\n);\n\n/**\n * Returns a boolean indicating whether a feature is active for a particular\n * scope.\n *\n * @param {Object} state The store state.\n * @param {string} scope The scope of the feature (e.g. core/edit-post).\n * @param {string} featureName The name of the feature.\n *\n * @return {boolean} Is the feature enabled?\n */\nexport const isFeatureActive = createRegistrySelector(\n\t( select ) => ( state, scope, featureName ) => {\n\t\tdeprecated(\n\t\t\t`wp.select( 'core/interface' ).isFeatureActive( scope, featureName )`,\n\t\t\t{\n\t\t\t\tsince: '6.0',\n\t\t\t\talternative: `!! wp.select( 'core/preferences' ).isFeatureActive( scope, featureName )`,\n\t\t\t}\n\t\t);\n\n\t\treturn !! select( preferencesStore ).get( scope, featureName );\n\t}\n);\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wordpress/interface",
3
- "version": "4.4.0",
3
+ "version": "4.5.0",
4
4
  "description": "Interface module for WordPress. The package contains shared functionality across the modern JavaScript-based WordPress screens.",
5
5
  "author": "The WordPress Contributors",
6
6
  "license": "GPL-2.0-or-later",
@@ -32,17 +32,17 @@
32
32
  ],
33
33
  "dependencies": {
34
34
  "@babel/runtime": "^7.16.0",
35
- "@wordpress/a11y": "^3.5.0",
36
- "@wordpress/components": "^19.7.0",
37
- "@wordpress/compose": "^5.3.0",
38
- "@wordpress/data": "^6.5.0",
39
- "@wordpress/deprecated": "^3.5.0",
40
- "@wordpress/element": "^4.3.0",
41
- "@wordpress/i18n": "^4.5.0",
42
- "@wordpress/icons": "^8.1.0",
43
- "@wordpress/plugins": "^4.3.0",
44
- "@wordpress/preferences": "^1.1.0",
45
- "@wordpress/viewport": "^4.3.0",
35
+ "@wordpress/a11y": "^3.6.0",
36
+ "@wordpress/components": "^19.8.0",
37
+ "@wordpress/compose": "^5.4.0",
38
+ "@wordpress/data": "^6.6.0",
39
+ "@wordpress/deprecated": "^3.6.0",
40
+ "@wordpress/element": "^4.4.0",
41
+ "@wordpress/i18n": "^4.6.0",
42
+ "@wordpress/icons": "^8.2.0",
43
+ "@wordpress/plugins": "^4.4.0",
44
+ "@wordpress/preferences": "^1.2.0",
45
+ "@wordpress/viewport": "^4.4.0",
46
46
  "classnames": "^2.3.1",
47
47
  "lodash": "^4.17.21"
48
48
  },
@@ -53,5 +53,5 @@
53
53
  "publishConfig": {
54
54
  "access": "public"
55
55
  },
56
- "gitHead": "aa003c3634016cc4ab6348b2106907e371c648e1"
56
+ "gitHead": "11eb1241e63c9240018323551c6753f8a5fa96f9"
57
57
  }
@@ -5,89 +5,83 @@ import deprecated from '@wordpress/deprecated';
5
5
  import { store as preferencesStore } from '@wordpress/preferences';
6
6
 
7
7
  /**
8
- * Returns an action object used in signalling that an active area should be changed.
9
- *
10
- * @param {string} itemType Type of item.
11
- * @param {string} scope Item scope.
12
- * @param {string} item Item identifier.
13
- *
14
- * @return {Object} Action object.
15
- */
16
- function setSingleEnableItem( itemType, scope, item ) {
17
- return {
18
- type: 'SET_SINGLE_ENABLE_ITEM',
19
- itemType,
20
- scope,
21
- item,
22
- };
23
- }
24
-
25
- /**
26
- * Returns an action object used in signalling that a complementary item should be enabled.
8
+ * Enable the complementary area.
27
9
  *
28
10
  * @param {string} scope Complementary area scope.
29
11
  * @param {string} area Area identifier.
30
- *
31
- * @return {Object} Action object.
32
12
  */
33
- export function enableComplementaryArea( scope, area ) {
34
- return setSingleEnableItem( 'complementaryArea', scope, area );
35
- }
13
+ export const enableComplementaryArea = ( scope, area ) => ( { registry } ) => {
14
+ // Return early if there's no area.
15
+ if ( ! area ) {
16
+ return;
17
+ }
18
+
19
+ registry
20
+ .dispatch( preferencesStore )
21
+ .set( scope, 'complementaryArea', area );
22
+ };
36
23
 
37
24
  /**
38
- * Returns an action object used in signalling that the complementary area of a given scope should be disabled.
25
+ * Disable the complementary area.
39
26
  *
40
27
  * @param {string} scope Complementary area scope.
41
- *
42
- * @return {Object} Action object.
43
28
  */
44
- export function disableComplementaryArea( scope ) {
45
- return setSingleEnableItem( 'complementaryArea', scope, undefined );
46
- }
29
+ export const disableComplementaryArea = ( scope ) => ( { registry } ) => {
30
+ registry
31
+ .dispatch( preferencesStore )
32
+ .set( scope, 'complementaryArea', null );
33
+ };
47
34
 
48
35
  /**
49
- * Returns an action object to make an area enabled/disabled.
36
+ * Pins an item.
50
37
  *
51
- * @param {string} itemType Type of item.
52
- * @param {string} scope Item scope.
53
- * @param {string} item Item identifier.
54
- * @param {boolean} isEnable Boolean indicating if an area should be pinned or not.
38
+ * @param {string} scope Item scope.
39
+ * @param {string} item Item identifier.
55
40
  *
56
41
  * @return {Object} Action object.
57
42
  */
58
- function setMultipleEnableItem( itemType, scope, item, isEnable ) {
59
- return {
60
- type: 'SET_MULTIPLE_ENABLE_ITEM',
61
- itemType,
62
- scope,
63
- item,
64
- isEnable,
65
- };
66
- }
43
+ export const pinItem = ( scope, item ) => ( { registry } ) => {
44
+ // Return early if there's no item.
45
+ if ( ! item ) {
46
+ return;
47
+ }
67
48
 
68
- /**
69
- * Returns an action object used in signalling that an item should be pinned.
70
- *
71
- * @param {string} scope Item scope.
72
- * @param {string} itemId Item identifier.
73
- *
74
- * @return {Object} Action object.
75
- */
76
- export function pinItem( scope, itemId ) {
77
- return setMultipleEnableItem( 'pinnedItems', scope, itemId, true );
78
- }
49
+ const pinnedItems = registry
50
+ .select( preferencesStore )
51
+ .get( scope, 'pinnedItems' );
52
+
53
+ // The item is already pinned, there's nothing to do.
54
+ if ( pinnedItems?.[ item ] === true ) {
55
+ return;
56
+ }
57
+
58
+ registry.dispatch( preferencesStore ).set( scope, 'pinnedItems', {
59
+ ...pinnedItems,
60
+ [ item ]: true,
61
+ } );
62
+ };
79
63
 
80
64
  /**
81
- * Returns an action object used in signalling that an item should be unpinned.
65
+ * Unpins an item.
82
66
  *
83
- * @param {string} scope Item scope.
84
- * @param {string} itemId Item identifier.
85
- *
86
- * @return {Object} Action object.
67
+ * @param {string} scope Item scope.
68
+ * @param {string} item Item identifier.
87
69
  */
88
- export function unpinItem( scope, itemId ) {
89
- return setMultipleEnableItem( 'pinnedItems', scope, itemId, false );
90
- }
70
+ export const unpinItem = ( scope, item ) => ( { registry } ) => {
71
+ // Return early if there's no item.
72
+ if ( ! item ) {
73
+ return;
74
+ }
75
+
76
+ const pinnedItems = registry
77
+ .select( preferencesStore )
78
+ .get( scope, 'pinnedItems' );
79
+
80
+ registry.dispatch( preferencesStore ).set( scope, 'pinnedItems', {
81
+ ...pinnedItems,
82
+ [ item ]: false,
83
+ } );
84
+ };
91
85
 
92
86
  /**
93
87
  * Returns an action object used in signalling that a feature should be toggled.
@@ -1,23 +1,15 @@
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
8
8
  */
9
- import reducer from './reducer';
10
9
  import * as actions from './actions';
11
10
  import * as selectors from './selectors';
12
11
  import { STORE_NAME } from './constants';
13
12
 
14
- const storeConfig = {
15
- reducer,
16
- actions,
17
- selectors,
18
- persist: [ 'enableItems' ],
19
- };
20
-
21
13
  /**
22
14
  * Store definition for the interface namespace.
23
15
  *
@@ -25,8 +17,12 @@ const storeConfig = {
25
17
  *
26
18
  * @type {Object}
27
19
  */
28
- export const store = createReduxStore( STORE_NAME, storeConfig );
20
+ export const store = createReduxStore( STORE_NAME, {
21
+ reducer: () => {},
22
+ actions,
23
+ selectors,
24
+ } );
29
25
 
30
26
  // Once we build a more generic persistence plugin that works across types of stores
31
27
  // we'd be able to replace this with a register call.
32
- registerStore( STORE_NAME, storeConfig );
28
+ register( store );
@@ -1,8 +1,3 @@
1
- /**
2
- * External dependencies
3
- */
4
- import { get } from 'lodash';
5
-
6
1
  /**
7
2
  * WordPress dependencies
8
3
  */
@@ -10,19 +5,6 @@ import { createRegistrySelector } from '@wordpress/data';
10
5
  import deprecated from '@wordpress/deprecated';
11
6
  import { store as preferencesStore } from '@wordpress/preferences';
12
7
 
13
- /**
14
- * Returns the item that is enabled in a given scope.
15
- *
16
- * @param {Object} state Global application state.
17
- * @param {string} itemType Type of item.
18
- * @param {string} scope Item scope.
19
- *
20
- * @return {?string|null} The item that is enabled in the passed scope and type.
21
- */
22
- function getSingleEnableItem( state, itemType, scope ) {
23
- return get( state.enableItems.singleEnableItems, [ itemType, scope ] );
24
- }
25
-
26
8
  /**
27
9
  * Returns the complementary area that is active in a given scope.
28
10
  *
@@ -31,27 +13,11 @@ function getSingleEnableItem( state, itemType, scope ) {
31
13
  *
32
14
  * @return {string} The complementary area that is active in the given scope.
33
15
  */
34
- export function getActiveComplementaryArea( state, scope ) {
35
- return getSingleEnableItem( state, 'complementaryArea', scope );
36
- }
37
-
38
- /**
39
- * Returns a boolean indicating if an item is enabled or not in a given scope.
40
- *
41
- * @param {Object} state Global application state.
42
- * @param {string} itemType Type of item.
43
- * @param {string} scope Scope.
44
- * @param {string} item Item to check.
45
- *
46
- * @return {boolean|undefined} True if the item is enabled, false otherwise if the item is explicitly disabled, and undefined if there is no information for that item.
47
- */
48
- function isMultipleEnabledItemEnabled( state, itemType, scope, item ) {
49
- return get( state.enableItems.multipleEnableItems, [
50
- itemType,
51
- scope,
52
- item,
53
- ] );
54
- }
16
+ export const getActiveComplementaryArea = createRegistrySelector(
17
+ ( select ) => ( state, scope ) => {
18
+ return select( preferencesStore ).get( scope, 'complementaryArea' );
19
+ }
20
+ );
55
21
 
56
22
  /**
57
23
  * Returns a boolean indicating if an item is pinned or not.
@@ -62,12 +28,15 @@ function isMultipleEnabledItemEnabled( state, itemType, scope, item ) {
62
28
  *
63
29
  * @return {boolean} True if the item is pinned and false otherwise.
64
30
  */
65
- export function isItemPinned( state, scope, item ) {
66
- return (
67
- isMultipleEnabledItemEnabled( state, 'pinnedItems', scope, item ) !==
68
- false
69
- );
70
- }
31
+ export const isItemPinned = createRegistrySelector(
32
+ ( select ) => ( state, scope, item ) => {
33
+ const pinnedItems = select( preferencesStore ).get(
34
+ scope,
35
+ 'pinnedItems'
36
+ );
37
+ return pinnedItems?.[ item ] ?? true;
38
+ }
39
+ );
71
40
 
72
41
  /**
73
42
  * Returns a boolean indicating whether a feature is active for a particular
@@ -22,6 +22,141 @@ describe( 'actions', () => {
22
22
  registry = createRegistryWithStores();
23
23
  } );
24
24
 
25
+ describe( 'enableComplementaryArea', () => {
26
+ it( 'sets a single area as active in the complementary area', () => {
27
+ // Starts off as `undefined`.
28
+ expect(
29
+ registry
30
+ .select( interfaceStore )
31
+ .getActiveComplementaryArea( 'my-plugin' )
32
+ ).toBeUndefined();
33
+
34
+ registry
35
+ .dispatch( interfaceStore )
36
+ .enableComplementaryArea( 'my-plugin', 'custom-sidebar-1' );
37
+
38
+ expect(
39
+ registry
40
+ .select( interfaceStore )
41
+ .getActiveComplementaryArea( 'my-plugin' )
42
+ ).toBe( 'custom-sidebar-1' );
43
+
44
+ registry
45
+ .dispatch( interfaceStore )
46
+ .enableComplementaryArea( 'my-plugin', 'custom-sidebar-2' );
47
+
48
+ expect(
49
+ registry
50
+ .select( interfaceStore )
51
+ .getActiveComplementaryArea( 'my-plugin' )
52
+ ).toBe( 'custom-sidebar-2' );
53
+ } );
54
+ } );
55
+
56
+ describe( 'disableComplementaryArea', () => {
57
+ it( 'removes any assignment to a complementary area', () => {
58
+ registry
59
+ .dispatch( interfaceStore )
60
+ .enableComplementaryArea( 'my-plugin', 'custom-sidebar' );
61
+
62
+ expect(
63
+ registry
64
+ .select( interfaceStore )
65
+ .getActiveComplementaryArea( 'my-plugin' )
66
+ ).toBe( 'custom-sidebar' );
67
+
68
+ registry
69
+ .dispatch( interfaceStore )
70
+ .disableComplementaryArea( 'my-plugin' );
71
+
72
+ expect(
73
+ registry
74
+ .select( interfaceStore )
75
+ .getActiveComplementaryArea( 'my-plugin' )
76
+ ).toBeNull();
77
+ } );
78
+ } );
79
+
80
+ describe( 'pinItem / unpinItem', () => {
81
+ it( 'can be used to pin and unpin multiple items using successive calls', () => {
82
+ // Items are pinned by default.
83
+ expect(
84
+ registry
85
+ .select( interfaceStore )
86
+ .isItemPinned( 'my-plugin', 'ui-item-1' )
87
+ ).toBe( true );
88
+
89
+ expect(
90
+ registry
91
+ .select( interfaceStore )
92
+ .isItemPinned( 'my-plugin', 'ui-item-2' )
93
+ ).toBe( true );
94
+
95
+ // Unpinning the default value works.
96
+ registry
97
+ .dispatch( interfaceStore )
98
+ .unpinItem( 'my-plugin', 'ui-item-1' );
99
+
100
+ registry
101
+ .dispatch( interfaceStore )
102
+ .unpinItem( 'my-plugin', 'ui-item-2' );
103
+
104
+ expect(
105
+ registry
106
+ .select( interfaceStore )
107
+ .isItemPinned( 'my-plugin', 'ui-item-1' )
108
+ ).toBe( false );
109
+
110
+ expect(
111
+ registry
112
+ .select( interfaceStore )
113
+ .isItemPinned( 'my-plugin', 'ui-item-2' )
114
+ ).toBe( false );
115
+
116
+ // Now explicitly set the items to be pinned.
117
+ registry
118
+ .dispatch( interfaceStore )
119
+ .pinItem( 'my-plugin', 'ui-item-1' );
120
+
121
+ registry
122
+ .dispatch( interfaceStore )
123
+ .pinItem( 'my-plugin', 'ui-item-2' );
124
+
125
+ expect(
126
+ registry
127
+ .select( interfaceStore )
128
+ .isItemPinned( 'my-plugin', 'ui-item-1' )
129
+ ).toBe( true );
130
+
131
+ expect(
132
+ registry
133
+ .select( interfaceStore )
134
+ .isItemPinned( 'my-plugin', 'ui-item-2' )
135
+ ).toBe( true );
136
+
137
+ // Unpinning should still work.
138
+ registry
139
+ .dispatch( interfaceStore )
140
+ .unpinItem( 'my-plugin', 'ui-item-1' );
141
+
142
+ registry
143
+ .dispatch( interfaceStore )
144
+ .unpinItem( 'my-plugin', 'ui-item-2' );
145
+
146
+ expect(
147
+ registry
148
+ .select( interfaceStore )
149
+ .isItemPinned( 'my-plugin', 'ui-item-1' )
150
+ ).toBe( false );
151
+
152
+ expect(
153
+ registry
154
+ .select( interfaceStore )
155
+ .isItemPinned( 'my-plugin', 'ui-item-2' )
156
+ ).toBe( false );
157
+ } );
158
+ } );
159
+
25
160
  describe( 'setFeatureDefaults', () => {
26
161
  it( 'results in default values being present', () => {
27
162
  registry.dispatch( interfaceStore ).setFeatureDefaults( 'test', {