@wordpress/edit-site 4.0.2 → 4.0.3-next.a55ed9455a.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (128) hide show
  1. package/build/components/app/index.js +20 -0
  2. package/build/components/app/index.js.map +1 -1
  3. package/build/components/editor/global-styles-renderer.js +7 -3
  4. package/build/components/editor/global-styles-renderer.js.map +1 -1
  5. package/build/components/editor/index.js +3 -18
  6. package/build/components/editor/index.js.map +1 -1
  7. package/build/components/global-styles/screen-block-list.js +31 -1
  8. package/build/components/global-styles/screen-block-list.js.map +1 -1
  9. package/build/components/global-styles/screen-typography.js.map +1 -1
  10. package/build/components/global-styles/utils.js +2 -2
  11. package/build/components/global-styles/utils.js.map +1 -1
  12. package/build/components/header/index.js +1 -1
  13. package/build/components/header/index.js.map +1 -1
  14. package/build/components/header/more-menu/index.js +9 -21
  15. package/build/components/header/more-menu/index.js.map +1 -1
  16. package/build/components/header/more-menu/site-export.js +1 -1
  17. package/build/components/header/more-menu/site-export.js.map +1 -1
  18. package/build/components/header/more-menu/welcome-guide-menu-item.js +4 -8
  19. package/build/components/header/more-menu/welcome-guide-menu-item.js.map +1 -1
  20. package/build/components/keyboard-shortcuts/index.js +1 -1
  21. package/build/components/keyboard-shortcuts/index.js.map +1 -1
  22. package/build/components/list/table.js +6 -19
  23. package/build/components/list/table.js.map +1 -1
  24. package/build/components/navigation-sidebar/navigation-panel/index.js +9 -3
  25. package/build/components/navigation-sidebar/navigation-panel/index.js.map +1 -1
  26. package/build/components/sidebar/global-styles-sidebar.js +5 -5
  27. package/build/components/sidebar/global-styles-sidebar.js.map +1 -1
  28. package/build/components/welcome-guide/editor.js +6 -6
  29. package/build/components/welcome-guide/editor.js.map +1 -1
  30. package/build/components/welcome-guide/styles.js +6 -4
  31. package/build/components/welcome-guide/styles.js.map +1 -1
  32. package/build/index.js +12 -11
  33. package/build/index.js.map +1 -1
  34. package/build/store/actions.js +38 -34
  35. package/build/store/actions.js.map +1 -1
  36. package/build/store/index.js +3 -6
  37. package/build/store/index.js.map +1 -1
  38. package/build/store/reducer.js +0 -44
  39. package/build/store/reducer.js.map +1 -1
  40. package/build/store/selectors.js +31 -9
  41. package/build/store/selectors.js.map +1 -1
  42. package/build-module/components/app/index.js +16 -0
  43. package/build-module/components/app/index.js.map +1 -1
  44. package/build-module/components/editor/global-styles-renderer.js +6 -3
  45. package/build-module/components/editor/global-styles-renderer.js.map +1 -1
  46. package/build-module/components/editor/index.js +4 -17
  47. package/build-module/components/editor/index.js.map +1 -1
  48. package/build-module/components/global-styles/screen-block-list.js +31 -2
  49. package/build-module/components/global-styles/screen-block-list.js.map +1 -1
  50. package/build-module/components/global-styles/screen-typography.js.map +1 -1
  51. package/build-module/components/global-styles/utils.js +2 -2
  52. package/build-module/components/global-styles/utils.js.map +1 -1
  53. package/build-module/components/header/index.js +1 -1
  54. package/build-module/components/header/index.js.map +1 -1
  55. package/build-module/components/header/more-menu/index.js +11 -22
  56. package/build-module/components/header/more-menu/index.js.map +1 -1
  57. package/build-module/components/header/more-menu/site-export.js +1 -1
  58. package/build-module/components/header/more-menu/site-export.js.map +1 -1
  59. package/build-module/components/header/more-menu/welcome-guide-menu-item.js +4 -8
  60. package/build-module/components/header/more-menu/welcome-guide-menu-item.js.map +1 -1
  61. package/build-module/components/keyboard-shortcuts/index.js +1 -1
  62. package/build-module/components/keyboard-shortcuts/index.js.map +1 -1
  63. package/build-module/components/list/table.js +7 -20
  64. package/build-module/components/list/table.js.map +1 -1
  65. package/build-module/components/navigation-sidebar/navigation-panel/index.js +9 -3
  66. package/build-module/components/navigation-sidebar/navigation-panel/index.js.map +1 -1
  67. package/build-module/components/sidebar/global-styles-sidebar.js +4 -4
  68. package/build-module/components/sidebar/global-styles-sidebar.js.map +1 -1
  69. package/build-module/components/welcome-guide/editor.js +5 -5
  70. package/build-module/components/welcome-guide/editor.js.map +1 -1
  71. package/build-module/components/welcome-guide/styles.js +5 -4
  72. package/build-module/components/welcome-guide/styles.js.map +1 -1
  73. package/build-module/index.js +11 -10
  74. package/build-module/index.js.map +1 -1
  75. package/build-module/store/actions.js +36 -34
  76. package/build-module/store/actions.js.map +1 -1
  77. package/build-module/store/index.js +4 -7
  78. package/build-module/store/index.js.map +1 -1
  79. package/build-module/store/reducer.js +0 -40
  80. package/build-module/store/reducer.js.map +1 -1
  81. package/build-module/store/selectors.js +26 -9
  82. package/build-module/store/selectors.js.map +1 -1
  83. package/build-style/style-rtl.css +90 -28
  84. package/build-style/style.css +90 -28
  85. package/package.json +33 -27
  86. package/src/components/app/index.js +19 -0
  87. package/src/components/editor/global-styles-renderer.js +7 -1
  88. package/src/components/editor/index.js +2 -20
  89. package/src/components/global-styles/screen-block-list.js +27 -2
  90. package/src/components/global-styles/screen-typography.js +1 -2
  91. package/src/components/global-styles/utils.js +2 -2
  92. package/src/components/header/index.js +1 -1
  93. package/src/components/header/more-menu/index.js +12 -29
  94. package/src/components/header/more-menu/site-export.js +1 -1
  95. package/src/components/header/more-menu/welcome-guide-menu-item.js +3 -7
  96. package/src/components/keyboard-shortcuts/index.js +1 -1
  97. package/src/components/list/table.js +13 -21
  98. package/src/components/navigation-sidebar/navigation-panel/index.js +16 -11
  99. package/src/components/navigation-sidebar/navigation-toggle/test/index.js +1 -1
  100. package/src/components/sidebar/global-styles-sidebar.js +6 -3
  101. package/src/components/sidebar/style.scss +1 -1
  102. package/src/components/welcome-guide/editor.js +8 -4
  103. package/src/components/welcome-guide/styles.js +5 -3
  104. package/src/index.js +12 -10
  105. package/src/store/actions.js +22 -13
  106. package/src/store/index.js +2 -6
  107. package/src/store/reducer.js +0 -30
  108. package/src/store/selectors.js +34 -10
  109. package/src/store/test/actions.js +17 -0
  110. package/src/store/test/reducer.js +0 -22
  111. package/src/store/test/selectors.js +14 -52
  112. package/src/style.scss +0 -1
  113. package/build/components/header/feature-toggle/index.js +0 -66
  114. package/build/components/header/feature-toggle/index.js.map +0 -1
  115. package/build/components/routes/redirect-to-homepage.js +0 -106
  116. package/build/components/routes/redirect-to-homepage.js.map +0 -1
  117. package/build/store/defaults.js +0 -15
  118. package/build/store/defaults.js.map +0 -1
  119. package/build-module/components/header/feature-toggle/index.js +0 -52
  120. package/build-module/components/header/feature-toggle/index.js.map +0 -1
  121. package/build-module/components/routes/redirect-to-homepage.js +0 -94
  122. package/build-module/components/routes/redirect-to-homepage.js.map +0 -1
  123. package/build-module/store/defaults.js +0 -8
  124. package/build-module/store/defaults.js.map +0 -1
  125. package/src/components/header/feature-toggle/index.js +0 -55
  126. package/src/components/header/more-menu/style.scss +0 -29
  127. package/src/components/routes/redirect-to-homepage.js +0 -94
  128. package/src/store/defaults.js +0 -7
@@ -1,7 +1,8 @@
1
1
  /**
2
2
  * WordPress dependencies
3
3
  */
4
- import { getBlockTypes } from '@wordpress/blocks';
4
+ import { store as blocksStore } from '@wordpress/blocks';
5
+ import { useSelect } from '@wordpress/data';
5
6
  import { __ } from '@wordpress/i18n';
6
7
  import {
7
8
  FlexItem,
@@ -19,6 +20,29 @@ import { useHasTypographyPanel } from './typography-panel';
19
20
  import ScreenHeader from './header';
20
21
  import { NavigationButton } from './navigation-button';
21
22
 
23
+ function useSortedBlockTypes() {
24
+ const blockItems = useSelect(
25
+ ( select ) => select( blocksStore ).getBlockTypes(),
26
+ []
27
+ );
28
+ // Ensure core blocks are prioritized in the returned results,
29
+ // because third party blocks can be registered earlier than
30
+ // the core blocks (usually by using the `init` action),
31
+ // thus affecting the display order.
32
+ // We don't sort reusable blocks as they are handled differently.
33
+ const groupByType = ( blocks, block ) => {
34
+ const { core, noncore } = blocks;
35
+ const type = block.name.startsWith( 'core/' ) ? core : noncore;
36
+ type.push( block );
37
+ return blocks;
38
+ };
39
+ const {
40
+ core: coreItems,
41
+ noncore: nonCoreItems,
42
+ } = blockItems.reduce( groupByType, { core: [], noncore: [] } );
43
+ return [ ...coreItems, ...nonCoreItems ];
44
+ }
45
+
22
46
  function BlockMenuItem( { block } ) {
23
47
  const hasTypographyPanel = useHasTypographyPanel( block.name );
24
48
  const hasColorPanel = useHasColorPanel( block.name );
@@ -45,6 +69,7 @@ function BlockMenuItem( { block } ) {
45
69
  }
46
70
 
47
71
  function ScreenBlockList() {
72
+ const sortedBlockTypes = useSortedBlockTypes();
48
73
  return (
49
74
  <>
50
75
  <ScreenHeader
@@ -53,7 +78,7 @@ function ScreenBlockList() {
53
78
  'Customize the appearance of specific blocks and for the whole site.'
54
79
  ) }
55
80
  />
56
- { getBlockTypes().map( ( block ) => (
81
+ { sortedBlockTypes.map( ( block ) => (
57
82
  <BlockMenuItem
58
83
  block={ block }
59
84
  key={ 'menu-itemblock-' + block.name }
@@ -99,8 +99,7 @@ function ScreenTypography( { name } ) {
99
99
  </VStack>
100
100
  </div>
101
101
  ) }
102
-
103
- { /* no typography elements support yet for blocks */ }
102
+ { /* No typography elements support yet for blocks. */ }
104
103
  { !! name && <TypographyPanel name={ name } element="text" /> }
105
104
  </>
106
105
  );
@@ -3,7 +3,7 @@
3
3
  */
4
4
  import { get, find, isString } from 'lodash';
5
5
 
6
- /* Supporting data */
6
+ /* Supporting data. */
7
7
  export const ROOT_BLOCK_NAME = 'root';
8
8
  export const ROOT_BLOCK_SELECTOR = 'body';
9
9
  export const ROOT_BLOCK_SUPPORTS = [
@@ -103,7 +103,7 @@ function findInPresetsBy(
103
103
  if ( presetProperty === 'slug' ) {
104
104
  return presetObject;
105
105
  }
106
- // if there is a highest priority preset with the same slug but different value the preset we found was overwritten and should be ignored.
106
+ // If there is a highest priority preset with the same slug but different value the preset we found was overwritten and should be ignored.
107
107
  const highestPresetObjectWithSameSlug = findInPresetsBy(
108
108
  features,
109
109
  blockName,
@@ -91,7 +91,7 @@ export default function Header( {
91
91
 
92
92
  const openInserter = useCallback( () => {
93
93
  if ( isInserterOpen ) {
94
- // Focusing the inserter button closes the inserter popover
94
+ // Focusing the inserter button closes the inserter popover.
95
95
  inserterButton.current.focus();
96
96
  } else {
97
97
  setIsInserterOpened( true );
@@ -5,34 +5,21 @@ import { __, _x } from '@wordpress/i18n';
5
5
  import { useReducer } from '@wordpress/element';
6
6
  import { useShortcut } from '@wordpress/keyboard-shortcuts';
7
7
  import { displayShortcut } from '@wordpress/keycodes';
8
- import { external, moreVertical } from '@wordpress/icons';
9
- import {
10
- DropdownMenu,
11
- MenuGroup,
12
- MenuItem,
13
- VisuallyHidden,
14
- } from '@wordpress/components';
15
- import { ActionItem } from '@wordpress/interface';
8
+ import { external } from '@wordpress/icons';
9
+ import { MenuGroup, MenuItem, VisuallyHidden } from '@wordpress/components';
10
+ import { ActionItem, MoreMenuDropdown } from '@wordpress/interface';
11
+ import { PreferenceToggleMenuItem } from '@wordpress/preferences';
16
12
 
17
13
  /**
18
14
  * Internal dependencies
19
15
  */
20
16
  import KeyboardShortcutHelpModal from '../../keyboard-shortcut-help-modal';
21
- import FeatureToggle from '../feature-toggle';
22
17
  import ToolsMoreMenuGroup from '../tools-more-menu-group';
23
18
  import SiteExport from './site-export';
24
19
  import WelcomeGuideMenuItem from './welcome-guide-menu-item';
25
20
  import CopyContentMenuItem from './copy-content-menu-item';
26
21
  import ModeSwitcher from '../mode-switcher';
27
22
 
28
- const POPOVER_PROPS = {
29
- className: 'edit-site-more-menu__content',
30
- position: 'bottom left',
31
- };
32
- const TOGGLE_PROPS = {
33
- tooltipPosition: 'bottom',
34
- };
35
-
36
23
  export default function MoreMenu() {
37
24
  const [ isModalActive, toggleModal ] = useReducer(
38
25
  ( isActive ) => ! isActive,
@@ -43,18 +30,13 @@ export default function MoreMenu() {
43
30
 
44
31
  return (
45
32
  <>
46
- <DropdownMenu
47
- className="edit-site-more-menu"
48
- icon={ moreVertical }
49
- label={ __( 'More tools & options' ) }
50
- popoverProps={ POPOVER_PROPS }
51
- toggleProps={ TOGGLE_PROPS }
52
- >
33
+ <MoreMenuDropdown>
53
34
  { ( { onClose } ) => (
54
35
  <>
55
36
  <MenuGroup label={ _x( 'View', 'noun' ) }>
56
- <FeatureToggle
57
- feature="fixedToolbar"
37
+ <PreferenceToggleMenuItem
38
+ scope="core/edit-site"
39
+ name="fixedToolbar"
58
40
  label={ __( 'Top toolbar' ) }
59
41
  info={ __(
60
42
  'Access all block and document tools in a single place'
@@ -66,8 +48,9 @@ export default function MoreMenu() {
66
48
  'Top toolbar deactivated'
67
49
  ) }
68
50
  />
69
- <FeatureToggle
70
- feature="focusMode"
51
+ <PreferenceToggleMenuItem
52
+ scope="core/edit-site"
53
+ name="focusMode"
71
54
  label={ __( 'Spotlight mode' ) }
72
55
  info={ __( 'Focus on one block at a time' ) }
73
56
  messageActivated={ __(
@@ -118,7 +101,7 @@ export default function MoreMenu() {
118
101
  </MenuGroup>
119
102
  </>
120
103
  ) }
121
- </DropdownMenu>
104
+ </MoreMenuDropdown>
122
105
  <KeyboardShortcutHelpModal
123
106
  isModalActive={ isModalActive }
124
107
  toggleModal={ toggleModal }
@@ -44,7 +44,7 @@ export default function SiteExport() {
44
44
  role="menuitem"
45
45
  icon={ download }
46
46
  onClick={ handleExport }
47
- info={ __( 'Download your templates and template parts.' ) }
47
+ info={ __( 'Download your templates and styles as a theme.' ) }
48
48
  >
49
49
  { _x( 'Export', 'site exporter menu item' ) }
50
50
  </MenuItem>
@@ -4,17 +4,13 @@
4
4
  import { __ } from '@wordpress/i18n';
5
5
  import { useDispatch } from '@wordpress/data';
6
6
  import { MenuItem } from '@wordpress/components';
7
-
8
- /**
9
- * Internal dependencies
10
- */
11
- import { store as editSiteStore } from '../../../store';
7
+ import { store as preferencesStore } from '@wordpress/preferences';
12
8
 
13
9
  export default function WelcomeGuideMenuItem() {
14
- const { toggleFeature } = useDispatch( editSiteStore );
10
+ const { toggle } = useDispatch( preferencesStore );
15
11
 
16
12
  return (
17
- <MenuItem onClick={ () => toggleFeature( 'welcomeGuide' ) }>
13
+ <MenuItem onClick={ () => toggle( 'core/edit-site', 'welcomeGuide' ) }>
18
14
  { __( 'Welcome Guide' ) }
19
15
  </MenuItem>
20
16
  );
@@ -91,7 +91,7 @@ function KeyboardShortcuts( { openEntitiesSavedStates } ) {
91
91
  }
92
92
 
93
93
  function KeyboardShortcutsRegister() {
94
- // Registering the shortcuts
94
+ // Registering the shortcuts.
95
95
  const { registerShortcut } = useDispatch( keyboardShortcutsStore );
96
96
  useEffect( () => {
97
97
  registerShortcut( {
@@ -2,7 +2,10 @@
2
2
  * WordPress dependencies
3
3
  */
4
4
  import { useSelect } from '@wordpress/data';
5
- import { store as coreStore } from '@wordpress/core-data';
5
+ import {
6
+ store as coreStore,
7
+ __experimentalUseEntityRecords as useEntityRecords,
8
+ } from '@wordpress/core-data';
6
9
  import { __, sprintf } from '@wordpress/i18n';
7
10
  import {
8
11
  VisuallyHidden,
@@ -18,26 +21,15 @@ import Actions from './actions';
18
21
  import AddedBy from './added-by';
19
22
 
20
23
  export default function Table( { templateType } ) {
21
- const { templates, isLoading, postType } = useSelect(
22
- ( select ) => {
23
- const {
24
- getEntityRecords,
25
- hasFinishedResolution,
26
- getPostType,
27
- } = select( coreStore );
28
-
29
- return {
30
- templates: getEntityRecords( 'postType', templateType, {
31
- per_page: -1,
32
- } ),
33
- isLoading: ! hasFinishedResolution( 'getEntityRecords', [
34
- 'postType',
35
- templateType,
36
- { per_page: -1 },
37
- ] ),
38
- postType: getPostType( templateType ),
39
- };
40
- },
24
+ const { records: templates, isResolving: isLoading } = useEntityRecords(
25
+ 'postType',
26
+ templateType,
27
+ {
28
+ per_page: -1,
29
+ }
30
+ );
31
+ const postType = useSelect(
32
+ ( select ) => select( coreStore ).getPostType( templateType ),
41
33
  [ templateType ]
42
34
  );
43
35
 
@@ -40,17 +40,22 @@ function NavLink( { params, replace, ...props } ) {
40
40
  }
41
41
 
42
42
  const NavigationPanel = ( { activeItem = SITE_EDITOR_KEY } ) => {
43
- const { isNavigationOpen, siteTitle } = useSelect( ( select ) => {
44
- const { getEntityRecord } = select( coreDataStore );
43
+ const { homeTemplate, isNavigationOpen, siteTitle } = useSelect(
44
+ ( select ) => {
45
+ const { getEntityRecord } = select( coreDataStore );
46
+ const { getSettings, isNavigationOpened } = select( editSiteStore );
45
47
 
46
- const siteData =
47
- getEntityRecord( 'root', '__unstableBase', undefined ) || {};
48
+ const siteData =
49
+ getEntityRecord( 'root', '__unstableBase', undefined ) || {};
48
50
 
49
- return {
50
- siteTitle: siteData.name,
51
- isNavigationOpen: select( editSiteStore ).isNavigationOpened(),
52
- };
53
- }, [] );
51
+ return {
52
+ siteTitle: siteData.name,
53
+ homeTemplate: getSettings().__unstableHomeTemplate,
54
+ isNavigationOpen: isNavigationOpened(),
55
+ };
56
+ },
57
+ []
58
+ );
54
59
  const { setIsNavigationPanelOpened } = useDispatch( editSiteStore );
55
60
 
56
61
  const closeOnEscape = ( event ) => {
@@ -91,8 +96,8 @@ const NavigationPanel = ( { activeItem = SITE_EDITOR_KEY } ) => {
91
96
  title={ __( 'Site' ) }
92
97
  item={ SITE_EDITOR_KEY }
93
98
  params={ {
94
- postId: undefined,
95
- postType: undefined,
99
+ postId: homeTemplate?.postId,
100
+ postType: homeTemplate?.postType,
96
101
  } }
97
102
  />
98
103
  <NavLink
@@ -14,7 +14,7 @@ import { useSelect } from '@wordpress/data';
14
14
  import NavigationToggle from '..';
15
15
 
16
16
  jest.mock( '@wordpress/data/src/components/use-select', () => {
17
- // This allows us to tweak the returned value on each test
17
+ // This allows us to tweak the returned value on each test.
18
18
  const mock = jest.fn();
19
19
  return mock;
20
20
  } );
@@ -5,17 +5,17 @@ import { DropdownMenu, FlexItem, FlexBlock, Flex } from '@wordpress/components';
5
5
  import { __ } from '@wordpress/i18n';
6
6
  import { styles, moreVertical } from '@wordpress/icons';
7
7
  import { useDispatch } from '@wordpress/data';
8
+ import { store as preferencesStore } from '@wordpress/preferences';
8
9
 
9
10
  /**
10
11
  * Internal dependencies
11
12
  */
12
13
  import DefaultSidebar from './default-sidebar';
13
14
  import { GlobalStylesUI, useGlobalStylesReset } from '../global-styles';
14
- import { store as editSiteStore } from '../../store';
15
15
 
16
16
  export default function GlobalStylesSidebar() {
17
17
  const [ canReset, onReset ] = useGlobalStylesReset();
18
- const { toggleFeature } = useDispatch( editSiteStore );
18
+ const { toggle } = useDispatch( preferencesStore );
19
19
 
20
20
  return (
21
21
  <DefaultSidebar
@@ -46,7 +46,10 @@ export default function GlobalStylesSidebar() {
46
46
  {
47
47
  title: __( 'Welcome Guide' ),
48
48
  onClick: () =>
49
- toggleFeature( 'welcomeGuideStyles' ),
49
+ toggle(
50
+ 'core/edit-site',
51
+ 'welcomeGuideStyles'
52
+ ),
50
53
  },
51
54
  ] }
52
55
  />
@@ -20,7 +20,7 @@
20
20
  .edit-site-global-styles-sidebar {
21
21
  display: flex;
22
22
  flex-direction: column;
23
- height: 100%;
23
+ min-height: 100%;
24
24
 
25
25
  &__panel,
26
26
  &__navigator-provider {
@@ -5,18 +5,22 @@ import { useDispatch, useSelect } from '@wordpress/data';
5
5
  import { Guide } from '@wordpress/components';
6
6
  import { __ } from '@wordpress/i18n';
7
7
  import { createInterpolateElement } from '@wordpress/element';
8
+ import { store as preferencesStore } from '@wordpress/preferences';
8
9
 
9
10
  /**
10
11
  * Internal dependencies
11
12
  */
12
13
  import WelcomeGuideImage from './image';
13
- import { store as editSiteStore } from '../../store';
14
14
 
15
15
  export default function WelcomeGuideEditor() {
16
- const { toggleFeature } = useDispatch( editSiteStore );
16
+ const { toggle } = useDispatch( preferencesStore );
17
17
 
18
18
  const isActive = useSelect(
19
- ( select ) => select( editSiteStore ).isFeatureActive( 'welcomeGuide' ),
19
+ ( select ) =>
20
+ !! select( preferencesStore ).get(
21
+ 'core/edit-site',
22
+ 'welcomeGuide'
23
+ ),
20
24
  []
21
25
  );
22
26
 
@@ -29,7 +33,7 @@ export default function WelcomeGuideEditor() {
29
33
  className="edit-site-welcome-guide"
30
34
  contentLabel={ __( 'Welcome to the site editor' ) }
31
35
  finishButtonText={ __( 'Get Started' ) }
32
- onFinish={ () => toggleFeature( 'welcomeGuide' ) }
36
+ onFinish={ () => toggle( 'core/edit-site', 'welcomeGuide' ) }
33
37
  pages={ [
34
38
  {
35
39
  image: (
@@ -5,6 +5,7 @@ import { useDispatch, useSelect } from '@wordpress/data';
5
5
  import { ExternalLink, Guide } from '@wordpress/components';
6
6
  import { __ } from '@wordpress/i18n';
7
7
  import { store as interfaceStore } from '@wordpress/interface';
8
+ import { store as preferencesStore } from '@wordpress/preferences';
8
9
 
9
10
  /**
10
11
  * Internal dependencies
@@ -13,7 +14,7 @@ import WelcomeGuideImage from './image';
13
14
  import { store as editSiteStore } from '../../store';
14
15
 
15
16
  export default function WelcomeGuideStyles() {
16
- const { toggleFeature } = useDispatch( editSiteStore );
17
+ const { toggle } = useDispatch( preferencesStore );
17
18
 
18
19
  const { isActive, isStylesOpen } = useSelect( ( select ) => {
19
20
  const sidebar = select( interfaceStore ).getActiveComplementaryArea(
@@ -21,7 +22,8 @@ export default function WelcomeGuideStyles() {
21
22
  );
22
23
 
23
24
  return {
24
- isActive: select( editSiteStore ).isFeatureActive(
25
+ isActive: !! select( preferencesStore ).get(
26
+ 'core/edit-site',
25
27
  'welcomeGuideStyles'
26
28
  ),
27
29
  isStylesOpen: sidebar === 'edit-site/global-styles',
@@ -37,7 +39,7 @@ export default function WelcomeGuideStyles() {
37
39
  className="edit-site-welcome-guide"
38
40
  contentLabel={ __( 'Welcome to styles' ) }
39
41
  finishButtonText={ __( 'Get Started' ) }
40
- onFinish={ () => toggleFeature( 'welcomeGuideStyles' ) }
42
+ onFinish={ () => toggle( 'core/edit-site', 'welcomeGuideStyles' ) }
41
43
  pages={ [
42
44
  {
43
45
  image: (
package/src/index.js CHANGED
@@ -13,6 +13,7 @@ import {
13
13
  __experimentalFetchUrlData as fetchUrlData,
14
14
  } from '@wordpress/core-data';
15
15
  import { store as editorStore } from '@wordpress/editor';
16
+ import { store as preferencesStore } from '@wordpress/preferences';
16
17
  import { __ } from '@wordpress/i18n';
17
18
  import { store as viewportStore } from '@wordpress/viewport';
18
19
  import { getQueryArgs } from '@wordpress/url';
@@ -24,7 +25,6 @@ import './hooks';
24
25
  import { store as editSiteStore } from './store';
25
26
  import EditSiteApp from './components/app';
26
27
  import getIsListPage from './utils/get-is-list-page';
27
- import redirectToHomepage from './components/routes/redirect-to-homepage';
28
28
  import ErrorBoundaryWarning from './components/error-boundary/warning';
29
29
 
30
30
  /**
@@ -35,20 +35,14 @@ import ErrorBoundaryWarning from './components/error-boundary/warning';
35
35
  * @param {Element} target DOM node in which editor is rendered.
36
36
  * @param {?Object} settings Editor settings object.
37
37
  */
38
- export async function reinitializeEditor( target, settings ) {
39
- // The site editor relies on `postType` and `postId` params in the URL to
40
- // define what's being edited. When visiting via the dashboard link, these
41
- // won't be present. Do a client side redirect to the 'homepage' if that's
42
- // the case.
43
- try {
44
- await redirectToHomepage( settings.siteUrl );
45
- } catch ( error ) {
38
+ export function reinitializeEditor( target, settings ) {
39
+ // Display warning if editor wasn't able to resolve homepage template.
40
+ if ( ! settings.__unstableHomeTemplate ) {
46
41
  render(
47
42
  <ErrorBoundaryWarning
48
43
  message={ __(
49
44
  'The editor is unable to find a block template for the homepage.'
50
45
  ) }
51
- error={ error }
52
46
  dashboardLink="index.php"
53
47
  />,
54
48
  target
@@ -63,6 +57,14 @@ export async function reinitializeEditor( target, settings ) {
63
57
  // We dispatch actions and update the store synchronously before rendering
64
58
  // so that we won't trigger unnecessary re-renders with useEffect.
65
59
  {
60
+ dispatch( preferencesStore ).setDefaults( 'core/edit-site', {
61
+ editorMode: 'visual',
62
+ fixedToolbar: false,
63
+ focusMode: false,
64
+ welcomeGuide: true,
65
+ welcomeGuideStyles: true,
66
+ } );
67
+
66
68
  dispatch( editSiteStore ).updateSettings( settings );
67
69
 
68
70
  // Keep the defaultTemplateTypes in the core/editor settings too,
@@ -3,6 +3,7 @@
3
3
  */
4
4
  import apiFetch from '@wordpress/api-fetch';
5
5
  import { parse, __unstableSerializeAndClean } from '@wordpress/blocks';
6
+ import deprecated from '@wordpress/deprecated';
6
7
  import { addQueryArgs, getPathAndQueryString } from '@wordpress/url';
7
8
  import { __, sprintf } from '@wordpress/i18n';
8
9
  import { store as noticesStore } from '@wordpress/notices';
@@ -10,6 +11,7 @@ import { store as coreStore } from '@wordpress/core-data';
10
11
  import { store as interfaceStore } from '@wordpress/interface';
11
12
  import { store as blockEditorStore } from '@wordpress/block-editor';
12
13
  import { speak } from '@wordpress/a11y';
14
+ import { store as preferencesStore } from '@wordpress/preferences';
13
15
 
14
16
  /**
15
17
  * Internal dependencies
@@ -18,16 +20,21 @@ import { STORE_NAME as editSiteStoreName } from './constants';
18
20
  import isTemplateRevertable from '../utils/is-template-revertable';
19
21
 
20
22
  /**
21
- * Action that toggles a feature flag.
23
+ * Dispatches an action that toggles a feature flag.
22
24
  *
23
- * @param {string} feature Feature name.
24
- *
25
- * @return {Object} Action object.
25
+ * @param {string} featureName Feature name.
26
26
  */
27
- export function toggleFeature( feature ) {
28
- return {
29
- type: 'TOGGLE_FEATURE',
30
- feature,
27
+ export function toggleFeature( featureName ) {
28
+ return function ( { registry } ) {
29
+ deprecated( "select( 'core/edit-site' ).toggleFeature( featureName )", {
30
+ since: '6.0',
31
+ alternative:
32
+ "select( 'core/preferences').toggle( 'core/edit-site', featureName )",
33
+ } );
34
+
35
+ registry
36
+ .dispatch( preferencesStore )
37
+ .toggle( 'core/edit-site', featureName );
31
38
  };
32
39
  }
33
40
 
@@ -374,12 +381,12 @@ export const revertTemplate = (
374
381
  template.type,
375
382
  template.id,
376
383
  {
377
- content: serializeBlocks, // required to make the `undo` behave correctly
378
- blocks: edited.blocks, // required to revert the blocks in the editor
384
+ content: serializeBlocks, // Required to make the `undo` behave correctly.
385
+ blocks: edited.blocks, // Required to revert the blocks in the editor.
379
386
  source: 'custom', // required to avoid turning the editor into a dirty state
380
387
  },
381
388
  {
382
- undoIgnore: true, // required to merge this edit with the last undo level
389
+ undoIgnore: true, // Required to merge this edit with the last undo level.
383
390
  }
384
391
  );
385
392
 
@@ -449,8 +456,10 @@ export const closeGeneralSidebar = () => ( { registry } ) => {
449
456
  .disableComplementaryArea( editSiteStoreName );
450
457
  };
451
458
 
452
- export const switchEditorMode = ( mode ) => ( { dispatch, registry } ) => {
453
- dispatch( { type: 'SWITCH_MODE', mode } );
459
+ export const switchEditorMode = ( mode ) => ( { registry } ) => {
460
+ registry
461
+ .dispatch( 'core/preferences' )
462
+ .set( 'core/edit-site', 'editorMode', mode );
454
463
 
455
464
  // Unselect blocks when we switch to a non visual mode.
456
465
  if ( mode !== 'visual' ) {
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * WordPress dependencies
3
3
  */
4
- import { createReduxStore, registerStore } from '@wordpress/data';
4
+ import { createReduxStore, register } from '@wordpress/data';
5
5
 
6
6
  /**
7
7
  * Internal dependencies
@@ -15,11 +15,7 @@ export const storeConfig = {
15
15
  reducer,
16
16
  actions,
17
17
  selectors,
18
- persist: [ 'preferences' ],
19
18
  };
20
19
 
21
20
  export const store = createReduxStore( STORE_NAME, storeConfig );
22
-
23
- // Once we build a more generic persistence plugin that works across types of stores
24
- // we'd be able to replace this with a register call.
25
- registerStore( STORE_NAME, storeConfig );
21
+ register( store );
@@ -6,37 +6,8 @@ import { combineReducers } from '@wordpress/data';
6
6
  /**
7
7
  * Internal dependencies
8
8
  */
9
- import { PREFERENCES_DEFAULTS } from './defaults';
10
9
  import { MENU_ROOT } from '../components/navigation-sidebar/navigation-panel/constants';
11
10
 
12
- /**
13
- * Reducer returning the user preferences.
14
- *
15
- * @param {Object} state Current state.
16
- * @param {Object} action Dispatched action.
17
- * @return {Object} Updated state.
18
- */
19
- export const preferences = combineReducers( {
20
- features( state = PREFERENCES_DEFAULTS.features, action ) {
21
- switch ( action.type ) {
22
- case 'TOGGLE_FEATURE': {
23
- return {
24
- ...state,
25
- [ action.feature ]: ! state[ action.feature ],
26
- };
27
- }
28
- default:
29
- return state;
30
- }
31
- },
32
- editorMode( state = PREFERENCES_DEFAULTS.editorMode, action ) {
33
- if ( action.type === 'SWITCH_MODE' ) {
34
- return action.mode;
35
- }
36
- return state;
37
- },
38
- } );
39
-
40
11
  /**
41
12
  * Reducer returning the editing canvas device type.
42
13
  *
@@ -213,7 +184,6 @@ export function listViewPanel( state = false, action ) {
213
184
  }
214
185
 
215
186
  export default combineReducers( {
216
- preferences,
217
187
  deviceType,
218
188
  settings,
219
189
  editedPost,