@wordpress/preferences-persistence 1.0.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 (58) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/LICENSE.md +788 -0
  3. package/README.md +59 -0
  4. package/build/create/debounce-async.js +80 -0
  5. package/build/create/debounce-async.js.map +1 -0
  6. package/build/create/index.js +115 -0
  7. package/build/create/index.js.map +1 -0
  8. package/build/index.js +61 -0
  9. package/build/index.js.map +1 -0
  10. package/build/migrations/legacy-local-storage-data/convert-edit-post-panels.js +60 -0
  11. package/build/migrations/legacy-local-storage-data/convert-edit-post-panels.js.map +1 -0
  12. package/build/migrations/legacy-local-storage-data/index.js +111 -0
  13. package/build/migrations/legacy-local-storage-data/index.js.map +1 -0
  14. package/build/migrations/legacy-local-storage-data/move-feature-preferences.js +135 -0
  15. package/build/migrations/legacy-local-storage-data/move-feature-preferences.js.map +1 -0
  16. package/build/migrations/legacy-local-storage-data/move-individual-preference.js +91 -0
  17. package/build/migrations/legacy-local-storage-data/move-individual-preference.js.map +1 -0
  18. package/build/migrations/legacy-local-storage-data/move-interface-enable-items.js +114 -0
  19. package/build/migrations/legacy-local-storage-data/move-interface-enable-items.js.map +1 -0
  20. package/build/migrations/legacy-local-storage-data/move-third-party-feature-preferences.js +99 -0
  21. package/build/migrations/legacy-local-storage-data/move-third-party-feature-preferences.js.map +1 -0
  22. package/build-module/create/debounce-async.js +73 -0
  23. package/build-module/create/debounce-async.js.map +1 -0
  24. package/build-module/create/index.js +104 -0
  25. package/build-module/create/index.js.map +1 -0
  26. package/build-module/index.js +45 -0
  27. package/build-module/index.js.map +1 -0
  28. package/build-module/migrations/legacy-local-storage-data/convert-edit-post-panels.js +53 -0
  29. package/build-module/migrations/legacy-local-storage-data/convert-edit-post-panels.js.map +1 -0
  30. package/build-module/migrations/legacy-local-storage-data/index.js +95 -0
  31. package/build-module/migrations/legacy-local-storage-data/index.js.map +1 -0
  32. package/build-module/migrations/legacy-local-storage-data/move-feature-preferences.js +128 -0
  33. package/build-module/migrations/legacy-local-storage-data/move-feature-preferences.js.map +1 -0
  34. package/build-module/migrations/legacy-local-storage-data/move-individual-preference.js +84 -0
  35. package/build-module/migrations/legacy-local-storage-data/move-individual-preference.js.map +1 -0
  36. package/build-module/migrations/legacy-local-storage-data/move-interface-enable-items.js +107 -0
  37. package/build-module/migrations/legacy-local-storage-data/move-interface-enable-items.js.map +1 -0
  38. package/build-module/migrations/legacy-local-storage-data/move-third-party-feature-preferences.js +92 -0
  39. package/build-module/migrations/legacy-local-storage-data/move-third-party-feature-preferences.js.map +1 -0
  40. package/package.json +37 -0
  41. package/src/create/debounce-async.js +75 -0
  42. package/src/create/index.js +112 -0
  43. package/src/create/test/debounce-async.js +129 -0
  44. package/src/create/test/index.js +178 -0
  45. package/src/index.js +49 -0
  46. package/src/migrations/legacy-local-storage-data/README.md +42 -0
  47. package/src/migrations/legacy-local-storage-data/convert-edit-post-panels.js +50 -0
  48. package/src/migrations/legacy-local-storage-data/index.js +102 -0
  49. package/src/migrations/legacy-local-storage-data/move-feature-preferences.js +135 -0
  50. package/src/migrations/legacy-local-storage-data/move-individual-preference.js +90 -0
  51. package/src/migrations/legacy-local-storage-data/move-interface-enable-items.js +120 -0
  52. package/src/migrations/legacy-local-storage-data/move-third-party-feature-preferences.js +98 -0
  53. package/src/migrations/legacy-local-storage-data/test/convert-edit-post-panels.js +47 -0
  54. package/src/migrations/legacy-local-storage-data/test/index.js +229 -0
  55. package/src/migrations/legacy-local-storage-data/test/move-feature-preferences.js +260 -0
  56. package/src/migrations/legacy-local-storage-data/test/move-individual-preference.js +188 -0
  57. package/src/migrations/legacy-local-storage-data/test/move-interface-enable-items.js +118 -0
  58. package/src/migrations/legacy-local-storage-data/test/move-third-party-feature-preferences.js +107 -0
@@ -0,0 +1,135 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = moveFeaturePreferences;
7
+
8
+ /**
9
+ * Move the 'features' object in local storage from the sourceStoreName to the
10
+ * preferences store data structure.
11
+ *
12
+ * Previously, editors used a data structure like this for feature preferences:
13
+ * ```js
14
+ * {
15
+ * 'core/edit-post': {
16
+ * preferences: {
17
+ * features; {
18
+ * topToolbar: true,
19
+ * // ... other boolean 'feature' preferences
20
+ * },
21
+ * },
22
+ * },
23
+ * }
24
+ * ```
25
+ *
26
+ * And for a while these feature preferences lived in the interface package:
27
+ * ```js
28
+ * {
29
+ * 'core/interface': {
30
+ * preferences: {
31
+ * features: {
32
+ * 'core/edit-post': {
33
+ * topToolbar: true
34
+ * }
35
+ * }
36
+ * }
37
+ * }
38
+ * }
39
+ * ```
40
+ *
41
+ * In the preferences store, 'features' aren't considered special, they're
42
+ * merged to the root level of the scope along with other preferences:
43
+ * ```js
44
+ * {
45
+ * 'core/preferences': {
46
+ * preferences: {
47
+ * 'core/edit-post': {
48
+ * topToolbar: true,
49
+ * // ... any other preferences.
50
+ * }
51
+ * }
52
+ * }
53
+ * }
54
+ * ```
55
+ *
56
+ * This function handles moving from either the source store or the interface
57
+ * store to the preferences data structure.
58
+ *
59
+ * @param {Object} state The state before migration.
60
+ * @param {string} sourceStoreName The name of the store that has persisted
61
+ * preferences to migrate to the preferences
62
+ * package.
63
+ * @return {Object} The migrated state
64
+ */
65
+ function moveFeaturePreferences(state, sourceStoreName) {
66
+ var _state$interfaceStore, _state$interfaceStore2, _state$interfaceStore3, _state$sourceStoreNam, _state$sourceStoreNam2, _state$preferencesSto;
67
+
68
+ const preferencesStoreName = 'core/preferences';
69
+ const interfaceStoreName = 'core/interface'; // Features most recently (and briefly) lived in the interface package.
70
+ // If data exists there, prioritize using that for the migration. If not
71
+ // also check the original package as the user may have updated from an
72
+ // older block editor version.
73
+
74
+ const interfaceFeatures = state === null || state === void 0 ? void 0 : (_state$interfaceStore = state[interfaceStoreName]) === null || _state$interfaceStore === void 0 ? void 0 : (_state$interfaceStore2 = _state$interfaceStore.preferences) === null || _state$interfaceStore2 === void 0 ? void 0 : (_state$interfaceStore3 = _state$interfaceStore2.features) === null || _state$interfaceStore3 === void 0 ? void 0 : _state$interfaceStore3[sourceStoreName];
75
+ const sourceFeatures = state === null || state === void 0 ? void 0 : (_state$sourceStoreNam = state[sourceStoreName]) === null || _state$sourceStoreNam === void 0 ? void 0 : (_state$sourceStoreNam2 = _state$sourceStoreNam.preferences) === null || _state$sourceStoreNam2 === void 0 ? void 0 : _state$sourceStoreNam2.features;
76
+ const featuresToMigrate = interfaceFeatures ? interfaceFeatures : sourceFeatures;
77
+
78
+ if (!featuresToMigrate) {
79
+ return state;
80
+ }
81
+
82
+ const existingPreferences = state === null || state === void 0 ? void 0 : (_state$preferencesSto = state[preferencesStoreName]) === null || _state$preferencesSto === void 0 ? void 0 : _state$preferencesSto.preferences; // Avoid migrating features again if they've previously been migrated.
83
+
84
+ if (existingPreferences !== null && existingPreferences !== void 0 && existingPreferences[sourceStoreName]) {
85
+ return state;
86
+ }
87
+
88
+ let updatedInterfaceState;
89
+
90
+ if (interfaceFeatures) {
91
+ var _state$interfaceStore4, _state$interfaceStore5;
92
+
93
+ const otherInterfaceState = state === null || state === void 0 ? void 0 : state[interfaceStoreName];
94
+ const otherInterfaceScopes = state === null || state === void 0 ? void 0 : (_state$interfaceStore4 = state[interfaceStoreName]) === null || _state$interfaceStore4 === void 0 ? void 0 : (_state$interfaceStore5 = _state$interfaceStore4.preferences) === null || _state$interfaceStore5 === void 0 ? void 0 : _state$interfaceStore5.features;
95
+ updatedInterfaceState = {
96
+ [interfaceStoreName]: { ...otherInterfaceState,
97
+ preferences: {
98
+ features: { ...otherInterfaceScopes,
99
+ [sourceStoreName]: undefined
100
+ }
101
+ }
102
+ }
103
+ };
104
+ }
105
+
106
+ let updatedSourceState;
107
+
108
+ if (sourceFeatures) {
109
+ var _state$sourceStoreNam3;
110
+
111
+ const otherSourceState = state === null || state === void 0 ? void 0 : state[sourceStoreName];
112
+ const sourcePreferences = state === null || state === void 0 ? void 0 : (_state$sourceStoreNam3 = state[sourceStoreName]) === null || _state$sourceStoreNam3 === void 0 ? void 0 : _state$sourceStoreNam3.preferences;
113
+ updatedSourceState = {
114
+ [sourceStoreName]: { ...otherSourceState,
115
+ preferences: { ...sourcePreferences,
116
+ features: undefined
117
+ }
118
+ }
119
+ };
120
+ } // Set the feature values in the interface store, the features
121
+ // object is keyed by 'scope', which matches the store name for
122
+ // the source.
123
+
124
+
125
+ return { ...state,
126
+ [preferencesStoreName]: {
127
+ preferences: { ...existingPreferences,
128
+ [sourceStoreName]: featuresToMigrate
129
+ }
130
+ },
131
+ ...updatedInterfaceState,
132
+ ...updatedSourceState
133
+ };
134
+ }
135
+ //# sourceMappingURL=move-feature-preferences.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["@wordpress/preferences-persistence/src/migrations/legacy-local-storage-data/move-feature-preferences.js"],"names":["moveFeaturePreferences","state","sourceStoreName","preferencesStoreName","interfaceStoreName","interfaceFeatures","preferences","features","sourceFeatures","featuresToMigrate","existingPreferences","updatedInterfaceState","otherInterfaceState","otherInterfaceScopes","undefined","updatedSourceState","otherSourceState","sourcePreferences"],"mappings":";;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,SAASA,sBAAT,CAAiCC,KAAjC,EAAwCC,eAAxC,EAA0D;AAAA;;AACxE,QAAMC,oBAAoB,GAAG,kBAA7B;AACA,QAAMC,kBAAkB,GAAG,gBAA3B,CAFwE,CAIxE;AACA;AACA;AACA;;AACA,QAAMC,iBAAiB,GACtBJ,KADsB,aACtBA,KADsB,gDACtBA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,KAAH,aAAGA,KAAH,iDAAGA,KAAK,CAAIC,eAAJ,CAAR,2DAAG,uBAA4BI,WAAtD;AAEAS,IAAAA,kBAAkB,GAAG;AACpB,OAAEb,eAAF,GAAqB,EACpB,GAAGc,gBADiB;AAEpBV,QAAAA,WAAW,EAAE,EACZ,GAAGW,iBADS;AAEZV,UAAAA,QAAQ,EAAEO;AAFE;AAFO;AADD,KAArB;AASA,GA7DuE,CA+DxE;AACA;AACA;;;AACA,SAAO,EACN,GAAGb,KADG;AAEN,KAAEE,oBAAF,GAA0B;AACzBG,MAAAA,WAAW,EAAE,EACZ,GAAGI,mBADS;AAEZ,SAAER,eAAF,GAAqBO;AAFT;AADY,KAFpB;AAQN,OAAGE,qBARG;AASN,OAAGI;AATG,GAAP;AAWA","sourcesContent":["/**\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 {Object} state The state before migration.\n * @param {string} sourceStoreName The name of the store that has persisted\n * preferences to migrate to the preferences\n * package.\n * @return {Object} The migrated state\n */\nexport default function moveFeaturePreferences( state, sourceStoreName ) {\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;\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"]}
@@ -0,0 +1,91 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = moveIndividualPreferenceToPreferences;
7
+
8
+ const identity = arg => arg;
9
+ /**
10
+ * Migrates an individual item inside the `preferences` object for a package's store.
11
+ *
12
+ * Previously, some packages had individual 'preferences' of any data type, and many used
13
+ * complex nested data structures. For example:
14
+ * ```js
15
+ * {
16
+ * 'core/edit-post': {
17
+ * preferences: {
18
+ * panels: {
19
+ * publish: {
20
+ * opened: true,
21
+ * enabled: true,
22
+ * }
23
+ * },
24
+ * // ...other preferences.
25
+ * },
26
+ * },
27
+ * }
28
+ *
29
+ * This function supports moving an individual preference like 'panels' above into the
30
+ * preferences package data structure.
31
+ *
32
+ * It supports moving a preference to a particular scope in the preferences store and
33
+ * optionally converting the data using a `convert` function.
34
+ *
35
+ * ```
36
+ *
37
+ * @param {Object} state The original state.
38
+ * @param {Object} migrate An options object that contains details of the migration.
39
+ * @param {string} migrate.from The name of the store to migrate from.
40
+ * @param {string} migrate.to The scope in the preferences store to migrate to.
41
+ * @param {string} key The key in the preferences object to migrate.
42
+ * @param {?Function} convert A function that converts preferences from one format to another.
43
+ */
44
+
45
+
46
+ function moveIndividualPreferenceToPreferences(state, _ref, key) {
47
+ var _state$sourceStoreNam, _state$sourceStoreNam2, _state$preferencesSto, _state$preferencesSto2, _state$preferencesSto3, _state$preferencesSto4, _state$preferencesSto5, _state$preferencesSto6, _state$sourceStoreNam3;
48
+
49
+ let {
50
+ from: sourceStoreName,
51
+ to: scope
52
+ } = _ref;
53
+ let convert = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : identity;
54
+ const preferencesStoreName = 'core/preferences';
55
+ const sourcePreference = state === null || state === void 0 ? void 0 : (_state$sourceStoreNam = state[sourceStoreName]) === null || _state$sourceStoreNam === void 0 ? void 0 : (_state$sourceStoreNam2 = _state$sourceStoreNam.preferences) === null || _state$sourceStoreNam2 === void 0 ? void 0 : _state$sourceStoreNam2[key]; // There's nothing to migrate, exit early.
56
+
57
+ if (sourcePreference === undefined) {
58
+ return state;
59
+ }
60
+
61
+ const targetPreference = state === null || state === void 0 ? void 0 : (_state$preferencesSto = state[preferencesStoreName]) === null || _state$preferencesSto === void 0 ? void 0 : (_state$preferencesSto2 = _state$preferencesSto.preferences) === null || _state$preferencesSto2 === void 0 ? void 0 : (_state$preferencesSto3 = _state$preferencesSto2[scope]) === null || _state$preferencesSto3 === void 0 ? void 0 : _state$preferencesSto3[key]; // There's existing data at the target, so don't overwrite it, exit early.
62
+
63
+ if (targetPreference) {
64
+ return state;
65
+ }
66
+
67
+ const otherScopes = state === null || state === void 0 ? void 0 : (_state$preferencesSto4 = state[preferencesStoreName]) === null || _state$preferencesSto4 === void 0 ? void 0 : _state$preferencesSto4.preferences;
68
+ const otherPreferences = state === null || state === void 0 ? void 0 : (_state$preferencesSto5 = state[preferencesStoreName]) === null || _state$preferencesSto5 === void 0 ? void 0 : (_state$preferencesSto6 = _state$preferencesSto5.preferences) === null || _state$preferencesSto6 === void 0 ? void 0 : _state$preferencesSto6[scope];
69
+ const otherSourceState = state === null || state === void 0 ? void 0 : state[sourceStoreName];
70
+ const allSourcePreferences = state === null || state === void 0 ? void 0 : (_state$sourceStoreNam3 = state[sourceStoreName]) === null || _state$sourceStoreNam3 === void 0 ? void 0 : _state$sourceStoreNam3.preferences; // Pass an object with the key and value as this allows the convert
71
+ // function to convert to a data structure that has different keys.
72
+
73
+ const convertedPreferences = convert({
74
+ [key]: sourcePreference
75
+ });
76
+ return { ...state,
77
+ [preferencesStoreName]: {
78
+ preferences: { ...otherScopes,
79
+ [scope]: { ...otherPreferences,
80
+ ...convertedPreferences
81
+ }
82
+ }
83
+ },
84
+ [sourceStoreName]: { ...otherSourceState,
85
+ preferences: { ...allSourcePreferences,
86
+ [key]: undefined
87
+ }
88
+ }
89
+ };
90
+ }
91
+ //# sourceMappingURL=move-individual-preference.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["@wordpress/preferences-persistence/src/migrations/legacy-local-storage-data/move-individual-preference.js"],"names":["identity","arg","moveIndividualPreferenceToPreferences","state","key","from","sourceStoreName","to","scope","convert","preferencesStoreName","sourcePreference","preferences","undefined","targetPreference","otherScopes","otherPreferences","otherSourceState","allSourcePreferences","convertedPreferences"],"mappings":";;;;;;;AAAA,MAAMA,QAAQ,GAAKC,GAAF,IAAWA,GAA5B;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACe,SAASC,qCAAT,CACdC,KADc,QAGdC,GAHc,EAKb;AAAA;;AAAA,MAHD;AAAEC,IAAAA,IAAI,EAAEC,eAAR;AAAyBC,IAAAA,EAAE,EAAEC;AAA7B,GAGC;AAAA,MADDC,OACC,uEADST,QACT;AACD,QAAMU,oBAAoB,GAAG,kBAA7B;AACA,QAAMC,gBAAgB,GAAGR,KAAH,aAAGA,KAAH,gDAAGA,KAAK,CAAIG,eAAJ,CAAR,oFAAG,sBAA4BM,WAA/B,2DAAG,uBAA2CR,GAA3C,CAAzB,CAFC,CAID;;AACA,MAAKO,gBAAgB,KAAKE,SAA1B,EAAsC;AACrC,WAAOV,KAAP;AACA;;AAED,QAAMW,gBAAgB,GACrBX,KADqB,aACrBA,KADqB,gDACrBA,KAAK,CAAIO,oBAAJ,CADgB,oFACrB,sBAAiCE,WADZ,qFACrB,uBAAgDJ,KAAhD,CADqB,2DACrB,uBAA2DJ,GAA3D,CADD,CATC,CAYD;;AACA,MAAKU,gBAAL,EAAwB;AACvB,WAAOX,KAAP;AACA;;AAED,QAAMY,WAAW,GAAGZ,KAAH,aAAGA,KAAH,iDAAGA,KAAK,CAAIO,oBAAJ,CAAR,2DAAG,uBAAiCE,WAArD;AACA,QAAMI,gBAAgB,GACrBb,KADqB,aACrBA,KADqB,iDACrBA,KAAK,CAAIO,oBAAJ,CADgB,qFACrB,uBAAiCE,WADZ,2DACrB,uBAAgDJ,KAAhD,CADD;AAGA,QAAMS,gBAAgB,GAAGd,KAAH,aAAGA,KAAH,uBAAGA,KAAK,CAAIG,eAAJ,CAA9B;AACA,QAAMY,oBAAoB,GAAGf,KAAH,aAAGA,KAAH,iDAAGA,KAAK,CAAIG,eAAJ,CAAR,2DAAG,uBAA4BM,WAAzD,CAtBC,CAwBD;AACA;;AACA,QAAMO,oBAAoB,GAAGV,OAAO,CAAE;AAAE,KAAEL,GAAF,GAASO;AAAX,GAAF,CAApC;AAEA,SAAO,EACN,GAAGR,KADG;AAEN,KAAEO,oBAAF,GAA0B;AACzBE,MAAAA,WAAW,EAAE,EACZ,GAAGG,WADS;AAEZ,SAAEP,KAAF,GAAW,EACV,GAAGQ,gBADO;AAEV,aAAGG;AAFO;AAFC;AADY,KAFpB;AAWN,KAAEb,eAAF,GAAqB,EACpB,GAAGW,gBADiB;AAEpBL,MAAAA,WAAW,EAAE,EACZ,GAAGM,oBADS;AAEZ,SAAEd,GAAF,GAASS;AAFG;AAFO;AAXf,GAAP;AAmBA","sourcesContent":["const identity = ( arg ) => 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 {Object} state The original state.\n * @param {Object} migrate An options object that contains details of the migration.\n * @param {string} migrate.from The name of the store to migrate from.\n * @param {string} migrate.to The scope in the preferences store to migrate to.\n * @param {string} key The key in the preferences object to migrate.\n * @param {?Function} convert A function that converts preferences from one format to another.\n */\nexport default function moveIndividualPreferenceToPreferences(\n\tstate,\n\t{ from: sourceStoreName, to: scope },\n\tkey,\n\tconvert = identity\n) {\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"]}
@@ -0,0 +1,114 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = moveInterfaceEnableItems;
7
+
8
+ /**
9
+ * Migrates interface 'enableItems' data to the preferences store.
10
+ *
11
+ * The interface package stores this data in this format:
12
+ * ```js
13
+ * {
14
+ * enableItems: {
15
+ * singleEnableItems: {
16
+ * complementaryArea: {
17
+ * 'core/edit-post': 'edit-post/document',
18
+ * 'core/edit-site': 'edit-site/global-styles',
19
+ * }
20
+ * },
21
+ * multipleEnableItems: {
22
+ * pinnedItems: {
23
+ * 'core/edit-post': {
24
+ * 'plugin-1': true,
25
+ * },
26
+ * 'core/edit-site': {
27
+ * 'plugin-2': true,
28
+ * },
29
+ * },
30
+ * }
31
+ * }
32
+ * }
33
+ * ```
34
+ *
35
+ * and it should be converted it to:
36
+ * ```js
37
+ * {
38
+ * 'core/edit-post': {
39
+ * complementaryArea: 'edit-post/document',
40
+ * pinnedItems: {
41
+ * 'plugin-1': true,
42
+ * },
43
+ * },
44
+ * 'core/edit-site': {
45
+ * complementaryArea: 'edit-site/global-styles',
46
+ * pinnedItems: {
47
+ * 'plugin-2': true,
48
+ * },
49
+ * },
50
+ * }
51
+ * ```
52
+ *
53
+ * @param {Object} state The local storage state.
54
+ */
55
+ function moveInterfaceEnableItems(state) {
56
+ var _state$interfaceStore, _state$preferencesSto, _state$preferencesSto2, _sourceEnableItems$si, _sourceEnableItems$si2, _sourceEnableItems$mu, _sourceEnableItems$mu2;
57
+
58
+ const interfaceStoreName = 'core/interface';
59
+ const preferencesStoreName = 'core/preferences';
60
+ const sourceEnableItems = state === null || state === void 0 ? void 0 : (_state$interfaceStore = state[interfaceStoreName]) === null || _state$interfaceStore === void 0 ? void 0 : _state$interfaceStore.enableItems; // There's nothing to migrate, exit early.
61
+
62
+ if (!sourceEnableItems) {
63
+ return state;
64
+ }
65
+
66
+ const allPreferences = (_state$preferencesSto = state === null || state === void 0 ? void 0 : (_state$preferencesSto2 = state[preferencesStoreName]) === null || _state$preferencesSto2 === void 0 ? void 0 : _state$preferencesSto2.preferences) !== null && _state$preferencesSto !== void 0 ? _state$preferencesSto : {}; // First convert complementaryAreas into the right format.
67
+ // Use the existing preferences as the accumulator so that the data is
68
+ // merged.
69
+
70
+ const sourceComplementaryAreas = (_sourceEnableItems$si = sourceEnableItems === null || sourceEnableItems === void 0 ? void 0 : (_sourceEnableItems$si2 = sourceEnableItems.singleEnableItems) === null || _sourceEnableItems$si2 === void 0 ? void 0 : _sourceEnableItems$si2.complementaryArea) !== null && _sourceEnableItems$si !== void 0 ? _sourceEnableItems$si : {};
71
+ const preferencesWithConvertedComplementaryAreas = Object.keys(sourceComplementaryAreas).reduce((accumulator, scope) => {
72
+ var _accumulator$scope;
73
+
74
+ const data = sourceComplementaryAreas[scope]; // Don't overwrite any existing data in the preferences store.
75
+
76
+ if (accumulator !== null && accumulator !== void 0 && (_accumulator$scope = accumulator[scope]) !== null && _accumulator$scope !== void 0 && _accumulator$scope.complementaryArea) {
77
+ return accumulator;
78
+ }
79
+
80
+ return { ...accumulator,
81
+ [scope]: { ...accumulator[scope],
82
+ complementaryArea: data
83
+ }
84
+ };
85
+ }, allPreferences); // Next feed the converted complementary areas back into a reducer that
86
+ // converts the pinned items, resulting in the fully migrated data.
87
+
88
+ const sourcePinnedItems = (_sourceEnableItems$mu = sourceEnableItems === null || sourceEnableItems === void 0 ? void 0 : (_sourceEnableItems$mu2 = sourceEnableItems.multipleEnableItems) === null || _sourceEnableItems$mu2 === void 0 ? void 0 : _sourceEnableItems$mu2.pinnedItems) !== null && _sourceEnableItems$mu !== void 0 ? _sourceEnableItems$mu : {};
89
+ const allConvertedData = Object.keys(sourcePinnedItems).reduce((accumulator, scope) => {
90
+ var _accumulator$scope2;
91
+
92
+ const data = sourcePinnedItems[scope]; // Don't overwrite any existing data in the preferences store.
93
+
94
+ if (accumulator !== null && accumulator !== void 0 && (_accumulator$scope2 = accumulator[scope]) !== null && _accumulator$scope2 !== void 0 && _accumulator$scope2.pinnedItems) {
95
+ return accumulator;
96
+ }
97
+
98
+ return { ...accumulator,
99
+ [scope]: { ...accumulator[scope],
100
+ pinnedItems: data
101
+ }
102
+ };
103
+ }, preferencesWithConvertedComplementaryAreas);
104
+ const otherInterfaceItems = state[interfaceStoreName];
105
+ return { ...state,
106
+ [preferencesStoreName]: {
107
+ preferences: allConvertedData
108
+ },
109
+ [interfaceStoreName]: { ...otherInterfaceItems,
110
+ enableItems: undefined
111
+ }
112
+ };
113
+ }
114
+ //# sourceMappingURL=move-interface-enable-items.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["@wordpress/preferences-persistence/src/migrations/legacy-local-storage-data/move-interface-enable-items.js"],"names":["moveInterfaceEnableItems","state","interfaceStoreName","preferencesStoreName","sourceEnableItems","enableItems","allPreferences","preferences","sourceComplementaryAreas","singleEnableItems","complementaryArea","preferencesWithConvertedComplementaryAreas","Object","keys","reduce","accumulator","scope","data","sourcePinnedItems","multipleEnableItems","pinnedItems","allConvertedData","otherInterfaceItems","undefined"],"mappings":";;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,SAASA,wBAAT,CAAmCC,KAAnC,EAA2C;AAAA;;AACzD,QAAMC,kBAAkB,GAAG,gBAA3B;AACA,QAAMC,oBAAoB,GAAG,kBAA7B;AACA,QAAMC,iBAAiB,GAAGH,KAAH,aAAGA,KAAH,gDAAGA,KAAK,CAAIC,kBAAJ,CAAR,0DAAG,sBAA+BG,WAAzD,CAHyD,CAKzD;;AACA,MAAK,CAAED,iBAAP,EAA2B;AAC1B,WAAOH,KAAP;AACA;;AAED,QAAMK,cAAc,4BAAGL,KAAH,aAAGA,KAAH,iDAAGA,KAAK,CAAIE,oBAAJ,CAAR,2DAAG,uBAAiCI,WAApC,yEAAmD,EAAvE,CAVyD,CAYzD;AACA;AACA;;AACA,QAAMC,wBAAwB,4BAC7BJ,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BA,QAAMW,mBAAmB,GAAGrB,KAAK,CAAEC,kBAAF,CAAjC;AAEA,SAAO,EACN,GAAGD,KADG;AAEN,KAAEE,oBAAF,GAA0B;AACzBI,MAAAA,WAAW,EAAEc;AADY,KAFpB;AAKN,KAAEnB,kBAAF,GAAwB,EACvB,GAAGoB,mBADoB;AAEvBjB,MAAAA,WAAW,EAAEkB;AAFU;AALlB,GAAP;AAUA","sourcesContent":["/**\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 {Object} state The local storage state.\n */\nexport default function moveInterfaceEnableItems( state ) {\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"]}
@@ -0,0 +1,99 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = moveThirdPartyFeaturePreferencesToPreferences;
7
+
8
+ /**
9
+ * The interface package previously had a public API that could be used by
10
+ * plugins to set persisted boolean 'feature' preferences.
11
+ *
12
+ * While usage was likely non-existent or very small, this function ensures
13
+ * those are migrated to the preferences data structure. The interface
14
+ * package's APIs have now been deprecated and use the preferences store.
15
+ *
16
+ * This will convert data that looks like this:
17
+ * ```js
18
+ * {
19
+ * 'core/interface': {
20
+ * preferences: {
21
+ * features: {
22
+ * 'my-plugin': {
23
+ * myPluginFeature: true
24
+ * }
25
+ * }
26
+ * }
27
+ * }
28
+ * }
29
+ * ```
30
+ *
31
+ * To this:
32
+ * ```js
33
+ * * {
34
+ * 'core/preferences': {
35
+ * preferences: {
36
+ * 'my-plugin': {
37
+ * myPluginFeature: true
38
+ * }
39
+ * }
40
+ * }
41
+ * }
42
+ * ```
43
+ *
44
+ * @param {Object} state The local storage state
45
+ *
46
+ * @return {Object} The state with third party preferences moved to the
47
+ * preferences data structure.
48
+ */
49
+ function moveThirdPartyFeaturePreferencesToPreferences(state) {
50
+ var _state$interfaceStore, _state$interfaceStore2;
51
+
52
+ const interfaceStoreName = 'core/interface';
53
+ const preferencesStoreName = 'core/preferences';
54
+ const interfaceScopes = state === null || state === void 0 ? void 0 : (_state$interfaceStore = state[interfaceStoreName]) === null || _state$interfaceStore === void 0 ? void 0 : (_state$interfaceStore2 = _state$interfaceStore.preferences) === null || _state$interfaceStore2 === void 0 ? void 0 : _state$interfaceStore2.features;
55
+ const interfaceScopeKeys = interfaceScopes ? Object.keys(interfaceScopes) : [];
56
+
57
+ if (!(interfaceScopeKeys !== null && interfaceScopeKeys !== void 0 && interfaceScopeKeys.length)) {
58
+ return state;
59
+ }
60
+
61
+ return interfaceScopeKeys.reduce(function (convertedState, scope) {
62
+ var _convertedState$prefe, _convertedState$prefe2, _convertedState$prefe3, _convertedState$inter, _convertedState$inter2;
63
+
64
+ if (scope.startsWith('core')) {
65
+ return convertedState;
66
+ }
67
+
68
+ const featuresToMigrate = interfaceScopes === null || interfaceScopes === void 0 ? void 0 : interfaceScopes[scope];
69
+
70
+ if (!featuresToMigrate) {
71
+ return convertedState;
72
+ }
73
+
74
+ const existingMigratedData = convertedState === null || convertedState === void 0 ? void 0 : (_convertedState$prefe = convertedState[preferencesStoreName]) === null || _convertedState$prefe === void 0 ? void 0 : (_convertedState$prefe2 = _convertedState$prefe.preferences) === null || _convertedState$prefe2 === void 0 ? void 0 : _convertedState$prefe2[scope];
75
+
76
+ if (existingMigratedData) {
77
+ return convertedState;
78
+ }
79
+
80
+ const otherPreferencesScopes = convertedState === null || convertedState === void 0 ? void 0 : (_convertedState$prefe3 = convertedState[preferencesStoreName]) === null || _convertedState$prefe3 === void 0 ? void 0 : _convertedState$prefe3.preferences;
81
+ const otherInterfaceState = convertedState === null || convertedState === void 0 ? void 0 : convertedState[interfaceStoreName];
82
+ const otherInterfaceScopes = convertedState === null || convertedState === void 0 ? void 0 : (_convertedState$inter = convertedState[interfaceStoreName]) === null || _convertedState$inter === void 0 ? void 0 : (_convertedState$inter2 = _convertedState$inter.preferences) === null || _convertedState$inter2 === void 0 ? void 0 : _convertedState$inter2.features;
83
+ return { ...convertedState,
84
+ [preferencesStoreName]: {
85
+ preferences: { ...otherPreferencesScopes,
86
+ [scope]: featuresToMigrate
87
+ }
88
+ },
89
+ [interfaceStoreName]: { ...otherInterfaceState,
90
+ preferences: {
91
+ features: { ...otherInterfaceScopes,
92
+ [scope]: undefined
93
+ }
94
+ }
95
+ }
96
+ };
97
+ }, state);
98
+ }
99
+ //# sourceMappingURL=move-third-party-feature-preferences.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["@wordpress/preferences-persistence/src/migrations/legacy-local-storage-data/move-third-party-feature-preferences.js"],"names":["moveThirdPartyFeaturePreferencesToPreferences","state","interfaceStoreName","preferencesStoreName","interfaceScopes","preferences","features","interfaceScopeKeys","Object","keys","length","reduce","convertedState","scope","startsWith","featuresToMigrate","existingMigratedData","otherPreferencesScopes","otherInterfaceState","otherInterfaceScopes","undefined"],"mappings":";;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAC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A1C;AACA,UAAMiB,oBAAoB,GACzBP,cADyB,aACzBA,cADyB,gDACzBA,cAAc,CAAIV,kBAAJ,CADW,oFACzB,sBAAwCG,WADf,2DACzB,uBAAqDC,QADtD;AAGA,WAAO,EACN,GAAGM,cADG;AAEN,OAAET,oBAAF,GAA0B;AACzBE,QAAAA,WAAW,EAAE,EACZ,GAAGY,sBADS;AAEZ,WAAEJ,KAAF,GAAWE;AAFC;AADY,OAFpB;AAQN,OAAEb,kBAAF,GAAwB,EACvB,GAAGgB,mBADoB;AAEvBb,QAAAA,WAAW,EAAE;AACZC,UAAAA,QAAQ,EAAE,EACT,GAAGa,oBADM;AAET,aAAEN,KAAF,GAAWO;AAFF;AADE;AAFU;AARlB,KAAP;AAkBA,GAzCM,EAyCJnB,KAzCI,CAAP;AA0CA","sourcesContent":["/**\n * The interface package previously had a public API that could be used by\n * plugins to set persisted boolean 'feature' preferences.\n *\n * While usage was likely non-existent or very small, this function ensures\n * those are migrated to the preferences data structure. The interface\n * package's APIs have now been deprecated and use the preferences store.\n *\n * This will convert data that looks like this:\n * ```js\n * {\n * 'core/interface': {\n * preferences: {\n * features: {\n * 'my-plugin': {\n * myPluginFeature: true\n * }\n * }\n * }\n * }\n * }\n * ```\n *\n * To this:\n * ```js\n * * {\n * 'core/preferences': {\n * preferences: {\n * 'my-plugin': {\n * myPluginFeature: true\n * }\n * }\n * }\n * }\n * ```\n *\n * @param {Object} state The local storage state\n *\n * @return {Object} The state with third party preferences moved to the\n * preferences data structure.\n */\nexport default function moveThirdPartyFeaturePreferencesToPreferences( state ) {\n\tconst interfaceStoreName = 'core/interface';\n\tconst preferencesStoreName = 'core/preferences';\n\n\tconst interfaceScopes =\n\t\tstate?.[ interfaceStoreName ]?.preferences?.features;\n\tconst interfaceScopeKeys = interfaceScopes\n\t\t? Object.keys( interfaceScopes )\n\t\t: [];\n\n\tif ( ! interfaceScopeKeys?.length ) {\n\t\treturn state;\n\t}\n\n\treturn interfaceScopeKeys.reduce( function ( convertedState, scope ) {\n\t\tif ( scope.startsWith( 'core' ) ) {\n\t\t\treturn convertedState;\n\t\t}\n\n\t\tconst featuresToMigrate = interfaceScopes?.[ scope ];\n\t\tif ( ! featuresToMigrate ) {\n\t\t\treturn convertedState;\n\t\t}\n\n\t\tconst existingMigratedData =\n\t\t\tconvertedState?.[ preferencesStoreName ]?.preferences?.[ scope ];\n\n\t\tif ( existingMigratedData ) {\n\t\t\treturn convertedState;\n\t\t}\n\n\t\tconst otherPreferencesScopes =\n\t\t\tconvertedState?.[ preferencesStoreName ]?.preferences;\n\t\tconst otherInterfaceState = convertedState?.[ interfaceStoreName ];\n\t\tconst otherInterfaceScopes =\n\t\t\tconvertedState?.[ interfaceStoreName ]?.preferences?.features;\n\n\t\treturn {\n\t\t\t...convertedState,\n\t\t\t[ preferencesStoreName ]: {\n\t\t\t\tpreferences: {\n\t\t\t\t\t...otherPreferencesScopes,\n\t\t\t\t\t[ scope ]: featuresToMigrate,\n\t\t\t\t},\n\t\t\t},\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[ scope ]: undefined,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t};\n\t}, state );\n}\n"]}
@@ -0,0 +1,73 @@
1
+ /**
2
+ * Performs a leading edge debounce of async functions.
3
+ *
4
+ * If three functions are throttled at the same time:
5
+ * - The first happens immediately.
6
+ * - The second is never called.
7
+ * - The third happens `delayMS` milliseconds after the first has resolved.
8
+ *
9
+ * This is distinct from `lodash.debounce` in that it waits for promise
10
+ * resolution.
11
+ *
12
+ * @param {Function} func A function that returns a promise.
13
+ * @param {number} delayMS A delay in milliseconds.
14
+ *
15
+ * @return {Function} A function that debounce whatever function is passed
16
+ * to it.
17
+ */
18
+ export default function debounceAsync(func, delayMS) {
19
+ let timeoutId;
20
+ let activePromise;
21
+ return async function debounced() {
22
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
23
+ args[_key] = arguments[_key];
24
+ }
25
+
26
+ // This is a leading edge debounce. If there's no promise or timeout
27
+ // in progress, call the debounced function immediately.
28
+ if (!activePromise && !timeoutId) {
29
+ return new Promise((resolve, reject) => {
30
+ // Keep a reference to the promise.
31
+ activePromise = func(...args).then(function () {
32
+ resolve(...arguments);
33
+ }).catch(error => {
34
+ reject(error);
35
+ }).finally(() => {
36
+ // As soon this promise is complete, clear the way for the
37
+ // next one to happen immediately.
38
+ activePromise = null;
39
+ });
40
+ });
41
+ }
42
+
43
+ if (activePromise) {
44
+ // Let any active promises finish before queuing the next request.
45
+ await activePromise;
46
+ } // Clear any active timeouts, abandoning any requests that have
47
+ // been queued but not been made.
48
+
49
+
50
+ if (timeoutId) {
51
+ clearTimeout(timeoutId);
52
+ timeoutId = null;
53
+ } // Trigger any trailing edge calls to the function.
54
+
55
+
56
+ return new Promise((resolve, reject) => {
57
+ // Schedule the next request but with a delay.
58
+ timeoutId = setTimeout(() => {
59
+ activePromise = func(...args).then(function () {
60
+ resolve(...arguments);
61
+ }).catch(error => {
62
+ reject(error);
63
+ }).finally(() => {
64
+ // As soon this promise is complete, clear the way for the
65
+ // next one to happen immediately.
66
+ activePromise = null;
67
+ timeoutId = null;
68
+ });
69
+ }, delayMS);
70
+ });
71
+ };
72
+ }
73
+ //# sourceMappingURL=debounce-async.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["@wordpress/preferences-persistence/src/create/debounce-async.js"],"names":["debounceAsync","func","delayMS","timeoutId","activePromise","debounced","args","Promise","resolve","reject","then","catch","error","finally","clearTimeout","setTimeout"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,SAASA,aAAT,CAAwBC,IAAxB,EAA8BC,OAA9B,EAAwC;AACtD,MAAIC,SAAJ;AACA,MAAIC,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eA,KAjBM,CAAP;AAkBA,GApDD;AAqDA","sourcesContent":["/**\n * Performs a leading edge debounce of async functions.\n *\n * If three functions are throttled at the same time:\n * - The first happens immediately.\n * - The second is never called.\n * - The third happens `delayMS` milliseconds after the first has resolved.\n *\n * This is distinct from `lodash.debounce` in that it waits for promise\n * resolution.\n *\n * @param {Function} func A function that returns a promise.\n * @param {number} delayMS A delay in milliseconds.\n *\n * @return {Function} A function that debounce whatever function is passed\n * to it.\n */\nexport default function debounceAsync( func, delayMS ) {\n\tlet timeoutId;\n\tlet activePromise;\n\n\treturn async function debounced( ...args ) {\n\t\t// This is a leading edge debounce. If there's no promise or timeout\n\t\t// in progress, call the debounced function immediately.\n\t\tif ( ! activePromise && ! timeoutId ) {\n\t\t\treturn new Promise( ( resolve, reject ) => {\n\t\t\t\t// Keep a reference to the promise.\n\t\t\t\tactivePromise = func( ...args )\n\t\t\t\t\t.then( ( ...thenArgs ) => {\n\t\t\t\t\t\tresolve( ...thenArgs );\n\t\t\t\t\t} )\n\t\t\t\t\t.catch( ( error ) => {\n\t\t\t\t\t\treject( error );\n\t\t\t\t\t} )\n\t\t\t\t\t.finally( () => {\n\t\t\t\t\t\t// As soon this promise is complete, clear the way for the\n\t\t\t\t\t\t// next one to happen immediately.\n\t\t\t\t\t\tactivePromise = null;\n\t\t\t\t\t} );\n\t\t\t} );\n\t\t}\n\n\t\tif ( activePromise ) {\n\t\t\t// Let any active promises finish before queuing the next request.\n\t\t\tawait activePromise;\n\t\t}\n\n\t\t// Clear any active timeouts, abandoning any requests that have\n\t\t// been queued but not been made.\n\t\tif ( timeoutId ) {\n\t\t\tclearTimeout( timeoutId );\n\t\t\ttimeoutId = null;\n\t\t}\n\n\t\t// Trigger any trailing edge calls to the function.\n\t\treturn new Promise( ( resolve, reject ) => {\n\t\t\t// Schedule the next request but with a delay.\n\t\t\ttimeoutId = setTimeout( () => {\n\t\t\t\tactivePromise = func( ...args )\n\t\t\t\t\t.then( ( ...thenArgs ) => {\n\t\t\t\t\t\tresolve( ...thenArgs );\n\t\t\t\t\t} )\n\t\t\t\t\t.catch( ( error ) => {\n\t\t\t\t\t\treject( error );\n\t\t\t\t\t} )\n\t\t\t\t\t.finally( () => {\n\t\t\t\t\t\t// As soon this promise is complete, clear the way for the\n\t\t\t\t\t\t// next one to happen immediately.\n\t\t\t\t\t\tactivePromise = null;\n\t\t\t\t\t\ttimeoutId = null;\n\t\t\t\t\t} );\n\t\t\t}, delayMS );\n\t\t} );\n\t};\n}\n"]}