@wordpress/preferences-persistence 2.32.0 → 2.32.1-next.47f435fc9.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.
- package/build/create/debounce-async.js +24 -39
- package/build/create/debounce-async.js.map +7 -1
- package/build/create/index.js +50 -61
- package/build/create/index.js.map +7 -1
- package/build/index.js +47 -42
- package/build/index.js.map +7 -1
- package/build/migrations/legacy-local-storage-data/convert-edit-post-panels.js +36 -52
- package/build/migrations/legacy-local-storage-data/convert-edit-post-panels.js.map +7 -1
- package/build/migrations/legacy-local-storage-data/index.js +80 -89
- package/build/migrations/legacy-local-storage-data/index.js.map +7 -1
- package/build/migrations/legacy-local-storage-data/move-feature-preferences.js +26 -78
- package/build/migrations/legacy-local-storage-data/move-feature-preferences.js.map +7 -1
- package/build/migrations/legacy-local-storage-data/move-individual-preference.js +28 -60
- package/build/migrations/legacy-local-storage-data/move-individual-preference.js.map +7 -1
- package/build/migrations/legacy-local-storage-data/move-interface-enable-items.js +46 -85
- package/build/migrations/legacy-local-storage-data/move-interface-enable-items.js.map +7 -1
- package/build/migrations/legacy-local-storage-data/move-third-party-feature-preferences.js +27 -52
- package/build/migrations/legacy-local-storage-data/move-third-party-feature-preferences.js.map +7 -1
- package/build/migrations/preferences-package-data/convert-complementary-areas.js +23 -11
- package/build/migrations/preferences-package-data/convert-complementary-areas.js.map +7 -1
- package/build/migrations/preferences-package-data/convert-editor-settings.js +50 -22
- package/build/migrations/preferences-package-data/convert-editor-settings.js.map +7 -1
- package/build/migrations/preferences-package-data/index.js +36 -15
- package/build/migrations/preferences-package-data/index.js.map +7 -1
- package/build-module/create/debounce-async.js +7 -35
- package/build-module/create/debounce-async.js.map +7 -1
- package/build-module/create/index.js +21 -53
- package/build-module/create/index.js.map +7 -1
- package/build-module/index.js +12 -29
- package/build-module/index.js.map +7 -1
- package/build-module/migrations/legacy-local-storage-data/convert-edit-post-panels.js +19 -48
- package/build-module/migrations/legacy-local-storage-data/convert-edit-post-panels.js.map +7 -1
- package/build-module/migrations/legacy-local-storage-data/index.js +48 -82
- package/build-module/migrations/legacy-local-storage-data/index.js.map +7 -1
- package/build-module/migrations/legacy-local-storage-data/move-feature-preferences.js +9 -74
- package/build-module/migrations/legacy-local-storage-data/move-feature-preferences.js.map +7 -1
- package/build-module/migrations/legacy-local-storage-data/move-individual-preference.js +10 -55
- package/build-module/migrations/legacy-local-storage-data/move-individual-preference.js.map +7 -1
- package/build-module/migrations/legacy-local-storage-data/move-interface-enable-items.js +29 -81
- package/build-module/migrations/legacy-local-storage-data/move-interface-enable-items.js.map +7 -1
- package/build-module/migrations/legacy-local-storage-data/move-third-party-feature-preferences.js +10 -48
- package/build-module/migrations/legacy-local-storage-data/move-third-party-feature-preferences.js.map +7 -1
- package/build-module/migrations/preferences-package-data/convert-complementary-areas.js +6 -7
- package/build-module/migrations/preferences-package-data/convert-complementary-areas.js.map +7 -1
- package/build-module/migrations/preferences-package-data/convert-editor-settings.js +33 -18
- package/build-module/migrations/preferences-package-data/convert-editor-settings.js.map +7 -1
- package/build-module/migrations/preferences-package-data/index.js +7 -7
- package/build-module/migrations/preferences-package-data/index.js.map +7 -1
- package/package.json +11 -4
|
@@ -1,76 +1,38 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.
|
|
4
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var move_interface_enable_items_exports = {};
|
|
19
|
+
__export(move_interface_enable_items_exports, {
|
|
20
|
+
default: () => moveInterfaceEnableItems
|
|
5
21
|
});
|
|
6
|
-
exports
|
|
7
|
-
/**
|
|
8
|
-
* Migrates interface 'enableItems' data to the preferences store.
|
|
9
|
-
*
|
|
10
|
-
* The interface package stores this data in this format:
|
|
11
|
-
* ```js
|
|
12
|
-
* {
|
|
13
|
-
* enableItems: {
|
|
14
|
-
* singleEnableItems: {
|
|
15
|
-
* complementaryArea: {
|
|
16
|
-
* 'core/edit-post': 'edit-post/document',
|
|
17
|
-
* 'core/edit-site': 'edit-site/global-styles',
|
|
18
|
-
* }
|
|
19
|
-
* },
|
|
20
|
-
* multipleEnableItems: {
|
|
21
|
-
* pinnedItems: {
|
|
22
|
-
* 'core/edit-post': {
|
|
23
|
-
* 'plugin-1': true,
|
|
24
|
-
* },
|
|
25
|
-
* 'core/edit-site': {
|
|
26
|
-
* 'plugin-2': true,
|
|
27
|
-
* },
|
|
28
|
-
* },
|
|
29
|
-
* }
|
|
30
|
-
* }
|
|
31
|
-
* }
|
|
32
|
-
* ```
|
|
33
|
-
*
|
|
34
|
-
* and it should be converted it to:
|
|
35
|
-
* ```js
|
|
36
|
-
* {
|
|
37
|
-
* 'core/edit-post': {
|
|
38
|
-
* complementaryArea: 'edit-post/document',
|
|
39
|
-
* pinnedItems: {
|
|
40
|
-
* 'plugin-1': true,
|
|
41
|
-
* },
|
|
42
|
-
* },
|
|
43
|
-
* 'core/edit-site': {
|
|
44
|
-
* complementaryArea: 'edit-site/global-styles',
|
|
45
|
-
* pinnedItems: {
|
|
46
|
-
* 'plugin-2': true,
|
|
47
|
-
* },
|
|
48
|
-
* },
|
|
49
|
-
* }
|
|
50
|
-
* ```
|
|
51
|
-
*
|
|
52
|
-
* @param {Object} state The local storage state.
|
|
53
|
-
*/
|
|
22
|
+
module.exports = __toCommonJS(move_interface_enable_items_exports);
|
|
54
23
|
function moveInterfaceEnableItems(state) {
|
|
55
|
-
|
|
56
|
-
const
|
|
57
|
-
const preferencesStoreName = 'core/preferences';
|
|
24
|
+
const interfaceStoreName = "core/interface";
|
|
25
|
+
const preferencesStoreName = "core/preferences";
|
|
58
26
|
const sourceEnableItems = state?.[interfaceStoreName]?.enableItems;
|
|
59
|
-
|
|
60
|
-
// There's nothing to migrate, exit early.
|
|
61
27
|
if (!sourceEnableItems) {
|
|
62
28
|
return state;
|
|
63
29
|
}
|
|
64
|
-
const allPreferences =
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
const sourceComplementaryAreas = (_sourceEnableItems$si = sourceEnableItems?.singleEnableItems?.complementaryArea) !== null && _sourceEnableItems$si !== void 0 ? _sourceEnableItems$si : {};
|
|
70
|
-
const preferencesWithConvertedComplementaryAreas = Object.keys(sourceComplementaryAreas).reduce((accumulator, scope) => {
|
|
30
|
+
const allPreferences = state?.[preferencesStoreName]?.preferences ?? {};
|
|
31
|
+
const sourceComplementaryAreas = sourceEnableItems?.singleEnableItems?.complementaryArea ?? {};
|
|
32
|
+
const preferencesWithConvertedComplementaryAreas = Object.keys(
|
|
33
|
+
sourceComplementaryAreas
|
|
34
|
+
).reduce((accumulator, scope) => {
|
|
71
35
|
const data = sourceComplementaryAreas[scope];
|
|
72
|
-
|
|
73
|
-
// Don't overwrite any existing data in the preferences store.
|
|
74
36
|
if (accumulator?.[scope]?.complementaryArea) {
|
|
75
37
|
return accumulator;
|
|
76
38
|
}
|
|
@@ -82,24 +44,23 @@ function moveInterfaceEnableItems(state) {
|
|
|
82
44
|
}
|
|
83
45
|
};
|
|
84
46
|
}, allPreferences);
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
// Don't overwrite any existing data in the preferences store.
|
|
92
|
-
if (accumulator?.[scope]?.pinnedItems) {
|
|
93
|
-
return accumulator;
|
|
94
|
-
}
|
|
95
|
-
return {
|
|
96
|
-
...accumulator,
|
|
97
|
-
[scope]: {
|
|
98
|
-
...accumulator[scope],
|
|
99
|
-
pinnedItems: data
|
|
47
|
+
const sourcePinnedItems = sourceEnableItems?.multipleEnableItems?.pinnedItems ?? {};
|
|
48
|
+
const allConvertedData = Object.keys(sourcePinnedItems).reduce(
|
|
49
|
+
(accumulator, scope) => {
|
|
50
|
+
const data = sourcePinnedItems[scope];
|
|
51
|
+
if (accumulator?.[scope]?.pinnedItems) {
|
|
52
|
+
return accumulator;
|
|
100
53
|
}
|
|
101
|
-
|
|
102
|
-
|
|
54
|
+
return {
|
|
55
|
+
...accumulator,
|
|
56
|
+
[scope]: {
|
|
57
|
+
...accumulator[scope],
|
|
58
|
+
pinnedItems: data
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
},
|
|
62
|
+
preferencesWithConvertedComplementaryAreas
|
|
63
|
+
);
|
|
103
64
|
const otherInterfaceItems = state[interfaceStoreName];
|
|
104
65
|
return {
|
|
105
66
|
...state,
|
|
@@ -108,8 +69,8 @@ function moveInterfaceEnableItems(state) {
|
|
|
108
69
|
},
|
|
109
70
|
[interfaceStoreName]: {
|
|
110
71
|
...otherInterfaceItems,
|
|
111
|
-
enableItems:
|
|
72
|
+
enableItems: void 0
|
|
112
73
|
}
|
|
113
74
|
};
|
|
114
75
|
}
|
|
115
|
-
//# sourceMappingURL=move-interface-enable-items.js.map
|
|
76
|
+
//# sourceMappingURL=move-interface-enable-items.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/migrations/legacy-local-storage-data/move-interface-enable-items.js"],
|
|
4
|
+
"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"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AA+Ce,SAAR,yBAA2C,OAAQ;AACzD,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,60 +1,35 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.
|
|
4
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var move_third_party_feature_preferences_exports = {};
|
|
19
|
+
__export(move_third_party_feature_preferences_exports, {
|
|
20
|
+
default: () => moveThirdPartyFeaturePreferencesToPreferences
|
|
5
21
|
});
|
|
6
|
-
exports
|
|
7
|
-
/**
|
|
8
|
-
* The interface package previously had a public API that could be used by
|
|
9
|
-
* plugins to set persisted boolean 'feature' preferences.
|
|
10
|
-
*
|
|
11
|
-
* While usage was likely non-existent or very small, this function ensures
|
|
12
|
-
* those are migrated to the preferences data structure. The interface
|
|
13
|
-
* package's APIs have now been deprecated and use the preferences store.
|
|
14
|
-
*
|
|
15
|
-
* This will convert data that looks like this:
|
|
16
|
-
* ```js
|
|
17
|
-
* {
|
|
18
|
-
* 'core/interface': {
|
|
19
|
-
* preferences: {
|
|
20
|
-
* features: {
|
|
21
|
-
* 'my-plugin': {
|
|
22
|
-
* myPluginFeature: true
|
|
23
|
-
* }
|
|
24
|
-
* }
|
|
25
|
-
* }
|
|
26
|
-
* }
|
|
27
|
-
* }
|
|
28
|
-
* ```
|
|
29
|
-
*
|
|
30
|
-
* To this:
|
|
31
|
-
* ```js
|
|
32
|
-
* * {
|
|
33
|
-
* 'core/preferences': {
|
|
34
|
-
* preferences: {
|
|
35
|
-
* 'my-plugin': {
|
|
36
|
-
* myPluginFeature: true
|
|
37
|
-
* }
|
|
38
|
-
* }
|
|
39
|
-
* }
|
|
40
|
-
* }
|
|
41
|
-
* ```
|
|
42
|
-
*
|
|
43
|
-
* @param {Object} state The local storage state
|
|
44
|
-
*
|
|
45
|
-
* @return {Object} The state with third party preferences moved to the
|
|
46
|
-
* preferences data structure.
|
|
47
|
-
*/
|
|
22
|
+
module.exports = __toCommonJS(move_third_party_feature_preferences_exports);
|
|
48
23
|
function moveThirdPartyFeaturePreferencesToPreferences(state) {
|
|
49
|
-
const interfaceStoreName =
|
|
50
|
-
const preferencesStoreName =
|
|
24
|
+
const interfaceStoreName = "core/interface";
|
|
25
|
+
const preferencesStoreName = "core/preferences";
|
|
51
26
|
const interfaceScopes = state?.[interfaceStoreName]?.preferences?.features;
|
|
52
27
|
const interfaceScopeKeys = interfaceScopes ? Object.keys(interfaceScopes) : [];
|
|
53
28
|
if (!interfaceScopeKeys?.length) {
|
|
54
29
|
return state;
|
|
55
30
|
}
|
|
56
|
-
return interfaceScopeKeys.reduce(function
|
|
57
|
-
if (scope.startsWith(
|
|
31
|
+
return interfaceScopeKeys.reduce(function(convertedState, scope) {
|
|
32
|
+
if (scope.startsWith("core")) {
|
|
58
33
|
return convertedState;
|
|
59
34
|
}
|
|
60
35
|
const featuresToMigrate = interfaceScopes?.[scope];
|
|
@@ -81,11 +56,11 @@ function moveThirdPartyFeaturePreferencesToPreferences(state) {
|
|
|
81
56
|
preferences: {
|
|
82
57
|
features: {
|
|
83
58
|
...otherInterfaceScopes,
|
|
84
|
-
[scope]:
|
|
59
|
+
[scope]: void 0
|
|
85
60
|
}
|
|
86
61
|
}
|
|
87
62
|
}
|
|
88
63
|
};
|
|
89
64
|
}, state);
|
|
90
65
|
}
|
|
91
|
-
//# sourceMappingURL=move-third-party-feature-preferences.js.map
|
|
66
|
+
//# sourceMappingURL=move-third-party-feature-preferences.js.map
|
package/build/migrations/legacy-local-storage-data/move-third-party-feature-preferences.js.map
CHANGED
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/migrations/legacy-local-storage-data/move-third-party-feature-preferences.js"],
|
|
4
|
+
"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"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAyCe,SAAR,8CAAgE,OAAQ;AAC9E,QAAM,qBAAqB;AAC3B,QAAM,uBAAuB;AAE7B,QAAM,kBACL,QAAS,kBAAmB,GAAG,aAAa;AAC7C,QAAM,qBAAqB,kBACxB,OAAO,KAAM,eAAgB,IAC7B,CAAC;AAEJ,MAAK,CAAE,oBAAoB,QAAS;AACnC,WAAO;AAAA,EACR;AAEA,SAAO,mBAAmB,OAAQ,SAAW,gBAAgB,OAAQ;AACpE,QAAK,MAAM,WAAY,MAAO,GAAI;AACjC,aAAO;AAAA,IACR;AAEA,UAAM,oBAAoB,kBAAmB,KAAM;AACnD,QAAK,CAAE,mBAAoB;AAC1B,aAAO;AAAA,IACR;AAEA,UAAM,uBACL,iBAAkB,oBAAqB,GAAG,cAAe,KAAM;AAEhE,QAAK,sBAAuB;AAC3B,aAAO;AAAA,IACR;AAEA,UAAM,yBACL,iBAAkB,oBAAqB,GAAG;AAC3C,UAAM,sBAAsB,iBAAkB,kBAAmB;AACjE,UAAM,uBACL,iBAAkB,kBAAmB,GAAG,aAAa;AAEtD,WAAO;AAAA,MACN,GAAG;AAAA,MACH,CAAE,oBAAqB,GAAG;AAAA,QACzB,aAAa;AAAA,UACZ,GAAG;AAAA,UACH,CAAE,KAAM,GAAG;AAAA,QACZ;AAAA,MACD;AAAA,MACA,CAAE,kBAAmB,GAAG;AAAA,QACvB,GAAG;AAAA,QACH,aAAa;AAAA,UACZ,UAAU;AAAA,YACT,GAAG;AAAA,YACH,CAAE,KAAM,GAAG;AAAA,UACZ;AAAA,QACD;AAAA,MACD;AAAA,IACD;AAAA,EACD,GAAG,KAAM;AACV;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,18 +1,30 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.
|
|
4
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var convert_complementary_areas_exports = {};
|
|
19
|
+
__export(convert_complementary_areas_exports, {
|
|
20
|
+
default: () => convertComplementaryAreas
|
|
5
21
|
});
|
|
6
|
-
exports
|
|
22
|
+
module.exports = __toCommonJS(convert_complementary_areas_exports);
|
|
7
23
|
function convertComplementaryAreas(state) {
|
|
8
24
|
return Object.keys(state).reduce((stateAccumulator, scope) => {
|
|
9
25
|
const scopeData = state[scope];
|
|
10
|
-
|
|
11
|
-
// If a complementary area is truthy, convert it to the `isComplementaryAreaVisible` boolean.
|
|
12
26
|
if (scopeData?.complementaryArea) {
|
|
13
|
-
const updatedScopeData = {
|
|
14
|
-
...scopeData
|
|
15
|
-
};
|
|
27
|
+
const updatedScopeData = { ...scopeData };
|
|
16
28
|
delete updatedScopeData.complementaryArea;
|
|
17
29
|
updatedScopeData.isComplementaryAreaVisible = true;
|
|
18
30
|
stateAccumulator[scope] = updatedScopeData;
|
|
@@ -21,4 +33,4 @@ function convertComplementaryAreas(state) {
|
|
|
21
33
|
return stateAccumulator;
|
|
22
34
|
}, state);
|
|
23
35
|
}
|
|
24
|
-
//# sourceMappingURL=convert-complementary-areas.js.map
|
|
36
|
+
//# sourceMappingURL=convert-complementary-areas.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/migrations/preferences-package-data/convert-complementary-areas.js"],
|
|
4
|
+
"sourcesContent": ["export default function convertComplementaryAreas( state ) {\n\treturn Object.keys( state ).reduce( ( stateAccumulator, scope ) => {\n\t\tconst scopeData = state[ scope ];\n\n\t\t// If a complementary area is truthy, convert it to the `isComplementaryAreaVisible` boolean.\n\t\tif ( scopeData?.complementaryArea ) {\n\t\t\tconst updatedScopeData = { ...scopeData };\n\t\t\tdelete updatedScopeData.complementaryArea;\n\t\t\tupdatedScopeData.isComplementaryAreaVisible = true;\n\t\t\tstateAccumulator[ scope ] = updatedScopeData;\n\t\t\treturn stateAccumulator;\n\t\t}\n\n\t\treturn stateAccumulator;\n\t}, state );\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAe,SAAR,0BAA4C,OAAQ;AAC1D,SAAO,OAAO,KAAM,KAAM,EAAE,OAAQ,CAAE,kBAAkB,UAAW;AAClE,UAAM,YAAY,MAAO,KAAM;AAG/B,QAAK,WAAW,mBAAoB;AACnC,YAAM,mBAAmB,EAAE,GAAG,UAAU;AACxC,aAAO,iBAAiB;AACxB,uBAAiB,6BAA6B;AAC9C,uBAAkB,KAAM,IAAI;AAC5B,aAAO;AAAA,IACR;AAEA,WAAO;AAAA,EACR,GAAG,KAAM;AACV;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,38 +1,66 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.
|
|
4
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var convert_editor_settings_exports = {};
|
|
19
|
+
__export(convert_editor_settings_exports, {
|
|
20
|
+
default: () => convertEditorSettings
|
|
5
21
|
});
|
|
6
|
-
exports
|
|
7
|
-
/**
|
|
8
|
-
* Internal dependencies
|
|
9
|
-
*/
|
|
10
|
-
|
|
22
|
+
module.exports = __toCommonJS(convert_editor_settings_exports);
|
|
11
23
|
function convertEditorSettings(data) {
|
|
12
|
-
var _newData$coreEditPo, _newData$coreEditSi;
|
|
13
24
|
let newData = data;
|
|
14
|
-
const settingsToMoveToCore = [
|
|
15
|
-
|
|
16
|
-
|
|
25
|
+
const settingsToMoveToCore = [
|
|
26
|
+
"allowRightClickOverrides",
|
|
27
|
+
"distractionFree",
|
|
28
|
+
"editorMode",
|
|
29
|
+
"fixedToolbar",
|
|
30
|
+
"focusMode",
|
|
31
|
+
"hiddenBlockTypes",
|
|
32
|
+
"inactivePanels",
|
|
33
|
+
"keepCaretInsideBlock",
|
|
34
|
+
"mostUsedBlocks",
|
|
35
|
+
"openPanels",
|
|
36
|
+
"showBlockBreadcrumbs",
|
|
37
|
+
"showIconLabels",
|
|
38
|
+
"showListViewByDefault",
|
|
39
|
+
"isPublishSidebarEnabled",
|
|
40
|
+
"isComplementaryAreaVisible",
|
|
41
|
+
"pinnedItems"
|
|
42
|
+
];
|
|
43
|
+
settingsToMoveToCore.forEach((setting) => {
|
|
44
|
+
if (data?.["core/edit-post"]?.[setting] !== void 0) {
|
|
17
45
|
newData = {
|
|
18
46
|
...newData,
|
|
19
47
|
core: {
|
|
20
48
|
...newData?.core,
|
|
21
|
-
[setting]: data[
|
|
49
|
+
[setting]: data["core/edit-post"][setting]
|
|
22
50
|
}
|
|
23
51
|
};
|
|
24
|
-
delete newData[
|
|
52
|
+
delete newData["core/edit-post"][setting];
|
|
25
53
|
}
|
|
26
|
-
if (data?.[
|
|
27
|
-
delete newData[
|
|
54
|
+
if (data?.["core/edit-site"]?.[setting] !== void 0) {
|
|
55
|
+
delete newData["core/edit-site"][setting];
|
|
28
56
|
}
|
|
29
57
|
});
|
|
30
|
-
if (Object.keys(
|
|
31
|
-
delete newData[
|
|
58
|
+
if (Object.keys(newData?.["core/edit-post"] ?? {})?.length === 0) {
|
|
59
|
+
delete newData["core/edit-post"];
|
|
32
60
|
}
|
|
33
|
-
if (Object.keys(
|
|
34
|
-
delete newData[
|
|
61
|
+
if (Object.keys(newData?.["core/edit-site"] ?? {})?.length === 0) {
|
|
62
|
+
delete newData["core/edit-site"];
|
|
35
63
|
}
|
|
36
64
|
return newData;
|
|
37
65
|
}
|
|
38
|
-
//# sourceMappingURL=convert-editor-settings.js.map
|
|
66
|
+
//# sourceMappingURL=convert-editor-settings.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/migrations/preferences-package-data/convert-editor-settings.js"],
|
|
4
|
+
"sourcesContent": ["/**\n * Internal dependencies\n */\n\nexport default function convertEditorSettings( data ) {\n\tlet newData = data;\n\tconst settingsToMoveToCore = [\n\t\t'allowRightClickOverrides',\n\t\t'distractionFree',\n\t\t'editorMode',\n\t\t'fixedToolbar',\n\t\t'focusMode',\n\t\t'hiddenBlockTypes',\n\t\t'inactivePanels',\n\t\t'keepCaretInsideBlock',\n\t\t'mostUsedBlocks',\n\t\t'openPanels',\n\t\t'showBlockBreadcrumbs',\n\t\t'showIconLabels',\n\t\t'showListViewByDefault',\n\t\t'isPublishSidebarEnabled',\n\t\t'isComplementaryAreaVisible',\n\t\t'pinnedItems',\n\t];\n\n\tsettingsToMoveToCore.forEach( ( setting ) => {\n\t\tif ( data?.[ 'core/edit-post' ]?.[ setting ] !== undefined ) {\n\t\t\tnewData = {\n\t\t\t\t...newData,\n\t\t\t\tcore: {\n\t\t\t\t\t...newData?.core,\n\t\t\t\t\t[ setting ]: data[ 'core/edit-post' ][ setting ],\n\t\t\t\t},\n\t\t\t};\n\t\t\tdelete newData[ 'core/edit-post' ][ setting ];\n\t\t}\n\n\t\tif ( data?.[ 'core/edit-site' ]?.[ setting ] !== undefined ) {\n\t\t\tdelete newData[ 'core/edit-site' ][ setting ];\n\t\t}\n\t} );\n\n\tif ( Object.keys( newData?.[ 'core/edit-post' ] ?? {} )?.length === 0 ) {\n\t\tdelete newData[ 'core/edit-post' ];\n\t}\n\n\tif ( Object.keys( newData?.[ 'core/edit-site' ] ?? {} )?.length === 0 ) {\n\t\tdelete newData[ 'core/edit-site' ];\n\t}\n\n\treturn newData;\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAIe,SAAR,sBAAwC,MAAO;AACrD,MAAI,UAAU;AACd,QAAM,uBAAuB;AAAA,IAC5B;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACD;AAEA,uBAAqB,QAAS,CAAE,YAAa;AAC5C,QAAK,OAAQ,gBAAiB,IAAK,OAAQ,MAAM,QAAY;AAC5D,gBAAU;AAAA,QACT,GAAG;AAAA,QACH,MAAM;AAAA,UACL,GAAG,SAAS;AAAA,UACZ,CAAE,OAAQ,GAAG,KAAM,gBAAiB,EAAG,OAAQ;AAAA,QAChD;AAAA,MACD;AACA,aAAO,QAAS,gBAAiB,EAAG,OAAQ;AAAA,IAC7C;AAEA,QAAK,OAAQ,gBAAiB,IAAK,OAAQ,MAAM,QAAY;AAC5D,aAAO,QAAS,gBAAiB,EAAG,OAAQ;AAAA,IAC7C;AAAA,EACD,CAAE;AAEF,MAAK,OAAO,KAAM,UAAW,gBAAiB,KAAK,CAAC,CAAE,GAAG,WAAW,GAAI;AACvE,WAAO,QAAS,gBAAiB;AAAA,EAClC;AAEA,MAAK,OAAO,KAAM,UAAW,gBAAiB,KAAK,CAAC,CAAE,GAAG,WAAW,GAAI;AACvE,WAAO,QAAS,gBAAiB;AAAA,EAClC;AAEA,SAAO;AACR;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,19 +1,40 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var
|
|
4
|
-
Object.
|
|
5
|
-
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
var preferences_package_data_exports = {};
|
|
29
|
+
__export(preferences_package_data_exports, {
|
|
30
|
+
default: () => convertPreferencesPackageData
|
|
6
31
|
});
|
|
7
|
-
exports
|
|
8
|
-
var
|
|
9
|
-
var
|
|
10
|
-
/**
|
|
11
|
-
* Internal dependencies
|
|
12
|
-
*/
|
|
13
|
-
|
|
32
|
+
module.exports = __toCommonJS(preferences_package_data_exports);
|
|
33
|
+
var import_convert_complementary_areas = __toESM(require("./convert-complementary-areas"));
|
|
34
|
+
var import_convert_editor_settings = __toESM(require("./convert-editor-settings"));
|
|
14
35
|
function convertPreferencesPackageData(data) {
|
|
15
|
-
let newData = (0,
|
|
16
|
-
newData = (0,
|
|
36
|
+
let newData = (0, import_convert_complementary_areas.default)(data);
|
|
37
|
+
newData = (0, import_convert_editor_settings.default)(newData);
|
|
17
38
|
return newData;
|
|
18
39
|
}
|
|
19
|
-
//# sourceMappingURL=index.js.map
|
|
40
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/migrations/preferences-package-data/index.js"],
|
|
4
|
+
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport convertComplementaryAreas from './convert-complementary-areas';\nimport convertEditorSettings from './convert-editor-settings';\n\nexport default function convertPreferencesPackageData( data ) {\n\tlet newData = convertComplementaryAreas( data );\n\tnewData = convertEditorSettings( newData );\n\treturn newData;\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,yCAAsC;AACtC,qCAAkC;AAEnB,SAAR,8BAAgD,MAAO;AAC7D,MAAI,cAAU,mCAAAA,SAA2B,IAAK;AAC9C,gBAAU,+BAAAC,SAAuB,OAAQ;AACzC,SAAO;AACR;",
|
|
6
|
+
"names": ["convertComplementaryAreas", "convertEditorSettings"]
|
|
7
|
+
}
|
|
@@ -1,63 +1,32 @@
|
|
|
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 `{ debounce } from @wordpress/compose` in that it
|
|
10
|
-
* waits for promise 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) {
|
|
1
|
+
function debounceAsync(func, delayMS) {
|
|
19
2
|
let timeoutId;
|
|
20
3
|
let activePromise;
|
|
21
4
|
return async function debounced(...args) {
|
|
22
|
-
// This is a leading edge debounce. If there's no promise or timeout
|
|
23
|
-
// in progress, call the debounced function immediately.
|
|
24
5
|
if (!activePromise && !timeoutId) {
|
|
25
6
|
return new Promise((resolve, reject) => {
|
|
26
|
-
// Keep a reference to the promise.
|
|
27
7
|
activePromise = func(...args).then((...thenArgs) => {
|
|
28
8
|
resolve(...thenArgs);
|
|
29
|
-
}).catch(error => {
|
|
9
|
+
}).catch((error) => {
|
|
30
10
|
reject(error);
|
|
31
11
|
}).finally(() => {
|
|
32
|
-
// As soon this promise is complete, clear the way for the
|
|
33
|
-
// next one to happen immediately.
|
|
34
12
|
activePromise = null;
|
|
35
13
|
});
|
|
36
14
|
});
|
|
37
15
|
}
|
|
38
16
|
if (activePromise) {
|
|
39
|
-
// Let any active promises finish before queuing the next request.
|
|
40
17
|
await activePromise;
|
|
41
18
|
}
|
|
42
|
-
|
|
43
|
-
// Clear any active timeouts, abandoning any requests that have
|
|
44
|
-
// been queued but not been made.
|
|
45
19
|
if (timeoutId) {
|
|
46
20
|
clearTimeout(timeoutId);
|
|
47
21
|
timeoutId = null;
|
|
48
22
|
}
|
|
49
|
-
|
|
50
|
-
// Trigger any trailing edge calls to the function.
|
|
51
23
|
return new Promise((resolve, reject) => {
|
|
52
|
-
// Schedule the next request but with a delay.
|
|
53
24
|
timeoutId = setTimeout(() => {
|
|
54
25
|
activePromise = func(...args).then((...thenArgs) => {
|
|
55
26
|
resolve(...thenArgs);
|
|
56
|
-
}).catch(error => {
|
|
27
|
+
}).catch((error) => {
|
|
57
28
|
reject(error);
|
|
58
29
|
}).finally(() => {
|
|
59
|
-
// As soon this promise is complete, clear the way for the
|
|
60
|
-
// next one to happen immediately.
|
|
61
30
|
activePromise = null;
|
|
62
31
|
timeoutId = null;
|
|
63
32
|
});
|
|
@@ -65,4 +34,7 @@ export default function debounceAsync(func, delayMS) {
|
|
|
65
34
|
});
|
|
66
35
|
};
|
|
67
36
|
}
|
|
68
|
-
|
|
37
|
+
export {
|
|
38
|
+
debounceAsync as default
|
|
39
|
+
};
|
|
40
|
+
//# sourceMappingURL=debounce-async.js.map
|