Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 packages/block-editor/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
- Convert `Iframe`, `EditorStyles`, `NavigableToolbar`, `CopyHandler` and `BlockBreadcrumb` to TypeScript ([#84922](https://github.com/WordPress/gutenberg/pull/84922)).
- Convert `MediaPlaceholder` and `ImageEditor` to TypeScript ([#84923](https://github.com/WordPress/gutenberg/pull/84923)).
- Convert `useBlockDropZone` to TypeScript ([#84946](https://github.com/WordPress/gutenberg/pull/84946)).
- Convert `BlockManager`, `PublishDateTimePicker` and the fit text hook to TypeScript ([#84949](https://github.com/WordPress/gutenberg/pull/84949)).

## 18.1.0 (2026-10-07)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
import { useCallback } from '@wordpress/element';
import { useInstanceId } from '@wordpress/compose';
import { CheckboxControl as WCCheckboxControl } from '@wordpress/components';
import type { BlockType } from '@wordpress/blocks';
import BlockTypesChecklist from './checklist';
import type { BlockManagerCategoryProps } from './types';

function BlockManagerCategory( {
title,
blockTypes,
selectedBlockTypes,
onChange,
} ) {
}: BlockManagerCategoryProps ) {
const instanceId = useInstanceId( BlockManagerCategory );

const toggleVisible = useCallback(
( blockType, nextIsChecked ) => {
( blockType: BlockType, nextIsChecked: boolean ) => {
if ( nextIsChecked ) {
onChange( [ ...selectedBlockTypes, blockType ] );
} else {
Expand All @@ -27,7 +29,7 @@ function BlockManagerCategory( {
);

const toggleAllVisible = useCallback(
( nextIsChecked ) => {
( nextIsChecked: boolean ) => {
if ( nextIsChecked ) {
onChange( [
...selectedBlockTypes,
Expand Down Expand Up @@ -80,7 +82,12 @@ function BlockManagerCategory( {
onChange={ toggleAllVisible }
className="block-editor-block-manager__category-title"
indeterminate={ isIndeterminate }
label={ <span id={ titleId }>{ title }</span> }
// The label renders as a node, so the title can carry its ID.
label={
(
<span id={ titleId }>{ title }</span>
) as unknown as string
}
/>
<BlockTypesChecklist
blockTypes={ blockTypes }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import { CheckboxControl as WCCheckboxControl } from '@wordpress/components';
import BlockIcon from '../block-icon';
import type { BlockTypesChecklistProps } from './types';

function BlockTypesChecklist( { blockTypes, value, onItemChange } ) {
function BlockTypesChecklist( {
blockTypes,
value,
onItemChange,
}: BlockTypesChecklistProps ) {
return (
<ul className="block-editor-block-manager__checklist">
{ blockTypes.map( ( blockType ) => (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,23 @@ import { useEffect, useState } from '@wordpress/element';
import { useDebounce } from '@wordpress/compose';
import { speak } from '@wordpress/a11y';
import BlockManagerCategory from './category';
import type { BlockManagerProps } from './types';

/**
* Provides a list of blocks with checkboxes.
*
* @param {Object} props Props.
* @param {Array} props.blockTypes An array of blocks.
* @param {Array} props.selectedBlockTypes An array of selected blocks.
* @param {Function} props.onChange Function to be called when the selected blocks change.
* @param {boolean} props.showSelectAll Whether to show the select all checkbox.
* @param props Props.
* @param props.blockTypes An array of blocks.
* @param props.selectedBlockTypes An array of selected blocks.
* @param props.onChange Function to be called when the selected blocks change.
* @param props.showSelectAll Whether to show the select all checkbox.
*/
export default function BlockManager( {
blockTypes,
selectedBlockTypes,
onChange,
showSelectAll = true,
} ) {
}: BlockManagerProps ) {
const debouncedSpeak = useDebounce( speak, 500 );
const [ search, setSearch ] = useState( '' );
const { categories, isMatchingSearchTerm } = useSelect( ( select ) => {
Expand Down Expand Up @@ -86,7 +87,8 @@ export default function BlockManager( {
/>
) }
<div
tabIndex="0"
// The attribute takes the string as given.
tabIndex={ '0' as unknown as number }
role="region"
aria-label={ __( 'Available block types' ) }
className="block-editor-block-manager__results"
Expand Down
45 changes: 45 additions & 0 deletions packages/block-editor/src/components/block-manager/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import type { BlockType } from '@wordpress/blocks';

/**
* Props of `BlockManager`.
*/
export interface BlockManagerProps {
/**
* An array of blocks.
*/
blockTypes: BlockType[];
/**
* An array of selected blocks.
*/
selectedBlockTypes: BlockType[];
/**
* Function to be called when the selected blocks change.
*/
onChange: ( selectedBlockTypes: BlockType[] ) => void;
/**
* Whether to show the select all checkbox.
*/
showSelectAll?: boolean;
}

/**
* Props of the block types of one category in `BlockManager`.
*/
export interface BlockManagerCategoryProps {
title: string;
blockTypes: BlockType[];
selectedBlockTypes: BlockType[];
onChange: ( selectedBlockTypes: BlockType[] ) => void;
}

/**
* Props of the checklist of block types in `BlockManager`.
*/
export interface BlockTypesChecklistProps {
blockTypes: BlockType[];
/**
* The names of the checked block types.
*/
value: string[];
onItemChange: ( blockType: BlockType, nextIsChecked: boolean ) => void;
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import type { ForwardedRef } from 'react';
import { DateTimePicker, TimePicker } from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import { forwardRef } from '@wordpress/element';
import { getSettings } from '@wordpress/date';
import InspectorPopoverHeader from '../inspector-popover-header';
import type {
PrivatePublishDateTimePickerProps,
PublishDateTimePickerProps,
} from './types';

export function PublishDateTimePicker(
{
Expand All @@ -14,8 +19,8 @@ export function PublishDateTimePicker(
currentDate,
title,
...additionalProps
},
ref
}: PrivatePublishDateTimePickerProps,
ref: ForwardedRef< HTMLDivElement >
) {
const datePickerProps = {
startOfWeek: getSettings().l10n.startOfWeek,
Expand All @@ -24,7 +29,10 @@ export function PublishDateTimePicker(
currentTime: isCompact ? currentDate : undefined,
...additionalProps,
};
const DatePickerComponent = isCompact ? TimePicker : DateTimePicker;
// `TimePicker` ignores the date props.
const DatePickerComponent = (
isCompact ? TimePicker : DateTimePicker
) as typeof DateTimePicker;
return (
<div ref={ ref } className="block-editor-publish-date-time-picker">
{ showPopoverHeader && (
Expand All @@ -50,7 +58,10 @@ export function PublishDateTimePicker(

export const PrivatePublishDateTimePicker = forwardRef( PublishDateTimePicker );

function PublicPublishDateTimePicker( props, ref ) {
function PublicPublishDateTimePicker(
props: PublishDateTimePickerProps,
ref: ForwardedRef< HTMLDivElement >
) {
return (
<PrivatePublishDateTimePicker
{ ...props }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import type { ComponentProps } from 'react';
import type { DateTimePicker } from '@wordpress/components';

/**
* Props of `PublishDateTimePicker`: the props of `DateTimePicker`, plus the
* popover header.
*/
export type PublishDateTimePickerProps = ComponentProps<
typeof DateTimePicker
> & {
/**
* The title displayed in the header of the popover.
*/
title?: string;
/**
* Called when the user presses the close button.
*/
onClose?: () => void;
/**
* Whether to render the popover header.
*/
showPopoverHeader?: boolean;
};

/**
* Props of the private `PublishDateTimePicker`.
*/
export type PrivatePublishDateTimePickerProps = PublishDateTimePickerProps & {
/**
* Whether to render the "Reset" action in the popover header.
*/
showPopoverHeaderActions?: boolean;
/**
* Whether to only pick the time.
*/
isCompact?: boolean;
};
Loading
Loading