1
1
/** Define the main block types **/
2
- import type { Extension , Node } from "@tiptap/core" ;
3
2
3
+ import type { Fragment , Schema } from "prosemirror-model" ;
4
+ import type { ViewMutationRecord } from "prosemirror-view" ;
4
5
import type { BlockNoteEditor } from "../../editor/BlockNoteEditor.js" ;
6
+ import type { BlockNoteExtension } from "../../editor/BlockNoteExtension.js" ;
5
7
import type {
6
8
InlineContent ,
7
9
InlineContentSchema ,
8
10
PartialInlineContent ,
9
11
} from "../inlineContent/types.js" ;
10
12
import type { PropSchema , Props } from "../propTypes.js" ;
11
13
import 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" ;
15
14
16
15
export type BlockNoteDOMElement =
17
16
| "editor"
@@ -76,45 +75,10 @@ export interface BlockConfig<
76
75
meta ?: BlockConfigMeta ;
77
76
}
78
77
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
-
109
78
// 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 > = {
116
80
config : T ;
117
- implementation : TiptapBlockImplementation < NoInfer < T > , B , I , S > ;
81
+ implementation : BlockImplementation < NoInfer < T [ "type" ] > , PropSchema > ;
118
82
} ;
119
83
120
84
// 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 {
133
97
// The keys are the "type" of a block
134
98
export type BlockSchema = NamesMatch < Record < string , BlockConfig > > ;
135
99
136
- export type BlockSpecs = Record <
137
- string ,
138
- BlockSpec < any , any , InlineContentSchema , StyleSchema >
139
- > ;
100
+ export type BlockSpecs = Record < string , BlockSpec < any > > ;
140
101
141
102
export type BlockImplementations = Record <
142
103
string ,
143
- TiptapBlockImplementation < any , any , any , any >
104
+ BlockImplementation < any , any >
144
105
> ;
145
106
146
107
export type BlockSchemaFromSpecs < T extends BlockSpecs > = {
0 commit comments