-
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.
Editor: Add support for editing embeds inside a post
Fixes #1729
- Loading branch information
Showing
6 changed files
with
161 additions
and
0 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
33 changes: 33 additions & 0 deletions
33
client/components/tinymce/plugins/wpcom-view/views/embed/embed-dialog/docs/example.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,33 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import React, { PureComponent } from 'react'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import Button from 'components/button'; | ||
import Card from 'components/card'; | ||
import EmbedDialog from 'components/tinymce/plugins/wpcom-view/views/embed/embed-dialog/'; | ||
|
||
class EmbedDialogExample extends PureComponent { | ||
state = { showDialog: false }; | ||
|
||
openDialog = () => this.setState( { showDialog: true } ); | ||
handleClose = () => this.setState( { showDialog: false } ); | ||
|
||
render() { | ||
return ( | ||
<Card> | ||
<Button onClick={ this.openDialog }>Open Embed Dialog</Button> | ||
<EmbedDialog | ||
embedUrl={ 'https://youtube.com/watch/foo' } | ||
isVisible={ this.state.showDialog } | ||
onClose={ this.handleClose } | ||
/> | ||
</Card> | ||
); | ||
} | ||
} | ||
|
||
export default EmbedDialogExample; |
76 changes: 76 additions & 0 deletions
76
client/components/tinymce/plugins/wpcom-view/views/embed/embed-dialog/index.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,76 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import React, { Component, PropTypes } from 'react'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import Dialog from 'components/dialog'; | ||
import Button from 'components/button'; | ||
import FormTextInput from 'components/forms/form-text-input'; | ||
|
||
import EmbedView from 'components/tinymce/plugins/wpcom-view/views/embed/view'; | ||
import ResizableIframe from 'components/resizable-iframe'; | ||
|
||
class EmbedDialog extends Component { | ||
static propTypes = { | ||
isVisible: PropTypes.bool, | ||
embedUrl: PropTypes.string, | ||
}; | ||
|
||
static defaultProps = { | ||
isVisible: false, | ||
embedUrl: '', | ||
}; | ||
|
||
state = { | ||
embedUrl: this.props.embedUrl, | ||
}; | ||
|
||
onUpdateEmbed = ( event ) => { | ||
console.log('on update'); | ||
// set to state. this.embedUrl ? | ||
// update tinymce content w/ state.embedUrl & re-render the embed inside the tinymce component | ||
this.props.onClose(); | ||
}; | ||
|
||
onChangeEmbedUrl = ( event ) => { | ||
this.setState( { embedUrl: event.target.value } ); | ||
// re-reder preview - should happen automatically | ||
// need to debounce or something so not every single second | ||
}; | ||
|
||
render() { | ||
return ( | ||
<Dialog | ||
isVisible={ this.props.isVisible } | ||
onClose={ this.props.onClose } | ||
buttons={ [ | ||
<Button onClick={ this.props.onClose }> | ||
Cancel | ||
</Button>, | ||
<Button primary onClick={ this.onUpdateEmbed }> | ||
Update | ||
</Button> | ||
] } | ||
> | ||
<h3>Embed URL</h3> | ||
|
||
<FormTextInput | ||
defaultValue={ this.state.embedUrl } | ||
onChange={ this.onChangeEmbedUrl } | ||
/> | ||
|
||
<EmbedView src={ this.state.embedUrl } /> | ||
<ResizableIframe src={ this.state.embedUrl } frameBorder="0" seamless width="100%" /> | ||
</Dialog> | ||
); | ||
{/* security issue above with src="user input", need to use wpcom oembed provider whitelist. | ||
ALSO WANT iframe sandbox params etc? | ||
also need to transform to canonical embeddable URL. youtube will block main url via x-frame-options, have to use `/embed/{id}` url | ||
*/} | ||
} | ||
} | ||
|
||
export default EmbedDialog; |
Empty file.
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