Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
34aa26e
Block Editor: Convert MediaUpload and MediaUploadCheck to TypeScript
manzoorwanijk Oct 15, 2026
71cf06f
Block Editor: Convert BlockTitle and useBlockDisplayTitle to TypeScript
manzoorwanijk Oct 15, 2026
66f4d84
Block Editor: Convert the BlockTitle tests to TypeScript
manzoorwanijk Oct 15, 2026
be82802
Block Editor: Convert useBlockDisplayInformation to TypeScript
manzoorwanijk Oct 15, 2026
dcd1256
Block Editor: Convert the useBlockDisplayInformation tests to TypeScript
manzoorwanijk Oct 15, 2026
489d00c
Block Editor: Convert BlockPopover to TypeScript
manzoorwanijk Oct 15, 2026
8aa50d1
Block Editor: Convert the color and gradient controls to TypeScript
manzoorwanijk Oct 15, 2026
7ecb2c6
Block Editor: Convert the color and gradient control tests to TypeScript
manzoorwanijk Oct 15, 2026
8aa48d3
Block Editor: Update the ESLint suppressions of the converted color a…
manzoorwanijk Oct 15, 2026
62a0f72
Block Editor: Prune the ESLint suppressions of the converted BlockPop…
manzoorwanijk Oct 15, 2026
6cfe5b7
Block Editor: Add the CHANGELOG entry for #84813
manzoorwanijk Oct 15, 2026
d106de5
Block Editor: Allow an absent neighboring block in BlockPopoverInbetween
manzoorwanijk Oct 15, 2026
ba2abaa
Block Editor: Let MediaUpload callers type the selected media
manzoorwanijk Oct 15, 2026
02617ea
Block Editor: Allow a null neighboring block in BlockPopoverInbetween
manzoorwanijk Oct 15, 2026
873ddcf
Block Editor: Convert the BlockPopover story to TypeScript
manzoorwanijk Oct 15, 2026
5600914
Block Editor: Update the ESLint suppressions of the converted BlockPo…
manzoorwanijk Oct 15, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/block-editor/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
- Convert the zoom out and content only section hooks to TypeScript ([#84731](https://github.com/WordPress/gutenberg/pull/84731)).
- Convert `BlockControls` to TypeScript ([#84733](https://github.com/WordPress/gutenberg/pull/84733)).
- Convert the flow layout to TypeScript ([#84734](https://github.com/WordPress/gutenberg/pull/84734)).
- Convert BlockPopover, the color and gradient controls, BlockTitle, useBlockDisplayInformation and MediaUpload to TypeScript ([#84813](https://github.com/WordPress/gutenberg/pull/84813)).

## 18.1.0 (2026-10-07)

Expand Down
2 changes: 1 addition & 1 deletion packages/block-editor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1126,7 +1126,7 @@ _Parameters_

_Returns_

- `?WPBlockDisplayInformation`: Block's display information, or `null` when the block or its type not found.
- `?BlockDisplayInformation`: Block's display information, or `null` when the block or its type not found.

### useBlockEditContext

Expand Down
1 change: 1 addition & 0 deletions packages/block-editor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
"remove-accents": "^0.5.0"
},
"devDependencies": {
"@storybook/react-vite": "^10.6.1",
"@testing-library/dom": "^10.4.2",
"@testing-library/react": "^16.3.3",
"@testing-library/user-event": "^14.6.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ The content rendered inside the popover.

The client ID of the block before the popover.

- Type: `String`
- Type: `String|null|undefined`
- Required: Yes

#### nextClientId

The client ID of the block after the popover.

- Type: `String`
- Type: `String|null|undefined`
- Required: Yes
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import type { CSSProperties, ForwardedRef, ReactNode } from 'react';
import { useEffect, useState, useMemo, forwardRef } from '@wordpress/element';
import { useBlockElement } from '../block-list/use-block-props/use-block-refs';
import { PrivateBlockPopover } from '.';
import type { BlockPopoverCoverProps } from './types';

function BlockPopoverCover(
{
Expand All @@ -10,12 +12,13 @@ function BlockPopoverCover(
shift = false,
additionalStyles,
...props
},
ref
}: BlockPopoverCoverProps,
ref: ForwardedRef< HTMLDivElement >
) {
bottomClientId ??= clientId;

const selectedElement = useBlockElement( clientId );
// Block wrappers are HTML elements.
const selectedElement = useBlockElement( clientId ) as HTMLElement | null;

return (
<PrivateBlockPopover
Expand Down Expand Up @@ -43,6 +46,10 @@ function CoverContainer( {
selectedElement,
additionalStyles = {},
children,
}: {
selectedElement: HTMLElement;
additionalStyles?: CSSProperties;
children?: ReactNode;
} ) {
const [ width, setWidth ] = useState( selectedElement.offsetWidth );
const [ height, setHeight ] = useState( selectedElement.offsetHeight );
Expand All @@ -56,7 +63,7 @@ function CoverContainer( {
return () => observer.disconnect();
}, [ selectedElement ] );

const style = useMemo( () => {
const style = useMemo< CSSProperties >( () => {
return {
position: 'absolute',
width,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { useReducedMotion } from '@wordpress/compose';
import { __unstableMotion as motion } from '@wordpress/components';
import { store as blockEditorStore } from '../../store';
import BlockPopoverCover from './cover';
import type { PrivateBlockPopoverSlotProps } from './types';

const animateVariants = {
hide: { opacity: 0, scaleY: 0.75 },
Expand All @@ -13,8 +14,8 @@ const animateVariants = {
function BlockDropZonePopover( {
__unstablePopoverSlot,
__unstableContentRef,
} ) {
const { clientId } = useSelect( ( select ) => {
}: PrivateBlockPopoverSlotProps ) {
const { clientId } = useSelect( ( select ): { clientId?: string } => {
const { getBlockOrder, getBlockInsertionPoint } =
select( blockEditorStore );
const insertionPoint = getBlockInsertionPoint();
Expand All @@ -25,14 +26,16 @@ function BlockDropZonePopover( {
}

return {
clientId: order[ insertionPoint.index ],
// A non-empty order always has an insertion index.
clientId: order[ insertionPoint.index! ],
};
}, [] );
const reducedMotion = useReducedMotion();

return (
<BlockPopoverCover
clientId={ clientId }
// Without a block the popover renders nothing.
clientId={ clientId! }
__unstablePopoverSlot={ __unstablePopoverSlot }
__unstableContentRef={ __unstableContentRef }
className="block-editor-block-popover__drop-zone"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { isRTL } from '@wordpress/i18n';
import { store as blockEditorStore } from '../../store';
import { useBlockElement } from '../block-list/use-block-props/use-block-refs';
import usePopoverScroll from './use-popover-scroll';
import type { BlockPopoverInbetweenProps } from './types';

const MAX_POPOVER_RECOMPUTE_COUNTER = Number.MAX_SAFE_INTEGER;

Expand All @@ -18,11 +19,11 @@ function BlockPopoverInbetween( {
operation = 'insert',
nearestSide = 'right',
...props
} ) {
}: BlockPopoverInbetweenProps ) {
// This is a temporary hack to get the inbetween inserter to recompute properly.
const [ popoverRecomputeCounter, forcePopoverRecompute ] = useReducer(
// Module is there to make sure that the counter doesn't overflow.
( s ) => ( s + 1 ) % MAX_POPOVER_RECOMPUTE_COUNTER,
( s: number ) => ( s + 1 ) % MAX_POPOVER_RECOMPUTE_COUNTER,
0
);

Expand All @@ -34,23 +35,26 @@ function BlockPopoverInbetween( {
isBlockVisible,
} = select( blockEditorStore );

// At least one neighboring block is set.
const _rootClientId = getBlockRootClientId(
previousClientId ?? nextClientId
( previousClientId ?? nextClientId )!
);
return {
orientation:
getBlockListSettings( _rootClientId )?.orientation ||
'vertical',
rootClientId: _rootClientId,
// An absent neighboring block is looked up as a missing one.
isVisible:
isBlockVisible( previousClientId ) &&
isBlockVisible( nextClientId ),
isBlockVisible( previousClientId as string ) &&
isBlockVisible( nextClientId as string ),
};
},
[ previousClientId, nextClientId ]
);
const previousElement = useBlockElement( previousClientId );
const nextElement = useBlockElement( nextClientId );
// An absent neighboring block has no element.
const previousElement = useBlockElement( previousClientId as string );
const nextElement = useBlockElement( nextClientId as string );
const isVertical = orientation === 'vertical';

const popoverAnchor = useMemo( () => {
Expand Down Expand Up @@ -80,13 +84,14 @@ function BlockPopoverInbetween( {
? nextElement.getBoundingClientRect()
: null;

// At least one of the elements exists, see the check above.
let left = 0;
let top = 0;
let width = 0;
let height = 0;

if ( operation === 'group' ) {
const targetRect = nextRect || previousRect;
const targetRect = ( nextRect || previousRect )!;
top = targetRect.top;
// No spacing is likely around blocks in this operation.
// So width of the inserter containing rect is set to 0.
Expand All @@ -100,28 +105,28 @@ function BlockPopoverInbetween( {
: targetRect.right - 2;
} else if ( isVertical ) {
// vertical
top = previousRect ? previousRect.bottom : nextRect.top;
top = previousRect ? previousRect.bottom : nextRect!.top;
width =
nextRect && previousRect
? ( previousRect.width + nextRect.width ) / 2
: ( previousRect || nextRect ).width;
: ( previousRect || nextRect )!.width;
height =
nextRect && previousRect
? nextRect.top - previousRect.bottom
: 0;
left =
nextRect && previousRect
? ( previousRect.left + nextRect.left ) / 2
: ( previousRect || nextRect ).left;
: ( previousRect || nextRect )!.left;
} else {
top = previousRect ? previousRect.top : nextRect.top;
top = previousRect ? previousRect.top : nextRect!.top;
height = previousRect
? previousRect.height
: nextRect.height;
: nextRect!.height;

if ( isRTL() ) {
// non vertical, rtl
left = nextRect ? nextRect.right : previousRect.left;
left = nextRect ? nextRect.right : previousRect!.left;
width =
previousRect && nextRect
? previousRect.left - nextRect.right
Expand All @@ -130,7 +135,7 @@ function BlockPopoverInbetween( {
// non vertical, ltr
left = previousRect
? previousRect.right
: nextRect.left;
: nextRect!.left;
width =
previousRect && nextRect
? nextRect.left - previousRect.right
Expand Down Expand Up @@ -193,7 +198,8 @@ function BlockPopoverInbetween( {
if ( ! previousElement ) {
return;
}
previousElement.ownerDocument.defaultView.addEventListener(
// Block elements live in a document with a window.
previousElement.ownerDocument.defaultView!.addEventListener(
'resize',
forcePopoverRecompute
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import clsx from 'clsx';
import type { ForwardedRef } from 'react';
import { useMergeRefs } from '@wordpress/compose';
import { Popover } from '@wordpress/components';
import {
Expand All @@ -10,6 +11,7 @@ import {
import { useBlockElement } from '../block-list/use-block-props/use-block-refs';
import usePopoverScroll from './use-popover-scroll';
import { rectUnion, getElementBounds } from '../../utils/dom';
import type { BlockPopoverProps, PrivateBlockPopoverProps } from './types';

const MAX_POPOVER_RECOMPUTE_COUNTER = Number.MAX_SAFE_INTEGER;

Expand All @@ -22,8 +24,8 @@ function BlockPopover(
__unstableContentRef,
shift = true,
...props
},
ref
}: PrivateBlockPopoverProps,
ref: ForwardedRef< HTMLDivElement >
) {
const selectedElement = useBlockElement( clientId );
const lastSelectedElement = useBlockElement( bottomClientId ?? clientId );
Expand All @@ -37,7 +39,7 @@ function BlockPopover(
forceRecomputePopoverDimensions,
] = useReducer(
// Module is there to make sure that the counter doesn't overflow.
( s ) => ( s + 1 ) % MAX_POPOVER_RECOMPUTE_COUNTER,
( s: number ) => ( s + 1 ) % MAX_POPOVER_RECOMPUTE_COUNTER,
0
);

Expand All @@ -53,7 +55,7 @@ function BlockPopover(
return;
}

let rafId;
let rafId: number | null | undefined;
const observer = new window.MutationObserver( () => {
if ( rafId ) {
return;
Expand Down Expand Up @@ -133,8 +135,8 @@ function BlockPopover(
export const PrivateBlockPopover = forwardRef( BlockPopover );

const PublicBlockPopover = (
{ clientId, bottomClientId, children, ...props },
ref
{ clientId, bottomClientId, children, ...props }: BlockPopoverProps,
ref: ForwardedRef< HTMLDivElement >
) => (
<PrivateBlockPopover
{ ...props }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { Meta, StoryObj } from '@storybook/react-vite';
import {
createBlock,
registerBlockType,
Expand All @@ -19,7 +20,7 @@ const clientIds = BLOCK_LABELS.map(
( label, index ) => `example-block-${ index + 1 }`
);

function ExampleEdit( { attributes } ) {
function ExampleEdit( { attributes }: { attributes: { content?: string } } ) {
return <p { ...useBlockProps() }>{ attributes.content }</p>;
}

Expand Down Expand Up @@ -73,7 +74,7 @@ const clientIdLabels = Object.fromEntries(
clientIds.map( ( clientId, index ) => [ clientId, `Block ${ index + 1 }` ] )
);

const meta = {
const meta: Meta< typeof BlockPopover > = {
id: 'blockeditor-blockpopover',
title: 'Editor/Block Editor/BlockPopover',
component: BlockPopover,
Expand Down Expand Up @@ -142,7 +143,9 @@ const meta = {

export default meta;

export const Default = {
type Story = StoryObj< typeof meta >;

export const Default: Story = {
args: {
clientId: clientIds[ 1 ],
children: 'This is a block popover example.',
Expand Down
Loading
Loading