@wordpress/preferences-persistence 3.0.0 → 3.2.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,81 +1,109 @@
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/migrations/legacy-local-storage-data/move-feature-preferences.ts
21
- var move_feature_preferences_exports = {};
22
- __export(move_feature_preferences_exports, {
23
- default: () => moveFeaturePreferences
2
+ Object.defineProperties(exports, {
3
+ __esModule: { value: true },
4
+ [Symbol.toStringTag]: { value: "Module" }
24
5
  });
25
- module.exports = __toCommonJS(move_feature_preferences_exports);
6
+ // packages/preferences-persistence/src/migrations/legacy-local-storage-data/move-feature-preferences.ts
7
+ /**
8
+ * Move the 'features' object in local storage from the sourceStoreName to the
9
+ * preferences store data structure.
10
+ *
11
+ * Previously, editors used a data structure like this for feature preferences:
12
+ * ```js
13
+ * {
14
+ * 'core/edit-post': {
15
+ * preferences: {
16
+ * features; {
17
+ * topToolbar: true,
18
+ * // ... other boolean 'feature' preferences
19
+ * },
20
+ * },
21
+ * },
22
+ * }
23
+ * ```
24
+ *
25
+ * And for a while these feature preferences lived in the interface package:
26
+ * ```js
27
+ * {
28
+ * 'core/interface': {
29
+ * preferences: {
30
+ * features: {
31
+ * 'core/edit-post': {
32
+ * topToolbar: true
33
+ * }
34
+ * }
35
+ * }
36
+ * }
37
+ * }
38
+ * ```
39
+ *
40
+ * In the preferences store, 'features' aren't considered special, they're
41
+ * merged to the root level of the scope along with other preferences:
42
+ * ```js
43
+ * {
44
+ * 'core/preferences': {
45
+ * preferences: {
46
+ * 'core/edit-post': {
47
+ * topToolbar: true,
48
+ * // ... any other preferences.
49
+ * }
50
+ * }
51
+ * }
52
+ * }
53
+ * ```
54
+ *
55
+ * This function handles moving from either the source store or the interface
56
+ * store to the preferences data structure.
57
+ *
58
+ * @param state The state before migration.
59
+ * @param sourceStoreName The name of the store that has persisted
60
+ * preferences to migrate to the preferences
61
+ * package.
62
+ * @return The migrated state
63
+ */
26
64
  function moveFeaturePreferences(state, sourceStoreName) {
27
- const preferencesStoreName = "core/preferences";
28
- const interfaceStoreName = "core/interface";
29
- const interfaceFeatures = state?.[interfaceStoreName]?.preferences?.features?.[sourceStoreName];
30
- const sourceFeatures = state?.[sourceStoreName]?.preferences?.features;
31
- const featuresToMigrate = interfaceFeatures ? interfaceFeatures : sourceFeatures;
32
- if (!featuresToMigrate) {
33
- return state;
34
- }
35
- const existingPreferences = state?.[preferencesStoreName]?.preferences;
36
- if (existingPreferences?.[sourceStoreName]) {
37
- return state;
38
- }
39
- let updatedInterfaceState;
40
- if (interfaceFeatures) {
41
- const otherInterfaceState = state?.[interfaceStoreName];
42
- const otherInterfaceScopes = state?.[interfaceStoreName]?.preferences?.features;
43
- updatedInterfaceState = {
44
- [interfaceStoreName]: {
45
- ...otherInterfaceState,
46
- preferences: {
47
- features: {
48
- ...otherInterfaceScopes,
49
- [sourceStoreName]: void 0
50
- }
51
- }
52
- }
53
- };
54
- }
55
- let updatedSourceState;
56
- if (sourceFeatures) {
57
- const otherSourceState = state?.[sourceStoreName];
58
- const sourcePreferences = state?.[sourceStoreName]?.preferences;
59
- updatedSourceState = {
60
- [sourceStoreName]: {
61
- ...otherSourceState,
62
- preferences: {
63
- ...sourcePreferences,
64
- features: void 0
65
- }
66
- }
67
- };
68
- }
69
- return {
70
- ...state,
71
- [preferencesStoreName]: {
72
- preferences: {
73
- ...existingPreferences,
74
- [sourceStoreName]: featuresToMigrate
75
- }
76
- },
77
- ...updatedInterfaceState,
78
- ...updatedSourceState
79
- };
65
+ const preferencesStoreName = "core/preferences";
66
+ const interfaceStoreName = "core/interface";
67
+ const interfaceFeatures = state?.[interfaceStoreName]?.preferences?.features?.[sourceStoreName];
68
+ const sourceFeatures = state?.[sourceStoreName]?.preferences?.features;
69
+ const featuresToMigrate = interfaceFeatures ? interfaceFeatures : sourceFeatures;
70
+ if (!featuresToMigrate) return state;
71
+ const existingPreferences = state?.[preferencesStoreName]?.preferences;
72
+ if (existingPreferences?.[sourceStoreName]) return state;
73
+ let updatedInterfaceState;
74
+ if (interfaceFeatures) {
75
+ const otherInterfaceState = state?.[interfaceStoreName];
76
+ const otherInterfaceScopes = state?.[interfaceStoreName]?.preferences?.features;
77
+ updatedInterfaceState = { [interfaceStoreName]: {
78
+ ...otherInterfaceState,
79
+ preferences: { features: {
80
+ ...otherInterfaceScopes,
81
+ [sourceStoreName]: void 0
82
+ } }
83
+ } };
84
+ }
85
+ let updatedSourceState;
86
+ if (sourceFeatures) {
87
+ const otherSourceState = state?.[sourceStoreName];
88
+ const sourcePreferences = state?.[sourceStoreName]?.preferences;
89
+ updatedSourceState = { [sourceStoreName]: {
90
+ ...otherSourceState,
91
+ preferences: {
92
+ ...sourcePreferences,
93
+ features: void 0
94
+ }
95
+ } };
96
+ }
97
+ return {
98
+ ...state,
99
+ [preferencesStoreName]: { preferences: {
100
+ ...existingPreferences,
101
+ [sourceStoreName]: featuresToMigrate
102
+ } },
103
+ ...updatedInterfaceState,
104
+ ...updatedSourceState
105
+ };
80
106
  }
81
- //# sourceMappingURL=move-feature-preferences.cjs.map
107
+ exports.default = moveFeaturePreferences;
108
+
109
+ //# sourceMappingURL=move-feature-preferences.cjs.map
@@ -1,7 +1 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/migrations/legacy-local-storage-data/move-feature-preferences.ts"],
4
- "sourcesContent": ["import type { FeaturePreferences, LegacyData } from './types';\n\n/**\n * Move the 'features' object in local storage from the sourceStoreName to the\n * preferences store data structure.\n *\n * Previously, editors used a data structure like this for feature preferences:\n * ```js\n * {\n * 'core/edit-post': {\n * preferences: {\n * features; {\n * topToolbar: true,\n * // ... other boolean 'feature' preferences\n * },\n * },\n * },\n * }\n * ```\n *\n * And for a while these feature preferences lived in the interface package:\n * ```js\n * {\n * 'core/interface': {\n * preferences: {\n * features: {\n * 'core/edit-post': {\n * topToolbar: true\n * }\n * }\n * }\n * }\n * }\n * ```\n *\n * In the preferences store, 'features' aren't considered special, they're\n * merged to the root level of the scope along with other preferences:\n * ```js\n * {\n * 'core/preferences': {\n * preferences: {\n * 'core/edit-post': {\n * topToolbar: true,\n * // ... any other preferences.\n * }\n * }\n * }\n * }\n * ```\n *\n * This function handles moving from either the source store or the interface\n * store to the preferences data structure.\n *\n * @param state The state before migration.\n * @param sourceStoreName The name of the store that has persisted\n * preferences to migrate to the preferences\n * package.\n * @return The migrated state\n */\nexport default function moveFeaturePreferences(\n\tstate: LegacyData,\n\tsourceStoreName: string\n): LegacyData {\n\tconst preferencesStoreName = 'core/preferences';\n\tconst interfaceStoreName = 'core/interface';\n\n\t// Features most recently (and briefly) lived in the interface package.\n\t// If data exists there, prioritize using that for the migration. If not\n\t// also check the original package as the user may have updated from an\n\t// older block editor version.\n\tconst interfaceFeatures =\n\t\tstate?.[ interfaceStoreName ]?.preferences?.features?.[\n\t\t\tsourceStoreName\n\t\t];\n\tconst sourceFeatures = state?.[ sourceStoreName ]?.preferences?.features as\n\t\tFeaturePreferences | undefined;\n\tconst featuresToMigrate = interfaceFeatures\n\t\t? interfaceFeatures\n\t\t: sourceFeatures;\n\n\tif ( ! featuresToMigrate ) {\n\t\treturn state;\n\t}\n\n\tconst existingPreferences = state?.[ preferencesStoreName ]?.preferences;\n\n\t// Avoid migrating features again if they've previously been migrated.\n\tif ( existingPreferences?.[ sourceStoreName ] ) {\n\t\treturn state;\n\t}\n\n\tlet updatedInterfaceState;\n\tif ( interfaceFeatures ) {\n\t\tconst otherInterfaceState = state?.[ interfaceStoreName ];\n\t\tconst otherInterfaceScopes =\n\t\t\tstate?.[ interfaceStoreName ]?.preferences?.features;\n\n\t\tupdatedInterfaceState = {\n\t\t\t[ interfaceStoreName ]: {\n\t\t\t\t...otherInterfaceState,\n\t\t\t\tpreferences: {\n\t\t\t\t\tfeatures: {\n\t\t\t\t\t\t...otherInterfaceScopes,\n\t\t\t\t\t\t[ sourceStoreName ]: undefined,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t};\n\t}\n\n\tlet updatedSourceState;\n\tif ( sourceFeatures ) {\n\t\tconst otherSourceState = state?.[ sourceStoreName ];\n\t\tconst sourcePreferences = state?.[ sourceStoreName ]?.preferences;\n\n\t\tupdatedSourceState = {\n\t\t\t[ sourceStoreName ]: {\n\t\t\t\t...otherSourceState,\n\t\t\t\tpreferences: {\n\t\t\t\t\t...sourcePreferences,\n\t\t\t\t\tfeatures: undefined,\n\t\t\t\t},\n\t\t\t},\n\t\t};\n\t}\n\n\t// Set the feature values in the interface store, the features\n\t// object is keyed by 'scope', which matches the store name for\n\t// the source.\n\treturn {\n\t\t...state,\n\t\t[ preferencesStoreName ]: {\n\t\t\tpreferences: {\n\t\t\t\t...existingPreferences,\n\t\t\t\t[ sourceStoreName ]: featuresToMigrate,\n\t\t\t},\n\t\t},\n\t\t...updatedInterfaceState,\n\t\t...updatedSourceState,\n\t};\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AA2De,SAAR,uBACN,OACA,iBACa;AACb,QAAM,uBAAuB;AAC7B,QAAM,qBAAqB;AAM3B,QAAM,oBACL,QAAS,kBAAmB,GAAG,aAAa,WAC3C,eACD;AACD,QAAM,iBAAiB,QAAS,eAAgB,GAAG,aAAa;AAEhE,QAAM,oBAAoB,oBACvB,oBACA;AAEH,MAAK,CAAE,mBAAoB;AAC1B,WAAO;AAAA,EACR;AAEA,QAAM,sBAAsB,QAAS,oBAAqB,GAAG;AAG7D,MAAK,sBAAuB,eAAgB,GAAI;AAC/C,WAAO;AAAA,EACR;AAEA,MAAI;AACJ,MAAK,mBAAoB;AACxB,UAAM,sBAAsB,QAAS,kBAAmB;AACxD,UAAM,uBACL,QAAS,kBAAmB,GAAG,aAAa;AAE7C,4BAAwB;AAAA,MACvB,CAAE,kBAAmB,GAAG;AAAA,QACvB,GAAG;AAAA,QACH,aAAa;AAAA,UACZ,UAAU;AAAA,YACT,GAAG;AAAA,YACH,CAAE,eAAgB,GAAG;AAAA,UACtB;AAAA,QACD;AAAA,MACD;AAAA,IACD;AAAA,EACD;AAEA,MAAI;AACJ,MAAK,gBAAiB;AACrB,UAAM,mBAAmB,QAAS,eAAgB;AAClD,UAAM,oBAAoB,QAAS,eAAgB,GAAG;AAEtD,yBAAqB;AAAA,MACpB,CAAE,eAAgB,GAAG;AAAA,QACpB,GAAG;AAAA,QACH,aAAa;AAAA,UACZ,GAAG;AAAA,UACH,UAAU;AAAA,QACX;AAAA,MACD;AAAA,IACD;AAAA,EACD;AAKA,SAAO;AAAA,IACN,GAAG;AAAA,IACH,CAAE,oBAAqB,GAAG;AAAA,MACzB,aAAa;AAAA,QACZ,GAAG;AAAA,QACH,CAAE,eAAgB,GAAG;AAAA,MACtB;AAAA,IACD;AAAA,IACA,GAAG;AAAA,IACH,GAAG;AAAA,EACJ;AACD;",
6
- "names": []
7
- }
1
+ {"version":3,"file":"move-feature-preferences.cjs","names":[],"sources":["../../../src/migrations/legacy-local-storage-data/move-feature-preferences.ts"],"sourcesContent":["import type { FeaturePreferences, LegacyData } from './types';\n\n/**\n * Move the 'features' object in local storage from the sourceStoreName to the\n * preferences store data structure.\n *\n * Previously, editors used a data structure like this for feature preferences:\n * ```js\n * {\n * 'core/edit-post': {\n * preferences: {\n * features; {\n * topToolbar: true,\n * // ... other boolean 'feature' preferences\n * },\n * },\n * },\n * }\n * ```\n *\n * And for a while these feature preferences lived in the interface package:\n * ```js\n * {\n * 'core/interface': {\n * preferences: {\n * features: {\n * 'core/edit-post': {\n * topToolbar: true\n * }\n * }\n * }\n * }\n * }\n * ```\n *\n * In the preferences store, 'features' aren't considered special, they're\n * merged to the root level of the scope along with other preferences:\n * ```js\n * {\n * 'core/preferences': {\n * preferences: {\n * 'core/edit-post': {\n * topToolbar: true,\n * // ... any other preferences.\n * }\n * }\n * }\n * }\n * ```\n *\n * This function handles moving from either the source store or the interface\n * store to the preferences data structure.\n *\n * @param state The state before migration.\n * @param sourceStoreName The name of the store that has persisted\n * preferences to migrate to the preferences\n * package.\n * @return The migrated state\n */\nexport default function moveFeaturePreferences(\n\tstate: LegacyData,\n\tsourceStoreName: string\n): LegacyData {\n\tconst preferencesStoreName = 'core/preferences';\n\tconst interfaceStoreName = 'core/interface';\n\n\t// Features most recently (and briefly) lived in the interface package.\n\t// If data exists there, prioritize using that for the migration. If not\n\t// also check the original package as the user may have updated from an\n\t// older block editor version.\n\tconst interfaceFeatures =\n\t\tstate?.[ interfaceStoreName ]?.preferences?.features?.[\n\t\t\tsourceStoreName\n\t\t];\n\tconst sourceFeatures = state?.[ sourceStoreName ]?.preferences?.features as\n\t\tFeaturePreferences | undefined;\n\tconst featuresToMigrate = interfaceFeatures\n\t\t? interfaceFeatures\n\t\t: sourceFeatures;\n\n\tif ( ! featuresToMigrate ) {\n\t\treturn state;\n\t}\n\n\tconst existingPreferences = state?.[ preferencesStoreName ]?.preferences;\n\n\t// Avoid migrating features again if they've previously been migrated.\n\tif ( existingPreferences?.[ sourceStoreName ] ) {\n\t\treturn state;\n\t}\n\n\tlet updatedInterfaceState;\n\tif ( interfaceFeatures ) {\n\t\tconst otherInterfaceState = state?.[ interfaceStoreName ];\n\t\tconst otherInterfaceScopes =\n\t\t\tstate?.[ interfaceStoreName ]?.preferences?.features;\n\n\t\tupdatedInterfaceState = {\n\t\t\t[ interfaceStoreName ]: {\n\t\t\t\t...otherInterfaceState,\n\t\t\t\tpreferences: {\n\t\t\t\t\tfeatures: {\n\t\t\t\t\t\t...otherInterfaceScopes,\n\t\t\t\t\t\t[ sourceStoreName ]: undefined,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t};\n\t}\n\n\tlet updatedSourceState;\n\tif ( sourceFeatures ) {\n\t\tconst otherSourceState = state?.[ sourceStoreName ];\n\t\tconst sourcePreferences = state?.[ sourceStoreName ]?.preferences;\n\n\t\tupdatedSourceState = {\n\t\t\t[ sourceStoreName ]: {\n\t\t\t\t...otherSourceState,\n\t\t\t\tpreferences: {\n\t\t\t\t\t...sourcePreferences,\n\t\t\t\t\tfeatures: undefined,\n\t\t\t\t},\n\t\t\t},\n\t\t};\n\t}\n\n\t// Set the feature values in the interface store, the features\n\t// object is keyed by 'scope', which matches the store name for\n\t// the source.\n\treturn {\n\t\t...state,\n\t\t[ preferencesStoreName ]: {\n\t\t\tpreferences: {\n\t\t\t\t...existingPreferences,\n\t\t\t\t[ sourceStoreName ]: featuresToMigrate,\n\t\t\t},\n\t\t},\n\t\t...updatedInterfaceState,\n\t\t...updatedSourceState,\n\t};\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2DA,SAAwB,uBACvB,OACA,iBACa;CACb,MAAM,uBAAuB;CAC7B,MAAM,qBAAqB;CAM3B,MAAM,oBACL,QAAS,mBAAoB,EAAE,aAAa,WAC3C;CAEF,MAAM,iBAAiB,QAAS,gBAAiB,EAAE,aAAa;CAEhE,MAAM,oBAAoB,oBACvB,oBACA;CAEH,IAAK,CAAE,mBACN,OAAO;CAGR,MAAM,sBAAsB,QAAS,qBAAsB,EAAE;CAG7D,IAAK,sBAAuB,kBAC3B,OAAO;CAGR,IAAI;CACJ,IAAK,mBAAoB;EACxB,MAAM,sBAAsB,QAAS;EACrC,MAAM,uBACL,QAAS,mBAAoB,EAAE,aAAa;EAE7C,wBAAwB,GACrB,qBAAsB;GACvB,GAAG;GACH,aAAa,EACZ,UAAU;IACT,GAAG;KACD,kBAAmB,KAAA;GACtB,EACD;EACD,EACD;CACD;CAEA,IAAI;CACJ,IAAK,gBAAiB;EACrB,MAAM,mBAAmB,QAAS;EAClC,MAAM,oBAAoB,QAAS,gBAAiB,EAAE;EAEtD,qBAAqB,GAClB,kBAAmB;GACpB,GAAG;GACH,aAAa;IACZ,GAAG;IACH,UAAU,KAAA;GACX;EACD,EACD;CACD;CAKA,OAAO;EACN,GAAG;GACD,uBAAwB,EACzB,aAAa;GACZ,GAAG;IACD,kBAAmB;EACtB,EACD;EACA,GAAG;EACH,GAAG;CACJ;AACD"}
@@ -1,62 +1,73 @@
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/migrations/legacy-local-storage-data/move-individual-preference.ts
21
- var move_individual_preference_exports = {};
22
- __export(move_individual_preference_exports, {
23
- default: () => moveIndividualPreferenceToPreferences
2
+ Object.defineProperties(exports, {
3
+ __esModule: { value: true },
4
+ [Symbol.toStringTag]: { value: "Module" }
24
5
  });
25
- module.exports = __toCommonJS(move_individual_preference_exports);
26
- var identity = (arg) => arg;
6
+ // packages/preferences-persistence/src/migrations/legacy-local-storage-data/move-individual-preference.ts
7
+ const identity = (arg) => arg;
8
+ /**
9
+ * Migrates an individual item inside the `preferences` object for a package's store.
10
+ *
11
+ * Previously, some packages had individual 'preferences' of any data type, and many used
12
+ * complex nested data structures. For example:
13
+ * ```js
14
+ * {
15
+ * 'core/edit-post': {
16
+ * preferences: {
17
+ * panels: {
18
+ * publish: {
19
+ * opened: true,
20
+ * enabled: true,
21
+ * }
22
+ * },
23
+ * // ...other preferences.
24
+ * },
25
+ * },
26
+ * }
27
+ *
28
+ * This function supports moving an individual preference like 'panels' above into the
29
+ * preferences package data structure.
30
+ *
31
+ * It supports moving a preference to a particular scope in the preferences store and
32
+ * optionally converting the data using a `convert` function.
33
+ *
34
+ * ```
35
+ *
36
+ * @param state The original state.
37
+ * @param migrate An options object that contains details of the migration.
38
+ * @param migrate.from The name of the store to migrate from.
39
+ * @param migrate.to The scope in the preferences store to migrate to.
40
+ * @param key The key in the preferences object to migrate.
41
+ * @param convert A function that converts preferences from one format to another.
42
+ */
27
43
  function moveIndividualPreferenceToPreferences(state, { from: sourceStoreName, to: scope }, key, convert = identity) {
28
- const preferencesStoreName = "core/preferences";
29
- const sourcePreference = state?.[sourceStoreName]?.preferences?.[key];
30
- if (sourcePreference === void 0) {
31
- return state;
32
- }
33
- const targetPreference = state?.[preferencesStoreName]?.preferences?.[scope]?.[key];
34
- if (targetPreference) {
35
- return state;
36
- }
37
- const otherScopes = state?.[preferencesStoreName]?.preferences;
38
- const otherPreferences = state?.[preferencesStoreName]?.preferences?.[scope];
39
- const otherSourceState = state?.[sourceStoreName];
40
- const allSourcePreferences = state?.[sourceStoreName]?.preferences;
41
- const convertedPreferences = convert({ [key]: sourcePreference });
42
- return {
43
- ...state,
44
- [preferencesStoreName]: {
45
- preferences: {
46
- ...otherScopes,
47
- [scope]: {
48
- ...otherPreferences,
49
- ...convertedPreferences
50
- }
51
- }
52
- },
53
- [sourceStoreName]: {
54
- ...otherSourceState,
55
- preferences: {
56
- ...allSourcePreferences,
57
- [key]: void 0
58
- }
59
- }
60
- };
44
+ const preferencesStoreName = "core/preferences";
45
+ const sourcePreference = state?.[sourceStoreName]?.preferences?.[key];
46
+ if (sourcePreference === void 0) return state;
47
+ if (state?.[preferencesStoreName]?.preferences?.[scope]?.[key]) return state;
48
+ const otherScopes = state?.[preferencesStoreName]?.preferences;
49
+ const otherPreferences = state?.[preferencesStoreName]?.preferences?.[scope];
50
+ const otherSourceState = state?.[sourceStoreName];
51
+ const allSourcePreferences = state?.[sourceStoreName]?.preferences;
52
+ const convertedPreferences = convert({ [key]: sourcePreference });
53
+ return {
54
+ ...state,
55
+ [preferencesStoreName]: { preferences: {
56
+ ...otherScopes,
57
+ [scope]: {
58
+ ...otherPreferences,
59
+ ...convertedPreferences
60
+ }
61
+ } },
62
+ [sourceStoreName]: {
63
+ ...otherSourceState,
64
+ preferences: {
65
+ ...allSourcePreferences,
66
+ [key]: void 0
67
+ }
68
+ }
69
+ };
61
70
  }
62
- //# sourceMappingURL=move-individual-preference.cjs.map
71
+ exports.default = moveIndividualPreferenceToPreferences;
72
+
73
+ //# sourceMappingURL=move-individual-preference.cjs.map
@@ -1,7 +1 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/migrations/legacy-local-storage-data/move-individual-preference.ts"],
4
- "sourcesContent": ["import type { ScopePreferences } from '../../types';\nimport type { LegacyData } from './types';\n\nconst identity = < T >( arg: T ) => arg;\n\n/**\n * Migrates an individual item inside the `preferences` object for a package's store.\n *\n * Previously, some packages had individual 'preferences' of any data type, and many used\n * complex nested data structures. For example:\n * ```js\n * {\n * 'core/edit-post': {\n * preferences: {\n * panels: {\n * publish: {\n * opened: true,\n * enabled: true,\n * }\n * },\n * // ...other preferences.\n * },\n * },\n * }\n *\n * This function supports moving an individual preference like 'panels' above into the\n * preferences package data structure.\n *\n * It supports moving a preference to a particular scope in the preferences store and\n * optionally converting the data using a `convert` function.\n *\n * ```\n *\n * @param state The original state.\n * @param migrate An options object that contains details of the migration.\n * @param migrate.from The name of the store to migrate from.\n * @param migrate.to The scope in the preferences store to migrate to.\n * @param key The key in the preferences object to migrate.\n * @param convert A function that converts preferences from one format to another.\n */\nexport default function moveIndividualPreferenceToPreferences(\n\tstate: LegacyData,\n\t{ from: sourceStoreName, to: scope }: { from: string; to: string },\n\tkey: string,\n\tconvert: ( preferences: ScopePreferences ) => object = identity\n): LegacyData {\n\tconst preferencesStoreName = 'core/preferences';\n\tconst sourcePreference = state?.[ sourceStoreName ]?.preferences?.[ key ];\n\n\t// There's nothing to migrate, exit early.\n\tif ( sourcePreference === undefined ) {\n\t\treturn state;\n\t}\n\n\tconst targetPreference =\n\t\tstate?.[ preferencesStoreName ]?.preferences?.[ scope ]?.[ key ];\n\n\t// There's existing data at the target, so don't overwrite it, exit early.\n\tif ( targetPreference ) {\n\t\treturn state;\n\t}\n\n\tconst otherScopes = state?.[ preferencesStoreName ]?.preferences;\n\tconst otherPreferences =\n\t\tstate?.[ preferencesStoreName ]?.preferences?.[ scope ];\n\n\tconst otherSourceState = state?.[ sourceStoreName ];\n\tconst allSourcePreferences = state?.[ sourceStoreName ]?.preferences;\n\n\t// Pass an object with the key and value as this allows the convert\n\t// function to convert to a data structure that has different keys.\n\tconst convertedPreferences = convert( { [ key ]: sourcePreference } );\n\n\treturn {\n\t\t...state,\n\t\t[ preferencesStoreName ]: {\n\t\t\tpreferences: {\n\t\t\t\t...otherScopes,\n\t\t\t\t[ scope ]: {\n\t\t\t\t\t...otherPreferences,\n\t\t\t\t\t...convertedPreferences,\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t\t[ sourceStoreName ]: {\n\t\t\t...otherSourceState,\n\t\t\tpreferences: {\n\t\t\t\t...allSourcePreferences,\n\t\t\t\t[ key ]: undefined,\n\t\t\t},\n\t\t},\n\t};\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,IAAM,WAAW,CAAO,QAAY;AAqCrB,SAAR,sCACN,OACA,EAAE,MAAM,iBAAiB,IAAI,MAAM,GACnC,KACA,UAAuD,UAC1C;AACb,QAAM,uBAAuB;AAC7B,QAAM,mBAAmB,QAAS,eAAgB,GAAG,cAAe,GAAI;AAGxE,MAAK,qBAAqB,QAAY;AACrC,WAAO;AAAA,EACR;AAEA,QAAM,mBACL,QAAS,oBAAqB,GAAG,cAAe,KAAM,IAAK,GAAI;AAGhE,MAAK,kBAAmB;AACvB,WAAO;AAAA,EACR;AAEA,QAAM,cAAc,QAAS,oBAAqB,GAAG;AACrD,QAAM,mBACL,QAAS,oBAAqB,GAAG,cAAe,KAAM;AAEvD,QAAM,mBAAmB,QAAS,eAAgB;AAClD,QAAM,uBAAuB,QAAS,eAAgB,GAAG;AAIzD,QAAM,uBAAuB,QAAS,EAAE,CAAE,GAAI,GAAG,iBAAiB,CAAE;AAEpE,SAAO;AAAA,IACN,GAAG;AAAA,IACH,CAAE,oBAAqB,GAAG;AAAA,MACzB,aAAa;AAAA,QACZ,GAAG;AAAA,QACH,CAAE,KAAM,GAAG;AAAA,UACV,GAAG;AAAA,UACH,GAAG;AAAA,QACJ;AAAA,MACD;AAAA,IACD;AAAA,IACA,CAAE,eAAgB,GAAG;AAAA,MACpB,GAAG;AAAA,MACH,aAAa;AAAA,QACZ,GAAG;AAAA,QACH,CAAE,GAAI,GAAG;AAAA,MACV;AAAA,IACD;AAAA,EACD;AACD;",
6
- "names": []
7
- }
1
+ {"version":3,"file":"move-individual-preference.cjs","names":[],"sources":["../../../src/migrations/legacy-local-storage-data/move-individual-preference.ts"],"sourcesContent":["import type { ScopePreferences } from '../../types';\nimport type { LegacyData } from './types';\n\nconst identity = < T >( arg: T ) => arg;\n\n/**\n * Migrates an individual item inside the `preferences` object for a package's store.\n *\n * Previously, some packages had individual 'preferences' of any data type, and many used\n * complex nested data structures. For example:\n * ```js\n * {\n * 'core/edit-post': {\n * preferences: {\n * panels: {\n * publish: {\n * opened: true,\n * enabled: true,\n * }\n * },\n * // ...other preferences.\n * },\n * },\n * }\n *\n * This function supports moving an individual preference like 'panels' above into the\n * preferences package data structure.\n *\n * It supports moving a preference to a particular scope in the preferences store and\n * optionally converting the data using a `convert` function.\n *\n * ```\n *\n * @param state The original state.\n * @param migrate An options object that contains details of the migration.\n * @param migrate.from The name of the store to migrate from.\n * @param migrate.to The scope in the preferences store to migrate to.\n * @param key The key in the preferences object to migrate.\n * @param convert A function that converts preferences from one format to another.\n */\nexport default function moveIndividualPreferenceToPreferences(\n\tstate: LegacyData,\n\t{ from: sourceStoreName, to: scope }: { from: string; to: string },\n\tkey: string,\n\tconvert: ( preferences: ScopePreferences ) => object = identity\n): LegacyData {\n\tconst preferencesStoreName = 'core/preferences';\n\tconst sourcePreference = state?.[ sourceStoreName ]?.preferences?.[ key ];\n\n\t// There's nothing to migrate, exit early.\n\tif ( sourcePreference === undefined ) {\n\t\treturn state;\n\t}\n\n\tconst targetPreference =\n\t\tstate?.[ preferencesStoreName ]?.preferences?.[ scope ]?.[ key ];\n\n\t// There's existing data at the target, so don't overwrite it, exit early.\n\tif ( targetPreference ) {\n\t\treturn state;\n\t}\n\n\tconst otherScopes = state?.[ preferencesStoreName ]?.preferences;\n\tconst otherPreferences =\n\t\tstate?.[ preferencesStoreName ]?.preferences?.[ scope ];\n\n\tconst otherSourceState = state?.[ sourceStoreName ];\n\tconst allSourcePreferences = state?.[ sourceStoreName ]?.preferences;\n\n\t// Pass an object with the key and value as this allows the convert\n\t// function to convert to a data structure that has different keys.\n\tconst convertedPreferences = convert( { [ key ]: sourcePreference } );\n\n\treturn {\n\t\t...state,\n\t\t[ preferencesStoreName ]: {\n\t\t\tpreferences: {\n\t\t\t\t...otherScopes,\n\t\t\t\t[ scope ]: {\n\t\t\t\t\t...otherPreferences,\n\t\t\t\t\t...convertedPreferences,\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t\t[ sourceStoreName ]: {\n\t\t\t...otherSourceState,\n\t\t\tpreferences: {\n\t\t\t\t...allSourcePreferences,\n\t\t\t\t[ key ]: undefined,\n\t\t\t},\n\t\t},\n\t};\n}\n"],"mappings":";;;;;;AAGA,MAAM,YAAkB,QAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqCpC,SAAwB,sCACvB,OACA,EAAE,MAAM,iBAAiB,IAAI,SAC7B,KACA,UAAuD,UAC1C;CACb,MAAM,uBAAuB;CAC7B,MAAM,mBAAmB,QAAS,gBAAiB,EAAE,cAAe;CAGpE,IAAK,qBAAqB,KAAA,GACzB,OAAO;CAOR,IAHC,QAAS,qBAAsB,EAAE,cAAe,MAAO,GAAI,MAI3D,OAAO;CAGR,MAAM,cAAc,QAAS,qBAAsB,EAAE;CACrD,MAAM,mBACL,QAAS,qBAAsB,EAAE,cAAe;CAEjD,MAAM,mBAAmB,QAAS;CAClC,MAAM,uBAAuB,QAAS,gBAAiB,EAAE;CAIzD,MAAM,uBAAuB,QAAS,GAAI,MAAO,iBAAiB,CAAE;CAEpE,OAAO;EACN,GAAG;GACD,uBAAwB,EACzB,aAAa;GACZ,GAAG;IACD,QAAS;IACV,GAAG;IACH,GAAG;GACJ;EACD,EACD;GACE,kBAAmB;GACpB,GAAG;GACH,aAAa;IACZ,GAAG;KACD,MAAO,KAAA;GACV;EACD;CACD;AACD"}
@@ -1,79 +1,96 @@
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/migrations/legacy-local-storage-data/move-interface-enable-items.ts
21
- var move_interface_enable_items_exports = {};
22
- __export(move_interface_enable_items_exports, {
23
- default: () => moveInterfaceEnableItems
2
+ Object.defineProperties(exports, {
3
+ __esModule: { value: true },
4
+ [Symbol.toStringTag]: { value: "Module" }
24
5
  });
25
- module.exports = __toCommonJS(move_interface_enable_items_exports);
6
+ // packages/preferences-persistence/src/migrations/legacy-local-storage-data/move-interface-enable-items.ts
7
+ /**
8
+ * Migrates interface 'enableItems' data to the preferences store.
9
+ *
10
+ * The interface package stores this data in this format:
11
+ * ```js
12
+ * {
13
+ * enableItems: {
14
+ * singleEnableItems: {
15
+ * complementaryArea: {
16
+ * 'core/edit-post': 'edit-post/document',
17
+ * 'core/edit-site': 'edit-site/global-styles',
18
+ * }
19
+ * },
20
+ * multipleEnableItems: {
21
+ * pinnedItems: {
22
+ * 'core/edit-post': {
23
+ * 'plugin-1': true,
24
+ * },
25
+ * 'core/edit-site': {
26
+ * 'plugin-2': true,
27
+ * },
28
+ * },
29
+ * }
30
+ * }
31
+ * }
32
+ * ```
33
+ *
34
+ * and it should be converted it to:
35
+ * ```js
36
+ * {
37
+ * 'core/edit-post': {
38
+ * complementaryArea: 'edit-post/document',
39
+ * pinnedItems: {
40
+ * 'plugin-1': true,
41
+ * },
42
+ * },
43
+ * 'core/edit-site': {
44
+ * complementaryArea: 'edit-site/global-styles',
45
+ * pinnedItems: {
46
+ * 'plugin-2': true,
47
+ * },
48
+ * },
49
+ * }
50
+ * ```
51
+ *
52
+ * @param state The local storage state.
53
+ */
26
54
  function moveInterfaceEnableItems(state) {
27
- const interfaceStoreName = "core/interface";
28
- const preferencesStoreName = "core/preferences";
29
- const sourceEnableItems = state?.[interfaceStoreName]?.enableItems;
30
- if (!sourceEnableItems) {
31
- return state;
32
- }
33
- const allPreferences = state?.[preferencesStoreName]?.preferences ?? {};
34
- const sourceComplementaryAreas = sourceEnableItems?.singleEnableItems?.complementaryArea ?? {};
35
- const preferencesWithConvertedComplementaryAreas = Object.keys(
36
- sourceComplementaryAreas
37
- ).reduce((accumulator, scope) => {
38
- const data = sourceComplementaryAreas[scope];
39
- if (accumulator?.[scope]?.complementaryArea) {
40
- return accumulator;
41
- }
42
- return {
43
- ...accumulator,
44
- [scope]: {
45
- ...accumulator[scope],
46
- complementaryArea: data
47
- }
48
- };
49
- }, allPreferences);
50
- const sourcePinnedItems = sourceEnableItems?.multipleEnableItems?.pinnedItems ?? {};
51
- const allConvertedData = Object.keys(sourcePinnedItems).reduce(
52
- (accumulator, scope) => {
53
- const data = sourcePinnedItems[scope];
54
- if (accumulator?.[scope]?.pinnedItems) {
55
- return accumulator;
56
- }
57
- return {
58
- ...accumulator,
59
- [scope]: {
60
- ...accumulator[scope],
61
- pinnedItems: data
62
- }
63
- };
64
- },
65
- preferencesWithConvertedComplementaryAreas
66
- );
67
- const otherInterfaceItems = state[interfaceStoreName];
68
- return {
69
- ...state,
70
- [preferencesStoreName]: {
71
- preferences: allConvertedData
72
- },
73
- [interfaceStoreName]: {
74
- ...otherInterfaceItems,
75
- enableItems: void 0
76
- }
77
- };
55
+ const interfaceStoreName = "core/interface";
56
+ const preferencesStoreName = "core/preferences";
57
+ const sourceEnableItems = state?.[interfaceStoreName]?.enableItems;
58
+ if (!sourceEnableItems) return state;
59
+ const allPreferences = state?.[preferencesStoreName]?.preferences ?? {};
60
+ const sourceComplementaryAreas = sourceEnableItems?.singleEnableItems?.complementaryArea ?? {};
61
+ const preferencesWithConvertedComplementaryAreas = Object.keys(sourceComplementaryAreas).reduce((accumulator, scope) => {
62
+ const data = sourceComplementaryAreas[scope];
63
+ if (accumulator?.[scope]?.complementaryArea) return accumulator;
64
+ return {
65
+ ...accumulator,
66
+ [scope]: {
67
+ ...accumulator[scope],
68
+ complementaryArea: data
69
+ }
70
+ };
71
+ }, allPreferences);
72
+ const sourcePinnedItems = sourceEnableItems?.multipleEnableItems?.pinnedItems ?? {};
73
+ const allConvertedData = Object.keys(sourcePinnedItems).reduce((accumulator, scope) => {
74
+ const data = sourcePinnedItems[scope];
75
+ if (accumulator?.[scope]?.pinnedItems) return accumulator;
76
+ return {
77
+ ...accumulator,
78
+ [scope]: {
79
+ ...accumulator[scope],
80
+ pinnedItems: data
81
+ }
82
+ };
83
+ }, preferencesWithConvertedComplementaryAreas);
84
+ const otherInterfaceItems = state[interfaceStoreName];
85
+ return {
86
+ ...state,
87
+ [preferencesStoreName]: { preferences: allConvertedData },
88
+ [interfaceStoreName]: {
89
+ ...otherInterfaceItems,
90
+ enableItems: void 0
91
+ }
92
+ };
78
93
  }
79
- //# sourceMappingURL=move-interface-enable-items.cjs.map
94
+ exports.default = moveInterfaceEnableItems;
95
+
96
+ //# sourceMappingURL=move-interface-enable-items.cjs.map
@@ -1,7 +1 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/migrations/legacy-local-storage-data/move-interface-enable-items.ts"],
4
- "sourcesContent": ["import type { LegacyData } from './types';\n\n/**\n * Migrates interface 'enableItems' data to the preferences store.\n *\n * The interface package stores this data in this format:\n * ```js\n * {\n * enableItems: {\n * singleEnableItems: {\n * \t complementaryArea: {\n * 'core/edit-post': 'edit-post/document',\n * 'core/edit-site': 'edit-site/global-styles',\n * }\n * },\n * multipleEnableItems: {\n * pinnedItems: {\n * 'core/edit-post': {\n * 'plugin-1': true,\n * },\n * 'core/edit-site': {\n * 'plugin-2': true,\n * },\n * },\n * }\n * }\n * }\n * ```\n *\n * and it should be converted it to:\n * ```js\n * {\n * 'core/edit-post': {\n * complementaryArea: 'edit-post/document',\n * pinnedItems: {\n * 'plugin-1': true,\n * },\n * },\n * 'core/edit-site': {\n * complementaryArea: 'edit-site/global-styles',\n * pinnedItems: {\n * 'plugin-2': true,\n * },\n * },\n * }\n * ```\n *\n * @param state The local storage state.\n */\nexport default function moveInterfaceEnableItems(\n\tstate: LegacyData\n): LegacyData {\n\tconst interfaceStoreName = 'core/interface';\n\tconst preferencesStoreName = 'core/preferences';\n\tconst sourceEnableItems = state?.[ interfaceStoreName ]?.enableItems;\n\n\t// There's nothing to migrate, exit early.\n\tif ( ! sourceEnableItems ) {\n\t\treturn state;\n\t}\n\n\tconst allPreferences = state?.[ preferencesStoreName ]?.preferences ?? {};\n\n\t// First convert complementaryAreas into the right format.\n\t// Use the existing preferences as the accumulator so that the data is\n\t// merged.\n\tconst sourceComplementaryAreas =\n\t\tsourceEnableItems?.singleEnableItems?.complementaryArea ?? {};\n\n\tconst preferencesWithConvertedComplementaryAreas = Object.keys(\n\t\tsourceComplementaryAreas\n\t).reduce( ( accumulator, scope ) => {\n\t\tconst data = sourceComplementaryAreas[ scope ];\n\n\t\t// Don't overwrite any existing data in the preferences store.\n\t\tif ( accumulator?.[ scope ]?.complementaryArea ) {\n\t\t\treturn accumulator;\n\t\t}\n\n\t\treturn {\n\t\t\t...accumulator,\n\t\t\t[ scope ]: {\n\t\t\t\t...accumulator[ scope ],\n\t\t\t\tcomplementaryArea: data,\n\t\t\t},\n\t\t};\n\t}, allPreferences );\n\n\t// Next feed the converted complementary areas back into a reducer that\n\t// converts the pinned items, resulting in the fully migrated data.\n\tconst sourcePinnedItems =\n\t\tsourceEnableItems?.multipleEnableItems?.pinnedItems ?? {};\n\tconst allConvertedData = Object.keys( sourcePinnedItems ).reduce(\n\t\t( accumulator, scope ) => {\n\t\t\tconst data = sourcePinnedItems[ scope ];\n\t\t\t// Don't overwrite any existing data in the preferences store.\n\t\t\tif ( accumulator?.[ scope ]?.pinnedItems ) {\n\t\t\t\treturn accumulator;\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\t...accumulator,\n\t\t\t\t[ scope ]: {\n\t\t\t\t\t...accumulator[ scope ],\n\t\t\t\t\tpinnedItems: data,\n\t\t\t\t},\n\t\t\t};\n\t\t},\n\t\tpreferencesWithConvertedComplementaryAreas\n\t);\n\n\tconst otherInterfaceItems = state[ interfaceStoreName ];\n\n\treturn {\n\t\t...state,\n\t\t[ preferencesStoreName ]: {\n\t\t\tpreferences: allConvertedData,\n\t\t},\n\t\t[ interfaceStoreName ]: {\n\t\t\t...otherInterfaceItems,\n\t\t\tenableItems: undefined,\n\t\t},\n\t};\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAiDe,SAAR,yBACN,OACa;AACb,QAAM,qBAAqB;AAC3B,QAAM,uBAAuB;AAC7B,QAAM,oBAAoB,QAAS,kBAAmB,GAAG;AAGzD,MAAK,CAAE,mBAAoB;AAC1B,WAAO;AAAA,EACR;AAEA,QAAM,iBAAiB,QAAS,oBAAqB,GAAG,eAAe,CAAC;AAKxE,QAAM,2BACL,mBAAmB,mBAAmB,qBAAqB,CAAC;AAE7D,QAAM,6CAA6C,OAAO;AAAA,IACzD;AAAA,EACD,EAAE,OAAQ,CAAE,aAAa,UAAW;AACnC,UAAM,OAAO,yBAA0B,KAAM;AAG7C,QAAK,cAAe,KAAM,GAAG,mBAAoB;AAChD,aAAO;AAAA,IACR;AAEA,WAAO;AAAA,MACN,GAAG;AAAA,MACH,CAAE,KAAM,GAAG;AAAA,QACV,GAAG,YAAa,KAAM;AAAA,QACtB,mBAAmB;AAAA,MACpB;AAAA,IACD;AAAA,EACD,GAAG,cAAe;AAIlB,QAAM,oBACL,mBAAmB,qBAAqB,eAAe,CAAC;AACzD,QAAM,mBAAmB,OAAO,KAAM,iBAAkB,EAAE;AAAA,IACzD,CAAE,aAAa,UAAW;AACzB,YAAM,OAAO,kBAAmB,KAAM;AAEtC,UAAK,cAAe,KAAM,GAAG,aAAc;AAC1C,eAAO;AAAA,MACR;AAEA,aAAO;AAAA,QACN,GAAG;AAAA,QACH,CAAE,KAAM,GAAG;AAAA,UACV,GAAG,YAAa,KAAM;AAAA,UACtB,aAAa;AAAA,QACd;AAAA,MACD;AAAA,IACD;AAAA,IACA;AAAA,EACD;AAEA,QAAM,sBAAsB,MAAO,kBAAmB;AAEtD,SAAO;AAAA,IACN,GAAG;AAAA,IACH,CAAE,oBAAqB,GAAG;AAAA,MACzB,aAAa;AAAA,IACd;AAAA,IACA,CAAE,kBAAmB,GAAG;AAAA,MACvB,GAAG;AAAA,MACH,aAAa;AAAA,IACd;AAAA,EACD;AACD;",
6
- "names": []
7
- }
1
+ {"version":3,"file":"move-interface-enable-items.cjs","names":[],"sources":["../../../src/migrations/legacy-local-storage-data/move-interface-enable-items.ts"],"sourcesContent":["import type { LegacyData } from './types';\n\n/**\n * Migrates interface 'enableItems' data to the preferences store.\n *\n * The interface package stores this data in this format:\n * ```js\n * {\n * enableItems: {\n * singleEnableItems: {\n * \t complementaryArea: {\n * 'core/edit-post': 'edit-post/document',\n * 'core/edit-site': 'edit-site/global-styles',\n * }\n * },\n * multipleEnableItems: {\n * pinnedItems: {\n * 'core/edit-post': {\n * 'plugin-1': true,\n * },\n * 'core/edit-site': {\n * 'plugin-2': true,\n * },\n * },\n * }\n * }\n * }\n * ```\n *\n * and it should be converted it to:\n * ```js\n * {\n * 'core/edit-post': {\n * complementaryArea: 'edit-post/document',\n * pinnedItems: {\n * 'plugin-1': true,\n * },\n * },\n * 'core/edit-site': {\n * complementaryArea: 'edit-site/global-styles',\n * pinnedItems: {\n * 'plugin-2': true,\n * },\n * },\n * }\n * ```\n *\n * @param state The local storage state.\n */\nexport default function moveInterfaceEnableItems(\n\tstate: LegacyData\n): LegacyData {\n\tconst interfaceStoreName = 'core/interface';\n\tconst preferencesStoreName = 'core/preferences';\n\tconst sourceEnableItems = state?.[ interfaceStoreName ]?.enableItems;\n\n\t// There's nothing to migrate, exit early.\n\tif ( ! sourceEnableItems ) {\n\t\treturn state;\n\t}\n\n\tconst allPreferences = state?.[ preferencesStoreName ]?.preferences ?? {};\n\n\t// First convert complementaryAreas into the right format.\n\t// Use the existing preferences as the accumulator so that the data is\n\t// merged.\n\tconst sourceComplementaryAreas =\n\t\tsourceEnableItems?.singleEnableItems?.complementaryArea ?? {};\n\n\tconst preferencesWithConvertedComplementaryAreas = Object.keys(\n\t\tsourceComplementaryAreas\n\t).reduce( ( accumulator, scope ) => {\n\t\tconst data = sourceComplementaryAreas[ scope ];\n\n\t\t// Don't overwrite any existing data in the preferences store.\n\t\tif ( accumulator?.[ scope ]?.complementaryArea ) {\n\t\t\treturn accumulator;\n\t\t}\n\n\t\treturn {\n\t\t\t...accumulator,\n\t\t\t[ scope ]: {\n\t\t\t\t...accumulator[ scope ],\n\t\t\t\tcomplementaryArea: data,\n\t\t\t},\n\t\t};\n\t}, allPreferences );\n\n\t// Next feed the converted complementary areas back into a reducer that\n\t// converts the pinned items, resulting in the fully migrated data.\n\tconst sourcePinnedItems =\n\t\tsourceEnableItems?.multipleEnableItems?.pinnedItems ?? {};\n\tconst allConvertedData = Object.keys( sourcePinnedItems ).reduce(\n\t\t( accumulator, scope ) => {\n\t\t\tconst data = sourcePinnedItems[ scope ];\n\t\t\t// Don't overwrite any existing data in the preferences store.\n\t\t\tif ( accumulator?.[ scope ]?.pinnedItems ) {\n\t\t\t\treturn accumulator;\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\t...accumulator,\n\t\t\t\t[ scope ]: {\n\t\t\t\t\t...accumulator[ scope ],\n\t\t\t\t\tpinnedItems: data,\n\t\t\t\t},\n\t\t\t};\n\t\t},\n\t\tpreferencesWithConvertedComplementaryAreas\n\t);\n\n\tconst otherInterfaceItems = state[ interfaceStoreName ];\n\n\treturn {\n\t\t...state,\n\t\t[ preferencesStoreName ]: {\n\t\t\tpreferences: allConvertedData,\n\t\t},\n\t\t[ interfaceStoreName ]: {\n\t\t\t...otherInterfaceItems,\n\t\t\tenableItems: undefined,\n\t\t},\n\t};\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiDA,SAAwB,yBACvB,OACa;CACb,MAAM,qBAAqB;CAC3B,MAAM,uBAAuB;CAC7B,MAAM,oBAAoB,QAAS,mBAAoB,EAAE;CAGzD,IAAK,CAAE,mBACN,OAAO;CAGR,MAAM,iBAAiB,QAAS,qBAAsB,EAAE,eAAe,CAAC;CAKxE,MAAM,2BACL,mBAAmB,mBAAmB,qBAAqB,CAAC;CAE7D,MAAM,6CAA6C,OAAO,KACzD,wBACD,CAAC,CAAC,QAAU,aAAa,UAAW;EACnC,MAAM,OAAO,yBAA0B;EAGvC,IAAK,cAAe,MAAO,EAAE,mBAC5B,OAAO;EAGR,OAAO;GACN,GAAG;IACD,QAAS;IACV,GAAG,YAAa;IAChB,mBAAmB;GACpB;EACD;CACD,GAAG,cAAe;CAIlB,MAAM,oBACL,mBAAmB,qBAAqB,eAAe,CAAC;CACzD,MAAM,mBAAmB,OAAO,KAAM,iBAAkB,CAAC,CAAC,QACvD,aAAa,UAAW;EACzB,MAAM,OAAO,kBAAmB;EAEhC,IAAK,cAAe,MAAO,EAAE,aAC5B,OAAO;EAGR,OAAO;GACN,GAAG;IACD,QAAS;IACV,GAAG,YAAa;IAChB,aAAa;GACd;EACD;CACD,GACA,0CACD;CAEA,MAAM,sBAAsB,MAAO;CAEnC,OAAO;EACN,GAAG;GACD,uBAAwB,EACzB,aAAa,iBACd;GACE,qBAAsB;GACvB,GAAG;GACH,aAAa,KAAA;EACd;CACD;AACD"}