-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Inline Images and Inline Blocks API #6959
Changes from all commits
8a75ebe
9f08a1f
280a33f
35071ec
91ede09
56c4043
013d2d3
7b3f099
043260c
0054f04
ebc5d75
689d79d
6fa4fcb
5eae85f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,6 +38,10 @@ | |
width: 100%; | ||
max-height: 100%; | ||
overflow: auto; | ||
|
||
img { | ||
display: inline; | ||
} | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,8 @@ import { withSelect, withDispatch } from '@wordpress/data'; | |
*/ | ||
import InserterMenu from './menu'; | ||
|
||
export { default as InserterResultsPortal } from './results-portal'; | ||
|
||
class Inserter extends Component { | ||
constructor() { | ||
super( ...arguments ); | ||
|
@@ -22,12 +24,6 @@ class Inserter extends Component { | |
onToggle( isOpen ) { | ||
const { onToggle } = this.props; | ||
|
||
if ( isOpen ) { | ||
this.props.showInsertionPoint(); | ||
} else { | ||
this.props.hideInsertionPoint(); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When you insert a block, the insertion point indicator is kept visible. I believe it has to do with these changes? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed |
||
|
||
// Surface toggle callback to parent component | ||
if ( onToggle ) { | ||
onToggle( isOpen ); | ||
|
@@ -101,8 +97,6 @@ export default compose( [ | |
}; | ||
} ), | ||
withDispatch( ( dispatch, ownProps ) => ( { | ||
showInsertionPoint: dispatch( 'core/editor' ).showInsertionPoint, | ||
hideInsertionPoint: dispatch( 'core/editor' ).hideInsertionPoint, | ||
onInsertBlock: ( item ) => { | ||
const { insertionPoint, selectedBlock } = ownProps; | ||
const { index, rootUID, layout } = insertionPoint; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,6 +37,7 @@ import './style.scss'; | |
import BlockPreview from '../block-preview'; | ||
import BlockTypesList from '../block-types-list'; | ||
import ChildBlocks from './child-blocks'; | ||
import InserterResultsPortal from './results-portal'; | ||
|
||
const MAX_SUGGESTED_ITEMS = 9; | ||
|
||
|
@@ -95,6 +96,12 @@ export class InserterMenu extends Component { | |
this.setState( { | ||
hoveredItem: item, | ||
} ); | ||
|
||
if ( item ) { | ||
this.props.showInsertionPoint(); | ||
} else { | ||
this.props.hideInsertionPoint(); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess the issue is that we need to |
||
} | ||
|
||
bindPanel( name ) { | ||
|
@@ -201,6 +208,8 @@ export class InserterMenu extends Component { | |
/> | ||
|
||
<div className="editor-inserter__results" ref={ this.inserterResults }> | ||
<InserterResultsPortal.Slot fillProps={ { filterValue } } /> | ||
|
||
<ChildBlocks | ||
rootUID={ rootUID } | ||
items={ childItems } | ||
|
@@ -275,6 +284,8 @@ export default compose( | |
} ), | ||
withDispatch( ( dispatch ) => ( { | ||
fetchSharedBlocks: dispatch( 'core/editor' ).fetchSharedBlocks, | ||
showInsertionPoint: dispatch( 'core/editor' ).showInsertionPoint, | ||
hideInsertionPoint: dispatch( 'core/editor' ).hideInsertionPoint, | ||
} ) ), | ||
withSpokenMessages, | ||
withInstanceId, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { createSlotFill, PanelBody } from '@wordpress/components'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import BlockTypesList from '../block-types-list'; | ||
import { searchItems } from './menu'; | ||
|
||
const { Fill, Slot } = createSlotFill( 'InserterResultsPortal' ); | ||
|
||
const InserterResultsPortal = ( { items, title, onSelect, onHover } ) => { | ||
return ( | ||
<Fill> | ||
{ ( { filterValue } ) => { | ||
const filteredItems = searchItems( items, filterValue ); | ||
|
||
if ( ! filteredItems.length ) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<PanelBody | ||
title={ title } | ||
> | ||
<BlockTypesList items={ filteredItems } onSelect={ onSelect } onHover={ onHover } /> | ||
</PanelBody> | ||
); | ||
} } | ||
</Fill> | ||
); | ||
}; | ||
|
||
InserterResultsPortal.Slot = Slot; | ||
|
||
export default InserterResultsPortal; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
.mce-content-body div.mce-resizehandle { | ||
border-radius: 50%; | ||
border: 2px solid $white; | ||
width: 15px !important; | ||
height: 15px !important; | ||
position: absolute; | ||
background: theme( primary ); | ||
padding: 0 3px 3px 0; | ||
box-sizing: border-box; | ||
cursor: se-resize; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import './editor.scss'; | ||
import MediaUpload from '../../../media-upload'; | ||
|
||
export const name = 'core/image'; | ||
|
||
export const settings = { | ||
id: 'image', | ||
|
||
title: __( 'Inline Image' ), | ||
|
||
type: 'image', | ||
|
||
icon: 'format-image', | ||
|
||
edit( { onSave } ) { | ||
return ( | ||
<MediaUpload | ||
type="image" | ||
onSelect={ ( media ) => onSave( media ) } | ||
onClose={ () => onSave( null ) } | ||
render={ ( { open } ) => { | ||
open(); | ||
return null; | ||
} } | ||
/> | ||
); | ||
}, | ||
|
||
save( { id, url, alt, width } ) { | ||
return ( | ||
<img | ||
className={ `wp-image-${ id }` } | ||
// set width in style attribute to prevent Block CSS from overriding it | ||
style={ { width: `${ Math.min( width, 150 ) }px` } } | ||
src={ url } | ||
alt={ alt } | ||
/> | ||
); | ||
}, | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import * as image from './image'; | ||
|
||
export { image }; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,6 +42,7 @@ import { pickAriaProps } from './aria'; | |
import patterns from './patterns'; | ||
import { withBlockEditContext } from '../block-edit/context'; | ||
import { domToFormat, valueToString } from './format'; | ||
import TokenUI from './tokens/ui'; | ||
|
||
const { BACKSPACE, DELETE, ENTER, rawShortcut } = keycodes; | ||
|
||
|
@@ -887,6 +888,12 @@ export class RichText extends Component { | |
{ formatToolbar } | ||
</div> | ||
) } | ||
{ isSelected && | ||
<TokenUI | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would a better name be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm also a bit torn on the module name There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, makes sense. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually |
||
editor={ this.editor } | ||
containerRef={ this.containerRef } | ||
/> | ||
} | ||
<Autocomplete onReplace={ this.props.onReplace } completers={ autocompleters }> | ||
{ ( { isExpanded, listBoxId, activeId } ) => ( | ||
<Fragment> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made this change to allow
null
values.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're changing existing functionality, though, right? We're no longer injecting
fillKey
in "regular" cases (function-as-child).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think I follow the purpose of this change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How so? There's still a key added. This change is needed because you can't return null when using the function. See https://github.com/WordPress/gutenberg/pull/6959/files#diff-8c9cd11f122f43914bc769f4ad5c36d9R21.