@wordpress/interface 4.3.1 → 4.5.1

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 CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 4.5.0 (2022-04-08)
6
+
7
+ ## 4.4.0 (2022-03-23)
8
+
5
9
  ## 4.3.0 (2022-03-11)
6
10
 
7
11
  ## 4.2.1 (2022-02-10)
@@ -1,105 +1,114 @@
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
- exports.disableComplementaryArea = disableComplementaryArea;
7
- exports.enableComplementaryArea = enableComplementaryArea;
8
- exports.pinItem = pinItem;
8
+ exports.pinItem = exports.enableComplementaryArea = exports.disableComplementaryArea = void 0;
9
9
  exports.setFeatureDefaults = setFeatureDefaults;
10
10
  exports.setFeatureValue = setFeatureValue;
11
11
  exports.toggleFeature = toggleFeature;
12
- exports.unpinItem = unpinItem;
12
+ exports.unpinItem = void 0;
13
+
14
+ var _deprecated = _interopRequireDefault(require("@wordpress/deprecated"));
15
+
16
+ var _preferences = require("@wordpress/preferences");
13
17
 
14
18
  /**
15
- * Returns an action object used in signalling that an active area should be changed.
16
- *
17
- * @param {string} itemType Type of item.
18
- * @param {string} scope Item scope.
19
- * @param {string} item Item identifier.
20
- *
21
- * @return {Object} Action object.
19
+ * WordPress dependencies
22
20
  */
23
- function setSingleEnableItem(itemType, scope, item) {
24
- return {
25
- type: 'SET_SINGLE_ENABLE_ITEM',
26
- itemType,
27
- scope,
28
- item
29
- };
30
- }
21
+
31
22
  /**
32
- * Returns an action object used in signalling that a complementary item should be enabled.
23
+ * Enable the complementary area.
33
24
  *
34
25
  * @param {string} scope Complementary area scope.
35
26
  * @param {string} area Area identifier.
36
- *
37
- * @return {Object} Action object.
38
27
  */
39
-
40
-
41
- function enableComplementaryArea(scope, area) {
42
- return setSingleEnableItem('complementaryArea', scope, area);
43
- }
28
+ const enableComplementaryArea = (scope, area) => _ref => {
29
+ let {
30
+ registry
31
+ } = _ref;
32
+
33
+ // Return early if there's no area.
34
+ if (!area) {
35
+ return;
36
+ }
37
+
38
+ registry.dispatch(_preferences.store).set(scope, 'complementaryArea', area);
39
+ };
44
40
  /**
45
- * Returns an action object used in signalling that the complementary area of a given scope should be disabled.
41
+ * Disable the complementary area.
46
42
  *
47
43
  * @param {string} scope Complementary area scope.
48
- *
49
- * @return {Object} Action object.
50
44
  */
51
45
 
52
46
 
53
- function disableComplementaryArea(scope) {
54
- return setSingleEnableItem('complementaryArea', scope, undefined);
55
- }
47
+ exports.enableComplementaryArea = enableComplementaryArea;
48
+
49
+ const disableComplementaryArea = scope => _ref2 => {
50
+ let {
51
+ registry
52
+ } = _ref2;
53
+ registry.dispatch(_preferences.store).set(scope, 'complementaryArea', null);
54
+ };
56
55
  /**
57
- * Returns an action object to make an area enabled/disabled.
56
+ * Pins an item.
58
57
  *
59
- * @param {string} itemType Type of item.
60
- * @param {string} scope Item scope.
61
- * @param {string} item Item identifier.
62
- * @param {boolean} isEnable Boolean indicating if an area should be pinned or not.
58
+ * @param {string} scope Item scope.
59
+ * @param {string} item Item identifier.
63
60
  *
64
61
  * @return {Object} Action object.
65
62
  */
66
63
 
67
64
 
68
- function setMultipleEnableItem(itemType, scope, item, isEnable) {
69
- return {
70
- type: 'SET_MULTIPLE_ENABLE_ITEM',
71
- itemType,
72
- scope,
73
- item,
74
- isEnable
75
- };
76
- }
77
- /**
78
- * Returns an action object used in signalling that an item should be pinned.
79
- *
80
- * @param {string} scope Item scope.
81
- * @param {string} itemId Item identifier.
82
- *
83
- * @return {Object} Action object.
84
- */
65
+ exports.disableComplementaryArea = disableComplementaryArea;
85
66
 
67
+ const pinItem = (scope, item) => _ref3 => {
68
+ let {
69
+ registry
70
+ } = _ref3;
86
71
 
87
- function pinItem(scope, itemId) {
88
- return setMultipleEnableItem('pinnedItems', scope, itemId, true);
89
- }
72
+ // Return early if there's no item.
73
+ if (!item) {
74
+ return;
75
+ }
76
+
77
+ const pinnedItems = registry.select(_preferences.store).get(scope, 'pinnedItems'); // The item is already pinned, there's nothing to do.
78
+
79
+ if ((pinnedItems === null || pinnedItems === void 0 ? void 0 : pinnedItems[item]) === true) {
80
+ return;
81
+ }
82
+
83
+ registry.dispatch(_preferences.store).set(scope, 'pinnedItems', { ...pinnedItems,
84
+ [item]: true
85
+ });
86
+ };
90
87
  /**
91
- * Returns an action object used in signalling that an item should be unpinned.
92
- *
93
- * @param {string} scope Item scope.
94
- * @param {string} itemId Item identifier.
88
+ * Unpins an item.
95
89
  *
96
- * @return {Object} Action object.
90
+ * @param {string} scope Item scope.
91
+ * @param {string} item Item identifier.
97
92
  */
98
93
 
99
94
 
100
- function unpinItem(scope, itemId) {
101
- return setMultipleEnableItem('pinnedItems', scope, itemId, false);
102
- }
95
+ exports.pinItem = pinItem;
96
+
97
+ const unpinItem = (scope, item) => _ref4 => {
98
+ let {
99
+ registry
100
+ } = _ref4;
101
+
102
+ // Return early if there's no item.
103
+ if (!item) {
104
+ return;
105
+ }
106
+
107
+ const pinnedItems = registry.select(_preferences.store).get(scope, 'pinnedItems');
108
+ registry.dispatch(_preferences.store).set(scope, 'pinnedItems', { ...pinnedItems,
109
+ [item]: false
110
+ });
111
+ };
103
112
  /**
104
113
  * Returns an action object used in signalling that a feature should be toggled.
105
114
  *
@@ -108,14 +117,18 @@ function unpinItem(scope, itemId) {
108
117
  */
109
118
 
110
119
 
120
+ exports.unpinItem = unpinItem;
121
+
111
122
  function toggleFeature(scope, featureName) {
112
- return function (_ref) {
123
+ return function (_ref5) {
113
124
  let {
114
- select,
115
- dispatch
116
- } = _ref;
117
- const currentValue = select.isFeatureActive(scope, featureName);
118
- dispatch.setFeatureValue(scope, featureName, !currentValue);
125
+ registry
126
+ } = _ref5;
127
+ (0, _deprecated.default)(`wp.dispatch( 'core/interface' ).toggleFeature`, {
128
+ since: '6.0',
129
+ alternative: `wp.dispatch( 'core/preferences' ).toggle`
130
+ });
131
+ registry.dispatch(_preferences.store).toggle(scope, featureName);
119
132
  };
120
133
  }
121
134
  /**
@@ -131,11 +144,15 @@ function toggleFeature(scope, featureName) {
131
144
 
132
145
 
133
146
  function setFeatureValue(scope, featureName, value) {
134
- return {
135
- type: 'SET_FEATURE_VALUE',
136
- scope,
137
- featureName,
138
- value: !!value
147
+ return function (_ref6) {
148
+ let {
149
+ registry
150
+ } = _ref6;
151
+ (0, _deprecated.default)(`wp.dispatch( 'core/interface' ).setFeatureValue`, {
152
+ since: '6.0',
153
+ alternative: `wp.dispatch( 'core/preferences' ).set`
154
+ });
155
+ registry.dispatch(_preferences.store).set(scope, featureName, !!value);
139
156
  };
140
157
  }
141
158
  /**
@@ -149,10 +166,15 @@ function setFeatureValue(scope, featureName, value) {
149
166
 
150
167
 
151
168
  function setFeatureDefaults(scope, defaults) {
152
- return {
153
- type: 'SET_FEATURE_DEFAULTS',
154
- scope,
155
- defaults
169
+ return function (_ref7) {
170
+ let {
171
+ registry
172
+ } = _ref7;
173
+ (0, _deprecated.default)(`wp.dispatch( 'core/interface' ).setFeatureDefaults`, {
174
+ since: '6.0',
175
+ alternative: `wp.dispatch( 'core/preferences' ).setDefaults`
176
+ });
177
+ registry.dispatch(_preferences.store).setDefaults(scope, defaults);
156
178
  };
157
179
  }
158
180
  //# 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","select","dispatch","currentValue","isFeatureActive","setFeatureValue","value","setFeatureDefaults","defaults"],"mappings":";;;;;;;;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASA,mBAAT,CAA8BC,QAA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O,gBAAkC;AAAA,QAAvB;AAAEC,MAAAA,MAAF;AAAUC,MAAAA;AAAV,KAAuB;AACxC,UAAMC,YAAY,GAAGF,MAAM,CAACG,eAAP,CAAwBjB,KAAxB,EAA+Ba,WAA/B,CAArB;AACAE,IAAAA,QAAQ,CAACG,eAAT,CAA0BlB,KAA1B,EAAiCa,WAAjC,EAA8C,CAAEG,YAAhD;AACA,GAHD;AAIA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASE,eAAT,CAA0BlB,KAA1B,EAAiCa,WAAjC,EAA8CM,KAA9C,EAAsD;AAC5D,SAAO;AACNjB,IAAAA,IAAI,EAAE,mBADA;AAENF,IAAAA,KAFM;AAGNa,IAAAA,WAHM;AAINM,IAAAA,KAAK,EAAE,CAAC,CAAEA;AAJJ,GAAP;AAMA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASC,kBAAT,CAA6BpB,KAA7B,EAAoCqB,QAApC,EAA+C;AACrD,SAAO;AACNnB,IAAAA,IAAI,EAAE,sBADA;AAENF,IAAAA,KAFM;AAGNqB,IAAAA;AAHM,GAAP;AAKA","sourcesContent":["/**\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 ( { select, dispatch } ) {\n\t\tconst currentValue = select.isFeatureActive( scope, featureName );\n\t\tdispatch.setFeatureValue( scope, featureName, ! currentValue );\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 {\n\t\ttype: 'SET_FEATURE_VALUE',\n\t\tscope,\n\t\tfeatureName,\n\t\tvalue: !! 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 {\n\t\ttype: 'SET_FEATURE_DEFAULTS',\n\t\tscope,\n\t\tdefaults,\n\t};\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/interface/src/store/actions.js"],"names":["enableComplementaryArea","scope","area","registry","dispatch","preferencesStore","set","disableComplementaryArea","pinItem","item","pinnedItems","select","get","unpinItem","toggleFeature","featureName","since","alternative","toggle","setFeatureValue","value","setFeatureDefaults","defaults","setDefaults"],"mappings":";;;;;;;;;;;;;AAGA;;AACA;;AAJA;AACA;AACA;;AAIA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMA,uBAAuB,GAAG,CAAEC,KAAF,EAASC,IAAT,KAAmB,QAAoB;AAAA,MAAlB;AAAEC,IAAAA;AAAF,GAAkB;;AAC7E;AACA,MAAK,CAAED,IAAP,EAAc;AACb;AACA;;AAEDC,EAAAA,QAAQ,CACNC,QADF,CACYC,kBADZ,EAEEC,GAFF,CAEOL,KAFP,EAEc,mBAFd,EAEmCC,IAFnC;AAGA,CATM;AAWP;AACA;AACA;AACA;AACA;;;;;AACO,MAAMK,wBAAwB,GAAKN,KAAF,IAAa,SAAoB;AAAA,MAAlB;AAAEE,IAAAA;AAAF,GAAkB;AACxEA,EAAAA,QAAQ,CACNC,QADF,CACYC,kBADZ,EAEEC,GAFF,CAEOL,KAFP,EAEc,mBAFd,EAEmC,IAFnC;AAGA,CAJM;AAMP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;AACO,MAAMO,OAAO,GAAG,CAAEP,KAAF,EAASQ,IAAT,KAAmB,SAAoB;AAAA,MAAlB;AAAEN,IAAAA;AAAF,GAAkB;;AAC7D;AACA,MAAK,CAAEM,IAAP,EAAc;AACb;AACA;;AAED,QAAMC,WAAW,GAAGP,QAAQ,CAC1BQ,MADkB,CACVN,kBADU,EAElBO,GAFk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A;;;AACO,SAASI,eAAT,CAA0BlB,KAA1B,EAAiCc,WAAjC,EAA8CK,KAA9C,EAAsD;AAC5D,SAAO,iBAA0B;AAAA,QAAf;AAAEjB,MAAAA;AAAF,KAAe;AAChC,6BAAa,iDAAb,EAA+D;AAC9Da,MAAAA,KAAK,EAAE,KADuD;AAE9DC,MAAAA,WAAW,EAAG;AAFgD,KAA/D;AAKAd,IAAAA,QAAQ,CACNC,QADF,CACYC,kBADZ,EAEEC,GAFF,CAEOL,KAFP,EAEcc,WAFd,EAE2B,CAAC,CAAEK,KAF9B;AAGA,GATD;AAUA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASC,kBAAT,CAA6BpB,KAA7B,EAAoCqB,QAApC,EAA+C;AACrD,SAAO,iBAA0B;AAAA,QAAf;AAAEnB,MAAAA;AAAF,KAAe;AAChC,6BAAa,oDAAb,EAAkE;AACjEa,MAAAA,KAAK,EAAE,KAD0D;AAEjEC,MAAAA,WAAW,EAAG;AAFmD,KAAlE;AAKAd,IAAAA,QAAQ,CAACC,QAAT,CAAmBC,kBAAnB,EAAsCkB,WAAtC,CAAmDtB,KAAnD,EAA0DqB,QAA1D;AACA,GAPD;AAQA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport deprecated from '@wordpress/deprecated';\nimport { store as preferencesStore } from '@wordpress/preferences';\n\n/**\n * Enable the complementary area.\n *\n * @param {string} scope Complementary area scope.\n * @param {string} area Area identifier.\n */\nexport const enableComplementaryArea = ( scope, area ) => ( { registry } ) => {\n\t// Return early if there's no area.\n\tif ( ! area ) {\n\t\treturn;\n\t}\n\n\tregistry\n\t\t.dispatch( preferencesStore )\n\t\t.set( scope, 'complementaryArea', area );\n};\n\n/**\n * Disable the complementary area.\n *\n * @param {string} scope Complementary area scope.\n */\nexport const disableComplementaryArea = ( scope ) => ( { registry } ) => {\n\tregistry\n\t\t.dispatch( preferencesStore )\n\t\t.set( scope, 'complementaryArea', null );\n};\n\n/**\n * Pins an item.\n *\n * @param {string} scope Item scope.\n * @param {string} item Item identifier.\n *\n * @return {Object} Action object.\n */\nexport const pinItem = ( scope, item ) => ( { registry } ) => {\n\t// Return early if there's no item.\n\tif ( ! item ) {\n\t\treturn;\n\t}\n\n\tconst pinnedItems = registry\n\t\t.select( preferencesStore )\n\t\t.get( scope, 'pinnedItems' );\n\n\t// The item is already pinned, there's nothing to do.\n\tif ( pinnedItems?.[ item ] === true ) {\n\t\treturn;\n\t}\n\n\tregistry.dispatch( preferencesStore ).set( scope, 'pinnedItems', {\n\t\t...pinnedItems,\n\t\t[ item ]: true,\n\t} );\n};\n\n/**\n * Unpins an item.\n *\n * @param {string} scope Item scope.\n * @param {string} item Item identifier.\n */\nexport const unpinItem = ( scope, item ) => ( { registry } ) => {\n\t// Return early if there's no item.\n\tif ( ! item ) {\n\t\treturn;\n\t}\n\n\tconst pinnedItems = registry\n\t\t.select( preferencesStore )\n\t\t.get( scope, 'pinnedItems' );\n\n\tregistry.dispatch( preferencesStore ).set( scope, 'pinnedItems', {\n\t\t...pinnedItems,\n\t\t[ item ]: false,\n\t} );\n};\n\n/**\n * Returns an action object used in signalling that a feature should be toggled.\n *\n * @param {string} scope The feature scope (e.g. core/edit-post).\n * @param {string} featureName The feature name.\n */\nexport function toggleFeature( scope, featureName ) {\n\treturn function ( { registry } ) {\n\t\tdeprecated( `wp.dispatch( 'core/interface' ).toggleFeature`, {\n\t\t\tsince: '6.0',\n\t\t\talternative: `wp.dispatch( 'core/preferences' ).toggle`,\n\t\t} );\n\n\t\tregistry.dispatch( preferencesStore ).toggle( scope, featureName );\n\t};\n}\n\n/**\n * Returns an action object used in signalling that a feature should be set to\n * a true or false value\n *\n * @param {string} scope The feature scope (e.g. core/edit-post).\n * @param {string} featureName The feature name.\n * @param {boolean} value The value to set.\n *\n * @return {Object} Action object.\n */\nexport function setFeatureValue( scope, featureName, value ) {\n\treturn function ( { registry } ) {\n\t\tdeprecated( `wp.dispatch( 'core/interface' ).setFeatureValue`, {\n\t\t\tsince: '6.0',\n\t\t\talternative: `wp.dispatch( 'core/preferences' ).set`,\n\t\t} );\n\n\t\tregistry\n\t\t\t.dispatch( preferencesStore )\n\t\t\t.set( scope, featureName, !! value );\n\t};\n}\n\n/**\n * Returns an action object used in signalling that defaults should be set for features.\n *\n * @param {string} scope The feature scope (e.g. core/edit-post).\n * @param {Object<string, boolean>} defaults A key/value map of feature names to values.\n *\n * @return {Object} Action object.\n */\nexport function setFeatureDefaults( scope, defaults ) {\n\treturn function ( { registry } ) {\n\t\tdeprecated( `wp.dispatch( 'core/interface' ).setFeatureDefaults`, {\n\t\t\tsince: '6.0',\n\t\t\talternative: `wp.dispatch( 'core/preferences' ).setDefaults`,\n\t\t} );\n\n\t\tregistry.dispatch( preferencesStore ).setDefaults( scope, defaults );\n\t};\n}\n"]}
@@ -1,7 +1,5 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
3
  Object.defineProperty(exports, "__esModule", {
6
4
  value: true
7
5
  });
@@ -9,8 +7,6 @@ exports.store = void 0;
9
7
 
10
8
  var _data = require("@wordpress/data");
11
9
 
12
- var _reducer = _interopRequireDefault(require("./reducer"));
13
-
14
10
  var actions = _interopRequireWildcard(require("./actions"));
15
11
 
16
12
  var selectors = _interopRequireWildcard(require("./selectors"));
@@ -28,12 +24,7 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
28
24
  /**
29
25
  * Internal dependencies
30
26
  */
31
- const storeConfig = {
32
- reducer: _reducer.default,
33
- actions,
34
- selectors,
35
- persist: ['enableItems', 'preferences']
36
- };
27
+
37
28
  /**
38
29
  * Store definition for the interface namespace.
39
30
  *
@@ -41,10 +32,13 @@ const storeConfig = {
41
32
  *
42
33
  * @type {Object}
43
34
  */
44
-
45
- const store = (0, _data.createReduxStore)(_constants.STORE_NAME, storeConfig); // Once we build a more generic persistence plugin that works across types of stores
35
+ const store = (0, _data.createReduxStore)(_constants.STORE_NAME, {
36
+ reducer: () => {},
37
+ actions,
38
+ selectors
39
+ }); // Once we build a more generic persistence plugin that works across types of stores
46
40
  // we'd be able to replace this with a register call.
47
41
 
48
42
  exports.store = store;
49
- (0, _data.registerStore)(_constants.STORE_NAME, storeConfig);
43
+ (0, _data.register)(store);
50
44
  //# sourceMappingURL=index.js.map
@@ -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,EAAiB,aAAjB;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', 'preferences' ],\n};\n\n/**\n * Store definition for the interface namespace.\n *\n * @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/data/README.md#createReduxStore\n *\n * @type {Object}\n */\nexport const store = createReduxStore( STORE_NAME, storeConfig );\n\n// Once we build a more generic persistence plugin that works across types of stores\n// we'd be able to replace this with a register call.\nregisterStore( STORE_NAME, storeConfig );\n"]}
1
+ {"version":3,"sources":["@wordpress/interface/src/store/index.js"],"names":["store","STORE_NAME","reducer","actions","selectors"],"mappings":";;;;;;;AAGA;;AAKA;;AACA;;AACA;;;;;;AAVA;AACA;AACA;;AAGA;AACA;AACA;;AAKA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMA,KAAK,GAAG,4BAAkBC,qBAAlB,EAA8B;AAClDC,EAAAA,OAAO,EAAE,MAAM,CAAE,CADiC;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 { STORE_NAME } from './constants';\n\n/**\n * Store definition for the interface namespace.\n *\n * @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/data/README.md#createReduxStore\n *\n * @type {Object}\n */\nexport const store = createReduxStore( STORE_NAME, {\n\treducer: () => {},\n\tactions,\n\tselectors,\n} );\n\n// Once we build a more generic persistence plugin that works across types of stores\n// we'd be able to replace this with a register call.\nregister( store );\n"]}
@@ -1,30 +1,22 @@
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
- exports.getActiveComplementaryArea = getActiveComplementaryArea;
7
- exports.isFeatureActive = isFeatureActive;
8
- exports.isItemPinned = isItemPinned;
8
+ exports.isItemPinned = exports.isFeatureActive = exports.getActiveComplementaryArea = void 0;
9
9
 
10
- var _lodash = require("lodash");
10
+ var _data = require("@wordpress/data");
11
11
 
12
- /**
13
- * External dependencies
14
- */
12
+ var _deprecated = _interopRequireDefault(require("@wordpress/deprecated"));
13
+
14
+ var _preferences = require("@wordpress/preferences");
15
15
 
16
16
  /**
17
- * Returns the item that is enabled in a given scope.
18
- *
19
- * @param {Object} state Global application state.
20
- * @param {string} itemType Type of item.
21
- * @param {string} scope Item scope.
22
- *
23
- * @return {?string|null} The item that is enabled in the passed scope and type.
17
+ * WordPress dependencies
24
18
  */
25
- function getSingleEnableItem(state, itemType, scope) {
26
- return (0, _lodash.get)(state.enableItems.singleEnableItems, [itemType, scope]);
27
- }
19
+
28
20
  /**
29
21
  * Returns the complementary area that is active in a given scope.
30
22
  *
@@ -33,26 +25,9 @@ function getSingleEnableItem(state, itemType, scope) {
33
25
  *
34
26
  * @return {string} The complementary area that is active in the given scope.
35
27
  */
36
-
37
-
38
- function getActiveComplementaryArea(state, scope) {
39
- return getSingleEnableItem(state, 'complementaryArea', scope);
40
- }
41
- /**
42
- * Returns a boolean indicating if an item is enabled or not in a given scope.
43
- *
44
- * @param {Object} state Global application state.
45
- * @param {string} itemType Type of item.
46
- * @param {string} scope Scope.
47
- * @param {string} item Item to check.
48
- *
49
- * @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.
50
- */
51
-
52
-
53
- function isMultipleEnabledItemEnabled(state, itemType, scope, item) {
54
- return (0, _lodash.get)(state.enableItems.multipleEnableItems, [itemType, scope, item]);
55
- }
28
+ const getActiveComplementaryArea = (0, _data.createRegistrySelector)(select => (state, scope) => {
29
+ return select(_preferences.store).get(scope, 'complementaryArea');
30
+ });
56
31
  /**
57
32
  * Returns a boolean indicating if an item is pinned or not.
58
33
  *
@@ -63,10 +38,13 @@ function isMultipleEnabledItemEnabled(state, itemType, scope, item) {
63
38
  * @return {boolean} True if the item is pinned and false otherwise.
64
39
  */
65
40
 
41
+ exports.getActiveComplementaryArea = getActiveComplementaryArea;
42
+ const isItemPinned = (0, _data.createRegistrySelector)(select => (state, scope, item) => {
43
+ var _pinnedItems$item;
66
44
 
67
- function isItemPinned(state, scope, item) {
68
- return isMultipleEnabledItemEnabled(state, 'pinnedItems', scope, item) !== false;
69
- }
45
+ const pinnedItems = select(_preferences.store).get(scope, 'pinnedItems');
46
+ return (_pinnedItems$item = pinnedItems === null || pinnedItems === void 0 ? void 0 : pinnedItems[item]) !== null && _pinnedItems$item !== void 0 ? _pinnedItems$item : true;
47
+ });
70
48
  /**
71
49
  * Returns a boolean indicating whether a feature is active for a particular
72
50
  * scope.
@@ -78,12 +56,13 @@ function isItemPinned(state, scope, item) {
78
56
  * @return {boolean} Is the feature enabled?
79
57
  */
80
58
 
81
-
82
- function isFeatureActive(state, scope, featureName) {
83
- var _state$preferences$fe, _state$preferenceDefa;
84
-
85
- const featureValue = (_state$preferences$fe = state.preferences.features[scope]) === null || _state$preferences$fe === void 0 ? void 0 : _state$preferences$fe[featureName];
86
- const defaultedFeatureValue = featureValue !== undefined ? featureValue : (_state$preferenceDefa = state.preferenceDefaults.features[scope]) === null || _state$preferenceDefa === void 0 ? void 0 : _state$preferenceDefa[featureName];
87
- return !!defaultedFeatureValue;
88
- }
59
+ exports.isItemPinned = isItemPinned;
60
+ const isFeatureActive = (0, _data.createRegistrySelector)(select => (state, scope, featureName) => {
61
+ (0, _deprecated.default)(`wp.select( 'core/interface' ).isFeatureActive( scope, featureName )`, {
62
+ since: '6.0',
63
+ alternative: `!! wp.select( 'core/preferences' ).isFeatureActive( scope, featureName )`
64
+ });
65
+ return !!select(_preferences.store).get(scope, featureName);
66
+ });
67
+ exports.isFeatureActive = isFeatureActive;
89
68
  //# 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","featureName","featureValue","preferences","features","defaultedFeatureValue","undefined","preferenceDefaults"],"mappings":";;;;;;;;;AAGA;;AAHA;AACA;AACA;;AAGA;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,SAASG,eAAT,CAA0BV,KAA1B,EAAiCE,KAAjC,EAAwCS,WAAxC,EAAsD;AAAA;;AAC5D,QAAMC,YAAY,4BAAGZ,KAAK,CAACa,WAAN,CAAkBC,QAAlB,CAA4BZ,KAA5B,CAAH,0DAAG,sBAAuCS,WAAvC,CAArB;AACA,QAAMI,qBAAqB,GAC1BH,YAAY,KAAKI,SAAjB,GACGJ,YADH,4BAEGZ,KAAK,CAACiB,kBAAN,CAAyBH,QAAzB,CAAmCZ,KAAnC,CAFH,0DAEG,sBAA8CS,WAA9C,CAHJ;AAKA,SAAO,CAAC,CAAEI,qBAAV;AACA","sourcesContent":["/**\n * External dependencies\n */\nimport { get } from 'lodash';\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 function isFeatureActive( state, scope, featureName ) {\n\tconst featureValue = state.preferences.features[ scope ]?.[ featureName ];\n\tconst defaultedFeatureValue =\n\t\tfeatureValue !== undefined\n\t\t\t? featureValue\n\t\t\t: state.preferenceDefaults.features[ scope ]?.[ featureName ];\n\n\treturn !! defaultedFeatureValue;\n}\n"]}
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,SAAOF,MAAM,CAAEG,kBAAF,CAAN,CAA2BC,GAA3B,CAAgCF,KAAhC,EAAuC,mBAAvC,CAAP;AACA,CAHwC,CAAnC;AAMP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,MAAMG,YAAY,GAAG,kCACzBL,MAAF,IAAc,CAAEC,KAAF,EAASC,KAAT,EAAgBI,IAAhB,KAA0B;AAAA;;AACvC,QAAMC,WAAW,GAAGP,MAAM,CAAEG,kBAAF,CAAN,CAA2BC,GAA3B,CACnBF,KADmB,EAEnB,aAFmB,CAApB;AAIA,8BAAOK,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,kCAC5BR,MAAF,IAAc,CAAEC,KAAF,EAASC,KAAT,EAAgBO,WAAhB,KAAiC;AAC9C,2BACE,qEADF,EAEC;AACCC,IAAAA,KAAK,EAAE,KADR;AAECC,IAAAA,WAAW,EAAG;AAFf,GAFD;AAQA,SAAO,CAAC,CAAEX,MAAM,CAAEG,kBAAF,CAAN,CAA2BC,GAA3B,CAAgCF,KAAhC,EAAuCO,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} The complementary area that is active in the given scope.\n */\nexport const getActiveComplementaryArea = createRegistrySelector(\n\t( select ) => ( state, scope ) => {\n\t\treturn select( preferencesStore ).get( scope, 'complementaryArea' );\n\t}\n);\n\n/**\n * Returns a boolean indicating if an item is pinned or not.\n *\n * @param {Object} state Global application state.\n * @param {string} scope Scope.\n * @param {string} item Item to check.\n *\n * @return {boolean} True if the item is pinned and false otherwise.\n */\nexport const isItemPinned = createRegistrySelector(\n\t( select ) => ( state, scope, item ) => {\n\t\tconst pinnedItems = select( preferencesStore ).get(\n\t\t\tscope,\n\t\t\t'pinnedItems'\n\t\t);\n\t\treturn pinnedItems?.[ item ] ?? true;\n\t}\n);\n\n/**\n * Returns a boolean indicating whether a feature is active for a particular\n * scope.\n *\n * @param {Object} state The store state.\n * @param {string} scope The scope of the feature (e.g. core/edit-post).\n * @param {string} featureName The name of the feature.\n *\n * @return {boolean} Is the feature enabled?\n */\nexport const isFeatureActive = createRegistrySelector(\n\t( select ) => ( state, scope, featureName ) => {\n\t\tdeprecated(\n\t\t\t`wp.select( 'core/interface' ).isFeatureActive( scope, featureName )`,\n\t\t\t{\n\t\t\t\tsince: '6.0',\n\t\t\t\talternative: `!! wp.select( 'core/preferences' ).isFeatureActive( scope, featureName )`,\n\t\t\t}\n\t\t);\n\n\t\treturn !! select( preferencesStore ).get( scope, featureName );\n\t}\n);\n"]}