Skip to content

Commit 09f9a09

Browse files
🤖 Merge PR DefinitelyTyped#74273 [@wordpress/block-editor] Add definitions for getBlocksByName and some missing props on RichText by @Toberumono
Co-authored-by: Joshua Lipstone <[email protected]>
1 parent 86aac7d commit 09f9a09

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

‎types/wordpress__block-editor/components/rich-text.d.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ declare namespace RichText {
1717
autocompleters?: ComponentProps<typeof Autocomplete>["completers"] | undefined;
1818
children?: never | undefined;
1919
className?: string | undefined;
20+
/**
21+
* Disables inserting line breaks on Enter when it is set to true
22+
*/
23+
disableLineBreaks?: boolean | undefined;
2024
identifier?: string | undefined;
2125
inlineToolbar?: boolean | undefined;
2226
/**
@@ -66,6 +70,10 @@ declare namespace RichText {
6670
* if provided.
6771
*/
6872
value: string;
73+
/**
74+
* By default, all formatting controls are present. This setting can be used to remove formatting controls that would make content interactive. This is useful if you want to make content that is already interactive editable.
75+
*/
76+
withoutInteractiveFormatting?: boolean | undefined;
6977
wrapperClassName?: string | undefined;
7078
}
7179
interface ContentProps<T extends keyof HTMLElementTagNameMap> extends HTMLProps<T> {

‎types/wordpress__block-editor/store/selectors.d.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,15 @@ export function getBlocks(rootClientId?: string): BlockInstance[];
191191
*/
192192
export function getBlocksByClientId(clientIds: string | string[]): Array<BlockInstance | null>;
193193

194+
/**
195+
* Returns all blocks that match a blockName. Results include nested blocks.
196+
*
197+
* @param blockName - Block name(s) for which clientIds are to be returned.
198+
*
199+
* @returns Array of clientIds of blocks with name equal to blockName.
200+
*/
201+
export function getBlocksByName(blockName: string | string[]): string[];
202+
194203
/**
195204
* Returns an array containing the clientIds of all descendants of the blocks given.
196205
*

‎types/wordpress__block-editor/wordpress__block-editor-tests.tsx‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,8 @@ be.withFontSizes("fontSize")(() => <h1>Hello World</h1>);
370370
onReplace={blocks => blocks.forEach(b => console.log(b.clientId))}
371371
allowedFormats={["core/bold", "core/italic"]}
372372
onSplit={(value, isOriginal) => createBlock("core/paragraph", { content: value })}
373+
disableLineBreaks
374+
withoutInteractiveFormatting
373375
/>;
374376
<be.RichText.Content value="foo" />;
375377
<be.RichText.Content tagName="p" style={{ color: "blue" }} className="foo" value="Hello World" dir="rtl" />;
@@ -608,6 +610,10 @@ useSelect("core/block-editor").getBlockParentsByBlockName("foo", ["core/query"])
608610
useSelect("core/block-editor").getBlockParents("foo", true);
609611
useSelect("core/block-editor").getBlockParentsByBlockName("foo", ["core/query"], true);
610612

613+
// $ExpectType string[]
614+
useSelect("core/block-editor").getBlocksByName("core/group");
615+
useSelect("core/block-editor").getBlocksByName(["core/group", "core/paragraph"]);
616+
611617
{
612618
const blockProps: UseBlockProps.Merged & UseBlockProps.Reserved = be.useBlockProps();
613619
blockProps;

0 commit comments

Comments
 (0)