@wordpress/preferences-persistence 3.0.0 → 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (82) hide show
  1. package/build/create/debounce-async.cjs +54 -58
  2. package/build/create/debounce-async.cjs.map +1 -7
  3. package/build/create/index.cjs +73 -79
  4. package/build/create/index.cjs.map +1 -7
  5. package/build/get-newest-data.cjs +50 -39
  6. package/build/get-newest-data.cjs.map +1 -7
  7. package/build/index.cjs +50 -43
  8. package/build/index.cjs.map +1 -7
  9. package/build/is-preferences-data.cjs +16 -25
  10. package/build/is-preferences-data.cjs.map +1 -7
  11. package/build/local-storage.cjs +33 -40
  12. package/build/local-storage.cjs.map +1 -7
  13. package/build/migrations/legacy-local-storage-data/convert-edit-post-panels.cjs +48 -38
  14. package/build/migrations/legacy-local-storage-data/convert-edit-post-panels.cjs.map +1 -7
  15. package/build/migrations/legacy-local-storage-data/index.cjs +93 -83
  16. package/build/migrations/legacy-local-storage-data/index.cjs.map +1 -7
  17. package/build/migrations/legacy-local-storage-data/move-feature-preferences.cjs +105 -77
  18. package/build/migrations/legacy-local-storage-data/move-feature-preferences.cjs.map +1 -7
  19. package/build/migrations/legacy-local-storage-data/move-individual-preference.cjs +69 -58
  20. package/build/migrations/legacy-local-storage-data/move-individual-preference.cjs.map +1 -7
  21. package/build/migrations/legacy-local-storage-data/move-interface-enable-items.cjs +92 -75
  22. package/build/migrations/legacy-local-storage-data/move-interface-enable-items.cjs.map +1 -7
  23. package/build/migrations/legacy-local-storage-data/move-third-party-feature-preferences.cjs +76 -65
  24. package/build/migrations/legacy-local-storage-data/move-third-party-feature-preferences.cjs.map +1 -7
  25. package/build/migrations/legacy-local-storage-data/types.cjs +4 -18
  26. package/build/migrations/preferences-package-data/convert-complementary-areas.cjs +18 -38
  27. package/build/migrations/preferences-package-data/convert-complementary-areas.cjs.map +1 -7
  28. package/build/migrations/preferences-package-data/convert-editor-settings.cjs +58 -72
  29. package/build/migrations/preferences-package-data/convert-editor-settings.cjs.map +1 -7
  30. package/build/migrations/preferences-package-data/index.cjs +27 -31
  31. package/build/migrations/preferences-package-data/index.cjs.map +1 -7
  32. package/build/types.cjs +4 -18
  33. package/build-module/create/debounce-async.mjs +50 -38
  34. package/build-module/create/debounce-async.mjs.map +1 -7
  35. package/build-module/create/index.mjs +48 -53
  36. package/build-module/create/index.mjs.map +1 -7
  37. package/build-module/get-newest-data.mjs +29 -15
  38. package/build-module/get-newest-data.mjs.map +1 -7
  39. package/build-module/index.mjs +23 -15
  40. package/build-module/index.mjs.map +1 -7
  41. package/build-module/is-preferences-data.mjs +12 -5
  42. package/build-module/is-preferences-data.mjs.map +1 -7
  43. package/build-module/local-storage.mjs +28 -15
  44. package/build-module/local-storage.mjs.map +1 -7
  45. package/build-module/migrations/legacy-local-storage-data/convert-edit-post-panels.mjs +44 -18
  46. package/build-module/migrations/legacy-local-storage-data/convert-edit-post-panels.mjs.map +1 -7
  47. package/build-module/migrations/legacy-local-storage-data/index.mjs +63 -51
  48. package/build-module/migrations/legacy-local-storage-data/index.mjs.map +1 -7
  49. package/build-module/migrations/legacy-local-storage-data/move-feature-preferences.mjs +101 -57
  50. package/build-module/migrations/legacy-local-storage-data/move-feature-preferences.mjs.map +1 -7
  51. package/build-module/migrations/legacy-local-storage-data/move-individual-preference.mjs +65 -38
  52. package/build-module/migrations/legacy-local-storage-data/move-individual-preference.mjs.map +1 -7
  53. package/build-module/migrations/legacy-local-storage-data/move-interface-enable-items.mjs +88 -55
  54. package/build-module/migrations/legacy-local-storage-data/move-interface-enable-items.mjs.map +1 -7
  55. package/build-module/migrations/legacy-local-storage-data/move-third-party-feature-preferences.mjs +72 -45
  56. package/build-module/migrations/legacy-local-storage-data/move-third-party-feature-preferences.mjs.map +1 -7
  57. package/build-module/migrations/legacy-local-storage-data/types.mjs +0 -1
  58. package/build-module/migrations/preferences-package-data/convert-complementary-areas.mjs +14 -18
  59. package/build-module/migrations/preferences-package-data/convert-complementary-areas.mjs.map +1 -7
  60. package/build-module/migrations/preferences-package-data/convert-editor-settings.mjs +40 -50
  61. package/build-module/migrations/preferences-package-data/convert-editor-settings.mjs.map +1 -7
  62. package/build-module/migrations/preferences-package-data/index.mjs +7 -8
  63. package/build-module/migrations/preferences-package-data/index.mjs.map +1 -7
  64. package/build-module/types.mjs +0 -1
  65. package/package.json +5 -4
  66. package/src/create/test/{debounce-async.js → debounce-async.ts} +7 -3
  67. package/src/create/test/{index.jsdom.test.js → index.jsdom.test.ts} +8 -5
  68. package/src/migrations/legacy-local-storage-data/test/{index.js → index.ts} +6 -1
  69. package/src/migrations/preferences-package-data/test/{convert-editor-settings.js → convert-editor-settings.ts} +3 -0
  70. package/src/test/{index.jsdom.test.js → index.jsdom.test.ts} +6 -4
  71. package/build/migrations/legacy-local-storage-data/types.cjs.map +0 -7
  72. package/build/types.cjs.map +0 -7
  73. package/build-module/migrations/legacy-local-storage-data/types.mjs.map +0 -7
  74. package/build-module/types.mjs.map +0 -7
  75. /package/src/migrations/legacy-local-storage-data/test/{convert-edit-post-panels.js → convert-edit-post-panels.ts} +0 -0
  76. /package/src/migrations/legacy-local-storage-data/test/{move-feature-preferences.js → move-feature-preferences.ts} +0 -0
  77. /package/src/migrations/legacy-local-storage-data/test/{move-individual-preference.js → move-individual-preference.ts} +0 -0
  78. /package/src/migrations/legacy-local-storage-data/test/{move-interface-enable-items.js → move-interface-enable-items.ts} +0 -0
  79. /package/src/migrations/legacy-local-storage-data/test/{move-third-party-feature-preferences.js → move-third-party-feature-preferences.ts} +0 -0
  80. /package/src/migrations/preferences-package-data/test/{convert-complementary-areas.js → convert-complementary-areas.ts} +0 -0
  81. /package/src/migrations/preferences-package-data/test/{index.js → index.ts} +0 -0
  82. /package/src/test/{local-storage.jsdom.test.js → local-storage.jsdom.test.ts} +0 -0
@@ -1,62 +1,58 @@
1
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/create/debounce-async.ts
21
- var debounce_async_exports = {};
22
- __export(debounce_async_exports, {
23
- default: () => debounceAsync
2
+ Object.defineProperties(exports, {
3
+ __esModule: { value: true },
4
+ [Symbol.toStringTag]: { value: "Module" }
24
5
  });
25
- module.exports = __toCommonJS(debounce_async_exports);
6
+ // packages/preferences-persistence/src/create/debounce-async.ts
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 func A function that returns a promise.
19
+ * @param delayMS A delay in milliseconds.
20
+ *
21
+ * @return A function that debounce whatever function is passed
22
+ * to it.
23
+ */
26
24
  function debounceAsync(func, delayMS) {
27
- let timeoutId;
28
- let activePromise;
29
- return async function debounced(...args) {
30
- if (!activePromise && !timeoutId) {
31
- return new Promise((resolve, reject) => {
32
- activePromise = func(...args).then((...thenArgs) => {
33
- resolve(...thenArgs);
34
- }).catch((error) => {
35
- reject(error);
36
- }).finally(() => {
37
- activePromise = null;
38
- });
39
- });
40
- }
41
- if (activePromise) {
42
- await activePromise;
43
- }
44
- if (timeoutId) {
45
- clearTimeout(timeoutId);
46
- timeoutId = null;
47
- }
48
- return new Promise((resolve, reject) => {
49
- timeoutId = setTimeout(() => {
50
- activePromise = func(...args).then((...thenArgs) => {
51
- resolve(...thenArgs);
52
- }).catch((error) => {
53
- reject(error);
54
- }).finally(() => {
55
- activePromise = null;
56
- timeoutId = null;
57
- });
58
- }, delayMS);
59
- });
60
- };
25
+ let timeoutId;
26
+ let activePromise;
27
+ return async function debounced(...args) {
28
+ if (!activePromise && !timeoutId) return new Promise((resolve, reject) => {
29
+ activePromise = func(...args).then((...thenArgs) => {
30
+ resolve(...thenArgs);
31
+ }).catch((error) => {
32
+ reject(error);
33
+ }).finally(() => {
34
+ activePromise = null;
35
+ });
36
+ });
37
+ if (activePromise) await activePromise;
38
+ if (timeoutId) {
39
+ clearTimeout(timeoutId);
40
+ timeoutId = null;
41
+ }
42
+ return new Promise((resolve, reject) => {
43
+ timeoutId = setTimeout(() => {
44
+ activePromise = func(...args).then((...thenArgs) => {
45
+ resolve(...thenArgs);
46
+ }).catch((error) => {
47
+ reject(error);
48
+ }).finally(() => {
49
+ activePromise = null;
50
+ timeoutId = null;
51
+ });
52
+ }, delayMS);
53
+ });
54
+ };
61
55
  }
62
- //# sourceMappingURL=debounce-async.cjs.map
56
+ exports.default = debounceAsync;
57
+
58
+ //# sourceMappingURL=debounce-async.cjs.map
@@ -1,7 +1 @@
1
- {
2
- "version": 3,
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
- "names": []
7
- }
1
+ {"version":3,"file":"debounce-async.cjs","names":[],"sources":["../../src/create/debounce-async.ts"],"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"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAiBA,SAAwB,cACvB,MACA,SACyC;CACzC,IAAI;CACJ,IAAI;CAEJ,OAAO,eAAe,UAAW,GAAG,MAAa;EAGhD,IAAK,CAAE,iBAAiB,CAAE,WACzB,OAAO,IAAI,SAAqB,SAAS,WAAY;GAEpD,gBAAgB,KAAM,GAAG,IAAK,CAAC,CAC7B,MAAQ,GAAG,aAAc;IACzB,QAAS,GAAG,QAAS;GACtB,CAAE,CAAC,CACF,OAAS,UAAW;IACpB,OAAQ,KAAM;GACf,CAAE,CAAC,CACF,cAAe;IAGf,gBAAgB;GACjB,CAAE;EACJ,CAAE;EAGH,IAAK,eAEJ,MAAM;EAKP,IAAK,WAAY;GAChB,aAAc,SAAU;GACxB,YAAY;EACb;EAGA,OAAO,IAAI,SAAqB,SAAS,WAAY;GAEpD,YAAY,iBAAkB;IAC7B,gBAAgB,KAAM,GAAG,IAAK,CAAC,CAC7B,MAAQ,GAAG,aAAc;KACzB,QAAS,GAAG,QAAS;IACtB,CAAE,CAAC,CACF,OAAS,UAAW;KACpB,OAAQ,KAAM;IACf,CAAE,CAAC,CACF,cAAe;KAGf,gBAAgB;KAChB,YAAY;IACb,CAAE;GACJ,GAAG,OAAQ;EACZ,CAAE;CACH;AACD"}
@@ -1,90 +1,84 @@
1
1
  "use strict";
2
+ Object.defineProperties(exports, {
3
+ __esModule: { value: true },
4
+ [Symbol.toStringTag]: { value: "Module" }
5
+ });
6
+ // \0rolldown/runtime.js
2
7
  var __create = Object.create;
3
8
  var __defProp = Object.defineProperty;
4
9
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
10
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
11
  var __getProtoOf = Object.getPrototypeOf;
7
12
  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
13
  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;
14
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
15
+ key = keys[i];
16
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
17
+ get: ((k) => from[k]).bind(null, key),
18
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
19
+ });
20
+ }
21
+ return to;
19
22
  };
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
-
23
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
24
+ value: mod,
25
+ enumerable: true
26
+ }) : target, mod));
27
+ let _wordpress_api_fetch = require("@wordpress/api-fetch");
28
+ _wordpress_api_fetch = __toESM(_wordpress_api_fetch);
29
+ let __debounce_async_ts = require("./debounce-async.cjs");
30
+ __debounce_async_ts = __toESM(__debounce_async_ts);
31
+ let ___get_newest_data_ts = require("../get-newest-data.cjs");
32
+ ___get_newest_data_ts = __toESM(___get_newest_data_ts);
33
+ let ___is_preferences_data_ts = require("../is-preferences-data.cjs");
34
+ ___is_preferences_data_ts = __toESM(___is_preferences_data_ts);
35
+ let ___local_storage_ts = require("../local-storage.cjs");
30
36
  // packages/preferences-persistence/src/create/index.ts
31
- var create_exports = {};
32
- __export(create_exports, {
33
- default: () => create
34
- });
35
- module.exports = __toCommonJS(create_exports);
36
- var import_api_fetch = __toESM(require("@wordpress/api-fetch"));
37
- var import_debounce_async = __toESM(require("./debounce-async.cjs"));
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");
41
- function create({
42
- preloadedData,
43
- localStorageRestoreKey = "WP_PREFERENCES_RESTORE_DATA",
44
- requestDebounceMS = 2500
45
- } = {}) {
46
- let cache = (0, import_is_preferences_data.default)(preloadedData) ? preloadedData : void 0;
47
- const debouncedApiFetch = (0, import_debounce_async.default)(import_api_fetch.default, requestDebounceMS);
48
- async function get() {
49
- if (cache) {
50
- return cache;
51
- }
52
- const user = await (0, import_api_fetch.default)({
53
- path: "/wp/v2/users/me?context=edit"
54
- });
55
- cache = (0, import_get_newest_data.default)(
56
- user?.meta?.persisted_preferences,
57
- localStorageRestoreKey
58
- ) ?? {};
59
- return cache;
60
- }
61
- function set(newData) {
62
- const dataWithTimestamp = {
63
- ...newData,
64
- _modified: (/* @__PURE__ */ new Date()).toISOString()
65
- };
66
- cache = dataWithTimestamp;
67
- (0, import_local_storage.writeStoredJSON)(localStorageRestoreKey, dataWithTimestamp);
68
- debouncedApiFetch({
69
- path: "/wp/v2/users/me",
70
- method: "PUT",
71
- // `keepalive` will still send the request in the background,
72
- // even when a browser unload event might interrupt it.
73
- // This should hopefully make things more resilient.
74
- // This does have a size limit of 64kb, but the data is usually
75
- // much less.
76
- keepalive: true,
77
- data: {
78
- meta: {
79
- persisted_preferences: dataWithTimestamp
80
- }
81
- }
82
- }).catch(() => {
83
- });
84
- }
85
- return {
86
- get,
87
- set
88
- };
37
+ /**
38
+ * Creates a persistence layer that stores data in WordPress user meta via the
39
+ * REST API.
40
+ *
41
+ * @param {CreateOptions} [options]
42
+ * @param {PreferencesData|null} [options.preloadedData] Any persisted preferences data that should be preloaded.
43
+ * When set, the persistence layer will avoid fetching data
44
+ * from the REST API.
45
+ * @param {string} [options.localStorageRestoreKey] The key to use for restoring the localStorage backup, used
46
+ * when the persistence layer calls `localStorage.getItem` or
47
+ * `localStorage.setItem`.
48
+ * @param {number} [options.requestDebounceMS] Debounce requests to the API so that they only occur at
49
+ * minimum every `requestDebounceMS` milliseconds, and don't
50
+ * swamp the server. Defaults to 2500ms.
51
+ *
52
+ * @return A persistence layer for WordPress user meta.
53
+ */
54
+ function create({ preloadedData, localStorageRestoreKey = "WP_PREFERENCES_RESTORE_DATA", requestDebounceMS = 2500 } = {}) {
55
+ let cache = (0, ___is_preferences_data_ts.default)(preloadedData) ? preloadedData : void 0;
56
+ const debouncedApiFetch = (0, __debounce_async_ts.default)(_wordpress_api_fetch.default, requestDebounceMS);
57
+ async function get() {
58
+ if (cache) return cache;
59
+ const user = await (0, _wordpress_api_fetch.default)({ path: "/wp/v2/users/me?context=edit" });
60
+ cache = (0, ___get_newest_data_ts.default)(user?.meta?.persisted_preferences, localStorageRestoreKey) ?? {};
61
+ return cache;
62
+ }
63
+ function set(newData) {
64
+ const dataWithTimestamp = {
65
+ ...newData,
66
+ _modified: (/* @__PURE__ */ new Date()).toISOString()
67
+ };
68
+ cache = dataWithTimestamp;
69
+ (0, ___local_storage_ts.writeStoredJSON)(localStorageRestoreKey, dataWithTimestamp);
70
+ debouncedApiFetch({
71
+ path: "/wp/v2/users/me",
72
+ method: "PUT",
73
+ keepalive: true,
74
+ data: { meta: { persisted_preferences: dataWithTimestamp } }
75
+ }).catch(() => {});
76
+ }
77
+ return {
78
+ get,
79
+ set
80
+ };
89
81
  }
90
- //# sourceMappingURL=index.cjs.map
82
+ exports.default = create;
83
+
84
+ //# sourceMappingURL=index.cjs.map
@@ -1,7 +1 @@
1
- {
2
- "version": 3,
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
- }
1
+ {"version":3,"file":"index.cjs","names":["isPreferencesData","debounceAsync","apiFetch","getNewestData"],"sources":["../../src/create/index.ts"],"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"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4BA,SAAwB,OAAQ,EAC/B,eACA,yBAAyB,+BACzB,oBAAoB,SACF,CAAC,GAAsB;CACzC,IAAI,SAAA,GAAQA,0BAAAA,QAAAA,CAAmB,aAAc,IAAI,gBAAgB,KAAA;CACjE,MAAM,qBAAA,GAAoBC,oBAAAA,QAAAA,CAAeC,qBAAAA,SAAU,iBAAkB;CAErE,eAAe,MAAM;EACpB,IAAK,OACJ,OAAO;EAGR,MAAM,OAAO,OAAA,GAAMA,qBAAAA,QAAAA,CAEd,EACJ,MAAM,+BACP,CAAE;EAEF,SAAA,GACCC,sBAAAA,QAAAA,CACC,MAAM,MAAM,uBACZ,sBACD,KAAK,CAAC;EAEP,OAAO;CACR;CAEA,SAAS,IAAK,SAA2B;EACxC,MAAM,oBAAoB;GACzB,GAAG;GACH,4BAAW,IAAI,KAAK,EAAA,CAAE,YAAY;EACnC;EACA,QAAQ;EAKR,CAAA,GAAA,oBAAA,gBAAA,CAAiB,wBAAwB,iBAAkB;EAO3D,kBAAmB;GAClB,MAAM;GACN,QAAQ;GAMR,WAAW;GACX,MAAM,EACL,MAAM,EACL,uBAAuB,kBACxB,EACD;EACD,CAAE,CAAC,CAAC,YAAa,CAAC,CAAE;CACrB;CAEA,OAAO;EACN;EACA;CACD;AACD"}
@@ -1,53 +1,64 @@
1
1
  "use strict";
2
+ Object.defineProperties(exports, {
3
+ __esModule: { value: true },
4
+ [Symbol.toStringTag]: { value: "Module" }
5
+ });
6
+ // \0rolldown/runtime.js
2
7
  var __create = Object.create;
3
8
  var __defProp = Object.defineProperty;
4
9
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
10
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
11
  var __getProtoOf = Object.getPrototypeOf;
7
12
  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
13
  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;
14
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
15
+ key = keys[i];
16
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
17
+ get: ((k) => from[k]).bind(null, key),
18
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
19
+ });
20
+ }
21
+ return to;
19
22
  };
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
-
23
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
24
+ value: mod,
25
+ enumerable: true
26
+ }) : target, mod));
27
+ let __is_preferences_data_ts = require("./is-preferences-data.cjs");
28
+ __is_preferences_data_ts = __toESM(__is_preferences_data_ts);
29
+ let __local_storage_ts = require("./local-storage.cjs");
30
+ let __migrations_preferences_package_data_index_ts = require("./migrations/preferences-package-data/index.cjs");
31
+ __migrations_preferences_package_data_index_ts = __toESM(__migrations_preferences_package_data_index_ts);
30
32
  // 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"));
33
+ /**
34
+ * Picks the most recently modified preferences from the server data and the
35
+ * local storage backup, ignoring either when it is not a preferences object.
36
+ *
37
+ * @param serverData Preferences data from the server.
38
+ * @param localStorageRestoreKey The key of the local storage backup.
39
+ *
40
+ * @return The newest preferences data, or `null` when neither is valid.
41
+ */
39
42
  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;
43
+ const storedData = (0, __local_storage_ts.readStoredJSON)(localStorageRestoreKey);
44
+ const localData = (0, __is_preferences_data_ts.default)(storedData) ? storedData : null;
45
+ if (!(0, __is_preferences_data_ts.default)(serverData)) return localData;
46
+ const serverModified = Date.parse(serverData._modified ?? "") || 0;
47
+ const localModified = Date.parse(localData?._modified ?? "") || 0;
48
+ return localData && localModified > serverModified ? localData : serverData;
48
49
  }
50
+ /**
51
+ * Gets the newest persisted preferences, migrated to the current format.
52
+ *
53
+ * @param serverData Preferences data from the server.
54
+ * @param localStorageRestoreKey The key of the local storage backup.
55
+ *
56
+ * @return The migrated preferences, or `undefined` when there are none.
57
+ */
49
58
  function getNewestData(serverData, localStorageRestoreKey) {
50
- const newestData = pickNewestData(serverData, localStorageRestoreKey);
51
- return newestData ? (0, import_preferences_package_data.default)(newestData) : void 0;
59
+ const newestData = pickNewestData(serverData, localStorageRestoreKey);
60
+ return newestData ? (0, __migrations_preferences_package_data_index_ts.default)(newestData) : void 0;
52
61
  }
53
- //# sourceMappingURL=get-newest-data.cjs.map
62
+ exports.default = getNewestData;
63
+
64
+ //# sourceMappingURL=get-newest-data.cjs.map
@@ -1,7 +1 @@
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
- }
1
+ {"version":3,"file":"get-newest-data.cjs","names":["readStoredJSON","isPreferencesData","convertPreferencesPackageData"],"sources":["../src/get-newest-data.ts"],"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"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAcA,SAAS,eACR,YACA,wBACyB;CACzB,MAAM,cAAA,GAAaA,mBAAAA,eAAAA,CAAgB,sBAAuB;CAC1D,MAAM,aAAA,GAAYC,yBAAAA,QAAAA,CAAmB,UAAW,IAAI,aAAa;CACjE,IAAK,EAAA,GAAEA,yBAAAA,QAAAA,CAAmB,UAAW,GACpC,OAAO;CAKR,MAAM,iBAAiB,KAAK,MAAO,WAAW,aAAa,EAAG,KAAK;CACnE,MAAM,gBAAgB,KAAK,MAAO,WAAW,aAAa,EAAG,KAAK;CAGlE,OAAO,aAAa,gBAAgB,iBAAiB,YAAY;AAClE;;;;;;;;;AAUA,SAAwB,cACvB,YACA,wBACgC;CAChC,MAAM,aAAa,eAAgB,YAAY,sBAAuB;CACtE,OAAO,cAAA,GACJC,+CAAAA,QAAAA,CAA+B,UAAgC,IAC/D,KAAA;AACJ"}
package/build/index.cjs CHANGED
@@ -1,56 +1,63 @@
1
1
  "use strict";
2
+ Object.defineProperties(exports, {
3
+ __esModule: { value: true },
4
+ [Symbol.toStringTag]: { value: "Module" }
5
+ });
6
+ // \0rolldown/runtime.js
2
7
  var __create = Object.create;
3
8
  var __defProp = Object.defineProperty;
4
9
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
10
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
11
  var __getProtoOf = Object.getPrototypeOf;
7
12
  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
13
  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;
14
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
15
+ key = keys[i];
16
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
17
+ get: ((k) => from[k]).bind(null, key),
18
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
19
+ });
20
+ }
21
+ return to;
19
22
  };
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
-
23
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
24
+ value: mod,
25
+ enumerable: true
26
+ }) : target, mod));
27
+ let __create_index_ts = require("./create/index.cjs");
28
+ __create_index_ts = __toESM(__create_index_ts);
29
+ let __migrations_legacy_local_storage_data_index_ts = require("./migrations/legacy-local-storage-data/index.cjs");
30
+ __migrations_legacy_local_storage_data_index_ts = __toESM(__migrations_legacy_local_storage_data_index_ts);
31
+ let __get_newest_data_ts = require("./get-newest-data.cjs");
32
+ __get_newest_data_ts = __toESM(__get_newest_data_ts);
30
33
  // packages/preferences-persistence/src/index.ts
31
- var index_exports = {};
32
- __export(index_exports, {
33
- __unstableCreatePersistenceLayer: () => __unstableCreatePersistenceLayer,
34
- create: () => import_create.default
35
- });
36
- module.exports = __toCommonJS(index_exports);
37
- var import_create = __toESM(require("./create/index.cjs"));
38
- var import_legacy_local_storage_data = __toESM(require("./migrations/legacy-local-storage-data/index.cjs"));
39
- var import_get_newest_data = __toESM(require("./get-newest-data.cjs"));
34
+ /**
35
+ * Creates the persistence layer with preloaded data.
36
+ *
37
+ * It prioritizes any data from the server, but falls back first to localStorage
38
+ * restore data, and then to any legacy data.
39
+ *
40
+ * This function is used internally by WordPress in an inline script, so
41
+ * prefixed with `__unstable`.
42
+ *
43
+ * @param serverData Preferences data preloaded from the server.
44
+ * @param userId The user id.
45
+ *
46
+ * @return The persistence layer initialized with the preloaded data.
47
+ */
40
48
  function __unstableCreatePersistenceLayer(serverData, userId) {
41
- const localStorageRestoreKey = `WP_PREFERENCES_USER_${userId}`;
42
- return (0, import_create.default)({
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) ?? {},
48
- localStorageRestoreKey
49
- });
49
+ const localStorageRestoreKey = `WP_PREFERENCES_USER_${userId}`;
50
+ return (0, __create_index_ts.default)({
51
+ preloadedData: (0, __get_newest_data_ts.default)(serverData, localStorageRestoreKey) ?? (0, __migrations_legacy_local_storage_data_index_ts.default)(userId) ?? {},
52
+ localStorageRestoreKey
53
+ });
50
54
  }
51
- // Annotate the CommonJS export names for ESM import in node:
52
- 0 && (module.exports = {
53
- __unstableCreatePersistenceLayer,
54
- create
55
+ exports.__unstableCreatePersistenceLayer = __unstableCreatePersistenceLayer;
56
+ Object.defineProperty(exports, "create", {
57
+ enumerable: true,
58
+ get: function() {
59
+ return __create_index_ts.default;
60
+ }
55
61
  });
56
- //# sourceMappingURL=index.cjs.map
62
+
63
+ //# sourceMappingURL=index.cjs.map
@@ -1,7 +1 @@
1
- {
2
- "version": 3,
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
- }
1
+ {"version":3,"file":"index.cjs","names":["create","getNewestData","convertLegacyLocalStorageData"],"sources":["../src/index.ts"],"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"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuBA,SAAgB,iCACf,YACA,QACmB;CACnB,MAAM,yBAAyB,uBAAwB;CACvD,QAAA,GAAOA,kBAAAA,QAAAA,CAAQ;EAKd,gBAAA,GACCC,qBAAAA,QAAAA,CAAe,YAAY,sBAAuB,MAAA,GAClDC,gDAAAA,QAAAA,CAA+B,MAAO,KACtC,CAAC;EACF;CACD,CAAE;AACH"}