🤖 Merge PR #65555 [draft-js] added DraftDecoratorComponentProps to support typed React components by @agiswand

Co-authored-by: Ilya Gerasimets <ilya.gerasimets@gmail.com>
This commit is contained in:
agiswand
2023-05-25 09:30:45 -07:00
committed by GitHub
parent acf0f103d8
commit b584b38d1b

View File

@@ -485,6 +485,30 @@ declare namespace Draft {
getPropsForKey(key: string): any;
}
/**
* DraftDecoratorComponentProps are the core set of props that will be
* passed to all DraftDecoratorComponents if a Custom Block Component is not used.
* Note that a component may also accept additional props outside of this list.
*/
interface DraftDecoratorComponentProps {
blockKey: string;
children?: Array<React.ReactNode>;
contentState: ContentState;
decoratedText: string;
dir: 'ltr' | 'rtl' | undefined;
end: number;
// Many folks mistakenly assume that there will always be an 'entityKey'
// passed to a DecoratorComponent.
// To find the `entityKey`, Draft calls
// `contentBlock.getEntityKeyAt(leafNode)` and in many cases the leafNode does
// not have an entityKey. In those cases the entityKey will be null or
// undefined. That's why `getEntityKeyAt()` is typed to return `?string`.
// See https://github.com/facebook/draft-js/blob/2da3dcb1c4c106d1b2a0f07b3d0275b8d724e777/src/model/immutable/BlockNode.js#L51
entityKey: string | undefined;
offsetKey: string;
start: number;
}
/**
* A DraftDecorator is a strategy-component pair intended for use when
* rendering content.
@@ -498,16 +522,19 @@ declare namespace Draft {
* - A "component": A React component that will be used to render the
* "decorated" section of text.
*
* - "props": Props to be passed into the React component that will be used.
* - "props": Props to be passed into the React component that will be used
* merged with DraftDecoratorComponentProps
*/
interface DraftDecorator {
interface DraftDecorator<P = any> {
strategy: (
block: ContentBlock,
callback: (start: number, end: number) => void,
contentState: ContentState,
) => void;
component: Function;
props?: object | undefined;
component: React.Component
| typeof React.Component
| ((props: DraftDecoratorComponentProps & P) => React.ReactNode);
props?: P | undefined;
}
/**