-
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
#8 Added ability to convert blocks to accordion items and back
- Loading branch information
Showing
11 changed files
with
80 additions
and
14 deletions.
There are no files selected for viewing
This file contains 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 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 +1 @@ | ||
<?php return array('dependencies' => array('wp-element', 'wp-polyfill'), 'version' => 'bd05025e0e1f34135f9be3977153795f'); | ||
<?php return array('dependencies' => array('wp-element', 'wp-polyfill'), 'version' => '41047dc9b2c0316e883f62232711ebaa'); |
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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 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 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 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 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 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,63 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
const { | ||
createBlock, | ||
} = wp.blocks; | ||
|
||
const { | ||
create, | ||
join, | ||
split, | ||
toHTMLString, | ||
} = wp.richText; | ||
|
||
|
||
|
||
export default { | ||
from: [ | ||
{ | ||
type: 'block', | ||
blocks: ['core/heading'], | ||
transform: (attributes) => { | ||
return createBlock('pb/accordion-item', { | ||
title: attributes.content, | ||
titleTag: 'h' + (attributes.level <= 4 ? attributes.level : 2), | ||
}); | ||
}, | ||
}, | ||
{ | ||
type: 'block', | ||
isMultiBlock: true, | ||
blocks: ['core/paragraph'], | ||
transform: (attributes) => { | ||
return createBlock('pb/accordion-item', {}, attributes.map( | ||
item => createBlock('core/paragraph', { | ||
content: item.content | ||
}) | ||
)); | ||
}, | ||
}, | ||
], | ||
to: [ | ||
{ | ||
type: 'block', | ||
blocks: ['core/paragraph'], | ||
transform: (attributes, innerBlocks) => { | ||
var newBlocks = innerBlocks.map(block => createBlock(block.name, block.attributes)); | ||
|
||
const level = attributes.titleTag !== 'button' ? | ||
parseInt(attributes.titleTag.replace('h', '')) : 2; | ||
|
||
newBlocks.splice(0, 0, createBlock('core/heading', { | ||
content: attributes.title, | ||
anchor: attributes.anchor, | ||
className: attributes.className, | ||
level: level, | ||
})); | ||
|
||
return newBlocks; | ||
}, | ||
}, | ||
], | ||
}; |