[@wordpress/blocks] miscellaneous fixes for compatibility with wordpress core (#36827)

* [@wordpress/blocks] miscellaneous fixes for compatibility with wordpress core

* fix lint errors
This commit is contained in:
Derek Sifford
2019-07-11 15:50:40 -07:00
committed by Armando Aguirre
parent 657fe5e753
commit 8355a2200f
8 changed files with 40 additions and 18 deletions
+3 -1
View File
@@ -1,7 +1,9 @@
import { Dashicon } from '@wordpress/components';
export interface Category {
slug: string;
title: string;
icon: JSX.Element | null;
icon?: JSX.Element | Dashicon.Icon | null;
}
/**
+4 -7
View File
@@ -11,7 +11,7 @@ import { Block, BlockInstance, Transform } from '../';
export function cloneBlock<T extends Record<string, any>>(
block: BlockInstance<T>,
mergeAttributes?: Partial<T>,
newInnerBlocks?: readonly BlockInstance[]
newInnerBlocks?: BlockInstance[]
): BlockInstance<T>;
/**
@@ -24,7 +24,7 @@ export function cloneBlock<T extends Record<string, any>>(
export function createBlock<T extends Record<string, any>>(
name: string,
attributes?: Partial<T>,
innerBlocks?: readonly BlockInstance[]
innerBlocks?: BlockInstance[]
): BlockInstance<T>;
/**
@@ -66,7 +66,7 @@ export function getBlockTransforms<T extends Record<string, any> = Record<string
*
* @returns Block types that ALL blocks in `blocks` can be transformed to.
*/
export function getPossibleBlockTransformations(blocks: readonly BlockInstance[]): Array<Block<Record<string, any>>>;
export function getPossibleBlockTransformations(blocks: BlockInstance[]): Array<Block<Record<string, any>>>;
/**
* Switch one or more blocks into one or more blocks of the new block type.
@@ -74,7 +74,4 @@ export function getPossibleBlockTransformations(blocks: readonly BlockInstance[]
* @param blocks - One or more `BlockInstance`.
* @param name - Block name of block to be switched to.
*/
export function switchToBlockType(
blocks: BlockInstance | readonly BlockInstance[],
name: string
): BlockInstance[] | null;
export function switchToBlockType(blocks: BlockInstance | BlockInstance[], name: string): BlockInstance[] | null;
+1 -1
View File
@@ -25,7 +25,7 @@ export function getBlockType<T = any>(name: string | undefined): Block<T> | unde
/**
* Returns all registered blocks.
*/
export function getBlockTypes(): ReadonlyArray<Block<any>>;
export function getBlockTypes(): Array<Block<any>>;
/**
* Returns an array with the child blocks of a given block.
+3 -3
View File
@@ -28,7 +28,7 @@ export function getBlockMenuDefaultClassName(blockName: string): string;
export function getSaveContent<T>(
blockTypeOrName: Block<T> | string,
attributes: T,
innerBlocks?: readonly BlockInstance[]
innerBlocks?: BlockInstance[]
): string;
/**
@@ -42,7 +42,7 @@ export function getSaveContent<T>(
export function getSaveElement<T>(
blockTypeOrName: Block<T> | string,
attributes: T,
innerBlocks?: readonly BlockInstance[]
innerBlocks?: BlockInstance[]
): ReactChild;
/**
@@ -50,4 +50,4 @@ export function getSaveElement<T>(
*
* @param blocks - Block(s) to serialize.
*/
export function serialize(blocks: readonly BlockInstance[]): string;
export function serialize(blocks: BlockInstance[]): string;
+1 -1
View File
@@ -9,7 +9,7 @@ export interface TemplateArray extends ReadonlyArray<Template> {}
* @param blocks - Block list.
* @param template - Block template.
*/
export function doBlocksMatchTemplate(blocks?: readonly BlockInstance[], template?: TemplateArray): boolean;
export function doBlocksMatchTemplate(blocks?: BlockInstance[], template?: TemplateArray): boolean;
/**
* Synchronize a block list with a block template.
+25 -2
View File
@@ -1,9 +1,32 @@
import { BlockInstance } from './';
import { ComponentType, ReactNode } from '@wordpress/element';
/**
* A Higher Order Component used to inject BlockContent using context to the
* wrapped component.
* A Higher Order Component used to inject BlockContent using context to the wrapped component.
*/
export function withBlockContentContext<T extends ComponentType<any>>(
wrapped: T
): T extends ComponentType<infer U> ? ComponentType<Omit<U, 'BlockContent'>> : never;
declare namespace BlockContentProvider {
interface Props {
children: ReactNode;
innerBlocks: BlockInstance[];
}
}
/**
* An internal block component used in block content serialization to inject nested block content
* within the `save` implementation of the ancestor component in which it is nested. The component
* provides a pre-bound `BlockContent` component via context, which is used by the developer-facing
* `InnerBlocks.Content` component to render block content.
*
* @example
* ```jsx
* <BlockContentProvider innerBlocks={ innerBlocks }>
* { blockSaveElement }
* </BlockContentProvider>
* ```
*/
declare const BlockContentProvider: ComponentType<BlockContentProvider.Props>;
export default BlockContentProvider;
+2 -2
View File
@@ -169,14 +169,14 @@ export interface BlockDeprecation<T extends Record<string, any>>
* technically valid even once deprecated, and requires updates to its
* attributes or inner blocks.
*/
isEligible?(attributes: Record<string, any>, innerBlocks: readonly BlockInstance[]): boolean;
isEligible?(attributes: Record<string, any>, innerBlocks: BlockInstance[]): boolean;
/**
* A function which, given the old attributes and inner blocks is
* expected to return either the new attributes or a tuple array of
* [attributes, innerBlocks] compatible with the block.
*/
migrate?(attributes: Record<string, any>): T;
migrate?(attributes: Record<string, any>, innerBlocks: readonly BlockInstance[]): [T, BlockInstance[]];
migrate?(attributes: Record<string, any>, innerBlocks: BlockInstance[]): [T, BlockInstance[]];
}
//
@@ -264,7 +264,7 @@ blocks.getBlockSupport('core/paragraph', 'inserter', { foo: 'bar' });
// $ExpectType Block<any> | undefined
blocks.getBlockType('core/paragraph');
// $ExpectType ReadonlyArray<Block<any>>
// $ExpectType Block<any>[]
blocks.getBlockTypes();
// $ExpectType string[]