Skip to content

Commit 76e9075

Browse files
committed
feat: restructured substitute transform to separate files per block
1 parent e1ea223 commit 76e9075

File tree

12 files changed

+99
-0
lines changed

12 files changed

+99
-0
lines changed

src/block/button-group/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import metadata from './block.json'
1616
import variations from './variations'
1717
import deprecated from './deprecated'
1818
import { buttonExample } from './example'
19+
import substitute from './substitute'
1920

2021
/**
2122
* WordPress dependencies
@@ -40,4 +41,5 @@ export const settings = {
4041
example: buttonExample,
4142
edit,
4243
save,
44+
substitute,
4345
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { BLOCK_STATE } from '~stackable/util'
2+
3+
export const substitute = {
4+
from: 'stackable/button-group',
5+
variants: [ 'stackable/button-group|icon-button', 'stackable/button-group|button' ],
6+
to: [ 'core/buttons', 'core/social-links' ],
7+
transform: ( oldAttributes, innerBlocks, disabledBlocks ) => {
8+
if ( 'stackable/button-group|icon-button' in disabledBlocks && disabledBlocks[ 'stackable/button-group|icon-button' ] === BLOCK_STATE.DISABLED && // eslint-disable-line camelcase
9+
innerBlocks.length &&
10+
innerBlocks[ 0 ][ 0 ] === 'stackable/icon-button'
11+
) {
12+
return [ 'core/social-links',
13+
{ align: oldAttributes.contentAlign },
14+
[
15+
[ 'core/social-link', { service: 'facebook' } ],
16+
[ 'core/social-link', { service: 'twitter' } ],
17+
],
18+
]
19+
}
20+
if ( 'stackable/button-group|button' in disabledBlocks && disabledBlocks[ 'stackable/button-group|button' ] === BLOCK_STATE.DISABLED ) { // eslint-disable-line camelcase
21+
return [ 'core/buttons', {}, innerBlocks ]
22+
}
23+
},
24+
}
25+
26+
export default substitute

src/block/button/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import schema from './schema'
1111
import metadata from './block.json'
1212
import transforms from './transforms'
1313
import deprecated from './deprecated'
14+
import substitute from './substitute'
1415

1516
/**
1617
* External dependencies
@@ -36,4 +37,5 @@ export const settings = {
3637
example,
3738
edit,
3839
save,
40+
substitute,
3941
}

src/block/button/substitute.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { BLOCK_STATE } from '~stackable/util'
2+
3+
export const substitute = {
4+
from: 'stackable/button',
5+
variants: [ 'stackable/button-group|button' ],
6+
to: 'core/paragraph',
7+
transform: ( oldAttributes, innerBlocks, disabledBlocks ) => {
8+
if ( 'stackable/button-group|button' in disabledBlocks && disabledBlocks[ 'stackable/button-group|button' ] === BLOCK_STATE.DISABLED ) { // eslint-disable-line camelcase
9+
return [ 'core/button', {
10+
text: oldAttributes.text,
11+
} ]
12+
}
13+
},
14+
}
15+
16+
export default substitute

src/block/heading/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import schema from './schema'
1616
import metadata from './block.json'
1717
import example from './example'
1818
import deprecated from './deprecated'
19+
import substitute from './substitute'
1920

2021
export const settings = {
2122
...metadata,
@@ -41,4 +42,5 @@ export const settings = {
4142
( ( attributesToMerge.hasOwnProperty( 'content' ) ? attributesToMerge.content : attributesToMerge.text ) || '' ),
4243
}
4344
},
45+
substitute,
4446
}

src/block/heading/substitute.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
export const substitute = {
2+
from: 'stackable/heading',
3+
to: 'core/heading',
4+
transform: oldAttributes => {
5+
return {
6+
content: oldAttributes.text,
7+
level: oldAttributes.textTag ? Number( oldAttributes.textTag.replace( 'h', '' ) ) : 2,
8+
}
9+
},
10+
}
11+
12+
export default substitute

src/block/image/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import metadata from './block.json'
1717
import example from './example'
1818
import transforms from './transforms'
1919
import deprecated from './deprecated'
20+
import substitute from './substitute'
2021

2122
/**
2223
* WordPress dependencies
@@ -38,4 +39,5 @@ export const settings = {
3839
deprecated,
3940
edit,
4041
save,
42+
substitute,
4143
}

src/block/image/substitute.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
export const substitute = {
2+
from: 'stackable/image',
3+
to: 'core/image',
4+
transform: oldAttributes => {
5+
if ( oldAttributes ) {
6+
return { height: oldAttributes.imageHeight }
7+
}
8+
},
9+
}
10+
11+
export default substitute

src/block/subtitle/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import schema from './schema'
1616
import metadata from './block.json'
1717
import example from './example'
1818
import deprecated from './deprecated'
19+
import substitute from './substitute'
1920

2021
export const settings = {
2122
...metadata,
@@ -40,4 +41,5 @@ export const settings = {
4041
( ( attributesToMerge.hasOwnProperty( 'content' ) ? attributesToMerge.content : attributesToMerge.text ) || '' ),
4142
}
4243
},
44+
substitute,
4345
}

src/block/subtitle/substitute.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
export const substitute = {
2+
from: 'stackable/subtitle',
3+
to: 'core/paragraph',
4+
transform: oldAttributes => {
5+
return {
6+
content: oldAttributes.text,
7+
}
8+
},
9+
}
10+
11+
export default substitute

0 commit comments

Comments
 (0)