@wordpress/edit-site 5.19.3 → 5.19.5

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 (66) hide show
  1. package/build/components/add-new-pattern/index.js +1 -1
  2. package/build/components/add-new-pattern/index.js.map +1 -1
  3. package/build/components/global-styles/font-library-modal/resolvers.js +1 -1
  4. package/build/components/global-styles/font-library-modal/resolvers.js.map +1 -1
  5. package/build/components/global-styles/font-library-modal/utils/index.js +1 -1
  6. package/build/components/global-styles/font-library-modal/utils/index.js.map +1 -1
  7. package/build/components/sidebar-edit-mode/template-panel/hooks.js +71 -0
  8. package/build/components/sidebar-edit-mode/template-panel/hooks.js.map +1 -0
  9. package/build/components/sidebar-edit-mode/template-panel/replace-template-button.js +82 -0
  10. package/build/components/sidebar-edit-mode/template-panel/replace-template-button.js.map +1 -0
  11. package/build/components/sidebar-edit-mode/template-panel/template-actions.js +10 -3
  12. package/build/components/sidebar-edit-mode/template-panel/template-actions.js.map +1 -1
  13. package/build/components/sidebar-navigation-screen-pattern/template-part-navigation-menu-list-item.js +5 -3
  14. package/build/components/sidebar-navigation-screen-pattern/template-part-navigation-menu-list-item.js.map +1 -1
  15. package/build/components/sidebar-navigation-screen-pattern/template-part-navigation-menu.js +5 -4
  16. package/build/components/sidebar-navigation-screen-pattern/template-part-navigation-menu.js.map +1 -1
  17. package/build/components/sidebar-navigation-screen-pattern/use-navigation-menu-content.js +8 -1
  18. package/build/components/sidebar-navigation-screen-pattern/use-navigation-menu-content.js.map +1 -1
  19. package/build/components/sidebar-navigation-screen-pattern/use-navigation-menu-title.js +29 -0
  20. package/build/components/sidebar-navigation-screen-pattern/use-navigation-menu-title.js.map +1 -0
  21. package/build/store/selectors.js +4 -5
  22. package/build/store/selectors.js.map +1 -1
  23. package/build/utils/constants.js +1 -1
  24. package/build/utils/constants.js.map +1 -1
  25. package/build-module/components/add-new-pattern/index.js +2 -2
  26. package/build-module/components/add-new-pattern/index.js.map +1 -1
  27. package/build-module/components/global-styles/font-library-modal/resolvers.js +1 -1
  28. package/build-module/components/global-styles/font-library-modal/resolvers.js.map +1 -1
  29. package/build-module/components/global-styles/font-library-modal/utils/index.js +1 -1
  30. package/build-module/components/global-styles/font-library-modal/utils/index.js.map +1 -1
  31. package/build-module/components/sidebar-edit-mode/template-panel/hooks.js +64 -0
  32. package/build-module/components/sidebar-edit-mode/template-panel/hooks.js.map +1 -0
  33. package/build-module/components/sidebar-edit-mode/template-panel/replace-template-button.js +76 -0
  34. package/build-module/components/sidebar-edit-mode/template-panel/replace-template-button.js.map +1 -0
  35. package/build-module/components/sidebar-edit-mode/template-panel/template-actions.js +10 -3
  36. package/build-module/components/sidebar-edit-mode/template-panel/template-actions.js.map +1 -1
  37. package/build-module/components/sidebar-navigation-screen-pattern/template-part-navigation-menu-list-item.js +5 -3
  38. package/build-module/components/sidebar-navigation-screen-pattern/template-part-navigation-menu-list-item.js.map +1 -1
  39. package/build-module/components/sidebar-navigation-screen-pattern/template-part-navigation-menu.js +5 -4
  40. package/build-module/components/sidebar-navigation-screen-pattern/template-part-navigation-menu.js.map +1 -1
  41. package/build-module/components/sidebar-navigation-screen-pattern/use-navigation-menu-content.js +7 -1
  42. package/build-module/components/sidebar-navigation-screen-pattern/use-navigation-menu-content.js.map +1 -1
  43. package/build-module/components/sidebar-navigation-screen-pattern/use-navigation-menu-title.js +22 -0
  44. package/build-module/components/sidebar-navigation-screen-pattern/use-navigation-menu-title.js.map +1 -0
  45. package/build-module/store/selectors.js +4 -5
  46. package/build-module/store/selectors.js.map +1 -1
  47. package/build-module/utils/constants.js +1 -1
  48. package/build-module/utils/constants.js.map +1 -1
  49. package/build-style/style-rtl.css +24 -0
  50. package/build-style/style.css +24 -0
  51. package/package.json +40 -40
  52. package/src/components/add-new-pattern/index.js +2 -2
  53. package/src/components/global-styles/font-library-modal/resolvers.js +1 -1
  54. package/src/components/global-styles/font-library-modal/utils/index.js +1 -1
  55. package/src/components/global-styles/font-library-modal/utils/test/makeFormDataFromFontFamilies.spec.js +1 -1
  56. package/src/components/sidebar-edit-mode/template-panel/hooks.js +97 -0
  57. package/src/components/sidebar-edit-mode/template-panel/replace-template-button.js +89 -0
  58. package/src/components/sidebar-edit-mode/template-panel/style.scss +18 -0
  59. package/src/components/sidebar-edit-mode/template-panel/template-actions.js +27 -12
  60. package/src/components/sidebar-navigation-screen/style.scss +13 -0
  61. package/src/components/sidebar-navigation-screen-pattern/template-part-navigation-menu-list-item.js +5 -8
  62. package/src/components/sidebar-navigation-screen-pattern/template-part-navigation-menu.js +5 -9
  63. package/src/components/sidebar-navigation-screen-pattern/use-navigation-menu-content.js +11 -5
  64. package/src/components/sidebar-navigation-screen-pattern/use-navigation-menu-title.js +32 -0
  65. package/src/store/selectors.js +9 -10
  66. package/src/utils/constants.js +1 -1
@@ -37,3 +37,21 @@ h3.edit-site-template-card__template-areas-title {
37
37
  font-weight: 500;
38
38
  margin: 0 0 $grid-unit-10;
39
39
  }
40
+
41
+
42
+ .edit-site-template-panel__replace-template-modal {
43
+ z-index: z-index(".edit-site-template-panel__replace-template-modal");
44
+ }
45
+
46
+ .edit-site-template-panel__replace-template-modal__content {
47
+ column-count: 2;
48
+ column-gap: $grid-unit-30;
49
+
50
+ @include break-medium() {
51
+ column-count: 3;
52
+ }
53
+
54
+ @include break-wide() {
55
+ column-count: 4;
56
+ }
57
+ }
@@ -11,13 +11,21 @@ import { moreVertical } from '@wordpress/icons';
11
11
  */
12
12
  import { store as editSiteStore } from '../../../store';
13
13
  import isTemplateRevertable from '../../../utils/is-template-revertable';
14
+ import ReplaceTemplateButton from './replace-template-button';
15
+ import { useAvailablePatterns } from './hooks';
14
16
 
15
17
  export default function Actions( { template } ) {
18
+ const availablePatterns = useAvailablePatterns( template );
16
19
  const { revertTemplate } = useDispatch( editSiteStore );
17
20
  const isRevertable = isTemplateRevertable( template );
18
- if ( ! isRevertable ) {
21
+
22
+ if (
23
+ ! isRevertable &&
24
+ ( ! availablePatterns.length || availablePatterns.length < 1 )
25
+ ) {
19
26
  return null;
20
27
  }
28
+
21
29
  return (
22
30
  <DropdownMenu
23
31
  icon={ moreVertical }
@@ -27,17 +35,24 @@ export default function Actions( { template } ) {
27
35
  >
28
36
  { ( { onClose } ) => (
29
37
  <MenuGroup>
30
- <MenuItem
31
- info={ __(
32
- 'Use the template as supplied by the theme.'
33
- ) }
34
- onClick={ () => {
35
- revertTemplate( template );
36
- onClose();
37
- } }
38
- >
39
- { __( 'Clear customizations' ) }
40
- </MenuItem>
38
+ { isRevertable && (
39
+ <MenuItem
40
+ info={ __(
41
+ 'Use the template as supplied by the theme.'
42
+ ) }
43
+ onClick={ () => {
44
+ revertTemplate( template );
45
+ onClose();
46
+ } }
47
+ >
48
+ { __( 'Clear customizations' ) }
49
+ </MenuItem>
50
+ ) }
51
+ <ReplaceTemplateButton
52
+ availableTemplates={ availablePatterns }
53
+ template={ template }
54
+ onClick={ onClose }
55
+ />
41
56
  </MenuGroup>
42
57
  ) }
43
58
  </DropdownMenu>
@@ -76,6 +76,19 @@
76
76
  }
77
77
 
78
78
  .edit-site-sidebar-navigation-screen__content .edit-site-global-styles-style-variations-container {
79
+ @include break-medium() {
80
+ // Safari does not currently support `scrollbar-gutter: stable`, so at
81
+ // particular viewport sizes it's possible for previews to render prior to a
82
+ // scrollbar appearing. This then causes a scrollbar to appear, which reduces
83
+ // the width of the container and can cause the preview's width to change.
84
+ // As a result, the preview can go into an endless loop of resizing, causing
85
+ // the preview elements to appear to "dance". A workaround is to provide a
86
+ // max-width for the container, which prevents the introduction of the scrollbar
87
+ // from causing the preview's width to change.
88
+ // See: https://github.com/WordPress/gutenberg/issues/55112
89
+ max-width: 292px;
90
+ }
91
+
79
92
  .edit-site-global-styles-variations_item-preview {
80
93
  border: $gray-900 $border-width solid;
81
94
  }
@@ -1,30 +1,27 @@
1
1
  /**
2
2
  * WordPress dependencies
3
3
  */
4
- import { useEntityProp } from '@wordpress/core-data';
5
4
  import { __ } from '@wordpress/i18n';
6
5
 
7
6
  /**
8
7
  * Internal dependencies
9
8
  */
10
9
  import SidebarNavigationItem from '../sidebar-navigation-item';
10
+ import useNavigationMenuTitle from './use-navigation-menu-title';
11
11
  import { useLink } from '../routes/link';
12
12
  import { NAVIGATION_POST_TYPE } from '../../utils/constants';
13
13
 
14
14
  export default function TemplatePartNavigationMenuListItem( { id } ) {
15
- const [ title ] = useEntityProp(
16
- 'postType',
17
- NAVIGATION_POST_TYPE,
18
- 'title',
19
- id
20
- );
15
+ const title = useNavigationMenuTitle( id );
21
16
 
22
17
  const linkInfo = useLink( {
23
18
  postId: id,
24
19
  postType: NAVIGATION_POST_TYPE,
25
20
  } );
26
21
 
27
- if ( ! id ) return null;
22
+ if ( ! id || title === undefined ) {
23
+ return null;
24
+ }
28
25
 
29
26
  return (
30
27
  <SidebarNavigationItem withChevron { ...linkInfo }>
@@ -3,23 +3,19 @@
3
3
  */
4
4
  import { __ } from '@wordpress/i18n';
5
5
  import { __experimentalHeading as Heading } from '@wordpress/components';
6
- import { useEntityProp } from '@wordpress/core-data';
7
6
 
8
7
  /**
9
8
  * Internal dependencies
10
9
  */
11
10
  import NavigationMenuEditor from '../sidebar-navigation-screen-navigation-menu/navigation-menu-editor';
12
- import { NAVIGATION_POST_TYPE } from '../../utils/constants';
11
+ import useNavigationMenuTitle from './use-navigation-menu-title';
13
12
 
14
13
  export default function TemplatePartNavigationMenu( { id } ) {
15
- const [ title ] = useEntityProp(
16
- 'postType',
17
- NAVIGATION_POST_TYPE,
18
- 'title',
19
- id
20
- );
14
+ const title = useNavigationMenuTitle( id );
21
15
 
22
- if ( ! id ) return null;
16
+ if ( ! id || title === undefined ) {
17
+ return null;
18
+ }
23
19
 
24
20
  return (
25
21
  <>
@@ -10,6 +10,16 @@ import TemplatePartNavigationMenus from './template-part-navigation-menus';
10
10
  import useEditedEntityRecord from '../use-edited-entity-record';
11
11
  import { TEMPLATE_PART_POST_TYPE } from '../../utils/constants';
12
12
 
13
+ function getBlocksFromRecord( record ) {
14
+ if ( record?.blocks ) {
15
+ return record?.blocks;
16
+ }
17
+
18
+ return record?.content && typeof record.content !== 'function'
19
+ ? parse( record.content )
20
+ : [];
21
+ }
22
+
13
23
  /**
14
24
  * Retrieves a list of specific blocks from a given tree of blocks.
15
25
  *
@@ -60,11 +70,7 @@ export default function useNavigationMenuContent( postType, postId ) {
60
70
  return;
61
71
  }
62
72
 
63
- const blocks =
64
- record?.content && typeof record.content !== 'function'
65
- ? parse( record.content )
66
- : [];
67
-
73
+ const blocks = getBlocksFromRecord( record );
68
74
  const navigationBlocks = getBlocksOfTypeFromBlocks(
69
75
  'core/navigation',
70
76
  blocks
@@ -0,0 +1,32 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import { useSelect } from '@wordpress/data';
5
+ import { store as coreStore } from '@wordpress/core-data';
6
+
7
+ /**
8
+ * Internal dependencies
9
+ */
10
+ import { NAVIGATION_POST_TYPE } from '../../utils/constants';
11
+
12
+ export default function useNavigationMenuTitle( id ) {
13
+ return useSelect(
14
+ ( select ) => {
15
+ if ( ! id ) {
16
+ return undefined;
17
+ }
18
+
19
+ const editedRecord = select( coreStore ).getEditedEntityRecord(
20
+ 'postType',
21
+ NAVIGATION_POST_TYPE,
22
+ id
23
+ );
24
+
25
+ // Do not display a 'trashed' navigation menu.
26
+ return editedRecord.status === 'trash'
27
+ ? undefined
28
+ : editedRecord.title;
29
+ },
30
+ [ id ]
31
+ );
32
+ }
@@ -292,22 +292,21 @@ export function isSaveViewOpened( state ) {
292
292
  * @return {Array} Template parts and their blocks in an array.
293
293
  */
294
294
  export const getCurrentTemplateTemplateParts = createRegistrySelector(
295
- ( select ) => ( state ) => {
296
- const templateType = getEditedPostType( state );
297
- const templateId = getEditedPostId( state );
298
- const template = select( coreDataStore ).getEditedEntityRecord(
299
- 'postType',
300
- templateType,
301
- templateId
302
- );
303
-
295
+ ( select ) => () => {
304
296
  const templateParts = select( coreDataStore ).getEntityRecords(
305
297
  'postType',
306
298
  TEMPLATE_PART_POST_TYPE,
307
299
  { per_page: -1 }
308
300
  );
309
301
 
310
- return getFilteredTemplatePartBlocks( template.blocks, templateParts );
302
+ const clientIds =
303
+ select( blockEditorStore ).__experimentalGetGlobalBlocksByName(
304
+ 'core/template-part'
305
+ );
306
+ const blocks =
307
+ select( blockEditorStore ).getBlocksByClientId( clientIds );
308
+
309
+ return getFilteredTemplatePartBlocks( blocks, templateParts );
311
310
  }
312
311
  );
313
312
 
@@ -50,7 +50,7 @@ export const PAGE_CONTENT_BLOCK_TYPES = {
50
50
 
51
51
  export const POST_TYPE_LABELS = {
52
52
  [ TEMPLATE_POST_TYPE ]: __( 'Template' ),
53
- [ TEMPLATE_PART_POST_TYPE ]: __( 'Template Part' ),
53
+ [ TEMPLATE_PART_POST_TYPE ]: __( 'Template part' ),
54
54
  [ PATTERN_TYPES.user ]: __( 'Pattern' ),
55
55
  [ NAVIGATION_POST_TYPE ]: __( 'Navigation' ),
56
56
  };