-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8342 from Automattic/add/editor-video-view
Editor: Support VideoPress post-editor preview (via Shortcode component)
- Loading branch information
Showing
6 changed files
with
155 additions
and
11 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
70 changes: 70 additions & 0 deletions
70
client/components/tinymce/plugins/wpcom-view/resizable-view.jsx
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,70 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import React, { PropTypes } from 'react'; | ||
import PureComponent from 'react-pure-render/component'; | ||
|
||
export default function( Component ) { | ||
const componentName = Component.displayName || Component.name || ''; | ||
|
||
return class extends PureComponent { | ||
static displayName = `ResizableView(${ componentName })`; | ||
|
||
static propTypes = { | ||
onResize: PropTypes.func | ||
}; | ||
|
||
static defaultProps = { | ||
onResize: () => {} | ||
}; | ||
|
||
constructor() { | ||
super( ...arguments ); | ||
|
||
this.boundSetWrapperState = this.setWrapperState.bind( this ); | ||
this.state = { | ||
wrapper: null | ||
}; | ||
} | ||
|
||
setWrapperState( wrapper ) { | ||
if ( ! wrapper ) { | ||
return; | ||
} | ||
|
||
this.setState( { wrapper } ); | ||
this.disconnectObserver(); | ||
this.observer = new MutationObserver( this.props.onResize ); | ||
this.observer.observe( wrapper, { | ||
attributes: true, | ||
childList: true, | ||
subtree: true | ||
} ); | ||
} | ||
|
||
componentWillUnmount() { | ||
this.disconnectObserver(); | ||
} | ||
|
||
disconnectObserver() { | ||
if ( this.observer ) { | ||
this.observer.disconnect(); | ||
} | ||
} | ||
|
||
render() { | ||
let childProps; | ||
if ( this.state.wrapper ) { | ||
childProps = { | ||
width: this.state.wrapper.clientWidth | ||
}; | ||
} | ||
|
||
return ( | ||
<div ref={ this.boundSetWrapperState }> | ||
<Component { ...this.props } { ...childProps } /> | ||
</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
27 changes: 27 additions & 0 deletions
27
client/components/tinymce/plugins/wpcom-view/views/video/index.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,27 @@ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import ShortcodeUtils from 'lib/shortcode'; | ||
import VideoView from './view'; | ||
|
||
export function match( content ) { | ||
const nextMatch = ShortcodeUtils.next( 'wpvideo', content ); | ||
|
||
if ( nextMatch ) { | ||
return { | ||
index: nextMatch.index, | ||
content: nextMatch.content, | ||
options: { | ||
shortcode: nextMatch.shortcode | ||
} | ||
}; | ||
} | ||
} | ||
|
||
export function serialize( content ) { | ||
return encodeURIComponent( content ); | ||
} | ||
|
||
export function getComponent() { | ||
return VideoView; | ||
} |
44 changes: 44 additions & 0 deletions
44
client/components/tinymce/plugins/wpcom-view/views/video/view.jsx
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,44 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import React, { PropTypes } from 'react'; | ||
import { connect } from 'react-redux'; | ||
import { merge } from 'lodash'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import resizableView from '../../resizable-view'; | ||
import { getSelectedSiteId } from 'state/ui/selectors'; | ||
import { stringify, parse } from 'lib/shortcode'; | ||
import Shortcode from 'components/shortcode'; | ||
|
||
function VideoView( { siteId, content, width } ) { | ||
if ( ! siteId || ! width ) { | ||
return null; | ||
} | ||
|
||
const shortcode = stringify( merge( { | ||
attrs: { | ||
named: { | ||
w: width | ||
} | ||
} | ||
}, parse( content ) ) ); | ||
|
||
return ( | ||
<Shortcode { ...{ siteId, width } }> | ||
{ shortcode } | ||
</Shortcode> | ||
); | ||
} | ||
|
||
VideoView.propTypes = { | ||
siteId: PropTypes.number, | ||
content: PropTypes.string, | ||
width: PropTypes.number | ||
}; | ||
|
||
export default connect( ( state ) => ( { | ||
siteId: getSelectedSiteId( state ) | ||
} ) )( resizableView( VideoView ) ); |
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