@@ -236,18 +236,27 @@ export function parseLink(
236236
237237 if ( isCell ( value ) || isStream ( value ) ) return value . getAsNormalizedFullLink ( ) ;
238238
239+ let baseLink : NormalizedLink | undefined ;
240+ if ( base ) {
241+ if ( isCell ( base ) || isStream ( base ) ) {
242+ baseLink = base . getAsNormalizedFullLink ( ) ;
243+ } else {
244+ baseLink = base as NormalizedLink ;
245+ }
246+ }
247+
239248 // Handle new sigil format
240249 if ( isSigilLink ( value ) ) {
241250 const link = value [ "/" ] [ LINK_V1_TAG ] ;
242251
243252 // Resolve relative references
244253 let id = link . id ;
245254 const path = link . path || [ ] ;
246- const resolvedSpace = link . space || base ?. space ;
255+ const resolvedSpace = link . space || baseLink ?. space ;
247256
248257 // If no id provided, use base cell's document
249- if ( ! id && base ) {
250- id = isAnyCell ( base ) ? toURI ( base . entityId ) : base . id ;
258+ if ( ! id && baseLink ?. id ) {
259+ id = baseLink . id ;
251260 }
252261
253262 return {
@@ -266,7 +275,7 @@ export function parseLink(
266275 return {
267276 id : toURI ( value . cell [ "/" ] ) ,
268277 path : value . path . map ( ( p ) => p . toString ( ) ) ,
269- ...( base ?. space && { space : base . space } ) ,
278+ ...( baseLink ?. space && { space : baseLink . space } ) ,
270279 type : "application/json" ,
271280 } ;
272281 }
@@ -275,7 +284,7 @@ export function parseLink(
275284 return {
276285 id : toURI ( value [ "/" ] ) ,
277286 path : [ ] ,
278- ...( base ?. space && { space : base . space } ) , // Space must come from context for JSON links
287+ ...( baseLink ?. space && { space : baseLink . space } ) , // Space must come from context for JSON links
279288 type : "application/json" ,
280289 } ;
281290 }
@@ -293,16 +302,16 @@ export function parseLink(
293302 }
294303
295304 // If no cell provided, use base cell's document
296- if ( ! id && base ) {
297- id = isAnyCell ( base ) ? toURI ( base . entityId ) : base . id ;
305+ if ( ! id && baseLink ?. id ) {
306+ id = baseLink . id ;
298307 }
299308
300309 return {
301310 ...( id && { id } ) ,
302311 path : Array . isArray ( alias . path )
303312 ? alias . path . map ( ( p ) => p . toString ( ) )
304313 : [ ] ,
305- ...( base ?. space && { space : base . space } ) ,
314+ ...( baseLink ?. space && { space : baseLink . space } ) ,
306315 type : "application/json" ,
307316 ...( alias . schema && { schema : alias . schema } ) ,
308317 ...( alias . rootSchema && { rootSchema : alias . rootSchema } ) ,
0 commit comments