/** * JavaScript code for the "Edit" section integration of the "Table Manipulation" buttons. * * @package TablePress * @subpackage Views JavaScript * @author Tobias Bäthge * @since 3.0.0 */ /** * WordPress dependencies. */ import { useState } from 'react'; import { Button, __experimentalHStack as HStack, // eslint-disable-line @wordpress/no-unsafe-wp-apis __experimentalNumberControl as NumberControl, // eslint-disable-line @wordpress/no-unsafe-wp-apis __experimentalVStack as VStack, // eslint-disable-line @wordpress/no-unsafe-wp-apis } from '@wordpress/components'; import { createInterpolateElement, RawHTML } from '@wordpress/element'; import { __, sprintf } from '@wordpress/i18n'; import { displayShortcut, shortcutAriaLabel } from '@wordpress/keycodes'; /** * Internal dependencies. */ import { initializeReactComponentInPortal } from '../common/react-loader'; import { Alert } from '../common/alert'; import { HelpBox } from '../common/help'; const Section = () => { const [ columnsAppendNumber, setColumnsAppendNumber ] = useState( 1 ); const [ rowsAppendNumber, setRowsAppendNumber ] = useState( 1 ); const [ alertMoveInvalidIsShown, setAlertMoveInvalidIsShown ] = useState( false ); const [ alertDeleteRowsInvalidIsShown, setAlertDeleteRowsInvalidIsShown ] = useState( false ); const [ alertDeleteColumnsInvalidIsShown, setAlertDeleteColumnsInvalidIsShown ] = useState( false ); const move = ( direction, type ) => { if ( ! tp.helpers.move_allowed( type, direction ) ) { setAlertMoveInvalidIsShown( true ); return; } tp.callbacks.move( direction, type ); }; const remove = ( type ) => { const handlingRows = ( 'rows' === type ); const numRoCs = handlingRows ? tp.editor.options.data.length : tp.editor.options.columns.length; if ( numRoCs === tp.helpers.selection[ type ].length ) { if ( handlingRows ) { setAlertDeleteRowsInvalidIsShown( true ); } else { setAlertDeleteColumnsInvalidIsShown( true ); } return; } tp.callbacks.remove( type ); }; return (
{ __( 'Selected cells', 'tablepress' ) }: { __( 'Selected cells', 'tablepress' ) }:
{ __( 'Selected rows', 'tablepress' ) }: { __( 'Selected columns', 'tablepress' ) }:
{ __( 'Selected rows', 'tablepress' ) }: { __( 'Selected columns', 'tablepress' ) }:
{ __( 'Selected rows', 'tablepress' ) }: { __( 'Selected columns', 'tablepress' ) }:
{ alertMoveInvalidIsShown && ( setAlertMoveInvalidIsShown( false ) } modalProps={ { size: 'small', } } /> ) } { alertDeleteRowsInvalidIsShown && ( setAlertDeleteRowsInvalidIsShown( false ) } /> ) } { alertDeleteColumnsInvalidIsShown && ( setAlertDeleteColumnsInvalidIsShown( false ) } /> ) }
); }; initializeReactComponentInPortal( 'table-manipulation', 'edit', Section, );