@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,7 +1 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/migrations/legacy-local-storage-data/index.ts"],
4
- "sourcesContent": ["import moveFeaturePreferences from './move-feature-preferences';\nimport moveThirdPartyFeaturePreferences from './move-third-party-feature-preferences';\nimport moveIndividualPreference from './move-individual-preference';\nimport moveInterfaceEnableItems from './move-interface-enable-items';\nimport convertEditPostPanels from './convert-edit-post-panels';\nimport isPreferencesData from '../../is-preferences-data';\nimport { readStoredJSON } from '../../local-storage';\nimport type { ScopedPreferences } from '../../types';\nimport type { LegacyData } from './types';\n\n/**\n * Gets the legacy local storage data for a given user.\n *\n * @param userId The user id.\n *\n * @return The local storage data.\n */\nfunction getLegacyData( userId: string | number ): LegacyData | null {\n\treturn readStoredJSON( `WP_DATA_USER_${ userId }` ) as LegacyData | null;\n}\n\n/**\n * Converts data from the old `@wordpress/data` package format.\n *\n * @param data The legacy data in its original format.\n *\n * @return The converted data or `undefined` if there was\n * nothing to convert.\n */\nexport function convertLegacyData(\n\tdata: LegacyData | null | undefined\n): ScopedPreferences | undefined {\n\tif ( ! data ) {\n\t\treturn;\n\t}\n\n\t// Move boolean feature preferences from each editor into the\n\t// preferences store data structure.\n\tdata = moveFeaturePreferences( data, 'core/edit-widgets' );\n\tdata = moveFeaturePreferences( data, 'core/customize-widgets' );\n\tdata = moveFeaturePreferences( data, 'core/edit-post' );\n\tdata = moveFeaturePreferences( data, 'core/edit-site' );\n\n\t// Move third party boolean feature preferences from the interface package\n\t// to the preferences store data structure.\n\tdata = moveThirdPartyFeaturePreferences( data );\n\n\t// Move and convert the interface store's `enableItems` data into the\n\t// preferences data structure.\n\tdata = moveInterfaceEnableItems( data );\n\n\t// Move individual ad-hoc preferences from various packages into the\n\t// preferences store data structure.\n\tdata = moveIndividualPreference(\n\t\tdata,\n\t\t{ from: 'core/edit-post', to: 'core/edit-post' },\n\t\t'hiddenBlockTypes'\n\t);\n\tdata = moveIndividualPreference(\n\t\tdata,\n\t\t{ from: 'core/edit-post', to: 'core/edit-post' },\n\t\t'editorMode'\n\t);\n\tdata = moveIndividualPreference(\n\t\tdata,\n\t\t{ from: 'core/edit-post', to: 'core/edit-post' },\n\t\t'panels',\n\t\tconvertEditPostPanels\n\t);\n\tdata = moveIndividualPreference(\n\t\tdata,\n\t\t{ from: 'core/editor', to: 'core' },\n\t\t'isPublishSidebarEnabled'\n\t);\n\tdata = moveIndividualPreference(\n\t\tdata,\n\t\t{ from: 'core/edit-post', to: 'core' },\n\t\t'isPublishSidebarEnabled'\n\t);\n\tdata = moveIndividualPreference(\n\t\tdata,\n\t\t{ from: 'core/edit-site', to: 'core/edit-site' },\n\t\t'editorMode'\n\t);\n\n\t// The new system is only concerned with persisting\n\t// 'core/preferences' preferences reducer, so only return that.\n\tconst preferences = data?.[ 'core/preferences' ]?.preferences;\n\treturn isPreferencesData( preferences ) ? preferences : undefined;\n}\n\n/**\n * Gets the legacy local storage data for the given user and returns the\n * data converted to the new format.\n *\n * @param userId The user id.\n *\n * @return The converted data or undefined if no local\n * storage data could be found.\n */\nexport default function convertLegacyLocalStorageData(\n\tuserId: string | number\n): ScopedPreferences | undefined {\n\tconst data = getLegacyData( userId );\n\treturn convertLegacyData( data );\n}\n"],
5
- "mappings": ";AAAA,OAAO,4BAA4B;AACnC,OAAO,sCAAsC;AAC7C,OAAO,8BAA8B;AACrC,OAAO,8BAA8B;AACrC,OAAO,2BAA2B;AAClC,OAAO,uBAAuB;AAC9B,SAAS,sBAAsB;AAW/B,SAAS,cAAe,QAA6C;AACpE,SAAO,eAAgB,gBAAiB,MAAO,EAAG;AACnD;AAUO,SAAS,kBACf,MACgC;AAChC,MAAK,CAAE,MAAO;AACb;AAAA,EACD;AAIA,SAAO,uBAAwB,MAAM,mBAAoB;AACzD,SAAO,uBAAwB,MAAM,wBAAyB;AAC9D,SAAO,uBAAwB,MAAM,gBAAiB;AACtD,SAAO,uBAAwB,MAAM,gBAAiB;AAItD,SAAO,iCAAkC,IAAK;AAI9C,SAAO,yBAA0B,IAAK;AAItC,SAAO;AAAA,IACN;AAAA,IACA,EAAE,MAAM,kBAAkB,IAAI,iBAAiB;AAAA,IAC/C;AAAA,EACD;AACA,SAAO;AAAA,IACN;AAAA,IACA,EAAE,MAAM,kBAAkB,IAAI,iBAAiB;AAAA,IAC/C;AAAA,EACD;AACA,SAAO;AAAA,IACN;AAAA,IACA,EAAE,MAAM,kBAAkB,IAAI,iBAAiB;AAAA,IAC/C;AAAA,IACA;AAAA,EACD;AACA,SAAO;AAAA,IACN;AAAA,IACA,EAAE,MAAM,eAAe,IAAI,OAAO;AAAA,IAClC;AAAA,EACD;AACA,SAAO;AAAA,IACN;AAAA,IACA,EAAE,MAAM,kBAAkB,IAAI,OAAO;AAAA,IACrC;AAAA,EACD;AACA,SAAO;AAAA,IACN;AAAA,IACA,EAAE,MAAM,kBAAkB,IAAI,iBAAiB;AAAA,IAC/C;AAAA,EACD;AAIA,QAAM,cAAc,OAAQ,kBAAmB,GAAG;AAClD,SAAO,kBAAmB,WAAY,IAAI,cAAc;AACzD;AAWe,SAAR,8BACN,QACgC;AAChC,QAAM,OAAO,cAAe,MAAO;AACnC,SAAO,kBAAmB,IAAK;AAChC;",
6
- "names": []
7
- }
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../../../src/migrations/legacy-local-storage-data/index.ts"],"sourcesContent":["import moveFeaturePreferences from './move-feature-preferences';\nimport moveThirdPartyFeaturePreferences from './move-third-party-feature-preferences';\nimport moveIndividualPreference from './move-individual-preference';\nimport moveInterfaceEnableItems from './move-interface-enable-items';\nimport convertEditPostPanels from './convert-edit-post-panels';\nimport isPreferencesData from '../../is-preferences-data';\nimport { readStoredJSON } from '../../local-storage';\nimport type { ScopedPreferences } from '../../types';\nimport type { LegacyData } from './types';\n\n/**\n * Gets the legacy local storage data for a given user.\n *\n * @param userId The user id.\n *\n * @return The local storage data.\n */\nfunction getLegacyData( userId: string | number ): LegacyData | null {\n\treturn readStoredJSON( `WP_DATA_USER_${ userId }` ) as LegacyData | null;\n}\n\n/**\n * Converts data from the old `@wordpress/data` package format.\n *\n * @param data The legacy data in its original format.\n *\n * @return The converted data or `undefined` if there was\n * nothing to convert.\n */\nexport function convertLegacyData(\n\tdata: LegacyData | null | undefined\n): ScopedPreferences | undefined {\n\tif ( ! data ) {\n\t\treturn;\n\t}\n\n\t// Move boolean feature preferences from each editor into the\n\t// preferences store data structure.\n\tdata = moveFeaturePreferences( data, 'core/edit-widgets' );\n\tdata = moveFeaturePreferences( data, 'core/customize-widgets' );\n\tdata = moveFeaturePreferences( data, 'core/edit-post' );\n\tdata = moveFeaturePreferences( data, 'core/edit-site' );\n\n\t// Move third party boolean feature preferences from the interface package\n\t// to the preferences store data structure.\n\tdata = moveThirdPartyFeaturePreferences( data );\n\n\t// Move and convert the interface store's `enableItems` data into the\n\t// preferences data structure.\n\tdata = moveInterfaceEnableItems( data );\n\n\t// Move individual ad-hoc preferences from various packages into the\n\t// preferences store data structure.\n\tdata = moveIndividualPreference(\n\t\tdata,\n\t\t{ from: 'core/edit-post', to: 'core/edit-post' },\n\t\t'hiddenBlockTypes'\n\t);\n\tdata = moveIndividualPreference(\n\t\tdata,\n\t\t{ from: 'core/edit-post', to: 'core/edit-post' },\n\t\t'editorMode'\n\t);\n\tdata = moveIndividualPreference(\n\t\tdata,\n\t\t{ from: 'core/edit-post', to: 'core/edit-post' },\n\t\t'panels',\n\t\tconvertEditPostPanels\n\t);\n\tdata = moveIndividualPreference(\n\t\tdata,\n\t\t{ from: 'core/editor', to: 'core' },\n\t\t'isPublishSidebarEnabled'\n\t);\n\tdata = moveIndividualPreference(\n\t\tdata,\n\t\t{ from: 'core/edit-post', to: 'core' },\n\t\t'isPublishSidebarEnabled'\n\t);\n\tdata = moveIndividualPreference(\n\t\tdata,\n\t\t{ from: 'core/edit-site', to: 'core/edit-site' },\n\t\t'editorMode'\n\t);\n\n\t// The new system is only concerned with persisting\n\t// 'core/preferences' preferences reducer, so only return that.\n\tconst preferences = data?.[ 'core/preferences' ]?.preferences;\n\treturn isPreferencesData( preferences ) ? preferences : undefined;\n}\n\n/**\n * Gets the legacy local storage data for the given user and returns the\n * data converted to the new format.\n *\n * @param userId The user id.\n *\n * @return The converted data or undefined if no local\n * storage data could be found.\n */\nexport default function convertLegacyLocalStorageData(\n\tuserId: string | number\n): ScopedPreferences | undefined {\n\tconst data = getLegacyData( userId );\n\treturn convertLegacyData( data );\n}\n"],"mappings":";;;;;;;;;;;;;;;AAiBA,SAAS,cAAe,QAA6C;CACpE,OAAO,eAAgB,gBAAiB,QAAU;AACnD;;;;;;;;;AAUA,SAAgB,kBACf,MACgC;CAChC,IAAK,CAAE,MACN;CAKD,OAAO,uBAAwB,MAAM,mBAAoB;CACzD,OAAO,uBAAwB,MAAM,wBAAyB;CAC9D,OAAO,uBAAwB,MAAM,gBAAiB;CACtD,OAAO,uBAAwB,MAAM,gBAAiB;CAItD,OAAO,iCAAkC,IAAK;CAI9C,OAAO,yBAA0B,IAAK;CAItC,OAAO,yBACN,MACA;EAAE,MAAM;EAAkB,IAAI;CAAiB,GAC/C,kBACD;CACA,OAAO,yBACN,MACA;EAAE,MAAM;EAAkB,IAAI;CAAiB,GAC/C,YACD;CACA,OAAO,yBACN,MACA;EAAE,MAAM;EAAkB,IAAI;CAAiB,GAC/C,UACA,qBACD;CACA,OAAO,yBACN,MACA;EAAE,MAAM;EAAe,IAAI;CAAO,GAClC,yBACD;CACA,OAAO,yBACN,MACA;EAAE,MAAM;EAAkB,IAAI;CAAO,GACrC,yBACD;CACA,OAAO,yBACN,MACA;EAAE,MAAM;EAAkB,IAAI;CAAiB,GAC/C,YACD;CAIA,MAAM,cAAc,OAAQ,mBAAoB,EAAE;CAClD,OAAO,kBAAmB,WAAY,IAAI,cAAc,KAAA;AACzD;;;;;;;;;;AAWA,SAAwB,8BACvB,QACgC;CAEhC,OAAO,kBADM,cAAe,MACC,CAAE;AAChC"}
@@ -1,60 +1,104 @@
1
1
  // packages/preferences-persistence/src/migrations/legacy-local-storage-data/move-feature-preferences.ts
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
+ */
2
59
  function moveFeaturePreferences(state, sourceStoreName) {
3
- const preferencesStoreName = "core/preferences";
4
- const interfaceStoreName = "core/interface";
5
- const interfaceFeatures = state?.[interfaceStoreName]?.preferences?.features?.[sourceStoreName];
6
- const sourceFeatures = state?.[sourceStoreName]?.preferences?.features;
7
- const featuresToMigrate = interfaceFeatures ? interfaceFeatures : sourceFeatures;
8
- if (!featuresToMigrate) {
9
- return state;
10
- }
11
- const existingPreferences = state?.[preferencesStoreName]?.preferences;
12
- if (existingPreferences?.[sourceStoreName]) {
13
- return state;
14
- }
15
- let updatedInterfaceState;
16
- if (interfaceFeatures) {
17
- const otherInterfaceState = state?.[interfaceStoreName];
18
- const otherInterfaceScopes = state?.[interfaceStoreName]?.preferences?.features;
19
- updatedInterfaceState = {
20
- [interfaceStoreName]: {
21
- ...otherInterfaceState,
22
- preferences: {
23
- features: {
24
- ...otherInterfaceScopes,
25
- [sourceStoreName]: void 0
26
- }
27
- }
28
- }
29
- };
30
- }
31
- let updatedSourceState;
32
- if (sourceFeatures) {
33
- const otherSourceState = state?.[sourceStoreName];
34
- const sourcePreferences = state?.[sourceStoreName]?.preferences;
35
- updatedSourceState = {
36
- [sourceStoreName]: {
37
- ...otherSourceState,
38
- preferences: {
39
- ...sourcePreferences,
40
- features: void 0
41
- }
42
- }
43
- };
44
- }
45
- return {
46
- ...state,
47
- [preferencesStoreName]: {
48
- preferences: {
49
- ...existingPreferences,
50
- [sourceStoreName]: featuresToMigrate
51
- }
52
- },
53
- ...updatedInterfaceState,
54
- ...updatedSourceState
55
- };
60
+ const preferencesStoreName = "core/preferences";
61
+ const interfaceStoreName = "core/interface";
62
+ const interfaceFeatures = state?.[interfaceStoreName]?.preferences?.features?.[sourceStoreName];
63
+ const sourceFeatures = state?.[sourceStoreName]?.preferences?.features;
64
+ const featuresToMigrate = interfaceFeatures ? interfaceFeatures : sourceFeatures;
65
+ if (!featuresToMigrate) return state;
66
+ const existingPreferences = state?.[preferencesStoreName]?.preferences;
67
+ if (existingPreferences?.[sourceStoreName]) return state;
68
+ let updatedInterfaceState;
69
+ if (interfaceFeatures) {
70
+ const otherInterfaceState = state?.[interfaceStoreName];
71
+ const otherInterfaceScopes = state?.[interfaceStoreName]?.preferences?.features;
72
+ updatedInterfaceState = { [interfaceStoreName]: {
73
+ ...otherInterfaceState,
74
+ preferences: { features: {
75
+ ...otherInterfaceScopes,
76
+ [sourceStoreName]: void 0
77
+ } }
78
+ } };
79
+ }
80
+ let updatedSourceState;
81
+ if (sourceFeatures) {
82
+ const otherSourceState = state?.[sourceStoreName];
83
+ const sourcePreferences = state?.[sourceStoreName]?.preferences;
84
+ updatedSourceState = { [sourceStoreName]: {
85
+ ...otherSourceState,
86
+ preferences: {
87
+ ...sourcePreferences,
88
+ features: void 0
89
+ }
90
+ } };
91
+ }
92
+ return {
93
+ ...state,
94
+ [preferencesStoreName]: { preferences: {
95
+ ...existingPreferences,
96
+ [sourceStoreName]: featuresToMigrate
97
+ } },
98
+ ...updatedInterfaceState,
99
+ ...updatedSourceState
100
+ };
56
101
  }
57
- export {
58
- moveFeaturePreferences as default
59
- };
60
- //# sourceMappingURL=move-feature-preferences.mjs.map
102
+ export { moveFeaturePreferences as default };
103
+
104
+ //# sourceMappingURL=move-feature-preferences.mjs.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": ";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.mjs","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,41 +1,68 @@
1
1
  // packages/preferences-persistence/src/migrations/legacy-local-storage-data/move-individual-preference.ts
2
- var identity = (arg) => arg;
2
+ const identity = (arg) => arg;
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
+ */
3
38
  function moveIndividualPreferenceToPreferences(state, { from: sourceStoreName, to: scope }, key, convert = identity) {
4
- const preferencesStoreName = "core/preferences";
5
- const sourcePreference = state?.[sourceStoreName]?.preferences?.[key];
6
- if (sourcePreference === void 0) {
7
- return state;
8
- }
9
- const targetPreference = state?.[preferencesStoreName]?.preferences?.[scope]?.[key];
10
- if (targetPreference) {
11
- return state;
12
- }
13
- const otherScopes = state?.[preferencesStoreName]?.preferences;
14
- const otherPreferences = state?.[preferencesStoreName]?.preferences?.[scope];
15
- const otherSourceState = state?.[sourceStoreName];
16
- const allSourcePreferences = state?.[sourceStoreName]?.preferences;
17
- const convertedPreferences = convert({ [key]: sourcePreference });
18
- return {
19
- ...state,
20
- [preferencesStoreName]: {
21
- preferences: {
22
- ...otherScopes,
23
- [scope]: {
24
- ...otherPreferences,
25
- ...convertedPreferences
26
- }
27
- }
28
- },
29
- [sourceStoreName]: {
30
- ...otherSourceState,
31
- preferences: {
32
- ...allSourcePreferences,
33
- [key]: void 0
34
- }
35
- }
36
- };
39
+ const preferencesStoreName = "core/preferences";
40
+ const sourcePreference = state?.[sourceStoreName]?.preferences?.[key];
41
+ if (sourcePreference === void 0) return state;
42
+ if (state?.[preferencesStoreName]?.preferences?.[scope]?.[key]) return state;
43
+ const otherScopes = state?.[preferencesStoreName]?.preferences;
44
+ const otherPreferences = state?.[preferencesStoreName]?.preferences?.[scope];
45
+ const otherSourceState = state?.[sourceStoreName];
46
+ const allSourcePreferences = state?.[sourceStoreName]?.preferences;
47
+ const convertedPreferences = convert({ [key]: sourcePreference });
48
+ return {
49
+ ...state,
50
+ [preferencesStoreName]: { preferences: {
51
+ ...otherScopes,
52
+ [scope]: {
53
+ ...otherPreferences,
54
+ ...convertedPreferences
55
+ }
56
+ } },
57
+ [sourceStoreName]: {
58
+ ...otherSourceState,
59
+ preferences: {
60
+ ...allSourcePreferences,
61
+ [key]: void 0
62
+ }
63
+ }
64
+ };
37
65
  }
38
- export {
39
- moveIndividualPreferenceToPreferences as default
40
- };
41
- //# sourceMappingURL=move-individual-preference.mjs.map
66
+ export { moveIndividualPreferenceToPreferences as default };
67
+
68
+ //# sourceMappingURL=move-individual-preference.mjs.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": ";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.mjs","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,58 +1,91 @@
1
1
  // packages/preferences-persistence/src/migrations/legacy-local-storage-data/move-interface-enable-items.ts
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
+ */
2
49
  function moveInterfaceEnableItems(state) {
3
- const interfaceStoreName = "core/interface";
4
- const preferencesStoreName = "core/preferences";
5
- const sourceEnableItems = state?.[interfaceStoreName]?.enableItems;
6
- if (!sourceEnableItems) {
7
- return state;
8
- }
9
- const allPreferences = state?.[preferencesStoreName]?.preferences ?? {};
10
- const sourceComplementaryAreas = sourceEnableItems?.singleEnableItems?.complementaryArea ?? {};
11
- const preferencesWithConvertedComplementaryAreas = Object.keys(
12
- sourceComplementaryAreas
13
- ).reduce((accumulator, scope) => {
14
- const data = sourceComplementaryAreas[scope];
15
- if (accumulator?.[scope]?.complementaryArea) {
16
- return accumulator;
17
- }
18
- return {
19
- ...accumulator,
20
- [scope]: {
21
- ...accumulator[scope],
22
- complementaryArea: data
23
- }
24
- };
25
- }, allPreferences);
26
- const sourcePinnedItems = sourceEnableItems?.multipleEnableItems?.pinnedItems ?? {};
27
- const allConvertedData = Object.keys(sourcePinnedItems).reduce(
28
- (accumulator, scope) => {
29
- const data = sourcePinnedItems[scope];
30
- if (accumulator?.[scope]?.pinnedItems) {
31
- return accumulator;
32
- }
33
- return {
34
- ...accumulator,
35
- [scope]: {
36
- ...accumulator[scope],
37
- pinnedItems: data
38
- }
39
- };
40
- },
41
- preferencesWithConvertedComplementaryAreas
42
- );
43
- const otherInterfaceItems = state[interfaceStoreName];
44
- return {
45
- ...state,
46
- [preferencesStoreName]: {
47
- preferences: allConvertedData
48
- },
49
- [interfaceStoreName]: {
50
- ...otherInterfaceItems,
51
- enableItems: void 0
52
- }
53
- };
50
+ const interfaceStoreName = "core/interface";
51
+ const preferencesStoreName = "core/preferences";
52
+ const sourceEnableItems = state?.[interfaceStoreName]?.enableItems;
53
+ if (!sourceEnableItems) return state;
54
+ const allPreferences = state?.[preferencesStoreName]?.preferences ?? {};
55
+ const sourceComplementaryAreas = sourceEnableItems?.singleEnableItems?.complementaryArea ?? {};
56
+ const preferencesWithConvertedComplementaryAreas = Object.keys(sourceComplementaryAreas).reduce((accumulator, scope) => {
57
+ const data = sourceComplementaryAreas[scope];
58
+ if (accumulator?.[scope]?.complementaryArea) return accumulator;
59
+ return {
60
+ ...accumulator,
61
+ [scope]: {
62
+ ...accumulator[scope],
63
+ complementaryArea: data
64
+ }
65
+ };
66
+ }, allPreferences);
67
+ const sourcePinnedItems = sourceEnableItems?.multipleEnableItems?.pinnedItems ?? {};
68
+ const allConvertedData = Object.keys(sourcePinnedItems).reduce((accumulator, scope) => {
69
+ const data = sourcePinnedItems[scope];
70
+ if (accumulator?.[scope]?.pinnedItems) return accumulator;
71
+ return {
72
+ ...accumulator,
73
+ [scope]: {
74
+ ...accumulator[scope],
75
+ pinnedItems: data
76
+ }
77
+ };
78
+ }, preferencesWithConvertedComplementaryAreas);
79
+ const otherInterfaceItems = state[interfaceStoreName];
80
+ return {
81
+ ...state,
82
+ [preferencesStoreName]: { preferences: allConvertedData },
83
+ [interfaceStoreName]: {
84
+ ...otherInterfaceItems,
85
+ enableItems: void 0
86
+ }
87
+ };
54
88
  }
55
- export {
56
- moveInterfaceEnableItems as default
57
- };
58
- //# sourceMappingURL=move-interface-enable-items.mjs.map
89
+ export { moveInterfaceEnableItems as default };
90
+
91
+ //# sourceMappingURL=move-interface-enable-items.mjs.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": ";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.mjs","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"}