@wordpress/data 6.4.1 → 6.6.1

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/CHANGELOG.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 6.6.0 (2022-04-08)
6
+
7
+ ## 6.5.0 (2022-03-23)
8
+
5
9
  ## 6.4.0 (2022-03-11)
6
10
 
7
11
  ## 6.3.0 (2022-02-23)
@@ -140,7 +140,7 @@ function useSelect(mapSelect, deps) {
140
140
  // and only subscribe to those stores later.
141
141
 
142
142
  const listeningStores = (0, _element.useRef)([]);
143
- const trapSelect = (0, _element.useCallback)(callback => registry.__experimentalMarkListeningStores(callback, listeningStores), [registry]); // Generate a "flag" for used in the effect dependency array.
143
+ const wrapSelect = (0, _element.useCallback)(callback => registry.__unstableMarkListeningStores(() => callback(registry.select, registry), listeningStores), [registry]); // Generate a "flag" for used in the effect dependency array.
144
144
  // It's different than just using `mapSelect` since deps could be undefined,
145
145
  // in that case, we would still want to memoize it.
146
146
 
@@ -154,7 +154,7 @@ function useSelect(mapSelect, deps) {
154
154
 
155
155
  if (hasReplacedMapSelect || lastMapSelectFailed) {
156
156
  try {
157
- mapOutput = trapSelect(() => _mapSelect(registry.select, registry));
157
+ mapOutput = wrapSelect(_mapSelect);
158
158
  } catch (error) {
159
159
  let errorMessage = `An error occurred while running 'mapSelect': ${error.message}`;
160
160
 
@@ -196,7 +196,7 @@ function useSelect(mapSelect, deps) {
196
196
  const onStoreChange = () => {
197
197
  if (isMountedAndNotUnsubscribing.current) {
198
198
  try {
199
- const newMapOutput = trapSelect(() => latestMapSelect.current(registry.select, registry));
199
+ const newMapOutput = wrapSelect(latestMapSelect.current);
200
200
 
201
201
  if ((0, _isShallowEqual.default)(latestMapOutput.current, newMapOutput)) {
202
202
  return;
@@ -209,15 +209,7 @@ function useSelect(mapSelect, deps) {
209
209
 
210
210
  forceRender();
211
211
  }
212
- }; // Catch any possible state changes during mount before the subscription
213
- // could be set.
214
-
215
-
216
- if (latestIsAsync.current) {
217
- renderQueue.add(queueContext, onStoreChange);
218
- } else {
219
- onStoreChange();
220
- }
212
+ };
221
213
 
222
214
  const onChange = () => {
223
215
  if (latestIsAsync.current) {
@@ -225,9 +217,12 @@ function useSelect(mapSelect, deps) {
225
217
  } else {
226
218
  onStoreChange();
227
219
  }
228
- };
220
+ }; // Catch any possible state changes during mount before the subscription
221
+ // could be set.
222
+
229
223
 
230
- const unsubscribers = listeningStores.current.map(storeName => registry.__experimentalSubscribeStore(storeName, onChange));
224
+ onChange();
225
+ const unsubscribers = listeningStores.current.map(storeName => registry.__unstableSubscribeStore(storeName, onChange));
231
226
  return () => {
232
227
  isMountedAndNotUnsubscribing.current = false; // The return value of the subscribe function could be undefined if the store is a custom generic store.
233
228
 
@@ -236,7 +231,7 @@ function useSelect(mapSelect, deps) {
236
231
  }; // If you're tempted to eliminate the spread dependencies below don't do it!
237
232
  // We're passing these in from the calling function and want to make sure we're
238
233
  // examining every individual value inside the `deps` array.
239
- }, [registry, trapSelect, hasMappingFunction, depsChangedFlag]);
234
+ }, [registry, wrapSelect, hasMappingFunction, depsChangedFlag]);
240
235
  return hasMappingFunction ? mapOutput : registry.select(mapSelect);
241
236
  }
242
237
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/data/src/components/use-select/index.js"],"names":["noop","renderQueue","useSelect","mapSelect","deps","hasMappingFunction","callbackMapper","_mapSelect","registry","isAsync","queueContext","queue","forceRender","s","latestMapSelect","latestIsAsync","latestMapOutput","latestMapOutputError","isMountedAndNotUnsubscribing","listeningStores","trapSelect","callback","__experimentalMarkListeningStores","depsChangedFlag","mapOutput","current","hasReplacedMapSelect","lastMapSelectFailed","select","error","errorMessage","message","stack","console","undefined","flush","onStoreChange","newMapOutput","add","onChange","unsubscribers","map","storeName","__experimentalSubscribeStore","forEach","unsubscribe"],"mappings":";;;;;;;;;AAGA;;AAKA;;AACA;;AACA;;AACA;;AAKA;;AACA;;AAjBA;AACA;AACA;;AAGA;AACA;AACA;;AAMA;AACA;AACA;AAIA,MAAMA,IAAI,GAAG,MAAM,CAAE,CAArB;;AACA,MAAMC,WAAW,GAAG,iCAApB;AAEA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACe,SAASC,SAAT,CAAoBC,SAApB,EAA+BC,IAA/B,EAAsC;AACpD,QAAMC,kBAAkB,GAAG,eAAe,OAAOF,SAAjD,CADoD,CAGpD;AACA;AACA;;AACA,MAAK,CAAEE,kBAAP,EAA4B;AAC3BD,IAAAA,IAAI,GAAG,EAAP;AACA,GARmD,CAUpD;AACA;AACA;AACA;AACA;;;AACA,QAAME,cAAc,GAAG,0BACtBD,kBAAkB,GAAGF,SAAH,GAAeH,IADX,EAEtBI,IAFsB,CAAvB;;AAIA,QAAMG,UAAU,GAAGF,kBAAkB,GAAGC,cAAH,GAAoB,IAAzD;;AAEA,QAAME,QAAQ,GAAG,2BAAjB;AACA,QAAMC,OAAO,GAAG,4BAAhB,CAtBoD,CAuBpD;AACA;AACA;;AACA,QAAMC,YAAY,GAAG,4BAAY,OAAQ;AAAEC,IAAAA,KAAK,EAAE;AAAT,GAAR,CAAZ,EAAuC,CAAEH,QAAF,CAAvC,CAArB;AACA,QAAM,GAAII,WAAJ,IAAoB,yBAAcC,CAAF,IAASA,CAAC,GAAG,CAAzB,EAA4B,CAA5B,CAA1B;AAEA,QAAMC,eAAe,GAAG,sBAAxB;AACA,QAAMC,aA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A6B;AAC5BxB,QAAAA,WAAW,CAACqC,GAAZ,CAAiB5B,YAAjB,EAA+B0B,aAA/B;AACA,OAFD,MAEO;AACNA,QAAAA,aAAa;AACb;AACD,KAND;;AAQA,UAAMI,aAAa,GAAGrB,eAAe,CAACM,OAAhB,CAAwBgB,GAAxB,CAA+BC,SAAF,IAClDlC,QAAQ,CAACmC,4BAAT,CAAuCD,SAAvC,EAAkDH,QAAlD,CADqB,CAAtB;AAIA,WAAO,MAAM;AACZrB,MAAAA,4BAA4B,CAACO,OAA7B,GAAuC,KAAvC,CADY,CAEZ;;AACAe,MAAAA,aAAa,CAACI,OAAd,CAAyBC,WAAF,IAAmBA,WAAnB,aAAmBA,WAAnB,uBAAmBA,WAAW,EAArD;AACA5C,MAAAA,WAAW,CAACkC,KAAZ,CAAmBzB,YAAnB;AACA,KALD,CA7CgC,CAmDhC;AACA;AACA;AACA,GAtDD,EAsDG,CAAEF,QAAF,EAAYY,UAAZ,EAAwBf,kBAAxB,EAA4CkB,eAA5C,CAtDH;AAwDA,SAAOlB,kBAAkB,GAAGmB,SAAH,GAAehB,QAAQ,CAACoB,MAAT,CAAiBzB,SAAjB,CAAxC;AACA","sourcesContent":["/**\n * External dependencies\n */\nimport { useMemoOne } from 'use-memo-one';\n\n/**\n * WordPress dependencies\n */\nimport { createQueue } from '@wordpress/priority-queue';\nimport { useRef, useCallback, useMemo, useReducer } from '@wordpress/element';\nimport isShallowEqual from '@wordpress/is-shallow-equal';\nimport { useIsomorphicLayoutEffect } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport useRegistry from '../registry-provider/use-registry';\nimport useAsyncMode from '../async-mode-provider/use-async-mode';\n\nconst noop = () => {};\nconst renderQueue = createQueue();\n\n/** @typedef {import('../../types').StoreDescriptor} StoreDescriptor */\n\n/**\n * Custom react hook for retrieving props from registered selectors.\n *\n * In general, this custom React hook follows the\n * [rules of hooks](https://reactjs.org/docs/hooks-rules.html).\n *\n * @param {Function|StoreDescriptor|string} mapSelect Function called on every state change. The\n * returned value is exposed to the component\n * implementing this hook. The function receives\n * the `registry.select` method on the first\n * argument and the `registry` on the second\n * argument.\n * When a store key is passed, all selectors for\n * the store will be returned. This is only meant\n * for usage of these selectors in event\n * callbacks, not for data needed to create the\n * element tree.\n * @param {Array} deps If provided, this memoizes the mapSelect so the\n * same `mapSelect` is invoked on every state\n * change unless the dependencies change.\n *\n * @example\n * ```js\n * import { useSelect } from '@wordpress/data';\n *\n * function HammerPriceDisplay( { currency } ) {\n * const price = useSelect( ( select ) => {\n * return select( 'my-shop' ).getPrice( 'hammer', currency )\n * }, [ currency ] );\n * return new Intl.NumberFormat( 'en-US', {\n * style: 'currency',\n * currency,\n * } ).format( price );\n * }\n *\n * // Rendered in the application:\n * // <HammerPriceDisplay currency=\"USD\" />\n * ```\n *\n * In the above example, when `HammerPriceDisplay` is rendered into an\n * application, the price will be retrieved from the store state using the\n * `mapSelect` callback on `useSelect`. If the currency prop changes then\n * any price in the state for that currency is retrieved. If the currency prop\n * doesn't change and other props are passed in that do change, the price will\n * not change because the dependency is just the currency.\n *\n * When data is only used in an event callback, the data should not be retrieved\n * on render, so it may be useful to get the selectors function instead.\n *\n * **Don't use `useSelect` this way when calling the selectors in the render\n * function because your component won't re-render on a data change.**\n *\n * ```js\n * import { useSelect } from '@wordpress/data';\n *\n * function Paste( { children } ) {\n * const { getSettings } = useSelect( 'my-shop' );\n * function onPaste() {\n * // Do something with the settings.\n * const settings = getSettings();\n * }\n * return <div onPaste={ onPaste }>{ children }</div>;\n * }\n * ```\n *\n * @return {Function} A custom react hook.\n */\nexport default function useSelect( mapSelect, deps ) {\n\tconst hasMappingFunction = 'function' === typeof mapSelect;\n\n\t// If we're recalling a store by its name or by\n\t// its descriptor then we won't be caching the\n\t// calls to `mapSelect` because we won't be calling it.\n\tif ( ! hasMappingFunction ) {\n\t\tdeps = [];\n\t}\n\n\t// Because of the \"rule of hooks\" we have to call `useCallback`\n\t// on every invocation whether or not we have a real function\n\t// for `mapSelect`. we'll create this intermediate variable to\n\t// fulfill that need and then reference it with our \"real\"\n\t// `_mapSelect` if we can.\n\tconst callbackMapper = useCallback(\n\t\thasMappingFunction ? mapSelect : noop,\n\t\tdeps\n\t);\n\tconst _mapSelect = hasMappingFunction ? callbackMapper : null;\n\n\tconst registry = useRegistry();\n\tconst isAsync = useAsyncMode();\n\t// React can sometimes clear the `useMemo` cache.\n\t// We use the cache-stable `useMemoOne` to avoid\n\t// losing queues.\n\tconst queueContext = useMemoOne( () => ( { queue: true } ), [ registry ] );\n\tconst [ , forceRender ] = useReducer( ( s ) => s + 1, 0 );\n\n\tconst latestMapSelect = useRef();\n\tconst latestIsAsync = useRef( isAsync );\n\tconst latestMapOutput = useRef();\n\tconst latestMapOutputError = useRef();\n\tconst isMountedAndNotUnsubscribing = useRef();\n\n\t// Keep track of the stores being selected in the _mapSelect function,\n\t// and only subscribe to those stores later.\n\tconst listeningStores = useRef( [] );\n\tconst trapSelect = useCallback(\n\t\t( callback ) =>\n\t\t\tregistry.__experimentalMarkListeningStores(\n\t\t\t\tcallback,\n\t\t\t\tlisteningStores\n\t\t\t),\n\t\t[ registry ]\n\t);\n\n\t// Generate a \"flag\" for used in the effect dependency array.\n\t// It's different than just using `mapSelect` since deps could be undefined,\n\t// in that case, we would still want to memoize it.\n\tconst depsChangedFlag = useMemo( () => ( {} ), deps || [] );\n\n\tlet mapOutput;\n\n\tif ( _mapSelect ) {\n\t\tmapOutput = latestMapOutput.current;\n\t\tconst hasReplacedMapSelect = latestMapSelect.current !== _mapSelect;\n\t\tconst lastMapSelectFailed = !! latestMapOutputError.current;\n\n\t\tif ( hasReplacedMapSelect || lastMapSelectFailed ) {\n\t\t\ttry {\n\t\t\t\tmapOutput = trapSelect( () =>\n\t\t\t\t\t_mapSelect( registry.select, registry )\n\t\t\t\t);\n\t\t\t} catch ( error ) {\n\t\t\t\tlet errorMessage = `An error occurred while running 'mapSelect': ${ error.message }`;\n\n\t\t\t\tif ( latestMapOutputError.current ) {\n\t\t\t\t\terrorMessage += `\\nThe error may be correlated with this previous error:\\n`;\n\t\t\t\t\terrorMessage += `${ latestMapOutputError.current.stack }\\n\\n`;\n\t\t\t\t\terrorMessage += 'Original stack trace:';\n\t\t\t\t}\n\n\t\t\t\t// eslint-disable-next-line no-console\n\t\t\t\tconsole.error( errorMessage );\n\t\t\t}\n\t\t}\n\t}\n\n\tuseIsomorphicLayoutEffect( () => {\n\t\tif ( ! hasMappingFunction ) {\n\t\t\treturn;\n\t\t}\n\n\t\tlatestMapSelect.current = _mapSelect;\n\t\tlatestMapOutput.current = mapOutput;\n\t\tlatestMapOutputError.current = undefined;\n\t\tisMountedAndNotUnsubscribing.current = true;\n\n\t\t// This has to run after the other ref updates\n\t\t// to avoid using stale values in the flushed\n\t\t// callbacks or potentially overwriting a\n\t\t// changed `latestMapOutput.current`.\n\t\tif ( latestIsAsync.current !== isAsync ) {\n\t\t\tlatestIsAsync.current = isAsync;\n\t\t\trenderQueue.flush( queueContext );\n\t\t}\n\t} );\n\n\tuseIsomorphicLayoutEffect( () => {\n\t\tif ( ! hasMappingFunction ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst onStoreChange = () => {\n\t\t\tif ( isMountedAndNotUnsubscribing.current ) {\n\t\t\t\ttry {\n\t\t\t\t\tconst newMapOutput = trapSelect( () =>\n\t\t\t\t\t\tlatestMapSelect.current( registry.select, registry )\n\t\t\t\t\t);\n\n\t\t\t\t\tif (\n\t\t\t\t\t\tisShallowEqual( latestMapOutput.current, newMapOutput )\n\t\t\t\t\t) {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tlatestMapOutput.current = newMapOutput;\n\t\t\t\t} catch ( error ) {\n\t\t\t\t\tlatestMapOutputError.current = error;\n\t\t\t\t}\n\t\t\t\tforceRender();\n\t\t\t}\n\t\t};\n\n\t\t// Catch any possible state changes during mount before the subscription\n\t\t// could be set.\n\t\tif ( latestIsAsync.current ) {\n\t\t\trenderQueue.add( queueContext, onStoreChange );\n\t\t} else {\n\t\t\tonStoreChange();\n\t\t}\n\n\t\tconst onChange = () => {\n\t\t\tif ( latestIsAsync.current ) {\n\t\t\t\trenderQueue.add( queueContext, onStoreChange );\n\t\t\t} else {\n\t\t\t\tonStoreChange();\n\t\t\t}\n\t\t};\n\n\t\tconst unsubscribers = listeningStores.current.map( ( storeName ) =>\n\t\t\tregistry.__experimentalSubscribeStore( storeName, onChange )\n\t\t);\n\n\t\treturn () => {\n\t\t\tisMountedAndNotUnsubscribing.current = false;\n\t\t\t// The return value of the subscribe function could be undefined if the store is a custom generic store.\n\t\t\tunsubscribers.forEach( ( unsubscribe ) => unsubscribe?.() );\n\t\t\trenderQueue.flush( queueContext );\n\t\t};\n\t\t// If you're tempted to eliminate the spread dependencies below don't do it!\n\t\t// We're passing these in from the calling function and want to make sure we're\n\t\t// examining every individual value inside the `deps` array.\n\t}, [ registry, trapSelect, hasMappingFunction, depsChangedFlag ] );\n\n\treturn hasMappingFunction ? mapOutput : registry.select( mapSelect );\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/data/src/components/use-select/index.js"],"names":["noop","renderQueue","useSelect","mapSelect","deps","hasMappingFunction","callbackMapper","_mapSelect","registry","isAsync","queueContext","queue","forceRender","s","latestMapSelect","latestIsAsync","latestMapOutput","latestMapOutputError","isMountedAndNotUnsubscribing","listeningStores","wrapSelect","callback","__unstableMarkListeningStores","select","depsChangedFlag","mapOutput","current","hasReplacedMapSelect","lastMapSelectFailed","error","errorMessage","message","stack","console","undefined","flush","onStoreChange","newMapOutput","onChange","add","unsubscribers","map","storeName","__unstableSubscribeStore","forEach","unsubscribe"],"mappings":";;;;;;;;;AAGA;;AAKA;;AACA;;AACA;;AACA;;AAKA;;AACA;;AAjBA;AACA;AACA;;AAGA;AACA;AACA;;AAMA;AACA;AACA;AAIA,MAAMA,IAAI,GAAG,MAAM,CAAE,CAArB;;AACA,MAAMC,WAAW,GAAG,iCAApB;AAEA;;AAEA;AACA;AACA;AACA;AACA;A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,CAAyBC,WAAF,IAAmBA,WAAnB,aAAmBA,WAAnB,uBAAmBA,WAAW,EAArD;AACA5C,MAAAA,WAAW,CAACkC,KAAZ,CAAmBzB,YAAnB;AACA,KALD,CAvCgC,CA6ChC;AACA;AACA;AACA,GAhDD,EAgDG,CAAEF,QAAF,EAAYY,UAAZ,EAAwBf,kBAAxB,EAA4CmB,eAA5C,CAhDH;AAkDA,SAAOnB,kBAAkB,GAAGoB,SAAH,GAAejB,QAAQ,CAACe,MAAT,CAAiBpB,SAAjB,CAAxC;AACA","sourcesContent":["/**\n * External dependencies\n */\nimport { useMemoOne } from 'use-memo-one';\n\n/**\n * WordPress dependencies\n */\nimport { createQueue } from '@wordpress/priority-queue';\nimport { useRef, useCallback, useMemo, useReducer } from '@wordpress/element';\nimport isShallowEqual from '@wordpress/is-shallow-equal';\nimport { useIsomorphicLayoutEffect } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport useRegistry from '../registry-provider/use-registry';\nimport useAsyncMode from '../async-mode-provider/use-async-mode';\n\nconst noop = () => {};\nconst renderQueue = createQueue();\n\n/** @typedef {import('../../types').StoreDescriptor} StoreDescriptor */\n\n/**\n * Custom react hook for retrieving props from registered selectors.\n *\n * In general, this custom React hook follows the\n * [rules of hooks](https://reactjs.org/docs/hooks-rules.html).\n *\n * @param {Function|StoreDescriptor|string} mapSelect Function called on every state change. The\n * returned value is exposed to the component\n * implementing this hook. The function receives\n * the `registry.select` method on the first\n * argument and the `registry` on the second\n * argument.\n * When a store key is passed, all selectors for\n * the store will be returned. This is only meant\n * for usage of these selectors in event\n * callbacks, not for data needed to create the\n * element tree.\n * @param {Array} deps If provided, this memoizes the mapSelect so the\n * same `mapSelect` is invoked on every state\n * change unless the dependencies change.\n *\n * @example\n * ```js\n * import { useSelect } from '@wordpress/data';\n *\n * function HammerPriceDisplay( { currency } ) {\n * const price = useSelect( ( select ) => {\n * return select( 'my-shop' ).getPrice( 'hammer', currency )\n * }, [ currency ] );\n * return new Intl.NumberFormat( 'en-US', {\n * style: 'currency',\n * currency,\n * } ).format( price );\n * }\n *\n * // Rendered in the application:\n * // <HammerPriceDisplay currency=\"USD\" />\n * ```\n *\n * In the above example, when `HammerPriceDisplay` is rendered into an\n * application, the price will be retrieved from the store state using the\n * `mapSelect` callback on `useSelect`. If the currency prop changes then\n * any price in the state for that currency is retrieved. If the currency prop\n * doesn't change and other props are passed in that do change, the price will\n * not change because the dependency is just the currency.\n *\n * When data is only used in an event callback, the data should not be retrieved\n * on render, so it may be useful to get the selectors function instead.\n *\n * **Don't use `useSelect` this way when calling the selectors in the render\n * function because your component won't re-render on a data change.**\n *\n * ```js\n * import { useSelect } from '@wordpress/data';\n *\n * function Paste( { children } ) {\n * const { getSettings } = useSelect( 'my-shop' );\n * function onPaste() {\n * // Do something with the settings.\n * const settings = getSettings();\n * }\n * return <div onPaste={ onPaste }>{ children }</div>;\n * }\n * ```\n *\n * @return {Function} A custom react hook.\n */\nexport default function useSelect( mapSelect, deps ) {\n\tconst hasMappingFunction = 'function' === typeof mapSelect;\n\n\t// If we're recalling a store by its name or by\n\t// its descriptor then we won't be caching the\n\t// calls to `mapSelect` because we won't be calling it.\n\tif ( ! hasMappingFunction ) {\n\t\tdeps = [];\n\t}\n\n\t// Because of the \"rule of hooks\" we have to call `useCallback`\n\t// on every invocation whether or not we have a real function\n\t// for `mapSelect`. we'll create this intermediate variable to\n\t// fulfill that need and then reference it with our \"real\"\n\t// `_mapSelect` if we can.\n\tconst callbackMapper = useCallback(\n\t\thasMappingFunction ? mapSelect : noop,\n\t\tdeps\n\t);\n\tconst _mapSelect = hasMappingFunction ? callbackMapper : null;\n\n\tconst registry = useRegistry();\n\tconst isAsync = useAsyncMode();\n\t// React can sometimes clear the `useMemo` cache.\n\t// We use the cache-stable `useMemoOne` to avoid\n\t// losing queues.\n\tconst queueContext = useMemoOne( () => ( { queue: true } ), [ registry ] );\n\tconst [ , forceRender ] = useReducer( ( s ) => s + 1, 0 );\n\n\tconst latestMapSelect = useRef();\n\tconst latestIsAsync = useRef( isAsync );\n\tconst latestMapOutput = useRef();\n\tconst latestMapOutputError = useRef();\n\tconst isMountedAndNotUnsubscribing = useRef();\n\n\t// Keep track of the stores being selected in the _mapSelect function,\n\t// and only subscribe to those stores later.\n\tconst listeningStores = useRef( [] );\n\tconst wrapSelect = useCallback(\n\t\t( callback ) =>\n\t\t\tregistry.__unstableMarkListeningStores(\n\t\t\t\t() => callback( registry.select, registry ),\n\t\t\t\tlisteningStores\n\t\t\t),\n\t\t[ registry ]\n\t);\n\n\t// Generate a \"flag\" for used in the effect dependency array.\n\t// It's different than just using `mapSelect` since deps could be undefined,\n\t// in that case, we would still want to memoize it.\n\tconst depsChangedFlag = useMemo( () => ( {} ), deps || [] );\n\n\tlet mapOutput;\n\n\tif ( _mapSelect ) {\n\t\tmapOutput = latestMapOutput.current;\n\t\tconst hasReplacedMapSelect = latestMapSelect.current !== _mapSelect;\n\t\tconst lastMapSelectFailed = !! latestMapOutputError.current;\n\n\t\tif ( hasReplacedMapSelect || lastMapSelectFailed ) {\n\t\t\ttry {\n\t\t\t\tmapOutput = wrapSelect( _mapSelect );\n\t\t\t} catch ( error ) {\n\t\t\t\tlet errorMessage = `An error occurred while running 'mapSelect': ${ error.message }`;\n\n\t\t\t\tif ( latestMapOutputError.current ) {\n\t\t\t\t\terrorMessage += `\\nThe error may be correlated with this previous error:\\n`;\n\t\t\t\t\terrorMessage += `${ latestMapOutputError.current.stack }\\n\\n`;\n\t\t\t\t\terrorMessage += 'Original stack trace:';\n\t\t\t\t}\n\n\t\t\t\t// eslint-disable-next-line no-console\n\t\t\t\tconsole.error( errorMessage );\n\t\t\t}\n\t\t}\n\t}\n\n\tuseIsomorphicLayoutEffect( () => {\n\t\tif ( ! hasMappingFunction ) {\n\t\t\treturn;\n\t\t}\n\n\t\tlatestMapSelect.current = _mapSelect;\n\t\tlatestMapOutput.current = mapOutput;\n\t\tlatestMapOutputError.current = undefined;\n\t\tisMountedAndNotUnsubscribing.current = true;\n\n\t\t// This has to run after the other ref updates\n\t\t// to avoid using stale values in the flushed\n\t\t// callbacks or potentially overwriting a\n\t\t// changed `latestMapOutput.current`.\n\t\tif ( latestIsAsync.current !== isAsync ) {\n\t\t\tlatestIsAsync.current = isAsync;\n\t\t\trenderQueue.flush( queueContext );\n\t\t}\n\t} );\n\n\tuseIsomorphicLayoutEffect( () => {\n\t\tif ( ! hasMappingFunction ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst onStoreChange = () => {\n\t\t\tif ( isMountedAndNotUnsubscribing.current ) {\n\t\t\t\ttry {\n\t\t\t\t\tconst newMapOutput = wrapSelect( latestMapSelect.current );\n\n\t\t\t\t\tif (\n\t\t\t\t\t\tisShallowEqual( latestMapOutput.current, newMapOutput )\n\t\t\t\t\t) {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tlatestMapOutput.current = newMapOutput;\n\t\t\t\t} catch ( error ) {\n\t\t\t\t\tlatestMapOutputError.current = error;\n\t\t\t\t}\n\t\t\t\tforceRender();\n\t\t\t}\n\t\t};\n\n\t\tconst onChange = () => {\n\t\t\tif ( latestIsAsync.current ) {\n\t\t\t\trenderQueue.add( queueContext, onStoreChange );\n\t\t\t} else {\n\t\t\t\tonStoreChange();\n\t\t\t}\n\t\t};\n\n\t\t// Catch any possible state changes during mount before the subscription\n\t\t// could be set.\n\t\tonChange();\n\n\t\tconst unsubscribers = listeningStores.current.map( ( storeName ) =>\n\t\t\tregistry.__unstableSubscribeStore( storeName, onChange )\n\t\t);\n\n\t\treturn () => {\n\t\t\tisMountedAndNotUnsubscribing.current = false;\n\t\t\t// The return value of the subscribe function could be undefined if the store is a custom generic store.\n\t\t\tunsubscribers.forEach( ( unsubscribe ) => unsubscribe?.() );\n\t\t\trenderQueue.flush( queueContext );\n\t\t};\n\t\t// If you're tempted to eliminate the spread dependencies below don't do it!\n\t\t// We're passing these in from the calling function and want to make sure we're\n\t\t// examining every individual value inside the `deps` array.\n\t}, [ registry, wrapSelect, hasMappingFunction, depsChangedFlag ] );\n\n\treturn hasMappingFunction ? mapOutput : registry.select( mapSelect );\n}\n"]}
@@ -5,11 +5,13 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
+ exports.convertEditPostPanels = convertEditPostPanels;
8
9
  exports.createPersistenceInterface = createPersistenceInterface;
9
10
  exports.default = void 0;
10
- exports.migrateFeaturePreferencesToInterfaceStore = migrateFeaturePreferencesToInterfaceStore;
11
11
  exports.migrateFeaturePreferencesToPreferencesStore = migrateFeaturePreferencesToPreferencesStore;
12
12
  exports.migrateIndividualPreferenceToPreferencesStore = migrateIndividualPreferenceToPreferencesStore;
13
+ exports.migrateInterfaceEnableItemsToPreferencesStore = migrateInterfaceEnableItemsToPreferencesStore;
14
+ exports.migrateThirdPartyFeaturePreferencesToPreferencesStore = migrateThirdPartyFeaturePreferencesToPreferencesStore;
13
15
  exports.withLazySameState = void 0;
14
16
 
15
17
  var _lodash = require("lodash");
@@ -257,14 +259,14 @@ function migrateFeaturePreferencesToPreferencesStore(persistence, sourceStoreNam
257
259
  if (featuresToMigrate) {
258
260
  var _state$preferencesSto;
259
261
 
260
- const targetFeatures = (_state$preferencesSto = state[preferencesStoreName]) === null || _state$preferencesSto === void 0 ? void 0 : _state$preferencesSto.preferences; // Avoid migrating features again if they've previously been migrated.
262
+ const existingPreferences = (_state$preferencesSto = state[preferencesStoreName]) === null || _state$preferencesSto === void 0 ? void 0 : _state$preferencesSto.preferences; // Avoid migrating features again if they've previously been migrated.
261
263
 
262
- if (!(targetFeatures !== null && targetFeatures !== void 0 && targetFeatures[sourceStoreName])) {
264
+ if (!(existingPreferences !== null && existingPreferences !== void 0 && existingPreferences[sourceStoreName])) {
263
265
  // Set the feature values in the interface store, the features
264
266
  // object is keyed by 'scope', which matches the store name for
265
267
  // the source.
266
268
  persistence.set(preferencesStoreName, {
267
- preferences: { ...targetFeatures,
269
+ preferences: { ...existingPreferences,
268
270
  [sourceStoreName]: featuresToMigrate
269
271
  }
270
272
  }); // Remove migrated feature preferences from `interface`.
@@ -272,10 +274,11 @@ function migrateFeaturePreferencesToPreferencesStore(persistence, sourceStoreNam
272
274
  if (interfaceFeatures) {
273
275
  var _state$interfaceStore4, _state$interfaceStore5;
274
276
 
275
- const otherInterfaceFeatures = (_state$interfaceStore4 = state[interfaceStoreName]) === null || _state$interfaceStore4 === void 0 ? void 0 : (_state$interfaceStore5 = _state$interfaceStore4.preferences) === null || _state$interfaceStore5 === void 0 ? void 0 : _state$interfaceStore5.features;
276
- persistence.set(interfaceStoreName, {
277
+ const otherInterfaceState = state[interfaceStoreName];
278
+ const otherInterfaceScopes = (_state$interfaceStore4 = state[interfaceStoreName]) === null || _state$interfaceStore4 === void 0 ? void 0 : (_state$interfaceStore5 = _state$interfaceStore4.preferences) === null || _state$interfaceStore5 === void 0 ? void 0 : _state$interfaceStore5.features;
279
+ persistence.set(interfaceStoreName, { ...otherInterfaceState,
277
280
  preferences: {
278
- features: { ...otherInterfaceFeatures,
281
+ features: { ...otherInterfaceScopes,
279
282
  [sourceStoreName]: undefined
280
283
  }
281
284
  }
@@ -286,8 +289,9 @@ function migrateFeaturePreferencesToPreferencesStore(persistence, sourceStoreNam
286
289
  if (sourceFeatures) {
287
290
  var _state$sourceStoreNam3;
288
291
 
292
+ const otherSourceState = state[sourceStoreName];
289
293
  const sourcePreferences = (_state$sourceStoreNam3 = state[sourceStoreName]) === null || _state$sourceStoreNam3 === void 0 ? void 0 : _state$sourceStoreNam3.preferences;
290
- persistence.set(sourceStoreName, {
294
+ persistence.set(sourceStoreName, { ...otherSourceState,
291
295
  preferences: { ...sourcePreferences,
292
296
  features: undefined
293
297
  }
@@ -296,94 +300,305 @@ function migrateFeaturePreferencesToPreferencesStore(persistence, sourceStoreNam
296
300
  }
297
301
  }
298
302
  }
303
+ /**
304
+ * Migrates an individual item inside the `preferences` object for a store.
305
+ *
306
+ * @param {Object} persistence The persistence interface.
307
+ * @param {Object} migrate An options object that contains details of the migration.
308
+ * @param {string} migrate.from The name of the store to migrate from.
309
+ * @param {string} migrate.scope The scope in the preferences store to migrate to.
310
+ * @param {string} key The key in the preferences object to migrate.
311
+ * @param {?Function} convert A function that converts preferences from one format to another.
312
+ */
299
313
 
300
- function migrateIndividualPreferenceToPreferencesStore(persistence, sourceStoreName, key) {
314
+
315
+ function migrateIndividualPreferenceToPreferencesStore(persistence, _ref, key) {
301
316
  var _state$sourceStoreNam4, _state$sourceStoreNam5, _state$preferencesSto2, _state$preferencesSto3, _state$preferencesSto4, _state$preferencesSto5, _state$preferencesSto6, _state$preferencesSto7, _state$sourceStoreNam6;
302
317
 
318
+ let {
319
+ from: sourceStoreName,
320
+ scope
321
+ } = _ref;
322
+ let convert = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : _lodash.identity;
303
323
  const preferencesStoreName = 'core/preferences';
304
324
  const state = persistence.get();
305
325
  const sourcePreference = (_state$sourceStoreNam4 = state[sourceStoreName]) === null || _state$sourceStoreNam4 === void 0 ? void 0 : (_state$sourceStoreNam5 = _state$sourceStoreNam4.preferences) === null || _state$sourceStoreNam5 === void 0 ? void 0 : _state$sourceStoreNam5[key]; // There's nothing to migrate, exit early.
306
326
 
307
- if (!sourcePreference) {
327
+ if (sourcePreference === undefined) {
308
328
  return;
309
329
  }
310
330
 
311
- const targetPreference = (_state$preferencesSto2 = state[preferencesStoreName]) === null || _state$preferencesSto2 === void 0 ? void 0 : (_state$preferencesSto3 = _state$preferencesSto2.preferences) === null || _state$preferencesSto3 === void 0 ? void 0 : (_state$preferencesSto4 = _state$preferencesSto3[sourceStoreName]) === null || _state$preferencesSto4 === void 0 ? void 0 : _state$preferencesSto4[key]; // There's existing data at the target, so don't overwrite it, exit early.
331
+ const targetPreference = (_state$preferencesSto2 = state[preferencesStoreName]) === null || _state$preferencesSto2 === void 0 ? void 0 : (_state$preferencesSto3 = _state$preferencesSto2.preferences) === null || _state$preferencesSto3 === void 0 ? void 0 : (_state$preferencesSto4 = _state$preferencesSto3[scope]) === null || _state$preferencesSto4 === void 0 ? void 0 : _state$preferencesSto4[key]; // There's existing data at the target, so don't overwrite it, exit early.
312
332
 
313
333
  if (targetPreference) {
314
334
  return;
315
335
  }
316
336
 
317
- const allPreferences = (_state$preferencesSto5 = state[preferencesStoreName]) === null || _state$preferencesSto5 === void 0 ? void 0 : _state$preferencesSto5.preferences;
318
- const targetPreferences = (_state$preferencesSto6 = state[preferencesStoreName]) === null || _state$preferencesSto6 === void 0 ? void 0 : (_state$preferencesSto7 = _state$preferencesSto6.preferences) === null || _state$preferencesSto7 === void 0 ? void 0 : _state$preferencesSto7[sourceStoreName];
337
+ const otherScopes = (_state$preferencesSto5 = state[preferencesStoreName]) === null || _state$preferencesSto5 === void 0 ? void 0 : _state$preferencesSto5.preferences;
338
+ const otherPreferences = (_state$preferencesSto6 = state[preferencesStoreName]) === null || _state$preferencesSto6 === void 0 ? void 0 : (_state$preferencesSto7 = _state$preferencesSto6.preferences) === null || _state$preferencesSto7 === void 0 ? void 0 : _state$preferencesSto7[scope]; // Pass an object with the key and value as this allows the convert
339
+ // function to convert to a data structure that has different keys.
340
+
341
+ const convertedPreferences = convert({
342
+ [key]: sourcePreference
343
+ });
319
344
  persistence.set(preferencesStoreName, {
320
- preferences: { ...allPreferences,
321
- [sourceStoreName]: { ...targetPreferences,
322
- [key]: sourcePreference
345
+ preferences: { ...otherScopes,
346
+ [scope]: { ...otherPreferences,
347
+ ...convertedPreferences
323
348
  }
324
349
  }
325
350
  }); // Remove migrated feature preferences from the source.
326
351
 
352
+ const otherSourceState = state[sourceStoreName];
327
353
  const allSourcePreferences = (_state$sourceStoreNam6 = state[sourceStoreName]) === null || _state$sourceStoreNam6 === void 0 ? void 0 : _state$sourceStoreNam6.preferences;
328
- persistence.set(sourceStoreName, {
354
+ persistence.set(sourceStoreName, { ...otherSourceState,
329
355
  preferences: { ...allSourcePreferences,
330
356
  [key]: undefined
331
357
  }
332
358
  });
333
359
  }
334
360
  /**
335
- * Move the 'features' object in local storage from the sourceStoreName to the
336
- * interface store.
361
+ * Convert from:
362
+ * ```
363
+ * {
364
+ * panels: {
365
+ * tags: {
366
+ * enabled: true,
367
+ * opened: true,
368
+ * },
369
+ * permalinks: {
370
+ * enabled: false,
371
+ * opened: false,
372
+ * },
373
+ * },
374
+ * }
375
+ * ```
337
376
  *
338
- * @param {Object} persistence The persistence interface.
339
- * @param {string} sourceStoreName The name of the store that has persisted
340
- * preferences to migrate to the interface
341
- * package.
377
+ * to:
378
+ * {
379
+ * inactivePanels: [
380
+ * 'permalinks',
381
+ * ],
382
+ * openPanels: [
383
+ * 'tags',
384
+ * ],
385
+ * }
386
+ *
387
+ * @param {Object} preferences A preferences object.
388
+ *
389
+ * @return {Object} The converted data.
342
390
  */
343
391
 
344
392
 
345
- function migrateFeaturePreferencesToInterfaceStore(persistence, sourceStoreName) {
346
- var _state$sourceStoreNam7;
393
+ function convertEditPostPanels(preferences) {
394
+ var _preferences$panels;
395
+
396
+ const panels = (_preferences$panels = preferences === null || preferences === void 0 ? void 0 : preferences.panels) !== null && _preferences$panels !== void 0 ? _preferences$panels : {};
397
+ return Object.keys(panels).reduce((convertedData, panelName) => {
398
+ const panel = panels[panelName];
399
+
400
+ if ((panel === null || panel === void 0 ? void 0 : panel.enabled) === false) {
401
+ convertedData.inactivePanels.push(panelName);
402
+ }
403
+
404
+ if ((panel === null || panel === void 0 ? void 0 : panel.opened) === true) {
405
+ convertedData.openPanels.push(panelName);
406
+ }
407
+
408
+ return convertedData;
409
+ }, {
410
+ inactivePanels: [],
411
+ openPanels: []
412
+ });
413
+ }
414
+
415
+ function migrateThirdPartyFeaturePreferencesToPreferencesStore(persistence) {
416
+ var _state$interfaceStore6, _state$interfaceStore7;
347
417
 
348
418
  const interfaceStoreName = 'core/interface';
349
- const state = persistence.get();
350
- const sourcePreferences = (_state$sourceStoreNam7 = state[sourceStoreName]) === null || _state$sourceStoreNam7 === void 0 ? void 0 : _state$sourceStoreNam7.preferences;
351
- const sourceFeatures = sourcePreferences === null || sourcePreferences === void 0 ? void 0 : sourcePreferences.features;
419
+ const preferencesStoreName = 'core/preferences';
420
+ let state = persistence.get();
421
+ const interfaceScopes = (_state$interfaceStore6 = state[interfaceStoreName]) === null || _state$interfaceStore6 === void 0 ? void 0 : (_state$interfaceStore7 = _state$interfaceStore6.preferences) === null || _state$interfaceStore7 === void 0 ? void 0 : _state$interfaceStore7.features;
352
422
 
353
- if (sourceFeatures) {
354
- var _state$interfaceStore6, _state$interfaceStore7;
423
+ for (const scope in interfaceScopes) {
424
+ var _state$preferencesSto8, _state$interfaceStore8, _state$interfaceStore9;
355
425
 
356
- const targetFeatures = (_state$interfaceStore6 = state[interfaceStoreName]) === null || _state$interfaceStore6 === void 0 ? void 0 : (_state$interfaceStore7 = _state$interfaceStore6.preferences) === null || _state$interfaceStore7 === void 0 ? void 0 : _state$interfaceStore7.features; // Avoid migrating features again if they've previously been migrated.
426
+ // Don't migrate any core 'scopes'.
427
+ if (scope.startsWith('core')) {
428
+ continue;
429
+ } // Skip this scope if there are no features to migrate.
357
430
 
358
- if (!(targetFeatures !== null && targetFeatures !== void 0 && targetFeatures[sourceStoreName])) {
359
- // Set the feature values in the interface store, the features
360
- // object is keyed by 'scope', which matches the store name for
361
- // the source.
362
- persistence.set(interfaceStoreName, {
363
- preferences: {
364
- features: { ...targetFeatures,
365
- [sourceStoreName]: sourceFeatures
366
- }
367
- }
368
- }); // Remove feature preferences from the source.
369
431
 
370
- persistence.set(sourceStoreName, {
371
- preferences: { ...sourcePreferences,
372
- features: undefined
373
- }
374
- });
432
+ const featuresToMigrate = interfaceScopes[scope];
433
+
434
+ if (!featuresToMigrate) {
435
+ continue;
375
436
  }
437
+
438
+ const existingPreferences = (_state$preferencesSto8 = state[preferencesStoreName]) === null || _state$preferencesSto8 === void 0 ? void 0 : _state$preferencesSto8.preferences; // Add the data to the preferences store structure.
439
+
440
+ persistence.set(preferencesStoreName, {
441
+ preferences: { ...existingPreferences,
442
+ [scope]: featuresToMigrate
443
+ }
444
+ }); // Remove the data from the interface store structure.
445
+ // Call `persistence.get` again to make sure `state` is up-to-date with
446
+ // any changes from the previous iteration of this loop.
447
+
448
+ state = persistence.get();
449
+ const otherInterfaceState = state[interfaceStoreName];
450
+ const otherInterfaceScopes = (_state$interfaceStore8 = state[interfaceStoreName]) === null || _state$interfaceStore8 === void 0 ? void 0 : (_state$interfaceStore9 = _state$interfaceStore8.preferences) === null || _state$interfaceStore9 === void 0 ? void 0 : _state$interfaceStore9.features;
451
+ persistence.set(interfaceStoreName, { ...otherInterfaceState,
452
+ preferences: {
453
+ features: { ...otherInterfaceScopes,
454
+ [scope]: undefined
455
+ }
456
+ }
457
+ });
376
458
  }
377
459
  }
460
+ /**
461
+ * Migrates interface 'enableItems' data to the preferences store.
462
+ *
463
+ * The interface package stores this data in this format:
464
+ * ```js
465
+ * {
466
+ * enableItems: {
467
+ * singleEnableItems: {
468
+ * complementaryArea: {
469
+ * 'core/edit-post': 'edit-post/document',
470
+ * 'core/edit-site': 'edit-site/global-styles',
471
+ * }
472
+ * },
473
+ * multipleEnableItems: {
474
+ * pinnedItems: {
475
+ * 'core/edit-post': {
476
+ * 'plugin-1': true,
477
+ * },
478
+ * 'core/edit-site': {
479
+ * 'plugin-2': true,
480
+ * },
481
+ * },
482
+ * }
483
+ * }
484
+ * }
485
+ * ```
486
+ * and it should be migrated it to:
487
+ * ```js
488
+ * {
489
+ * 'core/edit-post': {
490
+ * complementaryArea: 'edit-post/document',
491
+ * pinnedItems: {
492
+ * 'plugin-1': true,
493
+ * },
494
+ * },
495
+ * 'core/edit-site': {
496
+ * complementaryArea: 'edit-site/global-styles',
497
+ * pinnedItems: {
498
+ * 'plugin-2': true,
499
+ * },
500
+ * },
501
+ * }
502
+ * ```
503
+ *
504
+ * @param {Object} persistence The persistence interface.
505
+ */
506
+
507
+
508
+ function migrateInterfaceEnableItemsToPreferencesStore(persistence) {
509
+ var _state$interfaceStore10, _state$preferencesSto9, _state$preferencesSto10, _sourceEnableItems$si, _sourceEnableItems$si2, _sourceEnableItems$mu, _sourceEnableItems$mu2;
510
+
511
+ const interfaceStoreName = 'core/interface';
512
+ const preferencesStoreName = 'core/preferences';
513
+ const state = persistence.get();
514
+ const sourceEnableItems = (_state$interfaceStore10 = state[interfaceStoreName]) === null || _state$interfaceStore10 === void 0 ? void 0 : _state$interfaceStore10.enableItems; // There's nothing to migrate, exit early.
515
+
516
+ if (!sourceEnableItems) {
517
+ return;
518
+ }
519
+
520
+ const allPreferences = (_state$preferencesSto9 = (_state$preferencesSto10 = state[preferencesStoreName]) === null || _state$preferencesSto10 === void 0 ? void 0 : _state$preferencesSto10.preferences) !== null && _state$preferencesSto9 !== void 0 ? _state$preferencesSto9 : {}; // First convert complementaryAreas into the right format.
521
+ // Use the existing preferences as the accumulator so that the data is
522
+ // merged.
523
+
524
+ const sourceComplementaryAreas = (_sourceEnableItems$si = sourceEnableItems === null || sourceEnableItems === void 0 ? void 0 : (_sourceEnableItems$si2 = sourceEnableItems.singleEnableItems) === null || _sourceEnableItems$si2 === void 0 ? void 0 : _sourceEnableItems$si2.complementaryArea) !== null && _sourceEnableItems$si !== void 0 ? _sourceEnableItems$si : {};
525
+ const convertedComplementaryAreas = Object.keys(sourceComplementaryAreas).reduce((accumulator, scope) => {
526
+ var _accumulator$scope;
527
+
528
+ const data = sourceComplementaryAreas[scope]; // Don't overwrite any existing data in the preferences store.
529
+
530
+ if ((_accumulator$scope = accumulator[scope]) !== null && _accumulator$scope !== void 0 && _accumulator$scope.complementaryArea) {
531
+ return accumulator;
532
+ }
533
+
534
+ return { ...accumulator,
535
+ [scope]: { ...accumulator[scope],
536
+ complementaryArea: data
537
+ }
538
+ };
539
+ }, allPreferences); // Next feed the converted complementary areas back into a reducer that
540
+ // converts the pinned items, resulting in the fully migrated data.
541
+
542
+ const sourcePinnedItems = (_sourceEnableItems$mu = sourceEnableItems === null || sourceEnableItems === void 0 ? void 0 : (_sourceEnableItems$mu2 = sourceEnableItems.multipleEnableItems) === null || _sourceEnableItems$mu2 === void 0 ? void 0 : _sourceEnableItems$mu2.pinnedItems) !== null && _sourceEnableItems$mu !== void 0 ? _sourceEnableItems$mu : {};
543
+ const allConvertedData = Object.keys(sourcePinnedItems).reduce((accumulator, scope) => {
544
+ var _accumulator$scope2;
545
+
546
+ const data = sourcePinnedItems[scope]; // Don't overwrite any existing data in the preferences store.
547
+
548
+ if ((_accumulator$scope2 = accumulator[scope]) !== null && _accumulator$scope2 !== void 0 && _accumulator$scope2.pinnedItems) {
549
+ return accumulator;
550
+ }
551
+
552
+ return { ...accumulator,
553
+ [scope]: { ...accumulator[scope],
554
+ pinnedItems: data
555
+ }
556
+ };
557
+ }, convertedComplementaryAreas);
558
+ persistence.set(preferencesStoreName, {
559
+ preferences: allConvertedData
560
+ }); // Remove migrated preferences.
561
+
562
+ const otherInterfaceItems = state[interfaceStoreName];
563
+ persistence.set(interfaceStoreName, { ...otherInterfaceItems,
564
+ enableItems: undefined
565
+ });
566
+ }
378
567
 
379
568
  persistencePlugin.__unstableMigrate = pluginOptions => {
380
- const persistence = createPersistenceInterface(pluginOptions);
569
+ const persistence = createPersistenceInterface(pluginOptions); // Boolean feature preferences.
570
+
381
571
  migrateFeaturePreferencesToPreferencesStore(persistence, 'core/edit-widgets');
382
572
  migrateFeaturePreferencesToPreferencesStore(persistence, 'core/customize-widgets');
383
573
  migrateFeaturePreferencesToPreferencesStore(persistence, 'core/edit-post');
384
- migrateIndividualPreferenceToPreferencesStore(persistence, 'core/edit-post', 'hiddenBlockTypes');
385
574
  migrateFeaturePreferencesToPreferencesStore(persistence, 'core/edit-site');
386
- migrateIndividualPreferenceToPreferencesStore(persistence, 'core/edit-site', 'editorMode');
575
+ migrateThirdPartyFeaturePreferencesToPreferencesStore(persistence); // Other ad-hoc preferences.
576
+
577
+ migrateIndividualPreferenceToPreferencesStore(persistence, {
578
+ from: 'core/edit-post',
579
+ scope: 'core/edit-post'
580
+ }, 'hiddenBlockTypes');
581
+ migrateIndividualPreferenceToPreferencesStore(persistence, {
582
+ from: 'core/edit-post',
583
+ scope: 'core/edit-post'
584
+ }, 'editorMode');
585
+ migrateIndividualPreferenceToPreferencesStore(persistence, {
586
+ from: 'core/edit-post',
587
+ scope: 'core/edit-post'
588
+ }, 'preferredStyleVariations');
589
+ migrateIndividualPreferenceToPreferencesStore(persistence, {
590
+ from: 'core/edit-post',
591
+ scope: 'core/edit-post'
592
+ }, 'panels', convertEditPostPanels);
593
+ migrateIndividualPreferenceToPreferencesStore(persistence, {
594
+ from: 'core/editor',
595
+ scope: 'core/edit-post'
596
+ }, 'isPublishSidebarEnabled');
597
+ migrateIndividualPreferenceToPreferencesStore(persistence, {
598
+ from: 'core/edit-site',
599
+ scope: 'core/edit-site'
600
+ }, 'editorMode');
601
+ migrateInterfaceEnableItemsToPreferencesStore(persistence);
387
602
  };
388
603
 
389
604
  var _default = persistencePlugin;