-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Feature/WDSBT-20 Custom block build process
- Loading branch information
Showing
36 changed files
with
6,944 additions
and
4,167 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
blocks | ||
build | ||
node_modules | ||
vendor | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,7 @@ vendor/ | |
|
||
# theme | ||
build/ | ||
blocks/ | ||
|
||
#tests | ||
pa11y-ci-report/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
blocks | ||
build | ||
node_modules | ||
vendor | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
blocks/ | ||
build/ | ||
node_modules/ | ||
vendor/ | ||
style.css | ||
README.md | ||
acf-json/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
blocks/ | ||
build/ | ||
vendor/ | ||
node_modules/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/* -- Editor Stykes -- */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"presets": ["@babel/preset-env", "@babel/preset-react"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# WDS Block Template | ||
|
||
This template is configured to generate a block that is ready for block registration using the [`@wordpress/create-block`](https://developer.wordpress.org/block-editor/reference-guides/packages/packages-create-block/) tool. | ||
|
||
## Usage | ||
|
||
Run the following in the terminal of your choice: | ||
|
||
`npx @wordpress/create-block --template ../../inc/block-template --no-plugin` | ||
|
||
|
||
## Structure | ||
|
||
Once the command has completed, the following structure will be created: | ||
|
||
``` text | ||
📁src | ||
└── 📁blocks | ||
└── 📁{example-block} | ||
└── block.json | ||
└── edit.js | ||
└── editor.scss | ||
└── index.js | ||
└── render.php | ||
└── style.scss | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/** | ||
* WordPress Dependencies | ||
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
import { useBlockProps } from '@wordpress/block-editor'; | ||
|
||
/** | ||
* Internal Dependencies | ||
*/ | ||
import './editor.scss'; | ||
|
||
/** | ||
* The edit function describes the structure of your block in the context of the | ||
* editor. This represents what the editor will render when the block is used. | ||
* | ||
* @see https://developer.wordpress.org/block-editor/reference-guides/block-api/block-edit-save/#edit | ||
*/ | ||
export default function Edit() { | ||
return ( | ||
<p {...useBlockProps()}>{__('{{title}} – hello from the editor!', '{{textdomain}}')}</p> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/** | ||
* The following styles get applied inside the editor only. | ||
* | ||
* Replace them with your own styles or remove the file completely. | ||
*/ | ||
|
||
.wp-block-{{namespace}}-{{slug}} { | ||
border: 1px dotted var(--wp--preset--color--grey-400); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/** | ||
* Registers a new block provided a unique name and an object defining its behavior. | ||
* | ||
* @see https://developer.wordpress.org/block-editor/reference-guides/block-api/block-registration/ | ||
*/ | ||
import { registerBlockType } from '@wordpress/blocks'; | ||
|
||
/** | ||
* Lets webpack process CSS, SASS or SCSS files referenced in JavaScript files. | ||
* All files containing `style` keyword are bundled together. The code used | ||
* gets applied both to the front of your site and to the editor. | ||
* | ||
* @see https://www.npmjs.com/package/@wordpress/scripts#using-css | ||
*/ | ||
import './style.scss'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import Edit from './edit'; | ||
import metadata from './block.json'; | ||
|
||
/** | ||
* Every block starts by registering a new block type definition. | ||
* | ||
* @see https://developer.wordpress.org/block-editor/reference-guides/block-api/block-registration/ | ||
*/ | ||
registerBlockType(metadata.name, { | ||
/** | ||
* @see ./edit.js | ||
*/ | ||
edit: Edit, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
/** | ||
* PHP file to use when rendering the block type on the server to show on the front end. | ||
* | ||
* The following variables are exposed to the file: | ||
* $attributes (array): The block attributes. | ||
* $content (string): The block default content. | ||
* $block (WP_Block): The block instance. | ||
* | ||
* @see https://github.com/WordPress/gutenberg/blob/trunk/docs/reference-guides/block-api/block-metadata.md#render | ||
*/ | ||
|
||
{{#isInteractiveVariant}} | ||
// Define some global state | ||
wp_interactivity_state( | ||
'{{slug}}', | ||
array() | ||
); | ||
|
||
// Define some context. | ||
$context = array(); | ||
?> | ||
<p <?php echo wp_kses_data( get_block_wrapper_attributes() ); ?> | ||
data-wp-interactive="{{slug}}" | ||
<?php echo wp_interactivity_data_wp_context( $context ); ?> | ||
> | ||
<?php esc_html_e( '{{title}} – hello from an interactive block!', '{{textdomain}}' ); ?> | ||
</p> | ||
{{/isInteractiveVariant}} | ||
{{#isDynamicVariant}} | ||
?> | ||
<p <?php echo wp_kses_data( get_block_wrapper_attributes() ); ?>> | ||
<?php esc_html_e( '{{title}} – hello from a dynamic block!', '{{textdomain}}' ); ?> | ||
</p> | ||
{{/isDynamicVariant}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/** | ||
* The following styles get applied both on the front of your site | ||
* and in the editor. | ||
* | ||
* Replace them with your own styles or remove the file completely. | ||
*/ | ||
|
||
.wp-block-{{namespace}}-{{slug}} { | ||
border: 1px dotted var(--wp--preset--color--grey-400); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{{#isInteractiveVariant}} | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { store } from '@wordpress/interactivity'; | ||
|
||
store( '{{slug}}', { | ||
state: {}, | ||
actions: {}, | ||
callbacks: {}, | ||
} ); | ||
{{/isInteractiveVariant}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/** | ||
* Dependencies | ||
*/ | ||
const { join } = require('path'); | ||
|
||
module.exports = { | ||
defaultValues: { | ||
transformer: (view) => { | ||
const { | ||
variantVars: { isInteractiveVariant }, | ||
} = view; | ||
return { | ||
...view, | ||
requiresAtLeast: isInteractiveVariant ? '6.5' : '6.1', | ||
}; | ||
}, | ||
author: 'WebDevStudios', | ||
category: 'wds-blocks', | ||
dashicon: 'pets', | ||
description: 'A custom block created by the create-block for the theme', | ||
namespace: 'wdsbt', | ||
render: 'file:./render.php', | ||
version: '1.0.0', | ||
customPackageJSON: { | ||
prettier: '@wordpress/prettier-config', | ||
}, | ||
}, | ||
variants: { | ||
dynamic: {}, | ||
interactive: { | ||
viewScriptModule: 'file:./view.js', | ||
customScripts: { | ||
build: 'wp-scripts build --experimental-modules', | ||
start: 'wp-scripts start --experimental-modules', | ||
}, | ||
supports: { | ||
interactive: true, | ||
}, | ||
}, | ||
}, | ||
pluginTemplatesPath: join(__dirname, 'plugin'), | ||
blockTemplatesPath: join(__dirname, 'block'), | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
/** | ||
* Plugin Name: {{title}} | ||
{{#pluginURI}} | ||
* Plugin URI: {{{pluginURI}}} | ||
{{/pluginURI}} | ||
{{#description}} | ||
* Description: {{description}} | ||
{{/description}} | ||
* Requires at least: {{requiresAtLeast}} | ||
* Requires PHP: 7.0 | ||
* Version: {{version}} | ||
{{#author}} | ||
* Author: {{author}} | ||
{{/author}} | ||
{{#license}} | ||
* License: {{license}} | ||
{{/license}} | ||
{{#licenseURI}} | ||
* License URI: {{{licenseURI}}} | ||
{{/licenseURI}} | ||
* Text Domain: {{textdomain}} | ||
{{#domainPath}} | ||
* Domain Path: {{{domainPath}}} | ||
{{/domainPath}} | ||
{{#updateURI}} | ||
* Update URI: {{{updateURI}}} | ||
{{/updateURI}} | ||
* | ||
* @package {{slugPascalCase}} | ||
*/ | ||
|
||
namespace {{slugPascalCase}}; | ||
|
||
if ( ! defined( 'ABSPATH' ) ) { | ||
exit; // Exit if accessed directly. | ||
} | ||
|
||
/** | ||
* Registers the block using the metadata loaded from the `block.json` file. | ||
* Behind the scenes, it registers also all assets so they can be enqueued | ||
* through the block editor in the corresponding context. | ||
* | ||
* @see https://developer.wordpress.org/reference/functions/register_block_type/ | ||
*/ | ||
function {{slugSnakeCase}}_block_init() { | ||
register_block_type_from_metadata( __DIR__ . '/build' ); | ||
} | ||
add_action( 'init', __NAMESPACE__ . '{{slugSnakeCase}}_block_init' ); |
Oops, something went wrong.