mirror of
https://github.com/WordPress/WordPress.git
synced 2024-10-29 23:09:44 +01:00
8c85dde1c6
Adds a new feature to persist editor UI preferences between page loads and browsers. * Adds a new preferences persistence API. * Saves editor preferences in user meta instead of in browser's local storage. Why? Due to the transient nature of browser storage, this persistence is not as sticky as it is expected to be, including: switching browsers (unique storage between browsers), or using private browsing tabs (storage cleared between sessions), or the same user across a network of sites (storage unique by domain). This is a backport from Gutenberg.[https://github.com/WordPress/gutenberg/pull/39795 See WordPress/gutenberg PR 39795]. Props talldanwp, youknowriad, noisysocks, mamaduka, costdev, ironprogrammer, hellofromTonya. See #56467. Built from https://develop.svn.wordpress.org/trunk@54182 git-svn-id: http://core.svn.wordpress.org/trunk@53741 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2 lines
2.8 KiB
JavaScript
2 lines
2.8 KiB
JavaScript
/*! This file is auto-generated */
|
|
!function(){"use strict";var e={d:function(t,n){for(var r in n)e.o(n,r)&&!e.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:n[r]})},o:function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r:function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};e.r(t),e.d(t,{PreferenceToggleMenuItem:function(){return m},store:function(){return S}});var n={};e.r(n),e.d(n,{set:function(){return E},setDefaults:function(){return w},setPersistenceLayer:function(){return v},toggle:function(){return p}});var r={};e.r(r),e.d(r,{get:function(){return g}});var o=window.wp.element,c=window.wp.data,i=window.wp.components,s=window.wp.i18n,u=window.wp.primitives;var a=(0,o.createElement)(u.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,o.createElement)(u.Path,{d:"M16.7 7.1l-6.3 8.5-3.3-2.5-.9 1.2 4.5 3.4L17.9 8z"})),l=window.wp.a11y;const d=function(e){let t;return(n,r)=>{if("SET_PERSISTENCE_LAYER"===r.type){const{persistenceLayer:e,persistedData:n}=r;return t=e,n}const o=e(n,r);var c;"SET_PREFERENCE_VALUE"===r.type&&(null===(c=t)||void 0===c||c.set(o));return o}}((function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=arguments.length>1?arguments[1]:void 0;if("SET_PREFERENCE_VALUE"===t.type){const{scope:n,name:r,value:o}=t;return{...e,[n]:{...e[n],[r]:o}}}return e}));var f=(0,c.combineReducers)({defaults:function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=arguments.length>1?arguments[1]:void 0;if("SET_PREFERENCE_DEFAULTS"===t.type){const{scope:n,defaults:r}=t;return{...e,[n]:{...e[n],...r}}}return e},preferences:d});function p(e,t){return function(n){let{select:r,dispatch:o}=n;const c=r.get(e,t);o.set(e,t,!c)}}function E(e,t,n){return{type:"SET_PREFERENCE_VALUE",scope:e,name:t,value:n}}function w(e,t){return{type:"SET_PREFERENCE_DEFAULTS",scope:e,defaults:t}}async function v(e){const t=await e.get();return{type:"SET_PERSISTENCE_LAYER",persistenceLayer:e,persistedData:t}}function g(e,t,n){var r,o;const c=null===(r=e.preferences[t])||void 0===r?void 0:r[n];return void 0!==c?c:null===(o=e.defaults[t])||void 0===o?void 0:o[n]}const S=(0,c.createReduxStore)("core/preferences",{reducer:f,actions:n,selectors:r});function m(e){let{scope:t,name:n,label:r,info:u,messageActivated:d,messageDeactivated:f,shortcut:p}=e;const E=(0,c.useSelect)((e=>!!e(S).get(t,n)),[n]),{toggle:w}=(0,c.useDispatch)(S);return(0,o.createElement)(i.MenuItem,{icon:E&&a,isSelected:E,onClick:()=>{w(t,n),(()=>{if(E){const e=f||(0,s.sprintf)((0,s.__)("Preference deactivated - %s"),r);(0,l.speak)(e)}else{const e=d||(0,s.sprintf)((0,s.__)("Preference activated - %s"),r);(0,l.speak)(e)}})()},role:"menuitemcheckbox",info:u,shortcut:p},r)}(0,c.register)(S),(window.wp=window.wp||{}).preferences=t}(); |