@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,104 +1,95 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var
|
|
4
|
-
Object.
|
|
5
|
-
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
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
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
var legacy_local_storage_data_exports = {};
|
|
29
|
+
__export(legacy_local_storage_data_exports, {
|
|
30
|
+
convertLegacyData: () => convertLegacyData,
|
|
31
|
+
default: () => convertLegacyLocalStorageData
|
|
6
32
|
});
|
|
7
|
-
exports
|
|
8
|
-
|
|
9
|
-
var
|
|
10
|
-
var
|
|
11
|
-
var
|
|
12
|
-
var
|
|
13
|
-
var _convertEditPostPanels = _interopRequireDefault(require("./convert-edit-post-panels"));
|
|
14
|
-
/**
|
|
15
|
-
* Internal dependencies
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Gets the legacy local storage data for a given user.
|
|
20
|
-
*
|
|
21
|
-
* @param {string | number} userId The user id.
|
|
22
|
-
*
|
|
23
|
-
* @return {Object | null} The local storage data.
|
|
24
|
-
*/
|
|
33
|
+
module.exports = __toCommonJS(legacy_local_storage_data_exports);
|
|
34
|
+
var import_move_feature_preferences = __toESM(require("./move-feature-preferences"));
|
|
35
|
+
var import_move_third_party_feature_preferences = __toESM(require("./move-third-party-feature-preferences"));
|
|
36
|
+
var import_move_individual_preference = __toESM(require("./move-individual-preference"));
|
|
37
|
+
var import_move_interface_enable_items = __toESM(require("./move-interface-enable-items"));
|
|
38
|
+
var import_convert_edit_post_panels = __toESM(require("./convert-edit-post-panels"));
|
|
25
39
|
function getLegacyData(userId) {
|
|
26
40
|
const key = `WP_DATA_USER_${userId}`;
|
|
27
41
|
const unparsedData = window.localStorage.getItem(key);
|
|
28
42
|
return JSON.parse(unparsedData);
|
|
29
43
|
}
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Converts data from the old `@wordpress/data` package format.
|
|
33
|
-
*
|
|
34
|
-
* @param {Object | null | undefined} data The legacy data in its original format.
|
|
35
|
-
*
|
|
36
|
-
* @return {Object | undefined} The converted data or `undefined` if there was
|
|
37
|
-
* nothing to convert.
|
|
38
|
-
*/
|
|
39
44
|
function convertLegacyData(data) {
|
|
40
45
|
if (!data) {
|
|
41
46
|
return;
|
|
42
47
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
data = (0,
|
|
47
|
-
data = (0,
|
|
48
|
-
data = (0,
|
|
49
|
-
data = (0,
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
data = (0,
|
|
66
|
-
|
|
67
|
-
to:
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
data = (0, _moveIndividualPreference.default)(data, {
|
|
82
|
-
from: 'core/edit-site',
|
|
83
|
-
to: 'core/edit-site'
|
|
84
|
-
}, 'editorMode');
|
|
85
|
-
|
|
86
|
-
// The new system is only concerned with persisting
|
|
87
|
-
// 'core/preferences' preferences reducer, so only return that.
|
|
88
|
-
return data?.['core/preferences']?.preferences;
|
|
48
|
+
data = (0, import_move_feature_preferences.default)(data, "core/edit-widgets");
|
|
49
|
+
data = (0, import_move_feature_preferences.default)(data, "core/customize-widgets");
|
|
50
|
+
data = (0, import_move_feature_preferences.default)(data, "core/edit-post");
|
|
51
|
+
data = (0, import_move_feature_preferences.default)(data, "core/edit-site");
|
|
52
|
+
data = (0, import_move_third_party_feature_preferences.default)(data);
|
|
53
|
+
data = (0, import_move_interface_enable_items.default)(data);
|
|
54
|
+
data = (0, import_move_individual_preference.default)(
|
|
55
|
+
data,
|
|
56
|
+
{ from: "core/edit-post", to: "core/edit-post" },
|
|
57
|
+
"hiddenBlockTypes"
|
|
58
|
+
);
|
|
59
|
+
data = (0, import_move_individual_preference.default)(
|
|
60
|
+
data,
|
|
61
|
+
{ from: "core/edit-post", to: "core/edit-post" },
|
|
62
|
+
"editorMode"
|
|
63
|
+
);
|
|
64
|
+
data = (0, import_move_individual_preference.default)(
|
|
65
|
+
data,
|
|
66
|
+
{ from: "core/edit-post", to: "core/edit-post" },
|
|
67
|
+
"panels",
|
|
68
|
+
import_convert_edit_post_panels.default
|
|
69
|
+
);
|
|
70
|
+
data = (0, import_move_individual_preference.default)(
|
|
71
|
+
data,
|
|
72
|
+
{ from: "core/editor", to: "core" },
|
|
73
|
+
"isPublishSidebarEnabled"
|
|
74
|
+
);
|
|
75
|
+
data = (0, import_move_individual_preference.default)(
|
|
76
|
+
data,
|
|
77
|
+
{ from: "core/edit-post", to: "core" },
|
|
78
|
+
"isPublishSidebarEnabled"
|
|
79
|
+
);
|
|
80
|
+
data = (0, import_move_individual_preference.default)(
|
|
81
|
+
data,
|
|
82
|
+
{ from: "core/edit-site", to: "core/edit-site" },
|
|
83
|
+
"editorMode"
|
|
84
|
+
);
|
|
85
|
+
return data?.["core/preferences"]?.preferences;
|
|
89
86
|
}
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* Gets the legacy local storage data for the given user and returns the
|
|
93
|
-
* data converted to the new format.
|
|
94
|
-
*
|
|
95
|
-
* @param {string | number} userId The user id.
|
|
96
|
-
*
|
|
97
|
-
* @return {Object | undefined} The converted data or undefined if no local
|
|
98
|
-
* storage data could be found.
|
|
99
|
-
*/
|
|
100
87
|
function convertLegacyLocalStorageData(userId) {
|
|
101
88
|
const data = getLegacyData(userId);
|
|
102
89
|
return convertLegacyData(data);
|
|
103
90
|
}
|
|
104
|
-
|
|
91
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
92
|
+
0 && (module.exports = {
|
|
93
|
+
convertLegacyData
|
|
94
|
+
});
|
|
95
|
+
//# 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
|
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G;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,74 +1,28 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.
|
|
4
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
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
|
+
var move_feature_preferences_exports = {};
|
|
19
|
+
__export(move_feature_preferences_exports, {
|
|
20
|
+
default: () => moveFeaturePreferences
|
|
5
21
|
});
|
|
6
|
-
exports
|
|
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 {Object} state The state before migration.
|
|
59
|
-
* @param {string} sourceStoreName The name of the store that has persisted
|
|
60
|
-
* preferences to migrate to the preferences
|
|
61
|
-
* package.
|
|
62
|
-
* @return {Object} The migrated state
|
|
63
|
-
*/
|
|
22
|
+
module.exports = __toCommonJS(move_feature_preferences_exports);
|
|
64
23
|
function moveFeaturePreferences(state, sourceStoreName) {
|
|
65
|
-
const preferencesStoreName =
|
|
66
|
-
const interfaceStoreName =
|
|
67
|
-
|
|
68
|
-
// Features most recently (and briefly) lived in the interface package.
|
|
69
|
-
// If data exists there, prioritize using that for the migration. If not
|
|
70
|
-
// also check the original package as the user may have updated from an
|
|
71
|
-
// older block editor version.
|
|
24
|
+
const preferencesStoreName = "core/preferences";
|
|
25
|
+
const interfaceStoreName = "core/interface";
|
|
72
26
|
const interfaceFeatures = state?.[interfaceStoreName]?.preferences?.features?.[sourceStoreName];
|
|
73
27
|
const sourceFeatures = state?.[sourceStoreName]?.preferences?.features;
|
|
74
28
|
const featuresToMigrate = interfaceFeatures ? interfaceFeatures : sourceFeatures;
|
|
@@ -76,8 +30,6 @@ function moveFeaturePreferences(state, sourceStoreName) {
|
|
|
76
30
|
return state;
|
|
77
31
|
}
|
|
78
32
|
const existingPreferences = state?.[preferencesStoreName]?.preferences;
|
|
79
|
-
|
|
80
|
-
// Avoid migrating features again if they've previously been migrated.
|
|
81
33
|
if (existingPreferences?.[sourceStoreName]) {
|
|
82
34
|
return state;
|
|
83
35
|
}
|
|
@@ -91,7 +43,7 @@ function moveFeaturePreferences(state, sourceStoreName) {
|
|
|
91
43
|
preferences: {
|
|
92
44
|
features: {
|
|
93
45
|
...otherInterfaceScopes,
|
|
94
|
-
[sourceStoreName]:
|
|
46
|
+
[sourceStoreName]: void 0
|
|
95
47
|
}
|
|
96
48
|
}
|
|
97
49
|
}
|
|
@@ -106,15 +58,11 @@ function moveFeaturePreferences(state, sourceStoreName) {
|
|
|
106
58
|
...otherSourceState,
|
|
107
59
|
preferences: {
|
|
108
60
|
...sourcePreferences,
|
|
109
|
-
features:
|
|
61
|
+
features: void 0
|
|
110
62
|
}
|
|
111
63
|
}
|
|
112
64
|
};
|
|
113
65
|
}
|
|
114
|
-
|
|
115
|
-
// Set the feature values in the interface store, the features
|
|
116
|
-
// object is keyed by 'scope', which matches the store name for
|
|
117
|
-
// the source.
|
|
118
66
|
return {
|
|
119
67
|
...state,
|
|
120
68
|
[preferencesStoreName]: {
|
|
@@ -127,4 +75,4 @@ function moveFeaturePreferences(state, sourceStoreName) {
|
|
|
127
75
|
...updatedSourceState
|
|
128
76
|
};
|
|
129
77
|
}
|
|
130
|
-
//# sourceMappingURL=move-feature-preferences.js.map
|
|
78
|
+
//# sourceMappingURL=move-feature-preferences.js.map
|
|
@@ -1 +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,QAA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= Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
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
|
+
var move_individual_preference_exports = {};
|
|
19
|
+
__export(move_individual_preference_exports, {
|
|
20
|
+
default: () => moveIndividualPreferenceToPreferences
|
|
5
21
|
});
|
|
6
|
-
exports
|
|
7
|
-
const identity = arg => arg;
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
* Migrates an individual item inside the `preferences` object for a package's store.
|
|
11
|
-
*
|
|
12
|
-
* Previously, some packages had individual 'preferences' of any data type, and many used
|
|
13
|
-
* complex nested data structures. For example:
|
|
14
|
-
* ```js
|
|
15
|
-
* {
|
|
16
|
-
* 'core/edit-post': {
|
|
17
|
-
* preferences: {
|
|
18
|
-
* panels: {
|
|
19
|
-
* publish: {
|
|
20
|
-
* opened: true,
|
|
21
|
-
* enabled: true,
|
|
22
|
-
* }
|
|
23
|
-
* },
|
|
24
|
-
* // ...other preferences.
|
|
25
|
-
* },
|
|
26
|
-
* },
|
|
27
|
-
* }
|
|
28
|
-
*
|
|
29
|
-
* This function supports moving an individual preference like 'panels' above into the
|
|
30
|
-
* preferences package data structure.
|
|
31
|
-
*
|
|
32
|
-
* It supports moving a preference to a particular scope in the preferences store and
|
|
33
|
-
* optionally converting the data using a `convert` function.
|
|
34
|
-
*
|
|
35
|
-
* ```
|
|
36
|
-
*
|
|
37
|
-
* @param {Object} state The original state.
|
|
38
|
-
* @param {Object} migrate An options object that contains details of the migration.
|
|
39
|
-
* @param {string} migrate.from The name of the store to migrate from.
|
|
40
|
-
* @param {string} migrate.to The scope in the preferences store to migrate to.
|
|
41
|
-
* @param {string} key The key in the preferences object to migrate.
|
|
42
|
-
* @param {?Function} convert A function that converts preferences from one format to another.
|
|
43
|
-
*/
|
|
44
|
-
function moveIndividualPreferenceToPreferences(state, {
|
|
45
|
-
from: sourceStoreName,
|
|
46
|
-
to: scope
|
|
47
|
-
}, key, convert = identity) {
|
|
48
|
-
const preferencesStoreName = 'core/preferences';
|
|
22
|
+
module.exports = __toCommonJS(move_individual_preference_exports);
|
|
23
|
+
const identity = (arg) => arg;
|
|
24
|
+
function moveIndividualPreferenceToPreferences(state, { from: sourceStoreName, to: scope }, key, convert = identity) {
|
|
25
|
+
const preferencesStoreName = "core/preferences";
|
|
49
26
|
const sourcePreference = state?.[sourceStoreName]?.preferences?.[key];
|
|
50
|
-
|
|
51
|
-
// There's nothing to migrate, exit early.
|
|
52
|
-
if (sourcePreference === undefined) {
|
|
27
|
+
if (sourcePreference === void 0) {
|
|
53
28
|
return state;
|
|
54
29
|
}
|
|
55
30
|
const targetPreference = state?.[preferencesStoreName]?.preferences?.[scope]?.[key];
|
|
56
|
-
|
|
57
|
-
// There's existing data at the target, so don't overwrite it, exit early.
|
|
58
31
|
if (targetPreference) {
|
|
59
32
|
return state;
|
|
60
33
|
}
|
|
@@ -62,12 +35,7 @@ function moveIndividualPreferenceToPreferences(state, {
|
|
|
62
35
|
const otherPreferences = state?.[preferencesStoreName]?.preferences?.[scope];
|
|
63
36
|
const otherSourceState = state?.[sourceStoreName];
|
|
64
37
|
const allSourcePreferences = state?.[sourceStoreName]?.preferences;
|
|
65
|
-
|
|
66
|
-
// Pass an object with the key and value as this allows the convert
|
|
67
|
-
// function to convert to a data structure that has different keys.
|
|
68
|
-
const convertedPreferences = convert({
|
|
69
|
-
[key]: sourcePreference
|
|
70
|
-
});
|
|
38
|
+
const convertedPreferences = convert({ [key]: sourcePreference });
|
|
71
39
|
return {
|
|
72
40
|
...state,
|
|
73
41
|
[preferencesStoreName]: {
|
|
@@ -83,9 +51,9 @@ function moveIndividualPreferenceToPreferences(state, {
|
|
|
83
51
|
...otherSourceState,
|
|
84
52
|
preferences: {
|
|
85
53
|
...allSourcePreferences,
|
|
86
|
-
[key]:
|
|
54
|
+
[key]: void 0
|
|
87
55
|
}
|
|
88
56
|
}
|
|
89
57
|
};
|
|
90
58
|
}
|
|
91
|
-
//# sourceMappingURL=move-individual-preference.js.map
|
|
59
|
+
//# sourceMappingURL=move-individual-preference.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/migrations/legacy-local-storage-data/move-individual-preference.js"],
|
|
4
|
+
"sourcesContent": ["const identity = ( arg ) => arg;\n\n/**\n * Migrates an individual item inside the `preferences` object for a package's store.\n *\n * Previously, some packages had individual 'preferences' of any data type, and many used\n * complex nested data structures. For example:\n * ```js\n * {\n * 'core/edit-post': {\n * preferences: {\n * panels: {\n * publish: {\n * opened: true,\n * enabled: true,\n * }\n * },\n * // ...other preferences.\n * },\n * },\n * }\n *\n * This function supports moving an individual preference like 'panels' above into the\n * preferences package data structure.\n *\n * It supports moving a preference to a particular scope in the preferences store and\n * optionally converting the data using a `convert` function.\n *\n * ```\n *\n * @param {Object} state The original state.\n * @param {Object} migrate An options object that contains details of the migration.\n * @param {string} migrate.from The name of the store to migrate from.\n * @param {string} migrate.to The scope in the preferences store to migrate to.\n * @param {string} key The key in the preferences object to migrate.\n * @param {?Function} convert A function that converts preferences from one format to another.\n */\nexport default function moveIndividualPreferenceToPreferences(\n\tstate,\n\t{ from: sourceStoreName, to: scope },\n\tkey,\n\tconvert = identity\n) {\n\tconst preferencesStoreName = 'core/preferences';\n\tconst sourcePreference = state?.[ sourceStoreName ]?.preferences?.[ key ];\n\n\t// There's nothing to migrate, exit early.\n\tif ( sourcePreference === undefined ) {\n\t\treturn state;\n\t}\n\n\tconst targetPreference =\n\t\tstate?.[ preferencesStoreName ]?.preferences?.[ scope ]?.[ key ];\n\n\t// There's existing data at the target, so don't overwrite it, exit early.\n\tif ( targetPreference ) {\n\t\treturn state;\n\t}\n\n\tconst otherScopes = state?.[ preferencesStoreName ]?.preferences;\n\tconst otherPreferences =\n\t\tstate?.[ preferencesStoreName ]?.preferences?.[ scope ];\n\n\tconst otherSourceState = state?.[ sourceStoreName ];\n\tconst allSourcePreferences = state?.[ sourceStoreName ]?.preferences;\n\n\t// Pass an object with the key and value as this allows the convert\n\t// function to convert to a data structure that has different keys.\n\tconst convertedPreferences = convert( { [ key ]: sourcePreference } );\n\n\treturn {\n\t\t...state,\n\t\t[ preferencesStoreName ]: {\n\t\t\tpreferences: {\n\t\t\t\t...otherScopes,\n\t\t\t\t[ scope ]: {\n\t\t\t\t\t...otherPreferences,\n\t\t\t\t\t...convertedPreferences,\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t\t[ sourceStoreName ]: {\n\t\t\t...otherSourceState,\n\t\t\tpreferences: {\n\t\t\t\t...allSourcePreferences,\n\t\t\t\t[ key ]: undefined,\n\t\t\t},\n\t\t},\n\t};\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,MAAM,WAAW,CAAE,QAAS;AAqCb,SAAR,sCACN,OACA,EAAE,MAAM,iBAAiB,IAAI,MAAM,GACnC,KACA,UAAU,UACT;AACD,QAAM,uBAAuB;AAC7B,QAAM,mBAAmB,QAAS,eAAgB,GAAG,cAAe,GAAI;AAGxE,MAAK,qBAAqB,QAAY;AACrC,WAAO;AAAA,EACR;AAEA,QAAM,mBACL,QAAS,oBAAqB,GAAG,cAAe,KAAM,IAAK,GAAI;AAGhE,MAAK,kBAAmB;AACvB,WAAO;AAAA,EACR;AAEA,QAAM,cAAc,QAAS,oBAAqB,GAAG;AACrD,QAAM,mBACL,QAAS,oBAAqB,GAAG,cAAe,KAAM;AAEvD,QAAM,mBAAmB,QAAS,eAAgB;AAClD,QAAM,uBAAuB,QAAS,eAAgB,GAAG;AAIzD,QAAM,uBAAuB,QAAS,EAAE,CAAE,GAAI,GAAG,iBAAiB,CAAE;AAEpE,SAAO;AAAA,IACN,GAAG;AAAA,IACH,CAAE,oBAAqB,GAAG;AAAA,MACzB,aAAa;AAAA,QACZ,GAAG;AAAA,QACH,CAAE,KAAM,GAAG;AAAA,UACV,GAAG;AAAA,UACH,GAAG;AAAA,QACJ;AAAA,MACD;AAAA,IACD;AAAA,IACA,CAAE,eAAgB,GAAG;AAAA,MACpB,GAAG;AAAA,MACH,aAAa;AAAA,QACZ,GAAG;AAAA,QACH,CAAE,GAAI,GAAG;AAAA,MACV;AAAA,IACD;AAAA,EACD;AACD;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|