-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add block to represent unregistered block types
- Loading branch information
1 parent
2d338db
commit 4518c16
Showing
22 changed files
with
415 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
.editor-block-list__block[data-type="core/missing"] { | ||
.editor-warning { | ||
position: static; | ||
|
||
// Round corners for a better visual separation between the warning border | ||
// and the unrounded corners of the selected block outline. | ||
border-radius: 4px; | ||
} | ||
|
||
.editor-warning__contents { | ||
// Ensure action buttons display on the same line as the text. | ||
flex-wrap: nowrap; | ||
align-items: flex-start; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
import { RawHTML } from '@wordpress/element'; | ||
|
||
/** | ||
* Internal dependencies. | ||
*/ | ||
import MissingBlockWarning from './missing-block-warning'; | ||
import './editor.scss'; | ||
|
||
export const name = 'core/missing'; | ||
|
||
export const settings = { | ||
name, | ||
category: 'common', | ||
title: __( 'Missing Block' ), | ||
|
||
supports: { | ||
className: false, | ||
customClassName: false, | ||
inserter: false, | ||
html: false, | ||
preserveOriginalContent: true, | ||
}, | ||
|
||
attributes: { | ||
originalName: { | ||
type: 'string', | ||
}, | ||
originalUndelimitedContent: { | ||
type: 'string', | ||
}, | ||
originalContent: { | ||
type: 'string', | ||
source: 'html', | ||
}, | ||
}, | ||
|
||
edit: MissingBlockWarning, | ||
save( { attributes } ) { | ||
// Preserve the missing block's content. | ||
return <RawHTML>{ attributes.originalContent }</RawHTML>; | ||
}, | ||
}; |
62 changes: 62 additions & 0 deletions
62
packages/block-library/src/missing/missing-block-warning.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __, sprintf } from '@wordpress/i18n'; | ||
import { Button } from '@wordpress/components'; | ||
import { getBlockType, createBlock } from '@wordpress/blocks'; | ||
import { withSelect, withDispatch } from '@wordpress/data'; | ||
import { compose } from '@wordpress/compose'; | ||
import { Warning } from '@wordpress/editor'; | ||
|
||
export const name = 'core/unknown'; | ||
|
||
export function MissingBlockWarning( { attributes, convertToHTML } ) { | ||
const { originalName, originalUndelimitedContent } = attributes; | ||
const hasContent = !! originalUndelimitedContent; | ||
const hasHTMLBlock = getBlockType( 'core/html' ); | ||
|
||
const actions = []; | ||
let messageHTML; | ||
if ( hasContent && hasHTMLBlock ) { | ||
actions.push( | ||
<Button key="convert" onClick={ convertToHTML } isLarge isPrimary> | ||
{ __( 'HTML Block' ) } | ||
</Button> | ||
); | ||
messageHTML = sprintf( | ||
__( 'Your site doesn\'t include support for the <code>%s</code> block. You can leave this block intact, convert its content to a Custom HTML block, or remove it entirely.' ), | ||
originalName | ||
); | ||
} else { | ||
messageHTML = sprintf( | ||
__( 'Your site doesn\'t include support for the <code>%s</code> block. You can leave this block intact or remove it entirely.' ), | ||
originalName | ||
); | ||
} | ||
|
||
return ( | ||
<Warning actions={ actions }> | ||
<span dangerouslySetInnerHTML={ { __html: messageHTML } } /> | ||
</Warning> | ||
); | ||
} | ||
|
||
export default compose( [ | ||
withSelect( ( select, { clientId } ) => { | ||
const { getBlock } = select( 'core/editor' ); | ||
return { | ||
block: getBlock( clientId ), | ||
}; | ||
} ), | ||
withDispatch( ( dispatch, { block, attributes } ) => { | ||
const { replaceBlock } = dispatch( 'core/editor' ); | ||
return { | ||
convertToHTML() { | ||
replaceBlock( block.clientId, createBlock( 'core/html', { | ||
content: attributes.originalUndelimitedContent, | ||
} ) ); | ||
}, | ||
}; | ||
} ), | ||
] )( MissingBlockWarning ); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.