@wordpress/preferences-persistence 2.32.0 → 2.32.1-next.ff1cebbba.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 (49) hide show
  1. package/build/create/debounce-async.js +24 -39
  2. package/build/create/debounce-async.js.map +7 -1
  3. package/build/create/index.js +50 -61
  4. package/build/create/index.js.map +7 -1
  5. package/build/index.js +47 -42
  6. package/build/index.js.map +7 -1
  7. package/build/migrations/legacy-local-storage-data/convert-edit-post-panels.js +36 -52
  8. package/build/migrations/legacy-local-storage-data/convert-edit-post-panels.js.map +7 -1
  9. package/build/migrations/legacy-local-storage-data/index.js +80 -89
  10. package/build/migrations/legacy-local-storage-data/index.js.map +7 -1
  11. package/build/migrations/legacy-local-storage-data/move-feature-preferences.js +26 -78
  12. package/build/migrations/legacy-local-storage-data/move-feature-preferences.js.map +7 -1
  13. package/build/migrations/legacy-local-storage-data/move-individual-preference.js +28 -60
  14. package/build/migrations/legacy-local-storage-data/move-individual-preference.js.map +7 -1
  15. package/build/migrations/legacy-local-storage-data/move-interface-enable-items.js +46 -85
  16. package/build/migrations/legacy-local-storage-data/move-interface-enable-items.js.map +7 -1
  17. package/build/migrations/legacy-local-storage-data/move-third-party-feature-preferences.js +27 -52
  18. package/build/migrations/legacy-local-storage-data/move-third-party-feature-preferences.js.map +7 -1
  19. package/build/migrations/preferences-package-data/convert-complementary-areas.js +23 -11
  20. package/build/migrations/preferences-package-data/convert-complementary-areas.js.map +7 -1
  21. package/build/migrations/preferences-package-data/convert-editor-settings.js +50 -22
  22. package/build/migrations/preferences-package-data/convert-editor-settings.js.map +7 -1
  23. package/build/migrations/preferences-package-data/index.js +36 -15
  24. package/build/migrations/preferences-package-data/index.js.map +7 -1
  25. package/build-module/create/debounce-async.js +7 -35
  26. package/build-module/create/debounce-async.js.map +7 -1
  27. package/build-module/create/index.js +21 -53
  28. package/build-module/create/index.js.map +7 -1
  29. package/build-module/index.js +12 -29
  30. package/build-module/index.js.map +7 -1
  31. package/build-module/migrations/legacy-local-storage-data/convert-edit-post-panels.js +19 -48
  32. package/build-module/migrations/legacy-local-storage-data/convert-edit-post-panels.js.map +7 -1
  33. package/build-module/migrations/legacy-local-storage-data/index.js +48 -82
  34. package/build-module/migrations/legacy-local-storage-data/index.js.map +7 -1
  35. package/build-module/migrations/legacy-local-storage-data/move-feature-preferences.js +9 -74
  36. package/build-module/migrations/legacy-local-storage-data/move-feature-preferences.js.map +7 -1
  37. package/build-module/migrations/legacy-local-storage-data/move-individual-preference.js +10 -55
  38. package/build-module/migrations/legacy-local-storage-data/move-individual-preference.js.map +7 -1
  39. package/build-module/migrations/legacy-local-storage-data/move-interface-enable-items.js +29 -81
  40. package/build-module/migrations/legacy-local-storage-data/move-interface-enable-items.js.map +7 -1
  41. package/build-module/migrations/legacy-local-storage-data/move-third-party-feature-preferences.js +10 -48
  42. package/build-module/migrations/legacy-local-storage-data/move-third-party-feature-preferences.js.map +7 -1
  43. package/build-module/migrations/preferences-package-data/convert-complementary-areas.js +6 -7
  44. package/build-module/migrations/preferences-package-data/convert-complementary-areas.js.map +7 -1
  45. package/build-module/migrations/preferences-package-data/convert-editor-settings.js +33 -18
  46. package/build-module/migrations/preferences-package-data/convert-editor-settings.js.map +7 -1
  47. package/build-module/migrations/preferences-package-data/index.js +7 -7
  48. package/build-module/migrations/preferences-package-data/index.js.map +7 -1
  49. package/package.json +11 -4
@@ -1,69 +1,54 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var debounce_async_exports = {};
19
+ __export(debounce_async_exports, {
20
+ default: () => debounceAsync
5
21
  });
6
- exports.default = debounceAsync;
7
- /**
8
- * Performs a leading edge debounce of async functions.
9
- *
10
- * If three functions are throttled at the same time:
11
- * - The first happens immediately.
12
- * - The second is never called.
13
- * - The third happens `delayMS` milliseconds after the first has resolved.
14
- *
15
- * This is distinct from `{ debounce } from @wordpress/compose` in that it
16
- * waits for promise resolution.
17
- *
18
- * @param {Function} func A function that returns a promise.
19
- * @param {number} delayMS A delay in milliseconds.
20
- *
21
- * @return {Function} A function that debounce whatever function is passed
22
- * to it.
23
- */
22
+ module.exports = __toCommonJS(debounce_async_exports);
24
23
  function debounceAsync(func, delayMS) {
25
24
  let timeoutId;
26
25
  let activePromise;
27
26
  return async function debounced(...args) {
28
- // This is a leading edge debounce. If there's no promise or timeout
29
- // in progress, call the debounced function immediately.
30
27
  if (!activePromise && !timeoutId) {
31
28
  return new Promise((resolve, reject) => {
32
- // Keep a reference to the promise.
33
29
  activePromise = func(...args).then((...thenArgs) => {
34
30
  resolve(...thenArgs);
35
- }).catch(error => {
31
+ }).catch((error) => {
36
32
  reject(error);
37
33
  }).finally(() => {
38
- // As soon this promise is complete, clear the way for the
39
- // next one to happen immediately.
40
34
  activePromise = null;
41
35
  });
42
36
  });
43
37
  }
44
38
  if (activePromise) {
45
- // Let any active promises finish before queuing the next request.
46
39
  await activePromise;
47
40
  }
48
-
49
- // Clear any active timeouts, abandoning any requests that have
50
- // been queued but not been made.
51
41
  if (timeoutId) {
52
42
  clearTimeout(timeoutId);
53
43
  timeoutId = null;
54
44
  }
55
-
56
- // Trigger any trailing edge calls to the function.
57
45
  return new Promise((resolve, reject) => {
58
- // Schedule the next request but with a delay.
59
46
  timeoutId = setTimeout(() => {
60
47
  activePromise = func(...args).then((...thenArgs) => {
61
48
  resolve(...thenArgs);
62
- }).catch(error => {
49
+ }).catch((error) => {
63
50
  reject(error);
64
51
  }).finally(() => {
65
- // As soon this promise is complete, clear the way for the
66
- // next one to happen immediately.
67
52
  activePromise = null;
68
53
  timeoutId = null;
69
54
  });
@@ -71,4 +56,4 @@ function debounceAsync(func, delayMS) {
71
56
  });
72
57
  };
73
58
  }
74
- //# sourceMappingURL=debounce-async.js.map
59
+ //# sourceMappingURL=debounce-async.js.map
@@ -1 +1,7 @@
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","ignoreList":[]}
1
+ {
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;",
6
+ "names": []
7
+ }
@@ -1,64 +1,59 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+ var create_exports = {};
29
+ __export(create_exports, {
30
+ default: () => create
6
31
  });
7
- exports.default = create;
8
- var _apiFetch = _interopRequireDefault(require("@wordpress/api-fetch"));
9
- var _debounceAsync = _interopRequireDefault(require("./debounce-async"));
10
- /**
11
- * WordPress dependencies
12
- */
13
-
14
- /**
15
- * Internal dependencies
16
- */
17
-
32
+ module.exports = __toCommonJS(create_exports);
33
+ var import_api_fetch = __toESM(require("@wordpress/api-fetch"));
34
+ var import_debounce_async = __toESM(require("./debounce-async"));
18
35
  const EMPTY_OBJECT = {};
19
36
  const localStorage = window.localStorage;
20
-
21
- /**
22
- * Creates a persistence layer that stores data in WordPress user meta via the
23
- * REST API.
24
- *
25
- * @param {Object} options
26
- * @param {?Object} options.preloadedData Any persisted preferences data that should be preloaded.
27
- * When set, the persistence layer will avoid fetching data
28
- * from the REST API.
29
- * @param {?string} options.localStorageRestoreKey The key to use for restoring the localStorage backup, used
30
- * when the persistence layer calls `localStorage.getItem` or
31
- * `localStorage.setItem`.
32
- * @param {?number} options.requestDebounceMS Debounce requests to the API so that they only occur at
33
- * minimum every `requestDebounceMS` milliseconds, and don't
34
- * swamp the server. Defaults to 2500ms.
35
- *
36
- * @return {Object} A persistence layer for WordPress user meta.
37
- */
38
37
  function create({
39
38
  preloadedData,
40
- localStorageRestoreKey = 'WP_PREFERENCES_RESTORE_DATA',
39
+ localStorageRestoreKey = "WP_PREFERENCES_RESTORE_DATA",
41
40
  requestDebounceMS = 2500
42
41
  } = {}) {
43
42
  let cache = preloadedData;
44
- const debouncedApiFetch = (0, _debounceAsync.default)(_apiFetch.default, requestDebounceMS);
43
+ const debouncedApiFetch = (0, import_debounce_async.default)(import_api_fetch.default, requestDebounceMS);
45
44
  async function get() {
46
45
  if (cache) {
47
46
  return cache;
48
47
  }
49
- const user = await (0, _apiFetch.default)({
50
- path: '/wp/v2/users/me?context=edit'
48
+ const user = await (0, import_api_fetch.default)({
49
+ path: "/wp/v2/users/me?context=edit"
51
50
  });
52
51
  const serverData = user?.meta?.persisted_preferences;
53
- const localData = JSON.parse(localStorage.getItem(localStorageRestoreKey));
54
-
55
- // Date parse returns NaN for invalid input. Coerce anything invalid
56
- // into a conveniently comparable zero.
52
+ const localData = JSON.parse(
53
+ localStorage.getItem(localStorageRestoreKey)
54
+ );
57
55
  const serverTimestamp = Date.parse(serverData?._modified) || 0;
58
56
  const localTimestamp = Date.parse(localData?._modified) || 0;
59
-
60
- // Prefer server data if it exists and is more recent.
61
- // Otherwise fallback to localStorage data.
62
57
  if (serverData && serverTimestamp >= localTimestamp) {
63
58
  cache = serverData;
64
59
  } else if (localData) {
@@ -71,23 +66,16 @@ function create({
71
66
  function set(newData) {
72
67
  const dataWithTimestamp = {
73
68
  ...newData,
74
- _modified: new Date().toISOString()
69
+ _modified: (/* @__PURE__ */ new Date()).toISOString()
75
70
  };
76
71
  cache = dataWithTimestamp;
77
-
78
- // Store data in local storage as a fallback. If for some reason the
79
- // api request does not complete or becomes unavailable, this data
80
- // can be used to restore preferences.
81
- localStorage.setItem(localStorageRestoreKey, JSON.stringify(dataWithTimestamp));
82
-
83
- // The user meta endpoint seems susceptible to errors when consecutive
84
- // requests are made in quick succession. Ensure there's a gap between
85
- // any consecutive requests.
86
- //
87
- // Catch and do nothing with errors from the REST API.
72
+ localStorage.setItem(
73
+ localStorageRestoreKey,
74
+ JSON.stringify(dataWithTimestamp)
75
+ );
88
76
  debouncedApiFetch({
89
- path: '/wp/v2/users/me',
90
- method: 'PUT',
77
+ path: "/wp/v2/users/me",
78
+ method: "PUT",
91
79
  // `keepalive` will still send the request in the background,
92
80
  // even when a browser unload event might interrupt it.
93
81
  // This should hopefully make things more resilient.
@@ -99,11 +87,12 @@ function create({
99
87
  persisted_preferences: dataWithTimestamp
100
88
  }
101
89
  }
102
- }).catch(() => {});
90
+ }).catch(() => {
91
+ });
103
92
  }
104
93
  return {
105
94
  get,
106
95
  set
107
96
  };
108
97
  }
109
- //# sourceMappingURL=index.js.map
98
+ //# sourceMappingURL=index.js.map
@@ -1 +1,7 @@
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","ignoreList":[]}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/create/index.js"],
4
+ "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"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,uBAAqB;AAKrB,4BAA0B;AAE1B,MAAM,eAAe,CAAC;AACtB,MAAM,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"]
7
+ }
package/build/index.js CHANGED
@@ -1,57 +1,62 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.__unstableCreatePersistenceLayer = __unstableCreatePersistenceLayer;
8
- Object.defineProperty(exports, "create", {
9
- enumerable: true,
10
- get: function () {
11
- return _create.default;
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
12
16
  }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+ var index_exports = {};
29
+ __export(index_exports, {
30
+ __unstableCreatePersistenceLayer: () => __unstableCreatePersistenceLayer,
31
+ create: () => import_create.default
13
32
  });
14
- var _create = _interopRequireDefault(require("./create"));
15
- var _legacyLocalStorageData = _interopRequireDefault(require("./migrations/legacy-local-storage-data"));
16
- var _preferencesPackageData = _interopRequireDefault(require("./migrations/preferences-package-data"));
17
- /**
18
- * Internal dependencies
19
- */
20
-
21
- /**
22
- * Creates the persistence layer with preloaded data.
23
- *
24
- * It prioritizes any data from the server, but falls back first to localStorage
25
- * restore data, and then to any legacy data.
26
- *
27
- * This function is used internally by WordPress in an inline script, so
28
- * prefixed with `__unstable`.
29
- *
30
- * @param {Object} serverData Preferences data preloaded from the server.
31
- * @param {string} userId The user id.
32
- *
33
- * @return {Object} The persistence layer initialized with the preloaded data.
34
- */
33
+ module.exports = __toCommonJS(index_exports);
34
+ var import_create = __toESM(require("./create"));
35
+ var import_legacy_local_storage_data = __toESM(require("./migrations/legacy-local-storage-data"));
36
+ var import_preferences_package_data = __toESM(require("./migrations/preferences-package-data"));
35
37
  function __unstableCreatePersistenceLayer(serverData, userId) {
36
38
  const localStorageRestoreKey = `WP_PREFERENCES_USER_${userId}`;
37
- const localData = JSON.parse(window.localStorage.getItem(localStorageRestoreKey));
38
-
39
- // Date parse returns NaN for invalid input. Coerce anything invalid
40
- // into a conveniently comparable zero.
39
+ const localData = JSON.parse(
40
+ window.localStorage.getItem(localStorageRestoreKey)
41
+ );
41
42
  const serverModified = Date.parse(serverData && serverData._modified) || 0;
42
43
  const localModified = Date.parse(localData && localData._modified) || 0;
43
44
  let preloadedData;
44
45
  if (serverData && serverModified >= localModified) {
45
- preloadedData = (0, _preferencesPackageData.default)(serverData);
46
+ preloadedData = (0, import_preferences_package_data.default)(serverData);
46
47
  } else if (localData) {
47
- preloadedData = (0, _preferencesPackageData.default)(localData);
48
+ preloadedData = (0, import_preferences_package_data.default)(localData);
48
49
  } else {
49
- // Check if there is data in the legacy format from the old persistence system.
50
- preloadedData = (0, _legacyLocalStorageData.default)(userId);
50
+ preloadedData = (0, import_legacy_local_storage_data.default)(userId);
51
51
  }
52
- return (0, _create.default)({
52
+ return (0, import_create.default)({
53
53
  preloadedData,
54
54
  localStorageRestoreKey
55
55
  });
56
56
  }
57
- //# sourceMappingURL=index.js.map
57
+ // Annotate the CommonJS export names for ESM import in node:
58
+ 0 && (module.exports = {
59
+ __unstableCreatePersistenceLayer,
60
+ create
61
+ });
62
+ //# sourceMappingURL=index.js.map
@@ -1 +1,7 @@
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,GAAG,uBAAwBD,MAAM,EAAG;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","ignoreList":[]}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/index.js"],
4
+ "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"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA,8BAAAA;AAAA;AAAA;AAGA,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,cAAAF,SAAQ;AAAA,IACd;AAAA,IACA;AAAA,EACD,CAAE;AACH;",
6
+ "names": ["create", "convertPreferencesPackageData", "convertLegacyLocalStorageData"]
7
+ }
@@ -1,55 +1,39 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var convert_edit_post_panels_exports = {};
19
+ __export(convert_edit_post_panels_exports, {
20
+ default: () => convertEditPostPanels
5
21
  });
6
- exports.default = convertEditPostPanels;
7
- /**
8
- * Convert the post editor's panels state from:
9
- * ```
10
- * {
11
- * panels: {
12
- * tags: {
13
- * enabled: true,
14
- * opened: true,
15
- * },
16
- * permalinks: {
17
- * enabled: false,
18
- * opened: false,
19
- * },
20
- * },
21
- * }
22
- * ```
23
- *
24
- * to a new, more concise data structure:
25
- * {
26
- * inactivePanels: [
27
- * 'permalinks',
28
- * ],
29
- * openPanels: [
30
- * 'tags',
31
- * ],
32
- * }
33
- *
34
- * @param {Object} preferences A preferences object.
35
- *
36
- * @return {Object} The converted data.
37
- */
22
+ module.exports = __toCommonJS(convert_edit_post_panels_exports);
38
23
  function convertEditPostPanels(preferences) {
39
- var _preferences$panels;
40
- const panels = (_preferences$panels = preferences?.panels) !== null && _preferences$panels !== void 0 ? _preferences$panels : {};
41
- return Object.keys(panels).reduce((convertedData, panelName) => {
42
- const panel = panels[panelName];
43
- if (panel?.enabled === false) {
44
- convertedData.inactivePanels.push(panelName);
45
- }
46
- if (panel?.opened === true) {
47
- convertedData.openPanels.push(panelName);
48
- }
49
- return convertedData;
50
- }, {
51
- inactivePanels: [],
52
- openPanels: []
53
- });
24
+ const panels = preferences?.panels ?? {};
25
+ return Object.keys(panels).reduce(
26
+ (convertedData, panelName) => {
27
+ const panel = panels[panelName];
28
+ if (panel?.enabled === false) {
29
+ convertedData.inactivePanels.push(panelName);
30
+ }
31
+ if (panel?.opened === true) {
32
+ convertedData.openPanels.push(panelName);
33
+ }
34
+ return convertedData;
35
+ },
36
+ { inactivePanels: [], openPanels: [] }
37
+ );
54
38
  }
55
- //# sourceMappingURL=convert-edit-post-panels.js.map
39
+ //# sourceMappingURL=convert-edit-post-panels.js.map
@@ -1 +1,7 @@
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","ignoreList":[]}
1
+ {
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;",
6
+ "names": []
7
+ }