@wordpress/preferences-persistence 1.30.0 → 1.32.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.
Files changed (45) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/build/create/debounce-async.js +5 -7
  3. package/build/create/debounce-async.js.map +1 -1
  4. package/build/create/index.js +15 -18
  5. package/build/create/index.js.map +1 -1
  6. package/build/index.js +3 -9
  7. package/build/index.js.map +1 -1
  8. package/build/migrations/legacy-local-storage-data/convert-edit-post-panels.js +0 -5
  9. package/build/migrations/legacy-local-storage-data/convert-edit-post-panels.js.map +1 -1
  10. package/build/migrations/legacy-local-storage-data/index.js +15 -20
  11. package/build/migrations/legacy-local-storage-data/index.js.map +1 -1
  12. package/build/migrations/legacy-local-storage-data/move-feature-preferences.js +20 -19
  13. package/build/migrations/legacy-local-storage-data/move-feature-preferences.js.map +1 -1
  14. package/build/migrations/legacy-local-storage-data/move-individual-preference.js +18 -14
  15. package/build/migrations/legacy-local-storage-data/move-individual-preference.js.map +1 -1
  16. package/build/migrations/legacy-local-storage-data/move-interface-enable-items.js +23 -18
  17. package/build/migrations/legacy-local-storage-data/move-interface-enable-items.js.map +1 -1
  18. package/build/migrations/legacy-local-storage-data/move-third-party-feature-preferences.js +8 -12
  19. package/build/migrations/legacy-local-storage-data/move-third-party-feature-preferences.js.map +1 -1
  20. package/build/migrations/preferences-package-data/convert-complementary-areas.js +4 -4
  21. package/build/migrations/preferences-package-data/convert-complementary-areas.js.map +1 -1
  22. package/build/migrations/preferences-package-data/index.js +1 -3
  23. package/build/migrations/preferences-package-data/index.js.map +1 -1
  24. package/build-module/create/debounce-async.js +5 -6
  25. package/build-module/create/debounce-async.js.map +1 -1
  26. package/build-module/create/index.js +15 -15
  27. package/build-module/create/index.js.map +1 -1
  28. package/build-module/index.js +4 -5
  29. package/build-module/index.js.map +1 -1
  30. package/build-module/migrations/legacy-local-storage-data/convert-edit-post-panels.js +0 -4
  31. package/build-module/migrations/legacy-local-storage-data/convert-edit-post-panels.js.map +1 -1
  32. package/build-module/migrations/legacy-local-storage-data/index.js +16 -13
  33. package/build-module/migrations/legacy-local-storage-data/index.js.map +1 -1
  34. package/build-module/migrations/legacy-local-storage-data/move-feature-preferences.js +20 -18
  35. package/build-module/migrations/legacy-local-storage-data/move-feature-preferences.js.map +1 -1
  36. package/build-module/migrations/legacy-local-storage-data/move-individual-preference.js +18 -13
  37. package/build-module/migrations/legacy-local-storage-data/move-individual-preference.js.map +1 -1
  38. package/build-module/migrations/legacy-local-storage-data/move-interface-enable-items.js +23 -17
  39. package/build-module/migrations/legacy-local-storage-data/move-interface-enable-items.js.map +1 -1
  40. package/build-module/migrations/legacy-local-storage-data/move-third-party-feature-preferences.js +8 -11
  41. package/build-module/migrations/legacy-local-storage-data/move-third-party-feature-preferences.js.map +1 -1
  42. package/build-module/migrations/preferences-package-data/convert-complementary-areas.js +4 -3
  43. package/build-module/migrations/preferences-package-data/convert-complementary-areas.js.map +1 -1
  44. package/build-module/migrations/preferences-package-data/index.js.map +1 -1
  45. package/package.json +3 -3
package/CHANGELOG.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 1.32.0 (2023-08-16)
6
+
7
+ ## 1.31.0 (2023-08-10)
8
+
5
9
  ## 1.30.0 (2023-07-20)
6
10
 
7
11
  ## 1.29.0 (2023-07-05)
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = debounceAsync;
7
-
8
7
  /**
9
8
  * Performs a leading edge debounce of async functions.
10
9
  *
@@ -42,20 +41,19 @@ function debounceAsync(func, delayMS) {
42
41
  });
43
42
  });
44
43
  }
45
-
46
44
  if (activePromise) {
47
45
  // Let any active promises finish before queuing the next request.
48
46
  await activePromise;
49
- } // Clear any active timeouts, abandoning any requests that have
50
- // been queued but not been made.
51
-
47
+ }
52
48
 
49
+ // Clear any active timeouts, abandoning any requests that have
50
+ // been queued but not been made.
53
51
  if (timeoutId) {
54
52
  clearTimeout(timeoutId);
55
53
  timeoutId = null;
56
- } // Trigger any trailing edge calls to the function.
57
-
54
+ }
58
55
 
56
+ // Trigger any trailing edge calls to the function.
59
57
  return new Promise((resolve, reject) => {
60
58
  // Schedule the next request but with a delay.
61
59
  timeoutId = setTimeout(() => {
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/preferences-persistence/src/create/debounce-async.js"],"names":["debounceAsync","func","delayMS","timeoutId","activePromise","debounced","args","Promise","resolve","reject","then","thenArgs","catch","error","finally","clearTimeout","setTimeout"],"mappings":";;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,SAASA,aAAT,CAAwBC,IAAxB,EAA8BC,OAA9B,EAAwC;AACtD,MAAIC,SAAJ;AACA,MAAIC,aAAJ;AAEA,SAAO,eAAeC,SAAf,CAA0B,GAAGC,IAA7B,EAAoC;AAC1C;AACA;AACA,QAAK,CAAEF,aAAF,IAAmB,CAAED,SAA1B,EAAsC;AACrC,aAAO,IAAII,OAAJ,CAAa,CAAEC,OAAF,EAAWC,MAAX,KAAuB;AAC1C;AACAL,QAAAA,aAAa,GAAGH,IAAI,CAAE,GAAGK,IAAL,CAAJ,CACdI,IADc,CACR,CAAE,GAAGC,QAAL,KAAmB;AACzBH,UAAAA,OAAO,CAAE,GAAGG,QAAL,CAAP;AACA,SAHc,EAIdC,KAJc,CAILC,KAAF,IAAa;AACpBJ,UAAAA,MAAM,CAAEI,KAAF,CAAN;AACA,SANc,EAOdC,OAPc,CAOL,MAAM;AACf;AACA;AACAV,UAAAA,aAAa,GAAG,IAAhB;AACA,SAXc,CAAhB;AAYA,OAdM,CAAP;AAeA;;AAED,QAAKA,aAAL,EAAqB;AACpB;AACA,YAAMA,aAAN;AACA,KAxByC,CA0B1C;AACA;;;AACA,QAAKD,SAAL,EAAiB;AAChBY,MAAAA,YAAY,CAAEZ,SAAF,CAAZ;AACAA,MAAAA,SAAS,GAAG,IAAZ;AACA,KA/ByC,CAiC1C;;;AACA,WAAO,IAAII,OAAJ,CAAa,CAAEC,OAAF,EAAWC,MAAX,KAAuB;AAC1C;AACAN,MAAAA,SAAS,GAAGa,UAAU,CAAE,MAAM;AAC7BZ,QAAAA,aAAa,GAAGH,IAAI,CAAE,GAAGK,IAAL,CAAJ,CACdI,IADc,CACR,CAAE,GAAGC,QAAL,KAAmB;AACzBH,UAAAA,OAAO,CAAE,GAAGG,QAAL,CAAP;AACA,SAHc,EAIdC,KAJc,CAILC,KAAF,IAAa;AACpBJ,UAAAA,MAAM,CAAEI,KAAF,CAAN;AACA,SANc,EAOdC,OAPc,CAOL,MAAM;AACf;AACA;AACAV,UAAAA,aAAa,GAAG,IAAhB;AACAD,UAAAA,SAAS,GAAG,IAAZ;AACA,SAZc,CAAhB;AAaA,OAdqB,EAcnBD,OAdmB,CAAtB;AAeA,KAjBM,CAAP;AAkBA,GApDD;AAqDA","sourcesContent":["/**\n * Performs a leading edge debounce of async functions.\n *\n * If three functions are throttled at the same time:\n * - The first happens immediately.\n * - The second is never called.\n * - The third happens `delayMS` milliseconds after the first has resolved.\n *\n * This is distinct from `{ debounce } from @wordpress/compose` in that it\n * waits for promise resolution.\n *\n * @param {Function} func A function that returns a promise.\n * @param {number} delayMS A delay in milliseconds.\n *\n * @return {Function} A function that debounce whatever function is passed\n * to it.\n */\nexport default function debounceAsync( func, delayMS ) {\n\tlet timeoutId;\n\tlet activePromise;\n\n\treturn async function debounced( ...args ) {\n\t\t// This is a leading edge debounce. If there's no promise or timeout\n\t\t// in progress, call the debounced function immediately.\n\t\tif ( ! activePromise && ! timeoutId ) {\n\t\t\treturn new Promise( ( resolve, reject ) => {\n\t\t\t\t// Keep a reference to the promise.\n\t\t\t\tactivePromise = func( ...args )\n\t\t\t\t\t.then( ( ...thenArgs ) => {\n\t\t\t\t\t\tresolve( ...thenArgs );\n\t\t\t\t\t} )\n\t\t\t\t\t.catch( ( error ) => {\n\t\t\t\t\t\treject( error );\n\t\t\t\t\t} )\n\t\t\t\t\t.finally( () => {\n\t\t\t\t\t\t// As soon this promise is complete, clear the way for the\n\t\t\t\t\t\t// next one to happen immediately.\n\t\t\t\t\t\tactivePromise = null;\n\t\t\t\t\t} );\n\t\t\t} );\n\t\t}\n\n\t\tif ( activePromise ) {\n\t\t\t// Let any active promises finish before queuing the next request.\n\t\t\tawait activePromise;\n\t\t}\n\n\t\t// Clear any active timeouts, abandoning any requests that have\n\t\t// been queued but not been made.\n\t\tif ( timeoutId ) {\n\t\t\tclearTimeout( timeoutId );\n\t\t\ttimeoutId = null;\n\t\t}\n\n\t\t// Trigger any trailing edge calls to the function.\n\t\treturn new Promise( ( resolve, reject ) => {\n\t\t\t// Schedule the next request but with a delay.\n\t\t\ttimeoutId = setTimeout( () => {\n\t\t\t\tactivePromise = func( ...args )\n\t\t\t\t\t.then( ( ...thenArgs ) => {\n\t\t\t\t\t\tresolve( ...thenArgs );\n\t\t\t\t\t} )\n\t\t\t\t\t.catch( ( error ) => {\n\t\t\t\t\t\treject( error );\n\t\t\t\t\t} )\n\t\t\t\t\t.finally( () => {\n\t\t\t\t\t\t// As soon this promise is complete, clear the way for the\n\t\t\t\t\t\t// next one to happen immediately.\n\t\t\t\t\t\tactivePromise = null;\n\t\t\t\t\t\ttimeoutId = null;\n\t\t\t\t\t} );\n\t\t\t}, delayMS );\n\t\t} );\n\t};\n}\n"]}
1
+ {"version":3,"names":["debounceAsync","func","delayMS","timeoutId","activePromise","debounced","args","Promise","resolve","reject","then","thenArgs","catch","error","finally","clearTimeout","setTimeout"],"sources":["@wordpress/preferences-persistence/src/create/debounce-async.js"],"sourcesContent":["/**\n * Performs a leading edge debounce of async functions.\n *\n * If three functions are throttled at the same time:\n * - The first happens immediately.\n * - The second is never called.\n * - The third happens `delayMS` milliseconds after the first has resolved.\n *\n * This is distinct from `{ debounce } from @wordpress/compose` in that it\n * waits for promise resolution.\n *\n * @param {Function} func A function that returns a promise.\n * @param {number} delayMS A delay in milliseconds.\n *\n * @return {Function} A function that debounce whatever function is passed\n * to it.\n */\nexport default function debounceAsync( func, delayMS ) {\n\tlet timeoutId;\n\tlet activePromise;\n\n\treturn async function debounced( ...args ) {\n\t\t// This is a leading edge debounce. If there's no promise or timeout\n\t\t// in progress, call the debounced function immediately.\n\t\tif ( ! activePromise && ! timeoutId ) {\n\t\t\treturn new Promise( ( resolve, reject ) => {\n\t\t\t\t// Keep a reference to the promise.\n\t\t\t\tactivePromise = func( ...args )\n\t\t\t\t\t.then( ( ...thenArgs ) => {\n\t\t\t\t\t\tresolve( ...thenArgs );\n\t\t\t\t\t} )\n\t\t\t\t\t.catch( ( error ) => {\n\t\t\t\t\t\treject( error );\n\t\t\t\t\t} )\n\t\t\t\t\t.finally( () => {\n\t\t\t\t\t\t// As soon this promise is complete, clear the way for the\n\t\t\t\t\t\t// next one to happen immediately.\n\t\t\t\t\t\tactivePromise = null;\n\t\t\t\t\t} );\n\t\t\t} );\n\t\t}\n\n\t\tif ( activePromise ) {\n\t\t\t// Let any active promises finish before queuing the next request.\n\t\t\tawait activePromise;\n\t\t}\n\n\t\t// Clear any active timeouts, abandoning any requests that have\n\t\t// been queued but not been made.\n\t\tif ( timeoutId ) {\n\t\t\tclearTimeout( timeoutId );\n\t\t\ttimeoutId = null;\n\t\t}\n\n\t\t// Trigger any trailing edge calls to the function.\n\t\treturn new Promise( ( resolve, reject ) => {\n\t\t\t// Schedule the next request but with a delay.\n\t\t\ttimeoutId = setTimeout( () => {\n\t\t\t\tactivePromise = func( ...args )\n\t\t\t\t\t.then( ( ...thenArgs ) => {\n\t\t\t\t\t\tresolve( ...thenArgs );\n\t\t\t\t\t} )\n\t\t\t\t\t.catch( ( error ) => {\n\t\t\t\t\t\treject( error );\n\t\t\t\t\t} )\n\t\t\t\t\t.finally( () => {\n\t\t\t\t\t\t// As soon this promise is complete, clear the way for the\n\t\t\t\t\t\t// next one to happen immediately.\n\t\t\t\t\t\tactivePromise = null;\n\t\t\t\t\t\ttimeoutId = null;\n\t\t\t\t\t} );\n\t\t\t}, delayMS );\n\t\t} );\n\t};\n}\n"],"mappings":";;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,SAASA,aAAaA,CAAEC,IAAI,EAAEC,OAAO,EAAG;EACtD,IAAIC,SAAS;EACb,IAAIC,aAAa;EAEjB,OAAO,eAAeC,SAASA,CAAE,GAAGC,IAAI,EAAG;IAC1C;IACA;IACA,IAAK,CAAEF,aAAa,IAAI,CAAED,SAAS,EAAG;MACrC,OAAO,IAAII,OAAO,CAAE,CAAEC,OAAO,EAAEC,MAAM,KAAM;QAC1C;QACAL,aAAa,GAAGH,IAAI,CAAE,GAAGK,IAAK,CAAC,CAC7BI,IAAI,CAAE,CAAE,GAAGC,QAAQ,KAAM;UACzBH,OAAO,CAAE,GAAGG,QAAS,CAAC;QACvB,CAAE,CAAC,CACFC,KAAK,CAAIC,KAAK,IAAM;UACpBJ,MAAM,CAAEI,KAAM,CAAC;QAChB,CAAE,CAAC,CACFC,OAAO,CAAE,MAAM;UACf;UACA;UACAV,aAAa,GAAG,IAAI;QACrB,CAAE,CAAC;MACL,CAAE,CAAC;IACJ;IAEA,IAAKA,aAAa,EAAG;MACpB;MACA,MAAMA,aAAa;IACpB;;IAEA;IACA;IACA,IAAKD,SAAS,EAAG;MAChBY,YAAY,CAAEZ,SAAU,CAAC;MACzBA,SAAS,GAAG,IAAI;IACjB;;IAEA;IACA,OAAO,IAAII,OAAO,CAAE,CAAEC,OAAO,EAAEC,MAAM,KAAM;MAC1C;MACAN,SAAS,GAAGa,UAAU,CAAE,MAAM;QAC7BZ,aAAa,GAAGH,IAAI,CAAE,GAAGK,IAAK,CAAC,CAC7BI,IAAI,CAAE,CAAE,GAAGC,QAAQ,KAAM;UACzBH,OAAO,CAAE,GAAGG,QAAS,CAAC;QACvB,CAAE,CAAC,CACFC,KAAK,CAAIC,KAAK,IAAM;UACpBJ,MAAM,CAAEI,KAAM,CAAC;QAChB,CAAE,CAAC,CACFC,OAAO,CAAE,MAAM;UACf;UACA;UACAV,aAAa,GAAG,IAAI;UACpBD,SAAS,GAAG,IAAI;QACjB,CAAE,CAAC;MACL,CAAC,EAAED,OAAQ,CAAC;IACb,CAAE,CAAC;EACJ,CAAC;AACF"}
@@ -1,16 +1,12 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.default = create;
9
-
10
8
  var _apiFetch = _interopRequireDefault(require("@wordpress/api-fetch"));
11
-
12
9
  var _debounceAsync = _interopRequireDefault(require("./debounce-async"));
13
-
14
10
  /**
15
11
  * WordPress dependencies
16
12
  */
@@ -18,8 +14,10 @@ var _debounceAsync = _interopRequireDefault(require("./debounce-async"));
18
14
  /**
19
15
  * Internal dependencies
20
16
  */
17
+
21
18
  const EMPTY_OBJECT = {};
22
19
  const localStorage = window.localStorage;
20
+
23
21
  /**
24
22
  * Creates a persistence layer that stores data in WordPress user meta via the
25
23
  * REST API.
@@ -37,7 +35,6 @@ const localStorage = window.localStorage;
37
35
  *
38
36
  * @return {Object} A persistence layer for WordPress user meta.
39
37
  */
40
-
41
38
  function create({
42
39
  preloadedData,
43
40
  localStorageRestoreKey = 'WP_PREFERENCES_RESTORE_DATA',
@@ -45,23 +42,23 @@ function create({
45
42
  } = {}) {
46
43
  let cache = preloadedData;
47
44
  const debouncedApiFetch = (0, _debounceAsync.default)(_apiFetch.default, requestDebounceMS);
48
-
49
45
  async function get() {
50
46
  if (cache) {
51
47
  return cache;
52
48
  }
53
-
54
49
  const user = await (0, _apiFetch.default)({
55
50
  path: '/wp/v2/users/me?context=edit'
56
51
  });
57
52
  const serverData = user?.meta?.persisted_preferences;
58
- const localData = JSON.parse(localStorage.getItem(localStorageRestoreKey)); // Date parse returns NaN for invalid input. Coerce anything invalid
59
- // into a conveniently comparable zero.
53
+ const localData = JSON.parse(localStorage.getItem(localStorageRestoreKey));
60
54
 
55
+ // Date parse returns NaN for invalid input. Coerce anything invalid
56
+ // into a conveniently comparable zero.
61
57
  const serverTimestamp = Date.parse(serverData?._modified) || 0;
62
- const localTimestamp = Date.parse(localData?._modified) || 0; // Prefer server data if it exists and is more recent.
63
- // Otherwise fallback to localStorage data.
58
+ const localTimestamp = Date.parse(localData?._modified) || 0;
64
59
 
60
+ // Prefer server data if it exists and is more recent.
61
+ // Otherwise fallback to localStorage data.
65
62
  if (serverData && serverTimestamp >= localTimestamp) {
66
63
  cache = serverData;
67
64
  } else if (localData) {
@@ -69,24 +66,25 @@ function create({
69
66
  } else {
70
67
  cache = EMPTY_OBJECT;
71
68
  }
72
-
73
69
  return cache;
74
70
  }
75
-
76
71
  function set(newData) {
77
- const dataWithTimestamp = { ...newData,
72
+ const dataWithTimestamp = {
73
+ ...newData,
78
74
  _modified: new Date().toISOString()
79
75
  };
80
- cache = dataWithTimestamp; // Store data in local storage as a fallback. If for some reason the
76
+ cache = dataWithTimestamp;
77
+
78
+ // Store data in local storage as a fallback. If for some reason the
81
79
  // api request does not complete or becomes unavailable, this data
82
80
  // can be used to restore preferences.
81
+ localStorage.setItem(localStorageRestoreKey, JSON.stringify(dataWithTimestamp));
83
82
 
84
- localStorage.setItem(localStorageRestoreKey, JSON.stringify(dataWithTimestamp)); // The user meta endpoint seems susceptible to errors when consecutive
83
+ // The user meta endpoint seems susceptible to errors when consecutive
85
84
  // requests are made in quick succession. Ensure there's a gap between
86
85
  // any consecutive requests.
87
86
  //
88
87
  // Catch and do nothing with errors from the REST API.
89
-
90
88
  debouncedApiFetch({
91
89
  path: '/wp/v2/users/me',
92
90
  method: 'PUT',
@@ -103,7 +101,6 @@ function create({
103
101
  }
104
102
  }).catch(() => {});
105
103
  }
106
-
107
104
  return {
108
105
  get,
109
106
  set
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/preferences-persistence/src/create/index.js"],"names":["EMPTY_OBJECT","localStorage","window","create","preloadedData","localStorageRestoreKey","requestDebounceMS","cache","debouncedApiFetch","apiFetch","get","user","path","serverData","meta","persisted_preferences","localData","JSON","parse","getItem","serverTimestamp","Date","_modified","localTimestamp","set","newData","dataWithTimestamp","toISOString","setItem","stringify","method","keepalive","data","catch"],"mappings":";;;;;;;;;AAGA;;AAKA;;AARA;AACA;AACA;;AAGA;AACA;AACA;AAGA,MAAMA,YAAY,GAAG,EAArB;AACA,MAAMC,YAAY,GAAGC,MAAM,CAACD,YAA5B;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACe,SAASE,MAAT,CAAiB;AAC/BC,EAAAA,aAD+B;AAE/BC,EAAAA,sBAAsB,GAAG,6BAFM;AAG/BC,EAAAA,iBAAiB,GAAG;AAHW,IAI5B,EAJW,EAIN;AACR,MAAIC,KAAK,GAAGH,aAAZ;AACA,QAAMI,iBAAiB,GAAG,4BAAeC,iBAAf,EAAyBH,iBAAzB,CAA1B;;AAEA,iBAAeI,GAAf,GAAqB;AACpB,QAAKH,KAAL,EAAa;AACZ,aAAOA,KAAP;AACA;;AAED,UAAMI,IAAI,GAAG,MAAM,uBAAU;AAC5BC,MAAAA,IAAI,EAAE;AADsB,KAAV,CAAnB;AAIA,UAAMC,UAAU,GAAGF,IAAI,EAAEG,IAAN,EAAYC,qBAA/B;AACA,UAAMC,SAAS,GAAGC,IAAI,CAACC,KAAL,CACjBjB,YAAY,CAACkB,OAAb,CAAsBd,sBAAtB,CADiB,CAAlB,CAVoB,CAcpB;AACA;;AACA,UAAMe,eAAe,GAAGC,IAAI,CAACH,KAAL,CAAYL,UAAU,EAAES,SAAxB,KAAuC,CAA/D;AACA,UAAMC,cAAc,GAAGF,IAAI,CAACH,KAAL,CAAYF,SAAS,EAAEM,SAAvB,KAAsC,CAA7D,CAjBoB,CAmBpB;AACA;;AACA,QAAKT,UAAU,IAAIO,eAAe,IAAIG,cAAtC,EAAuD;AACtDhB,MAAAA,KAAK,GAAGM,UAAR;AACA,KAFD,MAEO,IAAKG,SAAL,EAAiB;AACvBT,MAAAA,KAAK,GAAGS,SAAR;AACA,KAFM,MAEA;AACNT,MAAAA,KAAK,GAAGP,YAAR;AACA;;AAED,WAAOO,KAAP;AACA;;AAED,WAASiB,GAAT,CAAcC,OAAd,EAAwB;AACvB,UAAMC,iBAAiB,GAAG,EACzB,GAAGD,OADsB;AAEzBH,MAAAA,SAAS,EAAE,IAAID,IAAJ,GAAWM,WAAX;AAFc,KAA1B;AAIApB,IAAAA,KAAK,GAAGmB,iBAAR,CALuB,CAOvB;AACA;AACA;;AACAzB,IAAAA,YAAY,CAAC2B,OAAb,CACCvB,sBADD,EAECY,IAAI,CAACY,SAAL,CAAgBH,iBAAhB,CAFD,EAVuB,CAevB;AACA;AACA;AACA;AACA;;AACAlB,IAAAA,iBAAiB,CAAE;AAClBI,MAAAA,IAAI,EAAE,iBADY;AAElBkB,MAAAA,MAAM,EAAE,KAFU;AAGlB;AACA;AACA;AACA;AACA;AACAC,MAAAA,SAAS,EAAE,IARO;AASlBC,MAAAA,IAAI,EAAE;AACLlB,QAAAA,IAAI,EAAE;AACLC,UAAAA,qBAAqB,EAAEW;AADlB;AADD;AATY,KAAF,CAAjB,CAcIO,KAdJ,CAcW,MAAM,CAAE,CAdnB;AAeA;;AAED,SAAO;AACNvB,IAAAA,GADM;AAENc,IAAAA;AAFM,GAAP;AAIA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport apiFetch from '@wordpress/api-fetch';\n\n/**\n * Internal dependencies\n */\nimport debounceAsync from './debounce-async';\n\nconst EMPTY_OBJECT = {};\nconst localStorage = window.localStorage;\n\n/**\n * Creates a persistence layer that stores data in WordPress user meta via the\n * REST API.\n *\n * @param {Object} options\n * @param {?Object} options.preloadedData Any persisted preferences data that should be preloaded.\n * When set, the persistence layer will avoid fetching data\n * from the REST API.\n * @param {?string} options.localStorageRestoreKey The key to use for restoring the localStorage backup, used\n * when the persistence layer calls `localStorage.getItem` or\n * `localStorage.setItem`.\n * @param {?number} options.requestDebounceMS Debounce requests to the API so that they only occur at\n * minimum every `requestDebounceMS` milliseconds, and don't\n * swamp the server. Defaults to 2500ms.\n *\n * @return {Object} A persistence layer for WordPress user meta.\n */\nexport default function create( {\n\tpreloadedData,\n\tlocalStorageRestoreKey = 'WP_PREFERENCES_RESTORE_DATA',\n\trequestDebounceMS = 2500,\n} = {} ) {\n\tlet cache = preloadedData;\n\tconst debouncedApiFetch = debounceAsync( apiFetch, requestDebounceMS );\n\n\tasync function get() {\n\t\tif ( cache ) {\n\t\t\treturn cache;\n\t\t}\n\n\t\tconst user = await apiFetch( {\n\t\t\tpath: '/wp/v2/users/me?context=edit',\n\t\t} );\n\n\t\tconst serverData = user?.meta?.persisted_preferences;\n\t\tconst localData = JSON.parse(\n\t\t\tlocalStorage.getItem( localStorageRestoreKey )\n\t\t);\n\n\t\t// Date parse returns NaN for invalid input. Coerce anything invalid\n\t\t// into a conveniently comparable zero.\n\t\tconst serverTimestamp = Date.parse( serverData?._modified ) || 0;\n\t\tconst localTimestamp = Date.parse( localData?._modified ) || 0;\n\n\t\t// Prefer server data if it exists and is more recent.\n\t\t// Otherwise fallback to localStorage data.\n\t\tif ( serverData && serverTimestamp >= localTimestamp ) {\n\t\t\tcache = serverData;\n\t\t} else if ( localData ) {\n\t\t\tcache = localData;\n\t\t} else {\n\t\t\tcache = EMPTY_OBJECT;\n\t\t}\n\n\t\treturn cache;\n\t}\n\n\tfunction set( newData ) {\n\t\tconst dataWithTimestamp = {\n\t\t\t...newData,\n\t\t\t_modified: new Date().toISOString(),\n\t\t};\n\t\tcache = dataWithTimestamp;\n\n\t\t// Store data in local storage as a fallback. If for some reason the\n\t\t// api request does not complete or becomes unavailable, this data\n\t\t// can be used to restore preferences.\n\t\tlocalStorage.setItem(\n\t\t\tlocalStorageRestoreKey,\n\t\t\tJSON.stringify( dataWithTimestamp )\n\t\t);\n\n\t\t// The user meta endpoint seems susceptible to errors when consecutive\n\t\t// requests are made in quick succession. Ensure there's a gap between\n\t\t// any consecutive requests.\n\t\t//\n\t\t// Catch and do nothing with errors from the REST API.\n\t\tdebouncedApiFetch( {\n\t\t\tpath: '/wp/v2/users/me',\n\t\t\tmethod: 'PUT',\n\t\t\t// `keepalive` will still send the request in the background,\n\t\t\t// even when a browser unload event might interrupt it.\n\t\t\t// This should hopefully make things more resilient.\n\t\t\t// This does have a size limit of 64kb, but the data is usually\n\t\t\t// much less.\n\t\t\tkeepalive: true,\n\t\t\tdata: {\n\t\t\t\tmeta: {\n\t\t\t\t\tpersisted_preferences: dataWithTimestamp,\n\t\t\t\t},\n\t\t\t},\n\t\t} ).catch( () => {} );\n\t}\n\n\treturn {\n\t\tget,\n\t\tset,\n\t};\n}\n"]}
1
+ {"version":3,"names":["_apiFetch","_interopRequireDefault","require","_debounceAsync","EMPTY_OBJECT","localStorage","window","create","preloadedData","localStorageRestoreKey","requestDebounceMS","cache","debouncedApiFetch","debounceAsync","apiFetch","get","user","path","serverData","meta","persisted_preferences","localData","JSON","parse","getItem","serverTimestamp","Date","_modified","localTimestamp","set","newData","dataWithTimestamp","toISOString","setItem","stringify","method","keepalive","data","catch"],"sources":["@wordpress/preferences-persistence/src/create/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport apiFetch from '@wordpress/api-fetch';\n\n/**\n * Internal dependencies\n */\nimport debounceAsync from './debounce-async';\n\nconst EMPTY_OBJECT = {};\nconst localStorage = window.localStorage;\n\n/**\n * Creates a persistence layer that stores data in WordPress user meta via the\n * REST API.\n *\n * @param {Object} options\n * @param {?Object} options.preloadedData Any persisted preferences data that should be preloaded.\n * When set, the persistence layer will avoid fetching data\n * from the REST API.\n * @param {?string} options.localStorageRestoreKey The key to use for restoring the localStorage backup, used\n * when the persistence layer calls `localStorage.getItem` or\n * `localStorage.setItem`.\n * @param {?number} options.requestDebounceMS Debounce requests to the API so that they only occur at\n * minimum every `requestDebounceMS` milliseconds, and don't\n * swamp the server. Defaults to 2500ms.\n *\n * @return {Object} A persistence layer for WordPress user meta.\n */\nexport default function create( {\n\tpreloadedData,\n\tlocalStorageRestoreKey = 'WP_PREFERENCES_RESTORE_DATA',\n\trequestDebounceMS = 2500,\n} = {} ) {\n\tlet cache = preloadedData;\n\tconst debouncedApiFetch = debounceAsync( apiFetch, requestDebounceMS );\n\n\tasync function get() {\n\t\tif ( cache ) {\n\t\t\treturn cache;\n\t\t}\n\n\t\tconst user = await apiFetch( {\n\t\t\tpath: '/wp/v2/users/me?context=edit',\n\t\t} );\n\n\t\tconst serverData = user?.meta?.persisted_preferences;\n\t\tconst localData = JSON.parse(\n\t\t\tlocalStorage.getItem( localStorageRestoreKey )\n\t\t);\n\n\t\t// Date parse returns NaN for invalid input. Coerce anything invalid\n\t\t// into a conveniently comparable zero.\n\t\tconst serverTimestamp = Date.parse( serverData?._modified ) || 0;\n\t\tconst localTimestamp = Date.parse( localData?._modified ) || 0;\n\n\t\t// Prefer server data if it exists and is more recent.\n\t\t// Otherwise fallback to localStorage data.\n\t\tif ( serverData && serverTimestamp >= localTimestamp ) {\n\t\t\tcache = serverData;\n\t\t} else if ( localData ) {\n\t\t\tcache = localData;\n\t\t} else {\n\t\t\tcache = EMPTY_OBJECT;\n\t\t}\n\n\t\treturn cache;\n\t}\n\n\tfunction set( newData ) {\n\t\tconst dataWithTimestamp = {\n\t\t\t...newData,\n\t\t\t_modified: new Date().toISOString(),\n\t\t};\n\t\tcache = dataWithTimestamp;\n\n\t\t// Store data in local storage as a fallback. If for some reason the\n\t\t// api request does not complete or becomes unavailable, this data\n\t\t// can be used to restore preferences.\n\t\tlocalStorage.setItem(\n\t\t\tlocalStorageRestoreKey,\n\t\t\tJSON.stringify( dataWithTimestamp )\n\t\t);\n\n\t\t// The user meta endpoint seems susceptible to errors when consecutive\n\t\t// requests are made in quick succession. Ensure there's a gap between\n\t\t// any consecutive requests.\n\t\t//\n\t\t// Catch and do nothing with errors from the REST API.\n\t\tdebouncedApiFetch( {\n\t\t\tpath: '/wp/v2/users/me',\n\t\t\tmethod: 'PUT',\n\t\t\t// `keepalive` will still send the request in the background,\n\t\t\t// even when a browser unload event might interrupt it.\n\t\t\t// This should hopefully make things more resilient.\n\t\t\t// This does have a size limit of 64kb, but the data is usually\n\t\t\t// much less.\n\t\t\tkeepalive: true,\n\t\t\tdata: {\n\t\t\t\tmeta: {\n\t\t\t\t\tpersisted_preferences: dataWithTimestamp,\n\t\t\t\t},\n\t\t\t},\n\t\t} ).catch( () => {} );\n\t}\n\n\treturn {\n\t\tget,\n\t\tset,\n\t};\n}\n"],"mappings":";;;;;;;AAGA,IAAAA,SAAA,GAAAC,sBAAA,CAAAC,OAAA;AAKA,IAAAC,cAAA,GAAAF,sBAAA,CAAAC,OAAA;AARA;AACA;AACA;;AAGA;AACA;AACA;;AAGA,MAAME,YAAY,GAAG,CAAC,CAAC;AACvB,MAAMC,YAAY,GAAGC,MAAM,CAACD,YAAY;;AAExC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,SAASE,MAAMA,CAAE;EAC/BC,aAAa;EACbC,sBAAsB,GAAG,6BAA6B;EACtDC,iBAAiB,GAAG;AACrB,CAAC,GAAG,CAAC,CAAC,EAAG;EACR,IAAIC,KAAK,GAAGH,aAAa;EACzB,MAAMI,iBAAiB,GAAG,IAAAC,sBAAa,EAAEC,iBAAQ,EAAEJ,iBAAkB,CAAC;EAEtE,eAAeK,GAAGA,CAAA,EAAG;IACpB,IAAKJ,KAAK,EAAG;MACZ,OAAOA,KAAK;IACb;IAEA,MAAMK,IAAI,GAAG,MAAM,IAAAF,iBAAQ,EAAE;MAC5BG,IAAI,EAAE;IACP,CAAE,CAAC;IAEH,MAAMC,UAAU,GAAGF,IAAI,EAAEG,IAAI,EAAEC,qBAAqB;IACpD,MAAMC,SAAS,GAAGC,IAAI,CAACC,KAAK,CAC3BlB,YAAY,CAACmB,OAAO,CAAEf,sBAAuB,CAC9C,CAAC;;IAED;IACA;IACA,MAAMgB,eAAe,GAAGC,IAAI,CAACH,KAAK,CAAEL,UAAU,EAAES,SAAU,CAAC,IAAI,CAAC;IAChE,MAAMC,cAAc,GAAGF,IAAI,CAACH,KAAK,CAAEF,SAAS,EAAEM,SAAU,CAAC,IAAI,CAAC;;IAE9D;IACA;IACA,IAAKT,UAAU,IAAIO,eAAe,IAAIG,cAAc,EAAG;MACtDjB,KAAK,GAAGO,UAAU;IACnB,CAAC,MAAM,IAAKG,SAAS,EAAG;MACvBV,KAAK,GAAGU,SAAS;IAClB,CAAC,MAAM;MACNV,KAAK,GAAGP,YAAY;IACrB;IAEA,OAAOO,KAAK;EACb;EAEA,SAASkB,GAAGA,CAAEC,OAAO,EAAG;IACvB,MAAMC,iBAAiB,GAAG;MACzB,GAAGD,OAAO;MACVH,SAAS,EAAE,IAAID,IAAI,CAAC,CAAC,CAACM,WAAW,CAAC;IACnC,CAAC;IACDrB,KAAK,GAAGoB,iBAAiB;;IAEzB;IACA;IACA;IACA1B,YAAY,CAAC4B,OAAO,CACnBxB,sBAAsB,EACtBa,IAAI,CAACY,SAAS,CAAEH,iBAAkB,CACnC,CAAC;;IAED;IACA;IACA;IACA;IACA;IACAnB,iBAAiB,CAAE;MAClBK,IAAI,EAAE,iBAAiB;MACvBkB,MAAM,EAAE,KAAK;MACb;MACA;MACA;MACA;MACA;MACAC,SAAS,EAAE,IAAI;MACfC,IAAI,EAAE;QACLlB,IAAI,EAAE;UACLC,qBAAqB,EAAEW;QACxB;MACD;IACD,CAAE,CAAC,CAACO,KAAK,CAAE,MAAM,CAAC,CAAE,CAAC;EACtB;EAEA,OAAO;IACNvB,GAAG;IACHc;EACD,CAAC;AACF"}
package/build/index.js CHANGED
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
@@ -12,13 +11,9 @@ Object.defineProperty(exports, "create", {
12
11
  return _create.default;
13
12
  }
14
13
  });
15
-
16
14
  var _create = _interopRequireDefault(require("./create"));
17
-
18
15
  var _legacyLocalStorageData = _interopRequireDefault(require("./migrations/legacy-local-storage-data"));
19
-
20
16
  var _preferencesPackageData = _interopRequireDefault(require("./migrations/preferences-package-data"));
21
-
22
17
  /**
23
18
  * Internal dependencies
24
19
  */
@@ -39,13 +34,13 @@ var _preferencesPackageData = _interopRequireDefault(require("./migrations/prefe
39
34
  */
40
35
  function __unstableCreatePersistenceLayer(serverData, userId) {
41
36
  const localStorageRestoreKey = `WP_PREFERENCES_USER_${userId}`;
42
- const localData = JSON.parse(window.localStorage.getItem(localStorageRestoreKey)); // Date parse returns NaN for invalid input. Coerce anything invalid
43
- // into a conveniently comparable zero.
37
+ const localData = JSON.parse(window.localStorage.getItem(localStorageRestoreKey));
44
38
 
39
+ // Date parse returns NaN for invalid input. Coerce anything invalid
40
+ // into a conveniently comparable zero.
45
41
  const serverModified = Date.parse(serverData && serverData._modified) || 0;
46
42
  const localModified = Date.parse(localData && localData._modified) || 0;
47
43
  let preloadedData;
48
-
49
44
  if (serverData && serverModified >= localModified) {
50
45
  preloadedData = (0, _preferencesPackageData.default)(serverData);
51
46
  } else if (localData) {
@@ -54,7 +49,6 @@ function __unstableCreatePersistenceLayer(serverData, userId) {
54
49
  // Check if there is data in the legacy format from the old persistence system.
55
50
  preloadedData = (0, _legacyLocalStorageData.default)(userId);
56
51
  }
57
-
58
52
  return (0, _create.default)({
59
53
  preloadedData,
60
54
  localStorageRestoreKey
@@ -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;;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"]}
1
+ {"version":3,"names":["_create","_interopRequireDefault","require","_legacyLocalStorageData","_preferencesPackageData","__unstableCreatePersistenceLayer","serverData","userId","localStorageRestoreKey","localData","JSON","parse","window","localStorage","getItem","serverModified","Date","_modified","localModified","preloadedData","convertPreferencesPackageData","convertLegacyLocalStorageData","create"],"sources":["@wordpress/preferences-persistence/src/index.js"],"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"],"mappings":";;;;;;;;;;;;;AAGA,IAAAA,OAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,uBAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,uBAAA,GAAAH,sBAAA,CAAAC,OAAA;AALA;AACA;AACA;;AAOA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASG,gCAAgCA,CAAEC,UAAU,EAAEC,MAAM,EAAG;EACtE,MAAMC,sBAAsB,GAAI,uBAAuBD,MAAQ,EAAC;EAChE,MAAME,SAAS,GAAGC,IAAI,CAACC,KAAK,CAC3BC,MAAM,CAACC,YAAY,CAACC,OAAO,CAAEN,sBAAuB,CACrD,CAAC;;EAED;EACA;EACA,MAAMO,cAAc,GACnBC,IAAI,CAACL,KAAK,CAAEL,UAAU,IAAIA,UAAU,CAACW,SAAU,CAAC,IAAI,CAAC;EACtD,MAAMC,aAAa,GAAGF,IAAI,CAACL,KAAK,CAAEF,SAAS,IAAIA,SAAS,CAACQ,SAAU,CAAC,IAAI,CAAC;EAEzE,IAAIE,aAAa;EACjB,IAAKb,UAAU,IAAIS,cAAc,IAAIG,aAAa,EAAG;IACpDC,aAAa,GAAG,IAAAC,+BAA6B,EAAEd,UAAW,CAAC;EAC5D,CAAC,MAAM,IAAKG,SAAS,EAAG;IACvBU,aAAa,GAAG,IAAAC,+BAA6B,EAAEX,SAAU,CAAC;EAC3D,CAAC,MAAM;IACN;IACAU,aAAa,GAAG,IAAAE,+BAA6B,EAAEd,MAAO,CAAC;EACxD;EAEA,OAAO,IAAAe,eAAM,EAAE;IACdH,aAAa;IACbX;EACD,CAAE,CAAC;AACJ"}
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = convertEditPostPanels;
7
-
8
7
  /**
9
8
  * Convert the post editor's panels state from:
10
9
  * ```
@@ -38,19 +37,15 @@ exports.default = convertEditPostPanels;
38
37
  */
39
38
  function convertEditPostPanels(preferences) {
40
39
  var _preferences$panels;
41
-
42
40
  const panels = (_preferences$panels = preferences?.panels) !== null && _preferences$panels !== void 0 ? _preferences$panels : {};
43
41
  return Object.keys(panels).reduce((convertedData, panelName) => {
44
42
  const panel = panels[panelName];
45
-
46
43
  if (panel?.enabled === false) {
47
44
  convertedData.inactivePanels.push(panelName);
48
45
  }
49
-
50
46
  if (panel?.opened === true) {
51
47
  convertedData.openPanels.push(panelName);
52
48
  }
53
-
54
49
  return convertedData;
55
50
  }, {
56
51
  inactivePanels: [],
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/preferences-persistence/src/migrations/legacy-local-storage-data/convert-edit-post-panels.js"],"names":["convertEditPostPanels","preferences","panels","Object","keys","reduce","convertedData","panelName","panel","enabled","inactivePanels","push","opened","openPanels"],"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;AACe,SAASA,qBAAT,CAAgCC,WAAhC,EAA8C;AAAA;;AAC5D,QAAMC,MAAM,0BAAGD,WAAW,EAAEC,MAAhB,qEAA0B,EAAtC;AACA,SAAOC,MAAM,CAACC,IAAP,CAAaF,MAAb,EAAsBG,MAAtB,CACN,CAAEC,aAAF,EAAiBC,SAAjB,KAAgC;AAC/B,UAAMC,KAAK,GAAGN,MAAM,CAAEK,SAAF,CAApB;;AAEA,QAAKC,KAAK,EAAEC,OAAP,KAAmB,KAAxB,EAAgC;AAC/BH,MAAAA,aAAa,CAACI,cAAd,CAA6BC,IAA7B,CAAmCJ,SAAnC;AACA;;AAED,QAAKC,KAAK,EAAEI,MAAP,KAAkB,IAAvB,EAA8B;AAC7BN,MAAAA,aAAa,CAACO,UAAd,CAAyBF,IAAzB,CAA+BJ,SAA/B;AACA;;AAED,WAAOD,aAAP;AACA,GAbK,EAcN;AAAEI,IAAAA,cAAc,EAAE,EAAlB;AAAsBG,IAAAA,UAAU,EAAE;AAAlC,GAdM,CAAP;AAgBA","sourcesContent":["/**\n * Convert the post editor's panels state from:\n * ```\n * {\n * panels: {\n * tags: {\n * enabled: true,\n * opened: true,\n * },\n * permalinks: {\n * enabled: false,\n * opened: false,\n * },\n * },\n * }\n * ```\n *\n * to a new, more concise data structure:\n * {\n * inactivePanels: [\n * 'permalinks',\n * ],\n * openPanels: [\n * 'tags',\n * ],\n * }\n *\n * @param {Object} preferences A preferences object.\n *\n * @return {Object} The converted data.\n */\nexport default function convertEditPostPanels( preferences ) {\n\tconst panels = preferences?.panels ?? {};\n\treturn Object.keys( panels ).reduce(\n\t\t( convertedData, panelName ) => {\n\t\t\tconst panel = panels[ panelName ];\n\n\t\t\tif ( panel?.enabled === false ) {\n\t\t\t\tconvertedData.inactivePanels.push( panelName );\n\t\t\t}\n\n\t\t\tif ( panel?.opened === true ) {\n\t\t\t\tconvertedData.openPanels.push( panelName );\n\t\t\t}\n\n\t\t\treturn convertedData;\n\t\t},\n\t\t{ inactivePanels: [], openPanels: [] }\n\t);\n}\n"]}
1
+ {"version":3,"names":["convertEditPostPanels","preferences","_preferences$panels","panels","Object","keys","reduce","convertedData","panelName","panel","enabled","inactivePanels","push","opened","openPanels"],"sources":["@wordpress/preferences-persistence/src/migrations/legacy-local-storage-data/convert-edit-post-panels.js"],"sourcesContent":["/**\n * Convert the post editor's panels state from:\n * ```\n * {\n * panels: {\n * tags: {\n * enabled: true,\n * opened: true,\n * },\n * permalinks: {\n * enabled: false,\n * opened: false,\n * },\n * },\n * }\n * ```\n *\n * to a new, more concise data structure:\n * {\n * inactivePanels: [\n * 'permalinks',\n * ],\n * openPanels: [\n * 'tags',\n * ],\n * }\n *\n * @param {Object} preferences A preferences object.\n *\n * @return {Object} The converted data.\n */\nexport default function convertEditPostPanels( preferences ) {\n\tconst panels = preferences?.panels ?? {};\n\treturn Object.keys( panels ).reduce(\n\t\t( convertedData, panelName ) => {\n\t\t\tconst panel = panels[ panelName ];\n\n\t\t\tif ( panel?.enabled === false ) {\n\t\t\t\tconvertedData.inactivePanels.push( panelName );\n\t\t\t}\n\n\t\t\tif ( panel?.opened === true ) {\n\t\t\t\tconvertedData.openPanels.push( panelName );\n\t\t\t}\n\n\t\t\treturn convertedData;\n\t\t},\n\t\t{ inactivePanels: [], openPanels: [] }\n\t);\n}\n"],"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;AACe,SAASA,qBAAqBA,CAAEC,WAAW,EAAG;EAAA,IAAAC,mBAAA;EAC5D,MAAMC,MAAM,IAAAD,mBAAA,GAAGD,WAAW,EAAEE,MAAM,cAAAD,mBAAA,cAAAA,mBAAA,GAAI,CAAC,CAAC;EACxC,OAAOE,MAAM,CAACC,IAAI,CAAEF,MAAO,CAAC,CAACG,MAAM,CAClC,CAAEC,aAAa,EAAEC,SAAS,KAAM;IAC/B,MAAMC,KAAK,GAAGN,MAAM,CAAEK,SAAS,CAAE;IAEjC,IAAKC,KAAK,EAAEC,OAAO,KAAK,KAAK,EAAG;MAC/BH,aAAa,CAACI,cAAc,CAACC,IAAI,CAAEJ,SAAU,CAAC;IAC/C;IAEA,IAAKC,KAAK,EAAEI,MAAM,KAAK,IAAI,EAAG;MAC7BN,aAAa,CAACO,UAAU,CAACF,IAAI,CAAEJ,SAAU,CAAC;IAC3C;IAEA,OAAOD,aAAa;EACrB,CAAC,EACD;IAAEI,cAAc,EAAE,EAAE;IAAEG,UAAU,EAAE;EAAG,CACtC,CAAC;AACF"}
@@ -1,23 +1,16 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.convertLegacyData = convertLegacyData;
9
8
  exports.default = convertLegacyLocalStorageData;
10
-
11
9
  var _moveFeaturePreferences = _interopRequireDefault(require("./move-feature-preferences"));
12
-
13
10
  var _moveThirdPartyFeaturePreferences = _interopRequireDefault(require("./move-third-party-feature-preferences"));
14
-
15
11
  var _moveIndividualPreference = _interopRequireDefault(require("./move-individual-preference"));
16
-
17
12
  var _moveInterfaceEnableItems = _interopRequireDefault(require("./move-interface-enable-items"));
18
-
19
13
  var _convertEditPostPanels = _interopRequireDefault(require("./convert-edit-post-panels"));
20
-
21
14
  /**
22
15
  * Internal dependencies
23
16
  */
@@ -34,6 +27,7 @@ function getLegacyData(userId) {
34
27
  const unparsedData = window.localStorage.getItem(key);
35
28
  return JSON.parse(unparsedData);
36
29
  }
30
+
37
31
  /**
38
32
  * Converts data from the old `@wordpress/data` package format.
39
33
  *
@@ -42,27 +36,28 @@ function getLegacyData(userId) {
42
36
  * @return {Object | undefined} The converted data or `undefined` if there was
43
37
  * nothing to convert.
44
38
  */
45
-
46
-
47
39
  function convertLegacyData(data) {
48
40
  if (!data) {
49
41
  return;
50
- } // Move boolean feature preferences from each editor into the
51
- // preferences store data structure.
52
-
42
+ }
53
43
 
44
+ // Move boolean feature preferences from each editor into the
45
+ // preferences store data structure.
54
46
  data = (0, _moveFeaturePreferences.default)(data, 'core/edit-widgets');
55
47
  data = (0, _moveFeaturePreferences.default)(data, 'core/customize-widgets');
56
48
  data = (0, _moveFeaturePreferences.default)(data, 'core/edit-post');
57
- data = (0, _moveFeaturePreferences.default)(data, 'core/edit-site'); // Move third party boolean feature preferences from the interface package
49
+ data = (0, _moveFeaturePreferences.default)(data, 'core/edit-site');
50
+
51
+ // Move third party boolean feature preferences from the interface package
58
52
  // to the preferences store data structure.
53
+ data = (0, _moveThirdPartyFeaturePreferences.default)(data);
59
54
 
60
- data = (0, _moveThirdPartyFeaturePreferences.default)(data); // Move and convert the interface store's `enableItems` data into the
55
+ // Move and convert the interface store's `enableItems` data into the
61
56
  // preferences data structure.
57
+ data = (0, _moveInterfaceEnableItems.default)(data);
62
58
 
63
- data = (0, _moveInterfaceEnableItems.default)(data); // Move individual ad-hoc preferences from various packages into the
59
+ // Move individual ad-hoc preferences from various packages into the
64
60
  // preferences store data structure.
65
-
66
61
  data = (0, _moveIndividualPreference.default)(data, {
67
62
  from: 'core/edit-post',
68
63
  to: 'core/edit-post'
@@ -86,11 +81,13 @@ function convertLegacyData(data) {
86
81
  data = (0, _moveIndividualPreference.default)(data, {
87
82
  from: 'core/edit-site',
88
83
  to: 'core/edit-site'
89
- }, 'editorMode'); // The new system is only concerned with persisting
90
- // 'core/preferences' preferences reducer, so only return that.
84
+ }, 'editorMode');
91
85
 
86
+ // The new system is only concerned with persisting
87
+ // 'core/preferences' preferences reducer, so only return that.
92
88
  return data?.['core/preferences']?.preferences;
93
89
  }
90
+
94
91
  /**
95
92
  * Gets the legacy local storage data for the given user and returns the
96
93
  * data converted to the new format.
@@ -100,8 +97,6 @@ function convertLegacyData(data) {
100
97
  * @return {Object | undefined} The converted data or undefined if no local
101
98
  * storage data could be found.
102
99
  */
103
-
104
-
105
100
  function convertLegacyLocalStorageData(userId) {
106
101
  const data = getLegacyData(userId);
107
102
  return convertLegacyData(data);
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/preferences-persistence/src/migrations/legacy-local-storage-data/index.js"],"names":["getLegacyData","userId","key","unparsedData","window","localStorage","getItem","JSON","parse","convertLegacyData","data","from","to","convertEditPostPanels","preferences","convertLegacyLocalStorageData"],"mappings":";;;;;;;;;;AAGA;;AACA;;AACA;;AACA;;AACA;;AAPA;AACA;AACA;;AAOA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASA,aAAT,CAAwBC,MAAxB,EAAiC;AAChC,QAAMC,GAAG,GAAI,gBAAgBD,MAAQ,EAArC;AACA,QAAME,YAAY,GAAGC,MAAM,CAACC,YAAP,CAAoBC,OAApB,CAA6BJ,GAA7B,CAArB;AACA,SAAOK,IAAI,CAACC,KAAL,CAAYL,YAAZ,CAAP;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASM,iBAAT,CAA4BC,IAA5B,EAAmC;AACzC,MAAK,CAAEA,IAAP,EAAc;AACb;AACA,GAHwC,CAKzC;AACA;;;AACAA,EAAAA,IAAI,GAAG,qCAAwBA,IAAxB,EAA8B,mBAA9B,CAAP;AACAA,EAAAA,IAAI,GAAG,qCAAwBA,IAAxB,EAA8B,wBAA9B,CAAP;AACAA,EAAAA,IAAI,GAAG,qCAAwBA,IAAxB,EAA8B,gBAA9B,CAAP;AACAA,EAAAA,IAAI,GAAG,qCAAwBA,IAAxB,EAA8B,gBAA9B,CAAP,CAVyC,CAYzC;AACA;;AACAA,EAAAA,IAAI,GAAG,+CAAkCA,IAAlC,CAAP,CAdyC,CAgBzC;AACA;;AACAA,EAAAA,IAAI,GAAG,uCAA0BA,IAA1B,CAAP,CAlByC,CAoBzC;AACA;;AACAA,EAAAA,IAAI,GAAG,uCACNA,IADM,EAEN;AAAEC,IAAAA,IAAI,EAAE,gBAAR;AAA0BC,IAAAA,EAAE,EAAE;AAA9B,GAFM,EAGN,kBAHM,CAAP;AAKAF,EAAAA,IAAI,GAAG,uCACNA,IADM,EAEN;AAAEC,IAAAA,IAAI,EAAE,gBAAR;AAA0BC,IAAAA,EAAE,EAAE;AAA9B,GAFM,EAGN,YAHM,CAAP;AAKAF,EAAAA,IAAI,GAAG,uCACNA,IADM,EAEN;AAAEC,IAAAA,IAAI,EAAE,gBAAR;AAA0BC,IAAAA,EAAE,EAAE;AAA9B,GAFM,EAGN,0BAHM,CAAP;AAKAF,EAAAA,IAAI,GAAG,uCACNA,IADM,EAEN;AAAEC,IAAAA,IAAI,EAAE,gBAAR;AAA0BC,IAAAA,EAAE,EAAE;AAA9B,GAFM,EAGN,QAHM,EAINC,8BAJM,CAAP;AAMAH,EAAAA,IAAI,GAAG,uCACNA,IADM,EAEN;AAAEC,IAAAA,IAAI,EAAE,aAAR;AAAuBC,IAAAA,EAAE,EAAE;AAA3B,GAFM,EAGN,yBAHM,CAAP;AAKAF,EAAAA,IAAI,GAAG,uCACNA,IADM,EAEN;AAAEC,IAAAA,IAAI,EAAE,gBAAR;AAA0BC,IAAAA,EAAE,EAAE;AAA9B,GAFM,EAGN,YAHM,CAAP,CAhDyC,CAsDzC;AACA;;AACA,SAAOF,IAAI,GAAI,kBAAJ,CAAJ,EAA8BI,WAArC;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACe,SAASC,6BAAT,CAAwCd,MAAxC,EAAiD;AAC/D,QAAMS,IAAI,GAAGV,aAAa,CAAEC,MAAF,CAA1B;AACA,SAAOQ,iBAAiB,CAAEC,IAAF,CAAxB;AACA","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"]}
1
+ {"version":3,"names":["_moveFeaturePreferences","_interopRequireDefault","require","_moveThirdPartyFeaturePreferences","_moveIndividualPreference","_moveInterfaceEnableItems","_convertEditPostPanels","getLegacyData","userId","key","unparsedData","window","localStorage","getItem","JSON","parse","convertLegacyData","data","moveFeaturePreferences","moveThirdPartyFeaturePreferences","moveInterfaceEnableItems","moveIndividualPreference","from","to","convertEditPostPanels","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":";;;;;;;;AAGA,IAAAA,uBAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,iCAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,yBAAA,GAAAH,sBAAA,CAAAC,OAAA;AACA,IAAAG,yBAAA,GAAAJ,sBAAA,CAAAC,OAAA;AACA,IAAAI,sBAAA,GAAAL,sBAAA,CAAAC,OAAA;AAPA;AACA;AACA;;AAOA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASK,aAAaA,CAAEC,MAAM,EAAG;EAChC,MAAMC,GAAG,GAAI,gBAAgBD,MAAQ,EAAC;EACtC,MAAME,YAAY,GAAGC,MAAM,CAACC,YAAY,CAACC,OAAO,CAAEJ,GAAI,CAAC;EACvD,OAAOK,IAAI,CAACC,KAAK,CAAEL,YAAa,CAAC;AAClC;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASM,iBAAiBA,CAAEC,IAAI,EAAG;EACzC,IAAK,CAAEA,IAAI,EAAG;IACb;EACD;;EAEA;EACA;EACAA,IAAI,GAAG,IAAAC,+BAAsB,EAAED,IAAI,EAAE,mBAAoB,CAAC;EAC1DA,IAAI,GAAG,IAAAC,+BAAsB,EAAED,IAAI,EAAE,wBAAyB,CAAC;EAC/DA,IAAI,GAAG,IAAAC,+BAAsB,EAAED,IAAI,EAAE,gBAAiB,CAAC;EACvDA,IAAI,GAAG,IAAAC,+BAAsB,EAAED,IAAI,EAAE,gBAAiB,CAAC;;EAEvD;EACA;EACAA,IAAI,GAAG,IAAAE,yCAAgC,EAAEF,IAAK,CAAC;;EAE/C;EACA;EACAA,IAAI,GAAG,IAAAG,iCAAwB,EAAEH,IAAK,CAAC;;EAEvC;EACA;EACAA,IAAI,GAAG,IAAAI,iCAAwB,EAC9BJ,IAAI,EACJ;IAAEK,IAAI,EAAE,gBAAgB;IAAEC,EAAE,EAAE;EAAiB,CAAC,EAChD,kBACD,CAAC;EACDN,IAAI,GAAG,IAAAI,iCAAwB,EAC9BJ,IAAI,EACJ;IAAEK,IAAI,EAAE,gBAAgB;IAAEC,EAAE,EAAE;EAAiB,CAAC,EAChD,YACD,CAAC;EACDN,IAAI,GAAG,IAAAI,iCAAwB,EAC9BJ,IAAI,EACJ;IAAEK,IAAI,EAAE,gBAAgB;IAAEC,EAAE,EAAE;EAAiB,CAAC,EAChD,0BACD,CAAC;EACDN,IAAI,GAAG,IAAAI,iCAAwB,EAC9BJ,IAAI,EACJ;IAAEK,IAAI,EAAE,gBAAgB;IAAEC,EAAE,EAAE;EAAiB,CAAC,EAChD,QAAQ,EACRC,8BACD,CAAC;EACDP,IAAI,GAAG,IAAAI,iCAAwB,EAC9BJ,IAAI,EACJ;IAAEK,IAAI,EAAE,aAAa;IAAEC,EAAE,EAAE;EAAiB,CAAC,EAC7C,yBACD,CAAC;EACDN,IAAI,GAAG,IAAAI,iCAAwB,EAC9BJ,IAAI,EACJ;IAAEK,IAAI,EAAE,gBAAgB;IAAEC,EAAE,EAAE;EAAiB,CAAC,EAChD,YACD,CAAC;;EAED;EACA;EACA,OAAON,IAAI,GAAI,kBAAkB,CAAE,EAAEQ,WAAW;AACjD;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,SAASC,6BAA6BA,CAAElB,MAAM,EAAG;EAC/D,MAAMS,IAAI,GAAGV,aAAa,CAAEC,MAAO,CAAC;EACpC,OAAOQ,iBAAiB,CAAEC,IAAK,CAAC;AACjC"}
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = moveFeaturePreferences;
7
-
8
7
  /**
9
8
  * Move the 'features' object in local storage from the sourceStoreName to the
10
9
  * preferences store data structure.
@@ -64,61 +63,63 @@ exports.default = moveFeaturePreferences;
64
63
  */
65
64
  function moveFeaturePreferences(state, sourceStoreName) {
66
65
  const preferencesStoreName = 'core/preferences';
67
- const interfaceStoreName = 'core/interface'; // Features most recently (and briefly) lived in the interface package.
66
+ const interfaceStoreName = 'core/interface';
67
+
68
+ // Features most recently (and briefly) lived in the interface package.
68
69
  // If data exists there, prioritize using that for the migration. If not
69
70
  // also check the original package as the user may have updated from an
70
71
  // older block editor version.
71
-
72
72
  const interfaceFeatures = state?.[interfaceStoreName]?.preferences?.features?.[sourceStoreName];
73
73
  const sourceFeatures = state?.[sourceStoreName]?.preferences?.features;
74
74
  const featuresToMigrate = interfaceFeatures ? interfaceFeatures : sourceFeatures;
75
-
76
75
  if (!featuresToMigrate) {
77
76
  return state;
78
77
  }
78
+ const existingPreferences = state?.[preferencesStoreName]?.preferences;
79
79
 
80
- const existingPreferences = state?.[preferencesStoreName]?.preferences; // Avoid migrating features again if they've previously been migrated.
81
-
80
+ // Avoid migrating features again if they've previously been migrated.
82
81
  if (existingPreferences?.[sourceStoreName]) {
83
82
  return state;
84
83
  }
85
-
86
84
  let updatedInterfaceState;
87
-
88
85
  if (interfaceFeatures) {
89
86
  const otherInterfaceState = state?.[interfaceStoreName];
90
87
  const otherInterfaceScopes = state?.[interfaceStoreName]?.preferences?.features;
91
88
  updatedInterfaceState = {
92
- [interfaceStoreName]: { ...otherInterfaceState,
89
+ [interfaceStoreName]: {
90
+ ...otherInterfaceState,
93
91
  preferences: {
94
- features: { ...otherInterfaceScopes,
92
+ features: {
93
+ ...otherInterfaceScopes,
95
94
  [sourceStoreName]: undefined
96
95
  }
97
96
  }
98
97
  }
99
98
  };
100
99
  }
101
-
102
100
  let updatedSourceState;
103
-
104
101
  if (sourceFeatures) {
105
102
  const otherSourceState = state?.[sourceStoreName];
106
103
  const sourcePreferences = state?.[sourceStoreName]?.preferences;
107
104
  updatedSourceState = {
108
- [sourceStoreName]: { ...otherSourceState,
109
- preferences: { ...sourcePreferences,
105
+ [sourceStoreName]: {
106
+ ...otherSourceState,
107
+ preferences: {
108
+ ...sourcePreferences,
110
109
  features: undefined
111
110
  }
112
111
  }
113
112
  };
114
- } // Set the feature values in the interface store, the features
113
+ }
114
+
115
+ // Set the feature values in the interface store, the features
115
116
  // object is keyed by 'scope', which matches the store name for
116
117
  // the source.
117
-
118
-
119
- return { ...state,
118
+ return {
119
+ ...state,
120
120
  [preferencesStoreName]: {
121
- preferences: { ...existingPreferences,
121
+ preferences: {
122
+ ...existingPreferences,
122
123
  [sourceStoreName]: featuresToMigrate
123
124
  }
124
125
  },
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/preferences-persistence/src/migrations/legacy-local-storage-data/move-feature-preferences.js"],"names":["moveFeaturePreferences","state","sourceStoreName","preferencesStoreName","interfaceStoreName","interfaceFeatures","preferences","features","sourceFeatures","featuresToMigrate","existingPreferences","updatedInterfaceState","otherInterfaceState","otherInterfaceScopes","undefined","updatedSourceState","otherSourceState","sourcePreferences"],"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;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,SAASA,sBAAT,CAAiCC,KAAjC,EAAwCC,eAAxC,EAA0D;AACxE,QAAMC,oBAAoB,GAAG,kBAA7B;AACA,QAAMC,kBAAkB,GAAG,gBAA3B,CAFwE,CAIxE;AACA;AACA;AACA;;AACA,QAAMC,iBAAiB,GACtBJ,KAAK,GAAIG,kBAAJ,CAAL,EAA+BE,WAA/B,EAA4CC,QAA5C,GACCL,eADD,CADD;AAIA,QAAMM,cAAc,GAAGP,KAAK,GAAIC,eAAJ,CAAL,EAA4BI,WAA5B,EAAyCC,QAAhE;AACA,QAAME,iBAAiB,GAAGJ,iBAAiB,GACxCA,iBADwC,GAExCG,cAFH;;AAIA,MAAK,CAAEC,iBAAP,EAA2B;AAC1B,WAAOR,KAAP;AACA;;AAED,QAAMS,mBAAmB,GAAGT,KAAK,GAAIE,oBAAJ,CAAL,EAAiCG,WAA7D,CArBwE,CAuBxE;;AACA,MAAKI,mBAAmB,GAAIR,eAAJ,CAAxB,EAAgD;AAC/C,WAAOD,KAAP;AACA;;AAED,MAAIU,qBAAJ;;AACA,MAAKN,iBAAL,EAAyB;AACxB,UAAMO,mBAAmB,GAAGX,KAAK,GAAIG,kBAAJ,CAAjC;AACA,UAAMS,oBAAoB,GACzBZ,KAAK,GAAIG,kBAAJ,CAAL,EAA+BE,WAA/B,EAA4CC,QAD7C;AAGAI,IAAAA,qBAAqB,GAAG;AACvB,OAAEP,kBAAF,GAAwB,EACvB,GAAGQ,mBADoB;AAEvBN,QAAAA,WAAW,EAAE;AACZC,UAAAA,QAAQ,EAAE,EACT,GAAGM,oBADM;AAET,aAAEX,eAAF,GAAqBY;AAFZ;AADE;AAFU;AADD,KAAxB;AAWA;;AAED,MAAIC,kBAAJ;;AACA,MAAKP,cAAL,EAAsB;AACrB,UAAMQ,gBAAgB,GAAGf,KAAK,GAAIC,eAAJ,CAA9B;AACA,UAAMe,iBAAiB,GAAGhB,KAAK,GAAIC,eAAJ,CAAL,EAA4BI,WAAtD;AAEAS,IAAAA,kBAAkB,GAAG;AACpB,OAAEb,eAAF,GAAqB,EACpB,GAAGc,gBADiB;AAEpBV,QAAAA,WAAW,EAAE,EACZ,GAAGW,iBADS;AAEZV,UAAAA,QAAQ,EAAEO;AAFE;AAFO;AADD,KAArB;AASA,GA7DuE,CA+DxE;AACA;AACA;;;AACA,SAAO,EACN,GAAGb,KADG;AAEN,KAAEE,oBAAF,GAA0B;AACzBG,MAAAA,WAAW,EAAE,EACZ,GAAGI,mBADS;AAEZ,SAAER,eAAF,GAAqBO;AAFT;AADY,KAFpB;AAQN,OAAGE,qBARG;AASN,OAAGI;AATG,GAAP;AAWA","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"]}
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;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,SAASA,sBAAsBA,CAAEC,KAAK,EAAEC,eAAe,EAAG;EACxE,MAAMC,oBAAoB,GAAG,kBAAkB;EAC/C,MAAMC,kBAAkB,GAAG,gBAAgB;;EAE3C;EACA;EACA;EACA;EACA,MAAMC,iBAAiB,GACtBJ,KAAK,GAAIG,kBAAkB,CAAE,EAAEE,WAAW,EAAEC,QAAQ,GACnDL,eAAe,CACf;EACF,MAAMM,cAAc,GAAGP,KAAK,GAAIC,eAAe,CAAE,EAAEI,WAAW,EAAEC,QAAQ;EACxE,MAAME,iBAAiB,GAAGJ,iBAAiB,GACxCA,iBAAiB,GACjBG,cAAc;EAEjB,IAAK,CAAEC,iBAAiB,EAAG;IAC1B,OAAOR,KAAK;EACb;EAEA,MAAMS,mBAAmB,GAAGT,KAAK,GAAIE,oBAAoB,CAAE,EAAEG,WAAW;;EAExE;EACA,IAAKI,mBAAmB,GAAIR,eAAe,CAAE,EAAG;IAC/C,OAAOD,KAAK;EACb;EAEA,IAAIU,qBAAqB;EACzB,IAAKN,iBAAiB,EAAG;IACxB,MAAMO,mBAAmB,GAAGX,KAAK,GAAIG,kBAAkB,CAAE;IACzD,MAAMS,oBAAoB,GACzBZ,KAAK,GAAIG,kBAAkB,CAAE,EAAEE,WAAW,EAAEC,QAAQ;IAErDI,qBAAqB,GAAG;MACvB,CAAEP,kBAAkB,GAAI;QACvB,GAAGQ,mBAAmB;QACtBN,WAAW,EAAE;UACZC,QAAQ,EAAE;YACT,GAAGM,oBAAoB;YACvB,CAAEX,eAAe,GAAIY;UACtB;QACD;MACD;IACD,CAAC;EACF;EAEA,IAAIC,kBAAkB;EACtB,IAAKP,cAAc,EAAG;IACrB,MAAMQ,gBAAgB,GAAGf,KAAK,GAAIC,eAAe,CAAE;IACnD,MAAMe,iBAAiB,GAAGhB,KAAK,GAAIC,eAAe,CAAE,EAAEI,WAAW;IAEjES,kBAAkB,GAAG;MACpB,CAAEb,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"}
@@ -4,8 +4,8 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = moveIndividualPreferenceToPreferences;
7
-
8
7
  const identity = arg => arg;
8
+
9
9
  /**
10
10
  * Migrates an individual item inside the `preferences` object for a package's store.
11
11
  *
@@ -41,44 +41,48 @@ const identity = arg => arg;
41
41
  * @param {string} key The key in the preferences object to migrate.
42
42
  * @param {?Function} convert A function that converts preferences from one format to another.
43
43
  */
44
-
45
-
46
44
  function moveIndividualPreferenceToPreferences(state, {
47
45
  from: sourceStoreName,
48
46
  to: scope
49
47
  }, key, convert = identity) {
50
48
  const preferencesStoreName = 'core/preferences';
51
- const sourcePreference = state?.[sourceStoreName]?.preferences?.[key]; // There's nothing to migrate, exit early.
49
+ const sourcePreference = state?.[sourceStoreName]?.preferences?.[key];
52
50
 
51
+ // There's nothing to migrate, exit early.
53
52
  if (sourcePreference === undefined) {
54
53
  return state;
55
54
  }
55
+ const targetPreference = state?.[preferencesStoreName]?.preferences?.[scope]?.[key];
56
56
 
57
- const targetPreference = state?.[preferencesStoreName]?.preferences?.[scope]?.[key]; // There's existing data at the target, so don't overwrite it, exit early.
58
-
57
+ // There's existing data at the target, so don't overwrite it, exit early.
59
58
  if (targetPreference) {
60
59
  return state;
61
60
  }
62
-
63
61
  const otherScopes = state?.[preferencesStoreName]?.preferences;
64
62
  const otherPreferences = state?.[preferencesStoreName]?.preferences?.[scope];
65
63
  const otherSourceState = state?.[sourceStoreName];
66
- const allSourcePreferences = state?.[sourceStoreName]?.preferences; // 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.
64
+ const allSourcePreferences = state?.[sourceStoreName]?.preferences;
68
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.
69
68
  const convertedPreferences = convert({
70
69
  [key]: sourcePreference
71
70
  });
72
- return { ...state,
71
+ return {
72
+ ...state,
73
73
  [preferencesStoreName]: {
74
- preferences: { ...otherScopes,
75
- [scope]: { ...otherPreferences,
74
+ preferences: {
75
+ ...otherScopes,
76
+ [scope]: {
77
+ ...otherPreferences,
76
78
  ...convertedPreferences
77
79
  }
78
80
  }
79
81
  },
80
- [sourceStoreName]: { ...otherSourceState,
81
- preferences: { ...allSourcePreferences,
82
+ [sourceStoreName]: {
83
+ ...otherSourceState,
84
+ preferences: {
85
+ ...allSourcePreferences,
82
86
  [key]: undefined
83
87
  }
84
88
  }