@wordpress/edit-site 4.13.0 → 4.13.1-next.957ca95e4c.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 (31) hide show
  1. package/build/components/add-new-template/new-template.js +1 -1
  2. package/build/components/add-new-template/new-template.js.map +1 -1
  3. package/build/components/add-new-template/utils.js +90 -52
  4. package/build/components/add-new-template/utils.js.map +1 -1
  5. package/build/components/global-styles/dimensions-panel.js +40 -23
  6. package/build/components/global-styles/dimensions-panel.js.map +1 -1
  7. package/build/components/global-styles/hooks.js +1 -1
  8. package/build/components/global-styles/hooks.js.map +1 -1
  9. package/build/components/global-styles/preview.js +2 -2
  10. package/build/components/global-styles/preview.js.map +1 -1
  11. package/build/components/global-styles/utils.js +1 -1
  12. package/build/components/global-styles/utils.js.map +1 -1
  13. package/build-module/components/add-new-template/new-template.js +2 -2
  14. package/build-module/components/add-new-template/new-template.js.map +1 -1
  15. package/build-module/components/add-new-template/utils.js +87 -52
  16. package/build-module/components/add-new-template/utils.js.map +1 -1
  17. package/build-module/components/global-styles/dimensions-panel.js +40 -23
  18. package/build-module/components/global-styles/dimensions-panel.js.map +1 -1
  19. package/build-module/components/global-styles/hooks.js +2 -2
  20. package/build-module/components/global-styles/hooks.js.map +1 -1
  21. package/build-module/components/global-styles/preview.js +2 -2
  22. package/build-module/components/global-styles/preview.js.map +1 -1
  23. package/build-module/components/global-styles/utils.js +1 -1
  24. package/build-module/components/global-styles/utils.js.map +1 -1
  25. package/package.json +29 -29
  26. package/src/components/add-new-template/new-template.js +2 -0
  27. package/src/components/add-new-template/utils.js +82 -20
  28. package/src/components/global-styles/dimensions-panel.js +52 -31
  29. package/src/components/global-styles/hooks.js +3 -5
  30. package/src/components/global-styles/preview.js +2 -2
  31. package/src/components/global-styles/utils.js +1 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wordpress/edit-site",
3
- "version": "4.13.0",
3
+ "version": "4.13.1-next.957ca95e4c.0",
4
4
  "description": "Edit Site Page module for WordPress.",
5
5
  "author": "The WordPress Contributors",
6
6
  "license": "GPL-2.0-or-later",
@@ -27,33 +27,33 @@
27
27
  "react-native": "src/index",
28
28
  "dependencies": {
29
29
  "@babel/runtime": "^7.16.0",
30
- "@wordpress/a11y": "^3.16.0",
31
- "@wordpress/api-fetch": "^6.13.0",
32
- "@wordpress/block-editor": "^9.8.0",
33
- "@wordpress/block-library": "^7.13.0",
34
- "@wordpress/blocks": "^11.15.0",
35
- "@wordpress/components": "^20.0.0",
36
- "@wordpress/compose": "^5.14.0",
37
- "@wordpress/core-data": "^4.14.0",
38
- "@wordpress/data": "^7.0.0",
39
- "@wordpress/deprecated": "^3.16.0",
40
- "@wordpress/editor": "^12.15.0",
41
- "@wordpress/element": "^4.14.0",
42
- "@wordpress/hooks": "^3.16.0",
43
- "@wordpress/html-entities": "^3.16.0",
44
- "@wordpress/i18n": "^4.16.0",
45
- "@wordpress/icons": "^9.7.0",
46
- "@wordpress/interface": "^4.15.0",
47
- "@wordpress/keyboard-shortcuts": "^3.14.0",
48
- "@wordpress/keycodes": "^3.16.0",
49
- "@wordpress/media-utils": "^4.7.0",
50
- "@wordpress/notices": "^3.16.0",
51
- "@wordpress/plugins": "^4.14.0",
52
- "@wordpress/preferences": "^2.8.0",
53
- "@wordpress/reusable-blocks": "^3.14.0",
54
- "@wordpress/style-engine": "^0.15.0",
55
- "@wordpress/url": "^3.17.0",
56
- "@wordpress/viewport": "^4.14.0",
30
+ "@wordpress/a11y": "^3.16.1-next.957ca95e4c.0",
31
+ "@wordpress/api-fetch": "^6.13.1-next.957ca95e4c.0",
32
+ "@wordpress/block-editor": "^9.8.1-next.957ca95e4c.0",
33
+ "@wordpress/block-library": "^7.13.1-next.957ca95e4c.0",
34
+ "@wordpress/blocks": "^11.15.1-next.957ca95e4c.0",
35
+ "@wordpress/components": "^20.0.2-next.957ca95e4c.0",
36
+ "@wordpress/compose": "^5.14.1-next.957ca95e4c.0",
37
+ "@wordpress/core-data": "^5.0.1-next.957ca95e4c.0",
38
+ "@wordpress/data": "^7.0.1-next.957ca95e4c.0",
39
+ "@wordpress/deprecated": "^3.16.1-next.957ca95e4c.0",
40
+ "@wordpress/editor": "^12.15.1-next.957ca95e4c.0",
41
+ "@wordpress/element": "^4.14.1-next.957ca95e4c.0",
42
+ "@wordpress/hooks": "^3.16.1-next.957ca95e4c.0",
43
+ "@wordpress/html-entities": "^3.16.1-next.957ca95e4c.0",
44
+ "@wordpress/i18n": "^4.16.1-next.957ca95e4c.0",
45
+ "@wordpress/icons": "^9.7.1-next.957ca95e4c.0",
46
+ "@wordpress/interface": "^4.15.1-next.957ca95e4c.0",
47
+ "@wordpress/keyboard-shortcuts": "^3.14.1-next.957ca95e4c.0",
48
+ "@wordpress/keycodes": "^3.16.1-next.957ca95e4c.0",
49
+ "@wordpress/media-utils": "^4.7.1-next.957ca95e4c.0",
50
+ "@wordpress/notices": "^3.16.1-next.957ca95e4c.0",
51
+ "@wordpress/plugins": "^4.14.1-next.957ca95e4c.0",
52
+ "@wordpress/preferences": "^2.8.1-next.957ca95e4c.0",
53
+ "@wordpress/reusable-blocks": "^3.14.1-next.957ca95e4c.0",
54
+ "@wordpress/style-engine": "^0.15.1-next.957ca95e4c.0",
55
+ "@wordpress/url": "^3.17.1-next.957ca95e4c.0",
56
+ "@wordpress/viewport": "^4.14.1-next.957ca95e4c.0",
57
57
  "classnames": "^2.3.1",
58
58
  "downloadjs": "^1.4.7",
59
59
  "history": "^5.1.0",
@@ -68,5 +68,5 @@
68
68
  "publishConfig": {
69
69
  "access": "public"
70
70
  },
71
- "gitHead": "171b87c7465b93e685e081c5f57f153507363c95"
71
+ "gitHead": "272a74bbbaab10ee24424eafe9578e705fbfbbb4"
72
72
  }
@@ -41,6 +41,7 @@ import {
41
41
  useTaxonomiesMenuItems,
42
42
  usePostTypeMenuItems,
43
43
  useAuthorMenuItem,
44
+ usePostTypeArchiveMenuItems,
44
45
  } from './utils';
45
46
  import AddCustomGenericTemplateModal from './add-custom-generic-template-modal';
46
47
  import { useHistory } from '../routes';
@@ -301,6 +302,7 @@ function useMissingTemplates(
301
302
  } );
302
303
  const missingTemplates = [
303
304
  ...enhancedMissingDefaultTemplateTypes,
305
+ ...usePostTypeArchiveMenuItems(),
304
306
  ...postTypesMenuItems,
305
307
  ...taxonomiesMenuItems,
306
308
  ];
@@ -12,7 +12,7 @@ import { store as editorStore } from '@wordpress/editor';
12
12
  import { decodeEntities } from '@wordpress/html-entities';
13
13
  import { useMemo, useCallback } from '@wordpress/element';
14
14
  import { __, sprintf } from '@wordpress/i18n';
15
- import { blockMeta, post } from '@wordpress/icons';
15
+ import { blockMeta, post, archive } from '@wordpress/icons';
16
16
 
17
17
  /**
18
18
  * @typedef IHasNameAndId
@@ -86,10 +86,90 @@ const usePublicTaxonomies = () => {
86
86
  }, [ taxonomies ] );
87
87
  };
88
88
 
89
+ function usePostTypeNeedsUniqueIdentifier( publicPostTypes ) {
90
+ const postTypeLabels = useMemo( () =>
91
+ publicPostTypes?.reduce( ( accumulator, { labels } ) => {
92
+ const singularName = labels.singular_name.toLowerCase();
93
+ accumulator[ singularName ] =
94
+ ( accumulator[ singularName ] || 0 ) + 1;
95
+ return accumulator;
96
+ }, {} )
97
+ );
98
+ return useCallback(
99
+ ( { labels, slug } ) => {
100
+ const singularName = labels.singular_name.toLowerCase();
101
+ return postTypeLabels[ singularName ] > 1 && singularName !== slug;
102
+ },
103
+ [ postTypeLabels ]
104
+ );
105
+ }
106
+
107
+ export function usePostTypeArchiveMenuItems() {
108
+ const publicPostTypes = usePublicPostTypes();
109
+ const postTypesWithArchives = useMemo(
110
+ () => publicPostTypes?.filter( ( postType ) => postType.has_archive ),
111
+ [ publicPostTypes ]
112
+ );
113
+ const existingTemplates = useExistingTemplates();
114
+ const needsUniqueIdentifier = usePostTypeNeedsUniqueIdentifier(
115
+ postTypesWithArchives
116
+ );
117
+ return useMemo(
118
+ () =>
119
+ postTypesWithArchives
120
+ ?.filter(
121
+ ( postType ) =>
122
+ ! ( existingTemplates || [] ).some(
123
+ ( existingTemplate ) =>
124
+ existingTemplate.slug ===
125
+ 'archive-' + postType.slug
126
+ )
127
+ )
128
+ .map( ( postType ) => {
129
+ let title;
130
+ if ( needsUniqueIdentifier( postType ) ) {
131
+ title = sprintf(
132
+ // translators: %1s: Name of the post type e.g: "Post"; %2s: Slug of the post type e.g: "book".
133
+ __( 'Archive: %1$s (%2$s)' ),
134
+ postType.labels.singular_name,
135
+ postType.slug
136
+ );
137
+ } else {
138
+ title = sprintf(
139
+ // translators: %s: Name of the post type e.g: "Post".
140
+ __( 'Archive: %s' ),
141
+ postType.labels.singular_name
142
+ );
143
+ }
144
+ return {
145
+ slug: 'archive-' + postType.slug,
146
+ description: sprintf(
147
+ // translators: %s: Name of the post type e.g: "Post".
148
+ __(
149
+ 'Displays an archive with the latests posts of type: %s.'
150
+ ),
151
+ postType.labels.singular_name
152
+ ),
153
+ title,
154
+ // `icon` is the `menu_icon` property of a post type. We
155
+ // only handle `dashicons` for now, even if the `menu_icon`
156
+ // also supports urls and svg as values.
157
+ icon: postType.icon?.startsWith( 'dashicons-' )
158
+ ? postType.icon.slice( 10 )
159
+ : archive,
160
+ templatePrefix: 'archive',
161
+ };
162
+ } ) || [],
163
+ [ postTypesWithArchives, existingTemplates, needsUniqueIdentifier ]
164
+ );
165
+ }
166
+
89
167
  export const usePostTypeMenuItems = ( onClickMenuItem ) => {
90
168
  const publicPostTypes = usePublicPostTypes();
91
169
  const existingTemplates = useExistingTemplates();
92
170
  const defaultTemplateTypes = useDefaultTemplateTypes();
171
+ const needsUniqueIdentifier =
172
+ usePostTypeNeedsUniqueIdentifier( publicPostTypes );
93
173
  // `page`is a special case in template hierarchy.
94
174
  const templatePrefixes = useMemo(
95
175
  () =>
@@ -103,21 +183,6 @@ export const usePostTypeMenuItems = ( onClickMenuItem ) => {
103
183
  }, {} ),
104
184
  [ publicPostTypes ]
105
185
  );
106
- // We need to keep track of naming conflicts. If a conflict
107
- // occurs, we need to add slug.
108
- const postTypeLabels = publicPostTypes?.reduce(
109
- ( accumulator, { labels } ) => {
110
- const singularName = labels.singular_name.toLowerCase();
111
- accumulator[ singularName ] =
112
- ( accumulator[ singularName ] || 0 ) + 1;
113
- return accumulator;
114
- },
115
- {}
116
- );
117
- const needsUniqueIdentifier = ( labels, slug ) => {
118
- const singularName = labels.singular_name.toLowerCase();
119
- return postTypeLabels[ singularName ] > 1 && singularName !== slug;
120
- };
121
186
  const postTypesInfo = useEntitiesInfo( 'postType', templatePrefixes );
122
187
  const existingTemplateSlugs = ( existingTemplates || [] ).map(
123
188
  ( { slug } ) => slug
@@ -134,10 +199,7 @@ export const usePostTypeMenuItems = ( onClickMenuItem ) => {
134
199
  );
135
200
  const hasGeneralTemplate =
136
201
  existingTemplateSlugs?.includes( generalTemplateSlug );
137
- const _needsUniqueIdentifier = needsUniqueIdentifier(
138
- labels,
139
- slug
140
- );
202
+ const _needsUniqueIdentifier = needsUniqueIdentifier( postType );
141
203
  let menuItemTitle = sprintf(
142
204
  // translators: %s: Name of the post type e.g: "Post".
143
205
  __( 'Single item: %s' ),
@@ -121,20 +121,21 @@ function splitStyleValue( value ) {
121
121
  function splitGapValue( value ) {
122
122
  // Check for shorthand value (a string value).
123
123
  if ( value && typeof value === 'string' ) {
124
- // Convert to value for individual sides for BoxControl.
124
+ // If the value is a string, treat it as a single side (top) for the spacing controls.
125
125
  return {
126
126
  top: value,
127
- right: value,
128
- bottom: value,
129
- left: value,
130
127
  };
131
128
  }
132
129
 
133
- return {
134
- ...value,
135
- right: value?.left,
136
- bottom: value?.top,
137
- };
130
+ if ( value ) {
131
+ return {
132
+ ...value,
133
+ right: value?.left,
134
+ bottom: value?.top,
135
+ };
136
+ }
137
+
138
+ return value;
138
139
  }
139
140
 
140
141
  // Props for managing `layout.contentSize`.
@@ -238,21 +239,26 @@ function useMarginProps( name ) {
238
239
  function useBlockGapProps( name ) {
239
240
  const [ gapValue, setGapValue ] = useStyle( 'spacing.blockGap', name );
240
241
  const gapValues = splitGapValue( gapValue );
241
- const setGapValues = ( nextBoxGapValue ) => {
242
- if ( ! nextBoxGapValue ) {
243
- setGapValue( null );
244
- }
245
- setGapValue( {
246
- top: nextBoxGapValue?.top,
247
- left: nextBoxGapValue?.left,
248
- } );
249
- };
250
242
  const gapSides = useCustomSides( name, 'blockGap' );
251
243
  const isAxialGap =
252
244
  gapSides && gapSides.some( ( side ) => AXIAL_SIDES.includes( side ) );
253
245
  const resetGapValue = () => setGapValue( undefined );
254
246
  const [ userSetGapValue ] = useStyle( 'spacing.blockGap', name, 'user' );
255
247
  const hasGapValue = () => !! userSetGapValue;
248
+ const setGapValues = ( nextBoxGapValue ) => {
249
+ if ( ! nextBoxGapValue ) {
250
+ setGapValue( null );
251
+ }
252
+ // If axial gap is not enabled, treat the 'top' value as the shorthand gap value.
253
+ if ( ! isAxialGap && nextBoxGapValue?.hasOwnProperty( 'top' ) ) {
254
+ setGapValue( nextBoxGapValue.top );
255
+ } else {
256
+ setGapValue( {
257
+ top: nextBoxGapValue?.top,
258
+ left: nextBoxGapValue?.left,
259
+ } );
260
+ }
261
+ };
256
262
  return {
257
263
  gapValue,
258
264
  gapValues,
@@ -469,27 +475,42 @@ export default function DimensionsPanel( { name } ) {
469
475
  label={ __( 'Block spacing' ) }
470
476
  onDeselect={ resetGapValue }
471
477
  isShownByDefault={ true }
478
+ className={ classnames( {
479
+ 'tools-panel-item-spacing': showSpacingPresetsControl,
480
+ } ) }
472
481
  >
473
- { isAxialGap ? (
474
- <BoxControl
482
+ { ! showSpacingPresetsControl &&
483
+ ( isAxialGap ? (
484
+ <BoxControl
485
+ label={ __( 'Block spacing' ) }
486
+ min={ 0 }
487
+ onChange={ setGapValues }
488
+ units={ units }
489
+ sides={ gapSides }
490
+ values={ gapValues }
491
+ allowReset={ false }
492
+ splitOnAxis={ isAxialGap }
493
+ />
494
+ ) : (
495
+ <UnitControl
496
+ label={ __( 'Block spacing' ) }
497
+ __unstableInputWidth="80px"
498
+ min={ 0 }
499
+ onChange={ setGapValue }
500
+ units={ units }
501
+ value={ gapValue }
502
+ />
503
+ ) ) }
504
+ { showSpacingPresetsControl && (
505
+ <SpacingSizesControl
475
506
  label={ __( 'Block spacing' ) }
476
507
  min={ 0 }
477
508
  onChange={ setGapValues }
478
- units={ units }
479
- sides={ gapSides }
509
+ sides={ isAxialGap ? gapSides : [ 'top' ] } // Use 'top' as the shorthand property in non-axial configurations.
480
510
  values={ gapValues }
481
511
  allowReset={ false }
482
512
  splitOnAxis={ isAxialGap }
483
513
  />
484
- ) : (
485
- <UnitControl
486
- label={ __( 'Block spacing' ) }
487
- __unstableInputWidth="80px"
488
- min={ 0 }
489
- onChange={ setGapValue }
490
- units={ units }
491
- value={ gapValue }
492
- />
493
514
  ) }
494
515
  </ToolsPanelItem>
495
516
  ) }
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * External dependencies
3
3
  */
4
- import { get, cloneDeep, set, isEqual, has } from 'lodash';
4
+ import { get, cloneDeep, set, isEqual } from 'lodash';
5
5
 
6
6
  /**
7
7
  * WordPress dependencies
@@ -210,10 +210,8 @@ export function getSupportedGlobalStylesPanels( name ) {
210
210
  // unset, we still enable it.
211
211
  if ( STYLE_PROPERTY[ styleName ].requiresOptOut ) {
212
212
  if (
213
- has(
214
- blockType.supports,
215
- STYLE_PROPERTY[ styleName ].support[ 0 ]
216
- ) &&
213
+ STYLE_PROPERTY[ styleName ].support[ 0 ] in
214
+ blockType.supports &&
217
215
  get(
218
216
  blockType.supports,
219
217
  STYLE_PROPERTY[ styleName ].support
@@ -79,13 +79,13 @@ const StylesPreview = ( { label, isFocused } ) => {
79
79
  )
80
80
  .slice( 0, 2 );
81
81
 
82
- // Reset leaked styles from WP common.css.
82
+ // Reset leaked styles from WP common.css and remove main content layout padding.
83
83
  const editorStyles = useMemo( () => {
84
84
  if ( styles ) {
85
85
  return [
86
86
  ...styles,
87
87
  {
88
- css: 'body{min-width: 0;}',
88
+ css: 'body{min-width: 0;padding: 0;}',
89
89
  isGlobalStyles: true,
90
90
  },
91
91
  ];
@@ -79,7 +79,7 @@ export const PRESET_METADATA = [
79
79
  },
80
80
  {
81
81
  path: [ 'spacing', 'spacingSizes' ],
82
- valueKey: 'spacingSizes',
82
+ valueKey: 'size',
83
83
  cssVarInfix: 'spacing',
84
84
  valueFunc: ( { size } ) => size,
85
85
  classes: [],