@@ -18,6 +18,7 @@ import {
1818} from "~/components/canvas/stores/assetStore" ;
1919import { showToast } from "./toastUtils" ;
2020import { CreateNodeModal } from "~/components/CreateNodeModal" ;
21+ import { calcDiscourseNodeSize } from "~/utils/calcDiscourseNodeSize" ;
2122
2223type ConvertToDiscourseNodeArgs = {
2324 editor : Editor ;
@@ -140,8 +141,10 @@ const convertImageShapeToNode = async ({
140141 throw new Error ( "Failed to create discourse node file" ) ;
141142 }
142143
144+ let imageSrc : string | undefined ;
143145 if ( imageFile ) {
144146 await embedImageInNode ( createdFile , imageFile , plugin ) ;
147+ imageSrc = plugin . app . vault . getResourcePath ( imageFile ) ;
145148 }
146149
147150 shapeId = await createDiscourseNodeShape ( {
@@ -151,6 +154,7 @@ const convertImageShapeToNode = async ({
151154 nodeType : selectedNodeType ,
152155 plugin,
153156 canvasFile,
157+ imageSrc,
154158 } ) ;
155159
156160 showToast ( {
@@ -178,38 +182,44 @@ const createDiscourseNodeShape = async ({
178182 nodeType,
179183 plugin,
180184 canvasFile,
185+ imageSrc,
181186} : {
182187 editor : Editor ;
183188 shape : TLShape ;
184189 createdFile : TFile ;
185190 nodeType : DiscourseNode ;
186191 plugin : DiscourseGraphPlugin ;
187192 canvasFile : TFile ;
193+ imageSrc ?: string ;
188194} ) : Promise < TLShapeId > => {
189195 const src = await addWikilinkBlockrefForFile ( {
190196 app : plugin . app ,
191197 canvasFile,
192198 linkedFile : createdFile ,
193199 } ) ;
194200
195- // Get the position and size of the original shape
196201 const { x, y } = shape ;
197- const width = "w" in shape . props ? Number ( shape . props . w ) : 200 ;
198- const height = "h" in shape . props ? Number ( shape . props . h ) : 100 ;
202+
203+ const { w, h } = await calcDiscourseNodeSize ( {
204+ title : createdFile . basename ,
205+ nodeTypeId : nodeType . id ,
206+ imageSrc,
207+ plugin,
208+ } ) ;
199209
200210 const shapeId = createShapeId ( ) ;
201- // TODO: Update the imageSrc, width and height of the shape after the key figure is merged
202211 editor . createShape ( {
203212 id : shapeId ,
204213 type : "discourse-node" ,
205214 x,
206215 y,
207216 props : {
208- w : Math . max ( width , 200 ) ,
209- h : Math . max ( height , 100 ) ,
217+ w,
218+ h,
210219 src : src ?? "" ,
211220 title : createdFile . basename ,
212221 nodeTypeId : nodeType . id ,
222+ imageSrc,
213223 } ,
214224 } ) ;
215225
0 commit comments