| 1 |
/** |
| 2 |
* JavaScript code for the "Edit" section integration of the "Table Preview". |
| 3 |
* |
| 4 |
* @package TablePress |
| 5 |
* @subpackage Views JavaScript |
| 6 |
* @author Tobias Bäthge |
| 7 |
* @since 3.1.0 |
| 8 |
*/ |
| 9 |
|
| 10 |
/** |
| 11 |
* WordPress dependencies. |
| 12 |
*/ |
| 13 |
import { |
| 14 |
Icon, |
| 15 |
Modal, |
| 16 |
} from '@wordpress/components'; |
| 17 |
import { __, sprintf } from '@wordpress/i18n'; |
| 18 |
|
| 19 |
/** |
| 20 |
* Internal dependencies. |
| 21 |
*/ |
| 22 |
import { initializeReactComponentInPortal } from '../common/react-loader'; |
| 23 |
import { TablePressIcon } from '../../img/tablepress-icon'; |
| 24 |
|
| 25 |
const Section = ( { screenData, updateScreenData, tableMeta } ) => { |
| 26 |
// Bail early if the current user can't preview the table or the preview is not open. |
| 27 |
if ( ! tp.screenOptions.currentUserCanPreviewTable || ! screenData.previewIsOpen ) { |
| 28 |
return <></>; |
| 29 |
} |
| 30 |
|
| 31 |
// Get the table name, and use "(no name)" if the table has no name. |
| 32 |
let tableName = tableMeta.name; |
| 33 |
if ( '' === tableName.trim() ) { |
| 34 |
tableName = __( '(no name)', 'tablepress' ); |
| 35 |
} |
| 36 |
|
| 37 |
/* translators: %1$s: Table name, %2$s: Table ID */ |
| 38 |
const title = sprintf( __( 'Preview of table “%1$s” (ID %2$s)', 'tablepress' ), tableName, tableMeta.id ); |
| 39 |
|
| 40 |
return ( |
| 41 |
<Modal |
| 42 |
icon={ <Icon icon={ TablePressIcon } size="36" style={ { display: 'flex', marginRight: '1rem' } } /> } |
| 43 |
title={ title } |
| 44 |
className="table-preview-modal" |
| 45 |
onRequestClose={ () => updateScreenData( { previewIsOpen: false, previewSrcDoc: '' } ) } |
| 46 |
size="fill" |
| 47 |
> |
| 48 |
<iframe |
| 49 |
title={ title } |
| 50 |
src={ '' === screenData.previewSrcDoc ? screenData.previewUrl : undefined } |
| 51 |
srcDoc={ '' !== screenData.previewSrcDoc ? screenData.previewSrcDoc : undefined } |
| 52 |
/> |
| 53 |
</Modal> |
| 54 |
); |
| 55 |
}; |
| 56 |
|
| 57 |
initializeReactComponentInPortal( |
| 58 |
'table-preview', |
| 59 |
'edit', |
| 60 |
Section, |
| 61 |
); |
| 62 |
|