@wordpress/create-block-tutorial-template 2.3.0 → 2.5.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 +6 -0
- package/block-templates/edit.js.mustache +2 -2
- package/block-templates/index.js.mustache +5 -0
- package/block-templates/save.js.mustache +4 -2
- package/block-templates/template.php.mustache +5 -0
- package/index.js +10 -0
- package/package.json +2 -2
- package/plugin-templates/$slug.php.mustache +27 -0
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
## Unreleased
|
|
4
4
|
|
|
5
|
+
## 2.5.0 (2022-08-24)
|
|
6
|
+
|
|
7
|
+
### Enhancement
|
|
8
|
+
|
|
9
|
+
- Add support to the `dynamic` variant ([#41289](https://github.com/WordPress/gutenberg/pull/41289), [#43481](https://github.com/WordPress/gutenberg/pull/43481)).
|
|
10
|
+
|
|
5
11
|
## 2.3.0 (2022-06-01)
|
|
6
12
|
|
|
7
13
|
### Enhancement
|
|
@@ -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.
|
|
@@ -20,7 +20,9 @@ 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}}
|
|
24
26
|
import metadata from './block.json';
|
|
25
27
|
|
|
26
28
|
/**
|
|
@@ -41,8 +43,11 @@ registerBlockType( metadata.name, {
|
|
|
41
43
|
* @see ./edit.js
|
|
42
44
|
*/
|
|
43
45
|
edit: Edit,
|
|
46
|
+
{{#isStaticVariant}}
|
|
47
|
+
|
|
44
48
|
/**
|
|
45
49
|
* @see ./save.js
|
|
46
50
|
*/
|
|
47
51
|
save,
|
|
52
|
+
{{/isStaticVariant}}
|
|
48
53
|
} );
|
|
@@ -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.5.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": "171b87c7465b93e685e081c5f57f153507363c95"
|
|
25
25
|
}
|
|
@@ -38,6 +38,33 @@
|
|
|
38
38
|
* @see https://developer.wordpress.org/reference/functions/register_block_type/
|
|
39
39
|
*/
|
|
40
40
|
function {{namespaceSnakeCase}}_{{slugSnakeCase}}_block_init() {
|
|
41
|
+
{{#isStaticVariant}}
|
|
41
42
|
register_block_type( __DIR__ . '/build' );
|
|
43
|
+
{{/isStaticVariant}}
|
|
44
|
+
{{#isDynamicVariant}}
|
|
45
|
+
register_block_type(
|
|
46
|
+
__DIR__ . '/build',
|
|
47
|
+
array(
|
|
48
|
+
'render_callback' => '{{namespaceSnakeCase}}_{{slugSnakeCase}}_render_callback',
|
|
49
|
+
)
|
|
50
|
+
);
|
|
51
|
+
{{/isDynamicVariant}}
|
|
42
52
|
}
|
|
43
53
|
add_action( 'init', '{{namespaceSnakeCase}}_{{slugSnakeCase}}_block_init' );
|
|
54
|
+
{{#isDynamicVariant}}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Render callback function.
|
|
58
|
+
*
|
|
59
|
+
* @param array $attributes The block attributes.
|
|
60
|
+
* @param string $content The block content.
|
|
61
|
+
* @param WP_Block $block Block instance.
|
|
62
|
+
*
|
|
63
|
+
* @return string The rendered output.
|
|
64
|
+
*/
|
|
65
|
+
function {{namespaceSnakeCase}}_{{slugSnakeCase}}_render_callback( $atts, $content, $block ) {
|
|
66
|
+
ob_start();
|
|
67
|
+
require plugin_dir_path( __FILE__ ) . 'build/template.php';
|
|
68
|
+
return ob_get_clean();
|
|
69
|
+
}
|
|
70
|
+
{{/isDynamicVariant}}
|