@wordpress/interface 4.7.0 → 4.8.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.
- package/CHANGELOG.md +2 -0
- package/build/store/actions.js +42 -10
- package/build/store/actions.js.map +1 -1
- package/build/store/index.js +5 -1
- package/build/store/index.js.map +1 -1
- package/build/store/reducer.js +55 -0
- package/build/store/reducer.js.map +1 -0
- package/build/store/selectors.js +19 -4
- package/build/store/selectors.js.map +1 -1
- package/build-module/store/actions.js +38 -9
- package/build-module/store/actions.js.map +1 -1
- package/build-module/store/index.js +2 -1
- package/build-module/store/index.js.map +1 -1
- package/build-module/store/reducer.js +43 -0
- package/build-module/store/reducer.js.map +1 -0
- package/build-module/store/selectors.js +19 -4
- package/build-module/store/selectors.js.map +1 -1
- package/build-style/style-rtl.css +0 -1
- package/build-style/style.css +0 -1
- package/package.json +13 -13
- package/src/components/more-menu-dropdown/style.scss +0 -1
- package/src/store/actions.js +48 -13
- package/src/store/index.js +2 -1
- package/src/store/reducer.js +35 -0
- package/src/store/selectors.js +21 -4
- package/src/store/test/actions.js +1 -1
package/CHANGELOG.md
CHANGED
package/build/store/actions.js
CHANGED
|
@@ -5,7 +5,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
|
-
exports.pinItem = exports.enableComplementaryArea = exports.disableComplementaryArea = void 0;
|
|
8
|
+
exports.setDefaultComplementaryArea = exports.pinItem = exports.enableComplementaryArea = exports.disableComplementaryArea = void 0;
|
|
9
9
|
exports.setFeatureDefaults = setFeatureDefaults;
|
|
10
10
|
exports.setFeatureValue = setFeatureValue;
|
|
11
11
|
exports.toggleFeature = toggleFeature;
|
|
@@ -19,15 +19,33 @@ var _preferences = require("@wordpress/preferences");
|
|
|
19
19
|
* WordPress dependencies
|
|
20
20
|
*/
|
|
21
21
|
|
|
22
|
+
/**
|
|
23
|
+
* Set a default complementary area.
|
|
24
|
+
*
|
|
25
|
+
* @param {string} scope Complementary area scope.
|
|
26
|
+
* @param {string} area Area identifier.
|
|
27
|
+
*
|
|
28
|
+
* @return {Object} Action object.
|
|
29
|
+
*/
|
|
30
|
+
const setDefaultComplementaryArea = (scope, area) => ({
|
|
31
|
+
type: 'SET_DEFAULT_COMPLEMENTARY_AREA',
|
|
32
|
+
scope,
|
|
33
|
+
area
|
|
34
|
+
});
|
|
22
35
|
/**
|
|
23
36
|
* Enable the complementary area.
|
|
24
37
|
*
|
|
25
38
|
* @param {string} scope Complementary area scope.
|
|
26
39
|
* @param {string} area Area identifier.
|
|
27
40
|
*/
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
exports.setDefaultComplementaryArea = setDefaultComplementaryArea;
|
|
44
|
+
|
|
28
45
|
const enableComplementaryArea = (scope, area) => _ref => {
|
|
29
46
|
let {
|
|
30
|
-
registry
|
|
47
|
+
registry,
|
|
48
|
+
dispatch
|
|
31
49
|
} = _ref;
|
|
32
50
|
|
|
33
51
|
// Return early if there's no area.
|
|
@@ -35,7 +53,17 @@ const enableComplementaryArea = (scope, area) => _ref => {
|
|
|
35
53
|
return;
|
|
36
54
|
}
|
|
37
55
|
|
|
38
|
-
registry.
|
|
56
|
+
const isComplementaryAreaVisible = registry.select(_preferences.store).get(scope, 'isComplementaryAreaVisible');
|
|
57
|
+
|
|
58
|
+
if (!isComplementaryAreaVisible) {
|
|
59
|
+
registry.dispatch(_preferences.store).set(scope, 'isComplementaryAreaVisible', true);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
dispatch({
|
|
63
|
+
type: 'ENABLE_COMPLEMENTARY_AREA',
|
|
64
|
+
scope,
|
|
65
|
+
area
|
|
66
|
+
});
|
|
39
67
|
};
|
|
40
68
|
/**
|
|
41
69
|
* Disable the complementary area.
|
|
@@ -50,7 +78,11 @@ const disableComplementaryArea = scope => _ref2 => {
|
|
|
50
78
|
let {
|
|
51
79
|
registry
|
|
52
80
|
} = _ref2;
|
|
53
|
-
registry.
|
|
81
|
+
const isComplementaryAreaVisible = registry.select(_preferences.store).get(scope, 'isComplementaryAreaVisible');
|
|
82
|
+
|
|
83
|
+
if (isComplementaryAreaVisible) {
|
|
84
|
+
registry.dispatch(_preferences.store).set(scope, 'isComplementaryAreaVisible', false);
|
|
85
|
+
}
|
|
54
86
|
};
|
|
55
87
|
/**
|
|
56
88
|
* Pins an item.
|
|
@@ -124,9 +156,9 @@ function toggleFeature(scope, featureName) {
|
|
|
124
156
|
let {
|
|
125
157
|
registry
|
|
126
158
|
} = _ref5;
|
|
127
|
-
(0, _deprecated.default)(`
|
|
159
|
+
(0, _deprecated.default)(`dispatch( 'core/interface' ).toggleFeature`, {
|
|
128
160
|
since: '6.0',
|
|
129
|
-
alternative: `
|
|
161
|
+
alternative: `dispatch( 'core/preferences' ).toggle`
|
|
130
162
|
});
|
|
131
163
|
registry.dispatch(_preferences.store).toggle(scope, featureName);
|
|
132
164
|
};
|
|
@@ -148,9 +180,9 @@ function setFeatureValue(scope, featureName, value) {
|
|
|
148
180
|
let {
|
|
149
181
|
registry
|
|
150
182
|
} = _ref6;
|
|
151
|
-
(0, _deprecated.default)(`
|
|
183
|
+
(0, _deprecated.default)(`dispatch( 'core/interface' ).setFeatureValue`, {
|
|
152
184
|
since: '6.0',
|
|
153
|
-
alternative: `
|
|
185
|
+
alternative: `dispatch( 'core/preferences' ).set`
|
|
154
186
|
});
|
|
155
187
|
registry.dispatch(_preferences.store).set(scope, featureName, !!value);
|
|
156
188
|
};
|
|
@@ -170,9 +202,9 @@ function setFeatureDefaults(scope, defaults) {
|
|
|
170
202
|
let {
|
|
171
203
|
registry
|
|
172
204
|
} = _ref7;
|
|
173
|
-
(0, _deprecated.default)(`
|
|
205
|
+
(0, _deprecated.default)(`dispatch( 'core/interface' ).setFeatureDefaults`, {
|
|
174
206
|
since: '6.0',
|
|
175
|
-
alternative: `
|
|
207
|
+
alternative: `dispatch( 'core/preferences' ).setDefaults`
|
|
176
208
|
});
|
|
177
209
|
registry.dispatch(_preferences.store).setDefaults(scope, defaults);
|
|
178
210
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/interface/src/store/actions.js"],"names":["
|
|
1
|
+
{"version":3,"sources":["@wordpress/interface/src/store/actions.js"],"names":["setDefaultComplementaryArea","scope","area","type","enableComplementaryArea","registry","dispatch","isComplementaryAreaVisible","select","preferencesStore","get","set","disableComplementaryArea","pinItem","item","pinnedItems","unpinItem","toggleFeature","featureName","since","alternative","toggle","setFeatureValue","value","setFeatureDefaults","defaults","setDefaults"],"mappings":";;;;;;;;;;;;;AAGA;;AACA;;AAJA;AACA;AACA;;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMA,2BAA2B,GAAG,CAAEC,KAAF,EAASC,IAAT,MAAqB;AAC/DC,EAAAA,IAAI,EAAE,gCADyD;AAE/DF,EAAAA,KAF+D;AAG/DC,EAAAA;AAH+D,CAArB,CAApC;AAMP;AACA;AACA;AACA;AACA;AACA;;;;;AACO,MAAME,uBAAuB,GAAG,CAAEH,KAAF,EAASC,IAAT,KAAmB,QAGnD;AAAA,MAHqD;AAC3DG,IAAAA,QAD2D;AAE3DC,IAAAA;AAF2D,GAGrD;;AACN;AACA,MAAK,CAAEJ,IAAP,EAAc;AACb;AACA;;AAED,QAAMK,0BAA0B,GAAGF,QAAQ,CACzCG,MADiC,CACzBC,kBADyB,EAEjCC,GAFiC,CAE5BT,KAF4B,EAErB,4BAFqB,CAAnC;;AAIA,MAAK,CAAEM,0BAAP,EAAoC;AACnCF,IAAAA,QAAQ,CACNC,QADF,CACYG,kBADZ,EAEEE,GAFF,CAEOV,KAFP,EAEc,4BAFd,EAE4C,IAF5C;AAGA;;AAEDK,EAAAA,QAAQ,CAAE;AACTH,IAAAA,IAAI,EAAE,2BADG;AAETF,IAAAA,KAFS;AAGTC,IAAAA;AAHS,GAAF,CAAR;AAKA,CA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E,KADuD;AAE9DC,MAAAA,WAAW,EAAG;AAFgD,KAA/D;AAKAf,IAAAA,QAAQ,CAACC,QAAT,CAAmBG,kBAAnB,EAAsCiB,WAAtC,CAAmDzB,KAAnD,EAA0DwB,QAA1D;AACA,GAPD;AAQA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport deprecated from '@wordpress/deprecated';\nimport { store as preferencesStore } from '@wordpress/preferences';\n\n/**\n * Set a default complementary area.\n *\n * @param {string} scope Complementary area scope.\n * @param {string} area Area identifier.\n *\n * @return {Object} Action object.\n */\nexport const setDefaultComplementaryArea = ( scope, area ) => ( {\n\ttype: 'SET_DEFAULT_COMPLEMENTARY_AREA',\n\tscope,\n\tarea,\n} );\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 ) => ( {\n\tregistry,\n\tdispatch,\n} ) => {\n\t// Return early if there's no area.\n\tif ( ! area ) {\n\t\treturn;\n\t}\n\n\tconst isComplementaryAreaVisible = registry\n\t\t.select( preferencesStore )\n\t\t.get( scope, 'isComplementaryAreaVisible' );\n\n\tif ( ! isComplementaryAreaVisible ) {\n\t\tregistry\n\t\t\t.dispatch( preferencesStore )\n\t\t\t.set( scope, 'isComplementaryAreaVisible', true );\n\t}\n\n\tdispatch( {\n\t\ttype: 'ENABLE_COMPLEMENTARY_AREA',\n\t\tscope,\n\t\tarea,\n\t} );\n};\n\n/**\n * Disable the complementary area.\n *\n * @param {string} scope Complementary area scope.\n */\nexport const disableComplementaryArea = ( scope ) => ( { registry } ) => {\n\tconst isComplementaryAreaVisible = registry\n\t\t.select( preferencesStore )\n\t\t.get( scope, 'isComplementaryAreaVisible' );\n\n\tif ( isComplementaryAreaVisible ) {\n\t\tregistry\n\t\t\t.dispatch( preferencesStore )\n\t\t\t.set( scope, 'isComplementaryAreaVisible', false );\n\t}\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( `dispatch( 'core/interface' ).toggleFeature`, {\n\t\t\tsince: '6.0',\n\t\t\talternative: `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( `dispatch( 'core/interface' ).setFeatureValue`, {\n\t\t\tsince: '6.0',\n\t\t\talternative: `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( `dispatch( 'core/interface' ).setFeatureDefaults`, {\n\t\t\tsince: '6.0',\n\t\t\talternative: `dispatch( 'core/preferences' ).setDefaults`,\n\t\t} );\n\n\t\tregistry.dispatch( preferencesStore ).setDefaults( scope, defaults );\n\t};\n}\n"]}
|
package/build/store/index.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
3
5
|
Object.defineProperty(exports, "__esModule", {
|
|
4
6
|
value: true
|
|
5
7
|
});
|
|
@@ -11,6 +13,8 @@ var actions = _interopRequireWildcard(require("./actions"));
|
|
|
11
13
|
|
|
12
14
|
var selectors = _interopRequireWildcard(require("./selectors"));
|
|
13
15
|
|
|
16
|
+
var _reducer = _interopRequireDefault(require("./reducer"));
|
|
17
|
+
|
|
14
18
|
var _constants = require("./constants");
|
|
15
19
|
|
|
16
20
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
@@ -33,7 +37,7 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
|
|
|
33
37
|
* @type {Object}
|
|
34
38
|
*/
|
|
35
39
|
const store = (0, _data.createReduxStore)(_constants.STORE_NAME, {
|
|
36
|
-
reducer:
|
|
40
|
+
reducer: _reducer.default,
|
|
37
41
|
actions,
|
|
38
42
|
selectors
|
|
39
43
|
}); // Once we build a more generic persistence plugin that works across types of stores
|
package/build/store/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/interface/src/store/index.js"],"names":["store","STORE_NAME","reducer","actions","selectors"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["@wordpress/interface/src/store/index.js"],"names":["store","STORE_NAME","reducer","actions","selectors"],"mappings":";;;;;;;;;AAGA;;AAKA;;AACA;;AACA;;AACA;;;;;;AAXA;AACA;AACA;;AAGA;AACA;AACA;;AAMA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMA,KAAK,GAAG,4BAAkBC,qBAAlB,EAA8B;AAClDC,EAAAA,OAAO,EAAPA,gBADkD;AAElDC,EAAAA,OAFkD;AAGlDC,EAAAA;AAHkD,CAA9B,CAAd,C,CAMP;AACA;;;AACA,oBAAUJ,KAAV","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 reducer from './reducer';\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"]}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.complementaryAreas = complementaryAreas;
|
|
7
|
+
exports.default = void 0;
|
|
8
|
+
|
|
9
|
+
var _data = require("@wordpress/data");
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* WordPress dependencies
|
|
13
|
+
*/
|
|
14
|
+
function complementaryAreas() {
|
|
15
|
+
let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
16
|
+
let action = arguments.length > 1 ? arguments[1] : undefined;
|
|
17
|
+
|
|
18
|
+
switch (action.type) {
|
|
19
|
+
case 'SET_DEFAULT_COMPLEMENTARY_AREA':
|
|
20
|
+
{
|
|
21
|
+
const {
|
|
22
|
+
scope,
|
|
23
|
+
area
|
|
24
|
+
} = action; // If there's already an area, don't overwrite it.
|
|
25
|
+
|
|
26
|
+
if (state[scope]) {
|
|
27
|
+
return state;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return { ...state,
|
|
31
|
+
[scope]: area
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
case 'ENABLE_COMPLEMENTARY_AREA':
|
|
36
|
+
{
|
|
37
|
+
const {
|
|
38
|
+
scope,
|
|
39
|
+
area
|
|
40
|
+
} = action;
|
|
41
|
+
return { ...state,
|
|
42
|
+
[scope]: area
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return state;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
var _default = (0, _data.combineReducers)({
|
|
51
|
+
complementaryAreas
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
exports.default = _default;
|
|
55
|
+
//# sourceMappingURL=reducer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["@wordpress/interface/src/store/reducer.js"],"names":["complementaryAreas","state","action","type","scope","area"],"mappings":";;;;;;;;AAGA;;AAHA;AACA;AACA;AAGO,SAASA,kBAAT,GAAkD;AAAA,MAArBC,KAAqB,uEAAb,EAAa;AAAA,MAATC,MAAS;;AACxD,UAASA,MAAM,CAACC,IAAhB;AACC,SAAK,gCAAL;AAAuC;AACtC,cAAM;AAAEC,UAAAA,KAAF;AAASC,UAAAA;AAAT,YAAkBH,MAAxB,CADsC,CAGtC;;AACA,YAAKD,KAAK,CAAEG,KAAF,CAAV,EAAsB;AACrB,iBAAOH,KAAP;AACA;;AAED,eAAO,EACN,GAAGA,KADG;AAEN,WAAEG,KAAF,GAAWC;AAFL,SAAP;AAIA;;AACD,SAAK,2BAAL;AAAkC;AACjC,cAAM;AAAED,UAAAA,KAAF;AAASC,UAAAA;AAAT,YAAkBH,MAAxB;AACA,eAAO,EACN,GAAGD,KADG;AAEN,WAAEG,KAAF,GAAWC;AAFL,SAAP;AAIA;AApBF;;AAuBA,SAAOJ,KAAP;AACA;;eAEc,2BAAiB;AAC/BD,EAAAA;AAD+B,CAAjB,C","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { combineReducers } from '@wordpress/data';\n\nexport function complementaryAreas( state = {}, action ) {\n\tswitch ( action.type ) {\n\t\tcase 'SET_DEFAULT_COMPLEMENTARY_AREA': {\n\t\t\tconst { scope, area } = action;\n\n\t\t\t// If there's already an area, don't overwrite it.\n\t\t\tif ( state[ scope ] ) {\n\t\t\t\treturn state;\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\t...state,\n\t\t\t\t[ scope ]: area,\n\t\t\t};\n\t\t}\n\t\tcase 'ENABLE_COMPLEMENTARY_AREA': {\n\t\t\tconst { scope, area } = action;\n\t\t\treturn {\n\t\t\t\t...state,\n\t\t\t\t[ scope ]: area,\n\t\t\t};\n\t\t}\n\t}\n\n\treturn state;\n}\n\nexport default combineReducers( {\n\tcomplementaryAreas,\n} );\n"]}
|
package/build/store/selectors.js
CHANGED
|
@@ -23,10 +23,25 @@ var _preferences = require("@wordpress/preferences");
|
|
|
23
23
|
* @param {Object} state Global application state.
|
|
24
24
|
* @param {string} scope Item scope.
|
|
25
25
|
*
|
|
26
|
-
* @return {string} The complementary area that is active in the given scope.
|
|
26
|
+
* @return {string | null | undefined} The complementary area that is active in the given scope.
|
|
27
27
|
*/
|
|
28
28
|
const getActiveComplementaryArea = (0, _data.createRegistrySelector)(select => (state, scope) => {
|
|
29
|
-
|
|
29
|
+
var _state$complementaryA;
|
|
30
|
+
|
|
31
|
+
const isComplementaryAreaVisible = select(_preferences.store).get(scope, 'isComplementaryAreaVisible'); // Return `undefined` to indicate that the user has never toggled
|
|
32
|
+
// visibility, this is the vanilla default. Other code relies on this
|
|
33
|
+
// nuance in the return value.
|
|
34
|
+
|
|
35
|
+
if (isComplementaryAreaVisible === undefined) {
|
|
36
|
+
return undefined;
|
|
37
|
+
} // Return `null` to indicate the user hid the complementary area.
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
if (!isComplementaryAreaVisible) {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return state === null || state === void 0 ? void 0 : (_state$complementaryA = state.complementaryAreas) === null || _state$complementaryA === void 0 ? void 0 : _state$complementaryA[scope];
|
|
30
45
|
});
|
|
31
46
|
/**
|
|
32
47
|
* Returns a boolean indicating if an item is pinned or not.
|
|
@@ -58,9 +73,9 @@ const isItemPinned = (0, _data.createRegistrySelector)(select => (state, scope,
|
|
|
58
73
|
|
|
59
74
|
exports.isItemPinned = isItemPinned;
|
|
60
75
|
const isFeatureActive = (0, _data.createRegistrySelector)(select => (state, scope, featureName) => {
|
|
61
|
-
(0, _deprecated.default)(`
|
|
76
|
+
(0, _deprecated.default)(`select( 'core/interface' ).isFeatureActive( scope, featureName )`, {
|
|
62
77
|
since: '6.0',
|
|
63
|
-
alternative:
|
|
78
|
+
alternative: `select( 'core/preferences' ).get( scope, featureName )`
|
|
64
79
|
});
|
|
65
80
|
return !!select(_preferences.store).get(scope, featureName);
|
|
66
81
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/interface/src/store/selectors.js"],"names":["getActiveComplementaryArea","select","state","scope","preferencesStore","get","isItemPinned","item","pinnedItems","isFeatureActive","featureName","since","alternative"],"mappings":";;;;;;;;;AAGA;;AACA;;AACA;;AALA;AACA;AACA;;AAKA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMA,0BAA0B,GAAG,kCACvCC,MAAF,IAAc,CAAEC,KAAF,EAASC,KAAT,KAAoB;AACjC,
|
|
1
|
+
{"version":3,"sources":["@wordpress/interface/src/store/selectors.js"],"names":["getActiveComplementaryArea","select","state","scope","isComplementaryAreaVisible","preferencesStore","get","undefined","complementaryAreas","isItemPinned","item","pinnedItems","isFeatureActive","featureName","since","alternative"],"mappings":";;;;;;;;;AAGA;;AACA;;AACA;;AALA;AACA;AACA;;AAKA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMA,0BAA0B,GAAG,kCACvCC,MAAF,IAAc,CAAEC,KAAF,EAASC,KAAT,KAAoB;AAAA;;AACjC,QAAMC,0BAA0B,GAAGH,MAAM,CAAEI,kBAAF,CAAN,CAA2BC,GAA3B,CAClCH,KADkC,EAElC,4BAFkC,CAAnC,CADiC,CAMjC;AACA;AACA;;AACA,MAAKC,0BAA0B,KAAKG,SAApC,EAAgD;AAC/C,WAAOA,SAAP;AACA,GAXgC,CAajC;;;AACA,MAAK,CAAEH,0BAAP,EAAoC;AACnC,WAAO,IAAP;AACA;;AAED,SAAOF,KAAP,aAAOA,KAAP,gDAAOA,KAAK,CAAEM,kBAAd,0DAAO,sBAA6BL,KAA7B,CAAP;AACA,CApBwC,CAAnC;AAuBP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,MAAMM,YAAY,GAAG,kCACzBR,MAAF,IAAc,CAAEC,KAAF,EAASC,KAAT,EAAgBO,IAAhB,KAA0B;AAAA;;AACvC,QAAMC,WAAW,GAAGV,MAAM,CAAEI,kBAAF,CAAN,CAA2BC,GAA3B,CACnBH,KADmB,EAEnB,aAFmB,CAApB;AAIA,8BAAOQ,WAAP,aAAOA,WAAP,uBAAOA,WAAW,CAAID,IAAJ,CAAlB,iEAAgC,IAAhC;AACA,CAP0B,CAArB;AAUP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,MAAME,eAAe,GAAG,kCAC5BX,MAAF,IAAc,CAAEC,KAAF,EAASC,KAAT,EAAgBU,WAAhB,KAAiC;AAC9C,2BACE,kEADF,EAEC;AACCC,IAAAA,KAAK,EAAE,KADR;AAECC,IAAAA,WAAW,EAAG;AAFf,GAFD;AAQA,SAAO,CAAC,CAAEd,MAAM,CAAEI,kBAAF,CAAN,CAA2BC,GAA3B,CAAgCH,KAAhC,EAAuCU,WAAvC,CAAV;AACA,CAX6B,CAAxB","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 | null | undefined} The complementary area that is active in the given scope.\n */\nexport const getActiveComplementaryArea = createRegistrySelector(\n\t( select ) => ( state, scope ) => {\n\t\tconst isComplementaryAreaVisible = select( preferencesStore ).get(\n\t\t\tscope,\n\t\t\t'isComplementaryAreaVisible'\n\t\t);\n\n\t\t// Return `undefined` to indicate that the user has never toggled\n\t\t// visibility, this is the vanilla default. Other code relies on this\n\t\t// nuance in the return value.\n\t\tif ( isComplementaryAreaVisible === undefined ) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\t// Return `null` to indicate the user hid the complementary area.\n\t\tif ( ! isComplementaryAreaVisible ) {\n\t\t\treturn null;\n\t\t}\n\n\t\treturn state?.complementaryAreas?.[ scope ];\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`select( 'core/interface' ).isFeatureActive( scope, featureName )`,\n\t\t\t{\n\t\t\t\tsince: '6.0',\n\t\t\t\talternative: `select( 'core/preferences' ).get( scope, featureName )`,\n\t\t\t}\n\t\t);\n\n\t\treturn !! select( preferencesStore ).get( scope, featureName );\n\t}\n);\n"]}
|
|
@@ -3,6 +3,20 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import deprecated from '@wordpress/deprecated';
|
|
5
5
|
import { store as preferencesStore } from '@wordpress/preferences';
|
|
6
|
+
/**
|
|
7
|
+
* Set a default complementary area.
|
|
8
|
+
*
|
|
9
|
+
* @param {string} scope Complementary area scope.
|
|
10
|
+
* @param {string} area Area identifier.
|
|
11
|
+
*
|
|
12
|
+
* @return {Object} Action object.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
export const setDefaultComplementaryArea = (scope, area) => ({
|
|
16
|
+
type: 'SET_DEFAULT_COMPLEMENTARY_AREA',
|
|
17
|
+
scope,
|
|
18
|
+
area
|
|
19
|
+
});
|
|
6
20
|
/**
|
|
7
21
|
* Enable the complementary area.
|
|
8
22
|
*
|
|
@@ -12,7 +26,8 @@ import { store as preferencesStore } from '@wordpress/preferences';
|
|
|
12
26
|
|
|
13
27
|
export const enableComplementaryArea = (scope, area) => _ref => {
|
|
14
28
|
let {
|
|
15
|
-
registry
|
|
29
|
+
registry,
|
|
30
|
+
dispatch
|
|
16
31
|
} = _ref;
|
|
17
32
|
|
|
18
33
|
// Return early if there's no area.
|
|
@@ -20,7 +35,17 @@ export const enableComplementaryArea = (scope, area) => _ref => {
|
|
|
20
35
|
return;
|
|
21
36
|
}
|
|
22
37
|
|
|
23
|
-
registry.
|
|
38
|
+
const isComplementaryAreaVisible = registry.select(preferencesStore).get(scope, 'isComplementaryAreaVisible');
|
|
39
|
+
|
|
40
|
+
if (!isComplementaryAreaVisible) {
|
|
41
|
+
registry.dispatch(preferencesStore).set(scope, 'isComplementaryAreaVisible', true);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
dispatch({
|
|
45
|
+
type: 'ENABLE_COMPLEMENTARY_AREA',
|
|
46
|
+
scope,
|
|
47
|
+
area
|
|
48
|
+
});
|
|
24
49
|
};
|
|
25
50
|
/**
|
|
26
51
|
* Disable the complementary area.
|
|
@@ -32,7 +57,11 @@ export const disableComplementaryArea = scope => _ref2 => {
|
|
|
32
57
|
let {
|
|
33
58
|
registry
|
|
34
59
|
} = _ref2;
|
|
35
|
-
registry.
|
|
60
|
+
const isComplementaryAreaVisible = registry.select(preferencesStore).get(scope, 'isComplementaryAreaVisible');
|
|
61
|
+
|
|
62
|
+
if (isComplementaryAreaVisible) {
|
|
63
|
+
registry.dispatch(preferencesStore).set(scope, 'isComplementaryAreaVisible', false);
|
|
64
|
+
}
|
|
36
65
|
};
|
|
37
66
|
/**
|
|
38
67
|
* Pins an item.
|
|
@@ -97,9 +126,9 @@ export function toggleFeature(scope, featureName) {
|
|
|
97
126
|
let {
|
|
98
127
|
registry
|
|
99
128
|
} = _ref5;
|
|
100
|
-
deprecated(`
|
|
129
|
+
deprecated(`dispatch( 'core/interface' ).toggleFeature`, {
|
|
101
130
|
since: '6.0',
|
|
102
|
-
alternative: `
|
|
131
|
+
alternative: `dispatch( 'core/preferences' ).toggle`
|
|
103
132
|
});
|
|
104
133
|
registry.dispatch(preferencesStore).toggle(scope, featureName);
|
|
105
134
|
};
|
|
@@ -120,9 +149,9 @@ export function setFeatureValue(scope, featureName, value) {
|
|
|
120
149
|
let {
|
|
121
150
|
registry
|
|
122
151
|
} = _ref6;
|
|
123
|
-
deprecated(`
|
|
152
|
+
deprecated(`dispatch( 'core/interface' ).setFeatureValue`, {
|
|
124
153
|
since: '6.0',
|
|
125
|
-
alternative: `
|
|
154
|
+
alternative: `dispatch( 'core/preferences' ).set`
|
|
126
155
|
});
|
|
127
156
|
registry.dispatch(preferencesStore).set(scope, featureName, !!value);
|
|
128
157
|
};
|
|
@@ -141,9 +170,9 @@ export function setFeatureDefaults(scope, defaults) {
|
|
|
141
170
|
let {
|
|
142
171
|
registry
|
|
143
172
|
} = _ref7;
|
|
144
|
-
deprecated(`
|
|
173
|
+
deprecated(`dispatch( 'core/interface' ).setFeatureDefaults`, {
|
|
145
174
|
since: '6.0',
|
|
146
|
-
alternative: `
|
|
175
|
+
alternative: `dispatch( 'core/preferences' ).setDefaults`
|
|
147
176
|
});
|
|
148
177
|
registry.dispatch(preferencesStore).setDefaults(scope, defaults);
|
|
149
178
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/interface/src/store/actions.js"],"names":["deprecated","store","preferencesStore","
|
|
1
|
+
{"version":3,"sources":["@wordpress/interface/src/store/actions.js"],"names":["deprecated","store","preferencesStore","setDefaultComplementaryArea","scope","area","type","enableComplementaryArea","registry","dispatch","isComplementaryAreaVisible","select","get","set","disableComplementaryArea","pinItem","item","pinnedItems","unpinItem","toggleFeature","featureName","since","alternative","toggle","setFeatureValue","value","setFeatureDefaults","defaults","setDefaults"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,UAAP,MAAuB,uBAAvB;AACA,SAASC,KAAK,IAAIC,gBAAlB,QAA0C,wBAA1C;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMC,2BAA2B,GAAG,CAAEC,KAAF,EAASC,IAAT,MAAqB;AAC/DC,EAAAA,IAAI,EAAE,gCADyD;AAE/DF,EAAAA,KAF+D;AAG/DC,EAAAA;AAH+D,CAArB,CAApC;AAMP;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAME,uBAAuB,GAAG,CA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AT,CAA0BpB,KAA1B,EAAiCgB,WAAjC,EAA8CK,KAA9C,EAAsD;AAC5D,SAAO,iBAA0B;AAAA,QAAf;AAAEjB,MAAAA;AAAF,KAAe;AAChCR,IAAAA,UAAU,CAAG,8CAAH,EAAkD;AAC3DqB,MAAAA,KAAK,EAAE,KADoD;AAE3DC,MAAAA,WAAW,EAAG;AAF6C,KAAlD,CAAV;AAKAd,IAAAA,QAAQ,CACNC,QADF,CACYP,gBADZ,EAEEW,GAFF,CAEOT,KAFP,EAEcgB,WAFd,EAE2B,CAAC,CAAEK,KAF9B;AAGA,GATD;AAUA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,kBAAT,CAA6BtB,KAA7B,EAAoCuB,QAApC,EAA+C;AACrD,SAAO,iBAA0B;AAAA,QAAf;AAAEnB,MAAAA;AAAF,KAAe;AAChCR,IAAAA,UAAU,CAAG,iDAAH,EAAqD;AAC9DqB,MAAAA,KAAK,EAAE,KADuD;AAE9DC,MAAAA,WAAW,EAAG;AAFgD,KAArD,CAAV;AAKAd,IAAAA,QAAQ,CAACC,QAAT,CAAmBP,gBAAnB,EAAsC0B,WAAtC,CAAmDxB,KAAnD,EAA0DuB,QAA1D;AACA,GAPD;AAQA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport deprecated from '@wordpress/deprecated';\nimport { store as preferencesStore } from '@wordpress/preferences';\n\n/**\n * Set a default complementary area.\n *\n * @param {string} scope Complementary area scope.\n * @param {string} area Area identifier.\n *\n * @return {Object} Action object.\n */\nexport const setDefaultComplementaryArea = ( scope, area ) => ( {\n\ttype: 'SET_DEFAULT_COMPLEMENTARY_AREA',\n\tscope,\n\tarea,\n} );\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 ) => ( {\n\tregistry,\n\tdispatch,\n} ) => {\n\t// Return early if there's no area.\n\tif ( ! area ) {\n\t\treturn;\n\t}\n\n\tconst isComplementaryAreaVisible = registry\n\t\t.select( preferencesStore )\n\t\t.get( scope, 'isComplementaryAreaVisible' );\n\n\tif ( ! isComplementaryAreaVisible ) {\n\t\tregistry\n\t\t\t.dispatch( preferencesStore )\n\t\t\t.set( scope, 'isComplementaryAreaVisible', true );\n\t}\n\n\tdispatch( {\n\t\ttype: 'ENABLE_COMPLEMENTARY_AREA',\n\t\tscope,\n\t\tarea,\n\t} );\n};\n\n/**\n * Disable the complementary area.\n *\n * @param {string} scope Complementary area scope.\n */\nexport const disableComplementaryArea = ( scope ) => ( { registry } ) => {\n\tconst isComplementaryAreaVisible = registry\n\t\t.select( preferencesStore )\n\t\t.get( scope, 'isComplementaryAreaVisible' );\n\n\tif ( isComplementaryAreaVisible ) {\n\t\tregistry\n\t\t\t.dispatch( preferencesStore )\n\t\t\t.set( scope, 'isComplementaryAreaVisible', false );\n\t}\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( `dispatch( 'core/interface' ).toggleFeature`, {\n\t\t\tsince: '6.0',\n\t\t\talternative: `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( `dispatch( 'core/interface' ).setFeatureValue`, {\n\t\t\tsince: '6.0',\n\t\t\talternative: `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( `dispatch( 'core/interface' ).setFeatureDefaults`, {\n\t\t\tsince: '6.0',\n\t\t\talternative: `dispatch( 'core/preferences' ).setDefaults`,\n\t\t} );\n\n\t\tregistry.dispatch( preferencesStore ).setDefaults( scope, defaults );\n\t};\n}\n"]}
|
|
@@ -8,6 +8,7 @@ import { createReduxStore, register } from '@wordpress/data';
|
|
|
8
8
|
|
|
9
9
|
import * as actions from './actions';
|
|
10
10
|
import * as selectors from './selectors';
|
|
11
|
+
import reducer from './reducer';
|
|
11
12
|
import { STORE_NAME } from './constants';
|
|
12
13
|
/**
|
|
13
14
|
* Store definition for the interface namespace.
|
|
@@ -18,7 +19,7 @@ import { STORE_NAME } from './constants';
|
|
|
18
19
|
*/
|
|
19
20
|
|
|
20
21
|
export const store = createReduxStore(STORE_NAME, {
|
|
21
|
-
reducer
|
|
22
|
+
reducer,
|
|
22
23
|
actions,
|
|
23
24
|
selectors
|
|
24
25
|
}); // Once we build a more generic persistence plugin that works across types of stores
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/interface/src/store/index.js"],"names":["createReduxStore","register","actions","selectors","
|
|
1
|
+
{"version":3,"sources":["@wordpress/interface/src/store/index.js"],"names":["createReduxStore","register","actions","selectors","reducer","STORE_NAME","store"],"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,OAAOC,OAAP,MAAoB,WAApB;AACA,SAASC,UAAT,QAA2B,aAA3B;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMC,KAAK,GAAGN,gBAAgB,CAAEK,UAAF,EAAc;AAClDD,EAAAA,OADkD;AAElDF,EAAAA,OAFkD;AAGlDC,EAAAA;AAHkD,CAAd,CAA9B,C,CAMP;AACA;;AACAF,QAAQ,CAAEK,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 reducer from './reducer';\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"]}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { combineReducers } from '@wordpress/data';
|
|
5
|
+
export function complementaryAreas() {
|
|
6
|
+
let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
7
|
+
let action = arguments.length > 1 ? arguments[1] : undefined;
|
|
8
|
+
|
|
9
|
+
switch (action.type) {
|
|
10
|
+
case 'SET_DEFAULT_COMPLEMENTARY_AREA':
|
|
11
|
+
{
|
|
12
|
+
const {
|
|
13
|
+
scope,
|
|
14
|
+
area
|
|
15
|
+
} = action; // If there's already an area, don't overwrite it.
|
|
16
|
+
|
|
17
|
+
if (state[scope]) {
|
|
18
|
+
return state;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return { ...state,
|
|
22
|
+
[scope]: area
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
case 'ENABLE_COMPLEMENTARY_AREA':
|
|
27
|
+
{
|
|
28
|
+
const {
|
|
29
|
+
scope,
|
|
30
|
+
area
|
|
31
|
+
} = action;
|
|
32
|
+
return { ...state,
|
|
33
|
+
[scope]: area
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return state;
|
|
39
|
+
}
|
|
40
|
+
export default combineReducers({
|
|
41
|
+
complementaryAreas
|
|
42
|
+
});
|
|
43
|
+
//# sourceMappingURL=reducer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["@wordpress/interface/src/store/reducer.js"],"names":["combineReducers","complementaryAreas","state","action","type","scope","area"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,eAAT,QAAgC,iBAAhC;AAEA,OAAO,SAASC,kBAAT,GAAkD;AAAA,MAArBC,KAAqB,uEAAb,EAAa;AAAA,MAATC,MAAS;;AACxD,UAASA,MAAM,CAACC,IAAhB;AACC,SAAK,gCAAL;AAAuC;AACtC,cAAM;AAAEC,UAAAA,KAAF;AAASC,UAAAA;AAAT,YAAkBH,MAAxB,CADsC,CAGtC;;AACA,YAAKD,KAAK,CAAEG,KAAF,CAAV,EAAsB;AACrB,iBAAOH,KAAP;AACA;;AAED,eAAO,EACN,GAAGA,KADG;AAEN,WAAEG,KAAF,GAAWC;AAFL,SAAP;AAIA;;AACD,SAAK,2BAAL;AAAkC;AACjC,cAAM;AAAED,UAAAA,KAAF;AAASC,UAAAA;AAAT,YAAkBH,MAAxB;AACA,eAAO,EACN,GAAGD,KADG;AAEN,WAAEG,KAAF,GAAWC;AAFL,SAAP;AAIA;AApBF;;AAuBA,SAAOJ,KAAP;AACA;AAED,eAAeF,eAAe,CAAE;AAC/BC,EAAAA;AAD+B,CAAF,CAA9B","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { combineReducers } from '@wordpress/data';\n\nexport function complementaryAreas( state = {}, action ) {\n\tswitch ( action.type ) {\n\t\tcase 'SET_DEFAULT_COMPLEMENTARY_AREA': {\n\t\t\tconst { scope, area } = action;\n\n\t\t\t// If there's already an area, don't overwrite it.\n\t\t\tif ( state[ scope ] ) {\n\t\t\t\treturn state;\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\t...state,\n\t\t\t\t[ scope ]: area,\n\t\t\t};\n\t\t}\n\t\tcase 'ENABLE_COMPLEMENTARY_AREA': {\n\t\t\tconst { scope, area } = action;\n\t\t\treturn {\n\t\t\t\t...state,\n\t\t\t\t[ scope ]: area,\n\t\t\t};\n\t\t}\n\t}\n\n\treturn state;\n}\n\nexport default combineReducers( {\n\tcomplementaryAreas,\n} );\n"]}
|
|
@@ -10,11 +10,26 @@ import { store as preferencesStore } from '@wordpress/preferences';
|
|
|
10
10
|
* @param {Object} state Global application state.
|
|
11
11
|
* @param {string} scope Item scope.
|
|
12
12
|
*
|
|
13
|
-
* @return {string} The complementary area that is active in the given scope.
|
|
13
|
+
* @return {string | null | undefined} The complementary area that is active in the given scope.
|
|
14
14
|
*/
|
|
15
15
|
|
|
16
16
|
export const getActiveComplementaryArea = createRegistrySelector(select => (state, scope) => {
|
|
17
|
-
|
|
17
|
+
var _state$complementaryA;
|
|
18
|
+
|
|
19
|
+
const isComplementaryAreaVisible = select(preferencesStore).get(scope, 'isComplementaryAreaVisible'); // Return `undefined` to indicate that the user has never toggled
|
|
20
|
+
// visibility, this is the vanilla default. Other code relies on this
|
|
21
|
+
// nuance in the return value.
|
|
22
|
+
|
|
23
|
+
if (isComplementaryAreaVisible === undefined) {
|
|
24
|
+
return undefined;
|
|
25
|
+
} // Return `null` to indicate the user hid the complementary area.
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
if (!isComplementaryAreaVisible) {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return state === null || state === void 0 ? void 0 : (_state$complementaryA = state.complementaryAreas) === null || _state$complementaryA === void 0 ? void 0 : _state$complementaryA[scope];
|
|
18
33
|
});
|
|
19
34
|
/**
|
|
20
35
|
* Returns a boolean indicating if an item is pinned or not.
|
|
@@ -44,9 +59,9 @@ export const isItemPinned = createRegistrySelector(select => (state, scope, item
|
|
|
44
59
|
*/
|
|
45
60
|
|
|
46
61
|
export const isFeatureActive = createRegistrySelector(select => (state, scope, featureName) => {
|
|
47
|
-
deprecated(`
|
|
62
|
+
deprecated(`select( 'core/interface' ).isFeatureActive( scope, featureName )`, {
|
|
48
63
|
since: '6.0',
|
|
49
|
-
alternative:
|
|
64
|
+
alternative: `select( 'core/preferences' ).get( scope, featureName )`
|
|
50
65
|
});
|
|
51
66
|
return !!select(preferencesStore).get(scope, featureName);
|
|
52
67
|
});
|
|
@@ -1 +1 @@
|
|
|
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,
|
|
1
|
+
{"version":3,"sources":["@wordpress/interface/src/store/selectors.js"],"names":["createRegistrySelector","deprecated","store","preferencesStore","getActiveComplementaryArea","select","state","scope","isComplementaryAreaVisible","get","undefined","complementaryAreas","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;AAAA;;AACjC,QAAMC,0BAA0B,GAAGH,MAAM,CAAEF,gBAAF,CAAN,CAA2BM,GAA3B,CAClCF,KADkC,EAElC,4BAFkC,CAAnC,CADiC,CAMjC;AACA;AACA;;AACA,MAAKC,0BAA0B,KAAKE,SAApC,EAAgD;AAC/C,WAAOA,SAAP;AACA,GAXgC,CAajC;;;AACA,MAAK,CAAEF,0BAAP,EAAoC;AACnC,WAAO,IAAP;AACA;;AAED,SAAOF,KAAP,aAAOA,KAAP,gDAAOA,KAAK,CAAEK,kBAAd,0DAAO,sBAA6BJ,KAA7B,CAAP;AACA,CApB8D,CAAzD;AAuBP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMK,YAAY,GAAGZ,sBAAsB,CAC/CK,MAAF,IAAc,CAAEC,KAAF,EAASC,KAAT,EAAgBM,IAAhB,KAA0B;AAAA;;AACvC,QAAMC,WAAW,GAAGT,MAAM,CAAEF,gBAAF,CAAN,CAA2BM,GAA3B,CACnBF,KADmB,EAEnB,aAFmB,CAApB;AAIA,8BAAOO,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,GAAGf,sBAAsB,CAClDK,MAAF,IAAc,CAAEC,KAAF,EAASC,KAAT,EAAgBS,WAAhB,KAAiC;AAC9Cf,EAAAA,UAAU,CACR,kEADQ,EAET;AACCgB,IAAAA,KAAK,EAAE,KADR;AAECC,IAAAA,WAAW,EAAG;AAFf,GAFS,CAAV;AAQA,SAAO,CAAC,CAAEb,MAAM,CAAEF,gBAAF,CAAN,CAA2BM,GAA3B,CAAgCF,KAAhC,EAAuCS,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 | null | undefined} The complementary area that is active in the given scope.\n */\nexport const getActiveComplementaryArea = createRegistrySelector(\n\t( select ) => ( state, scope ) => {\n\t\tconst isComplementaryAreaVisible = select( preferencesStore ).get(\n\t\t\tscope,\n\t\t\t'isComplementaryAreaVisible'\n\t\t);\n\n\t\t// Return `undefined` to indicate that the user has never toggled\n\t\t// visibility, this is the vanilla default. Other code relies on this\n\t\t// nuance in the return value.\n\t\tif ( isComplementaryAreaVisible === undefined ) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\t// Return `null` to indicate the user hid the complementary area.\n\t\tif ( ! isComplementaryAreaVisible ) {\n\t\t\treturn null;\n\t\t}\n\n\t\treturn state?.complementaryAreas?.[ scope ];\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`select( 'core/interface' ).isFeatureActive( scope, featureName )`,\n\t\t\t{\n\t\t\t\tsince: '6.0',\n\t\t\t\talternative: `select( 'core/preferences' ).get( scope, featureName )`,\n\t\t\t}\n\t\t);\n\n\t\treturn !! select( preferencesStore ).get( scope, featureName );\n\t}\n);\n"]}
|
package/build-style/style.css
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/interface",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.8.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.
|
|
36
|
-
"@wordpress/components": "^19.
|
|
37
|
-
"@wordpress/compose": "^5.
|
|
38
|
-
"@wordpress/data": "^6.
|
|
39
|
-
"@wordpress/deprecated": "^3.
|
|
40
|
-
"@wordpress/element": "^4.
|
|
41
|
-
"@wordpress/i18n": "^4.
|
|
42
|
-
"@wordpress/icons": "^
|
|
43
|
-
"@wordpress/plugins": "^4.
|
|
44
|
-
"@wordpress/preferences": "^2.
|
|
45
|
-
"@wordpress/viewport": "^4.
|
|
35
|
+
"@wordpress/a11y": "^3.9.0",
|
|
36
|
+
"@wordpress/components": "^19.11.0",
|
|
37
|
+
"@wordpress/compose": "^5.7.0",
|
|
38
|
+
"@wordpress/data": "^6.9.0",
|
|
39
|
+
"@wordpress/deprecated": "^3.9.0",
|
|
40
|
+
"@wordpress/element": "^4.7.0",
|
|
41
|
+
"@wordpress/i18n": "^4.9.0",
|
|
42
|
+
"@wordpress/icons": "^9.0.0",
|
|
43
|
+
"@wordpress/plugins": "^4.7.0",
|
|
44
|
+
"@wordpress/preferences": "^2.1.0",
|
|
45
|
+
"@wordpress/viewport": "^4.7.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": "
|
|
56
|
+
"gitHead": "198fa129cf1af8dc615918987ea6795cd40ab7df"
|
|
57
57
|
}
|
package/src/store/actions.js
CHANGED
|
@@ -4,21 +4,50 @@
|
|
|
4
4
|
import deprecated from '@wordpress/deprecated';
|
|
5
5
|
import { store as preferencesStore } from '@wordpress/preferences';
|
|
6
6
|
|
|
7
|
+
/**
|
|
8
|
+
* Set a default complementary area.
|
|
9
|
+
*
|
|
10
|
+
* @param {string} scope Complementary area scope.
|
|
11
|
+
* @param {string} area Area identifier.
|
|
12
|
+
*
|
|
13
|
+
* @return {Object} Action object.
|
|
14
|
+
*/
|
|
15
|
+
export const setDefaultComplementaryArea = ( scope, area ) => ( {
|
|
16
|
+
type: 'SET_DEFAULT_COMPLEMENTARY_AREA',
|
|
17
|
+
scope,
|
|
18
|
+
area,
|
|
19
|
+
} );
|
|
20
|
+
|
|
7
21
|
/**
|
|
8
22
|
* Enable the complementary area.
|
|
9
23
|
*
|
|
10
24
|
* @param {string} scope Complementary area scope.
|
|
11
25
|
* @param {string} area Area identifier.
|
|
12
26
|
*/
|
|
13
|
-
export const enableComplementaryArea = ( scope, area ) => ( {
|
|
27
|
+
export const enableComplementaryArea = ( scope, area ) => ( {
|
|
28
|
+
registry,
|
|
29
|
+
dispatch,
|
|
30
|
+
} ) => {
|
|
14
31
|
// Return early if there's no area.
|
|
15
32
|
if ( ! area ) {
|
|
16
33
|
return;
|
|
17
34
|
}
|
|
18
35
|
|
|
19
|
-
registry
|
|
20
|
-
.
|
|
21
|
-
.
|
|
36
|
+
const isComplementaryAreaVisible = registry
|
|
37
|
+
.select( preferencesStore )
|
|
38
|
+
.get( scope, 'isComplementaryAreaVisible' );
|
|
39
|
+
|
|
40
|
+
if ( ! isComplementaryAreaVisible ) {
|
|
41
|
+
registry
|
|
42
|
+
.dispatch( preferencesStore )
|
|
43
|
+
.set( scope, 'isComplementaryAreaVisible', true );
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
dispatch( {
|
|
47
|
+
type: 'ENABLE_COMPLEMENTARY_AREA',
|
|
48
|
+
scope,
|
|
49
|
+
area,
|
|
50
|
+
} );
|
|
22
51
|
};
|
|
23
52
|
|
|
24
53
|
/**
|
|
@@ -27,9 +56,15 @@ export const enableComplementaryArea = ( scope, area ) => ( { registry } ) => {
|
|
|
27
56
|
* @param {string} scope Complementary area scope.
|
|
28
57
|
*/
|
|
29
58
|
export const disableComplementaryArea = ( scope ) => ( { registry } ) => {
|
|
30
|
-
registry
|
|
31
|
-
.
|
|
32
|
-
.
|
|
59
|
+
const isComplementaryAreaVisible = registry
|
|
60
|
+
.select( preferencesStore )
|
|
61
|
+
.get( scope, 'isComplementaryAreaVisible' );
|
|
62
|
+
|
|
63
|
+
if ( isComplementaryAreaVisible ) {
|
|
64
|
+
registry
|
|
65
|
+
.dispatch( preferencesStore )
|
|
66
|
+
.set( scope, 'isComplementaryAreaVisible', false );
|
|
67
|
+
}
|
|
33
68
|
};
|
|
34
69
|
|
|
35
70
|
/**
|
|
@@ -91,9 +126,9 @@ export const unpinItem = ( scope, item ) => ( { registry } ) => {
|
|
|
91
126
|
*/
|
|
92
127
|
export function toggleFeature( scope, featureName ) {
|
|
93
128
|
return function ( { registry } ) {
|
|
94
|
-
deprecated( `
|
|
129
|
+
deprecated( `dispatch( 'core/interface' ).toggleFeature`, {
|
|
95
130
|
since: '6.0',
|
|
96
|
-
alternative: `
|
|
131
|
+
alternative: `dispatch( 'core/preferences' ).toggle`,
|
|
97
132
|
} );
|
|
98
133
|
|
|
99
134
|
registry.dispatch( preferencesStore ).toggle( scope, featureName );
|
|
@@ -112,9 +147,9 @@ export function toggleFeature( scope, featureName ) {
|
|
|
112
147
|
*/
|
|
113
148
|
export function setFeatureValue( scope, featureName, value ) {
|
|
114
149
|
return function ( { registry } ) {
|
|
115
|
-
deprecated( `
|
|
150
|
+
deprecated( `dispatch( 'core/interface' ).setFeatureValue`, {
|
|
116
151
|
since: '6.0',
|
|
117
|
-
alternative: `
|
|
152
|
+
alternative: `dispatch( 'core/preferences' ).set`,
|
|
118
153
|
} );
|
|
119
154
|
|
|
120
155
|
registry
|
|
@@ -133,9 +168,9 @@ export function setFeatureValue( scope, featureName, value ) {
|
|
|
133
168
|
*/
|
|
134
169
|
export function setFeatureDefaults( scope, defaults ) {
|
|
135
170
|
return function ( { registry } ) {
|
|
136
|
-
deprecated( `
|
|
171
|
+
deprecated( `dispatch( 'core/interface' ).setFeatureDefaults`, {
|
|
137
172
|
since: '6.0',
|
|
138
|
-
alternative: `
|
|
173
|
+
alternative: `dispatch( 'core/preferences' ).setDefaults`,
|
|
139
174
|
} );
|
|
140
175
|
|
|
141
176
|
registry.dispatch( preferencesStore ).setDefaults( scope, defaults );
|
package/src/store/index.js
CHANGED
|
@@ -8,6 +8,7 @@ import { createReduxStore, register } from '@wordpress/data';
|
|
|
8
8
|
*/
|
|
9
9
|
import * as actions from './actions';
|
|
10
10
|
import * as selectors from './selectors';
|
|
11
|
+
import reducer from './reducer';
|
|
11
12
|
import { STORE_NAME } from './constants';
|
|
12
13
|
|
|
13
14
|
/**
|
|
@@ -18,7 +19,7 @@ import { STORE_NAME } from './constants';
|
|
|
18
19
|
* @type {Object}
|
|
19
20
|
*/
|
|
20
21
|
export const store = createReduxStore( STORE_NAME, {
|
|
21
|
-
reducer
|
|
22
|
+
reducer,
|
|
22
23
|
actions,
|
|
23
24
|
selectors,
|
|
24
25
|
} );
|
|
@@ -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
|
+
} );
|
package/src/store/selectors.js
CHANGED
|
@@ -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
|
-
|
|
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
|
-
`
|
|
71
|
+
`select( 'core/interface' ).isFeatureActive( scope, featureName )`,
|
|
55
72
|
{
|
|
56
73
|
since: '6.0',
|
|
57
|
-
alternative:
|
|
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( '
|
|
57
|
+
it( 'results in the complementary area being inactive', () => {
|
|
58
58
|
registry
|
|
59
59
|
.dispatch( interfaceStore )
|
|
60
60
|
.enableComplementaryArea( 'my-plugin', 'custom-sidebar' );
|