-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
TinyMCE per block: Adding a simple embed block #181
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Large diffs are not rendered by default.
Oops, something went wrong.
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,19 @@ | ||
.embed-block__form textarea, .embed-block__form .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; | ||
} | ||
} | ||
|
||
.embed-block__content iframe { | ||
width: 100%; | ||
} |
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,51 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { createElement, Component } from 'wp-elements'; | ||
|
||
import { EnhancedInputComponent } from 'wp-blocks'; | ||
import BlockArrangement from 'controls/block-arrangement'; | ||
import { getEmbedHtmlFromUrl } from '../../utils/embed'; | ||
|
||
export default class EmbedBlockForm extends Component { | ||
merge = () => { | ||
this.props.remove(); | ||
}; | ||
|
||
bindInput = ( ref ) => { | ||
this.input = ref; | ||
}; | ||
|
||
render() { | ||
const { block, isFocused, change, moveUp, moveDown, remove, focusConfig, focus } = this.props; | ||
|
||
const removePrevious = () => { | ||
if ( ! block.url ) { | ||
remove(); | ||
} | ||
}; | ||
|
||
const html = getEmbedHtmlFromUrl( block.url ); | ||
console.log( html ); | ||
|
||
return ( | ||
<div> | ||
{ isFocused && <BlockArrangement block={ block } /> } | ||
<div className="embed-block__form"> | ||
<div className="embed-block__content" dangerouslySetInnerHTML={ { __html: html } } /> | ||
<EnhancedInputComponent | ||
ref={ this.bindInput } | ||
moveUp={ moveUp } | ||
removePrevious={ removePrevious } | ||
moveDown={ moveDown } | ||
value={ block.url } | ||
onChange={ ( value ) => change( { url: value } ) } | ||
focusConfig={ focusConfig } | ||
onFocusChange={ ( config ) => focus( config ) } | ||
placeholder="Enter an embed URL" | ||
/> | ||
</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,31 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { registerBlock } from 'wp-blocks'; | ||
import { VideoAlt3Icon } from 'dashicons'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import form from './form'; | ||
import { getEmbedHtmlFromUrl } from '../../utils/embed'; | ||
|
||
registerBlock( 'embed', { | ||
title: 'Embed', | ||
form: form, | ||
icon: VideoAlt3Icon, | ||
parse: ( rawBlock ) => { | ||
console.log( rawBlock ); | ||
return { | ||
blockType: 'embed', | ||
url: rawBlock.attrs.url, | ||
}; | ||
}, | ||
serialize: ( block ) => { | ||
return { | ||
blockType: 'embed', | ||
attrs: { url: block.url }, | ||
rawContent: getEmbedHtmlFromUrl( block.url ) | ||
}; | ||
} | ||
} ); |
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
13 changes: 13 additions & 0 deletions
13
tinymce-per-block/src/external/dashicons/icons/video-alt3.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,13 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { createElement } from 'wp-elements'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import createDashicon from '../create-dashicon'; | ||
|
||
export default createDashicon( | ||
<path d="M19 15v-10c0-1.1-0.9-2-2-2h-13c-1.1 0-2 0.9-2 2v10c0 1.1 0.9 2 2 2h13c1.1 0 2-0.9 2-2zM8 14v-8l6 4z"></path> | ||
); |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,18 @@ | ||
export const getEmbedHtmlFromUrl = ( url ) => { | ||
const getYoutubeId = ( youtubeUrl ) => { | ||
const regExp = /^.*(youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=|\&v=)([^#\&\?]*).*/; | ||
const match = youtubeUrl.match( regExp ); | ||
|
||
if ( match && match[ 2 ].length === 11 ) { | ||
return match[ 2 ]; | ||
} | ||
|
||
return false; | ||
}; | ||
|
||
const youtubeId = getYoutubeId( url ); | ||
return youtubeId | ||
? '<iframe width="560" height="315" src="//www.youtube.com/embed/' + | ||
youtubeId + '" frameborder="0" allowfullscreen></iframe>' | ||
: ''; | ||
}; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
@aduth I updated the markup because in static blocks, the markup should be the same as the output markup
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.
Hmm, this could have an interesting impact on oEmbeds in core though. Currently a post will store a link like this in its plain form (just the URL, not the frame) and fetch+cache the resulting embed at the time of content being rendered. This can be desirable in some cases to allow the embed provider to change their markup if need be and have it be reflected after a site's embed cache expires.
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.
Well! I assume this is the behavior of "dynamic" blocks, so I'm not agains considering the embed as a dynamic block. Which will be our first example of dynamic blocks