@wordpress/edit-site 5.12.16 → 5.12.18

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/header-edit-mode/document-actions/index.js +11 -25
  2. package/build/components/header-edit-mode/document-actions/index.js.map +1 -1
  3. package/build/components/page/index.js +3 -3
  4. package/build/components/page/index.js.map +1 -1
  5. package/build/components/sidebar-navigation-screen-navigation-menus/leaf-more-menu.js +1 -1
  6. package/build/components/sidebar-navigation-screen-navigation-menus/leaf-more-menu.js.map +1 -1
  7. package/build/components/sidebar-navigation-screen-template/home-template-details.js +2 -2
  8. package/build/components/sidebar-navigation-screen-template/home-template-details.js.map +1 -1
  9. package/build/hooks/push-changes-to-global-styles/index.js +147 -27
  10. package/build/hooks/push-changes-to-global-styles/index.js.map +1 -1
  11. package/build-module/components/header-edit-mode/document-actions/index.js +11 -26
  12. package/build-module/components/header-edit-mode/document-actions/index.js.map +1 -1
  13. package/build-module/components/page/index.js +3 -3
  14. package/build-module/components/page/index.js.map +1 -1
  15. package/build-module/components/sidebar-navigation-screen-navigation-menus/leaf-more-menu.js +1 -1
  16. package/build-module/components/sidebar-navigation-screen-navigation-menus/leaf-more-menu.js.map +1 -1
  17. package/build-module/components/sidebar-navigation-screen-template/home-template-details.js +2 -2
  18. package/build-module/components/sidebar-navigation-screen-template/home-template-details.js.map +1 -1
  19. package/build-module/hooks/push-changes-to-global-styles/index.js +148 -28
  20. package/build-module/hooks/push-changes-to-global-styles/index.js.map +1 -1
  21. package/build-style/style-rtl.css +25 -11
  22. package/build-style/style.css +25 -11
  23. package/package.json +39 -39
  24. package/src/components/header-edit-mode/document-actions/index.js +13 -26
  25. package/src/components/header-edit-mode/document-actions/style.scss +14 -6
  26. package/src/components/page/index.js +8 -8
  27. package/src/components/page/style.scss +8 -5
  28. package/src/components/sidebar-navigation-screen-navigation-menus/leaf-more-menu.js +11 -10
  29. package/src/components/sidebar-navigation-screen-template/home-template-details.js +4 -2
  30. package/src/components/table/style.scss +1 -0
  31. package/src/hooks/push-changes-to-global-styles/index.js +152 -28
@@ -198,8 +198,10 @@ export default function HomeTemplateDetails() {
198
198
  <SidebarNavigationScreenDetailsPanelRow>
199
199
  <CheckboxControl
200
200
  className="edit-site-sidebar-navigation-screen__input-control"
201
- label="Allow comments on new posts"
202
- help="Changes will apply to new posts only. Individual posts may override these settings."
201
+ label={ __( 'Allow comments on new posts' ) }
202
+ help={ __(
203
+ 'Changes will apply to new posts only. Individual posts may override these settings.'
204
+ ) }
203
205
  checked={ commentsOnNewPostsValue }
204
206
  onChange={ setAllowCommentsOnNewPosts }
205
207
  />
@@ -1,5 +1,6 @@
1
1
  .edit-site-table-wrapper {
2
2
  width: 100%;
3
+ padding: $grid-unit-40;
3
4
  }
4
5
 
5
6
  .edit-site-table {
@@ -16,7 +16,7 @@ import {
16
16
  import { BaseControl, Button } from '@wordpress/components';
17
17
  import { __, sprintf } from '@wordpress/i18n';
18
18
  import {
19
- __EXPERIMENTAL_STYLE_PROPERTY as STYLE_PROPERTY,
19
+ __EXPERIMENTAL_STYLE_PROPERTY,
20
20
  getBlockType,
21
21
  hasBlockSupport,
22
22
  } from '@wordpress/blocks';
@@ -30,14 +30,23 @@ import { store as noticesStore } from '@wordpress/notices';
30
30
  import { useSupportedStyles } from '../../components/global-styles/hooks';
31
31
  import { unlock } from '../../lock-unlock';
32
32
 
33
- const { GlobalStylesContext, useBlockEditingMode } = unlock(
33
+ const { cleanEmptyObject, GlobalStylesContext, useBlockEditingMode } = unlock(
34
34
  blockEditorPrivateApis
35
35
  );
36
36
 
37
+ // Block Gap is a special case and isn't defined within the blocks
38
+ // style properties config. We'll add it here to allow it to be pushed
39
+ // to global styles as well.
40
+ const STYLE_PROPERTY = {
41
+ ...__EXPERIMENTAL_STYLE_PROPERTY,
42
+ blockGap: { value: [ 'spacing', 'blockGap' ] },
43
+ };
44
+
37
45
  // TODO: Temporary duplication of constant in @wordpress/block-editor. Can be
38
46
  // removed by moving PushChangesToGlobalStylesControl to
39
47
  // @wordpress/block-editor.
40
48
  const STYLE_PATH_TO_CSS_VAR_INFIX = {
49
+ 'border.color': 'color',
41
50
  'color.background': 'color',
42
51
  'color.text': 'color',
43
52
  'elements.link.color.text': 'color',
@@ -79,6 +88,7 @@ const STYLE_PATH_TO_CSS_VAR_INFIX = {
79
88
  'elements.h6.typography.fontFamily': 'font-family',
80
89
  'elements.h6.color.gradient': 'gradient',
81
90
  'color.gradient': 'gradient',
91
+ blockGap: 'spacing',
82
92
  'typography.fontSize': 'font-size',
83
93
  'typography.fontFamily': 'font-family',
84
94
  };
@@ -87,6 +97,7 @@ const STYLE_PATH_TO_CSS_VAR_INFIX = {
87
97
  // removed by moving PushChangesToGlobalStylesControl to
88
98
  // @wordpress/block-editor.
89
99
  const STYLE_PATH_TO_PRESET_BLOCK_ATTRIBUTE = {
100
+ 'border.color': 'borderColor',
90
101
  'color.background': 'backgroundColor',
91
102
  'color.text': 'textColor',
92
103
  'color.gradient': 'gradient',
@@ -96,30 +107,124 @@ const STYLE_PATH_TO_PRESET_BLOCK_ATTRIBUTE = {
96
107
 
97
108
  const SUPPORTED_STYLES = [ 'border', 'color', 'spacing', 'typography' ];
98
109
 
99
- function useChangesToPush( name, attributes ) {
110
+ const flatBorderProperties = [ 'borderColor', 'borderWidth', 'borderStyle' ];
111
+ const sides = [ 'top', 'right', 'bottom', 'left' ];
112
+
113
+ function getBorderStyleChanges( border, presetColor, userStyle ) {
114
+ if ( ! border && ! presetColor ) {
115
+ return [];
116
+ }
117
+
118
+ const changes = [
119
+ ...getFallbackBorderStyleChange( 'top', border, userStyle ),
120
+ ...getFallbackBorderStyleChange( 'right', border, userStyle ),
121
+ ...getFallbackBorderStyleChange( 'bottom', border, userStyle ),
122
+ ...getFallbackBorderStyleChange( 'left', border, userStyle ),
123
+ ];
124
+
125
+ // Handle a flat border i.e. all sides the same, CSS shorthand.
126
+ const { color: customColor, style, width } = border || {};
127
+ const hasColorOrWidth = presetColor || customColor || width;
128
+
129
+ if ( hasColorOrWidth && ! style ) {
130
+ // Global Styles need individual side configurations to overcome
131
+ // theme.json configurations which are per side as well.
132
+ sides.forEach( ( side ) => {
133
+ // Only add fallback border-style if global styles don't already
134
+ // have something set.
135
+ if ( ! userStyle?.[ side ]?.style ) {
136
+ changes.push( {
137
+ path: [ 'border', side, 'style' ],
138
+ value: 'solid',
139
+ } );
140
+ }
141
+ } );
142
+ }
143
+
144
+ return changes;
145
+ }
146
+
147
+ function getFallbackBorderStyleChange( side, border, globalBorderStyle ) {
148
+ if ( ! border?.[ side ] || globalBorderStyle?.[ side ]?.style ) {
149
+ return [];
150
+ }
151
+
152
+ const { color, style, width } = border[ side ];
153
+ const hasColorOrWidth = color || width;
154
+
155
+ if ( ! hasColorOrWidth || style ) {
156
+ return [];
157
+ }
158
+
159
+ return [ { path: [ 'border', side, 'style' ], value: 'solid' } ];
160
+ }
161
+
162
+ function useChangesToPush( name, attributes, userConfig ) {
100
163
  const supports = useSupportedStyles( name );
164
+ const blockUserConfig = userConfig?.styles?.blocks?.[ name ];
165
+
166
+ return useMemo( () => {
167
+ const changes = supports.flatMap( ( key ) => {
168
+ if ( ! STYLE_PROPERTY[ key ] ) {
169
+ return [];
170
+ }
171
+ const { value: path } = STYLE_PROPERTY[ key ];
172
+ const presetAttributeKey = path.join( '.' );
173
+ const presetAttributeValue =
174
+ attributes[
175
+ STYLE_PATH_TO_PRESET_BLOCK_ATTRIBUTE[ presetAttributeKey ]
176
+ ];
177
+ const value = presetAttributeValue
178
+ ? `var:preset|${ STYLE_PATH_TO_CSS_VAR_INFIX[ presetAttributeKey ] }|${ presetAttributeValue }`
179
+ : get( attributes.style, path );
101
180
 
102
- return useMemo(
103
- () =>
104
- supports.flatMap( ( key ) => {
105
- if ( ! STYLE_PROPERTY[ key ] ) {
106
- return [];
181
+ // Links only have a single support entry but have two element
182
+ // style properties, color and hover color. The following check
183
+ // will add the hover color to the changes if required.
184
+ if ( key === 'linkColor' ) {
185
+ const linkChanges = value ? [ { path, value } ] : [];
186
+ const hoverPath = [
187
+ 'elements',
188
+ 'link',
189
+ ':hover',
190
+ 'color',
191
+ 'text',
192
+ ];
193
+ const hoverValue = get( attributes.style, hoverPath );
194
+
195
+ if ( hoverValue ) {
196
+ linkChanges.push( { path: hoverPath, value: hoverValue } );
107
197
  }
108
- const { value: path } = STYLE_PROPERTY[ key ];
109
- const presetAttributeKey = path.join( '.' );
110
- const presetAttributeValue =
111
- attributes[
112
- STYLE_PATH_TO_PRESET_BLOCK_ATTRIBUTE[
113
- presetAttributeKey
114
- ]
115
- ];
116
- const value = presetAttributeValue
117
- ? `var:preset|${ STYLE_PATH_TO_CSS_VAR_INFIX[ presetAttributeKey ] }|${ presetAttributeValue }`
118
- : get( attributes.style, path );
119
- return value ? [ { path, value } ] : [];
120
- } ),
121
- [ supports, name, attributes ]
122
- );
198
+
199
+ return linkChanges;
200
+ }
201
+
202
+ // The shorthand border styles can't be mapped directly as global
203
+ // styles requires longhand config.
204
+ if ( flatBorderProperties.includes( key ) && value ) {
205
+ // The shorthand config path is included to clear the block attribute.
206
+ const borderChanges = [ { path, value } ];
207
+ sides.forEach( ( side ) => {
208
+ const currentPath = [ ...path ];
209
+ currentPath.splice( -1, 0, side );
210
+ borderChanges.push( { path: currentPath, value } );
211
+ } );
212
+ return borderChanges;
213
+ }
214
+
215
+ return value ? [ { path, value } ] : [];
216
+ } );
217
+
218
+ // To ensure display of a visible border, global styles require a
219
+ // default border style if a border color or width is present.
220
+ getBorderStyleChanges(
221
+ attributes.style?.border,
222
+ attributes.borderColor,
223
+ blockUserConfig?.border
224
+ ).forEach( ( change ) => changes.push( change ) );
225
+
226
+ return changes;
227
+ }, [ supports, attributes, blockUserConfig ] );
123
228
  }
124
229
 
125
230
  function cloneDeep( object ) {
@@ -131,11 +236,11 @@ function PushChangesToGlobalStylesControl( {
131
236
  attributes,
132
237
  setAttributes,
133
238
  } ) {
134
- const changes = useChangesToPush( name, attributes );
135
-
136
239
  const { user: userConfig, setUserConfig } =
137
240
  useContext( GlobalStylesContext );
138
241
 
242
+ const changes = useChangesToPush( name, attributes, userConfig );
243
+
139
244
  const { __unstableMarkNextChangeAsNotPersistent } =
140
245
  useDispatch( blockEditorStore );
141
246
  const { createSuccessNotice } = useDispatch( noticesStore );
@@ -155,12 +260,22 @@ function PushChangesToGlobalStylesControl( {
155
260
  set( newUserConfig, [ 'styles', 'blocks', name, ...path ], value );
156
261
  }
157
262
 
263
+ const newBlockAttributes = {
264
+ borderColor: undefined,
265
+ backgroundColor: undefined,
266
+ textColor: undefined,
267
+ gradient: undefined,
268
+ fontSize: undefined,
269
+ fontFamily: undefined,
270
+ style: cleanEmptyObject( newBlockStyles ),
271
+ };
272
+
158
273
  // @wordpress/core-data doesn't support editing multiple entity types in
159
274
  // a single undo level. So for now, we disable @wordpress/core-data undo
160
275
  // tracking and implement our own Undo button in the snackbar
161
276
  // notification.
162
277
  __unstableMarkNextChangeAsNotPersistent();
163
- setAttributes( { style: newBlockStyles } );
278
+ setAttributes( newBlockAttributes );
164
279
  setUserConfig( () => newUserConfig, { undoIgnore: true } );
165
280
 
166
281
  createSuccessNotice(
@@ -176,7 +291,7 @@ function PushChangesToGlobalStylesControl( {
176
291
  label: __( 'Undo' ),
177
292
  onClick() {
178
293
  __unstableMarkNextChangeAsNotPersistent();
179
- setAttributes( { style: blockStyles } );
294
+ setAttributes( attributes );
180
295
  setUserConfig( () => userConfig, {
181
296
  undoIgnore: true,
182
297
  } );
@@ -185,7 +300,16 @@ function PushChangesToGlobalStylesControl( {
185
300
  ],
186
301
  }
187
302
  );
188
- }, [ changes, attributes, userConfig, name ] );
303
+ }, [
304
+ __unstableMarkNextChangeAsNotPersistent,
305
+ attributes,
306
+ changes,
307
+ createSuccessNotice,
308
+ name,
309
+ setAttributes,
310
+ setUserConfig,
311
+ userConfig,
312
+ ] );
189
313
 
190
314
  return (
191
315
  <BaseControl