From 82add5bfb8ce376f2cef79355235922387ee9609 Mon Sep 17 00:00:00 2001 From: jeremyfelt Date: Thu, 1 May 2025 06:02:37 -0700 Subject: [PATCH 1/3] Add toggle block to allowed blocks in navigation --- build/toggle-block/index.asset.php | 2 +- build/toggle-block/index.js | 2 +- src/toggle-block/extend-navigation-block.js | 27 +++++++++++++++++++++ src/toggle-block/index.js | 3 +++ 4 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 src/toggle-block/extend-navigation-block.js diff --git a/build/toggle-block/index.asset.php b/build/toggle-block/index.asset.php index 5bc1026..d9ab43d 100644 --- a/build/toggle-block/index.asset.php +++ b/build/toggle-block/index.asset.php @@ -1 +1 @@ - array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-i18n'), 'version' => '258f20c46a12ec82d3d1'); + array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-hooks', 'wp-i18n'), 'version' => '733fc54523ac610a70f9'); diff --git a/build/toggle-block/index.js b/build/toggle-block/index.js index 23e642b..c235890 100644 --- a/build/toggle-block/index.js +++ b/build/toggle-block/index.js @@ -1 +1 @@ -(()=>{"use strict";function t(){return t=Object.assign?Object.assign.bind():function(t){for(var e=1;e{"use strict";function t(){return t=Object.assign?Object.assign.bind():function(t){for(var e=1;et.length)&&(e=t.length);for(var r=0,o=Array(e);r { const { attributes: { bodyClass, buttonText, controlsId, labelText }, From 1a58fb48f3b81a9d30c68f5b0947e7d360fc67fc Mon Sep 17 00:00:00 2001 From: jeremyfelt Date: Thu, 1 May 2025 06:12:50 -0700 Subject: [PATCH 2/3] Allow a custom link to be transformed to a toggle block And vice versa, though the opposite kind of loses the text, or maybe assigns it to the wrong place? Fixes #3 --- build/toggle-block/index.asset.php | 2 +- build/toggle-block/index.js | 2 +- src/toggle-block/index.js | 36 +++++++++++++++++++++++++++++- 3 files changed, 37 insertions(+), 3 deletions(-) diff --git a/build/toggle-block/index.asset.php b/build/toggle-block/index.asset.php index d9ab43d..2bcab52 100644 --- a/build/toggle-block/index.asset.php +++ b/build/toggle-block/index.asset.php @@ -1 +1 @@ - array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-hooks', 'wp-i18n'), 'version' => '733fc54523ac610a70f9'); + array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-hooks', 'wp-i18n'), 'version' => 'd9fa622ec5870b26d6be'); diff --git a/build/toggle-block/index.js b/build/toggle-block/index.js index c235890..ab068b8 100644 --- a/build/toggle-block/index.js +++ b/build/toggle-block/index.js @@ -1 +1 @@ -(()=>{"use strict";function t(){return t=Object.assign?Object.assign.bind():function(t){for(var e=1;et.length)&&(e=t.length);for(var r=0,o=Array(e);r{"use strict";function t(){return t=Object.assign?Object.assign.bind():function(t){for(var e=1;et.length)&&(e=t.length);for(var o=0,r=Array(e);o { ); }; +const Transforms = { + from: [ + { + type: 'block', + blocks: ['core/navigation-link'], + transform: (attributes, innerBlocks) => { + return createBlock( + 'happyprime/toggle-block', + { + buttonText: attributes.label || attributes.title || '', + }, + innerBlocks + ); + }, + }, + ], + to: [ + { + type: 'block', + blocks: ['core/navigation-link'], + transform: (attributes, innerBlocks) => { + return createBlock( + 'core/navigation-link', + { + label: attributes.buttonText || '', + url: '', + }, + innerBlocks + ); + }, + }, + ], +}; registerBlockType(metadata, { edit: Edit, save: Save, + transforms: Transforms, }); From 186e16668de2ae88aa43699bb3d71c6741ec1de3 Mon Sep 17 00:00:00 2001 From: jeremyfelt Date: Thu, 1 May 2025 06:16:55 -0700 Subject: [PATCH 3/3] Use a hash as the default custom link URL on transform Things get funky with the custom link if you try to have one with an empty string. --- build/toggle-block/index.asset.php | 2 +- build/toggle-block/index.js | 2 +- src/toggle-block/index.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/build/toggle-block/index.asset.php b/build/toggle-block/index.asset.php index 2bcab52..f9ecafe 100644 --- a/build/toggle-block/index.asset.php +++ b/build/toggle-block/index.asset.php @@ -1 +1 @@ - array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-hooks', 'wp-i18n'), 'version' => 'd9fa622ec5870b26d6be'); + array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-hooks', 'wp-i18n'), 'version' => '1b8472592ef953dd9320'); diff --git a/build/toggle-block/index.js b/build/toggle-block/index.js index ab068b8..b78a411 100644 --- a/build/toggle-block/index.js +++ b/build/toggle-block/index.js @@ -1 +1 @@ -(()=>{"use strict";function t(){return t=Object.assign?Object.assign.bind():function(t){for(var e=1;et.length)&&(e=t.length);for(var o=0,r=Array(e);o{"use strict";function t(){return t=Object.assign?Object.assign.bind():function(t){for(var e=1;et.length)&&(e=t.length);for(var o=0,r=Array(e);o