Skip to content

Commit

Permalink
Set default blocks as default attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
George Hotelling committed Mar 16, 2020
1 parent 8018ef7 commit 0a4058f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 17 deletions.
23 changes: 18 additions & 5 deletions packages/block-library/src/query/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,24 @@
"type": "array",
"default": [
{
"isValid": true,
"clientId": null,
"name": "post-title",
"attributes": {},
"innerBlocks": []
"name": "core/post-title",
"innerBlocks": [],
"isValid": true
},
{
"name": "core/post-date",
"innerBlocks": [],
"isValid": true
},
{
"name": "core/post-author",
"innerBlocks": [],
"isValid": true
},
{
"name": "core/post-excerpt",
"innerBlocks": [],
"isValid": true
}
]
}
Expand Down
14 changes: 2 additions & 12 deletions packages/block-library/src/query/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,12 @@ import {
InspectorControls,
WritingFlow,
} from '@wordpress/block-editor';
import { cloneBlock, createBlock } from '@wordpress/blocks';
import { cloneBlock } from '@wordpress/blocks';
import { PanelBody, Placeholder, Spinner } from '@wordpress/components';
import { compose } from '@wordpress/compose';
import { EntityProvider } from '@wordpress/core-data';
import { withSelect } from '@wordpress/data';

const defaultFields = [
'core/post-title',
'core/post-date',
'core/post-author',
'core/post-excerpt',
];

class Edit extends Component {
constructor( props ) {
super( props );
Expand All @@ -49,7 +42,6 @@ class Edit extends Component {

componentDidMount() {
this.createBlockTree();
this.updateBlocks( defaultFields.map( ( f ) => createBlock( f ) ) );
}

componentDidUpdate( prevProps ) {
Expand All @@ -69,9 +61,7 @@ class Edit extends Component {
[ post.id ]:
post.id === editingPost
? blocksTree[ post.id ]
: blocks.map( ( block ) =>
cloneBlock( block, { post } )
),
: blocks.map( ( block ) => cloneBlock( block ) ),
} ),
{}
);
Expand Down

0 comments on commit 0a4058f

Please sign in to comment.