@wordpress/create-block-interactive-template 1.9.0 → 1.10.1

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/CHANGELOG.md CHANGED
@@ -2,6 +2,16 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 1.10.1 (2023-12-07)
6
+
7
+ - Update template to use modules instead of scripts. [#56694](https://github.com/WordPress/gutenberg/pull/56694)
8
+
9
+ ## 1.10.0 (2023-11-29)
10
+
11
+ ### Enhancement
12
+
13
+ - Update `view.js` and `render.php` templates to the new `store()` API. [#56613](https://github.com/WordPress/gutenberg/pull/56613)
14
+
5
15
  ## 1.9.0 (2023-11-16)
6
16
 
7
17
  ## 1.8.0 (2023-11-02)
@@ -11,26 +11,30 @@
11
11
  * @see https://github.com/WordPress/gutenberg/blob/trunk/docs/reference-guides/block-api/block-metadata.md#render
12
12
  */
13
13
 
14
- $unique_id = uniqid( 'p-' );
14
+ // Generate unique id for aria-controls.
15
+ $unique_id = wp_unique_id( 'p-' );
16
+
17
+ // Enqueue the view file.
18
+ gutenberg_enqueue_module( '{{namespace}}-view' );
15
19
  ?>
16
20
 
17
21
  <div
18
22
  <?php echo get_block_wrapper_attributes(); ?>
19
- data-wp-interactive
20
- data-wp-context='{ "{{namespace}}": { "isOpen": false } }'
21
- data-wp-effect="effects.{{namespace}}.logIsOpen"
23
+ data-wp-interactive='{ "namespace": "{{namespace}}" }'
24
+ data-wp-context='{ "isOpen": false }'
25
+ data-wp-watch="callbacks.logIsOpen"
22
26
  >
23
27
  <button
24
- data-wp-on--click="actions.{{namespace}}.toggle"
25
- data-wp-bind--aria-expanded="context.{{namespace}}.isOpen"
26
- aria-controls="p-<?php echo esc_attr( $unique_id ); ?>"
28
+ data-wp-on--click="actions.toggle"
29
+ data-wp-bind--aria-expanded="context.isOpen"
30
+ aria-controls="<?php echo esc_attr( $unique_id ); ?>"
27
31
  >
28
32
  <?php esc_html_e( 'Toggle', '{{textdomain}}' ); ?>
29
33
  </button>
30
34
 
31
35
  <p
32
- id="p-<?php echo esc_attr( $unique_id ); ?>"
33
- data-wp-bind--hidden="!context.{{namespace}}.isOpen"
36
+ id="<?php echo esc_attr( $unique_id ); ?>"
37
+ data-wp-bind--hidden="!context.isOpen"
34
38
  >
35
39
  <?php
36
40
  esc_html_e( '{{title}} - hello from an interactive block!', '{{textdomain}}' );
@@ -1,26 +1,23 @@
1
1
  {{#isBasicVariant}}
2
-
3
2
  /**
4
3
  * WordPress dependencies
5
4
  */
6
- import { store } from "@wordpress/interactivity";
5
+ import { store, getContext } from "@wordpress/interactivity";
7
6
 
8
- store( {
7
+ store( '{{namespace}}', {
9
8
  actions: {
10
- '{{namespace}}': {
11
- toggle: ( { context } ) => {
12
- context[ '{{namespace}}' ].isOpen = !context[ '{{namespace}}' ].isOpen;
13
- },
9
+ toggle: () => {
10
+ const context = getContext();
11
+ context.isOpen = ! context.isOpen;
14
12
  },
15
13
  },
16
- effects: {
17
- '{{namespace}}': {
18
- logIsOpen: ( { context } ) => {
19
- // Log the value of `isOpen` each time it changes.
20
- console.log( `Is open: ${ context[ '{{namespace}}' ].isOpen }` );
21
- },
14
+ callbacks: {
15
+ logIsOpen: () => {
16
+ const { isOpen } = getContext();
17
+ // Log the value of `isOpen` each time it changes.
18
+ console.log( `Is open: ${ isOpen }` );
22
19
  },
23
20
  },
24
21
  } );
25
22
 
26
- {{/isBasicVariant}}
23
+ {{/isBasicVariant}}
package/index.js CHANGED
@@ -14,7 +14,6 @@ module.exports = {
14
14
  interactivity: true,
15
15
  },
16
16
  render: 'file:./render.php',
17
- viewScript: 'file:./view.js',
18
17
  example: {},
19
18
  },
20
19
  variants: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wordpress/create-block-interactive-template",
3
- "version": "1.9.0",
3
+ "version": "1.10.1",
4
4
  "description": "Template for @wordpress/create-block to create interactive blocks with the Interactivity API.",
5
5
  "author": "The WordPress Contributors",
6
6
  "license": "GPL-2.0-or-later",
@@ -22,5 +22,5 @@
22
22
  "publishConfig": {
23
23
  "access": "public"
24
24
  },
25
- "gitHead": "839018ff6029ba749780e288e08ff9cd898e50e8"
25
+ "gitHead": "12b897d7feff1cb00ddbf9016b62c1177d9c0081"
26
26
  }
@@ -43,5 +43,12 @@ if ( ! defined( 'ABSPATH' ) ) {
43
43
  */
44
44
  function {{namespaceSnakeCase}}_{{slugSnakeCase}}_block_init() {
45
45
  register_block_type( __DIR__ . '/build' );
46
+
47
+ gutenberg_register_module(
48
+ '{{namespace}}-view',
49
+ plugin_dir_url( __FILE__ ) . 'src/view.js',
50
+ array( '@wordpress/interactivity' ),
51
+ '{{version}}'
52
+ );
46
53
  }
47
54
  add_action( 'init', '{{namespaceSnakeCase}}_{{slugSnakeCase}}_block_init' );