@wordpress/data 6.7.0 → 6.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/README.md +28 -0
- package/build/components/use-select/index.js +133 -19
- package/build/components/use-select/index.js.map +1 -1
- package/build/index.js +22 -3
- package/build/index.js.map +1 -1
- package/build/plugins/persistence/index.js +2 -375
- package/build/plugins/persistence/index.js.map +1 -1
- package/build/redux-store/index.js +52 -5
- package/build/redux-store/index.js.map +1 -1
- package/build/registry.js +31 -4
- package/build/registry.js.map +1 -1
- package/build-module/components/use-select/index.js +131 -19
- package/build-module/components/use-select/index.js.map +1 -1
- package/build-module/index.js +13 -1
- package/build-module/index.js.map +1 -1
- package/build-module/plugins/persistence/index.js +2 -365
- package/build-module/plugins/persistence/index.js.map +1 -1
- package/build-module/redux-store/index.js +52 -5
- package/build-module/redux-store/index.js.map +1 -1
- package/build-module/registry.js +31 -4
- package/build-module/registry.js.map +1 -1
- package/package.json +8 -8
- package/src/components/use-select/index.js +144 -14
- package/src/components/use-select/test/index.js +139 -3
- package/src/components/use-select/test/suspense.js +160 -0
- package/src/index.js +16 -1
- package/src/plugins/persistence/index.js +2 -420
- package/src/plugins/persistence/test/index.js +1 -777
- package/src/redux-store/index.js +43 -0
- package/src/registry.js +30 -4
- package/src/test/registry.js +8 -1
- package/tsconfig.json +2 -2
|
@@ -5,14 +5,8 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
|
-
exports.convertEditPostPanels = convertEditPostPanels;
|
|
9
8
|
exports.createPersistenceInterface = createPersistenceInterface;
|
|
10
|
-
exports.default = void 0;
|
|
11
|
-
exports.migrateFeaturePreferencesToPreferencesStore = migrateFeaturePreferencesToPreferencesStore;
|
|
12
|
-
exports.migrateIndividualPreferenceToPreferencesStore = migrateIndividualPreferenceToPreferencesStore;
|
|
13
|
-
exports.migrateInterfaceEnableItemsToPreferencesStore = migrateInterfaceEnableItemsToPreferencesStore;
|
|
14
|
-
exports.migrateThirdPartyFeaturePreferencesToPreferencesStore = migrateThirdPartyFeaturePreferencesToPreferencesStore;
|
|
15
|
-
exports.withLazySameState = void 0;
|
|
9
|
+
exports.withLazySameState = exports.default = void 0;
|
|
16
10
|
|
|
17
11
|
var _lodash = require("lodash");
|
|
18
12
|
|
|
@@ -231,375 +225,8 @@ function persistencePlugin(registry, pluginOptions) {
|
|
|
231
225
|
|
|
232
226
|
};
|
|
233
227
|
}
|
|
234
|
-
/**
|
|
235
|
-
* Move the 'features' object in local storage from the sourceStoreName to the
|
|
236
|
-
* preferences store.
|
|
237
|
-
*
|
|
238
|
-
* @param {Object} persistence The persistence interface.
|
|
239
|
-
* @param {string} sourceStoreName The name of the store that has persisted
|
|
240
|
-
* preferences to migrate to the preferences
|
|
241
|
-
* package.
|
|
242
|
-
*/
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
function migrateFeaturePreferencesToPreferencesStore(persistence, sourceStoreName) {
|
|
246
|
-
var _state$interfaceStore, _state$interfaceStore2, _state$interfaceStore3, _state$sourceStoreNam, _state$sourceStoreNam2;
|
|
247
|
-
|
|
248
|
-
const preferencesStoreName = 'core/preferences';
|
|
249
|
-
const interfaceStoreName = 'core/interface';
|
|
250
|
-
const state = persistence.get(); // Features most recently (and briefly) lived in the interface package.
|
|
251
|
-
// If data exists there, prioritize using that for the migration. If not
|
|
252
|
-
// also check the original package as the user may have updated from an
|
|
253
|
-
// older block editor version.
|
|
254
|
-
|
|
255
|
-
const interfaceFeatures = (_state$interfaceStore = state[interfaceStoreName]) === null || _state$interfaceStore === void 0 ? void 0 : (_state$interfaceStore2 = _state$interfaceStore.preferences) === null || _state$interfaceStore2 === void 0 ? void 0 : (_state$interfaceStore3 = _state$interfaceStore2.features) === null || _state$interfaceStore3 === void 0 ? void 0 : _state$interfaceStore3[sourceStoreName];
|
|
256
|
-
const sourceFeatures = (_state$sourceStoreNam = state[sourceStoreName]) === null || _state$sourceStoreNam === void 0 ? void 0 : (_state$sourceStoreNam2 = _state$sourceStoreNam.preferences) === null || _state$sourceStoreNam2 === void 0 ? void 0 : _state$sourceStoreNam2.features;
|
|
257
|
-
const featuresToMigrate = interfaceFeatures ? interfaceFeatures : sourceFeatures;
|
|
258
|
-
|
|
259
|
-
if (featuresToMigrate) {
|
|
260
|
-
var _state$preferencesSto;
|
|
261
|
-
|
|
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.
|
|
263
|
-
|
|
264
|
-
if (!(existingPreferences !== null && existingPreferences !== void 0 && existingPreferences[sourceStoreName])) {
|
|
265
|
-
// Set the feature values in the interface store, the features
|
|
266
|
-
// object is keyed by 'scope', which matches the store name for
|
|
267
|
-
// the source.
|
|
268
|
-
persistence.set(preferencesStoreName, {
|
|
269
|
-
preferences: { ...existingPreferences,
|
|
270
|
-
[sourceStoreName]: featuresToMigrate
|
|
271
|
-
}
|
|
272
|
-
}); // Remove migrated feature preferences from `interface`.
|
|
273
|
-
|
|
274
|
-
if (interfaceFeatures) {
|
|
275
|
-
var _state$interfaceStore4, _state$interfaceStore5;
|
|
276
|
-
|
|
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,
|
|
280
|
-
preferences: {
|
|
281
|
-
features: { ...otherInterfaceScopes,
|
|
282
|
-
[sourceStoreName]: undefined
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
});
|
|
286
|
-
} // Remove migrated feature preferences from the source.
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
if (sourceFeatures) {
|
|
290
|
-
var _state$sourceStoreNam3;
|
|
291
|
-
|
|
292
|
-
const otherSourceState = state[sourceStoreName];
|
|
293
|
-
const sourcePreferences = (_state$sourceStoreNam3 = state[sourceStoreName]) === null || _state$sourceStoreNam3 === void 0 ? void 0 : _state$sourceStoreNam3.preferences;
|
|
294
|
-
persistence.set(sourceStoreName, { ...otherSourceState,
|
|
295
|
-
preferences: { ...sourcePreferences,
|
|
296
|
-
features: undefined
|
|
297
|
-
}
|
|
298
|
-
});
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
}
|
|
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
|
-
*/
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
function migrateIndividualPreferenceToPreferencesStore(persistence, _ref, key) {
|
|
316
|
-
var _state$sourceStoreNam4, _state$sourceStoreNam5, _state$preferencesSto2, _state$preferencesSto3, _state$preferencesSto4, _state$preferencesSto5, _state$preferencesSto6, _state$preferencesSto7, _state$sourceStoreNam6;
|
|
317
|
-
|
|
318
|
-
let {
|
|
319
|
-
from: sourceStoreName,
|
|
320
|
-
scope
|
|
321
|
-
} = _ref;
|
|
322
|
-
let convert = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : _lodash.identity;
|
|
323
|
-
const preferencesStoreName = 'core/preferences';
|
|
324
|
-
const state = persistence.get();
|
|
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.
|
|
326
|
-
|
|
327
|
-
if (sourcePreference === undefined) {
|
|
328
|
-
return;
|
|
329
|
-
}
|
|
330
|
-
|
|
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.
|
|
332
|
-
|
|
333
|
-
if (targetPreference) {
|
|
334
|
-
return;
|
|
335
|
-
}
|
|
336
|
-
|
|
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
|
-
});
|
|
344
|
-
persistence.set(preferencesStoreName, {
|
|
345
|
-
preferences: { ...otherScopes,
|
|
346
|
-
[scope]: { ...otherPreferences,
|
|
347
|
-
...convertedPreferences
|
|
348
|
-
}
|
|
349
|
-
}
|
|
350
|
-
}); // Remove migrated feature preferences from the source.
|
|
351
|
-
|
|
352
|
-
const otherSourceState = state[sourceStoreName];
|
|
353
|
-
const allSourcePreferences = (_state$sourceStoreNam6 = state[sourceStoreName]) === null || _state$sourceStoreNam6 === void 0 ? void 0 : _state$sourceStoreNam6.preferences;
|
|
354
|
-
persistence.set(sourceStoreName, { ...otherSourceState,
|
|
355
|
-
preferences: { ...allSourcePreferences,
|
|
356
|
-
[key]: undefined
|
|
357
|
-
}
|
|
358
|
-
});
|
|
359
|
-
}
|
|
360
|
-
/**
|
|
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
|
-
* ```
|
|
376
|
-
*
|
|
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.
|
|
390
|
-
*/
|
|
391
|
-
|
|
392
|
-
|
|
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
228
|
|
|
404
|
-
|
|
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;
|
|
417
|
-
|
|
418
|
-
const interfaceStoreName = 'core/interface';
|
|
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;
|
|
422
|
-
|
|
423
|
-
for (const scope in interfaceScopes) {
|
|
424
|
-
var _state$preferencesSto8, _state$interfaceStore8, _state$interfaceStore9;
|
|
425
|
-
|
|
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.
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
const featuresToMigrate = interfaceScopes[scope];
|
|
433
|
-
|
|
434
|
-
if (!featuresToMigrate) {
|
|
435
|
-
continue;
|
|
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
|
-
});
|
|
458
|
-
}
|
|
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
|
-
}
|
|
567
|
-
|
|
568
|
-
persistencePlugin.__unstableMigrate = pluginOptions => {
|
|
569
|
-
const persistence = createPersistenceInterface(pluginOptions); // Boolean feature preferences.
|
|
570
|
-
|
|
571
|
-
migrateFeaturePreferencesToPreferencesStore(persistence, 'core/edit-widgets');
|
|
572
|
-
migrateFeaturePreferencesToPreferencesStore(persistence, 'core/customize-widgets');
|
|
573
|
-
migrateFeaturePreferencesToPreferencesStore(persistence, 'core/edit-post');
|
|
574
|
-
migrateFeaturePreferencesToPreferencesStore(persistence, 'core/edit-site');
|
|
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);
|
|
602
|
-
};
|
|
229
|
+
persistencePlugin.__unstableMigrate = () => {};
|
|
603
230
|
|
|
604
231
|
var _default = persistencePlugin;
|
|
605
232
|
exports.default = _default;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/data/src/plugins/persistence/index.js"],"names":["DEFAULT_STORAGE","defaultStorage","DEFAULT_STORAGE_KEY","withLazySameState","reducer","state","action","nextState","createPersistenceInterface","options","storage","storageKey","data","getData","undefined","persisted","getItem","JSON","parse","error","setData","key","value","setItem","stringify","get","set","persistencePlugin","registry","pluginOptions","persistence","createPersistOnChange","getState","storeName","keys","getPersistedState","Array","isArray","reducers","reduce","accumulator","Object","assign","lastState","registerStore","persist","persistedState","initialState","type","store","subscribe","migrateFeaturePreferencesToPreferencesStore","sourceStoreName","preferencesStoreName","interfaceStoreName","interfaceFeatures","preferences","features","sourceFeatures","featuresToMigrate","existingPreferences","otherInterfaceState","otherInterfaceScopes","otherSourceState","sourcePreferences","migrateIndividualPreferenceToPreferencesStore","from","scope","convert","identity","sourcePreference","targetPreference","otherScopes","otherPreferences","convertedPreferences","allSourcePreferences","convertEditPostPanels","panels","convertedData","panelName","panel","enabled","inactivePanels","push","opened","openPanels","migrateThirdPartyFeaturePreferencesToPreferencesStore","interfaceScopes","startsWith","migrateInterfaceEnableItemsToPreferencesStore","sourceEnableItems","enableItems","allPreferences","sourceComplementaryAreas","singleEnableItems","complementaryArea","convertedComplementaryAreas","sourcePinnedItems","multipleEnableItems","pinnedItems","allConvertedData","otherInterfaceItems","__unstableMigrate"],"mappings":";;;;;;;;;;;;;;;;AAGA;;AAKA;;AACA;;AATA;AACA;AACA;;AAGA;AACA;AACA;;AAIA;;AAEA;;AAEA;AACA;AACA;AACA;AACA;AACA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5CS,qBAJ4C,CAA7C;AAMAX,EAAAA,6CAA6C,CAC5CnC,WAD4C,EAE5C;AAAEoC,IAAAA,IAAI,EAAE,aAAR;AAAuBC,IAAAA,KAAK,EAAE;AAA9B,GAF4C,EAG5C,yBAH4C,CAA7C;AAKAF,EAAAA,6CAA6C,CAC5CnC,WAD4C,EAE5C;AAAEoC,IAAAA,IAAI,EAAE,gBAAR;AAA0BC,IAAAA,KAAK,EAAE;AAAjC,GAF4C,EAG5C,YAH4C,CAA7C;AAKAsB,EAAAA,6CAA6C,CAAE3D,WAAF,CAA7C;AACA,CAvDD;;eAyDeH,iB","sourcesContent":["/**\n * External dependencies\n */\nimport { merge, isPlainObject, identity } from 'lodash';\n\n/**\n * Internal dependencies\n */\nimport defaultStorage from './storage/default';\nimport { combineReducers } from '../../';\n\n/** @typedef {import('../../registry').WPDataRegistry} WPDataRegistry */\n\n/** @typedef {import('../../registry').WPDataPlugin} WPDataPlugin */\n\n/**\n * @typedef {Object} WPDataPersistencePluginOptions Persistence plugin options.\n *\n * @property {Storage} storage Persistent storage implementation. This must\n * at least implement `getItem` and `setItem` of\n * the Web Storage API.\n * @property {string} storageKey Key on which to set in persistent storage.\n *\n */\n\n/**\n * Default plugin storage.\n *\n * @type {Storage}\n */\nconst DEFAULT_STORAGE = defaultStorage;\n\n/**\n * Default plugin storage key.\n *\n * @type {string}\n */\nconst DEFAULT_STORAGE_KEY = 'WP_DATA';\n\n/**\n * Higher-order reducer which invokes the original reducer only if state is\n * inequal from that of the action's `nextState` property, otherwise returning\n * the original state reference.\n *\n * @param {Function} reducer Original reducer.\n *\n * @return {Function} Enhanced reducer.\n */\nexport const withLazySameState = ( reducer ) => ( state, action ) => {\n\tif ( action.nextState === state ) {\n\t\treturn state;\n\t}\n\n\treturn reducer( state, action );\n};\n\n/**\n * Creates a persistence interface, exposing getter and setter methods (`get`\n * and `set` respectively).\n *\n * @param {WPDataPersistencePluginOptions} options Plugin options.\n *\n * @return {Object} Persistence interface.\n */\nexport function createPersistenceInterface( options ) {\n\tconst {\n\t\tstorage = DEFAULT_STORAGE,\n\t\tstorageKey = DEFAULT_STORAGE_KEY,\n\t} = options;\n\n\tlet data;\n\n\t/**\n\t * Returns the persisted data as an object, defaulting to an empty object.\n\t *\n\t * @return {Object} Persisted data.\n\t */\n\tfunction getData() {\n\t\tif ( data === undefined ) {\n\t\t\t// If unset, getItem is expected to return null. Fall back to\n\t\t\t// empty object.\n\t\t\tconst persisted = storage.getItem( storageKey );\n\t\t\tif ( persisted === null ) {\n\t\t\t\tdata = {};\n\t\t\t} else {\n\t\t\t\ttry {\n\t\t\t\t\tdata = JSON.parse( persisted );\n\t\t\t\t} catch ( error ) {\n\t\t\t\t\t// Similarly, should any error be thrown during parse of\n\t\t\t\t\t// the string (malformed JSON), fall back to empty object.\n\t\t\t\t\tdata = {};\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn data;\n\t}\n\n\t/**\n\t * Merges an updated reducer state into the persisted data.\n\t *\n\t * @param {string} key Key to update.\n\t * @param {*} value Updated value.\n\t */\n\tfunction setData( key, value ) {\n\t\tdata = { ...data, [ key ]: value };\n\t\tstorage.setItem( storageKey, JSON.stringify( data ) );\n\t}\n\n\treturn {\n\t\tget: getData,\n\t\tset: setData,\n\t};\n}\n\n/**\n * Data plugin to persist store state into a single storage key.\n *\n * @param {WPDataRegistry} registry Data registry.\n * @param {?WPDataPersistencePluginOptions} pluginOptions Plugin options.\n *\n * @return {WPDataPlugin} Data plugin.\n */\nfunction persistencePlugin( registry, pluginOptions ) {\n\tconst persistence = createPersistenceInterface( pluginOptions );\n\n\t/**\n\t * Creates an enhanced store dispatch function, triggering the state of the\n\t * given store name to be persisted when changed.\n\t *\n\t * @param {Function} getState Function which returns current state.\n\t * @param {string} storeName Store name.\n\t * @param {?Array<string>} keys Optional subset of keys to save.\n\t *\n\t * @return {Function} Enhanced dispatch function.\n\t */\n\tfunction createPersistOnChange( getState, storeName, keys ) {\n\t\tlet getPersistedState;\n\t\tif ( Array.isArray( keys ) ) {\n\t\t\t// Given keys, the persisted state should by produced as an object\n\t\t\t// of the subset of keys. This implementation uses combineReducers\n\t\t\t// to leverage its behavior of returning the same object when none\n\t\t\t// of the property values changes. This allows a strict reference\n\t\t\t// equality to bypass a persistence set on an unchanging state.\n\t\t\tconst reducers = keys.reduce(\n\t\t\t\t( accumulator, key ) =>\n\t\t\t\t\tObject.assign( accumulator, {\n\t\t\t\t\t\t[ key ]: ( state, action ) => action.nextState[ key ],\n\t\t\t\t\t} ),\n\t\t\t\t{}\n\t\t\t);\n\n\t\t\tgetPersistedState = withLazySameState(\n\t\t\t\tcombineReducers( reducers )\n\t\t\t);\n\t\t} else {\n\t\t\tgetPersistedState = ( state, action ) => action.nextState;\n\t\t}\n\n\t\tlet lastState = getPersistedState( undefined, {\n\t\t\tnextState: getState(),\n\t\t} );\n\n\t\treturn () => {\n\t\t\tconst state = getPersistedState( lastState, {\n\t\t\t\tnextState: getState(),\n\t\t\t} );\n\t\t\tif ( state !== lastState ) {\n\t\t\t\tpersistence.set( storeName, state );\n\t\t\t\tlastState = state;\n\t\t\t}\n\t\t};\n\t}\n\n\treturn {\n\t\tregisterStore( storeName, options ) {\n\t\t\tif ( ! options.persist ) {\n\t\t\t\treturn registry.registerStore( storeName, options );\n\t\t\t}\n\n\t\t\t// Load from persistence to use as initial state.\n\t\t\tconst persistedState = persistence.get()[ storeName ];\n\t\t\tif ( persistedState !== undefined ) {\n\t\t\t\tlet initialState = options.reducer( options.initialState, {\n\t\t\t\t\ttype: '@@WP/PERSISTENCE_RESTORE',\n\t\t\t\t} );\n\n\t\t\t\tif (\n\t\t\t\t\tisPlainObject( initialState ) &&\n\t\t\t\t\tisPlainObject( persistedState )\n\t\t\t\t) {\n\t\t\t\t\t// If state is an object, ensure that:\n\t\t\t\t\t// - Other keys are left intact when persisting only a\n\t\t\t\t\t// subset of keys.\n\t\t\t\t\t// - New keys in what would otherwise be used as initial\n\t\t\t\t\t// state are deeply merged as base for persisted value.\n\t\t\t\t\tinitialState = merge( {}, initialState, persistedState );\n\t\t\t\t} else {\n\t\t\t\t\t// If there is a mismatch in object-likeness of default\n\t\t\t\t\t// initial or persisted state, defer to persisted value.\n\t\t\t\t\tinitialState = persistedState;\n\t\t\t\t}\n\n\t\t\t\toptions = {\n\t\t\t\t\t...options,\n\t\t\t\t\tinitialState,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tconst store = registry.registerStore( storeName, options );\n\n\t\t\tstore.subscribe(\n\t\t\t\tcreatePersistOnChange(\n\t\t\t\t\tstore.getState,\n\t\t\t\t\tstoreName,\n\t\t\t\t\toptions.persist\n\t\t\t\t)\n\t\t\t);\n\n\t\t\treturn store;\n\t\t},\n\t};\n}\n\n/**\n * Move the 'features' object in local storage from the sourceStoreName to the\n * preferences store.\n *\n * @param {Object} persistence The persistence interface.\n * @param {string} sourceStoreName The name of the store that has persisted\n * preferences to migrate to the preferences\n * package.\n */\nexport function migrateFeaturePreferencesToPreferencesStore(\n\tpersistence,\n\tsourceStoreName\n) {\n\tconst preferencesStoreName = 'core/preferences';\n\tconst interfaceStoreName = 'core/interface';\n\n\tconst state = persistence.get();\n\n\t// Features most recently (and briefly) lived in the interface package.\n\t// If data exists there, prioritize using that for the migration. If not\n\t// also check the original package as the user may have updated from an\n\t// older block editor version.\n\tconst interfaceFeatures =\n\t\tstate[ interfaceStoreName ]?.preferences?.features?.[ sourceStoreName ];\n\tconst sourceFeatures = state[ sourceStoreName ]?.preferences?.features;\n\tconst featuresToMigrate = interfaceFeatures\n\t\t? interfaceFeatures\n\t\t: sourceFeatures;\n\n\tif ( featuresToMigrate ) {\n\t\tconst existingPreferences = state[ preferencesStoreName ]?.preferences;\n\n\t\t// Avoid migrating features again if they've previously been migrated.\n\t\tif ( ! existingPreferences?.[ sourceStoreName ] ) {\n\t\t\t// Set the feature values in the interface store, the features\n\t\t\t// object is keyed by 'scope', which matches the store name for\n\t\t\t// the source.\n\t\t\tpersistence.set( preferencesStoreName, {\n\t\t\t\tpreferences: {\n\t\t\t\t\t...existingPreferences,\n\t\t\t\t\t[ sourceStoreName ]: featuresToMigrate,\n\t\t\t\t},\n\t\t\t} );\n\n\t\t\t// Remove migrated feature preferences from `interface`.\n\t\t\tif ( interfaceFeatures ) {\n\t\t\t\tconst otherInterfaceState = state[ interfaceStoreName ];\n\t\t\t\tconst otherInterfaceScopes =\n\t\t\t\t\tstate[ interfaceStoreName ]?.preferences?.features;\n\n\t\t\t\tpersistence.set( interfaceStoreName, {\n\t\t\t\t\t...otherInterfaceState,\n\t\t\t\t\tpreferences: {\n\t\t\t\t\t\tfeatures: {\n\t\t\t\t\t\t\t...otherInterfaceScopes,\n\t\t\t\t\t\t\t[ sourceStoreName ]: undefined,\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t} );\n\t\t\t}\n\n\t\t\t// Remove migrated feature preferences from the source.\n\t\t\tif ( sourceFeatures ) {\n\t\t\t\tconst otherSourceState = state[ sourceStoreName ];\n\t\t\t\tconst sourcePreferences = state[ sourceStoreName ]?.preferences;\n\n\t\t\t\tpersistence.set( sourceStoreName, {\n\t\t\t\t\t...otherSourceState,\n\t\t\t\t\tpreferences: {\n\t\t\t\t\t\t...sourcePreferences,\n\t\t\t\t\t\tfeatures: undefined,\n\t\t\t\t\t},\n\t\t\t\t} );\n\t\t\t}\n\t\t}\n\t}\n}\n\n/**\n * Migrates an individual item inside the `preferences` object for a store.\n *\n * @param {Object} persistence The persistence interface.\n * @param {Object} migrate An options object that contains details of the migration.\n * @param {string} migrate.from The name of the store to migrate from.\n * @param {string} migrate.scope The scope in the preferences store to migrate to.\n * @param {string} key The key in the preferences object to migrate.\n * @param {?Function} convert A function that converts preferences from one format to another.\n */\nexport function migrateIndividualPreferenceToPreferencesStore(\n\tpersistence,\n\t{ from: sourceStoreName, scope },\n\tkey,\n\tconvert = identity\n) {\n\tconst preferencesStoreName = 'core/preferences';\n\tconst state = persistence.get();\n\tconst sourcePreference = state[ sourceStoreName ]?.preferences?.[ key ];\n\n\t// There's nothing to migrate, exit early.\n\tif ( sourcePreference === undefined ) {\n\t\treturn;\n\t}\n\n\tconst targetPreference =\n\t\tstate[ preferencesStoreName ]?.preferences?.[ scope ]?.[ key ];\n\n\t// There's existing data at the target, so don't overwrite it, exit early.\n\tif ( targetPreference ) {\n\t\treturn;\n\t}\n\n\tconst otherScopes = state[ preferencesStoreName ]?.preferences;\n\tconst otherPreferences =\n\t\tstate[ preferencesStoreName ]?.preferences?.[ scope ];\n\n\t// Pass an object with the key and value as this allows the convert\n\t// function to convert to a data structure that has different keys.\n\tconst convertedPreferences = convert( { [ key ]: sourcePreference } );\n\n\tpersistence.set( preferencesStoreName, {\n\t\tpreferences: {\n\t\t\t...otherScopes,\n\t\t\t[ scope ]: {\n\t\t\t\t...otherPreferences,\n\t\t\t\t...convertedPreferences,\n\t\t\t},\n\t\t},\n\t} );\n\n\t// Remove migrated feature preferences from the source.\n\tconst otherSourceState = state[ sourceStoreName ];\n\tconst allSourcePreferences = state[ sourceStoreName ]?.preferences;\n\tpersistence.set( sourceStoreName, {\n\t\t...otherSourceState,\n\t\tpreferences: {\n\t\t\t...allSourcePreferences,\n\t\t\t[ key ]: undefined,\n\t\t},\n\t} );\n}\n\n/**\n * Convert from:\n * ```\n * {\n * panels: {\n * tags: {\n * enabled: true,\n * opened: true,\n * },\n * permalinks: {\n * enabled: false,\n * opened: false,\n * },\n * },\n * }\n * ```\n *\n * to:\n * {\n * inactivePanels: [\n * 'permalinks',\n * ],\n * openPanels: [\n * 'tags',\n * ],\n * }\n *\n * @param {Object} preferences A preferences object.\n *\n * @return {Object} The converted data.\n */\nexport function convertEditPostPanels( preferences ) {\n\tconst panels = preferences?.panels ?? {};\n\treturn Object.keys( panels ).reduce(\n\t\t( convertedData, panelName ) => {\n\t\t\tconst panel = panels[ panelName ];\n\n\t\t\tif ( panel?.enabled === false ) {\n\t\t\t\tconvertedData.inactivePanels.push( panelName );\n\t\t\t}\n\n\t\t\tif ( panel?.opened === true ) {\n\t\t\t\tconvertedData.openPanels.push( panelName );\n\t\t\t}\n\n\t\t\treturn convertedData;\n\t\t},\n\t\t{ inactivePanels: [], openPanels: [] }\n\t);\n}\n\nexport function migrateThirdPartyFeaturePreferencesToPreferencesStore(\n\tpersistence\n) {\n\tconst interfaceStoreName = 'core/interface';\n\tconst preferencesStoreName = 'core/preferences';\n\n\tlet state = persistence.get();\n\n\tconst interfaceScopes = state[ interfaceStoreName ]?.preferences?.features;\n\n\tfor ( const scope in interfaceScopes ) {\n\t\t// Don't migrate any core 'scopes'.\n\t\tif ( scope.startsWith( 'core' ) ) {\n\t\t\tcontinue;\n\t\t}\n\n\t\t// Skip this scope if there are no features to migrate.\n\t\tconst featuresToMigrate = interfaceScopes[ scope ];\n\t\tif ( ! featuresToMigrate ) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst existingPreferences = state[ preferencesStoreName ]?.preferences;\n\n\t\t// Add the data to the preferences store structure.\n\t\tpersistence.set( preferencesStoreName, {\n\t\t\tpreferences: {\n\t\t\t\t...existingPreferences,\n\t\t\t\t[ scope ]: featuresToMigrate,\n\t\t\t},\n\t\t} );\n\n\t\t// Remove the data from the interface store structure.\n\t\t// Call `persistence.get` again to make sure `state` is up-to-date with\n\t\t// any changes from the previous iteration of this loop.\n\t\tstate = persistence.get();\n\t\tconst otherInterfaceState = state[ interfaceStoreName ];\n\t\tconst otherInterfaceScopes =\n\t\t\tstate[ interfaceStoreName ]?.preferences?.features;\n\n\t\tpersistence.set( interfaceStoreName, {\n\t\t\t...otherInterfaceState,\n\t\t\tpreferences: {\n\t\t\t\tfeatures: {\n\t\t\t\t\t...otherInterfaceScopes,\n\t\t\t\t\t[ scope ]: undefined,\n\t\t\t\t},\n\t\t\t},\n\t\t} );\n\t}\n}\n\n/**\n * Migrates interface 'enableItems' data to the preferences store.\n *\n * The interface package stores this data in this format:\n * ```js\n * {\n * enableItems: {\n * singleEnableItems: {\n * \t complementaryArea: {\n * 'core/edit-post': 'edit-post/document',\n * 'core/edit-site': 'edit-site/global-styles',\n * }\n * },\n * multipleEnableItems: {\n * pinnedItems: {\n * 'core/edit-post': {\n * 'plugin-1': true,\n * },\n * 'core/edit-site': {\n * 'plugin-2': true,\n * },\n * },\n * }\n * }\n * }\n * ```\n * and it should be migrated it to:\n * ```js\n * {\n * 'core/edit-post': {\n * complementaryArea: 'edit-post/document',\n * pinnedItems: {\n * 'plugin-1': true,\n * },\n * },\n * 'core/edit-site': {\n * complementaryArea: 'edit-site/global-styles',\n * pinnedItems: {\n * 'plugin-2': true,\n * },\n * },\n * }\n * ```\n *\n * @param {Object} persistence The persistence interface.\n */\nexport function migrateInterfaceEnableItemsToPreferencesStore( persistence ) {\n\tconst interfaceStoreName = 'core/interface';\n\tconst preferencesStoreName = 'core/preferences';\n\tconst state = persistence.get();\n\tconst sourceEnableItems = state[ interfaceStoreName ]?.enableItems;\n\n\t// There's nothing to migrate, exit early.\n\tif ( ! sourceEnableItems ) {\n\t\treturn;\n\t}\n\n\tconst allPreferences = state[ preferencesStoreName ]?.preferences ?? {};\n\n\t// First convert complementaryAreas into the right format.\n\t// Use the existing preferences as the accumulator so that the data is\n\t// merged.\n\tconst sourceComplementaryAreas =\n\t\tsourceEnableItems?.singleEnableItems?.complementaryArea ?? {};\n\n\tconst convertedComplementaryAreas = Object.keys(\n\t\tsourceComplementaryAreas\n\t).reduce( ( accumulator, scope ) => {\n\t\tconst data = sourceComplementaryAreas[ scope ];\n\n\t\t// Don't overwrite any existing data in the preferences store.\n\t\tif ( accumulator[ scope ]?.complementaryArea ) {\n\t\t\treturn accumulator;\n\t\t}\n\n\t\treturn {\n\t\t\t...accumulator,\n\t\t\t[ scope ]: {\n\t\t\t\t...accumulator[ scope ],\n\t\t\t\tcomplementaryArea: data,\n\t\t\t},\n\t\t};\n\t}, allPreferences );\n\n\t// Next feed the converted complementary areas back into a reducer that\n\t// converts the pinned items, resulting in the fully migrated data.\n\tconst sourcePinnedItems =\n\t\tsourceEnableItems?.multipleEnableItems?.pinnedItems ?? {};\n\tconst allConvertedData = Object.keys( sourcePinnedItems ).reduce(\n\t\t( accumulator, scope ) => {\n\t\t\tconst data = sourcePinnedItems[ scope ];\n\t\t\t// Don't overwrite any existing data in the preferences store.\n\t\t\tif ( accumulator[ scope ]?.pinnedItems ) {\n\t\t\t\treturn accumulator;\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\t...accumulator,\n\t\t\t\t[ scope ]: {\n\t\t\t\t\t...accumulator[ scope ],\n\t\t\t\t\tpinnedItems: data,\n\t\t\t\t},\n\t\t\t};\n\t\t},\n\t\tconvertedComplementaryAreas\n\t);\n\n\tpersistence.set( preferencesStoreName, {\n\t\tpreferences: allConvertedData,\n\t} );\n\n\t// Remove migrated preferences.\n\tconst otherInterfaceItems = state[ interfaceStoreName ];\n\tpersistence.set( interfaceStoreName, {\n\t\t...otherInterfaceItems,\n\t\tenableItems: undefined,\n\t} );\n}\n\npersistencePlugin.__unstableMigrate = ( pluginOptions ) => {\n\tconst persistence = createPersistenceInterface( pluginOptions );\n\n\t// Boolean feature preferences.\n\tmigrateFeaturePreferencesToPreferencesStore(\n\t\tpersistence,\n\t\t'core/edit-widgets'\n\t);\n\tmigrateFeaturePreferencesToPreferencesStore(\n\t\tpersistence,\n\t\t'core/customize-widgets'\n\t);\n\tmigrateFeaturePreferencesToPreferencesStore(\n\t\tpersistence,\n\t\t'core/edit-post'\n\t);\n\tmigrateFeaturePreferencesToPreferencesStore(\n\t\tpersistence,\n\t\t'core/edit-site'\n\t);\n\tmigrateThirdPartyFeaturePreferencesToPreferencesStore( persistence );\n\n\t// Other ad-hoc preferences.\n\tmigrateIndividualPreferenceToPreferencesStore(\n\t\tpersistence,\n\t\t{ from: 'core/edit-post', scope: 'core/edit-post' },\n\t\t'hiddenBlockTypes'\n\t);\n\tmigrateIndividualPreferenceToPreferencesStore(\n\t\tpersistence,\n\t\t{ from: 'core/edit-post', scope: 'core/edit-post' },\n\t\t'editorMode'\n\t);\n\tmigrateIndividualPreferenceToPreferencesStore(\n\t\tpersistence,\n\t\t{ from: 'core/edit-post', scope: 'core/edit-post' },\n\t\t'preferredStyleVariations'\n\t);\n\tmigrateIndividualPreferenceToPreferencesStore(\n\t\tpersistence,\n\t\t{ from: 'core/edit-post', scope: 'core/edit-post' },\n\t\t'panels',\n\t\tconvertEditPostPanels\n\t);\n\tmigrateIndividualPreferenceToPreferencesStore(\n\t\tpersistence,\n\t\t{ from: 'core/editor', scope: 'core/edit-post' },\n\t\t'isPublishSidebarEnabled'\n\t);\n\tmigrateIndividualPreferenceToPreferencesStore(\n\t\tpersistence,\n\t\t{ from: 'core/edit-site', scope: 'core/edit-site' },\n\t\t'editorMode'\n\t);\n\tmigrateInterfaceEnableItemsToPreferencesStore( persistence );\n};\n\nexport default persistencePlugin;\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/data/src/plugins/persistence/index.js"],"names":["DEFAULT_STORAGE","defaultStorage","DEFAULT_STORAGE_KEY","withLazySameState","reducer","state","action","nextState","createPersistenceInterface","options","storage","storageKey","data","getData","undefined","persisted","getItem","JSON","parse","error","setData","key","value","setItem","stringify","get","set","persistencePlugin","registry","pluginOptions","persistence","createPersistOnChange","getState","storeName","keys","getPersistedState","Array","isArray","reducers","reduce","accumulator","Object","assign","lastState","registerStore","persist","persistedState","initialState","type","store","subscribe","__unstableMigrate"],"mappings":";;;;;;;;;;AAGA;;AAKA;;AACA;;AATA;AACA;AACA;;AAGA;AACA;AACA;;AAIA;;AAEA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA,MAAMA,eAAe,GAAGC,iBAAxB;AAEA;AACA;AACA;AACA;AACA;;AACA,MAAMC,mBAAmB,GAAG,SAA5B;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACO,MAAMC,iBAAiB,GAAKC,OAAF,IAAe,CAAEC,KAAF,EAASC,MAAT,KAAqB;AACpE,MAAKA,MAAM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AACoC,OAAf,EAAyB;AACxB,eAAOjB,QAAQ,CAACgB,aAAT,CAAwBX,SAAxB,EAAmCxB,OAAnC,CAAP;AACA,OAHkC,CAKnC;;;AACA,YAAMqC,cAAc,GAAGhB,WAAW,CAACL,GAAZ,GAAmBQ,SAAnB,CAAvB;;AACA,UAAKa,cAAc,KAAKhC,SAAxB,EAAoC;AACnC,YAAIiC,YAAY,GAAGtC,OAAO,CAACL,OAAR,CAAiBK,OAAO,CAACsC,YAAzB,EAAuC;AACzDC,UAAAA,IAAI,EAAE;AADmD,SAAvC,CAAnB;;AAIA,YACC,2BAAeD,YAAf,KACA,2BAAeD,cAAf,CAFD,EAGE;AACD;AACA;AACA;AACA;AACA;AACAC,UAAAA,YAAY,GAAG,mBAAO,EAAP,EAAWA,YAAX,EAAyBD,cAAzB,CAAf;AACA,SAVD,MAUO;AACN;AACA;AACAC,UAAAA,YAAY,GAAGD,cAAf;AACA;;AAEDrC,QAAAA,OAAO,GAAG,EACT,GAAGA,OADM;AAETsC,UAAAA;AAFS,SAAV;AAIA;;AAED,YAAME,KAAK,GAAGrB,QAAQ,CAACgB,aAAT,CAAwBX,SAAxB,EAAmCxB,OAAnC,CAAd;AAEAwC,MAAAA,KAAK,CAACC,SAAN,CACCnB,qBAAqB,CACpBkB,KAAK,CAACjB,QADc,EAEpBC,SAFoB,EAGpBxB,OAAO,CAACoC,OAHY,CADtB;AAQA,aAAOI,KAAP;AACA;;AA9CK,GAAP;AAgDA;;AAEDtB,iBAAiB,CAACwB,iBAAlB,GAAsC,MAAM,CAAE,CAA9C;;eAEexB,iB","sourcesContent":["/**\n * External dependencies\n */\nimport { merge, isPlainObject } from 'lodash';\n\n/**\n * Internal dependencies\n */\nimport defaultStorage from './storage/default';\nimport { combineReducers } from '../../';\n\n/** @typedef {import('../../registry').WPDataRegistry} WPDataRegistry */\n\n/** @typedef {import('../../registry').WPDataPlugin} WPDataPlugin */\n\n/**\n * @typedef {Object} WPDataPersistencePluginOptions Persistence plugin options.\n *\n * @property {Storage} storage Persistent storage implementation. This must\n * at least implement `getItem` and `setItem` of\n * the Web Storage API.\n * @property {string} storageKey Key on which to set in persistent storage.\n *\n */\n\n/**\n * Default plugin storage.\n *\n * @type {Storage}\n */\nconst DEFAULT_STORAGE = defaultStorage;\n\n/**\n * Default plugin storage key.\n *\n * @type {string}\n */\nconst DEFAULT_STORAGE_KEY = 'WP_DATA';\n\n/**\n * Higher-order reducer which invokes the original reducer only if state is\n * inequal from that of the action's `nextState` property, otherwise returning\n * the original state reference.\n *\n * @param {Function} reducer Original reducer.\n *\n * @return {Function} Enhanced reducer.\n */\nexport const withLazySameState = ( reducer ) => ( state, action ) => {\n\tif ( action.nextState === state ) {\n\t\treturn state;\n\t}\n\n\treturn reducer( state, action );\n};\n\n/**\n * Creates a persistence interface, exposing getter and setter methods (`get`\n * and `set` respectively).\n *\n * @param {WPDataPersistencePluginOptions} options Plugin options.\n *\n * @return {Object} Persistence interface.\n */\nexport function createPersistenceInterface( options ) {\n\tconst {\n\t\tstorage = DEFAULT_STORAGE,\n\t\tstorageKey = DEFAULT_STORAGE_KEY,\n\t} = options;\n\n\tlet data;\n\n\t/**\n\t * Returns the persisted data as an object, defaulting to an empty object.\n\t *\n\t * @return {Object} Persisted data.\n\t */\n\tfunction getData() {\n\t\tif ( data === undefined ) {\n\t\t\t// If unset, getItem is expected to return null. Fall back to\n\t\t\t// empty object.\n\t\t\tconst persisted = storage.getItem( storageKey );\n\t\t\tif ( persisted === null ) {\n\t\t\t\tdata = {};\n\t\t\t} else {\n\t\t\t\ttry {\n\t\t\t\t\tdata = JSON.parse( persisted );\n\t\t\t\t} catch ( error ) {\n\t\t\t\t\t// Similarly, should any error be thrown during parse of\n\t\t\t\t\t// the string (malformed JSON), fall back to empty object.\n\t\t\t\t\tdata = {};\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn data;\n\t}\n\n\t/**\n\t * Merges an updated reducer state into the persisted data.\n\t *\n\t * @param {string} key Key to update.\n\t * @param {*} value Updated value.\n\t */\n\tfunction setData( key, value ) {\n\t\tdata = { ...data, [ key ]: value };\n\t\tstorage.setItem( storageKey, JSON.stringify( data ) );\n\t}\n\n\treturn {\n\t\tget: getData,\n\t\tset: setData,\n\t};\n}\n\n/**\n * Data plugin to persist store state into a single storage key.\n *\n * @param {WPDataRegistry} registry Data registry.\n * @param {?WPDataPersistencePluginOptions} pluginOptions Plugin options.\n *\n * @return {WPDataPlugin} Data plugin.\n */\nfunction persistencePlugin( registry, pluginOptions ) {\n\tconst persistence = createPersistenceInterface( pluginOptions );\n\n\t/**\n\t * Creates an enhanced store dispatch function, triggering the state of the\n\t * given store name to be persisted when changed.\n\t *\n\t * @param {Function} getState Function which returns current state.\n\t * @param {string} storeName Store name.\n\t * @param {?Array<string>} keys Optional subset of keys to save.\n\t *\n\t * @return {Function} Enhanced dispatch function.\n\t */\n\tfunction createPersistOnChange( getState, storeName, keys ) {\n\t\tlet getPersistedState;\n\t\tif ( Array.isArray( keys ) ) {\n\t\t\t// Given keys, the persisted state should by produced as an object\n\t\t\t// of the subset of keys. This implementation uses combineReducers\n\t\t\t// to leverage its behavior of returning the same object when none\n\t\t\t// of the property values changes. This allows a strict reference\n\t\t\t// equality to bypass a persistence set on an unchanging state.\n\t\t\tconst reducers = keys.reduce(\n\t\t\t\t( accumulator, key ) =>\n\t\t\t\t\tObject.assign( accumulator, {\n\t\t\t\t\t\t[ key ]: ( state, action ) => action.nextState[ key ],\n\t\t\t\t\t} ),\n\t\t\t\t{}\n\t\t\t);\n\n\t\t\tgetPersistedState = withLazySameState(\n\t\t\t\tcombineReducers( reducers )\n\t\t\t);\n\t\t} else {\n\t\t\tgetPersistedState = ( state, action ) => action.nextState;\n\t\t}\n\n\t\tlet lastState = getPersistedState( undefined, {\n\t\t\tnextState: getState(),\n\t\t} );\n\n\t\treturn () => {\n\t\t\tconst state = getPersistedState( lastState, {\n\t\t\t\tnextState: getState(),\n\t\t\t} );\n\t\t\tif ( state !== lastState ) {\n\t\t\t\tpersistence.set( storeName, state );\n\t\t\t\tlastState = state;\n\t\t\t}\n\t\t};\n\t}\n\n\treturn {\n\t\tregisterStore( storeName, options ) {\n\t\t\tif ( ! options.persist ) {\n\t\t\t\treturn registry.registerStore( storeName, options );\n\t\t\t}\n\n\t\t\t// Load from persistence to use as initial state.\n\t\t\tconst persistedState = persistence.get()[ storeName ];\n\t\t\tif ( persistedState !== undefined ) {\n\t\t\t\tlet initialState = options.reducer( options.initialState, {\n\t\t\t\t\ttype: '@@WP/PERSISTENCE_RESTORE',\n\t\t\t\t} );\n\n\t\t\t\tif (\n\t\t\t\t\tisPlainObject( initialState ) &&\n\t\t\t\t\tisPlainObject( persistedState )\n\t\t\t\t) {\n\t\t\t\t\t// If state is an object, ensure that:\n\t\t\t\t\t// - Other keys are left intact when persisting only a\n\t\t\t\t\t// subset of keys.\n\t\t\t\t\t// - New keys in what would otherwise be used as initial\n\t\t\t\t\t// state are deeply merged as base for persisted value.\n\t\t\t\t\tinitialState = merge( {}, initialState, persistedState );\n\t\t\t\t} else {\n\t\t\t\t\t// If there is a mismatch in object-likeness of default\n\t\t\t\t\t// initial or persisted state, defer to persisted value.\n\t\t\t\t\tinitialState = persistedState;\n\t\t\t\t}\n\n\t\t\t\toptions = {\n\t\t\t\t\t...options,\n\t\t\t\t\tinitialState,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tconst store = registry.registerStore( storeName, options );\n\n\t\t\tstore.subscribe(\n\t\t\t\tcreatePersistOnChange(\n\t\t\t\t\tstore.getState,\n\t\t\t\t\tstoreName,\n\t\t\t\t\toptions.persist\n\t\t\t\t)\n\t\t\t);\n\n\t\t\treturn store;\n\t\t},\n\t};\n}\n\npersistencePlugin.__unstableMigrate = () => {};\n\nexport default persistencePlugin;\n"]}
|
|
@@ -174,12 +174,15 @@ function createReduxStore(key, options) {
|
|
|
174
174
|
}
|
|
175
175
|
|
|
176
176
|
const resolveSelectors = mapResolveSelectors(selectors, store);
|
|
177
|
+
const suspendSelectors = mapSuspendSelectors(selectors, store);
|
|
177
178
|
|
|
178
179
|
const getSelectors = () => selectors;
|
|
179
180
|
|
|
180
181
|
const getActions = () => actions;
|
|
181
182
|
|
|
182
|
-
const getResolveSelectors = () => resolveSelectors;
|
|
183
|
+
const getResolveSelectors = () => resolveSelectors;
|
|
184
|
+
|
|
185
|
+
const getSuspendSelectors = () => suspendSelectors; // We have some modules monkey-patching the store object
|
|
183
186
|
// It's wrong to do so but until we refactor all of our effects to controls
|
|
184
187
|
// We need to keep the same "store" instance here.
|
|
185
188
|
|
|
@@ -215,6 +218,7 @@ function createReduxStore(key, options) {
|
|
|
215
218
|
resolvers,
|
|
216
219
|
getSelectors,
|
|
217
220
|
getResolveSelectors,
|
|
221
|
+
getSuspendSelectors,
|
|
218
222
|
getActions,
|
|
219
223
|
subscribe
|
|
220
224
|
};
|
|
@@ -379,6 +383,49 @@ function mapResolveSelectors(selectors, store) {
|
|
|
379
383
|
};
|
|
380
384
|
});
|
|
381
385
|
}
|
|
386
|
+
/**
|
|
387
|
+
* Maps selectors to functions that throw a suspense promise if not yet resolved.
|
|
388
|
+
*
|
|
389
|
+
* @param {Object} selectors Selectors to map.
|
|
390
|
+
* @param {Object} store The redux store the selectors select from.
|
|
391
|
+
*
|
|
392
|
+
* @return {Object} Selectors mapped to their suspense functions.
|
|
393
|
+
*/
|
|
394
|
+
|
|
395
|
+
|
|
396
|
+
function mapSuspendSelectors(selectors, store) {
|
|
397
|
+
return (0, _lodash.mapValues)(selectors, (selector, selectorName) => {
|
|
398
|
+
// Selector without a resolver doesn't have any extra suspense behavior.
|
|
399
|
+
if (!selector.hasResolver) {
|
|
400
|
+
return selector;
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
return function () {
|
|
404
|
+
for (var _len5 = arguments.length, args = new Array(_len5), _key5 = 0; _key5 < _len5; _key5++) {
|
|
405
|
+
args[_key5] = arguments[_key5];
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
const result = selector.apply(null, args);
|
|
409
|
+
|
|
410
|
+
if (selectors.hasFinishedResolution(selectorName, args)) {
|
|
411
|
+
if (selectors.hasResolutionFailed(selectorName, args)) {
|
|
412
|
+
throw selectors.getResolutionError(selectorName, args);
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
return result;
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
throw new Promise(resolve => {
|
|
419
|
+
const unsubscribe = store.subscribe(() => {
|
|
420
|
+
if (selectors.hasFinishedResolution(selectorName, args)) {
|
|
421
|
+
resolve();
|
|
422
|
+
unsubscribe();
|
|
423
|
+
}
|
|
424
|
+
});
|
|
425
|
+
});
|
|
426
|
+
};
|
|
427
|
+
});
|
|
428
|
+
}
|
|
382
429
|
/**
|
|
383
430
|
* Returns resolvers with matched selectors for a given namespace.
|
|
384
431
|
* Resolvers are side effects invoked once per argument set of a given selector call,
|
|
@@ -416,8 +463,8 @@ function mapResolvers(resolvers, selectors, store, resolversCache) {
|
|
|
416
463
|
}
|
|
417
464
|
|
|
418
465
|
const selectorResolver = function () {
|
|
419
|
-
for (var
|
|
420
|
-
args[
|
|
466
|
+
for (var _len6 = arguments.length, args = new Array(_len6), _key6 = 0; _key6 < _len6; _key6++) {
|
|
467
|
+
args[_key6] = arguments[_key6];
|
|
421
468
|
}
|
|
422
469
|
|
|
423
470
|
async function fulfillSelector() {
|
|
@@ -479,8 +526,8 @@ async function fulfillResolver(store, resolvers, selectorName) {
|
|
|
479
526
|
return;
|
|
480
527
|
}
|
|
481
528
|
|
|
482
|
-
for (var
|
|
483
|
-
args[
|
|
529
|
+
for (var _len7 = arguments.length, args = new Array(_len7 > 3 ? _len7 - 3 : 0), _key7 = 3; _key7 < _len7; _key7++) {
|
|
530
|
+
args[_key7 - 3] = arguments[_key7];
|
|
484
531
|
}
|
|
485
532
|
|
|
486
533
|
const action = resolver.fulfill(...args);
|