@wordpress/data 6.3.0 → 6.3.1-next.a55ed9455a.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/build/components/use-select/index.js +1 -1
  3. package/build/components/use-select/index.js.map +1 -1
  4. package/build/factory.js +1 -1
  5. package/build/factory.js.map +1 -1
  6. package/build/plugins/persistence/index.js +114 -12
  7. package/build/plugins/persistence/index.js.map +1 -1
  8. package/build/redux-store/index.js +24 -8
  9. package/build/redux-store/index.js.map +1 -1
  10. package/build/redux-store/metadata/actions.js +47 -4
  11. package/build/redux-store/metadata/actions.js.map +1 -1
  12. package/build/redux-store/metadata/reducer.js +57 -4
  13. package/build/redux-store/metadata/reducer.js.map +1 -1
  14. package/build/redux-store/metadata/selectors.js +71 -7
  15. package/build/redux-store/metadata/selectors.js.map +1 -1
  16. package/build/registry.js +0 -2
  17. package/build/registry.js.map +1 -1
  18. package/build/resolvers-cache-middleware.js +3 -3
  19. package/build/resolvers-cache-middleware.js.map +1 -1
  20. package/build-module/components/use-select/index.js +1 -1
  21. package/build-module/components/use-select/index.js.map +1 -1
  22. package/build-module/factory.js +1 -1
  23. package/build-module/factory.js.map +1 -1
  24. package/build-module/plugins/persistence/index.js +111 -12
  25. package/build-module/plugins/persistence/index.js.map +1 -1
  26. package/build-module/redux-store/index.js +24 -8
  27. package/build-module/redux-store/index.js.map +1 -1
  28. package/build-module/redux-store/metadata/actions.js +43 -4
  29. package/build-module/redux-store/metadata/actions.js.map +1 -1
  30. package/build-module/redux-store/metadata/reducer.js +57 -4
  31. package/build-module/redux-store/metadata/reducer.js.map +1 -1
  32. package/build-module/redux-store/metadata/selectors.js +65 -7
  33. package/build-module/redux-store/metadata/selectors.js.map +1 -1
  34. package/build-module/registry.js +0 -2
  35. package/build-module/registry.js.map +1 -1
  36. package/build-module/resolvers-cache-middleware.js +3 -3
  37. package/build-module/resolvers-cache-middleware.js.map +1 -1
  38. package/build-types/redux-store/metadata/actions.d.ts +37 -4
  39. package/build-types/redux-store/metadata/actions.d.ts.map +1 -1
  40. package/build-types/redux-store/metadata/reducer.d.ts +10 -2
  41. package/build-types/redux-store/metadata/reducer.d.ts.map +1 -1
  42. package/build-types/redux-store/metadata/selectors.d.ts +40 -0
  43. package/build-types/redux-store/metadata/selectors.d.ts.map +1 -1
  44. package/build-types/types.d.ts.map +1 -1
  45. package/package.json +8 -8
  46. package/src/components/use-select/index.js +1 -1
  47. package/src/components/use-select/test/index.js +7 -7
  48. package/src/components/with-select/test/index.js +3 -3
  49. package/src/factory.js +1 -1
  50. package/src/plugins/persistence/index.js +142 -8
  51. package/src/plugins/persistence/test/index.js +405 -0
  52. package/src/redux-store/index.js +43 -15
  53. package/src/redux-store/metadata/actions.js +43 -4
  54. package/src/redux-store/metadata/reducer.ts +60 -9
  55. package/src/redux-store/metadata/selectors.js +60 -7
  56. package/src/redux-store/metadata/test/reducer.js +64 -24
  57. package/src/redux-store/metadata/test/selectors.js +263 -53
  58. package/src/redux-store/test/index.js +42 -0
  59. package/src/registry.js +0 -2
  60. package/src/resolvers-cache-middleware.js +4 -3
  61. package/src/test/controls.js +7 -7
  62. package/src/test/registry.js +6 -6
  63. package/src/types.ts +1 -3
  64. package/tsconfig.tsbuildinfo +1 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wordpress/data",
3
- "version": "6.3.0",
3
+ "version": "6.3.1-next.a55ed9455a.0",
4
4
  "description": "Data module for WordPress.",
5
5
  "author": "The WordPress Contributors",
6
6
  "license": "GPL-2.0-or-later",
@@ -28,12 +28,12 @@
28
28
  "sideEffects": false,
29
29
  "dependencies": {
30
30
  "@babel/runtime": "^7.16.0",
31
- "@wordpress/compose": "^5.1.2",
32
- "@wordpress/deprecated": "^3.3.1",
33
- "@wordpress/element": "^4.1.1",
34
- "@wordpress/is-shallow-equal": "^4.3.1",
35
- "@wordpress/priority-queue": "^2.3.1",
36
- "@wordpress/redux-routine": "^4.3.1",
31
+ "@wordpress/compose": "^5.1.3-next.a55ed9455a.0",
32
+ "@wordpress/deprecated": "^3.3.2-next.a55ed9455a.0",
33
+ "@wordpress/element": "^4.1.3-next.a55ed9455a.0",
34
+ "@wordpress/is-shallow-equal": "^4.3.2-next.a55ed9455a.0",
35
+ "@wordpress/priority-queue": "^2.3.2-next.a55ed9455a.0",
36
+ "@wordpress/redux-routine": "^4.3.2-next.a55ed9455a.0",
37
37
  "equivalent-key-map": "^0.2.2",
38
38
  "is-promise": "^4.0.0",
39
39
  "lodash": "^4.17.21",
@@ -47,5 +47,5 @@
47
47
  "publishConfig": {
48
48
  "access": "public"
49
49
  },
50
- "gitHead": "4566ac290359553d04de4eb574545309343f790b"
50
+ "gitHead": "c5108185851b824d531bce55991a3589947e8551"
51
51
  }
@@ -213,7 +213,7 @@ export default function useSelect( mapSelect, deps ) {
213
213
  }
214
214
  };
215
215
 
216
- // catch any possible state changes during mount before the subscription
216
+ // Catch any possible state changes during mount before the subscription
217
217
  // could be set.
218
218
  if ( latestIsAsync.current ) {
219
219
  renderQueue.add( queueContext, onStoreChange );
@@ -57,7 +57,7 @@ describe( 'useSelect', () => {
57
57
  expect( selectSpy ).toHaveBeenCalledTimes( 2 );
58
58
  expect( TestComponent ).toHaveBeenCalledTimes( 1 );
59
59
 
60
- // ensure expected state was rendered
60
+ // Ensure expected state was rendered.
61
61
  expect( testInstance.findByType( 'div' ).props ).toEqual( {
62
62
  children: 'bar',
63
63
  } );
@@ -92,12 +92,12 @@ describe( 'useSelect', () => {
92
92
  expect( selectSpyBar ).toHaveBeenCalledTimes( 0 );
93
93
  expect( TestComponent ).toHaveBeenCalledTimes( 1 );
94
94
 
95
- // ensure expected state was rendered
95
+ // Ensure expected state was rendered.
96
96
  expect( testInstance.findByType( 'div' ).props ).toEqual( {
97
97
  children: 'foo',
98
98
  } );
99
99
 
100
- //rerender with non dependency changed
100
+ // Rerender with non dependency changed.
101
101
  act( () => {
102
102
  renderer.update(
103
103
  <RegistryProvider value={ registry }>
@@ -110,12 +110,12 @@ describe( 'useSelect', () => {
110
110
  expect( selectSpyBar ).toHaveBeenCalledTimes( 0 );
111
111
  expect( TestComponent ).toHaveBeenCalledTimes( 2 );
112
112
 
113
- // ensure expected state was rendered
113
+ // Ensure expected state was rendered.
114
114
  expect( testInstance.findByType( 'div' ).props ).toEqual( {
115
115
  children: 'foo',
116
116
  } );
117
117
 
118
- // rerender with dependency changed
118
+ // Rerender with dependency changed.
119
119
  act( () => {
120
120
  renderer.update(
121
121
  <RegistryProvider value={ registry }>
@@ -128,7 +128,7 @@ describe( 'useSelect', () => {
128
128
  expect( selectSpyBar ).toHaveBeenCalledTimes( 2 );
129
129
  expect( TestComponent ).toHaveBeenCalledTimes( 3 );
130
130
 
131
- // ensure expected state was rendered
131
+ // Ensure expected state was rendered.
132
132
  expect( testInstance.findByType( 'div' ).props ).toEqual( {
133
133
  children: 'bar',
134
134
  } );
@@ -189,7 +189,7 @@ describe( 'useSelect', () => {
189
189
  );
190
190
  } );
191
191
  const testInstance = renderer.root;
192
- // ensure expected state was rendered.
192
+ // Ensure expected state was rendered.
193
193
  expect( testInstance.findByType( 'div' ).props.data ).toEqual(
194
194
  valueA
195
195
  );
@@ -131,7 +131,7 @@ describe( 'withSelect', () => {
131
131
  expect( mapSelectToProps ).toHaveBeenCalledTimes( 2 );
132
132
  expect( mapDispatchToProps ).toHaveBeenCalledTimes( 1 );
133
133
 
134
- // Simulate a click on the button
134
+ // Simulate a click on the button.
135
135
  act( () => {
136
136
  testInstance.findByType( 'button' ).props.onClick();
137
137
  } );
@@ -139,7 +139,7 @@ describe( 'withSelect', () => {
139
139
  expect( testInstance.findByType( 'button' ).props.children ).toBe( 1 );
140
140
  // 2 times =
141
141
  // 1. Initial mount
142
- // 2. When click handler is called
142
+ // 2. When click handler is called.
143
143
  expect( mapDispatchToProps ).toHaveBeenCalledTimes( 2 );
144
144
  // 4 times
145
145
  // - 1 on initial render
@@ -147,7 +147,7 @@ describe( 'withSelect', () => {
147
147
  // - 1 on click triggering subscription firing.
148
148
  // - 1 on rerender.
149
149
  expect( mapSelectToProps ).toHaveBeenCalledTimes( 4 );
150
- // verifies component only renders twice.
150
+ // Verifies component only renders twice.
151
151
  expect( OriginalComponent ).toHaveBeenCalledTimes( 2 );
152
152
  } );
153
153
 
package/src/factory.js CHANGED
@@ -36,7 +36,7 @@
36
36
  * @return {Function} Registry selector that can be registered with a store.
37
37
  */
38
38
  export function createRegistrySelector( registrySelector ) {
39
- // create a selector function that is bound to the registry referenced by `selector.registry`
39
+ // Create a selector function that is bound to the registry referenced by `selector.registry`
40
40
  // and that has the same API as a regular selector. Binding it in such a way makes it
41
41
  // possible to call the selector directly from another selector.
42
42
  const selector = ( ...args ) =>
@@ -222,6 +222,128 @@ function persistencePlugin( registry, pluginOptions ) {
222
222
  };
223
223
  }
224
224
 
225
+ /**
226
+ * Move the 'features' object in local storage from the sourceStoreName to the
227
+ * preferences store.
228
+ *
229
+ * @param {Object} persistence The persistence interface.
230
+ * @param {string} sourceStoreName The name of the store that has persisted
231
+ * preferences to migrate to the preferences
232
+ * package.
233
+ */
234
+ export function migrateFeaturePreferencesToPreferencesStore(
235
+ persistence,
236
+ sourceStoreName
237
+ ) {
238
+ const preferencesStoreName = 'core/preferences';
239
+ const interfaceStoreName = 'core/interface';
240
+
241
+ const state = persistence.get();
242
+
243
+ // Features most recently (and briefly) lived in the interface package.
244
+ // If data exists there, prioritize using that for the migration. If not
245
+ // also check the original package as the user may have updated from an
246
+ // older block editor version.
247
+ const interfaceFeatures =
248
+ state[ interfaceStoreName ]?.preferences?.features?.[ sourceStoreName ];
249
+ const sourceFeatures = state[ sourceStoreName ]?.preferences?.features;
250
+ const featuresToMigrate = interfaceFeatures
251
+ ? interfaceFeatures
252
+ : sourceFeatures;
253
+
254
+ if ( featuresToMigrate ) {
255
+ const targetFeatures = state[ preferencesStoreName ]?.preferences;
256
+
257
+ // Avoid migrating features again if they've previously been migrated.
258
+ if ( ! targetFeatures?.[ sourceStoreName ] ) {
259
+ // Set the feature values in the interface store, the features
260
+ // object is keyed by 'scope', which matches the store name for
261
+ // the source.
262
+ persistence.set( preferencesStoreName, {
263
+ preferences: {
264
+ ...targetFeatures,
265
+ [ sourceStoreName ]: featuresToMigrate,
266
+ },
267
+ } );
268
+
269
+ // Remove migrated feature preferences from `interface`.
270
+ if ( interfaceFeatures ) {
271
+ const otherInterfaceFeatures =
272
+ state[ interfaceStoreName ]?.preferences?.features;
273
+
274
+ persistence.set( interfaceStoreName, {
275
+ preferences: {
276
+ features: {
277
+ ...otherInterfaceFeatures,
278
+ [ sourceStoreName ]: undefined,
279
+ },
280
+ },
281
+ } );
282
+ }
283
+
284
+ // Remove migrated feature preferences from the source.
285
+ if ( sourceFeatures ) {
286
+ const sourcePreferences = state[ sourceStoreName ]?.preferences;
287
+
288
+ persistence.set( sourceStoreName, {
289
+ preferences: {
290
+ ...sourcePreferences,
291
+ features: undefined,
292
+ },
293
+ } );
294
+ }
295
+ }
296
+ }
297
+ }
298
+
299
+ export function migrateIndividualPreferenceToPreferencesStore(
300
+ persistence,
301
+ sourceStoreName,
302
+ key
303
+ ) {
304
+ const preferencesStoreName = 'core/preferences';
305
+ const state = persistence.get();
306
+ const sourcePreference = state[ sourceStoreName ]?.preferences?.[ key ];
307
+
308
+ // There's nothing to migrate, exit early.
309
+ if ( ! sourcePreference ) {
310
+ return;
311
+ }
312
+
313
+ const targetPreference =
314
+ state[ preferencesStoreName ]?.preferences?.[ sourceStoreName ]?.[
315
+ key
316
+ ];
317
+
318
+ // There's existing data at the target, so don't overwrite it, exit early.
319
+ if ( targetPreference ) {
320
+ return;
321
+ }
322
+
323
+ const allPreferences = state[ preferencesStoreName ]?.preferences;
324
+ const targetPreferences =
325
+ state[ preferencesStoreName ]?.preferences?.[ sourceStoreName ];
326
+
327
+ persistence.set( preferencesStoreName, {
328
+ preferences: {
329
+ ...allPreferences,
330
+ [ sourceStoreName ]: {
331
+ ...targetPreferences,
332
+ [ key ]: sourcePreference,
333
+ },
334
+ },
335
+ } );
336
+
337
+ // Remove migrated feature preferences from the source.
338
+ const allSourcePreferences = state[ sourceStoreName ]?.preferences;
339
+ persistence.set( sourceStoreName, {
340
+ preferences: {
341
+ ...allSourcePreferences,
342
+ [ key ]: undefined,
343
+ },
344
+ } );
345
+ }
346
+
225
347
  /**
226
348
  * Move the 'features' object in local storage from the sourceStoreName to the
227
349
  * interface store.
@@ -269,23 +391,35 @@ export function migrateFeaturePreferencesToInterfaceStore(
269
391
  }
270
392
  }
271
393
 
272
- /**
273
- * Deprecated: Remove this function and the code in WordPress Core that calls
274
- * it once WordPress 6.0 is released.
275
- */
276
-
277
394
  persistencePlugin.__unstableMigrate = ( pluginOptions ) => {
278
395
  const persistence = createPersistenceInterface( pluginOptions );
279
396
 
280
- migrateFeaturePreferencesToInterfaceStore(
397
+ migrateFeaturePreferencesToPreferencesStore(
281
398
  persistence,
282
399
  'core/edit-widgets'
283
400
  );
284
- migrateFeaturePreferencesToInterfaceStore(
401
+ migrateFeaturePreferencesToPreferencesStore(
285
402
  persistence,
286
403
  'core/customize-widgets'
287
404
  );
288
- migrateFeaturePreferencesToInterfaceStore( persistence, 'core/edit-post' );
405
+ migrateFeaturePreferencesToPreferencesStore(
406
+ persistence,
407
+ 'core/edit-post'
408
+ );
409
+ migrateIndividualPreferenceToPreferencesStore(
410
+ persistence,
411
+ 'core/edit-post',
412
+ 'hiddenBlockTypes'
413
+ );
414
+ migrateFeaturePreferencesToPreferencesStore(
415
+ persistence,
416
+ 'core/edit-site'
417
+ );
418
+ migrateIndividualPreferenceToPreferencesStore(
419
+ persistence,
420
+ 'core/edit-site',
421
+ 'editorMode'
422
+ );
289
423
  };
290
424
 
291
425
  export default persistencePlugin;