@wordpress/data 6.5.0 → 6.7.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 +4 -0
- package/build/components/use-select/index.js +25 -32
- package/build/components/use-select/index.js.map +1 -1
- package/build/plugins/persistence/index.js +218 -13
- package/build/plugins/persistence/index.js.map +1 -1
- package/build/redux-store/index.js +42 -27
- package/build/redux-store/index.js.map +1 -1
- package/build/registry.js +10 -17
- package/build/registry.js.map +1 -1
- package/build-module/components/use-select/index.js +25 -32
- package/build-module/components/use-select/index.js.map +1 -1
- package/build-module/plugins/persistence/index.js +215 -14
- package/build-module/plugins/persistence/index.js.map +1 -1
- package/build-module/redux-store/index.js +42 -27
- package/build-module/redux-store/index.js.map +1 -1
- package/build-module/registry.js +10 -17
- package/build-module/registry.js.map +1 -1
- package/package.json +8 -8
- package/src/components/use-select/index.js +28 -36
- package/src/components/use-select/test/index.js +439 -265
- package/src/plugins/persistence/index.js +214 -19
- package/src/plugins/persistence/test/index.js +233 -3
- package/src/redux-store/index.js +23 -12
- package/src/redux-store/test/index.js +15 -5
- package/src/registry.js +10 -10
- package/src/test/registry.js +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* External dependencies
|
|
3
3
|
*/
|
|
4
|
-
import { merge, isPlainObject } from 'lodash';
|
|
4
|
+
import { merge, isPlainObject, identity } from 'lodash';
|
|
5
5
|
/**
|
|
6
6
|
* Internal dependencies
|
|
7
7
|
*/
|
|
@@ -277,29 +277,50 @@ export function migrateFeaturePreferencesToPreferencesStore(persistence, sourceS
|
|
|
277
277
|
}
|
|
278
278
|
}
|
|
279
279
|
}
|
|
280
|
-
|
|
280
|
+
/**
|
|
281
|
+
* Migrates an individual item inside the `preferences` object for a store.
|
|
282
|
+
*
|
|
283
|
+
* @param {Object} persistence The persistence interface.
|
|
284
|
+
* @param {Object} migrate An options object that contains details of the migration.
|
|
285
|
+
* @param {string} migrate.from The name of the store to migrate from.
|
|
286
|
+
* @param {string} migrate.scope The scope in the preferences store to migrate to.
|
|
287
|
+
* @param {string} key The key in the preferences object to migrate.
|
|
288
|
+
* @param {?Function} convert A function that converts preferences from one format to another.
|
|
289
|
+
*/
|
|
290
|
+
|
|
291
|
+
export function migrateIndividualPreferenceToPreferencesStore(persistence, _ref, key) {
|
|
281
292
|
var _state$sourceStoreNam4, _state$sourceStoreNam5, _state$preferencesSto2, _state$preferencesSto3, _state$preferencesSto4, _state$preferencesSto5, _state$preferencesSto6, _state$preferencesSto7, _state$sourceStoreNam6;
|
|
282
293
|
|
|
294
|
+
let {
|
|
295
|
+
from: sourceStoreName,
|
|
296
|
+
scope
|
|
297
|
+
} = _ref;
|
|
298
|
+
let convert = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : identity;
|
|
283
299
|
const preferencesStoreName = 'core/preferences';
|
|
284
300
|
const state = persistence.get();
|
|
285
301
|
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.
|
|
286
302
|
|
|
287
|
-
if (
|
|
303
|
+
if (sourcePreference === undefined) {
|
|
288
304
|
return;
|
|
289
305
|
}
|
|
290
306
|
|
|
291
|
-
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[
|
|
307
|
+
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.
|
|
292
308
|
|
|
293
309
|
if (targetPreference) {
|
|
294
310
|
return;
|
|
295
311
|
}
|
|
296
312
|
|
|
297
|
-
const
|
|
298
|
-
const
|
|
313
|
+
const otherScopes = (_state$preferencesSto5 = state[preferencesStoreName]) === null || _state$preferencesSto5 === void 0 ? void 0 : _state$preferencesSto5.preferences;
|
|
314
|
+
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
|
|
315
|
+
// function to convert to a data structure that has different keys.
|
|
316
|
+
|
|
317
|
+
const convertedPreferences = convert({
|
|
318
|
+
[key]: sourcePreference
|
|
319
|
+
});
|
|
299
320
|
persistence.set(preferencesStoreName, {
|
|
300
|
-
preferences: { ...
|
|
301
|
-
[
|
|
302
|
-
|
|
321
|
+
preferences: { ...otherScopes,
|
|
322
|
+
[scope]: { ...otherPreferences,
|
|
323
|
+
...convertedPreferences
|
|
303
324
|
}
|
|
304
325
|
}
|
|
305
326
|
}); // Remove migrated feature preferences from the source.
|
|
@@ -312,6 +333,59 @@ export function migrateIndividualPreferenceToPreferencesStore(persistence, sourc
|
|
|
312
333
|
}
|
|
313
334
|
});
|
|
314
335
|
}
|
|
336
|
+
/**
|
|
337
|
+
* Convert from:
|
|
338
|
+
* ```
|
|
339
|
+
* {
|
|
340
|
+
* panels: {
|
|
341
|
+
* tags: {
|
|
342
|
+
* enabled: true,
|
|
343
|
+
* opened: true,
|
|
344
|
+
* },
|
|
345
|
+
* permalinks: {
|
|
346
|
+
* enabled: false,
|
|
347
|
+
* opened: false,
|
|
348
|
+
* },
|
|
349
|
+
* },
|
|
350
|
+
* }
|
|
351
|
+
* ```
|
|
352
|
+
*
|
|
353
|
+
* to:
|
|
354
|
+
* {
|
|
355
|
+
* inactivePanels: [
|
|
356
|
+
* 'permalinks',
|
|
357
|
+
* ],
|
|
358
|
+
* openPanels: [
|
|
359
|
+
* 'tags',
|
|
360
|
+
* ],
|
|
361
|
+
* }
|
|
362
|
+
*
|
|
363
|
+
* @param {Object} preferences A preferences object.
|
|
364
|
+
*
|
|
365
|
+
* @return {Object} The converted data.
|
|
366
|
+
*/
|
|
367
|
+
|
|
368
|
+
export function convertEditPostPanels(preferences) {
|
|
369
|
+
var _preferences$panels;
|
|
370
|
+
|
|
371
|
+
const panels = (_preferences$panels = preferences === null || preferences === void 0 ? void 0 : preferences.panels) !== null && _preferences$panels !== void 0 ? _preferences$panels : {};
|
|
372
|
+
return Object.keys(panels).reduce((convertedData, panelName) => {
|
|
373
|
+
const panel = panels[panelName];
|
|
374
|
+
|
|
375
|
+
if ((panel === null || panel === void 0 ? void 0 : panel.enabled) === false) {
|
|
376
|
+
convertedData.inactivePanels.push(panelName);
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
if ((panel === null || panel === void 0 ? void 0 : panel.opened) === true) {
|
|
380
|
+
convertedData.openPanels.push(panelName);
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
return convertedData;
|
|
384
|
+
}, {
|
|
385
|
+
inactivePanels: [],
|
|
386
|
+
openPanels: []
|
|
387
|
+
});
|
|
388
|
+
}
|
|
315
389
|
export function migrateThirdPartyFeaturePreferencesToPreferencesStore(persistence) {
|
|
316
390
|
var _state$interfaceStore6, _state$interfaceStore7;
|
|
317
391
|
|
|
@@ -326,7 +400,7 @@ export function migrateThirdPartyFeaturePreferencesToPreferencesStore(persistenc
|
|
|
326
400
|
// Don't migrate any core 'scopes'.
|
|
327
401
|
if (scope.startsWith('core')) {
|
|
328
402
|
continue;
|
|
329
|
-
} // Skip this scope if there are no features to
|
|
403
|
+
} // Skip this scope if there are no features to migrate.
|
|
330
404
|
|
|
331
405
|
|
|
332
406
|
const featuresToMigrate = interfaceScopes[scope];
|
|
@@ -357,6 +431,112 @@ export function migrateThirdPartyFeaturePreferencesToPreferencesStore(persistenc
|
|
|
357
431
|
});
|
|
358
432
|
}
|
|
359
433
|
}
|
|
434
|
+
/**
|
|
435
|
+
* Migrates interface 'enableItems' data to the preferences store.
|
|
436
|
+
*
|
|
437
|
+
* The interface package stores this data in this format:
|
|
438
|
+
* ```js
|
|
439
|
+
* {
|
|
440
|
+
* enableItems: {
|
|
441
|
+
* singleEnableItems: {
|
|
442
|
+
* complementaryArea: {
|
|
443
|
+
* 'core/edit-post': 'edit-post/document',
|
|
444
|
+
* 'core/edit-site': 'edit-site/global-styles',
|
|
445
|
+
* }
|
|
446
|
+
* },
|
|
447
|
+
* multipleEnableItems: {
|
|
448
|
+
* pinnedItems: {
|
|
449
|
+
* 'core/edit-post': {
|
|
450
|
+
* 'plugin-1': true,
|
|
451
|
+
* },
|
|
452
|
+
* 'core/edit-site': {
|
|
453
|
+
* 'plugin-2': true,
|
|
454
|
+
* },
|
|
455
|
+
* },
|
|
456
|
+
* }
|
|
457
|
+
* }
|
|
458
|
+
* }
|
|
459
|
+
* ```
|
|
460
|
+
* and it should be migrated it to:
|
|
461
|
+
* ```js
|
|
462
|
+
* {
|
|
463
|
+
* 'core/edit-post': {
|
|
464
|
+
* complementaryArea: 'edit-post/document',
|
|
465
|
+
* pinnedItems: {
|
|
466
|
+
* 'plugin-1': true,
|
|
467
|
+
* },
|
|
468
|
+
* },
|
|
469
|
+
* 'core/edit-site': {
|
|
470
|
+
* complementaryArea: 'edit-site/global-styles',
|
|
471
|
+
* pinnedItems: {
|
|
472
|
+
* 'plugin-2': true,
|
|
473
|
+
* },
|
|
474
|
+
* },
|
|
475
|
+
* }
|
|
476
|
+
* ```
|
|
477
|
+
*
|
|
478
|
+
* @param {Object} persistence The persistence interface.
|
|
479
|
+
*/
|
|
480
|
+
|
|
481
|
+
export function migrateInterfaceEnableItemsToPreferencesStore(persistence) {
|
|
482
|
+
var _state$interfaceStore10, _state$preferencesSto9, _state$preferencesSto10, _sourceEnableItems$si, _sourceEnableItems$si2, _sourceEnableItems$mu, _sourceEnableItems$mu2;
|
|
483
|
+
|
|
484
|
+
const interfaceStoreName = 'core/interface';
|
|
485
|
+
const preferencesStoreName = 'core/preferences';
|
|
486
|
+
const state = persistence.get();
|
|
487
|
+
const sourceEnableItems = (_state$interfaceStore10 = state[interfaceStoreName]) === null || _state$interfaceStore10 === void 0 ? void 0 : _state$interfaceStore10.enableItems; // There's nothing to migrate, exit early.
|
|
488
|
+
|
|
489
|
+
if (!sourceEnableItems) {
|
|
490
|
+
return;
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
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.
|
|
494
|
+
// Use the existing preferences as the accumulator so that the data is
|
|
495
|
+
// merged.
|
|
496
|
+
|
|
497
|
+
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 : {};
|
|
498
|
+
const convertedComplementaryAreas = Object.keys(sourceComplementaryAreas).reduce((accumulator, scope) => {
|
|
499
|
+
var _accumulator$scope;
|
|
500
|
+
|
|
501
|
+
const data = sourceComplementaryAreas[scope]; // Don't overwrite any existing data in the preferences store.
|
|
502
|
+
|
|
503
|
+
if ((_accumulator$scope = accumulator[scope]) !== null && _accumulator$scope !== void 0 && _accumulator$scope.complementaryArea) {
|
|
504
|
+
return accumulator;
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
return { ...accumulator,
|
|
508
|
+
[scope]: { ...accumulator[scope],
|
|
509
|
+
complementaryArea: data
|
|
510
|
+
}
|
|
511
|
+
};
|
|
512
|
+
}, allPreferences); // Next feed the converted complementary areas back into a reducer that
|
|
513
|
+
// converts the pinned items, resulting in the fully migrated data.
|
|
514
|
+
|
|
515
|
+
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 : {};
|
|
516
|
+
const allConvertedData = Object.keys(sourcePinnedItems).reduce((accumulator, scope) => {
|
|
517
|
+
var _accumulator$scope2;
|
|
518
|
+
|
|
519
|
+
const data = sourcePinnedItems[scope]; // Don't overwrite any existing data in the preferences store.
|
|
520
|
+
|
|
521
|
+
if ((_accumulator$scope2 = accumulator[scope]) !== null && _accumulator$scope2 !== void 0 && _accumulator$scope2.pinnedItems) {
|
|
522
|
+
return accumulator;
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
return { ...accumulator,
|
|
526
|
+
[scope]: { ...accumulator[scope],
|
|
527
|
+
pinnedItems: data
|
|
528
|
+
}
|
|
529
|
+
};
|
|
530
|
+
}, convertedComplementaryAreas);
|
|
531
|
+
persistence.set(preferencesStoreName, {
|
|
532
|
+
preferences: allConvertedData
|
|
533
|
+
}); // Remove migrated preferences.
|
|
534
|
+
|
|
535
|
+
const otherInterfaceItems = state[interfaceStoreName];
|
|
536
|
+
persistence.set(interfaceStoreName, { ...otherInterfaceItems,
|
|
537
|
+
enableItems: undefined
|
|
538
|
+
});
|
|
539
|
+
}
|
|
360
540
|
|
|
361
541
|
persistencePlugin.__unstableMigrate = pluginOptions => {
|
|
362
542
|
const persistence = createPersistenceInterface(pluginOptions); // Boolean feature preferences.
|
|
@@ -367,10 +547,31 @@ persistencePlugin.__unstableMigrate = pluginOptions => {
|
|
|
367
547
|
migrateFeaturePreferencesToPreferencesStore(persistence, 'core/edit-site');
|
|
368
548
|
migrateThirdPartyFeaturePreferencesToPreferencesStore(persistence); // Other ad-hoc preferences.
|
|
369
549
|
|
|
370
|
-
migrateIndividualPreferenceToPreferencesStore(persistence,
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
550
|
+
migrateIndividualPreferenceToPreferencesStore(persistence, {
|
|
551
|
+
from: 'core/edit-post',
|
|
552
|
+
scope: 'core/edit-post'
|
|
553
|
+
}, 'hiddenBlockTypes');
|
|
554
|
+
migrateIndividualPreferenceToPreferencesStore(persistence, {
|
|
555
|
+
from: 'core/edit-post',
|
|
556
|
+
scope: 'core/edit-post'
|
|
557
|
+
}, 'editorMode');
|
|
558
|
+
migrateIndividualPreferenceToPreferencesStore(persistence, {
|
|
559
|
+
from: 'core/edit-post',
|
|
560
|
+
scope: 'core/edit-post'
|
|
561
|
+
}, 'preferredStyleVariations');
|
|
562
|
+
migrateIndividualPreferenceToPreferencesStore(persistence, {
|
|
563
|
+
from: 'core/edit-post',
|
|
564
|
+
scope: 'core/edit-post'
|
|
565
|
+
}, 'panels', convertEditPostPanels);
|
|
566
|
+
migrateIndividualPreferenceToPreferencesStore(persistence, {
|
|
567
|
+
from: 'core/editor',
|
|
568
|
+
scope: 'core/edit-post'
|
|
569
|
+
}, 'isPublishSidebarEnabled');
|
|
570
|
+
migrateIndividualPreferenceToPreferencesStore(persistence, {
|
|
571
|
+
from: 'core/edit-site',
|
|
572
|
+
scope: 'core/edit-site'
|
|
573
|
+
}, 'editorMode');
|
|
574
|
+
migrateInterfaceEnableItemsToPreferencesStore(persistence);
|
|
374
575
|
};
|
|
375
576
|
|
|
376
577
|
export default persistencePlugin;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/data/src/plugins/persistence/index.js"],"names":["merge","isPlainObject","defaultStorage","combineReducers","DEFAULT_STORAGE","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","sourcePreference","targetPreference","allPreferences","targetPreferences","allSourcePreferences","migrateThirdPartyFeaturePreferencesToPreferencesStore","interfaceScopes","scope","startsWith","__unstableMigrate"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,KAAT,EAAgBC,aAAhB,QAAqC,QAArC;AAEA;AACA;AACA;;AACA,OAAOC,cAAP,MAA2B,mBAA3B;AACA,SAASC,eAAT,QAAgC,QAAhC;AAEA;;AAEA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AACA,MAAMC,eAAe,GAAGF,cAAxB;AAEA;AACA;AACA;AACA;AACA;;AACA,MAAMG,mBAAmB,GAAG,SAA5B;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMC,iBAAiB,GAAKC,OAAF,IAAe,CAAEC,KAAF,EAASC,MAAT,KAAqB;AACpE,MAAKA,MAAM,CAACC,SAAP,KAAqBF,KAA1B,EAAkC;AACjC,WAAOA,KAAP;AACA;;AAED,SAAOD,OAAO,CAAEC,KAAF,EAASC,MAAT,CAAd;AACA,CANM;AAQP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASE,0BAAT,CAAqCC,OAArC,EAA+C;AACrD,QAAM;AACLC,IAAAA,OAAO,GAAGT,eADL;AAELU,IAAAA,UAAU,GAAGT;AAF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C;AASA;AACD;;AAEDa,iBAAiB,CAACgD,iBAAlB,GAAwC9C,aAAF,IAAqB;AAC1D,QAAMC,WAAW,GAAGtB,0BAA0B,CAAEqB,aAAF,CAA9C,CAD0D,CAG1D;;AACAsB,EAAAA,2CAA2C,CAC1CrB,WAD0C,EAE1C,mBAF0C,CAA3C;AAIAqB,EAAAA,2CAA2C,CAC1CrB,WAD0C,EAE1C,wBAF0C,CAA3C;AAIAqB,EAAAA,2CAA2C,CAC1CrB,WAD0C,EAE1C,gBAF0C,CAA3C;AAIAqB,EAAAA,2CAA2C,CAC1CrB,WAD0C,EAE1C,gBAF0C,CAA3C;AAIAyC,EAAAA,qDAAqD,CAAEzC,WAAF,CAArD,CApB0D,CAsB1D;;AACAmC,EAAAA,6CAA6C,CAC5CnC,WAD4C,EAE5C,gBAF4C,EAG5C,kBAH4C,CAA7C;AAKAmC,EAAAA,6CAA6C,CAC5CnC,WAD4C,EAE5C,gBAF4C,EAG5C,YAH4C,CAA7C;AAKAmC,EAAAA,6CAA6C,CAC5CnC,WAD4C,EAE5C,gBAF4C,EAG5C,0BAH4C,CAA7C;AAKAmC,EAAAA,6CAA6C,CAC5CnC,WAD4C,EAE5C,gBAF4C,EAG5C,YAH4C,CAA7C;AAKA,CA3CD;;AA6CA,eAAeH,iBAAf","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\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\nexport function migrateIndividualPreferenceToPreferencesStore(\n\tpersistence,\n\tsourceStoreName,\n\tkey\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 ) {\n\t\treturn;\n\t}\n\n\tconst targetPreference =\n\t\tstate[ preferencesStoreName ]?.preferences?.[ sourceStoreName ]?.[\n\t\t\tkey\n\t\t];\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 allPreferences = state[ preferencesStoreName ]?.preferences;\n\tconst targetPreferences =\n\t\tstate[ preferencesStoreName ]?.preferences?.[ sourceStoreName ];\n\n\tpersistence.set( preferencesStoreName, {\n\t\tpreferences: {\n\t\t\t...allPreferences,\n\t\t\t[ sourceStoreName ]: {\n\t\t\t\t...targetPreferences,\n\t\t\t\t[ key ]: sourcePreference,\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\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 migrates\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\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'core/edit-post',\n\t\t'hiddenBlockTypes'\n\t);\n\tmigrateIndividualPreferenceToPreferencesStore(\n\t\tpersistence,\n\t\t'core/edit-post',\n\t\t'editorMode'\n\t);\n\tmigrateIndividualPreferenceToPreferencesStore(\n\t\tpersistence,\n\t\t'core/edit-post',\n\t\t'preferredStyleVariations'\n\t);\n\tmigrateIndividualPreferenceToPreferencesStore(\n\t\tpersistence,\n\t\t'core/edit-site',\n\t\t'editorMode'\n\t);\n};\n\nexport default persistencePlugin;\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/data/src/plugins/persistence/index.js"],"names":["merge","isPlainObject","identity","defaultStorage","combineReducers","DEFAULT_STORAGE","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","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":"AAAA;AACA;AACA;AACA,SAASA,KAAT,EAAgBC,aAAhB,EAA+BC,QAA/B,QAA+C,QAA/C;AAEA;AACA;AACA;;AACA,OAAOC,cAAP,MAA2B,mBAA3B;AACA,SAASC,eAAT,QAAgC,QAAhC;AA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,EAE5C;AAAEoC,IAAAA,IAAI,EAAE,gBAAR;AAA0BC,IAAAA,KAAK,EAAE;AAAjC,GAF4C,EAG5C,QAH4C,EAI5CQ,qBAJ4C,CAA7C;AAMAV,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;AAKAqB,EAAAA,6CAA6C,CAAE1D,WAAF,CAA7C;AACA,CAvDD;;AAyDA,eAAeH,iBAAf","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"]}
|
|
@@ -301,41 +301,56 @@ function mapActions(actions, store) {
|
|
|
301
301
|
|
|
302
302
|
|
|
303
303
|
function mapResolveSelectors(selectors, store) {
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
304
|
+
const storeSelectors = omit(selectors, ['getIsResolving', 'hasStartedResolution', 'hasFinishedResolution', 'hasResolutionFailed', 'isResolving', 'getCachedResolvers', 'getResolutionState', 'getResolutionError']);
|
|
305
|
+
return mapValues(storeSelectors, (selector, selectorName) => {
|
|
306
|
+
// If the selector doesn't have a resolver, just convert the return value
|
|
307
|
+
// (including exceptions) to a Promise, no additional extra behavior is needed.
|
|
308
|
+
if (!selector.hasResolver) {
|
|
309
|
+
return async function () {
|
|
310
|
+
for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
|
|
311
|
+
args[_key3] = arguments[_key3];
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
return selector.apply(null, args);
|
|
315
|
+
};
|
|
307
316
|
}
|
|
308
317
|
|
|
309
|
-
return
|
|
310
|
-
|
|
318
|
+
return function () {
|
|
319
|
+
for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
|
|
320
|
+
args[_key4] = arguments[_key4];
|
|
321
|
+
}
|
|
311
322
|
|
|
312
|
-
|
|
313
|
-
const
|
|
323
|
+
return new Promise((resolve, reject) => {
|
|
324
|
+
const hasFinished = () => selectors.hasFinishedResolution(selectorName, args);
|
|
314
325
|
|
|
315
|
-
|
|
316
|
-
const
|
|
317
|
-
reject(error);
|
|
318
|
-
} else {
|
|
319
|
-
resolve(result);
|
|
320
|
-
}
|
|
321
|
-
};
|
|
326
|
+
const finalize = result => {
|
|
327
|
+
const hasFailed = selectors.hasResolutionFailed(selectorName, args);
|
|
322
328
|
|
|
323
|
-
|
|
329
|
+
if (hasFailed) {
|
|
330
|
+
const error = selectors.getResolutionError(selectorName, args);
|
|
331
|
+
reject(error);
|
|
332
|
+
} else {
|
|
333
|
+
resolve(result);
|
|
334
|
+
}
|
|
335
|
+
};
|
|
324
336
|
|
|
337
|
+
const getResult = () => selector.apply(null, args); // Trigger the selector (to trigger the resolver)
|
|
325
338
|
|
|
326
|
-
const result = getResult();
|
|
327
339
|
|
|
328
|
-
|
|
329
|
-
return finalize(result);
|
|
330
|
-
}
|
|
340
|
+
const result = getResult();
|
|
331
341
|
|
|
332
|
-
const unsubscribe = store.subscribe(() => {
|
|
333
342
|
if (hasFinished()) {
|
|
334
|
-
|
|
335
|
-
finalize(getResult());
|
|
343
|
+
return finalize(result);
|
|
336
344
|
}
|
|
345
|
+
|
|
346
|
+
const unsubscribe = store.subscribe(() => {
|
|
347
|
+
if (hasFinished()) {
|
|
348
|
+
unsubscribe();
|
|
349
|
+
finalize(getResult());
|
|
350
|
+
}
|
|
351
|
+
});
|
|
337
352
|
});
|
|
338
|
-
}
|
|
353
|
+
};
|
|
339
354
|
});
|
|
340
355
|
}
|
|
341
356
|
/**
|
|
@@ -375,8 +390,8 @@ function mapResolvers(resolvers, selectors, store, resolversCache) {
|
|
|
375
390
|
}
|
|
376
391
|
|
|
377
392
|
const selectorResolver = function () {
|
|
378
|
-
for (var
|
|
379
|
-
args[
|
|
393
|
+
for (var _len5 = arguments.length, args = new Array(_len5), _key5 = 0; _key5 < _len5; _key5++) {
|
|
394
|
+
args[_key5] = arguments[_key5];
|
|
380
395
|
}
|
|
381
396
|
|
|
382
397
|
async function fulfillSelector() {
|
|
@@ -438,8 +453,8 @@ async function fulfillResolver(store, resolvers, selectorName) {
|
|
|
438
453
|
return;
|
|
439
454
|
}
|
|
440
455
|
|
|
441
|
-
for (var
|
|
442
|
-
args[
|
|
456
|
+
for (var _len6 = arguments.length, args = new Array(_len6 > 3 ? _len6 - 3 : 0), _key6 = 3; _key6 < _len6; _key6++) {
|
|
457
|
+
args[_key6 - 3] = arguments[_key6];
|
|
443
458
|
}
|
|
444
459
|
|
|
445
460
|
const action = resolver.fulfill(...args);
|