-
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.
Merge pull request #82 from alleyinteractive/feature/wp-scripts
Add support for @wordpress/scripts, block.json and create block
- Loading branch information
Showing
30 changed files
with
8,734 additions
and
17,379 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
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
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
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,24 +1,3 @@ | ||
{ | ||
"extends": "stylelint-config-sass-guidelines", | ||
"rules": { | ||
"max-nesting-depth": [ | ||
3, | ||
{ | ||
"ignoreAtRules": [ | ||
"each", | ||
"media", | ||
"supports", | ||
"include" | ||
] | ||
} | ||
], | ||
"selector-class-pattern": [ | ||
"^[a-z0-9\\-_]+$", | ||
{ | ||
"message": | ||
"Selector should be written in lowercase with hyphens and/or underscores (selector-class-pattern)" | ||
} | ||
], | ||
"selector-no-qualifying-type": null | ||
} | ||
} | ||
"extends": "@alleyinteractive/stylelint-config" | ||
} |
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
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,14 @@ | ||
/** | ||
* This babel config is used by Jest to ensure that tests | ||
* will run correctly in Typescript and JavaScript files. | ||
* | ||
* Jest supports TypeScript, via Babel. | ||
* | ||
* @see https://jestjs.io/docs/getting-started#using-typescript | ||
*/ | ||
module.exports = { | ||
presets: [ | ||
'@babel/preset-env', | ||
'@wordpress/babel-preset-default', | ||
], | ||
}; |
This file was deleted.
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,24 @@ | ||
const path = require('path'); | ||
|
||
/** | ||
* Custom Variables and templates for scaffolding blocks. | ||
* @see https://github.com/WordPress/gutenberg/blob/trunk/packages/create-block/docs/external-template.md#external-project-templates | ||
*/ | ||
module.exports = { | ||
defaultValues: { | ||
namespace: 'create-wordpress-plugin', | ||
plugin: false, | ||
description: '', | ||
dashicon: 'palmtree', | ||
category: 'widgets', | ||
editorScript: 'file:index.js', | ||
editorStyle: 'file:index.css', | ||
style: ['file:style-index.css'], | ||
render: 'file:render.php', | ||
}, | ||
variants: { | ||
static: {}, | ||
dynamic: {}, | ||
}, | ||
blockTemplatesPath: path.join(__dirname, 'templates', '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,38 @@ | ||
/** | ||
* Retrieves the translation of text. | ||
* | ||
* @see https://developer.wordpress.org/block-editor/reference-guides/packages/packages-i18n/ | ||
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
|
||
/** | ||
* React hook that is used to mark the block wrapper element. | ||
* It provides all the necessary props like the class name. | ||
* | ||
* @see https://developer.wordpress.org/block-editor/reference-guides/packages/packages-block-editor/#useblockprops | ||
*/ | ||
import { useBlockProps } from '@wordpress/block-editor'; | ||
|
||
/** | ||
* Lets webpack process CSS, SASS or SCSS files referenced in JavaScript files. | ||
* Those files can contain any CSS code that gets applied to the editor. | ||
* | ||
* @see https://www.npmjs.com/package/@wordpress/scripts#using-css | ||
*/ | ||
import './index.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 | ||
* | ||
* @return {WPElement} Element to render. | ||
*/ | ||
export default function Edit() { | ||
return ( | ||
<p {...useBlockProps()}> | ||
{ __('Block Title – hello from the editor!', 'create-wordpress-plugin') } | ||
</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,42 @@ | ||
/** | ||
* 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'; | ||
{{#isStaticVariant}} | ||
import save from './save'; | ||
{{/isStaticVariant}} | ||
import metadata from './block.json'; | ||
{{#isAnotherVariant}} | ||
console.log('it worked'); | ||
{{/isAnotherVariant}} | ||
|
||
/** | ||
* 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, | ||
{ | ||
edit, | ||
{{#isStaticVariant}} | ||
save, | ||
{{/isStaticVariant}} | ||
}, | ||
); |
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 @@ | ||
<?php | ||
/** | ||
* Block Name: {{title}}. | ||
* | ||
* @package create-wordpress-plugin | ||
*/ | ||
|
||
/** | ||
* 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 {{namespaceSnakeCase}}_{{slugSnakeCase}}_block_init() { | ||
// Register the block by passing the location of block.json. | ||
register_block_type( | ||
__DIR__ | ||
); | ||
} | ||
add_action( 'init', '{{namespaceSnakeCase}}_{{slugSnakeCase}}_block_init' ); |
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,13 @@ | ||
/** | ||
* The following styles get applied inside the editor only. | ||
* | ||
* All imported CSS files are bundled into one chunk named after the entry point, | ||
* which defaults to index.js, and thus the file created becomes index.css. | ||
* This is for styles used only in the editor. | ||
* | ||
* Replace them with your own styles or remove the file completely. | ||
*/ | ||
|
||
.wp-block-{{namespace}}-{{slug}} { | ||
border: 1px dotted #f00; | ||
} |
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,17 @@ | ||
{{#isDynamicVariant}} | ||
<?php | ||
/** | ||
* All of the parameters passed to the function where this file is being required are accessible in this scope: | ||
* | ||
* @param array $attributes The array of attributes for this block. | ||
* @param string $content Rendered block output. ie. <InnerBlocks.Content />. | ||
* @param WP_Block $block_instance The instance of the WP_Block class that represents the block being rendered. | ||
* | ||
* @package create-wordpress-plugin | ||
*/ | ||
|
||
?> | ||
<p <?php echo wp_kses_data( get_block_wrapper_attributes() ); ?>> | ||
<?php esc_html_e( '{{title}} – hello from a dynamic block!', 'create-wordpress-plugin' ); ?> | ||
</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,26 @@ | ||
{{#isStaticVariant}} | ||
/** | ||
* React hook that is used to mark the block wrapper element. | ||
* It provides all the necessary props like the class name. | ||
* | ||
* @see https://developer.wordpress.org/block-editor/reference-guides/packages/packages-block-editor/#useblockprops | ||
*/ | ||
import { useBlockProps } from '@wordpress/block-editor'; | ||
|
||
/** | ||
* The save function defines the way in which the different attributes should | ||
* be combined into the final markup, which is then serialized by the block | ||
* editor into `post_content`. | ||
* | ||
* @see https://developer.wordpress.org/block-editor/reference-guides/block-api/block-edit-save/#save | ||
* | ||
* @return {WPElement} Element to render. | ||
*/ | ||
export default function save() { | ||
return ( | ||
<p { ...useBlockProps.save() }> | ||
{ '{{title}} – hello from the saved content!' } | ||
</p> | ||
); | ||
} | ||
{{/isStaticVariant}} |
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,18 @@ | ||
/** | ||
* The following styles get applied both on the front of your site | ||
* and in the editor. | ||
* | ||
* Imported style.css file(s) (applies to SASS and SCSS extensions) | ||
* get bundled into one style-index.css file that is meant to be | ||
* used both on the front-end and in the editor. | ||
* | ||
* Replace them with your own styles or remove the file completely. | ||
* | ||
* @see https://developer.wordpress.org/block-editor/reference-guides/block-api/block-metadata/#block-styles | ||
*/ | ||
|
||
.wp-block-{{namespace}}-{{slug}} { | ||
background-color: #21759b; | ||
color: #fff; | ||
padding: 2px; | ||
} |
Oops, something went wrong.