You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

861 lines
28 KiB

1 year ago
  1. /******/ (function() { // webpackBootstrap
  2. /******/ "use strict";
  3. /******/ // The require scope
  4. /******/ var __webpack_require__ = {};
  5. /******/
  6. /************************************************************************/
  7. /******/ /* webpack/runtime/compat get default export */
  8. /******/ !function() {
  9. /******/ // getDefaultExport function for compatibility with non-harmony modules
  10. /******/ __webpack_require__.n = function(module) {
  11. /******/ var getter = module && module.__esModule ?
  12. /******/ function() { return module['default']; } :
  13. /******/ function() { return module; };
  14. /******/ __webpack_require__.d(getter, { a: getter });
  15. /******/ return getter;
  16. /******/ };
  17. /******/ }();
  18. /******/
  19. /******/ /* webpack/runtime/define property getters */
  20. /******/ !function() {
  21. /******/ // define getter functions for harmony exports
  22. /******/ __webpack_require__.d = function(exports, definition) {
  23. /******/ for(var key in definition) {
  24. /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
  25. /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
  26. /******/ }
  27. /******/ }
  28. /******/ };
  29. /******/ }();
  30. /******/
  31. /******/ /* webpack/runtime/hasOwnProperty shorthand */
  32. /******/ !function() {
  33. /******/ __webpack_require__.o = function(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); }
  34. /******/ }();
  35. /******/
  36. /******/ /* webpack/runtime/make namespace object */
  37. /******/ !function() {
  38. /******/ // define __esModule on exports
  39. /******/ __webpack_require__.r = function(exports) {
  40. /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
  41. /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
  42. /******/ }
  43. /******/ Object.defineProperty(exports, '__esModule', { value: true });
  44. /******/ };
  45. /******/ }();
  46. /******/
  47. /************************************************************************/
  48. var __webpack_exports__ = {};
  49. // ESM COMPAT FLAG
  50. __webpack_require__.r(__webpack_exports__);
  51. // EXPORTS
  52. __webpack_require__.d(__webpack_exports__, {
  53. __unstableCreatePersistenceLayer: function() { return /* binding */ __unstableCreatePersistenceLayer; },
  54. create: function() { return /* reexport */ create; }
  55. });
  56. ;// CONCATENATED MODULE: external ["wp","apiFetch"]
  57. var external_wp_apiFetch_namespaceObject = window["wp"]["apiFetch"];
  58. var external_wp_apiFetch_default = /*#__PURE__*/__webpack_require__.n(external_wp_apiFetch_namespaceObject);
  59. ;// CONCATENATED MODULE: ./node_modules/@wordpress/preferences-persistence/build-module/create/debounce-async.js
  60. /**
  61. * Performs a leading edge debounce of async functions.
  62. *
  63. * If three functions are throttled at the same time:
  64. * - The first happens immediately.
  65. * - The second is never called.
  66. * - The third happens `delayMS` milliseconds after the first has resolved.
  67. *
  68. * This is distinct from `{ debounce } from @wordpress/compose` in that it
  69. * waits for promise resolution.
  70. *
  71. * @param {Function} func A function that returns a promise.
  72. * @param {number} delayMS A delay in milliseconds.
  73. *
  74. * @return {Function} A function that debounce whatever function is passed
  75. * to it.
  76. */
  77. function debounceAsync(func, delayMS) {
  78. let timeoutId;
  79. let activePromise;
  80. return async function debounced(...args) {
  81. // This is a leading edge debounce. If there's no promise or timeout
  82. // in progress, call the debounced function immediately.
  83. if (!activePromise && !timeoutId) {
  84. return new Promise((resolve, reject) => {
  85. // Keep a reference to the promise.
  86. activePromise = func(...args).then((...thenArgs) => {
  87. resolve(...thenArgs);
  88. }).catch(error => {
  89. reject(error);
  90. }).finally(() => {
  91. // As soon this promise is complete, clear the way for the
  92. // next one to happen immediately.
  93. activePromise = null;
  94. });
  95. });
  96. }
  97. if (activePromise) {
  98. // Let any active promises finish before queuing the next request.
  99. await activePromise;
  100. }
  101. // Clear any active timeouts, abandoning any requests that have
  102. // been queued but not been made.
  103. if (timeoutId) {
  104. clearTimeout(timeoutId);
  105. timeoutId = null;
  106. }
  107. // Trigger any trailing edge calls to the function.
  108. return new Promise((resolve, reject) => {
  109. // Schedule the next request but with a delay.
  110. timeoutId = setTimeout(() => {
  111. activePromise = func(...args).then((...thenArgs) => {
  112. resolve(...thenArgs);
  113. }).catch(error => {
  114. reject(error);
  115. }).finally(() => {
  116. // As soon this promise is complete, clear the way for the
  117. // next one to happen immediately.
  118. activePromise = null;
  119. timeoutId = null;
  120. });
  121. }, delayMS);
  122. });
  123. };
  124. }
  125. ;// CONCATENATED MODULE: ./node_modules/@wordpress/preferences-persistence/build-module/create/index.js
  126. /**
  127. * WordPress dependencies
  128. */
  129. /**
  130. * Internal dependencies
  131. */
  132. const EMPTY_OBJECT = {};
  133. const localStorage = window.localStorage;
  134. /**
  135. * Creates a persistence layer that stores data in WordPress user meta via the
  136. * REST API.
  137. *
  138. * @param {Object} options
  139. * @param {?Object} options.preloadedData Any persisted preferences data that should be preloaded.
  140. * When set, the persistence layer will avoid fetching data
  141. * from the REST API.
  142. * @param {?string} options.localStorageRestoreKey The key to use for restoring the localStorage backup, used
  143. * when the persistence layer calls `localStorage.getItem` or
  144. * `localStorage.setItem`.
  145. * @param {?number} options.requestDebounceMS Debounce requests to the API so that they only occur at
  146. * minimum every `requestDebounceMS` milliseconds, and don't
  147. * swamp the server. Defaults to 2500ms.
  148. *
  149. * @return {Object} A persistence layer for WordPress user meta.
  150. */
  151. function create({
  152. preloadedData,
  153. localStorageRestoreKey = 'WP_PREFERENCES_RESTORE_DATA',
  154. requestDebounceMS = 2500
  155. } = {}) {
  156. let cache = preloadedData;
  157. const debouncedApiFetch = debounceAsync((external_wp_apiFetch_default()), requestDebounceMS);
  158. async function get() {
  159. if (cache) {
  160. return cache;
  161. }
  162. const user = await external_wp_apiFetch_default()({
  163. path: '/wp/v2/users/me?context=edit'
  164. });
  165. const serverData = user?.meta?.persisted_preferences;
  166. const localData = JSON.parse(localStorage.getItem(localStorageRestoreKey));
  167. // Date parse returns NaN for invalid input. Coerce anything invalid
  168. // into a conveniently comparable zero.
  169. const serverTimestamp = Date.parse(serverData?._modified) || 0;
  170. const localTimestamp = Date.parse(localData?._modified) || 0;
  171. // Prefer server data if it exists and is more recent.
  172. // Otherwise fallback to localStorage data.
  173. if (serverData && serverTimestamp >= localTimestamp) {
  174. cache = serverData;
  175. } else if (localData) {
  176. cache = localData;
  177. } else {
  178. cache = EMPTY_OBJECT;
  179. }
  180. return cache;
  181. }
  182. function set(newData) {
  183. const dataWithTimestamp = {
  184. ...newData,
  185. _modified: new Date().toISOString()
  186. };
  187. cache = dataWithTimestamp;
  188. // Store data in local storage as a fallback. If for some reason the
  189. // api request does not complete or becomes unavailable, this data
  190. // can be used to restore preferences.
  191. localStorage.setItem(localStorageRestoreKey, JSON.stringify(dataWithTimestamp));
  192. // The user meta endpoint seems susceptible to errors when consecutive
  193. // requests are made in quick succession. Ensure there's a gap between
  194. // any consecutive requests.
  195. //
  196. // Catch and do nothing with errors from the REST API.
  197. debouncedApiFetch({
  198. path: '/wp/v2/users/me',
  199. method: 'PUT',
  200. // `keepalive` will still send the request in the background,
  201. // even when a browser unload event might interrupt it.
  202. // This should hopefully make things more resilient.
  203. // This does have a size limit of 64kb, but the data is usually
  204. // much less.
  205. keepalive: true,
  206. data: {
  207. meta: {
  208. persisted_preferences: dataWithTimestamp
  209. }
  210. }
  211. }).catch(() => {});
  212. }
  213. return {
  214. get,
  215. set
  216. };
  217. }
  218. ;// CONCATENATED MODULE: ./node_modules/@wordpress/preferences-persistence/build-module/migrations/legacy-local-storage-data/move-feature-preferences.js
  219. /**
  220. * Move the 'features' object in local storage from the sourceStoreName to the
  221. * preferences store data structure.
  222. *
  223. * Previously, editors used a data structure like this for feature preferences:
  224. * ```js
  225. * {
  226. * 'core/edit-post': {
  227. * preferences: {
  228. * features; {
  229. * topToolbar: true,
  230. * // ... other boolean 'feature' preferences
  231. * },
  232. * },
  233. * },
  234. * }
  235. * ```
  236. *
  237. * And for a while these feature preferences lived in the interface package:
  238. * ```js
  239. * {
  240. * 'core/interface': {
  241. * preferences: {
  242. * features: {
  243. * 'core/edit-post': {
  244. * topToolbar: true
  245. * }
  246. * }
  247. * }
  248. * }
  249. * }
  250. * ```
  251. *
  252. * In the preferences store, 'features' aren't considered special, they're
  253. * merged to the root level of the scope along with other preferences:
  254. * ```js
  255. * {
  256. * 'core/preferences': {
  257. * preferences: {
  258. * 'core/edit-post': {
  259. * topToolbar: true,
  260. * // ... any other preferences.
  261. * }
  262. * }
  263. * }
  264. * }
  265. * ```
  266. *
  267. * This function handles moving from either the source store or the interface
  268. * store to the preferences data structure.
  269. *
  270. * @param {Object} state The state before migration.
  271. * @param {string} sourceStoreName The name of the store that has persisted
  272. * preferences to migrate to the preferences
  273. * package.
  274. * @return {Object} The migrated state
  275. */
  276. function moveFeaturePreferences(state, sourceStoreName) {
  277. const preferencesStoreName = 'core/preferences';
  278. const interfaceStoreName = 'core/interface';
  279. // Features most recently (and briefly) lived in the interface package.
  280. // If data exists there, prioritize using that for the migration. If not
  281. // also check the original package as the user may have updated from an
  282. // older block editor version.
  283. const interfaceFeatures = state?.[interfaceStoreName]?.preferences?.features?.[sourceStoreName];
  284. const sourceFeatures = state?.[sourceStoreName]?.preferences?.features;
  285. const featuresToMigrate = interfaceFeatures ? interfaceFeatures : sourceFeatures;
  286. if (!featuresToMigrate) {
  287. return state;
  288. }
  289. const existingPreferences = state?.[preferencesStoreName]?.preferences;
  290. // Avoid migrating features again if they've previously been migrated.
  291. if (existingPreferences?.[sourceStoreName]) {
  292. return state;
  293. }
  294. let updatedInterfaceState;
  295. if (interfaceFeatures) {
  296. const otherInterfaceState = state?.[interfaceStoreName];
  297. const otherInterfaceScopes = state?.[interfaceStoreName]?.preferences?.features;
  298. updatedInterfaceState = {
  299. [interfaceStoreName]: {
  300. ...otherInterfaceState,
  301. preferences: {
  302. features: {
  303. ...otherInterfaceScopes,
  304. [sourceStoreName]: undefined
  305. }
  306. }
  307. }
  308. };
  309. }
  310. let updatedSourceState;
  311. if (sourceFeatures) {
  312. const otherSourceState = state?.[sourceStoreName];
  313. const sourcePreferences = state?.[sourceStoreName]?.preferences;
  314. updatedSourceState = {
  315. [sourceStoreName]: {
  316. ...otherSourceState,
  317. preferences: {
  318. ...sourcePreferences,
  319. features: undefined
  320. }
  321. }
  322. };
  323. }
  324. // Set the feature values in the interface store, the features
  325. // object is keyed by 'scope', which matches the store name for
  326. // the source.
  327. return {
  328. ...state,
  329. [preferencesStoreName]: {
  330. preferences: {
  331. ...existingPreferences,
  332. [sourceStoreName]: featuresToMigrate
  333. }
  334. },
  335. ...updatedInterfaceState,
  336. ...updatedSourceState
  337. };
  338. }
  339. ;// CONCATENATED MODULE: ./node_modules/@wordpress/preferences-persistence/build-module/migrations/legacy-local-storage-data/move-third-party-feature-preferences.js
  340. /**
  341. * The interface package previously had a public API that could be used by
  342. * plugins to set persisted boolean 'feature' preferences.
  343. *
  344. * While usage was likely non-existent or very small, this function ensures
  345. * those are migrated to the preferences data structure. The interface
  346. * package's APIs have now been deprecated and use the preferences store.
  347. *
  348. * This will convert data that looks like this:
  349. * ```js
  350. * {
  351. * 'core/interface': {
  352. * preferences: {
  353. * features: {
  354. * 'my-plugin': {
  355. * myPluginFeature: true
  356. * }
  357. * }
  358. * }
  359. * }
  360. * }
  361. * ```
  362. *
  363. * To this:
  364. * ```js
  365. * * {
  366. * 'core/preferences': {
  367. * preferences: {
  368. * 'my-plugin': {
  369. * myPluginFeature: true
  370. * }
  371. * }
  372. * }
  373. * }
  374. * ```
  375. *
  376. * @param {Object} state The local storage state
  377. *
  378. * @return {Object} The state with third party preferences moved to the
  379. * preferences data structure.
  380. */
  381. function moveThirdPartyFeaturePreferencesToPreferences(state) {
  382. const interfaceStoreName = 'core/interface';
  383. const preferencesStoreName = 'core/preferences';
  384. const interfaceScopes = state?.[interfaceStoreName]?.preferences?.features;
  385. const interfaceScopeKeys = interfaceScopes ? Object.keys(interfaceScopes) : [];
  386. if (!interfaceScopeKeys?.length) {
  387. return state;
  388. }
  389. return interfaceScopeKeys.reduce(function (convertedState, scope) {
  390. if (scope.startsWith('core')) {
  391. return convertedState;
  392. }
  393. const featuresToMigrate = interfaceScopes?.[scope];
  394. if (!featuresToMigrate) {
  395. return convertedState;
  396. }
  397. const existingMigratedData = convertedState?.[preferencesStoreName]?.preferences?.[scope];
  398. if (existingMigratedData) {
  399. return convertedState;
  400. }
  401. const otherPreferencesScopes = convertedState?.[preferencesStoreName]?.preferences;
  402. const otherInterfaceState = convertedState?.[interfaceStoreName];
  403. const otherInterfaceScopes = convertedState?.[interfaceStoreName]?.preferences?.features;
  404. return {
  405. ...convertedState,
  406. [preferencesStoreName]: {
  407. preferences: {
  408. ...otherPreferencesScopes,
  409. [scope]: featuresToMigrate
  410. }
  411. },
  412. [interfaceStoreName]: {
  413. ...otherInterfaceState,
  414. preferences: {
  415. features: {
  416. ...otherInterfaceScopes,
  417. [scope]: undefined
  418. }
  419. }
  420. }
  421. };
  422. }, state);
  423. }
  424. ;// CONCATENATED MODULE: ./node_modules/@wordpress/preferences-persistence/build-module/migrations/legacy-local-storage-data/move-individual-preference.js
  425. const identity = arg => arg;
  426. /**
  427. * Migrates an individual item inside the `preferences` object for a package's store.
  428. *
  429. * Previously, some packages had individual 'preferences' of any data type, and many used
  430. * complex nested data structures. For example:
  431. * ```js
  432. * {
  433. * 'core/edit-post': {
  434. * preferences: {
  435. * panels: {
  436. * publish: {
  437. * opened: true,
  438. * enabled: true,
  439. * }
  440. * },
  441. * // ...other preferences.
  442. * },
  443. * },
  444. * }
  445. *
  446. * This function supports moving an individual preference like 'panels' above into the
  447. * preferences package data structure.
  448. *
  449. * It supports moving a preference to a particular scope in the preferences store and
  450. * optionally converting the data using a `convert` function.
  451. *
  452. * ```
  453. *
  454. * @param {Object} state The original state.
  455. * @param {Object} migrate An options object that contains details of the migration.
  456. * @param {string} migrate.from The name of the store to migrate from.
  457. * @param {string} migrate.to The scope in the preferences store to migrate to.
  458. * @param {string} key The key in the preferences object to migrate.
  459. * @param {?Function} convert A function that converts preferences from one format to another.
  460. */
  461. function moveIndividualPreferenceToPreferences(state, {
  462. from: sourceStoreName,
  463. to: scope
  464. }, key, convert = identity) {
  465. const preferencesStoreName = 'core/preferences';
  466. const sourcePreference = state?.[sourceStoreName]?.preferences?.[key];
  467. // There's nothing to migrate, exit early.
  468. if (sourcePreference === undefined) {
  469. return state;
  470. }
  471. const targetPreference = state?.[preferencesStoreName]?.preferences?.[scope]?.[key];
  472. // There's existing data at the target, so don't overwrite it, exit early.
  473. if (targetPreference) {
  474. return state;
  475. }
  476. const otherScopes = state?.[preferencesStoreName]?.preferences;
  477. const otherPreferences = state?.[preferencesStoreName]?.preferences?.[scope];
  478. const otherSourceState = state?.[sourceStoreName];
  479. const allSourcePreferences = state?.[sourceStoreName]?.preferences;
  480. // Pass an object with the key and value as this allows the convert
  481. // function to convert to a data structure that has different keys.
  482. const convertedPreferences = convert({
  483. [key]: sourcePreference
  484. });
  485. return {
  486. ...state,
  487. [preferencesStoreName]: {
  488. preferences: {
  489. ...otherScopes,
  490. [scope]: {
  491. ...otherPreferences,
  492. ...convertedPreferences
  493. }
  494. }
  495. },
  496. [sourceStoreName]: {
  497. ...otherSourceState,
  498. preferences: {
  499. ...allSourcePreferences,
  500. [key]: undefined
  501. }
  502. }
  503. };
  504. }
  505. ;// CONCATENATED MODULE: ./node_modules/@wordpress/preferences-persistence/build-module/migrations/legacy-local-storage-data/move-interface-enable-items.js
  506. /**
  507. * Migrates interface 'enableItems' data to the preferences store.
  508. *
  509. * The interface package stores this data in this format:
  510. * ```js
  511. * {
  512. * enableItems: {
  513. * singleEnableItems: {
  514. * complementaryArea: {
  515. * 'core/edit-post': 'edit-post/document',
  516. * 'core/edit-site': 'edit-site/global-styles',
  517. * }
  518. * },
  519. * multipleEnableItems: {
  520. * pinnedItems: {
  521. * 'core/edit-post': {
  522. * 'plugin-1': true,
  523. * },
  524. * 'core/edit-site': {
  525. * 'plugin-2': true,
  526. * },
  527. * },
  528. * }
  529. * }
  530. * }
  531. * ```
  532. *
  533. * and it should be converted it to:
  534. * ```js
  535. * {
  536. * 'core/edit-post': {
  537. * complementaryArea: 'edit-post/document',
  538. * pinnedItems: {
  539. * 'plugin-1': true,
  540. * },
  541. * },
  542. * 'core/edit-site': {
  543. * complementaryArea: 'edit-site/global-styles',
  544. * pinnedItems: {
  545. * 'plugin-2': true,
  546. * },
  547. * },
  548. * }
  549. * ```
  550. *
  551. * @param {Object} state The local storage state.
  552. */
  553. function moveInterfaceEnableItems(state) {
  554. var _state$preferencesSto, _sourceEnableItems$si, _sourceEnableItems$mu;
  555. const interfaceStoreName = 'core/interface';
  556. const preferencesStoreName = 'core/preferences';
  557. const sourceEnableItems = state?.[interfaceStoreName]?.enableItems;
  558. // There's nothing to migrate, exit early.
  559. if (!sourceEnableItems) {
  560. return state;
  561. }
  562. const allPreferences = (_state$preferencesSto = state?.[preferencesStoreName]?.preferences) !== null && _state$preferencesSto !== void 0 ? _state$preferencesSto : {};
  563. // First convert complementaryAreas into the right format.
  564. // Use the existing preferences as the accumulator so that the data is
  565. // merged.
  566. const sourceComplementaryAreas = (_sourceEnableItems$si = sourceEnableItems?.singleEnableItems?.complementaryArea) !== null && _sourceEnableItems$si !== void 0 ? _sourceEnableItems$si : {};
  567. const preferencesWithConvertedComplementaryAreas = Object.keys(sourceComplementaryAreas).reduce((accumulator, scope) => {
  568. const data = sourceComplementaryAreas[scope];
  569. // Don't overwrite any existing data in the preferences store.
  570. if (accumulator?.[scope]?.complementaryArea) {
  571. return accumulator;
  572. }
  573. return {
  574. ...accumulator,
  575. [scope]: {
  576. ...accumulator[scope],
  577. complementaryArea: data
  578. }
  579. };
  580. }, allPreferences);
  581. // Next feed the converted complementary areas back into a reducer that
  582. // converts the pinned items, resulting in the fully migrated data.
  583. const sourcePinnedItems = (_sourceEnableItems$mu = sourceEnableItems?.multipleEnableItems?.pinnedItems) !== null && _sourceEnableItems$mu !== void 0 ? _sourceEnableItems$mu : {};
  584. const allConvertedData = Object.keys(sourcePinnedItems).reduce((accumulator, scope) => {
  585. const data = sourcePinnedItems[scope];
  586. // Don't overwrite any existing data in the preferences store.
  587. if (accumulator?.[scope]?.pinnedItems) {
  588. return accumulator;
  589. }
  590. return {
  591. ...accumulator,
  592. [scope]: {
  593. ...accumulator[scope],
  594. pinnedItems: data
  595. }
  596. };
  597. }, preferencesWithConvertedComplementaryAreas);
  598. const otherInterfaceItems = state[interfaceStoreName];
  599. return {
  600. ...state,
  601. [preferencesStoreName]: {
  602. preferences: allConvertedData
  603. },
  604. [interfaceStoreName]: {
  605. ...otherInterfaceItems,
  606. enableItems: undefined
  607. }
  608. };
  609. }
  610. ;// CONCATENATED MODULE: ./node_modules/@wordpress/preferences-persistence/build-module/migrations/legacy-local-storage-data/convert-edit-post-panels.js
  611. /**
  612. * Convert the post editor's panels state from:
  613. * ```
  614. * {
  615. * panels: {
  616. * tags: {
  617. * enabled: true,
  618. * opened: true,
  619. * },
  620. * permalinks: {
  621. * enabled: false,
  622. * opened: false,
  623. * },
  624. * },
  625. * }
  626. * ```
  627. *
  628. * to a new, more concise data structure:
  629. * {
  630. * inactivePanels: [
  631. * 'permalinks',
  632. * ],
  633. * openPanels: [
  634. * 'tags',
  635. * ],
  636. * }
  637. *
  638. * @param {Object} preferences A preferences object.
  639. *
  640. * @return {Object} The converted data.
  641. */
  642. function convertEditPostPanels(preferences) {
  643. var _preferences$panels;
  644. const panels = (_preferences$panels = preferences?.panels) !== null && _preferences$panels !== void 0 ? _preferences$panels : {};
  645. return Object.keys(panels).reduce((convertedData, panelName) => {
  646. const panel = panels[panelName];
  647. if (panel?.enabled === false) {
  648. convertedData.inactivePanels.push(panelName);
  649. }
  650. if (panel?.opened === true) {
  651. convertedData.openPanels.push(panelName);
  652. }
  653. return convertedData;
  654. }, {
  655. inactivePanels: [],
  656. openPanels: []
  657. });
  658. }
  659. ;// CONCATENATED MODULE: ./node_modules/@wordpress/preferences-persistence/build-module/migrations/legacy-local-storage-data/index.js
  660. /**
  661. * Internal dependencies
  662. */
  663. /**
  664. * Gets the legacy local storage data for a given user.
  665. *
  666. * @param {string | number} userId The user id.
  667. *
  668. * @return {Object | null} The local storage data.
  669. */
  670. function getLegacyData(userId) {
  671. const key = `WP_DATA_USER_${userId}`;
  672. const unparsedData = window.localStorage.getItem(key);
  673. return JSON.parse(unparsedData);
  674. }
  675. /**
  676. * Converts data from the old `@wordpress/data` package format.
  677. *
  678. * @param {Object | null | undefined} data The legacy data in its original format.
  679. *
  680. * @return {Object | undefined} The converted data or `undefined` if there was
  681. * nothing to convert.
  682. */
  683. function convertLegacyData(data) {
  684. if (!data) {
  685. return;
  686. }
  687. // Move boolean feature preferences from each editor into the
  688. // preferences store data structure.
  689. data = moveFeaturePreferences(data, 'core/edit-widgets');
  690. data = moveFeaturePreferences(data, 'core/customize-widgets');
  691. data = moveFeaturePreferences(data, 'core/edit-post');
  692. data = moveFeaturePreferences(data, 'core/edit-site');
  693. // Move third party boolean feature preferences from the interface package
  694. // to the preferences store data structure.
  695. data = moveThirdPartyFeaturePreferencesToPreferences(data);
  696. // Move and convert the interface store's `enableItems` data into the
  697. // preferences data structure.
  698. data = moveInterfaceEnableItems(data);
  699. // Move individual ad-hoc preferences from various packages into the
  700. // preferences store data structure.
  701. data = moveIndividualPreferenceToPreferences(data, {
  702. from: 'core/edit-post',
  703. to: 'core/edit-post'
  704. }, 'hiddenBlockTypes');
  705. data = moveIndividualPreferenceToPreferences(data, {
  706. from: 'core/edit-post',
  707. to: 'core/edit-post'
  708. }, 'editorMode');
  709. data = moveIndividualPreferenceToPreferences(data, {
  710. from: 'core/edit-post',
  711. to: 'core/edit-post'
  712. }, 'preferredStyleVariations');
  713. data = moveIndividualPreferenceToPreferences(data, {
  714. from: 'core/edit-post',
  715. to: 'core/edit-post'
  716. }, 'panels', convertEditPostPanels);
  717. data = moveIndividualPreferenceToPreferences(data, {
  718. from: 'core/editor',
  719. to: 'core/edit-post'
  720. }, 'isPublishSidebarEnabled');
  721. data = moveIndividualPreferenceToPreferences(data, {
  722. from: 'core/edit-site',
  723. to: 'core/edit-site'
  724. }, 'editorMode');
  725. // The new system is only concerned with persisting
  726. // 'core/preferences' preferences reducer, so only return that.
  727. return data?.['core/preferences']?.preferences;
  728. }
  729. /**
  730. * Gets the legacy local storage data for the given user and returns the
  731. * data converted to the new format.
  732. *
  733. * @param {string | number} userId The user id.
  734. *
  735. * @return {Object | undefined} The converted data or undefined if no local
  736. * storage data could be found.
  737. */
  738. function convertLegacyLocalStorageData(userId) {
  739. const data = getLegacyData(userId);
  740. return convertLegacyData(data);
  741. }
  742. ;// CONCATENATED MODULE: ./node_modules/@wordpress/preferences-persistence/build-module/migrations/preferences-package-data/convert-complementary-areas.js
  743. function convertComplementaryAreas(state) {
  744. return Object.keys(state).reduce((stateAccumulator, scope) => {
  745. const scopeData = state[scope];
  746. // If a complementary area is truthy, convert it to the `isComplementaryAreaVisible` boolean.
  747. if (scopeData?.complementaryArea) {
  748. const updatedScopeData = {
  749. ...scopeData
  750. };
  751. delete updatedScopeData.complementaryArea;
  752. updatedScopeData.isComplementaryAreaVisible = true;
  753. stateAccumulator[scope] = updatedScopeData;
  754. return stateAccumulator;
  755. }
  756. return stateAccumulator;
  757. }, state);
  758. }
  759. ;// CONCATENATED MODULE: ./node_modules/@wordpress/preferences-persistence/build-module/migrations/preferences-package-data/index.js
  760. /**
  761. * Internal dependencies
  762. */
  763. function convertPreferencesPackageData(data) {
  764. return convertComplementaryAreas(data);
  765. }
  766. ;// CONCATENATED MODULE: ./node_modules/@wordpress/preferences-persistence/build-module/index.js
  767. /**
  768. * Internal dependencies
  769. */
  770. /**
  771. * Creates the persistence layer with preloaded data.
  772. *
  773. * It prioritizes any data from the server, but falls back first to localStorage
  774. * restore data, and then to any legacy data.
  775. *
  776. * This function is used internally by WordPress in an inline script, so
  777. * prefixed with `__unstable`.
  778. *
  779. * @param {Object} serverData Preferences data preloaded from the server.
  780. * @param {string} userId The user id.
  781. *
  782. * @return {Object} The persistence layer initialized with the preloaded data.
  783. */
  784. function __unstableCreatePersistenceLayer(serverData, userId) {
  785. const localStorageRestoreKey = `WP_PREFERENCES_USER_${userId}`;
  786. const localData = JSON.parse(window.localStorage.getItem(localStorageRestoreKey));
  787. // Date parse returns NaN for invalid input. Coerce anything invalid
  788. // into a conveniently comparable zero.
  789. const serverModified = Date.parse(serverData && serverData._modified) || 0;
  790. const localModified = Date.parse(localData && localData._modified) || 0;
  791. let preloadedData;
  792. if (serverData && serverModified >= localModified) {
  793. preloadedData = convertPreferencesPackageData(serverData);
  794. } else if (localData) {
  795. preloadedData = convertPreferencesPackageData(localData);
  796. } else {
  797. // Check if there is data in the legacy format from the old persistence system.
  798. preloadedData = convertLegacyLocalStorageData(userId);
  799. }
  800. return create({
  801. preloadedData,
  802. localStorageRestoreKey
  803. });
  804. }
  805. (window.wp = window.wp || {}).preferencesPersistence = __webpack_exports__;
  806. /******/ })()
  807. ;