2016-07-28 15:38:17 -07:00
|
|
|
import React from 'react'
|
|
|
|
|
|
|
|
/**
|
|
|
|
* An video embed component.
|
|
|
|
*
|
|
|
|
* @type {Component}
|
|
|
|
*/
|
|
|
|
|
|
|
|
class Video extends React.Component {
|
|
|
|
/**
|
|
|
|
* When the input text changes, update the `video` data on the node.
|
|
|
|
*
|
|
|
|
* @param {Event} e
|
|
|
|
*/
|
|
|
|
|
2018-02-06 23:12:00 +00:00
|
|
|
onChange = e => {
|
2016-07-28 15:38:17 -07:00
|
|
|
const video = e.target.value
|
2016-10-25 13:12:00 +02:00
|
|
|
const { node, editor } = this.props
|
2018-02-06 23:12:00 +00:00
|
|
|
editor.change(c => c.setNodeByKey(node.key, { data: { video } }))
|
2016-07-28 15:38:17 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* When clicks happen in the input, stop propagation so that the void node
|
|
|
|
* itself isn't focused, since that would unfocus the input.
|
|
|
|
*
|
|
|
|
* @type {Event} e
|
|
|
|
*/
|
|
|
|
|
2018-02-06 23:12:00 +00:00
|
|
|
onClick = e => {
|
2016-07-28 15:38:17 -07:00
|
|
|
e.stopPropagation()
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Render.
|
|
|
|
*
|
|
|
|
* @return {Element}
|
|
|
|
*/
|
|
|
|
|
2017-08-02 18:36:33 +02:00
|
|
|
render() {
|
2018-07-04 01:07:38 +02:00
|
|
|
const { isSelected } = this.props
|
|
|
|
|
2016-07-28 15:38:17 -07:00
|
|
|
return (
|
2016-08-04 14:12:27 -07:00
|
|
|
<div {...this.props.attributes}>
|
2016-07-28 15:38:17 -07:00
|
|
|
{this.renderVideo()}
|
2018-07-04 01:07:38 +02:00
|
|
|
{isSelected ? this.renderInput() : null}
|
2016-08-04 14:12:27 -07:00
|
|
|
</div>
|
2016-07-28 15:38:17 -07:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Render the Youtube iframe, responsively.
|
|
|
|
*
|
|
|
|
* @return {Element}
|
|
|
|
*/
|
|
|
|
|
|
|
|
renderVideo = () => {
|
2018-07-04 01:07:38 +02:00
|
|
|
const { node, isFocused } = this.props
|
2017-09-07 14:33:34 -07:00
|
|
|
const video = node.data.get('video')
|
2016-12-02 17:01:08 -08:00
|
|
|
|
2016-07-28 15:38:17 -07:00
|
|
|
const wrapperStyle = {
|
|
|
|
position: 'relative',
|
2018-07-04 01:07:38 +02:00
|
|
|
outline: isFocused ? '2px solid blue' : 'none',
|
2016-12-02 17:01:08 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
const maskStyle = {
|
2018-07-04 01:07:38 +02:00
|
|
|
display: isFocused ? 'none' : 'block',
|
2016-12-02 17:01:08 -08:00
|
|
|
position: 'absolute',
|
2017-09-12 17:51:26 +02:00
|
|
|
top: '0',
|
|
|
|
left: '0',
|
2016-12-02 17:01:08 -08:00
|
|
|
height: '100%',
|
2017-09-12 17:51:26 +02:00
|
|
|
width: '100%',
|
2016-12-02 17:01:08 -08:00
|
|
|
cursor: 'cell',
|
|
|
|
zIndex: 1,
|
2016-07-28 15:38:17 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
const iframeStyle = {
|
2018-02-06 23:12:00 +00:00
|
|
|
display: 'block',
|
2016-07-28 15:38:17 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div style={wrapperStyle}>
|
2016-12-02 17:01:08 -08:00
|
|
|
<div style={maskStyle} />
|
2016-07-28 15:38:17 -07:00
|
|
|
<iframe
|
|
|
|
id="ytplayer"
|
|
|
|
type="text/html"
|
|
|
|
width="640"
|
2017-09-12 17:51:26 +02:00
|
|
|
height="476"
|
2016-07-28 15:38:17 -07:00
|
|
|
src={video}
|
|
|
|
frameBorder="0"
|
|
|
|
style={iframeStyle}
|
2016-10-25 13:12:00 +02:00
|
|
|
/>
|
2016-07-28 15:38:17 -07:00
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Render the video URL input.
|
|
|
|
*
|
|
|
|
* @return {Element}
|
|
|
|
*/
|
|
|
|
|
|
|
|
renderInput = () => {
|
2017-09-07 14:33:34 -07:00
|
|
|
const { node } = this.props
|
|
|
|
const video = node.data.get('video')
|
2017-09-12 17:51:26 +02:00
|
|
|
const style = {
|
|
|
|
marginTop: '5px',
|
2018-02-06 23:12:00 +00:00
|
|
|
boxSizing: 'border-box',
|
2017-09-12 17:51:26 +02:00
|
|
|
}
|
|
|
|
|
2016-07-28 15:38:17 -07:00
|
|
|
return (
|
|
|
|
<input
|
|
|
|
value={video}
|
|
|
|
onChange={this.onChange}
|
|
|
|
onClick={this.onClick}
|
2017-09-12 17:51:26 +02:00
|
|
|
style={style}
|
2016-07-28 15:38:17 -07:00
|
|
|
/>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Export.
|
|
|
|
*/
|
|
|
|
|
|
|
|
export default Video
|