wp/wp-includes/js/dist/preferences.js
changeset 19 3d72ae0968f4
child 21 48c4eec2b7e6
equal deleted inserted replaced
18:be944660c56a 19:3d72ae0968f4
       
     1 /******/ (function() { // webpackBootstrap
       
     2 /******/ 	"use strict";
       
     3 /******/ 	// The require scope
       
     4 /******/ 	var __webpack_require__ = {};
       
     5 /******/ 	
       
     6 /************************************************************************/
       
     7 /******/ 	/* webpack/runtime/define property getters */
       
     8 /******/ 	!function() {
       
     9 /******/ 		// define getter functions for harmony exports
       
    10 /******/ 		__webpack_require__.d = function(exports, definition) {
       
    11 /******/ 			for(var key in definition) {
       
    12 /******/ 				if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
       
    13 /******/ 					Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
       
    14 /******/ 				}
       
    15 /******/ 			}
       
    16 /******/ 		};
       
    17 /******/ 	}();
       
    18 /******/ 	
       
    19 /******/ 	/* webpack/runtime/hasOwnProperty shorthand */
       
    20 /******/ 	!function() {
       
    21 /******/ 		__webpack_require__.o = function(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); }
       
    22 /******/ 	}();
       
    23 /******/ 	
       
    24 /******/ 	/* webpack/runtime/make namespace object */
       
    25 /******/ 	!function() {
       
    26 /******/ 		// define __esModule on exports
       
    27 /******/ 		__webpack_require__.r = function(exports) {
       
    28 /******/ 			if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
       
    29 /******/ 				Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
       
    30 /******/ 			}
       
    31 /******/ 			Object.defineProperty(exports, '__esModule', { value: true });
       
    32 /******/ 		};
       
    33 /******/ 	}();
       
    34 /******/ 	
       
    35 /************************************************************************/
       
    36 var __webpack_exports__ = {};
       
    37 // ESM COMPAT FLAG
       
    38 __webpack_require__.r(__webpack_exports__);
       
    39 
       
    40 // EXPORTS
       
    41 __webpack_require__.d(__webpack_exports__, {
       
    42   "PreferenceToggleMenuItem": function() { return /* reexport */ PreferenceToggleMenuItem; },
       
    43   "store": function() { return /* reexport */ store; }
       
    44 });
       
    45 
       
    46 // NAMESPACE OBJECT: ./node_modules/@wordpress/preferences/build-module/store/actions.js
       
    47 var actions_namespaceObject = {};
       
    48 __webpack_require__.r(actions_namespaceObject);
       
    49 __webpack_require__.d(actions_namespaceObject, {
       
    50   "set": function() { return set; },
       
    51   "setDefaults": function() { return setDefaults; },
       
    52   "toggle": function() { return toggle; }
       
    53 });
       
    54 
       
    55 // NAMESPACE OBJECT: ./node_modules/@wordpress/preferences/build-module/store/selectors.js
       
    56 var selectors_namespaceObject = {};
       
    57 __webpack_require__.r(selectors_namespaceObject);
       
    58 __webpack_require__.d(selectors_namespaceObject, {
       
    59   "get": function() { return get; }
       
    60 });
       
    61 
       
    62 ;// CONCATENATED MODULE: external ["wp","element"]
       
    63 var external_wp_element_namespaceObject = window["wp"]["element"];
       
    64 ;// CONCATENATED MODULE: external ["wp","data"]
       
    65 var external_wp_data_namespaceObject = window["wp"]["data"];
       
    66 ;// CONCATENATED MODULE: external ["wp","components"]
       
    67 var external_wp_components_namespaceObject = window["wp"]["components"];
       
    68 ;// CONCATENATED MODULE: external ["wp","i18n"]
       
    69 var external_wp_i18n_namespaceObject = window["wp"]["i18n"];
       
    70 ;// CONCATENATED MODULE: external ["wp","primitives"]
       
    71 var external_wp_primitives_namespaceObject = window["wp"]["primitives"];
       
    72 ;// CONCATENATED MODULE: ./node_modules/@wordpress/icons/build-module/library/check.js
       
    73 
       
    74 
       
    75 /**
       
    76  * WordPress dependencies
       
    77  */
       
    78 
       
    79 const check = (0,external_wp_element_namespaceObject.createElement)(external_wp_primitives_namespaceObject.SVG, {
       
    80   xmlns: "http://www.w3.org/2000/svg",
       
    81   viewBox: "0 0 24 24"
       
    82 }, (0,external_wp_element_namespaceObject.createElement)(external_wp_primitives_namespaceObject.Path, {
       
    83   d: "M16.7 7.1l-6.3 8.5-3.3-2.5-.9 1.2 4.5 3.4L17.9 8z"
       
    84 }));
       
    85 /* harmony default export */ var library_check = (check);
       
    86 
       
    87 ;// CONCATENATED MODULE: external ["wp","a11y"]
       
    88 var external_wp_a11y_namespaceObject = window["wp"]["a11y"];
       
    89 ;// CONCATENATED MODULE: ./node_modules/@wordpress/preferences/build-module/store/reducer.js
       
    90 /**
       
    91  * WordPress dependencies
       
    92  */
       
    93 
       
    94 /**
       
    95  * Reducer returning the defaults for user preferences.
       
    96  *
       
    97  * This is kept intentionally separate from the preferences
       
    98  * themselves so that defaults are not persisted.
       
    99  *
       
   100  * @param {Object} state  Current state.
       
   101  * @param {Object} action Dispatched action.
       
   102  *
       
   103  * @return {Object} Updated state.
       
   104  */
       
   105 
       
   106 function defaults() {
       
   107   let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
       
   108   let action = arguments.length > 1 ? arguments[1] : undefined;
       
   109 
       
   110   if (action.type === 'SET_PREFERENCE_DEFAULTS') {
       
   111     const {
       
   112       scope,
       
   113       defaults: values
       
   114     } = action;
       
   115     return { ...state,
       
   116       [scope]: { ...state[scope],
       
   117         ...values
       
   118       }
       
   119     };
       
   120   }
       
   121 
       
   122   return state;
       
   123 }
       
   124 /**
       
   125  * Reducer returning the user preferences.
       
   126  *
       
   127  * @param {Object} state  Current state.
       
   128  * @param {Object} action Dispatched action.
       
   129  *
       
   130  * @return {Object} Updated state.
       
   131  */
       
   132 
       
   133 function preferences() {
       
   134   let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
       
   135   let action = arguments.length > 1 ? arguments[1] : undefined;
       
   136 
       
   137   if (action.type === 'SET_PREFERENCE_VALUE') {
       
   138     const {
       
   139       scope,
       
   140       name,
       
   141       value
       
   142     } = action;
       
   143     return { ...state,
       
   144       [scope]: { ...state[scope],
       
   145         [name]: value
       
   146       }
       
   147     };
       
   148   }
       
   149 
       
   150   return state;
       
   151 }
       
   152 /* harmony default export */ var reducer = ((0,external_wp_data_namespaceObject.combineReducers)({
       
   153   defaults,
       
   154   preferences
       
   155 }));
       
   156 
       
   157 ;// CONCATENATED MODULE: ./node_modules/@wordpress/preferences/build-module/store/actions.js
       
   158 /**
       
   159  * Returns an action object used in signalling that a preference should be
       
   160  * toggled.
       
   161  *
       
   162  * @param {string} scope The preference scope (e.g. core/edit-post).
       
   163  * @param {string} name  The preference name.
       
   164  */
       
   165 function toggle(scope, name) {
       
   166   return function (_ref) {
       
   167     let {
       
   168       select,
       
   169       dispatch
       
   170     } = _ref;
       
   171     const currentValue = select.get(scope, name);
       
   172     dispatch.set(scope, name, !currentValue);
       
   173   };
       
   174 }
       
   175 /**
       
   176  * Returns an action object used in signalling that a preference should be set
       
   177  * to a value
       
   178  *
       
   179  * @param {string} scope The preference scope (e.g. core/edit-post).
       
   180  * @param {string} name  The preference name.
       
   181  * @param {*}      value The value to set.
       
   182  *
       
   183  * @return {Object} Action object.
       
   184  */
       
   185 
       
   186 function set(scope, name, value) {
       
   187   return {
       
   188     type: 'SET_PREFERENCE_VALUE',
       
   189     scope,
       
   190     name,
       
   191     value
       
   192   };
       
   193 }
       
   194 /**
       
   195  * Returns an action object used in signalling that preference defaults should
       
   196  * be set.
       
   197  *
       
   198  * @param {string}            scope    The preference scope (e.g. core/edit-post).
       
   199  * @param {Object<string, *>} defaults A key/value map of preference names to values.
       
   200  *
       
   201  * @return {Object} Action object.
       
   202  */
       
   203 
       
   204 function setDefaults(scope, defaults) {
       
   205   return {
       
   206     type: 'SET_PREFERENCE_DEFAULTS',
       
   207     scope,
       
   208     defaults
       
   209   };
       
   210 }
       
   211 
       
   212 ;// CONCATENATED MODULE: ./node_modules/@wordpress/preferences/build-module/store/selectors.js
       
   213 /**
       
   214  * Returns a boolean indicating whether a prefer is active for a particular
       
   215  * scope.
       
   216  *
       
   217  * @param {Object} state The store state.
       
   218  * @param {string} scope The scope of the feature (e.g. core/edit-post).
       
   219  * @param {string} name  The name of the feature.
       
   220  *
       
   221  * @return {*} Is the feature enabled?
       
   222  */
       
   223 function get(state, scope, name) {
       
   224   var _state$preferences$sc, _state$defaults$scope;
       
   225 
       
   226   const value = (_state$preferences$sc = state.preferences[scope]) === null || _state$preferences$sc === void 0 ? void 0 : _state$preferences$sc[name];
       
   227   return value !== undefined ? value : (_state$defaults$scope = state.defaults[scope]) === null || _state$defaults$scope === void 0 ? void 0 : _state$defaults$scope[name];
       
   228 }
       
   229 
       
   230 ;// CONCATENATED MODULE: ./node_modules/@wordpress/preferences/build-module/store/constants.js
       
   231 /**
       
   232  * The identifier for the data store.
       
   233  *
       
   234  * @type {string}
       
   235  */
       
   236 const STORE_NAME = 'core/preferences';
       
   237 
       
   238 ;// CONCATENATED MODULE: ./node_modules/@wordpress/preferences/build-module/store/index.js
       
   239 /**
       
   240  * WordPress dependencies
       
   241  */
       
   242 
       
   243 /**
       
   244  * Internal dependencies
       
   245  */
       
   246 
       
   247 /**
       
   248  * Internal dependencies
       
   249  */
       
   250 
       
   251 
       
   252 
       
   253 
       
   254 
       
   255 /**
       
   256  * Store definition for the interface namespace.
       
   257  *
       
   258  * @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/data/README.md#createReduxStore
       
   259  *
       
   260  * @type {Object}
       
   261  */
       
   262 
       
   263 const store = (0,external_wp_data_namespaceObject.createReduxStore)(STORE_NAME, {
       
   264   reducer: reducer,
       
   265   actions: actions_namespaceObject,
       
   266   selectors: selectors_namespaceObject,
       
   267   persist: ['preferences']
       
   268 }); // Once we build a more generic persistence plugin that works across types of stores
       
   269 // we'd be able to replace this with a register call.
       
   270 
       
   271 (0,external_wp_data_namespaceObject.registerStore)(STORE_NAME, {
       
   272   reducer: reducer,
       
   273   actions: actions_namespaceObject,
       
   274   selectors: selectors_namespaceObject,
       
   275   persist: ['preferences']
       
   276 });
       
   277 
       
   278 ;// CONCATENATED MODULE: ./node_modules/@wordpress/preferences/build-module/components/preference-toggle-menu-item/index.js
       
   279 
       
   280 
       
   281 /**
       
   282  * WordPress dependencies
       
   283  */
       
   284 
       
   285 
       
   286 
       
   287 
       
   288 
       
   289 /**
       
   290  * Internal dependencies
       
   291  */
       
   292 
       
   293 
       
   294 function PreferenceToggleMenuItem(_ref) {
       
   295   let {
       
   296     scope,
       
   297     name,
       
   298     label,
       
   299     info,
       
   300     messageActivated,
       
   301     messageDeactivated,
       
   302     shortcut
       
   303   } = _ref;
       
   304   const isActive = (0,external_wp_data_namespaceObject.useSelect)(select => !!select(store).get(scope, name), [name]);
       
   305   const {
       
   306     toggle
       
   307   } = (0,external_wp_data_namespaceObject.useDispatch)(store);
       
   308 
       
   309   const speakMessage = () => {
       
   310     if (isActive) {
       
   311       const message = messageDeactivated || (0,external_wp_i18n_namespaceObject.sprintf)(
       
   312       /* translators: %s: preference name, e.g. 'Fullscreen mode' */
       
   313       (0,external_wp_i18n_namespaceObject.__)('Preference deactivated - %s'), label);
       
   314       (0,external_wp_a11y_namespaceObject.speak)(message);
       
   315     } else {
       
   316       const message = messageActivated || (0,external_wp_i18n_namespaceObject.sprintf)(
       
   317       /* translators: %s: preference name, e.g. 'Fullscreen mode' */
       
   318       (0,external_wp_i18n_namespaceObject.__)('Preference activated - %s'), label);
       
   319       (0,external_wp_a11y_namespaceObject.speak)(message);
       
   320     }
       
   321   };
       
   322 
       
   323   return (0,external_wp_element_namespaceObject.createElement)(external_wp_components_namespaceObject.MenuItem, {
       
   324     icon: isActive && library_check,
       
   325     isSelected: isActive,
       
   326     onClick: () => {
       
   327       toggle(scope, name);
       
   328       speakMessage();
       
   329     },
       
   330     role: "menuitemcheckbox",
       
   331     info: info,
       
   332     shortcut: shortcut
       
   333   }, label);
       
   334 }
       
   335 
       
   336 ;// CONCATENATED MODULE: ./node_modules/@wordpress/preferences/build-module/components/index.js
       
   337 
       
   338 
       
   339 ;// CONCATENATED MODULE: ./node_modules/@wordpress/preferences/build-module/index.js
       
   340 
       
   341 
       
   342 
       
   343 (window.wp = window.wp || {}).preferences = __webpack_exports__;
       
   344 /******/ })()
       
   345 ;