@wordpress/block-library 9.33.6 → 9.33.8
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/build/heading/index.js +3 -1
- package/build/heading/index.js.map +3 -3
- package/build/heading/variations.js +53 -0
- package/build/heading/variations.js.map +7 -0
- package/build/navigation-link/edit.js +31 -10
- package/build/navigation-link/edit.js.map +2 -2
- package/build/navigation-link/link-ui/index.js +8 -3
- package/build/navigation-link/link-ui/index.js.map +2 -2
- package/build/navigation-link/shared/controls.js +74 -23
- package/build/navigation-link/shared/controls.js.map +2 -2
- package/build/navigation-link/shared/index.js +4 -0
- package/build/navigation-link/shared/index.js.map +2 -2
- package/build/navigation-link/shared/use-entity-binding.js +32 -2
- package/build/navigation-link/shared/use-entity-binding.js.map +3 -3
- package/build/paragraph/index.js +3 -1
- package/build/paragraph/index.js.map +3 -3
- package/build/paragraph/variations.js +55 -0
- package/build/paragraph/variations.js.map +7 -0
- package/build/social-links/edit.js +1 -1
- package/build/social-links/edit.js.map +1 -1
- package/build-module/heading/index.js +3 -1
- package/build-module/heading/index.js.map +2 -2
- package/build-module/heading/variations.js +33 -0
- package/build-module/heading/variations.js.map +7 -0
- package/build-module/navigation-link/edit.js +45 -14
- package/build-module/navigation-link/edit.js.map +2 -2
- package/build-module/navigation-link/link-ui/index.js +8 -3
- package/build-module/navigation-link/link-ui/index.js.map +2 -2
- package/build-module/navigation-link/shared/controls.js +72 -23
- package/build-module/navigation-link/shared/controls.js.map +2 -2
- package/build-module/navigation-link/shared/index.js +3 -1
- package/build-module/navigation-link/shared/index.js.map +2 -2
- package/build-module/navigation-link/shared/use-entity-binding.js +36 -3
- package/build-module/navigation-link/shared/use-entity-binding.js.map +2 -2
- package/build-module/paragraph/index.js +3 -1
- package/build-module/paragraph/index.js.map +2 -2
- package/build-module/paragraph/variations.js +35 -0
- package/build-module/paragraph/variations.js.map +7 -0
- package/build-module/social-links/edit.js +1 -1
- package/build-module/social-links/edit.js.map +1 -1
- package/build-style/accordion-heading/style-rtl.css +19 -3
- package/build-style/accordion-heading/style.css +19 -3
- package/build-style/accordion-panel/style-rtl.css +4 -1
- package/build-style/accordion-panel/style.css +4 -1
- package/build-style/editor-rtl.css +7 -0
- package/build-style/editor.css +7 -0
- package/build-style/navigation-link/editor-rtl.css +7 -0
- package/build-style/navigation-link/editor.css +7 -0
- package/build-style/style-rtl.css +23 -4
- package/build-style/style.css +23 -4
- package/package.json +11 -11
- package/src/accordion-heading/style.scss +40 -7
- package/src/accordion-panel/style.scss +6 -1
- package/src/heading/index.js +2 -0
- package/src/heading/variations.js +37 -0
- package/src/navigation-link/edit.js +71 -17
- package/src/navigation-link/editor.scss +7 -0
- package/src/navigation-link/link-ui/index.js +9 -8
- package/src/navigation-link/shared/controls.js +120 -26
- package/src/navigation-link/shared/index.js +1 -1
- package/src/navigation-link/shared/test/controls.js +19 -9
- package/src/navigation-link/shared/test/use-entity-binding.js +14 -1
- package/src/navigation-link/shared/use-entity-binding.js +60 -9
- package/src/paragraph/index.js +2 -0
- package/src/paragraph/variations.js +39 -0
- package/src/social-links/edit.js +1 -1
|
@@ -2,7 +2,12 @@
|
|
|
2
2
|
* WordPress dependencies
|
|
3
3
|
*/
|
|
4
4
|
import { useCallback } from '@wordpress/element';
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
useBlockBindingsUtils,
|
|
7
|
+
useBlockEditingMode,
|
|
8
|
+
} from '@wordpress/block-editor';
|
|
9
|
+
import { useSelect } from '@wordpress/data';
|
|
10
|
+
import { store as coreStore } from '@wordpress/core-data';
|
|
6
11
|
|
|
7
12
|
/**
|
|
8
13
|
* Builds entity binding configuration for navigation link URLs.
|
|
@@ -16,7 +21,7 @@ import { useBlockBindingsUtils } from '@wordpress/block-editor';
|
|
|
16
21
|
* @throws {Error} If kind is not 'post-type' or 'taxonomy'
|
|
17
22
|
*/
|
|
18
23
|
export function buildNavigationLinkEntityBinding( kind ) {
|
|
19
|
-
// Validate kind parameter exists
|
|
24
|
+
// Validate kind parameter exists.
|
|
20
25
|
if ( kind === undefined ) {
|
|
21
26
|
throw new Error(
|
|
22
27
|
'buildNavigationLinkEntityBinding requires a kind parameter. ' +
|
|
@@ -24,7 +29,7 @@ export function buildNavigationLinkEntityBinding( kind ) {
|
|
|
24
29
|
);
|
|
25
30
|
}
|
|
26
31
|
|
|
27
|
-
// Validate kind parameter value
|
|
32
|
+
// Validate kind parameter value.
|
|
28
33
|
if ( kind !== 'post-type' && kind !== 'taxonomy' ) {
|
|
29
34
|
throw new Error(
|
|
30
35
|
`Invalid kind "${ kind }" provided to buildNavigationLinkEntityBinding. ` +
|
|
@@ -57,7 +62,8 @@ export function buildNavigationLinkEntityBinding( kind ) {
|
|
|
57
62
|
*/
|
|
58
63
|
export function useEntityBinding( { clientId, attributes } ) {
|
|
59
64
|
const { updateBlockBindings } = useBlockBindingsUtils( clientId );
|
|
60
|
-
const { metadata, id, kind } = attributes;
|
|
65
|
+
const { metadata, id, kind, type } = attributes;
|
|
66
|
+
const blockEditingMode = useBlockEditingMode();
|
|
61
67
|
|
|
62
68
|
const hasUrlBinding = !! metadata?.bindings?.url && !! id;
|
|
63
69
|
const expectedSource =
|
|
@@ -65,6 +71,50 @@ export function useEntityBinding( { clientId, attributes } ) {
|
|
|
65
71
|
const hasCorrectBinding =
|
|
66
72
|
hasUrlBinding && metadata?.bindings?.url?.source === expectedSource;
|
|
67
73
|
|
|
74
|
+
// Check if the bound entity is available (not deleted).
|
|
75
|
+
const isBoundEntityAvailable = useSelect(
|
|
76
|
+
( select ) => {
|
|
77
|
+
// First check: metadata/binding must exist
|
|
78
|
+
if ( ! hasCorrectBinding || ! id ) {
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const isPostType = kind === 'post-type';
|
|
83
|
+
const isTaxonomy = kind === 'taxonomy';
|
|
84
|
+
|
|
85
|
+
// Only check entity availability for post types and taxonomies.
|
|
86
|
+
if ( ! isPostType && ! isTaxonomy ) {
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// Skip check in disabled contexts to avoid unnecessary requests.
|
|
91
|
+
if ( blockEditingMode === 'disabled' ) {
|
|
92
|
+
return true; // Assume available in disabled contexts.
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// Second check: entity must exist
|
|
96
|
+
const { getEntityRecord, hasFinishedResolution } =
|
|
97
|
+
select( coreStore );
|
|
98
|
+
|
|
99
|
+
// Use the correct entity type based on kind.
|
|
100
|
+
const entityType = isTaxonomy ? 'taxonomy' : 'postType';
|
|
101
|
+
// Convert 'tag' back to 'post_tag' for the API call
|
|
102
|
+
// (it was converted from 'post_tag' to 'tag' for storage in updateAttributes)
|
|
103
|
+
const typeForAPI = type === 'tag' ? 'post_tag' : type;
|
|
104
|
+
const entityRecord = getEntityRecord( entityType, typeForAPI, id );
|
|
105
|
+
const hasResolved = hasFinishedResolution( 'getEntityRecord', [
|
|
106
|
+
entityType,
|
|
107
|
+
typeForAPI,
|
|
108
|
+
id,
|
|
109
|
+
] );
|
|
110
|
+
|
|
111
|
+
// If resolution has finished and entityRecord is undefined, the entity was deleted.
|
|
112
|
+
// Return true if entity exists, false if deleted.
|
|
113
|
+
return hasResolved ? entityRecord !== undefined : true;
|
|
114
|
+
},
|
|
115
|
+
[ kind, type, id, hasCorrectBinding, blockEditingMode ]
|
|
116
|
+
);
|
|
117
|
+
|
|
68
118
|
const clearBinding = useCallback( () => {
|
|
69
119
|
if ( hasUrlBinding ) {
|
|
70
120
|
updateBlockBindings( { url: undefined } );
|
|
@@ -73,11 +123,11 @@ export function useEntityBinding( { clientId, attributes } ) {
|
|
|
73
123
|
|
|
74
124
|
const createBinding = useCallback(
|
|
75
125
|
( updatedAttributes ) => {
|
|
76
|
-
// Use updated attributes if provided, otherwise fall back to closure attributes
|
|
77
|
-
// updatedAttributes needed to access the most up-to-date data when called synchronously
|
|
126
|
+
// Use updated attributes if provided, otherwise fall back to closure attributes.
|
|
127
|
+
// updatedAttributes needed to access the most up-to-date data when called synchronously.
|
|
78
128
|
const kindToUse = updatedAttributes?.kind ?? kind;
|
|
79
129
|
|
|
80
|
-
// Avoid creating binding if no kind is provided
|
|
130
|
+
// Avoid creating binding if no kind is provided.
|
|
81
131
|
if ( ! kindToUse ) {
|
|
82
132
|
return;
|
|
83
133
|
}
|
|
@@ -91,14 +141,15 @@ export function useEntityBinding( { clientId, attributes } ) {
|
|
|
91
141
|
'Failed to create entity binding:',
|
|
92
142
|
error.message
|
|
93
143
|
);
|
|
94
|
-
// Don't create binding if validation fails
|
|
144
|
+
// Don't create binding if validation fails.
|
|
95
145
|
}
|
|
96
146
|
},
|
|
97
|
-
[ updateBlockBindings, kind
|
|
147
|
+
[ updateBlockBindings, kind ]
|
|
98
148
|
);
|
|
99
149
|
|
|
100
150
|
return {
|
|
101
151
|
hasUrlBinding: hasCorrectBinding,
|
|
152
|
+
isBoundEntityAvailable,
|
|
102
153
|
clearBinding,
|
|
103
154
|
createBinding,
|
|
104
155
|
};
|
package/src/paragraph/index.js
CHANGED
|
@@ -13,6 +13,7 @@ import edit from './edit';
|
|
|
13
13
|
import metadata from './block.json';
|
|
14
14
|
import save from './save';
|
|
15
15
|
import transforms from './transforms';
|
|
16
|
+
import variations from './variations';
|
|
16
17
|
|
|
17
18
|
const { name } = metadata;
|
|
18
19
|
|
|
@@ -54,6 +55,7 @@ export const settings = {
|
|
|
54
55
|
},
|
|
55
56
|
edit,
|
|
56
57
|
save,
|
|
58
|
+
variations,
|
|
57
59
|
};
|
|
58
60
|
|
|
59
61
|
export const init = () => initBlock( { name, metadata, settings } );
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { __ } from '@wordpress/i18n';
|
|
5
|
+
import { Path, SVG } from '@wordpress/primitives';
|
|
6
|
+
import { paragraph } from '@wordpress/icons';
|
|
7
|
+
|
|
8
|
+
const variations = [
|
|
9
|
+
{
|
|
10
|
+
name: 'paragraph',
|
|
11
|
+
title: __( 'Paragraph' ),
|
|
12
|
+
description: __(
|
|
13
|
+
'Start with the basic building block of all narrative.'
|
|
14
|
+
),
|
|
15
|
+
isDefault: true,
|
|
16
|
+
scope: [ 'block', 'inserter', 'transform' ],
|
|
17
|
+
attributes: { fitText: undefined },
|
|
18
|
+
icon: paragraph,
|
|
19
|
+
},
|
|
20
|
+
// There is a hardcoded workaround in packages/block-editor/src/store/selectors.js
|
|
21
|
+
// to make Stretchy variations appear as the last of their sections in the inserter.
|
|
22
|
+
{
|
|
23
|
+
name: 'stretchy-paragraph',
|
|
24
|
+
title: __( 'Stretchy Paragraph' ),
|
|
25
|
+
description: __( 'Paragraph that resizes to fit its container.' ),
|
|
26
|
+
icon: (
|
|
27
|
+
<SVG xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
|
|
28
|
+
<Path d="M3 9c0 2.8 2.2 5 5 5v-.2V20h1.5V5.5H12V20h1.5V5.5h3V4H8C5.2 4 3 6.2 3 9Zm16.2-.2v1.5h2.2L17.7 14l1.1 1.1 3.7-3.7v2.2H24V8.8h-4.8Z" />
|
|
29
|
+
</SVG>
|
|
30
|
+
),
|
|
31
|
+
attributes: {
|
|
32
|
+
fitText: true,
|
|
33
|
+
},
|
|
34
|
+
scope: [ 'inserter', 'transform' ],
|
|
35
|
+
isActive: ( blockAttributes ) => blockAttributes.fitText === true,
|
|
36
|
+
},
|
|
37
|
+
];
|
|
38
|
+
|
|
39
|
+
export default variations;
|
package/src/social-links/edit.js
CHANGED
|
@@ -183,7 +183,7 @@ export function SocialLinksEdit( props ) {
|
|
|
183
183
|
<SelectControl
|
|
184
184
|
__next40pxDefaultSize
|
|
185
185
|
__nextHasNoMarginBottom
|
|
186
|
-
label={ __( 'Icon
|
|
186
|
+
label={ __( 'Icon size' ) }
|
|
187
187
|
onChange={ ( newSize ) => {
|
|
188
188
|
setAttributes( {
|
|
189
189
|
size: newSize === '' ? undefined : newSize,
|