-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Create block interactive template (discarded) #52549
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
juanmaguitar
wants to merge
3
commits into
WordPress:create-block-interactive-template
from
juanma-wp:create-block-interactive-template
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 @@ | ||
| package-lock=false |
This file contains hidden or 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 @@ | ||
| <!-- Learn how to maintain this file at https://github.com/WordPress/gutenberg/tree/HEAD/packages#maintaining-changelogs. --> |
This file contains hidden or 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,19 @@ | ||
| # Create Block Interactive Template | ||
|
|
||
| This is a template for [`@wordpress/create-block`](https://github.com/WordPress/gutenberg/tree/HEAD/packages/create-block/README.md) to create interactive blocks | ||
|
|
||
| ## Usage | ||
|
|
||
| This block template can be used by running the following command: | ||
|
|
||
| ```bash | ||
| npx @wordpress/create-block --template @wordpress/create-block-interactive-template | ||
| ``` | ||
|
|
||
| ## Contributing to this package | ||
|
|
||
| This is an individual package that's part of the Gutenberg project. The project is organized as a monorepo. It's made up of multiple self-contained software packages, each with a specific purpose. The packages in this monorepo are published to [npm](https://www.npmjs.com/) and used by [WordPress](https://make.wordpress.org/core/) as well as other software projects. | ||
|
|
||
| To find out more about contributing to this package or Gutenberg as a whole, please read the project's main [contributor guide](https://github.com/WordPress/gutenberg/tree/HEAD/CONTRIBUTING.md). | ||
|
|
||
| <br /><br /><p align="center"><img src="https://s.w.org/style/images/codeispoetry.png?1" alt="Code is Poetry." /></p> |
16 changes: 16 additions & 0 deletions
16
packages/create-block-interactive-template/block-templates/README.md.mustache
This file contains hidden or 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,16 @@ | ||
| # Interactive Block | ||
|
|
||
| > **Warning** | ||
| > **This block requires Gutenberg 16.2 or superior to work**. The Interactivity API is, at the moment, not part of WordPress Core as it is still very experimental, and very likely to change. | ||
|
|
||
| > **Note** | ||
| > This block uses the API shared at [Proposal: The Interactivity API – A better developer experience in building interactive blocks](https://make.wordpress.org/core/2023/03/30/proposal-the-interactivity-api-a-better-developer-experience-in-building-interactive-blocks/). | ||
|
|
||
| {{#isBasicVariant}} | ||
| This block has been created with the `create-block-interactive-template` and shows a basic structure of an interactive block that uses the Interactivity API. | ||
| {{/isBasicVariant}} | ||
|
|
||
| Check the following resources for more info about the Interactivity API: | ||
| - [`@wordpress/interactivity` package](https://github.com/WordPress/gutenberg/blob/trunk/packages/interactivity/README.md) | ||
| - [Proposal: The Interactivity API – A better developer experience in building interactive blocks](https://make.wordpress.org/core/2023/03/30/proposal-the-interactivity-api-a-better-developer-experience-in-building-interactive-blocks/) | ||
| - [“Interactivity API” category](https://github.com/WordPress/gutenberg/discussions/categories/interactivity-api) in Gutenberg repo discussions |
33 changes: 33 additions & 0 deletions
33
packages/create-block-interactive-template/block-templates/render.php.mustache
This file contains hidden or 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 @@ | ||
| {{#isBasicVariant}} | ||
| <?php | ||
| /** | ||
| * @see https://github.com/WordPress/gutenberg/blob/trunk/docs/reference-guides/block-api/block-metadata.md#render | ||
| */ | ||
|
|
||
| $unique_id = uniqid( 'p-' ); | ||
| ?> | ||
|
|
||
| <div | ||
| <?php echo get_block_wrapper_attributes(); ?> | ||
| data-wp-interactive | ||
| data-wp-context='{ "{{namespace}}": { "isOpen": false } }' | ||
| data-wp-effect="effects.{{namespace}}.logIsOpen" | ||
| > | ||
| <button | ||
| data-wp-on--click="actions.{{namespace}}.toggle" | ||
| data-wp-bind--aria-expanded="context.{{namespace}}.isOpen" | ||
| aria-controls="p-<?php echo $unique_id; ?>" | ||
| > | ||
| <?php _e( 'Toggle', '{{textdomain}}' ); ?> | ||
| </button> | ||
|
|
||
| <p | ||
| id="p-<?php echo $unique_id; ?>" | ||
| data-wp-bind--hidden="!context.{{namespace}}.isOpen" | ||
| > | ||
| <?php | ||
| _e( '{{title}} - hello from an interactive block!', '{{textdomain}}' ); | ||
| ?> | ||
| </p> | ||
| </div> | ||
| {{/isBasicVariant}} |
48 changes: 48 additions & 0 deletions
48
packages/create-block-interactive-template/block-templates/view.js.mustache
This file contains hidden or 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,48 @@ | ||||||
| {{#isBasicVariant}} | ||||||
|
|
||||||
| /** | ||||||
|
|
||||||
| * WordPress dependencies | ||||||
|
|
||||||
| */ | ||||||
|
|
||||||
| import { store } from "@wordpress/interactivity"; | ||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
| store( { | ||||||
|
|
||||||
| actions: { | ||||||
|
|
||||||
| '{{namespace}}': { | ||||||
|
|
||||||
| toggle: ( { context } ) => { | ||||||
|
|
||||||
| context[ '{{namespace}}' ].isOpen = !context[ '{{namespace}}' ].isOpen; | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There's a missing space after the |
||||||
|
|
||||||
| }, | ||||||
|
|
||||||
| }, | ||||||
|
|
||||||
| }, | ||||||
|
|
||||||
| effects: { | ||||||
|
|
||||||
| '{{namespace}}': { | ||||||
|
|
||||||
| logIsOpen: ( { context } ) => { | ||||||
|
|
||||||
| // Log the value of `isOpen` each time it changes. | ||||||
|
|
||||||
| console.log( `Is open: ${ context[ '{{namespace}}' ].isOpen }` ); | ||||||
|
|
||||||
| }, | ||||||
|
|
||||||
| }, | ||||||
|
|
||||||
| }, | ||||||
|
|
||||||
| } ); | ||||||
|
|
||||||
| {{/isBasicVariant}} | ||||||
This file contains hidden or 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,25 @@ | ||
| /** | ||
| * External dependencies | ||
| */ | ||
| const { join } = require( 'path' ); | ||
|
|
||
| module.exports = { | ||
| defaultValues: { | ||
| slug: 'example-interactive', | ||
| title: 'Example Interactive', | ||
| description: 'An interactive block with the Interactivity API', | ||
| dashicon: 'interactivity', | ||
| npmDependencies: [ '@wordpress/interactivity' ], | ||
| supports: { | ||
| interactivity: true, | ||
| }, | ||
| render: 'file:./render.php', | ||
| viewScript: 'file:./view.js', | ||
| }, | ||
| variants: { | ||
| basic: {}, | ||
| }, | ||
| pluginTemplatesPath: join( __dirname, 'plugin-templates' ), | ||
| blockTemplatesPath: join( __dirname, 'block-templates' ), | ||
| assetsPath: join( __dirname, 'assets' ), | ||
| }; |
This file contains hidden or 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,25 @@ | ||
| { | ||
| "name": "@wordpress/create-block-interactive-template", | ||
| "version": "1.0.0", | ||
| "description": "Template for @wordpress/create-block to create interactive blocks with the Interactivity API.", | ||
| "author": "The WordPress Contributors", | ||
| "license": "GPL-2.0-or-later", | ||
| "keywords": [ | ||
| "wordpress", | ||
| "create block", | ||
| "block template", | ||
| "Interactivity API" | ||
| ], | ||
| "homepage": "https://github.com/WordPress/gutenberg/tree/HEAD/docs/getting-started/create-block", | ||
| "repository": { | ||
| "type": "git", | ||
| "url": "https://github.com/WordPress/gutenberg.git", | ||
| "directory": "packages/create-block-interactive-template" | ||
| }, | ||
| "bugs": { | ||
| "url": "https://github.com/WordPress/gutenberg/issues" | ||
| }, | ||
| "publishConfig": { | ||
| "access": "public" | ||
| } | ||
| } |
43 changes: 43 additions & 0 deletions
43
packages/create-block-interactive-template/plugin-templates/$slug.php.mustache
This file contains hidden or 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 @@ | ||
| <?php | ||
| /** | ||
| * Plugin Name: {{title}} | ||
| {{#pluginURI}} | ||
| * Plugin URI: {{{pluginURI}}} | ||
| {{/pluginURI}} | ||
| {{#description}} | ||
| * Description: {{description}} | ||
| {{/description}} | ||
| * Version: {{version}} | ||
| * Requires at least: 6.1 | ||
| * Requires PHP: 7.0 | ||
| {{#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 {{namespace}} | ||
| */ | ||
|
|
||
| /** | ||
| * 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_block_type( __DIR__ . '/build' ); | ||
| } | ||
| add_action( 'init', '{{namespaceSnakeCase}}_{{slugSnakeCase}}_block_init' ); |
61 changes: 61 additions & 0 deletions
61
packages/create-block-interactive-template/plugin-templates/readme.txt.mustache
This file contains hidden or 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,61 @@ | ||
| === {{title}} === | ||
| {{#author}} | ||
| Contributors: {{author}} | ||
| {{/author}} | ||
| Tags: block | ||
| Tested up to: 6.1 | ||
| Stable tag: {{version}} | ||
| {{#license}} | ||
| License: {{license}} | ||
| {{/license}} | ||
| {{#licenseURI}} | ||
| License URI: {{{licenseURI}}} | ||
| {{/licenseURI}} | ||
|
|
||
| {{description}} | ||
|
|
||
| == Description == | ||
|
|
||
| This is the long description. No limit, and you can use Markdown (as well as in the following sections). | ||
|
|
||
| For backwards compatibility, if this section is missing, the full length of the short description will be used, and | ||
| Markdown parsed. | ||
|
|
||
| == Installation == | ||
|
|
||
| This section describes how to install the plugin and get it working. | ||
|
|
||
| e.g. | ||
|
|
||
| 1. Upload the plugin files to the `/wp-content/plugins/{{slug}}` directory, or install the plugin through the WordPress plugins screen directly. | ||
| 1. Activate the plugin through the 'Plugins' screen in WordPress | ||
|
|
||
|
|
||
| == Frequently Asked Questions == | ||
|
|
||
| = A question that someone might have = | ||
|
|
||
| An answer to that question. | ||
|
|
||
| = What about foo bar? = | ||
|
|
||
| Answer to foo bar dilemma. | ||
|
|
||
| == Screenshots == | ||
|
|
||
| 1. This screen shot description corresponds to screenshot-1.(png|jpg|jpeg|gif). Note that the screenshot is taken from | ||
| the /assets directory or the directory that contains the stable readme.txt (tags or trunk). Screenshots in the /assets | ||
| directory take precedence. For example, `/assets/screenshot-1.png` would win over `/tags/4.3/screenshot-1.png` | ||
| (or jpg, jpeg, gif). | ||
| 2. This is the second screen shot | ||
|
|
||
| == Changelog == | ||
|
|
||
| = {{version}} = | ||
| * Release | ||
|
|
||
| == Arbitrary section == | ||
|
|
||
| You may provide arbitrary sections, in the same format as the ones above. This may be of use for extremely complicated | ||
| plugins where more information needs to be conveyed that doesn't fit into the categories of "description" or | ||
| "installation." Arbitrary sections will be shown below the built-in sections outlined above. |
This file contains hidden or 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 hidden or 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 hidden or 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 @@ | ||
| {{#isInteractiveVariant}} | ||
| /** | ||
| * WordPress dependencies | ||
| */ | ||
| import { store } from "@wordpress/interactivity"; | ||
|
|
||
| store( { | ||
| actions: { | ||
| '{{namespace}}': { | ||
| toggle: ( { context } ) => { | ||
| context[ '{{namespace}}' ].isOpen = !context[ '{{namespace}}' ].isOpen; | ||
| }, | ||
| }, | ||
| }, | ||
| effects: { | ||
| '{{namespace}}': { | ||
| logIsOpen: ( { context } ) => { | ||
| // Log the value of `isOpen` each time it changes. | ||
| console.log( `Is open: ${ context[ '{{namespace}}' ].isOpen }` ); | ||
| }, | ||
| }, | ||
| }, | ||
| } ); | ||
| {{/isInteractiveVariant}} | ||
| console.log("Hello World! (from {{namespace}}-{{slug}} block)") |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see double-line breaks in this file. Is it on purpose?