1/******/ (() => { // webpackBootstrap 2/******/ "use strict"; 3/******/ // The require scope 4/******/ var __webpack_require__ = {}; 5/******/ 6/************************************************************************/ 7/******/ /* webpack/runtime/define property getters */ 8/******/ (() => { 9/******/ // define getter functions for harmony exports 10/******/ __webpack_require__.d = (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/******/ (() => { 21/******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop)) 22/******/ })(); 23/******/ 24/******/ /* webpack/runtime/make namespace object */ 25/******/ (() => { 26/******/ // define __esModule on exports 27/******/ __webpack_require__.r = (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/************************************************************************/ 36var __webpack_exports__ = {}; 37// ESM COMPAT FLAG 38__webpack_require__.r(__webpack_exports__); 39 40// EXPORTS 41__webpack_require__.d(__webpack_exports__, { 42 "PreferenceToggleMenuItem": () => (/* reexport */ PreferenceToggleMenuItem), 43 "store": () => (/* reexport */ store) 44}); 45 46// NAMESPACE OBJECT: ./packages/preferences/build-module/store/actions.js 47var actions_namespaceObject = {}; 48__webpack_require__.r(actions_namespaceObject); 49__webpack_require__.d(actions_namespaceObject, { 50 "set": () => (set), 51 "setDefaults": () => (setDefaults), 52 "setPersistenceLayer": () => (setPersistenceLayer), 53 "toggle": () => (toggle) 54}); 55 56// NAMESPACE OBJECT: ./packages/preferences/build-module/store/selectors.js 57var selectors_namespaceObject = {}; 58__webpack_require__.r(selectors_namespaceObject); 59__webpack_require__.d(selectors_namespaceObject, { 60 "get": () => (get) 61}); 62 63;// CONCATENATED MODULE: external ["wp","element"] 64const external_wp_element_namespaceObject = window["wp"]["element"]; 65;// CONCATENATED MODULE: external ["wp","data"] 66const external_wp_data_namespaceObject = window["wp"]["data"]; 67;// CONCATENATED MODULE: external ["wp","components"] 68const external_wp_components_namespaceObject = window["wp"]["components"]; 69;// CONCATENATED MODULE: external ["wp","i18n"] 70const external_wp_i18n_namespaceObject = window["wp"]["i18n"]; 71;// CONCATENATED MODULE: external ["wp","primitives"] 72const external_wp_primitives_namespaceObject = window["wp"]["primitives"]; 73;// CONCATENATED MODULE: ./packages/icons/build-module/library/check.js 74 75/** 76 * WordPress dependencies 77 */ 78 79const 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 */ const library_check = (check); 86 87;// CONCATENATED MODULE: external ["wp","a11y"] 88const external_wp_a11y_namespaceObject = window["wp"]["a11y"]; 89;// CONCATENATED MODULE: ./packages/preferences/build-module/store/reducer.js 90/** 91 * WordPress dependencies 92 */ 93 94 95/** 96 * Reducer returning the defaults for user preferences. 97 * 98 * This is kept intentionally separate from the preferences 99 * themselves so that defaults are not persisted. 100 * 101 * @param {Object} state Current state. 102 * @param {Object} action Dispatched action. 103 * 104 * @return {Object} Updated state. 105 */ 106function defaults(state = {}, action) { 107 if (action.type === 'SET_PREFERENCE_DEFAULTS') { 108 const { 109 scope, 110 defaults: values 111 } = action; 112 return { 113 ...state, 114 [scope]: { 115 ...state[scope], 116 ...values 117 } 118 }; 119 } 120 return state; 121} 122 123/** 124 * Higher order reducer that does the following: 125 * - Merges any data from the persistence layer into the state when the 126 * `SET_PERSISTENCE_LAYER` action is received. 127 * - Passes any preferences changes to the persistence layer. 128 * 129 * @param {Function} reducer The preferences reducer. 130 * 131 * @return {Function} The enhanced reducer. 132 */ 133function withPersistenceLayer(reducer) { 134 let persistenceLayer; 135 return (state, action) => { 136 // Setup the persistence layer, and return the persisted data 137 // as the state. 138 if (action.type === 'SET_PERSISTENCE_LAYER') { 139 const { 140 persistenceLayer: persistence, 141 persistedData 142 } = action; 143 persistenceLayer = persistence; 144 return persistedData; 145 } 146 const nextState = reducer(state, action); 147 if (action.type === 'SET_PREFERENCE_VALUE') { 148 persistenceLayer?.set(nextState); 149 } 150 return nextState; 151 }; 152} 153 154/** 155 * Reducer returning the user preferences. 156 * 157 * @param {Object} state Current state. 158 * @param {Object}
158 action Dispatched action. 159 * 160 * @return {Object} Updated state. 161 */ 162const preferences = withPersistenceLayer((state = {}, action) => { 163 if (action.type === 'SET_PREFERENCE_VALUE') { 164 const { 165 scope, 166 name, 167 value 168 } = action; 169 return { 170 ...state, 171 [scope]: { 172 ...state[scope], 173 [name]: value 174 } 175 }; 176 } 177 return state; 178}); 179/* harmony default export */ const reducer = ((0,external_wp_data_namespaceObject.combineReducers)({ 180 defaults, 181 preferences 182})); 183 184;// CONCATENATED MODULE: ./packages/preferences/build-module/store/actions.js 185/** 186 * Returns an action object used in signalling that a preference should be 187 * toggled. 188 * 189 * @param {string} scope The preference scope (e.g. core/edit-post). 190 * @param {string} name The preference name. 191 */ 192function toggle(scope, name) { 193 return function ({ 194 select, 195 dispatch 196 }) { 197 const currentValue = select.get(scope, name); 198 dispatch.set(scope, name, !currentValue); 199 }; 200} 201 202/** 203 * Returns an action object used in signalling that a preference should be set 204 * to a value 205 * 206 * @param {string} scope The preference scope (e.g. core/edit-post). 207 * @param {string} name The preference name. 208 * @param {*} value The value to set. 209 * 210 * @return {Object} Action object. 211 */ 212function set(scope, name, value) { 213 return { 214 type: 'SET_PREFERENCE_VALUE', 215 scope, 216 name, 217 value 218 }; 219} 220 221/** 222 * Returns an action object used in signalling that preference defaults should 223 * be set. 224 * 225 * @param {string} scope The preference scope (e.g. core/edit-post). 226 * @param {Object<string, *>} defaults A key/value map of preference names to values. 227 * 228 * @return {Object} Action object. 229 */ 230function setDefaults(scope, defaults) { 231 return { 232 type: 'SET_PREFERENCE_DEFAULTS', 233 scope, 234 defaults 235 }; 236} 237 238/** @typedef {() => Promise<Object>} WPPreferencesPersistenceLayerGet */ 239/** @typedef {(Object) => void} WPPreferencesPersistenceLayerSet */ 240/** 241 * @typedef WPPreferencesPersistenceLayer 242 * 243 * @property {WPPreferencesPersistenceLayerGet} get An async function that gets data from the persistence layer. 244 * @property {WPPreferencesPersistenceLayerSet} set A function that sets data in the persistence layer. 245 */ 246 247/** 248 * Sets the persistence layer. 249 * 250 * When a persistence layer is set, the preferences store will: 251 * - call `get` immediately and update the store state to the value returned. 252 * - call `set` with all preferences whenever a preference changes value. 253 * 254 * `setPersistenceLayer` should ideally be dispatched at the start of an 255 * application's lifecycle, before any other actions have been dispatched to 256 * the preferences store. 257 * 258 * @param {WPPreferencesPersistenceLayer} persistenceLayer The persistence layer. 259 * 260 * @return {Object} Action object. 261 */ 262async function setPersistenceLayer(persistenceLayer) { 263 const persistedData = await persistenceLayer.get(); 264 return { 265 type: 'SET_PERSISTENCE_LAYER', 266 persistenceLayer, 267 persistedData 268 }; 269} 270 271;// CONCATENATED MODULE: ./packages/preferences/build-module/store/selectors.js 272/** 273 * Returns a boolean indicating whether a prefer is active for a particular 274 * scope. 275 * 276 * @param {Object} state The store state. 277 * @param {string} scope The scope of the feature (e.g. core/edit-post). 278 * @param {string} name The name of the feature. 279 * 280 * @return {*} Is the feature enabled? 281 */ 282function get(state, scope, name) { 283 const value = state.preferences[scope]?.[name]; 284 return value !== undefined ? value : state.defaults[scope]?.[name]; 285} 286 287;// CONCATENATED MODULE: ./packages/preferences/build-module/store/constants.js 288/** 289 * The identifier for the data store. 290 * 291 * @type {string} 292 */ 293const STORE_NAME = 'core/preferences'; 294 295;// CONCATENATED MODULE: ./packages/preferences/build-module/store/index.js 296/** 297 * WordPress dependencies 298 */ 299 300 301/** 302 * Internal dependencies 303 */ 304 305 306 307 308 309/** 310 * Store definition for the interface namespace. 311 * 312 * @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/data/README.md#createReduxStore 313 * 314 * @type {Object} 315 */ 316const store = (0,external_wp_data_namespaceObject.createReduxStore)(STORE_NAME, { 317 reducer: reducer, 318 actions: actions_namespaceObject, 319 selectors: selectors_namespaceObject 320}); 321(0,external_wp_data_namespaceObject.register)(store); 322 323;// CONCATENATED MODULE: ./packages/preferences/build-module/components/preference-toggle-menu-item/index.js 324 325/** 326 * WordPress dependencies 327 */ 328 329 330 331 332 333 334/** 335 * Internal dependencies 336 */ 337 338function PreferenceToggleMenuItem({ 339 scope, 340 name, 341 label, 342 info, 343 messageActivated, 344 messageDeactivated, 345 shortcut, 346 onToggle = () => null, 347 disabled = false 348}) { 349 const isActive = (0,external_wp_data_namespaceObject.useSelect)(select => !!select(store).get(scope, name), [scope, name]); 350 const { 351 toggle 352 } = (0,external_wp_data_namespaceObject.useDispatch)(store); 353 const speakMessage = () => { 354 if (isActive) { 355 const message = messageDeactivated || (0,external_wp_i18n_namespaceObject.sprintf)( /* translators: %s: preference name, e.g. 'Fullscreen mode' */ 356 (0,external_wp_i18n_namespaceObject.__)('Preference deactivated - %s'), label); 357 (0,external_wp_a11y_namespaceObject.speak)(message); 358 } else { 359 const message = messageActivated || (0,external_wp_i18n_namespaceObject.sprintf)( /* translators: %s: preference name, e.g. 'Fullscreen mode' */ 360 (0,external_wp_i18n_namespaceObject.__)('Preference activated - %s'), label); 361 (0,external_wp_a11y_namespaceObject.speak)(message); 362 } 363 }; 364 return (0,external_wp_element_namespaceObject.createElement)(external_wp_components_namespaceObject.MenuItem, { 365 icon: isActive && library_check, 366 isSelected: isActive, 367 onClick: () => {
368 onToggle(); 369 toggle(scope, name); 370 speakMessage(); 371 }, 372 role: "menuitemcheckbox", 373 info: info, 374 shortcut: shortcut, 375 disabled: disabled 376 }, label); 377} 378 379;// CONCATENATED MODULE: ./packages/preferences/build-module/components/index.js 380 381 382;// CONCATENATED MODULE: ./packages/preferences/build-module/index.js 383 384 385 386(window.wp = window.wp || {}).preferences = __webpack_exports__; 387/******/ })() 388;
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.