@wordpress/preferences-persistence 1.31.0 → 1.32.1
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/CHANGELOG.md +2 -0
- package/build/create/debounce-async.js +5 -7
- package/build/create/debounce-async.js.map +1 -1
- package/build/create/index.js +15 -18
- package/build/create/index.js.map +1 -1
- package/build/index.js +3 -9
- package/build/index.js.map +1 -1
- package/build/migrations/legacy-local-storage-data/convert-edit-post-panels.js +0 -5
- package/build/migrations/legacy-local-storage-data/convert-edit-post-panels.js.map +1 -1
- package/build/migrations/legacy-local-storage-data/index.js +15 -20
- package/build/migrations/legacy-local-storage-data/index.js.map +1 -1
- package/build/migrations/legacy-local-storage-data/move-feature-preferences.js +20 -19
- package/build/migrations/legacy-local-storage-data/move-feature-preferences.js.map +1 -1
- package/build/migrations/legacy-local-storage-data/move-individual-preference.js +18 -14
- package/build/migrations/legacy-local-storage-data/move-individual-preference.js.map +1 -1
- package/build/migrations/legacy-local-storage-data/move-interface-enable-items.js +23 -18
- package/build/migrations/legacy-local-storage-data/move-interface-enable-items.js.map +1 -1
- package/build/migrations/legacy-local-storage-data/move-third-party-feature-preferences.js +8 -12
- package/build/migrations/legacy-local-storage-data/move-third-party-feature-preferences.js.map +1 -1
- package/build/migrations/preferences-package-data/convert-complementary-areas.js +4 -4
- package/build/migrations/preferences-package-data/convert-complementary-areas.js.map +1 -1
- package/build/migrations/preferences-package-data/index.js +1 -3
- package/build/migrations/preferences-package-data/index.js.map +1 -1
- package/build-module/create/debounce-async.js +5 -6
- package/build-module/create/debounce-async.js.map +1 -1
- package/build-module/create/index.js +15 -15
- package/build-module/create/index.js.map +1 -1
- package/build-module/index.js +4 -5
- package/build-module/index.js.map +1 -1
- package/build-module/migrations/legacy-local-storage-data/convert-edit-post-panels.js +0 -4
- package/build-module/migrations/legacy-local-storage-data/convert-edit-post-panels.js.map +1 -1
- package/build-module/migrations/legacy-local-storage-data/index.js +16 -13
- package/build-module/migrations/legacy-local-storage-data/index.js.map +1 -1
- package/build-module/migrations/legacy-local-storage-data/move-feature-preferences.js +20 -18
- package/build-module/migrations/legacy-local-storage-data/move-feature-preferences.js.map +1 -1
- package/build-module/migrations/legacy-local-storage-data/move-individual-preference.js +18 -13
- package/build-module/migrations/legacy-local-storage-data/move-individual-preference.js.map +1 -1
- package/build-module/migrations/legacy-local-storage-data/move-interface-enable-items.js +23 -17
- package/build-module/migrations/legacy-local-storage-data/move-interface-enable-items.js.map +1 -1
- package/build-module/migrations/legacy-local-storage-data/move-third-party-feature-preferences.js +8 -11
- package/build-module/migrations/legacy-local-storage-data/move-third-party-feature-preferences.js.map +1 -1
- package/build-module/migrations/preferences-package-data/convert-complementary-areas.js +4 -3
- package/build-module/migrations/preferences-package-data/convert-complementary-areas.js.map +1 -1
- package/build-module/migrations/preferences-package-data/index.js.map +1 -1
- package/package.json +3 -3
@@ -6,6 +6,7 @@ import moveThirdPartyFeaturePreferences from './move-third-party-feature-prefere
|
|
6
6
|
import moveIndividualPreference from './move-individual-preference';
|
7
7
|
import moveInterfaceEnableItems from './move-interface-enable-items';
|
8
8
|
import convertEditPostPanels from './convert-edit-post-panels';
|
9
|
+
|
9
10
|
/**
|
10
11
|
* Gets the legacy local storage data for a given user.
|
11
12
|
*
|
@@ -13,12 +14,12 @@ import convertEditPostPanels from './convert-edit-post-panels';
|
|
13
14
|
*
|
14
15
|
* @return {Object | null} The local storage data.
|
15
16
|
*/
|
16
|
-
|
17
17
|
function getLegacyData(userId) {
|
18
18
|
const key = `WP_DATA_USER_${userId}`;
|
19
19
|
const unparsedData = window.localStorage.getItem(key);
|
20
20
|
return JSON.parse(unparsedData);
|
21
21
|
}
|
22
|
+
|
22
23
|
/**
|
23
24
|
* Converts data from the old `@wordpress/data` package format.
|
24
25
|
*
|
@@ -27,27 +28,28 @@ function getLegacyData(userId) {
|
|
27
28
|
* @return {Object | undefined} The converted data or `undefined` if there was
|
28
29
|
* nothing to convert.
|
29
30
|
*/
|
30
|
-
|
31
|
-
|
32
31
|
export function convertLegacyData(data) {
|
33
32
|
if (!data) {
|
34
33
|
return;
|
35
|
-
}
|
36
|
-
// preferences store data structure.
|
37
|
-
|
34
|
+
}
|
38
35
|
|
36
|
+
// Move boolean feature preferences from each editor into the
|
37
|
+
// preferences store data structure.
|
39
38
|
data = moveFeaturePreferences(data, 'core/edit-widgets');
|
40
39
|
data = moveFeaturePreferences(data, 'core/customize-widgets');
|
41
40
|
data = moveFeaturePreferences(data, 'core/edit-post');
|
42
|
-
data = moveFeaturePreferences(data, 'core/edit-site');
|
41
|
+
data = moveFeaturePreferences(data, 'core/edit-site');
|
42
|
+
|
43
|
+
// Move third party boolean feature preferences from the interface package
|
43
44
|
// to the preferences store data structure.
|
45
|
+
data = moveThirdPartyFeaturePreferences(data);
|
44
46
|
|
45
|
-
|
47
|
+
// Move and convert the interface store's `enableItems` data into the
|
46
48
|
// preferences data structure.
|
49
|
+
data = moveInterfaceEnableItems(data);
|
47
50
|
|
48
|
-
|
51
|
+
// Move individual ad-hoc preferences from various packages into the
|
49
52
|
// preferences store data structure.
|
50
|
-
|
51
53
|
data = moveIndividualPreference(data, {
|
52
54
|
from: 'core/edit-post',
|
53
55
|
to: 'core/edit-post'
|
@@ -71,11 +73,13 @@ export function convertLegacyData(data) {
|
|
71
73
|
data = moveIndividualPreference(data, {
|
72
74
|
from: 'core/edit-site',
|
73
75
|
to: 'core/edit-site'
|
74
|
-
}, 'editorMode');
|
75
|
-
// 'core/preferences' preferences reducer, so only return that.
|
76
|
+
}, 'editorMode');
|
76
77
|
|
78
|
+
// The new system is only concerned with persisting
|
79
|
+
// 'core/preferences' preferences reducer, so only return that.
|
77
80
|
return data?.['core/preferences']?.preferences;
|
78
81
|
}
|
82
|
+
|
79
83
|
/**
|
80
84
|
* Gets the legacy local storage data for the given user and returns the
|
81
85
|
* data converted to the new format.
|
@@ -85,7 +89,6 @@ export function convertLegacyData(data) {
|
|
85
89
|
* @return {Object | undefined} The converted data or undefined if no local
|
86
90
|
* storage data could be found.
|
87
91
|
*/
|
88
|
-
|
89
92
|
export default function convertLegacyLocalStorageData(userId) {
|
90
93
|
const data = getLegacyData(userId);
|
91
94
|
return convertLegacyData(data);
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"
|
1
|
+
{"version":3,"names":["moveFeaturePreferences","moveThirdPartyFeaturePreferences","moveIndividualPreference","moveInterfaceEnableItems","convertEditPostPanels","getLegacyData","userId","key","unparsedData","window","localStorage","getItem","JSON","parse","convertLegacyData","data","from","to","preferences","convertLegacyLocalStorageData"],"sources":["@wordpress/preferences-persistence/src/migrations/legacy-local-storage-data/index.js"],"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'preferredStyleVariations'\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/edit-post' },\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"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,sBAAsB,MAAM,4BAA4B;AAC/D,OAAOC,gCAAgC,MAAM,wCAAwC;AACrF,OAAOC,wBAAwB,MAAM,8BAA8B;AACnE,OAAOC,wBAAwB,MAAM,+BAA+B;AACpE,OAAOC,qBAAqB,MAAM,4BAA4B;;AAE9D;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASC,aAAaA,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Rb,qBACD,CAAC;EACDW,IAAI,GAAGb,wBAAwB,CAC9Ba,IAAI,EACJ;IAAEC,IAAI,EAAE,aAAa;IAAEC,EAAE,EAAE;EAAiB,CAAC,EAC7C,yBACD,CAAC;EACDF,IAAI,GAAGb,wBAAwB,CAC9Ba,IAAI,EACJ;IAAEC,IAAI,EAAE,gBAAgB;IAAEC,EAAE,EAAE;EAAiB,CAAC,EAChD,YACD,CAAC;;EAED;EACA;EACA,OAAOF,IAAI,GAAI,kBAAkB,CAAE,EAAEG,WAAW;AACjD;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,SAASC,6BAA6BA,CAAEb,MAAM,EAAG;EAC/D,MAAMS,IAAI,GAAGV,aAAa,CAAEC,MAAO,CAAC;EACpC,OAAOQ,iBAAiB,CAAEC,IAAK,CAAC;AACjC"}
|
@@ -57,61 +57,63 @@
|
|
57
57
|
*/
|
58
58
|
export default function moveFeaturePreferences(state, sourceStoreName) {
|
59
59
|
const preferencesStoreName = 'core/preferences';
|
60
|
-
const interfaceStoreName = 'core/interface';
|
60
|
+
const interfaceStoreName = 'core/interface';
|
61
|
+
|
62
|
+
// Features most recently (and briefly) lived in the interface package.
|
61
63
|
// If data exists there, prioritize using that for the migration. If not
|
62
64
|
// also check the original package as the user may have updated from an
|
63
65
|
// older block editor version.
|
64
|
-
|
65
66
|
const interfaceFeatures = state?.[interfaceStoreName]?.preferences?.features?.[sourceStoreName];
|
66
67
|
const sourceFeatures = state?.[sourceStoreName]?.preferences?.features;
|
67
68
|
const featuresToMigrate = interfaceFeatures ? interfaceFeatures : sourceFeatures;
|
68
|
-
|
69
69
|
if (!featuresToMigrate) {
|
70
70
|
return state;
|
71
71
|
}
|
72
|
+
const existingPreferences = state?.[preferencesStoreName]?.preferences;
|
72
73
|
|
73
|
-
|
74
|
-
|
74
|
+
// Avoid migrating features again if they've previously been migrated.
|
75
75
|
if (existingPreferences?.[sourceStoreName]) {
|
76
76
|
return state;
|
77
77
|
}
|
78
|
-
|
79
78
|
let updatedInterfaceState;
|
80
|
-
|
81
79
|
if (interfaceFeatures) {
|
82
80
|
const otherInterfaceState = state?.[interfaceStoreName];
|
83
81
|
const otherInterfaceScopes = state?.[interfaceStoreName]?.preferences?.features;
|
84
82
|
updatedInterfaceState = {
|
85
|
-
[interfaceStoreName]: {
|
83
|
+
[interfaceStoreName]: {
|
84
|
+
...otherInterfaceState,
|
86
85
|
preferences: {
|
87
|
-
features: {
|
86
|
+
features: {
|
87
|
+
...otherInterfaceScopes,
|
88
88
|
[sourceStoreName]: undefined
|
89
89
|
}
|
90
90
|
}
|
91
91
|
}
|
92
92
|
};
|
93
93
|
}
|
94
|
-
|
95
94
|
let updatedSourceState;
|
96
|
-
|
97
95
|
if (sourceFeatures) {
|
98
96
|
const otherSourceState = state?.[sourceStoreName];
|
99
97
|
const sourcePreferences = state?.[sourceStoreName]?.preferences;
|
100
98
|
updatedSourceState = {
|
101
|
-
[sourceStoreName]: {
|
102
|
-
|
99
|
+
[sourceStoreName]: {
|
100
|
+
...otherSourceState,
|
101
|
+
preferences: {
|
102
|
+
...sourcePreferences,
|
103
103
|
features: undefined
|
104
104
|
}
|
105
105
|
}
|
106
106
|
};
|
107
|
-
}
|
107
|
+
}
|
108
|
+
|
109
|
+
// Set the feature values in the interface store, the features
|
108
110
|
// object is keyed by 'scope', which matches the store name for
|
109
111
|
// the source.
|
110
|
-
|
111
|
-
|
112
|
-
return { ...state,
|
112
|
+
return {
|
113
|
+
...state,
|
113
114
|
[preferencesStoreName]: {
|
114
|
-
preferences: {
|
115
|
+
preferences: {
|
116
|
+
...existingPreferences,
|
115
117
|
[sourceStoreName]: featuresToMigrate
|
116
118
|
}
|
117
119
|
},
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"
|
1
|
+
{"version":3,"names":["moveFeaturePreferences","state","sourceStoreName","preferencesStoreName","interfaceStoreName","interfaceFeatures","preferences","features","sourceFeatures","featuresToMigrate","existingPreferences","updatedInterfaceState","otherInterfaceState","otherInterfaceScopes","undefined","updatedSourceState","otherSourceState","sourcePreferences"],"sources":["@wordpress/preferences-persistence/src/migrations/legacy-local-storage-data/move-feature-preferences.js"],"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"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAC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eAAe,GAAI;QACpB,GAAGc,gBAAgB;QACnBV,WAAW,EAAE;UACZ,GAAGW,iBAAiB;UACpBV,QAAQ,EAAEO;QACX;MACD;IACD,CAAC;EACF;;EAEA;EACA;EACA;EACA,OAAO;IACN,GAAGb,KAAK;IACR,CAAEE,oBAAoB,GAAI;MACzBG,WAAW,EAAE;QACZ,GAAGI,mBAAmB;QACtB,CAAER,eAAe,GAAIO;MACtB;IACD,CAAC;IACD,GAAGE,qBAAqB;IACxB,GAAGI;EACJ,CAAC;AACF"}
|
@@ -1,4 +1,5 @@
|
|
1
1
|
const identity = arg => arg;
|
2
|
+
|
2
3
|
/**
|
3
4
|
* Migrates an individual item inside the `preferences` object for a package's store.
|
4
5
|
*
|
@@ -34,44 +35,48 @@ const identity = arg => arg;
|
|
34
35
|
* @param {string} key The key in the preferences object to migrate.
|
35
36
|
* @param {?Function} convert A function that converts preferences from one format to another.
|
36
37
|
*/
|
37
|
-
|
38
|
-
|
39
38
|
export default function moveIndividualPreferenceToPreferences(state, {
|
40
39
|
from: sourceStoreName,
|
41
40
|
to: scope
|
42
41
|
}, key, convert = identity) {
|
43
42
|
const preferencesStoreName = 'core/preferences';
|
44
|
-
const sourcePreference = state?.[sourceStoreName]?.preferences?.[key];
|
43
|
+
const sourcePreference = state?.[sourceStoreName]?.preferences?.[key];
|
45
44
|
|
45
|
+
// There's nothing to migrate, exit early.
|
46
46
|
if (sourcePreference === undefined) {
|
47
47
|
return state;
|
48
48
|
}
|
49
|
+
const targetPreference = state?.[preferencesStoreName]?.preferences?.[scope]?.[key];
|
49
50
|
|
50
|
-
|
51
|
-
|
51
|
+
// There's existing data at the target, so don't overwrite it, exit early.
|
52
52
|
if (targetPreference) {
|
53
53
|
return state;
|
54
54
|
}
|
55
|
-
|
56
55
|
const otherScopes = state?.[preferencesStoreName]?.preferences;
|
57
56
|
const otherPreferences = state?.[preferencesStoreName]?.preferences?.[scope];
|
58
57
|
const otherSourceState = state?.[sourceStoreName];
|
59
|
-
const allSourcePreferences = state?.[sourceStoreName]?.preferences;
|
60
|
-
// function to convert to a data structure that has different keys.
|
58
|
+
const allSourcePreferences = state?.[sourceStoreName]?.preferences;
|
61
59
|
|
60
|
+
// Pass an object with the key and value as this allows the convert
|
61
|
+
// function to convert to a data structure that has different keys.
|
62
62
|
const convertedPreferences = convert({
|
63
63
|
[key]: sourcePreference
|
64
64
|
});
|
65
|
-
return {
|
65
|
+
return {
|
66
|
+
...state,
|
66
67
|
[preferencesStoreName]: {
|
67
|
-
preferences: {
|
68
|
-
|
68
|
+
preferences: {
|
69
|
+
...otherScopes,
|
70
|
+
[scope]: {
|
71
|
+
...otherPreferences,
|
69
72
|
...convertedPreferences
|
70
73
|
}
|
71
74
|
}
|
72
75
|
},
|
73
|
-
[sourceStoreName]: {
|
74
|
-
|
76
|
+
[sourceStoreName]: {
|
77
|
+
...otherSourceState,
|
78
|
+
preferences: {
|
79
|
+
...allSourcePreferences,
|
75
80
|
[key]: undefined
|
76
81
|
}
|
77
82
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"
|
1
|
+
{"version":3,"names":["identity","arg","moveIndividualPreferenceToPreferences","state","from","sourceStoreName","to","scope","key","convert","preferencesStoreName","sourcePreference","preferences","undefined","targetPreference","otherScopes","otherPreferences","otherSourceState","allSourcePreferences","convertedPreferences"],"sources":["@wordpress/preferences-persistence/src/migrations/legacy-local-storage-data/move-individual-preference.js"],"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"],"mappings":"AAAA,MAAMA,QAAQ,GAAKC,GAAG,IAAMA,GAAG;;AAE/B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;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WAAW,EAAE;QACZ,GAAGM,oBAAoB;QACvB,CAAEV,GAAG,GAAIK;MACV;IACD;EACD,CAAC;AACF"}
|
@@ -47,55 +47,61 @@
|
|
47
47
|
*/
|
48
48
|
export default function moveInterfaceEnableItems(state) {
|
49
49
|
var _state$preferencesSto, _sourceEnableItems$si, _sourceEnableItems$mu;
|
50
|
-
|
51
50
|
const interfaceStoreName = 'core/interface';
|
52
51
|
const preferencesStoreName = 'core/preferences';
|
53
|
-
const sourceEnableItems = state?.[interfaceStoreName]?.enableItems;
|
52
|
+
const sourceEnableItems = state?.[interfaceStoreName]?.enableItems;
|
54
53
|
|
54
|
+
// There's nothing to migrate, exit early.
|
55
55
|
if (!sourceEnableItems) {
|
56
56
|
return state;
|
57
57
|
}
|
58
|
+
const allPreferences = (_state$preferencesSto = state?.[preferencesStoreName]?.preferences) !== null && _state$preferencesSto !== void 0 ? _state$preferencesSto : {};
|
58
59
|
|
59
|
-
|
60
|
+
// First convert complementaryAreas into the right format.
|
60
61
|
// Use the existing preferences as the accumulator so that the data is
|
61
62
|
// merged.
|
62
|
-
|
63
63
|
const sourceComplementaryAreas = (_sourceEnableItems$si = sourceEnableItems?.singleEnableItems?.complementaryArea) !== null && _sourceEnableItems$si !== void 0 ? _sourceEnableItems$si : {};
|
64
64
|
const preferencesWithConvertedComplementaryAreas = Object.keys(sourceComplementaryAreas).reduce((accumulator, scope) => {
|
65
|
-
const data = sourceComplementaryAreas[scope];
|
65
|
+
const data = sourceComplementaryAreas[scope];
|
66
66
|
|
67
|
+
// Don't overwrite any existing data in the preferences store.
|
67
68
|
if (accumulator?.[scope]?.complementaryArea) {
|
68
69
|
return accumulator;
|
69
70
|
}
|
70
|
-
|
71
|
-
|
72
|
-
[scope]: {
|
71
|
+
return {
|
72
|
+
...accumulator,
|
73
|
+
[scope]: {
|
74
|
+
...accumulator[scope],
|
73
75
|
complementaryArea: data
|
74
76
|
}
|
75
77
|
};
|
76
|
-
}, allPreferences);
|
77
|
-
// converts the pinned items, resulting in the fully migrated data.
|
78
|
+
}, allPreferences);
|
78
79
|
|
80
|
+
// Next feed the converted complementary areas back into a reducer that
|
81
|
+
// converts the pinned items, resulting in the fully migrated data.
|
79
82
|
const sourcePinnedItems = (_sourceEnableItems$mu = sourceEnableItems?.multipleEnableItems?.pinnedItems) !== null && _sourceEnableItems$mu !== void 0 ? _sourceEnableItems$mu : {};
|
80
83
|
const allConvertedData = Object.keys(sourcePinnedItems).reduce((accumulator, scope) => {
|
81
|
-
const data = sourcePinnedItems[scope];
|
82
|
-
|
84
|
+
const data = sourcePinnedItems[scope];
|
85
|
+
// Don't overwrite any existing data in the preferences store.
|
83
86
|
if (accumulator?.[scope]?.pinnedItems) {
|
84
87
|
return accumulator;
|
85
88
|
}
|
86
|
-
|
87
|
-
|
88
|
-
[scope]: {
|
89
|
+
return {
|
90
|
+
...accumulator,
|
91
|
+
[scope]: {
|
92
|
+
...accumulator[scope],
|
89
93
|
pinnedItems: data
|
90
94
|
}
|
91
95
|
};
|
92
96
|
}, preferencesWithConvertedComplementaryAreas);
|
93
97
|
const otherInterfaceItems = state[interfaceStoreName];
|
94
|
-
return {
|
98
|
+
return {
|
99
|
+
...state,
|
95
100
|
[preferencesStoreName]: {
|
96
101
|
preferences: allConvertedData
|
97
102
|
},
|
98
|
-
[interfaceStoreName]: {
|
103
|
+
[interfaceStoreName]: {
|
104
|
+
...otherInterfaceItems,
|
99
105
|
enableItems: undefined
|
100
106
|
}
|
101
107
|
};
|
package/build-module/migrations/legacy-local-storage-data/move-interface-enable-items.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"
|
1
|
+
{"version":3,"names":["moveInterfaceEnableItems","state","_state$preferencesSto","_sourceEnableItems$si","_sourceEnableItems$mu","interfaceStoreName","preferencesStoreName","sourceEnableItems","enableItems","allPreferences","preferences","sourceComplementaryAreas","singleEnableItems","complementaryArea","preferencesWithConvertedComplementaryAreas","Object","keys","reduce","accumulator","scope","data","sourcePinnedItems","multipleEnableItems","pinnedItems","allConvertedData","otherInterfaceItems","undefined"],"sources":["@wordpress/preferences-persistence/src/migrations/legacy-local-storage-data/move-interface-enable-items.js"],"sourcesContent":["/**\n * Migrates interface 'enableItems' data to the preferences store.\n *\n * The interface package stores this data in this format:\n * ```js\n * {\n * enableItems: {\n * singleEnableItems: {\n * \t complementaryArea: {\n * 'core/edit-post': 'edit-post/document',\n * 'core/edit-site': 'edit-site/global-styles',\n * }\n * },\n * multipleEnableItems: {\n * pinnedItems: {\n * 'core/edit-post': {\n * 'plugin-1': true,\n * },\n * 'core/edit-site': {\n * 'plugin-2': true,\n * },\n * },\n * }\n * }\n * }\n * ```\n *\n * and it should be converted it to:\n * ```js\n * {\n * 'core/edit-post': {\n * complementaryArea: 'edit-post/document',\n * pinnedItems: {\n * 'plugin-1': true,\n * },\n * },\n * 'core/edit-site': {\n * complementaryArea: 'edit-site/global-styles',\n * pinnedItems: {\n * 'plugin-2': true,\n * },\n * },\n * }\n * ```\n *\n * @param {Object} state The local storage state.\n */\nexport default function moveInterfaceEnableItems( state ) {\n\tconst interfaceStoreName = 'core/interface';\n\tconst preferencesStoreName = 'core/preferences';\n\tconst sourceEnableItems = state?.[ interfaceStoreName ]?.enableItems;\n\n\t// There's nothing to migrate, exit early.\n\tif ( ! sourceEnableItems ) {\n\t\treturn state;\n\t}\n\n\tconst allPreferences = state?.[ preferencesStoreName ]?.preferences ?? {};\n\n\t// First convert complementaryAreas into the right format.\n\t// Use the existing preferences as the accumulator so that the data is\n\t// merged.\n\tconst sourceComplementaryAreas =\n\t\tsourceEnableItems?.singleEnableItems?.complementaryArea ?? {};\n\n\tconst preferencesWithConvertedComplementaryAreas = Object.keys(\n\t\tsourceComplementaryAreas\n\t).reduce( ( accumulator, scope ) => {\n\t\tconst data = sourceComplementaryAreas[ scope ];\n\n\t\t// Don't overwrite any existing data in the preferences store.\n\t\tif ( accumulator?.[ scope ]?.complementaryArea ) {\n\t\t\treturn accumulator;\n\t\t}\n\n\t\treturn {\n\t\t\t...accumulator,\n\t\t\t[ scope ]: {\n\t\t\t\t...accumulator[ scope ],\n\t\t\t\tcomplementaryArea: data,\n\t\t\t},\n\t\t};\n\t}, allPreferences );\n\n\t// Next feed the converted complementary areas back into a reducer that\n\t// converts the pinned items, resulting in the fully migrated data.\n\tconst sourcePinnedItems =\n\t\tsourceEnableItems?.multipleEnableItems?.pinnedItems ?? {};\n\tconst allConvertedData = Object.keys( sourcePinnedItems ).reduce(\n\t\t( accumulator, scope ) => {\n\t\t\tconst data = sourcePinnedItems[ scope ];\n\t\t\t// Don't overwrite any existing data in the preferences store.\n\t\t\tif ( accumulator?.[ scope ]?.pinnedItems ) {\n\t\t\t\treturn accumulator;\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\t...accumulator,\n\t\t\t\t[ scope ]: {\n\t\t\t\t\t...accumulator[ scope ],\n\t\t\t\t\tpinnedItems: data,\n\t\t\t\t},\n\t\t\t};\n\t\t},\n\t\tpreferencesWithConvertedComplementaryAreas\n\t);\n\n\tconst otherInterfaceItems = state[ interfaceStoreName ];\n\n\treturn {\n\t\t...state,\n\t\t[ preferencesStoreName ]: {\n\t\t\tpreferences: allConvertedData,\n\t\t},\n\t\t[ interfaceStoreName ]: {\n\t\t\t...otherInterfaceItems,\n\t\t\tenableItems: undefined,\n\t\t},\n\t};\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,SAASA,wBAAwBA,CAAEC,KAAK,EAAG;EAAA,IAAAC,qBAAA,EAAAC,qBAAA,EAAAC,qBAAA;EACzD,MAAMC,kBAAkB,GAAG,gBAAgB;EAC3C,MAAMC,oBAAoB,GAAG,kBAAkB;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AOL,WAAW;IACnB;IAEA,OAAO;MACN,GAAGA,WAAW;MACd,CAAEC,KAAK,GAAI;QACV,GAAGD,WAAW,CAAEC,KAAK,CAAE;QACvBI,WAAW,EAAEH;MACd;IACD,CAAC;EACF,CAAC,EACDN,0CACD,CAAC;EAED,MAAMW,mBAAmB,GAAGxB,KAAK,CAAEI,kBAAkB,CAAE;EAEvD,OAAO;IACN,GAAGJ,KAAK;IACR,CAAEK,oBAAoB,GAAI;MACzBI,WAAW,EAAEc;IACd,CAAC;IACD,CAAEnB,kBAAkB,GAAI;MACvB,GAAGoB,mBAAmB;MACtBjB,WAAW,EAAEkB;IACd;EACD,CAAC;AACF"}
|
package/build-module/migrations/legacy-local-storage-data/move-third-party-feature-preferences.js
CHANGED
@@ -44,40 +44,37 @@ export default function moveThirdPartyFeaturePreferencesToPreferences(state) {
|
|
44
44
|
const preferencesStoreName = 'core/preferences';
|
45
45
|
const interfaceScopes = state?.[interfaceStoreName]?.preferences?.features;
|
46
46
|
const interfaceScopeKeys = interfaceScopes ? Object.keys(interfaceScopes) : [];
|
47
|
-
|
48
47
|
if (!interfaceScopeKeys?.length) {
|
49
48
|
return state;
|
50
49
|
}
|
51
|
-
|
52
50
|
return interfaceScopeKeys.reduce(function (convertedState, scope) {
|
53
51
|
if (scope.startsWith('core')) {
|
54
52
|
return convertedState;
|
55
53
|
}
|
56
|
-
|
57
54
|
const featuresToMigrate = interfaceScopes?.[scope];
|
58
|
-
|
59
55
|
if (!featuresToMigrate) {
|
60
56
|
return convertedState;
|
61
57
|
}
|
62
|
-
|
63
58
|
const existingMigratedData = convertedState?.[preferencesStoreName]?.preferences?.[scope];
|
64
|
-
|
65
59
|
if (existingMigratedData) {
|
66
60
|
return convertedState;
|
67
61
|
}
|
68
|
-
|
69
62
|
const otherPreferencesScopes = convertedState?.[preferencesStoreName]?.preferences;
|
70
63
|
const otherInterfaceState = convertedState?.[interfaceStoreName];
|
71
64
|
const otherInterfaceScopes = convertedState?.[interfaceStoreName]?.preferences?.features;
|
72
|
-
return {
|
65
|
+
return {
|
66
|
+
...convertedState,
|
73
67
|
[preferencesStoreName]: {
|
74
|
-
preferences: {
|
68
|
+
preferences: {
|
69
|
+
...otherPreferencesScopes,
|
75
70
|
[scope]: featuresToMigrate
|
76
71
|
}
|
77
72
|
},
|
78
|
-
[interfaceStoreName]: {
|
73
|
+
[interfaceStoreName]: {
|
74
|
+
...otherInterfaceState,
|
79
75
|
preferences: {
|
80
|
-
features: {
|
76
|
+
features: {
|
77
|
+
...otherInterfaceScopes,
|
81
78
|
[scope]: undefined
|
82
79
|
}
|
83
80
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"
|
1
|
+
{"version":3,"names":["moveThirdPartyFeaturePreferencesToPreferences","state","interfaceStoreName","preferencesStoreName","interfaceScopes","preferences","features","interfaceScopeKeys","Object","keys","length","reduce","convertedState","scope","startsWith","featuresToMigrate","existingMigratedData","otherPreferencesScopes","otherInterfaceState","otherInterfaceScopes","undefined"],"sources":["@wordpress/preferences-persistence/src/migrations/legacy-local-storage-data/move-third-party-feature-preferences.js"],"sourcesContent":["/**\n * The interface package previously had a public API that could be used by\n * plugins to set persisted boolean 'feature' preferences.\n *\n * While usage was likely non-existent or very small, this function ensures\n * those are migrated to the preferences data structure. The interface\n * package's APIs have now been deprecated and use the preferences store.\n *\n * This will convert data that looks like this:\n * ```js\n * {\n * 'core/interface': {\n * preferences: {\n * features: {\n * 'my-plugin': {\n * myPluginFeature: true\n * }\n * }\n * }\n * }\n * }\n * ```\n *\n * To this:\n * ```js\n * * {\n * 'core/preferences': {\n * preferences: {\n * 'my-plugin': {\n * myPluginFeature: true\n * }\n * }\n * }\n * }\n * ```\n *\n * @param {Object} state The local storage state\n *\n * @return {Object} The state with third party preferences moved to the\n * preferences data structure.\n */\nexport default function moveThirdPartyFeaturePreferencesToPreferences( state ) {\n\tconst interfaceStoreName = 'core/interface';\n\tconst preferencesStoreName = 'core/preferences';\n\n\tconst interfaceScopes =\n\t\tstate?.[ interfaceStoreName ]?.preferences?.features;\n\tconst interfaceScopeKeys = interfaceScopes\n\t\t? Object.keys( interfaceScopes )\n\t\t: [];\n\n\tif ( ! interfaceScopeKeys?.length ) {\n\t\treturn state;\n\t}\n\n\treturn interfaceScopeKeys.reduce( function ( convertedState, scope ) {\n\t\tif ( scope.startsWith( 'core' ) ) {\n\t\t\treturn convertedState;\n\t\t}\n\n\t\tconst featuresToMigrate = interfaceScopes?.[ scope ];\n\t\tif ( ! featuresToMigrate ) {\n\t\t\treturn convertedState;\n\t\t}\n\n\t\tconst existingMigratedData =\n\t\t\tconvertedState?.[ preferencesStoreName ]?.preferences?.[ scope ];\n\n\t\tif ( existingMigratedData ) {\n\t\t\treturn convertedState;\n\t\t}\n\n\t\tconst otherPreferencesScopes =\n\t\t\tconvertedState?.[ preferencesStoreName ]?.preferences;\n\t\tconst otherInterfaceState = convertedState?.[ interfaceStoreName ];\n\t\tconst otherInterfaceScopes =\n\t\t\tconvertedState?.[ interfaceStoreName ]?.preferences?.features;\n\n\t\treturn {\n\t\t\t...convertedState,\n\t\t\t[ preferencesStoreName ]: {\n\t\t\t\tpreferences: {\n\t\t\t\t\t...otherPreferencesScopes,\n\t\t\t\t\t[ scope ]: featuresToMigrate,\n\t\t\t\t},\n\t\t\t},\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[ scope ]: undefined,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t};\n\t}, state );\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAA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BAAoB;YACvB,CAAEN,KAAK,GAAIO;UACZ;QACD;MACD;IACD,CAAC;EACF,CAAC,EAAEnB,KAAM,CAAC;AACX"}
|
@@ -1,16 +1,17 @@
|
|
1
1
|
export default function convertComplementaryAreas(state) {
|
2
2
|
return Object.keys(state).reduce((stateAccumulator, scope) => {
|
3
|
-
const scopeData = state[scope];
|
3
|
+
const scopeData = state[scope];
|
4
4
|
|
5
|
+
// If a complementary area is truthy, convert it to the `isComplementaryAreaVisible` boolean.
|
5
6
|
if (scopeData?.complementaryArea) {
|
6
|
-
const updatedScopeData = {
|
7
|
+
const updatedScopeData = {
|
8
|
+
...scopeData
|
7
9
|
};
|
8
10
|
delete updatedScopeData.complementaryArea;
|
9
11
|
updatedScopeData.isComplementaryAreaVisible = true;
|
10
12
|
stateAccumulator[scope] = updatedScopeData;
|
11
13
|
return stateAccumulator;
|
12
14
|
}
|
13
|
-
|
14
15
|
return stateAccumulator;
|
15
16
|
}, state);
|
16
17
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"
|
1
|
+
{"version":3,"names":["convertComplementaryAreas","state","Object","keys","reduce","stateAccumulator","scope","scopeData","complementaryArea","updatedScopeData","isComplementaryAreaVisible"],"sources":["@wordpress/preferences-persistence/src/migrations/preferences-package-data/convert-complementary-areas.js"],"sourcesContent":["export default function convertComplementaryAreas( state ) {\n\treturn Object.keys( state ).reduce( ( stateAccumulator, scope ) => {\n\t\tconst scopeData = state[ scope ];\n\n\t\t// If a complementary area is truthy, convert it to the `isComplementaryAreaVisible` boolean.\n\t\tif ( scopeData?.complementaryArea ) {\n\t\t\tconst updatedScopeData = { ...scopeData };\n\t\t\tdelete updatedScopeData.complementaryArea;\n\t\t\tupdatedScopeData.isComplementaryAreaVisible = true;\n\t\t\tstateAccumulator[ scope ] = updatedScopeData;\n\t\t\treturn stateAccumulator;\n\t\t}\n\n\t\treturn stateAccumulator;\n\t}, state );\n}\n"],"mappings":"AAAA,eAAe,SAASA,yBAAyBA,CAAEC,KAAK,EAAG;EAC1D,OAAOC,MAAM,CAACC,IAAI,CAAEF,KAAM,CAAC,CAACG,MAAM,CAAE,CAAEC,gBAAgB,EAAEC,KAAK,KAAM;IAClE,MAAMC,SAAS,GAAGN,KAAK,CAAEK,KAAK,CAAE;;IAEhC;IACA,IAAKC,SAAS,EAAEC,iBAAiB,EAAG;MACnC,MAAMC,gBAAgB,GAAG;QAAE,GAAGF;MAAU,CAAC;MACzC,OAAOE,gBAAgB,CAACD,iBAAiB;MACzCC,gBAAgB,CAACC,0BAA0B,GAAG,IAAI;MAClDL,gBAAgB,CAAEC,KAAK,CAAE,GAAGG,gBAAgB;MAC5C,OAAOJ,gBAAgB;IACxB;IAEA,OAAOA,gBAAgB;EACxB,CAAC,EAAEJ,KAAM,CAAC;AACX"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["@wordpress/preferences-persistence/src/migrations/preferences-package-data/index.js"],"
|
1
|
+
{"version":3,"names":["convertComplementaryAreas","convertPreferencesPackageData","data"],"sources":["@wordpress/preferences-persistence/src/migrations/preferences-package-data/index.js"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport convertComplementaryAreas from './convert-complementary-areas';\n\nexport default function convertPreferencesPackageData( data ) {\n\treturn convertComplementaryAreas( data );\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,yBAAyB,MAAM,+BAA+B;AAErE,eAAe,SAASC,6BAA6BA,CAAEC,IAAI,EAAG;EAC7D,OAAOF,yBAAyB,CAAEE,IAAK,CAAC;AACzC"}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@wordpress/preferences-persistence",
|
3
|
-
"version": "1.
|
3
|
+
"version": "1.32.1",
|
4
4
|
"description": "Persistence utilities for `wordpress/preferences`.",
|
5
5
|
"author": "The WordPress Contributors",
|
6
6
|
"license": "GPL-2.0-or-later",
|
@@ -28,10 +28,10 @@
|
|
28
28
|
"sideEffects": false,
|
29
29
|
"dependencies": {
|
30
30
|
"@babel/runtime": "^7.16.0",
|
31
|
-
"@wordpress/api-fetch": "^6.
|
31
|
+
"@wordpress/api-fetch": "^6.37.1"
|
32
32
|
},
|
33
33
|
"publishConfig": {
|
34
34
|
"access": "public"
|
35
35
|
},
|
36
|
-
"gitHead": "
|
36
|
+
"gitHead": "bb1fbf87bb0f451744530fc6a85de2dff1263bed"
|
37
37
|
}
|