@wordpress/block-library 8.9.0 → 8.10.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/comment-author-name/edit.js +1 -1
- package/build/comment-author-name/edit.js.map +1 -1
- package/build/comment-edit-link/edit.js +1 -1
- package/build/comment-edit-link/edit.js.map +1 -1
- package/build/cover/edit/inspector-controls.js +1 -1
- package/build/cover/edit/inspector-controls.js.map +1 -1
- package/build/cover/index.js +1 -1
- package/build/cover/variations.js +1 -1
- package/build/cover/variations.js.map +1 -1
- package/build/details/edit.js +19 -5
- package/build/details/edit.js.map +1 -1
- package/build/details/index.js +14 -10
- package/build/details/index.js.map +1 -1
- package/build/details/save.js +4 -1
- package/build/details/save.js.map +1 -1
- package/build/embed/variations.js +2 -2
- package/build/embed/variations.js.map +1 -1
- package/build/file/view.js +1 -1
- package/build/file/view.js.map +1 -1
- package/build/gallery/edit.js +2 -8
- package/build/gallery/edit.js.map +1 -1
- package/build/index.js +0 -6
- package/build/index.js.map +1 -1
- package/build/index.native.js +1 -1
- package/build/index.native.js.map +1 -1
- package/build/list-item/utils.js +5 -1
- package/build/list-item/utils.js.map +1 -1
- package/build/loginout/index.js +11 -1
- package/build/loginout/index.js.map +1 -1
- package/build/navigation/constants.js +13 -0
- package/build/navigation/constants.js.map +1 -0
- package/build/navigation/edit/index.js +16 -26
- package/build/navigation/edit/index.js.map +1 -1
- package/build/navigation/edit/inner-blocks.js +4 -7
- package/build/navigation/edit/inner-blocks.js.map +1 -1
- package/build/navigation/edit/unsaved-inner-blocks.js +4 -6
- package/build/navigation/edit/unsaved-inner-blocks.js.map +1 -1
- package/build/navigation/edit/use-convert-classic-menu-to-block-menu.js +1 -1
- package/build/navigation/edit/use-convert-classic-menu-to-block-menu.js.map +1 -1
- package/build/navigation/interactivity.js +139 -0
- package/build/navigation/interactivity.js.map +1 -0
- package/build/navigation-link/edit.js +1 -1
- package/build/navigation-link/edit.js.map +1 -1
- package/build/navigation-submenu/edit.js +1 -1
- package/build/navigation-submenu/edit.js.map +1 -1
- package/build/paragraph/index.js +5 -1
- package/build/paragraph/index.js.map +1 -1
- package/build/paragraph/transforms.js +5 -1
- package/build/paragraph/transforms.js.map +1 -1
- package/build/post-author-name/edit.js +1 -1
- package/build/post-author-name/edit.js.map +1 -1
- package/build/post-featured-image/edit.js +1 -2
- package/build/post-featured-image/edit.js.map +1 -1
- package/build/post-featured-image/overlay.js +5 -0
- package/build/post-featured-image/overlay.js.map +1 -1
- package/build/post-title/edit.js +14 -4
- package/build/post-title/edit.js.map +1 -1
- package/build/preformatted/edit.native.js +3 -2
- package/build/preformatted/edit.native.js.map +1 -1
- package/build/quote/transforms.js +16 -27
- package/build/quote/transforms.js.map +1 -1
- package/build/read-more/edit.js +1 -1
- package/build/read-more/edit.js.map +1 -1
- package/build/search/edit.js +9 -1
- package/build/search/edit.js.map +1 -1
- package/build/site-title/edit/index.js +1 -1
- package/build/site-title/edit/index.js.map +1 -1
- package/build/social-links/edit.js +2 -2
- package/build/social-links/edit.js.map +1 -1
- package/build/utils/interactivity/constants.js +9 -0
- package/build/utils/interactivity/constants.js.map +1 -0
- package/build/utils/interactivity/directives.js +208 -0
- package/build/utils/interactivity/directives.js.map +1 -0
- package/build/utils/interactivity/hooks.js +112 -0
- package/build/utils/interactivity/hooks.js.map +1 -0
- package/build/utils/interactivity/hydration.js +34 -0
- package/build/utils/interactivity/hydration.js.map +1 -0
- package/build/utils/interactivity/index.js +34 -0
- package/build/utils/interactivity/index.js.map +1 -0
- package/build/utils/interactivity/store.js +67 -0
- package/build/utils/interactivity/store.js.map +1 -0
- package/build/utils/interactivity/utils.js +87 -0
- package/build/utils/interactivity/utils.js.map +1 -0
- package/build/utils/interactivity/vdom.js +109 -0
- package/build/utils/interactivity/vdom.js.map +1 -0
- package/build-module/comment-author-name/edit.js +1 -1
- package/build-module/comment-author-name/edit.js.map +1 -1
- package/build-module/comment-edit-link/edit.js +1 -1
- package/build-module/comment-edit-link/edit.js.map +1 -1
- package/build-module/cover/edit/inspector-controls.js +1 -1
- package/build-module/cover/edit/inspector-controls.js.map +1 -1
- package/build-module/cover/index.js +1 -1
- package/build-module/cover/variations.js +1 -1
- package/build-module/cover/variations.js.map +1 -1
- package/build-module/details/edit.js +20 -6
- package/build-module/details/edit.js.map +1 -1
- package/build-module/details/index.js +14 -10
- package/build-module/details/index.js.map +1 -1
- package/build-module/details/save.js +5 -2
- package/build-module/details/save.js.map +1 -1
- package/build-module/embed/variations.js +2 -2
- package/build-module/embed/variations.js.map +1 -1
- package/build-module/file/view.js +1 -1
- package/build-module/file/view.js.map +1 -1
- package/build-module/gallery/edit.js +2 -8
- package/build-module/gallery/edit.js.map +1 -1
- package/build-module/index.js +0 -4
- package/build-module/index.js.map +1 -1
- package/build-module/index.native.js +1 -1
- package/build-module/index.native.js.map +1 -1
- package/build-module/list-item/utils.js +5 -1
- package/build-module/list-item/utils.js.map +1 -1
- package/build-module/loginout/index.js +11 -1
- package/build-module/loginout/index.js.map +1 -1
- package/build-module/navigation/constants.js +5 -0
- package/build-module/navigation/constants.js.map +1 -0
- package/build-module/navigation/edit/index.js +18 -27
- package/build-module/navigation/edit/index.js.map +1 -1
- package/build-module/navigation/edit/inner-blocks.js +1 -4
- package/build-module/navigation/edit/inner-blocks.js.map +1 -1
- package/build-module/navigation/edit/unsaved-inner-blocks.js +1 -4
- package/build-module/navigation/edit/unsaved-inner-blocks.js.map +1 -1
- package/build-module/navigation/edit/use-convert-classic-menu-to-block-menu.js +1 -1
- package/build-module/navigation/edit/use-convert-classic-menu-to-block-menu.js.map +1 -1
- package/build-module/navigation/interactivity.js +136 -0
- package/build-module/navigation/interactivity.js.map +1 -0
- package/build-module/navigation-link/edit.js +1 -1
- package/build-module/navigation-link/edit.js.map +1 -1
- package/build-module/navigation-submenu/edit.js +1 -1
- package/build-module/navigation-submenu/edit.js.map +1 -1
- package/build-module/paragraph/index.js +5 -1
- package/build-module/paragraph/index.js.map +1 -1
- package/build-module/paragraph/transforms.js +5 -1
- package/build-module/paragraph/transforms.js.map +1 -1
- package/build-module/post-author-name/edit.js +1 -1
- package/build-module/post-author-name/edit.js.map +1 -1
- package/build-module/post-featured-image/edit.js +1 -2
- package/build-module/post-featured-image/edit.js.map +1 -1
- package/build-module/post-featured-image/overlay.js +5 -0
- package/build-module/post-featured-image/overlay.js.map +1 -1
- package/build-module/post-title/edit.js +13 -4
- package/build-module/post-title/edit.js.map +1 -1
- package/build-module/preformatted/edit.native.js +3 -2
- package/build-module/preformatted/edit.native.js.map +1 -1
- package/build-module/quote/transforms.js +16 -27
- package/build-module/quote/transforms.js.map +1 -1
- package/build-module/read-more/edit.js +1 -1
- package/build-module/read-more/edit.js.map +1 -1
- package/build-module/search/edit.js +9 -1
- package/build-module/search/edit.js.map +1 -1
- package/build-module/site-title/edit/index.js +1 -1
- package/build-module/site-title/edit/index.js.map +1 -1
- package/build-module/social-links/edit.js +2 -2
- package/build-module/social-links/edit.js.map +1 -1
- package/build-module/utils/interactivity/constants.js +2 -0
- package/build-module/utils/interactivity/constants.js.map +1 -0
- package/build-module/utils/interactivity/directives.js +193 -0
- package/build-module/utils/interactivity/directives.js.map +1 -0
- package/build-module/utils/interactivity/hooks.js +98 -0
- package/build-module/utils/interactivity/hooks.js.map +1 -0
- package/build-module/utils/interactivity/hydration.js +21 -0
- package/build-module/utils/interactivity/hydration.js.map +1 -0
- package/build-module/utils/interactivity/index.js +17 -0
- package/build-module/utils/interactivity/index.js.map +1 -0
- package/build-module/utils/interactivity/store.js +56 -0
- package/build-module/utils/interactivity/store.js.map +1 -0
- package/build-module/utils/interactivity/utils.js +75 -0
- package/build-module/utils/interactivity/utils.js.map +1 -0
- package/build-module/utils/interactivity/vdom.js +97 -0
- package/build-module/utils/interactivity/vdom.js.map +1 -0
- package/build-style/cover/style-rtl.css +2 -0
- package/build-style/cover/style.css +2 -0
- package/build-style/{details-summary → details}/editor-rtl.css +1 -1
- package/build-style/{details-summary → details}/editor.css +1 -1
- package/build-style/details/style-rtl.css +14 -0
- package/build-style/details/style.css +14 -0
- package/build-style/editor-rtl.css +3 -5
- package/build-style/editor.css +3 -5
- package/build-style/gallery/editor-rtl.css +0 -4
- package/build-style/gallery/editor.css +0 -4
- package/build-style/search/editor-rtl.css +1 -0
- package/build-style/search/editor.css +1 -0
- package/build-style/site-logo/editor-rtl.css +1 -0
- package/build-style/site-logo/editor.css +1 -0
- package/build-style/style-rtl.css +13 -1
- package/build-style/style.css +13 -1
- package/package.json +36 -32
- package/src/comment-author-name/edit.js +1 -1
- package/src/comment-edit-link/edit.js +1 -1
- package/src/comment-template/index.php +8 -7
- package/src/cover/block.json +1 -1
- package/src/cover/edit/inspector-controls.js +56 -54
- package/src/cover/style.scss +5 -0
- package/src/cover/test/edit.js +56 -2
- package/src/cover/variations.js +1 -3
- package/src/details/block.json +8 -6
- package/src/details/edit.js +27 -5
- package/src/details/editor.scss +3 -0
- package/src/details/index.js +10 -5
- package/src/details/save.js +5 -1
- package/src/details/style.scss +16 -0
- package/src/editor.scss +1 -1
- package/src/embed/variations.js +2 -2
- package/src/file/view.js +4 -1
- package/src/gallery/edit.js +5 -8
- package/src/gallery/editor.scss +0 -6
- package/src/gallery/test/index.native.js +48 -3
- package/src/image/test/edit.native.js +38 -16
- package/src/index.js +0 -4
- package/src/index.native.js +1 -0
- package/src/loginout/block.json +11 -1
- package/src/navigation/constants.js +16 -0
- package/src/navigation/edit/index.js +71 -83
- package/src/navigation/edit/inner-blocks.js +1 -16
- package/src/navigation/edit/unsaved-inner-blocks.js +1 -16
- package/src/navigation/edit/use-convert-classic-menu-to-block-menu.js +1 -1
- package/src/navigation/index.php +209 -203
- package/src/navigation/interactivity.js +144 -0
- package/src/navigation-link/edit.js +1 -1
- package/src/navigation-submenu/edit.js +1 -1
- package/src/paragraph/block.json +5 -1
- package/src/post-author-name/edit.js +1 -1
- package/src/post-featured-image/edit.js +1 -1
- package/src/post-featured-image/index.php +1 -1
- package/src/post-featured-image/overlay.js +4 -0
- package/src/post-terms/index.php +2 -2
- package/src/post-title/edit.js +8 -1
- package/src/preformatted/edit.native.js +1 -3
- package/src/quote/transforms.js +0 -6
- package/src/read-more/edit.js +1 -1
- package/src/search/edit.js +9 -4
- package/src/search/editor.scss +1 -0
- package/src/site-logo/editor.scss +2 -1
- package/src/site-title/edit/index.js +1 -1
- package/src/social-links/edit.js +33 -31
- package/src/style.scss +0 -1
- package/src/template-part/index.php +20 -5
- package/src/utils/interactivity/constants.js +1 -0
- package/src/utils/interactivity/directives.js +179 -0
- package/src/utils/interactivity/hooks.js +76 -0
- package/src/utils/interactivity/hydration.js +22 -0
- package/src/utils/interactivity/index.js +17 -0
- package/src/utils/interactivity/store.js +45 -0
- package/src/utils/interactivity/utils.js +66 -0
- package/src/utils/interactivity/vdom.js +94 -0
- package/tsconfig.json +1 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/build/details-content/edit.js +0 -34
- package/build/details-content/edit.js.map +0 -1
- package/build/details-content/index.js +0 -94
- package/build/details-content/index.js.map +0 -1
- package/build/details-content/save.js +0 -20
- package/build/details-content/save.js.map +0 -1
- package/build/details-summary/edit.js +0 -42
- package/build/details-summary/edit.js.map +0 -1
- package/build/details-summary/index.js +0 -97
- package/build/details-summary/index.js.map +0 -1
- package/build/details-summary/save.js +0 -24
- package/build/details-summary/save.js.map +0 -1
- package/build-module/details-content/edit.js +0 -23
- package/build-module/details-content/edit.js.map +0 -1
- package/build-module/details-content/index.js +0 -76
- package/build-module/details-content/index.js.map +0 -1
- package/build-module/details-content/save.js +0 -11
- package/build-module/details-content/save.js.map +0 -1
- package/build-module/details-summary/edit.js +0 -30
- package/build-module/details-summary/edit.js.map +0 -1
- package/build-module/details-summary/index.js +0 -79
- package/build-module/details-summary/index.js.map +0 -1
- package/build-module/details-summary/save.js +0 -16
- package/build-module/details-summary/save.js.map +0 -1
- package/build-style/details-summary/style-rtl.css +0 -91
- package/build-style/details-summary/style.css +0 -91
- package/src/details-content/block.json +0 -50
- package/src/details-content/edit.js +0 -29
- package/src/details-content/index.js +0 -23
- package/src/details-content/save.js +0 -12
- package/src/details-summary/block.json +0 -53
- package/src/details-summary/edit.js +0 -27
- package/src/details-summary/editor.scss +0 -3
- package/src/details-summary/index.js +0 -23
- package/src/details-summary/save.js +0 -13
- package/src/details-summary/style.scss +0 -3
package/src/post-title/edit.js
CHANGED
|
@@ -15,6 +15,7 @@ import {
|
|
|
15
15
|
} from '@wordpress/block-editor';
|
|
16
16
|
import { ToggleControl, TextControl, PanelBody } from '@wordpress/components';
|
|
17
17
|
import { __ } from '@wordpress/i18n';
|
|
18
|
+
import { createBlock, getDefaultBlockName } from '@wordpress/blocks';
|
|
18
19
|
import { useEntityProp } from '@wordpress/core-data';
|
|
19
20
|
|
|
20
21
|
/**
|
|
@@ -27,6 +28,7 @@ export default function PostTitleEdit( {
|
|
|
27
28
|
attributes: { level, textAlign, isLink, rel, linkTarget },
|
|
28
29
|
setAttributes,
|
|
29
30
|
context: { postType, postId, queryId },
|
|
31
|
+
insertBlocksAfter,
|
|
30
32
|
} ) {
|
|
31
33
|
const TagName = 0 === level ? 'p' : 'h' + level;
|
|
32
34
|
const isDescendentOfQueryLoop = Number.isFinite( queryId );
|
|
@@ -38,6 +40,9 @@ export default function PostTitleEdit( {
|
|
|
38
40
|
postId
|
|
39
41
|
);
|
|
40
42
|
const [ link ] = useEntityProp( 'postType', postType, 'link', postId );
|
|
43
|
+
const onSplitAtEnd = () => {
|
|
44
|
+
insertBlocksAfter( createBlock( getDefaultBlockName() ) );
|
|
45
|
+
};
|
|
41
46
|
const blockProps = useBlockProps( {
|
|
42
47
|
className: classnames( {
|
|
43
48
|
[ `has-text-align-${ textAlign }` ]: textAlign,
|
|
@@ -57,6 +62,7 @@ export default function PostTitleEdit( {
|
|
|
57
62
|
value={ rawTitle }
|
|
58
63
|
onChange={ setTitle }
|
|
59
64
|
__experimentalVersion={ 2 }
|
|
65
|
+
__unstableOnSplitAtEnd={ onSplitAtEnd }
|
|
60
66
|
{ ...blockProps }
|
|
61
67
|
/>
|
|
62
68
|
) : (
|
|
@@ -82,6 +88,7 @@ export default function PostTitleEdit( {
|
|
|
82
88
|
value={ rawTitle }
|
|
83
89
|
onChange={ setTitle }
|
|
84
90
|
__experimentalVersion={ 2 }
|
|
91
|
+
__unstableOnSplitAtEnd={ onSplitAtEnd }
|
|
85
92
|
/>
|
|
86
93
|
</TagName>
|
|
87
94
|
) : (
|
|
@@ -116,7 +123,7 @@ export default function PostTitleEdit( {
|
|
|
116
123
|
/>
|
|
117
124
|
</BlockControls>
|
|
118
125
|
<InspectorControls>
|
|
119
|
-
<PanelBody title={ __( '
|
|
126
|
+
<PanelBody title={ __( 'Settings' ) }>
|
|
120
127
|
<ToggleControl
|
|
121
128
|
__nextHasNoMarginBottom
|
|
122
129
|
label={ __( 'Make title a link' ) }
|
|
@@ -28,12 +28,10 @@ export default function PreformattedEdit( props ) {
|
|
|
28
28
|
...( style?.fontSize && { fontSize: style.fontSize } ),
|
|
29
29
|
...( style?.color && { color: style.color } ),
|
|
30
30
|
};
|
|
31
|
-
const hasBaseColors =
|
|
32
|
-
style?.baseColors && Object.entries( style.baseColors ).length !== 0;
|
|
33
31
|
const containerStyles = [
|
|
34
32
|
wpBlockPreformatted,
|
|
35
33
|
style?.backgroundColor && { backgroundColor: style.backgroundColor },
|
|
36
|
-
|
|
34
|
+
style?.baseColors?.color &&
|
|
37
35
|
! style?.backgroundColor &&
|
|
38
36
|
styles[ 'wp-block-preformatted__no-background' ],
|
|
39
37
|
];
|
package/src/quote/transforms.js
CHANGED
package/src/read-more/edit.js
CHANGED
package/src/search/edit.js
CHANGED
|
@@ -115,10 +115,15 @@ export default function SearchEdit( {
|
|
|
115
115
|
|
|
116
116
|
const colorProps = useColorProps( attributes );
|
|
117
117
|
const fluidTypographySettings = useSetting( 'typography.fluid' );
|
|
118
|
-
const
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
118
|
+
const layout = useSetting( 'layout' );
|
|
119
|
+
const typographyProps = useTypographyProps( attributes, {
|
|
120
|
+
typography: {
|
|
121
|
+
fluid: fluidTypographySettings,
|
|
122
|
+
},
|
|
123
|
+
layout: {
|
|
124
|
+
wideSize: layout?.wideSize,
|
|
125
|
+
},
|
|
126
|
+
} );
|
|
122
127
|
const unitControlInstanceId = useInstanceId( UnitControl );
|
|
123
128
|
const unitControlInputId = `wp-block-search__width-${ unitControlInstanceId }`;
|
|
124
129
|
const isButtonPositionInside = 'button-inside' === buttonPosition;
|
package/src/search/editor.scss
CHANGED
|
@@ -109,7 +109,7 @@ export default function SiteTitleEdit( {
|
|
|
109
109
|
/>
|
|
110
110
|
</BlockControls>
|
|
111
111
|
<InspectorControls>
|
|
112
|
-
<PanelBody title={ __( '
|
|
112
|
+
<PanelBody title={ __( 'Settings' ) }>
|
|
113
113
|
<ToggleControl
|
|
114
114
|
__nextHasNoMarginBottom
|
|
115
115
|
label={ __( 'Make title link to home' ) }
|
package/src/social-links/edit.js
CHANGED
|
@@ -195,7 +195,7 @@ export function SocialLinksEdit( props ) {
|
|
|
195
195
|
</ToolbarDropdownMenu>
|
|
196
196
|
</BlockControls>
|
|
197
197
|
<InspectorControls>
|
|
198
|
-
<PanelBody title={ __( '
|
|
198
|
+
<PanelBody title={ __( 'Settings' ) }>
|
|
199
199
|
<ToggleControl
|
|
200
200
|
__nextHasNoMarginBottom
|
|
201
201
|
label={ __( 'Open links in new tab' ) }
|
|
@@ -214,37 +214,39 @@ export function SocialLinksEdit( props ) {
|
|
|
214
214
|
/>
|
|
215
215
|
</PanelBody>
|
|
216
216
|
</InspectorControls>
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
{
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
217
|
+
{ colorGradientSettings.hasColorsOrGradients && (
|
|
218
|
+
<InspectorControls group="color">
|
|
219
|
+
{ colorSettings.map(
|
|
220
|
+
( { onChange, label, value, resetAllFilter } ) => (
|
|
221
|
+
<ColorGradientSettingsDropdown
|
|
222
|
+
key={ `social-links-color-${ label }` }
|
|
223
|
+
__experimentalIsRenderedInSidebar
|
|
224
|
+
settings={ [
|
|
225
|
+
{
|
|
226
|
+
colorValue: value,
|
|
227
|
+
label,
|
|
228
|
+
onColorChange: onChange,
|
|
229
|
+
isShownByDefault: true,
|
|
230
|
+
resetAllFilter,
|
|
231
|
+
enableAlpha: true,
|
|
232
|
+
},
|
|
233
|
+
] }
|
|
234
|
+
panelId={ clientId }
|
|
235
|
+
{ ...colorGradientSettings }
|
|
236
|
+
/>
|
|
237
|
+
)
|
|
238
|
+
) }
|
|
239
|
+
{ ! logosOnly && (
|
|
240
|
+
<ContrastChecker
|
|
241
|
+
{ ...{
|
|
242
|
+
textColor: iconColorValue,
|
|
243
|
+
backgroundColor: iconBackgroundColorValue,
|
|
244
|
+
} }
|
|
245
|
+
isLargeText={ false }
|
|
235
246
|
/>
|
|
236
|
-
)
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
<ContrastChecker
|
|
240
|
-
{ ...{
|
|
241
|
-
textColor: iconColorValue,
|
|
242
|
-
backgroundColor: iconBackgroundColorValue,
|
|
243
|
-
} }
|
|
244
|
-
isLargeText={ false }
|
|
245
|
-
/>
|
|
246
|
-
) }
|
|
247
|
-
</InspectorControls>
|
|
247
|
+
) }
|
|
248
|
+
</InspectorControls>
|
|
249
|
+
) }
|
|
248
250
|
<ul { ...innerBlocksProps } />
|
|
249
251
|
</>
|
|
250
252
|
);
|
package/src/style.scss
CHANGED
|
@@ -173,21 +173,34 @@ function render_block_core_template_part( $attributes ) {
|
|
|
173
173
|
/**
|
|
174
174
|
* Returns an array of area variation objects for the template part block.
|
|
175
175
|
*
|
|
176
|
+
* @param array $instance_variations The variations for instances.
|
|
177
|
+
*
|
|
176
178
|
* @return array Array containing the block variation objects.
|
|
177
179
|
*/
|
|
178
|
-
function build_template_part_block_area_variations() {
|
|
180
|
+
function build_template_part_block_area_variations( $instance_variations ) {
|
|
179
181
|
$variations = array();
|
|
180
182
|
$defined_areas = get_allowed_block_template_part_areas();
|
|
183
|
+
|
|
181
184
|
foreach ( $defined_areas as $area ) {
|
|
182
185
|
if ( 'uncategorized' !== $area['area'] ) {
|
|
186
|
+
$has_instance_for_area = false;
|
|
187
|
+
foreach ( $instance_variations as $variation ) {
|
|
188
|
+
if ( $variation['attributes']['area'] === $area['area'] ) {
|
|
189
|
+
$has_instance_for_area = true;
|
|
190
|
+
break;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
$scope = $has_instance_for_area ? array() : array( 'inserter' );
|
|
195
|
+
|
|
183
196
|
$variations[] = array(
|
|
184
|
-
'name' => $area['area'],
|
|
197
|
+
'name' => 'area_' . $area['area'],
|
|
185
198
|
'title' => $area['label'],
|
|
186
199
|
'description' => $area['description'],
|
|
187
200
|
'attributes' => array(
|
|
188
201
|
'area' => $area['area'],
|
|
189
202
|
),
|
|
190
|
-
'scope' =>
|
|
203
|
+
'scope' => $scope,
|
|
191
204
|
'icon' => $area['icon'],
|
|
192
205
|
);
|
|
193
206
|
}
|
|
@@ -223,7 +236,7 @@ function build_template_part_block_instance_variations() {
|
|
|
223
236
|
|
|
224
237
|
foreach ( $template_parts as $template_part ) {
|
|
225
238
|
$variations[] = array(
|
|
226
|
-
'name' => sanitize_title( $template_part->slug ),
|
|
239
|
+
'name' => 'instance_' . sanitize_title( $template_part->slug ),
|
|
227
240
|
'title' => $template_part->title,
|
|
228
241
|
// If there's no description for the template part don't show the
|
|
229
242
|
// block description. This is a bit hacky, but prevent the fallback
|
|
@@ -255,7 +268,9 @@ function build_template_part_block_instance_variations() {
|
|
|
255
268
|
* @return array Array containing the block variation objects.
|
|
256
269
|
*/
|
|
257
270
|
function build_template_part_block_variations() {
|
|
258
|
-
|
|
271
|
+
$instance_variations = build_template_part_block_instance_variations();
|
|
272
|
+
$area_variations = build_template_part_block_area_variations( $instance_variations );
|
|
273
|
+
return array_merge( $area_variations, $instance_variations );
|
|
259
274
|
}
|
|
260
275
|
|
|
261
276
|
/**
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const directivePrefix = 'data-wp-';
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { useContext, useMemo, useEffect } from 'preact/hooks';
|
|
5
|
+
import { deepSignal, peek } from 'deepsignal';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Internal dependencies
|
|
9
|
+
*/
|
|
10
|
+
import { useSignalEffect } from './utils';
|
|
11
|
+
import { directive } from './hooks';
|
|
12
|
+
|
|
13
|
+
const isObject = ( item ) =>
|
|
14
|
+
item && typeof item === 'object' && ! Array.isArray( item );
|
|
15
|
+
|
|
16
|
+
const mergeDeepSignals = ( target, source ) => {
|
|
17
|
+
for ( const k in source ) {
|
|
18
|
+
if ( typeof peek( target, k ) === 'undefined' ) {
|
|
19
|
+
target[ `$${ k }` ] = source[ `$${ k }` ];
|
|
20
|
+
} else if (
|
|
21
|
+
isObject( peek( target, k ) ) &&
|
|
22
|
+
isObject( peek( source, k ) )
|
|
23
|
+
) {
|
|
24
|
+
mergeDeepSignals(
|
|
25
|
+
target[ `$${ k }` ].peek(),
|
|
26
|
+
source[ `$${ k }` ].peek()
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export default () => {
|
|
33
|
+
// data-wp-context
|
|
34
|
+
directive(
|
|
35
|
+
'context',
|
|
36
|
+
( {
|
|
37
|
+
directives: {
|
|
38
|
+
context: { default: context },
|
|
39
|
+
},
|
|
40
|
+
props: { children },
|
|
41
|
+
context: inherited,
|
|
42
|
+
} ) => {
|
|
43
|
+
const { Provider } = inherited;
|
|
44
|
+
const inheritedValue = useContext( inherited );
|
|
45
|
+
const value = useMemo( () => {
|
|
46
|
+
const localValue = deepSignal( context );
|
|
47
|
+
mergeDeepSignals( localValue, inheritedValue );
|
|
48
|
+
return localValue;
|
|
49
|
+
}, [ context, inheritedValue ] );
|
|
50
|
+
|
|
51
|
+
return <Provider value={ value }>{ children }</Provider>;
|
|
52
|
+
}
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
// data-wp-effect.[name]
|
|
56
|
+
directive( 'effect', ( { directives: { effect }, context, evaluate } ) => {
|
|
57
|
+
const contextValue = useContext( context );
|
|
58
|
+
Object.values( effect ).forEach( ( path ) => {
|
|
59
|
+
useSignalEffect( () => {
|
|
60
|
+
return evaluate( path, { context: contextValue } );
|
|
61
|
+
} );
|
|
62
|
+
} );
|
|
63
|
+
} );
|
|
64
|
+
|
|
65
|
+
// data-wp-init.[name]
|
|
66
|
+
directive( 'init', ( { directives: { init }, context, evaluate } ) => {
|
|
67
|
+
const contextValue = useContext( context );
|
|
68
|
+
Object.values( init ).forEach( ( path ) => {
|
|
69
|
+
useEffect( () => {
|
|
70
|
+
return evaluate( path, { context: contextValue } );
|
|
71
|
+
}, [] );
|
|
72
|
+
} );
|
|
73
|
+
} );
|
|
74
|
+
|
|
75
|
+
// data-wp-on.[event]
|
|
76
|
+
directive( 'on', ( { directives: { on }, element, evaluate, context } ) => {
|
|
77
|
+
const contextValue = useContext( context );
|
|
78
|
+
Object.entries( on ).forEach( ( [ name, path ] ) => {
|
|
79
|
+
element.props[ `on${ name }` ] = ( event ) => {
|
|
80
|
+
evaluate( path, { event, context: contextValue } );
|
|
81
|
+
};
|
|
82
|
+
} );
|
|
83
|
+
} );
|
|
84
|
+
|
|
85
|
+
// data-wp-class.[classname]
|
|
86
|
+
directive(
|
|
87
|
+
'class',
|
|
88
|
+
( {
|
|
89
|
+
directives: { class: className },
|
|
90
|
+
element,
|
|
91
|
+
evaluate,
|
|
92
|
+
context,
|
|
93
|
+
} ) => {
|
|
94
|
+
const contextValue = useContext( context );
|
|
95
|
+
Object.keys( className )
|
|
96
|
+
.filter( ( n ) => n !== 'default' )
|
|
97
|
+
.forEach( ( name ) => {
|
|
98
|
+
const result = evaluate( className[ name ], {
|
|
99
|
+
className: name,
|
|
100
|
+
context: contextValue,
|
|
101
|
+
} );
|
|
102
|
+
const currentClass = element.props.class || '';
|
|
103
|
+
const classFinder = new RegExp(
|
|
104
|
+
`(^|\\s)${ name }(\\s|$)`,
|
|
105
|
+
'g'
|
|
106
|
+
);
|
|
107
|
+
if ( ! result )
|
|
108
|
+
element.props.class = currentClass
|
|
109
|
+
.replace( classFinder, ' ' )
|
|
110
|
+
.trim();
|
|
111
|
+
else if ( ! classFinder.test( currentClass ) )
|
|
112
|
+
element.props.class = currentClass
|
|
113
|
+
? `${ currentClass } ${ name }`
|
|
114
|
+
: name;
|
|
115
|
+
|
|
116
|
+
useEffect( () => {
|
|
117
|
+
// This seems necessary because Preact doesn't change the class
|
|
118
|
+
// names on the hydration, so we have to do it manually. It doesn't
|
|
119
|
+
// need deps because it only needs to do it the first time.
|
|
120
|
+
if ( ! result ) {
|
|
121
|
+
element.ref.current.classList.remove( name );
|
|
122
|
+
} else {
|
|
123
|
+
element.ref.current.classList.add( name );
|
|
124
|
+
}
|
|
125
|
+
}, [] );
|
|
126
|
+
} );
|
|
127
|
+
}
|
|
128
|
+
);
|
|
129
|
+
|
|
130
|
+
// data-wp-bind.[attribute]
|
|
131
|
+
directive(
|
|
132
|
+
'bind',
|
|
133
|
+
( { directives: { bind }, element, context, evaluate } ) => {
|
|
134
|
+
const contextValue = useContext( context );
|
|
135
|
+
Object.entries( bind )
|
|
136
|
+
.filter( ( n ) => n !== 'default' )
|
|
137
|
+
.forEach( ( [ attribute, path ] ) => {
|
|
138
|
+
const result = evaluate( path, {
|
|
139
|
+
context: contextValue,
|
|
140
|
+
} );
|
|
141
|
+
element.props[ attribute ] = result;
|
|
142
|
+
|
|
143
|
+
useEffect( () => {
|
|
144
|
+
// This seems necessary because Preact doesn't change the attributes
|
|
145
|
+
// on the hydration, so we have to do it manually. It doesn't need
|
|
146
|
+
// deps because it only needs to do it the first time.
|
|
147
|
+
if ( result === false ) {
|
|
148
|
+
element.ref.current.removeAttribute( attribute );
|
|
149
|
+
} else {
|
|
150
|
+
element.ref.current.setAttribute(
|
|
151
|
+
attribute,
|
|
152
|
+
result === true ? '' : result
|
|
153
|
+
);
|
|
154
|
+
}
|
|
155
|
+
}, [] );
|
|
156
|
+
} );
|
|
157
|
+
}
|
|
158
|
+
);
|
|
159
|
+
|
|
160
|
+
// data-wp-ignore
|
|
161
|
+
directive(
|
|
162
|
+
'ignore',
|
|
163
|
+
( {
|
|
164
|
+
element: {
|
|
165
|
+
type: Type,
|
|
166
|
+
props: { innerHTML, ...rest },
|
|
167
|
+
},
|
|
168
|
+
} ) => {
|
|
169
|
+
// Preserve the initial inner HTML.
|
|
170
|
+
const cached = useMemo( () => innerHTML, [] );
|
|
171
|
+
return (
|
|
172
|
+
<Type
|
|
173
|
+
dangerouslySetInnerHTML={ { __html: cached } }
|
|
174
|
+
{ ...rest }
|
|
175
|
+
/>
|
|
176
|
+
);
|
|
177
|
+
}
|
|
178
|
+
);
|
|
179
|
+
};
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { h, options, createContext } from 'preact';
|
|
5
|
+
import { useRef, useMemo } from 'preact/hooks';
|
|
6
|
+
/**
|
|
7
|
+
* Internal dependencies
|
|
8
|
+
*/
|
|
9
|
+
import { rawStore as store } from './store';
|
|
10
|
+
|
|
11
|
+
// Main context.
|
|
12
|
+
const context = createContext( {} );
|
|
13
|
+
|
|
14
|
+
// WordPress Directives.
|
|
15
|
+
const directiveMap = {};
|
|
16
|
+
export const directive = ( name, cb ) => {
|
|
17
|
+
directiveMap[ name ] = cb;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
// Resolve the path to some property of the store object.
|
|
21
|
+
const resolve = ( path, ctx ) => {
|
|
22
|
+
// If path starts with !, remove it and save a flag.
|
|
23
|
+
const hasNegationOperator =
|
|
24
|
+
path[ 0 ] === '!' && !! ( path = path.slice( 1 ) );
|
|
25
|
+
let current = { ...store, context: ctx };
|
|
26
|
+
path.split( '.' ).forEach( ( p ) => ( current = current[ p ] ) );
|
|
27
|
+
return hasNegationOperator ? ! current : current;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
// Generate the evaluate function.
|
|
31
|
+
const getEvaluate =
|
|
32
|
+
( { ref } = {} ) =>
|
|
33
|
+
( path, extraArgs = {} ) => {
|
|
34
|
+
const value = resolve( path, extraArgs.context );
|
|
35
|
+
return typeof value === 'function'
|
|
36
|
+
? value( {
|
|
37
|
+
ref: ref.current,
|
|
38
|
+
...store,
|
|
39
|
+
...extraArgs,
|
|
40
|
+
} )
|
|
41
|
+
: value;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
// Directive wrapper.
|
|
45
|
+
const Directive = ( { type, directives, props: originalProps } ) => {
|
|
46
|
+
const ref = useRef( null );
|
|
47
|
+
const element = h( type, { ...originalProps, ref } );
|
|
48
|
+
const props = { ...originalProps, children: element };
|
|
49
|
+
const evaluate = useMemo( () => getEvaluate( { ref } ), [] );
|
|
50
|
+
const directiveArgs = { directives, props, element, context, evaluate };
|
|
51
|
+
|
|
52
|
+
for ( const d in directives ) {
|
|
53
|
+
const wrapper = directiveMap[ d ]?.( directiveArgs );
|
|
54
|
+
if ( wrapper !== undefined ) props.children = wrapper;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return props.children;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
// Preact Options Hook called each time a vnode is created.
|
|
61
|
+
const old = options.vnode;
|
|
62
|
+
options.vnode = ( vnode ) => {
|
|
63
|
+
if ( vnode.props.__directives ) {
|
|
64
|
+
const props = vnode.props;
|
|
65
|
+
const directives = props.__directives;
|
|
66
|
+
delete props.__directives;
|
|
67
|
+
vnode.props = {
|
|
68
|
+
type: vnode.type,
|
|
69
|
+
directives,
|
|
70
|
+
props,
|
|
71
|
+
};
|
|
72
|
+
vnode.type = Directive;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if ( old ) old( vnode );
|
|
76
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { hydrate } from 'preact';
|
|
5
|
+
/**
|
|
6
|
+
* Internal dependencies
|
|
7
|
+
*/
|
|
8
|
+
import { toVdom, hydratedIslands } from './vdom';
|
|
9
|
+
import { createRootFragment } from './utils';
|
|
10
|
+
import { directivePrefix } from './constants';
|
|
11
|
+
|
|
12
|
+
export const init = async () => {
|
|
13
|
+
document
|
|
14
|
+
.querySelectorAll( `[${ directivePrefix }island]` )
|
|
15
|
+
.forEach( ( node ) => {
|
|
16
|
+
if ( ! hydratedIslands.has( node ) ) {
|
|
17
|
+
const fragment = createRootFragment( node.parentNode, node );
|
|
18
|
+
const vdom = toVdom( node );
|
|
19
|
+
hydrate( vdom, fragment );
|
|
20
|
+
}
|
|
21
|
+
} );
|
|
22
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Internal dependencies
|
|
3
|
+
*/
|
|
4
|
+
import registerDirectives from './directives';
|
|
5
|
+
import { init } from './hydration';
|
|
6
|
+
export { store } from './store';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Initialize the Interactivity API.
|
|
10
|
+
*/
|
|
11
|
+
registerDirectives();
|
|
12
|
+
|
|
13
|
+
document.addEventListener( 'DOMContentLoaded', async () => {
|
|
14
|
+
await init();
|
|
15
|
+
// eslint-disable-next-line no-console
|
|
16
|
+
console.log( 'Interactivity API started' );
|
|
17
|
+
} );
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { deepSignal } from 'deepsignal';
|
|
5
|
+
|
|
6
|
+
const isObject = ( item ) =>
|
|
7
|
+
item && typeof item === 'object' && ! Array.isArray( item );
|
|
8
|
+
|
|
9
|
+
const deepMerge = ( target, source ) => {
|
|
10
|
+
if ( isObject( target ) && isObject( source ) ) {
|
|
11
|
+
for ( const key in source ) {
|
|
12
|
+
if ( isObject( source[ key ] ) ) {
|
|
13
|
+
if ( ! target[ key ] ) Object.assign( target, { [ key ]: {} } );
|
|
14
|
+
deepMerge( target[ key ], source[ key ] );
|
|
15
|
+
} else {
|
|
16
|
+
Object.assign( target, { [ key ]: source[ key ] } );
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const getSerializedState = () => {
|
|
23
|
+
// TODO: change the store tag ID for a better one.
|
|
24
|
+
const storeTag = document.querySelector(
|
|
25
|
+
`script[type="application/json"]#store`
|
|
26
|
+
);
|
|
27
|
+
if ( ! storeTag ) return {};
|
|
28
|
+
try {
|
|
29
|
+
const { state } = JSON.parse( storeTag.textContent );
|
|
30
|
+
if ( isObject( state ) ) return state;
|
|
31
|
+
throw Error( 'Parsed state is not an object' );
|
|
32
|
+
} catch ( e ) {
|
|
33
|
+
// eslint-disable-next-line no-console
|
|
34
|
+
console.log( e );
|
|
35
|
+
}
|
|
36
|
+
return {};
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const rawState = getSerializedState();
|
|
40
|
+
export const rawStore = { state: deepSignal( rawState ) };
|
|
41
|
+
|
|
42
|
+
export const store = ( { state, ...block } ) => {
|
|
43
|
+
deepMerge( rawStore, block );
|
|
44
|
+
deepMerge( rawState, state );
|
|
45
|
+
};
|