-
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.
- Loading branch information
1 parent
a975273
commit d276d2d
Showing
11 changed files
with
264 additions
and
17 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
.editor-block-list__block[data-type="core/missing"] { | ||
.editor-warning { | ||
position: static; | ||
} | ||
} |
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,39 @@ | ||
/** | ||
* 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: { | ||
originalContent: { | ||
type: 'string', | ||
source: 'html', | ||
}, | ||
}, | ||
|
||
edit: MissingBlockWarning, | ||
save( { attributes } ) { | ||
return <RawHTML>{ attributes.originalContent }</RawHTML>; | ||
}, | ||
}; |
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,61 @@ | ||
/** | ||
* 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( { block, convertToHTML } ) { | ||
const hasContent = !! block.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 the block intact, convert its content to a Custom HTML block, or remove it entirely.' ), | ||
block.originalName | ||
); | ||
} else { | ||
messageHTML = sprintf( | ||
__( 'Your site doesn\'t include support for the <code>%s</code> block. You can leave the block intact or remove it entirely.' ), | ||
block.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 } ) => { | ||
const { replaceBlock } = dispatch( 'core/editor' ); | ||
return { | ||
convertToHTML() { | ||
replaceBlock( block.clientId, createBlock( 'core/html', { | ||
content: block.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
Oops, something went wrong.