Skip to content

Commit 34af17b

Browse files
authored
Merge pull request #28 from vektor-inc/add/wrap-unwrap
ラップ・アンラップする機能を追加
2 parents 757c718 + c2e1517 commit 34af17b

File tree

4 files changed

+48
-4
lines changed

4 files changed

+48
-4
lines changed

readme.txt

+4-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Tags: dynamic block, if, Conditional branch, Conditional Display, Custom Field,
44
Requires at least: 6.0
55
Tested up to: 6.2
66
Requires PHP: 7.4
7-
Stable tag: 0.4.3
7+
Stable tag: 0.5.0
88
License: GPLv2 or later
99
License URI: http://www.gnu.org/licenses/gpl-2.0.html
1010

@@ -35,6 +35,9 @@ However, by nesting Dynamic If Blocks, various conditional branching can be hand
3535

3636
== Changelog ==
3737

38+
= 0.5.0 =
39+
[ Add Function ]Added transforms settings to wrap and unwrap.
40+
3841
= 0.4.3 =
3942
* [ Bug fix ] Fixed bug in conditional branching based on custom field values
4043

src/index.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@ import {
88
ToggleControl
99
} from '@wordpress/components';
1010
import { ReactComponent as Icon } from './icon.svg';
11+
import transforms from './transforms';
1112

1213
registerBlockType('vk-blocks/dynamic-if', {
1314
apiVersion: 2,
1415
title: __('Dynamic If', 'vk-dynamic-if-block'),
1516
icon: <Icon />,
17+
transforms,
1618
category: 'theme',
1719
attributes: {
1820
ifPageType: {
@@ -155,4 +157,4 @@ registerBlockType('vk-blocks/dynamic-if', {
155157
save() {
156158
return <InnerBlocks.Content />;
157159
},
158-
});
160+
});

src/transforms.js

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/**
2+
* WordPress dependencies
3+
*/
4+
import { createBlock } from '@wordpress/blocks';
5+
6+
const transforms = {
7+
from: [
8+
{
9+
type: 'block',
10+
isMultiBlock: true,
11+
blocks: ['*'],
12+
__experimentalConvert(blocks) {
13+
// Clone the Blocks to be Grouped
14+
// Failing to create new block references causes the original blocks
15+
// to be replaced in the switchToBlockType call thereby meaning they
16+
// are removed both from their original location and within the
17+
// new group block.
18+
const groupInnerBlocks = blocks.map((block) => {
19+
return createBlock(
20+
block.name,
21+
block.attributes,
22+
block.innerBlocks
23+
);
24+
});
25+
26+
return createBlock('vk-blocks/dynamic-if', {}, groupInnerBlocks);
27+
},
28+
},
29+
],
30+
to: [
31+
{
32+
type: 'block',
33+
blocks: ['*'],
34+
transform: (attributes, innerBlocks) => innerBlocks,
35+
},
36+
],
37+
};
38+
39+
export default transforms;

vk-dynamic-if-block.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
* Description: A dynamic block displays its Inner Blocks based on specified conditions, such as whether the current page is the front page or a single post, the post type, or the value of a Custom Field.
66
* Author: Vektor,Inc.
77
* Author URI: https://vektor-inc.co.jp/en/
8-
* Version: 0.4.3
9-
* Stable tag: 0.4.3
8+
* Version: 0.5.0
9+
* Stable tag: 0.5.0
1010
* License: GPL-2.0-or-later
1111
* Text Domain: vk-dynamic-if-block
1212
*

0 commit comments

Comments
 (0)