Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93
/home/sportsfe.../httpdocs/clone/wp-inclu.../js/dist
File: preferences-persistence.js
/******/ (() => { // webpackBootstrap
[0] Fix | Delete
/******/ "use strict";
[1] Fix | Delete
/******/ // The require scope
[2] Fix | Delete
/******/ var __webpack_require__ = {};
[3] Fix | Delete
/******/
[4] Fix | Delete
/************************************************************************/
[5] Fix | Delete
/******/ /* webpack/runtime/compat get default export */
[6] Fix | Delete
/******/ (() => {
[7] Fix | Delete
/******/ // getDefaultExport function for compatibility with non-harmony modules
[8] Fix | Delete
/******/ __webpack_require__.n = (module) => {
[9] Fix | Delete
/******/ var getter = module && module.__esModule ?
[10] Fix | Delete
/******/ () => (module['default']) :
[11] Fix | Delete
/******/ () => (module);
[12] Fix | Delete
/******/ __webpack_require__.d(getter, { a: getter });
[13] Fix | Delete
/******/ return getter;
[14] Fix | Delete
/******/ };
[15] Fix | Delete
/******/ })();
[16] Fix | Delete
/******/
[17] Fix | Delete
/******/ /* webpack/runtime/define property getters */
[18] Fix | Delete
/******/ (() => {
[19] Fix | Delete
/******/ // define getter functions for harmony exports
[20] Fix | Delete
/******/ __webpack_require__.d = (exports, definition) => {
[21] Fix | Delete
/******/ for(var key in definition) {
[22] Fix | Delete
/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
[23] Fix | Delete
/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
[24] Fix | Delete
/******/ }
[25] Fix | Delete
/******/ }
[26] Fix | Delete
/******/ };
[27] Fix | Delete
/******/ })();
[28] Fix | Delete
/******/
[29] Fix | Delete
/******/ /* webpack/runtime/hasOwnProperty shorthand */
[30] Fix | Delete
/******/ (() => {
[31] Fix | Delete
/******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
[32] Fix | Delete
/******/ })();
[33] Fix | Delete
/******/
[34] Fix | Delete
/******/ /* webpack/runtime/make namespace object */
[35] Fix | Delete
/******/ (() => {
[36] Fix | Delete
/******/ // define __esModule on exports
[37] Fix | Delete
/******/ __webpack_require__.r = (exports) => {
[38] Fix | Delete
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
[39] Fix | Delete
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
[40] Fix | Delete
/******/ }
[41] Fix | Delete
/******/ Object.defineProperty(exports, '__esModule', { value: true });
[42] Fix | Delete
/******/ };
[43] Fix | Delete
/******/ })();
[44] Fix | Delete
/******/
[45] Fix | Delete
/************************************************************************/
[46] Fix | Delete
var __webpack_exports__ = {};
[47] Fix | Delete
// ESM COMPAT FLAG
[48] Fix | Delete
__webpack_require__.r(__webpack_exports__);
[49] Fix | Delete
[50] Fix | Delete
// EXPORTS
[51] Fix | Delete
__webpack_require__.d(__webpack_exports__, {
[52] Fix | Delete
__unstableCreatePersistenceLayer: () => (/* binding */ __unstableCreatePersistenceLayer),
[53] Fix | Delete
create: () => (/* reexport */ create)
[54] Fix | Delete
});
[55] Fix | Delete
[56] Fix | Delete
;// CONCATENATED MODULE: external ["wp","apiFetch"]
[57] Fix | Delete
const external_wp_apiFetch_namespaceObject = window["wp"]["apiFetch"];
[58] Fix | Delete
var external_wp_apiFetch_default = /*#__PURE__*/__webpack_require__.n(external_wp_apiFetch_namespaceObject);
[59] Fix | Delete
;// CONCATENATED MODULE: ./node_modules/@wordpress/preferences-persistence/build-module/create/debounce-async.js
[60] Fix | Delete
/**
[61] Fix | Delete
* Performs a leading edge debounce of async functions.
[62] Fix | Delete
*
[63] Fix | Delete
* If three functions are throttled at the same time:
[64] Fix | Delete
* - The first happens immediately.
[65] Fix | Delete
* - The second is never called.
[66] Fix | Delete
* - The third happens `delayMS` milliseconds after the first has resolved.
[67] Fix | Delete
*
[68] Fix | Delete
* This is distinct from `{ debounce } from @wordpress/compose` in that it
[69] Fix | Delete
* waits for promise resolution.
[70] Fix | Delete
*
[71] Fix | Delete
* @param {Function} func A function that returns a promise.
[72] Fix | Delete
* @param {number} delayMS A delay in milliseconds.
[73] Fix | Delete
*
[74] Fix | Delete
* @return {Function} A function that debounce whatever function is passed
[75] Fix | Delete
* to it.
[76] Fix | Delete
*/
[77] Fix | Delete
function debounceAsync(func, delayMS) {
[78] Fix | Delete
let timeoutId;
[79] Fix | Delete
let activePromise;
[80] Fix | Delete
return async function debounced(...args) {
[81] Fix | Delete
// This is a leading edge debounce. If there's no promise or timeout
[82] Fix | Delete
// in progress, call the debounced function immediately.
[83] Fix | Delete
if (!activePromise && !timeoutId) {
[84] Fix | Delete
return new Promise((resolve, reject) => {
[85] Fix | Delete
// Keep a reference to the promise.
[86] Fix | Delete
activePromise = func(...args).then((...thenArgs) => {
[87] Fix | Delete
resolve(...thenArgs);
[88] Fix | Delete
}).catch(error => {
[89] Fix | Delete
reject(error);
[90] Fix | Delete
}).finally(() => {
[91] Fix | Delete
// As soon this promise is complete, clear the way for the
[92] Fix | Delete
// next one to happen immediately.
[93] Fix | Delete
activePromise = null;
[94] Fix | Delete
});
[95] Fix | Delete
});
[96] Fix | Delete
}
[97] Fix | Delete
if (activePromise) {
[98] Fix | Delete
// Let any active promises finish before queuing the next request.
[99] Fix | Delete
await activePromise;
[100] Fix | Delete
}
[101] Fix | Delete
[102] Fix | Delete
// Clear any active timeouts, abandoning any requests that have
[103] Fix | Delete
// been queued but not been made.
[104] Fix | Delete
if (timeoutId) {
[105] Fix | Delete
clearTimeout(timeoutId);
[106] Fix | Delete
timeoutId = null;
[107] Fix | Delete
}
[108] Fix | Delete
[109] Fix | Delete
// Trigger any trailing edge calls to the function.
[110] Fix | Delete
return new Promise((resolve, reject) => {
[111] Fix | Delete
// Schedule the next request but with a delay.
[112] Fix | Delete
timeoutId = setTimeout(() => {
[113] Fix | Delete
activePromise = func(...args).then((...thenArgs) => {
[114] Fix | Delete
resolve(...thenArgs);
[115] Fix | Delete
}).catch(error => {
[116] Fix | Delete
reject(error);
[117] Fix | Delete
}).finally(() => {
[118] Fix | Delete
// As soon this promise is complete, clear the way for the
[119] Fix | Delete
// next one to happen immediately.
[120] Fix | Delete
activePromise = null;
[121] Fix | Delete
timeoutId = null;
[122] Fix | Delete
});
[123] Fix | Delete
}, delayMS);
[124] Fix | Delete
});
[125] Fix | Delete
};
[126] Fix | Delete
}
[127] Fix | Delete
[128] Fix | Delete
;// CONCATENATED MODULE: ./node_modules/@wordpress/preferences-persistence/build-module/create/index.js
[129] Fix | Delete
/**
[130] Fix | Delete
* WordPress dependencies
[131] Fix | Delete
*/
[132] Fix | Delete
[133] Fix | Delete
[134] Fix | Delete
/**
[135] Fix | Delete
* Internal dependencies
[136] Fix | Delete
*/
[137] Fix | Delete
[138] Fix | Delete
const EMPTY_OBJECT = {};
[139] Fix | Delete
const localStorage = window.localStorage;
[140] Fix | Delete
[141] Fix | Delete
/**
[142] Fix | Delete
* Creates a persistence layer that stores data in WordPress user meta via the
[143] Fix | Delete
* REST API.
[144] Fix | Delete
*
[145] Fix | Delete
* @param {Object} options
[146] Fix | Delete
* @param {?Object} options.preloadedData Any persisted preferences data that should be preloaded.
[147] Fix | Delete
* When set, the persistence layer will avoid fetching data
[148] Fix | Delete
* from the REST API.
[149] Fix | Delete
* @param {?string} options.localStorageRestoreKey The key to use for restoring the localStorage backup, used
[150] Fix | Delete
* when the persistence layer calls `localStorage.getItem` or
[151] Fix | Delete
* `localStorage.setItem`.
[152] Fix | Delete
* @param {?number} options.requestDebounceMS Debounce requests to the API so that they only occur at
[153] Fix | Delete
* minimum every `requestDebounceMS` milliseconds, and don't
[154] Fix | Delete
* swamp the server. Defaults to 2500ms.
[155] Fix | Delete
*
[156] Fix | Delete
* @return {Object} A persistence layer for WordPress user meta.
[157] Fix | Delete
*/
[158] Fix | Delete
function create({
[159] Fix | Delete
preloadedData,
[160] Fix | Delete
localStorageRestoreKey = 'WP_PREFERENCES_RESTORE_DATA',
[161] Fix | Delete
requestDebounceMS = 2500
[162] Fix | Delete
} = {}) {
[163] Fix | Delete
let cache = preloadedData;
[164] Fix | Delete
const debouncedApiFetch = debounceAsync((external_wp_apiFetch_default()), requestDebounceMS);
[165] Fix | Delete
async function get() {
[166] Fix | Delete
if (cache) {
[167] Fix | Delete
return cache;
[168] Fix | Delete
}
[169] Fix | Delete
const user = await external_wp_apiFetch_default()({
[170] Fix | Delete
path: '/wp/v2/users/me?context=edit'
[171] Fix | Delete
});
[172] Fix | Delete
const serverData = user?.meta?.persisted_preferences;
[173] Fix | Delete
const localData = JSON.parse(localStorage.getItem(localStorageRestoreKey));
[174] Fix | Delete
[175] Fix | Delete
// Date parse returns NaN for invalid input. Coerce anything invalid
[176] Fix | Delete
// into a conveniently comparable zero.
[177] Fix | Delete
const serverTimestamp = Date.parse(serverData?._modified) || 0;
[178] Fix | Delete
const localTimestamp = Date.parse(localData?._modified) || 0;
[179] Fix | Delete
[180] Fix | Delete
// Prefer server data if it exists and is more recent.
[181] Fix | Delete
// Otherwise fallback to localStorage data.
[182] Fix | Delete
if (serverData && serverTimestamp >= localTimestamp) {
[183] Fix | Delete
cache = serverData;
[184] Fix | Delete
} else if (localData) {
[185] Fix | Delete
cache = localData;
[186] Fix | Delete
} else {
[187] Fix | Delete
cache = EMPTY_OBJECT;
[188] Fix | Delete
}
[189] Fix | Delete
return cache;
[190] Fix | Delete
}
[191] Fix | Delete
function set(newData) {
[192] Fix | Delete
const dataWithTimestamp = {
[193] Fix | Delete
...newData,
[194] Fix | Delete
_modified: new Date().toISOString()
[195] Fix | Delete
};
[196] Fix | Delete
cache = dataWithTimestamp;
[197] Fix | Delete
[198] Fix | Delete
// Store data in local storage as a fallback. If for some reason the
[199] Fix | Delete
// api request does not complete or becomes unavailable, this data
[200] Fix | Delete
// can be used to restore preferences.
[201] Fix | Delete
localStorage.setItem(localStorageRestoreKey, JSON.stringify(dataWithTimestamp));
[202] Fix | Delete
[203] Fix | Delete
// The user meta endpoint seems susceptible to errors when consecutive
[204] Fix | Delete
// requests are made in quick succession. Ensure there's a gap between
[205] Fix | Delete
// any consecutive requests.
[206] Fix | Delete
//
[207] Fix | Delete
// Catch and do nothing with errors from the REST API.
[208] Fix | Delete
debouncedApiFetch({
[209] Fix | Delete
path: '/wp/v2/users/me',
[210] Fix | Delete
method: 'PUT',
[211] Fix | Delete
// `keepalive` will still send the request in the background,
[212] Fix | Delete
// even when a browser unload event might interrupt it.
[213] Fix | Delete
// This should hopefully make things more resilient.
[214] Fix | Delete
// This does have a size limit of 64kb, but the data is usually
[215] Fix | Delete
// much less.
[216] Fix | Delete
keepalive: true,
[217] Fix | Delete
data: {
[218] Fix | Delete
meta: {
[219] Fix | Delete
persisted_preferences: dataWithTimestamp
[220] Fix | Delete
}
[221] Fix | Delete
}
[222] Fix | Delete
}).catch(() => {});
[223] Fix | Delete
}
[224] Fix | Delete
return {
[225] Fix | Delete
get,
[226] Fix | Delete
set
[227] Fix | Delete
};
[228] Fix | Delete
}
[229] Fix | Delete
[230] Fix | Delete
;// CONCATENATED MODULE: ./node_modules/@wordpress/preferences-persistence/build-module/migrations/legacy-local-storage-data/move-feature-preferences.js
[231] Fix | Delete
/**
[232] Fix | Delete
* Move the 'features' object in local storage from the sourceStoreName to the
[233] Fix | Delete
* preferences store data structure.
[234] Fix | Delete
*
[235] Fix | Delete
* Previously, editors used a data structure like this for feature preferences:
[236] Fix | Delete
* ```js
[237] Fix | Delete
* {
[238] Fix | Delete
* 'core/edit-post': {
[239] Fix | Delete
* preferences: {
[240] Fix | Delete
* features; {
[241] Fix | Delete
* topToolbar: true,
[242] Fix | Delete
* // ... other boolean 'feature' preferences
[243] Fix | Delete
* },
[244] Fix | Delete
* },
[245] Fix | Delete
* },
[246] Fix | Delete
* }
[247] Fix | Delete
* ```
[248] Fix | Delete
*
[249] Fix | Delete
* And for a while these feature preferences lived in the interface package:
[250] Fix | Delete
* ```js
[251] Fix | Delete
* {
[252] Fix | Delete
* 'core/interface': {
[253] Fix | Delete
* preferences: {
[254] Fix | Delete
* features: {
[255] Fix | Delete
* 'core/edit-post': {
[256] Fix | Delete
* topToolbar: true
[257] Fix | Delete
* }
[258] Fix | Delete
* }
[259] Fix | Delete
* }
[260] Fix | Delete
* }
[261] Fix | Delete
* }
[262] Fix | Delete
* ```
[263] Fix | Delete
*
[264] Fix | Delete
* In the preferences store, 'features' aren't considered special, they're
[265] Fix | Delete
* merged to the root level of the scope along with other preferences:
[266] Fix | Delete
* ```js
[267] Fix | Delete
* {
[268] Fix | Delete
* 'core/preferences': {
[269] Fix | Delete
* preferences: {
[270] Fix | Delete
* 'core/edit-post': {
[271] Fix | Delete
* topToolbar: true,
[272] Fix | Delete
* // ... any other preferences.
[273] Fix | Delete
* }
[274] Fix | Delete
* }
[275] Fix | Delete
* }
[276] Fix | Delete
* }
[277] Fix | Delete
* ```
[278] Fix | Delete
*
[279] Fix | Delete
* This function handles moving from either the source store or the interface
[280] Fix | Delete
* store to the preferences data structure.
[281] Fix | Delete
*
[282] Fix | Delete
* @param {Object} state The state before migration.
[283] Fix | Delete
* @param {string} sourceStoreName The name of the store that has persisted
[284] Fix | Delete
* preferences to migrate to the preferences
[285] Fix | Delete
* package.
[286] Fix | Delete
* @return {Object} The migrated state
[287] Fix | Delete
*/
[288] Fix | Delete
function moveFeaturePreferences(state, sourceStoreName) {
[289] Fix | Delete
const preferencesStoreName = 'core/preferences';
[290] Fix | Delete
const interfaceStoreName = 'core/interface';
[291] Fix | Delete
[292] Fix | Delete
// Features most recently (and briefly) lived in the interface package.
[293] Fix | Delete
// If data exists there, prioritize using that for the migration. If not
[294] Fix | Delete
// also check the original package as the user may have updated from an
[295] Fix | Delete
// older block editor version.
[296] Fix | Delete
const interfaceFeatures = state?.[interfaceStoreName]?.preferences?.features?.[sourceStoreName];
[297] Fix | Delete
const sourceFeatures = state?.[sourceStoreName]?.preferences?.features;
[298] Fix | Delete
const featuresToMigrate = interfaceFeatures ? interfaceFeatures : sourceFeatures;
[299] Fix | Delete
if (!featuresToMigrate) {
[300] Fix | Delete
return state;
[301] Fix | Delete
}
[302] Fix | Delete
const existingPreferences = state?.[preferencesStoreName]?.preferences;
[303] Fix | Delete
[304] Fix | Delete
// Avoid migrating features again if they've previously been migrated.
[305] Fix | Delete
if (existingPreferences?.[sourceStoreName]) {
[306] Fix | Delete
return state;
[307] Fix | Delete
}
[308] Fix | Delete
let updatedInterfaceState;
[309] Fix | Delete
if (interfaceFeatures) {
[310] Fix | Delete
const otherInterfaceState = state?.[interfaceStoreName];
[311] Fix | Delete
const otherInterfaceScopes = state?.[interfaceStoreName]?.preferences?.features;
[312] Fix | Delete
updatedInterfaceState = {
[313] Fix | Delete
[interfaceStoreName]: {
[314] Fix | Delete
...otherInterfaceState,
[315] Fix | Delete
preferences: {
[316] Fix | Delete
features: {
[317] Fix | Delete
...otherInterfaceScopes,
[318] Fix | Delete
[sourceStoreName]: undefined
[319] Fix | Delete
}
[320] Fix | Delete
}
[321] Fix | Delete
}
[322] Fix | Delete
};
[323] Fix | Delete
}
[324] Fix | Delete
let updatedSourceState;
[325] Fix | Delete
if (sourceFeatures) {
[326] Fix | Delete
const otherSourceState = state?.[sourceStoreName];
[327] Fix | Delete
const sourcePreferences = state?.[sourceStoreName]?.preferences;
[328] Fix | Delete
updatedSourceState = {
[329] Fix | Delete
[sourceStoreName]: {
[330] Fix | Delete
...otherSourceState,
[331] Fix | Delete
preferences: {
[332] Fix | Delete
...sourcePreferences,
[333] Fix | Delete
features: undefined
[334] Fix | Delete
}
[335] Fix | Delete
}
[336] Fix | Delete
};
[337] Fix | Delete
}
[338] Fix | Delete
[339] Fix | Delete
// Set the feature values in the interface store, the features
[340] Fix | Delete
// object is keyed by 'scope', which matches the store name for
[341] Fix | Delete
// the source.
[342] Fix | Delete
return {
[343] Fix | Delete
...state,
[344] Fix | Delete
[preferencesStoreName]: {
[345] Fix | Delete
preferences: {
[346] Fix | Delete
...existingPreferences,
[347] Fix | Delete
[sourceStoreName]: featuresToMigrate
[348] Fix | Delete
}
[349] Fix | Delete
},
[350] Fix | Delete
...updatedInterfaceState,
[351] Fix | Delete
...updatedSourceState
[352] Fix | Delete
};
[353] Fix | Delete
}
[354] Fix | Delete
[355] Fix | Delete
;// CONCATENATED MODULE: ./node_modules/@wordpress/preferences-persistence/build-module/migrations/legacy-local-storage-data/move-third-party-feature-preferences.js
[356] Fix | Delete
/**
[357] Fix | Delete
* The interface package previously had a public API that could be used by
[358] Fix | Delete
* plugins to set persisted boolean 'feature' preferences.
[359] Fix | Delete
*
[360] Fix | Delete
* While usage was likely non-existent or very small, this function ensures
[361] Fix | Delete
* those are migrated to the preferences data structure. The interface
[362] Fix | Delete
* package's APIs have now been deprecated and use the preferences store.
[363] Fix | Delete
*
[364] Fix | Delete
* This will convert data that looks like this:
[365] Fix | Delete
* ```js
[366] Fix | Delete
* {
[367] Fix | Delete
* 'core/interface': {
[368] Fix | Delete
* preferences: {
[369] Fix | Delete
* features: {
[370] Fix | Delete
* 'my-plugin': {
[371] Fix | Delete
* myPluginFeature: true
[372] Fix | Delete
* }
[373] Fix | Delete
* }
[374] Fix | Delete
* }
[375] Fix | Delete
* }
[376] Fix | Delete
* }
[377] Fix | Delete
* ```
[378] Fix | Delete
*
[379] Fix | Delete
* To this:
[380] Fix | Delete
* ```js
[381] Fix | Delete
* * {
[382] Fix | Delete
* 'core/preferences': {
[383] Fix | Delete
* preferences: {
[384] Fix | Delete
* 'my-plugin': {
[385] Fix | Delete
* myPluginFeature: true
[386] Fix | Delete
* }
[387] Fix | Delete
* }
[388] Fix | Delete
* }
[389] Fix | Delete
* }
[390] Fix | Delete
* ```
[391] Fix | Delete
*
[392] Fix | Delete
* @param {Object} state The local storage state
[393] Fix | Delete
*
[394] Fix | Delete
* @return {Object} The state with third party preferences moved to the
[395] Fix | Delete
* preferences data structure.
[396] Fix | Delete
*/
[397] Fix | Delete
function moveThirdPartyFeaturePreferencesToPreferences(state) {
[398] Fix | Delete
const interfaceStoreName = 'core/interface';
[399] Fix | Delete
const preferencesStoreName = 'core/preferences';
[400] Fix | Delete
const interfaceScopes = state?.[interfaceStoreName]?.preferences?.features;
[401] Fix | Delete
const interfaceScopeKeys = interfaceScopes ? Object.keys(interfaceScopes) : [];
[402] Fix | Delete
if (!interfaceScopeKeys?.length) {
[403] Fix | Delete
return state;
[404] Fix | Delete
}
[405] Fix | Delete
return interfaceScopeKeys.reduce(function (convertedState, scope) {
[406] Fix | Delete
if (scope.startsWith('core')) {
[407] Fix | Delete
return convertedState;
[408] Fix | Delete
}
[409] Fix | Delete
const featuresToMigrate = interfaceScopes?.[scope];
[410] Fix | Delete
if (!featuresToMigrate) {
[411] Fix | Delete
return convertedState;
[412] Fix | Delete
}
[413] Fix | Delete
const existingMigratedData = convertedState?.[preferencesStoreName]?.preferences?.[scope];
[414] Fix | Delete
if (existingMigratedData) {
[415] Fix | Delete
return convertedState;
[416] Fix | Delete
}
[417] Fix | Delete
const otherPreferencesScopes = convertedState?.[preferencesStoreName]?.preferences;
[418] Fix | Delete
const otherInterfaceState = convertedState?.[interfaceStoreName];
[419] Fix | Delete
const otherInterfaceScopes = convertedState?.[interfaceStoreName]?.preferences?.features;
[420] Fix | Delete
return {
[421] Fix | Delete
...convertedState,
[422] Fix | Delete
[preferencesStoreName]: {
[423] Fix | Delete
preferences: {
[424] Fix | Delete
...otherPreferencesScopes,
[425] Fix | Delete
[scope]: featuresToMigrate
[426] Fix | Delete
}
[427] Fix | Delete
},
[428] Fix | Delete
[interfaceStoreName]: {
[429] Fix | Delete
...otherInterfaceState,
[430] Fix | Delete
preferences: {
[431] Fix | Delete
features: {
[432] Fix | Delete
...otherInterfaceScopes,
[433] Fix | Delete
[scope]: undefined
[434] Fix | Delete
}
[435] Fix | Delete
}
[436] Fix | Delete
}
[437] Fix | Delete
};
[438] Fix | Delete
}, state);
[439] Fix | Delete
}
[440] Fix | Delete
[441] Fix | Delete
;// CONCATENATED MODULE: ./node_modules/@wordpress/preferences-persistence/build-module/migrations/legacy-local-storage-data/move-individual-preference.js
[442] Fix | Delete
const identity = arg => arg;
[443] Fix | Delete
[444] Fix | Delete
/**
[445] Fix | Delete
* Migrates an individual item inside the `preferences` object for a package's store.
[446] Fix | Delete
*
[447] Fix | Delete
* Previously, some packages had individual 'preferences' of any data type, and many used
[448] Fix | Delete
* complex nested data structures. For example:
[449] Fix | Delete
* ```js
[450] Fix | Delete
* {
[451] Fix | Delete
* 'core/edit-post': {
[452] Fix | Delete
* preferences: {
[453] Fix | Delete
* panels: {
[454] Fix | Delete
* publish: {
[455] Fix | Delete
* opened: true,
[456] Fix | Delete
* enabled: true,
[457] Fix | Delete
* }
[458] Fix | Delete
* },
[459] Fix | Delete
* // ...other preferences.
[460] Fix | Delete
* },
[461] Fix | Delete
* },
[462] Fix | Delete
* }
[463] Fix | Delete
*
[464] Fix | Delete
* This function supports moving an individual preference like 'panels' above into the
[465] Fix | Delete
* preferences package data structure.
[466] Fix | Delete
*
[467] Fix | Delete
* It supports moving a preference to a particular scope in the preferences store and
[468] Fix | Delete
* optionally converting the data using a `convert` function.
[469] Fix | Delete
*
[470] Fix | Delete
* ```
[471] Fix | Delete
*
[472] Fix | Delete
* @param {Object} state The original state.
[473] Fix | Delete
* @param {Object} migrate An options object that contains details of the migration.
[474] Fix | Delete
* @param {string} migrate.from The name of the store to migrate from.
[475] Fix | Delete
* @param {string} migrate.to The scope in the preferences store to migrate to.
[476] Fix | Delete
* @param {string} key The key in the preferences object to migrate.
[477] Fix | Delete
* @param {?Function} convert A function that converts preferences from one format to another.
[478] Fix | Delete
*/
[479] Fix | Delete
function moveIndividualPreferenceToPreferences(state, {
[480] Fix | Delete
from: sourceStoreName,
[481] Fix | Delete
to: scope
[482] Fix | Delete
}, key, convert = identity) {
[483] Fix | Delete
const preferencesStoreName = 'core/preferences';
[484] Fix | Delete
const sourcePreference = state?.[sourceStoreName]?.preferences?.[key];
[485] Fix | Delete
[486] Fix | Delete
// There's nothing to migrate, exit early.
[487] Fix | Delete
if (sourcePreference === undefined) {
[488] Fix | Delete
return state;
[489] Fix | Delete
}
[490] Fix | Delete
const targetPreference = state?.[preferencesStoreName]?.preferences?.[scope]?.[key];
[491] Fix | Delete
[492] Fix | Delete
// There's existing data at the target, so don't overwrite it, exit early.
[493] Fix | Delete
if (targetPreference) {
[494] Fix | Delete
return state;
[495] Fix | Delete
}
[496] Fix | Delete
const otherScopes = state?.[preferencesStoreName]?.preferences;
[497] Fix | Delete
const otherPreferences = state?.[preferencesStoreName]?.preferences?.[scope];
[498] Fix | Delete
const otherSourceState = state?.[sourceStoreName];
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function