@wordpress/block-library 8.28.3 → 8.28.4

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 (71) hide show
  1. package/build/button/edit.js +1 -1
  2. package/build/button/edit.js.map +1 -1
  3. package/build/buttons/transforms.js +16 -2
  4. package/build/buttons/transforms.js.map +1 -1
  5. package/build/code/transforms.js +17 -6
  6. package/build/code/transforms.js.map +1 -1
  7. package/build/cover/edit/block-controls.js +14 -3
  8. package/build/cover/edit/block-controls.js.map +1 -1
  9. package/build/cover/edit/inspector-controls.js +1 -1
  10. package/build/cover/edit/inspector-controls.js.map +1 -1
  11. package/build/heading/transforms.js +17 -4
  12. package/build/heading/transforms.js.map +1 -1
  13. package/build/image/edit.js +2 -1
  14. package/build/image/edit.js.map +1 -1
  15. package/build/image/image.js +11 -3
  16. package/build/image/image.js.map +1 -1
  17. package/build/post-featured-image/edit.js +8 -11
  18. package/build/post-featured-image/edit.js.map +1 -1
  19. package/build/post-title/edit.js +2 -2
  20. package/build/post-title/edit.js.map +1 -1
  21. package/build/utils/caption.js +15 -5
  22. package/build/utils/caption.js.map +1 -1
  23. package/build/utils/get-transformed-metadata.js +57 -0
  24. package/build/utils/get-transformed-metadata.js.map +1 -0
  25. package/build-module/button/edit.js +2 -2
  26. package/build-module/button/edit.js.map +1 -1
  27. package/build-module/buttons/transforms.js +16 -2
  28. package/build-module/buttons/transforms.js.map +1 -1
  29. package/build-module/code/transforms.js +17 -6
  30. package/build-module/code/transforms.js.map +1 -1
  31. package/build-module/cover/edit/block-controls.js +15 -4
  32. package/build-module/cover/edit/block-controls.js.map +1 -1
  33. package/build-module/cover/edit/inspector-controls.js +1 -1
  34. package/build-module/cover/edit/inspector-controls.js.map +1 -1
  35. package/build-module/heading/transforms.js +17 -4
  36. package/build-module/heading/transforms.js.map +1 -1
  37. package/build-module/image/edit.js +2 -1
  38. package/build-module/image/edit.js.map +1 -1
  39. package/build-module/image/image.js +12 -4
  40. package/build-module/image/image.js.map +1 -1
  41. package/build-module/post-featured-image/edit.js +9 -12
  42. package/build-module/post-featured-image/edit.js.map +1 -1
  43. package/build-module/post-title/edit.js +2 -2
  44. package/build-module/post-title/edit.js.map +1 -1
  45. package/build-module/utils/caption.js +13 -3
  46. package/build-module/utils/caption.js.map +1 -1
  47. package/build-module/utils/get-transformed-metadata.js +51 -0
  48. package/build-module/utils/get-transformed-metadata.js.map +1 -0
  49. package/build-style/cover/style-rtl.css +2 -1
  50. package/build-style/cover/style.css +2 -1
  51. package/build-style/search/style-rtl.css +2 -0
  52. package/build-style/search/style.css +2 -0
  53. package/build-style/style-rtl.css +4 -1
  54. package/build-style/style.css +4 -1
  55. package/package.json +12 -12
  56. package/src/button/edit.js +2 -1
  57. package/src/buttons/transforms.js +14 -4
  58. package/src/code/transforms.js +20 -5
  59. package/src/cover/edit/block-controls.js +16 -2
  60. package/src/cover/edit/inspector-controls.js +5 -1
  61. package/src/cover/style.scss +3 -2
  62. package/src/footnotes/index.php +1 -1
  63. package/src/heading/transforms.js +27 -8
  64. package/src/image/edit.js +2 -1
  65. package/src/image/image.js +12 -4
  66. package/src/navigation/index.php +7 -3
  67. package/src/post-featured-image/edit.js +9 -11
  68. package/src/post-title/edit.js +49 -43
  69. package/src/search/style.scss +2 -0
  70. package/src/utils/caption.js +10 -1
  71. package/src/utils/get-transformed-metadata.js +65 -0
@@ -115,53 +115,59 @@ export default function PostTitleEdit( {
115
115
  return (
116
116
  <>
117
117
  { blockEditingMode === 'default' && (
118
- <BlockControls group="block">
119
- <HeadingLevelDropdown
120
- value={ level }
121
- onChange={ ( newLevel ) =>
122
- setAttributes( { level: newLevel } )
123
- }
124
- />
125
- <AlignmentControl
126
- value={ textAlign }
127
- onChange={ ( nextAlign ) => {
128
- setAttributes( { textAlign: nextAlign } );
129
- } }
130
- />
131
- </BlockControls>
132
- ) }
133
- <InspectorControls>
134
- <PanelBody title={ __( 'Settings' ) }>
135
- <ToggleControl
136
- __nextHasNoMarginBottom
137
- label={ __( 'Make title a link' ) }
138
- onChange={ () => setAttributes( { isLink: ! isLink } ) }
139
- checked={ isLink }
140
- />
141
- { isLink && (
142
- <>
118
+ <>
119
+ <BlockControls group="block">
120
+ <HeadingLevelDropdown
121
+ value={ level }
122
+ onChange={ ( newLevel ) =>
123
+ setAttributes( { level: newLevel } )
124
+ }
125
+ />
126
+ <AlignmentControl
127
+ value={ textAlign }
128
+ onChange={ ( nextAlign ) => {
129
+ setAttributes( { textAlign: nextAlign } );
130
+ } }
131
+ />
132
+ </BlockControls>
133
+ <InspectorControls>
134
+ <PanelBody title={ __( 'Settings' ) }>
143
135
  <ToggleControl
144
136
  __nextHasNoMarginBottom
145
- label={ __( 'Open in new tab' ) }
146
- onChange={ ( value ) =>
147
- setAttributes( {
148
- linkTarget: value ? '_blank' : '_self',
149
- } )
137
+ label={ __( 'Make title a link' ) }
138
+ onChange={ () =>
139
+ setAttributes( { isLink: ! isLink } )
150
140
  }
151
- checked={ linkTarget === '_blank' }
141
+ checked={ isLink }
152
142
  />
153
- <TextControl
154
- __nextHasNoMarginBottom
155
- label={ __( 'Link rel' ) }
156
- value={ rel }
157
- onChange={ ( newRel ) =>
158
- setAttributes( { rel: newRel } )
159
- }
160
- />
161
- </>
162
- ) }
163
- </PanelBody>
164
- </InspectorControls>
143
+ { isLink && (
144
+ <>
145
+ <ToggleControl
146
+ __nextHasNoMarginBottom
147
+ label={ __( 'Open in new tab' ) }
148
+ onChange={ ( value ) =>
149
+ setAttributes( {
150
+ linkTarget: value
151
+ ? '_blank'
152
+ : '_self',
153
+ } )
154
+ }
155
+ checked={ linkTarget === '_blank' }
156
+ />
157
+ <TextControl
158
+ __nextHasNoMarginBottom
159
+ label={ __( 'Link rel' ) }
160
+ value={ rel }
161
+ onChange={ ( newRel ) =>
162
+ setAttributes( { rel: newRel } )
163
+ }
164
+ />
165
+ </>
166
+ ) }
167
+ </PanelBody>
168
+ </InspectorControls>
169
+ </>
170
+ ) }
165
171
  { titleElement }
166
172
  </>
167
173
  );
@@ -12,6 +12,8 @@ $button-spacing-y: math.div($grid-unit-15, 2); // 6px
12
12
  svg {
13
13
  min-width: $grid-unit-30;
14
14
  min-height: $grid-unit-30;
15
+ width: 1.25em;
16
+ height: 1.25em;
15
17
  fill: currentColor;
16
18
  vertical-align: text-bottom;
17
19
  }
@@ -10,14 +10,21 @@ import { useState, useEffect, useCallback } from '@wordpress/element';
10
10
  import { usePrevious } from '@wordpress/compose';
11
11
  import { __ } from '@wordpress/i18n';
12
12
  import {
13
- RichText,
14
13
  BlockControls,
15
14
  __experimentalGetElementClassName,
15
+ privateApis as blockEditorPrivateApis,
16
16
  } from '@wordpress/block-editor';
17
17
  import { ToolbarButton } from '@wordpress/components';
18
18
  import { caption as captionIcon } from '@wordpress/icons';
19
19
  import { createBlock, getDefaultBlockName } from '@wordpress/blocks';
20
20
 
21
+ /**
22
+ * Internal dependencies
23
+ */
24
+ import { unlock } from '../lock-unlock';
25
+
26
+ const { PrivateRichText: RichText } = unlock( blockEditorPrivateApis );
27
+
21
28
  export function Caption( {
22
29
  key = 'caption',
23
30
  attributes,
@@ -28,6 +35,7 @@ export function Caption( {
28
35
  label = __( 'Caption text' ),
29
36
  showToolbarButton = true,
30
37
  className,
38
+ disableEditing,
31
39
  } ) {
32
40
  const caption = attributes[ key ];
33
41
  const prevCaption = usePrevious( caption );
@@ -101,6 +109,7 @@ export function Caption( {
101
109
  createBlock( getDefaultBlockName() )
102
110
  )
103
111
  }
112
+ disableEditing={ disableEditing }
104
113
  />
105
114
  ) }
106
115
  </>
@@ -0,0 +1,65 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import { getBlockType } from '@wordpress/blocks';
5
+
6
+ /**
7
+ * Transform the metadata attribute with only the values and bindings specified by each transform.
8
+ * Returns `undefined` if the input metadata is falsy.
9
+ *
10
+ * @param {Object} metadata Original metadata attribute from the block that is being transformed.
11
+ * @param {Object} newBlockName Name of the final block after the transformation.
12
+ * @param {Function} bindingsCallback Optional callback to transform the `bindings` property object.
13
+ * @return {Object|undefined} New metadata object only with the relevant properties.
14
+ */
15
+ export function getTransformedMetadata(
16
+ metadata,
17
+ newBlockName,
18
+ bindingsCallback
19
+ ) {
20
+ if ( ! metadata ) {
21
+ return;
22
+ }
23
+ const { supports } = getBlockType( newBlockName );
24
+ // Fixed until an opt-in mechanism is implemented.
25
+ const BLOCK_BINDINGS_SUPPORTED_BLOCKS = [
26
+ 'core/paragraph',
27
+ 'core/heading',
28
+ 'core/image',
29
+ 'core/button',
30
+ ];
31
+ // The metadata properties that should be preserved after the transform.
32
+ const transformSupportedProps = [];
33
+ // If it support bindings, and there is a transform bindings callback, add the `id` and `bindings` properties.
34
+ if (
35
+ BLOCK_BINDINGS_SUPPORTED_BLOCKS.includes( newBlockName ) &&
36
+ bindingsCallback
37
+ ) {
38
+ transformSupportedProps.push( 'id', 'bindings' );
39
+ }
40
+ // If it support block naming (true by default), add the `name` property.
41
+ if ( supports.renaming !== false ) {
42
+ transformSupportedProps.push( 'name' );
43
+ }
44
+
45
+ // Return early if no supported properties.
46
+ if ( ! transformSupportedProps.length ) {
47
+ return;
48
+ }
49
+
50
+ const newMetadata = Object.entries( metadata ).reduce(
51
+ ( obj, [ prop, value ] ) => {
52
+ // If prop is not supported, don't add it to the new metadata object.
53
+ if ( ! transformSupportedProps.includes( prop ) ) {
54
+ return obj;
55
+ }
56
+ obj[ prop ] =
57
+ prop === 'bindings' ? bindingsCallback( value ) : value;
58
+ return obj;
59
+ },
60
+ {}
61
+ );
62
+
63
+ // Return undefined if object is empty.
64
+ return Object.keys( newMetadata ).length ? newMetadata : undefined;
65
+ }