11/** Define the main block types **/
2- import type { Extension , Node } from "@tiptap/core" ;
32
3+ import type { Fragment , Schema } from "prosemirror-model" ;
4+ import type { ViewMutationRecord } from "prosemirror-view" ;
45import type { BlockNoteEditor } from "../../editor/BlockNoteEditor.js" ;
6+ import type { BlockNoteExtension } from "../../editor/BlockNoteExtension.js" ;
57import type {
68 InlineContent ,
79 InlineContentSchema ,
810 PartialInlineContent ,
911} from "../inlineContent/types.js" ;
1012import type { PropSchema , Props } from "../propTypes.js" ;
1113import type { StyleSchema } from "../styles/types.js" ;
12- import type { BlockNoteExtension } from "../../editor/BlockNoteExtension.js" ;
13- import type { Fragment , Schema } from "prosemirror-model" ;
14- import type { ViewMutationRecord } from "prosemirror-view" ;
1514
1615export type BlockNoteDOMElement =
1716 | "editor"
@@ -76,45 +75,10 @@ export interface BlockConfig<
7675 meta ?: BlockConfigMeta ;
7776}
7877
79- // Block implementation contains the "implementation" info about a Block
80- // such as the functions / Nodes required to render and / or serialize it
81- export type TiptapBlockImplementation <
82- T extends BlockConfig ,
83- B extends BlockSchema ,
84- I extends InlineContentSchema ,
85- S extends StyleSchema ,
86- > = {
87- requiredExtensions ?: Array < Extension | Node > ;
88- node : Node ;
89- toInternalHTML : (
90- block : BlockFromConfigNoChildren < T , I , S > & {
91- children : BlockNoDefaults < B , I , S > [ ] ;
92- } ,
93- editor : BlockNoteEditor < B , I , S > ,
94- ) => {
95- dom : HTMLElement ;
96- contentDOM ?: HTMLElement ;
97- } ;
98- toExternalHTML : (
99- block : BlockFromConfigNoChildren < T , I , S > & {
100- children : BlockNoDefaults < B , I , S > [ ] ;
101- } ,
102- editor : BlockNoteEditor < B , I , S > ,
103- ) => {
104- dom : HTMLElement ;
105- contentDOM ?: HTMLElement ;
106- } ;
107- } ;
108-
10978// A Spec contains both the Config and Implementation
110- export type BlockSpec <
111- T extends BlockConfig ,
112- B extends BlockSchema ,
113- I extends InlineContentSchema ,
114- S extends StyleSchema ,
115- > = {
79+ export type BlockSpec < T extends BlockConfig > = {
11680 config : T ;
117- implementation : TiptapBlockImplementation < NoInfer < T > , B , I , S > ;
81+ implementation : BlockImplementation < NoInfer < T [ "type" ] > , PropSchema > ;
11882} ;
11983
12084// Utility type. For a given object block schema, ensures that the key of each
@@ -133,14 +97,11 @@ type NamesMatch<Blocks extends Record<string, BlockConfig>> = Blocks extends {
13397// The keys are the "type" of a block
13498export type BlockSchema = NamesMatch < Record < string , BlockConfig > > ;
13599
136- export type BlockSpecs = Record <
137- string ,
138- BlockSpec < any , any , InlineContentSchema , StyleSchema >
139- > ;
100+ export type BlockSpecs = Record < string , BlockSpec < any > > ;
140101
141102export type BlockImplementations = Record <
142103 string ,
143- TiptapBlockImplementation < any , any , any , any >
104+ BlockImplementation < any , any >
144105> ;
145106
146107export type BlockSchemaFromSpecs < T extends BlockSpecs > = {
0 commit comments