Add tool selector option to iframe editor (#38686)
* Add tool selector option to iframe editor * Fix lint errors
This commit is contained in:
parent
d51f69d2d7
commit
3ad98ec8b4
|
@ -0,0 +1,4 @@
|
||||||
|
Significance: minor
|
||||||
|
Type: add
|
||||||
|
|
||||||
|
Add tool selector option to iframe editor
|
|
@ -4,10 +4,6 @@
|
||||||
import { useSelect } from '@wordpress/data';
|
import { useSelect } from '@wordpress/data';
|
||||||
import { useViewportMatch } from '@wordpress/compose';
|
import { useViewportMatch } from '@wordpress/compose';
|
||||||
import { __ } from '@wordpress/i18n';
|
import { __ } from '@wordpress/i18n';
|
||||||
import {
|
|
||||||
NavigableToolbar,
|
|
||||||
store as blockEditorStore,
|
|
||||||
} from '@wordpress/block-editor';
|
|
||||||
import { plus } from '@wordpress/icons';
|
import { plus } from '@wordpress/icons';
|
||||||
import {
|
import {
|
||||||
createElement,
|
createElement,
|
||||||
|
@ -17,6 +13,13 @@ import {
|
||||||
useContext,
|
useContext,
|
||||||
} from '@wordpress/element';
|
} from '@wordpress/element';
|
||||||
import { MouseEvent } from 'react';
|
import { MouseEvent } from 'react';
|
||||||
|
import {
|
||||||
|
NavigableToolbar,
|
||||||
|
store as blockEditorStore,
|
||||||
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||||
|
// @ts-ignore ToolSelector exists in WordPress components.
|
||||||
|
ToolSelector,
|
||||||
|
} from '@wordpress/block-editor';
|
||||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||||
// @ts-ignore ToolbarItem exists in WordPress components.
|
// @ts-ignore ToolbarItem exists in WordPress components.
|
||||||
// eslint-disable-next-line @woocommerce/dependency-group
|
// eslint-disable-next-line @woocommerce/dependency-group
|
||||||
|
@ -33,8 +36,9 @@ export function HeaderToolbar() {
|
||||||
const { isInserterOpened, setIsInserterOpened } =
|
const { isInserterOpened, setIsInserterOpened } =
|
||||||
useContext( EditorContext );
|
useContext( EditorContext );
|
||||||
const isWideViewport = useViewportMatch( 'wide' );
|
const isWideViewport = useViewportMatch( 'wide' );
|
||||||
|
const isLargeViewport = useViewportMatch( 'medium' );
|
||||||
const inserterButton = useRef< HTMLButtonElement | null >( null );
|
const inserterButton = useRef< HTMLButtonElement | null >( null );
|
||||||
const { isInserterEnabled } = useSelect( ( select ) => {
|
const { isInserterEnabled, isTextModeEnabled } = useSelect( ( select ) => {
|
||||||
const {
|
const {
|
||||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||||
// @ts-ignore These selectors are available in the block data store.
|
// @ts-ignore These selectors are available in the block data store.
|
||||||
|
@ -45,9 +49,13 @@ export function HeaderToolbar() {
|
||||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||||
// @ts-ignore These selectors are available in the block data store.
|
// @ts-ignore These selectors are available in the block data store.
|
||||||
getBlockSelectionEnd,
|
getBlockSelectionEnd,
|
||||||
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||||
|
// @ts-ignore These selectors are available in the block data store.
|
||||||
|
__unstableGetEditorMode: getEditorMode,
|
||||||
} = select( blockEditorStore );
|
} = select( blockEditorStore );
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
isTextModeEnabled: getEditorMode() === 'text',
|
||||||
isInserterEnabled: hasInserterItems(
|
isInserterEnabled: hasInserterItems(
|
||||||
getBlockRootClientId( getBlockSelectionEnd() )
|
getBlockRootClientId( getBlockSelectionEnd() )
|
||||||
),
|
),
|
||||||
|
@ -98,6 +106,12 @@ export function HeaderToolbar() {
|
||||||
/>
|
/>
|
||||||
{ isWideViewport && (
|
{ isWideViewport && (
|
||||||
<>
|
<>
|
||||||
|
{ isLargeViewport && (
|
||||||
|
<ToolbarItem
|
||||||
|
as={ ToolSelector }
|
||||||
|
disabled={ isTextModeEnabled }
|
||||||
|
/>
|
||||||
|
) }
|
||||||
<ToolbarItem as={ EditorHistoryUndo } />
|
<ToolbarItem as={ EditorHistoryUndo } />
|
||||||
<ToolbarItem as={ EditorHistoryRedo } />
|
<ToolbarItem as={ EditorHistoryRedo } />
|
||||||
</>
|
</>
|
||||||
|
|
Loading…
Reference in New Issue