@wordpress/edit-site 4.9.0 → 4.12.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 (199) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/build/components/add-new-template/add-custom-generic-template-modal.js +84 -0
  3. package/build/components/add-new-template/add-custom-generic-template-modal.js.map +1 -0
  4. package/build/components/add-new-template/add-custom-template-modal.js +82 -61
  5. package/build/components/add-new-template/add-custom-template-modal.js.map +1 -1
  6. package/build/components/add-new-template/new-template.js +94 -81
  7. package/build/components/add-new-template/new-template.js.map +1 -1
  8. package/build/components/add-new-template/utils.js +574 -57
  9. package/build/components/add-new-template/utils.js.map +1 -1
  10. package/build/components/block-editor/index.js +1 -3
  11. package/build/components/block-editor/index.js.map +1 -1
  12. package/build/components/code-editor/index.js +17 -4
  13. package/build/components/code-editor/index.js.map +1 -1
  14. package/build/components/editor/index.js +16 -0
  15. package/build/components/editor/index.js.map +1 -1
  16. package/build/components/error-boundary/index.js +6 -0
  17. package/build/components/error-boundary/index.js.map +1 -1
  18. package/build/components/global-styles/dimensions-panel.js +191 -21
  19. package/build/components/global-styles/dimensions-panel.js.map +1 -1
  20. package/build/components/global-styles/global-styles-provider.js +4 -2
  21. package/build/components/global-styles/global-styles-provider.js.map +1 -1
  22. package/build/components/global-styles/hooks.js +11 -2
  23. package/build/components/global-styles/hooks.js.map +1 -1
  24. package/build/components/global-styles/screen-color-palette.js +13 -17
  25. package/build/components/global-styles/screen-color-palette.js.map +1 -1
  26. package/build/components/global-styles/screen-colors.js +59 -7
  27. package/build/components/global-styles/screen-colors.js.map +1 -1
  28. package/build/components/global-styles/screen-heading-color.js +157 -0
  29. package/build/components/global-styles/screen-heading-color.js.map +1 -0
  30. package/build/components/global-styles/screen-link-color.js +48 -14
  31. package/build/components/global-styles/screen-link-color.js.map +1 -1
  32. package/build/components/global-styles/screen-typography-element.js +4 -0
  33. package/build/components/global-styles/screen-typography-element.js.map +1 -1
  34. package/build/components/global-styles/screen-typography.js +5 -0
  35. package/build/components/global-styles/screen-typography.js.map +1 -1
  36. package/build/components/global-styles/typography-panel.js +73 -12
  37. package/build/components/global-styles/typography-panel.js.map +1 -1
  38. package/build/components/global-styles/typography-utils.js +217 -0
  39. package/build/components/global-styles/typography-utils.js.map +1 -0
  40. package/build/components/global-styles/ui.js +11 -0
  41. package/build/components/global-styles/ui.js.map +1 -1
  42. package/build/components/global-styles/use-global-styles-output.js +298 -61
  43. package/build/components/global-styles/use-global-styles-output.js.map +1 -1
  44. package/build/components/global-styles/utils.js +49 -3
  45. package/build/components/global-styles/utils.js.map +1 -1
  46. package/build/components/header/index.js +22 -10
  47. package/build/components/header/index.js.map +1 -1
  48. package/build/components/header/undo-redo/redo.js +2 -1
  49. package/build/components/header/undo-redo/redo.js.map +1 -1
  50. package/build/components/keyboard-shortcut-help-modal/index.js +1 -3
  51. package/build/components/keyboard-shortcut-help-modal/index.js.map +1 -1
  52. package/build/components/list/actions/index.js +1 -1
  53. package/build/components/list/actions/index.js.map +1 -1
  54. package/build/components/save-button/index.js +2 -3
  55. package/build/components/save-button/index.js.map +1 -1
  56. package/build/components/sidebar/navigation-menu-sidebar/navigation-menu.js +2 -2
  57. package/build/components/sidebar/navigation-menu-sidebar/navigation-menu.js.map +1 -1
  58. package/build/components/sidebar/template-card/template-actions.js +1 -1
  59. package/build/components/sidebar/template-card/template-actions.js.map +1 -1
  60. package/build/components/template-details/edit-template-title.js +11 -3
  61. package/build/components/template-details/edit-template-title.js.map +1 -1
  62. package/build/components/template-details/index.js +2 -21
  63. package/build/components/template-details/index.js.map +1 -1
  64. package/build/components/template-details/template-areas.js +1 -1
  65. package/build/components/template-details/template-areas.js.map +1 -1
  66. package/build/components/template-part-converter/convert-to-template-part.js +4 -1
  67. package/build/components/template-part-converter/convert-to-template-part.js.map +1 -1
  68. package/build/hooks/index.js +2 -0
  69. package/build/hooks/index.js.map +1 -1
  70. package/build/hooks/template-part-edit.js +86 -0
  71. package/build/hooks/template-part-edit.js.map +1 -0
  72. package/build/store/selectors.js +4 -1
  73. package/build/store/selectors.js.map +1 -1
  74. package/build-module/components/add-new-template/add-custom-generic-template-modal.js +77 -0
  75. package/build-module/components/add-new-template/add-custom-generic-template-modal.js.map +1 -0
  76. package/build-module/components/add-new-template/add-custom-template-modal.js +82 -61
  77. package/build-module/components/add-new-template/add-custom-template-modal.js.map +1 -1
  78. package/build-module/components/add-new-template/new-template.js +96 -84
  79. package/build-module/components/add-new-template/new-template.js.map +1 -1
  80. package/build-module/components/add-new-template/utils.js +555 -50
  81. package/build-module/components/add-new-template/utils.js.map +1 -1
  82. package/build-module/components/block-editor/index.js +1 -2
  83. package/build-module/components/block-editor/index.js.map +1 -1
  84. package/build-module/components/code-editor/index.js +18 -5
  85. package/build-module/components/code-editor/index.js.map +1 -1
  86. package/build-module/components/editor/index.js +16 -0
  87. package/build-module/components/editor/index.js.map +1 -1
  88. package/build-module/components/error-boundary/index.js +5 -0
  89. package/build-module/components/error-boundary/index.js.map +1 -1
  90. package/build-module/components/global-styles/dimensions-panel.js +191 -22
  91. package/build-module/components/global-styles/dimensions-panel.js.map +1 -1
  92. package/build-module/components/global-styles/global-styles-provider.js +4 -2
  93. package/build-module/components/global-styles/global-styles-provider.js.map +1 -1
  94. package/build-module/components/global-styles/hooks.js +11 -2
  95. package/build-module/components/global-styles/hooks.js.map +1 -1
  96. package/build-module/components/global-styles/screen-color-palette.js +14 -19
  97. package/build-module/components/global-styles/screen-color-palette.js.map +1 -1
  98. package/build-module/components/global-styles/screen-colors.js +59 -7
  99. package/build-module/components/global-styles/screen-colors.js.map +1 -1
  100. package/build-module/components/global-styles/screen-heading-color.js +143 -0
  101. package/build-module/components/global-styles/screen-heading-color.js.map +1 -0
  102. package/build-module/components/global-styles/screen-link-color.js +47 -14
  103. package/build-module/components/global-styles/screen-link-color.js.map +1 -1
  104. package/build-module/components/global-styles/screen-typography-element.js +4 -0
  105. package/build-module/components/global-styles/screen-typography-element.js.map +1 -1
  106. package/build-module/components/global-styles/screen-typography.js +5 -0
  107. package/build-module/components/global-styles/screen-typography.js.map +1 -1
  108. package/build-module/components/global-styles/typography-panel.js +74 -13
  109. package/build-module/components/global-styles/typography-panel.js.map +1 -1
  110. package/build-module/components/global-styles/typography-utils.js +204 -0
  111. package/build-module/components/global-styles/typography-utils.js.map +1 -0
  112. package/build-module/components/global-styles/ui.js +10 -0
  113. package/build-module/components/global-styles/ui.js.map +1 -1
  114. package/build-module/components/global-styles/use-global-styles-output.js +294 -69
  115. package/build-module/components/global-styles/use-global-styles-output.js.map +1 -1
  116. package/build-module/components/global-styles/utils.js +47 -4
  117. package/build-module/components/global-styles/utils.js.map +1 -1
  118. package/build-module/components/header/index.js +25 -12
  119. package/build-module/components/header/index.js.map +1 -1
  120. package/build-module/components/header/undo-redo/redo.js +3 -2
  121. package/build-module/components/header/undo-redo/redo.js.map +1 -1
  122. package/build-module/components/keyboard-shortcut-help-modal/index.js +1 -2
  123. package/build-module/components/keyboard-shortcut-help-modal/index.js.map +1 -1
  124. package/build-module/components/list/actions/index.js +1 -1
  125. package/build-module/components/list/actions/index.js.map +1 -1
  126. package/build-module/components/save-button/index.js +3 -4
  127. package/build-module/components/save-button/index.js.map +1 -1
  128. package/build-module/components/sidebar/navigation-menu-sidebar/navigation-menu.js +3 -3
  129. package/build-module/components/sidebar/navigation-menu-sidebar/navigation-menu.js.map +1 -1
  130. package/build-module/components/sidebar/template-card/template-actions.js +1 -1
  131. package/build-module/components/sidebar/template-card/template-actions.js.map +1 -1
  132. package/build-module/components/template-details/edit-template-title.js +12 -3
  133. package/build-module/components/template-details/edit-template-title.js.map +1 -1
  134. package/build-module/components/template-details/index.js +3 -22
  135. package/build-module/components/template-details/index.js.map +1 -1
  136. package/build-module/components/template-details/template-areas.js +1 -1
  137. package/build-module/components/template-details/template-areas.js.map +1 -1
  138. package/build-module/components/template-part-converter/convert-to-template-part.js +3 -1
  139. package/build-module/components/template-part-converter/convert-to-template-part.js.map +1 -1
  140. package/build-module/hooks/index.js +1 -0
  141. package/build-module/hooks/index.js.map +1 -1
  142. package/build-module/hooks/template-part-edit.js +67 -0
  143. package/build-module/hooks/template-part-edit.js.map +1 -0
  144. package/build-module/store/selectors.js +5 -2
  145. package/build-module/store/selectors.js.map +1 -1
  146. package/build-style/style-rtl.css +55 -48
  147. package/build-style/style.css +55 -48
  148. package/package.json +29 -29
  149. package/src/components/add-new-template/add-custom-generic-template-modal.js +97 -0
  150. package/src/components/add-new-template/add-custom-template-modal.js +93 -68
  151. package/src/components/add-new-template/new-template.js +126 -95
  152. package/src/components/add-new-template/style.scss +41 -8
  153. package/src/components/add-new-template/utils.js +622 -80
  154. package/src/components/block-editor/index.js +0 -2
  155. package/src/components/code-editor/index.js +15 -5
  156. package/src/components/editor/index.js +11 -0
  157. package/src/components/error-boundary/index.js +5 -0
  158. package/src/components/global-styles/dimensions-panel.js +214 -24
  159. package/src/components/global-styles/global-styles-provider.js +8 -9
  160. package/src/components/global-styles/hooks.js +18 -0
  161. package/src/components/global-styles/screen-color-palette.js +25 -27
  162. package/src/components/global-styles/screen-colors.js +55 -7
  163. package/src/components/global-styles/screen-heading-color.js +201 -0
  164. package/src/components/global-styles/screen-link-color.js +65 -23
  165. package/src/components/global-styles/screen-typography-element.js +4 -0
  166. package/src/components/global-styles/screen-typography.js +6 -0
  167. package/src/components/global-styles/style.scss +14 -11
  168. package/src/components/global-styles/test/typography-utils.js +130 -0
  169. package/src/components/global-styles/test/use-global-styles-output.js +296 -2
  170. package/src/components/global-styles/typography-panel.js +85 -16
  171. package/src/components/global-styles/typography-utils.js +228 -0
  172. package/src/components/global-styles/ui.js +13 -0
  173. package/src/components/global-styles/use-global-styles-output.js +387 -89
  174. package/src/components/global-styles/utils.js +43 -2
  175. package/src/components/header/index.js +37 -13
  176. package/src/components/header/style.scss +5 -3
  177. package/src/components/header/undo-redo/redo.js +6 -2
  178. package/src/components/keyboard-shortcut-help-modal/index.js +1 -2
  179. package/src/components/keyboard-shortcut-help-modal/style.scss +0 -5
  180. package/src/components/list/actions/index.js +3 -1
  181. package/src/components/list/style.scss +0 -8
  182. package/src/components/save-button/index.js +10 -13
  183. package/src/components/sidebar/navigation-menu-sidebar/navigation-menu.js +1 -5
  184. package/src/components/sidebar/style.scss +4 -0
  185. package/src/components/sidebar/template-card/template-actions.js +3 -1
  186. package/src/components/template-details/edit-template-title.js +10 -2
  187. package/src/components/template-details/index.js +7 -22
  188. package/src/components/template-details/template-areas.js +3 -1
  189. package/src/components/template-part-converter/convert-to-template-part.js +3 -1
  190. package/src/components/test/error-boundary.js +38 -0
  191. package/src/hooks/index.js +1 -0
  192. package/src/hooks/template-part-edit.js +82 -0
  193. package/src/store/selectors.js +11 -5
  194. package/src/style.scss +0 -1
  195. package/build/components/edit-template-part-menu-button/index.js +0 -90
  196. package/build/components/edit-template-part-menu-button/index.js.map +0 -1
  197. package/build-module/components/edit-template-part-menu-button/index.js +0 -72
  198. package/build-module/components/edit-template-part-menu-button/index.js.map +0 -1
  199. package/src/components/edit-template-part-menu-button/index.js +0 -82
@@ -1,7 +1,12 @@
1
1
  /**
2
2
  * External dependencies
3
3
  */
4
- import { get, find, isString } from 'lodash';
4
+ import { get, find } from 'lodash';
5
+
6
+ /**
7
+ * Internal dependencies
8
+ */
9
+ import { getTypographyFontSizeValue } from './typography-utils';
5
10
 
6
11
  /* Supporting data. */
7
12
  export const ROOT_BLOCK_NAME = 'root';
@@ -58,6 +63,8 @@ export const PRESET_METADATA = [
58
63
  },
59
64
  {
60
65
  path: [ 'typography', 'fontSizes' ],
66
+ valueFunc: ( preset, { typography: typographySettings } ) =>
67
+ getTypographyFontSizeValue( preset, typographySettings ),
61
68
  valueKey: 'size',
62
69
  cssVarInfix: 'font-size',
63
70
  classes: [ { classSuffix: 'font-size', propertyName: 'font-size' } ],
@@ -78,6 +85,9 @@ const STYLE_PATH_TO_CSS_VAR_INFIX = {
78
85
  'elements.link.color.text': 'color',
79
86
  'elements.button.color.text': 'color',
80
87
  'elements.button.backgroundColor': 'background-color',
88
+ 'elements.heading.color': 'color',
89
+ 'elements.heading.backgroundColor': 'background-color',
90
+ 'elements.heading.gradient': 'gradient',
81
91
  'color.gradient': 'gradient',
82
92
  'typography.fontSize': 'font-size',
83
93
  'typography.fontFamily': 'font-family',
@@ -213,7 +223,7 @@ function getValueFromCustomVariable( features, blockName, variable, path ) {
213
223
  }
214
224
 
215
225
  export function getValueFromVariable( features, blockName, variable ) {
216
- if ( ! variable || ! isString( variable ) ) {
226
+ if ( ! variable || typeof variable !== 'string' ) {
217
227
  return variable;
218
228
  }
219
229
  const USER_VALUE_PREFIX = 'var:';
@@ -255,3 +265,34 @@ export function getValueFromVariable( features, blockName, variable ) {
255
265
  }
256
266
  return variable;
257
267
  }
268
+
269
+ /**
270
+ * Function that scopes a selector with another one. This works a bit like
271
+ * SCSS nesting except the `&` operator isn't supported.
272
+ *
273
+ * @example
274
+ * ```js
275
+ * const scope = '.a, .b .c';
276
+ * const selector = '> .x, .y';
277
+ * const merged = scopeSelector( scope, selector );
278
+ * // merged is '.a > .x, .a .y, .b .c > .x, .b .c .y'
279
+ * ```
280
+ *
281
+ * @param {string} scope Selector to scope to.
282
+ * @param {string} selector Original selector.
283
+ *
284
+ * @return {string} Scoped selector.
285
+ */
286
+ export function scopeSelector( scope, selector ) {
287
+ const scopes = scope.split( ',' );
288
+ const selectors = selector.split( ',' );
289
+
290
+ const selectorsScoped = [];
291
+ scopes.forEach( ( outer ) => {
292
+ selectors.forEach( ( inner ) => {
293
+ selectorsScoped.push( `${ outer.trim() } ${ inner.trim() }` );
294
+ } );
295
+ } );
296
+
297
+ return selectorsScoped.join( ', ' );
298
+ }
@@ -11,8 +11,14 @@ import {
11
11
  import { useSelect, useDispatch } from '@wordpress/data';
12
12
  import { PinnedItems } from '@wordpress/interface';
13
13
  import { _x, __ } from '@wordpress/i18n';
14
- import { listView, plus } from '@wordpress/icons';
15
- import { Button, ToolbarItem } from '@wordpress/components';
14
+ import { listView, plus, external } from '@wordpress/icons';
15
+ import {
16
+ Button,
17
+ ToolbarItem,
18
+ MenuGroup,
19
+ MenuItem,
20
+ VisuallyHidden,
21
+ } from '@wordpress/components';
16
22
  import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';
17
23
  import { store as editorStore } from '@wordpress/editor';
18
24
  import { store as coreStore } from '@wordpress/core-data';
@@ -48,6 +54,7 @@ export default function Header( {
48
54
  listViewShortcut,
49
55
  isLoaded,
50
56
  isVisualMode,
57
+ settings,
51
58
  } = useSelect( ( select ) => {
52
59
  const {
53
60
  __experimentalGetPreviewDeviceType,
@@ -56,6 +63,7 @@ export default function Header( {
56
63
  isInserterOpened,
57
64
  isListViewOpened,
58
65
  getEditorMode,
66
+ getSettings,
59
67
  } = select( editSiteStore );
60
68
  const { getEditedEntityRecord } = select( coreStore );
61
69
  const { __experimentalGetTemplateInfo: getTemplateInfo } =
@@ -79,6 +87,7 @@ export default function Header( {
79
87
  'core/edit-site/toggle-list-view'
80
88
  ),
81
89
  isVisualMode: getEditorMode() === 'visual',
90
+ settings: getSettings(),
82
91
  };
83
92
  }, [] );
84
93
 
@@ -106,6 +115,13 @@ export default function Header( {
106
115
 
107
116
  const isFocusMode = templateType === 'wp_template_part';
108
117
 
118
+ /* translators: button label text should, if possible, be under 16 characters. */
119
+ const longLabel = _x(
120
+ 'Toggle block inserter',
121
+ 'Generic label for block inserter button'
122
+ );
123
+ const shortLabel = ! isInserterOpen ? __( 'Add' ) : __( 'Close' );
124
+
109
125
  return (
110
126
  <div className="edit-site-header">
111
127
  <NavigableToolbar
@@ -123,17 +139,9 @@ export default function Header( {
123
139
  onClick={ openInserter }
124
140
  disabled={ ! isVisualMode }
125
141
  icon={ plus }
126
- /* translators: button label text should, if possible, be under 16
127
- characters. */
128
- label={ _x(
129
- 'Toggle block inserter',
130
- 'Generic label for block inserter button'
131
- ) }
142
+ label={ showIconLabels ? shortLabel : longLabel }
132
143
  showTooltip={ ! showIconLabels }
133
- >
134
- { showIconLabels &&
135
- ( ! isInserterOpen ? __( 'Add' ) : __( 'Close' ) ) }
136
- </ToolbarItem>
144
+ />
137
145
  { isLargeViewport && (
138
146
  <>
139
147
  <ToolbarItem
@@ -201,7 +209,23 @@ export default function Header( {
201
209
  <PreviewOptions
202
210
  deviceType={ deviceType }
203
211
  setDeviceType={ setPreviewDeviceType }
204
- />
212
+ >
213
+ <MenuGroup>
214
+ <MenuItem
215
+ href={ settings?.siteUrl }
216
+ target="_blank"
217
+ icon={ external }
218
+ >
219
+ { __( 'View site' ) }
220
+ <VisuallyHidden as="span">
221
+ {
222
+ /* translators: accessibility text */
223
+ __( '(opens in a new tab)' )
224
+ }
225
+ </VisuallyHidden>
226
+ </MenuItem>
227
+ </MenuGroup>
228
+ </PreviewOptions>
205
229
  ) }
206
230
  <SaveButton
207
231
  openEntitiesSavedStates={ openEntitiesSavedStates }
@@ -226,15 +226,17 @@ body.is-navigation-sidebar-open {
226
226
  padding-right: 6px;
227
227
  }
228
228
 
229
- // The inserter and the template details toggle have custom labels, different from their aria-label, so we don't want to display both.
230
- .edit-site-header-toolbar__inserter-toggle.edit-site-header-toolbar__inserter-toggle,
229
+ // The template details toggle has a custom label, different from its aria-label, so we don't want to display both.
231
230
  .edit-site-document-actions__get-info.edit-site-document-actions__get-info.edit-site-document-actions__get-info {
232
231
  &::after {
233
232
  content: none;
234
233
  }
234
+ }
235
235
 
236
+ .edit-site-header-toolbar__inserter-toggle.edit-site-header-toolbar__inserter-toggle,
237
+ .edit-site-document-actions__get-info.edit-site-document-actions__get-info.edit-site-document-actions__get-info {
236
238
  height: 36px;
237
- padding: 0 6px;
239
+ padding: 0 $grid-unit-10;
238
240
  }
239
241
 
240
242
  .edit-site-header_start .edit-site-header__toolbar > * + * {
@@ -5,11 +5,15 @@ import { __, isRTL } from '@wordpress/i18n';
5
5
  import { Button } from '@wordpress/components';
6
6
  import { useSelect, useDispatch } from '@wordpress/data';
7
7
  import { redo as redoIcon, undo as undoIcon } from '@wordpress/icons';
8
- import { displayShortcut } from '@wordpress/keycodes';
8
+ import { displayShortcut, isAppleOS } from '@wordpress/keycodes';
9
9
  import { store as coreStore } from '@wordpress/core-data';
10
10
  import { forwardRef } from '@wordpress/element';
11
11
 
12
12
  function RedoButton( props, ref ) {
13
+ const shortcut = isAppleOS()
14
+ ? displayShortcut.primaryShift( 'z' )
15
+ : displayShortcut.primary( 'y' );
16
+
13
17
  const hasRedo = useSelect(
14
18
  ( select ) => select( coreStore ).hasRedo(),
15
19
  []
@@ -21,7 +25,7 @@ function RedoButton( props, ref ) {
21
25
  ref={ ref }
22
26
  icon={ ! isRTL() ? redoIcon : undoIcon }
23
27
  label={ __( 'Redo' ) }
24
- shortcut={ displayShortcut.primaryShift( 'z' ) }
28
+ shortcut={ shortcut }
25
29
  // If there are no undo levels we don't want to actually disable this
26
30
  // button, because it will remove focus for keyboard users.
27
31
  // See: https://github.com/WordPress/gutenberg/issues/3486
@@ -2,7 +2,6 @@
2
2
  * External dependencies
3
3
  */
4
4
  import classnames from 'classnames';
5
- import { isString } from 'lodash';
6
5
 
7
6
  /**
8
7
  * WordPress dependencies
@@ -34,7 +33,7 @@ const ShortcutList = ( { shortcuts } ) => (
34
33
  className="edit-site-keyboard-shortcut-help-modal__shortcut"
35
34
  key={ index }
36
35
  >
37
- { isString( shortcut ) ? (
36
+ { typeof shortcut === 'string' ? (
38
37
  <DynamicShortcut name={ shortcut } />
39
38
  ) : (
40
39
  <Shortcut { ...shortcut } />
@@ -3,11 +3,6 @@
3
3
  margin: 0 0 2rem 0;
4
4
  }
5
5
 
6
- &__main-shortcuts .edit-site-keyboard-shortcut-help-modal__shortcut-list {
7
- // Push the shortcut to be flush with top modal header.
8
- margin-top: -$grid-unit-30 -$border-width;
9
- }
10
-
11
6
  &__section-title {
12
7
  font-size: 0.9rem;
13
8
  font-weight: 600;
@@ -79,7 +79,9 @@ export default function Actions( { template } ) {
79
79
  ) }
80
80
  { isRevertable && (
81
81
  <MenuItem
82
- info={ __( 'Restore to default state' ) }
82
+ info={ __(
83
+ 'Use the template as supplied by the theme.'
84
+ ) }
83
85
  onClick={ () => {
84
86
  revertAndSaveTemplate();
85
87
  onClose();
@@ -131,14 +131,6 @@
131
131
  width: $grid-unit * 40;
132
132
  }
133
133
  }
134
-
135
- .components-modal__header {
136
- border-bottom: none;
137
- }
138
-
139
- .components-modal__content::before {
140
- margin-bottom: $grid-unit-05;
141
- }
142
134
  }
143
135
 
144
136
  .edit-site-list__rename-modal-actions {
@@ -30,18 +30,15 @@ export default function SaveButton( {
30
30
  const disabled = ! isDirty || isSaving;
31
31
 
32
32
  return (
33
- <>
34
- <Button
35
- variant="primary"
36
- className="edit-site-save-button__button"
37
- aria-disabled={ disabled }
38
- aria-expanded={ isEntitiesSavedStatesOpen }
39
- disabled={ disabled }
40
- isBusy={ isSaving }
41
- onClick={ disabled ? undefined : openEntitiesSavedStates }
42
- >
43
- { __( 'Save' ) }
44
- </Button>
45
- </>
33
+ <Button
34
+ variant="primary"
35
+ className="edit-site-save-button__button"
36
+ aria-disabled={ disabled }
37
+ aria-expanded={ isEntitiesSavedStatesOpen }
38
+ isBusy={ isSaving }
39
+ onClick={ disabled ? undefined : openEntitiesSavedStates }
40
+ >
41
+ { __( 'Save' ) }
42
+ </Button>
46
43
  );
47
44
  }
@@ -48,9 +48,5 @@ export default function NavigationMenu( { innerBlocks, id } ) {
48
48
  }
49
49
  } );
50
50
  }, [ updateBlockListSettings, innerBlocks ] );
51
- return (
52
- <>
53
- <ListView id={ id } />
54
- </>
55
- );
51
+ return <ListView id={ id } />;
56
52
  }
@@ -60,6 +60,10 @@
60
60
  grid-column: span 1;
61
61
  }
62
62
 
63
+ .edit-site-global-styles-sidebar .components-tools-panel .span-columns {
64
+ grid-column: 1 / -1;
65
+ }
66
+
63
67
  .edit-site-global-styles-sidebar__blocks-group {
64
68
  padding-top: $grid-unit-30;
65
69
  border-top: $border-width solid $gray-200;
@@ -28,7 +28,9 @@ export default function Actions( { template } ) {
28
28
  { ( { onClose } ) => (
29
29
  <MenuGroup>
30
30
  <MenuItem
31
- info={ __( 'Restore to default state' ) }
31
+ info={ __(
32
+ 'Use the template as supplied by the theme.'
33
+ ) }
32
34
  onClick={ () => {
33
35
  revertTemplate( template );
34
36
  onClose();
@@ -4,8 +4,10 @@
4
4
  import { __ } from '@wordpress/i18n';
5
5
  import { TextControl } from '@wordpress/components';
6
6
  import { useEntityProp } from '@wordpress/core-data';
7
+ import { useState } from '@wordpress/element';
7
8
 
8
9
  export default function EditTemplateTitle( { template } ) {
10
+ const [ forceEmpty, setForceEmpty ] = useState( false );
9
11
  const [ title, setTitle ] = useEntityProp(
10
12
  'postType',
11
13
  template.type,
@@ -16,13 +18,19 @@ export default function EditTemplateTitle( { template } ) {
16
18
  return (
17
19
  <TextControl
18
20
  label={ __( 'Title' ) }
19
- value={ title }
21
+ value={ forceEmpty ? '' : title }
20
22
  help={ __(
21
23
  'Give the template a title that indicates its purpose, e.g. "Full Width".'
22
24
  ) }
23
25
  onChange={ ( newTitle ) => {
24
- setTitle( newTitle || template.slug );
26
+ if ( ! newTitle && ! forceEmpty ) {
27
+ setForceEmpty( true );
28
+ return;
29
+ }
30
+ setForceEmpty( false );
31
+ setTitle( newTitle );
25
32
  } }
33
+ onBlur={ () => setForceEmpty( false ) }
26
34
  />
27
35
  );
28
36
  }
@@ -1,8 +1,7 @@
1
1
  /**
2
2
  * WordPress dependencies
3
3
  */
4
- import { useMemo } from '@wordpress/element';
5
- import { sprintf, __ } from '@wordpress/i18n';
4
+ import { __ } from '@wordpress/i18n';
6
5
  import {
7
6
  Button,
8
7
  MenuGroup,
@@ -17,10 +16,6 @@ import { store as editorStore } from '@wordpress/editor';
17
16
  * Internal dependencies
18
17
  */
19
18
  import isTemplateRevertable from '../../utils/is-template-revertable';
20
- import {
21
- MENU_TEMPLATES,
22
- TEMPLATE_PARTS_SUB_MENUS,
23
- } from '../navigation-sidebar/navigation-panel/constants';
24
19
  import { store as editSiteStore } from '../../store';
25
20
  import TemplateAreas from './template-areas';
26
21
  import EditTemplateTitle from './edit-template-title';
@@ -34,16 +29,6 @@ export default function TemplateDetails( { template, onClose } ) {
34
29
  );
35
30
  const { revertTemplate } = useDispatch( editSiteStore );
36
31
 
37
- const templateSubMenu = useMemo( () => {
38
- if ( template?.type === 'wp_template' ) {
39
- return { title: __( 'templates' ), menu: MENU_TEMPLATES };
40
- }
41
-
42
- return TEMPLATE_PARTS_SUB_MENUS.find(
43
- ( { area } ) => area === template?.area
44
- );
45
- }, [ template ] );
46
-
47
32
  const browseAllLinkProps = useLink( {
48
33
  // TODO: We should update this to filter by template part's areas as well.
49
34
  postType: template.type,
@@ -94,7 +79,9 @@ export default function TemplateDetails( { template, onClose } ) {
94
79
  <MenuGroup className="edit-site-template-details__group edit-site-template-details__revert">
95
80
  <MenuItem
96
81
  className="edit-site-template-details__revert-button"
97
- info={ __( 'Restore template to default state' ) }
82
+ info={ __(
83
+ 'Use the template as supplied by the theme.'
84
+ ) }
98
85
  onClick={ revert }
99
86
  >
100
87
  { __( 'Clear customizations' ) }
@@ -106,11 +93,9 @@ export default function TemplateDetails( { template, onClose } ) {
106
93
  className="edit-site-template-details__show-all-button"
107
94
  { ...browseAllLinkProps }
108
95
  >
109
- { sprintf(
110
- /* translators: the template part's area name ("Headers", "Sidebars") or "templates". */
111
- __( 'Browse all %s' ),
112
- templateSubMenu.title
113
- ) }
96
+ { template?.type === 'wp_template'
97
+ ? __( 'Browse all templates' )
98
+ : __( 'Browse all template parts' ) }
114
99
  </Button>
115
100
  </div>
116
101
  );
@@ -59,7 +59,9 @@ function TemplatePartItemMore( {
59
59
  { isTemplateRevertable( templatePart ) && (
60
60
  <MenuGroup>
61
61
  <MenuItem
62
- info={ __( 'Restore template to default state' ) }
62
+ info={ __(
63
+ 'Use the template part as supplied by the theme.'
64
+ ) }
63
65
  onClick={ clearCustomizations }
64
66
  >
65
67
  { __( 'Clear customizations' ) }
@@ -17,6 +17,7 @@ import { __ } from '@wordpress/i18n';
17
17
  import { useState } from '@wordpress/element';
18
18
  import { store as coreStore } from '@wordpress/core-data';
19
19
  import { store as noticesStore } from '@wordpress/notices';
20
+ import { symbolFilled } from '@wordpress/icons';
20
21
 
21
22
  /**
22
23
  * Internal dependencies
@@ -65,11 +66,12 @@ export default function ConvertToTemplatePart( { clientIds, blocks } ) {
65
66
  <BlockSettingsMenuControls>
66
67
  { () => (
67
68
  <MenuItem
69
+ icon={ symbolFilled }
68
70
  onClick={ () => {
69
71
  setIsModalOpen( true );
70
72
  } }
71
73
  >
72
- { __( 'Make template part' ) }
74
+ { __( 'Create Template part' ) }
73
75
  </MenuItem>
74
76
  ) }
75
77
  </BlockSettingsMenuControls>
@@ -0,0 +1,38 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import * as wpHooks from '@wordpress/hooks';
5
+ /**
6
+ * Internal dependencies
7
+ */
8
+ import ErrorBoundary from '../error-boundary';
9
+ /**
10
+ * External dependencies
11
+ */
12
+ import { render } from '@testing-library/react';
13
+
14
+ const theError = new Error( 'Kaboom' );
15
+
16
+ const ChildComponent = () => {
17
+ throw theError;
18
+ };
19
+
20
+ describe( 'Error Boundary', () => {
21
+ describe( 'when error is thrown from a Child component', () => {
22
+ it( 'calls the `editor.ErrorBoundary.errorLogged` hook action with the error object', () => {
23
+ const doAction = jest.spyOn( wpHooks, 'doAction' );
24
+
25
+ render(
26
+ <ErrorBoundary>
27
+ <ChildComponent />
28
+ </ErrorBoundary>
29
+ );
30
+
31
+ expect( doAction ).toHaveBeenCalledWith(
32
+ 'editor.ErrorBoundary.errorLogged',
33
+ theError
34
+ );
35
+ expect( console ).toHaveErrored();
36
+ } );
37
+ } );
38
+ } );
@@ -2,3 +2,4 @@
2
2
  * Internal dependencies
3
3
  */
4
4
  import './components';
5
+ import './template-part-edit';
@@ -0,0 +1,82 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import { __ } from '@wordpress/i18n';
5
+ import { useSelect } from '@wordpress/data';
6
+ import { BlockControls } from '@wordpress/block-editor';
7
+ import { store as coreStore } from '@wordpress/core-data';
8
+ import { ToolbarButton } from '@wordpress/components';
9
+ import { addFilter } from '@wordpress/hooks';
10
+ import { createHigherOrderComponent } from '@wordpress/compose';
11
+
12
+ /**
13
+ * Internal dependencies
14
+ */
15
+ import { useLocation } from '../components/routes';
16
+ import { useLink } from '../components/routes/link';
17
+
18
+ function EditTemplatePartMenuItem( { attributes } ) {
19
+ const { theme, slug } = attributes;
20
+ const { params } = useLocation();
21
+ const templatePart = useSelect(
22
+ ( select ) => {
23
+ return select( coreStore ).getEntityRecord(
24
+ 'postType',
25
+ 'wp_template_part',
26
+ // Ideally this should be an official public API.
27
+ `${ theme }//${ slug }`
28
+ );
29
+ },
30
+ [ theme, slug ]
31
+ );
32
+
33
+ const linkProps = useLink(
34
+ {
35
+ postId: templatePart?.id,
36
+ postType: templatePart?.type,
37
+ },
38
+ {
39
+ fromTemplateId: params.postId,
40
+ }
41
+ );
42
+
43
+ if ( ! templatePart ) {
44
+ return null;
45
+ }
46
+
47
+ return (
48
+ <BlockControls group="other">
49
+ <ToolbarButton
50
+ { ...linkProps }
51
+ onClick={ ( event ) => {
52
+ linkProps.onClick( event );
53
+ } }
54
+ >
55
+ { __( 'Edit' ) }
56
+ </ToolbarButton>
57
+ </BlockControls>
58
+ );
59
+ }
60
+
61
+ export const withEditBlockControls = createHigherOrderComponent(
62
+ ( BlockEdit ) => ( props ) => {
63
+ const { attributes, name } = props;
64
+ const isDisplayed = name === 'core/template-part' && attributes.slug;
65
+
66
+ return (
67
+ <>
68
+ <BlockEdit { ...props } />
69
+ { isDisplayed && (
70
+ <EditTemplatePartMenuItem attributes={ attributes } />
71
+ ) }
72
+ </>
73
+ );
74
+ },
75
+ 'withEditBlockControls'
76
+ );
77
+
78
+ addFilter(
79
+ 'editor.BlockEdit',
80
+ 'core/edit-site/template-part-edit-button',
81
+ withEditBlockControls
82
+ );
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * External dependencies
3
3
  */
4
- import { map, keyBy } from 'lodash';
4
+ import { map } from 'lodash';
5
5
  import createSelector from 'rememo';
6
6
 
7
7
  /**
@@ -341,10 +341,16 @@ export const getCurrentTemplateTemplateParts = createRegistrySelector(
341
341
  'wp_template_part',
342
342
  { per_page: -1 }
343
343
  );
344
- const templatePartsById = keyBy(
345
- templateParts,
346
- ( templatePart ) => templatePart.id
347
- );
344
+ const templatePartsById = templateParts
345
+ ? // Key template parts by their ID.
346
+ templateParts.reduce(
347
+ ( newTemplateParts, part ) => ( {
348
+ ...newTemplateParts,
349
+ [ part.id ]: part,
350
+ } ),
351
+ {}
352
+ )
353
+ : {};
348
354
 
349
355
  return ( template.blocks ?? [] )
350
356
  .filter( ( block ) => isTemplatePart( block ) )
package/src/style.scss CHANGED
@@ -26,7 +26,6 @@ html.wp-toolbar {
26
26
  background: $white;
27
27
  }
28
28
 
29
- body.appearance_page_gutenberg-edit-site,
30
29
  body.site-editor-php {
31
30
  @include wp-admin-reset(".edit-site");
32
31
  }