@wordpress/preferences-persistence 2.56.0 → 3.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.
- package/README.md +7 -7
- package/build/create/debounce-async.cjs +2 -1
- package/build/create/debounce-async.cjs.map +3 -3
- package/build/create/index.cjs +11 -21
- package/build/create/index.cjs.map +4 -4
- package/build/get-newest-data.cjs +53 -0
- package/build/get-newest-data.cjs.map +7 -0
- package/build/index.cjs +8 -16
- package/build/index.cjs.map +4 -4
- package/build/is-preferences-data.cjs +29 -0
- package/build/is-preferences-data.cjs.map +7 -0
- package/build/local-storage.cjs +46 -0
- package/build/local-storage.cjs.map +7 -0
- package/build/migrations/legacy-local-storage-data/convert-edit-post-panels.cjs +2 -1
- package/build/migrations/legacy-local-storage-data/convert-edit-post-panels.cjs.map +3 -3
- package/build/migrations/legacy-local-storage-data/index.cjs +7 -5
- package/build/migrations/legacy-local-storage-data/index.cjs.map +4 -4
- package/build/migrations/legacy-local-storage-data/move-feature-preferences.cjs +2 -1
- package/build/migrations/legacy-local-storage-data/move-feature-preferences.cjs.map +3 -3
- package/build/migrations/legacy-local-storage-data/move-individual-preference.cjs +2 -1
- package/build/migrations/legacy-local-storage-data/move-individual-preference.cjs.map +3 -3
- package/build/migrations/legacy-local-storage-data/move-interface-enable-items.cjs +2 -1
- package/build/migrations/legacy-local-storage-data/move-interface-enable-items.cjs.map +3 -3
- package/build/migrations/legacy-local-storage-data/move-third-party-feature-preferences.cjs +2 -1
- package/build/migrations/legacy-local-storage-data/move-third-party-feature-preferences.cjs.map +3 -3
- package/build/migrations/legacy-local-storage-data/types.cjs +19 -0
- package/build/migrations/legacy-local-storage-data/types.cjs.map +7 -0
- package/build/migrations/preferences-package-data/convert-complementary-areas.cjs +15 -11
- package/build/migrations/preferences-package-data/convert-complementary-areas.cjs.map +3 -3
- package/build/migrations/preferences-package-data/convert-editor-settings.cjs +30 -14
- package/build/migrations/preferences-package-data/convert-editor-settings.cjs.map +4 -4
- package/build/migrations/preferences-package-data/index.cjs +2 -1
- package/build/migrations/preferences-package-data/index.cjs.map +3 -3
- package/build/types.cjs +19 -0
- package/build/types.cjs.map +7 -0
- package/build-module/create/debounce-async.mjs +1 -1
- package/build-module/create/debounce-async.mjs.map +3 -3
- package/build-module/create/index.mjs +10 -21
- package/build-module/create/index.mjs.map +3 -3
- package/build-module/get-newest-data.mjs +22 -0
- package/build-module/get-newest-data.mjs.map +7 -0
- package/build-module/index.mjs +7 -16
- package/build-module/index.mjs.map +3 -3
- package/build-module/is-preferences-data.mjs +8 -0
- package/build-module/is-preferences-data.mjs.map +7 -0
- package/build-module/local-storage.mjs +20 -0
- package/build-module/local-storage.mjs.map +7 -0
- package/build-module/migrations/legacy-local-storage-data/convert-edit-post-panels.mjs +1 -1
- package/build-module/migrations/legacy-local-storage-data/convert-edit-post-panels.mjs.map +3 -3
- package/build-module/migrations/legacy-local-storage-data/index.mjs +6 -5
- package/build-module/migrations/legacy-local-storage-data/index.mjs.map +3 -3
- package/build-module/migrations/legacy-local-storage-data/move-feature-preferences.mjs +1 -1
- package/build-module/migrations/legacy-local-storage-data/move-feature-preferences.mjs.map +3 -3
- package/build-module/migrations/legacy-local-storage-data/move-individual-preference.mjs +1 -1
- package/build-module/migrations/legacy-local-storage-data/move-individual-preference.mjs.map +3 -3
- package/build-module/migrations/legacy-local-storage-data/move-interface-enable-items.mjs +1 -1
- package/build-module/migrations/legacy-local-storage-data/move-interface-enable-items.mjs.map +3 -3
- package/build-module/migrations/legacy-local-storage-data/move-third-party-feature-preferences.mjs +1 -1
- package/build-module/migrations/legacy-local-storage-data/move-third-party-feature-preferences.mjs.map +3 -3
- package/build-module/migrations/legacy-local-storage-data/types.mjs +1 -0
- package/build-module/migrations/legacy-local-storage-data/types.mjs.map +7 -0
- package/build-module/migrations/preferences-package-data/convert-complementary-areas.mjs +14 -11
- package/build-module/migrations/preferences-package-data/convert-complementary-areas.mjs.map +3 -3
- package/build-module/migrations/preferences-package-data/convert-editor-settings.mjs +19 -14
- package/build-module/migrations/preferences-package-data/convert-editor-settings.mjs.map +3 -3
- package/build-module/migrations/preferences-package-data/index.mjs +1 -1
- package/build-module/migrations/preferences-package-data/index.mjs.map +3 -3
- package/build-module/types.mjs +1 -0
- package/build-module/types.mjs.map +7 -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 +7 -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 +2 -3
- package/src/create/test/index.jsdom.test.js +45 -0
- 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 +6 -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 +10 -0
- package/src/migrations/preferences-package-data/test/convert-editor-settings.js +35 -0
- package/src/test/index.jsdom.test.js +95 -0
- package/src/test/local-storage.jsdom.test.js +50 -0
- package/src/types.ts +43 -0
- package/CHANGELOG.md +0 -226
- 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
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
var __defProp = Object.defineProperty;
|
|
2
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
@@ -16,7 +17,7 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
17
|
};
|
|
17
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
19
|
|
|
19
|
-
// packages/preferences-persistence/src/migrations/legacy-local-storage-data/move-interface-enable-items.
|
|
20
|
+
// packages/preferences-persistence/src/migrations/legacy-local-storage-data/move-interface-enable-items.ts
|
|
20
21
|
var move_interface_enable_items_exports = {};
|
|
21
22
|
__export(move_interface_enable_items_exports, {
|
|
22
23
|
default: () => moveInterfaceEnableItems
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../../src/migrations/legacy-local-storage-data/move-interface-enable-items.
|
|
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
|
|
5
|
-
"mappings": "
|
|
3
|
+
"sources": ["../../../src/migrations/legacy-local-storage-data/move-interface-enable-items.ts"],
|
|
4
|
+
"sourcesContent": ["import type { LegacyData } from './types';\n\n/**\n * Migrates interface 'enableItems' data to the preferences store.\n *\n * The interface package stores this data in this format:\n * ```js\n * {\n * enableItems: {\n * singleEnableItems: {\n * \t complementaryArea: {\n * 'core/edit-post': 'edit-post/document',\n * 'core/edit-site': 'edit-site/global-styles',\n * }\n * },\n * multipleEnableItems: {\n * pinnedItems: {\n * 'core/edit-post': {\n * 'plugin-1': true,\n * },\n * 'core/edit-site': {\n * 'plugin-2': true,\n * },\n * },\n * }\n * }\n * }\n * ```\n *\n * and it should be converted it to:\n * ```js\n * {\n * 'core/edit-post': {\n * complementaryArea: 'edit-post/document',\n * pinnedItems: {\n * 'plugin-1': true,\n * },\n * },\n * 'core/edit-site': {\n * complementaryArea: 'edit-site/global-styles',\n * pinnedItems: {\n * 'plugin-2': true,\n * },\n * },\n * }\n * ```\n *\n * @param state The local storage state.\n */\nexport default function moveInterfaceEnableItems(\n\tstate: LegacyData\n): LegacyData {\n\tconst interfaceStoreName = 'core/interface';\n\tconst preferencesStoreName = 'core/preferences';\n\tconst sourceEnableItems = state?.[ interfaceStoreName ]?.enableItems;\n\n\t// There's nothing to migrate, exit early.\n\tif ( ! sourceEnableItems ) {\n\t\treturn state;\n\t}\n\n\tconst allPreferences = state?.[ preferencesStoreName ]?.preferences ?? {};\n\n\t// First convert complementaryAreas into the right format.\n\t// Use the existing preferences as the accumulator so that the data is\n\t// merged.\n\tconst sourceComplementaryAreas =\n\t\tsourceEnableItems?.singleEnableItems?.complementaryArea ?? {};\n\n\tconst preferencesWithConvertedComplementaryAreas = Object.keys(\n\t\tsourceComplementaryAreas\n\t).reduce( ( accumulator, scope ) => {\n\t\tconst data = sourceComplementaryAreas[ scope ];\n\n\t\t// Don't overwrite any existing data in the preferences store.\n\t\tif ( accumulator?.[ scope ]?.complementaryArea ) {\n\t\t\treturn accumulator;\n\t\t}\n\n\t\treturn {\n\t\t\t...accumulator,\n\t\t\t[ scope ]: {\n\t\t\t\t...accumulator[ scope ],\n\t\t\t\tcomplementaryArea: data,\n\t\t\t},\n\t\t};\n\t}, allPreferences );\n\n\t// Next feed the converted complementary areas back into a reducer that\n\t// converts the pinned items, resulting in the fully migrated data.\n\tconst sourcePinnedItems =\n\t\tsourceEnableItems?.multipleEnableItems?.pinnedItems ?? {};\n\tconst allConvertedData = Object.keys( sourcePinnedItems ).reduce(\n\t\t( accumulator, scope ) => {\n\t\t\tconst data = sourcePinnedItems[ scope ];\n\t\t\t// Don't overwrite any existing data in the preferences store.\n\t\t\tif ( accumulator?.[ scope ]?.pinnedItems ) {\n\t\t\t\treturn accumulator;\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\t...accumulator,\n\t\t\t\t[ scope ]: {\n\t\t\t\t\t...accumulator[ scope ],\n\t\t\t\t\tpinnedItems: data,\n\t\t\t\t},\n\t\t\t};\n\t\t},\n\t\tpreferencesWithConvertedComplementaryAreas\n\t);\n\n\tconst otherInterfaceItems = state[ interfaceStoreName ];\n\n\treturn {\n\t\t...state,\n\t\t[ preferencesStoreName ]: {\n\t\t\tpreferences: allConvertedData,\n\t\t},\n\t\t[ interfaceStoreName ]: {\n\t\t\t...otherInterfaceItems,\n\t\t\tenableItems: undefined,\n\t\t},\n\t};\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAiDe,SAAR,yBACN,OACa;AACb,QAAM,qBAAqB;AAC3B,QAAM,uBAAuB;AAC7B,QAAM,oBAAoB,QAAS,kBAAmB,GAAG;AAGzD,MAAK,CAAE,mBAAoB;AAC1B,WAAO;AAAA,EACR;AAEA,QAAM,iBAAiB,QAAS,oBAAqB,GAAG,eAAe,CAAC;AAKxE,QAAM,2BACL,mBAAmB,mBAAmB,qBAAqB,CAAC;AAE7D,QAAM,6CAA6C,OAAO;AAAA,IACzD;AAAA,EACD,EAAE,OAAQ,CAAE,aAAa,UAAW;AACnC,UAAM,OAAO,yBAA0B,KAAM;AAG7C,QAAK,cAAe,KAAM,GAAG,mBAAoB;AAChD,aAAO;AAAA,IACR;AAEA,WAAO;AAAA,MACN,GAAG;AAAA,MACH,CAAE,KAAM,GAAG;AAAA,QACV,GAAG,YAAa,KAAM;AAAA,QACtB,mBAAmB;AAAA,MACpB;AAAA,IACD;AAAA,EACD,GAAG,cAAe;AAIlB,QAAM,oBACL,mBAAmB,qBAAqB,eAAe,CAAC;AACzD,QAAM,mBAAmB,OAAO,KAAM,iBAAkB,EAAE;AAAA,IACzD,CAAE,aAAa,UAAW;AACzB,YAAM,OAAO,kBAAmB,KAAM;AAEtC,UAAK,cAAe,KAAM,GAAG,aAAc;AAC1C,eAAO;AAAA,MACR;AAEA,aAAO;AAAA,QACN,GAAG;AAAA,QACH,CAAE,KAAM,GAAG;AAAA,UACV,GAAG,YAAa,KAAM;AAAA,UACtB,aAAa;AAAA,QACd;AAAA,MACD;AAAA,IACD;AAAA,IACA;AAAA,EACD;AAEA,QAAM,sBAAsB,MAAO,kBAAmB;AAEtD,SAAO;AAAA,IACN,GAAG;AAAA,IACH,CAAE,oBAAqB,GAAG;AAAA,MACzB,aAAa;AAAA,IACd;AAAA,IACA,CAAE,kBAAmB,GAAG;AAAA,MACvB,GAAG;AAAA,MACH,aAAa;AAAA,IACd;AAAA,EACD;AACD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
var __defProp = Object.defineProperty;
|
|
2
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
@@ -16,7 +17,7 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
17
|
};
|
|
17
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
19
|
|
|
19
|
-
// packages/preferences-persistence/src/migrations/legacy-local-storage-data/move-third-party-feature-preferences.
|
|
20
|
+
// packages/preferences-persistence/src/migrations/legacy-local-storage-data/move-third-party-feature-preferences.ts
|
|
20
21
|
var move_third_party_feature_preferences_exports = {};
|
|
21
22
|
__export(move_third_party_feature_preferences_exports, {
|
|
22
23
|
default: () => moveThirdPartyFeaturePreferencesToPreferences
|
package/build/migrations/legacy-local-storage-data/move-third-party-feature-preferences.cjs.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../../src/migrations/legacy-local-storage-data/move-third-party-feature-preferences.
|
|
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
|
|
5
|
-
"mappings": "
|
|
3
|
+
"sources": ["../../../src/migrations/legacy-local-storage-data/move-third-party-feature-preferences.ts"],
|
|
4
|
+
"sourcesContent": ["import type { LegacyData } from './types';\n\n/**\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 state The local storage state\n *\n * @return The state with third party preferences moved to the\n * preferences data structure.\n */\nexport default function moveThirdPartyFeaturePreferencesToPreferences(\n\tstate: LegacyData\n): LegacyData {\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;AA2Ce,SAAR,8CACN,OACa;AACb,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
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
|
|
16
|
+
// packages/preferences-persistence/src/migrations/legacy-local-storage-data/types.ts
|
|
17
|
+
var types_exports = {};
|
|
18
|
+
module.exports = __toCommonJS(types_exports);
|
|
19
|
+
//# sourceMappingURL=types.cjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/migrations/legacy-local-storage-data/types.ts"],
|
|
4
|
+
"sourcesContent": ["import type { ScopedPreferences } from '../../types';\n\n/**\n * Boolean 'feature' preferences, keyed by feature name.\n */\nexport type FeaturePreferences = Record< string, boolean | undefined >;\n\n/**\n * Persisted state of a package's store, such as `core/edit-post`.\n */\nexport interface LegacyStoreState {\n\tpreferences?: Record< string, unknown >;\n\t[ key: string ]: unknown;\n}\n\n/**\n * Persisted state of the `core/interface` store.\n */\nexport interface LegacyInterfaceStoreState {\n\tpreferences?: {\n\t\tfeatures?: Record< string, FeaturePreferences | undefined >;\n\t\t[ key: string ]: unknown;\n\t};\n\tenableItems?: {\n\t\tsingleEnableItems?: {\n\t\t\tcomplementaryArea?: Record< string, string >;\n\t\t};\n\t\tmultipleEnableItems?: {\n\t\t\tpinnedItems?: Record< string, Record< string, boolean > >;\n\t\t};\n\t};\n\t[ key: string ]: unknown;\n}\n\n/**\n * Persisted state of the `core/preferences` store.\n */\nexport interface LegacyPreferencesStoreState {\n\tpreferences?: ScopedPreferences;\n\t[ key: string ]: unknown;\n}\n\n/**\n * Local storage data in the legacy `@wordpress/data` format, keyed by store name.\n */\nexport interface LegacyData {\n\t'core/interface'?: LegacyInterfaceStoreState;\n\t'core/preferences'?: LegacyPreferencesStoreState;\n\t[ storeName: string ]: LegacyStoreState | undefined;\n}\n\n/**\n * The post editor's panels state in the legacy format.\n */\nexport interface LegacyEditPostPanel {\n\tenabled?: boolean;\n\topened?: boolean;\n}\n\n/**\n * The post editor's panels state in the preferences format.\n */\nexport interface EditPostPanels {\n\tinactivePanels: string[];\n\topenPanels: string[];\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;AAAA;AAAA;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
var __defProp = Object.defineProperty;
|
|
2
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
@@ -16,23 +17,26 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
17
|
};
|
|
17
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
19
|
|
|
19
|
-
// packages/preferences-persistence/src/migrations/preferences-package-data/convert-complementary-areas.
|
|
20
|
+
// packages/preferences-persistence/src/migrations/preferences-package-data/convert-complementary-areas.ts
|
|
20
21
|
var convert_complementary_areas_exports = {};
|
|
21
22
|
__export(convert_complementary_areas_exports, {
|
|
22
23
|
default: () => convertComplementaryAreas
|
|
23
24
|
});
|
|
24
25
|
module.exports = __toCommonJS(convert_complementary_areas_exports);
|
|
25
26
|
function convertComplementaryAreas(state) {
|
|
26
|
-
return Object.keys(state).reduce(
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
27
|
+
return Object.keys(state).reduce(
|
|
28
|
+
(stateAccumulator, scope) => {
|
|
29
|
+
const scopeData = state[scope];
|
|
30
|
+
if (scopeData?.complementaryArea) {
|
|
31
|
+
const updatedScopeData = { ...scopeData };
|
|
32
|
+
delete updatedScopeData.complementaryArea;
|
|
33
|
+
updatedScopeData.isComplementaryAreaVisible = true;
|
|
34
|
+
stateAccumulator[scope] = updatedScopeData;
|
|
35
|
+
return stateAccumulator;
|
|
36
|
+
}
|
|
33
37
|
return stateAccumulator;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
|
|
38
|
+
},
|
|
39
|
+
{ ...state }
|
|
40
|
+
);
|
|
37
41
|
}
|
|
38
42
|
//# sourceMappingURL=convert-complementary-areas.cjs.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../../src/migrations/preferences-package-data/convert-complementary-areas.
|
|
4
|
-
"sourcesContent": ["
|
|
5
|
-
"mappings": "
|
|
3
|
+
"sources": ["../../../src/migrations/preferences-package-data/convert-complementary-areas.ts"],
|
|
4
|
+
"sourcesContent": ["import type { ScopedPreferences } from '../../types';\n\nexport default function convertComplementaryAreas( state: ScopedPreferences ) {\n\treturn Object.keys( state ).reduce(\n\t\t( stateAccumulator, scope ) => {\n\t\t\tconst scopeData = state[ scope ];\n\n\t\t\t// If a complementary area is truthy, convert it to the `isComplementaryAreaVisible` boolean.\n\t\t\tif ( scopeData?.complementaryArea ) {\n\t\t\t\tconst updatedScopeData = { ...scopeData };\n\t\t\t\tdelete updatedScopeData.complementaryArea;\n\t\t\t\tupdatedScopeData.isComplementaryAreaVisible = true;\n\t\t\t\tstateAccumulator[ scope ] = updatedScopeData;\n\t\t\t\treturn stateAccumulator;\n\t\t\t}\n\n\t\t\treturn stateAccumulator;\n\t\t},\n\t\t{ ...state }\n\t);\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEe,SAAR,0BAA4C,OAA2B;AAC7E,SAAO,OAAO,KAAM,KAAM,EAAE;AAAA,IAC3B,CAAE,kBAAkB,UAAW;AAC9B,YAAM,YAAY,MAAO,KAAM;AAG/B,UAAK,WAAW,mBAAoB;AACnC,cAAM,mBAAmB,EAAE,GAAG,UAAU;AACxC,eAAO,iBAAiB;AACxB,yBAAiB,6BAA6B;AAC9C,yBAAkB,KAAM,IAAI;AAC5B,eAAO;AAAA,MACR;AAEA,aAAO;AAAA,IACR;AAAA,IACA,EAAE,GAAG,MAAM;AAAA,EACZ;AACD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
1
3
|
var __defProp = Object.defineProperty;
|
|
2
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
4
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
8
|
var __export = (target, all) => {
|
|
6
9
|
for (var name in all)
|
|
@@ -14,16 +17,28 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
14
17
|
}
|
|
15
18
|
return to;
|
|
16
19
|
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
17
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
29
|
|
|
19
|
-
// packages/preferences-persistence/src/migrations/preferences-package-data/convert-editor-settings.
|
|
30
|
+
// packages/preferences-persistence/src/migrations/preferences-package-data/convert-editor-settings.ts
|
|
20
31
|
var convert_editor_settings_exports = {};
|
|
21
32
|
__export(convert_editor_settings_exports, {
|
|
22
33
|
default: () => convertEditorSettings
|
|
23
34
|
});
|
|
24
35
|
module.exports = __toCommonJS(convert_editor_settings_exports);
|
|
36
|
+
var import_is_preferences_data = __toESM(require("../../is-preferences-data.cjs"));
|
|
37
|
+
var copyScope = (scope) => (0, import_is_preferences_data.default)(scope) ? { ...scope } : void 0;
|
|
25
38
|
function convertEditorSettings(data) {
|
|
26
|
-
|
|
39
|
+
const newData = { ...data };
|
|
40
|
+
const editPost = copyScope(data["core/edit-post"]);
|
|
41
|
+
const editSite = copyScope(data["core/edit-site"]);
|
|
27
42
|
const settingsToMoveToCore = [
|
|
28
43
|
"allowRightClickOverrides",
|
|
29
44
|
"distractionFree",
|
|
@@ -43,24 +58,25 @@ function convertEditorSettings(data) {
|
|
|
43
58
|
"pinnedItems"
|
|
44
59
|
];
|
|
45
60
|
settingsToMoveToCore.forEach((setting) => {
|
|
46
|
-
if (
|
|
47
|
-
newData = {
|
|
48
|
-
...newData,
|
|
49
|
-
|
|
50
|
-
...newData?.core,
|
|
51
|
-
[setting]: data["core/edit-post"][setting]
|
|
52
|
-
}
|
|
61
|
+
if (editPost?.[setting] !== void 0) {
|
|
62
|
+
newData.core = {
|
|
63
|
+
...copyScope(newData.core),
|
|
64
|
+
[setting]: editPost[setting]
|
|
53
65
|
};
|
|
54
|
-
delete
|
|
66
|
+
delete editPost[setting];
|
|
55
67
|
}
|
|
56
|
-
if (
|
|
57
|
-
delete
|
|
68
|
+
if (editSite?.[setting] !== void 0) {
|
|
69
|
+
delete editSite[setting];
|
|
58
70
|
}
|
|
59
71
|
});
|
|
60
|
-
if (Object.keys(
|
|
72
|
+
if (editPost && Object.keys(editPost).length > 0) {
|
|
73
|
+
newData["core/edit-post"] = editPost;
|
|
74
|
+
} else {
|
|
61
75
|
delete newData["core/edit-post"];
|
|
62
76
|
}
|
|
63
|
-
if (Object.keys(
|
|
77
|
+
if (editSite && Object.keys(editSite).length > 0) {
|
|
78
|
+
newData["core/edit-site"] = editSite;
|
|
79
|
+
} else {
|
|
64
80
|
delete newData["core/edit-site"];
|
|
65
81
|
}
|
|
66
82
|
return newData;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../../src/migrations/preferences-package-data/convert-editor-settings.
|
|
4
|
-
"sourcesContent": ["
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": []
|
|
3
|
+
"sources": ["../../../src/migrations/preferences-package-data/convert-editor-settings.ts"],
|
|
4
|
+
"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"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,iCAA8B;AAG9B,IAAM,YAAY,CAAE,cACnB,2BAAAA,SAAmB,KAAM,IAAI,EAAE,GAAG,MAAM,IAAI;AAE9B,SAAR,sBAAwC,MAA0B;AACxE,QAAM,UAAU,EAAE,GAAG,KAAK;AAC1B,QAAM,WAAW,UAAW,KAAM,gBAAiB,CAAE;AACrD,QAAM,WAAW,UAAW,KAAM,gBAAiB,CAAE;AACrD,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,WAAY,OAAQ,MAAM,QAAY;AAC1C,cAAQ,OAAO;AAAA,QACd,GAAG,UAAW,QAAQ,IAAK;AAAA,QAC3B,CAAE,OAAQ,GAAG,SAAU,OAAQ;AAAA,MAChC;AACA,aAAO,SAAU,OAAQ;AAAA,IAC1B;AAEA,QAAK,WAAY,OAAQ,MAAM,QAAY;AAC1C,aAAO,SAAU,OAAQ;AAAA,IAC1B;AAAA,EACD,CAAE;AAGF,MAAK,YAAY,OAAO,KAAM,QAAS,EAAE,SAAS,GAAI;AACrD,YAAS,gBAAiB,IAAI;AAAA,EAC/B,OAAO;AACN,WAAO,QAAS,gBAAiB;AAAA,EAClC;AAEA,MAAK,YAAY,OAAO,KAAM,QAAS,EAAE,SAAS,GAAI;AACrD,YAAS,gBAAiB,IAAI;AAAA,EAC/B,OAAO;AACN,WAAO,QAAS,gBAAiB;AAAA,EAClC;AAEA,SAAO;AACR;",
|
|
6
|
+
"names": ["isPreferencesData"]
|
|
7
7
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -26,7 +27,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
26
27
|
));
|
|
27
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
29
|
|
|
29
|
-
// packages/preferences-persistence/src/migrations/preferences-package-data/index.
|
|
30
|
+
// packages/preferences-persistence/src/migrations/preferences-package-data/index.ts
|
|
30
31
|
var preferences_package_data_exports = {};
|
|
31
32
|
__export(preferences_package_data_exports, {
|
|
32
33
|
default: () => convertPreferencesPackageData
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../../src/migrations/preferences-package-data/index.
|
|
4
|
-
"sourcesContent": ["import convertComplementaryAreas from './convert-complementary-areas';\nimport convertEditorSettings from './convert-editor-settings';\n\nexport default function convertPreferencesPackageData(
|
|
5
|
-
"mappings": "
|
|
3
|
+
"sources": ["../../../src/migrations/preferences-package-data/index.ts"],
|
|
4
|
+
"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"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,yCAAsC;AACtC,qCAAkC;AAGnB,SAAR,8BACN,MACC;AACD,MAAI,cAAU,mCAAAA,SAA2B,IAAK;AAC9C,gBAAU,+BAAAC,SAAuB,OAAQ;AACzC,SAAO;AACR;",
|
|
6
6
|
"names": ["convertComplementaryAreas", "convertEditorSettings"]
|
|
7
7
|
}
|
package/build/types.cjs
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
|
|
16
|
+
// packages/preferences-persistence/src/types.ts
|
|
17
|
+
var types_exports = {};
|
|
18
|
+
module.exports = __toCommonJS(types_exports);
|
|
19
|
+
//# sourceMappingURL=types.cjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/types.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * Preferences of a single scope, such as `core/edit-post`.\n */\nexport type ScopePreferences = Record< string, unknown >;\n\n/**\n * Preferences store data, keyed by scope.\n */\nexport type ScopedPreferences = Record< string, ScopePreferences | undefined >;\n\n/**\n * Persisted preferences data, keyed by scope.\n */\nexport interface PreferencesData {\n\t/**\n\t * When the data was last modified, as an ISO 8601 date string.\n\t */\n\t_modified?: string;\n\t[ scope: string ]: unknown;\n}\n\nexport interface CreateOptions {\n\t/**\n\t * Any persisted preferences data that should be preloaded.\n\t * When set, the persistence layer will avoid fetching data from the REST API.\n\t */\n\tpreloadedData?: PreferencesData | null;\n\t/**\n\t * The key to use for restoring the localStorage backup, used when the\n\t * persistence layer calls `localStorage.getItem` or `localStorage.setItem`.\n\t */\n\tlocalStorageRestoreKey?: string;\n\t/**\n\t * Debounce requests to the API so that they only occur at minimum every\n\t * `requestDebounceMS` milliseconds, and don't swamp the server. Defaults to 2500ms.\n\t */\n\trequestDebounceMS?: number;\n}\n\nexport interface PersistenceLayer {\n\tget: () => Promise< PreferencesData >;\n\tset: ( newData: PreferencesData ) => void;\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;AAAA;AAAA;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../src/create/debounce-async.
|
|
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
|
|
5
|
-
"mappings": ";AAiBe,SAAR,
|
|
3
|
+
"sources": ["../../src/create/debounce-async.ts"],
|
|
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 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"],
|
|
5
|
+
"mappings": ";AAiBe,SAAR,cACN,MACA,SACyC;AACzC,MAAI;AACJ,MAAI;AAEJ,SAAO,eAAe,aAAc,MAAa;AAGhD,QAAK,CAAE,iBAAiB,CAAE,WAAY;AACrC,aAAO,IAAI,QAAmB,CAAE,SAAS,WAAY;AAEpD,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,QAAmB,CAAE,SAAS,WAAY;AAEpD,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
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
// packages/preferences-persistence/src/create/index.
|
|
1
|
+
// packages/preferences-persistence/src/create/index.ts
|
|
2
2
|
import apiFetch from "@wordpress/api-fetch";
|
|
3
3
|
import debounceAsync from "./debounce-async.mjs";
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
import getNewestData from "../get-newest-data.mjs";
|
|
5
|
+
import isPreferencesData from "../is-preferences-data.mjs";
|
|
6
|
+
import { writeStoredJSON } from "../local-storage.mjs";
|
|
6
7
|
function create({
|
|
7
8
|
preloadedData,
|
|
8
9
|
localStorageRestoreKey = "WP_PREFERENCES_RESTORE_DATA",
|
|
9
10
|
requestDebounceMS = 2500
|
|
10
11
|
} = {}) {
|
|
11
|
-
let cache = preloadedData;
|
|
12
|
+
let cache = isPreferencesData(preloadedData) ? preloadedData : void 0;
|
|
12
13
|
const debouncedApiFetch = debounceAsync(apiFetch, requestDebounceMS);
|
|
13
14
|
async function get() {
|
|
14
15
|
if (cache) {
|
|
@@ -17,19 +18,10 @@ function create({
|
|
|
17
18
|
const user = await apiFetch({
|
|
18
19
|
path: "/wp/v2/users/me?context=edit"
|
|
19
20
|
});
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
);
|
|
24
|
-
const serverTimestamp = Date.parse(serverData?._modified) || 0;
|
|
25
|
-
const localTimestamp = Date.parse(localData?._modified) || 0;
|
|
26
|
-
if (serverData && serverTimestamp >= localTimestamp) {
|
|
27
|
-
cache = serverData;
|
|
28
|
-
} else if (localData) {
|
|
29
|
-
cache = localData;
|
|
30
|
-
} else {
|
|
31
|
-
cache = EMPTY_OBJECT;
|
|
32
|
-
}
|
|
21
|
+
cache = getNewestData(
|
|
22
|
+
user?.meta?.persisted_preferences,
|
|
23
|
+
localStorageRestoreKey
|
|
24
|
+
) ?? {};
|
|
33
25
|
return cache;
|
|
34
26
|
}
|
|
35
27
|
function set(newData) {
|
|
@@ -38,10 +30,7 @@ function create({
|
|
|
38
30
|
_modified: (/* @__PURE__ */ new Date()).toISOString()
|
|
39
31
|
};
|
|
40
32
|
cache = dataWithTimestamp;
|
|
41
|
-
|
|
42
|
-
localStorageRestoreKey,
|
|
43
|
-
JSON.stringify(dataWithTimestamp)
|
|
44
|
-
);
|
|
33
|
+
writeStoredJSON(localStorageRestoreKey, dataWithTimestamp);
|
|
45
34
|
debouncedApiFetch({
|
|
46
35
|
path: "/wp/v2/users/me",
|
|
47
36
|
method: "PUT",
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../src/create/index.
|
|
4
|
-
"sourcesContent": ["import apiFetch from '@wordpress/api-fetch';\nimport debounceAsync from './debounce-async';\
|
|
5
|
-
"mappings": ";AAAA,OAAO,cAAc;AACrB,OAAO,mBAAmB;
|
|
3
|
+
"sources": ["../../src/create/index.ts"],
|
|
4
|
+
"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"],
|
|
5
|
+
"mappings": ";AAAA,OAAO,cAAc;AACrB,OAAO,mBAAmB;AAC1B,OAAO,mBAAmB;AAC1B,OAAO,uBAAuB;AAC9B,SAAS,uBAAuB;AAwBjB,SAAR,OAAyB;AAAA,EAC/B;AAAA,EACA,yBAAyB;AAAA,EACzB,oBAAoB;AACrB,IAAmB,CAAC,GAAsB;AACzC,MAAI,QAAQ,kBAAmB,aAAc,IAAI,gBAAgB;AACjE,QAAM,oBAAoB,cAAe,UAAU,iBAAkB;AAErE,iBAAe,MAAM;AACpB,QAAK,OAAQ;AACZ,aAAO;AAAA,IACR;AAEA,UAAM,OAAO,MAAM,SAEd;AAAA,MACJ,MAAM;AAAA,IACP,CAAE;AAEF,YACC;AAAA,MACC,MAAM,MAAM;AAAA,MACZ;AAAA,IACD,KAAK,CAAC;AAEP,WAAO;AAAA,EACR;AAEA,WAAS,IAAK,SAA2B;AACxC,UAAM,oBAAoB;AAAA,MACzB,GAAG;AAAA,MACH,YAAW,oBAAI,KAAK,GAAE,YAAY;AAAA,IACnC;AACA,YAAQ;AAKR,oBAAiB,wBAAwB,iBAAkB;AAO3D,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
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// packages/preferences-persistence/src/get-newest-data.ts
|
|
2
|
+
import isPreferencesData from "./is-preferences-data.mjs";
|
|
3
|
+
import { readStoredJSON } from "./local-storage.mjs";
|
|
4
|
+
import convertPreferencesPackageData from "./migrations/preferences-package-data/index.mjs";
|
|
5
|
+
function pickNewestData(serverData, localStorageRestoreKey) {
|
|
6
|
+
const storedData = readStoredJSON(localStorageRestoreKey);
|
|
7
|
+
const localData = isPreferencesData(storedData) ? storedData : null;
|
|
8
|
+
if (!isPreferencesData(serverData)) {
|
|
9
|
+
return localData;
|
|
10
|
+
}
|
|
11
|
+
const serverModified = Date.parse(serverData._modified ?? "") || 0;
|
|
12
|
+
const localModified = Date.parse(localData?._modified ?? "") || 0;
|
|
13
|
+
return localData && localModified > serverModified ? localData : serverData;
|
|
14
|
+
}
|
|
15
|
+
function getNewestData(serverData, localStorageRestoreKey) {
|
|
16
|
+
const newestData = pickNewestData(serverData, localStorageRestoreKey);
|
|
17
|
+
return newestData ? convertPreferencesPackageData(newestData) : void 0;
|
|
18
|
+
}
|
|
19
|
+
export {
|
|
20
|
+
getNewestData as default
|
|
21
|
+
};
|
|
22
|
+
//# sourceMappingURL=get-newest-data.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/get-newest-data.ts"],
|
|
4
|
+
"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"],
|
|
5
|
+
"mappings": ";AAAA,OAAO,uBAAuB;AAC9B,SAAS,sBAAsB;AAC/B,OAAO,mCAAmC;AAY1C,SAAS,eACR,YACA,wBACyB;AACzB,QAAM,aAAa,eAAgB,sBAAuB;AAC1D,QAAM,YAAY,kBAAmB,UAAW,IAAI,aAAa;AACjE,MAAK,CAAE,kBAAmB,UAAW,GAAI;AACxC,WAAO;AAAA,EACR;AAIA,QAAM,iBAAiB,KAAK,MAAO,WAAW,aAAa,EAAG,KAAK;AACnE,QAAM,gBAAgB,KAAK,MAAO,WAAW,aAAa,EAAG,KAAK;AAGlE,SAAO,aAAa,gBAAgB,iBAAiB,YAAY;AAClE;AAUe,SAAR,cACN,YACA,wBACgC;AAChC,QAAM,aAAa,eAAgB,YAAY,sBAAuB;AACtE,SAAO,aACJ,8BAA+B,UAAgC,IAC/D;AACJ;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/build-module/index.mjs
CHANGED
|
@@ -1,24 +1,15 @@
|
|
|
1
|
-
// packages/preferences-persistence/src/index.
|
|
1
|
+
// packages/preferences-persistence/src/index.ts
|
|
2
2
|
import create from "./create/index.mjs";
|
|
3
3
|
import convertLegacyLocalStorageData from "./migrations/legacy-local-storage-data/index.mjs";
|
|
4
|
-
import
|
|
4
|
+
import getNewestData from "./get-newest-data.mjs";
|
|
5
5
|
function __unstableCreatePersistenceLayer(serverData, userId) {
|
|
6
6
|
const localStorageRestoreKey = `WP_PREFERENCES_USER_${userId}`;
|
|
7
|
-
const localData = JSON.parse(
|
|
8
|
-
window.localStorage.getItem(localStorageRestoreKey)
|
|
9
|
-
);
|
|
10
|
-
const serverModified = Date.parse(serverData && serverData._modified) || 0;
|
|
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
7
|
return create({
|
|
21
|
-
|
|
8
|
+
/*
|
|
9
|
+
* Fall back to data in the legacy format from the old persistence system.
|
|
10
|
+
* The server data is already preloaded, so fetching it again is redundant.
|
|
11
|
+
*/
|
|
12
|
+
preloadedData: getNewestData(serverData, localStorageRestoreKey) ?? convertLegacyLocalStorageData(userId) ?? {},
|
|
22
13
|
localStorageRestoreKey
|
|
23
14
|
});
|
|
24
15
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../src/index.
|
|
4
|
-
"sourcesContent": ["import create from './create';\nimport convertLegacyLocalStorageData from './migrations/legacy-local-storage-data';\nimport
|
|
5
|
-
"mappings": ";AAAA,OAAO,YAAY;AACnB,OAAO,mCAAmC;AAC1C,OAAO,
|
|
3
|
+
"sources": ["../src/index.ts"],
|
|
4
|
+
"sourcesContent": ["import create from './create';\nimport convertLegacyLocalStorageData from './migrations/legacy-local-storage-data';\nimport getNewestData from './get-newest-data';\nimport type { PersistenceLayer } from './types';\n\nexport { create };\n\nexport type * from './types';\n\n/**\n * Creates the persistence layer with preloaded data.\n *\n * It prioritizes any data from the server, but falls back first to localStorage\n * restore data, and then to any legacy data.\n *\n * This function is used internally by WordPress in an inline script, so\n * prefixed with `__unstable`.\n *\n * @param serverData Preferences data preloaded from the server.\n * @param userId The user id.\n *\n * @return The persistence layer initialized with the preloaded data.\n */\nexport function __unstableCreatePersistenceLayer(\n\tserverData: unknown,\n\tuserId: string | number\n): PersistenceLayer {\n\tconst localStorageRestoreKey = `WP_PREFERENCES_USER_${ userId }`;\n\treturn create( {\n\t\t/*\n\t\t * Fall back to data in the legacy format from the old persistence system.\n\t\t * The server data is already preloaded, so fetching it again is redundant.\n\t\t */\n\t\tpreloadedData:\n\t\t\tgetNewestData( serverData, localStorageRestoreKey ) ??\n\t\t\tconvertLegacyLocalStorageData( userId ) ??\n\t\t\t{},\n\t\tlocalStorageRestoreKey,\n\t} );\n}\n"],
|
|
5
|
+
"mappings": ";AAAA,OAAO,YAAY;AACnB,OAAO,mCAAmC;AAC1C,OAAO,mBAAmB;AAqBnB,SAAS,iCACf,YACA,QACmB;AACnB,QAAM,yBAAyB,uBAAwB,MAAO;AAC9D,SAAO,OAAQ;AAAA;AAAA;AAAA;AAAA;AAAA,IAKd,eACC,cAAe,YAAY,sBAAuB,KAClD,8BAA+B,MAAO,KACtC,CAAC;AAAA,IACF;AAAA,EACD,CAAE;AACH;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// packages/preferences-persistence/src/is-preferences-data.ts
|
|
2
|
+
function isPreferencesData(data) {
|
|
3
|
+
return !!data && typeof data === "object" && !Array.isArray(data);
|
|
4
|
+
}
|
|
5
|
+
export {
|
|
6
|
+
isPreferencesData as default
|
|
7
|
+
};
|
|
8
|
+
//# sourceMappingURL=is-preferences-data.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/is-preferences-data.ts"],
|
|
4
|
+
"sourcesContent": ["import type { PreferencesData } from './types';\n\n/**\n * Checks whether persisted data is a preferences object. Empty user meta\n * reaches the client as `[]` or `''`, which must not be used as preferences.\n *\n * @param data The persisted data.\n *\n * @return Whether the data is a preferences object.\n */\nexport default function isPreferencesData(\n\tdata: unknown\n): data is PreferencesData {\n\treturn !! data && typeof data === 'object' && ! Array.isArray( data );\n}\n"],
|
|
5
|
+
"mappings": ";AAUe,SAAR,kBACN,MAC0B;AAC1B,SAAO,CAAC,CAAE,QAAQ,OAAO,SAAS,YAAY,CAAE,MAAM,QAAS,IAAK;AACrE;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// packages/preferences-persistence/src/local-storage.ts
|
|
2
|
+
function readStoredJSON(key) {
|
|
3
|
+
try {
|
|
4
|
+
const value = window.localStorage.getItem(key);
|
|
5
|
+
return value === null ? null : JSON.parse(value);
|
|
6
|
+
} catch {
|
|
7
|
+
return null;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
function writeStoredJSON(key, value) {
|
|
11
|
+
try {
|
|
12
|
+
window.localStorage.setItem(key, JSON.stringify(value));
|
|
13
|
+
} catch {
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
export {
|
|
17
|
+
readStoredJSON,
|
|
18
|
+
writeStoredJSON
|
|
19
|
+
};
|
|
20
|
+
//# sourceMappingURL=local-storage.mjs.map
|