@wordpress/preferences-persistence 2.57.0 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -7
- package/build/create/debounce-async.cjs +55 -58
- package/build/create/debounce-async.cjs.map +1 -7
- package/build/create/index.cjs +75 -91
- package/build/create/index.cjs.map +1 -7
- package/build/get-newest-data.cjs +64 -0
- package/build/get-newest-data.cjs.map +1 -0
- package/build/index.cjs +52 -53
- package/build/index.cjs.map +1 -7
- package/build/is-preferences-data.cjs +20 -0
- package/build/is-preferences-data.cjs.map +1 -0
- package/build/local-storage.cjs +39 -0
- package/build/local-storage.cjs.map +1 -0
- package/build/migrations/legacy-local-storage-data/convert-edit-post-panels.cjs +49 -38
- package/build/migrations/legacy-local-storage-data/convert-edit-post-panels.cjs.map +1 -7
- package/build/migrations/legacy-local-storage-data/index.cjs +95 -83
- package/build/migrations/legacy-local-storage-data/index.cjs.map +1 -7
- package/build/migrations/legacy-local-storage-data/move-feature-preferences.cjs +106 -77
- package/build/migrations/legacy-local-storage-data/move-feature-preferences.cjs.map +1 -7
- package/build/migrations/legacy-local-storage-data/move-individual-preference.cjs +70 -58
- package/build/migrations/legacy-local-storage-data/move-individual-preference.cjs.map +1 -7
- package/build/migrations/legacy-local-storage-data/move-interface-enable-items.cjs +93 -75
- package/build/migrations/legacy-local-storage-data/move-interface-enable-items.cjs.map +1 -7
- package/build/migrations/legacy-local-storage-data/move-third-party-feature-preferences.cjs +77 -65
- package/build/migrations/legacy-local-storage-data/move-third-party-feature-preferences.cjs.map +1 -7
- package/build/migrations/legacy-local-storage-data/types.cjs +5 -0
- package/build/migrations/preferences-package-data/convert-complementary-areas.cjs +19 -35
- package/build/migrations/preferences-package-data/convert-complementary-areas.cjs.map +1 -7
- package/build/migrations/preferences-package-data/convert-editor-settings.cjs +62 -60
- package/build/migrations/preferences-package-data/convert-editor-settings.cjs.map +1 -7
- package/build/migrations/preferences-package-data/index.cjs +29 -32
- package/build/migrations/preferences-package-data/index.cjs.map +1 -7
- package/build/types.cjs +5 -0
- package/build-module/create/debounce-async.mjs +51 -39
- package/build-module/create/debounce-async.mjs.map +1 -7
- package/build-module/create/index.mjs +51 -67
- package/build-module/create/index.mjs.map +1 -7
- package/build-module/get-newest-data.mjs +36 -0
- package/build-module/get-newest-data.mjs.map +1 -0
- package/build-module/index.mjs +24 -25
- package/build-module/index.mjs.map +1 -7
- package/build-module/is-preferences-data.mjs +15 -0
- package/build-module/is-preferences-data.mjs.map +1 -0
- package/build-module/local-storage.mjs +33 -0
- package/build-module/local-storage.mjs.map +1 -0
- package/build-module/migrations/legacy-local-storage-data/convert-edit-post-panels.mjs +45 -19
- package/build-module/migrations/legacy-local-storage-data/convert-edit-post-panels.mjs.map +1 -7
- package/build-module/migrations/legacy-local-storage-data/index.mjs +65 -52
- package/build-module/migrations/legacy-local-storage-data/index.mjs.map +1 -7
- package/build-module/migrations/legacy-local-storage-data/move-feature-preferences.mjs +102 -58
- package/build-module/migrations/legacy-local-storage-data/move-feature-preferences.mjs.map +1 -7
- package/build-module/migrations/legacy-local-storage-data/move-individual-preference.mjs +66 -39
- package/build-module/migrations/legacy-local-storage-data/move-individual-preference.mjs.map +1 -7
- package/build-module/migrations/legacy-local-storage-data/move-interface-enable-items.mjs +89 -56
- package/build-module/migrations/legacy-local-storage-data/move-interface-enable-items.mjs.map +1 -7
- package/build-module/migrations/legacy-local-storage-data/move-third-party-feature-preferences.mjs +73 -46
- package/build-module/migrations/legacy-local-storage-data/move-third-party-feature-preferences.mjs.map +1 -7
- package/build-module/migrations/legacy-local-storage-data/types.mjs +0 -0
- package/build-module/migrations/preferences-package-data/convert-complementary-areas.mjs +15 -16
- package/build-module/migrations/preferences-package-data/convert-complementary-areas.mjs.map +1 -7
- package/build-module/migrations/preferences-package-data/convert-editor-settings.mjs +41 -46
- package/build-module/migrations/preferences-package-data/convert-editor-settings.mjs.map +1 -7
- package/build-module/migrations/preferences-package-data/index.mjs +7 -8
- package/build-module/migrations/preferences-package-data/index.mjs.map +1 -7
- package/build-module/types.mjs +0 -0
- package/build-types/create/debounce-async.d.ts +19 -0
- package/build-types/create/debounce-async.d.ts.map +1 -0
- package/build-types/create/index.d.ts +20 -0
- package/build-types/create/index.d.ts.map +1 -0
- package/build-types/get-newest-data.d.ts +11 -0
- package/build-types/get-newest-data.d.ts.map +1 -0
- package/build-types/index.d.ts +20 -0
- package/build-types/index.d.ts.map +1 -0
- package/build-types/is-preferences-data.d.ts +11 -0
- package/build-types/is-preferences-data.d.ts.map +1 -0
- package/build-types/local-storage.d.ts +19 -0
- package/build-types/local-storage.d.ts.map +1 -0
- package/build-types/migrations/legacy-local-storage-data/convert-edit-post-panels.d.ts +35 -0
- package/build-types/migrations/legacy-local-storage-data/convert-edit-post-panels.d.ts.map +1 -0
- package/build-types/migrations/legacy-local-storage-data/index.d.ts +22 -0
- package/build-types/migrations/legacy-local-storage-data/index.d.ts.map +1 -0
- package/build-types/migrations/legacy-local-storage-data/move-feature-preferences.d.ts +60 -0
- package/build-types/migrations/legacy-local-storage-data/move-feature-preferences.d.ts.map +1 -0
- package/build-types/migrations/legacy-local-storage-data/move-individual-preference.d.ts +42 -0
- package/build-types/migrations/legacy-local-storage-data/move-individual-preference.d.ts.map +1 -0
- package/build-types/migrations/legacy-local-storage-data/move-interface-enable-items.d.ts +50 -0
- package/build-types/migrations/legacy-local-storage-data/move-interface-enable-items.d.ts.map +1 -0
- package/build-types/migrations/legacy-local-storage-data/move-third-party-feature-preferences.d.ts +44 -0
- package/build-types/migrations/legacy-local-storage-data/move-third-party-feature-preferences.d.ts.map +1 -0
- package/build-types/migrations/legacy-local-storage-data/types.d.ts +60 -0
- package/build-types/migrations/legacy-local-storage-data/types.d.ts.map +1 -0
- package/build-types/migrations/preferences-package-data/convert-complementary-areas.d.ts +5 -0
- package/build-types/migrations/preferences-package-data/convert-complementary-areas.d.ts.map +1 -0
- package/build-types/migrations/preferences-package-data/convert-editor-settings.d.ts +5 -0
- package/build-types/migrations/preferences-package-data/convert-editor-settings.d.ts.map +1 -0
- package/build-types/migrations/preferences-package-data/index.d.ts +5 -0
- package/build-types/migrations/preferences-package-data/index.d.ts.map +1 -0
- package/build-types/types.d.ts +40 -0
- package/build-types/types.d.ts.map +1 -0
- package/package.json +8 -7
- package/src/create/{debounce-async.js → debounce-async.ts} +13 -10
- package/src/create/index.ts +95 -0
- package/src/create/test/{debounce-async.js → debounce-async.ts} +7 -3
- package/src/create/test/{index.jsdom.test.js → index.jsdom.test.ts} +52 -4
- package/src/get-newest-data.ts +50 -0
- package/src/index.ts +40 -0
- package/src/is-preferences-data.ts +15 -0
- package/src/local-storage.ts +30 -0
- package/src/migrations/legacy-local-storage-data/{convert-edit-post-panels.js → convert-edit-post-panels.ts} +13 -5
- package/src/migrations/legacy-local-storage-data/{index.js → index.ts} +22 -15
- package/src/migrations/legacy-local-storage-data/{move-feature-preferences.js → move-feature-preferences.ts} +13 -7
- package/src/migrations/legacy-local-storage-data/{move-individual-preference.js → move-individual-preference.ts} +15 -12
- package/src/migrations/legacy-local-storage-data/{move-interface-enable-items.js → move-interface-enable-items.ts} +6 -2
- package/src/migrations/legacy-local-storage-data/{move-third-party-feature-preferences.js → move-third-party-feature-preferences.ts} +8 -4
- package/src/migrations/legacy-local-storage-data/test/{index.js → index.ts} +11 -0
- package/src/migrations/legacy-local-storage-data/types.ts +66 -0
- package/src/migrations/preferences-package-data/convert-complementary-areas.ts +21 -0
- package/src/migrations/preferences-package-data/convert-editor-settings.ts +58 -0
- package/src/migrations/preferences-package-data/{index.js → index.ts} +4 -1
- package/src/migrations/preferences-package-data/test/{convert-complementary-areas.js → convert-complementary-areas.ts} +10 -0
- package/src/migrations/preferences-package-data/test/convert-editor-settings.ts +58 -0
- package/src/test/index.jsdom.test.ts +97 -0
- package/src/test/local-storage.jsdom.test.ts +50 -0
- package/src/types.ts +43 -0
- package/CHANGELOG.md +0 -228
- package/src/create/index.js +0 -105
- package/src/index.js +0 -47
- package/src/migrations/preferences-package-data/convert-complementary-areas.js +0 -16
- package/src/migrations/preferences-package-data/convert-editor-settings.js +0 -48
- package/src/migrations/preferences-package-data/test/convert-editor-settings.js +0 -20
- /package/src/migrations/legacy-local-storage-data/test/{convert-edit-post-panels.js → convert-edit-post-panels.ts} +0 -0
- /package/src/migrations/legacy-local-storage-data/test/{move-feature-preferences.js → move-feature-preferences.ts} +0 -0
- /package/src/migrations/legacy-local-storage-data/test/{move-individual-preference.js → move-individual-preference.ts} +0 -0
- /package/src/migrations/legacy-local-storage-data/test/{move-interface-enable-items.js → move-interface-enable-items.ts} +0 -0
- /package/src/migrations/legacy-local-storage-data/test/{move-third-party-feature-preferences.js → move-third-party-feature-preferences.ts} +0 -0
- /package/src/migrations/preferences-package-data/test/{index.js → index.ts} +0 -0
|
@@ -1,68 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperties(exports, {
|
|
3
|
+
__esModule: { value: true },
|
|
4
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
5
|
+
});
|
|
6
|
+
// \0rolldown/runtime.js
|
|
7
|
+
var __create = Object.create;
|
|
1
8
|
var __defProp = Object.defineProperty;
|
|
2
9
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
10
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
11
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
4
12
|
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
13
|
var __copyProps = (to, from, except, desc) => {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
15
|
+
key = keys[i];
|
|
16
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
17
|
+
get: ((k) => from[k]).bind(null, key),
|
|
18
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
return to;
|
|
16
22
|
};
|
|
17
|
-
var
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
24
|
+
value: mod,
|
|
25
|
+
enumerable: true
|
|
26
|
+
}) : target, mod));
|
|
27
|
+
let ______is_preferences_data_ts = require("../../is-preferences-data.cjs");
|
|
28
|
+
______is_preferences_data_ts = __toESM(______is_preferences_data_ts);
|
|
29
|
+
// packages/preferences-persistence/src/migrations/preferences-package-data/convert-editor-settings.ts
|
|
30
|
+
const copyScope = (scope) => (0, ______is_preferences_data_ts.default)(scope) ? { ...scope } : void 0;
|
|
25
31
|
function convertEditorSettings(data) {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
delete newData["core/edit-post"];
|
|
62
|
-
}
|
|
63
|
-
if (Object.keys(newData?.["core/edit-site"] ?? {})?.length === 0) {
|
|
64
|
-
delete newData["core/edit-site"];
|
|
65
|
-
}
|
|
66
|
-
return newData;
|
|
32
|
+
const newData = { ...data };
|
|
33
|
+
const editPost = copyScope(data["core/edit-post"]);
|
|
34
|
+
const editSite = copyScope(data["core/edit-site"]);
|
|
35
|
+
[
|
|
36
|
+
"allowRightClickOverrides",
|
|
37
|
+
"distractionFree",
|
|
38
|
+
"editorMode",
|
|
39
|
+
"fixedToolbar",
|
|
40
|
+
"focusMode",
|
|
41
|
+
"hiddenBlockTypes",
|
|
42
|
+
"inactivePanels",
|
|
43
|
+
"keepCaretInsideBlock",
|
|
44
|
+
"mostUsedBlocks",
|
|
45
|
+
"openPanels",
|
|
46
|
+
"showBlockBreadcrumbs",
|
|
47
|
+
"showIconLabels",
|
|
48
|
+
"showListViewByDefault",
|
|
49
|
+
"isPublishSidebarEnabled",
|
|
50
|
+
"isComplementaryAreaVisible",
|
|
51
|
+
"pinnedItems"
|
|
52
|
+
].forEach((setting) => {
|
|
53
|
+
if (editPost?.[setting] !== void 0) {
|
|
54
|
+
newData.core = {
|
|
55
|
+
...copyScope(newData.core),
|
|
56
|
+
[setting]: editPost[setting]
|
|
57
|
+
};
|
|
58
|
+
delete editPost[setting];
|
|
59
|
+
}
|
|
60
|
+
if (editSite?.[setting] !== void 0) delete editSite[setting];
|
|
61
|
+
});
|
|
62
|
+
if (editPost && Object.keys(editPost).length > 0) newData["core/edit-post"] = editPost;
|
|
63
|
+
else delete newData["core/edit-post"];
|
|
64
|
+
if (editSite && Object.keys(editSite).length > 0) newData["core/edit-site"] = editSite;
|
|
65
|
+
else delete newData["core/edit-site"];
|
|
66
|
+
return newData;
|
|
67
67
|
}
|
|
68
|
-
|
|
68
|
+
exports.default = convertEditorSettings;
|
|
69
|
+
|
|
70
|
+
//# sourceMappingURL=convert-editor-settings.cjs.map
|
|
@@ -1,7 +1 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/migrations/preferences-package-data/convert-editor-settings.js"],
|
|
4
|
-
"sourcesContent": ["export 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;AAAe,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
|
+
{"version":3,"file":"convert-editor-settings.cjs","names":["isPreferencesData"],"sources":["../../../src/migrations/preferences-package-data/convert-editor-settings.ts"],"sourcesContent":["import isPreferencesData from '../../is-preferences-data';\nimport type { ScopedPreferences } from '../../types';\n\nconst copyScope = ( scope: unknown ) =>\n\tisPreferencesData( scope ) ? { ...scope } : undefined;\n\nexport default function convertEditorSettings( data: ScopedPreferences ) {\n\tconst newData = { ...data };\n\tconst editPost = copyScope( data[ 'core/edit-post' ] );\n\tconst editSite = copyScope( data[ 'core/edit-site' ] );\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 ( editPost?.[ setting ] !== undefined ) {\n\t\t\tnewData.core = {\n\t\t\t\t...copyScope( newData.core ),\n\t\t\t\t[ setting ]: editPost[ setting ],\n\t\t\t};\n\t\t\tdelete editPost[ setting ];\n\t\t}\n\n\t\tif ( editSite?.[ setting ] !== undefined ) {\n\t\t\tdelete editSite[ setting ];\n\t\t}\n\t} );\n\n\t// Empty and invalid scopes are removed rather than persisted.\n\tif ( editPost && Object.keys( editPost ).length > 0 ) {\n\t\tnewData[ 'core/edit-post' ] = editPost;\n\t} else {\n\t\tdelete newData[ 'core/edit-post' ];\n\t}\n\n\tif ( editSite && Object.keys( editSite ).length > 0 ) {\n\t\tnewData[ 'core/edit-site' ] = editSite;\n\t} else {\n\t\tdelete newData[ 'core/edit-site' ];\n\t}\n\n\treturn newData;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGA,MAAM,aAAc,WAAA,GACnBA,6BAAAA,QAAAA,CAAmB,KAAM,IAAI,EAAE,GAAG,MAAM,IAAI,KAAA;AAE7C,SAAwB,sBAAuB,MAA0B;CACxE,MAAM,UAAU,EAAE,GAAG,KAAK;CAC1B,MAAM,WAAW,UAAW,KAAM,iBAAmB;CACrD,MAAM,WAAW,UAAW,KAAM,iBAAmB;CAoBrD;EAlBC;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CAGkB,CAAC,CAAC,SAAW,YAAa;EAC5C,IAAK,WAAY,aAAc,KAAA,GAAY;GAC1C,QAAQ,OAAO;IACd,GAAG,UAAW,QAAQ,IAAK;KACzB,UAAW,SAAU;GACxB;GACA,OAAO,SAAU;EAClB;EAEA,IAAK,WAAY,aAAc,KAAA,GAC9B,OAAO,SAAU;CAEnB,CAAE;CAGF,IAAK,YAAY,OAAO,KAAM,QAAS,CAAC,CAAC,SAAS,GACjD,QAAS,oBAAqB;MAE9B,OAAO,QAAS;CAGjB,IAAK,YAAY,OAAO,KAAM,QAAS,CAAC,CAAC,SAAS,GACjD,QAAS,oBAAqB;MAE9B,OAAO,QAAS;CAGjB,OAAO;AACR"}
|
|
@@ -1,42 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperties(exports, {
|
|
3
|
+
__esModule: { value: true },
|
|
4
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
5
|
+
});
|
|
6
|
+
// \0rolldown/runtime.js
|
|
1
7
|
var __create = Object.create;
|
|
2
8
|
var __defProp = Object.defineProperty;
|
|
3
9
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
10
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
11
|
var __getProtoOf = Object.getPrototypeOf;
|
|
6
12
|
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
13
|
var __copyProps = (to, from, except, desc) => {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
15
|
+
key = keys[i];
|
|
16
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
17
|
+
get: ((k) => from[k]).bind(null, key),
|
|
18
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
return to;
|
|
18
22
|
};
|
|
19
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
)
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
// packages/preferences-persistence/src/migrations/preferences-package-data/index.js
|
|
30
|
-
var preferences_package_data_exports = {};
|
|
31
|
-
__export(preferences_package_data_exports, {
|
|
32
|
-
default: () => convertPreferencesPackageData
|
|
33
|
-
});
|
|
34
|
-
module.exports = __toCommonJS(preferences_package_data_exports);
|
|
35
|
-
var import_convert_complementary_areas = __toESM(require("./convert-complementary-areas.cjs"));
|
|
36
|
-
var import_convert_editor_settings = __toESM(require("./convert-editor-settings.cjs"));
|
|
23
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
24
|
+
value: mod,
|
|
25
|
+
enumerable: true
|
|
26
|
+
}) : target, mod));
|
|
27
|
+
let __convert_complementary_areas_ts = require("./convert-complementary-areas.cjs");
|
|
28
|
+
__convert_complementary_areas_ts = __toESM(__convert_complementary_areas_ts);
|
|
29
|
+
let __convert_editor_settings_ts = require("./convert-editor-settings.cjs");
|
|
30
|
+
__convert_editor_settings_ts = __toESM(__convert_editor_settings_ts);
|
|
31
|
+
// packages/preferences-persistence/src/migrations/preferences-package-data/index.ts
|
|
37
32
|
function convertPreferencesPackageData(data) {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
33
|
+
let newData = (0, __convert_complementary_areas_ts.default)(data);
|
|
34
|
+
newData = (0, __convert_editor_settings_ts.default)(newData);
|
|
35
|
+
return newData;
|
|
41
36
|
}
|
|
42
|
-
|
|
37
|
+
exports.default = convertPreferencesPackageData;
|
|
38
|
+
|
|
39
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -1,7 +1 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/migrations/preferences-package-data/index.js"],
|
|
4
|
-
"sourcesContent": ["import 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;AAAA,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
|
+
{"version":3,"file":"index.cjs","names":["convertComplementaryAreas","convertEditorSettings"],"sources":["../../../src/migrations/preferences-package-data/index.ts"],"sourcesContent":["import convertComplementaryAreas from './convert-complementary-areas';\nimport convertEditorSettings from './convert-editor-settings';\nimport type { ScopedPreferences } from '../../types';\n\nexport default function convertPreferencesPackageData(\n\tdata: ScopedPreferences\n) {\n\tlet newData = convertComplementaryAreas( data );\n\tnewData = convertEditorSettings( newData );\n\treturn newData;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,SAAwB,8BACvB,MACC;CACD,IAAI,WAAA,GAAUA,iCAAAA,QAAAA,CAA2B,IAAK;CAC9C,WAAA,GAAUC,6BAAAA,QAAAA,CAAuB,OAAQ;CACzC,OAAO;AACR"}
|
package/build/types.cjs
ADDED
|
@@ -1,41 +1,53 @@
|
|
|
1
|
-
// packages/preferences-persistence/src/create/debounce-async.
|
|
1
|
+
// packages/preferences-persistence/src/create/debounce-async.ts
|
|
2
|
+
/**
|
|
3
|
+
* Performs a leading edge debounce of async functions.
|
|
4
|
+
*
|
|
5
|
+
* If three functions are throttled at the same time:
|
|
6
|
+
* - The first happens immediately.
|
|
7
|
+
* - The second is never called.
|
|
8
|
+
* - The third happens `delayMS` milliseconds after the first has resolved.
|
|
9
|
+
*
|
|
10
|
+
* This is distinct from `{ debounce } from @wordpress/compose` in that it
|
|
11
|
+
* waits for promise resolution.
|
|
12
|
+
*
|
|
13
|
+
* @param func A function that returns a promise.
|
|
14
|
+
* @param delayMS A delay in milliseconds.
|
|
15
|
+
*
|
|
16
|
+
* @return A function that debounce whatever function is passed
|
|
17
|
+
* to it.
|
|
18
|
+
*/
|
|
2
19
|
function debounceAsync(func, delayMS) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
});
|
|
34
|
-
}, delayMS);
|
|
35
|
-
});
|
|
36
|
-
};
|
|
20
|
+
let timeoutId;
|
|
21
|
+
let activePromise;
|
|
22
|
+
return async function debounced(...args) {
|
|
23
|
+
if (!activePromise && !timeoutId) return new Promise((resolve, reject) => {
|
|
24
|
+
activePromise = func(...args).then((...thenArgs) => {
|
|
25
|
+
resolve(...thenArgs);
|
|
26
|
+
}).catch((error) => {
|
|
27
|
+
reject(error);
|
|
28
|
+
}).finally(() => {
|
|
29
|
+
activePromise = null;
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
if (activePromise) await activePromise;
|
|
33
|
+
if (timeoutId) {
|
|
34
|
+
clearTimeout(timeoutId);
|
|
35
|
+
timeoutId = null;
|
|
36
|
+
}
|
|
37
|
+
return new Promise((resolve, reject) => {
|
|
38
|
+
timeoutId = setTimeout(() => {
|
|
39
|
+
activePromise = func(...args).then((...thenArgs) => {
|
|
40
|
+
resolve(...thenArgs);
|
|
41
|
+
}).catch((error) => {
|
|
42
|
+
reject(error);
|
|
43
|
+
}).finally(() => {
|
|
44
|
+
activePromise = null;
|
|
45
|
+
timeoutId = null;
|
|
46
|
+
});
|
|
47
|
+
}, delayMS);
|
|
48
|
+
});
|
|
49
|
+
};
|
|
37
50
|
}
|
|
38
|
-
export {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
//# sourceMappingURL=debounce-async.mjs.map
|
|
51
|
+
export { debounceAsync as default };
|
|
52
|
+
|
|
53
|
+
//# sourceMappingURL=debounce-async.mjs.map
|
|
@@ -1,7 +1 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/create/debounce-async.js"],
|
|
4
|
-
"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 `{ debounce } from @wordpress/compose` in that it\n * waits for promise 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"],
|
|
5
|
-
"mappings": ";AAiBe,SAAR,cAAgC,MAAM,SAAU;AACtD,MAAI;AACJ,MAAI;AAEJ,SAAO,eAAe,aAAc,MAAO;AAG1C,QAAK,CAAE,iBAAiB,CAAE,WAAY;AACrC,aAAO,IAAI,QAAS,CAAE,SAAS,WAAY;AAE1C,wBAAgB,KAAM,GAAG,IAAK,EAC5B,KAAM,IAAK,aAAc;AACzB,kBAAS,GAAG,QAAS;AAAA,QACtB,CAAE,EACD,MAAO,CAAE,UAAW;AACpB,iBAAQ,KAAM;AAAA,QACf,CAAE,EACD,QAAS,MAAM;AAGf,0BAAgB;AAAA,QACjB,CAAE;AAAA,MACJ,CAAE;AAAA,IACH;AAEA,QAAK,eAAgB;AAEpB,YAAM;AAAA,IACP;AAIA,QAAK,WAAY;AAChB,mBAAc,SAAU;AACxB,kBAAY;AAAA,IACb;AAGA,WAAO,IAAI,QAAS,CAAE,SAAS,WAAY;AAE1C,kBAAY,WAAY,MAAM;AAC7B,wBAAgB,KAAM,GAAG,IAAK,EAC5B,KAAM,IAAK,aAAc;AACzB,kBAAS,GAAG,QAAS;AAAA,QACtB,CAAE,EACD,MAAO,CAAE,UAAW;AACpB,iBAAQ,KAAM;AAAA,QACf,CAAE,EACD,QAAS,MAAM;AAGf,0BAAgB;AAChB,sBAAY;AAAA,QACb,CAAE;AAAA,MACJ,GAAG,OAAQ;AAAA,IACZ,CAAE;AAAA,EACH;AACD;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
1
|
+
{"version":3,"file":"debounce-async.mjs","names":[],"sources":["../../src/create/debounce-async.ts"],"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 `{ debounce } from @wordpress/compose` in that it\n * waits for promise resolution.\n *\n * @param func A function that returns a promise.\n * @param delayMS A delay in milliseconds.\n *\n * @return A function that debounce whatever function is passed\n * to it.\n */\nexport default function debounceAsync< Args extends unknown[], Result >(\n\tfunc: ( ...args: Args ) => Promise< Result >,\n\tdelayMS: number\n): ( ...args: Args ) => Promise< Result > {\n\tlet timeoutId: ReturnType< typeof setTimeout > | null | undefined;\n\tlet activePromise: Promise< void > | null | undefined;\n\n\treturn async function debounced( ...args: 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< Result >( ( 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< Result >( ( 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"],"mappings":";;;;;;;;;;;;;;;;;;AAiBA,SAAwB,cACvB,MACA,SACyC;CACzC,IAAI;CACJ,IAAI;CAEJ,OAAO,eAAe,UAAW,GAAG,MAAa;EAGhD,IAAK,CAAE,iBAAiB,CAAE,WACzB,OAAO,IAAI,SAAqB,SAAS,WAAY;GAEpD,gBAAgB,KAAM,GAAG,IAAK,CAAC,CAC7B,MAAQ,GAAG,aAAc;IACzB,QAAS,GAAG,QAAS;GACtB,CAAE,CAAC,CACF,OAAS,UAAW;IACpB,OAAQ,KAAM;GACf,CAAE,CAAC,CACF,cAAe;IAGf,gBAAgB;GACjB,CAAE;EACJ,CAAE;EAGH,IAAK,eAEJ,MAAM;EAKP,IAAK,WAAY;GAChB,aAAc,SAAU;GACxB,YAAY;EACb;EAGA,OAAO,IAAI,SAAqB,SAAS,WAAY;GAEpD,YAAY,iBAAkB;IAC7B,gBAAgB,KAAM,GAAG,IAAK,CAAC,CAC7B,MAAQ,GAAG,aAAc;KACzB,QAAS,GAAG,QAAS;IACtB,CAAE,CAAC,CACF,OAAS,UAAW;KACpB,OAAQ,KAAM;IACf,CAAE,CAAC,CACF,cAAe;KAGf,gBAAgB;KAChB,YAAY;IACb,CAAE;GACJ,GAAG,OAAQ;EACZ,CAAE;CACH;AACD"}
|
|
@@ -1,70 +1,54 @@
|
|
|
1
|
-
// packages/preferences-persistence/src/create/index.js
|
|
2
1
|
import apiFetch from "@wordpress/api-fetch";
|
|
3
2
|
import debounceAsync from "./debounce-async.mjs";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
// much less.
|
|
53
|
-
keepalive: true,
|
|
54
|
-
data: {
|
|
55
|
-
meta: {
|
|
56
|
-
persisted_preferences: dataWithTimestamp
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
}).catch(() => {
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
return {
|
|
63
|
-
get,
|
|
64
|
-
set
|
|
65
|
-
};
|
|
3
|
+
import getNewestData from "../get-newest-data.mjs";
|
|
4
|
+
import isPreferencesData from "../is-preferences-data.mjs";
|
|
5
|
+
import { writeStoredJSON } from "../local-storage.mjs";
|
|
6
|
+
// packages/preferences-persistence/src/create/index.ts
|
|
7
|
+
/**
|
|
8
|
+
* Creates a persistence layer that stores data in WordPress user meta via the
|
|
9
|
+
* REST API.
|
|
10
|
+
*
|
|
11
|
+
* @param {CreateOptions} [options]
|
|
12
|
+
* @param {PreferencesData|null} [options.preloadedData] Any persisted preferences data that should be preloaded.
|
|
13
|
+
* When set, the persistence layer will avoid fetching data
|
|
14
|
+
* from the REST API.
|
|
15
|
+
* @param {string} [options.localStorageRestoreKey] The key to use for restoring the localStorage backup, used
|
|
16
|
+
* when the persistence layer calls `localStorage.getItem` or
|
|
17
|
+
* `localStorage.setItem`.
|
|
18
|
+
* @param {number} [options.requestDebounceMS] Debounce requests to the API so that they only occur at
|
|
19
|
+
* minimum every `requestDebounceMS` milliseconds, and don't
|
|
20
|
+
* swamp the server. Defaults to 2500ms.
|
|
21
|
+
*
|
|
22
|
+
* @return A persistence layer for WordPress user meta.
|
|
23
|
+
*/
|
|
24
|
+
function create({ preloadedData, localStorageRestoreKey = "WP_PREFERENCES_RESTORE_DATA", requestDebounceMS = 2500 } = {}) {
|
|
25
|
+
let cache = isPreferencesData(preloadedData) ? preloadedData : void 0;
|
|
26
|
+
const debouncedApiFetch = debounceAsync(apiFetch, requestDebounceMS);
|
|
27
|
+
async function get() {
|
|
28
|
+
if (cache) return cache;
|
|
29
|
+
const user = await apiFetch({ path: "/wp/v2/users/me?context=edit" });
|
|
30
|
+
cache = getNewestData(user?.meta?.persisted_preferences, localStorageRestoreKey) ?? {};
|
|
31
|
+
return cache;
|
|
32
|
+
}
|
|
33
|
+
function set(newData) {
|
|
34
|
+
const dataWithTimestamp = {
|
|
35
|
+
...newData,
|
|
36
|
+
_modified: (/* @__PURE__ */ new Date()).toISOString()
|
|
37
|
+
};
|
|
38
|
+
cache = dataWithTimestamp;
|
|
39
|
+
writeStoredJSON(localStorageRestoreKey, dataWithTimestamp);
|
|
40
|
+
debouncedApiFetch({
|
|
41
|
+
path: "/wp/v2/users/me",
|
|
42
|
+
method: "PUT",
|
|
43
|
+
keepalive: true,
|
|
44
|
+
data: { meta: { persisted_preferences: dataWithTimestamp } }
|
|
45
|
+
}).catch(() => {});
|
|
46
|
+
}
|
|
47
|
+
return {
|
|
48
|
+
get,
|
|
49
|
+
set
|
|
50
|
+
};
|
|
66
51
|
}
|
|
67
|
-
export {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
//# sourceMappingURL=index.mjs.map
|
|
52
|
+
export { create as default };
|
|
53
|
+
|
|
54
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -1,7 +1 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/create/index.js"],
|
|
4
|
-
"sourcesContent": ["import apiFetch from '@wordpress/api-fetch';\nimport debounceAsync from './debounce-async';\n\nconst EMPTY_OBJECT = {};\nconst localStorage = window.localStorage;\n\n/**\n * Creates a persistence layer that stores data in WordPress user meta via the\n * REST API.\n *\n * @param {Object} options\n * @param {?Object} options.preloadedData Any persisted preferences data that should be preloaded.\n * When set, the persistence layer will avoid fetching data\n * from the REST API.\n * @param {?string} options.localStorageRestoreKey The key to use for restoring the localStorage backup, used\n * when the persistence layer calls `localStorage.getItem` or\n * `localStorage.setItem`.\n * @param {?number} options.requestDebounceMS Debounce requests to the API so that they only occur at\n * minimum every `requestDebounceMS` milliseconds, and don't\n * swamp the server. Defaults to 2500ms.\n *\n * @return {Object} A persistence layer for WordPress user meta.\n */\nexport default function create( {\n\tpreloadedData,\n\tlocalStorageRestoreKey = 'WP_PREFERENCES_RESTORE_DATA',\n\trequestDebounceMS = 2500,\n} = {} ) {\n\tlet cache = preloadedData;\n\tconst debouncedApiFetch = debounceAsync( apiFetch, requestDebounceMS );\n\n\tasync function get() {\n\t\tif ( cache ) {\n\t\t\treturn cache;\n\t\t}\n\n\t\tconst user = await apiFetch( {\n\t\t\tpath: '/wp/v2/users/me?context=edit',\n\t\t} );\n\n\t\tconst serverData = user?.meta?.persisted_preferences;\n\t\tconst localData = JSON.parse(\n\t\t\tlocalStorage.getItem( localStorageRestoreKey )\n\t\t);\n\n\t\t// Date parse returns NaN for invalid input. Coerce anything invalid\n\t\t// into a conveniently comparable zero.\n\t\tconst serverTimestamp = Date.parse( serverData?._modified ) || 0;\n\t\tconst localTimestamp = Date.parse( localData?._modified ) || 0;\n\n\t\t// Prefer server data if it exists and is more recent.\n\t\t// Otherwise fallback to localStorage data.\n\t\tif ( serverData && serverTimestamp >= localTimestamp ) {\n\t\t\tcache = serverData;\n\t\t} else if ( localData ) {\n\t\t\tcache = localData;\n\t\t} else {\n\t\t\tcache = EMPTY_OBJECT;\n\t\t}\n\n\t\treturn cache;\n\t}\n\n\tfunction set( newData ) {\n\t\tconst dataWithTimestamp = {\n\t\t\t...newData,\n\t\t\t_modified: new Date().toISOString(),\n\t\t};\n\t\tcache = dataWithTimestamp;\n\n\t\t// Store data in local storage as a fallback. If for some reason the\n\t\t// api request does not complete or becomes unavailable, this data\n\t\t// can be used to restore preferences.\n\t\tlocalStorage.setItem(\n\t\t\tlocalStorageRestoreKey,\n\t\t\tJSON.stringify( dataWithTimestamp )\n\t\t);\n\n\t\t// The user meta endpoint seems susceptible to errors when consecutive\n\t\t// requests are made in quick succession. Ensure there's a gap between\n\t\t// any consecutive requests.\n\t\t//\n\t\t// Catch and do nothing with errors from the REST API.\n\t\tdebouncedApiFetch( {\n\t\t\tpath: '/wp/v2/users/me',\n\t\t\tmethod: 'PUT',\n\t\t\t// `keepalive` will still send the request in the background,\n\t\t\t// even when a browser unload event might interrupt it.\n\t\t\t// This should hopefully make things more resilient.\n\t\t\t// This does have a size limit of 64kb, but the data is usually\n\t\t\t// much less.\n\t\t\tkeepalive: true,\n\t\t\tdata: {\n\t\t\t\tmeta: {\n\t\t\t\t\tpersisted_preferences: dataWithTimestamp,\n\t\t\t\t},\n\t\t\t},\n\t\t} ).catch( () => {} );\n\t}\n\n\treturn {\n\t\tget,\n\t\tset,\n\t};\n}\n"],
|
|
5
|
-
"mappings": ";AAAA,OAAO,cAAc;AACrB,OAAO,mBAAmB;AAE1B,IAAM,eAAe,CAAC;AACtB,IAAM,eAAe,OAAO;AAmBb,SAAR,OAAyB;AAAA,EAC/B;AAAA,EACA,yBAAyB;AAAA,EACzB,oBAAoB;AACrB,IAAI,CAAC,GAAI;AACR,MAAI,QAAQ;AACZ,QAAM,oBAAoB,cAAe,UAAU,iBAAkB;AAErE,iBAAe,MAAM;AACpB,QAAK,OAAQ;AACZ,aAAO;AAAA,IACR;AAEA,UAAM,OAAO,MAAM,SAAU;AAAA,MAC5B,MAAM;AAAA,IACP,CAAE;AAEF,UAAM,aAAa,MAAM,MAAM;AAC/B,UAAM,YAAY,KAAK;AAAA,MACtB,aAAa,QAAS,sBAAuB;AAAA,IAC9C;AAIA,UAAM,kBAAkB,KAAK,MAAO,YAAY,SAAU,KAAK;AAC/D,UAAM,iBAAiB,KAAK,MAAO,WAAW,SAAU,KAAK;AAI7D,QAAK,cAAc,mBAAmB,gBAAiB;AACtD,cAAQ;AAAA,IACT,WAAY,WAAY;AACvB,cAAQ;AAAA,IACT,OAAO;AACN,cAAQ;AAAA,IACT;AAEA,WAAO;AAAA,EACR;AAEA,WAAS,IAAK,SAAU;AACvB,UAAM,oBAAoB;AAAA,MACzB,GAAG;AAAA,MACH,YAAW,oBAAI,KAAK,GAAE,YAAY;AAAA,IACnC;AACA,YAAQ;AAKR,iBAAa;AAAA,MACZ;AAAA,MACA,KAAK,UAAW,iBAAkB;AAAA,IACnC;AAOA,sBAAmB;AAAA,MAClB,MAAM;AAAA,MACN,QAAQ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,MAMR,WAAW;AAAA,MACX,MAAM;AAAA,QACL,MAAM;AAAA,UACL,uBAAuB;AAAA,QACxB;AAAA,MACD;AAAA,IACD,CAAE,EAAE,MAAO,MAAM;AAAA,IAAC,CAAE;AAAA,EACrB;AAEA,SAAO;AAAA,IACN;AAAA,IACA;AAAA,EACD;AACD;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/create/index.ts"],"sourcesContent":["import apiFetch from '@wordpress/api-fetch';\nimport debounceAsync from './debounce-async';\nimport getNewestData from '../get-newest-data';\nimport isPreferencesData from '../is-preferences-data';\nimport { writeStoredJSON } from '../local-storage';\nimport type {\n\tCreateOptions,\n\tPersistenceLayer,\n\tPreferencesData,\n} from '../types';\n\n/**\n * Creates a persistence layer that stores data in WordPress user meta via the\n * REST API.\n *\n * @param {CreateOptions} [options]\n * @param {PreferencesData|null} [options.preloadedData] Any persisted preferences data that should be preloaded.\n * When set, the persistence layer will avoid fetching data\n * from the REST API.\n * @param {string} [options.localStorageRestoreKey] The key to use for restoring the localStorage backup, used\n * when the persistence layer calls `localStorage.getItem` or\n * `localStorage.setItem`.\n * @param {number} [options.requestDebounceMS] Debounce requests to the API so that they only occur at\n * minimum every `requestDebounceMS` milliseconds, and don't\n * swamp the server. Defaults to 2500ms.\n *\n * @return A persistence layer for WordPress user meta.\n */\nexport default function create( {\n\tpreloadedData,\n\tlocalStorageRestoreKey = 'WP_PREFERENCES_RESTORE_DATA',\n\trequestDebounceMS = 2500,\n}: CreateOptions = {} ): PersistenceLayer {\n\tlet cache = isPreferencesData( preloadedData ) ? preloadedData : undefined;\n\tconst debouncedApiFetch = debounceAsync( apiFetch, requestDebounceMS );\n\n\tasync function get() {\n\t\tif ( cache ) {\n\t\t\treturn cache;\n\t\t}\n\n\t\tconst user = await apiFetch< {\n\t\t\tmeta?: { persisted_preferences?: unknown };\n\t\t} >( {\n\t\t\tpath: '/wp/v2/users/me?context=edit',\n\t\t} );\n\n\t\tcache =\n\t\t\tgetNewestData(\n\t\t\t\tuser?.meta?.persisted_preferences,\n\t\t\t\tlocalStorageRestoreKey\n\t\t\t) ?? {};\n\n\t\treturn cache;\n\t}\n\n\tfunction set( newData: PreferencesData ) {\n\t\tconst dataWithTimestamp = {\n\t\t\t...newData,\n\t\t\t_modified: new Date().toISOString(),\n\t\t};\n\t\tcache = dataWithTimestamp;\n\n\t\t// Store data in local storage as a fallback. If for some reason the\n\t\t// api request does not complete or becomes unavailable, this data\n\t\t// can be used to restore preferences.\n\t\twriteStoredJSON( localStorageRestoreKey, dataWithTimestamp );\n\n\t\t// The user meta endpoint seems susceptible to errors when consecutive\n\t\t// requests are made in quick succession. Ensure there's a gap between\n\t\t// any consecutive requests.\n\t\t//\n\t\t// Catch and do nothing with errors from the REST API.\n\t\tdebouncedApiFetch( {\n\t\t\tpath: '/wp/v2/users/me',\n\t\t\tmethod: 'PUT',\n\t\t\t// `keepalive` will still send the request in the background,\n\t\t\t// even when a browser unload event might interrupt it.\n\t\t\t// This should hopefully make things more resilient.\n\t\t\t// This does have a size limit of 64kb, but the data is usually\n\t\t\t// much less.\n\t\t\tkeepalive: true,\n\t\t\tdata: {\n\t\t\t\tmeta: {\n\t\t\t\t\tpersisted_preferences: dataWithTimestamp,\n\t\t\t\t},\n\t\t\t},\n\t\t} ).catch( () => {} );\n\t}\n\n\treturn {\n\t\tget,\n\t\tset,\n\t};\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AA4BA,SAAwB,OAAQ,EAC/B,eACA,yBAAyB,+BACzB,oBAAoB,SACF,CAAC,GAAsB;CACzC,IAAI,QAAQ,kBAAmB,aAAc,IAAI,gBAAgB,KAAA;CACjE,MAAM,oBAAoB,cAAe,UAAU,iBAAkB;CAErE,eAAe,MAAM;EACpB,IAAK,OACJ,OAAO;EAGR,MAAM,OAAO,MAAM,SAEd,EACJ,MAAM,+BACP,CAAE;EAEF,QACC,cACC,MAAM,MAAM,uBACZ,sBACD,KAAK,CAAC;EAEP,OAAO;CACR;CAEA,SAAS,IAAK,SAA2B;EACxC,MAAM,oBAAoB;GACzB,GAAG;GACH,4BAAW,IAAI,KAAK,EAAA,CAAE,YAAY;EACnC;EACA,QAAQ;EAKR,gBAAiB,wBAAwB,iBAAkB;EAO3D,kBAAmB;GAClB,MAAM;GACN,QAAQ;GAMR,WAAW;GACX,MAAM,EACL,MAAM,EACL,uBAAuB,kBACxB,EACD;EACD,CAAE,CAAC,CAAC,YAAa,CAAC,CAAE;CACrB;CAEA,OAAO;EACN;EACA;CACD;AACD"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import isPreferencesData from "./is-preferences-data.mjs";
|
|
2
|
+
import { readStoredJSON } from "./local-storage.mjs";
|
|
3
|
+
import convertPreferencesPackageData from "./migrations/preferences-package-data/index.mjs";
|
|
4
|
+
// packages/preferences-persistence/src/get-newest-data.ts
|
|
5
|
+
/**
|
|
6
|
+
* Picks the most recently modified preferences from the server data and the
|
|
7
|
+
* local storage backup, ignoring either when it is not a preferences object.
|
|
8
|
+
*
|
|
9
|
+
* @param serverData Preferences data from the server.
|
|
10
|
+
* @param localStorageRestoreKey The key of the local storage backup.
|
|
11
|
+
*
|
|
12
|
+
* @return The newest preferences data, or `null` when neither is valid.
|
|
13
|
+
*/
|
|
14
|
+
function pickNewestData(serverData, localStorageRestoreKey) {
|
|
15
|
+
const storedData = readStoredJSON(localStorageRestoreKey);
|
|
16
|
+
const localData = isPreferencesData(storedData) ? storedData : null;
|
|
17
|
+
if (!isPreferencesData(serverData)) return localData;
|
|
18
|
+
const serverModified = Date.parse(serverData._modified ?? "") || 0;
|
|
19
|
+
const localModified = Date.parse(localData?._modified ?? "") || 0;
|
|
20
|
+
return localData && localModified > serverModified ? localData : serverData;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Gets the newest persisted preferences, migrated to the current format.
|
|
24
|
+
*
|
|
25
|
+
* @param serverData Preferences data from the server.
|
|
26
|
+
* @param localStorageRestoreKey The key of the local storage backup.
|
|
27
|
+
*
|
|
28
|
+
* @return The migrated preferences, or `undefined` when there are none.
|
|
29
|
+
*/
|
|
30
|
+
function getNewestData(serverData, localStorageRestoreKey) {
|
|
31
|
+
const newestData = pickNewestData(serverData, localStorageRestoreKey);
|
|
32
|
+
return newestData ? convertPreferencesPackageData(newestData) : void 0;
|
|
33
|
+
}
|
|
34
|
+
export { getNewestData as default };
|
|
35
|
+
|
|
36
|
+
//# sourceMappingURL=get-newest-data.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-newest-data.mjs","names":[],"sources":["../src/get-newest-data.ts"],"sourcesContent":["import isPreferencesData from './is-preferences-data';\nimport { readStoredJSON } from './local-storage';\nimport convertPreferencesPackageData from './migrations/preferences-package-data';\nimport type { PreferencesData, ScopedPreferences } from './types';\n\n/**\n * Picks the most recently modified preferences from the server data and the\n * local storage backup, ignoring either when it is not a preferences object.\n *\n * @param serverData Preferences data from the server.\n * @param localStorageRestoreKey The key of the local storage backup.\n *\n * @return The newest preferences data, or `null` when neither is valid.\n */\nfunction pickNewestData(\n\tserverData: unknown,\n\tlocalStorageRestoreKey: string\n): PreferencesData | null {\n\tconst storedData = readStoredJSON( localStorageRestoreKey );\n\tconst localData = isPreferencesData( storedData ) ? storedData : null;\n\tif ( ! isPreferencesData( serverData ) ) {\n\t\treturn localData;\n\t}\n\n\t// Date parse returns NaN for invalid input. Coerce anything invalid\n\t// into a conveniently comparable zero.\n\tconst serverModified = Date.parse( serverData._modified ?? '' ) || 0;\n\tconst localModified = Date.parse( localData?._modified ?? '' ) || 0;\n\n\t// Prefer server data when it is at least as recent.\n\treturn localData && localModified > serverModified ? localData : serverData;\n}\n\n/**\n * Gets the newest persisted preferences, migrated to the current format.\n *\n * @param serverData Preferences data from the server.\n * @param localStorageRestoreKey The key of the local storage backup.\n *\n * @return The migrated preferences, or `undefined` when there are none.\n */\nexport default function getNewestData(\n\tserverData: unknown,\n\tlocalStorageRestoreKey: string\n): ScopedPreferences | undefined {\n\tconst newestData = pickNewestData( serverData, localStorageRestoreKey );\n\treturn newestData\n\t\t? convertPreferencesPackageData( newestData as ScopedPreferences )\n\t\t: undefined;\n}\n"],"mappings":";;;;;;;;;;;;;AAcA,SAAS,eACR,YACA,wBACyB;CACzB,MAAM,aAAa,eAAgB,sBAAuB;CAC1D,MAAM,YAAY,kBAAmB,UAAW,IAAI,aAAa;CACjE,IAAK,CAAE,kBAAmB,UAAW,GACpC,OAAO;CAKR,MAAM,iBAAiB,KAAK,MAAO,WAAW,aAAa,EAAG,KAAK;CACnE,MAAM,gBAAgB,KAAK,MAAO,WAAW,aAAa,EAAG,KAAK;CAGlE,OAAO,aAAa,gBAAgB,iBAAiB,YAAY;AAClE;;;;;;;;;AAUA,SAAwB,cACvB,YACA,wBACgC;CAChC,MAAM,aAAa,eAAgB,YAAY,sBAAuB;CACtE,OAAO,aACJ,8BAA+B,UAAgC,IAC/D,KAAA;AACJ"}
|
package/build-module/index.mjs
CHANGED
|
@@ -1,29 +1,28 @@
|
|
|
1
|
-
// packages/preferences-persistence/src/index.js
|
|
2
1
|
import create from "./create/index.mjs";
|
|
3
2
|
import convertLegacyLocalStorageData from "./migrations/legacy-local-storage-data/index.mjs";
|
|
4
|
-
import
|
|
3
|
+
import getNewestData from "./get-newest-data.mjs";
|
|
4
|
+
// packages/preferences-persistence/src/index.ts
|
|
5
|
+
/**
|
|
6
|
+
* Creates the persistence layer with preloaded data.
|
|
7
|
+
*
|
|
8
|
+
* It prioritizes any data from the server, but falls back first to localStorage
|
|
9
|
+
* restore data, and then to any legacy data.
|
|
10
|
+
*
|
|
11
|
+
* This function is used internally by WordPress in an inline script, so
|
|
12
|
+
* prefixed with `__unstable`.
|
|
13
|
+
*
|
|
14
|
+
* @param serverData Preferences data preloaded from the server.
|
|
15
|
+
* @param userId The user id.
|
|
16
|
+
*
|
|
17
|
+
* @return The persistence layer initialized with the preloaded data.
|
|
18
|
+
*/
|
|
5
19
|
function __unstableCreatePersistenceLayer(serverData, userId) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const localModified = Date.parse(localData && localData._modified) || 0;
|
|
12
|
-
let preloadedData;
|
|
13
|
-
if (serverData && serverModified >= localModified) {
|
|
14
|
-
preloadedData = convertPreferencesPackageData(serverData);
|
|
15
|
-
} else if (localData) {
|
|
16
|
-
preloadedData = convertPreferencesPackageData(localData);
|
|
17
|
-
} else {
|
|
18
|
-
preloadedData = convertLegacyLocalStorageData(userId);
|
|
19
|
-
}
|
|
20
|
-
return create({
|
|
21
|
-
preloadedData,
|
|
22
|
-
localStorageRestoreKey
|
|
23
|
-
});
|
|
20
|
+
const localStorageRestoreKey = `WP_PREFERENCES_USER_${userId}`;
|
|
21
|
+
return create({
|
|
22
|
+
preloadedData: getNewestData(serverData, localStorageRestoreKey) ?? convertLegacyLocalStorageData(userId) ?? {},
|
|
23
|
+
localStorageRestoreKey
|
|
24
|
+
});
|
|
24
25
|
}
|
|
25
|
-
export {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
};
|
|
29
|
-
//# sourceMappingURL=index.mjs.map
|
|
26
|
+
export { __unstableCreatePersistenceLayer, create };
|
|
27
|
+
|
|
28
|
+
//# sourceMappingURL=index.mjs.map
|