All Projects → zackify → Gutenblock

zackify / Gutenblock

Licence: mit
The easiest way to develop and release Gutenberg blocks (components) for WordPress

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Gutenblock

The Events Calendar
The Events Calendar WordPress plugin by Modern Tribe
Stars: ✭ 208 (-9.17%)
Mutual labels:  wordpress
Go
The most flexible Gutenberg-first WordPress theme built for go-getters everywhere.
Stars: ✭ 218 (-4.8%)
Mutual labels:  wordpress
Wordpress Ajax Load More
🔥 WordPress infinite scroll with Ajax Load More - the ultimate solution to add infinite scroll functionality to your WordPress powered website.
Stars: ✭ 222 (-3.06%)
Mutual labels:  wordpress
Extended Acf
Register advanced custom fields with object oriented PHP
Stars: ✭ 212 (-7.42%)
Mutual labels:  wordpress
Wp Scb Framework
Utilities for speeding up WordPress plugin and theme development
Stars: ✭ 215 (-6.11%)
Mutual labels:  wordpress
Oceanwp
Free multi-purpose WordPress theme
Stars: ✭ 219 (-4.37%)
Mutual labels:  wordpress
Glotpress Wp
🌍 🌎 🌏 GlotPress is a WordPress plugin to let you set up your own collaborative, web-based software translation tool.
Stars: ✭ 205 (-10.48%)
Mutual labels:  wordpress
Code Snippets
Code Snippets WordPress Plugin
Stars: ✭ 226 (-1.31%)
Mutual labels:  wordpress
Versionpress
Git-based version control for WordPress. Whoa!
Stars: ✭ 2,479 (+982.53%)
Mutual labels:  wordpress
Wp Jamstack Deployments
A WordPress plugin for JAMstack deployments
Stars: ✭ 222 (-3.06%)
Mutual labels:  wordpress
List Category Posts
WordPress plugin which allows you to list posts from a category into a post/page using the [catlist] shortcode.
Stars: ✭ 212 (-7.42%)
Mutual labels:  wordpress
Vue Wp Starter
A WordPress Vue.js starter plugin
Stars: ✭ 214 (-6.55%)
Mutual labels:  wordpress
Kasia
🎩 A React Redux toolset for the WordPress API
Stars: ✭ 219 (-4.37%)
Mutual labels:  wordpress
Wp E Commerce
WP eCommerce - The most popular independent eCommerce platform for WordPress
Stars: ✭ 209 (-8.73%)
Mutual labels:  wordpress
Wordpress Android
WordPress for Android
Stars: ✭ 2,601 (+1035.81%)
Mutual labels:  wordpress
Block Options
EditorsKit — a toolkit for the Gutenberg block editor.
Stars: ✭ 208 (-9.17%)
Mutual labels:  wordpress
Vuetheme
WordPress theme using Rest API and Vue.js
Stars: ✭ 219 (-4.37%)
Mutual labels:  wordpress
Headless Wp Nuxt
🏔 Headless WordPress JAMstack Template
Stars: ✭ 229 (+0%)
Mutual labels:  wordpress
Wechatblog
💘微信小程序 & 个人博客 & WordPress & WordPress REST API
Stars: ✭ 223 (-2.62%)
Mutual labels:  wordpress
Wordpress Popular Posts
WordPress Popular Posts - A highly customizable WordPress widget that displays your most popular posts
Stars: ✭ 219 (-4.37%)
Mutual labels:  wordpress

Contents

Install

npm install gutenblock -g

This is a Gutenberg plugin creator + reusable inspector components with hot loading and code splits built in.

Quickstart

If you have never done WordPress development, getting started couldn't be easier.

When you add docker on the end of the watch command, it will bring up WordPress for you. Simply create an account, install the Gutenberg plugin, and activate the blocks plugin. You're all set.

Comparison with other tooling

Currently, there is only one tool out there to help create blocks (that I have found so far). It's called Create Guten Block. This library was inspired by it. I've added what I consider to be good defaults that everyone would want when creating blocks. These features are not included in other libraries by default:

  • Auto Block registration
  • Helper utlities
  • Automatic code splitting
  • Hot reloading (without page reload)
  • Custom webpack config without ejection

Auto Block registration

No need to call registerBlockType for WordPress. Our loader does this for you.

Helper utilities

Currently, when editing things in gutenberg you make components like this:

const { RichText } = wp.editor;

export default ({ setAttributes, attributes }) => (
  <div>
    <RichText
      tagName="h1"
      value={attributes.title}
      placeholder="Title"
      onChange={title => setAttributes({ title })}
    />
  </div>
);

With Gutenblock, we created a higher order context that is loaded into all edit components. This means you can import our abstracted inputs:

import { RichText } from 'gutenblock-controls';

const Edit = () => (
  <div>
    <RichText name="description" />
  </div>
);

We've included a Select MediaSelect Input Inspector Repeat and other form fields to help you build blocks faster. A repeat component will handle the hard work of letting users add infinite items to an array of form fields, replacing items, and deleting them.

The name field is the key in your gutenberg attributes defined in block.js. You can create your own inputs that connect and get access to setAttributes and attributes, no longer needing to pass them all over in your components. See the example

Code splitting

If you have many blocks, you don't want Gutenberg to load all of that JS when it initializes. With this plugin, your edit blocks will only be loaded in once they are dragged out to the canvas.

Hot reloading

Every edit block is hooked into react-hot-loader with our loader so that updates won't need a full page load. Full reloads can make development much slower when Gutenberg has a lot of content on the page at once.

Custom Webpack

Add a gutenblock.config.js file in your blocks folder. It looks like this:

const path = require('path');

module.exports = webpack => ({
  //customize gutenblock options if needed
  gutenblock: {
    devHost: 'localhost',
    devPort: 8080,
    //build asset output path relative to the plugin directory
    outputPath: '/test',
    //when building the plugin, gutenblock will default to the folder name inside wp-content, if you have a different wp-content folder you can change it here
    publicPath: `/app/plugins/blocks/test/`,
  },
  resolve: {
    alias: {
      shared: path.resolve(__dirname, '../src/shared'),
    },
  },
  plugins: [new webpack.EnvironmentPlugin(['NODE_ENV'])],
  module: {
    rules: [
      {
        test: /\.css$/,
        use: [require.resolve('style-loader'), require.resolve('css-loader')],
      },
    ],
  },
});

The configuration is the exact same as webpack with one extra piece: pass babelOptions with plugins and presets like a babelrc has to customize the babel loader.

If you choose to extend the configuration, down the road a future webpack release may require you to make changes and update your configuration. If you do not extend anything, you'll never have to update any configuration in order to upgrade gutenblock!

Future plans

  • Automatic i18n
  • Complicated examples (tabs component, loading in data from WordPress)
  • Test coverage
  • Batch updates when updating nested tabs that cause lots of rerenders in Gutenberg

Usage

gutenblock init will scaffold out a WordPress plugin for you.

gutenblock watch inside the folder will start development mode. Copy the blocks folder into your plugins directory, or use docker

gutenblock build production build the plugin. After, edit line 35 of yourplugin/src/init.php to point to the production assets. All set to publish!

Creating a block

Inside src you will create blocks matching the example one.

All blocks need a block.js and edit.js.

./src/paragraph/block.js

//Optionally use a save block for static rendering on the WordPress frontend

import Save from './save';

const Block = {
  title: 'Paragraph',
  icon: 'shield-alt',
  category: 'common',
  attributes: {
    body: {
      type: 'string',
    },
  },
  save: Save,
};

./src/paragraph/edit.js

import { RichText } from 'gutenblock-controls';

const Edit = () => (
  <RichText tagName="p" name="body" style={{ color: 'black' }} />
);

./src/paragraph/save.js

export default ({ attributes }) => <p>{attributes.body}</p>;

Side note: We don't use save blocks at Crossfield. This is because we fetch WordPress pages and posts via the api and render the blocks using a custom react frontend. Sadly, if you use save blocks, they will not be code split. This is a limitation of the gutenberg editor not supporting awaiting to render the save method.

No registering blocks, importing them into a root folder. It's all done for you.

Now we can run gutenblock watch inside our plugin folder. Inside WordPress the components will hot reload as you edit, thanks to react-hot-loader

You can read more about the Block API

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].