@wordpress/block-library 9.26.1-next.719a03cbe.0 → 9.27.1-next.46f643fa0.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.
- package/CHANGELOG.md +2 -0
- package/build/categories/edit.js +15 -3
- package/build/categories/edit.js.map +1 -1
- package/build/cover/edit/block-controls.js +4 -2
- package/build/cover/edit/block-controls.js.map +1 -1
- package/build/cover/edit/index.js +6 -3
- package/build/cover/edit/index.js.map +1 -1
- package/build/cover/edit/inspector-controls.js +13 -4
- package/build/cover/edit/inspector-controls.js.map +1 -1
- package/build/cover/index.js +6 -0
- package/build/cover/index.js.map +1 -1
- package/build/cover/save.js +3 -1
- package/build/cover/save.js.map +1 -1
- package/build/file/edit.js +2 -1
- package/build/file/edit.js.map +1 -1
- package/build/latest-posts/edit.js +0 -2
- package/build/latest-posts/edit.js.map +1 -1
- package/build/media-text/edit.js +2 -2
- package/build/media-text/edit.js.map +1 -1
- package/build/navigation-link/edit.js +32 -15
- package/build/navigation-link/edit.js.map +1 -1
- package/build/navigation-link/update-attributes.js +112 -14
- package/build/navigation-link/update-attributes.js.map +1 -1
- package/build/navigation-submenu/edit.js +19 -2
- package/build/navigation-submenu/edit.js.map +1 -1
- package/build/paragraph/edit.js +2 -2
- package/build/paragraph/edit.js.map +1 -1
- package/build/post-content/edit.js +78 -16
- package/build/post-content/edit.js.map +1 -1
- package/build/post-content/index.js +6 -0
- package/build/post-content/index.js.map +1 -1
- package/build/post-date/deprecated.js +104 -1
- package/build/post-date/deprecated.js.map +1 -1
- package/build/post-date/edit.js +32 -32
- package/build/post-date/edit.js.map +1 -1
- package/build/post-date/index.js +4 -4
- package/build/post-date/index.js.map +1 -1
- package/build/post-date/variations.js +32 -3
- package/build/post-date/variations.js.map +1 -1
- package/build/separator/edit.js +5 -30
- package/build/separator/edit.js.map +1 -1
- package/build/site-tagline/index.js +1 -1
- package/build/social-link/variations.js +51 -49
- package/build/social-link/variations.js.map +1 -1
- package/build/utils/poster-image.js +93 -0
- package/build/utils/poster-image.js.map +1 -0
- package/build/video/edit.js +7 -6
- package/build/video/edit.js.map +1 -1
- package/build/video/tracks-editor.js +95 -104
- package/build/video/tracks-editor.js.map +1 -1
- package/build/video/tracks.js +6 -2
- package/build/video/tracks.js.map +1 -1
- package/build-module/categories/edit.js +15 -3
- package/build-module/categories/edit.js.map +1 -1
- package/build-module/cover/edit/block-controls.js +4 -2
- package/build-module/cover/edit/block-controls.js.map +1 -1
- package/build-module/cover/edit/index.js +6 -3
- package/build-module/cover/edit/index.js.map +1 -1
- package/build-module/cover/edit/inspector-controls.js +12 -4
- package/build-module/cover/edit/inspector-controls.js.map +1 -1
- package/build-module/cover/index.js +6 -0
- package/build-module/cover/index.js.map +1 -1
- package/build-module/cover/save.js +3 -1
- package/build-module/cover/save.js.map +1 -1
- package/build-module/file/edit.js +2 -1
- package/build-module/file/edit.js.map +1 -1
- package/build-module/latest-posts/edit.js +0 -2
- package/build-module/latest-posts/edit.js.map +1 -1
- package/build-module/media-text/edit.js +2 -2
- package/build-module/media-text/edit.js.map +1 -1
- package/build-module/navigation-link/edit.js +32 -15
- package/build-module/navigation-link/edit.js.map +1 -1
- package/build-module/navigation-link/update-attributes.js +113 -15
- package/build-module/navigation-link/update-attributes.js.map +1 -1
- package/build-module/navigation-submenu/edit.js +20 -3
- package/build-module/navigation-submenu/edit.js.map +1 -1
- package/build-module/paragraph/edit.js +2 -2
- package/build-module/paragraph/edit.js.map +1 -1
- package/build-module/post-content/edit.js +80 -18
- package/build-module/post-content/edit.js.map +1 -1
- package/build-module/post-content/index.js +6 -0
- package/build-module/post-content/index.js.map +1 -1
- package/build-module/post-date/deprecated.js +104 -1
- package/build-module/post-date/deprecated.js.map +1 -1
- package/build-module/post-date/edit.js +35 -35
- package/build-module/post-date/edit.js.map +1 -1
- package/build-module/post-date/index.js +4 -4
- package/build-module/post-date/index.js.map +1 -1
- package/build-module/post-date/variations.js +32 -3
- package/build-module/post-date/variations.js.map +1 -1
- package/build-module/separator/edit.js +6 -31
- package/build-module/separator/edit.js.map +1 -1
- package/build-module/site-tagline/index.js +1 -1
- package/build-module/social-link/variations.js +52 -50
- package/build-module/social-link/variations.js.map +1 -1
- package/build-module/utils/poster-image.js +85 -0
- package/build-module/utils/poster-image.js.map +1 -0
- package/build-module/video/edit.js +7 -6
- package/build-module/video/edit.js.map +1 -1
- package/build-module/video/tracks-editor.js +96 -105
- package/build-module/video/tracks-editor.js.map +1 -1
- package/build-module/video/tracks.js +6 -2
- package/build-module/video/tracks.js.map +1 -1
- package/build-style/archives/editor-rtl.css +0 -4
- package/build-style/archives/editor.css +0 -4
- package/build-style/editor-rtl.css +67 -18
- package/build-style/editor.css +67 -18
- package/build-style/file/style-rtl.css +1 -1
- package/build-style/file/style.css +1 -1
- package/build-style/navigation/editor-rtl.css +6 -6
- package/build-style/navigation/editor.css +6 -6
- package/build-style/navigation/style-rtl.css +1 -0
- package/build-style/navigation/style.css +1 -0
- package/build-style/page-list/editor-rtl.css +0 -4
- package/build-style/page-list/editor.css +0 -4
- package/build-style/style-rtl.css +3 -1
- package/build-style/style.css +3 -1
- package/build-style/video/editor-rtl.css +0 -4
- package/build-style/video/editor.css +0 -4
- package/build-style/video/style-rtl.css +1 -0
- package/build-style/video/style.css +1 -0
- package/package.json +35 -35
- package/src/archives/editor.scss +0 -4
- package/src/categories/edit.js +13 -1
- package/src/comments-pagination/index.php +7 -2
- package/src/cover/block.json +6 -0
- package/src/cover/edit/block-controls.js +22 -17
- package/src/cover/edit/index.js +4 -1
- package/src/cover/edit/inspector-controls.js +15 -2
- package/src/cover/save.js +2 -0
- package/src/editor.scss +1 -0
- package/src/file/edit.js +4 -1
- package/src/file/style.scss +1 -1
- package/src/latest-posts/edit.js +0 -2
- package/src/media-text/edit.js +1 -1
- package/src/navigation/style.scss +1 -0
- package/src/navigation-link/edit.js +28 -16
- package/src/navigation-link/test/edit.js +738 -6
- package/src/navigation-link/update-attributes.js +125 -12
- package/src/navigation-submenu/edit.js +21 -1
- package/src/page-list/editor.scss +0 -6
- package/src/paragraph/edit.js +2 -2
- package/src/post-content/block.json +6 -0
- package/src/post-content/edit.js +71 -19
- package/src/post-content/index.php +11 -4
- package/src/post-date/block.json +4 -4
- package/src/post-date/deprecated.js +104 -1
- package/src/post-date/edit.js +74 -86
- package/src/post-date/index.php +55 -28
- package/src/post-date/variations.js +37 -3
- package/src/post-featured-image/index.php +3 -2
- package/src/separator/edit.js +8 -43
- package/src/site-tagline/block.json +1 -1
- package/src/social-link/README.md +21 -0
- package/src/social-link/index.php +49 -49
- package/src/social-link/variations.js +51 -49
- package/src/utils/poster-image.js +131 -0
- package/src/utils/poster-image.scss +75 -0
- package/src/video/edit.js +8 -6
- package/src/video/editor.scss +0 -6
- package/src/video/index.php +91 -0
- package/src/video/style.native.scss +1 -0
- package/src/video/style.scss +1 -0
- package/src/video/tracks-editor.js +93 -103
- package/src/video/tracks.js +2 -1
- package/build/video/poster-image.js +0 -81
- package/build/video/poster-image.js.map +0 -1
- package/build-module/video/poster-image.js +0 -74
- package/build-module/video/poster-image.js.map +0 -1
- package/src/video/poster-image.js +0 -86
|
@@ -2,7 +2,89 @@
|
|
|
2
2
|
* WordPress dependencies
|
|
3
3
|
*/
|
|
4
4
|
import { escapeHTML } from '@wordpress/escape-html';
|
|
5
|
-
import { safeDecodeURI } from '@wordpress/url';
|
|
5
|
+
import { safeDecodeURI, getPath } from '@wordpress/url';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Determines if an entity link should be severed based on URL changes.
|
|
9
|
+
*
|
|
10
|
+
* @param {string} originalUrl - The original URL
|
|
11
|
+
* @param {string} newUrl - The new URL
|
|
12
|
+
* @return {boolean} True if the entity link should be severed
|
|
13
|
+
*/
|
|
14
|
+
const shouldSeverEntityLink = ( originalUrl, newUrl ) => {
|
|
15
|
+
if ( ! originalUrl || ! newUrl ) {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const normalizePath = ( path ) => {
|
|
20
|
+
if ( ! path ) {
|
|
21
|
+
return '';
|
|
22
|
+
}
|
|
23
|
+
return path.replace( /\/+$/, '' ); // Remove trailing slashes
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
// Helper function to create URL objects with proper base handling
|
|
27
|
+
const createUrlObject = ( url, baseUrl = null ) => {
|
|
28
|
+
try {
|
|
29
|
+
// Always provide a base URL - it will be ignored for absolute URLs
|
|
30
|
+
// Use window.location.origin in browser, fallback for Node/tests
|
|
31
|
+
const base =
|
|
32
|
+
baseUrl ||
|
|
33
|
+
( typeof window !== 'undefined'
|
|
34
|
+
? window.location.origin
|
|
35
|
+
: 'https://wordpress.org' );
|
|
36
|
+
return new URL( url, base );
|
|
37
|
+
} catch ( error ) {
|
|
38
|
+
// If URL construction still fails, it's likely an invalid URL
|
|
39
|
+
// and we should sever the entity link
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const originalUrlObj = createUrlObject( originalUrl );
|
|
45
|
+
if ( ! originalUrlObj ) {
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const newUrlObj = createUrlObject( newUrl, originalUrl );
|
|
50
|
+
if ( ! newUrlObj ) {
|
|
51
|
+
return true;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// Move these declarations here, after the null checks
|
|
55
|
+
const originalHostname = originalUrlObj.hostname;
|
|
56
|
+
const newHostname = newUrlObj.hostname;
|
|
57
|
+
const originalPath = normalizePath( getPath( originalUrlObj.toString() ) );
|
|
58
|
+
const newPath = normalizePath( getPath( newUrlObj.toString() ) );
|
|
59
|
+
|
|
60
|
+
// If hostname or path changed, sever the entity link
|
|
61
|
+
if ( originalHostname !== newHostname || originalPath !== newPath ) {
|
|
62
|
+
return true;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// Special handling for plain permalinks (query string post IDs)
|
|
66
|
+
const originalP = originalUrlObj.searchParams.get( 'p' );
|
|
67
|
+
const newP = newUrlObj.searchParams.get( 'p' );
|
|
68
|
+
|
|
69
|
+
// If both are plain permalinks (with ?p= or ?page_id=), compare the IDs
|
|
70
|
+
if ( originalP && newP && originalP !== newP ) {
|
|
71
|
+
return true;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const originalPageId = originalUrlObj.searchParams.get( 'page_id' );
|
|
75
|
+
const newPageId = newUrlObj.searchParams.get( 'page_id' );
|
|
76
|
+
|
|
77
|
+
if ( originalPageId && newPageId && originalPageId !== newPageId ) {
|
|
78
|
+
return true;
|
|
79
|
+
}
|
|
80
|
+
// If switching between ?p= and ?page_id=, or one is missing, sever
|
|
81
|
+
if ( ( originalP && newPageId ) || ( originalPageId && newP ) ) {
|
|
82
|
+
return true;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// If only query string or fragment changed, preserve the entity link
|
|
86
|
+
return false;
|
|
87
|
+
};
|
|
6
88
|
|
|
7
89
|
/**
|
|
8
90
|
* @typedef {'post-type'|'custom'|'taxonomy'|'post-type-archive'} WPNavigationLinkKind
|
|
@@ -42,19 +124,23 @@ export const updateAttributes = (
|
|
|
42
124
|
|
|
43
125
|
const {
|
|
44
126
|
title: newLabel = '', // the title of any provided Post.
|
|
45
|
-
|
|
127
|
+
label: newLabelFromLabel = '', // alternative to title
|
|
128
|
+
url: newUrl,
|
|
46
129
|
opensInNewTab,
|
|
47
|
-
id,
|
|
130
|
+
id: newID,
|
|
48
131
|
kind: newKind = originalKind,
|
|
49
132
|
type: newType = originalType,
|
|
50
133
|
} = updatedValue;
|
|
51
134
|
|
|
52
|
-
|
|
53
|
-
const
|
|
135
|
+
// Use title if provided, otherwise fall back to label
|
|
136
|
+
const finalNewLabel = newLabel || newLabelFromLabel;
|
|
137
|
+
|
|
138
|
+
const newLabelWithoutHttp = finalNewLabel.replace( /http(s?):\/\//gi, '' );
|
|
139
|
+
const newUrlWithoutHttp = newUrl?.replace( /http(s?):\/\//gi, '' ) ?? '';
|
|
54
140
|
|
|
55
141
|
const useNewLabel =
|
|
56
|
-
|
|
57
|
-
|
|
142
|
+
finalNewLabel &&
|
|
143
|
+
finalNewLabel !== originalLabel &&
|
|
58
144
|
// LinkControl without the title field relies
|
|
59
145
|
// on the check below. Specifically, it assumes that
|
|
60
146
|
// the URL is the same as a title.
|
|
@@ -73,7 +159,7 @@ export const updateAttributes = (
|
|
|
73
159
|
// - https://github.com/WordPress/gutenberg/pull/41063
|
|
74
160
|
// - https://github.com/WordPress/gutenberg/pull/18617.
|
|
75
161
|
const label = useNewLabel
|
|
76
|
-
? escapeHTML(
|
|
162
|
+
? escapeHTML( finalNewLabel )
|
|
77
163
|
: originalLabel || escapeHTML( newUrlWithoutHttp );
|
|
78
164
|
|
|
79
165
|
// In https://github.com/WordPress/gutenberg/pull/24670 we decided to use "tag" in favor of "post_tag"
|
|
@@ -86,13 +172,40 @@ export const updateAttributes = (
|
|
|
86
172
|
( ! newKind && ! isBuiltInType ) || newKind === 'custom';
|
|
87
173
|
const kind = isCustomLink ? 'custom' : newKind;
|
|
88
174
|
|
|
89
|
-
|
|
175
|
+
const attributes = {
|
|
90
176
|
// Passed `url` may already be encoded. To prevent double encoding, decodeURI is executed to revert to the original string.
|
|
91
|
-
...( newUrl
|
|
177
|
+
...( newUrl !== undefined
|
|
178
|
+
? { url: newUrl ? encodeURI( safeDecodeURI( newUrl ) ) : newUrl }
|
|
179
|
+
: {} ),
|
|
92
180
|
...( label && { label } ),
|
|
93
181
|
...( undefined !== opensInNewTab && { opensInNewTab } ),
|
|
94
|
-
...( id && Number.isInteger( id ) && { id } ),
|
|
95
182
|
...( kind && { kind } ),
|
|
96
183
|
...( type && type !== 'URL' && { type } ),
|
|
97
|
-
}
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
// If the block's id is set then the menu item is linking to an entity.
|
|
187
|
+
// Therefore, if the URL is set but a new ID is not provided, check if
|
|
188
|
+
// the entity link should be severed based on URL changes.
|
|
189
|
+
if ( newUrl && ! newID && blockAttributes.id ) {
|
|
190
|
+
const shouldSever = shouldSeverEntityLink(
|
|
191
|
+
blockAttributes.url,
|
|
192
|
+
newUrl
|
|
193
|
+
);
|
|
194
|
+
|
|
195
|
+
if ( shouldSever ) {
|
|
196
|
+
attributes.id = undefined; // explicitly "unset" the ID.
|
|
197
|
+
// When URL is manually changed in a way that severs the entity link,
|
|
198
|
+
// update kind and type to "custom" to indicate this is now a custom link.
|
|
199
|
+
attributes.kind = 'custom';
|
|
200
|
+
attributes.type = 'custom';
|
|
201
|
+
}
|
|
202
|
+
} else if ( newID && Number.isInteger( newID ) ) {
|
|
203
|
+
attributes.id = newID;
|
|
204
|
+
} else if ( blockAttributes.id ) {
|
|
205
|
+
// If we have an existing ID and no URL change, ensure kind and type are preserved
|
|
206
|
+
attributes.kind = kind;
|
|
207
|
+
attributes.type = type;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
setAttributes( attributes );
|
|
98
211
|
};
|
|
@@ -8,6 +8,7 @@ import clsx from 'clsx';
|
|
|
8
8
|
*/
|
|
9
9
|
import { useSelect, useDispatch } from '@wordpress/data';
|
|
10
10
|
import {
|
|
11
|
+
CheckboxControl,
|
|
11
12
|
TextControl,
|
|
12
13
|
TextareaControl,
|
|
13
14
|
ToolbarButton,
|
|
@@ -134,7 +135,7 @@ export default function NavigationSubmenuEdit( {
|
|
|
134
135
|
context,
|
|
135
136
|
clientId,
|
|
136
137
|
} ) {
|
|
137
|
-
const { label, url, description, rel } = attributes;
|
|
138
|
+
const { label, url, description, rel, opensInNewTab } = attributes;
|
|
138
139
|
|
|
139
140
|
const { showSubmenuIcon, maxNestingLevel, openSubmenusOnClick } = context;
|
|
140
141
|
|
|
@@ -392,6 +393,7 @@ export default function NavigationSubmenuEdit( {
|
|
|
392
393
|
url: '',
|
|
393
394
|
description: '',
|
|
394
395
|
rel: '',
|
|
396
|
+
opensInNewTab: false,
|
|
395
397
|
} );
|
|
396
398
|
} }
|
|
397
399
|
dropdownMenuProps={ dropdownMenuProps }
|
|
@@ -433,6 +435,24 @@ export default function NavigationSubmenuEdit( {
|
|
|
433
435
|
/>
|
|
434
436
|
</ToolsPanelItem>
|
|
435
437
|
|
|
438
|
+
<ToolsPanelItem
|
|
439
|
+
hasValue={ () => !! opensInNewTab }
|
|
440
|
+
label={ __( 'Open in new tab' ) }
|
|
441
|
+
onDeselect={ () =>
|
|
442
|
+
setAttributes( { opensInNewTab: false } )
|
|
443
|
+
}
|
|
444
|
+
isShownByDefault
|
|
445
|
+
>
|
|
446
|
+
<CheckboxControl
|
|
447
|
+
__nextHasNoMarginBottom
|
|
448
|
+
label={ __( 'Open in new tab' ) }
|
|
449
|
+
checked={ opensInNewTab }
|
|
450
|
+
onChange={ ( value ) =>
|
|
451
|
+
setAttributes( { opensInNewTab: value } )
|
|
452
|
+
}
|
|
453
|
+
/>
|
|
454
|
+
</ToolsPanelItem>
|
|
455
|
+
|
|
436
456
|
<ToolsPanelItem
|
|
437
457
|
label={ __( 'Description' ) }
|
|
438
458
|
isShownByDefault
|
|
@@ -1,10 +1,4 @@
|
|
|
1
1
|
.wp-block-navigation {
|
|
2
|
-
// Block wrapper gets the classes in the editor, and there's an extra div wrapper for now, so background styles need to be inherited.
|
|
3
|
-
.wp-block-page-list > div,
|
|
4
|
-
.wp-block-page-list {
|
|
5
|
-
background-color: inherit;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
2
|
// space-between justification.
|
|
9
3
|
&.items-justified-space-between {
|
|
10
4
|
.wp-block-page-list > div,
|
package/src/paragraph/edit.js
CHANGED
|
@@ -81,8 +81,8 @@ function DropCapControl( { clientId, attributes, setAttributes, name } ) {
|
|
|
81
81
|
hasValue={ () => !! dropCap }
|
|
82
82
|
label={ __( 'Drop cap' ) }
|
|
83
83
|
isShownByDefault={ isDropCapControlEnabledByDefault }
|
|
84
|
-
onDeselect={ () => setAttributes( { dropCap:
|
|
85
|
-
resetAllFilter={ () => ( { dropCap:
|
|
84
|
+
onDeselect={ () => setAttributes( { dropCap: false } ) }
|
|
85
|
+
resetAllFilter={ () => ( { dropCap: false } ) }
|
|
86
86
|
panelId={ clientId }
|
|
87
87
|
>
|
|
88
88
|
<ToggleControl
|
|
@@ -7,6 +7,12 @@
|
|
|
7
7
|
"description": "Displays the contents of a post or page.",
|
|
8
8
|
"textdomain": "default",
|
|
9
9
|
"usesContext": [ "postId", "postType", "queryId" ],
|
|
10
|
+
"attributes": {
|
|
11
|
+
"tagName": {
|
|
12
|
+
"type": "string",
|
|
13
|
+
"default": "div"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
10
16
|
"example": {
|
|
11
17
|
"viewportWidth": 350
|
|
12
18
|
},
|
package/src/post-content/edit.js
CHANGED
|
@@ -3,11 +3,13 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { __ } from '@wordpress/i18n';
|
|
5
5
|
import {
|
|
6
|
+
InspectorControls,
|
|
6
7
|
useBlockProps,
|
|
7
8
|
useInnerBlocksProps,
|
|
8
9
|
RecursionProvider,
|
|
9
10
|
useHasRecursion,
|
|
10
11
|
Warning,
|
|
12
|
+
privateApis as blockEditorPrivateApis,
|
|
11
13
|
__experimentalUseBlockPreview as useBlockPreview,
|
|
12
14
|
} from '@wordpress/block-editor';
|
|
13
15
|
import { parse } from '@wordpress/blocks';
|
|
@@ -23,6 +25,9 @@ import { useMemo } from '@wordpress/element';
|
|
|
23
25
|
* Internal dependencies
|
|
24
26
|
*/
|
|
25
27
|
import { useCanEditEntity } from '../utils/hooks';
|
|
28
|
+
import { unlock } from '../lock-unlock';
|
|
29
|
+
|
|
30
|
+
const { HTMLElementControl } = unlock( blockEditorPrivateApis );
|
|
26
31
|
|
|
27
32
|
function ReadOnlyContent( {
|
|
28
33
|
parentLayout,
|
|
@@ -30,6 +35,7 @@ function ReadOnlyContent( {
|
|
|
30
35
|
userCanEdit,
|
|
31
36
|
postType,
|
|
32
37
|
postId,
|
|
38
|
+
tagName: TagName = 'div',
|
|
33
39
|
} ) {
|
|
34
40
|
const [ , , content ] = useEntityProp(
|
|
35
41
|
'postType',
|
|
@@ -60,18 +66,18 @@ function ReadOnlyContent( {
|
|
|
60
66
|
}
|
|
61
67
|
|
|
62
68
|
return content?.protected ? (
|
|
63
|
-
<
|
|
69
|
+
<TagName { ...blockProps }>
|
|
64
70
|
<Warning>{ __( 'This content is password protected.' ) }</Warning>
|
|
65
|
-
</
|
|
71
|
+
</TagName>
|
|
66
72
|
) : (
|
|
67
|
-
<
|
|
73
|
+
<TagName
|
|
68
74
|
{ ...blockProps }
|
|
69
75
|
dangerouslySetInnerHTML={ { __html: content?.rendered } }
|
|
70
|
-
></
|
|
76
|
+
></TagName>
|
|
71
77
|
);
|
|
72
78
|
}
|
|
73
79
|
|
|
74
|
-
function EditableContent( { context = {} } ) {
|
|
80
|
+
function EditableContent( { context = {}, tagName: TagName = 'div' } ) {
|
|
75
81
|
const { postType, postId } = context;
|
|
76
82
|
|
|
77
83
|
const [ blocks, onInput, onChange ] = useEntityBlockEditor(
|
|
@@ -104,12 +110,15 @@ function EditableContent( { context = {} } ) {
|
|
|
104
110
|
template: ! hasInnerBlocks ? initialInnerBlocks : undefined,
|
|
105
111
|
}
|
|
106
112
|
);
|
|
107
|
-
return <
|
|
113
|
+
return <TagName { ...props } />;
|
|
108
114
|
}
|
|
109
115
|
|
|
110
116
|
function Content( props ) {
|
|
111
|
-
const {
|
|
112
|
-
|
|
117
|
+
const {
|
|
118
|
+
context: { queryId, postType, postId } = {},
|
|
119
|
+
layoutClassNames,
|
|
120
|
+
tagName,
|
|
121
|
+
} = props;
|
|
113
122
|
const userCanEdit = useCanEditEntity( 'postType', postType, postId );
|
|
114
123
|
if ( userCanEdit === undefined ) {
|
|
115
124
|
return null;
|
|
@@ -127,6 +136,7 @@ function Content( props ) {
|
|
|
127
136
|
userCanEdit={ userCanEdit }
|
|
128
137
|
postType={ postType }
|
|
129
138
|
postId={ postId }
|
|
139
|
+
tagName={ tagName }
|
|
130
140
|
/>
|
|
131
141
|
);
|
|
132
142
|
}
|
|
@@ -165,8 +175,39 @@ function RecursionError() {
|
|
|
165
175
|
);
|
|
166
176
|
}
|
|
167
177
|
|
|
178
|
+
/**
|
|
179
|
+
* Render inspector controls for the PostContent block.
|
|
180
|
+
*
|
|
181
|
+
* @param {Object} props Component props.
|
|
182
|
+
* @param {string} props.tagName The HTML tag name.
|
|
183
|
+
* @param {Function} props.onSelectTagName onChange function for the SelectControl.
|
|
184
|
+
* @param {string} props.clientId The client ID of the current block.
|
|
185
|
+
*
|
|
186
|
+
* @return {JSX.Element} The control group.
|
|
187
|
+
*/
|
|
188
|
+
function PostContentEditControls( { tagName, onSelectTagName, clientId } ) {
|
|
189
|
+
return (
|
|
190
|
+
<InspectorControls group="advanced">
|
|
191
|
+
<HTMLElementControl
|
|
192
|
+
tagName={ tagName }
|
|
193
|
+
onChange={ onSelectTagName }
|
|
194
|
+
clientId={ clientId }
|
|
195
|
+
options={ [
|
|
196
|
+
{ label: __( 'Default (<div>)' ), value: 'div' },
|
|
197
|
+
{ label: '<main>', value: 'main' },
|
|
198
|
+
{ label: '<section>', value: 'section' },
|
|
199
|
+
{ label: '<article>', value: 'article' },
|
|
200
|
+
] }
|
|
201
|
+
/>
|
|
202
|
+
</InspectorControls>
|
|
203
|
+
);
|
|
204
|
+
}
|
|
205
|
+
|
|
168
206
|
export default function PostContentEdit( {
|
|
169
207
|
context,
|
|
208
|
+
attributes: { tagName = 'div' },
|
|
209
|
+
setAttributes,
|
|
210
|
+
clientId,
|
|
170
211
|
__unstableLayoutClassNames: layoutClassNames,
|
|
171
212
|
__unstableParentLayout: parentLayout,
|
|
172
213
|
} ) {
|
|
@@ -177,17 +218,28 @@ export default function PostContentEdit( {
|
|
|
177
218
|
return <RecursionError />;
|
|
178
219
|
}
|
|
179
220
|
|
|
221
|
+
const handleSelectTagName = ( value ) => {
|
|
222
|
+
setAttributes( { tagName: value } );
|
|
223
|
+
};
|
|
224
|
+
|
|
180
225
|
return (
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
226
|
+
<>
|
|
227
|
+
<PostContentEditControls
|
|
228
|
+
tagName={ tagName }
|
|
229
|
+
onSelectTagName={ handleSelectTagName }
|
|
230
|
+
clientId={ clientId }
|
|
231
|
+
/>
|
|
232
|
+
<RecursionProvider uniqueId={ contextPostId }>
|
|
233
|
+
{ contextPostId && contextPostType ? (
|
|
234
|
+
<Content
|
|
235
|
+
context={ context }
|
|
236
|
+
parentLayout={ parentLayout }
|
|
237
|
+
layoutClassNames={ layoutClassNames }
|
|
238
|
+
/>
|
|
239
|
+
) : (
|
|
240
|
+
<Placeholder layoutClassNames={ layoutClassNames } />
|
|
241
|
+
) }
|
|
242
|
+
</RecursionProvider>
|
|
243
|
+
</>
|
|
192
244
|
);
|
|
193
245
|
}
|
|
@@ -54,12 +54,19 @@ function render_block_core_post_content( $attributes, $content, $block ) {
|
|
|
54
54
|
return '';
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
+
$tag_name = 'div';
|
|
58
|
+
|
|
59
|
+
if ( ! empty( $attributes['tagName'] ) && tag_escape( $attributes['tagName'] ) === $attributes['tagName'] ) {
|
|
60
|
+
$tag_name = $attributes['tagName'];
|
|
61
|
+
}
|
|
62
|
+
|
|
57
63
|
$wrapper_attributes = get_block_wrapper_attributes( array( 'class' => 'entry-content' ) );
|
|
58
64
|
|
|
59
|
-
return (
|
|
60
|
-
'
|
|
61
|
-
|
|
62
|
-
|
|
65
|
+
return sprintf(
|
|
66
|
+
'<%1$s %2$s>%3$s</%1$s>',
|
|
67
|
+
$tag_name,
|
|
68
|
+
$wrapper_attributes,
|
|
69
|
+
$content
|
|
63
70
|
);
|
|
64
71
|
}
|
|
65
72
|
|
package/src/post-date/block.json
CHANGED
|
@@ -7,6 +7,10 @@
|
|
|
7
7
|
"description": "Display the publish date for an entry such as a post or page.",
|
|
8
8
|
"textdomain": "default",
|
|
9
9
|
"attributes": {
|
|
10
|
+
"datetime": {
|
|
11
|
+
"type": "string",
|
|
12
|
+
"role": "content"
|
|
13
|
+
},
|
|
10
14
|
"textAlign": {
|
|
11
15
|
"type": "string"
|
|
12
16
|
},
|
|
@@ -17,10 +21,6 @@
|
|
|
17
21
|
"type": "boolean",
|
|
18
22
|
"default": false,
|
|
19
23
|
"role": "content"
|
|
20
|
-
},
|
|
21
|
-
"displayType": {
|
|
22
|
-
"type": "string",
|
|
23
|
-
"default": "date"
|
|
24
24
|
}
|
|
25
25
|
},
|
|
26
26
|
"usesContext": [ "postId", "postType", "queryId" ],
|
|
@@ -1,8 +1,111 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External dependencies
|
|
3
|
+
*/
|
|
4
|
+
import clsx from 'clsx';
|
|
5
|
+
|
|
1
6
|
/**
|
|
2
7
|
* Internal dependencies
|
|
3
8
|
*/
|
|
4
9
|
import migrateFontFamily from '../utils/migrate-font-family';
|
|
5
10
|
|
|
11
|
+
const v2 = {
|
|
12
|
+
attributes: {
|
|
13
|
+
textAlign: {
|
|
14
|
+
type: 'string',
|
|
15
|
+
},
|
|
16
|
+
format: {
|
|
17
|
+
type: 'string',
|
|
18
|
+
},
|
|
19
|
+
isLink: {
|
|
20
|
+
type: 'boolean',
|
|
21
|
+
default: false,
|
|
22
|
+
role: 'content',
|
|
23
|
+
},
|
|
24
|
+
displayType: {
|
|
25
|
+
type: 'string',
|
|
26
|
+
default: 'date',
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
supports: {
|
|
30
|
+
html: false,
|
|
31
|
+
color: {
|
|
32
|
+
gradients: true,
|
|
33
|
+
link: true,
|
|
34
|
+
__experimentalDefaultControls: {
|
|
35
|
+
background: true,
|
|
36
|
+
text: true,
|
|
37
|
+
link: true,
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
spacing: {
|
|
41
|
+
margin: true,
|
|
42
|
+
padding: true,
|
|
43
|
+
},
|
|
44
|
+
typography: {
|
|
45
|
+
fontSize: true,
|
|
46
|
+
lineHeight: true,
|
|
47
|
+
__experimentalFontFamily: true,
|
|
48
|
+
__experimentalFontWeight: true,
|
|
49
|
+
__experimentalFontStyle: true,
|
|
50
|
+
__experimentalTextTransform: true,
|
|
51
|
+
__experimentalTextDecoration: true,
|
|
52
|
+
__experimentalLetterSpacing: true,
|
|
53
|
+
__experimentalDefaultControls: {
|
|
54
|
+
fontSize: true,
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
interactivity: {
|
|
58
|
+
clientNavigation: true,
|
|
59
|
+
},
|
|
60
|
+
__experimentalBorder: {
|
|
61
|
+
radius: true,
|
|
62
|
+
color: true,
|
|
63
|
+
width: true,
|
|
64
|
+
style: true,
|
|
65
|
+
__experimentalDefaultControls: {
|
|
66
|
+
radius: true,
|
|
67
|
+
color: true,
|
|
68
|
+
width: true,
|
|
69
|
+
style: true,
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
save() {
|
|
74
|
+
return null;
|
|
75
|
+
},
|
|
76
|
+
migrate( { className, displayType, metadata, ...otherAttributes } ) {
|
|
77
|
+
if ( displayType === 'date' || displayType === 'modified' ) {
|
|
78
|
+
if ( displayType === 'modified' ) {
|
|
79
|
+
className = clsx(
|
|
80
|
+
className,
|
|
81
|
+
'wp-block-post-date__modified-date'
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return {
|
|
86
|
+
...otherAttributes,
|
|
87
|
+
className,
|
|
88
|
+
metadata: {
|
|
89
|
+
...metadata,
|
|
90
|
+
bindings: {
|
|
91
|
+
datetime: {
|
|
92
|
+
source: 'core/post-data',
|
|
93
|
+
args: { key: displayType },
|
|
94
|
+
},
|
|
95
|
+
},
|
|
96
|
+
},
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
},
|
|
100
|
+
isEligible( attributes ) {
|
|
101
|
+
// If there's neither an explicit `datetime` attribute nor a block binding for that attribute,
|
|
102
|
+
// then we're dealing with an old version of the block.
|
|
103
|
+
return (
|
|
104
|
+
! attributes.datetime && ! attributes?.metadata?.bindings?.datetime
|
|
105
|
+
);
|
|
106
|
+
},
|
|
107
|
+
};
|
|
108
|
+
|
|
6
109
|
const v1 = {
|
|
7
110
|
attributes: {
|
|
8
111
|
textAlign: {
|
|
@@ -49,4 +152,4 @@ const v1 = {
|
|
|
49
152
|
*
|
|
50
153
|
* See block-deprecation.md
|
|
51
154
|
*/
|
|
52
|
-
export default [ v1 ];
|
|
155
|
+
export default [ v2, v1 ];
|