@wordpress/preferences 3.10.0 → 3.12.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 +4 -0
- package/build/components/preference-toggle-menu-item/index.js +12 -13
- package/build/components/preference-toggle-menu-item/index.js.map +1 -1
- package/build/store/actions.js +4 -5
- package/build/store/actions.js.map +1 -1
- package/build/store/reducer.js +3 -11
- package/build/store/reducer.js.map +1 -1
- package/build/store/selectors.js +2 -4
- package/build/store/selectors.js.map +1 -1
- package/build-module/components/preference-toggle-menu-item/index.js +12 -13
- package/build-module/components/preference-toggle-menu-item/index.js.map +1 -1
- package/build-module/store/actions.js +4 -5
- package/build-module/store/actions.js.map +1 -1
- package/build-module/store/reducer.js +3 -11
- package/build-module/store/reducer.js.map +1 -1
- package/build-module/store/selectors.js +2 -4
- package/build-module/store/selectors.js.map +1 -1
- package/package.json +7 -7
- package/src/components/preference-toggle-menu-item/index.js +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -26,19 +26,18 @@ var _store = require("../../store");
|
|
|
26
26
|
/**
|
|
27
27
|
* Internal dependencies
|
|
28
28
|
*/
|
|
29
|
-
function PreferenceToggleMenuItem(
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
const isActive = (0, _data.useSelect)(select => !!select(_store.store).get(scope, name), [name]);
|
|
29
|
+
function PreferenceToggleMenuItem({
|
|
30
|
+
scope,
|
|
31
|
+
name,
|
|
32
|
+
label,
|
|
33
|
+
info,
|
|
34
|
+
messageActivated,
|
|
35
|
+
messageDeactivated,
|
|
36
|
+
shortcut,
|
|
37
|
+
onToggle = () => null,
|
|
38
|
+
disabled = false
|
|
39
|
+
}) {
|
|
40
|
+
const isActive = (0, _data.useSelect)(select => !!select(_store.store).get(scope, name), [scope, name]);
|
|
42
41
|
const {
|
|
43
42
|
toggle
|
|
44
43
|
} = (0, _data.useDispatch)(_store.store);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/preferences/src/components/preference-toggle-menu-item/index.js"],"names":["PreferenceToggleMenuItem","scope","name","label","info","messageActivated","messageDeactivated","shortcut","onToggle","disabled","isActive","select","preferencesStore","get","toggle","speakMessage","message","check"],"mappings":";;;;;;;;;AAGA;;AACA;;AACA;;AACA;;AACA;;AAKA;;AAZA;AACA;AACA;;AAOA;AACA;AACA;AAGe,SAASA,wBAAT,
|
|
1
|
+
{"version":3,"sources":["@wordpress/preferences/src/components/preference-toggle-menu-item/index.js"],"names":["PreferenceToggleMenuItem","scope","name","label","info","messageActivated","messageDeactivated","shortcut","onToggle","disabled","isActive","select","preferencesStore","get","toggle","speakMessage","message","check"],"mappings":";;;;;;;;;AAGA;;AACA;;AACA;;AACA;;AACA;;AAKA;;AAZA;AACA;AACA;;AAOA;AACA;AACA;AAGe,SAASA,wBAAT,CAAmC;AACjDC,EAAAA,KADiD;AAEjDC,EAAAA,IAFiD;AAGjDC,EAAAA,KAHiD;AAIjDC,EAAAA,IAJiD;AAKjDC,EAAAA,gBALiD;AAMjDC,EAAAA,kBANiD;AAOjDC,EAAAA,QAPiD;AAQjDC,EAAAA,QAAQ,GAAG,MAAM,IARgC;AASjDC,EAAAA,QAAQ,GAAG;AATsC,CAAnC,EAUX;AACH,QAAMC,QAAQ,GAAG,qBACdC,MAAF,IAAc,CAAC,CAAEA,MAAM,CAAEC,YAAF,CAAN,CAA2BC,GAA3B,CAAgCZ,KAAhC,EAAuCC,IAAvC,CADD,EAEhB,CAAED,KAAF,EAASC,IAAT,CAFgB,CAAjB;AAIA,QAAM;AAAEY,IAAAA;AAAF,MAAa,uBAAaF,YAAb,CAAnB;;AACA,QAAMG,YAAY,GAAG,MAAM;AAC1B,QAAKL,QAAL,EAAgB;AACf,YAAMM,OAAO,GACZV,kBAAkB,IAClB;AACC;AACA,oBAAI,6BAAJ,CAFD,EAGCH,KAHD,CAFD;AAOA,uBAAOa,OAAP;AACA,KATD,MASO;AACN,YAAMA,OAAO,GACZX,gBAAgB,IAChB;AACC;AACA,oBAAI,2BAAJ,CAFD,EAGCF,KAHD,CAFD;AAOA,uBAAOa,OAAP;AACA;AACD,GApBD;;AAsBA,SACC,4BAAC,oBAAD;AACC,IAAA,IAAI,EAAGN,QAAQ,IAAIO,YADpB;AAEC,IAAA,UAAU,EAAGP,QAFd;AAGC,IAAA,OAAO,EAAG,MAAM;AACfF,MAAAA,QAAQ;AACRM,MAAAA,MAAM,CAAEb,KAAF,EAASC,IAAT,CAAN;AACAa,MAAAA,YAAY;AACZ,KAPF;AAQC,IAAA,IAAI,EAAC,kBARN;AASC,IAAA,IAAI,EAAGX,IATR;AAUC,IAAA,QAAQ,EAAGG,QAVZ;AAWC,IAAA,QAAQ,EAAGE;AAXZ,KAaGN,KAbH,CADD;AAiBA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { MenuItem } from '@wordpress/components';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { check } from '@wordpress/icons';\nimport { speak } from '@wordpress/a11y';\n\n/**\n * Internal dependencies\n */\nimport { store as preferencesStore } from '../../store';\n\nexport default function PreferenceToggleMenuItem( {\n\tscope,\n\tname,\n\tlabel,\n\tinfo,\n\tmessageActivated,\n\tmessageDeactivated,\n\tshortcut,\n\tonToggle = () => null,\n\tdisabled = false,\n} ) {\n\tconst isActive = useSelect(\n\t\t( select ) => !! select( preferencesStore ).get( scope, name ),\n\t\t[ scope, name ]\n\t);\n\tconst { toggle } = useDispatch( preferencesStore );\n\tconst speakMessage = () => {\n\t\tif ( isActive ) {\n\t\t\tconst message =\n\t\t\t\tmessageDeactivated ||\n\t\t\t\tsprintf(\n\t\t\t\t\t/* translators: %s: preference name, e.g. 'Fullscreen mode' */\n\t\t\t\t\t__( 'Preference deactivated - %s' ),\n\t\t\t\t\tlabel\n\t\t\t\t);\n\t\t\tspeak( message );\n\t\t} else {\n\t\t\tconst message =\n\t\t\t\tmessageActivated ||\n\t\t\t\tsprintf(\n\t\t\t\t\t/* translators: %s: preference name, e.g. 'Fullscreen mode' */\n\t\t\t\t\t__( 'Preference activated - %s' ),\n\t\t\t\t\tlabel\n\t\t\t\t);\n\t\t\tspeak( message );\n\t\t}\n\t};\n\n\treturn (\n\t\t<MenuItem\n\t\t\ticon={ isActive && check }\n\t\t\tisSelected={ isActive }\n\t\t\tonClick={ () => {\n\t\t\t\tonToggle();\n\t\t\t\ttoggle( scope, name );\n\t\t\t\tspeakMessage();\n\t\t\t} }\n\t\t\trole=\"menuitemcheckbox\"\n\t\t\tinfo={ info }\n\t\t\tshortcut={ shortcut }\n\t\t\tdisabled={ disabled }\n\t\t>\n\t\t\t{ label }\n\t\t</MenuItem>\n\t);\n}\n"]}
|
package/build/store/actions.js
CHANGED
|
@@ -16,11 +16,10 @@ exports.toggle = toggle;
|
|
|
16
16
|
* @param {string} name The preference name.
|
|
17
17
|
*/
|
|
18
18
|
function toggle(scope, name) {
|
|
19
|
-
return function (
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
} = _ref;
|
|
19
|
+
return function ({
|
|
20
|
+
select,
|
|
21
|
+
dispatch
|
|
22
|
+
}) {
|
|
24
23
|
const currentValue = select.get(scope, name);
|
|
25
24
|
dispatch.set(scope, name, !currentValue);
|
|
26
25
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/preferences/src/store/actions.js"],"names":["toggle","scope","name","select","dispatch","currentValue","get","set","value","type","setDefaults","defaults","setPersistenceLayer","persistenceLayer","persistedData"],"mappings":";;;;;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,MAAT,CAAiBC,KAAjB,EAAwBC,IAAxB,EAA+B;AACrC,SAAO,
|
|
1
|
+
{"version":3,"sources":["@wordpress/preferences/src/store/actions.js"],"names":["toggle","scope","name","select","dispatch","currentValue","get","set","value","type","setDefaults","defaults","setPersistenceLayer","persistenceLayer","persistedData"],"mappings":";;;;;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,MAAT,CAAiBC,KAAjB,EAAwBC,IAAxB,EAA+B;AACrC,SAAO,UAAW;AAAEC,IAAAA,MAAF;AAAUC,IAAAA;AAAV,GAAX,EAAkC;AACxC,UAAMC,YAAY,GAAGF,MAAM,CAACG,GAAP,CAAYL,KAAZ,EAAmBC,IAAnB,CAArB;AACAE,IAAAA,QAAQ,CAACG,GAAT,CAAcN,KAAd,EAAqBC,IAArB,EAA2B,CAAEG,YAA7B;AACA,GAHD;AAIA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASE,GAAT,CAAcN,KAAd,EAAqBC,IAArB,EAA2BM,KAA3B,EAAmC;AACzC,SAAO;AACNC,IAAAA,IAAI,EAAE,sBADA;AAENR,IAAAA,KAFM;AAGNC,IAAAA,IAHM;AAINM,IAAAA;AAJM,GAAP;AAMA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASE,WAAT,CAAsBT,KAAtB,EAA6BU,QAA7B,EAAwC;AAC9C,SAAO;AACNF,IAAAA,IAAI,EAAE,yBADA;AAENR,IAAAA,KAFM;AAGNU,IAAAA;AAHM,GAAP;AAKA;AAED;;AACA;;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,eAAeC,mBAAf,CAAoCC,gBAApC,EAAuD;AAC7D,QAAMC,aAAa,GAAG,MAAMD,gBAAgB,CAACP,GAAjB,EAA5B;AACA,SAAO;AACNG,IAAAA,IAAI,EAAE,uBADA;AAENI,IAAAA,gBAFM;AAGNC,IAAAA;AAHM,GAAP;AAKA","sourcesContent":["/**\n * Returns an action object used in signalling that a preference should be\n * toggled.\n *\n * @param {string} scope The preference scope (e.g. core/edit-post).\n * @param {string} name The preference name.\n */\nexport function toggle( scope, name ) {\n\treturn function ( { select, dispatch } ) {\n\t\tconst currentValue = select.get( scope, name );\n\t\tdispatch.set( scope, name, ! currentValue );\n\t};\n}\n\n/**\n * Returns an action object used in signalling that a preference should be set\n * to a value\n *\n * @param {string} scope The preference scope (e.g. core/edit-post).\n * @param {string} name The preference name.\n * @param {*} value The value to set.\n *\n * @return {Object} Action object.\n */\nexport function set( scope, name, value ) {\n\treturn {\n\t\ttype: 'SET_PREFERENCE_VALUE',\n\t\tscope,\n\t\tname,\n\t\tvalue,\n\t};\n}\n\n/**\n * Returns an action object used in signalling that preference defaults should\n * be set.\n *\n * @param {string} scope The preference scope (e.g. core/edit-post).\n * @param {Object<string, *>} defaults A key/value map of preference names to values.\n *\n * @return {Object} Action object.\n */\nexport function setDefaults( scope, defaults ) {\n\treturn {\n\t\ttype: 'SET_PREFERENCE_DEFAULTS',\n\t\tscope,\n\t\tdefaults,\n\t};\n}\n\n/** @typedef {() => Promise<Object>} WPPreferencesPersistenceLayerGet */\n/** @typedef {(Object) => void} WPPreferencesPersistenceLayerSet */\n/**\n * @typedef WPPreferencesPersistenceLayer\n *\n * @property {WPPreferencesPersistenceLayerGet} get An async function that gets data from the persistence layer.\n * @property {WPPreferencesPersistenceLayerSet} set A function that sets data in the persistence layer.\n */\n\n/**\n * Sets the persistence layer.\n *\n * When a persistence layer is set, the preferences store will:\n * - call `get` immediately and update the store state to the value returned.\n * - call `set` with all preferences whenever a preference changes value.\n *\n * `setPersistenceLayer` should ideally be dispatched at the start of an\n * application's lifecycle, before any other actions have been dispatched to\n * the preferences store.\n *\n * @param {WPPreferencesPersistenceLayer} persistenceLayer The persistence layer.\n *\n * @return {Object} Action object.\n */\nexport async function setPersistenceLayer( persistenceLayer ) {\n\tconst persistedData = await persistenceLayer.get();\n\treturn {\n\t\ttype: 'SET_PERSISTENCE_LAYER',\n\t\tpersistenceLayer,\n\t\tpersistedData,\n\t};\n}\n"]}
|
package/build/store/reducer.js
CHANGED
|
@@ -24,10 +24,7 @@ var _data = require("@wordpress/data");
|
|
|
24
24
|
*
|
|
25
25
|
* @return {Object} Updated state.
|
|
26
26
|
*/
|
|
27
|
-
function defaults() {
|
|
28
|
-
let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
29
|
-
let action = arguments.length > 1 ? arguments[1] : undefined;
|
|
30
|
-
|
|
27
|
+
function defaults(state = {}, action) {
|
|
31
28
|
if (action.type === 'SET_PREFERENCE_DEFAULTS') {
|
|
32
29
|
const {
|
|
33
30
|
scope,
|
|
@@ -71,9 +68,7 @@ function withPersistenceLayer(reducer) {
|
|
|
71
68
|
const nextState = reducer(state, action);
|
|
72
69
|
|
|
73
70
|
if (action.type === 'SET_PREFERENCE_VALUE') {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
(_persistenceLayer = persistenceLayer) === null || _persistenceLayer === void 0 ? void 0 : _persistenceLayer.set(nextState);
|
|
71
|
+
persistenceLayer?.set(nextState);
|
|
77
72
|
}
|
|
78
73
|
|
|
79
74
|
return nextState;
|
|
@@ -89,10 +84,7 @@ function withPersistenceLayer(reducer) {
|
|
|
89
84
|
*/
|
|
90
85
|
|
|
91
86
|
|
|
92
|
-
const preferences = withPersistenceLayer(
|
|
93
|
-
let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
94
|
-
let action = arguments.length > 1 ? arguments[1] : undefined;
|
|
95
|
-
|
|
87
|
+
const preferences = withPersistenceLayer((state = {}, action) => {
|
|
96
88
|
if (action.type === 'SET_PREFERENCE_VALUE') {
|
|
97
89
|
const {
|
|
98
90
|
scope,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/preferences/src/store/reducer.js"],"names":["defaults","state","action","type","scope","values","withPersistenceLayer","reducer","persistenceLayer","persistence","persistedData","nextState","set","preferences","name","value"],"mappings":";;;;;;;;;AAGA;;AAHA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,QAAT,
|
|
1
|
+
{"version":3,"sources":["@wordpress/preferences/src/store/reducer.js"],"names":["defaults","state","action","type","scope","values","withPersistenceLayer","reducer","persistenceLayer","persistence","persistedData","nextState","set","preferences","name","value"],"mappings":";;;;;;;;;AAGA;;AAHA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,QAAT,CAAmBC,KAAK,GAAG,EAA3B,EAA+BC,MAA/B,EAAwC;AAC9C,MAAKA,MAAM,CAACC,IAAP,KAAgB,yBAArB,EAAiD;AAChD,UAAM;AAAEC,MAAAA,KAAF;AAASJ,MAAAA,QAAQ,EAAEK;AAAnB,QAA8BH,MAApC;AACA,WAAO,EACN,GAAGD,KADG;AAEN,OAAEG,KAAF,GAAW,EACV,GAAGH,KAAK,CAAEG,KAAF,CADE;AAEV,WAAGC;AAFO;AAFL,KAAP;AAOA;;AAED,SAAOJ,KAAP;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,SAASK,oBAAT,CAA+BC,OAA/B,EAAyC;AACxC,MAAIC,gBAAJ;AAEA,SAAO,CAAEP,KAAF,EAASC,MAAT,KAAqB;AAC3B;AACA;AACA,QAAKA,MAAM,CAACC,IAAP,KAAgB,uBAArB,EAA+C;AAC9C,YAAM;AAAEK,QAAAA,gBAAgB,EAAEC,WAApB;AAAiCC,QAAAA;AAAjC,UAAmDR,MAAzD;AACAM,MAAAA,gBAAgB,GAAGC,WAAnB;AACA,aAAOC,aAAP;AACA;;AAED,UAAMC,SAAS,GAAGJ,OAAO,CAAEN,KAAF,EAASC,MAAT,CAAzB;;AACA,QAAKA,MAAM,CAACC,IAAP,KAAgB,sBAArB,EAA8C;AAC7CK,MAAAA,gBAAgB,EAAEI,GAAlB,CAAuBD,SAAvB;AACA;;AAED,WAAOA,SAAP;AACA,GAfD;AAgBA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,MAAME,WAAW,GAAGP,oBAAoB,CAAE,CAAEL,KAAK,GAAG,EAAV,EAAcC,MAAd,KAA0B;AAC1E,MAAKA,MAAM,CAACC,IAAP,KAAgB,sBAArB,EAA8C;AAC7C,UAAM;AAAEC,MAAAA,KAAF;AAASU,MAAAA,IAAT;AAAeC,MAAAA;AAAf,QAAyBb,MAA/B;AACA,WAAO,EACN,GAAGD,KADG;AAEN,OAAEG,KAAF,GAAW,EACV,GAAGH,KAAK,CAAEG,KAAF,CADE;AAEV,SAAEU,IAAF,GAAUC;AAFA;AAFL,KAAP;AAOA;;AAED,SAAOd,KAAP;AACA,CAb8C,CAAxC;;;eAeQ,2BAAiB;AAC/BD,EAAAA,QAD+B;AAE/Ba,EAAAA;AAF+B,CAAjB,C","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { combineReducers } from '@wordpress/data';\n\n/**\n * Reducer returning the defaults for user preferences.\n *\n * This is kept intentionally separate from the preferences\n * themselves so that defaults are not persisted.\n *\n * @param {Object} state Current state.\n * @param {Object} action Dispatched action.\n *\n * @return {Object} Updated state.\n */\nexport function defaults( state = {}, action ) {\n\tif ( action.type === 'SET_PREFERENCE_DEFAULTS' ) {\n\t\tconst { scope, defaults: values } = action;\n\t\treturn {\n\t\t\t...state,\n\t\t\t[ scope ]: {\n\t\t\t\t...state[ scope ],\n\t\t\t\t...values,\n\t\t\t},\n\t\t};\n\t}\n\n\treturn state;\n}\n\n/**\n * Higher order reducer that does the following:\n * - Merges any data from the persistence layer into the state when the\n * `SET_PERSISTENCE_LAYER` action is received.\n * - Passes any preferences changes to the persistence layer.\n *\n * @param {Function} reducer The preferences reducer.\n *\n * @return {Function} The enhanced reducer.\n */\nfunction withPersistenceLayer( reducer ) {\n\tlet persistenceLayer;\n\n\treturn ( state, action ) => {\n\t\t// Setup the persistence layer, and return the persisted data\n\t\t// as the state.\n\t\tif ( action.type === 'SET_PERSISTENCE_LAYER' ) {\n\t\t\tconst { persistenceLayer: persistence, persistedData } = action;\n\t\t\tpersistenceLayer = persistence;\n\t\t\treturn persistedData;\n\t\t}\n\n\t\tconst nextState = reducer( state, action );\n\t\tif ( action.type === 'SET_PREFERENCE_VALUE' ) {\n\t\t\tpersistenceLayer?.set( nextState );\n\t\t}\n\n\t\treturn nextState;\n\t};\n}\n\n/**\n * Reducer returning the user preferences.\n *\n * @param {Object} state Current state.\n * @param {Object} action Dispatched action.\n *\n * @return {Object} Updated state.\n */\nexport const preferences = withPersistenceLayer( ( state = {}, action ) => {\n\tif ( action.type === 'SET_PREFERENCE_VALUE' ) {\n\t\tconst { scope, name, value } = action;\n\t\treturn {\n\t\t\t...state,\n\t\t\t[ scope ]: {\n\t\t\t\t...state[ scope ],\n\t\t\t\t[ name ]: value,\n\t\t\t},\n\t\t};\n\t}\n\n\treturn state;\n} );\n\nexport default combineReducers( {\n\tdefaults,\n\tpreferences,\n} );\n"]}
|
package/build/store/selectors.js
CHANGED
|
@@ -16,9 +16,7 @@ exports.get = get;
|
|
|
16
16
|
* @return {*} Is the feature enabled?
|
|
17
17
|
*/
|
|
18
18
|
function get(state, scope, name) {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
const value = (_state$preferences$sc = state.preferences[scope]) === null || _state$preferences$sc === void 0 ? void 0 : _state$preferences$sc[name];
|
|
22
|
-
return value !== undefined ? value : (_state$defaults$scope = state.defaults[scope]) === null || _state$defaults$scope === void 0 ? void 0 : _state$defaults$scope[name];
|
|
19
|
+
const value = state.preferences[scope]?.[name];
|
|
20
|
+
return value !== undefined ? value : state.defaults[scope]?.[name];
|
|
23
21
|
}
|
|
24
22
|
//# sourceMappingURL=selectors.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/preferences/src/store/selectors.js"],"names":["get","state","scope","name","value","preferences","undefined","defaults"],"mappings":";;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,GAAT,CAAcC,KAAd,EAAqBC,KAArB,EAA4BC,IAA5B,EAAmC;
|
|
1
|
+
{"version":3,"sources":["@wordpress/preferences/src/store/selectors.js"],"names":["get","state","scope","name","value","preferences","undefined","defaults"],"mappings":";;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,GAAT,CAAcC,KAAd,EAAqBC,KAArB,EAA4BC,IAA5B,EAAmC;AACzC,QAAMC,KAAK,GAAGH,KAAK,CAACI,WAAN,CAAmBH,KAAnB,IAA8BC,IAA9B,CAAd;AACA,SAAOC,KAAK,KAAKE,SAAV,GAAsBF,KAAtB,GAA8BH,KAAK,CAACM,QAAN,CAAgBL,KAAhB,IAA2BC,IAA3B,CAArC;AACA","sourcesContent":["/**\n * Returns a boolean indicating whether a prefer 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} name The name of the feature.\n *\n * @return {*} Is the feature enabled?\n */\nexport function get( state, scope, name ) {\n\tconst value = state.preferences[ scope ]?.[ name ];\n\treturn value !== undefined ? value : state.defaults[ scope ]?.[ name ];\n}\n"]}
|
|
@@ -13,19 +13,18 @@ import { speak } from '@wordpress/a11y';
|
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
15
|
import { store as preferencesStore } from '../../store';
|
|
16
|
-
export default function PreferenceToggleMenuItem(
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
const isActive = useSelect(select => !!select(preferencesStore).get(scope, name), [name]);
|
|
16
|
+
export default function PreferenceToggleMenuItem({
|
|
17
|
+
scope,
|
|
18
|
+
name,
|
|
19
|
+
label,
|
|
20
|
+
info,
|
|
21
|
+
messageActivated,
|
|
22
|
+
messageDeactivated,
|
|
23
|
+
shortcut,
|
|
24
|
+
onToggle = () => null,
|
|
25
|
+
disabled = false
|
|
26
|
+
}) {
|
|
27
|
+
const isActive = useSelect(select => !!select(preferencesStore).get(scope, name), [scope, name]);
|
|
29
28
|
const {
|
|
30
29
|
toggle
|
|
31
30
|
} = useDispatch(preferencesStore);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/preferences/src/components/preference-toggle-menu-item/index.js"],"names":["useSelect","useDispatch","MenuItem","__","sprintf","check","speak","store","preferencesStore","PreferenceToggleMenuItem","scope","name","label","info","messageActivated","messageDeactivated","shortcut","onToggle","disabled","isActive","select","get","toggle","speakMessage","message"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,SAAT,EAAoBC,WAApB,QAAuC,iBAAvC;AACA,SAASC,QAAT,QAAyB,uBAAzB;AACA,SAASC,EAAT,EAAaC,OAAb,QAA4B,iBAA5B;AACA,SAASC,KAAT,QAAsB,kBAAtB;AACA,SAASC,KAAT,QAAsB,iBAAtB;AAEA;AACA;AACA;;AACA,SAASC,KAAK,IAAIC,gBAAlB,QAA0C,aAA1C;AAEA,eAAe,SAASC,wBAAT,
|
|
1
|
+
{"version":3,"sources":["@wordpress/preferences/src/components/preference-toggle-menu-item/index.js"],"names":["useSelect","useDispatch","MenuItem","__","sprintf","check","speak","store","preferencesStore","PreferenceToggleMenuItem","scope","name","label","info","messageActivated","messageDeactivated","shortcut","onToggle","disabled","isActive","select","get","toggle","speakMessage","message"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,SAAT,EAAoBC,WAApB,QAAuC,iBAAvC;AACA,SAASC,QAAT,QAAyB,uBAAzB;AACA,SAASC,EAAT,EAAaC,OAAb,QAA4B,iBAA5B;AACA,SAASC,KAAT,QAAsB,kBAAtB;AACA,SAASC,KAAT,QAAsB,iBAAtB;AAEA;AACA;AACA;;AACA,SAASC,KAAK,IAAIC,gBAAlB,QAA0C,aAA1C;AAEA,eAAe,SAASC,wBAAT,CAAmC;AACjDC,EAAAA,KADiD;AAEjDC,EAAAA,IAFiD;AAGjDC,EAAAA,KAHiD;AAIjDC,EAAAA,IAJiD;AAKjDC,EAAAA,gBALiD;AAMjDC,EAAAA,kBANiD;AAOjDC,EAAAA,QAPiD;AAQjDC,EAAAA,QAAQ,GAAG,MAAM,IARgC;AASjDC,EAAAA,QAAQ,GAAG;AATsC,CAAnC,EAUX;AACH,QAAMC,QAAQ,GAAGnB,SAAS,CACvBoB,MAAF,IAAc,CAAC,CAAEA,MAAM,CAAEZ,gBAAF,CAAN,CAA2Ba,GAA3B,CAAgCX,KAAhC,EAAuCC,IAAvC,CADQ,EAEzB,CAAED,KAAF,EAASC,IAAT,CAFyB,CAA1B;AAIA,QAAM;AAAEW,IAAAA;AAAF,MAAarB,WAAW,CAAEO,gBAAF,CAA9B;;AACA,QAAMe,YAAY,GAAG,MAAM;AAC1B,QAAKJ,QAAL,EAAgB;AACf,YAAMK,OAAO,GACZT,kBAAkB,IAClBX,OAAO;AACN;AACAD,MAAAA,EAAE,CAAE,6BAAF,CAFI,EAGNS,KAHM,CAFR;AAOAN,MAAAA,KAAK,CAAEkB,OAAF,CAAL;AACA,KATD,MASO;AACN,YAAMA,OAAO,GACZV,gBAAgB,IAChBV,OAAO;AACN;AACAD,MAAAA,EAAE,CAAE,2BAAF,CAFI,EAGNS,KAHM,CAFR;AAOAN,MAAAA,KAAK,CAAEkB,OAAF,CAAL;AACA;AACD,GApBD;;AAsBA,SACC,cAAC,QAAD;AACC,IAAA,IAAI,EAAGL,QAAQ,IAAId,KADpB;AAEC,IAAA,UAAU,EAAGc,QAFd;AAGC,IAAA,OAAO,EAAG,MAAM;AACfF,MAAAA,QAAQ;AACRK,MAAAA,MAAM,CAAEZ,KAAF,EAASC,IAAT,CAAN;AACAY,MAAAA,YAAY;AACZ,KAPF;AAQC,IAAA,IAAI,EAAC,kBARN;AASC,IAAA,IAAI,EAAGV,IATR;AAUC,IAAA,QAAQ,EAAGG,QAVZ;AAWC,IAAA,QAAQ,EAAGE;AAXZ,KAaGN,KAbH,CADD;AAiBA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { MenuItem } from '@wordpress/components';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { check } from '@wordpress/icons';\nimport { speak } from '@wordpress/a11y';\n\n/**\n * Internal dependencies\n */\nimport { store as preferencesStore } from '../../store';\n\nexport default function PreferenceToggleMenuItem( {\n\tscope,\n\tname,\n\tlabel,\n\tinfo,\n\tmessageActivated,\n\tmessageDeactivated,\n\tshortcut,\n\tonToggle = () => null,\n\tdisabled = false,\n} ) {\n\tconst isActive = useSelect(\n\t\t( select ) => !! select( preferencesStore ).get( scope, name ),\n\t\t[ scope, name ]\n\t);\n\tconst { toggle } = useDispatch( preferencesStore );\n\tconst speakMessage = () => {\n\t\tif ( isActive ) {\n\t\t\tconst message =\n\t\t\t\tmessageDeactivated ||\n\t\t\t\tsprintf(\n\t\t\t\t\t/* translators: %s: preference name, e.g. 'Fullscreen mode' */\n\t\t\t\t\t__( 'Preference deactivated - %s' ),\n\t\t\t\t\tlabel\n\t\t\t\t);\n\t\t\tspeak( message );\n\t\t} else {\n\t\t\tconst message =\n\t\t\t\tmessageActivated ||\n\t\t\t\tsprintf(\n\t\t\t\t\t/* translators: %s: preference name, e.g. 'Fullscreen mode' */\n\t\t\t\t\t__( 'Preference activated - %s' ),\n\t\t\t\t\tlabel\n\t\t\t\t);\n\t\t\tspeak( message );\n\t\t}\n\t};\n\n\treturn (\n\t\t<MenuItem\n\t\t\ticon={ isActive && check }\n\t\t\tisSelected={ isActive }\n\t\t\tonClick={ () => {\n\t\t\t\tonToggle();\n\t\t\t\ttoggle( scope, name );\n\t\t\t\tspeakMessage();\n\t\t\t} }\n\t\t\trole=\"menuitemcheckbox\"\n\t\t\tinfo={ info }\n\t\t\tshortcut={ shortcut }\n\t\t\tdisabled={ disabled }\n\t\t>\n\t\t\t{ label }\n\t\t</MenuItem>\n\t);\n}\n"]}
|
|
@@ -6,11 +6,10 @@
|
|
|
6
6
|
* @param {string} name The preference name.
|
|
7
7
|
*/
|
|
8
8
|
export function toggle(scope, name) {
|
|
9
|
-
return function (
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
} = _ref;
|
|
9
|
+
return function ({
|
|
10
|
+
select,
|
|
11
|
+
dispatch
|
|
12
|
+
}) {
|
|
14
13
|
const currentValue = select.get(scope, name);
|
|
15
14
|
dispatch.set(scope, name, !currentValue);
|
|
16
15
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/preferences/src/store/actions.js"],"names":["toggle","scope","name","select","dispatch","currentValue","get","set","value","type","setDefaults","defaults","setPersistenceLayer","persistenceLayer","persistedData"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASA,MAAT,CAAiBC,KAAjB,EAAwBC,IAAxB,EAA+B;AACrC,SAAO,
|
|
1
|
+
{"version":3,"sources":["@wordpress/preferences/src/store/actions.js"],"names":["toggle","scope","name","select","dispatch","currentValue","get","set","value","type","setDefaults","defaults","setPersistenceLayer","persistenceLayer","persistedData"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASA,MAAT,CAAiBC,KAAjB,EAAwBC,IAAxB,EAA+B;AACrC,SAAO,UAAW;AAAEC,IAAAA,MAAF;AAAUC,IAAAA;AAAV,GAAX,EAAkC;AACxC,UAAMC,YAAY,GAAGF,MAAM,CAACG,GAAP,CAAYL,KAAZ,EAAmBC,IAAnB,CAArB;AACAE,IAAAA,QAAQ,CAACG,GAAT,CAAcN,KAAd,EAAqBC,IAArB,EAA2B,CAAEG,YAA7B;AACA,GAHD;AAIA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASE,GAAT,CAAcN,KAAd,EAAqBC,IAArB,EAA2BM,KAA3B,EAAmC;AACzC,SAAO;AACNC,IAAAA,IAAI,EAAE,sBADA;AAENR,IAAAA,KAFM;AAGNC,IAAAA,IAHM;AAINM,IAAAA;AAJM,GAAP;AAMA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASE,WAAT,CAAsBT,KAAtB,EAA6BU,QAA7B,EAAwC;AAC9C,SAAO;AACNF,IAAAA,IAAI,EAAE,yBADA;AAENR,IAAAA,KAFM;AAGNU,IAAAA;AAHM,GAAP;AAKA;AAED;;AACA;;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,eAAeC,mBAAf,CAAoCC,gBAApC,EAAuD;AAC7D,QAAMC,aAAa,GAAG,MAAMD,gBAAgB,CAACP,GAAjB,EAA5B;AACA,SAAO;AACNG,IAAAA,IAAI,EAAE,uBADA;AAENI,IAAAA,gBAFM;AAGNC,IAAAA;AAHM,GAAP;AAKA","sourcesContent":["/**\n * Returns an action object used in signalling that a preference should be\n * toggled.\n *\n * @param {string} scope The preference scope (e.g. core/edit-post).\n * @param {string} name The preference name.\n */\nexport function toggle( scope, name ) {\n\treturn function ( { select, dispatch } ) {\n\t\tconst currentValue = select.get( scope, name );\n\t\tdispatch.set( scope, name, ! currentValue );\n\t};\n}\n\n/**\n * Returns an action object used in signalling that a preference should be set\n * to a value\n *\n * @param {string} scope The preference scope (e.g. core/edit-post).\n * @param {string} name The preference name.\n * @param {*} value The value to set.\n *\n * @return {Object} Action object.\n */\nexport function set( scope, name, value ) {\n\treturn {\n\t\ttype: 'SET_PREFERENCE_VALUE',\n\t\tscope,\n\t\tname,\n\t\tvalue,\n\t};\n}\n\n/**\n * Returns an action object used in signalling that preference defaults should\n * be set.\n *\n * @param {string} scope The preference scope (e.g. core/edit-post).\n * @param {Object<string, *>} defaults A key/value map of preference names to values.\n *\n * @return {Object} Action object.\n */\nexport function setDefaults( scope, defaults ) {\n\treturn {\n\t\ttype: 'SET_PREFERENCE_DEFAULTS',\n\t\tscope,\n\t\tdefaults,\n\t};\n}\n\n/** @typedef {() => Promise<Object>} WPPreferencesPersistenceLayerGet */\n/** @typedef {(Object) => void} WPPreferencesPersistenceLayerSet */\n/**\n * @typedef WPPreferencesPersistenceLayer\n *\n * @property {WPPreferencesPersistenceLayerGet} get An async function that gets data from the persistence layer.\n * @property {WPPreferencesPersistenceLayerSet} set A function that sets data in the persistence layer.\n */\n\n/**\n * Sets the persistence layer.\n *\n * When a persistence layer is set, the preferences store will:\n * - call `get` immediately and update the store state to the value returned.\n * - call `set` with all preferences whenever a preference changes value.\n *\n * `setPersistenceLayer` should ideally be dispatched at the start of an\n * application's lifecycle, before any other actions have been dispatched to\n * the preferences store.\n *\n * @param {WPPreferencesPersistenceLayer} persistenceLayer The persistence layer.\n *\n * @return {Object} Action object.\n */\nexport async function setPersistenceLayer( persistenceLayer ) {\n\tconst persistedData = await persistenceLayer.get();\n\treturn {\n\t\ttype: 'SET_PERSISTENCE_LAYER',\n\t\tpersistenceLayer,\n\t\tpersistedData,\n\t};\n}\n"]}
|
|
@@ -14,10 +14,7 @@ import { combineReducers } from '@wordpress/data';
|
|
|
14
14
|
* @return {Object} Updated state.
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
|
-
export function defaults() {
|
|
18
|
-
let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
19
|
-
let action = arguments.length > 1 ? arguments[1] : undefined;
|
|
20
|
-
|
|
17
|
+
export function defaults(state = {}, action) {
|
|
21
18
|
if (action.type === 'SET_PREFERENCE_DEFAULTS') {
|
|
22
19
|
const {
|
|
23
20
|
scope,
|
|
@@ -60,9 +57,7 @@ function withPersistenceLayer(reducer) {
|
|
|
60
57
|
const nextState = reducer(state, action);
|
|
61
58
|
|
|
62
59
|
if (action.type === 'SET_PREFERENCE_VALUE') {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
(_persistenceLayer = persistenceLayer) === null || _persistenceLayer === void 0 ? void 0 : _persistenceLayer.set(nextState);
|
|
60
|
+
persistenceLayer?.set(nextState);
|
|
66
61
|
}
|
|
67
62
|
|
|
68
63
|
return nextState;
|
|
@@ -78,10 +73,7 @@ function withPersistenceLayer(reducer) {
|
|
|
78
73
|
*/
|
|
79
74
|
|
|
80
75
|
|
|
81
|
-
export const preferences = withPersistenceLayer(
|
|
82
|
-
let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
83
|
-
let action = arguments.length > 1 ? arguments[1] : undefined;
|
|
84
|
-
|
|
76
|
+
export const preferences = withPersistenceLayer((state = {}, action) => {
|
|
85
77
|
if (action.type === 'SET_PREFERENCE_VALUE') {
|
|
86
78
|
const {
|
|
87
79
|
scope,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/preferences/src/store/reducer.js"],"names":["combineReducers","defaults","state","action","type","scope","values","withPersistenceLayer","reducer","persistenceLayer","persistence","persistedData","nextState","set","preferences","name","value"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,eAAT,QAAgC,iBAAhC;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,QAAT,
|
|
1
|
+
{"version":3,"sources":["@wordpress/preferences/src/store/reducer.js"],"names":["combineReducers","defaults","state","action","type","scope","values","withPersistenceLayer","reducer","persistenceLayer","persistence","persistedData","nextState","set","preferences","name","value"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,eAAT,QAAgC,iBAAhC;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,QAAT,CAAmBC,KAAK,GAAG,EAA3B,EAA+BC,MAA/B,EAAwC;AAC9C,MAAKA,MAAM,CAACC,IAAP,KAAgB,yBAArB,EAAiD;AAChD,UAAM;AAAEC,MAAAA,KAAF;AAASJ,MAAAA,QAAQ,EAAEK;AAAnB,QAA8BH,MAApC;AACA,WAAO,EACN,GAAGD,KADG;AAEN,OAAEG,KAAF,GAAW,EACV,GAAGH,KAAK,CAAEG,KAAF,CADE;AAEV,WAAGC;AAFO;AAFL,KAAP;AAOA;;AAED,SAAOJ,KAAP;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,SAASK,oBAAT,CAA+BC,OAA/B,EAAyC;AACxC,MAAIC,gBAAJ;AAEA,SAAO,CAAEP,KAAF,EAASC,MAAT,KAAqB;AAC3B;AACA;AACA,QAAKA,MAAM,CAACC,IAAP,KAAgB,uBAArB,EAA+C;AAC9C,YAAM;AAAEK,QAAAA,gBAAgB,EAAEC,WAApB;AAAiCC,QAAAA;AAAjC,UAAmDR,MAAzD;AACAM,MAAAA,gBAAgB,GAAGC,WAAnB;AACA,aAAOC,aAAP;AACA;;AAED,UAAMC,SAAS,GAAGJ,OAAO,CAAEN,KAAF,EAASC,MAAT,CAAzB;;AACA,QAAKA,MAAM,CAACC,IAAP,KAAgB,sBAArB,EAA8C;AAC7CK,MAAAA,gBAAgB,EAAEI,GAAlB,CAAuBD,SAAvB;AACA;;AAED,WAAOA,SAAP;AACA,GAfD;AAgBA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,OAAO,MAAME,WAAW,GAAGP,oBAAoB,CAAE,CAAEL,KAAK,GAAG,EAAV,EAAcC,MAAd,KAA0B;AAC1E,MAAKA,MAAM,CAACC,IAAP,KAAgB,sBAArB,EAA8C;AAC7C,UAAM;AAAEC,MAAAA,KAAF;AAASU,MAAAA,IAAT;AAAeC,MAAAA;AAAf,QAAyBb,MAA/B;AACA,WAAO,EACN,GAAGD,KADG;AAEN,OAAEG,KAAF,GAAW,EACV,GAAGH,KAAK,CAAEG,KAAF,CADE;AAEV,SAAEU,IAAF,GAAUC;AAFA;AAFL,KAAP;AAOA;;AAED,SAAOd,KAAP;AACA,CAb8C,CAAxC;AAeP,eAAeF,eAAe,CAAE;AAC/BC,EAAAA,QAD+B;AAE/Ba,EAAAA;AAF+B,CAAF,CAA9B","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { combineReducers } from '@wordpress/data';\n\n/**\n * Reducer returning the defaults for user preferences.\n *\n * This is kept intentionally separate from the preferences\n * themselves so that defaults are not persisted.\n *\n * @param {Object} state Current state.\n * @param {Object} action Dispatched action.\n *\n * @return {Object} Updated state.\n */\nexport function defaults( state = {}, action ) {\n\tif ( action.type === 'SET_PREFERENCE_DEFAULTS' ) {\n\t\tconst { scope, defaults: values } = action;\n\t\treturn {\n\t\t\t...state,\n\t\t\t[ scope ]: {\n\t\t\t\t...state[ scope ],\n\t\t\t\t...values,\n\t\t\t},\n\t\t};\n\t}\n\n\treturn state;\n}\n\n/**\n * Higher order reducer that does the following:\n * - Merges any data from the persistence layer into the state when the\n * `SET_PERSISTENCE_LAYER` action is received.\n * - Passes any preferences changes to the persistence layer.\n *\n * @param {Function} reducer The preferences reducer.\n *\n * @return {Function} The enhanced reducer.\n */\nfunction withPersistenceLayer( reducer ) {\n\tlet persistenceLayer;\n\n\treturn ( state, action ) => {\n\t\t// Setup the persistence layer, and return the persisted data\n\t\t// as the state.\n\t\tif ( action.type === 'SET_PERSISTENCE_LAYER' ) {\n\t\t\tconst { persistenceLayer: persistence, persistedData } = action;\n\t\t\tpersistenceLayer = persistence;\n\t\t\treturn persistedData;\n\t\t}\n\n\t\tconst nextState = reducer( state, action );\n\t\tif ( action.type === 'SET_PREFERENCE_VALUE' ) {\n\t\t\tpersistenceLayer?.set( nextState );\n\t\t}\n\n\t\treturn nextState;\n\t};\n}\n\n/**\n * Reducer returning the user preferences.\n *\n * @param {Object} state Current state.\n * @param {Object} action Dispatched action.\n *\n * @return {Object} Updated state.\n */\nexport const preferences = withPersistenceLayer( ( state = {}, action ) => {\n\tif ( action.type === 'SET_PREFERENCE_VALUE' ) {\n\t\tconst { scope, name, value } = action;\n\t\treturn {\n\t\t\t...state,\n\t\t\t[ scope ]: {\n\t\t\t\t...state[ scope ],\n\t\t\t\t[ name ]: value,\n\t\t\t},\n\t\t};\n\t}\n\n\treturn state;\n} );\n\nexport default combineReducers( {\n\tdefaults,\n\tpreferences,\n} );\n"]}
|
|
@@ -9,9 +9,7 @@
|
|
|
9
9
|
* @return {*} Is the feature enabled?
|
|
10
10
|
*/
|
|
11
11
|
export function get(state, scope, name) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const value = (_state$preferences$sc = state.preferences[scope]) === null || _state$preferences$sc === void 0 ? void 0 : _state$preferences$sc[name];
|
|
15
|
-
return value !== undefined ? value : (_state$defaults$scope = state.defaults[scope]) === null || _state$defaults$scope === void 0 ? void 0 : _state$defaults$scope[name];
|
|
12
|
+
const value = state.preferences[scope]?.[name];
|
|
13
|
+
return value !== undefined ? value : state.defaults[scope]?.[name];
|
|
16
14
|
}
|
|
17
15
|
//# sourceMappingURL=selectors.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/preferences/src/store/selectors.js"],"names":["get","state","scope","name","value","preferences","undefined","defaults"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASA,GAAT,CAAcC,KAAd,EAAqBC,KAArB,EAA4BC,IAA5B,EAAmC;
|
|
1
|
+
{"version":3,"sources":["@wordpress/preferences/src/store/selectors.js"],"names":["get","state","scope","name","value","preferences","undefined","defaults"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASA,GAAT,CAAcC,KAAd,EAAqBC,KAArB,EAA4BC,IAA5B,EAAmC;AACzC,QAAMC,KAAK,GAAGH,KAAK,CAACI,WAAN,CAAmBH,KAAnB,IAA8BC,IAA9B,CAAd;AACA,SAAOC,KAAK,KAAKE,SAAV,GAAsBF,KAAtB,GAA8BH,KAAK,CAACM,QAAN,CAAgBL,KAAhB,IAA2BC,IAA3B,CAArC;AACA","sourcesContent":["/**\n * Returns a boolean indicating whether a prefer 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} name The name of the feature.\n *\n * @return {*} Is the feature enabled?\n */\nexport function get( state, scope, name ) {\n\tconst value = state.preferences[ scope ]?.[ name ];\n\treturn value !== undefined ? value : state.defaults[ scope ]?.[ name ];\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/preferences",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.12.0",
|
|
4
4
|
"description": "Utilities for managing WordPress preferences.",
|
|
5
5
|
"author": "The WordPress Contributors",
|
|
6
6
|
"license": "GPL-2.0-or-later",
|
|
@@ -29,11 +29,11 @@
|
|
|
29
29
|
"sideEffects": false,
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"@babel/runtime": "^7.16.0",
|
|
32
|
-
"@wordpress/a11y": "^3.
|
|
33
|
-
"@wordpress/components": "^
|
|
34
|
-
"@wordpress/data": "^9.
|
|
35
|
-
"@wordpress/i18n": "^4.
|
|
36
|
-
"@wordpress/icons": "^9.
|
|
32
|
+
"@wordpress/a11y": "^3.35.0",
|
|
33
|
+
"@wordpress/components": "^25.1.0",
|
|
34
|
+
"@wordpress/data": "^9.5.0",
|
|
35
|
+
"@wordpress/i18n": "^4.35.0",
|
|
36
|
+
"@wordpress/icons": "^9.26.0",
|
|
37
37
|
"classnames": "^2.3.1"
|
|
38
38
|
},
|
|
39
39
|
"peerDependencies": {
|
|
@@ -43,5 +43,5 @@
|
|
|
43
43
|
"publishConfig": {
|
|
44
44
|
"access": "public"
|
|
45
45
|
},
|
|
46
|
-
"gitHead": "
|
|
46
|
+
"gitHead": "a92f606309b1541b834ff9b0a76ed2a466fc45ed"
|
|
47
47
|
}
|
|
@@ -25,7 +25,7 @@ export default function PreferenceToggleMenuItem( {
|
|
|
25
25
|
} ) {
|
|
26
26
|
const isActive = useSelect(
|
|
27
27
|
( select ) => !! select( preferencesStore ).get( scope, name ),
|
|
28
|
-
[ name ]
|
|
28
|
+
[ scope, name ]
|
|
29
29
|
);
|
|
30
30
|
const { toggle } = useDispatch( preferencesStore );
|
|
31
31
|
const speakMessage = () => {
|