Skip to content

Commit 6614245

Browse files
committed
blocks: Fix __EXPERIMENTAL_ELEMENTS type and matcherFromSource docgen
- Type __EXPERIMENTAL_ELEMENTS as Record<string, string> since it's used as a generic key-value lookup with arbitrary element names. - Restructure matcherFromSource to avoid explicit outer type annotation pattern that confuses the docgen tool, fixing docs:build failure.
1 parent ad4f5fa commit 6614245

2 files changed

Lines changed: 9 additions & 13 deletions

File tree

‎packages/blocks/src/api/constants.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ export const __EXPERIMENTAL_STYLE_PROPERTY = {
289289
},
290290
};
291291

292-
export const __EXPERIMENTAL_ELEMENTS = {
292+
export const __EXPERIMENTAL_ELEMENTS: Record< string, string > = {
293293
link: 'a:where(:not(.wp-element-button))',
294294
heading: 'h1, h2, h3, h4, h5, h6',
295295
h1: 'h1',

‎packages/blocks/src/api/parser/get-block-attributes.ts‎

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -198,17 +198,11 @@ export function isValidByEnum(
198198
return ! Array.isArray( enumSet ) || enumSet.includes( value );
199199
}
200200

201-
/**
202-
* Returns an hpq matcher given a source object.
203-
*
204-
* @param {BlockAttribute} sourceConfig Attribute Source object.
205-
*
206-
* @return {Function} A hpq Matcher.
207-
*/
208-
export const matcherFromSource: (
209-
sourceConfig: BlockAttribute
210-
) => ( ( domNode: Node ) => unknown ) | undefined = memoize(
211-
( sourceConfig: BlockAttribute ) => {
201+
// Returns an hpq matcher given a source object.
202+
export const matcherFromSource = memoize(
203+
(
204+
sourceConfig: BlockAttribute
205+
): ( ( domNode: Element ) => unknown ) | undefined => {
212206
switch ( sourceConfig.source ) {
213207
case 'attribute': {
214208
let matcher = attr(
@@ -282,7 +276,9 @@ export function parseWithAttributeSchema(
282276
innerHTML: string | Node,
283277
attributeSchema: BlockAttribute
284278
): unknown {
285-
return matcherFromSource( attributeSchema )!( parseHtml( innerHTML ) );
279+
return matcherFromSource( attributeSchema )!(
280+
parseHtml( innerHTML ) as Element
281+
);
286282
}
287283

288284
/**

0 commit comments

Comments
 (0)