Skip to content

Commit cfb7275

Browse files
committed
fix: also apply default attribute to transform
1 parent 0aa58cc commit cfb7275

6 files changed

Lines changed: 66 additions & 35 deletions

File tree

‎src/block/heading/transforms.js‎

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,16 @@
33
*/
44
import { createBlock, createBlocksFromInnerBlocksTemplate } from '@wordpress/blocks'
55

6+
/**
7+
* External dependencies
8+
*/
9+
import { settings } from 'stackable'
10+
611
/**
712
* Internal dependencies
813
*/
914
import { TEMPLATE as ICON_LABEL_TEMPLATE } from '../icon-label/edit'
15+
import { getHeadingDefaultAttributes } from './util'
1016

1117
const transforms = {
1218
from: [
@@ -15,15 +21,21 @@ const transforms = {
1521
isMultiBlock: true,
1622
blocks: [ 'stackable/text' ],
1723
transform: attributes => {
18-
return attributes.map( ( { ...attrs } ) => createBlock( 'stackable/heading', { ...attrs } ) )
24+
return attributes.map( ( { ...attrs } ) => createBlock( 'stackable/heading', {
25+
...getHeadingDefaultAttributes( settings ),
26+
...attrs,
27+
} ) )
1928
},
2029
},
2130
{
2231
type: 'block',
2332
isMultiBlock: true,
2433
blocks: [ 'stackable/subtitle' ],
2534
transform: attributes => {
26-
return attributes.map( ( { ...attrs } ) => createBlock( 'stackable/heading', { ...attrs } ) )
35+
return attributes.map( ( { ...attrs } ) => createBlock( 'stackable/heading', {
36+
...getHeadingDefaultAttributes( settings ),
37+
...attrs,
38+
} ) )
2739
},
2840
},
2941
{
@@ -32,6 +44,7 @@ const transforms = {
3244
blocks: [ 'core/paragraph' ],
3345
transform: attributes => {
3446
return attributes.map( ( { content } ) => createBlock( 'stackable/heading', {
47+
...getHeadingDefaultAttributes( settings ),
3548
text: content,
3649
} ) )
3750
},
@@ -42,6 +55,7 @@ const transforms = {
4255
blocks: [ 'core/heading' ],
4356
transform: attributes => {
4457
return attributes.map( ( { content } ) => createBlock( 'stackable/heading', {
58+
...getHeadingDefaultAttributes( settings ),
4559
text: content,
4660
} ) )
4761
},

‎src/block/heading/util.js‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// This helper is called only by the inserter variation and explicit block
2+
// transforms. Parsed existing blocks and Design Library blocks do not call it.
3+
export const getHeadingDefaultAttributes = ( editorSettings = {} ) => {
4+
const isPost = editorSettings.stackable_current_post_type === 'post'
5+
6+
return {
7+
// Posts and non-post editor screens have separate admin defaults.
8+
useThemeTextMargins: isPost
9+
? !! editorSettings.stackable_enable_heading_default_theme_margins_posts
10+
: !! editorSettings.stackable_enable_heading_default_theme_margins_non_posts,
11+
}
12+
}

‎src/block/heading/variations.js‎

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,19 @@
33
*/
44
import { settings } from 'stackable'
55

6-
// Keep the admin default scoped to direct inserter creation. Parsed blocks and
7-
// blocks created by the Design Library do not apply inserter variations.
8-
export const getHeadingVariations = ( editorSettings = {} ) => {
9-
const isPost = editorSettings.stackable_current_post_type === 'post'
10-
const useThemeTextMargins = isPost
11-
? !! editorSettings.stackable_enable_heading_default_theme_margins_posts
12-
: !! editorSettings.stackable_enable_heading_default_theme_margins_non_posts
6+
/**
7+
* Internal dependencies
8+
*/
9+
import { getHeadingDefaultAttributes } from './util'
1310

14-
return [
15-
{
16-
name: 'default',
17-
isDefault: true,
18-
scope: [ 'inserter' ],
19-
attributes: {
20-
useThemeTextMargins,
21-
},
22-
},
23-
]
24-
}
11+
// Scope this variation to direct inserter creation.
12+
export const getHeadingVariations = ( editorSettings = {} ) => [
13+
{
14+
name: 'default',
15+
isDefault: true,
16+
scope: [ 'inserter' ],
17+
attributes: getHeadingDefaultAttributes( editorSettings ),
18+
},
19+
]
2520

2621
export default getHeadingVariations( settings )

‎src/block/icon-list/transforms.js‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,15 @@ import {
66
create, split, toHTMLString,
77
} from '@wordpress/rich-text'
88

9+
/**
10+
* External dependencies
11+
*/
12+
import { settings } from 'stackable'
13+
914
/**
1015
* Internal dependencies
1116
*/
17+
import { getIconListDefaultAttributes } from './util'
1218

1319
// import { createListBlockFromDOMElement } from './util'
1420

@@ -69,6 +75,7 @@ const transforms = {
6975
return createBlock(
7076
'stackable/icon-list',
7177
{
78+
...getIconListDefaultAttributes( settings ),
7279
anchor: blockAttributes.anchor,
7380
},
7481
childBlocks
@@ -85,6 +92,7 @@ const transforms = {
8592
return createBlock(
8693
'stackable/icon-list',
8794
{
95+
...getIconListDefaultAttributes( settings ),
8896
anchor: blockAttributes.anchor,
8997
},
9098
childBlocks

‎src/block/icon-list/util.js‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@ import { i18n } from 'stackable'
1212
// The default icon list SVG.
1313
export const DEFAULT_SVG = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 190 190"><polygon points="173.8,28.4 60.4,141.8 15.7,97.2 5.1,107.8 60.4,163 184.4,39 173.8,28.4"/></svg>'
1414

15+
// This helper is called only by the inserter variation and explicit block
16+
// transforms. Parsed existing blocks and Design Library blocks do not call it.
17+
export const getIconListDefaultAttributes = ( editorSettings = {} ) => ( {
18+
// Preserve the original schema icon when no custom admin default is set.
19+
icon: editorSettings.stackable_icon_list_block_default_icon || DEFAULT_SVG,
20+
} )
21+
1522
export const IconSvgDef = props => {
1623
const { icon, uniqueId } = props
1724

‎src/block/icon-list/variations.js‎

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,16 @@ import { settings } from 'stackable'
66
/**
77
* Internal dependencies
88
*/
9-
import { DEFAULT_SVG } from './util'
9+
import { getIconListDefaultAttributes } from './util'
1010

11-
// Keep the admin default scoped to direct inserter creation. Parsed blocks and
12-
// blocks created by the Design Library do not apply inserter variations.
13-
export const getIconListVariations = ( editorSettings = {} ) => {
14-
return [
15-
{
16-
name: 'default',
17-
isDefault: true,
18-
scope: [ 'inserter' ],
19-
attributes: {
20-
icon: editorSettings.stackable_icon_list_block_default_icon || DEFAULT_SVG,
21-
},
22-
},
23-
]
24-
}
11+
// Scope this variation to direct inserter creation.
12+
export const getIconListVariations = ( editorSettings = {} ) => [
13+
{
14+
name: 'default',
15+
isDefault: true,
16+
scope: [ 'inserter' ],
17+
attributes: getIconListDefaultAttributes( editorSettings ),
18+
},
19+
]
2520

2621
export default getIconListVariations( settings )

0 commit comments

Comments
 (0)