UNPKG

@blocknote/react

Version:

A "Notion-style" block-based extensible text editor built on top of Prosemirror and Tiptap.

36 lines (35 loc) 3.7 kB
import { BlockConfig, BlockConfigOrCreator, BlockNoDefaults, BlockNoteEditor, BlockSpec, CustomBlockImplementation, Extension, ExtensionFactoryInstance, ExtractBlockConfigFromConfigOrCreator, Props, PropSchema } from "@blocknote/core"; import { FC, ReactNode } from "react"; export type ReactCustomBlockRenderProps<B extends BlockConfigOrCreator, Config extends ExtractBlockConfigFromConfigOrCreator<B> = ExtractBlockConfigFromConfigOrCreator<B>> = { block: BlockNoDefaults<Record<Config["type"], Config>, any, any>; editor: BlockNoteEditor<Record<Config["type"], Config>, any, any>; } & (Config["content"] extends "inline" ? { contentRef: (node: HTMLElement | null) => void; } : object); export type ReactCustomBlockImplementation<B extends BlockConfigOrCreator = BlockConfigOrCreator, Config extends ExtractBlockConfigFromConfigOrCreator<B> = ExtractBlockConfigFromConfigOrCreator<B>> = Omit<CustomBlockImplementation<Config["type"], Config["propSchema"], Config["content"]>, "render" | "toExternalHTML"> & { render: FC<ReactCustomBlockRenderProps<B>>; toExternalHTML?: FC<ReactCustomBlockRenderProps<B> & { context: { nestingLevel: number; }; }>; }; export type ReactCustomBlockSpec<B extends BlockConfig<string, PropSchema, "inline" | "none"> = BlockConfig<string, PropSchema, "inline" | "none">> = { config: B; implementation: ReactCustomBlockImplementation<B>; extensions?: Extension<any>[]; }; export declare function BlockContentWrapper<BType extends string, PSchema extends PropSchema>(props: { blockType: BType; blockProps: Props<PSchema>; propSchema: PSchema; isFileBlock?: boolean; domAttributes?: Record<string, string>; children: ReactNode; }): import("react/jsx-runtime").JSX.Element; /** * Helper function to create a React block definition. * Can accept either functions that return the required objects, or the objects directly. */ export declare function createReactBlockSpec<const TName extends string, const TProps extends PropSchema, const TContent extends "inline" | "none", const TOptions extends Record<string, any> | undefined = undefined>(blockConfigOrCreator: BlockConfig<TName, TProps, TContent>, blockImplementationOrCreator: ReactCustomBlockImplementation<BlockConfig<TName, TProps, TContent>> | (TOptions extends undefined ? () => ReactCustomBlockImplementation<BlockConfig<TName, TProps, TContent>> : (options: Partial<TOptions>) => ReactCustomBlockImplementation<BlockConfig<TName, TProps, TContent>>), extensionsOrCreator?: (ExtensionFactoryInstance | Extension)[] | (TOptions extends undefined ? () => (ExtensionFactoryInstance | Extension)[] : (options: Partial<TOptions>) => (ExtensionFactoryInstance | Extension)[])): (options?: Partial<TOptions>) => BlockSpec<TName, TProps, TContent>; export declare function createReactBlockSpec<const TName extends string, const TProps extends PropSchema, const TContent extends "inline" | "none", const BlockConf extends BlockConfig<TName, TProps, TContent>, const TOptions extends Partial<Record<string, any>>>(blockCreator: (options: Partial<TOptions>) => BlockConf, blockImplementationOrCreator: ReactCustomBlockImplementation<BlockConf> | (TOptions extends undefined ? () => ReactCustomBlockImplementation<BlockConf> : (options: Partial<TOptions>) => ReactCustomBlockImplementation<BlockConf>), extensionsOrCreator?: (ExtensionFactoryInstance | Extension)[] | (TOptions extends undefined ? () => (ExtensionFactoryInstance | Extension)[] : (options: Partial<TOptions>) => (ExtensionFactoryInstance | Extension)[])): (options?: Partial<TOptions>) => BlockSpec<BlockConf["type"], BlockConf["propSchema"], BlockConf["content"]>;