diff --git a/blocks/library/shortcode/block.js b/blocks/library/shortcode/block.js
new file mode 100644
index 0000000000000..621ec1213e68d
--- /dev/null
+++ b/blocks/library/shortcode/block.js
@@ -0,0 +1,74 @@
+/**
+ * WordPress dependencies
+ */
+import { withInstanceId, Dashicon } from '@wordpress/components';
+import { Component } from '@wordpress/element';
+import { __ } from '@wordpress/i18n';
+
+/**
+ * Internal dependencies
+ */
+import ShortcodePreview from './preview';
+import BlockControls from '../../block-controls';
+import PlainText from '../../plain-text';
+
+export class Shortcode extends Component {
+ constructor() {
+ super();
+ this.state = {
+ preview: false,
+ };
+ }
+
+ render() {
+ const { preview } = this.state;
+ const { instanceId, postId, setAttributes, attributes, isSelected } = this.props;
+ const inputId = `blocks-shortcode-input-${ instanceId }`;
+ const shortcodeContent = ( attributes.text || '' ).trim();
+
+ const controls = isSelected && (
+
+
+
+
+
+
+ );
+
+ if ( preview ) {
+ return [
+ controls,
+ ,
+ ];
+ }
+
+ return [
+ controls,
+
+
+
setAttributes( { text } ) }
+ />
+ ,
+ ];
+ }
+}
+
+export default withInstanceId( Shortcode );
diff --git a/blocks/library/shortcode/index.js b/blocks/library/shortcode/index.js
index 4f95bf4acc8bc..18e284b4ae969 100644
--- a/blocks/library/shortcode/index.js
+++ b/blocks/library/shortcode/index.js
@@ -3,13 +3,12 @@
*/
import { RawHTML } from '@wordpress/element';
import { __ } from '@wordpress/i18n';
-import { withInstanceId, Dashicon } from '@wordpress/components';
/**
* Internal dependencies
*/
import './editor.scss';
-import PlainText from '../../plain-text';
+import Shortcode from './block';
export const name = 'core/shortcode';
@@ -60,27 +59,7 @@ export const settings = {
html: false,
},
- edit: withInstanceId(
- ( { attributes, setAttributes, instanceId } ) => {
- const inputId = `blocks-shortcode-input-${ instanceId }`;
-
- return (
-
-
-
setAttributes( { text } ) }
- />
-
- );
- }
- ),
+ edit: Shortcode,
save( { attributes } ) {
return { attributes.text };
diff --git a/blocks/library/shortcode/preview.js b/blocks/library/shortcode/preview.js
new file mode 100644
index 0000000000000..28feb4e44300f
--- /dev/null
+++ b/blocks/library/shortcode/preview.js
@@ -0,0 +1,53 @@
+/**
+ * External dependencies
+ */
+import { connect } from 'react-redux';
+
+/**
+ * WordPress dependencies
+ */
+import { withAPIData, Spinner, SandBox } from '@wordpress/components';
+import { __ } from '@wordpress/i18n';
+import { compose } from '@wordpress/element';
+
+function ShortcodePreview( { response } ) {
+ if ( response.isLoading || ! response.data ) {
+ return (
+
+
+
{ __( 'Loading...' ) }
+
+ );
+ }
+
+ const html = response.data.head_scripts_styles + ' ' + response.data.html + ' ' + response.data.footer_scripts_styles;
+ return (
+
+ );
+}
+
+const applyConnect = connect(
+ ( state ) => {
+ return {
+ postId: state.currentPost.id,
+ };
+ },
+);
+
+const applyWithAPIData = withAPIData( ( props ) => {
+ const { shortcode, postId } = props;
+ return {
+ response: `/gutenberg/v1/shortcodes?shortcode=${ encodeURIComponent( shortcode ) }&postId=${ postId }`,
+ };
+} );
+
+export default compose( [
+ applyConnect,
+ applyWithAPIData,
+] )( ShortcodePreview );
diff --git a/blocks/library/shortcode/test/index.js b/blocks/library/shortcode/test/index.js
index 5892b6e57a1ad..6c56ce58218f8 100644
--- a/blocks/library/shortcode/test/index.js
+++ b/blocks/library/shortcode/test/index.js
@@ -7,7 +7,6 @@ import { blockEditRender } from 'blocks/test/helpers';
describe( 'core/shortcode', () => {
test( 'block edit matches snapshot', () => {
const wrapper = blockEditRender( name, settings );
-
expect( wrapper ).toMatchSnapshot();
} );
} );
diff --git a/components/sandbox/index.js b/components/sandbox/index.js
index 840bbaa94f721..ffddaa4c115f9 100644
--- a/components/sandbox/index.js
+++ b/components/sandbox/index.js
@@ -136,12 +136,18 @@ class Sandbox extends Component {
body {
margin: 0;
}
+
+ body.html {
+ width: 100%;
+ }
+
body.video,
body.video > div,
body.video > div > iframe {
width: 100%;
height: 100%;
}
+
body > div > * {
margin-top: 0 !important; /* has to have !important to override inline styles */
margin-bottom: 0 !important;
@@ -157,8 +163,9 @@ class Sandbox extends Component {
-
+
+