1- import { Attribute , Attributes , Editor , Node } from "@tiptap/core" ;
1+ import { Attribute , Attributes , Node } from "@tiptap/core" ;
2+ import type { Node as PMNode } from "prosemirror-model" ;
3+ import { getBlock } from "../../api/blockManipulation/getBlock/getBlock.js" ;
24import { defaultBlockToHTML } from "../../blocks/defaultBlockHelpers.js" ;
3- import type { BlockNoteEditor } from "../../editor/BlockNoteEditor.js" ;
45import type { ExtensionFactoryInstance } from "../../editor/BlockNoteExtension.js" ;
56import { mergeCSSClasses } from "../../util/browser.js" ;
67import { camelToDataKebab } from "../../util/string.js" ;
7- import { InlineContentSchema } from "../inlineContent/types.js" ;
88import { PropSchema , Props } from "../propTypes.js" ;
9- import { StyleSchema } from "../styles/types.js" ;
10- import {
11- BlockConfig ,
12- BlockSchemaWithBlock ,
13- LooseBlockSpec ,
14- SpecificBlock ,
15- } from "./types.js" ;
9+ import { BlockConfig , BlockFromConfig , LooseBlockSpec } from "./types.js" ;
1610
1711// Function that uses the 'propSchema' of a blockConfig to create a TipTap
1812// node's `addAttributes` property.
@@ -85,22 +79,16 @@ export function propsToAttributes(propSchema: PropSchema): Attributes {
8579export function getBlockFromPos <
8680 BType extends string ,
8781 Config extends BlockConfig ,
88- BSchema extends BlockSchemaWithBlock < BType , Config > ,
89- I extends InlineContentSchema ,
90- S extends StyleSchema ,
91- > (
92- getPos : ( ) => number | undefined ,
93- editor : BlockNoteEditor < BSchema , I , S > ,
94- tipTapEditor : Editor ,
95- type : BType ,
96- ) {
82+ > ( getPos : ( ) => number | undefined , doc : PMNode , type : BType ) {
83+ // TODO is there a cleaner implementation of this? Probably...
9784 const pos = getPos ( ) ;
9885 // Gets position of the node
9986 if ( pos === undefined ) {
10087 throw new Error ( "Cannot find node position" ) ;
10188 }
89+
10290 // Gets parent blockContainer node
103- const blockContainer = tipTapEditor . state . doc . resolve ( pos ! ) . node ( ) ;
91+ const blockContainer = doc . resolve ( pos ) . node ( ) ;
10492 // Gets block identifier
10593 const blockIdentifier = blockContainer . attrs . id ;
10694
@@ -109,16 +97,14 @@ export function getBlockFromPos<
10997 }
11098
11199 // Gets the block
112- const block = editor . getBlock ( blockIdentifier ) ! as SpecificBlock <
113- BSchema ,
114- BType ,
115- I ,
116- S
100+ const block = getBlock ( doc , blockIdentifier ) as BlockFromConfig <
101+ Config ,
102+ any ,
103+ any
117104 > ;
118105 if ( block . type !== type ) {
119106 throw new Error ( "Block type does not match" ) ;
120107 }
121-
122108 return block ;
123109}
124110
0 commit comments