-
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
a7e203b
commit e0542af
Showing
9 changed files
with
133 additions
and
6 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
22 changes: 22 additions & 0 deletions
22
tinymce-per-block/src/blocks/image-caption-block/_style.scss
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,22 @@ | ||
.image-caption-block__display { | ||
display: block; | ||
max-width: 100%; | ||
} | ||
|
||
|
||
.image-caption-block__caption textarea, | ||
.image-caption-block__caption .textarea-mirror { | ||
margin-top: 10px; | ||
width: 100%; | ||
border: none; | ||
font: inherit; | ||
font-family: "Merriweather", serif; | ||
font-weight: 300; | ||
font-size: 14px; | ||
color: $gray-dark-300; | ||
resize: none; | ||
|
||
&:focus { | ||
outline: 0; | ||
} | ||
} |
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,71 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { createElement, Component } from 'wp-elements'; | ||
import { find } from 'lodash'; | ||
import { EnhancedInputComponent } from 'wp-blocks'; | ||
|
||
export default class ImageBlockForm extends Component { | ||
|
||
merge() { | ||
this.props.remove(); | ||
} | ||
|
||
focus( position ) { | ||
this.caption.focus( position ); | ||
} | ||
|
||
bindCaption = ( ref ) => { | ||
this.caption = ref; | ||
} | ||
|
||
render() { | ||
const { block: { attrs, children }, setAttributes, moveDown, moveUp, remove, appendBlock } = this.props; | ||
const image = find( children, ( { name } ) => 'img' === name ); | ||
if ( ! image ) { | ||
return null; | ||
} | ||
const caption = attrs.caption || ''; | ||
const removePrevious = () => { | ||
if ( ! caption ) { | ||
remove(); | ||
} | ||
}; | ||
const splitValue = ( left, right ) => { | ||
setAttributes( { caption: left } ); | ||
appendBlock( { | ||
type: 'WP_Block', | ||
blockType: 'paragraph', | ||
attrs: {}, | ||
startText: '<!-- wp:paragraph -->', | ||
endText: '<!-- /wp -->', | ||
rawContent: '<!-- wp:paragraph -->' + right + '<!-- /wp -->', | ||
children: [ { | ||
type: 'Text', | ||
value: right | ||
} ] | ||
} ); | ||
}; | ||
|
||
return ( | ||
<div> | ||
<img | ||
src={ image.attrs.src } | ||
className="image-caption-block__display" | ||
/> | ||
<div className="image-caption-block__caption"> | ||
<EnhancedInputComponent | ||
ref={ this.bindCaption } | ||
moveUp={ moveUp } | ||
removePrevious={ removePrevious } | ||
moveDown={ moveDown } | ||
splitValue={ splitValue } | ||
value={ caption } | ||
onChange={ ( value ) => setAttributes( { caption: value } ) } | ||
placeholder="Enter a caption" | ||
/> | ||
</div> | ||
</div> | ||
); | ||
} | ||
} |
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,16 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { registerBlock } from 'wp-blocks'; | ||
import { FormatImageIcon } from 'dashicons'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import form from './form'; | ||
|
||
registerBlock( 'imagecaption', { | ||
title: 'Image With Caption', | ||
icon: FormatImageIcon, | ||
form | ||
} ); |
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