Skip to content

Commit 1817b7f

Browse files
committed
fix: only apply template on first insert so unlocked changes persist on referesh
1 parent 783643d commit 1817b7f

4 files changed

Lines changed: 25 additions & 4 deletions

File tree

src/block/blockquote/edit.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ const Edit = props => {
103103

104104
<ContainerDiv className={ contentClassNames }>
105105
<InnerBlocks
106-
template={ TEMPLATE }
106+
template={ hasInnerBlocks ? undefined : TEMPLATE }
107107
templateLock="all"
108108
/>
109109
</ContainerDiv>

src/block/expand/edit.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import { InnerBlocks } from '@wordpress/block-editor'
3838
import { __ } from '@wordpress/i18n'
3939
import { addFilter } from '@wordpress/hooks'
4040
import { memo } from '@wordpress/element'
41+
import { useSelect } from '@wordpress/data'
4142

4243
const TEMPLATE = [
4344
[ 'stackable/text', {
@@ -70,6 +71,12 @@ const Edit = props => {
7071
} = props
7172

7273
const blockAlignmentClass = getAlignmentClasses( props.attributes )
74+
const { hasInnerBlocks } = useSelect( select => {
75+
const { getBlockOrder } = select( 'core/block-editor' )
76+
return {
77+
hasInnerBlocks: getBlockOrder( props.clientId ).length > 0,
78+
}
79+
}, [ props.clientId ] )
7380

7481
const blockClassNames = classnames( [
7582
className,
@@ -110,7 +117,7 @@ const Edit = props => {
110117
>
111118
<div className={ contentClassNames }>
112119
<InnerBlocks
113-
template={ TEMPLATE }
120+
template={ hasInnerBlocks ? undefined : TEMPLATE }
114121
templateLock="all"
115122
orientation="horizontal"
116123
/>

src/block/price/edit.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import { InnerBlocks } from '@wordpress/block-editor'
3636
import { __ } from '@wordpress/i18n'
3737
import { addFilter } from '@wordpress/hooks'
3838
import { memo } from '@wordpress/element'
39+
import { useSelect } from '@wordpress/data'
3940

4041
export const defaultIcon = '<svg data-prefix="fas" data-icon="play" class="svg-inline--fa fa-play fa-w-14" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512" aria-hidden="true"><path fill="currentColor" d="M424.4 214.7L72.4 6.6C43.8-10.3 0 6.1 0 47.9V464c0 37.5 40.7 60.1 72.4 41.3l352-208c31.4-18.5 31.5-64.1 0-82.6z"></path></svg>'
4142

@@ -59,6 +60,12 @@ const Edit = props => {
5960

6061
const rowClass = getRowClasses( attributes )
6162
const blockAlignmentClass = getAlignmentClasses( attributes )
63+
const { hasInnerBlocks } = useSelect( select => {
64+
const { getBlockOrder } = select( 'core/block-editor' )
65+
return {
66+
hasInnerBlocks: getBlockOrder( props.clientId ).length > 0,
67+
}
68+
}, [ props.clientId ] )
6269

6370
const blockClassNames = classnames( [
6471
className,
@@ -92,7 +99,7 @@ const Edit = props => {
9299
className={ blockClassNames }
93100
>
94101
<InnerBlocks
95-
template={ TEMPLATE }
102+
template={ hasInnerBlocks ? undefined : TEMPLATE }
96103
templateLock="all"
97104
/>
98105
</BlockDiv>

src/block/video-popup/edit.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ import { addFilter } from '@wordpress/hooks'
5353
import { memo } from '@wordpress/element'
5454
import { DateTimePicker } from '@wordpress/components'
5555
import { getSettings as getDateSettings } from '@wordpress/date'
56+
import { useSelect } from '@wordpress/data'
5657

5758
export const defaultIcon = '<svg data-prefix="fas" data-icon="play" class="svg-inline--fa fa-play fa-w-14" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512" aria-hidden="true"><path fill="currentColor" d="M424.4 214.7L72.4 6.6C43.8-10.3 0 6.1 0 47.9V464c0 37.5 40.7 60.1 72.4 41.3l352-208c31.4-18.5 31.5-64.1 0-82.6z"></path></svg>'
5859

@@ -80,6 +81,12 @@ const Edit = props => {
8081

8182
const rowClass = getRowClasses( attributes )
8283
const blockAlignmentClass = getAlignmentClasses( attributes )
84+
const { hasInnerBlocks } = useSelect( select => {
85+
const { getBlockOrder } = select( 'core/block-editor' )
86+
return {
87+
hasInnerBlocks: getBlockOrder( props.clientId ).length > 0,
88+
}
89+
}, [ props.clientId ] )
8390

8491
const blockClassNames = classnames( [
8592
className,
@@ -128,7 +135,7 @@ const Edit = props => {
128135
>
129136
<div className={ contentClassNames }>
130137
<InnerBlocks
131-
template={ TEMPLATE }
138+
template={ hasInnerBlocks ? undefined : TEMPLATE }
132139
templateLock="all"
133140
/>
134141
</div>

0 commit comments

Comments
 (0)