@wordpress/create-block-tutorial-template 2.2.0 → 2.4.1-next.d6164808d3.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 +10 -0
- package/block-templates/edit.js.mustache +8 -7
- package/block-templates/index.js.mustache +6 -1
- package/block-templates/save.js.mustache +4 -2
- package/block-templates/style.scss.mustache +1 -1
- package/block-templates/template.php.mustache +5 -0
- package/index.js +10 -0
- package/package.json +2 -2
- package/plugin-templates/$slug.php.mustache +29 -1
- package/plugin-templates/readme.txt.mustache +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,16 @@
|
|
|
2
2
|
|
|
3
3
|
## Unreleased
|
|
4
4
|
|
|
5
|
+
## 2.3.0 (2022-06-01)
|
|
6
|
+
|
|
7
|
+
### Enhancement
|
|
8
|
+
|
|
9
|
+
- Read the block name from `block.json` file in JavaScript files ([#41273](https://github.com/WordPress/gutenberg/pull/41273)).
|
|
10
|
+
|
|
11
|
+
### Bug Fix
|
|
12
|
+
|
|
13
|
+
- Fix the issue with the block wrapper in the editor ([#41273](https://github.com/WordPress/gutenberg/pull/41273)).
|
|
14
|
+
|
|
5
15
|
## 2.1.0 (2022-04-21)
|
|
6
16
|
|
|
7
17
|
### Bug Fix
|
|
@@ -9,7 +9,7 @@ import { TextControl } from '@wordpress/components';
|
|
|
9
9
|
* React hook that is used to mark the block wrapper element.
|
|
10
10
|
* It provides all the necessary props like the class name.
|
|
11
11
|
*
|
|
12
|
-
* @see https://developer.wordpress.org/block-editor/packages/packages-block-editor/#
|
|
12
|
+
* @see https://developer.wordpress.org/block-editor/reference-guides/packages/packages-block-editor/#useblockprops
|
|
13
13
|
*/
|
|
14
14
|
import { useBlockProps } from '@wordpress/block-editor';
|
|
15
15
|
|
|
@@ -17,7 +17,7 @@ import { useBlockProps } from '@wordpress/block-editor';
|
|
|
17
17
|
* The edit function describes the structure of your block in the context of the
|
|
18
18
|
* editor. This represents what the editor will render when the block is used.
|
|
19
19
|
*
|
|
20
|
-
* @see https://developer.wordpress.org/block-editor/
|
|
20
|
+
* @see https://developer.wordpress.org/block-editor/reference-guides/block-api/block-edit-save/#edit
|
|
21
21
|
*
|
|
22
22
|
* @param {Object} props Properties passed to the function.
|
|
23
23
|
* @param {Object} props.attributes Available block attributes.
|
|
@@ -28,10 +28,11 @@ import { useBlockProps } from '@wordpress/block-editor';
|
|
|
28
28
|
export default function Edit( { attributes, setAttributes } ) {
|
|
29
29
|
const blockProps = useBlockProps();
|
|
30
30
|
return (
|
|
31
|
-
<
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
31
|
+
<div { ...blockProps }>
|
|
32
|
+
<TextControl
|
|
33
|
+
value={ attributes.message }
|
|
34
|
+
onChange={ ( val ) => setAttributes( { message: val } ) }
|
|
35
|
+
/>
|
|
36
|
+
</div>
|
|
36
37
|
);
|
|
37
38
|
}
|
|
@@ -20,14 +20,17 @@ import './editor.scss';
|
|
|
20
20
|
* Internal dependencies
|
|
21
21
|
*/
|
|
22
22
|
import Edit from './edit';
|
|
23
|
+
{{#isStaticVariant}}
|
|
23
24
|
import save from './save';
|
|
25
|
+
{{/isStaticVariant}}
|
|
26
|
+
import metadata from './block.json';
|
|
24
27
|
|
|
25
28
|
/**
|
|
26
29
|
* Every block starts by registering a new block type definition.
|
|
27
30
|
*
|
|
28
31
|
* @see https://developer.wordpress.org/block-editor/developers/block-api/#registering-a-block
|
|
29
32
|
*/
|
|
30
|
-
registerBlockType(
|
|
33
|
+
registerBlockType( metadata.name, {
|
|
31
34
|
/**
|
|
32
35
|
* Used to construct a preview for the block to be shown in the block inserter.
|
|
33
36
|
*/
|
|
@@ -40,8 +43,10 @@ registerBlockType( '{{namespace}}/{{slug}}', {
|
|
|
40
43
|
* @see ./edit.js
|
|
41
44
|
*/
|
|
42
45
|
edit: Edit,
|
|
46
|
+
{{#isStaticVariant}}
|
|
43
47
|
/**
|
|
44
48
|
* @see ./save.js
|
|
45
49
|
*/
|
|
46
50
|
save,
|
|
51
|
+
{{/isStaticVariant}}
|
|
47
52
|
} );
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
{{#isStaticVariant}}
|
|
1
2
|
/**
|
|
2
3
|
* React hook that is used to mark the block wrapper element.
|
|
3
4
|
* It provides all the necessary props like the class name.
|
|
4
5
|
*
|
|
5
|
-
* @see https://developer.wordpress.org/block-editor/packages/packages-block-editor/#
|
|
6
|
+
* @see https://developer.wordpress.org/block-editor/reference-guides/packages/packages-block-editor/#useblockprops
|
|
6
7
|
*/
|
|
7
8
|
import { useBlockProps } from '@wordpress/block-editor';
|
|
8
9
|
|
|
@@ -11,7 +12,7 @@ import { useBlockProps } from '@wordpress/block-editor';
|
|
|
11
12
|
* be combined into the final markup, which is then serialized by the block
|
|
12
13
|
* editor into `post_content`.
|
|
13
14
|
*
|
|
14
|
-
* @see https://developer.wordpress.org/block-editor/
|
|
15
|
+
* @see https://developer.wordpress.org/block-editor/reference-guides/block-api/block-edit-save/#save
|
|
15
16
|
*
|
|
16
17
|
* @param {Object} props Properties passed to the function.
|
|
17
18
|
* @param {Object} props.attributes Available block attributes.
|
|
@@ -21,3 +22,4 @@ export default function save( { attributes } ) {
|
|
|
21
22
|
const blockProps = useBlockProps.save();
|
|
22
23
|
return <div { ...blockProps }>{ attributes.message }</div>;
|
|
23
24
|
}
|
|
25
|
+
{{/isStaticVariant}}
|
package/index.js
CHANGED
|
@@ -22,6 +22,16 @@ module.exports = {
|
|
|
22
22
|
html: false,
|
|
23
23
|
},
|
|
24
24
|
},
|
|
25
|
+
variants: {
|
|
26
|
+
static: {},
|
|
27
|
+
dynamic: {
|
|
28
|
+
attributes: {
|
|
29
|
+
message: {
|
|
30
|
+
type: 'string',
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
},
|
|
25
35
|
pluginTemplatesPath: join( __dirname, 'plugin-templates' ),
|
|
26
36
|
blockTemplatesPath: join( __dirname, 'block-templates' ),
|
|
27
37
|
assetsPath: join( __dirname, 'assets' ),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/create-block-tutorial-template",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.4.1-next.d6164808d3.0",
|
|
4
4
|
"description": "Template for @wordpress/create-block used in the official WordPress tutorial.",
|
|
5
5
|
"author": "The WordPress Contributors",
|
|
6
6
|
"license": "GPL-2.0-or-later",
|
|
@@ -21,5 +21,5 @@
|
|
|
21
21
|
"publishConfig": {
|
|
22
22
|
"access": "public"
|
|
23
23
|
},
|
|
24
|
-
"gitHead": "
|
|
24
|
+
"gitHead": "ba8a396d2f418e53a6c4c50575582f3f3eb11ff7"
|
|
25
25
|
}
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* Description: {{description}}
|
|
9
9
|
{{/description}}
|
|
10
10
|
* Version: {{version}}
|
|
11
|
-
* Requires at least: 5.
|
|
11
|
+
* Requires at least: 5.9
|
|
12
12
|
* Requires PHP: 7.0
|
|
13
13
|
{{#author}}
|
|
14
14
|
* Author: {{author}}
|
|
@@ -37,7 +37,35 @@
|
|
|
37
37
|
*
|
|
38
38
|
* @see https://developer.wordpress.org/reference/functions/register_block_type/
|
|
39
39
|
*/
|
|
40
|
+
{{#isStaticVariant}}
|
|
40
41
|
function {{namespaceSnakeCase}}_{{slugSnakeCase}}_block_init() {
|
|
41
42
|
register_block_type( __DIR__ . '/build' );
|
|
42
43
|
}
|
|
43
44
|
add_action( 'init', '{{namespaceSnakeCase}}_{{slugSnakeCase}}_block_init' );
|
|
45
|
+
{{/isStaticVariant}}
|
|
46
|
+
{{#isDynamicVariant}}
|
|
47
|
+
function {{namespaceSnakeCase}}_{{slugSnakeCase}}_block_init() {
|
|
48
|
+
register_block_type(
|
|
49
|
+
__DIR__ . '/build',
|
|
50
|
+
array(
|
|
51
|
+
'render_callback' => '{{namespaceSnakeCase}}_{{slugSnakeCase}}_render_callback',
|
|
52
|
+
)
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
add_action( 'init', '{{namespaceSnakeCase}}_{{slugSnakeCase}}_block_init' );
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Render callback function
|
|
59
|
+
*
|
|
60
|
+
* @param array $attributes The block attributes.
|
|
61
|
+
* @param string $content The block content.
|
|
62
|
+
* @param WP_Block $block Block instance.
|
|
63
|
+
*
|
|
64
|
+
* @return string The rendered output.
|
|
65
|
+
*/
|
|
66
|
+
function {{namespaceSnakeCase}}_{{slugSnakeCase}}_render_callback( $atts, $content, $block) {
|
|
67
|
+
ob_start();
|
|
68
|
+
require plugin_dir_path( __FILE__ ) . 'build/template.php';
|
|
69
|
+
return ob_get_clean();
|
|
70
|
+
}
|
|
71
|
+
{{/isDynamicVariant}}
|