preferences.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  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. // EXPORTS
  40. __webpack_require__.d(__webpack_exports__, {
  41. "PreferenceToggleMenuItem": function() { return /* reexport */ PreferenceToggleMenuItem; },
  42. "store": function() { return /* reexport */ store; }
  43. });
  44. // NAMESPACE OBJECT: ./node_modules/@wordpress/preferences/build-module/store/actions.js
  45. var actions_namespaceObject = {};
  46. __webpack_require__.r(actions_namespaceObject);
  47. __webpack_require__.d(actions_namespaceObject, {
  48. "set": function() { return set; },
  49. "setDefaults": function() { return setDefaults; },
  50. "toggle": function() { return toggle; }
  51. });
  52. // NAMESPACE OBJECT: ./node_modules/@wordpress/preferences/build-module/store/selectors.js
  53. var selectors_namespaceObject = {};
  54. __webpack_require__.r(selectors_namespaceObject);
  55. __webpack_require__.d(selectors_namespaceObject, {
  56. "get": function() { return get; }
  57. });
  58. ;// CONCATENATED MODULE: external ["wp","element"]
  59. var external_wp_element_namespaceObject = window["wp"]["element"];
  60. ;// CONCATENATED MODULE: external ["wp","data"]
  61. var external_wp_data_namespaceObject = window["wp"]["data"];
  62. ;// CONCATENATED MODULE: external ["wp","components"]
  63. var external_wp_components_namespaceObject = window["wp"]["components"];
  64. ;// CONCATENATED MODULE: external ["wp","i18n"]
  65. var external_wp_i18n_namespaceObject = window["wp"]["i18n"];
  66. ;// CONCATENATED MODULE: external ["wp","primitives"]
  67. var external_wp_primitives_namespaceObject = window["wp"]["primitives"];
  68. ;// CONCATENATED MODULE: ./node_modules/@wordpress/icons/build-module/library/check.js
  69. /**
  70. * WordPress dependencies
  71. */
  72. const check = (0,external_wp_element_namespaceObject.createElement)(external_wp_primitives_namespaceObject.SVG, {
  73. xmlns: "http://www.w3.org/2000/svg",
  74. viewBox: "0 0 24 24"
  75. }, (0,external_wp_element_namespaceObject.createElement)(external_wp_primitives_namespaceObject.Path, {
  76. d: "M16.7 7.1l-6.3 8.5-3.3-2.5-.9 1.2 4.5 3.4L17.9 8z"
  77. }));
  78. /* harmony default export */ var library_check = (check);
  79. ;// CONCATENATED MODULE: external ["wp","a11y"]
  80. var external_wp_a11y_namespaceObject = window["wp"]["a11y"];
  81. ;// CONCATENATED MODULE: ./node_modules/@wordpress/preferences/build-module/store/reducer.js
  82. /**
  83. * WordPress dependencies
  84. */
  85. /**
  86. * Reducer returning the defaults for user preferences.
  87. *
  88. * This is kept intentionally separate from the preferences
  89. * themselves so that defaults are not persisted.
  90. *
  91. * @param {Object} state Current state.
  92. * @param {Object} action Dispatched action.
  93. *
  94. * @return {Object} Updated state.
  95. */
  96. function defaults() {
  97. let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  98. let action = arguments.length > 1 ? arguments[1] : undefined;
  99. if (action.type === 'SET_PREFERENCE_DEFAULTS') {
  100. const {
  101. scope,
  102. defaults: values
  103. } = action;
  104. return { ...state,
  105. [scope]: { ...state[scope],
  106. ...values
  107. }
  108. };
  109. }
  110. return state;
  111. }
  112. /**
  113. * Reducer returning the user preferences.
  114. *
  115. * @param {Object} state Current state.
  116. * @param {Object} action Dispatched action.
  117. *
  118. * @return {Object} Updated state.
  119. */
  120. function preferences() {
  121. let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  122. let action = arguments.length > 1 ? arguments[1] : undefined;
  123. if (action.type === 'SET_PREFERENCE_VALUE') {
  124. const {
  125. scope,
  126. name,
  127. value
  128. } = action;
  129. return { ...state,
  130. [scope]: { ...state[scope],
  131. [name]: value
  132. }
  133. };
  134. }
  135. return state;
  136. }
  137. /* harmony default export */ var reducer = ((0,external_wp_data_namespaceObject.combineReducers)({
  138. defaults,
  139. preferences
  140. }));
  141. ;// CONCATENATED MODULE: ./node_modules/@wordpress/preferences/build-module/store/actions.js
  142. /**
  143. * Returns an action object used in signalling that a preference should be
  144. * toggled.
  145. *
  146. * @param {string} scope The preference scope (e.g. core/edit-post).
  147. * @param {string} name The preference name.
  148. */
  149. function toggle(scope, name) {
  150. return function (_ref) {
  151. let {
  152. select,
  153. dispatch
  154. } = _ref;
  155. const currentValue = select.get(scope, name);
  156. dispatch.set(scope, name, !currentValue);
  157. };
  158. }
  159. /**
  160. * Returns an action object used in signalling that a preference should be set
  161. * to a value
  162. *
  163. * @param {string} scope The preference scope (e.g. core/edit-post).
  164. * @param {string} name The preference name.
  165. * @param {*} value The value to set.
  166. *
  167. * @return {Object} Action object.
  168. */
  169. function set(scope, name, value) {
  170. return {
  171. type: 'SET_PREFERENCE_VALUE',
  172. scope,
  173. name,
  174. value
  175. };
  176. }
  177. /**
  178. * Returns an action object used in signalling that preference defaults should
  179. * be set.
  180. *
  181. * @param {string} scope The preference scope (e.g. core/edit-post).
  182. * @param {Object<string, *>} defaults A key/value map of preference names to values.
  183. *
  184. * @return {Object} Action object.
  185. */
  186. function setDefaults(scope, defaults) {
  187. return {
  188. type: 'SET_PREFERENCE_DEFAULTS',
  189. scope,
  190. defaults
  191. };
  192. }
  193. ;// CONCATENATED MODULE: ./node_modules/@wordpress/preferences/build-module/store/selectors.js
  194. /**
  195. * Returns a boolean indicating whether a prefer is active for a particular
  196. * scope.
  197. *
  198. * @param {Object} state The store state.
  199. * @param {string} scope The scope of the feature (e.g. core/edit-post).
  200. * @param {string} name The name of the feature.
  201. *
  202. * @return {*} Is the feature enabled?
  203. */
  204. function get(state, scope, name) {
  205. var _state$preferences$sc, _state$defaults$scope;
  206. const value = (_state$preferences$sc = state.preferences[scope]) === null || _state$preferences$sc === void 0 ? void 0 : _state$preferences$sc[name];
  207. return value !== undefined ? value : (_state$defaults$scope = state.defaults[scope]) === null || _state$defaults$scope === void 0 ? void 0 : _state$defaults$scope[name];
  208. }
  209. ;// CONCATENATED MODULE: ./node_modules/@wordpress/preferences/build-module/store/constants.js
  210. /**
  211. * The identifier for the data store.
  212. *
  213. * @type {string}
  214. */
  215. const STORE_NAME = 'core/preferences';
  216. ;// CONCATENATED MODULE: ./node_modules/@wordpress/preferences/build-module/store/index.js
  217. /**
  218. * WordPress dependencies
  219. */
  220. /**
  221. * Internal dependencies
  222. */
  223. /**
  224. * Internal dependencies
  225. */
  226. /**
  227. * Store definition for the interface namespace.
  228. *
  229. * @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/data/README.md#createReduxStore
  230. *
  231. * @type {Object}
  232. */
  233. const store = (0,external_wp_data_namespaceObject.createReduxStore)(STORE_NAME, {
  234. reducer: reducer,
  235. actions: actions_namespaceObject,
  236. selectors: selectors_namespaceObject,
  237. persist: ['preferences']
  238. }); // Once we build a more generic persistence plugin that works across types of stores
  239. // we'd be able to replace this with a register call.
  240. (0,external_wp_data_namespaceObject.registerStore)(STORE_NAME, {
  241. reducer: reducer,
  242. actions: actions_namespaceObject,
  243. selectors: selectors_namespaceObject,
  244. persist: ['preferences']
  245. });
  246. ;// CONCATENATED MODULE: ./node_modules/@wordpress/preferences/build-module/components/preference-toggle-menu-item/index.js
  247. /**
  248. * WordPress dependencies
  249. */
  250. /**
  251. * Internal dependencies
  252. */
  253. function PreferenceToggleMenuItem(_ref) {
  254. let {
  255. scope,
  256. name,
  257. label,
  258. info,
  259. messageActivated,
  260. messageDeactivated,
  261. shortcut
  262. } = _ref;
  263. const isActive = (0,external_wp_data_namespaceObject.useSelect)(select => !!select(store).get(scope, name), [name]);
  264. const {
  265. toggle
  266. } = (0,external_wp_data_namespaceObject.useDispatch)(store);
  267. const speakMessage = () => {
  268. if (isActive) {
  269. const message = messageDeactivated || (0,external_wp_i18n_namespaceObject.sprintf)(
  270. /* translators: %s: preference name, e.g. 'Fullscreen mode' */
  271. (0,external_wp_i18n_namespaceObject.__)('Preference deactivated - %s'), label);
  272. (0,external_wp_a11y_namespaceObject.speak)(message);
  273. } else {
  274. const message = messageActivated || (0,external_wp_i18n_namespaceObject.sprintf)(
  275. /* translators: %s: preference name, e.g. 'Fullscreen mode' */
  276. (0,external_wp_i18n_namespaceObject.__)('Preference activated - %s'), label);
  277. (0,external_wp_a11y_namespaceObject.speak)(message);
  278. }
  279. };
  280. return (0,external_wp_element_namespaceObject.createElement)(external_wp_components_namespaceObject.MenuItem, {
  281. icon: isActive && library_check,
  282. isSelected: isActive,
  283. onClick: () => {
  284. toggle(scope, name);
  285. speakMessage();
  286. },
  287. role: "menuitemcheckbox",
  288. info: info,
  289. shortcut: shortcut
  290. }, label);
  291. }
  292. ;// CONCATENATED MODULE: ./node_modules/@wordpress/preferences/build-module/components/index.js
  293. ;// CONCATENATED MODULE: ./node_modules/@wordpress/preferences/build-module/index.js
  294. (window.wp = window.wp || {}).preferences = __webpack_exports__;
  295. /******/ })()
  296. ;