Skip to content

Commit 5d86492

Browse files
🤖 Merge PR DefinitelyTyped#73749 [@wordpress/block-editor] Add blockParent selectors by @joshualip-plaudit
1 parent 7512a18 commit 5d86492

File tree

3 files changed

+40
-5
lines changed

3 files changed

+40
-5
lines changed

‎types/wordpress__block-editor/package.json‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
{
22
"private": true,
33
"name": "@types/wordpress__block-editor",
4-
"version": "11.5.9999",
4+
"version": "14.21.9999",
55
"projects": [
66
"https://github.com/WordPress/gutenberg/tree/master/packages/block-editor/README.md"
77
],
88
"dependencies": {
99
"@types/react": "^18",
1010
"@types/wordpress__blocks": "*",
11-
"@wordpress/components": "^27.2.0",
12-
"@wordpress/data": "^9.13.0",
13-
"@wordpress/element": "^5.0.0",
14-
"@wordpress/keycodes": "^3.54.0",
11+
"@wordpress/components": "^29.12.0",
12+
"@wordpress/data": "^10.26.0",
13+
"@wordpress/element": "^6.26.0",
14+
"@wordpress/keycodes": "^4.26.0",
1515
"react-autosize-textarea": "^7.1.0"
1616
},
1717
"devDependencies": {
@@ -29,6 +29,10 @@
2929
{
3030
"name": "Dennis Snell",
3131
"githubUsername": "dmsnell"
32+
},
33+
{
34+
"name": "Joshua Lipstone",
35+
"githubUsername": "joshualip-plaudit"
3236
}
3337
]
3438
}

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,31 @@ export function getBlockName(clientId: string): string | null;
118118
*/
119119
export function getBlockOrder(rootClientId?: string): string[];
120120

121+
/**
122+
* Returns a block's parents' client IDs given its client ID
123+
*
124+
* @param clientId - Block client ID.
125+
* @param ascending - If true, the client ids will be returned from closest to farthest instead of the default of farthest to closest
126+
*
127+
* @returns The client IDs of all parent blocks
128+
*/
129+
export function getBlockParents(clientId: string, ascending?: boolean): string[];
130+
131+
/**
132+
* Returns a block's parents' client IDs given its client ID pre-filtered to only include blocks with the passed blockNames
133+
*
134+
* @param clientId - Block client ID.
135+
* @param blockName - the name or names of the block types to which the parents list should be filtered
136+
* @param ascending - If true, the client ids will be returned from closest to farthest instead of the default of farthest to closest
137+
*
138+
* @returns The client IDs of all parent blocks filtered by the passed block name or names
139+
*/
140+
export function getBlockParentsByBlockName(
141+
clientId: string,
142+
blockName: string | string[],
143+
ascending?: boolean,
144+
): string[];
145+
121146
/**
122147
* Given a block client ID, returns the root block from which the block is nested, an empty string
123148
* for top-level blocks, or `null` if the block does not exist.

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,12 @@ select("core/block-editor").getAdjacentBlockClientId("foo");
566566
select("core/block-editor").getAdjacentBlockClientId("foo", -1);
567567
select("core/block-editor").getAdjacentBlockClientId("foo", 1);
568568

569+
// $ExpectType string[]
570+
select("core/block-editor").getBlockParents("foo");
571+
select("core/block-editor").getBlockParentsByBlockName("foo", ["core/query"]);
572+
select("core/block-editor").getBlockParents("foo", true);
573+
select("core/block-editor").getBlockParentsByBlockName("foo", ["core/query"], true);
574+
569575
{
570576
const blockProps: UseBlockProps.Merged & UseBlockProps.Reserved = be.useBlockProps();
571577
blockProps;

0 commit comments

Comments
 (0)