mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-07-04 01:00:05 +00:00
[@wordpress/blocks] misc scattered fixes found in the wild (#36638)
* misc small fixes * fix: allow possibly `undefined` parameter in getBlockType * fix: add get/set for groupingBlockName to exposed store functions * make innerblocks mutable since wordpress core mutates them * misc fixes
This commit is contained in:
committed by
Armando Aguirre
parent
9f538f114e
commit
967c083537
2
types/wordpress__blocks/api/children.d.ts
vendored
2
types/wordpress__blocks/api/children.d.ts
vendored
@@ -30,7 +30,7 @@ declare namespace children {
|
||||
*
|
||||
* @param selector - DOM selector.
|
||||
*/
|
||||
function matcher(selector: string): (domNode: ParentNode) => ReactChild[];
|
||||
function matcher(selector: string): (domNode: Node & ParentNode) => ReactChild[];
|
||||
|
||||
/**
|
||||
* Given a block node, returns its HTML string representation.
|
||||
|
||||
12
types/wordpress__blocks/api/factory.d.ts
vendored
12
types/wordpress__blocks/api/factory.d.ts
vendored
@@ -39,10 +39,10 @@ export function createBlock<T extends Record<string, any>>(
|
||||
*
|
||||
* @returns Highest-priority transform candidate.
|
||||
*/
|
||||
export function findTransform<T extends Record<string, any> = Record<string, any>>(
|
||||
transforms: readonly Transform[],
|
||||
predicate: (transform: Transform) => boolean
|
||||
): Transform<T>; // tslint:disable-line:no-unnecessary-generics
|
||||
export function findTransform<T extends Transform, U extends Record<string, any> = Record<string, any>>(
|
||||
transforms: T[],
|
||||
predicate: (transform: T) => boolean
|
||||
): Transform<U> | null; // tslint:disable-line:no-unnecessary-generics
|
||||
|
||||
/**
|
||||
* Returns normal block transforms for a given transform direction, optionally
|
||||
@@ -55,8 +55,8 @@ export function findTransform<T extends Record<string, any> = Record<string, any
|
||||
*/
|
||||
export function getBlockTransforms<T extends Record<string, any> = Record<string, any>>(
|
||||
direction: 'to' | 'from',
|
||||
blockTypeOrName: string | Block
|
||||
): Array<Transform<T>>; // tslint:disable-line:no-unnecessary-generics
|
||||
blockTypeOrName?: string | Block
|
||||
): Array<Transform<T> & { blockName: string }>; // tslint:disable-line:no-unnecessary-generics
|
||||
|
||||
/**
|
||||
* Returns an array of block types that the set of blocks received as argument
|
||||
|
||||
@@ -20,7 +20,7 @@ export function getBlockSupport<T>(
|
||||
* Returns a registered block type.
|
||||
*/
|
||||
// tslint:disable:no-unnecessary-generics
|
||||
export function getBlockType<T = any>(name: string): Block<T> | undefined;
|
||||
export function getBlockType<T = any>(name: string | undefined): Block<T> | undefined;
|
||||
|
||||
/**
|
||||
* Returns all registered blocks.
|
||||
|
||||
13
types/wordpress__blocks/index.d.ts
vendored
13
types/wordpress__blocks/index.d.ts
vendored
@@ -145,7 +145,7 @@ export interface BlockInstance<T extends Record<string, any> = { [k: string]: an
|
||||
/**
|
||||
* Array of inner blocks, if the block has any.
|
||||
*/
|
||||
readonly innerBlocks: readonly BlockInstance[];
|
||||
readonly innerBlocks: BlockInstance[];
|
||||
/**
|
||||
* Indicates whether or not the block is valid.
|
||||
*/
|
||||
@@ -348,16 +348,17 @@ export type TransformRawSchema = {
|
||||
|
||||
export interface TransformBlock<T extends Record<string, any>> {
|
||||
type: 'block';
|
||||
blocks: string[];
|
||||
priority?: number;
|
||||
blocks: string[];
|
||||
isMatch?(attributes: T): boolean;
|
||||
isMultiBlock?: boolean;
|
||||
transform(attributes: T): BlockInstance<Partial<T>>;
|
||||
}
|
||||
|
||||
export interface TransformEnter<T extends Record<string, any>> {
|
||||
type: 'enter';
|
||||
regExp: RegExp;
|
||||
priority?: number;
|
||||
regExp: RegExp;
|
||||
transform(): BlockInstance<Partial<T>>;
|
||||
}
|
||||
|
||||
@@ -370,12 +371,14 @@ export interface TransformFiles<T extends Record<string, any>> {
|
||||
|
||||
export interface TransformPrefix<T extends Record<string, any>> {
|
||||
type: 'prefix';
|
||||
priority?: number;
|
||||
prefix: string;
|
||||
transform(content: string): BlockInstance<Partial<T>>;
|
||||
}
|
||||
|
||||
export interface TransformRaw<T extends Record<string, any>> {
|
||||
type: 'raw';
|
||||
priority?: number;
|
||||
/**
|
||||
* Comma-separated list of selectors, no spaces.
|
||||
*
|
||||
@@ -383,15 +386,15 @@ export interface TransformRaw<T extends Record<string, any>> {
|
||||
*/
|
||||
selector?: string;
|
||||
schema?: TransformRawSchema;
|
||||
priority?: number;
|
||||
isMatch?(node: Node): boolean;
|
||||
transform?(node: Node): BlockInstance<Partial<T>> | void;
|
||||
}
|
||||
|
||||
export interface TransformShortcode<T extends Record<string, any>> {
|
||||
type: 'shortcode';
|
||||
priority?: number;
|
||||
tag: string;
|
||||
attributes?: any; // fix this if I ever need it.
|
||||
attributes?: any; // TODO: add stronger types here.
|
||||
}
|
||||
|
||||
export type Transform<T extends Record<string, any> = Record<string, any>> =
|
||||
|
||||
1
types/wordpress__blocks/store/actions.d.ts
vendored
1
types/wordpress__blocks/store/actions.d.ts
vendored
@@ -7,5 +7,6 @@ export function removeBlockTypes(names: string | readonly string[]): void;
|
||||
export function setCategories(categories: readonly Category[]): void;
|
||||
export function setDefaultBlockName(name: string): void;
|
||||
export function setFreeformFallbackBlockName(name: string): void;
|
||||
export function setGroupingBlockName(name: string): void;
|
||||
export function setUnregisteredFallbackBlockName(name: string): void;
|
||||
export function updateCategory(slug: string, category: Partial<Category>): void;
|
||||
|
||||
1
types/wordpress__blocks/store/selectors.d.ts
vendored
1
types/wordpress__blocks/store/selectors.d.ts
vendored
@@ -7,6 +7,7 @@ export {
|
||||
getCategories,
|
||||
getChildBlockNames,
|
||||
getDefaultBlockName,
|
||||
getGroupingBlockName,
|
||||
hasBlockSupport,
|
||||
hasChildBlocks,
|
||||
hasChildBlocksWithInserterSupport,
|
||||
|
||||
@@ -66,7 +66,7 @@ blocks.updateCategory('foo', { title: 'Foobar' });
|
||||
// $ExpectType ReactChild[]
|
||||
blocks.children.fromDOM(document.querySelectorAll('div'));
|
||||
|
||||
// $ExpectType (domNode: ParentNode) => ReactChild[]
|
||||
// $ExpectType (domNode: Node & ParentNode) => ReactChild[]
|
||||
blocks.children.matcher('.foo');
|
||||
|
||||
//
|
||||
@@ -79,7 +79,6 @@ blocks.cloneBlock(BLOCK_INSTANCE);
|
||||
// $ExpectType BlockInstance<{ foo: string; }>
|
||||
blocks.createBlock('my/foo', { foo: 'bar' });
|
||||
|
||||
// $ExpectType Transform<Record<string, any>>
|
||||
blocks.findTransform(
|
||||
[
|
||||
{
|
||||
@@ -94,11 +93,14 @@ blocks.findTransform(
|
||||
transform => transform.type === 'block'
|
||||
);
|
||||
|
||||
// $ExpectType Transform<Record<string, any>>[]
|
||||
blocks.getBlockTransforms('to', 'my/foo');
|
||||
declare const RAW_TRANSFORM_ARRAY: Array<blocks.TransformRaw<any>>;
|
||||
blocks.findTransform(RAW_TRANSFORM_ARRAY, ({ isMatch }) => true);
|
||||
|
||||
// $ExpectType Transform<{ foo: string; }>[]
|
||||
blocks.getBlockTransforms<{ foo: string }>('to', 'my/foo');
|
||||
// $ExpectType string
|
||||
blocks.getBlockTransforms('to', 'my/foo')[0].blockName;
|
||||
|
||||
// $ExpectType string
|
||||
blocks.getBlockTransforms<{ foo: string }>('to', 'my/foo')[0].blockName;
|
||||
|
||||
// $ExpectType Block<Record<string, any>>[]
|
||||
blocks.getPossibleBlockTransformations([BLOCK_INSTANCE]);
|
||||
|
||||
Reference in New Issue
Block a user