@wordpress/preferences-persistence 2.57.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 (136) hide show
  1. package/README.md +7 -7
  2. package/build/create/debounce-async.cjs +55 -58
  3. package/build/create/debounce-async.cjs.map +1 -7
  4. package/build/create/index.cjs +75 -91
  5. package/build/create/index.cjs.map +1 -7
  6. package/build/get-newest-data.cjs +64 -0
  7. package/build/get-newest-data.cjs.map +1 -0
  8. package/build/index.cjs +52 -53
  9. package/build/index.cjs.map +1 -7
  10. package/build/is-preferences-data.cjs +20 -0
  11. package/build/is-preferences-data.cjs.map +1 -0
  12. package/build/local-storage.cjs +39 -0
  13. package/build/local-storage.cjs.map +1 -0
  14. package/build/migrations/legacy-local-storage-data/convert-edit-post-panels.cjs +49 -38
  15. package/build/migrations/legacy-local-storage-data/convert-edit-post-panels.cjs.map +1 -7
  16. package/build/migrations/legacy-local-storage-data/index.cjs +95 -83
  17. package/build/migrations/legacy-local-storage-data/index.cjs.map +1 -7
  18. package/build/migrations/legacy-local-storage-data/move-feature-preferences.cjs +106 -77
  19. package/build/migrations/legacy-local-storage-data/move-feature-preferences.cjs.map +1 -7
  20. package/build/migrations/legacy-local-storage-data/move-individual-preference.cjs +70 -58
  21. package/build/migrations/legacy-local-storage-data/move-individual-preference.cjs.map +1 -7
  22. package/build/migrations/legacy-local-storage-data/move-interface-enable-items.cjs +93 -75
  23. package/build/migrations/legacy-local-storage-data/move-interface-enable-items.cjs.map +1 -7
  24. package/build/migrations/legacy-local-storage-data/move-third-party-feature-preferences.cjs +77 -65
  25. package/build/migrations/legacy-local-storage-data/move-third-party-feature-preferences.cjs.map +1 -7
  26. package/build/migrations/legacy-local-storage-data/types.cjs +5 -0
  27. package/build/migrations/preferences-package-data/convert-complementary-areas.cjs +19 -35
  28. package/build/migrations/preferences-package-data/convert-complementary-areas.cjs.map +1 -7
  29. package/build/migrations/preferences-package-data/convert-editor-settings.cjs +62 -60
  30. package/build/migrations/preferences-package-data/convert-editor-settings.cjs.map +1 -7
  31. package/build/migrations/preferences-package-data/index.cjs +29 -32
  32. package/build/migrations/preferences-package-data/index.cjs.map +1 -7
  33. package/build/types.cjs +5 -0
  34. package/build-module/create/debounce-async.mjs +51 -39
  35. package/build-module/create/debounce-async.mjs.map +1 -7
  36. package/build-module/create/index.mjs +51 -67
  37. package/build-module/create/index.mjs.map +1 -7
  38. package/build-module/get-newest-data.mjs +36 -0
  39. package/build-module/get-newest-data.mjs.map +1 -0
  40. package/build-module/index.mjs +24 -25
  41. package/build-module/index.mjs.map +1 -7
  42. package/build-module/is-preferences-data.mjs +15 -0
  43. package/build-module/is-preferences-data.mjs.map +1 -0
  44. package/build-module/local-storage.mjs +33 -0
  45. package/build-module/local-storage.mjs.map +1 -0
  46. package/build-module/migrations/legacy-local-storage-data/convert-edit-post-panels.mjs +45 -19
  47. package/build-module/migrations/legacy-local-storage-data/convert-edit-post-panels.mjs.map +1 -7
  48. package/build-module/migrations/legacy-local-storage-data/index.mjs +65 -52
  49. package/build-module/migrations/legacy-local-storage-data/index.mjs.map +1 -7
  50. package/build-module/migrations/legacy-local-storage-data/move-feature-preferences.mjs +102 -58
  51. package/build-module/migrations/legacy-local-storage-data/move-feature-preferences.mjs.map +1 -7
  52. package/build-module/migrations/legacy-local-storage-data/move-individual-preference.mjs +66 -39
  53. package/build-module/migrations/legacy-local-storage-data/move-individual-preference.mjs.map +1 -7
  54. package/build-module/migrations/legacy-local-storage-data/move-interface-enable-items.mjs +89 -56
  55. package/build-module/migrations/legacy-local-storage-data/move-interface-enable-items.mjs.map +1 -7
  56. package/build-module/migrations/legacy-local-storage-data/move-third-party-feature-preferences.mjs +73 -46
  57. package/build-module/migrations/legacy-local-storage-data/move-third-party-feature-preferences.mjs.map +1 -7
  58. package/build-module/migrations/legacy-local-storage-data/types.mjs +0 -0
  59. package/build-module/migrations/preferences-package-data/convert-complementary-areas.mjs +15 -16
  60. package/build-module/migrations/preferences-package-data/convert-complementary-areas.mjs.map +1 -7
  61. package/build-module/migrations/preferences-package-data/convert-editor-settings.mjs +41 -46
  62. package/build-module/migrations/preferences-package-data/convert-editor-settings.mjs.map +1 -7
  63. package/build-module/migrations/preferences-package-data/index.mjs +7 -8
  64. package/build-module/migrations/preferences-package-data/index.mjs.map +1 -7
  65. package/build-module/types.mjs +0 -0
  66. package/build-types/create/debounce-async.d.ts +19 -0
  67. package/build-types/create/debounce-async.d.ts.map +1 -0
  68. package/build-types/create/index.d.ts +20 -0
  69. package/build-types/create/index.d.ts.map +1 -0
  70. package/build-types/get-newest-data.d.ts +11 -0
  71. package/build-types/get-newest-data.d.ts.map +1 -0
  72. package/build-types/index.d.ts +20 -0
  73. package/build-types/index.d.ts.map +1 -0
  74. package/build-types/is-preferences-data.d.ts +11 -0
  75. package/build-types/is-preferences-data.d.ts.map +1 -0
  76. package/build-types/local-storage.d.ts +19 -0
  77. package/build-types/local-storage.d.ts.map +1 -0
  78. package/build-types/migrations/legacy-local-storage-data/convert-edit-post-panels.d.ts +35 -0
  79. package/build-types/migrations/legacy-local-storage-data/convert-edit-post-panels.d.ts.map +1 -0
  80. package/build-types/migrations/legacy-local-storage-data/index.d.ts +22 -0
  81. package/build-types/migrations/legacy-local-storage-data/index.d.ts.map +1 -0
  82. package/build-types/migrations/legacy-local-storage-data/move-feature-preferences.d.ts +60 -0
  83. package/build-types/migrations/legacy-local-storage-data/move-feature-preferences.d.ts.map +1 -0
  84. package/build-types/migrations/legacy-local-storage-data/move-individual-preference.d.ts +42 -0
  85. package/build-types/migrations/legacy-local-storage-data/move-individual-preference.d.ts.map +1 -0
  86. package/build-types/migrations/legacy-local-storage-data/move-interface-enable-items.d.ts +50 -0
  87. package/build-types/migrations/legacy-local-storage-data/move-interface-enable-items.d.ts.map +1 -0
  88. package/build-types/migrations/legacy-local-storage-data/move-third-party-feature-preferences.d.ts +44 -0
  89. package/build-types/migrations/legacy-local-storage-data/move-third-party-feature-preferences.d.ts.map +1 -0
  90. package/build-types/migrations/legacy-local-storage-data/types.d.ts +60 -0
  91. package/build-types/migrations/legacy-local-storage-data/types.d.ts.map +1 -0
  92. package/build-types/migrations/preferences-package-data/convert-complementary-areas.d.ts +5 -0
  93. package/build-types/migrations/preferences-package-data/convert-complementary-areas.d.ts.map +1 -0
  94. package/build-types/migrations/preferences-package-data/convert-editor-settings.d.ts +5 -0
  95. package/build-types/migrations/preferences-package-data/convert-editor-settings.d.ts.map +1 -0
  96. package/build-types/migrations/preferences-package-data/index.d.ts +5 -0
  97. package/build-types/migrations/preferences-package-data/index.d.ts.map +1 -0
  98. package/build-types/types.d.ts +40 -0
  99. package/build-types/types.d.ts.map +1 -0
  100. package/package.json +8 -7
  101. package/src/create/{debounce-async.js → debounce-async.ts} +13 -10
  102. package/src/create/index.ts +95 -0
  103. package/src/create/test/{debounce-async.js → debounce-async.ts} +7 -3
  104. package/src/create/test/{index.jsdom.test.js → index.jsdom.test.ts} +52 -4
  105. package/src/get-newest-data.ts +50 -0
  106. package/src/index.ts +40 -0
  107. package/src/is-preferences-data.ts +15 -0
  108. package/src/local-storage.ts +30 -0
  109. package/src/migrations/legacy-local-storage-data/{convert-edit-post-panels.js → convert-edit-post-panels.ts} +13 -5
  110. package/src/migrations/legacy-local-storage-data/{index.js → index.ts} +22 -15
  111. package/src/migrations/legacy-local-storage-data/{move-feature-preferences.js → move-feature-preferences.ts} +13 -7
  112. package/src/migrations/legacy-local-storage-data/{move-individual-preference.js → move-individual-preference.ts} +15 -12
  113. package/src/migrations/legacy-local-storage-data/{move-interface-enable-items.js → move-interface-enable-items.ts} +6 -2
  114. package/src/migrations/legacy-local-storage-data/{move-third-party-feature-preferences.js → move-third-party-feature-preferences.ts} +8 -4
  115. package/src/migrations/legacy-local-storage-data/test/{index.js → index.ts} +11 -0
  116. package/src/migrations/legacy-local-storage-data/types.ts +66 -0
  117. package/src/migrations/preferences-package-data/convert-complementary-areas.ts +21 -0
  118. package/src/migrations/preferences-package-data/convert-editor-settings.ts +58 -0
  119. package/src/migrations/preferences-package-data/{index.js → index.ts} +4 -1
  120. package/src/migrations/preferences-package-data/test/{convert-complementary-areas.js → convert-complementary-areas.ts} +10 -0
  121. package/src/migrations/preferences-package-data/test/convert-editor-settings.ts +58 -0
  122. package/src/test/index.jsdom.test.ts +97 -0
  123. package/src/test/local-storage.jsdom.test.ts +50 -0
  124. package/src/types.ts +43 -0
  125. package/CHANGELOG.md +0 -228
  126. package/src/create/index.js +0 -105
  127. package/src/index.js +0 -47
  128. package/src/migrations/preferences-package-data/convert-complementary-areas.js +0 -16
  129. package/src/migrations/preferences-package-data/convert-editor-settings.js +0 -48
  130. package/src/migrations/preferences-package-data/test/convert-editor-settings.js +0 -20
  131. /package/src/migrations/legacy-local-storage-data/test/{convert-edit-post-panels.js → convert-edit-post-panels.ts} +0 -0
  132. /package/src/migrations/legacy-local-storage-data/test/{move-feature-preferences.js → move-feature-preferences.ts} +0 -0
  133. /package/src/migrations/legacy-local-storage-data/test/{move-individual-preference.js → move-individual-preference.ts} +0 -0
  134. /package/src/migrations/legacy-local-storage-data/test/{move-interface-enable-items.js → move-interface-enable-items.ts} +0 -0
  135. /package/src/migrations/legacy-local-storage-data/test/{move-third-party-feature-preferences.js → move-third-party-feature-preferences.ts} +0 -0
  136. /package/src/migrations/preferences-package-data/test/{index.js → index.ts} +0 -0
@@ -0,0 +1,20 @@
1
+ import create from './create';
2
+ import type { PersistenceLayer } from './types';
3
+ export { create };
4
+ export type * from './types';
5
+ /**
6
+ * Creates the persistence layer with preloaded data.
7
+ *
8
+ * It prioritizes any data from the server, but falls back first to localStorage
9
+ * restore data, and then to any legacy data.
10
+ *
11
+ * This function is used internally by WordPress in an inline script, so
12
+ * prefixed with `__unstable`.
13
+ *
14
+ * @param serverData Preferences data preloaded from the server.
15
+ * @param userId The user id.
16
+ *
17
+ * @return The persistence layer initialized with the preloaded data.
18
+ */
19
+ export declare function __unstableCreatePersistenceLayer(serverData: unknown, userId: string | number): PersistenceLayer;
20
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,UAAU,CAAC;AAG9B,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAEhD,OAAO,EAAE,MAAM,EAAE,CAAC;AAElB,mBAAmB,SAAS,CAAC;AAE7B;;;;;;;;;;;;;GAaG;AACH,wBAAgB,gCAAgC,CAC/C,UAAU,EAAE,OAAO,EACnB,MAAM,EAAE,MAAM,GAAG,MAAM,GACrB,gBAAgB,CAalB"}
@@ -0,0 +1,11 @@
1
+ import type { PreferencesData } from './types';
2
+ /**
3
+ * Checks whether persisted data is a preferences object. Empty user meta
4
+ * reaches the client as `[]` or `''`, which must not be used as preferences.
5
+ *
6
+ * @param data The persisted data.
7
+ *
8
+ * @return Whether the data is a preferences object.
9
+ */
10
+ export default function isPreferencesData(data: unknown): data is PreferencesData;
11
+ //# sourceMappingURL=is-preferences-data.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"is-preferences-data.d.ts","sourceRoot":"","sources":["../src/is-preferences-data.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAE/C;;;;;;;GAOG;AACH,MAAM,CAAC,OAAO,UAAU,iBAAiB,CACxC,IAAI,EAAE,OAAO,GACX,IAAI,IAAI,eAAe,CAEzB"}
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Reads and parses a JSON value from local storage.
3
+ *
4
+ * @param key The local storage key.
5
+ *
6
+ * @return The parsed value, or `null` when the value is missing or invalid,
7
+ * or local storage is unavailable.
8
+ */
9
+ export declare function readStoredJSON(key: string): unknown;
10
+ /**
11
+ * Stores a value in local storage as JSON.
12
+ *
13
+ * Failures, such as blocked storage or an exceeded quota, are ignored.
14
+ *
15
+ * @param key The local storage key.
16
+ * @param value The value to store.
17
+ */
18
+ export declare function writeStoredJSON(key: string, value: unknown): void;
19
+ //# sourceMappingURL=local-storage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"local-storage.d.ts","sourceRoot":"","sources":["../src/local-storage.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAE,GAAG,EAAE,MAAM,GAAI,OAAO,CAOrD;AAED;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,QAI3D"}
@@ -0,0 +1,35 @@
1
+ import type { ScopePreferences } from '../../types';
2
+ import type { EditPostPanels } from './types';
3
+ /**
4
+ * Convert the post editor's panels state from:
5
+ * ```
6
+ * {
7
+ * panels: {
8
+ * tags: {
9
+ * enabled: true,
10
+ * opened: true,
11
+ * },
12
+ * permalinks: {
13
+ * enabled: false,
14
+ * opened: false,
15
+ * },
16
+ * },
17
+ * }
18
+ * ```
19
+ *
20
+ * to a new, more concise data structure:
21
+ * {
22
+ * inactivePanels: [
23
+ * 'permalinks',
24
+ * ],
25
+ * openPanels: [
26
+ * 'tags',
27
+ * ],
28
+ * }
29
+ *
30
+ * @param preferences A preferences object.
31
+ *
32
+ * @return The converted data.
33
+ */
34
+ export default function convertEditPostPanels(preferences: ScopePreferences): EditPostPanels;
35
+ //# sourceMappingURL=convert-edit-post-panels.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"convert-edit-post-panels.d.ts","sourceRoot":"","sources":["../../../src/migrations/legacy-local-storage-data/convert-edit-post-panels.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,KAAK,EAAE,cAAc,EAAuB,MAAM,SAAS,CAAC;AAEnE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,MAAM,CAAC,OAAO,UAAU,qBAAqB,CAC5C,WAAW,EAAE,gBAAgB,GAC3B,cAAc,CAqBhB"}
@@ -0,0 +1,22 @@
1
+ import type { ScopedPreferences } from '../../types';
2
+ import type { LegacyData } from './types';
3
+ /**
4
+ * Converts data from the old `@wordpress/data` package format.
5
+ *
6
+ * @param data The legacy data in its original format.
7
+ *
8
+ * @return The converted data or `undefined` if there was
9
+ * nothing to convert.
10
+ */
11
+ export declare function convertLegacyData(data: LegacyData | null | undefined): ScopedPreferences | undefined;
12
+ /**
13
+ * Gets the legacy local storage data for the given user and returns the
14
+ * data converted to the new format.
15
+ *
16
+ * @param userId The user id.
17
+ *
18
+ * @return The converted data or undefined if no local
19
+ * storage data could be found.
20
+ */
21
+ export default function convertLegacyLocalStorageData(userId: string | number): ScopedPreferences | undefined;
22
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/migrations/legacy-local-storage-data/index.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AACrD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAa1C;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAChC,IAAI,EAAE,UAAU,GAAG,IAAI,GAAG,SAAS,GACjC,iBAAiB,GAAG,SAAS,CA0D/B;AAED;;;;;;;;GAQG;AACH,MAAM,CAAC,OAAO,UAAU,6BAA6B,CACpD,MAAM,EAAE,MAAM,GAAG,MAAM,GACrB,iBAAiB,GAAG,SAAS,CAG/B"}
@@ -0,0 +1,60 @@
1
+ import type { LegacyData } from './types';
2
+ /**
3
+ * Move the 'features' object in local storage from the sourceStoreName to the
4
+ * preferences store data structure.
5
+ *
6
+ * Previously, editors used a data structure like this for feature preferences:
7
+ * ```js
8
+ * {
9
+ * 'core/edit-post': {
10
+ * preferences: {
11
+ * features; {
12
+ * topToolbar: true,
13
+ * // ... other boolean 'feature' preferences
14
+ * },
15
+ * },
16
+ * },
17
+ * }
18
+ * ```
19
+ *
20
+ * And for a while these feature preferences lived in the interface package:
21
+ * ```js
22
+ * {
23
+ * 'core/interface': {
24
+ * preferences: {
25
+ * features: {
26
+ * 'core/edit-post': {
27
+ * topToolbar: true
28
+ * }
29
+ * }
30
+ * }
31
+ * }
32
+ * }
33
+ * ```
34
+ *
35
+ * In the preferences store, 'features' aren't considered special, they're
36
+ * merged to the root level of the scope along with other preferences:
37
+ * ```js
38
+ * {
39
+ * 'core/preferences': {
40
+ * preferences: {
41
+ * 'core/edit-post': {
42
+ * topToolbar: true,
43
+ * // ... any other preferences.
44
+ * }
45
+ * }
46
+ * }
47
+ * }
48
+ * ```
49
+ *
50
+ * This function handles moving from either the source store or the interface
51
+ * store to the preferences data structure.
52
+ *
53
+ * @param state The state before migration.
54
+ * @param sourceStoreName The name of the store that has persisted
55
+ * preferences to migrate to the preferences
56
+ * package.
57
+ * @return The migrated state
58
+ */
59
+ export default function moveFeaturePreferences(state: LegacyData, sourceStoreName: string): LegacyData;
60
+ //# sourceMappingURL=move-feature-preferences.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"move-feature-preferences.d.ts","sourceRoot":"","sources":["../../../src/migrations/legacy-local-storage-data/move-feature-preferences.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAsB,UAAU,EAAE,MAAM,SAAS,CAAC;AAE9D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwDG;AACH,MAAM,CAAC,OAAO,UAAU,sBAAsB,CAC7C,KAAK,EAAE,UAAU,EACjB,eAAe,EAAE,MAAM,GACrB,UAAU,CA8EZ"}
@@ -0,0 +1,42 @@
1
+ import type { ScopePreferences } from '../../types';
2
+ import type { LegacyData } from './types';
3
+ /**
4
+ * Migrates an individual item inside the `preferences` object for a package's store.
5
+ *
6
+ * Previously, some packages had individual 'preferences' of any data type, and many used
7
+ * complex nested data structures. For example:
8
+ * ```js
9
+ * {
10
+ * 'core/edit-post': {
11
+ * preferences: {
12
+ * panels: {
13
+ * publish: {
14
+ * opened: true,
15
+ * enabled: true,
16
+ * }
17
+ * },
18
+ * // ...other preferences.
19
+ * },
20
+ * },
21
+ * }
22
+ *
23
+ * This function supports moving an individual preference like 'panels' above into the
24
+ * preferences package data structure.
25
+ *
26
+ * It supports moving a preference to a particular scope in the preferences store and
27
+ * optionally converting the data using a `convert` function.
28
+ *
29
+ * ```
30
+ *
31
+ * @param state The original state.
32
+ * @param migrate An options object that contains details of the migration.
33
+ * @param migrate.from The name of the store to migrate from.
34
+ * @param migrate.to The scope in the preferences store to migrate to.
35
+ * @param key The key in the preferences object to migrate.
36
+ * @param convert A function that converts preferences from one format to another.
37
+ */
38
+ export default function moveIndividualPreferenceToPreferences(state: LegacyData, { from: sourceStoreName, to: scope }: {
39
+ from: string;
40
+ to: string;
41
+ }, key: string, convert?: (preferences: ScopePreferences) => object): LegacyData;
42
+ //# sourceMappingURL=move-individual-preference.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"move-individual-preference.d.ts","sourceRoot":"","sources":["../../../src/migrations/legacy-local-storage-data/move-individual-preference.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAI1C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,MAAM,CAAC,OAAO,UAAU,qCAAqC,CAC5D,KAAK,EAAE,UAAU,EACjB,EAAE,IAAI,EAAE,eAAe,EAAE,EAAE,EAAE,KAAK,EAAE,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,MAAM,CAAA;CAAE,EAClE,GAAG,EAAE,MAAM,EACX,OAAO,GAAE,CAAE,WAAW,EAAE,gBAAgB,KAAM,MAAiB,GAC7D,UAAU,CA+CZ"}
@@ -0,0 +1,50 @@
1
+ import type { LegacyData } from './types';
2
+ /**
3
+ * Migrates interface 'enableItems' data to the preferences store.
4
+ *
5
+ * The interface package stores this data in this format:
6
+ * ```js
7
+ * {
8
+ * enableItems: {
9
+ * singleEnableItems: {
10
+ * complementaryArea: {
11
+ * 'core/edit-post': 'edit-post/document',
12
+ * 'core/edit-site': 'edit-site/global-styles',
13
+ * }
14
+ * },
15
+ * multipleEnableItems: {
16
+ * pinnedItems: {
17
+ * 'core/edit-post': {
18
+ * 'plugin-1': true,
19
+ * },
20
+ * 'core/edit-site': {
21
+ * 'plugin-2': true,
22
+ * },
23
+ * },
24
+ * }
25
+ * }
26
+ * }
27
+ * ```
28
+ *
29
+ * and it should be converted it to:
30
+ * ```js
31
+ * {
32
+ * 'core/edit-post': {
33
+ * complementaryArea: 'edit-post/document',
34
+ * pinnedItems: {
35
+ * 'plugin-1': true,
36
+ * },
37
+ * },
38
+ * 'core/edit-site': {
39
+ * complementaryArea: 'edit-site/global-styles',
40
+ * pinnedItems: {
41
+ * 'plugin-2': true,
42
+ * },
43
+ * },
44
+ * }
45
+ * ```
46
+ *
47
+ * @param state The local storage state.
48
+ */
49
+ export default function moveInterfaceEnableItems(state: LegacyData): LegacyData;
50
+ //# sourceMappingURL=move-interface-enable-items.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"move-interface-enable-items.d.ts","sourceRoot":"","sources":["../../../src/migrations/legacy-local-storage-data/move-interface-enable-items.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAE1C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AACH,MAAM,CAAC,OAAO,UAAU,wBAAwB,CAC/C,KAAK,EAAE,UAAU,GACf,UAAU,CAwEZ"}
@@ -0,0 +1,44 @@
1
+ import type { LegacyData } from './types';
2
+ /**
3
+ * The interface package previously had a public API that could be used by
4
+ * plugins to set persisted boolean 'feature' preferences.
5
+ *
6
+ * While usage was likely non-existent or very small, this function ensures
7
+ * those are migrated to the preferences data structure. The interface
8
+ * package's APIs have now been deprecated and use the preferences store.
9
+ *
10
+ * This will convert data that looks like this:
11
+ * ```js
12
+ * {
13
+ * 'core/interface': {
14
+ * preferences: {
15
+ * features: {
16
+ * 'my-plugin': {
17
+ * myPluginFeature: true
18
+ * }
19
+ * }
20
+ * }
21
+ * }
22
+ * }
23
+ * ```
24
+ *
25
+ * To this:
26
+ * ```js
27
+ * * {
28
+ * 'core/preferences': {
29
+ * preferences: {
30
+ * 'my-plugin': {
31
+ * myPluginFeature: true
32
+ * }
33
+ * }
34
+ * }
35
+ * }
36
+ * ```
37
+ *
38
+ * @param state The local storage state
39
+ *
40
+ * @return The state with third party preferences moved to the
41
+ * preferences data structure.
42
+ */
43
+ export default function moveThirdPartyFeaturePreferencesToPreferences(state: LegacyData): LegacyData;
44
+ //# sourceMappingURL=move-third-party-feature-preferences.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"move-third-party-feature-preferences.d.ts","sourceRoot":"","sources":["../../../src/migrations/legacy-local-storage-data/move-third-party-feature-preferences.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAE1C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AACH,MAAM,CAAC,OAAO,UAAU,6CAA6C,CACpE,KAAK,EAAE,UAAU,GACf,UAAU,CAwDZ"}
@@ -0,0 +1,60 @@
1
+ import type { ScopedPreferences } from '../../types';
2
+ /**
3
+ * Boolean 'feature' preferences, keyed by feature name.
4
+ */
5
+ export type FeaturePreferences = Record<string, boolean | undefined>;
6
+ /**
7
+ * Persisted state of a package's store, such as `core/edit-post`.
8
+ */
9
+ export interface LegacyStoreState {
10
+ preferences?: Record<string, unknown>;
11
+ [key: string]: unknown;
12
+ }
13
+ /**
14
+ * Persisted state of the `core/interface` store.
15
+ */
16
+ export interface LegacyInterfaceStoreState {
17
+ preferences?: {
18
+ features?: Record<string, FeaturePreferences | undefined>;
19
+ [key: string]: unknown;
20
+ };
21
+ enableItems?: {
22
+ singleEnableItems?: {
23
+ complementaryArea?: Record<string, string>;
24
+ };
25
+ multipleEnableItems?: {
26
+ pinnedItems?: Record<string, Record<string, boolean>>;
27
+ };
28
+ };
29
+ [key: string]: unknown;
30
+ }
31
+ /**
32
+ * Persisted state of the `core/preferences` store.
33
+ */
34
+ export interface LegacyPreferencesStoreState {
35
+ preferences?: ScopedPreferences;
36
+ [key: string]: unknown;
37
+ }
38
+ /**
39
+ * Local storage data in the legacy `@wordpress/data` format, keyed by store name.
40
+ */
41
+ export interface LegacyData {
42
+ 'core/interface'?: LegacyInterfaceStoreState;
43
+ 'core/preferences'?: LegacyPreferencesStoreState;
44
+ [storeName: string]: LegacyStoreState | undefined;
45
+ }
46
+ /**
47
+ * The post editor's panels state in the legacy format.
48
+ */
49
+ export interface LegacyEditPostPanel {
50
+ enabled?: boolean;
51
+ opened?: boolean;
52
+ }
53
+ /**
54
+ * The post editor's panels state in the preferences format.
55
+ */
56
+ export interface EditPostPanels {
57
+ inactivePanels: string[];
58
+ openPanels: string[];
59
+ }
60
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/migrations/legacy-local-storage-data/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAErD;;GAEG;AACH,MAAM,MAAM,kBAAkB,GAAG,MAAM,CAAE,MAAM,EAAE,OAAO,GAAG,SAAS,CAAE,CAAC;AAEvE;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAChC,WAAW,CAAC,EAAE,MAAM,CAAE,MAAM,EAAE,OAAO,CAAE,CAAC;IACxC,CAAE,GAAG,EAAE,MAAM,GAAI,OAAO,CAAC;CACzB;AAED;;GAEG;AACH,MAAM,WAAW,yBAAyB;IACzC,WAAW,CAAC,EAAE;QACb,QAAQ,CAAC,EAAE,MAAM,CAAE,MAAM,EAAE,kBAAkB,GAAG,SAAS,CAAE,CAAC;QAC5D,CAAE,GAAG,EAAE,MAAM,GAAI,OAAO,CAAC;KACzB,CAAC;IACF,WAAW,CAAC,EAAE;QACb,iBAAiB,CAAC,EAAE;YACnB,iBAAiB,CAAC,EAAE,MAAM,CAAE,MAAM,EAAE,MAAM,CAAE,CAAC;SAC7C,CAAC;QACF,mBAAmB,CAAC,EAAE;YACrB,WAAW,CAAC,EAAE,MAAM,CAAE,MAAM,EAAE,MAAM,CAAE,MAAM,EAAE,OAAO,CAAE,CAAE,CAAC;SAC1D,CAAC;KACF,CAAC;IACF,CAAE,GAAG,EAAE,MAAM,GAAI,OAAO,CAAC;CACzB;AAED;;GAEG;AACH,MAAM,WAAW,2BAA2B;IAC3C,WAAW,CAAC,EAAE,iBAAiB,CAAC;IAChC,CAAE,GAAG,EAAE,MAAM,GAAI,OAAO,CAAC;CACzB;AAED;;GAEG;AACH,MAAM,WAAW,UAAU;IAC1B,gBAAgB,CAAC,EAAE,yBAAyB,CAAC;IAC7C,kBAAkB,CAAC,EAAE,2BAA2B,CAAC;IACjD,CAAE,SAAS,EAAE,MAAM,GAAI,gBAAgB,GAAG,SAAS,CAAC;CACpD;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB;IACnC,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,MAAM,CAAC,EAAE,OAAO,CAAC;CACjB;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC9B,cAAc,EAAE,MAAM,EAAE,CAAC;IACzB,UAAU,EAAE,MAAM,EAAE,CAAC;CACrB"}
@@ -0,0 +1,5 @@
1
+ import type { ScopedPreferences } from '../../types';
2
+ export default function convertComplementaryAreas(state: ScopedPreferences): {
3
+ [x: string]: import("../..").ScopePreferences | undefined;
4
+ };
5
+ //# sourceMappingURL=convert-complementary-areas.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"convert-complementary-areas.d.ts","sourceRoot":"","sources":["../../../src/migrations/preferences-package-data/convert-complementary-areas.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAErD,MAAM,CAAC,OAAO,UAAU,yBAAyB,CAAE,KAAK,EAAE,iBAAiB;;EAkB1E"}
@@ -0,0 +1,5 @@
1
+ import type { ScopedPreferences } from '../../types';
2
+ export default function convertEditorSettings(data: ScopedPreferences): {
3
+ [x: string]: import("../..").ScopePreferences | undefined;
4
+ };
5
+ //# sourceMappingURL=convert-editor-settings.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"convert-editor-settings.d.ts","sourceRoot":"","sources":["../../../src/migrations/preferences-package-data/convert-editor-settings.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAKrD,MAAM,CAAC,OAAO,UAAU,qBAAqB,CAAE,IAAI,EAAE,iBAAiB;;EAmDrE"}
@@ -0,0 +1,5 @@
1
+ import type { ScopedPreferences } from '../../types';
2
+ export default function convertPreferencesPackageData(data: ScopedPreferences): {
3
+ [x: string]: import("../..").ScopePreferences | undefined;
4
+ };
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/migrations/preferences-package-data/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAErD,MAAM,CAAC,OAAO,UAAU,6BAA6B,CACpD,IAAI,EAAE,iBAAiB;;EAKvB"}
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Preferences of a single scope, such as `core/edit-post`.
3
+ */
4
+ export type ScopePreferences = Record<string, unknown>;
5
+ /**
6
+ * Preferences store data, keyed by scope.
7
+ */
8
+ export type ScopedPreferences = Record<string, ScopePreferences | undefined>;
9
+ /**
10
+ * Persisted preferences data, keyed by scope.
11
+ */
12
+ export interface PreferencesData {
13
+ /**
14
+ * When the data was last modified, as an ISO 8601 date string.
15
+ */
16
+ _modified?: string;
17
+ [scope: string]: unknown;
18
+ }
19
+ export interface CreateOptions {
20
+ /**
21
+ * Any persisted preferences data that should be preloaded.
22
+ * When set, the persistence layer will avoid fetching data from the REST API.
23
+ */
24
+ preloadedData?: PreferencesData | null;
25
+ /**
26
+ * The key to use for restoring the localStorage backup, used when the
27
+ * persistence layer calls `localStorage.getItem` or `localStorage.setItem`.
28
+ */
29
+ localStorageRestoreKey?: string;
30
+ /**
31
+ * Debounce requests to the API so that they only occur at minimum every
32
+ * `requestDebounceMS` milliseconds, and don't swamp the server. Defaults to 2500ms.
33
+ */
34
+ requestDebounceMS?: number;
35
+ }
36
+ export interface PersistenceLayer {
37
+ get: () => Promise<PreferencesData>;
38
+ set: (newData: PreferencesData) => void;
39
+ }
40
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG,MAAM,CAAE,MAAM,EAAE,OAAO,CAAE,CAAC;AAEzD;;GAEG;AACH,MAAM,MAAM,iBAAiB,GAAG,MAAM,CAAE,MAAM,EAAE,gBAAgB,GAAG,SAAS,CAAE,CAAC;AAE/E;;GAEG;AACH,MAAM,WAAW,eAAe;IAC/B;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,CAAE,KAAK,EAAE,MAAM,GAAI,OAAO,CAAC;CAC3B;AAED,MAAM,WAAW,aAAa;IAC7B;;;OAGG;IACH,aAAa,CAAC,EAAE,eAAe,GAAG,IAAI,CAAC;IACvC;;;OAGG;IACH,sBAAsB,CAAC,EAAE,MAAM,CAAC;IAChC;;;OAGG;IACH,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED,MAAM,WAAW,gBAAgB;IAChC,GAAG,EAAE,MAAM,OAAO,CAAE,eAAe,CAAE,CAAC;IACtC,GAAG,EAAE,CAAE,OAAO,EAAE,eAAe,KAAM,IAAI,CAAC;CAC1C"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wordpress/preferences-persistence",
3
- "version": "2.57.0",
3
+ "version": "3.1.0",
4
4
  "description": "Persistence utilities for `wordpress/preferences`.",
5
5
  "author": "The WordPress Contributors",
6
6
  "license": "GPL-2.0-or-later",
@@ -20,14 +20,13 @@
20
20
  "url": "https://github.com/WordPress/gutenberg/issues"
21
21
  },
22
22
  "engines": {
23
- "node": ">=18.12.0"
23
+ "node": ">=22.13.0"
24
24
  },
25
25
  "files": [
26
26
  "src",
27
27
  "build",
28
28
  "build-module",
29
- "build-types",
30
- "*.md"
29
+ "build-types"
31
30
  ],
32
31
  "main": "build/index.cjs",
33
32
  "module": "build-module/index.mjs",
@@ -40,15 +39,17 @@
40
39
  "./package.json": "./package.json"
41
40
  },
42
41
  "wpScript": true,
42
+ "types": "build-types",
43
43
  "sideEffects": false,
44
44
  "dependencies": {
45
- "@wordpress/api-fetch": "^7.57.0"
45
+ "@wordpress/api-fetch": "^8.1.0"
46
46
  },
47
47
  "devDependencies": {
48
- "vitest": "^5.0.3"
48
+ "@types/node": "^24.13.3",
49
+ "vitest": "^5.0.5"
49
50
  },
50
51
  "publishConfig": {
51
52
  "access": "public"
52
53
  },
53
- "gitHead": "12441e2520c78b2254a792a8cba40c34110be060"
54
+ "gitHead": "9b70363b9f93cff0583a1f3153738d383cf5a49e"
54
55
  }
@@ -9,21 +9,24 @@
9
9
  * This is distinct from `{ debounce } from @wordpress/compose` in that it
10
10
  * waits for promise resolution.
11
11
  *
12
- * @param {Function} func A function that returns a promise.
13
- * @param {number} delayMS A delay in milliseconds.
12
+ * @param func A function that returns a promise.
13
+ * @param delayMS A delay in milliseconds.
14
14
  *
15
- * @return {Function} A function that debounce whatever function is passed
16
- * to it.
15
+ * @return A function that debounce whatever function is passed
16
+ * to it.
17
17
  */
18
- export default function debounceAsync( func, delayMS ) {
19
- let timeoutId;
20
- let activePromise;
18
+ export default function debounceAsync< Args extends unknown[], Result >(
19
+ func: ( ...args: Args ) => Promise< Result >,
20
+ delayMS: number
21
+ ): ( ...args: Args ) => Promise< Result > {
22
+ let timeoutId: ReturnType< typeof setTimeout > | null | undefined;
23
+ let activePromise: Promise< void > | null | undefined;
21
24
 
22
- return async function debounced( ...args ) {
25
+ return async function debounced( ...args: Args ) {
23
26
  // This is a leading edge debounce. If there's no promise or timeout
24
27
  // in progress, call the debounced function immediately.
25
28
  if ( ! activePromise && ! timeoutId ) {
26
- return new Promise( ( resolve, reject ) => {
29
+ return new Promise< Result >( ( resolve, reject ) => {
27
30
  // Keep a reference to the promise.
28
31
  activePromise = func( ...args )
29
32
  .then( ( ...thenArgs ) => {
@@ -53,7 +56,7 @@ export default function debounceAsync( func, delayMS ) {
53
56
  }
54
57
 
55
58
  // Trigger any trailing edge calls to the function.
56
- return new Promise( ( resolve, reject ) => {
59
+ return new Promise< Result >( ( resolve, reject ) => {
57
60
  // Schedule the next request but with a delay.
58
61
  timeoutId = setTimeout( () => {
59
62
  activePromise = func( ...args )