@wordpress/preferences-persistence 2.57.0 → 3.0.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 (132) hide show
  1. package/README.md +7 -7
  2. package/build/create/debounce-async.cjs +2 -1
  3. package/build/create/debounce-async.cjs.map +3 -3
  4. package/build/create/index.cjs +11 -21
  5. package/build/create/index.cjs.map +4 -4
  6. package/build/get-newest-data.cjs +53 -0
  7. package/build/get-newest-data.cjs.map +7 -0
  8. package/build/index.cjs +8 -16
  9. package/build/index.cjs.map +4 -4
  10. package/build/is-preferences-data.cjs +29 -0
  11. package/build/is-preferences-data.cjs.map +7 -0
  12. package/build/local-storage.cjs +46 -0
  13. package/build/local-storage.cjs.map +7 -0
  14. package/build/migrations/legacy-local-storage-data/convert-edit-post-panels.cjs +2 -1
  15. package/build/migrations/legacy-local-storage-data/convert-edit-post-panels.cjs.map +3 -3
  16. package/build/migrations/legacy-local-storage-data/index.cjs +7 -5
  17. package/build/migrations/legacy-local-storage-data/index.cjs.map +4 -4
  18. package/build/migrations/legacy-local-storage-data/move-feature-preferences.cjs +2 -1
  19. package/build/migrations/legacy-local-storage-data/move-feature-preferences.cjs.map +3 -3
  20. package/build/migrations/legacy-local-storage-data/move-individual-preference.cjs +2 -1
  21. package/build/migrations/legacy-local-storage-data/move-individual-preference.cjs.map +3 -3
  22. package/build/migrations/legacy-local-storage-data/move-interface-enable-items.cjs +2 -1
  23. package/build/migrations/legacy-local-storage-data/move-interface-enable-items.cjs.map +3 -3
  24. package/build/migrations/legacy-local-storage-data/move-third-party-feature-preferences.cjs +2 -1
  25. package/build/migrations/legacy-local-storage-data/move-third-party-feature-preferences.cjs.map +3 -3
  26. package/build/migrations/legacy-local-storage-data/types.cjs +19 -0
  27. package/build/migrations/legacy-local-storage-data/types.cjs.map +7 -0
  28. package/build/migrations/preferences-package-data/convert-complementary-areas.cjs +15 -11
  29. package/build/migrations/preferences-package-data/convert-complementary-areas.cjs.map +3 -3
  30. package/build/migrations/preferences-package-data/convert-editor-settings.cjs +30 -14
  31. package/build/migrations/preferences-package-data/convert-editor-settings.cjs.map +4 -4
  32. package/build/migrations/preferences-package-data/index.cjs +2 -1
  33. package/build/migrations/preferences-package-data/index.cjs.map +3 -3
  34. package/build/types.cjs +19 -0
  35. package/build/types.cjs.map +7 -0
  36. package/build-module/create/debounce-async.mjs +1 -1
  37. package/build-module/create/debounce-async.mjs.map +3 -3
  38. package/build-module/create/index.mjs +10 -21
  39. package/build-module/create/index.mjs.map +3 -3
  40. package/build-module/get-newest-data.mjs +22 -0
  41. package/build-module/get-newest-data.mjs.map +7 -0
  42. package/build-module/index.mjs +7 -16
  43. package/build-module/index.mjs.map +3 -3
  44. package/build-module/is-preferences-data.mjs +8 -0
  45. package/build-module/is-preferences-data.mjs.map +7 -0
  46. package/build-module/local-storage.mjs +20 -0
  47. package/build-module/local-storage.mjs.map +7 -0
  48. package/build-module/migrations/legacy-local-storage-data/convert-edit-post-panels.mjs +1 -1
  49. package/build-module/migrations/legacy-local-storage-data/convert-edit-post-panels.mjs.map +3 -3
  50. package/build-module/migrations/legacy-local-storage-data/index.mjs +6 -5
  51. package/build-module/migrations/legacy-local-storage-data/index.mjs.map +3 -3
  52. package/build-module/migrations/legacy-local-storage-data/move-feature-preferences.mjs +1 -1
  53. package/build-module/migrations/legacy-local-storage-data/move-feature-preferences.mjs.map +3 -3
  54. package/build-module/migrations/legacy-local-storage-data/move-individual-preference.mjs +1 -1
  55. package/build-module/migrations/legacy-local-storage-data/move-individual-preference.mjs.map +3 -3
  56. package/build-module/migrations/legacy-local-storage-data/move-interface-enable-items.mjs +1 -1
  57. package/build-module/migrations/legacy-local-storage-data/move-interface-enable-items.mjs.map +3 -3
  58. package/build-module/migrations/legacy-local-storage-data/move-third-party-feature-preferences.mjs +1 -1
  59. package/build-module/migrations/legacy-local-storage-data/move-third-party-feature-preferences.mjs.map +3 -3
  60. package/build-module/migrations/legacy-local-storage-data/types.mjs +1 -0
  61. package/build-module/migrations/legacy-local-storage-data/types.mjs.map +7 -0
  62. package/build-module/migrations/preferences-package-data/convert-complementary-areas.mjs +14 -11
  63. package/build-module/migrations/preferences-package-data/convert-complementary-areas.mjs.map +3 -3
  64. package/build-module/migrations/preferences-package-data/convert-editor-settings.mjs +19 -14
  65. package/build-module/migrations/preferences-package-data/convert-editor-settings.mjs.map +3 -3
  66. package/build-module/migrations/preferences-package-data/index.mjs +1 -1
  67. package/build-module/migrations/preferences-package-data/index.mjs.map +3 -3
  68. package/build-module/types.mjs +1 -0
  69. package/build-module/types.mjs.map +7 -0
  70. package/build-types/create/debounce-async.d.ts +19 -0
  71. package/build-types/create/debounce-async.d.ts.map +1 -0
  72. package/build-types/create/index.d.ts +20 -0
  73. package/build-types/create/index.d.ts.map +1 -0
  74. package/build-types/get-newest-data.d.ts +11 -0
  75. package/build-types/get-newest-data.d.ts.map +1 -0
  76. package/build-types/index.d.ts +20 -0
  77. package/build-types/index.d.ts.map +1 -0
  78. package/build-types/is-preferences-data.d.ts +11 -0
  79. package/build-types/is-preferences-data.d.ts.map +1 -0
  80. package/build-types/local-storage.d.ts +19 -0
  81. package/build-types/local-storage.d.ts.map +1 -0
  82. package/build-types/migrations/legacy-local-storage-data/convert-edit-post-panels.d.ts +35 -0
  83. package/build-types/migrations/legacy-local-storage-data/convert-edit-post-panels.d.ts.map +1 -0
  84. package/build-types/migrations/legacy-local-storage-data/index.d.ts +22 -0
  85. package/build-types/migrations/legacy-local-storage-data/index.d.ts.map +1 -0
  86. package/build-types/migrations/legacy-local-storage-data/move-feature-preferences.d.ts +60 -0
  87. package/build-types/migrations/legacy-local-storage-data/move-feature-preferences.d.ts.map +1 -0
  88. package/build-types/migrations/legacy-local-storage-data/move-individual-preference.d.ts +42 -0
  89. package/build-types/migrations/legacy-local-storage-data/move-individual-preference.d.ts.map +1 -0
  90. package/build-types/migrations/legacy-local-storage-data/move-interface-enable-items.d.ts +50 -0
  91. package/build-types/migrations/legacy-local-storage-data/move-interface-enable-items.d.ts.map +1 -0
  92. package/build-types/migrations/legacy-local-storage-data/move-third-party-feature-preferences.d.ts +44 -0
  93. package/build-types/migrations/legacy-local-storage-data/move-third-party-feature-preferences.d.ts.map +1 -0
  94. package/build-types/migrations/legacy-local-storage-data/types.d.ts +60 -0
  95. package/build-types/migrations/legacy-local-storage-data/types.d.ts.map +1 -0
  96. package/build-types/migrations/preferences-package-data/convert-complementary-areas.d.ts +5 -0
  97. package/build-types/migrations/preferences-package-data/convert-complementary-areas.d.ts.map +1 -0
  98. package/build-types/migrations/preferences-package-data/convert-editor-settings.d.ts +5 -0
  99. package/build-types/migrations/preferences-package-data/convert-editor-settings.d.ts.map +1 -0
  100. package/build-types/migrations/preferences-package-data/index.d.ts +5 -0
  101. package/build-types/migrations/preferences-package-data/index.d.ts.map +1 -0
  102. package/build-types/types.d.ts +40 -0
  103. package/build-types/types.d.ts.map +1 -0
  104. package/package.json +6 -6
  105. package/src/create/{debounce-async.js → debounce-async.ts} +13 -10
  106. package/src/create/index.ts +95 -0
  107. package/src/create/test/index.jsdom.test.js +45 -0
  108. package/src/get-newest-data.ts +50 -0
  109. package/src/index.ts +40 -0
  110. package/src/is-preferences-data.ts +15 -0
  111. package/src/local-storage.ts +30 -0
  112. package/src/migrations/legacy-local-storage-data/{convert-edit-post-panels.js → convert-edit-post-panels.ts} +13 -5
  113. package/src/migrations/legacy-local-storage-data/{index.js → index.ts} +22 -15
  114. package/src/migrations/legacy-local-storage-data/{move-feature-preferences.js → move-feature-preferences.ts} +13 -7
  115. package/src/migrations/legacy-local-storage-data/{move-individual-preference.js → move-individual-preference.ts} +15 -12
  116. package/src/migrations/legacy-local-storage-data/{move-interface-enable-items.js → move-interface-enable-items.ts} +6 -2
  117. package/src/migrations/legacy-local-storage-data/{move-third-party-feature-preferences.js → move-third-party-feature-preferences.ts} +8 -4
  118. package/src/migrations/legacy-local-storage-data/test/index.js +6 -0
  119. package/src/migrations/legacy-local-storage-data/types.ts +66 -0
  120. package/src/migrations/preferences-package-data/convert-complementary-areas.ts +21 -0
  121. package/src/migrations/preferences-package-data/convert-editor-settings.ts +58 -0
  122. package/src/migrations/preferences-package-data/{index.js → index.ts} +4 -1
  123. package/src/migrations/preferences-package-data/test/convert-complementary-areas.js +10 -0
  124. package/src/migrations/preferences-package-data/test/convert-editor-settings.js +35 -0
  125. package/src/test/index.jsdom.test.js +95 -0
  126. package/src/test/local-storage.jsdom.test.js +50 -0
  127. package/src/types.ts +43 -0
  128. package/CHANGELOG.md +0 -228
  129. package/src/create/index.js +0 -105
  130. package/src/index.js +0 -47
  131. package/src/migrations/preferences-package-data/convert-complementary-areas.js +0 -16
  132. package/src/migrations/preferences-package-data/convert-editor-settings.js +0 -48
package/README.md CHANGED
@@ -30,7 +30,7 @@ wp.data( 'core/preferences' ).setPersistenceLayer( persistenceLayer );
30
30
 
31
31
  ## Reference
32
32
 
33
- <!-- START TOKEN(Autogenerated Docs|src/index.js) -->
33
+ <!-- START TOKEN(Autogenerated Docs|src/index.ts) -->
34
34
 
35
35
  ### create
36
36
 
@@ -38,16 +38,16 @@ Creates a persistence layer that stores data in WordPress user meta via the REST
38
38
 
39
39
  _Parameters_
40
40
 
41
- - _options_ `Object`:
42
- - _options.preloadedData_ `?Object`: Any persisted preferences data that should be preloaded. When set, the persistence layer will avoid fetching data from the REST API.
43
- - _options.localStorageRestoreKey_ `?string`: The key to use for restoring the localStorage backup, used when the persistence layer calls `localStorage.getItem` or `localStorage.setItem`.
44
- - _options.requestDebounceMS_ `?number`: Debounce requests to the API so that they only occur at minimum every `requestDebounceMS` milliseconds, and don't swamp the server. Defaults to 2500ms.
41
+ - _options_ `[CreateOptions]`:
42
+ - _options.preloadedData_ `[PreferencesData|null]`: Any persisted preferences data that should be preloaded. When set, the persistence layer will avoid fetching data from the REST API.
43
+ - _options.localStorageRestoreKey_ `[string]`: The key to use for restoring the localStorage backup, used when the persistence layer calls `localStorage.getItem` or `localStorage.setItem`.
44
+ - _options.requestDebounceMS_ `[number]`: Debounce requests to the API so that they only occur at minimum every `requestDebounceMS` milliseconds, and don't swamp the server. Defaults to 2500ms.
45
45
 
46
46
  _Returns_
47
47
 
48
- - `Object`: A persistence layer for WordPress user meta.
48
+ - `PersistenceLayer`: A persistence layer for WordPress user meta.
49
49
 
50
- <!-- END TOKEN(Autogenerated Docs|src/index.js) -->
50
+ <!-- END TOKEN(Autogenerated Docs|src/index.ts) -->
51
51
 
52
52
  ## Contributing to this package
53
53
 
@@ -1,3 +1,4 @@
1
+ "use strict";
1
2
  var __defProp = Object.defineProperty;
2
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
@@ -16,7 +17,7 @@ var __copyProps = (to, from, except, desc) => {
16
17
  };
17
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
19
 
19
- // packages/preferences-persistence/src/create/debounce-async.js
20
+ // packages/preferences-persistence/src/create/debounce-async.ts
20
21
  var debounce_async_exports = {};
21
22
  __export(debounce_async_exports, {
22
23
  default: () => debounceAsync
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../../src/create/debounce-async.js"],
4
- "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"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAiBe,SAAR,cAAgC,MAAM,SAAU;AACtD,MAAI;AACJ,MAAI;AAEJ,SAAO,eAAe,aAAc,MAAO;AAG1C,QAAK,CAAE,iBAAiB,CAAE,WAAY;AACrC,aAAO,IAAI,QAAS,CAAE,SAAS,WAAY;AAE1C,wBAAgB,KAAM,GAAG,IAAK,EAC5B,KAAM,IAAK,aAAc;AACzB,kBAAS,GAAG,QAAS;AAAA,QACtB,CAAE,EACD,MAAO,CAAE,UAAW;AACpB,iBAAQ,KAAM;AAAA,QACf,CAAE,EACD,QAAS,MAAM;AAGf,0BAAgB;AAAA,QACjB,CAAE;AAAA,MACJ,CAAE;AAAA,IACH;AAEA,QAAK,eAAgB;AAEpB,YAAM;AAAA,IACP;AAIA,QAAK,WAAY;AAChB,mBAAc,SAAU;AACxB,kBAAY;AAAA,IACb;AAGA,WAAO,IAAI,QAAS,CAAE,SAAS,WAAY;AAE1C,kBAAY,WAAY,MAAM;AAC7B,wBAAgB,KAAM,GAAG,IAAK,EAC5B,KAAM,IAAK,aAAc;AACzB,kBAAS,GAAG,QAAS;AAAA,QACtB,CAAE,EACD,MAAO,CAAE,UAAW;AACpB,iBAAQ,KAAM;AAAA,QACf,CAAE,EACD,QAAS,MAAM;AAGf,0BAAgB;AAChB,sBAAY;AAAA,QACb,CAAE;AAAA,MACJ,GAAG,OAAQ;AAAA,IACZ,CAAE;AAAA,EACH;AACD;",
3
+ "sources": ["../../src/create/debounce-async.ts"],
4
+ "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 func A function that returns a promise.\n * @param delayMS A delay in milliseconds.\n *\n * @return A function that debounce whatever function is passed\n * to it.\n */\nexport default function debounceAsync< Args extends unknown[], Result >(\n\tfunc: ( ...args: Args ) => Promise< Result >,\n\tdelayMS: number\n): ( ...args: Args ) => Promise< Result > {\n\tlet timeoutId: ReturnType< typeof setTimeout > | null | undefined;\n\tlet activePromise: Promise< void > | null | undefined;\n\n\treturn async function debounced( ...args: 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< Result >( ( 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< Result >( ( 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"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAiBe,SAAR,cACN,MACA,SACyC;AACzC,MAAI;AACJ,MAAI;AAEJ,SAAO,eAAe,aAAc,MAAa;AAGhD,QAAK,CAAE,iBAAiB,CAAE,WAAY;AACrC,aAAO,IAAI,QAAmB,CAAE,SAAS,WAAY;AAEpD,wBAAgB,KAAM,GAAG,IAAK,EAC5B,KAAM,IAAK,aAAc;AACzB,kBAAS,GAAG,QAAS;AAAA,QACtB,CAAE,EACD,MAAO,CAAE,UAAW;AACpB,iBAAQ,KAAM;AAAA,QACf,CAAE,EACD,QAAS,MAAM;AAGf,0BAAgB;AAAA,QACjB,CAAE;AAAA,MACJ,CAAE;AAAA,IACH;AAEA,QAAK,eAAgB;AAEpB,YAAM;AAAA,IACP;AAIA,QAAK,WAAY;AAChB,mBAAc,SAAU;AACxB,kBAAY;AAAA,IACb;AAGA,WAAO,IAAI,QAAmB,CAAE,SAAS,WAAY;AAEpD,kBAAY,WAAY,MAAM;AAC7B,wBAAgB,KAAM,GAAG,IAAK,EAC5B,KAAM,IAAK,aAAc;AACzB,kBAAS,GAAG,QAAS;AAAA,QACtB,CAAE,EACD,MAAO,CAAE,UAAW;AACpB,iBAAQ,KAAM;AAAA,QACf,CAAE,EACD,QAAS,MAAM;AAGf,0BAAgB;AAChB,sBAAY;AAAA,QACb,CAAE;AAAA,MACJ,GAAG,OAAQ;AAAA,IACZ,CAAE;AAAA,EACH;AACD;",
6
6
  "names": []
7
7
  }
@@ -1,3 +1,4 @@
1
+ "use strict";
1
2
  var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -26,7 +27,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
26
27
  ));
27
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
29
 
29
- // packages/preferences-persistence/src/create/index.js
30
+ // packages/preferences-persistence/src/create/index.ts
30
31
  var create_exports = {};
31
32
  __export(create_exports, {
32
33
  default: () => create
@@ -34,14 +35,15 @@ __export(create_exports, {
34
35
  module.exports = __toCommonJS(create_exports);
35
36
  var import_api_fetch = __toESM(require("@wordpress/api-fetch"));
36
37
  var import_debounce_async = __toESM(require("./debounce-async.cjs"));
37
- var EMPTY_OBJECT = {};
38
- var localStorage = window.localStorage;
38
+ var import_get_newest_data = __toESM(require("../get-newest-data.cjs"));
39
+ var import_is_preferences_data = __toESM(require("../is-preferences-data.cjs"));
40
+ var import_local_storage = require("../local-storage.cjs");
39
41
  function create({
40
42
  preloadedData,
41
43
  localStorageRestoreKey = "WP_PREFERENCES_RESTORE_DATA",
42
44
  requestDebounceMS = 2500
43
45
  } = {}) {
44
- let cache = preloadedData;
46
+ let cache = (0, import_is_preferences_data.default)(preloadedData) ? preloadedData : void 0;
45
47
  const debouncedApiFetch = (0, import_debounce_async.default)(import_api_fetch.default, requestDebounceMS);
46
48
  async function get() {
47
49
  if (cache) {
@@ -50,19 +52,10 @@ function create({
50
52
  const user = await (0, import_api_fetch.default)({
51
53
  path: "/wp/v2/users/me?context=edit"
52
54
  });
53
- const serverData = user?.meta?.persisted_preferences;
54
- const localData = JSON.parse(
55
- localStorage.getItem(localStorageRestoreKey)
56
- );
57
- const serverTimestamp = Date.parse(serverData?._modified) || 0;
58
- const localTimestamp = Date.parse(localData?._modified) || 0;
59
- if (serverData && serverTimestamp >= localTimestamp) {
60
- cache = serverData;
61
- } else if (localData) {
62
- cache = localData;
63
- } else {
64
- cache = EMPTY_OBJECT;
65
- }
55
+ cache = (0, import_get_newest_data.default)(
56
+ user?.meta?.persisted_preferences,
57
+ localStorageRestoreKey
58
+ ) ?? {};
66
59
  return cache;
67
60
  }
68
61
  function set(newData) {
@@ -71,10 +64,7 @@ function create({
71
64
  _modified: (/* @__PURE__ */ new Date()).toISOString()
72
65
  };
73
66
  cache = dataWithTimestamp;
74
- localStorage.setItem(
75
- localStorageRestoreKey,
76
- JSON.stringify(dataWithTimestamp)
77
- );
67
+ (0, import_local_storage.writeStoredJSON)(localStorageRestoreKey, dataWithTimestamp);
78
68
  debouncedApiFetch({
79
69
  path: "/wp/v2/users/me",
80
70
  method: "PUT",
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../../src/create/index.js"],
4
- "sourcesContent": ["import apiFetch from '@wordpress/api-fetch';\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"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAAqB;AACrB,4BAA0B;AAE1B,IAAM,eAAe,CAAC;AACtB,IAAM,eAAe,OAAO;AAmBb,SAAR,OAAyB;AAAA,EAC/B;AAAA,EACA,yBAAyB;AAAA,EACzB,oBAAoB;AACrB,IAAI,CAAC,GAAI;AACR,MAAI,QAAQ;AACZ,QAAM,wBAAoB,sBAAAA,SAAe,iBAAAC,SAAU,iBAAkB;AAErE,iBAAe,MAAM;AACpB,QAAK,OAAQ;AACZ,aAAO;AAAA,IACR;AAEA,UAAM,OAAO,UAAM,iBAAAA,SAAU;AAAA,MAC5B,MAAM;AAAA,IACP,CAAE;AAEF,UAAM,aAAa,MAAM,MAAM;AAC/B,UAAM,YAAY,KAAK;AAAA,MACtB,aAAa,QAAS,sBAAuB;AAAA,IAC9C;AAIA,UAAM,kBAAkB,KAAK,MAAO,YAAY,SAAU,KAAK;AAC/D,UAAM,iBAAiB,KAAK,MAAO,WAAW,SAAU,KAAK;AAI7D,QAAK,cAAc,mBAAmB,gBAAiB;AACtD,cAAQ;AAAA,IACT,WAAY,WAAY;AACvB,cAAQ;AAAA,IACT,OAAO;AACN,cAAQ;AAAA,IACT;AAEA,WAAO;AAAA,EACR;AAEA,WAAS,IAAK,SAAU;AACvB,UAAM,oBAAoB;AAAA,MACzB,GAAG;AAAA,MACH,YAAW,oBAAI,KAAK,GAAE,YAAY;AAAA,IACnC;AACA,YAAQ;AAKR,iBAAa;AAAA,MACZ;AAAA,MACA,KAAK,UAAW,iBAAkB;AAAA,IACnC;AAOA,sBAAmB;AAAA,MAClB,MAAM;AAAA,MACN,QAAQ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,MAMR,WAAW;AAAA,MACX,MAAM;AAAA,QACL,MAAM;AAAA,UACL,uBAAuB;AAAA,QACxB;AAAA,MACD;AAAA,IACD,CAAE,EAAE,MAAO,MAAM;AAAA,IAAC,CAAE;AAAA,EACrB;AAEA,SAAO;AAAA,IACN;AAAA,IACA;AAAA,EACD;AACD;",
6
- "names": ["debounceAsync", "apiFetch"]
3
+ "sources": ["../../src/create/index.ts"],
4
+ "sourcesContent": ["import apiFetch from '@wordpress/api-fetch';\nimport debounceAsync from './debounce-async';\nimport getNewestData from '../get-newest-data';\nimport isPreferencesData from '../is-preferences-data';\nimport { writeStoredJSON } from '../local-storage';\nimport type {\n\tCreateOptions,\n\tPersistenceLayer,\n\tPreferencesData,\n} from '../types';\n\n/**\n * Creates a persistence layer that stores data in WordPress user meta via the\n * REST API.\n *\n * @param {CreateOptions} [options]\n * @param {PreferencesData|null} [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 A persistence layer for WordPress user meta.\n */\nexport default function create( {\n\tpreloadedData,\n\tlocalStorageRestoreKey = 'WP_PREFERENCES_RESTORE_DATA',\n\trequestDebounceMS = 2500,\n}: CreateOptions = {} ): PersistenceLayer {\n\tlet cache = isPreferencesData( preloadedData ) ? preloadedData : undefined;\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\tmeta?: { persisted_preferences?: unknown };\n\t\t} >( {\n\t\t\tpath: '/wp/v2/users/me?context=edit',\n\t\t} );\n\n\t\tcache =\n\t\t\tgetNewestData(\n\t\t\t\tuser?.meta?.persisted_preferences,\n\t\t\t\tlocalStorageRestoreKey\n\t\t\t) ?? {};\n\n\t\treturn cache;\n\t}\n\n\tfunction set( newData: PreferencesData ) {\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\twriteStoredJSON( localStorageRestoreKey, dataWithTimestamp );\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"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAAqB;AACrB,4BAA0B;AAC1B,6BAA0B;AAC1B,iCAA8B;AAC9B,2BAAgC;AAwBjB,SAAR,OAAyB;AAAA,EAC/B;AAAA,EACA,yBAAyB;AAAA,EACzB,oBAAoB;AACrB,IAAmB,CAAC,GAAsB;AACzC,MAAI,YAAQ,2BAAAA,SAAmB,aAAc,IAAI,gBAAgB;AACjE,QAAM,wBAAoB,sBAAAC,SAAe,iBAAAC,SAAU,iBAAkB;AAErE,iBAAe,MAAM;AACpB,QAAK,OAAQ;AACZ,aAAO;AAAA,IACR;AAEA,UAAM,OAAO,UAAM,iBAAAA,SAEd;AAAA,MACJ,MAAM;AAAA,IACP,CAAE;AAEF,gBACC,uBAAAC;AAAA,MACC,MAAM,MAAM;AAAA,MACZ;AAAA,IACD,KAAK,CAAC;AAEP,WAAO;AAAA,EACR;AAEA,WAAS,IAAK,SAA2B;AACxC,UAAM,oBAAoB;AAAA,MACzB,GAAG;AAAA,MACH,YAAW,oBAAI,KAAK,GAAE,YAAY;AAAA,IACnC;AACA,YAAQ;AAKR,8CAAiB,wBAAwB,iBAAkB;AAO3D,sBAAmB;AAAA,MAClB,MAAM;AAAA,MACN,QAAQ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,MAMR,WAAW;AAAA,MACX,MAAM;AAAA,QACL,MAAM;AAAA,UACL,uBAAuB;AAAA,QACxB;AAAA,MACD;AAAA,IACD,CAAE,EAAE,MAAO,MAAM;AAAA,IAAC,CAAE;AAAA,EACrB;AAEA,SAAO;AAAA,IACN;AAAA,IACA;AAAA,EACD;AACD;",
6
+ "names": ["isPreferencesData", "debounceAsync", "apiFetch", "getNewestData"]
7
7
  }
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // packages/preferences-persistence/src/get-newest-data.ts
31
+ var get_newest_data_exports = {};
32
+ __export(get_newest_data_exports, {
33
+ default: () => getNewestData
34
+ });
35
+ module.exports = __toCommonJS(get_newest_data_exports);
36
+ var import_is_preferences_data = __toESM(require("./is-preferences-data.cjs"));
37
+ var import_local_storage = require("./local-storage.cjs");
38
+ var import_preferences_package_data = __toESM(require("./migrations/preferences-package-data/index.cjs"));
39
+ function pickNewestData(serverData, localStorageRestoreKey) {
40
+ const storedData = (0, import_local_storage.readStoredJSON)(localStorageRestoreKey);
41
+ const localData = (0, import_is_preferences_data.default)(storedData) ? storedData : null;
42
+ if (!(0, import_is_preferences_data.default)(serverData)) {
43
+ return localData;
44
+ }
45
+ const serverModified = Date.parse(serverData._modified ?? "") || 0;
46
+ const localModified = Date.parse(localData?._modified ?? "") || 0;
47
+ return localData && localModified > serverModified ? localData : serverData;
48
+ }
49
+ function getNewestData(serverData, localStorageRestoreKey) {
50
+ const newestData = pickNewestData(serverData, localStorageRestoreKey);
51
+ return newestData ? (0, import_preferences_package_data.default)(newestData) : void 0;
52
+ }
53
+ //# sourceMappingURL=get-newest-data.cjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/get-newest-data.ts"],
4
+ "sourcesContent": ["import isPreferencesData from './is-preferences-data';\nimport { readStoredJSON } from './local-storage';\nimport convertPreferencesPackageData from './migrations/preferences-package-data';\nimport type { PreferencesData, ScopedPreferences } from './types';\n\n/**\n * Picks the most recently modified preferences from the server data and the\n * local storage backup, ignoring either when it is not a preferences object.\n *\n * @param serverData Preferences data from the server.\n * @param localStorageRestoreKey The key of the local storage backup.\n *\n * @return The newest preferences data, or `null` when neither is valid.\n */\nfunction pickNewestData(\n\tserverData: unknown,\n\tlocalStorageRestoreKey: string\n): PreferencesData | null {\n\tconst storedData = readStoredJSON( localStorageRestoreKey );\n\tconst localData = isPreferencesData( storedData ) ? storedData : null;\n\tif ( ! isPreferencesData( serverData ) ) {\n\t\treturn localData;\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 = Date.parse( serverData._modified ?? '' ) || 0;\n\tconst localModified = Date.parse( localData?._modified ?? '' ) || 0;\n\n\t// Prefer server data when it is at least as recent.\n\treturn localData && localModified > serverModified ? localData : serverData;\n}\n\n/**\n * Gets the newest persisted preferences, migrated to the current format.\n *\n * @param serverData Preferences data from the server.\n * @param localStorageRestoreKey The key of the local storage backup.\n *\n * @return The migrated preferences, or `undefined` when there are none.\n */\nexport default function getNewestData(\n\tserverData: unknown,\n\tlocalStorageRestoreKey: string\n): ScopedPreferences | undefined {\n\tconst newestData = pickNewestData( serverData, localStorageRestoreKey );\n\treturn newestData\n\t\t? convertPreferencesPackageData( newestData as ScopedPreferences )\n\t\t: undefined;\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,iCAA8B;AAC9B,2BAA+B;AAC/B,sCAA0C;AAY1C,SAAS,eACR,YACA,wBACyB;AACzB,QAAM,iBAAa,qCAAgB,sBAAuB;AAC1D,QAAM,gBAAY,2BAAAA,SAAmB,UAAW,IAAI,aAAa;AACjE,MAAK,KAAE,2BAAAA,SAAmB,UAAW,GAAI;AACxC,WAAO;AAAA,EACR;AAIA,QAAM,iBAAiB,KAAK,MAAO,WAAW,aAAa,EAAG,KAAK;AACnE,QAAM,gBAAgB,KAAK,MAAO,WAAW,aAAa,EAAG,KAAK;AAGlE,SAAO,aAAa,gBAAgB,iBAAiB,YAAY;AAClE;AAUe,SAAR,cACN,YACA,wBACgC;AAChC,QAAM,aAAa,eAAgB,YAAY,sBAAuB;AACtE,SAAO,iBACJ,gCAAAC,SAA+B,UAAgC,IAC/D;AACJ;",
6
+ "names": ["isPreferencesData", "convertPreferencesPackageData"]
7
+ }
package/build/index.cjs CHANGED
@@ -1,3 +1,4 @@
1
+ "use strict";
1
2
  var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -26,7 +27,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
26
27
  ));
27
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
29
 
29
- // packages/preferences-persistence/src/index.js
30
+ // packages/preferences-persistence/src/index.ts
30
31
  var index_exports = {};
31
32
  __export(index_exports, {
32
33
  __unstableCreatePersistenceLayer: () => __unstableCreatePersistenceLayer,
@@ -35,24 +36,15 @@ __export(index_exports, {
35
36
  module.exports = __toCommonJS(index_exports);
36
37
  var import_create = __toESM(require("./create/index.cjs"));
37
38
  var import_legacy_local_storage_data = __toESM(require("./migrations/legacy-local-storage-data/index.cjs"));
38
- var import_preferences_package_data = __toESM(require("./migrations/preferences-package-data/index.cjs"));
39
+ var import_get_newest_data = __toESM(require("./get-newest-data.cjs"));
39
40
  function __unstableCreatePersistenceLayer(serverData, userId) {
40
41
  const localStorageRestoreKey = `WP_PREFERENCES_USER_${userId}`;
41
- const localData = JSON.parse(
42
- window.localStorage.getItem(localStorageRestoreKey)
43
- );
44
- const serverModified = Date.parse(serverData && serverData._modified) || 0;
45
- const localModified = Date.parse(localData && localData._modified) || 0;
46
- let preloadedData;
47
- if (serverData && serverModified >= localModified) {
48
- preloadedData = (0, import_preferences_package_data.default)(serverData);
49
- } else if (localData) {
50
- preloadedData = (0, import_preferences_package_data.default)(localData);
51
- } else {
52
- preloadedData = (0, import_legacy_local_storage_data.default)(userId);
53
- }
54
42
  return (0, import_create.default)({
55
- preloadedData,
43
+ /*
44
+ * Fall back to data in the legacy format from the old persistence system.
45
+ * The server data is already preloaded, so fetching it again is redundant.
46
+ */
47
+ preloadedData: (0, import_get_newest_data.default)(serverData, localStorageRestoreKey) ?? (0, import_legacy_local_storage_data.default)(userId) ?? {},
56
48
  localStorageRestoreKey
57
49
  });
58
50
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../src/index.js"],
4
- "sourcesContent": ["import 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"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA,8BAAAA;AAAA;AAAA;AAAA,oBAAmB;AACnB,uCAA0C;AAC1C,sCAA0C;AAkBnC,SAAS,iCAAkC,YAAY,QAAS;AACtE,QAAM,yBAAyB,uBAAwB,MAAO;AAC9D,QAAM,YAAY,KAAK;AAAA,IACtB,OAAO,aAAa,QAAS,sBAAuB;AAAA,EACrD;AAIA,QAAM,iBACL,KAAK,MAAO,cAAc,WAAW,SAAU,KAAK;AACrD,QAAM,gBAAgB,KAAK,MAAO,aAAa,UAAU,SAAU,KAAK;AAExE,MAAI;AACJ,MAAK,cAAc,kBAAkB,eAAgB;AACpD,wBAAgB,gCAAAC,SAA+B,UAAW;AAAA,EAC3D,WAAY,WAAY;AACvB,wBAAgB,gCAAAA,SAA+B,SAAU;AAAA,EAC1D,OAAO;AAEN,wBAAgB,iCAAAC,SAA+B,MAAO;AAAA,EACvD;AAEA,aAAO,cAAAC,SAAQ;AAAA,IACd;AAAA,IACA;AAAA,EACD,CAAE;AACH;",
6
- "names": ["create", "convertPreferencesPackageData", "convertLegacyLocalStorageData", "create"]
3
+ "sources": ["../src/index.ts"],
4
+ "sourcesContent": ["import create from './create';\nimport convertLegacyLocalStorageData from './migrations/legacy-local-storage-data';\nimport getNewestData from './get-newest-data';\nimport type { PersistenceLayer } from './types';\n\nexport { create };\n\nexport type * from './types';\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 serverData Preferences data preloaded from the server.\n * @param userId The user id.\n *\n * @return The persistence layer initialized with the preloaded data.\n */\nexport function __unstableCreatePersistenceLayer(\n\tserverData: unknown,\n\tuserId: string | number\n): PersistenceLayer {\n\tconst localStorageRestoreKey = `WP_PREFERENCES_USER_${ userId }`;\n\treturn create( {\n\t\t/*\n\t\t * Fall back to data in the legacy format from the old persistence system.\n\t\t * The server data is already preloaded, so fetching it again is redundant.\n\t\t */\n\t\tpreloadedData:\n\t\t\tgetNewestData( serverData, localStorageRestoreKey ) ??\n\t\t\tconvertLegacyLocalStorageData( userId ) ??\n\t\t\t{},\n\t\tlocalStorageRestoreKey,\n\t} );\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA,8BAAAA;AAAA;AAAA;AAAA,oBAAmB;AACnB,uCAA0C;AAC1C,6BAA0B;AAqBnB,SAAS,iCACf,YACA,QACmB;AACnB,QAAM,yBAAyB,uBAAwB,MAAO;AAC9D,aAAO,cAAAC,SAAQ;AAAA;AAAA;AAAA;AAAA;AAAA,IAKd,mBACC,uBAAAC,SAAe,YAAY,sBAAuB,SAClD,iCAAAC,SAA+B,MAAO,KACtC,CAAC;AAAA,IACF;AAAA,EACD,CAAE;AACH;",
6
+ "names": ["create", "create", "getNewestData", "convertLegacyLocalStorageData"]
7
7
  }
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // packages/preferences-persistence/src/is-preferences-data.ts
21
+ var is_preferences_data_exports = {};
22
+ __export(is_preferences_data_exports, {
23
+ default: () => isPreferencesData
24
+ });
25
+ module.exports = __toCommonJS(is_preferences_data_exports);
26
+ function isPreferencesData(data) {
27
+ return !!data && typeof data === "object" && !Array.isArray(data);
28
+ }
29
+ //# sourceMappingURL=is-preferences-data.cjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/is-preferences-data.ts"],
4
+ "sourcesContent": ["import type { PreferencesData } from './types';\n\n/**\n * Checks whether persisted data is a preferences object. Empty user meta\n * reaches the client as `[]` or `''`, which must not be used as preferences.\n *\n * @param data The persisted data.\n *\n * @return Whether the data is a preferences object.\n */\nexport default function isPreferencesData(\n\tdata: unknown\n): data is PreferencesData {\n\treturn !! data && typeof data === 'object' && ! Array.isArray( data );\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAUe,SAAR,kBACN,MAC0B;AAC1B,SAAO,CAAC,CAAE,QAAQ,OAAO,SAAS,YAAY,CAAE,MAAM,QAAS,IAAK;AACrE;",
6
+ "names": []
7
+ }
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // packages/preferences-persistence/src/local-storage.ts
21
+ var local_storage_exports = {};
22
+ __export(local_storage_exports, {
23
+ readStoredJSON: () => readStoredJSON,
24
+ writeStoredJSON: () => writeStoredJSON
25
+ });
26
+ module.exports = __toCommonJS(local_storage_exports);
27
+ function readStoredJSON(key) {
28
+ try {
29
+ const value = window.localStorage.getItem(key);
30
+ return value === null ? null : JSON.parse(value);
31
+ } catch {
32
+ return null;
33
+ }
34
+ }
35
+ function writeStoredJSON(key, value) {
36
+ try {
37
+ window.localStorage.setItem(key, JSON.stringify(value));
38
+ } catch {
39
+ }
40
+ }
41
+ // Annotate the CommonJS export names for ESM import in node:
42
+ 0 && (module.exports = {
43
+ readStoredJSON,
44
+ writeStoredJSON
45
+ });
46
+ //# sourceMappingURL=local-storage.cjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/local-storage.ts"],
4
+ "sourcesContent": ["/**\n * Reads and parses a JSON value from local storage.\n *\n * @param key The local storage key.\n *\n * @return The parsed value, or `null` when the value is missing or invalid,\n * or local storage is unavailable.\n */\nexport function readStoredJSON( key: string ): unknown {\n\ttry {\n\t\tconst value = window.localStorage.getItem( key );\n\t\treturn value === null ? null : JSON.parse( value );\n\t} catch {\n\t\treturn null;\n\t}\n}\n\n/**\n * Stores a value in local storage as JSON.\n *\n * Failures, such as blocked storage or an exceeded quota, are ignored.\n *\n * @param key The local storage key.\n * @param value The value to store.\n */\nexport function writeStoredJSON( key: string, value: unknown ) {\n\ttry {\n\t\twindow.localStorage.setItem( key, JSON.stringify( value ) );\n\t} catch {}\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAQO,SAAS,eAAgB,KAAuB;AACtD,MAAI;AACH,UAAM,QAAQ,OAAO,aAAa,QAAS,GAAI;AAC/C,WAAO,UAAU,OAAO,OAAO,KAAK,MAAO,KAAM;AAAA,EAClD,QAAQ;AACP,WAAO;AAAA,EACR;AACD;AAUO,SAAS,gBAAiB,KAAa,OAAiB;AAC9D,MAAI;AACH,WAAO,aAAa,QAAS,KAAK,KAAK,UAAW,KAAM,CAAE;AAAA,EAC3D,QAAQ;AAAA,EAAC;AACV;",
6
+ "names": []
7
+ }
@@ -1,3 +1,4 @@
1
+ "use strict";
1
2
  var __defProp = Object.defineProperty;
2
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
@@ -16,7 +17,7 @@ var __copyProps = (to, from, except, desc) => {
16
17
  };
17
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
19
 
19
- // packages/preferences-persistence/src/migrations/legacy-local-storage-data/convert-edit-post-panels.js
20
+ // packages/preferences-persistence/src/migrations/legacy-local-storage-data/convert-edit-post-panels.ts
20
21
  var convert_edit_post_panels_exports = {};
21
22
  __export(convert_edit_post_panels_exports, {
22
23
  default: () => convertEditPostPanels
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../../../src/migrations/legacy-local-storage-data/convert-edit-post-panels.js"],
4
- "sourcesContent": ["/**\n * Convert the post editor's panels state from:\n * ```\n * {\n * panels: {\n * tags: {\n * enabled: true,\n * opened: true,\n * },\n * permalinks: {\n * enabled: false,\n * opened: false,\n * },\n * },\n * }\n * ```\n *\n * to a new, more concise data structure:\n * {\n * inactivePanels: [\n * 'permalinks',\n * ],\n * openPanels: [\n * 'tags',\n * ],\n * }\n *\n * @param {Object} preferences A preferences object.\n *\n * @return {Object} The converted data.\n */\nexport default function convertEditPostPanels( preferences ) {\n\tconst panels = preferences?.panels ?? {};\n\treturn Object.keys( panels ).reduce(\n\t\t( convertedData, panelName ) => {\n\t\t\tconst panel = panels[ panelName ];\n\n\t\t\tif ( panel?.enabled === false ) {\n\t\t\t\tconvertedData.inactivePanels.push( panelName );\n\t\t\t}\n\n\t\t\tif ( panel?.opened === true ) {\n\t\t\t\tconvertedData.openPanels.push( panelName );\n\t\t\t}\n\n\t\t\treturn convertedData;\n\t\t},\n\t\t{ inactivePanels: [], openPanels: [] }\n\t);\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AA+Be,SAAR,sBAAwC,aAAc;AAC5D,QAAM,SAAS,aAAa,UAAU,CAAC;AACvC,SAAO,OAAO,KAAM,MAAO,EAAE;AAAA,IAC5B,CAAE,eAAe,cAAe;AAC/B,YAAM,QAAQ,OAAQ,SAAU;AAEhC,UAAK,OAAO,YAAY,OAAQ;AAC/B,sBAAc,eAAe,KAAM,SAAU;AAAA,MAC9C;AAEA,UAAK,OAAO,WAAW,MAAO;AAC7B,sBAAc,WAAW,KAAM,SAAU;AAAA,MAC1C;AAEA,aAAO;AAAA,IACR;AAAA,IACA,EAAE,gBAAgB,CAAC,GAAG,YAAY,CAAC,EAAE;AAAA,EACtC;AACD;",
3
+ "sources": ["../../../src/migrations/legacy-local-storage-data/convert-edit-post-panels.ts"],
4
+ "sourcesContent": ["import type { ScopePreferences } from '../../types';\nimport type { EditPostPanels, LegacyEditPostPanel } from './types';\n\n/**\n * Convert the post editor's panels state from:\n * ```\n * {\n * panels: {\n * tags: {\n * enabled: true,\n * opened: true,\n * },\n * permalinks: {\n * enabled: false,\n * opened: false,\n * },\n * },\n * }\n * ```\n *\n * to a new, more concise data structure:\n * {\n * inactivePanels: [\n * 'permalinks',\n * ],\n * openPanels: [\n * 'tags',\n * ],\n * }\n *\n * @param preferences A preferences object.\n *\n * @return The converted data.\n */\nexport default function convertEditPostPanels(\n\tpreferences: ScopePreferences\n): EditPostPanels {\n\tconst panels = ( preferences?.panels ?? {} ) as Record<\n\t\tstring,\n\t\tLegacyEditPostPanel | undefined\n\t>;\n\treturn Object.keys( panels ).reduce< EditPostPanels >(\n\t\t( convertedData, panelName ) => {\n\t\t\tconst panel = panels[ panelName ];\n\n\t\t\tif ( panel?.enabled === false ) {\n\t\t\t\tconvertedData.inactivePanels.push( panelName );\n\t\t\t}\n\n\t\t\tif ( panel?.opened === true ) {\n\t\t\t\tconvertedData.openPanels.push( panelName );\n\t\t\t}\n\n\t\t\treturn convertedData;\n\t\t},\n\t\t{ inactivePanels: [], openPanels: [] }\n\t);\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAkCe,SAAR,sBACN,aACiB;AACjB,QAAM,SAAW,aAAa,UAAU,CAAC;AAIzC,SAAO,OAAO,KAAM,MAAO,EAAE;AAAA,IAC5B,CAAE,eAAe,cAAe;AAC/B,YAAM,QAAQ,OAAQ,SAAU;AAEhC,UAAK,OAAO,YAAY,OAAQ;AAC/B,sBAAc,eAAe,KAAM,SAAU;AAAA,MAC9C;AAEA,UAAK,OAAO,WAAW,MAAO;AAC7B,sBAAc,WAAW,KAAM,SAAU;AAAA,MAC1C;AAEA,aAAO;AAAA,IACR;AAAA,IACA,EAAE,gBAAgB,CAAC,GAAG,YAAY,CAAC,EAAE;AAAA,EACtC;AACD;",
6
6
  "names": []
7
7
  }
@@ -1,3 +1,4 @@
1
+ "use strict";
1
2
  var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -26,7 +27,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
26
27
  ));
27
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
29
 
29
- // packages/preferences-persistence/src/migrations/legacy-local-storage-data/index.js
30
+ // packages/preferences-persistence/src/migrations/legacy-local-storage-data/index.ts
30
31
  var legacy_local_storage_data_exports = {};
31
32
  __export(legacy_local_storage_data_exports, {
32
33
  convertLegacyData: () => convertLegacyData,
@@ -38,10 +39,10 @@ var import_move_third_party_feature_preferences = __toESM(require("./move-third-
38
39
  var import_move_individual_preference = __toESM(require("./move-individual-preference.cjs"));
39
40
  var import_move_interface_enable_items = __toESM(require("./move-interface-enable-items.cjs"));
40
41
  var import_convert_edit_post_panels = __toESM(require("./convert-edit-post-panels.cjs"));
42
+ var import_is_preferences_data = __toESM(require("../../is-preferences-data.cjs"));
43
+ var import_local_storage = require("../../local-storage.cjs");
41
44
  function getLegacyData(userId) {
42
- const key = `WP_DATA_USER_${userId}`;
43
- const unparsedData = window.localStorage.getItem(key);
44
- return JSON.parse(unparsedData);
45
+ return (0, import_local_storage.readStoredJSON)(`WP_DATA_USER_${userId}`);
45
46
  }
46
47
  function convertLegacyData(data) {
47
48
  if (!data) {
@@ -84,7 +85,8 @@ function convertLegacyData(data) {
84
85
  { from: "core/edit-site", to: "core/edit-site" },
85
86
  "editorMode"
86
87
  );
87
- return data?.["core/preferences"]?.preferences;
88
+ const preferences = data?.["core/preferences"]?.preferences;
89
+ return (0, import_is_preferences_data.default)(preferences) ? preferences : void 0;
88
90
  }
89
91
  function convertLegacyLocalStorageData(userId) {
90
92
  const data = getLegacyData(userId);
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../../../src/migrations/legacy-local-storage-data/index.js"],
4
- "sourcesContent": ["import moveFeaturePreferences from './move-feature-preferences';\nimport moveThirdPartyFeaturePreferences from './move-third-party-feature-preferences';\nimport moveIndividualPreference from './move-individual-preference';\nimport moveInterfaceEnableItems from './move-interface-enable-items';\nimport convertEditPostPanels from './convert-edit-post-panels';\n\n/**\n * Gets the legacy local storage data for a given user.\n *\n * @param {string | number} userId The user id.\n *\n * @return {Object | null} The local storage data.\n */\nfunction getLegacyData( userId ) {\n\tconst key = `WP_DATA_USER_${ userId }`;\n\tconst unparsedData = window.localStorage.getItem( key );\n\treturn JSON.parse( unparsedData );\n}\n\n/**\n * Converts data from the old `@wordpress/data` package format.\n *\n * @param {Object | null | undefined} data The legacy data in its original format.\n *\n * @return {Object | undefined} The converted data or `undefined` if there was\n * nothing to convert.\n */\nexport function convertLegacyData( data ) {\n\tif ( ! data ) {\n\t\treturn;\n\t}\n\n\t// Move boolean feature preferences from each editor into the\n\t// preferences store data structure.\n\tdata = moveFeaturePreferences( data, 'core/edit-widgets' );\n\tdata = moveFeaturePreferences( data, 'core/customize-widgets' );\n\tdata = moveFeaturePreferences( data, 'core/edit-post' );\n\tdata = moveFeaturePreferences( data, 'core/edit-site' );\n\n\t// Move third party boolean feature preferences from the interface package\n\t// to the preferences store data structure.\n\tdata = moveThirdPartyFeaturePreferences( data );\n\n\t// Move and convert the interface store's `enableItems` data into the\n\t// preferences data structure.\n\tdata = moveInterfaceEnableItems( data );\n\n\t// Move individual ad-hoc preferences from various packages into the\n\t// preferences store data structure.\n\tdata = moveIndividualPreference(\n\t\tdata,\n\t\t{ from: 'core/edit-post', to: 'core/edit-post' },\n\t\t'hiddenBlockTypes'\n\t);\n\tdata = moveIndividualPreference(\n\t\tdata,\n\t\t{ from: 'core/edit-post', to: 'core/edit-post' },\n\t\t'editorMode'\n\t);\n\tdata = moveIndividualPreference(\n\t\tdata,\n\t\t{ from: 'core/edit-post', to: 'core/edit-post' },\n\t\t'panels',\n\t\tconvertEditPostPanels\n\t);\n\tdata = moveIndividualPreference(\n\t\tdata,\n\t\t{ from: 'core/editor', to: 'core' },\n\t\t'isPublishSidebarEnabled'\n\t);\n\tdata = moveIndividualPreference(\n\t\tdata,\n\t\t{ from: 'core/edit-post', to: 'core' },\n\t\t'isPublishSidebarEnabled'\n\t);\n\tdata = moveIndividualPreference(\n\t\tdata,\n\t\t{ from: 'core/edit-site', to: 'core/edit-site' },\n\t\t'editorMode'\n\t);\n\n\t// The new system is only concerned with persisting\n\t// 'core/preferences' preferences reducer, so only return that.\n\treturn data?.[ 'core/preferences' ]?.preferences;\n}\n\n/**\n * Gets the legacy local storage data for the given user and returns the\n * data converted to the new format.\n *\n * @param {string | number} userId The user id.\n *\n * @return {Object | undefined} The converted data or undefined if no local\n * storage data could be found.\n */\nexport default function convertLegacyLocalStorageData( userId ) {\n\tconst data = getLegacyData( userId );\n\treturn convertLegacyData( data );\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sCAAmC;AACnC,kDAA6C;AAC7C,wCAAqC;AACrC,yCAAqC;AACrC,sCAAkC;AASlC,SAAS,cAAe,QAAS;AAChC,QAAM,MAAM,gBAAiB,MAAO;AACpC,QAAM,eAAe,OAAO,aAAa,QAAS,GAAI;AACtD,SAAO,KAAK,MAAO,YAAa;AACjC;AAUO,SAAS,kBAAmB,MAAO;AACzC,MAAK,CAAE,MAAO;AACb;AAAA,EACD;AAIA,aAAO,gCAAAA,SAAwB,MAAM,mBAAoB;AACzD,aAAO,gCAAAA,SAAwB,MAAM,wBAAyB;AAC9D,aAAO,gCAAAA,SAAwB,MAAM,gBAAiB;AACtD,aAAO,gCAAAA,SAAwB,MAAM,gBAAiB;AAItD,aAAO,4CAAAC,SAAkC,IAAK;AAI9C,aAAO,mCAAAC,SAA0B,IAAK;AAItC,aAAO,kCAAAC;AAAA,IACN;AAAA,IACA,EAAE,MAAM,kBAAkB,IAAI,iBAAiB;AAAA,IAC/C;AAAA,EACD;AACA,aAAO,kCAAAA;AAAA,IACN;AAAA,IACA,EAAE,MAAM,kBAAkB,IAAI,iBAAiB;AAAA,IAC/C;AAAA,EACD;AACA,aAAO,kCAAAA;AAAA,IACN;AAAA,IACA,EAAE,MAAM,kBAAkB,IAAI,iBAAiB;AAAA,IAC/C;AAAA,IACA,gCAAAC;AAAA,EACD;AACA,aAAO,kCAAAD;AAAA,IACN;AAAA,IACA,EAAE,MAAM,eAAe,IAAI,OAAO;AAAA,IAClC;AAAA,EACD;AACA,aAAO,kCAAAA;AAAA,IACN;AAAA,IACA,EAAE,MAAM,kBAAkB,IAAI,OAAO;AAAA,IACrC;AAAA,EACD;AACA,aAAO,kCAAAA;AAAA,IACN;AAAA,IACA,EAAE,MAAM,kBAAkB,IAAI,iBAAiB;AAAA,IAC/C;AAAA,EACD;AAIA,SAAO,OAAQ,kBAAmB,GAAG;AACtC;AAWe,SAAR,8BAAgD,QAAS;AAC/D,QAAM,OAAO,cAAe,MAAO;AACnC,SAAO,kBAAmB,IAAK;AAChC;",
6
- "names": ["moveFeaturePreferences", "moveThirdPartyFeaturePreferences", "moveInterfaceEnableItems", "moveIndividualPreference", "convertEditPostPanels"]
3
+ "sources": ["../../../src/migrations/legacy-local-storage-data/index.ts"],
4
+ "sourcesContent": ["import moveFeaturePreferences from './move-feature-preferences';\nimport moveThirdPartyFeaturePreferences from './move-third-party-feature-preferences';\nimport moveIndividualPreference from './move-individual-preference';\nimport moveInterfaceEnableItems from './move-interface-enable-items';\nimport convertEditPostPanels from './convert-edit-post-panels';\nimport isPreferencesData from '../../is-preferences-data';\nimport { readStoredJSON } from '../../local-storage';\nimport type { ScopedPreferences } from '../../types';\nimport type { LegacyData } from './types';\n\n/**\n * Gets the legacy local storage data for a given user.\n *\n * @param userId The user id.\n *\n * @return The local storage data.\n */\nfunction getLegacyData( userId: string | number ): LegacyData | null {\n\treturn readStoredJSON( `WP_DATA_USER_${ userId }` ) as LegacyData | null;\n}\n\n/**\n * Converts data from the old `@wordpress/data` package format.\n *\n * @param data The legacy data in its original format.\n *\n * @return The converted data or `undefined` if there was\n * nothing to convert.\n */\nexport function convertLegacyData(\n\tdata: LegacyData | null | undefined\n): ScopedPreferences | undefined {\n\tif ( ! data ) {\n\t\treturn;\n\t}\n\n\t// Move boolean feature preferences from each editor into the\n\t// preferences store data structure.\n\tdata = moveFeaturePreferences( data, 'core/edit-widgets' );\n\tdata = moveFeaturePreferences( data, 'core/customize-widgets' );\n\tdata = moveFeaturePreferences( data, 'core/edit-post' );\n\tdata = moveFeaturePreferences( data, 'core/edit-site' );\n\n\t// Move third party boolean feature preferences from the interface package\n\t// to the preferences store data structure.\n\tdata = moveThirdPartyFeaturePreferences( data );\n\n\t// Move and convert the interface store's `enableItems` data into the\n\t// preferences data structure.\n\tdata = moveInterfaceEnableItems( data );\n\n\t// Move individual ad-hoc preferences from various packages into the\n\t// preferences store data structure.\n\tdata = moveIndividualPreference(\n\t\tdata,\n\t\t{ from: 'core/edit-post', to: 'core/edit-post' },\n\t\t'hiddenBlockTypes'\n\t);\n\tdata = moveIndividualPreference(\n\t\tdata,\n\t\t{ from: 'core/edit-post', to: 'core/edit-post' },\n\t\t'editorMode'\n\t);\n\tdata = moveIndividualPreference(\n\t\tdata,\n\t\t{ from: 'core/edit-post', to: 'core/edit-post' },\n\t\t'panels',\n\t\tconvertEditPostPanels\n\t);\n\tdata = moveIndividualPreference(\n\t\tdata,\n\t\t{ from: 'core/editor', to: 'core' },\n\t\t'isPublishSidebarEnabled'\n\t);\n\tdata = moveIndividualPreference(\n\t\tdata,\n\t\t{ from: 'core/edit-post', to: 'core' },\n\t\t'isPublishSidebarEnabled'\n\t);\n\tdata = moveIndividualPreference(\n\t\tdata,\n\t\t{ from: 'core/edit-site', to: 'core/edit-site' },\n\t\t'editorMode'\n\t);\n\n\t// The new system is only concerned with persisting\n\t// 'core/preferences' preferences reducer, so only return that.\n\tconst preferences = data?.[ 'core/preferences' ]?.preferences;\n\treturn isPreferencesData( preferences ) ? preferences : undefined;\n}\n\n/**\n * Gets the legacy local storage data for the given user and returns the\n * data converted to the new format.\n *\n * @param userId The user id.\n *\n * @return The converted data or undefined if no local\n * storage data could be found.\n */\nexport default function convertLegacyLocalStorageData(\n\tuserId: string | number\n): ScopedPreferences | undefined {\n\tconst data = getLegacyData( userId );\n\treturn convertLegacyData( data );\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sCAAmC;AACnC,kDAA6C;AAC7C,wCAAqC;AACrC,yCAAqC;AACrC,sCAAkC;AAClC,iCAA8B;AAC9B,2BAA+B;AAW/B,SAAS,cAAe,QAA6C;AACpE,aAAO,qCAAgB,gBAAiB,MAAO,EAAG;AACnD;AAUO,SAAS,kBACf,MACgC;AAChC,MAAK,CAAE,MAAO;AACb;AAAA,EACD;AAIA,aAAO,gCAAAA,SAAwB,MAAM,mBAAoB;AACzD,aAAO,gCAAAA,SAAwB,MAAM,wBAAyB;AAC9D,aAAO,gCAAAA,SAAwB,MAAM,gBAAiB;AACtD,aAAO,gCAAAA,SAAwB,MAAM,gBAAiB;AAItD,aAAO,4CAAAC,SAAkC,IAAK;AAI9C,aAAO,mCAAAC,SAA0B,IAAK;AAItC,aAAO,kCAAAC;AAAA,IACN;AAAA,IACA,EAAE,MAAM,kBAAkB,IAAI,iBAAiB;AAAA,IAC/C;AAAA,EACD;AACA,aAAO,kCAAAA;AAAA,IACN;AAAA,IACA,EAAE,MAAM,kBAAkB,IAAI,iBAAiB;AAAA,IAC/C;AAAA,EACD;AACA,aAAO,kCAAAA;AAAA,IACN;AAAA,IACA,EAAE,MAAM,kBAAkB,IAAI,iBAAiB;AAAA,IAC/C;AAAA,IACA,gCAAAC;AAAA,EACD;AACA,aAAO,kCAAAD;AAAA,IACN;AAAA,IACA,EAAE,MAAM,eAAe,IAAI,OAAO;AAAA,IAClC;AAAA,EACD;AACA,aAAO,kCAAAA;AAAA,IACN;AAAA,IACA,EAAE,MAAM,kBAAkB,IAAI,OAAO;AAAA,IACrC;AAAA,EACD;AACA,aAAO,kCAAAA;AAAA,IACN;AAAA,IACA,EAAE,MAAM,kBAAkB,IAAI,iBAAiB;AAAA,IAC/C;AAAA,EACD;AAIA,QAAM,cAAc,OAAQ,kBAAmB,GAAG;AAClD,aAAO,2BAAAE,SAAmB,WAAY,IAAI,cAAc;AACzD;AAWe,SAAR,8BACN,QACgC;AAChC,QAAM,OAAO,cAAe,MAAO;AACnC,SAAO,kBAAmB,IAAK;AAChC;",
6
+ "names": ["moveFeaturePreferences", "moveThirdPartyFeaturePreferences", "moveInterfaceEnableItems", "moveIndividualPreference", "convertEditPostPanels", "isPreferencesData"]
7
7
  }
@@ -1,3 +1,4 @@
1
+ "use strict";
1
2
  var __defProp = Object.defineProperty;
2
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
@@ -16,7 +17,7 @@ var __copyProps = (to, from, except, desc) => {
16
17
  };
17
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
19
 
19
- // packages/preferences-persistence/src/migrations/legacy-local-storage-data/move-feature-preferences.js
20
+ // packages/preferences-persistence/src/migrations/legacy-local-storage-data/move-feature-preferences.ts
20
21
  var move_feature_preferences_exports = {};
21
22
  __export(move_feature_preferences_exports, {
22
23
  default: () => moveFeaturePreferences
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../../../src/migrations/legacy-local-storage-data/move-feature-preferences.js"],
4
- "sourcesContent": ["/**\n * Move the 'features' object in local storage from the sourceStoreName to the\n * preferences store data structure.\n *\n * Previously, editors used a data structure like this for feature preferences:\n * ```js\n * {\n * 'core/edit-post': {\n * preferences: {\n * features; {\n * topToolbar: true,\n * // ... other boolean 'feature' preferences\n * },\n * },\n * },\n * }\n * ```\n *\n * And for a while these feature preferences lived in the interface package:\n * ```js\n * {\n * 'core/interface': {\n * preferences: {\n * features: {\n * 'core/edit-post': {\n * topToolbar: true\n * }\n * }\n * }\n * }\n * }\n * ```\n *\n * In the preferences store, 'features' aren't considered special, they're\n * merged to the root level of the scope along with other preferences:\n * ```js\n * {\n * 'core/preferences': {\n * preferences: {\n * 'core/edit-post': {\n * topToolbar: true,\n * // ... any other preferences.\n * }\n * }\n * }\n * }\n * ```\n *\n * This function handles moving from either the source store or the interface\n * store to the preferences data structure.\n *\n * @param {Object} state The state before migration.\n * @param {string} sourceStoreName The name of the store that has persisted\n * preferences to migrate to the preferences\n * package.\n * @return {Object} The migrated state\n */\nexport default function moveFeaturePreferences( state, sourceStoreName ) {\n\tconst preferencesStoreName = 'core/preferences';\n\tconst interfaceStoreName = 'core/interface';\n\n\t// Features most recently (and briefly) lived in the interface package.\n\t// If data exists there, prioritize using that for the migration. If not\n\t// also check the original package as the user may have updated from an\n\t// older block editor version.\n\tconst interfaceFeatures =\n\t\tstate?.[ interfaceStoreName ]?.preferences?.features?.[\n\t\t\tsourceStoreName\n\t\t];\n\tconst sourceFeatures = state?.[ sourceStoreName ]?.preferences?.features;\n\tconst featuresToMigrate = interfaceFeatures\n\t\t? interfaceFeatures\n\t\t: sourceFeatures;\n\n\tif ( ! featuresToMigrate ) {\n\t\treturn state;\n\t}\n\n\tconst existingPreferences = state?.[ preferencesStoreName ]?.preferences;\n\n\t// Avoid migrating features again if they've previously been migrated.\n\tif ( existingPreferences?.[ sourceStoreName ] ) {\n\t\treturn state;\n\t}\n\n\tlet updatedInterfaceState;\n\tif ( interfaceFeatures ) {\n\t\tconst otherInterfaceState = state?.[ interfaceStoreName ];\n\t\tconst otherInterfaceScopes =\n\t\t\tstate?.[ interfaceStoreName ]?.preferences?.features;\n\n\t\tupdatedInterfaceState = {\n\t\t\t[ interfaceStoreName ]: {\n\t\t\t\t...otherInterfaceState,\n\t\t\t\tpreferences: {\n\t\t\t\t\tfeatures: {\n\t\t\t\t\t\t...otherInterfaceScopes,\n\t\t\t\t\t\t[ sourceStoreName ]: undefined,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t};\n\t}\n\n\tlet updatedSourceState;\n\tif ( sourceFeatures ) {\n\t\tconst otherSourceState = state?.[ sourceStoreName ];\n\t\tconst sourcePreferences = state?.[ sourceStoreName ]?.preferences;\n\n\t\tupdatedSourceState = {\n\t\t\t[ sourceStoreName ]: {\n\t\t\t\t...otherSourceState,\n\t\t\t\tpreferences: {\n\t\t\t\t\t...sourcePreferences,\n\t\t\t\t\tfeatures: undefined,\n\t\t\t\t},\n\t\t\t},\n\t\t};\n\t}\n\n\t// Set the feature values in the interface store, the features\n\t// object is keyed by 'scope', which matches the store name for\n\t// the source.\n\treturn {\n\t\t...state,\n\t\t[ preferencesStoreName ]: {\n\t\t\tpreferences: {\n\t\t\t\t...existingPreferences,\n\t\t\t\t[ sourceStoreName ]: featuresToMigrate,\n\t\t\t},\n\t\t},\n\t\t...updatedInterfaceState,\n\t\t...updatedSourceState,\n\t};\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAyDe,SAAR,uBAAyC,OAAO,iBAAkB;AACxE,QAAM,uBAAuB;AAC7B,QAAM,qBAAqB;AAM3B,QAAM,oBACL,QAAS,kBAAmB,GAAG,aAAa,WAC3C,eACD;AACD,QAAM,iBAAiB,QAAS,eAAgB,GAAG,aAAa;AAChE,QAAM,oBAAoB,oBACvB,oBACA;AAEH,MAAK,CAAE,mBAAoB;AAC1B,WAAO;AAAA,EACR;AAEA,QAAM,sBAAsB,QAAS,oBAAqB,GAAG;AAG7D,MAAK,sBAAuB,eAAgB,GAAI;AAC/C,WAAO;AAAA,EACR;AAEA,MAAI;AACJ,MAAK,mBAAoB;AACxB,UAAM,sBAAsB,QAAS,kBAAmB;AACxD,UAAM,uBACL,QAAS,kBAAmB,GAAG,aAAa;AAE7C,4BAAwB;AAAA,MACvB,CAAE,kBAAmB,GAAG;AAAA,QACvB,GAAG;AAAA,QACH,aAAa;AAAA,UACZ,UAAU;AAAA,YACT,GAAG;AAAA,YACH,CAAE,eAAgB,GAAG;AAAA,UACtB;AAAA,QACD;AAAA,MACD;AAAA,IACD;AAAA,EACD;AAEA,MAAI;AACJ,MAAK,gBAAiB;AACrB,UAAM,mBAAmB,QAAS,eAAgB;AAClD,UAAM,oBAAoB,QAAS,eAAgB,GAAG;AAEtD,yBAAqB;AAAA,MACpB,CAAE,eAAgB,GAAG;AAAA,QACpB,GAAG;AAAA,QACH,aAAa;AAAA,UACZ,GAAG;AAAA,UACH,UAAU;AAAA,QACX;AAAA,MACD;AAAA,IACD;AAAA,EACD;AAKA,SAAO;AAAA,IACN,GAAG;AAAA,IACH,CAAE,oBAAqB,GAAG;AAAA,MACzB,aAAa;AAAA,QACZ,GAAG;AAAA,QACH,CAAE,eAAgB,GAAG;AAAA,MACtB;AAAA,IACD;AAAA,IACA,GAAG;AAAA,IACH,GAAG;AAAA,EACJ;AACD;",
3
+ "sources": ["../../../src/migrations/legacy-local-storage-data/move-feature-preferences.ts"],
4
+ "sourcesContent": ["import type { FeaturePreferences, LegacyData } from './types';\n\n/**\n * Move the 'features' object in local storage from the sourceStoreName to the\n * preferences store data structure.\n *\n * Previously, editors used a data structure like this for feature preferences:\n * ```js\n * {\n * 'core/edit-post': {\n * preferences: {\n * features; {\n * topToolbar: true,\n * // ... other boolean 'feature' preferences\n * },\n * },\n * },\n * }\n * ```\n *\n * And for a while these feature preferences lived in the interface package:\n * ```js\n * {\n * 'core/interface': {\n * preferences: {\n * features: {\n * 'core/edit-post': {\n * topToolbar: true\n * }\n * }\n * }\n * }\n * }\n * ```\n *\n * In the preferences store, 'features' aren't considered special, they're\n * merged to the root level of the scope along with other preferences:\n * ```js\n * {\n * 'core/preferences': {\n * preferences: {\n * 'core/edit-post': {\n * topToolbar: true,\n * // ... any other preferences.\n * }\n * }\n * }\n * }\n * ```\n *\n * This function handles moving from either the source store or the interface\n * store to the preferences data structure.\n *\n * @param state The state before migration.\n * @param sourceStoreName The name of the store that has persisted\n * preferences to migrate to the preferences\n * package.\n * @return The migrated state\n */\nexport default function moveFeaturePreferences(\n\tstate: LegacyData,\n\tsourceStoreName: string\n): LegacyData {\n\tconst preferencesStoreName = 'core/preferences';\n\tconst interfaceStoreName = 'core/interface';\n\n\t// Features most recently (and briefly) lived in the interface package.\n\t// If data exists there, prioritize using that for the migration. If not\n\t// also check the original package as the user may have updated from an\n\t// older block editor version.\n\tconst interfaceFeatures =\n\t\tstate?.[ interfaceStoreName ]?.preferences?.features?.[\n\t\t\tsourceStoreName\n\t\t];\n\tconst sourceFeatures = state?.[ sourceStoreName ]?.preferences?.features as\n\t\tFeaturePreferences | undefined;\n\tconst featuresToMigrate = interfaceFeatures\n\t\t? interfaceFeatures\n\t\t: sourceFeatures;\n\n\tif ( ! featuresToMigrate ) {\n\t\treturn state;\n\t}\n\n\tconst existingPreferences = state?.[ preferencesStoreName ]?.preferences;\n\n\t// Avoid migrating features again if they've previously been migrated.\n\tif ( existingPreferences?.[ sourceStoreName ] ) {\n\t\treturn state;\n\t}\n\n\tlet updatedInterfaceState;\n\tif ( interfaceFeatures ) {\n\t\tconst otherInterfaceState = state?.[ interfaceStoreName ];\n\t\tconst otherInterfaceScopes =\n\t\t\tstate?.[ interfaceStoreName ]?.preferences?.features;\n\n\t\tupdatedInterfaceState = {\n\t\t\t[ interfaceStoreName ]: {\n\t\t\t\t...otherInterfaceState,\n\t\t\t\tpreferences: {\n\t\t\t\t\tfeatures: {\n\t\t\t\t\t\t...otherInterfaceScopes,\n\t\t\t\t\t\t[ sourceStoreName ]: undefined,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t};\n\t}\n\n\tlet updatedSourceState;\n\tif ( sourceFeatures ) {\n\t\tconst otherSourceState = state?.[ sourceStoreName ];\n\t\tconst sourcePreferences = state?.[ sourceStoreName ]?.preferences;\n\n\t\tupdatedSourceState = {\n\t\t\t[ sourceStoreName ]: {\n\t\t\t\t...otherSourceState,\n\t\t\t\tpreferences: {\n\t\t\t\t\t...sourcePreferences,\n\t\t\t\t\tfeatures: undefined,\n\t\t\t\t},\n\t\t\t},\n\t\t};\n\t}\n\n\t// Set the feature values in the interface store, the features\n\t// object is keyed by 'scope', which matches the store name for\n\t// the source.\n\treturn {\n\t\t...state,\n\t\t[ preferencesStoreName ]: {\n\t\t\tpreferences: {\n\t\t\t\t...existingPreferences,\n\t\t\t\t[ sourceStoreName ]: featuresToMigrate,\n\t\t\t},\n\t\t},\n\t\t...updatedInterfaceState,\n\t\t...updatedSourceState,\n\t};\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AA2De,SAAR,uBACN,OACA,iBACa;AACb,QAAM,uBAAuB;AAC7B,QAAM,qBAAqB;AAM3B,QAAM,oBACL,QAAS,kBAAmB,GAAG,aAAa,WAC3C,eACD;AACD,QAAM,iBAAiB,QAAS,eAAgB,GAAG,aAAa;AAEhE,QAAM,oBAAoB,oBACvB,oBACA;AAEH,MAAK,CAAE,mBAAoB;AAC1B,WAAO;AAAA,EACR;AAEA,QAAM,sBAAsB,QAAS,oBAAqB,GAAG;AAG7D,MAAK,sBAAuB,eAAgB,GAAI;AAC/C,WAAO;AAAA,EACR;AAEA,MAAI;AACJ,MAAK,mBAAoB;AACxB,UAAM,sBAAsB,QAAS,kBAAmB;AACxD,UAAM,uBACL,QAAS,kBAAmB,GAAG,aAAa;AAE7C,4BAAwB;AAAA,MACvB,CAAE,kBAAmB,GAAG;AAAA,QACvB,GAAG;AAAA,QACH,aAAa;AAAA,UACZ,UAAU;AAAA,YACT,GAAG;AAAA,YACH,CAAE,eAAgB,GAAG;AAAA,UACtB;AAAA,QACD;AAAA,MACD;AAAA,IACD;AAAA,EACD;AAEA,MAAI;AACJ,MAAK,gBAAiB;AACrB,UAAM,mBAAmB,QAAS,eAAgB;AAClD,UAAM,oBAAoB,QAAS,eAAgB,GAAG;AAEtD,yBAAqB;AAAA,MACpB,CAAE,eAAgB,GAAG;AAAA,QACpB,GAAG;AAAA,QACH,aAAa;AAAA,UACZ,GAAG;AAAA,UACH,UAAU;AAAA,QACX;AAAA,MACD;AAAA,IACD;AAAA,EACD;AAKA,SAAO;AAAA,IACN,GAAG;AAAA,IACH,CAAE,oBAAqB,GAAG;AAAA,MACzB,aAAa;AAAA,QACZ,GAAG;AAAA,QACH,CAAE,eAAgB,GAAG;AAAA,MACtB;AAAA,IACD;AAAA,IACA,GAAG;AAAA,IACH,GAAG;AAAA,EACJ;AACD;",
6
6
  "names": []
7
7
  }
@@ -1,3 +1,4 @@
1
+ "use strict";
1
2
  var __defProp = Object.defineProperty;
2
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
@@ -16,7 +17,7 @@ var __copyProps = (to, from, except, desc) => {
16
17
  };
17
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
19
 
19
- // packages/preferences-persistence/src/migrations/legacy-local-storage-data/move-individual-preference.js
20
+ // packages/preferences-persistence/src/migrations/legacy-local-storage-data/move-individual-preference.ts
20
21
  var move_individual_preference_exports = {};
21
22
  __export(move_individual_preference_exports, {
22
23
  default: () => moveIndividualPreferenceToPreferences
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../../../src/migrations/legacy-local-storage-data/move-individual-preference.js"],
4
- "sourcesContent": ["const identity = ( arg ) => arg;\n\n/**\n * Migrates an individual item inside the `preferences` object for a package's store.\n *\n * Previously, some packages had individual 'preferences' of any data type, and many used\n * complex nested data structures. For example:\n * ```js\n * {\n * 'core/edit-post': {\n * preferences: {\n * panels: {\n * publish: {\n * opened: true,\n * enabled: true,\n * }\n * },\n * // ...other preferences.\n * },\n * },\n * }\n *\n * This function supports moving an individual preference like 'panels' above into the\n * preferences package data structure.\n *\n * It supports moving a preference to a particular scope in the preferences store and\n * optionally converting the data using a `convert` function.\n *\n * ```\n *\n * @param {Object} state The original state.\n * @param {Object} migrate An options object that contains details of the migration.\n * @param {string} migrate.from The name of the store to migrate from.\n * @param {string} migrate.to The scope in the preferences store to migrate to.\n * @param {string} key The key in the preferences object to migrate.\n * @param {?Function} convert A function that converts preferences from one format to another.\n */\nexport default function moveIndividualPreferenceToPreferences(\n\tstate,\n\t{ from: sourceStoreName, to: scope },\n\tkey,\n\tconvert = identity\n) {\n\tconst preferencesStoreName = 'core/preferences';\n\tconst sourcePreference = state?.[ sourceStoreName ]?.preferences?.[ key ];\n\n\t// There's nothing to migrate, exit early.\n\tif ( sourcePreference === undefined ) {\n\t\treturn state;\n\t}\n\n\tconst targetPreference =\n\t\tstate?.[ preferencesStoreName ]?.preferences?.[ scope ]?.[ key ];\n\n\t// There's existing data at the target, so don't overwrite it, exit early.\n\tif ( targetPreference ) {\n\t\treturn state;\n\t}\n\n\tconst otherScopes = state?.[ preferencesStoreName ]?.preferences;\n\tconst otherPreferences =\n\t\tstate?.[ preferencesStoreName ]?.preferences?.[ scope ];\n\n\tconst otherSourceState = state?.[ sourceStoreName ];\n\tconst allSourcePreferences = state?.[ sourceStoreName ]?.preferences;\n\n\t// Pass an object with the key and value as this allows the convert\n\t// function to convert to a data structure that has different keys.\n\tconst convertedPreferences = convert( { [ key ]: sourcePreference } );\n\n\treturn {\n\t\t...state,\n\t\t[ preferencesStoreName ]: {\n\t\t\tpreferences: {\n\t\t\t\t...otherScopes,\n\t\t\t\t[ scope ]: {\n\t\t\t\t\t...otherPreferences,\n\t\t\t\t\t...convertedPreferences,\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t\t[ sourceStoreName ]: {\n\t\t\t...otherSourceState,\n\t\t\tpreferences: {\n\t\t\t\t...allSourcePreferences,\n\t\t\t\t[ key ]: undefined,\n\t\t\t},\n\t\t},\n\t};\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAM,WAAW,CAAE,QAAS;AAqCb,SAAR,sCACN,OACA,EAAE,MAAM,iBAAiB,IAAI,MAAM,GACnC,KACA,UAAU,UACT;AACD,QAAM,uBAAuB;AAC7B,QAAM,mBAAmB,QAAS,eAAgB,GAAG,cAAe,GAAI;AAGxE,MAAK,qBAAqB,QAAY;AACrC,WAAO;AAAA,EACR;AAEA,QAAM,mBACL,QAAS,oBAAqB,GAAG,cAAe,KAAM,IAAK,GAAI;AAGhE,MAAK,kBAAmB;AACvB,WAAO;AAAA,EACR;AAEA,QAAM,cAAc,QAAS,oBAAqB,GAAG;AACrD,QAAM,mBACL,QAAS,oBAAqB,GAAG,cAAe,KAAM;AAEvD,QAAM,mBAAmB,QAAS,eAAgB;AAClD,QAAM,uBAAuB,QAAS,eAAgB,GAAG;AAIzD,QAAM,uBAAuB,QAAS,EAAE,CAAE,GAAI,GAAG,iBAAiB,CAAE;AAEpE,SAAO;AAAA,IACN,GAAG;AAAA,IACH,CAAE,oBAAqB,GAAG;AAAA,MACzB,aAAa;AAAA,QACZ,GAAG;AAAA,QACH,CAAE,KAAM,GAAG;AAAA,UACV,GAAG;AAAA,UACH,GAAG;AAAA,QACJ;AAAA,MACD;AAAA,IACD;AAAA,IACA,CAAE,eAAgB,GAAG;AAAA,MACpB,GAAG;AAAA,MACH,aAAa;AAAA,QACZ,GAAG;AAAA,QACH,CAAE,GAAI,GAAG;AAAA,MACV;AAAA,IACD;AAAA,EACD;AACD;",
3
+ "sources": ["../../../src/migrations/legacy-local-storage-data/move-individual-preference.ts"],
4
+ "sourcesContent": ["import type { ScopePreferences } from '../../types';\nimport type { LegacyData } from './types';\n\nconst identity = < T >( arg: T ) => arg;\n\n/**\n * Migrates an individual item inside the `preferences` object for a package's store.\n *\n * Previously, some packages had individual 'preferences' of any data type, and many used\n * complex nested data structures. For example:\n * ```js\n * {\n * 'core/edit-post': {\n * preferences: {\n * panels: {\n * publish: {\n * opened: true,\n * enabled: true,\n * }\n * },\n * // ...other preferences.\n * },\n * },\n * }\n *\n * This function supports moving an individual preference like 'panels' above into the\n * preferences package data structure.\n *\n * It supports moving a preference to a particular scope in the preferences store and\n * optionally converting the data using a `convert` function.\n *\n * ```\n *\n * @param state The original state.\n * @param migrate An options object that contains details of the migration.\n * @param migrate.from The name of the store to migrate from.\n * @param migrate.to The scope in the preferences store to migrate to.\n * @param key The key in the preferences object to migrate.\n * @param convert A function that converts preferences from one format to another.\n */\nexport default function moveIndividualPreferenceToPreferences(\n\tstate: LegacyData,\n\t{ from: sourceStoreName, to: scope }: { from: string; to: string },\n\tkey: string,\n\tconvert: ( preferences: ScopePreferences ) => object = identity\n): LegacyData {\n\tconst preferencesStoreName = 'core/preferences';\n\tconst sourcePreference = state?.[ sourceStoreName ]?.preferences?.[ key ];\n\n\t// There's nothing to migrate, exit early.\n\tif ( sourcePreference === undefined ) {\n\t\treturn state;\n\t}\n\n\tconst targetPreference =\n\t\tstate?.[ preferencesStoreName ]?.preferences?.[ scope ]?.[ key ];\n\n\t// There's existing data at the target, so don't overwrite it, exit early.\n\tif ( targetPreference ) {\n\t\treturn state;\n\t}\n\n\tconst otherScopes = state?.[ preferencesStoreName ]?.preferences;\n\tconst otherPreferences =\n\t\tstate?.[ preferencesStoreName ]?.preferences?.[ scope ];\n\n\tconst otherSourceState = state?.[ sourceStoreName ];\n\tconst allSourcePreferences = state?.[ sourceStoreName ]?.preferences;\n\n\t// Pass an object with the key and value as this allows the convert\n\t// function to convert to a data structure that has different keys.\n\tconst convertedPreferences = convert( { [ key ]: sourcePreference } );\n\n\treturn {\n\t\t...state,\n\t\t[ preferencesStoreName ]: {\n\t\t\tpreferences: {\n\t\t\t\t...otherScopes,\n\t\t\t\t[ scope ]: {\n\t\t\t\t\t...otherPreferences,\n\t\t\t\t\t...convertedPreferences,\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t\t[ sourceStoreName ]: {\n\t\t\t...otherSourceState,\n\t\t\tpreferences: {\n\t\t\t\t...allSourcePreferences,\n\t\t\t\t[ key ]: undefined,\n\t\t\t},\n\t\t},\n\t};\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,IAAM,WAAW,CAAO,QAAY;AAqCrB,SAAR,sCACN,OACA,EAAE,MAAM,iBAAiB,IAAI,MAAM,GACnC,KACA,UAAuD,UAC1C;AACb,QAAM,uBAAuB;AAC7B,QAAM,mBAAmB,QAAS,eAAgB,GAAG,cAAe,GAAI;AAGxE,MAAK,qBAAqB,QAAY;AACrC,WAAO;AAAA,EACR;AAEA,QAAM,mBACL,QAAS,oBAAqB,GAAG,cAAe,KAAM,IAAK,GAAI;AAGhE,MAAK,kBAAmB;AACvB,WAAO;AAAA,EACR;AAEA,QAAM,cAAc,QAAS,oBAAqB,GAAG;AACrD,QAAM,mBACL,QAAS,oBAAqB,GAAG,cAAe,KAAM;AAEvD,QAAM,mBAAmB,QAAS,eAAgB;AAClD,QAAM,uBAAuB,QAAS,eAAgB,GAAG;AAIzD,QAAM,uBAAuB,QAAS,EAAE,CAAE,GAAI,GAAG,iBAAiB,CAAE;AAEpE,SAAO;AAAA,IACN,GAAG;AAAA,IACH,CAAE,oBAAqB,GAAG;AAAA,MACzB,aAAa;AAAA,QACZ,GAAG;AAAA,QACH,CAAE,KAAM,GAAG;AAAA,UACV,GAAG;AAAA,UACH,GAAG;AAAA,QACJ;AAAA,MACD;AAAA,IACD;AAAA,IACA,CAAE,eAAgB,GAAG;AAAA,MACpB,GAAG;AAAA,MACH,aAAa;AAAA,QACZ,GAAG;AAAA,QACH,CAAE,GAAI,GAAG;AAAA,MACV;AAAA,IACD;AAAA,EACD;AACD;",
6
6
  "names": []
7
7
  }