@wordpress/block-editor 14.18.0 → 14.20.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 (48) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/build/components/background-image-control/index.js +21 -11
  3. package/build/components/background-image-control/index.js.map +1 -1
  4. package/build/components/html-element-control/index.js +1 -1
  5. package/build/components/html-element-control/index.js.map +1 -1
  6. package/build/components/html-element-control/messages.js +2 -0
  7. package/build/components/html-element-control/messages.js.map +1 -1
  8. package/build/components/image-size-control/index.js +5 -6
  9. package/build/components/image-size-control/index.js.map +1 -1
  10. package/build/components/media-placeholder/index.js +3 -4
  11. package/build/components/media-placeholder/index.js.map +1 -1
  12. package/build/layouts/flex.js +5 -1
  13. package/build/layouts/flex.js.map +1 -1
  14. package/build/store/selectors.js +3 -3
  15. package/build/store/selectors.js.map +1 -1
  16. package/build-module/components/background-image-control/index.js +21 -11
  17. package/build-module/components/background-image-control/index.js.map +1 -1
  18. package/build-module/components/html-element-control/index.js +1 -1
  19. package/build-module/components/html-element-control/index.js.map +1 -1
  20. package/build-module/components/html-element-control/messages.js +2 -0
  21. package/build-module/components/html-element-control/messages.js.map +1 -1
  22. package/build-module/components/image-size-control/index.js +6 -7
  23. package/build-module/components/image-size-control/index.js.map +1 -1
  24. package/build-module/components/media-placeholder/index.js +3 -4
  25. package/build-module/components/media-placeholder/index.js.map +1 -1
  26. package/build-module/layouts/flex.js +5 -1
  27. package/build-module/layouts/flex.js.map +1 -1
  28. package/build-module/store/selectors.js +3 -3
  29. package/build-module/store/selectors.js.map +1 -1
  30. package/build-style/content-rtl.css +130 -9
  31. package/build-style/content.css +130 -9
  32. package/build-style/default-editor-styles-rtl.css +130 -9
  33. package/build-style/default-editor-styles.css +130 -9
  34. package/build-style/style-rtl.css +134 -19
  35. package/build-style/style.css +134 -19
  36. package/package.json +34 -34
  37. package/src/components/background-image-control/index.js +21 -13
  38. package/src/components/block-inspector/style.scss +4 -2
  39. package/src/components/html-element-control/index.js +1 -1
  40. package/src/components/html-element-control/messages.js +6 -0
  41. package/src/components/image-size-control/index.js +6 -7
  42. package/src/components/media-placeholder/index.js +4 -4
  43. package/src/components/rich-text/README.md +1 -1
  44. package/src/components/url-popover/stories/index.story.js +9 -1
  45. package/src/layouts/flex.js +7 -2
  46. package/src/store/selectors.js +3 -3
  47. package/src/style.scss +0 -1
  48. package/src/components/image-size-control/style.scss +0 -8
@@ -249,6 +249,7 @@ function BackgroundImageControls( {
249
249
  onResetImage = noop,
250
250
  displayInPanel,
251
251
  defaultValues,
252
+ containerRef,
252
253
  } ) {
253
254
  const [ isUploading, setIsUploading ] = useState( false );
254
255
  const { getSettings } = useSelect( blockEditorStore );
@@ -256,7 +257,6 @@ function BackgroundImageControls( {
256
257
  const { id, title, url } = style?.background?.backgroundImage || {
257
258
  ...inheritedValue?.background?.backgroundImage,
258
259
  };
259
- const replaceContainerRef = useRef();
260
260
  const { createErrorNotice } = useDispatch( noticesStore );
261
261
  const onUploadError = ( message ) => {
262
262
  createErrorNotice( message, { type: 'snackbar' } );
@@ -324,6 +324,8 @@ function BackgroundImageControls( {
324
324
  } )
325
325
  );
326
326
  setIsUploading( false );
327
+ // Close the dropdown and focus the toggle button.
328
+ closeAndFocus();
327
329
  };
328
330
 
329
331
  // Drag and drop callback, restricting image to one.
@@ -342,14 +344,19 @@ function BackgroundImageControls( {
342
344
  const hasValue = hasBackgroundImageValue( style );
343
345
 
344
346
  const closeAndFocus = () => {
345
- const [ toggleButton ] = focus.tabbable.find(
346
- replaceContainerRef.current
347
- );
348
- // Focus the toggle button and close the dropdown menu.
349
- // This ensures similar behaviour as to selecting an image, where the dropdown is
350
- // closed and focus is redirected to the dropdown toggle button.
351
- toggleButton?.focus();
352
- toggleButton?.click();
347
+ // Use requestAnimationFrame to ensure DOM updates are complete
348
+ window.requestAnimationFrame( () => {
349
+ const [ toggleButton ] = focus.tabbable.find(
350
+ containerRef?.current
351
+ );
352
+ if ( ! toggleButton ) {
353
+ return;
354
+ }
355
+ // Focus the toggle button and close the dropdown menu.
356
+ // This ensures similar behaviour as to selecting an image, where the dropdown is
357
+ // closed and focus is redirected to the dropdown toggle button.
358
+ toggleButton.focus();
359
+ } );
353
360
  };
354
361
 
355
362
  const onRemove = () =>
@@ -363,10 +370,7 @@ function BackgroundImageControls( {
363
370
  title || getFilename( url ) || __( 'Add background image' );
364
371
 
365
372
  return (
366
- <div
367
- ref={ replaceContainerRef }
368
- className="block-editor-global-styles-background-panel__image-tools-panel-item"
369
- >
373
+ <div className="block-editor-global-styles-background-panel__image-tools-panel-item">
370
374
  { isUploading && <LoadingSpinner /> }
371
375
  <MediaReplaceFlow
372
376
  mediaId={ id }
@@ -697,9 +701,11 @@ export default function BackgroundImagePanel( {
697
701
  settings?.background?.backgroundRepeat );
698
702
 
699
703
  const [ isDropDownOpen, setIsDropDownOpen ] = useState( false );
704
+ const containerRef = useRef();
700
705
 
701
706
  return (
702
707
  <div
708
+ ref={ containerRef }
703
709
  className={ clsx(
704
710
  'block-editor-global-styles-background-panel__inspector-media-replace-container',
705
711
  {
@@ -727,6 +733,7 @@ export default function BackgroundImagePanel( {
727
733
  } }
728
734
  onRemoveImage={ () => setIsDropDownOpen( false ) }
729
735
  defaultValues={ defaultValues }
736
+ containerRef={ containerRef }
730
737
  />
731
738
  <BackgroundSizeControls
732
739
  onChange={ onChange }
@@ -747,6 +754,7 @@ export default function BackgroundImagePanel( {
747
754
  resetBackground();
748
755
  } }
749
756
  onRemoveImage={ () => setIsDropDownOpen( false ) }
757
+ containerRef={ containerRef }
750
758
  />
751
759
  ) }
752
760
  </div>
@@ -12,7 +12,8 @@
12
12
 
13
13
  .components-base-control,
14
14
  .components-radio-control,
15
- .block-editor-html-element-control {
15
+ .block-editor-html-element-control,
16
+ .block-editor-image-size-control {
16
17
  &:where(:not(:last-child)) {
17
18
  margin-bottom: $grid-unit-20;
18
19
  }
@@ -22,7 +23,8 @@
22
23
  .components-focal-point-picker-control,
23
24
  .components-query-controls,
24
25
  .components-range-control,
25
- .block-editor-html-element-control {
26
+ .block-editor-html-element-control,
27
+ .block-editor-image-size-control {
26
28
  .components-base-control {
27
29
  margin-bottom: 0;
28
30
  }
@@ -22,7 +22,7 @@ import { htmlElementMessages } from './messages';
22
22
  * @param {Object} props Component props.
23
23
  * @param {string} props.tagName The current HTML tag name.
24
24
  * @param {Function} props.onChange Function to call when the tag is changed.
25
- * @param {string} props.clientId The client ID of the current block.
25
+ * @param {string} props.clientId Optional. The client ID of the block. Used to check for existing <main> elements.
26
26
  * @param {Array} props.options SelectControl options (optional).
27
27
  *
28
28
  * @return {Component} The HTML element select control with validation.
@@ -7,12 +7,18 @@ import { __ } from '@wordpress/i18n';
7
7
  * Messages providing helpful descriptions for HTML elements.
8
8
  */
9
9
  export const htmlElementMessages = {
10
+ a: __(
11
+ 'The <a> element should be used for links that navigate to a different page or to a different section within the same page.'
12
+ ),
10
13
  article: __(
11
14
  'The <article> element should represent a self-contained, syndicatable portion of the document.'
12
15
  ),
13
16
  aside: __(
14
17
  "The <aside> element should represent a portion of a document whose content is only indirectly related to the document's main content."
15
18
  ),
19
+ button: __(
20
+ 'The <button> element should be used for interactive controls that perform an action on the current page, such as opening a modal or toggling content visibility.'
21
+ ),
16
22
  div: __(
17
23
  'The <div> element should only be used if the block is a design element with no semantic meaning.'
18
24
  ),
@@ -5,6 +5,7 @@ import {
5
5
  SelectControl,
6
6
  __experimentalNumberControl as NumberControl,
7
7
  __experimentalHStack as HStack,
8
+ __experimentalVStack as VStack,
8
9
  __experimentalToggleGroupControl as ToggleGroupControl,
9
10
  __experimentalToggleGroupControlOption as ToggleGroupControlOption,
10
11
  } from '@wordpress/components';
@@ -87,7 +88,7 @@ export default function ImageSizeControl( {
87
88
  } );
88
89
 
89
90
  return (
90
- <>
91
+ <VStack className="block-editor-image-size-control" spacing="4">
91
92
  { imageSizeOptions && imageSizeOptions.length > 0 && (
92
93
  <SelectControl
93
94
  __nextHasNoMarginBottom
@@ -100,10 +101,9 @@ export default function ImageSizeControl( {
100
101
  />
101
102
  ) }
102
103
  { isResizable && (
103
- <div className="block-editor-image-size-control">
104
- <HStack align="baseline" spacing="3">
104
+ <>
105
+ <HStack align="baseline" spacing="4">
105
106
  <NumberControl
106
- className="block-editor-image-size-control__width"
107
107
  label={ __( 'Width' ) }
108
108
  value={ currentWidth }
109
109
  min={ 1 }
@@ -113,7 +113,6 @@ export default function ImageSizeControl( {
113
113
  size="__unstable-large"
114
114
  />
115
115
  <NumberControl
116
- className="block-editor-image-size-control__height"
117
116
  label={ __( 'Height' ) }
118
117
  value={ currentHeight }
119
118
  min={ 1 }
@@ -146,8 +145,8 @@ export default function ImageSizeControl( {
146
145
  );
147
146
  } ) }
148
147
  </ToggleGroupControl>
149
- </div>
148
+ </>
150
149
  ) }
151
- </>
150
+ </VStack>
152
151
  );
153
152
  }
@@ -272,11 +272,11 @@ export function MediaPlaceholder( {
272
272
  } )
273
273
  ).catch( ( err ) => onError( err ) );
274
274
 
275
- if ( multiple ) {
276
- onSelect( uploadedMediaList );
277
- } else {
278
- onSelect( uploadedMediaList[ 0 ] );
275
+ if ( ! uploadedMediaList?.length ) {
276
+ return;
279
277
  }
278
+
279
+ onSelect( multiple ? uploadedMediaList : uploadedMediaList[ 0 ] );
280
280
  }
281
281
 
282
282
  const onUpload = ( event ) => {
@@ -23,7 +23,7 @@ _Default: `div`._ The [tag name](https://www.w3.org/TR/html51/syntax.html#tag-na
23
23
  ### `placeholder: String`
24
24
 
25
25
  _Optional._ Placeholder text to show when the field is empty, similar to the
26
- [`input` and `textarea` attribute of the same name](https://developer.mozilla.org/en-US/docs/Learn/HTML/Forms/HTML5_updates#The_placeholder_attribute).
26
+ [`input` and `textarea` attribute of the same name](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Attributes/placeholder).
27
27
 
28
28
  ### `disableLineBreaks: Boolean`
29
29
 
@@ -20,6 +20,10 @@ const TestURLPopover = () => {
20
20
  const close = () => setVisiblility( false );
21
21
  const setTarget = () => {};
22
22
 
23
+ const handleUrlChange = ( event ) => {
24
+ setUrl( event.target.value );
25
+ };
26
+
23
27
  return (
24
28
  <>
25
29
  <Button
@@ -40,7 +44,11 @@ const TestURLPopover = () => {
40
44
  ) }
41
45
  >
42
46
  <form onSubmit={ close }>
43
- <input type="url" value={ url } onChange={ setUrl } />
47
+ <input
48
+ type="url"
49
+ value={ url }
50
+ onChange={ handleUrlChange }
51
+ />
44
52
  <Button
45
53
  __next40pxDefaultSize
46
54
  icon={ keyboardReturn }
@@ -56,6 +56,11 @@ const verticalAlignmentMap = {
56
56
  'space-between': 'space-between',
57
57
  };
58
58
 
59
+ const defaultAlignments = {
60
+ horizontal: 'center',
61
+ vertical: 'top',
62
+ };
63
+
59
64
  const flexWrapOptions = [ 'wrap', 'nowrap' ];
60
65
 
61
66
  export default {
@@ -201,8 +206,8 @@ function FlexLayoutVerticalAlignmentControl( { layout, onChange } ) {
201
206
 
202
207
  const defaultVerticalAlignment =
203
208
  orientation === 'horizontal'
204
- ? verticalAlignmentMap.center
205
- : verticalAlignmentMap.top;
209
+ ? defaultAlignments.horizontal
210
+ : defaultAlignments.vertical;
206
211
 
207
212
  const { verticalAlignment = defaultVerticalAlignment } = layout;
208
213
 
@@ -1807,9 +1807,9 @@ export const canInsertBlockType = createRegistrySelector( ( select ) =>
1807
1807
  * Determines if the given blocks are allowed to be inserted into the block
1808
1808
  * list.
1809
1809
  *
1810
- * @param {Object} state Editor state.
1811
- * @param {string} clientIds The block client IDs to be inserted.
1812
- * @param {?string} rootClientId Optional root client ID of block list.
1810
+ * @param {Object} state Editor state.
1811
+ * @param {string[]} clientIds The block client IDs to be inserted.
1812
+ * @param {?string} rootClientId Optional root client ID of block list.
1813
1813
  *
1814
1814
  * @return {boolean} Whether the given blocks are allowed to be inserted.
1815
1815
  */
package/src/style.scss CHANGED
@@ -33,7 +33,6 @@
33
33
  @import "./components/grid/style.scss";
34
34
  @import "./components/height-control/style.scss";
35
35
  @import "./components/iframe/style.scss";
36
- @import "./components/image-size-control/style.scss";
37
36
  @import "./components/inserter-list-item/style.scss";
38
37
  @import "./components/inspector-controls-tabs/style.scss";
39
38
  @import "./components/inspector-popover-header/style.scss";
@@ -1,8 +0,0 @@
1
- .block-editor-image-size-control {
2
- margin-bottom: 1em;
3
-
4
- .block-editor-image-size-control__width,
5
- .block-editor-image-size-control__height {
6
- margin-bottom: 1.115em;
7
- }
8
- }