@wordpress/create-block 4.3.0 → 4.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/lib/init-block.js +4 -0
- package/lib/init-package-json.js +2 -0
- package/lib/scaffold.js +6 -0
- package/lib/templates/block/{template.php.mustache → render.php.mustache} +1 -1
- package/lib/templates/es5/$slug.php.mustache +2 -22
- package/lib/templates/es5/index.js.mustache +0 -47
- package/lib/templates/es5/readme.txt.mustache +1 -1
- package/lib/templates/es5/{template.php.mustache → render.php.mustache} +1 -1
- package/lib/templates/plugin/$slug.php.mustache +1 -28
- package/lib/templates/plugin/readme.txt.mustache +1 -1
- package/lib/templates.js +8 -3
- package/package.json +3 -3
package/lib/init-block.js
CHANGED
|
@@ -29,6 +29,8 @@ async function initBlockJSON( {
|
|
|
29
29
|
editorScript,
|
|
30
30
|
editorStyle,
|
|
31
31
|
style,
|
|
32
|
+
render,
|
|
33
|
+
customBlockJSON,
|
|
32
34
|
} ) {
|
|
33
35
|
info( '' );
|
|
34
36
|
info( 'Creating a "block.json" file.' );
|
|
@@ -56,6 +58,8 @@ async function initBlockJSON( {
|
|
|
56
58
|
editorScript,
|
|
57
59
|
editorStyle,
|
|
58
60
|
style,
|
|
61
|
+
render,
|
|
62
|
+
...customBlockJSON,
|
|
59
63
|
} ).filter( ( [ , value ] ) => !! value )
|
|
60
64
|
),
|
|
61
65
|
null,
|
package/lib/init-package-json.js
CHANGED
|
@@ -24,6 +24,7 @@ module.exports = async ( {
|
|
|
24
24
|
npmDevDependencies,
|
|
25
25
|
customScripts,
|
|
26
26
|
isDynamicVariant,
|
|
27
|
+
customPackageJSON,
|
|
27
28
|
} ) => {
|
|
28
29
|
const cwd = join( process.cwd(), slug );
|
|
29
30
|
|
|
@@ -58,6 +59,7 @@ module.exports = async ( {
|
|
|
58
59
|
...( wpEnv && { env: 'wp-env' } ),
|
|
59
60
|
...customScripts,
|
|
60
61
|
},
|
|
62
|
+
...customPackageJSON,
|
|
61
63
|
} ).filter( ( [ , value ] ) => !! value )
|
|
62
64
|
)
|
|
63
65
|
);
|
package/lib/scaffold.js
CHANGED
|
@@ -43,7 +43,10 @@ module.exports = async (
|
|
|
43
43
|
editorScript,
|
|
44
44
|
editorStyle,
|
|
45
45
|
style,
|
|
46
|
+
render,
|
|
46
47
|
variantVars,
|
|
48
|
+
customPackageJSON,
|
|
49
|
+
customBlockJSON,
|
|
47
50
|
}
|
|
48
51
|
) => {
|
|
49
52
|
slug = slug.toLowerCase();
|
|
@@ -99,6 +102,9 @@ module.exports = async (
|
|
|
99
102
|
editorScript,
|
|
100
103
|
editorStyle,
|
|
101
104
|
style,
|
|
105
|
+
render,
|
|
106
|
+
customPackageJSON,
|
|
107
|
+
customBlockJSON,
|
|
102
108
|
...variantVars,
|
|
103
109
|
};
|
|
104
110
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{{#isDynamicVariant}}
|
|
2
2
|
<p <?php echo get_block_wrapper_attributes(); ?>>
|
|
3
|
-
|
|
3
|
+
<?php esc_html_e( '{{title}} – hello from a dynamic block!', '{{textdomain}}' ); ?>
|
|
4
4
|
</p>
|
|
5
5
|
{{/isDynamicVariant}}
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
{{#description}}
|
|
8
8
|
* Description: {{description}}
|
|
9
9
|
{{/description}}
|
|
10
|
-
* Requires at least:
|
|
10
|
+
* Requires at least: 6.1
|
|
11
11
|
* Requires PHP: 7.0
|
|
12
12
|
* Version: {{version}}
|
|
13
13
|
{{#author}}
|
|
@@ -70,32 +70,12 @@ function {{namespaceSnakeCase}}_{{slugSnakeCase}}_block_init() {
|
|
|
70
70
|
);
|
|
71
71
|
|
|
72
72
|
register_block_type(
|
|
73
|
-
|
|
73
|
+
$dir,
|
|
74
74
|
array(
|
|
75
75
|
'editor_script' => '{{namespace}}-{{slug}}-block-editor',
|
|
76
76
|
'editor_style' => '{{namespace}}-{{slug}}-block-editor',
|
|
77
77
|
'style' => '{{namespace}}-{{slug}}-block',
|
|
78
|
-
{{#isDynamicVariant}}
|
|
79
|
-
'render_callback' => '{{namespaceSnakeCase}}_{{slugSnakeCase}}_render_callback',
|
|
80
|
-
{{/isDynamicVariant}}
|
|
81
78
|
)
|
|
82
79
|
);
|
|
83
80
|
}
|
|
84
81
|
add_action( 'init', '{{namespaceSnakeCase}}_{{slugSnakeCase}}_block_init' );
|
|
85
|
-
{{#isDynamicVariant}}
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* Render callback function.
|
|
89
|
-
*
|
|
90
|
-
* @param array $attributes The block attributes.
|
|
91
|
-
* @param string $content The block content.
|
|
92
|
-
* @param WP_Block $block Block instance.
|
|
93
|
-
*
|
|
94
|
-
* @return string The rendered output.
|
|
95
|
-
*/
|
|
96
|
-
function {{namespaceSnakeCase}}_{{slugSnakeCase}}_render_callback( $attributes, $content, $block ) {
|
|
97
|
-
ob_start();
|
|
98
|
-
require plugin_dir_path( __FILE__ ) . '/template.php';
|
|
99
|
-
return ob_get_clean();
|
|
100
|
-
}
|
|
101
|
-
{{/isDynamicVariant}}
|
|
@@ -33,53 +33,6 @@
|
|
|
33
33
|
* @see https://developer.wordpress.org/block-editor/reference-guides/block-api/block-registration/
|
|
34
34
|
*/
|
|
35
35
|
registerBlockType( '{{namespace}}/{{slug}}', {
|
|
36
|
-
/**
|
|
37
|
-
* @see https://make.wordpress.org/core/2020/11/18/block-api-version-2/
|
|
38
|
-
*/
|
|
39
|
-
apiVersion: {{apiVersion}},
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* This is the display title for your block, which can be translated with `i18n` functions.
|
|
43
|
-
* The block inserter will show this name.
|
|
44
|
-
*/
|
|
45
|
-
title: __(
|
|
46
|
-
'{{title}}',
|
|
47
|
-
'{{textdomain}}'
|
|
48
|
-
),
|
|
49
|
-
|
|
50
|
-
{{#description}}
|
|
51
|
-
/**
|
|
52
|
-
* This is a short description for your block, can be translated with `i18n` functions.
|
|
53
|
-
* It will be shown in the Block Tab in the Settings Sidebar.
|
|
54
|
-
*/
|
|
55
|
-
description: __(
|
|
56
|
-
'{{description}}',
|
|
57
|
-
'{{textdomain}}'
|
|
58
|
-
),
|
|
59
|
-
|
|
60
|
-
{{/description}}
|
|
61
|
-
/**
|
|
62
|
-
* Blocks are grouped into categories to help users browse and discover them.
|
|
63
|
-
* The categories provided by core are `text`, `media`, `design`, `widgets`, and `embed`.
|
|
64
|
-
*/
|
|
65
|
-
category: '{{category}}',
|
|
66
|
-
|
|
67
|
-
{{#dashicon}}
|
|
68
|
-
/**
|
|
69
|
-
* An icon property should be specified to make it easier to identify a block.
|
|
70
|
-
* These can be any of WordPress’ Dashicons, or a custom svg element.
|
|
71
|
-
*/
|
|
72
|
-
icon: '{{dashicon}}',
|
|
73
|
-
|
|
74
|
-
{{/dashicon}}
|
|
75
|
-
/**
|
|
76
|
-
* Optional block extended support features.
|
|
77
|
-
*/
|
|
78
|
-
supports: {
|
|
79
|
-
// Removes support for an HTML mode.
|
|
80
|
-
html: false,
|
|
81
|
-
},
|
|
82
|
-
|
|
83
36
|
/**
|
|
84
37
|
* The edit function describes the structure of your block in the context of the editor.
|
|
85
38
|
* This represents what the editor will render when the block is used.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{{#isDynamicVariant}}
|
|
2
2
|
<p <?php echo get_block_wrapper_attributes(); ?>>
|
|
3
|
-
|
|
3
|
+
<?php esc_html_e( '{{title}} – hello from a dynamic block!', '{{textdomain}}' ); ?>
|
|
4
4
|
</p>
|
|
5
5
|
{{/isDynamicVariant}}
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
{{#description}}
|
|
8
8
|
* Description: {{description}}
|
|
9
9
|
{{/description}}
|
|
10
|
-
* Requires at least:
|
|
10
|
+
* Requires at least: 6.1
|
|
11
11
|
* Requires PHP: 7.0
|
|
12
12
|
* Version: {{version}}
|
|
13
13
|
{{#author}}
|
|
@@ -38,33 +38,6 @@
|
|
|
38
38
|
* @see https://developer.wordpress.org/reference/functions/register_block_type/
|
|
39
39
|
*/
|
|
40
40
|
function {{namespaceSnakeCase}}_{{slugSnakeCase}}_block_init() {
|
|
41
|
-
{{#isStaticVariant}}
|
|
42
41
|
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}}
|
|
52
42
|
}
|
|
53
43
|
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( $attributes, $content, $block ) {
|
|
66
|
-
ob_start();
|
|
67
|
-
require plugin_dir_path( __FILE__ ) . 'build/template.php';
|
|
68
|
-
return ob_get_clean();
|
|
69
|
-
}
|
|
70
|
-
{{/isDynamicVariant}}
|
package/lib/templates.js
CHANGED
|
@@ -26,10 +26,13 @@ const predefinedPluginTemplates = {
|
|
|
26
26
|
description:
|
|
27
27
|
'Example block scaffolded with Create Block tool – no build step required.',
|
|
28
28
|
dashicon: 'smiley',
|
|
29
|
+
supports: {
|
|
30
|
+
html: false,
|
|
31
|
+
},
|
|
29
32
|
wpScripts: false,
|
|
30
|
-
editorScript:
|
|
31
|
-
editorStyle:
|
|
32
|
-
style:
|
|
33
|
+
editorScript: null,
|
|
34
|
+
editorStyle: null,
|
|
35
|
+
style: null,
|
|
33
36
|
},
|
|
34
37
|
templatesPath: join( __dirname, 'templates', 'es5' ),
|
|
35
38
|
variants: {
|
|
@@ -37,6 +40,7 @@ const predefinedPluginTemplates = {
|
|
|
37
40
|
dynamic: {
|
|
38
41
|
slug: 'example-dynamic-es5',
|
|
39
42
|
title: 'Example Dynamic (ES5)',
|
|
43
|
+
render: 'file:./render.php',
|
|
40
44
|
},
|
|
41
45
|
},
|
|
42
46
|
},
|
|
@@ -55,6 +59,7 @@ const predefinedPluginTemplates = {
|
|
|
55
59
|
dynamic: {
|
|
56
60
|
slug: 'example-dynamic',
|
|
57
61
|
title: 'Example Dynamic',
|
|
62
|
+
render: 'file:./render.php',
|
|
58
63
|
},
|
|
59
64
|
},
|
|
60
65
|
},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/create-block",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.5.0",
|
|
4
4
|
"description": "Generates PHP, JS and CSS code for registering a block for a WordPress plugin.",
|
|
5
5
|
"author": "The WordPress Contributors",
|
|
6
6
|
"license": "GPL-2.0-or-later",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"wp-create-block": "./index.js"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@wordpress/lazy-import": "^1.
|
|
34
|
+
"@wordpress/lazy-import": "^1.8.0",
|
|
35
35
|
"chalk": "^4.0.0",
|
|
36
36
|
"change-case": "^4.1.2",
|
|
37
37
|
"check-node-version": "^4.1.0",
|
|
@@ -48,5 +48,5 @@
|
|
|
48
48
|
"publishConfig": {
|
|
49
49
|
"access": "public"
|
|
50
50
|
},
|
|
51
|
-
"gitHead": "
|
|
51
|
+
"gitHead": "511f4cc1f0138641bc4394bc1cf36e833109c791"
|
|
52
52
|
}
|