@@ -43,7 +43,8 @@ export type Node =
43
43
| "taskList"
44
44
| "blockquote"
45
45
| "table"
46
- | "tableRow" ;
46
+ | "tableRow"
47
+ | "tableBody" ;
47
48
attrs ?: Attrs ;
48
49
marks ?: Array < Mark > ;
49
50
content ?: Array < Node > ;
@@ -239,7 +240,6 @@ export const RichText = <
239
240
key = { index }
240
241
components = { props . components }
241
242
blocks = { props . blocks }
242
- level = { 0 }
243
243
slugger = { slugger }
244
244
/>
245
245
) ;
@@ -331,14 +331,12 @@ const Node = ({
331
331
components,
332
332
blocks,
333
333
parent,
334
- level,
335
334
slugger,
336
335
} : {
337
336
node : Node ;
338
337
components ?: Partial < Handlers > ;
339
338
blocks ?: readonly CustomBlockBase [ ] ;
340
339
parent ?: Node ;
341
- level : number ;
342
340
slugger : GithubSlugger ;
343
341
} ) => {
344
342
const children = node . content ?. map ( ( childNode , index ) => {
@@ -349,7 +347,6 @@ const Node = ({
349
347
key = { index }
350
348
components = { components }
351
349
blocks = { blocks }
352
- level = { level + 1 }
353
350
slugger = { slugger }
354
351
/>
355
352
) ;
@@ -437,7 +434,23 @@ const Node = ({
437
434
break ;
438
435
case "table" :
439
436
handler = components ?. table ?? defaultHandlers . table ;
440
- props = { children } satisfies ExtractPropsForHandler < Handlers [ "table" ] > ;
437
+
438
+ /**
439
+ * In the case of table, we add a tableBody node that wraps its children, as it seems to be missing in the response.
440
+ */
441
+ const overridenChildren = (
442
+ < Node
443
+ node = { { type : "tableBody" , content : node . content } }
444
+ parent = { node }
445
+ components = { components }
446
+ blocks = { blocks }
447
+ slugger = { slugger }
448
+ />
449
+ ) ;
450
+
451
+ props = { children : overridenChildren } satisfies ExtractPropsForHandler <
452
+ Handlers [ "table" ]
453
+ > ;
441
454
break ;
442
455
case "tableRow" :
443
456
handler = components ?. tr ?? defaultHandlers . tr ;
@@ -459,6 +472,14 @@ const Node = ({
459
472
rowspan : node . attrs . rowspan ,
460
473
} satisfies ExtractPropsForHandler < Handlers [ "th" ] > ;
461
474
break ;
475
+ case "tableFooter" :
476
+ handler = components ?. tfoot ?? defaultHandlers . tfoot ;
477
+ props = { children } satisfies ExtractPropsForHandler < Handlers [ "tfoot" ] > ;
478
+ break ;
479
+ case "tableBody" :
480
+ handler = components ?. tbody ?? defaultHandlers . tbody ;
481
+ props = { children } satisfies ExtractPropsForHandler < Handlers [ "tbody" ] > ;
482
+ break ;
462
483
case "image" :
463
484
handler = components ?. img ?? defaultHandlers . img ;
464
485
props = {
@@ -481,23 +502,29 @@ const Node = ({
481
502
break ;
482
503
case "basehub-block" : {
483
504
const block = blocks ?. find ( ( block : any ) => {
505
+ const typename = block ?. __typename as string | undefined ;
506
+ const keysLength = Object . keys ( block ) . length ;
484
507
const id = block ?. _id ?? block ?. _sys ?. id ;
485
- if ( typeof id !== "string" ) {
508
+ if ( typeof id !== "string" && ( ! typename || keysLength > 1 ) ) {
486
509
if ( isDev ) {
487
510
console . warn (
488
- `BaseHub RichText Error: make sure you send through the _id and the __typename for all custom blocks.`
511
+ `BaseHub RichText Error: make sure you send through the _id and the __typename for all custom blocks.\nReceived ${ JSON . stringify (
512
+ block ,
513
+ null ,
514
+ 2
515
+ ) } .`
489
516
) ;
490
517
}
491
518
return false ;
492
519
}
493
520
return id === node . attrs . id ;
494
521
} ) ;
495
522
if ( ! block ) {
496
- if ( isDev ) {
497
- console . warn (
498
- `BaseHub RichText Error: block "${ node . attrs . id } " not found.`
499
- ) ;
500
- }
523
+ // if (isDev) {
524
+ // console.warn(
525
+ // `BaseHub RichText Error: block "${node.attrs.id}" not found.`
526
+ // );
527
+ // }
501
528
break ;
502
529
}
503
530
// @ts -ignore
@@ -577,22 +604,29 @@ const Marks = ({
577
604
break ;
578
605
case "basehub-inline-block" : {
579
606
const block = blocks ?. find ( ( block : any ) => {
607
+ const typename = block ?. __typename as string | undefined ;
608
+ const keysLength = Object . keys ( block ) . length ;
580
609
const id = block ?. _id ?? block ?. _sys ?. id ;
581
- if ( typeof id !== "string" ) {
610
+ if ( typeof id !== "string" && ( ! typename || keysLength > 1 ) ) {
582
611
if ( isDev ) {
583
612
console . warn (
584
- `BaseHub RichText Error: make sure you send through the _id and the __typename for all custom blocks.`
613
+ `BaseHub RichText Error: make sure you send through the _id and the __typename for all custom blocks.\nReceived ${ JSON . stringify (
614
+ block ,
615
+ null ,
616
+ 2
617
+ ) } .`
585
618
) ;
586
619
}
620
+ return false ;
587
621
}
588
622
return id === mark . attrs . id ;
589
623
} ) ;
590
624
if ( ! block ) {
591
- if ( isDev ) {
592
- console . warn (
593
- `BaseHub RichText Error: block "${ mark . attrs . id } " not found.`
594
- ) ;
595
- }
625
+ // if (isDev) {
626
+ // console.warn(
627
+ // `BaseHub RichText Error: block "${mark.attrs.id}" not found.`
628
+ // );
629
+ // }
596
630
break ;
597
631
}
598
632
handler =
0 commit comments