From 728f07a6183b6b7f3245a0c73642e86a7093eb63 Mon Sep 17 00:00:00 2001 From: George Stephanis Date: Fri, 4 Aug 2017 17:40:45 -0400 Subject: [PATCH 01/21] A good start maybe? --- modules/shortcodes/tweet.php | 58 ++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/modules/shortcodes/tweet.php b/modules/shortcodes/tweet.php index 9a6a679a8dbdc..d8c5e85918d47 100644 --- a/modules/shortcodes/tweet.php +++ b/modules/shortcodes/tweet.php @@ -17,6 +17,7 @@ */ add_shortcode( 'tweet', array( 'Jetpack_Tweet', 'jetpack_tweet_shortcode' ) ); +add_action( 'enqueue_block_editor_assets', array( 'Jetpack_Tweet', 'enqueue_block_editor_assets' ) ); class Jetpack_Tweet { @@ -142,4 +143,61 @@ static public function jetpack_tweet_shortcode_script() { } } + static public function enqueue_block_editor_assets() { + wp_enqueue_script( 'wp-blocks' ); + wp_enqueue_script( 'wp-i18n' ); + wp_enqueue_script( 'wp-element' ); + wp_enqueue_script( 'shortcode' ); + add_action( 'admin_print_footer_scripts', array( __CLASS__, 'admin_footer' ), 999 ); + } + + static public function admin_footer() { +?> + + Date: Fri, 4 Aug 2017 21:51:11 -0400 Subject: [PATCH 02/21] Correct how we refer to the tweet attribute. --- modules/shortcodes/tweet.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/shortcodes/tweet.php b/modules/shortcodes/tweet.php index d8c5e85918d47..487ab65f74ff0 100644 --- a/modules/shortcodes/tweet.php +++ b/modules/shortcodes/tweet.php @@ -176,7 +176,7 @@ static public function admin_footer() { { name : 'tweet', type : 'url', - value : props.tweet + value : props.attributes.tweet }, null ); @@ -188,7 +188,7 @@ static public function admin_footer() { attrs : { named : {}, numeric : [ - props.tweet + props.attributes.tweet ] } }); From b9da75c753701d38c53a46a25feb177ceb585554 Mon Sep 17 00:00:00 2001 From: George Stephanis Date: Fri, 4 Aug 2017 22:34:07 -0400 Subject: [PATCH 03/21] Update the prop when the field changes. Still not thrilled with this method. --- modules/shortcodes/tweet.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/modules/shortcodes/tweet.php b/modules/shortcodes/tweet.php index 487ab65f74ff0..55d7c8f9610b6 100644 --- a/modules/shortcodes/tweet.php +++ b/modules/shortcodes/tweet.php @@ -176,7 +176,12 @@ static public function admin_footer() { { name : 'tweet', type : 'url', - value : props.attributes.tweet + value : props.attributes.tweet, + onInput: function( event ) { + props.setAttributes({ + tweet: event.target.value + }); + } }, null ); From 1fbb0d4843681333d890d94e60ae1f4fcc4e351b Mon Sep 17 00:00:00 2001 From: George Stephanis Date: Fri, 4 Aug 2017 22:34:53 -0400 Subject: [PATCH 04/21] Add a dummy function to explore how we can parse this on initialization. --- modules/shortcodes/tweet.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/modules/shortcodes/tweet.php b/modules/shortcodes/tweet.php index 55d7c8f9610b6..97aa94a715e2f 100644 --- a/modules/shortcodes/tweet.php +++ b/modules/shortcodes/tweet.php @@ -167,7 +167,9 @@ static public function admin_footer() { category: 'layout', attributes : { - tweet : wp.blocks.query.query( 'input[name=tweet]').value + tweet : function ( node ) { + console.log( node ); + } }, edit : function( props ) { From 6817940b28fd178c106303f1439fc4d4930829ec Mon Sep 17 00:00:00 2001 From: George Stephanis Date: Sat, 5 Aug 2017 12:29:51 -0400 Subject: [PATCH 05/21] Somewhat tidier way of doing the script. This lets it be inline on the page, with the other scripts -- rather than printed at the very bottom. Leaving the `script` tags there but commented out so PHPStorm still syntax highlights it as js. --- modules/shortcodes/tweet.php | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/modules/shortcodes/tweet.php b/modules/shortcodes/tweet.php index 97aa94a715e2f..d9e22ff00283d 100644 --- a/modules/shortcodes/tweet.php +++ b/modules/shortcodes/tweet.php @@ -144,16 +144,23 @@ static public function jetpack_tweet_shortcode_script() { } static public function enqueue_block_editor_assets() { - wp_enqueue_script( 'wp-blocks' ); - wp_enqueue_script( 'wp-i18n' ); - wp_enqueue_script( 'wp-element' ); - wp_enqueue_script( 'shortcode' ); - add_action( 'admin_print_footer_scripts', array( __CLASS__, 'admin_footer' ), 999 ); + wp_register_script( + 'jetpack-shortcode-tweet-gutenberg', + null, + array( 'wp-blocks', 'wp-i18n', 'wp-element', 'shortcode' ) + ); + wp_enqueue_script( 'jetpack-shortcode-tweet-gutenberg' ); + + ob_start(); + self::jetpack_shortcode_tweet_gutenberg_script(); + $content = ob_get_clean(); + + wp_script_add_data( 'jetpack-shortcode-tweet-gutenberg', 'data', $content ); } - static public function admin_footer() { + static public function jetpack_shortcode_tweet_gutenberg_script() { ?> - +// Date: Mon, 7 Aug 2017 14:31:51 -0400 Subject: [PATCH 06/21] Clear out some unused chaff. --- modules/shortcodes/tweet.php | 6 ------ 1 file changed, 6 deletions(-) diff --git a/modules/shortcodes/tweet.php b/modules/shortcodes/tweet.php index d9e22ff00283d..2af1a96937ad3 100644 --- a/modules/shortcodes/tweet.php +++ b/modules/shortcodes/tweet.php @@ -162,12 +162,6 @@ static public function jetpack_shortcode_tweet_gutenberg_script() { ?> //