@wordpress/block-library 8.26.0 → 8.27.1
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.
- package/CHANGELOG.md +2 -0
- package/build/avatar/edit.js +2 -2
- package/build/avatar/edit.js.map +1 -1
- package/build/block/edit.js +76 -13
- package/build/block/edit.js.map +1 -1
- package/build/block/{v1/edit.native.js → edit.native.js} +4 -4
- package/build/block/edit.native.js.map +1 -0
- package/build/block/index.js +5 -3
- package/build/block/index.js.map +1 -1
- package/build/button/edit.js +24 -6
- package/build/button/edit.js.map +1 -1
- package/build/button/index.js +1 -0
- package/build/button/index.js.map +1 -1
- package/build/button/save.js +3 -1
- package/build/button/save.js.map +1 -1
- package/build/cover/edit/index.js +2 -1
- package/build/cover/edit/index.js.map +1 -1
- package/build/cover/edit/inspector-controls.js +13 -1
- package/build/cover/edit/inspector-controls.js.map +1 -1
- package/build/cover/edit.native.js +1 -0
- package/build/cover/edit.native.js.map +1 -1
- package/build/cover/index.js +3 -0
- package/build/cover/index.js.map +1 -1
- package/build/embed/edit.js +3 -2
- package/build/embed/edit.js.map +1 -1
- package/build/file/index.js +0 -1
- package/build/file/index.js.map +1 -1
- package/build/footnotes/edit.js +2 -1
- package/build/footnotes/edit.js.map +1 -1
- package/build/footnotes/format.js +17 -19
- package/build/footnotes/format.js.map +1 -1
- package/build/group/index.js +1 -0
- package/build/group/index.js.map +1 -1
- package/build/heading/edit.js +2 -1
- package/build/heading/edit.js.map +1 -1
- package/build/heading/edit.native.js +141 -0
- package/build/heading/edit.native.js.map +1 -0
- package/build/heading/index.js +1 -0
- package/build/heading/index.js.map +1 -1
- package/build/image/edit.js +8 -4
- package/build/image/edit.js.map +1 -1
- package/build/image/image.js +33 -7
- package/build/image/image.js.map +1 -1
- package/build/image/index.js +6 -3
- package/build/image/index.js.map +1 -1
- package/build/more/index.js +4 -0
- package/build/more/index.js.map +1 -1
- package/build/navigation/edit/index.js +2 -2
- package/build/navigation/edit/index.js.map +1 -1
- package/build/navigation/index.js +0 -1
- package/build/navigation/index.js.map +1 -1
- package/build/paragraph/edit.js +2 -1
- package/build/paragraph/edit.js.map +1 -1
- package/build/paragraph/index.js +1 -2
- package/build/paragraph/index.js.map +1 -1
- package/build/paragraph/transforms.js +1 -2
- package/build/paragraph/transforms.js.map +1 -1
- package/build/post-content/edit.js +2 -2
- package/build/post-content/edit.js.map +1 -1
- package/build/post-date/edit.js +1 -1
- package/build/post-date/edit.js.map +1 -1
- package/build/post-navigation-link/edit.js +43 -2
- package/build/post-navigation-link/edit.js.map +1 -1
- package/build/post-navigation-link/index.js +8 -0
- package/build/post-navigation-link/index.js.map +1 -1
- package/build/pullquote/index.js +4 -0
- package/build/pullquote/index.js.map +1 -1
- package/build/query/edit/inspector-controls/index.js +3 -3
- package/build/query/edit/inspector-controls/index.js.map +1 -1
- package/build/query/edit/query-content.js +2 -2
- package/build/query/edit/query-content.js.map +1 -1
- package/build/query/edit/query-placeholder.js +6 -7
- package/build/query/edit/query-placeholder.js.map +1 -1
- package/build/query/index.js +1 -2
- package/build/query/index.js.map +1 -1
- package/build/query/variations.js +8 -1
- package/build/query/variations.js.map +1 -1
- package/build/query/view.js +31 -12
- package/build/query/view.js.map +1 -1
- package/build/search/index.js +0 -1
- package/build/search/index.js.map +1 -1
- package/build/table-of-contents/hooks.js +2 -2
- package/build/table-of-contents/hooks.js.map +1 -1
- package/build/template-part/edit/advanced-controls.js +1 -4
- package/build/template-part/edit/advanced-controls.js.map +1 -1
- package/build/template-part/edit/index.js +39 -17
- package/build/template-part/edit/index.js.map +1 -1
- package/build/video/edit.native.js +7 -2
- package/build/video/edit.native.js.map +1 -1
- package/build/video/transforms.js +17 -0
- package/build/video/transforms.js.map +1 -1
- package/build-module/avatar/edit.js +2 -2
- package/build-module/avatar/edit.js.map +1 -1
- package/build-module/block/edit.js +76 -13
- package/build-module/block/edit.js.map +1 -1
- package/build-module/block/{v1/edit.native.js → edit.native.js} +3 -3
- package/build-module/block/edit.native.js.map +1 -0
- package/build-module/block/index.js +5 -3
- package/build-module/block/index.js.map +1 -1
- package/build-module/button/edit.js +25 -7
- package/build-module/button/edit.js.map +1 -1
- package/build-module/button/index.js +1 -0
- package/build-module/button/index.js.map +1 -1
- package/build-module/button/save.js +4 -2
- package/build-module/button/save.js.map +1 -1
- package/build-module/cover/edit/index.js +2 -1
- package/build-module/cover/edit/index.js.map +1 -1
- package/build-module/cover/edit/inspector-controls.js +14 -2
- package/build-module/cover/edit/inspector-controls.js.map +1 -1
- package/build-module/cover/edit.native.js +1 -0
- package/build-module/cover/edit.native.js.map +1 -1
- package/build-module/cover/index.js +3 -0
- package/build-module/cover/index.js.map +1 -1
- package/build-module/embed/edit.js +3 -2
- package/build-module/embed/edit.js.map +1 -1
- package/build-module/file/index.js +0 -1
- package/build-module/file/index.js.map +1 -1
- package/build-module/footnotes/edit.js +2 -1
- package/build-module/footnotes/edit.js.map +1 -1
- package/build-module/footnotes/format.js +17 -19
- package/build-module/footnotes/format.js.map +1 -1
- package/build-module/group/index.js +1 -0
- package/build-module/group/index.js.map +1 -1
- package/build-module/heading/edit.js +3 -2
- package/build-module/heading/edit.js.map +1 -1
- package/build-module/heading/edit.native.js +132 -0
- package/build-module/heading/edit.native.js.map +1 -0
- package/build-module/heading/index.js +1 -0
- package/build-module/heading/index.js.map +1 -1
- package/build-module/image/edit.js +9 -5
- package/build-module/image/edit.js.map +1 -1
- package/build-module/image/image.js +33 -7
- package/build-module/image/image.js.map +1 -1
- package/build-module/image/index.js +6 -3
- package/build-module/image/index.js.map +1 -1
- package/build-module/more/index.js +4 -0
- package/build-module/more/index.js.map +1 -1
- package/build-module/navigation/edit/index.js +1 -1
- package/build-module/navigation/edit/index.js.map +1 -1
- package/build-module/navigation/index.js +0 -1
- package/build-module/navigation/index.js.map +1 -1
- package/build-module/paragraph/edit.js +3 -2
- package/build-module/paragraph/edit.js.map +1 -1
- package/build-module/paragraph/index.js +1 -2
- package/build-module/paragraph/index.js.map +1 -1
- package/build-module/paragraph/transforms.js +1 -2
- package/build-module/paragraph/transforms.js.map +1 -1
- package/build-module/post-content/edit.js +1 -1
- package/build-module/post-content/edit.js.map +1 -1
- package/build-module/post-date/edit.js +1 -1
- package/build-module/post-date/edit.js.map +1 -1
- package/build-module/post-navigation-link/edit.js +44 -3
- package/build-module/post-navigation-link/edit.js.map +1 -1
- package/build-module/post-navigation-link/index.js +8 -0
- package/build-module/post-navigation-link/index.js.map +1 -1
- package/build-module/pullquote/index.js +4 -0
- package/build-module/pullquote/index.js.map +1 -1
- package/build-module/query/edit/inspector-controls/index.js +4 -4
- package/build-module/query/edit/inspector-controls/index.js.map +1 -1
- package/build-module/query/edit/query-content.js +2 -2
- package/build-module/query/edit/query-content.js.map +1 -1
- package/build-module/query/edit/query-placeholder.js +7 -8
- package/build-module/query/edit/query-placeholder.js.map +1 -1
- package/build-module/query/index.js +1 -2
- package/build-module/query/index.js.map +1 -1
- package/build-module/query/variations.js +8 -1
- package/build-module/query/variations.js.map +1 -1
- package/build-module/query/view.js +30 -9
- package/build-module/query/view.js.map +1 -1
- package/build-module/search/index.js +0 -1
- package/build-module/search/index.js.map +1 -1
- package/build-module/table-of-contents/hooks.js +2 -2
- package/build-module/table-of-contents/hooks.js.map +1 -1
- package/build-module/template-part/edit/advanced-controls.js +1 -4
- package/build-module/template-part/edit/advanced-controls.js.map +1 -1
- package/build-module/template-part/edit/index.js +38 -16
- package/build-module/template-part/edit/index.js.map +1 -1
- package/build-module/video/edit.native.js +7 -2
- package/build-module/video/edit.native.js.map +1 -1
- package/build-module/video/transforms.js +17 -0
- package/build-module/video/transforms.js.map +1 -1
- package/build-style/common-rtl.css +4 -2
- package/build-style/common.css +4 -2
- package/build-style/cover/style-rtl.css +2 -4
- package/build-style/cover/style.css +2 -4
- package/build-style/editor-rtl.css +6 -4
- package/build-style/editor.css +6 -4
- package/build-style/gallery/style-rtl.css +2 -4
- package/build-style/gallery/style.css +2 -4
- package/build-style/image/editor-rtl.css +6 -0
- package/build-style/image/editor.css +6 -0
- package/build-style/page-list/editor-rtl.css +0 -4
- package/build-style/page-list/editor.css +0 -4
- package/build-style/pullquote/style-rtl.css +10 -1
- package/build-style/pullquote/style.css +10 -1
- package/build-style/search/style-rtl.css +2 -1
- package/build-style/search/style.css +2 -1
- package/build-style/style-rtl.css +20 -13
- package/build-style/style.css +20 -13
- package/build-style/video/style-rtl.css +1 -2
- package/build-style/video/style.css +1 -2
- package/package.json +34 -32
- package/src/avatar/edit.js +16 -18
- package/src/block/block.json +3 -0
- package/src/block/edit.js +102 -20
- package/src/block/{v1/edit.native.js → edit.native.js} +4 -4
- package/src/block/index.js +2 -3
- package/src/block/index.php +3 -31
- package/src/button/block.json +1 -0
- package/src/button/edit.js +76 -43
- package/src/button/save.js +3 -0
- package/src/buttons/test/__snapshots__/edit.native.js.snap +6 -0
- package/src/buttons/test/edit.native.js +49 -0
- package/src/cover/block.json +3 -0
- package/src/cover/edit/index.js +2 -1
- package/src/cover/edit/inspector-controls.js +14 -1
- package/src/cover/edit.native.js +1 -0
- package/src/cover/style.scss +2 -3
- package/src/embed/edit.js +3 -2
- package/src/file/block.json +0 -1
- package/src/file/index.php +11 -57
- package/src/footnotes/edit.js +2 -1
- package/src/footnotes/format.js +34 -31
- package/src/footnotes/index.php +20 -11
- package/src/gallery/index.php +0 -3
- package/src/group/block.json +1 -0
- package/src/heading/block.json +1 -0
- package/src/heading/edit.js +18 -14
- package/src/heading/edit.native.js +144 -0
- package/src/image/block.json +7 -3
- package/src/image/edit.js +19 -6
- package/src/image/editor.scss +6 -1
- package/src/image/image.js +101 -42
- package/src/image/index.js +6 -0
- package/src/image/index.php +14 -51
- package/src/more/index.js +6 -0
- package/src/navigation/block.json +0 -1
- package/src/navigation/edit/index.js +2 -2
- package/src/navigation/index.php +777 -28
- package/src/navigation-link/index.php +78 -16
- package/src/page-list/editor.scss +0 -4
- package/src/paragraph/block.json +1 -2
- package/src/paragraph/edit.js +23 -19
- package/src/post-content/edit.js +2 -2
- package/src/post-date/edit.js +38 -33
- package/src/post-navigation-link/block.json +8 -0
- package/src/post-navigation-link/edit.js +63 -1
- package/src/post-navigation-link/index.php +17 -3
- package/src/post-terms/index.php +13 -4
- package/src/pullquote/block.json +4 -0
- package/src/pullquote/style.scss +13 -1
- package/src/query/block.json +1 -2
- package/src/query/edit/inspector-controls/index.js +137 -146
- package/src/query/edit/query-content.js +9 -7
- package/src/query/edit/query-placeholder.js +11 -11
- package/src/query/index.php +33 -71
- package/src/query/variations.js +4 -0
- package/src/query/view.js +24 -19
- package/src/search/block.json +0 -1
- package/src/search/index.php +18 -36
- package/src/table-of-contents/hooks.js +2 -2
- package/src/template-part/edit/advanced-controls.js +2 -3
- package/src/template-part/edit/index.js +77 -50
- package/src/template-part/index.php +2 -2
- package/src/video/edit.native.js +5 -2
- package/src/video/test/edit.native.js +38 -0
- package/src/video/transforms.js +32 -0
- package/tsconfig.json +1 -0
- package/build/block/v1/edit.js +0 -116
- package/build/block/v1/edit.js.map +0 -1
- package/build/block/v1/edit.native.js.map +0 -1
- package/build-module/block/v1/edit.js +0 -108
- package/build-module/block/v1/edit.js.map +0 -1
- package/build-module/block/v1/edit.native.js.map +0 -1
- package/src/block/v1/edit.js +0 -163
package/src/heading/edit.js
CHANGED
|
@@ -17,6 +17,7 @@ import {
|
|
|
17
17
|
useBlockProps,
|
|
18
18
|
store as blockEditorStore,
|
|
19
19
|
HeadingLevelDropdown,
|
|
20
|
+
useBlockEditingMode,
|
|
20
21
|
} from '@wordpress/block-editor';
|
|
21
22
|
|
|
22
23
|
/**
|
|
@@ -40,6 +41,7 @@ function HeadingEdit( {
|
|
|
40
41
|
} ),
|
|
41
42
|
style,
|
|
42
43
|
} );
|
|
44
|
+
const blockEditingMode = useBlockEditingMode();
|
|
43
45
|
|
|
44
46
|
const { canGenerateAnchors } = useSelect( ( select ) => {
|
|
45
47
|
const { getGlobalBlockCount, getSettings } = select( blockEditorStore );
|
|
@@ -90,20 +92,22 @@ function HeadingEdit( {
|
|
|
90
92
|
|
|
91
93
|
return (
|
|
92
94
|
<>
|
|
93
|
-
|
|
94
|
-
<
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
95
|
+
{ blockEditingMode === 'default' && (
|
|
96
|
+
<BlockControls group="block">
|
|
97
|
+
<HeadingLevelDropdown
|
|
98
|
+
value={ level }
|
|
99
|
+
onChange={ ( newLevel ) =>
|
|
100
|
+
setAttributes( { level: newLevel } )
|
|
101
|
+
}
|
|
102
|
+
/>
|
|
103
|
+
<AlignmentControl
|
|
104
|
+
value={ textAlign }
|
|
105
|
+
onChange={ ( nextAlign ) => {
|
|
106
|
+
setAttributes( { textAlign: nextAlign } );
|
|
107
|
+
} }
|
|
108
|
+
/>
|
|
109
|
+
</BlockControls>
|
|
110
|
+
) }
|
|
107
111
|
<RichText
|
|
108
112
|
identifier="content"
|
|
109
113
|
tagName={ tagName }
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External dependencies
|
|
3
|
+
*/
|
|
4
|
+
import classnames from 'classnames';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* WordPress dependencies
|
|
8
|
+
*/
|
|
9
|
+
import { __ } from '@wordpress/i18n';
|
|
10
|
+
import { useEffect, Platform } from '@wordpress/element';
|
|
11
|
+
import { useDispatch, useSelect } from '@wordpress/data';
|
|
12
|
+
import { createBlock, getDefaultBlockName } from '@wordpress/blocks';
|
|
13
|
+
import {
|
|
14
|
+
AlignmentControl,
|
|
15
|
+
BlockControls,
|
|
16
|
+
RichText,
|
|
17
|
+
useBlockProps,
|
|
18
|
+
store as blockEditorStore,
|
|
19
|
+
HeadingLevelDropdown,
|
|
20
|
+
} from '@wordpress/block-editor';
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Internal dependencies
|
|
24
|
+
*/
|
|
25
|
+
import { generateAnchor, setAnchor } from './autogenerate-anchors';
|
|
26
|
+
|
|
27
|
+
function HeadingEdit( {
|
|
28
|
+
attributes,
|
|
29
|
+
setAttributes,
|
|
30
|
+
mergeBlocks,
|
|
31
|
+
onReplace,
|
|
32
|
+
style,
|
|
33
|
+
clientId,
|
|
34
|
+
} ) {
|
|
35
|
+
const { textAlign, content, level, placeholder, anchor } = attributes;
|
|
36
|
+
const tagName = 'h' + level;
|
|
37
|
+
const blockProps = useBlockProps( {
|
|
38
|
+
className: classnames( {
|
|
39
|
+
[ `has-text-align-${ textAlign }` ]: textAlign,
|
|
40
|
+
} ),
|
|
41
|
+
style,
|
|
42
|
+
} );
|
|
43
|
+
|
|
44
|
+
const { canGenerateAnchors } = useSelect( ( select ) => {
|
|
45
|
+
const { getGlobalBlockCount, getSettings } = select( blockEditorStore );
|
|
46
|
+
const settings = getSettings();
|
|
47
|
+
|
|
48
|
+
return {
|
|
49
|
+
canGenerateAnchors:
|
|
50
|
+
!! settings.generateAnchors ||
|
|
51
|
+
getGlobalBlockCount( 'core/table-of-contents' ) > 0,
|
|
52
|
+
};
|
|
53
|
+
}, [] );
|
|
54
|
+
|
|
55
|
+
const { __unstableMarkNextChangeAsNotPersistent } =
|
|
56
|
+
useDispatch( blockEditorStore );
|
|
57
|
+
|
|
58
|
+
// Initially set anchor for headings that have content but no anchor set.
|
|
59
|
+
// This is used when transforming a block to heading, or for legacy anchors.
|
|
60
|
+
useEffect( () => {
|
|
61
|
+
if ( ! canGenerateAnchors ) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if ( ! anchor && content ) {
|
|
66
|
+
// This side-effect should not create an undo level.
|
|
67
|
+
__unstableMarkNextChangeAsNotPersistent();
|
|
68
|
+
setAttributes( {
|
|
69
|
+
anchor: generateAnchor( clientId, content ),
|
|
70
|
+
} );
|
|
71
|
+
}
|
|
72
|
+
setAnchor( clientId, anchor );
|
|
73
|
+
|
|
74
|
+
// Remove anchor map when block unmounts.
|
|
75
|
+
return () => setAnchor( clientId, null );
|
|
76
|
+
}, [ anchor, content, clientId, canGenerateAnchors ] );
|
|
77
|
+
|
|
78
|
+
const onContentChange = ( value ) => {
|
|
79
|
+
const newAttrs = { content: value };
|
|
80
|
+
if (
|
|
81
|
+
canGenerateAnchors &&
|
|
82
|
+
( ! anchor ||
|
|
83
|
+
! value ||
|
|
84
|
+
generateAnchor( clientId, content ) === anchor )
|
|
85
|
+
) {
|
|
86
|
+
newAttrs.anchor = generateAnchor( clientId, value );
|
|
87
|
+
}
|
|
88
|
+
setAttributes( newAttrs );
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
return (
|
|
92
|
+
<>
|
|
93
|
+
<BlockControls group="block">
|
|
94
|
+
<HeadingLevelDropdown
|
|
95
|
+
value={ level }
|
|
96
|
+
onChange={ ( newLevel ) =>
|
|
97
|
+
setAttributes( { level: newLevel } )
|
|
98
|
+
}
|
|
99
|
+
/>
|
|
100
|
+
<AlignmentControl
|
|
101
|
+
value={ textAlign }
|
|
102
|
+
onChange={ ( nextAlign ) => {
|
|
103
|
+
setAttributes( { textAlign: nextAlign } );
|
|
104
|
+
} }
|
|
105
|
+
/>
|
|
106
|
+
</BlockControls>
|
|
107
|
+
<RichText
|
|
108
|
+
identifier="content"
|
|
109
|
+
tagName={ tagName }
|
|
110
|
+
value={ content }
|
|
111
|
+
onChange={ onContentChange }
|
|
112
|
+
onMerge={ mergeBlocks }
|
|
113
|
+
onSplit={ ( value, isOriginal ) => {
|
|
114
|
+
let block;
|
|
115
|
+
|
|
116
|
+
if ( isOriginal || value ) {
|
|
117
|
+
block = createBlock( 'core/heading', {
|
|
118
|
+
...attributes,
|
|
119
|
+
content: value,
|
|
120
|
+
} );
|
|
121
|
+
} else {
|
|
122
|
+
block = createBlock(
|
|
123
|
+
getDefaultBlockName() ?? 'core/heading'
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
if ( isOriginal ) {
|
|
128
|
+
block.clientId = clientId;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
return block;
|
|
132
|
+
} }
|
|
133
|
+
onReplace={ onReplace }
|
|
134
|
+
onRemove={ () => onReplace( [] ) }
|
|
135
|
+
placeholder={ placeholder || __( 'Heading' ) }
|
|
136
|
+
textAlign={ textAlign }
|
|
137
|
+
{ ...( Platform.isNative && { deleteEnter: true } ) } // setup RichText on native mobile to delete the "Enter" key as it's handled by the JS/RN side
|
|
138
|
+
{ ...blockProps }
|
|
139
|
+
/>
|
|
140
|
+
</>
|
|
141
|
+
);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
export default HeadingEdit;
|
package/src/image/block.json
CHANGED
|
@@ -4,7 +4,12 @@
|
|
|
4
4
|
"name": "core/image",
|
|
5
5
|
"title": "Image",
|
|
6
6
|
"category": "media",
|
|
7
|
-
"usesContext": [
|
|
7
|
+
"usesContext": [
|
|
8
|
+
"allowResize",
|
|
9
|
+
"imageCrop",
|
|
10
|
+
"fixedHeight",
|
|
11
|
+
"pattern/overrides"
|
|
12
|
+
],
|
|
8
13
|
"description": "Insert an image to make a visual statement.",
|
|
9
14
|
"keywords": [ "img", "photo", "picture" ],
|
|
10
15
|
"textdomain": "default",
|
|
@@ -129,6 +134,5 @@
|
|
|
129
134
|
{ "name": "rounded", "label": "Rounded" }
|
|
130
135
|
],
|
|
131
136
|
"editorStyle": "wp-block-image-editor",
|
|
132
|
-
"style": "wp-block-image"
|
|
133
|
-
"viewScript": "file:./view.min.js"
|
|
137
|
+
"style": "wp-block-image"
|
|
134
138
|
}
|
package/src/image/edit.js
CHANGED
|
@@ -19,7 +19,7 @@ import {
|
|
|
19
19
|
} from '@wordpress/block-editor';
|
|
20
20
|
import { useEffect, useRef, useState } from '@wordpress/element';
|
|
21
21
|
import { __ } from '@wordpress/i18n';
|
|
22
|
-
import { image as icon } from '@wordpress/icons';
|
|
22
|
+
import { image as icon, plugins as pluginsIcon } from '@wordpress/icons';
|
|
23
23
|
import { store as noticesStore } from '@wordpress/notices';
|
|
24
24
|
|
|
25
25
|
/**
|
|
@@ -111,6 +111,7 @@ export function ImageEdit( {
|
|
|
111
111
|
aspectRatio,
|
|
112
112
|
scale,
|
|
113
113
|
align,
|
|
114
|
+
metadata,
|
|
114
115
|
} = attributes;
|
|
115
116
|
const [ temporaryURL, setTemporaryURL ] = useState();
|
|
116
117
|
|
|
@@ -332,6 +333,7 @@ export function ImageEdit( {
|
|
|
332
333
|
} );
|
|
333
334
|
|
|
334
335
|
// Much of this description is duplicated from MediaPlaceholder.
|
|
336
|
+
const isUrlAttributeConnected = !! metadata?.bindings?.url;
|
|
335
337
|
const placeholder = ( content ) => {
|
|
336
338
|
return (
|
|
337
339
|
<Placeholder
|
|
@@ -340,11 +342,14 @@ export function ImageEdit( {
|
|
|
340
342
|
!! borderProps.className && ! isSelected,
|
|
341
343
|
} ) }
|
|
342
344
|
withIllustration={ true }
|
|
343
|
-
icon={ icon }
|
|
345
|
+
icon={ isUrlAttributeConnected ? pluginsIcon : icon }
|
|
344
346
|
label={ __( 'Image' ) }
|
|
345
|
-
instructions={
|
|
346
|
-
|
|
347
|
-
|
|
347
|
+
instructions={
|
|
348
|
+
! isUrlAttributeConnected &&
|
|
349
|
+
__(
|
|
350
|
+
'Upload an image file, pick one from your media library, or add one with a URL.'
|
|
351
|
+
)
|
|
352
|
+
}
|
|
348
353
|
style={ {
|
|
349
354
|
aspectRatio:
|
|
350
355
|
! ( width && height ) && aspectRatio
|
|
@@ -356,7 +361,15 @@ export function ImageEdit( {
|
|
|
356
361
|
...borderProps.style,
|
|
357
362
|
} }
|
|
358
363
|
>
|
|
359
|
-
{
|
|
364
|
+
{ isUrlAttributeConnected ? (
|
|
365
|
+
<span
|
|
366
|
+
className={ 'block-bindings-media-placeholder-message' }
|
|
367
|
+
>
|
|
368
|
+
{ __( 'Connected to a custom field' ) }
|
|
369
|
+
</span>
|
|
370
|
+
) : (
|
|
371
|
+
content
|
|
372
|
+
) }
|
|
360
373
|
</Placeholder>
|
|
361
374
|
);
|
|
362
375
|
};
|
package/src/image/editor.scss
CHANGED
|
@@ -27,6 +27,12 @@
|
|
|
27
27
|
opacity: 0;
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
|
+
.block-bindings-media-placeholder-message {
|
|
31
|
+
opacity: 0;
|
|
32
|
+
}
|
|
33
|
+
&.is-selected .block-bindings-media-placeholder-message {
|
|
34
|
+
opacity: 1;
|
|
35
|
+
}
|
|
30
36
|
|
|
31
37
|
// Remove the transition while we still have a legacy placeholder style.
|
|
32
38
|
// Otherwise the content jumps between the 1px placeholder border, and any inherited custom
|
|
@@ -38,7 +44,6 @@
|
|
|
38
44
|
}
|
|
39
45
|
}
|
|
40
46
|
|
|
41
|
-
|
|
42
47
|
figure.wp-block-image:not(.wp-block) {
|
|
43
48
|
margin: 0;
|
|
44
49
|
}
|
package/src/image/image.js
CHANGED
|
@@ -124,6 +124,7 @@ export default function Image( {
|
|
|
124
124
|
linkTarget,
|
|
125
125
|
sizeSlug,
|
|
126
126
|
lightbox,
|
|
127
|
+
metadata,
|
|
127
128
|
} = attributes;
|
|
128
129
|
|
|
129
130
|
// The only supported unit is px, so we can parseInt to strip the px here.
|
|
@@ -355,7 +356,8 @@ export default function Image( {
|
|
|
355
356
|
const lightboxChecked =
|
|
356
357
|
!! lightbox?.enabled || ( ! lightbox && !! lightboxSetting?.enabled );
|
|
357
358
|
|
|
358
|
-
const lightboxToggleDisabled =
|
|
359
|
+
const lightboxToggleDisabled =
|
|
360
|
+
linkDestination && linkDestination !== 'none';
|
|
359
361
|
|
|
360
362
|
const dimensionsControl = (
|
|
361
363
|
<DimensionsTool
|
|
@@ -410,21 +412,59 @@ export default function Image( {
|
|
|
410
412
|
</InspectorControls>
|
|
411
413
|
);
|
|
412
414
|
|
|
415
|
+
const {
|
|
416
|
+
lockUrlControls = false,
|
|
417
|
+
lockAltControls = false,
|
|
418
|
+
lockTitleControls = false,
|
|
419
|
+
} = useSelect(
|
|
420
|
+
( select ) => {
|
|
421
|
+
if ( ! isSelected ) {
|
|
422
|
+
return {};
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
const { getBlockBindingsSource } = unlock(
|
|
426
|
+
select( blockEditorStore )
|
|
427
|
+
);
|
|
428
|
+
const {
|
|
429
|
+
url: urlBinding,
|
|
430
|
+
alt: altBinding,
|
|
431
|
+
title: titleBinding,
|
|
432
|
+
} = metadata?.bindings || {};
|
|
433
|
+
return {
|
|
434
|
+
lockUrlControls:
|
|
435
|
+
!! urlBinding &&
|
|
436
|
+
getBlockBindingsSource( urlBinding?.source?.name )
|
|
437
|
+
?.lockAttributesEditing === true,
|
|
438
|
+
lockAltControls:
|
|
439
|
+
!! altBinding &&
|
|
440
|
+
getBlockBindingsSource( altBinding?.source?.name )
|
|
441
|
+
?.lockAttributesEditing === true,
|
|
442
|
+
lockTitleControls:
|
|
443
|
+
!! titleBinding &&
|
|
444
|
+
getBlockBindingsSource( titleBinding?.source?.name )
|
|
445
|
+
?.lockAttributesEditing === true,
|
|
446
|
+
};
|
|
447
|
+
},
|
|
448
|
+
[ isSelected ]
|
|
449
|
+
);
|
|
450
|
+
|
|
413
451
|
const controls = (
|
|
414
452
|
<>
|
|
415
453
|
<BlockControls group="block">
|
|
416
|
-
{ ! multiImageSelection &&
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
454
|
+
{ ! multiImageSelection &&
|
|
455
|
+
! isEditingImage &&
|
|
456
|
+
! lockUrlControls && (
|
|
457
|
+
<ImageURLInputUI
|
|
458
|
+
url={ href || '' }
|
|
459
|
+
onChangeUrl={ onSetHref }
|
|
460
|
+
linkDestination={ linkDestination }
|
|
461
|
+
mediaUrl={ ( image && image.source_url ) || url }
|
|
462
|
+
mediaLink={ image && image.link }
|
|
463
|
+
linkTarget={ linkTarget }
|
|
464
|
+
linkClass={ linkClass }
|
|
465
|
+
rel={ rel }
|
|
466
|
+
/>
|
|
467
|
+
) }
|
|
428
468
|
{ allowCrop && (
|
|
429
469
|
<ToolbarButton
|
|
430
470
|
onClick={ () => setIsEditingImage( true ) }
|
|
@@ -440,19 +480,21 @@ export default function Image( {
|
|
|
440
480
|
/>
|
|
441
481
|
) }
|
|
442
482
|
</BlockControls>
|
|
443
|
-
{ ! multiImageSelection &&
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
483
|
+
{ ! multiImageSelection &&
|
|
484
|
+
! isEditingImage &&
|
|
485
|
+
! lockUrlControls && (
|
|
486
|
+
<BlockControls group="other">
|
|
487
|
+
<MediaReplaceFlow
|
|
488
|
+
mediaId={ id }
|
|
489
|
+
mediaURL={ url }
|
|
490
|
+
allowedTypes={ ALLOWED_MEDIA_TYPES }
|
|
491
|
+
accept="image/*"
|
|
492
|
+
onSelect={ onSelectImage }
|
|
493
|
+
onSelectURL={ onSelectURL }
|
|
494
|
+
onError={ onUploadError }
|
|
495
|
+
/>
|
|
496
|
+
</BlockControls>
|
|
497
|
+
) }
|
|
456
498
|
{ ! multiImageSelection && externalBlob && (
|
|
457
499
|
<BlockControls>
|
|
458
500
|
<ToolbarGroup>
|
|
@@ -483,16 +525,27 @@ export default function Image( {
|
|
|
483
525
|
label={ __( 'Alternative text' ) }
|
|
484
526
|
value={ alt || '' }
|
|
485
527
|
onChange={ updateAlt }
|
|
528
|
+
disabled={ lockAltControls }
|
|
486
529
|
help={
|
|
487
|
-
|
|
488
|
-
|
|
530
|
+
lockAltControls ? (
|
|
531
|
+
<>
|
|
532
|
+
{ __(
|
|
533
|
+
'Connected to a custom field'
|
|
534
|
+
) }
|
|
535
|
+
</>
|
|
536
|
+
) : (
|
|
537
|
+
<>
|
|
538
|
+
<ExternalLink href="https://www.w3.org/WAI/tutorials/images/decision-tree">
|
|
539
|
+
{ __(
|
|
540
|
+
'Describe the purpose of the image.'
|
|
541
|
+
) }
|
|
542
|
+
</ExternalLink>
|
|
543
|
+
<br />
|
|
489
544
|
{ __(
|
|
490
|
-
'
|
|
545
|
+
'Leave empty if decorative.'
|
|
491
546
|
) }
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
{ __( 'Leave empty if decorative.' ) }
|
|
495
|
-
</>
|
|
547
|
+
</>
|
|
548
|
+
)
|
|
496
549
|
}
|
|
497
550
|
__nextHasNoMarginBottom
|
|
498
551
|
/>
|
|
@@ -542,17 +595,22 @@ export default function Image( {
|
|
|
542
595
|
label={ __( 'Title attribute' ) }
|
|
543
596
|
value={ title || '' }
|
|
544
597
|
onChange={ onSetTitle }
|
|
598
|
+
disabled={ lockTitleControls }
|
|
545
599
|
help={
|
|
546
|
-
|
|
547
|
-
{ __(
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
<ExternalLink href="https://www.w3.org/TR/html52/dom.html#the-title-attribute">
|
|
600
|
+
lockTitleControls ? (
|
|
601
|
+
<>{ __( 'Connected to a custom field' ) }</>
|
|
602
|
+
) : (
|
|
603
|
+
<>
|
|
551
604
|
{ __(
|
|
552
|
-
'
|
|
605
|
+
'Describe the role of this image on the page.'
|
|
553
606
|
) }
|
|
554
|
-
|
|
555
|
-
|
|
607
|
+
<ExternalLink href="https://www.w3.org/TR/html52/dom.html#the-title-attribute">
|
|
608
|
+
{ __(
|
|
609
|
+
'(Note: many devices and browsers do not display this text.)'
|
|
610
|
+
) }
|
|
611
|
+
</ExternalLink>
|
|
612
|
+
</>
|
|
613
|
+
)
|
|
556
614
|
}
|
|
557
615
|
/>
|
|
558
616
|
</InspectorControls>
|
|
@@ -747,7 +805,8 @@ export default function Image( {
|
|
|
747
805
|
}
|
|
748
806
|
|
|
749
807
|
if ( ! url && ! temporaryURL ) {
|
|
750
|
-
|
|
808
|
+
// Add all controls if the image attributes are connected.
|
|
809
|
+
return metadata?.bindings ? controls : sizeControls;
|
|
751
810
|
}
|
|
752
811
|
|
|
753
812
|
return (
|
package/src/image/index.js
CHANGED
|
@@ -29,6 +29,12 @@ export const settings = {
|
|
|
29
29
|
},
|
|
30
30
|
},
|
|
31
31
|
__experimentalLabel( attributes, { context } ) {
|
|
32
|
+
const customName = attributes?.metadata?.name;
|
|
33
|
+
|
|
34
|
+
if ( context === 'list-view' && customName ) {
|
|
35
|
+
return customName;
|
|
36
|
+
}
|
|
37
|
+
|
|
32
38
|
if ( context === 'accessibility' ) {
|
|
33
39
|
const { caption, alt, url } = attributes;
|
|
34
40
|
|
package/src/image/index.php
CHANGED
|
@@ -37,10 +37,6 @@ function render_block_core_image( $attributes, $content, $block ) {
|
|
|
37
37
|
$link_destination = isset( $attributes['linkDestination'] ) ? $attributes['linkDestination'] : 'none';
|
|
38
38
|
$lightbox_settings = block_core_image_get_lightbox_settings( $block->parsed_block );
|
|
39
39
|
|
|
40
|
-
$is_gutenberg_plugin = defined( 'IS_GUTENBERG_PLUGIN' ) && IS_GUTENBERG_PLUGIN;
|
|
41
|
-
$view_js_file_handle = 'wp-block-image-view';
|
|
42
|
-
$script_handles = $block->block_type->view_script_handles;
|
|
43
|
-
|
|
44
40
|
/*
|
|
45
41
|
* If the lightbox is enabled and the image is not linked, add the filter
|
|
46
42
|
* and the JavaScript view file.
|
|
@@ -51,34 +47,22 @@ function render_block_core_image( $attributes, $content, $block ) {
|
|
|
51
47
|
isset( $lightbox_settings['enabled'] ) &&
|
|
52
48
|
true === $lightbox_settings['enabled']
|
|
53
49
|
) {
|
|
54
|
-
|
|
55
|
-
gutenberg_enqueue_module( '@wordpress/block-library/image' );
|
|
56
|
-
// Remove the view script because we are using the module.
|
|
57
|
-
$block->block_type->view_script_handles = array_diff( $script_handles, array( $view_js_file_handle ) );
|
|
58
|
-
} elseif ( ! in_array( $view_js_file_handle, $script_handles, true ) ) {
|
|
59
|
-
$block->block_type->view_script_handles = array_merge( $script_handles, array( $view_js_file_handle ) );
|
|
60
|
-
}
|
|
50
|
+
wp_enqueue_script_module( '@wordpress/block-library/image' );
|
|
61
51
|
|
|
62
52
|
/*
|
|
63
|
-
* This render needs to happen in a filter with priority 15 to ensure
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
*
|
|
53
|
+
* This render needs to happen in a filter with priority 15 to ensure that
|
|
54
|
+
* it runs after the duotone filter and that duotone styles are applied to
|
|
55
|
+
* the image in the lightbox. Lightbox has to work with any plugins that
|
|
56
|
+
* might use filters as well. Removing this can be considered in the
|
|
57
|
+
* future if the way the blocks are rendered changes, or if a
|
|
58
|
+
* new kind of filter is introduced.
|
|
69
59
|
*/
|
|
70
60
|
add_filter( 'render_block_core/image', 'block_core_image_render_lightbox', 15, 2 );
|
|
71
61
|
} else {
|
|
72
62
|
/*
|
|
73
|
-
* Remove the filter
|
|
74
|
-
* other Image blocks.
|
|
63
|
+
* Remove the filter if previously added by other Image blocks.
|
|
75
64
|
*/
|
|
76
65
|
remove_filter( 'render_block_core/image', 'block_core_image_render_lightbox', 15 );
|
|
77
|
-
|
|
78
|
-
// If the script is not needed, and it is still in the `view_script_handles`, remove it.
|
|
79
|
-
if ( in_array( $view_js_file_handle, $script_handles, true ) ) {
|
|
80
|
-
$block->block_type->view_script_handles = array_diff( $script_handles, array( $view_js_file_handle ) );
|
|
81
|
-
}
|
|
82
66
|
}
|
|
83
67
|
|
|
84
68
|
return $processor->get_updated_html();
|
|
@@ -328,25 +312,6 @@ HTML;
|
|
|
328
312
|
return str_replace( '</figure>', $lightbox_html . '</figure>', $body_content );
|
|
329
313
|
}
|
|
330
314
|
|
|
331
|
-
/**
|
|
332
|
-
* Ensures that the view script has the `wp-interactivity` dependency.
|
|
333
|
-
*
|
|
334
|
-
* @since 6.4.0
|
|
335
|
-
*
|
|
336
|
-
* @global WP_Scripts $wp_scripts
|
|
337
|
-
*/
|
|
338
|
-
function block_core_image_ensure_interactivity_dependency() {
|
|
339
|
-
global $wp_scripts;
|
|
340
|
-
if (
|
|
341
|
-
isset( $wp_scripts->registered['wp-block-image-view'] ) &&
|
|
342
|
-
! in_array( 'wp-interactivity', $wp_scripts->registered['wp-block-image-view']->deps, true )
|
|
343
|
-
) {
|
|
344
|
-
$wp_scripts->registered['wp-block-image-view']->deps[] = 'wp-interactivity';
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
add_action( 'wp_print_scripts', 'block_core_image_ensure_interactivity_dependency' );
|
|
349
|
-
|
|
350
315
|
/**
|
|
351
316
|
* Registers the `core/image` block on server.
|
|
352
317
|
*/
|
|
@@ -358,13 +323,11 @@ function register_block_core_image() {
|
|
|
358
323
|
)
|
|
359
324
|
);
|
|
360
325
|
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
);
|
|
368
|
-
}
|
|
326
|
+
wp_register_script_module(
|
|
327
|
+
'@wordpress/block-library/image',
|
|
328
|
+
defined( 'IS_GUTENBERG_PLUGIN' ) && IS_GUTENBERG_PLUGIN ? gutenberg_url( '/build/interactivity/image.min.js' ) : includes_url( 'blocks/image/view.min.js' ),
|
|
329
|
+
array( '@wordpress/interactivity' ),
|
|
330
|
+
defined( 'GUTENBERG_VERSION' ) ? GUTENBERG_VERSION : get_bloginfo( 'version' )
|
|
331
|
+
);
|
|
369
332
|
}
|
|
370
333
|
add_action( 'init', 'register_block_core_image' );
|
package/src/more/index.js
CHANGED
|
@@ -20,6 +20,12 @@ export const settings = {
|
|
|
20
20
|
icon,
|
|
21
21
|
example: {},
|
|
22
22
|
__experimentalLabel( attributes, { context } ) {
|
|
23
|
+
const customName = attributes?.metadata?.name;
|
|
24
|
+
|
|
25
|
+
if ( context === 'list-view' && customName ) {
|
|
26
|
+
return customName;
|
|
27
|
+
}
|
|
28
|
+
|
|
23
29
|
if ( context === 'accessibility' ) {
|
|
24
30
|
return attributes.customText;
|
|
25
31
|
}
|
|
@@ -16,8 +16,8 @@ import {
|
|
|
16
16
|
import {
|
|
17
17
|
InspectorControls,
|
|
18
18
|
useBlockProps,
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
RecursionProvider,
|
|
20
|
+
useHasRecursion,
|
|
21
21
|
store as blockEditorStore,
|
|
22
22
|
withColors,
|
|
23
23
|
ContrastChecker,
|