@wordpress/preferences-persistence 2.57.0 → 3.1.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/README.md +7 -7
- package/build/create/debounce-async.cjs +55 -58
- package/build/create/debounce-async.cjs.map +1 -7
- package/build/create/index.cjs +75 -91
- package/build/create/index.cjs.map +1 -7
- package/build/get-newest-data.cjs +64 -0
- package/build/get-newest-data.cjs.map +1 -0
- package/build/index.cjs +52 -53
- package/build/index.cjs.map +1 -7
- package/build/is-preferences-data.cjs +20 -0
- package/build/is-preferences-data.cjs.map +1 -0
- package/build/local-storage.cjs +39 -0
- package/build/local-storage.cjs.map +1 -0
- package/build/migrations/legacy-local-storage-data/convert-edit-post-panels.cjs +49 -38
- package/build/migrations/legacy-local-storage-data/convert-edit-post-panels.cjs.map +1 -7
- package/build/migrations/legacy-local-storage-data/index.cjs +95 -83
- package/build/migrations/legacy-local-storage-data/index.cjs.map +1 -7
- package/build/migrations/legacy-local-storage-data/move-feature-preferences.cjs +106 -77
- package/build/migrations/legacy-local-storage-data/move-feature-preferences.cjs.map +1 -7
- package/build/migrations/legacy-local-storage-data/move-individual-preference.cjs +70 -58
- package/build/migrations/legacy-local-storage-data/move-individual-preference.cjs.map +1 -7
- package/build/migrations/legacy-local-storage-data/move-interface-enable-items.cjs +93 -75
- package/build/migrations/legacy-local-storage-data/move-interface-enable-items.cjs.map +1 -7
- package/build/migrations/legacy-local-storage-data/move-third-party-feature-preferences.cjs +77 -65
- package/build/migrations/legacy-local-storage-data/move-third-party-feature-preferences.cjs.map +1 -7
- package/build/migrations/legacy-local-storage-data/types.cjs +5 -0
- package/build/migrations/preferences-package-data/convert-complementary-areas.cjs +19 -35
- package/build/migrations/preferences-package-data/convert-complementary-areas.cjs.map +1 -7
- package/build/migrations/preferences-package-data/convert-editor-settings.cjs +62 -60
- package/build/migrations/preferences-package-data/convert-editor-settings.cjs.map +1 -7
- package/build/migrations/preferences-package-data/index.cjs +29 -32
- package/build/migrations/preferences-package-data/index.cjs.map +1 -7
- package/build/types.cjs +5 -0
- package/build-module/create/debounce-async.mjs +51 -39
- package/build-module/create/debounce-async.mjs.map +1 -7
- package/build-module/create/index.mjs +51 -67
- package/build-module/create/index.mjs.map +1 -7
- package/build-module/get-newest-data.mjs +36 -0
- package/build-module/get-newest-data.mjs.map +1 -0
- package/build-module/index.mjs +24 -25
- package/build-module/index.mjs.map +1 -7
- package/build-module/is-preferences-data.mjs +15 -0
- package/build-module/is-preferences-data.mjs.map +1 -0
- package/build-module/local-storage.mjs +33 -0
- package/build-module/local-storage.mjs.map +1 -0
- package/build-module/migrations/legacy-local-storage-data/convert-edit-post-panels.mjs +45 -19
- package/build-module/migrations/legacy-local-storage-data/convert-edit-post-panels.mjs.map +1 -7
- package/build-module/migrations/legacy-local-storage-data/index.mjs +65 -52
- package/build-module/migrations/legacy-local-storage-data/index.mjs.map +1 -7
- package/build-module/migrations/legacy-local-storage-data/move-feature-preferences.mjs +102 -58
- package/build-module/migrations/legacy-local-storage-data/move-feature-preferences.mjs.map +1 -7
- package/build-module/migrations/legacy-local-storage-data/move-individual-preference.mjs +66 -39
- package/build-module/migrations/legacy-local-storage-data/move-individual-preference.mjs.map +1 -7
- package/build-module/migrations/legacy-local-storage-data/move-interface-enable-items.mjs +89 -56
- package/build-module/migrations/legacy-local-storage-data/move-interface-enable-items.mjs.map +1 -7
- package/build-module/migrations/legacy-local-storage-data/move-third-party-feature-preferences.mjs +73 -46
- package/build-module/migrations/legacy-local-storage-data/move-third-party-feature-preferences.mjs.map +1 -7
- package/build-module/migrations/legacy-local-storage-data/types.mjs +0 -0
- package/build-module/migrations/preferences-package-data/convert-complementary-areas.mjs +15 -16
- package/build-module/migrations/preferences-package-data/convert-complementary-areas.mjs.map +1 -7
- package/build-module/migrations/preferences-package-data/convert-editor-settings.mjs +41 -46
- package/build-module/migrations/preferences-package-data/convert-editor-settings.mjs.map +1 -7
- package/build-module/migrations/preferences-package-data/index.mjs +7 -8
- package/build-module/migrations/preferences-package-data/index.mjs.map +1 -7
- package/build-module/types.mjs +0 -0
- package/build-types/create/debounce-async.d.ts +19 -0
- package/build-types/create/debounce-async.d.ts.map +1 -0
- package/build-types/create/index.d.ts +20 -0
- package/build-types/create/index.d.ts.map +1 -0
- package/build-types/get-newest-data.d.ts +11 -0
- package/build-types/get-newest-data.d.ts.map +1 -0
- package/build-types/index.d.ts +20 -0
- package/build-types/index.d.ts.map +1 -0
- package/build-types/is-preferences-data.d.ts +11 -0
- package/build-types/is-preferences-data.d.ts.map +1 -0
- package/build-types/local-storage.d.ts +19 -0
- package/build-types/local-storage.d.ts.map +1 -0
- package/build-types/migrations/legacy-local-storage-data/convert-edit-post-panels.d.ts +35 -0
- package/build-types/migrations/legacy-local-storage-data/convert-edit-post-panels.d.ts.map +1 -0
- package/build-types/migrations/legacy-local-storage-data/index.d.ts +22 -0
- package/build-types/migrations/legacy-local-storage-data/index.d.ts.map +1 -0
- package/build-types/migrations/legacy-local-storage-data/move-feature-preferences.d.ts +60 -0
- package/build-types/migrations/legacy-local-storage-data/move-feature-preferences.d.ts.map +1 -0
- package/build-types/migrations/legacy-local-storage-data/move-individual-preference.d.ts +42 -0
- package/build-types/migrations/legacy-local-storage-data/move-individual-preference.d.ts.map +1 -0
- package/build-types/migrations/legacy-local-storage-data/move-interface-enable-items.d.ts +50 -0
- package/build-types/migrations/legacy-local-storage-data/move-interface-enable-items.d.ts.map +1 -0
- package/build-types/migrations/legacy-local-storage-data/move-third-party-feature-preferences.d.ts +44 -0
- package/build-types/migrations/legacy-local-storage-data/move-third-party-feature-preferences.d.ts.map +1 -0
- package/build-types/migrations/legacy-local-storage-data/types.d.ts +60 -0
- package/build-types/migrations/legacy-local-storage-data/types.d.ts.map +1 -0
- package/build-types/migrations/preferences-package-data/convert-complementary-areas.d.ts +5 -0
- package/build-types/migrations/preferences-package-data/convert-complementary-areas.d.ts.map +1 -0
- package/build-types/migrations/preferences-package-data/convert-editor-settings.d.ts +5 -0
- package/build-types/migrations/preferences-package-data/convert-editor-settings.d.ts.map +1 -0
- package/build-types/migrations/preferences-package-data/index.d.ts +5 -0
- package/build-types/migrations/preferences-package-data/index.d.ts.map +1 -0
- package/build-types/types.d.ts +40 -0
- package/build-types/types.d.ts.map +1 -0
- package/package.json +8 -7
- package/src/create/{debounce-async.js → debounce-async.ts} +13 -10
- package/src/create/index.ts +95 -0
- package/src/create/test/{debounce-async.js → debounce-async.ts} +7 -3
- package/src/create/test/{index.jsdom.test.js → index.jsdom.test.ts} +52 -4
- package/src/get-newest-data.ts +50 -0
- package/src/index.ts +40 -0
- package/src/is-preferences-data.ts +15 -0
- package/src/local-storage.ts +30 -0
- package/src/migrations/legacy-local-storage-data/{convert-edit-post-panels.js → convert-edit-post-panels.ts} +13 -5
- package/src/migrations/legacy-local-storage-data/{index.js → index.ts} +22 -15
- package/src/migrations/legacy-local-storage-data/{move-feature-preferences.js → move-feature-preferences.ts} +13 -7
- package/src/migrations/legacy-local-storage-data/{move-individual-preference.js → move-individual-preference.ts} +15 -12
- package/src/migrations/legacy-local-storage-data/{move-interface-enable-items.js → move-interface-enable-items.ts} +6 -2
- package/src/migrations/legacy-local-storage-data/{move-third-party-feature-preferences.js → move-third-party-feature-preferences.ts} +8 -4
- package/src/migrations/legacy-local-storage-data/test/{index.js → index.ts} +11 -0
- package/src/migrations/legacy-local-storage-data/types.ts +66 -0
- package/src/migrations/preferences-package-data/convert-complementary-areas.ts +21 -0
- package/src/migrations/preferences-package-data/convert-editor-settings.ts +58 -0
- package/src/migrations/preferences-package-data/{index.js → index.ts} +4 -1
- package/src/migrations/preferences-package-data/test/{convert-complementary-areas.js → convert-complementary-areas.ts} +10 -0
- package/src/migrations/preferences-package-data/test/convert-editor-settings.ts +58 -0
- package/src/test/index.jsdom.test.ts +97 -0
- package/src/test/local-storage.jsdom.test.ts +50 -0
- package/src/types.ts +43 -0
- package/CHANGELOG.md +0 -228
- package/src/create/index.js +0 -105
- package/src/index.js +0 -47
- package/src/migrations/preferences-package-data/convert-complementary-areas.js +0 -16
- package/src/migrations/preferences-package-data/convert-editor-settings.js +0 -48
- package/src/migrations/preferences-package-data/test/convert-editor-settings.js +0 -20
- /package/src/migrations/legacy-local-storage-data/test/{convert-edit-post-panels.js → convert-edit-post-panels.ts} +0 -0
- /package/src/migrations/legacy-local-storage-data/test/{move-feature-preferences.js → move-feature-preferences.ts} +0 -0
- /package/src/migrations/legacy-local-storage-data/test/{move-individual-preference.js → move-individual-preference.ts} +0 -0
- /package/src/migrations/legacy-local-storage-data/test/{move-interface-enable-items.js → move-interface-enable-items.ts} +0 -0
- /package/src/migrations/legacy-local-storage-data/test/{move-third-party-feature-preferences.js → move-third-party-feature-preferences.ts} +0 -0
- /package/src/migrations/preferences-package-data/test/{index.js → index.ts} +0 -0
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperties(exports, {
|
|
3
|
+
__esModule: { value: true },
|
|
4
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
5
|
+
});
|
|
6
|
+
// packages/preferences-persistence/src/local-storage.ts
|
|
7
|
+
/**
|
|
8
|
+
* Reads and parses a JSON value from local storage.
|
|
9
|
+
*
|
|
10
|
+
* @param key The local storage key.
|
|
11
|
+
*
|
|
12
|
+
* @return The parsed value, or `null` when the value is missing or invalid,
|
|
13
|
+
* or local storage is unavailable.
|
|
14
|
+
*/
|
|
15
|
+
function readStoredJSON(key) {
|
|
16
|
+
try {
|
|
17
|
+
const value = window.localStorage.getItem(key);
|
|
18
|
+
return value === null ? null : JSON.parse(value);
|
|
19
|
+
} catch {
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Stores a value in local storage as JSON.
|
|
25
|
+
*
|
|
26
|
+
* Failures, such as blocked storage or an exceeded quota, are ignored.
|
|
27
|
+
*
|
|
28
|
+
* @param key The local storage key.
|
|
29
|
+
* @param value The value to store.
|
|
30
|
+
*/
|
|
31
|
+
function writeStoredJSON(key, value) {
|
|
32
|
+
try {
|
|
33
|
+
window.localStorage.setItem(key, JSON.stringify(value));
|
|
34
|
+
} catch {}
|
|
35
|
+
}
|
|
36
|
+
exports.readStoredJSON = readStoredJSON;
|
|
37
|
+
exports.writeStoredJSON = writeStoredJSON;
|
|
38
|
+
|
|
39
|
+
//# sourceMappingURL=local-storage.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"local-storage.cjs","names":[],"sources":["../src/local-storage.ts"],"sourcesContent":["/**\n * Reads and parses a JSON value from local storage.\n *\n * @param key The local storage key.\n *\n * @return The parsed value, or `null` when the value is missing or invalid,\n * or local storage is unavailable.\n */\nexport function readStoredJSON( key: string ): unknown {\n\ttry {\n\t\tconst value = window.localStorage.getItem( key );\n\t\treturn value === null ? null : JSON.parse( value );\n\t} catch {\n\t\treturn null;\n\t}\n}\n\n/**\n * Stores a value in local storage as JSON.\n *\n * Failures, such as blocked storage or an exceeded quota, are ignored.\n *\n * @param key The local storage key.\n * @param value The value to store.\n */\nexport function writeStoredJSON( key: string, value: unknown ) {\n\ttry {\n\t\twindow.localStorage.setItem( key, JSON.stringify( value ) );\n\t} catch {}\n}\n"],"mappings":";;;;;;;;;;;;;;AAQA,SAAgB,eAAgB,KAAuB;CACtD,IAAI;EACH,MAAM,QAAQ,OAAO,aAAa,QAAS,GAAI;EAC/C,OAAO,UAAU,OAAO,OAAO,KAAK,MAAO,KAAM;CAClD,QAAQ;EACP,OAAO;CACR;AACD;;;;;;;;;AAUA,SAAgB,gBAAiB,KAAa,OAAiB;CAC9D,IAAI;EACH,OAAO,aAAa,QAAS,KAAK,KAAK,UAAW,KAAM,CAAE;CAC3D,QAAQ,CAAC;AACV"}
|
|
@@ -1,41 +1,52 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var __export = (target, all) => {
|
|
6
|
-
for (var name in all)
|
|
7
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
-
};
|
|
9
|
-
var __copyProps = (to, from, except, desc) => {
|
|
10
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
-
for (let key of __getOwnPropNames(from))
|
|
12
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
-
}
|
|
15
|
-
return to;
|
|
16
|
-
};
|
|
17
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
-
|
|
19
|
-
// packages/preferences-persistence/src/migrations/legacy-local-storage-data/convert-edit-post-panels.js
|
|
20
|
-
var convert_edit_post_panels_exports = {};
|
|
21
|
-
__export(convert_edit_post_panels_exports, {
|
|
22
|
-
default: () => convertEditPostPanels
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperties(exports, {
|
|
3
|
+
__esModule: { value: true },
|
|
4
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
23
5
|
});
|
|
24
|
-
|
|
6
|
+
// packages/preferences-persistence/src/migrations/legacy-local-storage-data/convert-edit-post-panels.ts
|
|
7
|
+
/**
|
|
8
|
+
* Convert the post editor's panels state from:
|
|
9
|
+
* ```
|
|
10
|
+
* {
|
|
11
|
+
* panels: {
|
|
12
|
+
* tags: {
|
|
13
|
+
* enabled: true,
|
|
14
|
+
* opened: true,
|
|
15
|
+
* },
|
|
16
|
+
* permalinks: {
|
|
17
|
+
* enabled: false,
|
|
18
|
+
* opened: false,
|
|
19
|
+
* },
|
|
20
|
+
* },
|
|
21
|
+
* }
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* to a new, more concise data structure:
|
|
25
|
+
* {
|
|
26
|
+
* inactivePanels: [
|
|
27
|
+
* 'permalinks',
|
|
28
|
+
* ],
|
|
29
|
+
* openPanels: [
|
|
30
|
+
* 'tags',
|
|
31
|
+
* ],
|
|
32
|
+
* }
|
|
33
|
+
*
|
|
34
|
+
* @param preferences A preferences object.
|
|
35
|
+
*
|
|
36
|
+
* @return The converted data.
|
|
37
|
+
*/
|
|
25
38
|
function convertEditPostPanels(preferences) {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
return convertedData;
|
|
37
|
-
},
|
|
38
|
-
{ inactivePanels: [], openPanels: [] }
|
|
39
|
-
);
|
|
39
|
+
const panels = preferences?.panels ?? {};
|
|
40
|
+
return Object.keys(panels).reduce((convertedData, panelName) => {
|
|
41
|
+
const panel = panels[panelName];
|
|
42
|
+
if (panel?.enabled === false) convertedData.inactivePanels.push(panelName);
|
|
43
|
+
if (panel?.opened === true) convertedData.openPanels.push(panelName);
|
|
44
|
+
return convertedData;
|
|
45
|
+
}, {
|
|
46
|
+
inactivePanels: [],
|
|
47
|
+
openPanels: []
|
|
48
|
+
});
|
|
40
49
|
}
|
|
41
|
-
|
|
50
|
+
exports.default = convertEditPostPanels;
|
|
51
|
+
|
|
52
|
+
//# sourceMappingURL=convert-edit-post-panels.cjs.map
|
|
@@ -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": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;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
|
+
{"version":3,"file":"convert-edit-post-panels.cjs","names":[],"sources":["../../../src/migrations/legacy-local-storage-data/convert-edit-post-panels.ts"],"sourcesContent":["import type { ScopePreferences } from '../../types';\nimport type { EditPostPanels, LegacyEditPostPanel } from './types';\n\n/**\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 preferences A preferences object.\n *\n * @return The converted data.\n */\nexport default function convertEditPostPanels(\n\tpreferences: ScopePreferences\n): EditPostPanels {\n\tconst panels = ( preferences?.panels ?? {} ) as Record<\n\t\tstring,\n\t\tLegacyEditPostPanel | undefined\n\t>;\n\treturn Object.keys( panels ).reduce< EditPostPanels >(\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"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkCA,SAAwB,sBACvB,aACiB;CACjB,MAAM,SAAW,aAAa,UAAU,CAAC;CAIzC,OAAO,OAAO,KAAM,MAAO,CAAC,CAAC,QAC1B,eAAe,cAAe;EAC/B,MAAM,QAAQ,OAAQ;EAEtB,IAAK,OAAO,YAAY,OACvB,cAAc,eAAe,KAAM,SAAU;EAG9C,IAAK,OAAO,WAAW,MACtB,cAAc,WAAW,KAAM,SAAU;EAG1C,OAAO;CACR,GACA;EAAE,gBAAgB,CAAC;EAAG,YAAY,CAAC;CAAE,CACtC;AACD"}
|
|
@@ -1,97 +1,109 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperties(exports, {
|
|
3
|
+
__esModule: { value: true },
|
|
4
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
5
|
+
});
|
|
6
|
+
// \0rolldown/runtime.js
|
|
1
7
|
var __create = Object.create;
|
|
2
8
|
var __defProp = Object.defineProperty;
|
|
3
9
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
10
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
11
|
var __getProtoOf = Object.getPrototypeOf;
|
|
6
12
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __export = (target, all) => {
|
|
8
|
-
for (var name in all)
|
|
9
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
-
};
|
|
11
13
|
var __copyProps = (to, from, except, desc) => {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
15
|
+
key = keys[i];
|
|
16
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
17
|
+
get: ((k) => from[k]).bind(null, key),
|
|
18
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
return to;
|
|
18
22
|
};
|
|
19
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
)
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
23
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
24
|
+
value: mod,
|
|
25
|
+
enumerable: true
|
|
26
|
+
}) : target, mod));
|
|
27
|
+
let __move_feature_preferences_ts = require("./move-feature-preferences.cjs");
|
|
28
|
+
__move_feature_preferences_ts = __toESM(__move_feature_preferences_ts);
|
|
29
|
+
let __move_third_party_feature_preferences_ts = require("./move-third-party-feature-preferences.cjs");
|
|
30
|
+
__move_third_party_feature_preferences_ts = __toESM(__move_third_party_feature_preferences_ts);
|
|
31
|
+
let __move_individual_preference_ts = require("./move-individual-preference.cjs");
|
|
32
|
+
__move_individual_preference_ts = __toESM(__move_individual_preference_ts);
|
|
33
|
+
let __move_interface_enable_items_ts = require("./move-interface-enable-items.cjs");
|
|
34
|
+
__move_interface_enable_items_ts = __toESM(__move_interface_enable_items_ts);
|
|
35
|
+
let __convert_edit_post_panels_ts = require("./convert-edit-post-panels.cjs");
|
|
36
|
+
__convert_edit_post_panels_ts = __toESM(__convert_edit_post_panels_ts);
|
|
37
|
+
let ______is_preferences_data_ts = require("../../is-preferences-data.cjs");
|
|
38
|
+
______is_preferences_data_ts = __toESM(______is_preferences_data_ts);
|
|
39
|
+
let ______local_storage_ts = require("../../local-storage.cjs");
|
|
40
|
+
// packages/preferences-persistence/src/migrations/legacy-local-storage-data/index.ts
|
|
41
|
+
/**
|
|
42
|
+
* Gets the legacy local storage data for a given user.
|
|
43
|
+
*
|
|
44
|
+
* @param userId The user id.
|
|
45
|
+
*
|
|
46
|
+
* @return The local storage data.
|
|
47
|
+
*/
|
|
41
48
|
function getLegacyData(userId) {
|
|
42
|
-
|
|
43
|
-
const unparsedData = window.localStorage.getItem(key);
|
|
44
|
-
return JSON.parse(unparsedData);
|
|
49
|
+
return (0, ______local_storage_ts.readStoredJSON)(`WP_DATA_USER_${userId}`);
|
|
45
50
|
}
|
|
51
|
+
/**
|
|
52
|
+
* Converts data from the old `@wordpress/data` package format.
|
|
53
|
+
*
|
|
54
|
+
* @param data The legacy data in its original format.
|
|
55
|
+
*
|
|
56
|
+
* @return The converted data or `undefined` if there was
|
|
57
|
+
* nothing to convert.
|
|
58
|
+
*/
|
|
46
59
|
function convertLegacyData(data) {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
"isPublishSidebarEnabled"
|
|
81
|
-
);
|
|
82
|
-
data = (0, import_move_individual_preference.default)(
|
|
83
|
-
data,
|
|
84
|
-
{ from: "core/edit-site", to: "core/edit-site" },
|
|
85
|
-
"editorMode"
|
|
86
|
-
);
|
|
87
|
-
return data?.["core/preferences"]?.preferences;
|
|
60
|
+
if (!data) return;
|
|
61
|
+
data = (0, __move_feature_preferences_ts.default)(data, "core/edit-widgets");
|
|
62
|
+
data = (0, __move_feature_preferences_ts.default)(data, "core/customize-widgets");
|
|
63
|
+
data = (0, __move_feature_preferences_ts.default)(data, "core/edit-post");
|
|
64
|
+
data = (0, __move_feature_preferences_ts.default)(data, "core/edit-site");
|
|
65
|
+
data = (0, __move_third_party_feature_preferences_ts.default)(data);
|
|
66
|
+
data = (0, __move_interface_enable_items_ts.default)(data);
|
|
67
|
+
data = (0, __move_individual_preference_ts.default)(data, {
|
|
68
|
+
from: "core/edit-post",
|
|
69
|
+
to: "core/edit-post"
|
|
70
|
+
}, "hiddenBlockTypes");
|
|
71
|
+
data = (0, __move_individual_preference_ts.default)(data, {
|
|
72
|
+
from: "core/edit-post",
|
|
73
|
+
to: "core/edit-post"
|
|
74
|
+
}, "editorMode");
|
|
75
|
+
data = (0, __move_individual_preference_ts.default)(data, {
|
|
76
|
+
from: "core/edit-post",
|
|
77
|
+
to: "core/edit-post"
|
|
78
|
+
}, "panels", __convert_edit_post_panels_ts.default);
|
|
79
|
+
data = (0, __move_individual_preference_ts.default)(data, {
|
|
80
|
+
from: "core/editor",
|
|
81
|
+
to: "core"
|
|
82
|
+
}, "isPublishSidebarEnabled");
|
|
83
|
+
data = (0, __move_individual_preference_ts.default)(data, {
|
|
84
|
+
from: "core/edit-post",
|
|
85
|
+
to: "core"
|
|
86
|
+
}, "isPublishSidebarEnabled");
|
|
87
|
+
data = (0, __move_individual_preference_ts.default)(data, {
|
|
88
|
+
from: "core/edit-site",
|
|
89
|
+
to: "core/edit-site"
|
|
90
|
+
}, "editorMode");
|
|
91
|
+
const preferences = data?.["core/preferences"]?.preferences;
|
|
92
|
+
return (0, ______is_preferences_data_ts.default)(preferences) ? preferences : void 0;
|
|
88
93
|
}
|
|
94
|
+
/**
|
|
95
|
+
* Gets the legacy local storage data for the given user and returns the
|
|
96
|
+
* data converted to the new format.
|
|
97
|
+
*
|
|
98
|
+
* @param userId The user id.
|
|
99
|
+
*
|
|
100
|
+
* @return The converted data or undefined if no local
|
|
101
|
+
* storage data could be found.
|
|
102
|
+
*/
|
|
89
103
|
function convertLegacyLocalStorageData(userId) {
|
|
90
|
-
|
|
91
|
-
return convertLegacyData(data);
|
|
104
|
+
return convertLegacyData(getLegacyData(userId));
|
|
92
105
|
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
//# sourceMappingURL=index.cjs.map
|
|
106
|
+
exports.convertLegacyData = convertLegacyData;
|
|
107
|
+
exports.default = convertLegacyLocalStorageData;
|
|
108
|
+
|
|
109
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -1,7 +1 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/migrations/legacy-local-storage-data/index.js"],
|
|
4
|
-
"sourcesContent": ["import 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": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sCAAmC;AACnC,kDAA6C;AAC7C,wCAAqC;AACrC,yCAAqC;AACrC,sCAAkC;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,aAAO,gCAAAA,SAAwB,MAAM,mBAAoB;AACzD,aAAO,gCAAAA,SAAwB,MAAM,wBAAyB;AAC9D,aAAO,gCAAAA,SAAwB,MAAM,gBAAiB;AACtD,aAAO,gCAAAA,SAAwB,MAAM,gBAAiB;AAItD,aAAO,4CAAAC,SAAkC,IAAK;AAI9C,aAAO,mCAAAC,SAA0B,IAAK;AAItC,aAAO,kCAAAC;AAAA,IACN;AAAA,IACA,EAAE,MAAM,kBAAkB,IAAI,iBAAiB;AAAA,IAC/C;AAAA,EACD;AACA,aAAO,kCAAAA;AAAA,IACN;AAAA,IACA,EAAE,MAAM,kBAAkB,IAAI,iBAAiB;AAAA,IAC/C;AAAA,EACD;AACA,aAAO,kCAAAA;AAAA,IACN;AAAA,IACA,EAAE,MAAM,kBAAkB,IAAI,iBAAiB;AAAA,IAC/C;AAAA,IACA,gCAAAC;AAAA,EACD;AACA,aAAO,kCAAAD;AAAA,IACN;AAAA,IACA,EAAE,MAAM,eAAe,IAAI,OAAO;AAAA,IAClC;AAAA,EACD;AACA,aAAO,kCAAAA;AAAA,IACN;AAAA,IACA,EAAE,MAAM,kBAAkB,IAAI,OAAO;AAAA,IACrC;AAAA,EACD;AACA,aAAO,kCAAAA;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": ["moveFeaturePreferences", "moveThirdPartyFeaturePreferences", "moveInterfaceEnableItems", "moveIndividualPreference", "convertEditPostPanels"]
|
|
7
|
-
}
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["readStoredJSON","moveFeaturePreferences","moveThirdPartyFeaturePreferences","moveInterfaceEnableItems","moveIndividualPreference","convertEditPostPanels","isPreferencesData"],"sources":["../../../src/migrations/legacy-local-storage-data/index.ts"],"sourcesContent":["import 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';\nimport isPreferencesData from '../../is-preferences-data';\nimport { readStoredJSON } from '../../local-storage';\nimport type { ScopedPreferences } from '../../types';\nimport type { LegacyData } from './types';\n\n/**\n * Gets the legacy local storage data for a given user.\n *\n * @param userId The user id.\n *\n * @return The local storage data.\n */\nfunction getLegacyData( userId: string | number ): LegacyData | null {\n\treturn readStoredJSON( `WP_DATA_USER_${ userId }` ) as LegacyData | null;\n}\n\n/**\n * Converts data from the old `@wordpress/data` package format.\n *\n * @param data The legacy data in its original format.\n *\n * @return The converted data or `undefined` if there was\n * nothing to convert.\n */\nexport function convertLegacyData(\n\tdata: LegacyData | null | undefined\n): ScopedPreferences | undefined {\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\tconst preferences = data?.[ 'core/preferences' ]?.preferences;\n\treturn isPreferencesData( preferences ) ? preferences : undefined;\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 userId The user id.\n *\n * @return The converted data or undefined if no local\n * storage data could be found.\n */\nexport default function convertLegacyLocalStorageData(\n\tuserId: string | number\n): ScopedPreferences | undefined {\n\tconst data = getLegacyData( userId );\n\treturn convertLegacyData( data );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiBA,SAAS,cAAe,QAA6C;CACpE,QAAA,GAAOA,uBAAAA,eAAAA,CAAgB,gBAAiB,QAAU;AACnD;;;;;;;;;AAUA,SAAgB,kBACf,MACgC;CAChC,IAAK,CAAE,MACN;CAKD,QAAA,GAAOC,8BAAAA,QAAAA,CAAwB,MAAM,mBAAoB;CACzD,QAAA,GAAOA,8BAAAA,QAAAA,CAAwB,MAAM,wBAAyB;CAC9D,QAAA,GAAOA,8BAAAA,QAAAA,CAAwB,MAAM,gBAAiB;CACtD,QAAA,GAAOA,8BAAAA,QAAAA,CAAwB,MAAM,gBAAiB;CAItD,QAAA,GAAOC,0CAAAA,QAAAA,CAAkC,IAAK;CAI9C,QAAA,GAAOC,iCAAAA,QAAAA,CAA0B,IAAK;CAItC,QAAA,GAAOC,gCAAAA,QAAAA,CACN,MACA;EAAE,MAAM;EAAkB,IAAI;CAAiB,GAC/C,kBACD;CACA,QAAA,GAAOA,gCAAAA,QAAAA,CACN,MACA;EAAE,MAAM;EAAkB,IAAI;CAAiB,GAC/C,YACD;CACA,QAAA,GAAOA,gCAAAA,QAAAA,CACN,MACA;EAAE,MAAM;EAAkB,IAAI;CAAiB,GAC/C,UACAC,8BAAAA,OACD;CACA,QAAA,GAAOD,gCAAAA,QAAAA,CACN,MACA;EAAE,MAAM;EAAe,IAAI;CAAO,GAClC,yBACD;CACA,QAAA,GAAOA,gCAAAA,QAAAA,CACN,MACA;EAAE,MAAM;EAAkB,IAAI;CAAO,GACrC,yBACD;CACA,QAAA,GAAOA,gCAAAA,QAAAA,CACN,MACA;EAAE,MAAM;EAAkB,IAAI;CAAiB,GAC/C,YACD;CAIA,MAAM,cAAc,OAAQ,mBAAoB,EAAE;CAClD,QAAA,GAAOE,6BAAAA,QAAAA,CAAmB,WAAY,IAAI,cAAc,KAAA;AACzD;;;;;;;;;;AAWA,SAAwB,8BACvB,QACgC;CAEhC,OAAO,kBADM,cAAe,MACC,CAAE;AAChC"}
|
|
@@ -1,80 +1,109 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var __export = (target, all) => {
|
|
6
|
-
for (var name in all)
|
|
7
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
-
};
|
|
9
|
-
var __copyProps = (to, from, except, desc) => {
|
|
10
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
-
for (let key of __getOwnPropNames(from))
|
|
12
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
-
}
|
|
15
|
-
return to;
|
|
16
|
-
};
|
|
17
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
-
|
|
19
|
-
// packages/preferences-persistence/src/migrations/legacy-local-storage-data/move-feature-preferences.js
|
|
20
|
-
var move_feature_preferences_exports = {};
|
|
21
|
-
__export(move_feature_preferences_exports, {
|
|
22
|
-
default: () => moveFeaturePreferences
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperties(exports, {
|
|
3
|
+
__esModule: { value: true },
|
|
4
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
23
5
|
});
|
|
24
|
-
|
|
6
|
+
// packages/preferences-persistence/src/migrations/legacy-local-storage-data/move-feature-preferences.ts
|
|
7
|
+
/**
|
|
8
|
+
* Move the 'features' object in local storage from the sourceStoreName to the
|
|
9
|
+
* preferences store data structure.
|
|
10
|
+
*
|
|
11
|
+
* Previously, editors used a data structure like this for feature preferences:
|
|
12
|
+
* ```js
|
|
13
|
+
* {
|
|
14
|
+
* 'core/edit-post': {
|
|
15
|
+
* preferences: {
|
|
16
|
+
* features; {
|
|
17
|
+
* topToolbar: true,
|
|
18
|
+
* // ... other boolean 'feature' preferences
|
|
19
|
+
* },
|
|
20
|
+
* },
|
|
21
|
+
* },
|
|
22
|
+
* }
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* And for a while these feature preferences lived in the interface package:
|
|
26
|
+
* ```js
|
|
27
|
+
* {
|
|
28
|
+
* 'core/interface': {
|
|
29
|
+
* preferences: {
|
|
30
|
+
* features: {
|
|
31
|
+
* 'core/edit-post': {
|
|
32
|
+
* topToolbar: true
|
|
33
|
+
* }
|
|
34
|
+
* }
|
|
35
|
+
* }
|
|
36
|
+
* }
|
|
37
|
+
* }
|
|
38
|
+
* ```
|
|
39
|
+
*
|
|
40
|
+
* In the preferences store, 'features' aren't considered special, they're
|
|
41
|
+
* merged to the root level of the scope along with other preferences:
|
|
42
|
+
* ```js
|
|
43
|
+
* {
|
|
44
|
+
* 'core/preferences': {
|
|
45
|
+
* preferences: {
|
|
46
|
+
* 'core/edit-post': {
|
|
47
|
+
* topToolbar: true,
|
|
48
|
+
* // ... any other preferences.
|
|
49
|
+
* }
|
|
50
|
+
* }
|
|
51
|
+
* }
|
|
52
|
+
* }
|
|
53
|
+
* ```
|
|
54
|
+
*
|
|
55
|
+
* This function handles moving from either the source store or the interface
|
|
56
|
+
* store to the preferences data structure.
|
|
57
|
+
*
|
|
58
|
+
* @param state The state before migration.
|
|
59
|
+
* @param sourceStoreName The name of the store that has persisted
|
|
60
|
+
* preferences to migrate to the preferences
|
|
61
|
+
* package.
|
|
62
|
+
* @return The migrated state
|
|
63
|
+
*/
|
|
25
64
|
function moveFeaturePreferences(state, sourceStoreName) {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
}
|
|
68
|
-
return {
|
|
69
|
-
...state,
|
|
70
|
-
[preferencesStoreName]: {
|
|
71
|
-
preferences: {
|
|
72
|
-
...existingPreferences,
|
|
73
|
-
[sourceStoreName]: featuresToMigrate
|
|
74
|
-
}
|
|
75
|
-
},
|
|
76
|
-
...updatedInterfaceState,
|
|
77
|
-
...updatedSourceState
|
|
78
|
-
};
|
|
65
|
+
const preferencesStoreName = "core/preferences";
|
|
66
|
+
const interfaceStoreName = "core/interface";
|
|
67
|
+
const interfaceFeatures = state?.[interfaceStoreName]?.preferences?.features?.[sourceStoreName];
|
|
68
|
+
const sourceFeatures = state?.[sourceStoreName]?.preferences?.features;
|
|
69
|
+
const featuresToMigrate = interfaceFeatures ? interfaceFeatures : sourceFeatures;
|
|
70
|
+
if (!featuresToMigrate) return state;
|
|
71
|
+
const existingPreferences = state?.[preferencesStoreName]?.preferences;
|
|
72
|
+
if (existingPreferences?.[sourceStoreName]) return state;
|
|
73
|
+
let updatedInterfaceState;
|
|
74
|
+
if (interfaceFeatures) {
|
|
75
|
+
const otherInterfaceState = state?.[interfaceStoreName];
|
|
76
|
+
const otherInterfaceScopes = state?.[interfaceStoreName]?.preferences?.features;
|
|
77
|
+
updatedInterfaceState = { [interfaceStoreName]: {
|
|
78
|
+
...otherInterfaceState,
|
|
79
|
+
preferences: { features: {
|
|
80
|
+
...otherInterfaceScopes,
|
|
81
|
+
[sourceStoreName]: void 0
|
|
82
|
+
} }
|
|
83
|
+
} };
|
|
84
|
+
}
|
|
85
|
+
let updatedSourceState;
|
|
86
|
+
if (sourceFeatures) {
|
|
87
|
+
const otherSourceState = state?.[sourceStoreName];
|
|
88
|
+
const sourcePreferences = state?.[sourceStoreName]?.preferences;
|
|
89
|
+
updatedSourceState = { [sourceStoreName]: {
|
|
90
|
+
...otherSourceState,
|
|
91
|
+
preferences: {
|
|
92
|
+
...sourcePreferences,
|
|
93
|
+
features: void 0
|
|
94
|
+
}
|
|
95
|
+
} };
|
|
96
|
+
}
|
|
97
|
+
return {
|
|
98
|
+
...state,
|
|
99
|
+
[preferencesStoreName]: { preferences: {
|
|
100
|
+
...existingPreferences,
|
|
101
|
+
[sourceStoreName]: featuresToMigrate
|
|
102
|
+
} },
|
|
103
|
+
...updatedInterfaceState,
|
|
104
|
+
...updatedSourceState
|
|
105
|
+
};
|
|
79
106
|
}
|
|
80
|
-
|
|
107
|
+
exports.default = moveFeaturePreferences;
|
|
108
|
+
|
|
109
|
+
//# sourceMappingURL=move-feature-preferences.cjs.map
|
|
@@ -1,7 +1 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/migrations/legacy-local-storage-data/move-feature-preferences.js"],
|
|
4
|
-
"sourcesContent": ["/**\n * Move the 'features' object in local storage from the sourceStoreName to the\n * preferences store data structure.\n *\n * Previously, editors used a data structure like this for feature preferences:\n * ```js\n * {\n * 'core/edit-post': {\n * preferences: {\n * features; {\n * topToolbar: true,\n * // ... other boolean 'feature' preferences\n * },\n * },\n * },\n * }\n * ```\n *\n * And for a while these feature preferences lived in the interface package:\n * ```js\n * {\n * 'core/interface': {\n * preferences: {\n * features: {\n * 'core/edit-post': {\n * topToolbar: true\n * }\n * }\n * }\n * }\n * }\n * ```\n *\n * In the preferences store, 'features' aren't considered special, they're\n * merged to the root level of the scope along with other preferences:\n * ```js\n * {\n * 'core/preferences': {\n * preferences: {\n * 'core/edit-post': {\n * topToolbar: true,\n * // ... any other preferences.\n * }\n * }\n * }\n * }\n * ```\n *\n * This function handles moving from either the source store or the interface\n * store to the preferences data structure.\n *\n * @param {Object} state The state before migration.\n * @param {string} sourceStoreName The name of the store that has persisted\n * preferences to migrate to the preferences\n * package.\n * @return {Object} The migrated state\n */\nexport default function moveFeaturePreferences( state, sourceStoreName ) {\n\tconst preferencesStoreName = 'core/preferences';\n\tconst interfaceStoreName = 'core/interface';\n\n\t// Features most recently (and briefly) lived in the interface package.\n\t// If data exists there, prioritize using that for the migration. If not\n\t// also check the original package as the user may have updated from an\n\t// older block editor version.\n\tconst interfaceFeatures =\n\t\tstate?.[ interfaceStoreName ]?.preferences?.features?.[\n\t\t\tsourceStoreName\n\t\t];\n\tconst sourceFeatures = state?.[ sourceStoreName ]?.preferences?.features;\n\tconst featuresToMigrate = interfaceFeatures\n\t\t? interfaceFeatures\n\t\t: sourceFeatures;\n\n\tif ( ! featuresToMigrate ) {\n\t\treturn state;\n\t}\n\n\tconst existingPreferences = state?.[ preferencesStoreName ]?.preferences;\n\n\t// Avoid migrating features again if they've previously been migrated.\n\tif ( existingPreferences?.[ sourceStoreName ] ) {\n\t\treturn state;\n\t}\n\n\tlet updatedInterfaceState;\n\tif ( interfaceFeatures ) {\n\t\tconst otherInterfaceState = state?.[ interfaceStoreName ];\n\t\tconst otherInterfaceScopes =\n\t\t\tstate?.[ interfaceStoreName ]?.preferences?.features;\n\n\t\tupdatedInterfaceState = {\n\t\t\t[ interfaceStoreName ]: {\n\t\t\t\t...otherInterfaceState,\n\t\t\t\tpreferences: {\n\t\t\t\t\tfeatures: {\n\t\t\t\t\t\t...otherInterfaceScopes,\n\t\t\t\t\t\t[ sourceStoreName ]: undefined,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t};\n\t}\n\n\tlet updatedSourceState;\n\tif ( sourceFeatures ) {\n\t\tconst otherSourceState = state?.[ sourceStoreName ];\n\t\tconst sourcePreferences = state?.[ sourceStoreName ]?.preferences;\n\n\t\tupdatedSourceState = {\n\t\t\t[ sourceStoreName ]: {\n\t\t\t\t...otherSourceState,\n\t\t\t\tpreferences: {\n\t\t\t\t\t...sourcePreferences,\n\t\t\t\t\tfeatures: undefined,\n\t\t\t\t},\n\t\t\t},\n\t\t};\n\t}\n\n\t// Set the feature values in the interface store, the features\n\t// object is keyed by 'scope', which matches the store name for\n\t// the source.\n\treturn {\n\t\t...state,\n\t\t[ preferencesStoreName ]: {\n\t\t\tpreferences: {\n\t\t\t\t...existingPreferences,\n\t\t\t\t[ sourceStoreName ]: featuresToMigrate,\n\t\t\t},\n\t\t},\n\t\t...updatedInterfaceState,\n\t\t...updatedSourceState,\n\t};\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAyDe,SAAR,uBAAyC,OAAO,iBAAkB;AACxE,QAAM,uBAAuB;AAC7B,QAAM,qBAAqB;AAM3B,QAAM,oBACL,QAAS,kBAAmB,GAAG,aAAa,WAC3C,eACD;AACD,QAAM,iBAAiB,QAAS,eAAgB,GAAG,aAAa;AAChE,QAAM,oBAAoB,oBACvB,oBACA;AAEH,MAAK,CAAE,mBAAoB;AAC1B,WAAO;AAAA,EACR;AAEA,QAAM,sBAAsB,QAAS,oBAAqB,GAAG;AAG7D,MAAK,sBAAuB,eAAgB,GAAI;AAC/C,WAAO;AAAA,EACR;AAEA,MAAI;AACJ,MAAK,mBAAoB;AACxB,UAAM,sBAAsB,QAAS,kBAAmB;AACxD,UAAM,uBACL,QAAS,kBAAmB,GAAG,aAAa;AAE7C,4BAAwB;AAAA,MACvB,CAAE,kBAAmB,GAAG;AAAA,QACvB,GAAG;AAAA,QACH,aAAa;AAAA,UACZ,UAAU;AAAA,YACT,GAAG;AAAA,YACH,CAAE,eAAgB,GAAG;AAAA,UACtB;AAAA,QACD;AAAA,MACD;AAAA,IACD;AAAA,EACD;AAEA,MAAI;AACJ,MAAK,gBAAiB;AACrB,UAAM,mBAAmB,QAAS,eAAgB;AAClD,UAAM,oBAAoB,QAAS,eAAgB,GAAG;AAEtD,yBAAqB;AAAA,MACpB,CAAE,eAAgB,GAAG;AAAA,QACpB,GAAG;AAAA,QACH,aAAa;AAAA,UACZ,GAAG;AAAA,UACH,UAAU;AAAA,QACX;AAAA,MACD;AAAA,IACD;AAAA,EACD;AAKA,SAAO;AAAA,IACN,GAAG;AAAA,IACH,CAAE,oBAAqB,GAAG;AAAA,MACzB,aAAa;AAAA,QACZ,GAAG;AAAA,QACH,CAAE,eAAgB,GAAG;AAAA,MACtB;AAAA,IACD;AAAA,IACA,GAAG;AAAA,IACH,GAAG;AAAA,EACJ;AACD;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
1
|
+
{"version":3,"file":"move-feature-preferences.cjs","names":[],"sources":["../../../src/migrations/legacy-local-storage-data/move-feature-preferences.ts"],"sourcesContent":["import type { FeaturePreferences, LegacyData } from './types';\n\n/**\n * Move the 'features' object in local storage from the sourceStoreName to the\n * preferences store data structure.\n *\n * Previously, editors used a data structure like this for feature preferences:\n * ```js\n * {\n * 'core/edit-post': {\n * preferences: {\n * features; {\n * topToolbar: true,\n * // ... other boolean 'feature' preferences\n * },\n * },\n * },\n * }\n * ```\n *\n * And for a while these feature preferences lived in the interface package:\n * ```js\n * {\n * 'core/interface': {\n * preferences: {\n * features: {\n * 'core/edit-post': {\n * topToolbar: true\n * }\n * }\n * }\n * }\n * }\n * ```\n *\n * In the preferences store, 'features' aren't considered special, they're\n * merged to the root level of the scope along with other preferences:\n * ```js\n * {\n * 'core/preferences': {\n * preferences: {\n * 'core/edit-post': {\n * topToolbar: true,\n * // ... any other preferences.\n * }\n * }\n * }\n * }\n * ```\n *\n * This function handles moving from either the source store or the interface\n * store to the preferences data structure.\n *\n * @param state The state before migration.\n * @param sourceStoreName The name of the store that has persisted\n * preferences to migrate to the preferences\n * package.\n * @return The migrated state\n */\nexport default function moveFeaturePreferences(\n\tstate: LegacyData,\n\tsourceStoreName: string\n): LegacyData {\n\tconst preferencesStoreName = 'core/preferences';\n\tconst interfaceStoreName = 'core/interface';\n\n\t// Features most recently (and briefly) lived in the interface package.\n\t// If data exists there, prioritize using that for the migration. If not\n\t// also check the original package as the user may have updated from an\n\t// older block editor version.\n\tconst interfaceFeatures =\n\t\tstate?.[ interfaceStoreName ]?.preferences?.features?.[\n\t\t\tsourceStoreName\n\t\t];\n\tconst sourceFeatures = state?.[ sourceStoreName ]?.preferences?.features as\n\t\tFeaturePreferences | undefined;\n\tconst featuresToMigrate = interfaceFeatures\n\t\t? interfaceFeatures\n\t\t: sourceFeatures;\n\n\tif ( ! featuresToMigrate ) {\n\t\treturn state;\n\t}\n\n\tconst existingPreferences = state?.[ preferencesStoreName ]?.preferences;\n\n\t// Avoid migrating features again if they've previously been migrated.\n\tif ( existingPreferences?.[ sourceStoreName ] ) {\n\t\treturn state;\n\t}\n\n\tlet updatedInterfaceState;\n\tif ( interfaceFeatures ) {\n\t\tconst otherInterfaceState = state?.[ interfaceStoreName ];\n\t\tconst otherInterfaceScopes =\n\t\t\tstate?.[ interfaceStoreName ]?.preferences?.features;\n\n\t\tupdatedInterfaceState = {\n\t\t\t[ interfaceStoreName ]: {\n\t\t\t\t...otherInterfaceState,\n\t\t\t\tpreferences: {\n\t\t\t\t\tfeatures: {\n\t\t\t\t\t\t...otherInterfaceScopes,\n\t\t\t\t\t\t[ sourceStoreName ]: undefined,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t};\n\t}\n\n\tlet updatedSourceState;\n\tif ( sourceFeatures ) {\n\t\tconst otherSourceState = state?.[ sourceStoreName ];\n\t\tconst sourcePreferences = state?.[ sourceStoreName ]?.preferences;\n\n\t\tupdatedSourceState = {\n\t\t\t[ sourceStoreName ]: {\n\t\t\t\t...otherSourceState,\n\t\t\t\tpreferences: {\n\t\t\t\t\t...sourcePreferences,\n\t\t\t\t\tfeatures: undefined,\n\t\t\t\t},\n\t\t\t},\n\t\t};\n\t}\n\n\t// Set the feature values in the interface store, the features\n\t// object is keyed by 'scope', which matches the store name for\n\t// the source.\n\treturn {\n\t\t...state,\n\t\t[ preferencesStoreName ]: {\n\t\t\tpreferences: {\n\t\t\t\t...existingPreferences,\n\t\t\t\t[ sourceStoreName ]: featuresToMigrate,\n\t\t\t},\n\t\t},\n\t\t...updatedInterfaceState,\n\t\t...updatedSourceState,\n\t};\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2DA,SAAwB,uBACvB,OACA,iBACa;CACb,MAAM,uBAAuB;CAC7B,MAAM,qBAAqB;CAM3B,MAAM,oBACL,QAAS,mBAAoB,EAAE,aAAa,WAC3C;CAEF,MAAM,iBAAiB,QAAS,gBAAiB,EAAE,aAAa;CAEhE,MAAM,oBAAoB,oBACvB,oBACA;CAEH,IAAK,CAAE,mBACN,OAAO;CAGR,MAAM,sBAAsB,QAAS,qBAAsB,EAAE;CAG7D,IAAK,sBAAuB,kBAC3B,OAAO;CAGR,IAAI;CACJ,IAAK,mBAAoB;EACxB,MAAM,sBAAsB,QAAS;EACrC,MAAM,uBACL,QAAS,mBAAoB,EAAE,aAAa;EAE7C,wBAAwB,GACrB,qBAAsB;GACvB,GAAG;GACH,aAAa,EACZ,UAAU;IACT,GAAG;KACD,kBAAmB,KAAA;GACtB,EACD;EACD,EACD;CACD;CAEA,IAAI;CACJ,IAAK,gBAAiB;EACrB,MAAM,mBAAmB,QAAS;EAClC,MAAM,oBAAoB,QAAS,gBAAiB,EAAE;EAEtD,qBAAqB,GAClB,kBAAmB;GACpB,GAAG;GACH,aAAa;IACZ,GAAG;IACH,UAAU,KAAA;GACX;EACD,EACD;CACD;CAKA,OAAO;EACN,GAAG;GACD,uBAAwB,EACzB,aAAa;GACZ,GAAG;IACD,kBAAmB;EACtB,EACD;EACA,GAAG;EACH,GAAG;CACJ;AACD"}
|