PluginProbe
TablePress – Tables in WordPress made easy / 3.3.2
TablePress – Tables in WordPress made easy v3.3.2
3.3.4 3.3.3 3.3.2 3.3.1 trunk 1.12 1.14 1.9.2 2.0.4 2.1.7 2.1.8 2.2 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.3 2.3.1 2.3.2 2.4 2.4.1 2.4.2 2.4.3 2.4.4 All 44 releases
tablepress / admin / js / edit / table-preview.js

table-preview.js in TablePress – Tables in WordPress made easy 3.3.2, at admin/js/edit/table-preview.js

62 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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