@wordpress/preferences-persistence 2.32.0 → 2.32.1-next.47f435fc9.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/build/create/debounce-async.js +24 -39
- package/build/create/debounce-async.js.map +7 -1
- package/build/create/index.js +50 -61
- package/build/create/index.js.map +7 -1
- package/build/index.js +47 -42
- package/build/index.js.map +7 -1
- package/build/migrations/legacy-local-storage-data/convert-edit-post-panels.js +36 -52
- package/build/migrations/legacy-local-storage-data/convert-edit-post-panels.js.map +7 -1
- package/build/migrations/legacy-local-storage-data/index.js +80 -89
- package/build/migrations/legacy-local-storage-data/index.js.map +7 -1
- package/build/migrations/legacy-local-storage-data/move-feature-preferences.js +26 -78
- package/build/migrations/legacy-local-storage-data/move-feature-preferences.js.map +7 -1
- package/build/migrations/legacy-local-storage-data/move-individual-preference.js +28 -60
- package/build/migrations/legacy-local-storage-data/move-individual-preference.js.map +7 -1
- package/build/migrations/legacy-local-storage-data/move-interface-enable-items.js +46 -85
- package/build/migrations/legacy-local-storage-data/move-interface-enable-items.js.map +7 -1
- package/build/migrations/legacy-local-storage-data/move-third-party-feature-preferences.js +27 -52
- package/build/migrations/legacy-local-storage-data/move-third-party-feature-preferences.js.map +7 -1
- package/build/migrations/preferences-package-data/convert-complementary-areas.js +23 -11
- package/build/migrations/preferences-package-data/convert-complementary-areas.js.map +7 -1
- package/build/migrations/preferences-package-data/convert-editor-settings.js +50 -22
- package/build/migrations/preferences-package-data/convert-editor-settings.js.map +7 -1
- package/build/migrations/preferences-package-data/index.js +36 -15
- package/build/migrations/preferences-package-data/index.js.map +7 -1
- package/build-module/create/debounce-async.js +7 -35
- package/build-module/create/debounce-async.js.map +7 -1
- package/build-module/create/index.js +21 -53
- package/build-module/create/index.js.map +7 -1
- package/build-module/index.js +12 -29
- package/build-module/index.js.map +7 -1
- package/build-module/migrations/legacy-local-storage-data/convert-edit-post-panels.js +19 -48
- package/build-module/migrations/legacy-local-storage-data/convert-edit-post-panels.js.map +7 -1
- package/build-module/migrations/legacy-local-storage-data/index.js +48 -82
- package/build-module/migrations/legacy-local-storage-data/index.js.map +7 -1
- package/build-module/migrations/legacy-local-storage-data/move-feature-preferences.js +9 -74
- package/build-module/migrations/legacy-local-storage-data/move-feature-preferences.js.map +7 -1
- package/build-module/migrations/legacy-local-storage-data/move-individual-preference.js +10 -55
- package/build-module/migrations/legacy-local-storage-data/move-individual-preference.js.map +7 -1
- package/build-module/migrations/legacy-local-storage-data/move-interface-enable-items.js +29 -81
- package/build-module/migrations/legacy-local-storage-data/move-interface-enable-items.js.map +7 -1
- package/build-module/migrations/legacy-local-storage-data/move-third-party-feature-preferences.js +10 -48
- package/build-module/migrations/legacy-local-storage-data/move-third-party-feature-preferences.js.map +7 -1
- package/build-module/migrations/preferences-package-data/convert-complementary-areas.js +6 -7
- package/build-module/migrations/preferences-package-data/convert-complementary-areas.js.map +7 -1
- package/build-module/migrations/preferences-package-data/convert-editor-settings.js +33 -18
- package/build-module/migrations/preferences-package-data/convert-editor-settings.js.map +7 -1
- package/build-module/migrations/preferences-package-data/index.js +7 -7
- package/build-module/migrations/preferences-package-data/index.js.map +7 -1
- package/package.json +11 -4
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/create/debounce-async.js"],
|
|
4
|
+
"sourcesContent": ["/**\n * Performs a leading edge debounce of async functions.\n *\n * If three functions are throttled at the same time:\n * - The first happens immediately.\n * - The second is never called.\n * - The third happens `delayMS` milliseconds after the first has resolved.\n *\n * This is distinct from `{ debounce } from @wordpress/compose` in that it\n * waits for promise resolution.\n *\n * @param {Function} func A function that returns a promise.\n * @param {number} delayMS A delay in milliseconds.\n *\n * @return {Function} A function that debounce whatever function is passed\n * to it.\n */\nexport default function debounceAsync( func, delayMS ) {\n\tlet timeoutId;\n\tlet activePromise;\n\n\treturn async function debounced( ...args ) {\n\t\t// This is a leading edge debounce. If there's no promise or timeout\n\t\t// in progress, call the debounced function immediately.\n\t\tif ( ! activePromise && ! timeoutId ) {\n\t\t\treturn new Promise( ( resolve, reject ) => {\n\t\t\t\t// Keep a reference to the promise.\n\t\t\t\tactivePromise = func( ...args )\n\t\t\t\t\t.then( ( ...thenArgs ) => {\n\t\t\t\t\t\tresolve( ...thenArgs );\n\t\t\t\t\t} )\n\t\t\t\t\t.catch( ( error ) => {\n\t\t\t\t\t\treject( error );\n\t\t\t\t\t} )\n\t\t\t\t\t.finally( () => {\n\t\t\t\t\t\t// As soon this promise is complete, clear the way for the\n\t\t\t\t\t\t// next one to happen immediately.\n\t\t\t\t\t\tactivePromise = null;\n\t\t\t\t\t} );\n\t\t\t} );\n\t\t}\n\n\t\tif ( activePromise ) {\n\t\t\t// Let any active promises finish before queuing the next request.\n\t\t\tawait activePromise;\n\t\t}\n\n\t\t// Clear any active timeouts, abandoning any requests that have\n\t\t// been queued but not been made.\n\t\tif ( timeoutId ) {\n\t\t\tclearTimeout( timeoutId );\n\t\t\ttimeoutId = null;\n\t\t}\n\n\t\t// Trigger any trailing edge calls to the function.\n\t\treturn new Promise( ( resolve, reject ) => {\n\t\t\t// Schedule the next request but with a delay.\n\t\t\ttimeoutId = setTimeout( () => {\n\t\t\t\tactivePromise = func( ...args )\n\t\t\t\t\t.then( ( ...thenArgs ) => {\n\t\t\t\t\t\tresolve( ...thenArgs );\n\t\t\t\t\t} )\n\t\t\t\t\t.catch( ( error ) => {\n\t\t\t\t\t\treject( error );\n\t\t\t\t\t} )\n\t\t\t\t\t.finally( () => {\n\t\t\t\t\t\t// As soon this promise is complete, clear the way for the\n\t\t\t\t\t\t// next one to happen immediately.\n\t\t\t\t\t\tactivePromise = null;\n\t\t\t\t\t\ttimeoutId = null;\n\t\t\t\t\t} );\n\t\t\t}, delayMS );\n\t\t} );\n\t};\n}\n"],
|
|
5
|
+
"mappings": "AAiBe,SAAR,cAAgC,MAAM,SAAU;AACtD,MAAI;AACJ,MAAI;AAEJ,SAAO,eAAe,aAAc,MAAO;AAG1C,QAAK,CAAE,iBAAiB,CAAE,WAAY;AACrC,aAAO,IAAI,QAAS,CAAE,SAAS,WAAY;AAE1C,wBAAgB,KAAM,GAAG,IAAK,EAC5B,KAAM,IAAK,aAAc;AACzB,kBAAS,GAAG,QAAS;AAAA,QACtB,CAAE,EACD,MAAO,CAAE,UAAW;AACpB,iBAAQ,KAAM;AAAA,QACf,CAAE,EACD,QAAS,MAAM;AAGf,0BAAgB;AAAA,QACjB,CAAE;AAAA,MACJ,CAAE;AAAA,IACH;AAEA,QAAK,eAAgB;AAEpB,YAAM;AAAA,IACP;AAIA,QAAK,WAAY;AAChB,mBAAc,SAAU;AACxB,kBAAY;AAAA,IACb;AAGA,WAAO,IAAI,QAAS,CAAE,SAAS,WAAY;AAE1C,kBAAY,WAAY,MAAM;AAC7B,wBAAgB,KAAM,GAAG,IAAK,EAC5B,KAAM,IAAK,aAAc;AACzB,kBAAS,GAAG,QAAS;AAAA,QACtB,CAAE,EACD,MAAO,CAAE,UAAW;AACpB,iBAAQ,KAAM;AAAA,QACf,CAAE,EACD,QAAS,MAAM;AAGf,0BAAgB;AAChB,sBAAY;AAAA,QACb,CAAE;AAAA,MACJ,GAAG,OAAQ;AAAA,IACZ,CAAE;AAAA,EACH;AACD;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,35 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
*/
|
|
4
|
-
import apiFetch from '@wordpress/api-fetch';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Internal dependencies
|
|
8
|
-
*/
|
|
9
|
-
import debounceAsync from './debounce-async';
|
|
1
|
+
import apiFetch from "@wordpress/api-fetch";
|
|
2
|
+
import debounceAsync from "./debounce-async";
|
|
10
3
|
const EMPTY_OBJECT = {};
|
|
11
4
|
const localStorage = window.localStorage;
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Creates a persistence layer that stores data in WordPress user meta via the
|
|
15
|
-
* REST API.
|
|
16
|
-
*
|
|
17
|
-
* @param {Object} options
|
|
18
|
-
* @param {?Object} options.preloadedData Any persisted preferences data that should be preloaded.
|
|
19
|
-
* When set, the persistence layer will avoid fetching data
|
|
20
|
-
* from the REST API.
|
|
21
|
-
* @param {?string} options.localStorageRestoreKey The key to use for restoring the localStorage backup, used
|
|
22
|
-
* when the persistence layer calls `localStorage.getItem` or
|
|
23
|
-
* `localStorage.setItem`.
|
|
24
|
-
* @param {?number} options.requestDebounceMS Debounce requests to the API so that they only occur at
|
|
25
|
-
* minimum every `requestDebounceMS` milliseconds, and don't
|
|
26
|
-
* swamp the server. Defaults to 2500ms.
|
|
27
|
-
*
|
|
28
|
-
* @return {Object} A persistence layer for WordPress user meta.
|
|
29
|
-
*/
|
|
30
|
-
export default function create({
|
|
5
|
+
function create({
|
|
31
6
|
preloadedData,
|
|
32
|
-
localStorageRestoreKey =
|
|
7
|
+
localStorageRestoreKey = "WP_PREFERENCES_RESTORE_DATA",
|
|
33
8
|
requestDebounceMS = 2500
|
|
34
9
|
} = {}) {
|
|
35
10
|
let cache = preloadedData;
|
|
@@ -39,18 +14,14 @@ export default function create({
|
|
|
39
14
|
return cache;
|
|
40
15
|
}
|
|
41
16
|
const user = await apiFetch({
|
|
42
|
-
path:
|
|
17
|
+
path: "/wp/v2/users/me?context=edit"
|
|
43
18
|
});
|
|
44
19
|
const serverData = user?.meta?.persisted_preferences;
|
|
45
|
-
const localData = JSON.parse(
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
// into a conveniently comparable zero.
|
|
20
|
+
const localData = JSON.parse(
|
|
21
|
+
localStorage.getItem(localStorageRestoreKey)
|
|
22
|
+
);
|
|
49
23
|
const serverTimestamp = Date.parse(serverData?._modified) || 0;
|
|
50
24
|
const localTimestamp = Date.parse(localData?._modified) || 0;
|
|
51
|
-
|
|
52
|
-
// Prefer server data if it exists and is more recent.
|
|
53
|
-
// Otherwise fallback to localStorage data.
|
|
54
25
|
if (serverData && serverTimestamp >= localTimestamp) {
|
|
55
26
|
cache = serverData;
|
|
56
27
|
} else if (localData) {
|
|
@@ -63,23 +34,16 @@ export default function create({
|
|
|
63
34
|
function set(newData) {
|
|
64
35
|
const dataWithTimestamp = {
|
|
65
36
|
...newData,
|
|
66
|
-
_modified: new Date().toISOString()
|
|
37
|
+
_modified: (/* @__PURE__ */ new Date()).toISOString()
|
|
67
38
|
};
|
|
68
39
|
cache = dataWithTimestamp;
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
localStorage.setItem(localStorageRestoreKey, JSON.stringify(dataWithTimestamp));
|
|
74
|
-
|
|
75
|
-
// The user meta endpoint seems susceptible to errors when consecutive
|
|
76
|
-
// requests are made in quick succession. Ensure there's a gap between
|
|
77
|
-
// any consecutive requests.
|
|
78
|
-
//
|
|
79
|
-
// Catch and do nothing with errors from the REST API.
|
|
40
|
+
localStorage.setItem(
|
|
41
|
+
localStorageRestoreKey,
|
|
42
|
+
JSON.stringify(dataWithTimestamp)
|
|
43
|
+
);
|
|
80
44
|
debouncedApiFetch({
|
|
81
|
-
path:
|
|
82
|
-
method:
|
|
45
|
+
path: "/wp/v2/users/me",
|
|
46
|
+
method: "PUT",
|
|
83
47
|
// `keepalive` will still send the request in the background,
|
|
84
48
|
// even when a browser unload event might interrupt it.
|
|
85
49
|
// This should hopefully make things more resilient.
|
|
@@ -91,11 +55,15 @@ export default function create({
|
|
|
91
55
|
persisted_preferences: dataWithTimestamp
|
|
92
56
|
}
|
|
93
57
|
}
|
|
94
|
-
}).catch(() => {
|
|
58
|
+
}).catch(() => {
|
|
59
|
+
});
|
|
95
60
|
}
|
|
96
61
|
return {
|
|
97
62
|
get,
|
|
98
63
|
set
|
|
99
64
|
};
|
|
100
65
|
}
|
|
101
|
-
|
|
66
|
+
export {
|
|
67
|
+
create as default
|
|
68
|
+
};
|
|
69
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/create/index.js"],
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport apiFetch from '@wordpress/api-fetch';\n\n/**\n * Internal dependencies\n */\nimport debounceAsync from './debounce-async';\n\nconst EMPTY_OBJECT = {};\nconst localStorage = window.localStorage;\n\n/**\n * Creates a persistence layer that stores data in WordPress user meta via the\n * REST API.\n *\n * @param {Object} options\n * @param {?Object} options.preloadedData Any persisted preferences data that should be preloaded.\n * When set, the persistence layer will avoid fetching data\n * from the REST API.\n * @param {?string} options.localStorageRestoreKey The key to use for restoring the localStorage backup, used\n * when the persistence layer calls `localStorage.getItem` or\n * `localStorage.setItem`.\n * @param {?number} options.requestDebounceMS Debounce requests to the API so that they only occur at\n * minimum every `requestDebounceMS` milliseconds, and don't\n * swamp the server. Defaults to 2500ms.\n *\n * @return {Object} A persistence layer for WordPress user meta.\n */\nexport default function create( {\n\tpreloadedData,\n\tlocalStorageRestoreKey = 'WP_PREFERENCES_RESTORE_DATA',\n\trequestDebounceMS = 2500,\n} = {} ) {\n\tlet cache = preloadedData;\n\tconst debouncedApiFetch = debounceAsync( apiFetch, requestDebounceMS );\n\n\tasync function get() {\n\t\tif ( cache ) {\n\t\t\treturn cache;\n\t\t}\n\n\t\tconst user = await apiFetch( {\n\t\t\tpath: '/wp/v2/users/me?context=edit',\n\t\t} );\n\n\t\tconst serverData = user?.meta?.persisted_preferences;\n\t\tconst localData = JSON.parse(\n\t\t\tlocalStorage.getItem( localStorageRestoreKey )\n\t\t);\n\n\t\t// Date parse returns NaN for invalid input. Coerce anything invalid\n\t\t// into a conveniently comparable zero.\n\t\tconst serverTimestamp = Date.parse( serverData?._modified ) || 0;\n\t\tconst localTimestamp = Date.parse( localData?._modified ) || 0;\n\n\t\t// Prefer server data if it exists and is more recent.\n\t\t// Otherwise fallback to localStorage data.\n\t\tif ( serverData && serverTimestamp >= localTimestamp ) {\n\t\t\tcache = serverData;\n\t\t} else if ( localData ) {\n\t\t\tcache = localData;\n\t\t} else {\n\t\t\tcache = EMPTY_OBJECT;\n\t\t}\n\n\t\treturn cache;\n\t}\n\n\tfunction set( newData ) {\n\t\tconst dataWithTimestamp = {\n\t\t\t...newData,\n\t\t\t_modified: new Date().toISOString(),\n\t\t};\n\t\tcache = dataWithTimestamp;\n\n\t\t// Store data in local storage as a fallback. If for some reason the\n\t\t// api request does not complete or becomes unavailable, this data\n\t\t// can be used to restore preferences.\n\t\tlocalStorage.setItem(\n\t\t\tlocalStorageRestoreKey,\n\t\t\tJSON.stringify( dataWithTimestamp )\n\t\t);\n\n\t\t// The user meta endpoint seems susceptible to errors when consecutive\n\t\t// requests are made in quick succession. Ensure there's a gap between\n\t\t// any consecutive requests.\n\t\t//\n\t\t// Catch and do nothing with errors from the REST API.\n\t\tdebouncedApiFetch( {\n\t\t\tpath: '/wp/v2/users/me',\n\t\t\tmethod: 'PUT',\n\t\t\t// `keepalive` will still send the request in the background,\n\t\t\t// even when a browser unload event might interrupt it.\n\t\t\t// This should hopefully make things more resilient.\n\t\t\t// This does have a size limit of 64kb, but the data is usually\n\t\t\t// much less.\n\t\t\tkeepalive: true,\n\t\t\tdata: {\n\t\t\t\tmeta: {\n\t\t\t\t\tpersisted_preferences: dataWithTimestamp,\n\t\t\t\t},\n\t\t\t},\n\t\t} ).catch( () => {} );\n\t}\n\n\treturn {\n\t\tget,\n\t\tset,\n\t};\n}\n"],
|
|
5
|
+
"mappings": "AAGA,OAAO,cAAc;AAKrB,OAAO,mBAAmB;AAE1B,MAAM,eAAe,CAAC;AACtB,MAAM,eAAe,OAAO;AAmBb,SAAR,OAAyB;AAAA,EAC/B;AAAA,EACA,yBAAyB;AAAA,EACzB,oBAAoB;AACrB,IAAI,CAAC,GAAI;AACR,MAAI,QAAQ;AACZ,QAAM,oBAAoB,cAAe,UAAU,iBAAkB;AAErE,iBAAe,MAAM;AACpB,QAAK,OAAQ;AACZ,aAAO;AAAA,IACR;AAEA,UAAM,OAAO,MAAM,SAAU;AAAA,MAC5B,MAAM;AAAA,IACP,CAAE;AAEF,UAAM,aAAa,MAAM,MAAM;AAC/B,UAAM,YAAY,KAAK;AAAA,MACtB,aAAa,QAAS,sBAAuB;AAAA,IAC9C;AAIA,UAAM,kBAAkB,KAAK,MAAO,YAAY,SAAU,KAAK;AAC/D,UAAM,iBAAiB,KAAK,MAAO,WAAW,SAAU,KAAK;AAI7D,QAAK,cAAc,mBAAmB,gBAAiB;AACtD,cAAQ;AAAA,IACT,WAAY,WAAY;AACvB,cAAQ;AAAA,IACT,OAAO;AACN,cAAQ;AAAA,IACT;AAEA,WAAO;AAAA,EACR;AAEA,WAAS,IAAK,SAAU;AACvB,UAAM,oBAAoB;AAAA,MACzB,GAAG;AAAA,MACH,YAAW,oBAAI,KAAK,GAAE,YAAY;AAAA,IACnC;AACA,YAAQ;AAKR,iBAAa;AAAA,MACZ;AAAA,MACA,KAAK,UAAW,iBAAkB;AAAA,IACnC;AAOA,sBAAmB;AAAA,MAClB,MAAM;AAAA,MACN,QAAQ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,MAMR,WAAW;AAAA,MACX,MAAM;AAAA,QACL,MAAM;AAAA,UACL,uBAAuB;AAAA,QACxB;AAAA,MACD;AAAA,IACD,CAAE,EAAE,MAAO,MAAM;AAAA,IAAC,CAAE;AAAA,EACrB;AAEA,SAAO;AAAA,IACN;AAAA,IACA;AAAA,EACD;AACD;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/build-module/index.js
CHANGED
|
@@ -1,31 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import convertLegacyLocalStorageData from './migrations/legacy-local-storage-data';
|
|
6
|
-
import convertPreferencesPackageData from './migrations/preferences-package-data';
|
|
7
|
-
export { create };
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Creates the persistence layer with preloaded data.
|
|
11
|
-
*
|
|
12
|
-
* It prioritizes any data from the server, but falls back first to localStorage
|
|
13
|
-
* restore data, and then to any legacy data.
|
|
14
|
-
*
|
|
15
|
-
* This function is used internally by WordPress in an inline script, so
|
|
16
|
-
* prefixed with `__unstable`.
|
|
17
|
-
*
|
|
18
|
-
* @param {Object} serverData Preferences data preloaded from the server.
|
|
19
|
-
* @param {string} userId The user id.
|
|
20
|
-
*
|
|
21
|
-
* @return {Object} The persistence layer initialized with the preloaded data.
|
|
22
|
-
*/
|
|
23
|
-
export function __unstableCreatePersistenceLayer(serverData, userId) {
|
|
1
|
+
import create from "./create";
|
|
2
|
+
import convertLegacyLocalStorageData from "./migrations/legacy-local-storage-data";
|
|
3
|
+
import convertPreferencesPackageData from "./migrations/preferences-package-data";
|
|
4
|
+
function __unstableCreatePersistenceLayer(serverData, userId) {
|
|
24
5
|
const localStorageRestoreKey = `WP_PREFERENCES_USER_${userId}`;
|
|
25
|
-
const localData = JSON.parse(
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
// into a conveniently comparable zero.
|
|
6
|
+
const localData = JSON.parse(
|
|
7
|
+
window.localStorage.getItem(localStorageRestoreKey)
|
|
8
|
+
);
|
|
29
9
|
const serverModified = Date.parse(serverData && serverData._modified) || 0;
|
|
30
10
|
const localModified = Date.parse(localData && localData._modified) || 0;
|
|
31
11
|
let preloadedData;
|
|
@@ -34,7 +14,6 @@ export function __unstableCreatePersistenceLayer(serverData, userId) {
|
|
|
34
14
|
} else if (localData) {
|
|
35
15
|
preloadedData = convertPreferencesPackageData(localData);
|
|
36
16
|
} else {
|
|
37
|
-
// Check if there is data in the legacy format from the old persistence system.
|
|
38
17
|
preloadedData = convertLegacyLocalStorageData(userId);
|
|
39
18
|
}
|
|
40
19
|
return create({
|
|
@@ -42,4 +21,8 @@ export function __unstableCreatePersistenceLayer(serverData, userId) {
|
|
|
42
21
|
localStorageRestoreKey
|
|
43
22
|
});
|
|
44
23
|
}
|
|
45
|
-
|
|
24
|
+
export {
|
|
25
|
+
__unstableCreatePersistenceLayer,
|
|
26
|
+
create
|
|
27
|
+
};
|
|
28
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/index.js"],
|
|
4
|
+
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport create from './create';\nimport convertLegacyLocalStorageData from './migrations/legacy-local-storage-data';\nimport convertPreferencesPackageData from './migrations/preferences-package-data';\n\nexport { create };\n\n/**\n * Creates the persistence layer with preloaded data.\n *\n * It prioritizes any data from the server, but falls back first to localStorage\n * restore data, and then to any legacy data.\n *\n * This function is used internally by WordPress in an inline script, so\n * prefixed with `__unstable`.\n *\n * @param {Object} serverData Preferences data preloaded from the server.\n * @param {string} userId The user id.\n *\n * @return {Object} The persistence layer initialized with the preloaded data.\n */\nexport function __unstableCreatePersistenceLayer( serverData, userId ) {\n\tconst localStorageRestoreKey = `WP_PREFERENCES_USER_${ userId }`;\n\tconst localData = JSON.parse(\n\t\twindow.localStorage.getItem( localStorageRestoreKey )\n\t);\n\n\t// Date parse returns NaN for invalid input. Coerce anything invalid\n\t// into a conveniently comparable zero.\n\tconst serverModified =\n\t\tDate.parse( serverData && serverData._modified ) || 0;\n\tconst localModified = Date.parse( localData && localData._modified ) || 0;\n\n\tlet preloadedData;\n\tif ( serverData && serverModified >= localModified ) {\n\t\tpreloadedData = convertPreferencesPackageData( serverData );\n\t} else if ( localData ) {\n\t\tpreloadedData = convertPreferencesPackageData( localData );\n\t} else {\n\t\t// Check if there is data in the legacy format from the old persistence system.\n\t\tpreloadedData = convertLegacyLocalStorageData( userId );\n\t}\n\n\treturn create( {\n\t\tpreloadedData,\n\t\tlocalStorageRestoreKey,\n\t} );\n}\n"],
|
|
5
|
+
"mappings": "AAGA,OAAO,YAAY;AACnB,OAAO,mCAAmC;AAC1C,OAAO,mCAAmC;AAkBnC,SAAS,iCAAkC,YAAY,QAAS;AACtE,QAAM,yBAAyB,uBAAwB,MAAO;AAC9D,QAAM,YAAY,KAAK;AAAA,IACtB,OAAO,aAAa,QAAS,sBAAuB;AAAA,EACrD;AAIA,QAAM,iBACL,KAAK,MAAO,cAAc,WAAW,SAAU,KAAK;AACrD,QAAM,gBAAgB,KAAK,MAAO,aAAa,UAAU,SAAU,KAAK;AAExE,MAAI;AACJ,MAAK,cAAc,kBAAkB,eAAgB;AACpD,oBAAgB,8BAA+B,UAAW;AAAA,EAC3D,WAAY,WAAY;AACvB,oBAAgB,8BAA+B,SAAU;AAAA,EAC1D,OAAO;AAEN,oBAAgB,8BAA+B,MAAO;AAAA,EACvD;AAEA,SAAO,OAAQ;AAAA,IACd;AAAA,IACA;AAAA,EACD,CAAE;AACH;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,49 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
* ```
|
|
17
|
-
*
|
|
18
|
-
* to a new, more concise data structure:
|
|
19
|
-
* {
|
|
20
|
-
* inactivePanels: [
|
|
21
|
-
* 'permalinks',
|
|
22
|
-
* ],
|
|
23
|
-
* openPanels: [
|
|
24
|
-
* 'tags',
|
|
25
|
-
* ],
|
|
26
|
-
* }
|
|
27
|
-
*
|
|
28
|
-
* @param {Object} preferences A preferences object.
|
|
29
|
-
*
|
|
30
|
-
* @return {Object} The converted data.
|
|
31
|
-
*/
|
|
32
|
-
export default function convertEditPostPanels(preferences) {
|
|
33
|
-
var _preferences$panels;
|
|
34
|
-
const panels = (_preferences$panels = preferences?.panels) !== null && _preferences$panels !== void 0 ? _preferences$panels : {};
|
|
35
|
-
return Object.keys(panels).reduce((convertedData, panelName) => {
|
|
36
|
-
const panel = panels[panelName];
|
|
37
|
-
if (panel?.enabled === false) {
|
|
38
|
-
convertedData.inactivePanels.push(panelName);
|
|
39
|
-
}
|
|
40
|
-
if (panel?.opened === true) {
|
|
41
|
-
convertedData.openPanels.push(panelName);
|
|
42
|
-
}
|
|
43
|
-
return convertedData;
|
|
44
|
-
}, {
|
|
45
|
-
inactivePanels: [],
|
|
46
|
-
openPanels: []
|
|
47
|
-
});
|
|
1
|
+
function convertEditPostPanels(preferences) {
|
|
2
|
+
const panels = preferences?.panels ?? {};
|
|
3
|
+
return Object.keys(panels).reduce(
|
|
4
|
+
(convertedData, panelName) => {
|
|
5
|
+
const panel = panels[panelName];
|
|
6
|
+
if (panel?.enabled === false) {
|
|
7
|
+
convertedData.inactivePanels.push(panelName);
|
|
8
|
+
}
|
|
9
|
+
if (panel?.opened === true) {
|
|
10
|
+
convertedData.openPanels.push(panelName);
|
|
11
|
+
}
|
|
12
|
+
return convertedData;
|
|
13
|
+
},
|
|
14
|
+
{ inactivePanels: [], openPanels: [] }
|
|
15
|
+
);
|
|
48
16
|
}
|
|
49
|
-
|
|
17
|
+
export {
|
|
18
|
+
convertEditPostPanels as default
|
|
19
|
+
};
|
|
20
|
+
//# sourceMappingURL=convert-edit-post-panels.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/migrations/legacy-local-storage-data/convert-edit-post-panels.js"],
|
|
4
|
+
"sourcesContent": ["/**\n * Convert the post editor's panels state from:\n * ```\n * {\n * panels: {\n * tags: {\n * enabled: true,\n * opened: true,\n * },\n * permalinks: {\n * enabled: false,\n * opened: false,\n * },\n * },\n * }\n * ```\n *\n * to a new, more concise data structure:\n * {\n * inactivePanels: [\n * 'permalinks',\n * ],\n * openPanels: [\n * 'tags',\n * ],\n * }\n *\n * @param {Object} preferences A preferences object.\n *\n * @return {Object} The converted data.\n */\nexport default function convertEditPostPanels( preferences ) {\n\tconst panels = preferences?.panels ?? {};\n\treturn Object.keys( panels ).reduce(\n\t\t( convertedData, panelName ) => {\n\t\t\tconst panel = panels[ panelName ];\n\n\t\t\tif ( panel?.enabled === false ) {\n\t\t\t\tconvertedData.inactivePanels.push( panelName );\n\t\t\t}\n\n\t\t\tif ( panel?.opened === true ) {\n\t\t\t\tconvertedData.openPanels.push( panelName );\n\t\t\t}\n\n\t\t\treturn convertedData;\n\t\t},\n\t\t{ inactivePanels: [], openPanels: [] }\n\t);\n}\n"],
|
|
5
|
+
"mappings": "AA+Be,SAAR,sBAAwC,aAAc;AAC5D,QAAM,SAAS,aAAa,UAAU,CAAC;AACvC,SAAO,OAAO,KAAM,MAAO,EAAE;AAAA,IAC5B,CAAE,eAAe,cAAe;AAC/B,YAAM,QAAQ,OAAQ,SAAU;AAEhC,UAAK,OAAO,YAAY,OAAQ;AAC/B,sBAAc,eAAe,KAAM,SAAU;AAAA,MAC9C;AAEA,UAAK,OAAO,WAAW,MAAO;AAC7B,sBAAc,WAAW,KAAM,SAAU;AAAA,MAC1C;AAEA,aAAO;AAAA,IACR;AAAA,IACA,EAAE,gBAAgB,CAAC,GAAG,YAAY,CAAC,EAAE;AAAA,EACtC;AACD;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,96 +1,62 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import moveIndividualPreference from './move-individual-preference';
|
|
7
|
-
import moveInterfaceEnableItems from './move-interface-enable-items';
|
|
8
|
-
import convertEditPostPanels from './convert-edit-post-panels';
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Gets the legacy local storage data for a given user.
|
|
12
|
-
*
|
|
13
|
-
* @param {string | number} userId The user id.
|
|
14
|
-
*
|
|
15
|
-
* @return {Object | null} The local storage data.
|
|
16
|
-
*/
|
|
1
|
+
import moveFeaturePreferences from "./move-feature-preferences";
|
|
2
|
+
import moveThirdPartyFeaturePreferences from "./move-third-party-feature-preferences";
|
|
3
|
+
import moveIndividualPreference from "./move-individual-preference";
|
|
4
|
+
import moveInterfaceEnableItems from "./move-interface-enable-items";
|
|
5
|
+
import convertEditPostPanels from "./convert-edit-post-panels";
|
|
17
6
|
function getLegacyData(userId) {
|
|
18
7
|
const key = `WP_DATA_USER_${userId}`;
|
|
19
8
|
const unparsedData = window.localStorage.getItem(key);
|
|
20
9
|
return JSON.parse(unparsedData);
|
|
21
10
|
}
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Converts data from the old `@wordpress/data` package format.
|
|
25
|
-
*
|
|
26
|
-
* @param {Object | null | undefined} data The legacy data in its original format.
|
|
27
|
-
*
|
|
28
|
-
* @return {Object | undefined} The converted data or `undefined` if there was
|
|
29
|
-
* nothing to convert.
|
|
30
|
-
*/
|
|
31
|
-
export function convertLegacyData(data) {
|
|
11
|
+
function convertLegacyData(data) {
|
|
32
12
|
if (!data) {
|
|
33
13
|
return;
|
|
34
14
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
data = moveFeaturePreferences(data,
|
|
39
|
-
data = moveFeaturePreferences(data, 'core/customize-widgets');
|
|
40
|
-
data = moveFeaturePreferences(data, 'core/edit-post');
|
|
41
|
-
data = moveFeaturePreferences(data, 'core/edit-site');
|
|
42
|
-
|
|
43
|
-
// Move third party boolean feature preferences from the interface package
|
|
44
|
-
// to the preferences store data structure.
|
|
15
|
+
data = moveFeaturePreferences(data, "core/edit-widgets");
|
|
16
|
+
data = moveFeaturePreferences(data, "core/customize-widgets");
|
|
17
|
+
data = moveFeaturePreferences(data, "core/edit-post");
|
|
18
|
+
data = moveFeaturePreferences(data, "core/edit-site");
|
|
45
19
|
data = moveThirdPartyFeaturePreferences(data);
|
|
46
|
-
|
|
47
|
-
// Move and convert the interface store's `enableItems` data into the
|
|
48
|
-
// preferences data structure.
|
|
49
20
|
data = moveInterfaceEnableItems(data);
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
from:
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
21
|
+
data = moveIndividualPreference(
|
|
22
|
+
data,
|
|
23
|
+
{ from: "core/edit-post", to: "core/edit-post" },
|
|
24
|
+
"hiddenBlockTypes"
|
|
25
|
+
);
|
|
26
|
+
data = moveIndividualPreference(
|
|
27
|
+
data,
|
|
28
|
+
{ from: "core/edit-post", to: "core/edit-post" },
|
|
29
|
+
"editorMode"
|
|
30
|
+
);
|
|
31
|
+
data = moveIndividualPreference(
|
|
32
|
+
data,
|
|
33
|
+
{ from: "core/edit-post", to: "core/edit-post" },
|
|
34
|
+
"panels",
|
|
35
|
+
convertEditPostPanels
|
|
36
|
+
);
|
|
37
|
+
data = moveIndividualPreference(
|
|
38
|
+
data,
|
|
39
|
+
{ from: "core/editor", to: "core" },
|
|
40
|
+
"isPublishSidebarEnabled"
|
|
41
|
+
);
|
|
42
|
+
data = moveIndividualPreference(
|
|
43
|
+
data,
|
|
44
|
+
{ from: "core/edit-post", to: "core" },
|
|
45
|
+
"isPublishSidebarEnabled"
|
|
46
|
+
);
|
|
47
|
+
data = moveIndividualPreference(
|
|
48
|
+
data,
|
|
49
|
+
{ from: "core/edit-site", to: "core/edit-site" },
|
|
50
|
+
"editorMode"
|
|
51
|
+
);
|
|
52
|
+
return data?.["core/preferences"]?.preferences;
|
|
81
53
|
}
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* Gets the legacy local storage data for the given user and returns the
|
|
85
|
-
* data converted to the new format.
|
|
86
|
-
*
|
|
87
|
-
* @param {string | number} userId The user id.
|
|
88
|
-
*
|
|
89
|
-
* @return {Object | undefined} The converted data or undefined if no local
|
|
90
|
-
* storage data could be found.
|
|
91
|
-
*/
|
|
92
|
-
export default function convertLegacyLocalStorageData(userId) {
|
|
54
|
+
function convertLegacyLocalStorageData(userId) {
|
|
93
55
|
const data = getLegacyData(userId);
|
|
94
56
|
return convertLegacyData(data);
|
|
95
57
|
}
|
|
96
|
-
|
|
58
|
+
export {
|
|
59
|
+
convertLegacyData,
|
|
60
|
+
convertLegacyLocalStorageData as default
|
|
61
|
+
};
|
|
62
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/migrations/legacy-local-storage-data/index.js"],
|
|
4
|
+
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport moveFeaturePreferences from './move-feature-preferences';\nimport moveThirdPartyFeaturePreferences from './move-third-party-feature-preferences';\nimport moveIndividualPreference from './move-individual-preference';\nimport moveInterfaceEnableItems from './move-interface-enable-items';\nimport convertEditPostPanels from './convert-edit-post-panels';\n\n/**\n * Gets the legacy local storage data for a given user.\n *\n * @param {string | number} userId The user id.\n *\n * @return {Object | null} The local storage data.\n */\nfunction getLegacyData( userId ) {\n\tconst key = `WP_DATA_USER_${ userId }`;\n\tconst unparsedData = window.localStorage.getItem( key );\n\treturn JSON.parse( unparsedData );\n}\n\n/**\n * Converts data from the old `@wordpress/data` package format.\n *\n * @param {Object | null | undefined} data The legacy data in its original format.\n *\n * @return {Object | undefined} The converted data or `undefined` if there was\n * nothing to convert.\n */\nexport function convertLegacyData( data ) {\n\tif ( ! data ) {\n\t\treturn;\n\t}\n\n\t// Move boolean feature preferences from each editor into the\n\t// preferences store data structure.\n\tdata = moveFeaturePreferences( data, 'core/edit-widgets' );\n\tdata = moveFeaturePreferences( data, 'core/customize-widgets' );\n\tdata = moveFeaturePreferences( data, 'core/edit-post' );\n\tdata = moveFeaturePreferences( data, 'core/edit-site' );\n\n\t// Move third party boolean feature preferences from the interface package\n\t// to the preferences store data structure.\n\tdata = moveThirdPartyFeaturePreferences( data );\n\n\t// Move and convert the interface store's `enableItems` data into the\n\t// preferences data structure.\n\tdata = moveInterfaceEnableItems( data );\n\n\t// Move individual ad-hoc preferences from various packages into the\n\t// preferences store data structure.\n\tdata = moveIndividualPreference(\n\t\tdata,\n\t\t{ from: 'core/edit-post', to: 'core/edit-post' },\n\t\t'hiddenBlockTypes'\n\t);\n\tdata = moveIndividualPreference(\n\t\tdata,\n\t\t{ from: 'core/edit-post', to: 'core/edit-post' },\n\t\t'editorMode'\n\t);\n\tdata = moveIndividualPreference(\n\t\tdata,\n\t\t{ from: 'core/edit-post', to: 'core/edit-post' },\n\t\t'panels',\n\t\tconvertEditPostPanels\n\t);\n\tdata = moveIndividualPreference(\n\t\tdata,\n\t\t{ from: 'core/editor', to: 'core' },\n\t\t'isPublishSidebarEnabled'\n\t);\n\tdata = moveIndividualPreference(\n\t\tdata,\n\t\t{ from: 'core/edit-post', to: 'core' },\n\t\t'isPublishSidebarEnabled'\n\t);\n\tdata = moveIndividualPreference(\n\t\tdata,\n\t\t{ from: 'core/edit-site', to: 'core/edit-site' },\n\t\t'editorMode'\n\t);\n\n\t// The new system is only concerned with persisting\n\t// 'core/preferences' preferences reducer, so only return that.\n\treturn data?.[ 'core/preferences' ]?.preferences;\n}\n\n/**\n * Gets the legacy local storage data for the given user and returns the\n * data converted to the new format.\n *\n * @param {string | number} userId The user id.\n *\n * @return {Object | undefined} The converted data or undefined if no local\n * storage data could be found.\n */\nexport default function convertLegacyLocalStorageData( userId ) {\n\tconst data = getLegacyData( userId );\n\treturn convertLegacyData( data );\n}\n"],
|
|
5
|
+
"mappings": "AAGA,OAAO,4BAA4B;AACnC,OAAO,sCAAsC;AAC7C,OAAO,8BAA8B;AACrC,OAAO,8BAA8B;AACrC,OAAO,2BAA2B;AASlC,SAAS,cAAe,QAAS;AAChC,QAAM,MAAM,gBAAiB,MAAO;AACpC,QAAM,eAAe,OAAO,aAAa,QAAS,GAAI;AACtD,SAAO,KAAK,MAAO,YAAa;AACjC;AAUO,SAAS,kBAAmB,MAAO;AACzC,MAAK,CAAE,MAAO;AACb;AAAA,EACD;AAIA,SAAO,uBAAwB,MAAM,mBAAoB;AACzD,SAAO,uBAAwB,MAAM,wBAAyB;AAC9D,SAAO,uBAAwB,MAAM,gBAAiB;AACtD,SAAO,uBAAwB,MAAM,gBAAiB;AAItD,SAAO,iCAAkC,IAAK;AAI9C,SAAO,yBAA0B,IAAK;AAItC,SAAO;AAAA,IACN;AAAA,IACA,EAAE,MAAM,kBAAkB,IAAI,iBAAiB;AAAA,IAC/C;AAAA,EACD;AACA,SAAO;AAAA,IACN;AAAA,IACA,EAAE,MAAM,kBAAkB,IAAI,iBAAiB;AAAA,IAC/C;AAAA,EACD;AACA,SAAO;AAAA,IACN;AAAA,IACA,EAAE,MAAM,kBAAkB,IAAI,iBAAiB;AAAA,IAC/C;AAAA,IACA;AAAA,EACD;AACA,SAAO;AAAA,IACN;AAAA,IACA,EAAE,MAAM,eAAe,IAAI,OAAO;AAAA,IAClC;AAAA,EACD;AACA,SAAO;AAAA,IACN;AAAA,IACA,EAAE,MAAM,kBAAkB,IAAI,OAAO;AAAA,IACrC;AAAA,EACD;AACA,SAAO;AAAA,IACN;AAAA,IACA,EAAE,MAAM,kBAAkB,IAAI,iBAAiB;AAAA,IAC/C;AAAA,EACD;AAIA,SAAO,OAAQ,kBAAmB,GAAG;AACtC;AAWe,SAAR,8BAAgD,QAAS;AAC/D,QAAM,OAAO,cAAe,MAAO;AACnC,SAAO,kBAAmB,IAAK;AAChC;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,68 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
*
|
|
5
|
-
* Previously, editors used a data structure like this for feature preferences:
|
|
6
|
-
* ```js
|
|
7
|
-
* {
|
|
8
|
-
* 'core/edit-post': {
|
|
9
|
-
* preferences: {
|
|
10
|
-
* features; {
|
|
11
|
-
* topToolbar: true,
|
|
12
|
-
* // ... other boolean 'feature' preferences
|
|
13
|
-
* },
|
|
14
|
-
* },
|
|
15
|
-
* },
|
|
16
|
-
* }
|
|
17
|
-
* ```
|
|
18
|
-
*
|
|
19
|
-
* And for a while these feature preferences lived in the interface package:
|
|
20
|
-
* ```js
|
|
21
|
-
* {
|
|
22
|
-
* 'core/interface': {
|
|
23
|
-
* preferences: {
|
|
24
|
-
* features: {
|
|
25
|
-
* 'core/edit-post': {
|
|
26
|
-
* topToolbar: true
|
|
27
|
-
* }
|
|
28
|
-
* }
|
|
29
|
-
* }
|
|
30
|
-
* }
|
|
31
|
-
* }
|
|
32
|
-
* ```
|
|
33
|
-
*
|
|
34
|
-
* In the preferences store, 'features' aren't considered special, they're
|
|
35
|
-
* merged to the root level of the scope along with other preferences:
|
|
36
|
-
* ```js
|
|
37
|
-
* {
|
|
38
|
-
* 'core/preferences': {
|
|
39
|
-
* preferences: {
|
|
40
|
-
* 'core/edit-post': {
|
|
41
|
-
* topToolbar: true,
|
|
42
|
-
* // ... any other preferences.
|
|
43
|
-
* }
|
|
44
|
-
* }
|
|
45
|
-
* }
|
|
46
|
-
* }
|
|
47
|
-
* ```
|
|
48
|
-
*
|
|
49
|
-
* This function handles moving from either the source store or the interface
|
|
50
|
-
* store to the preferences data structure.
|
|
51
|
-
*
|
|
52
|
-
* @param {Object} state The state before migration.
|
|
53
|
-
* @param {string} sourceStoreName The name of the store that has persisted
|
|
54
|
-
* preferences to migrate to the preferences
|
|
55
|
-
* package.
|
|
56
|
-
* @return {Object} The migrated state
|
|
57
|
-
*/
|
|
58
|
-
export default function moveFeaturePreferences(state, sourceStoreName) {
|
|
59
|
-
const preferencesStoreName = 'core/preferences';
|
|
60
|
-
const interfaceStoreName = 'core/interface';
|
|
61
|
-
|
|
62
|
-
// Features most recently (and briefly) lived in the interface package.
|
|
63
|
-
// If data exists there, prioritize using that for the migration. If not
|
|
64
|
-
// also check the original package as the user may have updated from an
|
|
65
|
-
// older block editor version.
|
|
1
|
+
function moveFeaturePreferences(state, sourceStoreName) {
|
|
2
|
+
const preferencesStoreName = "core/preferences";
|
|
3
|
+
const interfaceStoreName = "core/interface";
|
|
66
4
|
const interfaceFeatures = state?.[interfaceStoreName]?.preferences?.features?.[sourceStoreName];
|
|
67
5
|
const sourceFeatures = state?.[sourceStoreName]?.preferences?.features;
|
|
68
6
|
const featuresToMigrate = interfaceFeatures ? interfaceFeatures : sourceFeatures;
|
|
@@ -70,8 +8,6 @@ export default function moveFeaturePreferences(state, sourceStoreName) {
|
|
|
70
8
|
return state;
|
|
71
9
|
}
|
|
72
10
|
const existingPreferences = state?.[preferencesStoreName]?.preferences;
|
|
73
|
-
|
|
74
|
-
// Avoid migrating features again if they've previously been migrated.
|
|
75
11
|
if (existingPreferences?.[sourceStoreName]) {
|
|
76
12
|
return state;
|
|
77
13
|
}
|
|
@@ -85,7 +21,7 @@ export default function moveFeaturePreferences(state, sourceStoreName) {
|
|
|
85
21
|
preferences: {
|
|
86
22
|
features: {
|
|
87
23
|
...otherInterfaceScopes,
|
|
88
|
-
[sourceStoreName]:
|
|
24
|
+
[sourceStoreName]: void 0
|
|
89
25
|
}
|
|
90
26
|
}
|
|
91
27
|
}
|
|
@@ -100,15 +36,11 @@ export default function moveFeaturePreferences(state, sourceStoreName) {
|
|
|
100
36
|
...otherSourceState,
|
|
101
37
|
preferences: {
|
|
102
38
|
...sourcePreferences,
|
|
103
|
-
features:
|
|
39
|
+
features: void 0
|
|
104
40
|
}
|
|
105
41
|
}
|
|
106
42
|
};
|
|
107
43
|
}
|
|
108
|
-
|
|
109
|
-
// Set the feature values in the interface store, the features
|
|
110
|
-
// object is keyed by 'scope', which matches the store name for
|
|
111
|
-
// the source.
|
|
112
44
|
return {
|
|
113
45
|
...state,
|
|
114
46
|
[preferencesStoreName]: {
|
|
@@ -121,4 +53,7 @@ export default function moveFeaturePreferences(state, sourceStoreName) {
|
|
|
121
53
|
...updatedSourceState
|
|
122
54
|
};
|
|
123
55
|
}
|
|
124
|
-
|
|
56
|
+
export {
|
|
57
|
+
moveFeaturePreferences as default
|
|
58
|
+
};
|
|
59
|
+
//# sourceMappingURL=move-feature-preferences.js.map
|