@wordpress/interface 4.3.1 → 4.4.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 +34 -13
- package/build/store/actions.js.map +1 -1
- package/build/store/index.js +1 -1
- package/build/store/index.js.map +1 -1
- package/build/store/reducer.js +1 -70
- package/build/store/reducer.js.map +1 -1
- package/build/store/selectors.js +21 -8
- package/build/store/selectors.js.map +1 -1
- package/build-module/store/actions.js +30 -13
- package/build-module/store/actions.js.map +1 -1
- package/build-module/store/index.js +1 -1
- package/build-module/store/index.js.map +1 -1
- package/build-module/store/reducer.js +1 -67
- package/build-module/store/reducer.js.map +1 -1
- package/build-module/store/selectors.js +14 -7
- package/build-module/store/selectors.js.map +1 -1
- package/build-style/style-rtl.css +1 -1
- package/build-style/style.css +1 -1
- package/package.json +13 -11
- package/src/store/actions.js +29 -12
- package/src/store/index.js +1 -1
- package/src/store/reducer.js +0 -55
- package/src/store/selectors.js +19 -8
- package/src/store/test/actions.js +124 -0
- package/src/store/test/selectors.js +0 -107
package/CHANGELOG.md
CHANGED
package/build/store/actions.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,14 @@ exports.setFeatureValue = setFeatureValue;
|
|
|
11
13
|
exports.toggleFeature = toggleFeature;
|
|
12
14
|
exports.unpinItem = unpinItem;
|
|
13
15
|
|
|
16
|
+
var _deprecated = _interopRequireDefault(require("@wordpress/deprecated"));
|
|
17
|
+
|
|
18
|
+
var _preferences = require("@wordpress/preferences");
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* WordPress dependencies
|
|
22
|
+
*/
|
|
23
|
+
|
|
14
24
|
/**
|
|
15
25
|
* Returns an action object used in signalling that an active area should be changed.
|
|
16
26
|
*
|
|
@@ -111,11 +121,13 @@ function unpinItem(scope, itemId) {
|
|
|
111
121
|
function toggleFeature(scope, featureName) {
|
|
112
122
|
return function (_ref) {
|
|
113
123
|
let {
|
|
114
|
-
|
|
115
|
-
dispatch
|
|
124
|
+
registry
|
|
116
125
|
} = _ref;
|
|
117
|
-
|
|
118
|
-
|
|
126
|
+
(0, _deprecated.default)(`wp.dispatch( 'core/interface' ).toggleFeature`, {
|
|
127
|
+
since: '6.0',
|
|
128
|
+
alternative: `wp.dispatch( 'core/preferences' ).toggle`
|
|
129
|
+
});
|
|
130
|
+
registry.dispatch(_preferences.store).toggle(scope, featureName);
|
|
119
131
|
};
|
|
120
132
|
}
|
|
121
133
|
/**
|
|
@@ -131,11 +143,15 @@ function toggleFeature(scope, featureName) {
|
|
|
131
143
|
|
|
132
144
|
|
|
133
145
|
function setFeatureValue(scope, featureName, value) {
|
|
134
|
-
return {
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
146
|
+
return function (_ref2) {
|
|
147
|
+
let {
|
|
148
|
+
registry
|
|
149
|
+
} = _ref2;
|
|
150
|
+
(0, _deprecated.default)(`wp.dispatch( 'core/interface' ).setFeatureValue`, {
|
|
151
|
+
since: '6.0',
|
|
152
|
+
alternative: `wp.dispatch( 'core/preferences' ).set`
|
|
153
|
+
});
|
|
154
|
+
registry.dispatch(_preferences.store).set(scope, featureName, !!value);
|
|
139
155
|
};
|
|
140
156
|
}
|
|
141
157
|
/**
|
|
@@ -149,10 +165,15 @@ function setFeatureValue(scope, featureName, value) {
|
|
|
149
165
|
|
|
150
166
|
|
|
151
167
|
function setFeatureDefaults(scope, defaults) {
|
|
152
|
-
return {
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
168
|
+
return function (_ref3) {
|
|
169
|
+
let {
|
|
170
|
+
registry
|
|
171
|
+
} = _ref3;
|
|
172
|
+
(0, _deprecated.default)(`wp.dispatch( 'core/interface' ).setFeatureDefaults`, {
|
|
173
|
+
since: '6.0',
|
|
174
|
+
alternative: `wp.dispatch( 'core/preferences' ).setDefaults`
|
|
175
|
+
});
|
|
176
|
+
registry.dispatch(_preferences.store).setDefaults(scope, defaults);
|
|
156
177
|
};
|
|
157
178
|
}
|
|
158
179
|
//# sourceMappingURL=actions.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/interface/src/store/actions.js"],"names":["setSingleEnableItem","itemType","scope","item","type","enableComplementaryArea","area","disableComplementaryArea","undefined","setMultipleEnableItem","isEnable","pinItem","itemId","unpinItem","toggleFeature","featureName","
|
|
1
|
+
{"version":3,"sources":["@wordpress/interface/src/store/actions.js"],"names":["setSingleEnableItem","itemType","scope","item","type","enableComplementaryArea","area","disableComplementaryArea","undefined","setMultipleEnableItem","isEnable","pinItem","itemId","unpinItem","toggleFeature","featureName","registry","since","alternative","dispatch","preferencesStore","toggle","setFeatureValue","value","set","setFeatureDefaults","defaults","setDefaults"],"mappings":";;;;;;;;;;;;;;;AAGA;;AACA;;AAJA;AACA;AACA;;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASA,mBAAT,CAA8BC,QAA9B,EAAwCC,KAAxC,EAA+CC,IAA/C,EAAsD;AACrD,SAAO;AACNC,IAAAA,IAAI,EAAE,wBADA;AAENH,IAAAA,QAFM;AAGNC,IAAAA,KAHM;AAINC,IAAAA;AAJM,GAAP;AAMA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASE,uBAAT,CAAkCH,KAAlC,EAAyCI,IAAzC,EAAgD;AACtD,SAAON,mBAAmB,CAAE,mBAAF,EAAuBE,KAAvB,EAA8BI,IAA9B,CAA1B;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASC,wBAAT,CAAmCL,KAAnC,EAA2C;AACjD,SAAOF,mBAAmB,CAAE,mBAAF,EA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KAAe;AAChC,6BAAa,iDAAb,EAA+D;AAC9DC,MAAAA,KAAK,EAAE,KADuD;AAE9DC,MAAAA,WAAW,EAAG;AAFgD,KAA/D;AAKAF,IAAAA,QAAQ,CACNG,QADF,CACYC,kBADZ,EAEEI,GAFF,CAEOtB,KAFP,EAEca,WAFd,EAE2B,CAAC,CAAEQ,KAF9B;AAGA,GATD;AAUA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASE,kBAAT,CAA6BvB,KAA7B,EAAoCwB,QAApC,EAA+C;AACrD,SAAO,iBAA0B;AAAA,QAAf;AAAEV,MAAAA;AAAF,KAAe;AAChC,6BAAa,oDAAb,EAAkE;AACjEC,MAAAA,KAAK,EAAE,KAD0D;AAEjEC,MAAAA,WAAW,EAAG;AAFmD,KAAlE;AAKAF,IAAAA,QAAQ,CAACG,QAAT,CAAmBC,kBAAnB,EAAsCO,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 * 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"]}
|
package/build/store/index.js
CHANGED
package/build/store/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/interface/src/store/index.js"],"names":["storeConfig","reducer","actions","selectors","persist","store","STORE_NAME"],"mappings":";;;;;;;;;AAGA;;AAKA;;AACA;;AACA;;AACA;;;;;;AAXA;AACA;AACA;;AAGA;AACA;AACA;AAMA,MAAMA,WAAW,GAAG;AACnBC,EAAAA,OAAO,EAAPA,gBADmB;AAEnBC,EAAAA,OAFmB;AAGnBC,EAAAA,SAHmB;AAInBC,EAAAA,OAAO,EAAE,CAAE,aAAF
|
|
1
|
+
{"version":3,"sources":["@wordpress/interface/src/store/index.js"],"names":["storeConfig","reducer","actions","selectors","persist","store","STORE_NAME"],"mappings":";;;;;;;;;AAGA;;AAKA;;AACA;;AACA;;AACA;;;;;;AAXA;AACA;AACA;;AAGA;AACA;AACA;AAMA,MAAMA,WAAW,GAAG;AACnBC,EAAAA,OAAO,EAAPA,gBADmB;AAEnBC,EAAAA,OAFmB;AAGnBC,EAAAA,SAHmB;AAInBC,EAAAA,OAAO,EAAE,CAAE,aAAF;AAJU,CAApB;AAOA;AACA;AACA;AACA;AACA;AACA;AACA;;AACO,MAAMC,KAAK,GAAG,4BAAkBC,qBAAlB,EAA8BN,WAA9B,CAAd,C,CAEP;AACA;;;AACA,yBAAeM,qBAAf,EAA2BN,WAA3B","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"]}
|
package/build/store/reducer.js
CHANGED
|
@@ -5,7 +5,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
exports.multipleEnableItems = multipleEnableItems;
|
|
8
|
-
exports.preferences = exports.preferenceDefaults = void 0;
|
|
9
8
|
exports.singleEnableItems = singleEnableItems;
|
|
10
9
|
|
|
11
10
|
var _lodash = require("lodash");
|
|
@@ -90,82 +89,14 @@ function multipleEnableItems() {
|
|
|
90
89
|
}
|
|
91
90
|
};
|
|
92
91
|
}
|
|
93
|
-
/**
|
|
94
|
-
* Reducer returning the defaults for user preferences.
|
|
95
|
-
*
|
|
96
|
-
* This is kept intentionally separate from the preferences
|
|
97
|
-
* themselves so that defaults are not persisted.
|
|
98
|
-
*
|
|
99
|
-
* @param {Object} state Current state.
|
|
100
|
-
* @param {Object} action Dispatched action.
|
|
101
|
-
*
|
|
102
|
-
* @return {Object} Updated state.
|
|
103
|
-
*/
|
|
104
|
-
|
|
105
92
|
|
|
106
|
-
const preferenceDefaults = (0, _data.combineReducers)({
|
|
107
|
-
features() {
|
|
108
|
-
let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
109
|
-
let action = arguments.length > 1 ? arguments[1] : undefined;
|
|
110
|
-
|
|
111
|
-
if (action.type === 'SET_FEATURE_DEFAULTS') {
|
|
112
|
-
const {
|
|
113
|
-
scope,
|
|
114
|
-
defaults
|
|
115
|
-
} = action;
|
|
116
|
-
return { ...state,
|
|
117
|
-
[scope]: { ...state[scope],
|
|
118
|
-
...defaults
|
|
119
|
-
}
|
|
120
|
-
};
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
return state;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
});
|
|
127
|
-
/**
|
|
128
|
-
* Reducer returning the user preferences.
|
|
129
|
-
*
|
|
130
|
-
* @param {Object} state Current state.
|
|
131
|
-
* @param {Object} action Dispatched action.
|
|
132
|
-
*
|
|
133
|
-
* @return {Object} Updated state.
|
|
134
|
-
*/
|
|
135
|
-
|
|
136
|
-
exports.preferenceDefaults = preferenceDefaults;
|
|
137
|
-
const preferences = (0, _data.combineReducers)({
|
|
138
|
-
features() {
|
|
139
|
-
let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
140
|
-
let action = arguments.length > 1 ? arguments[1] : undefined;
|
|
141
|
-
|
|
142
|
-
if (action.type === 'SET_FEATURE_VALUE') {
|
|
143
|
-
const {
|
|
144
|
-
scope,
|
|
145
|
-
featureName,
|
|
146
|
-
value
|
|
147
|
-
} = action;
|
|
148
|
-
return { ...state,
|
|
149
|
-
[scope]: { ...state[scope],
|
|
150
|
-
[featureName]: value
|
|
151
|
-
}
|
|
152
|
-
};
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
return state;
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
});
|
|
159
|
-
exports.preferences = preferences;
|
|
160
93
|
const enableItems = (0, _data.combineReducers)({
|
|
161
94
|
singleEnableItems,
|
|
162
95
|
multipleEnableItems
|
|
163
96
|
});
|
|
164
97
|
|
|
165
98
|
var _default = (0, _data.combineReducers)({
|
|
166
|
-
enableItems
|
|
167
|
-
preferenceDefaults,
|
|
168
|
-
preferences
|
|
99
|
+
enableItems
|
|
169
100
|
});
|
|
170
101
|
|
|
171
102
|
exports.default = _default;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/interface/src/store/reducer.js"],"names":["singleEnableItems","state","type","itemType","scope","item","multipleEnableItems","isEnable","currentTypeState","currentScopeState","
|
|
1
|
+
{"version":3,"sources":["@wordpress/interface/src/store/reducer.js"],"names":["singleEnableItems","state","type","itemType","scope","item","multipleEnableItems","isEnable","currentTypeState","currentScopeState","enableItems"],"mappings":";;;;;;;;;AAGA;;AAKA;;AARA;AACA;AACA;;AAGA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,iBAAT,GAGL;AAAA,MAFDC,KAEC,uEAFO,EAEP;AAAA,MADD;AAAEC,IAAAA,IAAF;AAAQC,IAAAA,QAAR;AAAkBC,IAAAA,KAAlB;AAAyBC,IAAAA;AAAzB,GACC;;AACD,MAAKH,IAAI,KAAK,wBAAT,IAAqC,CAAEC,QAAvC,IAAmD,CAAEC,KAA1D,EAAkE;AACjE,WAAOH,KAAP;AACA;;AAED,SAAO,EACN,GAAGA,KADG;AAEN,KAAEE,QAAF,GAAc,EACb,GAAGF,KAAK,CAAEE,QAAF,CADK;AAEb,OAAEC,KAAF,GAAWC,IAAI,IAAI;AAFN;AAFR,GAAP;AAOA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASC,mBAAT,GAGL;AAAA,MAFDL,KAEC,uEAFO,EAEP;AAAA,MADD;AAAEC,IAAAA,IAAF;AAAQC,IAAAA,QAAR;AAAkBC,IAAAA,KAAlB;AAAyBC,IAAAA,IAAzB;AAA+BE,IAAAA;AAA/B,GACC;;AACD,MACCL,IAAI,KAAK,0BAAT,IACA,CAAEC,QADF,IAEA,CAAEC,KAFF,IAGA,CAAEC,IAHF,IAIA,iBAAKJ,KAAL,EAAY,CAAEE,QAAF,EAAYC,KAAZ,EAAmBC,IAAnB,CAAZ,MAA4CE,QAL7C,EAME;AACD,WAAON,KAAP;AACA;;AACD,QAAMO,gBAAgB,GAAGP,KAAK,CAAEE,QAAF,CAAL,IAAqB,EAA9C;AACA,QAAMM,iBAAiB,GAAGD,gBAAgB,CAAEJ,KAAF,CAAhB,IAA6B,EAAvD;AAEA,SAAO,EACN,GAAGH,KADG;AAEN,KAAEE,QAAF,GAAc,EACb,GAAGK,gBADU;AAEb,OAAEJ,KAAF,GAAW,EACV,GAAGK,iBADO;AAEV,SAAEJ,IAAF,GAAUE,QAAQ,IAAI;AAFZ;AAFE;AAFR,GAAP;AAUA;;AAED,MAAMG,WAAW,GAAG,2BAAiB;AACpCV,EAAAA,iBADoC;AAEpCM,EAAAA;AAFoC,CAAjB,CAApB;;eAKe,2BAAiB;AAC/BI,EAAAA;AAD+B,CAAjB,C","sourcesContent":["/**\n * External dependencies\n */\nimport { get } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport { combineReducers } from '@wordpress/data';\n\n/**\n * Reducer to keep tract of the active area per scope.\n *\n * @param {boolean} state Previous state.\n * @param {Object} action Action object.\n * @param {string} action.type Action type.\n * @param {string} action.itemType Type of item.\n * @param {string} action.scope Item scope.\n * @param {string} action.item Item name.\n *\n * @return {Object} Updated state.\n */\nexport function singleEnableItems(\n\tstate = {},\n\t{ type, itemType, scope, item }\n) {\n\tif ( type !== 'SET_SINGLE_ENABLE_ITEM' || ! itemType || ! scope ) {\n\t\treturn state;\n\t}\n\n\treturn {\n\t\t...state,\n\t\t[ itemType ]: {\n\t\t\t...state[ itemType ],\n\t\t\t[ scope ]: item || null,\n\t\t},\n\t};\n}\n\n/**\n * Reducer keeping track of the \"pinned\" items per scope.\n *\n * @param {boolean} state Previous state.\n * @param {Object} action Action object.\n * @param {string} action.type Action type.\n * @param {string} action.itemType Type of item.\n * @param {string} action.scope Item scope.\n * @param {string} action.item Item name.\n * @param {boolean} action.isEnable Whether the item is pinned.\n *\n * @return {Object} Updated state.\n */\nexport function multipleEnableItems(\n\tstate = {},\n\t{ type, itemType, scope, item, isEnable }\n) {\n\tif (\n\t\ttype !== 'SET_MULTIPLE_ENABLE_ITEM' ||\n\t\t! itemType ||\n\t\t! scope ||\n\t\t! item ||\n\t\tget( state, [ itemType, scope, item ] ) === isEnable\n\t) {\n\t\treturn state;\n\t}\n\tconst currentTypeState = state[ itemType ] || {};\n\tconst currentScopeState = currentTypeState[ scope ] || {};\n\n\treturn {\n\t\t...state,\n\t\t[ itemType ]: {\n\t\t\t...currentTypeState,\n\t\t\t[ scope ]: {\n\t\t\t\t...currentScopeState,\n\t\t\t\t[ item ]: isEnable || false,\n\t\t\t},\n\t\t},\n\t};\n}\n\nconst enableItems = combineReducers( {\n\tsingleEnableItems,\n\tmultipleEnableItems,\n} );\n\nexport default combineReducers( {\n\tenableItems,\n} );\n"]}
|
package/build/store/selectors.js
CHANGED
|
@@ -1,18 +1,30 @@
|
|
|
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
|
});
|
|
6
8
|
exports.getActiveComplementaryArea = getActiveComplementaryArea;
|
|
7
|
-
exports.isFeatureActive =
|
|
9
|
+
exports.isFeatureActive = void 0;
|
|
8
10
|
exports.isItemPinned = isItemPinned;
|
|
9
11
|
|
|
10
12
|
var _lodash = require("lodash");
|
|
11
13
|
|
|
14
|
+
var _data = require("@wordpress/data");
|
|
15
|
+
|
|
16
|
+
var _deprecated = _interopRequireDefault(require("@wordpress/deprecated"));
|
|
17
|
+
|
|
18
|
+
var _preferences = require("@wordpress/preferences");
|
|
19
|
+
|
|
12
20
|
/**
|
|
13
21
|
* External dependencies
|
|
14
22
|
*/
|
|
15
23
|
|
|
24
|
+
/**
|
|
25
|
+
* WordPress dependencies
|
|
26
|
+
*/
|
|
27
|
+
|
|
16
28
|
/**
|
|
17
29
|
* Returns the item that is enabled in a given scope.
|
|
18
30
|
*
|
|
@@ -79,11 +91,12 @@ function isItemPinned(state, scope, item) {
|
|
|
79
91
|
*/
|
|
80
92
|
|
|
81
93
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
return !!
|
|
88
|
-
}
|
|
94
|
+
const isFeatureActive = (0, _data.createRegistrySelector)(select => (state, scope, featureName) => {
|
|
95
|
+
(0, _deprecated.default)(`wp.select( 'core/interface' ).isFeatureActive( scope, featureName )`, {
|
|
96
|
+
since: '6.0',
|
|
97
|
+
alternative: `!! wp.select( 'core/preferences' ).isFeatureActive( scope, featureName )`
|
|
98
|
+
});
|
|
99
|
+
return !!select(_preferences.store).get(scope, featureName);
|
|
100
|
+
});
|
|
101
|
+
exports.isFeatureActive = isFeatureActive;
|
|
89
102
|
//# sourceMappingURL=selectors.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/interface/src/store/selectors.js"],"names":["getSingleEnableItem","state","itemType","scope","enableItems","singleEnableItems","getActiveComplementaryArea","isMultipleEnabledItemEnabled","item","multipleEnableItems","isItemPinned","isFeatureActive","
|
|
1
|
+
{"version":3,"sources":["@wordpress/interface/src/store/selectors.js"],"names":["getSingleEnableItem","state","itemType","scope","enableItems","singleEnableItems","getActiveComplementaryArea","isMultipleEnabledItemEnabled","item","multipleEnableItems","isItemPinned","isFeatureActive","select","featureName","since","alternative","preferencesStore","get"],"mappings":";;;;;;;;;;;AAGA;;AAKA;;AACA;;AACA;;AAVA;AACA;AACA;;AAGA;AACA;AACA;;AAKA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASA,mBAAT,CAA8BC,KAA9B,EAAqCC,QAArC,EAA+CC,KAA/C,EAAuD;AACtD,SAAO,iBAAKF,KAAK,CAACG,WAAN,CAAkBC,iBAAvB,EAA0C,CAAEH,QAAF,EAAYC,KAAZ,CAA1C,CAAP;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,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,SAAO,iBAAKP,KAAK,CAACG,WAAN,CAAkBK,mBAAvB,EAA4C,CAClDP,QADkD,EAElDC,KAFkD,EAGlDK,IAHkD,CAA5C,CAAP;AAKA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,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;;;AACO,MAAMG,eAAe,GAAG,kCAC5BC,MAAF,IAAc,CAAEX,KAAF,EAASE,KAAT,EAAgBU,WAAhB,KAAiC;AAC9C,2BACE,qEADF,EAEC;AACCC,IAAAA,KAAK,EAAE,KADR;AAECC,IAAAA,WAAW,EAAG;AAFf,GAFD;AAQA,SAAO,CAAC,CAAEH,MAAM,CAAEI,kBAAF,CAAN,CAA2BC,GAA3B,CAAgCd,KAAhC,EAAuCU,WAAvC,CAAV;AACA,CAX6B,CAAxB","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,3 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import deprecated from '@wordpress/deprecated';
|
|
5
|
+
import { store as preferencesStore } from '@wordpress/preferences';
|
|
1
6
|
/**
|
|
2
7
|
* Returns an action object used in signalling that an active area should be changed.
|
|
3
8
|
*
|
|
@@ -7,6 +12,7 @@
|
|
|
7
12
|
*
|
|
8
13
|
* @return {Object} Action object.
|
|
9
14
|
*/
|
|
15
|
+
|
|
10
16
|
function setSingleEnableItem(itemType, scope, item) {
|
|
11
17
|
return {
|
|
12
18
|
type: 'SET_SINGLE_ENABLE_ITEM',
|
|
@@ -94,11 +100,13 @@ export function unpinItem(scope, itemId) {
|
|
|
94
100
|
export function toggleFeature(scope, featureName) {
|
|
95
101
|
return function (_ref) {
|
|
96
102
|
let {
|
|
97
|
-
|
|
98
|
-
dispatch
|
|
103
|
+
registry
|
|
99
104
|
} = _ref;
|
|
100
|
-
|
|
101
|
-
|
|
105
|
+
deprecated(`wp.dispatch( 'core/interface' ).toggleFeature`, {
|
|
106
|
+
since: '6.0',
|
|
107
|
+
alternative: `wp.dispatch( 'core/preferences' ).toggle`
|
|
108
|
+
});
|
|
109
|
+
registry.dispatch(preferencesStore).toggle(scope, featureName);
|
|
102
110
|
};
|
|
103
111
|
}
|
|
104
112
|
/**
|
|
@@ -113,11 +121,15 @@ export function toggleFeature(scope, featureName) {
|
|
|
113
121
|
*/
|
|
114
122
|
|
|
115
123
|
export function setFeatureValue(scope, featureName, value) {
|
|
116
|
-
return {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
124
|
+
return function (_ref2) {
|
|
125
|
+
let {
|
|
126
|
+
registry
|
|
127
|
+
} = _ref2;
|
|
128
|
+
deprecated(`wp.dispatch( 'core/interface' ).setFeatureValue`, {
|
|
129
|
+
since: '6.0',
|
|
130
|
+
alternative: `wp.dispatch( 'core/preferences' ).set`
|
|
131
|
+
});
|
|
132
|
+
registry.dispatch(preferencesStore).set(scope, featureName, !!value);
|
|
121
133
|
};
|
|
122
134
|
}
|
|
123
135
|
/**
|
|
@@ -130,10 +142,15 @@ export function setFeatureValue(scope, featureName, value) {
|
|
|
130
142
|
*/
|
|
131
143
|
|
|
132
144
|
export function setFeatureDefaults(scope, defaults) {
|
|
133
|
-
return {
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
145
|
+
return function (_ref3) {
|
|
146
|
+
let {
|
|
147
|
+
registry
|
|
148
|
+
} = _ref3;
|
|
149
|
+
deprecated(`wp.dispatch( 'core/interface' ).setFeatureDefaults`, {
|
|
150
|
+
since: '6.0',
|
|
151
|
+
alternative: `wp.dispatch( 'core/preferences' ).setDefaults`
|
|
152
|
+
});
|
|
153
|
+
registry.dispatch(preferencesStore).setDefaults(scope, defaults);
|
|
137
154
|
};
|
|
138
155
|
}
|
|
139
156
|
//# sourceMappingURL=actions.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/interface/src/store/actions.js"],"names":["setSingleEnableItem","itemType","scope","item","type","enableComplementaryArea","area","disableComplementaryArea","undefined","setMultipleEnableItem","isEnable","pinItem","itemId","unpinItem","toggleFeature","featureName","
|
|
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":"AAAA;AACA;AACA;AAC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AT,CAAmBpB,gBAAnB,EAAsC2B,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 * 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 +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
|
|
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"]}
|
|
@@ -77,77 +77,11 @@ export function multipleEnableItems() {
|
|
|
77
77
|
}
|
|
78
78
|
};
|
|
79
79
|
}
|
|
80
|
-
/**
|
|
81
|
-
* Reducer returning the defaults for user preferences.
|
|
82
|
-
*
|
|
83
|
-
* This is kept intentionally separate from the preferences
|
|
84
|
-
* themselves so that defaults are not persisted.
|
|
85
|
-
*
|
|
86
|
-
* @param {Object} state Current state.
|
|
87
|
-
* @param {Object} action Dispatched action.
|
|
88
|
-
*
|
|
89
|
-
* @return {Object} Updated state.
|
|
90
|
-
*/
|
|
91
|
-
|
|
92
|
-
export const preferenceDefaults = combineReducers({
|
|
93
|
-
features() {
|
|
94
|
-
let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
95
|
-
let action = arguments.length > 1 ? arguments[1] : undefined;
|
|
96
|
-
|
|
97
|
-
if (action.type === 'SET_FEATURE_DEFAULTS') {
|
|
98
|
-
const {
|
|
99
|
-
scope,
|
|
100
|
-
defaults
|
|
101
|
-
} = action;
|
|
102
|
-
return { ...state,
|
|
103
|
-
[scope]: { ...state[scope],
|
|
104
|
-
...defaults
|
|
105
|
-
}
|
|
106
|
-
};
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
return state;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
});
|
|
113
|
-
/**
|
|
114
|
-
* Reducer returning the user preferences.
|
|
115
|
-
*
|
|
116
|
-
* @param {Object} state Current state.
|
|
117
|
-
* @param {Object} action Dispatched action.
|
|
118
|
-
*
|
|
119
|
-
* @return {Object} Updated state.
|
|
120
|
-
*/
|
|
121
|
-
|
|
122
|
-
export const preferences = combineReducers({
|
|
123
|
-
features() {
|
|
124
|
-
let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
125
|
-
let action = arguments.length > 1 ? arguments[1] : undefined;
|
|
126
|
-
|
|
127
|
-
if (action.type === 'SET_FEATURE_VALUE') {
|
|
128
|
-
const {
|
|
129
|
-
scope,
|
|
130
|
-
featureName,
|
|
131
|
-
value
|
|
132
|
-
} = action;
|
|
133
|
-
return { ...state,
|
|
134
|
-
[scope]: { ...state[scope],
|
|
135
|
-
[featureName]: value
|
|
136
|
-
}
|
|
137
|
-
};
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
return state;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
});
|
|
144
80
|
const enableItems = combineReducers({
|
|
145
81
|
singleEnableItems,
|
|
146
82
|
multipleEnableItems
|
|
147
83
|
});
|
|
148
84
|
export default combineReducers({
|
|
149
|
-
enableItems
|
|
150
|
-
preferenceDefaults,
|
|
151
|
-
preferences
|
|
85
|
+
enableItems
|
|
152
86
|
});
|
|
153
87
|
//# sourceMappingURL=reducer.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/interface/src/store/reducer.js"],"names":["get","combineReducers","singleEnableItems","state","type","itemType","scope","item","multipleEnableItems","isEnable","currentTypeState","currentScopeState","
|
|
1
|
+
{"version":3,"sources":["@wordpress/interface/src/store/reducer.js"],"names":["get","combineReducers","singleEnableItems","state","type","itemType","scope","item","multipleEnableItems","isEnable","currentTypeState","currentScopeState","enableItems"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,GAAT,QAAoB,QAApB;AAEA;AACA;AACA;;AACA,SAASC,eAAT,QAAgC,iBAAhC;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,i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Ae,CAAE;AACpCC,EAAAA,iBADoC;AAEpCM,EAAAA;AAFoC,CAAF,CAAnC;AAKA,eAAeP,eAAe,CAAE;AAC/BW,EAAAA;AAD+B,CAAF,CAA9B","sourcesContent":["/**\n * External dependencies\n */\nimport { get } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport { combineReducers } from '@wordpress/data';\n\n/**\n * Reducer to keep tract of the active area per scope.\n *\n * @param {boolean} state Previous state.\n * @param {Object} action Action object.\n * @param {string} action.type Action type.\n * @param {string} action.itemType Type of item.\n * @param {string} action.scope Item scope.\n * @param {string} action.item Item name.\n *\n * @return {Object} Updated state.\n */\nexport function singleEnableItems(\n\tstate = {},\n\t{ type, itemType, scope, item }\n) {\n\tif ( type !== 'SET_SINGLE_ENABLE_ITEM' || ! itemType || ! scope ) {\n\t\treturn state;\n\t}\n\n\treturn {\n\t\t...state,\n\t\t[ itemType ]: {\n\t\t\t...state[ itemType ],\n\t\t\t[ scope ]: item || null,\n\t\t},\n\t};\n}\n\n/**\n * Reducer keeping track of the \"pinned\" items per scope.\n *\n * @param {boolean} state Previous state.\n * @param {Object} action Action object.\n * @param {string} action.type Action type.\n * @param {string} action.itemType Type of item.\n * @param {string} action.scope Item scope.\n * @param {string} action.item Item name.\n * @param {boolean} action.isEnable Whether the item is pinned.\n *\n * @return {Object} Updated state.\n */\nexport function multipleEnableItems(\n\tstate = {},\n\t{ type, itemType, scope, item, isEnable }\n) {\n\tif (\n\t\ttype !== 'SET_MULTIPLE_ENABLE_ITEM' ||\n\t\t! itemType ||\n\t\t! scope ||\n\t\t! item ||\n\t\tget( state, [ itemType, scope, item ] ) === isEnable\n\t) {\n\t\treturn state;\n\t}\n\tconst currentTypeState = state[ itemType ] || {};\n\tconst currentScopeState = currentTypeState[ scope ] || {};\n\n\treturn {\n\t\t...state,\n\t\t[ itemType ]: {\n\t\t\t...currentTypeState,\n\t\t\t[ scope ]: {\n\t\t\t\t...currentScopeState,\n\t\t\t\t[ item ]: isEnable || false,\n\t\t\t},\n\t\t},\n\t};\n}\n\nconst enableItems = combineReducers( {\n\tsingleEnableItems,\n\tmultipleEnableItems,\n} );\n\nexport default combineReducers( {\n\tenableItems,\n} );\n"]}
|
|
@@ -2,6 +2,13 @@
|
|
|
2
2
|
* External dependencies
|
|
3
3
|
*/
|
|
4
4
|
import { get } from 'lodash';
|
|
5
|
+
/**
|
|
6
|
+
* WordPress dependencies
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { createRegistrySelector } from '@wordpress/data';
|
|
10
|
+
import deprecated from '@wordpress/deprecated';
|
|
11
|
+
import { store as preferencesStore } from '@wordpress/preferences';
|
|
5
12
|
/**
|
|
6
13
|
* Returns the item that is enabled in a given scope.
|
|
7
14
|
*
|
|
@@ -67,11 +74,11 @@ export function isItemPinned(state, scope, item) {
|
|
|
67
74
|
* @return {boolean} Is the feature enabled?
|
|
68
75
|
*/
|
|
69
76
|
|
|
70
|
-
export
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
return !!
|
|
76
|
-
}
|
|
77
|
+
export const isFeatureActive = createRegistrySelector(select => (state, scope, featureName) => {
|
|
78
|
+
deprecated(`wp.select( 'core/interface' ).isFeatureActive( scope, featureName )`, {
|
|
79
|
+
since: '6.0',
|
|
80
|
+
alternative: `!! wp.select( 'core/preferences' ).isFeatureActive( scope, featureName )`
|
|
81
|
+
});
|
|
82
|
+
return !!select(preferencesStore).get(scope, featureName);
|
|
83
|
+
});
|
|
77
84
|
//# sourceMappingURL=selectors.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/interface/src/store/selectors.js"],"names":["get","getSingleEnableItem","state","itemType","scope","enableItems","singleEnableItems","getActiveComplementaryArea","isMultipleEnabledItemEnabled","item","multipleEnableItems","isItemPinned","isFeatureActive","
|
|
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"]}
|
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.4.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,15 +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/
|
|
40
|
-
"@wordpress/
|
|
41
|
-
"@wordpress/
|
|
42
|
-
"@wordpress/
|
|
43
|
-
"@wordpress/
|
|
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",
|
|
44
46
|
"classnames": "^2.3.1",
|
|
45
47
|
"lodash": "^4.17.21"
|
|
46
48
|
},
|
|
@@ -51,5 +53,5 @@
|
|
|
51
53
|
"publishConfig": {
|
|
52
54
|
"access": "public"
|
|
53
55
|
},
|
|
54
|
-
"gitHead": "
|
|
56
|
+
"gitHead": "aa003c3634016cc4ab6348b2106907e371c648e1"
|
|
55
57
|
}
|
package/src/store/actions.js
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import deprecated from '@wordpress/deprecated';
|
|
5
|
+
import { store as preferencesStore } from '@wordpress/preferences';
|
|
6
|
+
|
|
1
7
|
/**
|
|
2
8
|
* Returns an action object used in signalling that an active area should be changed.
|
|
3
9
|
*
|
|
@@ -90,9 +96,13 @@ export function unpinItem( scope, itemId ) {
|
|
|
90
96
|
* @param {string} featureName The feature name.
|
|
91
97
|
*/
|
|
92
98
|
export function toggleFeature( scope, featureName ) {
|
|
93
|
-
return function ( {
|
|
94
|
-
|
|
95
|
-
|
|
99
|
+
return function ( { registry } ) {
|
|
100
|
+
deprecated( `wp.dispatch( 'core/interface' ).toggleFeature`, {
|
|
101
|
+
since: '6.0',
|
|
102
|
+
alternative: `wp.dispatch( 'core/preferences' ).toggle`,
|
|
103
|
+
} );
|
|
104
|
+
|
|
105
|
+
registry.dispatch( preferencesStore ).toggle( scope, featureName );
|
|
96
106
|
};
|
|
97
107
|
}
|
|
98
108
|
|
|
@@ -107,11 +117,15 @@ export function toggleFeature( scope, featureName ) {
|
|
|
107
117
|
* @return {Object} Action object.
|
|
108
118
|
*/
|
|
109
119
|
export function setFeatureValue( scope, featureName, value ) {
|
|
110
|
-
return {
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
120
|
+
return function ( { registry } ) {
|
|
121
|
+
deprecated( `wp.dispatch( 'core/interface' ).setFeatureValue`, {
|
|
122
|
+
since: '6.0',
|
|
123
|
+
alternative: `wp.dispatch( 'core/preferences' ).set`,
|
|
124
|
+
} );
|
|
125
|
+
|
|
126
|
+
registry
|
|
127
|
+
.dispatch( preferencesStore )
|
|
128
|
+
.set( scope, featureName, !! value );
|
|
115
129
|
};
|
|
116
130
|
}
|
|
117
131
|
|
|
@@ -124,9 +138,12 @@ export function setFeatureValue( scope, featureName, value ) {
|
|
|
124
138
|
* @return {Object} Action object.
|
|
125
139
|
*/
|
|
126
140
|
export function setFeatureDefaults( scope, defaults ) {
|
|
127
|
-
return {
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
141
|
+
return function ( { registry } ) {
|
|
142
|
+
deprecated( `wp.dispatch( 'core/interface' ).setFeatureDefaults`, {
|
|
143
|
+
since: '6.0',
|
|
144
|
+
alternative: `wp.dispatch( 'core/preferences' ).setDefaults`,
|
|
145
|
+
} );
|
|
146
|
+
|
|
147
|
+
registry.dispatch( preferencesStore ).setDefaults( scope, defaults );
|
|
131
148
|
};
|
|
132
149
|
}
|
package/src/store/index.js
CHANGED
package/src/store/reducer.js
CHANGED
|
@@ -78,59 +78,6 @@ export function multipleEnableItems(
|
|
|
78
78
|
};
|
|
79
79
|
}
|
|
80
80
|
|
|
81
|
-
/**
|
|
82
|
-
* Reducer returning the defaults for user preferences.
|
|
83
|
-
*
|
|
84
|
-
* This is kept intentionally separate from the preferences
|
|
85
|
-
* themselves so that defaults are not persisted.
|
|
86
|
-
*
|
|
87
|
-
* @param {Object} state Current state.
|
|
88
|
-
* @param {Object} action Dispatched action.
|
|
89
|
-
*
|
|
90
|
-
* @return {Object} Updated state.
|
|
91
|
-
*/
|
|
92
|
-
export const preferenceDefaults = combineReducers( {
|
|
93
|
-
features( state = {}, action ) {
|
|
94
|
-
if ( action.type === 'SET_FEATURE_DEFAULTS' ) {
|
|
95
|
-
const { scope, defaults } = action;
|
|
96
|
-
return {
|
|
97
|
-
...state,
|
|
98
|
-
[ scope ]: {
|
|
99
|
-
...state[ scope ],
|
|
100
|
-
...defaults,
|
|
101
|
-
},
|
|
102
|
-
};
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
return state;
|
|
106
|
-
},
|
|
107
|
-
} );
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
* Reducer returning the user preferences.
|
|
111
|
-
*
|
|
112
|
-
* @param {Object} state Current state.
|
|
113
|
-
* @param {Object} action Dispatched action.
|
|
114
|
-
*
|
|
115
|
-
* @return {Object} Updated state.
|
|
116
|
-
*/
|
|
117
|
-
export const preferences = combineReducers( {
|
|
118
|
-
features( state = {}, action ) {
|
|
119
|
-
if ( action.type === 'SET_FEATURE_VALUE' ) {
|
|
120
|
-
const { scope, featureName, value } = action;
|
|
121
|
-
return {
|
|
122
|
-
...state,
|
|
123
|
-
[ scope ]: {
|
|
124
|
-
...state[ scope ],
|
|
125
|
-
[ featureName ]: value,
|
|
126
|
-
},
|
|
127
|
-
};
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
return state;
|
|
131
|
-
},
|
|
132
|
-
} );
|
|
133
|
-
|
|
134
81
|
const enableItems = combineReducers( {
|
|
135
82
|
singleEnableItems,
|
|
136
83
|
multipleEnableItems,
|
|
@@ -138,6 +85,4 @@ const enableItems = combineReducers( {
|
|
|
138
85
|
|
|
139
86
|
export default combineReducers( {
|
|
140
87
|
enableItems,
|
|
141
|
-
preferenceDefaults,
|
|
142
|
-
preferences,
|
|
143
88
|
} );
|
package/src/store/selectors.js
CHANGED
|
@@ -3,6 +3,13 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { get } from 'lodash';
|
|
5
5
|
|
|
6
|
+
/**
|
|
7
|
+
* WordPress dependencies
|
|
8
|
+
*/
|
|
9
|
+
import { createRegistrySelector } from '@wordpress/data';
|
|
10
|
+
import deprecated from '@wordpress/deprecated';
|
|
11
|
+
import { store as preferencesStore } from '@wordpress/preferences';
|
|
12
|
+
|
|
6
13
|
/**
|
|
7
14
|
* Returns the item that is enabled in a given scope.
|
|
8
15
|
*
|
|
@@ -72,12 +79,16 @@ export function isItemPinned( state, scope, item ) {
|
|
|
72
79
|
*
|
|
73
80
|
* @return {boolean} Is the feature enabled?
|
|
74
81
|
*/
|
|
75
|
-
export
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
82
|
+
export const isFeatureActive = createRegistrySelector(
|
|
83
|
+
( select ) => ( state, scope, featureName ) => {
|
|
84
|
+
deprecated(
|
|
85
|
+
`wp.select( 'core/interface' ).isFeatureActive( scope, featureName )`,
|
|
86
|
+
{
|
|
87
|
+
since: '6.0',
|
|
88
|
+
alternative: `!! wp.select( 'core/preferences' ).isFeatureActive( scope, featureName )`,
|
|
89
|
+
}
|
|
90
|
+
);
|
|
81
91
|
|
|
82
|
-
|
|
83
|
-
}
|
|
92
|
+
return !! select( preferencesStore ).get( scope, featureName );
|
|
93
|
+
}
|
|
94
|
+
);
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { createRegistry } from '@wordpress/data';
|
|
5
|
+
import { store as preferencesStore } from '@wordpress/preferences';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Internal dependencies
|
|
9
|
+
*/
|
|
10
|
+
import { store as interfaceStore } from '../';
|
|
11
|
+
|
|
12
|
+
function createRegistryWithStores() {
|
|
13
|
+
// Create a registry and register used stores.
|
|
14
|
+
const registry = createRegistry();
|
|
15
|
+
[ interfaceStore, preferencesStore ].forEach( registry.register );
|
|
16
|
+
return registry;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
describe( 'actions', () => {
|
|
20
|
+
let registry;
|
|
21
|
+
beforeEach( () => {
|
|
22
|
+
registry = createRegistryWithStores();
|
|
23
|
+
} );
|
|
24
|
+
|
|
25
|
+
describe( 'setFeatureDefaults', () => {
|
|
26
|
+
it( 'results in default values being present', () => {
|
|
27
|
+
registry.dispatch( interfaceStore ).setFeatureDefaults( 'test', {
|
|
28
|
+
feature1: true,
|
|
29
|
+
feature2: false,
|
|
30
|
+
} );
|
|
31
|
+
|
|
32
|
+
expect(
|
|
33
|
+
registry
|
|
34
|
+
.select( interfaceStore )
|
|
35
|
+
.isFeatureActive( 'test', 'feature1' )
|
|
36
|
+
).toBe( true );
|
|
37
|
+
expect(
|
|
38
|
+
registry
|
|
39
|
+
.select( interfaceStore )
|
|
40
|
+
.isFeatureActive( 'test', 'feature2' )
|
|
41
|
+
).toBe( false );
|
|
42
|
+
|
|
43
|
+
// Expect a deprecation message.
|
|
44
|
+
expect( console ).toHaveWarned();
|
|
45
|
+
} );
|
|
46
|
+
} );
|
|
47
|
+
|
|
48
|
+
describe( 'setFeatureValue', () => {
|
|
49
|
+
it( 'sets a feature to a boolean value', () => {
|
|
50
|
+
registry
|
|
51
|
+
.dispatch( interfaceStore )
|
|
52
|
+
.setFeatureValue( 'test', 'feature1', false );
|
|
53
|
+
registry
|
|
54
|
+
.dispatch( interfaceStore )
|
|
55
|
+
.setFeatureValue( 'test', 'feature2', true );
|
|
56
|
+
expect(
|
|
57
|
+
registry
|
|
58
|
+
.select( interfaceStore )
|
|
59
|
+
.isFeatureActive( 'test', 'feature1' )
|
|
60
|
+
).toBe( false );
|
|
61
|
+
expect(
|
|
62
|
+
registry
|
|
63
|
+
.select( interfaceStore )
|
|
64
|
+
.isFeatureActive( 'test', 'feature2' )
|
|
65
|
+
).toBe( true );
|
|
66
|
+
|
|
67
|
+
// Expect a deprecation message.
|
|
68
|
+
expect( console ).toHaveWarned();
|
|
69
|
+
} );
|
|
70
|
+
|
|
71
|
+
it( 'coerces non-boolean values into booleans', () => {
|
|
72
|
+
registry
|
|
73
|
+
.dispatch( interfaceStore )
|
|
74
|
+
.setFeatureValue( 'test', 'feature1', 'avocado' );
|
|
75
|
+
registry
|
|
76
|
+
.dispatch( interfaceStore )
|
|
77
|
+
.setFeatureValue( 'test', 'feature2', 0 );
|
|
78
|
+
|
|
79
|
+
expect(
|
|
80
|
+
registry
|
|
81
|
+
.select( interfaceStore )
|
|
82
|
+
.isFeatureActive( 'test', 'feature1' )
|
|
83
|
+
).toBe( true );
|
|
84
|
+
expect(
|
|
85
|
+
registry
|
|
86
|
+
.select( interfaceStore )
|
|
87
|
+
.isFeatureActive( 'test', 'feature2' )
|
|
88
|
+
).toBe( false );
|
|
89
|
+
} );
|
|
90
|
+
} );
|
|
91
|
+
|
|
92
|
+
describe( 'toggleFeature', () => {
|
|
93
|
+
it( 'changes a value that was true to false', () => {
|
|
94
|
+
registry
|
|
95
|
+
.dispatch( interfaceStore )
|
|
96
|
+
.setFeatureValue( 'test', 'feature1', true );
|
|
97
|
+
registry
|
|
98
|
+
.dispatch( interfaceStore )
|
|
99
|
+
.toggleFeature( 'test', 'feature1' );
|
|
100
|
+
expect(
|
|
101
|
+
registry
|
|
102
|
+
.select( interfaceStore )
|
|
103
|
+
.isFeatureActive( 'test', 'feature1' )
|
|
104
|
+
).toBe( false );
|
|
105
|
+
|
|
106
|
+
// Expect a deprecation message.
|
|
107
|
+
expect( console ).toHaveWarned();
|
|
108
|
+
} );
|
|
109
|
+
|
|
110
|
+
it( 'changes a value that was false to true', () => {
|
|
111
|
+
registry
|
|
112
|
+
.dispatch( interfaceStore )
|
|
113
|
+
.setFeatureValue( 'test', 'feature1', false );
|
|
114
|
+
registry
|
|
115
|
+
.dispatch( interfaceStore )
|
|
116
|
+
.toggleFeature( 'test', 'feature1' );
|
|
117
|
+
expect(
|
|
118
|
+
registry
|
|
119
|
+
.select( interfaceStore )
|
|
120
|
+
.isFeatureActive( 'test', 'feature1' )
|
|
121
|
+
).toBe( true );
|
|
122
|
+
} );
|
|
123
|
+
} );
|
|
124
|
+
} );
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Internal dependencies
|
|
3
|
-
*/
|
|
4
|
-
import { isFeatureActive } from '../selectors';
|
|
5
|
-
|
|
6
|
-
describe( 'selectors', () => {
|
|
7
|
-
describe( 'isFeatureActive', () => {
|
|
8
|
-
it( 'returns false if the there is no state for the feature', () => {
|
|
9
|
-
const emptyState = {
|
|
10
|
-
preferenceDefaults: {
|
|
11
|
-
features: {},
|
|
12
|
-
},
|
|
13
|
-
preferences: {
|
|
14
|
-
features: {},
|
|
15
|
-
},
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
expect(
|
|
19
|
-
isFeatureActive( emptyState, 'test-scope', 'testFeatureName' )
|
|
20
|
-
).toBe( false );
|
|
21
|
-
} );
|
|
22
|
-
|
|
23
|
-
it( 'returns false if the the default for a feature is false and there is no preference state', () => {
|
|
24
|
-
const emptyState = {
|
|
25
|
-
preferenceDefaults: {
|
|
26
|
-
features: {
|
|
27
|
-
'test-scope': {
|
|
28
|
-
testFeatureName: false,
|
|
29
|
-
},
|
|
30
|
-
},
|
|
31
|
-
},
|
|
32
|
-
preferences: {
|
|
33
|
-
features: {},
|
|
34
|
-
},
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
expect(
|
|
38
|
-
isFeatureActive( emptyState, 'test-scope', 'testFeatureName' )
|
|
39
|
-
).toBe( false );
|
|
40
|
-
} );
|
|
41
|
-
|
|
42
|
-
it( 'returns true if the the default for a feature is true and there is no preference state', () => {
|
|
43
|
-
const emptyState = {
|
|
44
|
-
preferenceDefaults: {
|
|
45
|
-
features: {
|
|
46
|
-
'test-scope': {
|
|
47
|
-
testFeatureName: true,
|
|
48
|
-
},
|
|
49
|
-
},
|
|
50
|
-
},
|
|
51
|
-
preferences: {
|
|
52
|
-
features: {},
|
|
53
|
-
},
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
expect(
|
|
57
|
-
isFeatureActive( emptyState, 'test-scope', 'testFeatureName' )
|
|
58
|
-
).toBe( true );
|
|
59
|
-
} );
|
|
60
|
-
|
|
61
|
-
it( 'returns true if the the default for a feature is false but the preference is true', () => {
|
|
62
|
-
const emptyState = {
|
|
63
|
-
preferenceDefaults: {
|
|
64
|
-
features: {
|
|
65
|
-
'test-scope': {
|
|
66
|
-
testFeatureName: false,
|
|
67
|
-
},
|
|
68
|
-
},
|
|
69
|
-
},
|
|
70
|
-
preferences: {
|
|
71
|
-
features: {
|
|
72
|
-
'test-scope': {
|
|
73
|
-
testFeatureName: true,
|
|
74
|
-
},
|
|
75
|
-
},
|
|
76
|
-
},
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
expect(
|
|
80
|
-
isFeatureActive( emptyState, 'test-scope', 'testFeatureName' )
|
|
81
|
-
).toBe( true );
|
|
82
|
-
} );
|
|
83
|
-
|
|
84
|
-
it( 'returns false if the the default for a feature is true but the preference is false', () => {
|
|
85
|
-
const emptyState = {
|
|
86
|
-
preferenceDefaults: {
|
|
87
|
-
features: {
|
|
88
|
-
'test-scope': {
|
|
89
|
-
testFeatureName: true,
|
|
90
|
-
},
|
|
91
|
-
},
|
|
92
|
-
},
|
|
93
|
-
preferences: {
|
|
94
|
-
features: {
|
|
95
|
-
'test-scope': {
|
|
96
|
-
testFeatureName: false,
|
|
97
|
-
},
|
|
98
|
-
},
|
|
99
|
-
},
|
|
100
|
-
};
|
|
101
|
-
|
|
102
|
-
expect(
|
|
103
|
-
isFeatureActive( emptyState, 'test-scope', 'testFeatureName' )
|
|
104
|
-
).toBe( false );
|
|
105
|
-
} );
|
|
106
|
-
} );
|
|
107
|
-
} );
|