Skip to content

Commit 1119662

Browse files
committed
substitute: spacer, toc, testimonial, videoPopup
1 parent 1bd276b commit 1119662

File tree

6 files changed

+65
-4
lines changed

6 files changed

+65
-4
lines changed

src/block/design-library/edit.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,19 @@ const createBlockWithAttributes = ( blockName, attributes, innerBlocks, design )
4040
const traverseBlocksAndSubstitute = blocks => {
4141
return blocks.map( block => {
4242
let isDisabled = true
43+
// Maximum attempt to error if no substitution rule for the block
44+
let attempts = 10
4345

4446
// Check if the new substituted block is still disabled
45-
while ( isDisabled ) {
47+
while ( isDisabled && attempts > 0 ) {
4648
const previousBlockName = block[ 0 ]
4749
block = substituteCoreIfDisabled( ...block, substitutionRules )
4850
isDisabled = block[ 0 ] in disabledBlocks && disabledBlocks[ block[ 0 ] ] === BLOCK_STATE.DISABLED
49-
5051
// If the previous block is different from the new block, substitution has been made
5152
if ( ! hasSubstituted && previousBlockName !== block[ 0 ] ) {
5253
hasSubstituted = true
5354
}
55+
attempts--
5456
}
5557

5658
// Do a preorder traversal by subsituting first before traversing

src/block/spacer/substitute.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
export const substitute = {
2+
from: 'stackable/spacer',
3+
transform: oldAttributes => {
4+
return [
5+
'core/spacer',
6+
{
7+
height: `${ oldAttributes?.height ?? 50 }px`,
8+
},
9+
]
10+
},
11+
}
12+
13+
export default substitute
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
export const substitute = {
2+
from: 'stackable/table-of-contents',
3+
transform: oldAttributes => {
4+
return [
5+
'stackable/columns', { ...oldAttributes }, [
6+
[ 'stackable/column', {}, [
7+
[ 'stackable/text', { text: 'Table of Contents' } ],
8+
[ 'core/list', {}, [
9+
[ 'core/list-item', { content: 'First line of content' } ],
10+
[ 'core/list-item', { content: 'Second line of content' } ],
11+
[ 'core/list-item', { content: 'Third line of content' } ],
12+
] ],
13+
] ],
14+
],
15+
]
16+
},
17+
}
18+
19+
export default substitute
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
export const substitute = {
2+
from: 'stackable/testimonial',
3+
transform: ( oldAttributes, innerBlocks ) => {
4+
return [
5+
'stackable/columns',
6+
{
7+
...oldAttributes,
8+
},
9+
[ [ 'stackable/column', { hasContainer: true }, innerBlocks ] ],
10+
]
11+
},
12+
}
13+
14+
export default substitute

src/block/text/substitute.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ export const substitute = {
44
return [
55
'core/paragraph',
66
{
7-
content: oldAttributes.text,
8-
align: oldAttributes.contentAlign,
7+
content: oldAttributes?.text,
8+
align: oldAttributes?.contentAlign,
99
},
1010
]
1111
},
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
export const substitute = {
2+
from: 'stackable/video-popup',
3+
transform: oldAttributes => {
4+
return [
5+
'core/video',
6+
{
7+
src: oldAttributes?.oldAttributes,
8+
},
9+
]
10+
},
11+
}
12+
13+
export default substitute

0 commit comments

Comments
 (0)