@wordpress/preferences-persistence 1.0.0 → 1.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/CHANGELOG.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 1.1.0 (2022-05-18)
6
+
5
7
  ## 1.0.0 (2022-05-04)
6
8
 
7
9
  - Initial version of the package.
package/build/index.js CHANGED
@@ -17,6 +17,8 @@ var _create = _interopRequireDefault(require("./create"));
17
17
 
18
18
  var _legacyLocalStorageData = _interopRequireDefault(require("./migrations/legacy-local-storage-data"));
19
19
 
20
+ var _preferencesPackageData = _interopRequireDefault(require("./migrations/preferences-package-data"));
21
+
20
22
  /**
21
23
  * Internal dependencies
22
24
  */
@@ -45,9 +47,9 @@ function __unstableCreatePersistenceLayer(serverData, userId) {
45
47
  let preloadedData;
46
48
 
47
49
  if (serverData && serverModified >= localModified) {
48
- preloadedData = serverData;
50
+ preloadedData = (0, _preferencesPackageData.default)(serverData);
49
51
  } else if (localData) {
50
- preloadedData = localData;
52
+ preloadedData = (0, _preferencesPackageData.default)(localData);
51
53
  } else {
52
54
  // Check if there is data in the legacy format from the old persistence system.
53
55
  preloadedData = (0, _legacyLocalStorageData.default)(userId);
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/preferences-persistence/src/index.js"],"names":["__unstableCreatePersistenceLayer","serverData","userId","localStorageRestoreKey","localData","JSON","parse","window","localStorage","getItem","serverModified","Date","_modified","localModified","preloadedData"],"mappings":";;;;;;;;;;;;;;;AAGA;;AACA;;AAJA;AACA;AACA;;AAMA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,gCAAT,CAA2CC,UAA3C,EAAuDC,MAAvD,EAAgE;AACtE,QAAMC,sBAAsB,GAAI,uBAAuBD,MAAQ,EAA/D;AACA,QAAME,SAAS,GAAGC,IAAI,CAACC,KAAL,CACjBC,MAAM,CAACC,YAAP,CAAoBC,OAApB,CAA6BN,sBAA7B,CADiB,CAAlB,CAFsE,CAMtE;AACA;;AACA,QAAMO,cAAc,GACnBC,IAAI,CAACL,KAAL,CAAYL,UAAU,IAAIA,UAAU,CAACW,SAArC,KAAoD,CADrD;AAEA,QAAMC,aAAa,GAAGF,IAAI,CAACL,KAAL,CAAYF,SAAS,IAAIA,SAAS,CAACQ,SAAnC,KAAkD,CAAxE;AAEA,MAAIE,aAAJ;;AACA,MAAKb,UAAU,IAAIS,cAAc,IAAIG,aAArC,EAAqD;AACpDC,IAAAA,aAAa,GAAGb,UAAhB;AACA,GAFD,MAEO,IAAKG,SAAL,EAAiB;AACvBU,IAAAA,aAAa,GAAGV,SAAhB;AACA,GAFM,MAEA;AACN;AACAU,IAAAA,aAAa,GAAG,qCAA+BZ,MAA/B,CAAhB;AACA;;AAED,SAAO,qBAAQ;AACdY,IAAAA,aADc;AAEdX,IAAAA;AAFc,GAAR,CAAP;AAIA","sourcesContent":["/**\n * Internal dependencies\n */\nimport create from './create';\nimport convertLegacyLocalStorageData from './migrations/legacy-local-storage-data';\n\nexport { create };\n\n/**\n * Creates the persistence layer with preloaded data.\n *\n * It prioritizes any data from the server, but falls back first to localStorage\n * restore data, and then to any legacy data.\n *\n * This function is used internally by WordPress in an inline script, so\n * prefixed with `__unstable`.\n *\n * @param {Object} serverData Preferences data preloaded from the server.\n * @param {string} userId The user id.\n *\n * @return {Object} The persistence layer initialized with the preloaded data.\n */\nexport function __unstableCreatePersistenceLayer( serverData, userId ) {\n\tconst localStorageRestoreKey = `WP_PREFERENCES_USER_${ userId }`;\n\tconst localData = JSON.parse(\n\t\twindow.localStorage.getItem( localStorageRestoreKey )\n\t);\n\n\t// Date parse returns NaN for invalid input. Coerce anything invalid\n\t// into a conveniently comparable zero.\n\tconst serverModified =\n\t\tDate.parse( serverData && serverData._modified ) || 0;\n\tconst localModified = Date.parse( localData && localData._modified ) || 0;\n\n\tlet preloadedData;\n\tif ( serverData && serverModified >= localModified ) {\n\t\tpreloadedData = serverData;\n\t} else if ( localData ) {\n\t\tpreloadedData = localData;\n\t} else {\n\t\t// Check if there is data in the legacy format from the old persistence system.\n\t\tpreloadedData = convertLegacyLocalStorageData( userId );\n\t}\n\n\treturn create( {\n\t\tpreloadedData,\n\t\tlocalStorageRestoreKey,\n\t} );\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/preferences-persistence/src/index.js"],"names":["__unstableCreatePersistenceLayer","serverData","userId","localStorageRestoreKey","localData","JSON","parse","window","localStorage","getItem","serverModified","Date","_modified","localModified","preloadedData"],"mappings":";;;;;;;;;;;;;;;AAGA;;AACA;;AACA;;AALA;AACA;AACA;;AAOA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,gCAAT,CAA2CC,UAA3C,EAAuDC,MAAvD,EAAgE;AACtE,QAAMC,sBAAsB,GAAI,uBAAuBD,MAAQ,EAA/D;AACA,QAAME,SAAS,GAAGC,IAAI,CAACC,KAAL,CACjBC,MAAM,CAACC,YAAP,CAAoBC,OAApB,CAA6BN,sBAA7B,CADiB,CAAlB,CAFsE,CAMtE;AACA;;AACA,QAAMO,cAAc,GACnBC,IAAI,CAACL,KAAL,CAAYL,UAAU,IAAIA,UAAU,CAACW,SAArC,KAAoD,CADrD;AAEA,QAAMC,aAAa,GAAGF,IAAI,CAACL,KAAL,CAAYF,SAAS,IAAIA,SAAS,CAACQ,SAAnC,KAAkD,CAAxE;AAEA,MAAIE,aAAJ;;AACA,MAAKb,UAAU,IAAIS,cAAc,IAAIG,aAArC,EAAqD;AACpDC,IAAAA,aAAa,GAAG,qCAA+Bb,UAA/B,CAAhB;AACA,GAFD,MAEO,IAAKG,SAAL,EAAiB;AACvBU,IAAAA,aAAa,GAAG,qCAA+BV,SAA/B,CAAhB;AACA,GAFM,MAEA;AACN;AACAU,IAAAA,aAAa,GAAG,qCAA+BZ,MAA/B,CAAhB;AACA;;AAED,SAAO,qBAAQ;AACdY,IAAAA,aADc;AAEdX,IAAAA;AAFc,GAAR,CAAP;AAIA","sourcesContent":["/**\n * Internal dependencies\n */\nimport create from './create';\nimport convertLegacyLocalStorageData from './migrations/legacy-local-storage-data';\nimport convertPreferencesPackageData from './migrations/preferences-package-data';\n\nexport { create };\n\n/**\n * Creates the persistence layer with preloaded data.\n *\n * It prioritizes any data from the server, but falls back first to localStorage\n * restore data, and then to any legacy data.\n *\n * This function is used internally by WordPress in an inline script, so\n * prefixed with `__unstable`.\n *\n * @param {Object} serverData Preferences data preloaded from the server.\n * @param {string} userId The user id.\n *\n * @return {Object} The persistence layer initialized with the preloaded data.\n */\nexport function __unstableCreatePersistenceLayer( serverData, userId ) {\n\tconst localStorageRestoreKey = `WP_PREFERENCES_USER_${ userId }`;\n\tconst localData = JSON.parse(\n\t\twindow.localStorage.getItem( localStorageRestoreKey )\n\t);\n\n\t// Date parse returns NaN for invalid input. Coerce anything invalid\n\t// into a conveniently comparable zero.\n\tconst serverModified =\n\t\tDate.parse( serverData && serverData._modified ) || 0;\n\tconst localModified = Date.parse( localData && localData._modified ) || 0;\n\n\tlet preloadedData;\n\tif ( serverData && serverModified >= localModified ) {\n\t\tpreloadedData = convertPreferencesPackageData( serverData );\n\t} else if ( localData ) {\n\t\tpreloadedData = convertPreferencesPackageData( localData );\n\t} else {\n\t\t// Check if there is data in the legacy format from the old persistence system.\n\t\tpreloadedData = convertLegacyLocalStorageData( userId );\n\t}\n\n\treturn create( {\n\t\tpreloadedData,\n\t\tlocalStorageRestoreKey,\n\t} );\n}\n"]}
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = convertComplementaryAreas;
7
+
8
+ function convertComplementaryAreas(state) {
9
+ return Object.keys(state).reduce((stateAccumulator, scope) => {
10
+ const scopeData = state[scope]; // If a complementary area is truthy, convert it to the `isComplementaryAreaVisible` boolean.
11
+
12
+ if (scopeData !== null && scopeData !== void 0 && scopeData.complementaryArea) {
13
+ const updatedScopeData = { ...scopeData
14
+ };
15
+ delete updatedScopeData.complementaryArea;
16
+ updatedScopeData.isComplementaryAreaVisible = true;
17
+ stateAccumulator[scope] = updatedScopeData;
18
+ return stateAccumulator;
19
+ }
20
+
21
+ return stateAccumulator;
22
+ }, state);
23
+ }
24
+ //# sourceMappingURL=convert-complementary-areas.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["@wordpress/preferences-persistence/src/migrations/preferences-package-data/convert-complementary-areas.js"],"names":["convertComplementaryAreas","state","Object","keys","reduce","stateAccumulator","scope","scopeData","complementaryArea","updatedScopeData","isComplementaryAreaVisible"],"mappings":";;;;;;;AAAe,SAASA,yBAAT,CAAoCC,KAApC,EAA4C;AAC1D,SAAOC,MAAM,CAACC,IAAP,CAAaF,KAAb,EAAqBG,MAArB,CAA6B,CAAEC,gBAAF,EAAoBC,KAApB,KAA+B;AAClE,UAAMC,SAAS,GAAGN,KAAK,CAAEK,KAAF,CAAvB,CADkE,CAGlE;;AACA,QAAKC,SAAL,aAAKA,SAAL,eAAKA,SAAS,CAAEC,iBAAhB,EAAoC;AACnC,YAAMC,gBAAgB,GAAG,EAAE,GAAGF;AAAL,OAAzB;AACA,aAAOE,gBAAgB,CAACD,iBAAxB;AACAC,MAAAA,gBAAgB,CAACC,0BAAjB,GAA8C,IAA9C;AACAL,MAAAA,gBAAgB,CAAEC,KAAF,CAAhB,GAA4BG,gBAA5B;AACA,aAAOJ,gBAAP;AACA;;AAED,WAAOA,gBAAP;AACA,GAbM,EAaJJ,KAbI,CAAP;AAcA","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"]}
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.default = convertPreferencesPackageData;
9
+
10
+ var _convertComplementaryAreas = _interopRequireDefault(require("./convert-complementary-areas"));
11
+
12
+ /**
13
+ * Internal dependencies
14
+ */
15
+ function convertPreferencesPackageData(data) {
16
+ return (0, _convertComplementaryAreas.default)(data);
17
+ }
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["@wordpress/preferences-persistence/src/migrations/preferences-package-data/index.js"],"names":["convertPreferencesPackageData","data"],"mappings":";;;;;;;;;AAGA;;AAHA;AACA;AACA;AAGe,SAASA,6BAAT,CAAwCC,IAAxC,EAA+C;AAC7D,SAAO,wCAA2BA,IAA3B,CAAP;AACA","sourcesContent":["/**\n * Internal dependencies\n */\nimport convertComplementaryAreas from './convert-complementary-areas';\n\nexport default function convertPreferencesPackageData( data ) {\n\treturn convertComplementaryAreas( data );\n}\n"]}
@@ -3,6 +3,7 @@
3
3
  */
4
4
  import create from './create';
5
5
  import convertLegacyLocalStorageData from './migrations/legacy-local-storage-data';
6
+ import convertPreferencesPackageData from './migrations/preferences-package-data';
6
7
  export { create };
7
8
  /**
8
9
  * Creates the persistence layer with preloaded data.
@@ -29,9 +30,9 @@ export function __unstableCreatePersistenceLayer(serverData, userId) {
29
30
  let preloadedData;
30
31
 
31
32
  if (serverData && serverModified >= localModified) {
32
- preloadedData = serverData;
33
+ preloadedData = convertPreferencesPackageData(serverData);
33
34
  } else if (localData) {
34
- preloadedData = localData;
35
+ preloadedData = convertPreferencesPackageData(localData);
35
36
  } else {
36
37
  // Check if there is data in the legacy format from the old persistence system.
37
38
  preloadedData = convertLegacyLocalStorageData(userId);
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/preferences-persistence/src/index.js"],"names":["create","convertLegacyLocalStorageData","__unstableCreatePersistenceLayer","serverData","userId","localStorageRestoreKey","localData","JSON","parse","window","localStorage","getItem","serverModified","Date","_modified","localModified","preloadedData"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,MAAP,MAAmB,UAAnB;AACA,OAAOC,6BAAP,MAA0C,wCAA1C;AAEA,SAASD,MAAT;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASE,gCAAT,CAA2CC,UAA3C,EAAuDC,MAAvD,EAAgE;AACtE,QAAMC,sBAAsB,GAAI,uBAAuBD,MAAQ,EAA/D;AACA,QAAME,SAAS,GAAGC,IAAI,CAACC,KAAL,CACjBC,MAAM,CAACC,YAAP,CAAoBC,OAApB,CAA6BN,sBAA7B,CADiB,CAAlB,CAFsE,CAMtE;AACA;;AACA,QAAMO,cAAc,GACnBC,IAAI,CAACL,KAAL,CAAYL,UAAU,IAAIA,UAAU,CAACW,SAArC,KAAoD,CADrD;AAEA,QAAMC,aAAa,GAAGF,IAAI,CAACL,KAAL,CAAYF,SAAS,IAAIA,SAAS,CAACQ,SAAnC,KAAkD,CAAxE;AAEA,MAAIE,aAAJ;;AACA,MAAKb,UAAU,IAAIS,cAAc,IAAIG,aAArC,EAAqD;AACpDC,IAAAA,aAAa,GAAGb,UAAhB;AACA,GAFD,MAEO,IAAKG,SAAL,EAAiB;AACvBU,IAAAA,aAAa,GAAGV,SAAhB;AACA,GAFM,MAEA;AACN;AACAU,IAAAA,aAAa,GAAGf,6BAA6B,CAAEG,MAAF,CAA7C;AACA;;AAED,SAAOJ,MAAM,CAAE;AACdgB,IAAAA,aADc;AAEdX,IAAAA;AAFc,GAAF,CAAb;AAIA","sourcesContent":["/**\n * Internal dependencies\n */\nimport create from './create';\nimport convertLegacyLocalStorageData from './migrations/legacy-local-storage-data';\n\nexport { create };\n\n/**\n * Creates the persistence layer with preloaded data.\n *\n * It prioritizes any data from the server, but falls back first to localStorage\n * restore data, and then to any legacy data.\n *\n * This function is used internally by WordPress in an inline script, so\n * prefixed with `__unstable`.\n *\n * @param {Object} serverData Preferences data preloaded from the server.\n * @param {string} userId The user id.\n *\n * @return {Object} The persistence layer initialized with the preloaded data.\n */\nexport function __unstableCreatePersistenceLayer( serverData, userId ) {\n\tconst localStorageRestoreKey = `WP_PREFERENCES_USER_${ userId }`;\n\tconst localData = JSON.parse(\n\t\twindow.localStorage.getItem( localStorageRestoreKey )\n\t);\n\n\t// Date parse returns NaN for invalid input. Coerce anything invalid\n\t// into a conveniently comparable zero.\n\tconst serverModified =\n\t\tDate.parse( serverData && serverData._modified ) || 0;\n\tconst localModified = Date.parse( localData && localData._modified ) || 0;\n\n\tlet preloadedData;\n\tif ( serverData && serverModified >= localModified ) {\n\t\tpreloadedData = serverData;\n\t} else if ( localData ) {\n\t\tpreloadedData = localData;\n\t} else {\n\t\t// Check if there is data in the legacy format from the old persistence system.\n\t\tpreloadedData = convertLegacyLocalStorageData( userId );\n\t}\n\n\treturn create( {\n\t\tpreloadedData,\n\t\tlocalStorageRestoreKey,\n\t} );\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/preferences-persistence/src/index.js"],"names":["create","convertLegacyLocalStorageData","convertPreferencesPackageData","__unstableCreatePersistenceLayer","serverData","userId","localStorageRestoreKey","localData","JSON","parse","window","localStorage","getItem","serverModified","Date","_modified","localModified","preloadedData"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,MAAP,MAAmB,UAAnB;AACA,OAAOC,6BAAP,MAA0C,wCAA1C;AACA,OAAOC,6BAAP,MAA0C,uCAA1C;AAEA,SAASF,MAAT;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASG,gCAAT,CAA2CC,UAA3C,EAAuDC,MAAvD,EAAgE;AACtE,QAAMC,sBAAsB,GAAI,uBAAuBD,MAAQ,EAA/D;AACA,QAAME,SAAS,GAAGC,IAAI,CAACC,KAAL,CACjBC,MAAM,CAACC,YAAP,CAAoBC,OAApB,CAA6BN,sBAA7B,CADiB,CAAlB,CAFsE,CAMtE;AACA;;AACA,QAAMO,cAAc,GACnBC,IAAI,CAACL,KAAL,CAAYL,UAAU,IAAIA,UAAU,CAACW,SAArC,KAAoD,CADrD;AAEA,QAAMC,aAAa,GAAGF,IAAI,CAACL,KAAL,CAAYF,SAAS,IAAIA,SAAS,CAACQ,SAAnC,KAAkD,CAAxE;AAEA,MAAIE,aAAJ;;AACA,MAAKb,UAAU,IAAIS,cAAc,IAAIG,aAArC,EAAqD;AACpDC,IAAAA,aAAa,GAAGf,6BAA6B,CAAEE,UAAF,CAA7C;AACA,GAFD,MAEO,IAAKG,SAAL,EAAiB;AACvBU,IAAAA,aAAa,GAAGf,6BAA6B,CAAEK,SAAF,CAA7C;AACA,GAFM,MAEA;AACN;AACAU,IAAAA,aAAa,GAAGhB,6BAA6B,CAAEI,MAAF,CAA7C;AACA;;AAED,SAAOL,MAAM,CAAE;AACdiB,IAAAA,aADc;AAEdX,IAAAA;AAFc,GAAF,CAAb;AAIA","sourcesContent":["/**\n * Internal dependencies\n */\nimport create from './create';\nimport convertLegacyLocalStorageData from './migrations/legacy-local-storage-data';\nimport convertPreferencesPackageData from './migrations/preferences-package-data';\n\nexport { create };\n\n/**\n * Creates the persistence layer with preloaded data.\n *\n * It prioritizes any data from the server, but falls back first to localStorage\n * restore data, and then to any legacy data.\n *\n * This function is used internally by WordPress in an inline script, so\n * prefixed with `__unstable`.\n *\n * @param {Object} serverData Preferences data preloaded from the server.\n * @param {string} userId The user id.\n *\n * @return {Object} The persistence layer initialized with the preloaded data.\n */\nexport function __unstableCreatePersistenceLayer( serverData, userId ) {\n\tconst localStorageRestoreKey = `WP_PREFERENCES_USER_${ userId }`;\n\tconst localData = JSON.parse(\n\t\twindow.localStorage.getItem( localStorageRestoreKey )\n\t);\n\n\t// Date parse returns NaN for invalid input. Coerce anything invalid\n\t// into a conveniently comparable zero.\n\tconst serverModified =\n\t\tDate.parse( serverData && serverData._modified ) || 0;\n\tconst localModified = Date.parse( localData && localData._modified ) || 0;\n\n\tlet preloadedData;\n\tif ( serverData && serverModified >= localModified ) {\n\t\tpreloadedData = convertPreferencesPackageData( serverData );\n\t} else if ( localData ) {\n\t\tpreloadedData = convertPreferencesPackageData( localData );\n\t} else {\n\t\t// Check if there is data in the legacy format from the old persistence system.\n\t\tpreloadedData = convertLegacyLocalStorageData( userId );\n\t}\n\n\treturn create( {\n\t\tpreloadedData,\n\t\tlocalStorageRestoreKey,\n\t} );\n}\n"]}
@@ -0,0 +1,17 @@
1
+ export default function convertComplementaryAreas(state) {
2
+ return Object.keys(state).reduce((stateAccumulator, scope) => {
3
+ const scopeData = state[scope]; // If a complementary area is truthy, convert it to the `isComplementaryAreaVisible` boolean.
4
+
5
+ if (scopeData !== null && scopeData !== void 0 && scopeData.complementaryArea) {
6
+ const updatedScopeData = { ...scopeData
7
+ };
8
+ delete updatedScopeData.complementaryArea;
9
+ updatedScopeData.isComplementaryAreaVisible = true;
10
+ stateAccumulator[scope] = updatedScopeData;
11
+ return stateAccumulator;
12
+ }
13
+
14
+ return stateAccumulator;
15
+ }, state);
16
+ }
17
+ //# sourceMappingURL=convert-complementary-areas.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["@wordpress/preferences-persistence/src/migrations/preferences-package-data/convert-complementary-areas.js"],"names":["convertComplementaryAreas","state","Object","keys","reduce","stateAccumulator","scope","scopeData","complementaryArea","updatedScopeData","isComplementaryAreaVisible"],"mappings":"AAAA,eAAe,SAASA,yBAAT,CAAoCC,KAApC,EAA4C;AAC1D,SAAOC,MAAM,CAACC,IAAP,CAAaF,KAAb,EAAqBG,MAArB,CAA6B,CAAEC,gBAAF,EAAoBC,KAApB,KAA+B;AAClE,UAAMC,SAAS,GAAGN,KAAK,CAAEK,KAAF,CAAvB,CADkE,CAGlE;;AACA,QAAKC,SAAL,aAAKA,SAAL,eAAKA,SAAS,CAAEC,iBAAhB,EAAoC;AACnC,YAAMC,gBAAgB,GAAG,EAAE,GAAGF;AAAL,OAAzB;AACA,aAAOE,gBAAgB,CAACD,iBAAxB;AACAC,MAAAA,gBAAgB,CAACC,0BAAjB,GAA8C,IAA9C;AACAL,MAAAA,gBAAgB,CAAEC,KAAF,CAAhB,GAA4BG,gBAA5B;AACA,aAAOJ,gBAAP;AACA;;AAED,WAAOA,gBAAP;AACA,GAbM,EAaJJ,KAbI,CAAP;AAcA","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"]}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Internal dependencies
3
+ */
4
+ import convertComplementaryAreas from './convert-complementary-areas';
5
+ export default function convertPreferencesPackageData(data) {
6
+ return convertComplementaryAreas(data);
7
+ }
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["@wordpress/preferences-persistence/src/migrations/preferences-package-data/index.js"],"names":["convertComplementaryAreas","convertPreferencesPackageData","data"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,yBAAP,MAAsC,+BAAtC;AAEA,eAAe,SAASC,6BAAT,CAAwCC,IAAxC,EAA+C;AAC7D,SAAOF,yBAAyB,CAAEE,IAAF,CAAhC;AACA","sourcesContent":["/**\n * Internal dependencies\n */\nimport convertComplementaryAreas from './convert-complementary-areas';\n\nexport default function convertPreferencesPackageData( data ) {\n\treturn convertComplementaryAreas( data );\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wordpress/preferences-persistence",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
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.5.0"
31
+ "@wordpress/api-fetch": "^6.6.0"
32
32
  },
33
33
  "publishConfig": {
34
34
  "access": "public"
35
35
  },
36
- "gitHead": "4631d515033397fcfeda77e5755960253caef9bf"
36
+ "gitHead": "198fa129cf1af8dc615918987ea6795cd40ab7df"
37
37
  }
package/src/index.js CHANGED
@@ -3,6 +3,7 @@
3
3
  */
4
4
  import create from './create';
5
5
  import convertLegacyLocalStorageData from './migrations/legacy-local-storage-data';
6
+ import convertPreferencesPackageData from './migrations/preferences-package-data';
6
7
 
7
8
  export { create };
8
9
 
@@ -34,9 +35,9 @@ export function __unstableCreatePersistenceLayer( serverData, userId ) {
34
35
 
35
36
  let preloadedData;
36
37
  if ( serverData && serverModified >= localModified ) {
37
- preloadedData = serverData;
38
+ preloadedData = convertPreferencesPackageData( serverData );
38
39
  } else if ( localData ) {
39
- preloadedData = localData;
40
+ preloadedData = convertPreferencesPackageData( localData );
40
41
  } else {
41
42
  // Check if there is data in the legacy format from the old persistence system.
42
43
  preloadedData = convertLegacyLocalStorageData( userId );
@@ -0,0 +1,16 @@
1
+ export default function convertComplementaryAreas( state ) {
2
+ return Object.keys( state ).reduce( ( stateAccumulator, scope ) => {
3
+ const scopeData = state[ scope ];
4
+
5
+ // If a complementary area is truthy, convert it to the `isComplementaryAreaVisible` boolean.
6
+ if ( scopeData?.complementaryArea ) {
7
+ const updatedScopeData = { ...scopeData };
8
+ delete updatedScopeData.complementaryArea;
9
+ updatedScopeData.isComplementaryAreaVisible = true;
10
+ stateAccumulator[ scope ] = updatedScopeData;
11
+ return stateAccumulator;
12
+ }
13
+
14
+ return stateAccumulator;
15
+ }, state );
16
+ }
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Internal dependencies
3
+ */
4
+ import convertComplementaryAreas from './convert-complementary-areas';
5
+
6
+ export default function convertPreferencesPackageData( data ) {
7
+ return convertComplementaryAreas( data );
8
+ }
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Internal dependencies
3
+ */
4
+ import convertComplementaryAreas from '../convert-complementary-areas';
5
+
6
+ describe( 'convertComplementaryAreas', () => {
7
+ it( 'converts the `complementaryArea` property in each scope to an `isComplementaryAreaVisible` boolean', () => {
8
+ const input = {
9
+ 'core/customize-widgets': {
10
+ complementaryArea: 'edit-post/block',
11
+ },
12
+ 'core/edit-site': {
13
+ complementaryArea: 'edit-site/template',
14
+ },
15
+ 'core/edit-post': {
16
+ complementaryArea: 'edit-post/block',
17
+ },
18
+ 'core/edit-widgets': {},
19
+ };
20
+
21
+ const expectedOutput = {
22
+ 'core/customize-widgets': {
23
+ isComplementaryAreaVisible: true,
24
+ },
25
+ 'core/edit-site': {
26
+ isComplementaryAreaVisible: true,
27
+ },
28
+ 'core/edit-post': {
29
+ isComplementaryAreaVisible: true,
30
+ },
31
+ 'core/edit-widgets': {},
32
+ };
33
+
34
+ expect( convertComplementaryAreas( input ) ).toEqual( expectedOutput );
35
+ } );
36
+ } );
@@ -0,0 +1,84 @@
1
+ /**
2
+ * Internal dependencies
3
+ */
4
+ import convertPreferencesPackageData from '../';
5
+
6
+ const input = {
7
+ 'core/customize-widgets': {
8
+ welcomeGuide: false,
9
+ fixedToolbar: true,
10
+ },
11
+ 'core/edit-widgets': {
12
+ welcomeGuide: false,
13
+ fixedToolbar: true,
14
+ showBlockBreadcrumbs: false,
15
+ complementaryArea: 'edit-widgets/block-areas',
16
+ },
17
+ 'core/edit-post': {
18
+ welcomeGuide: false,
19
+ fixedToolbar: true,
20
+ fullscreenMode: false,
21
+ hiddenBlockTypes: [ 'core/audio', 'core/cover' ],
22
+ editorMode: 'visual',
23
+ preferredStyleVariations: {
24
+ 'core/quote': 'large',
25
+ },
26
+ inactivePanels: [],
27
+ openPanels: [ 'post-status' ],
28
+ pinnedItems: {
29
+ 'my-sidebar-plugin/title-sidebar': false,
30
+ },
31
+ },
32
+ 'core/edit-site': {
33
+ welcomeGuide: false,
34
+ welcomeGuideStyles: false,
35
+ fixedToolbar: true,
36
+ complementaryArea: 'edit-site/global-styles',
37
+ },
38
+ };
39
+
40
+ describe( 'convertPreferencesPackageData', () => {
41
+ it( 'converts data to the expected format', () => {
42
+ expect( convertPreferencesPackageData( input ) )
43
+ .toMatchInlineSnapshot( `
44
+ Object {
45
+ "core/customize-widgets": Object {
46
+ "fixedToolbar": true,
47
+ "welcomeGuide": false,
48
+ },
49
+ "core/edit-post": Object {
50
+ "editorMode": "visual",
51
+ "fixedToolbar": true,
52
+ "fullscreenMode": false,
53
+ "hiddenBlockTypes": Array [
54
+ "core/audio",
55
+ "core/cover",
56
+ ],
57
+ "inactivePanels": Array [],
58
+ "openPanels": Array [
59
+ "post-status",
60
+ ],
61
+ "pinnedItems": Object {
62
+ "my-sidebar-plugin/title-sidebar": false,
63
+ },
64
+ "preferredStyleVariations": Object {
65
+ "core/quote": "large",
66
+ },
67
+ "welcomeGuide": false,
68
+ },
69
+ "core/edit-site": Object {
70
+ "fixedToolbar": true,
71
+ "isComplementaryAreaVisible": true,
72
+ "welcomeGuide": false,
73
+ "welcomeGuideStyles": false,
74
+ },
75
+ "core/edit-widgets": Object {
76
+ "fixedToolbar": true,
77
+ "isComplementaryAreaVisible": true,
78
+ "showBlockBreadcrumbs": false,
79
+ "welcomeGuide": false,
80
+ },
81
+ }
82
+ ` );
83
+ } );
84
+ } );