@@ -20,6 +20,8 @@ const serializeBlockTree = (children: TreeNode[]): RoamNodeType[] =>
2020 . sort ( ( a , b ) => a . order - b . order )
2121 . map ( ( child ) => ( {
2222 text : child . text ,
23+ ...( child . heading && { heading : child . heading as 0 | 1 | 2 | 3 } ) ,
24+ ...( child . open === false && { open : false } ) ,
2325 ...( child . children . length > 0 && {
2426 children : serializeBlockTree ( child . children ) ,
2527 } ) ,
@@ -49,24 +51,29 @@ const DualWriteBlocksPanel = ({
4951
5052 useEffect ( ( ) => {
5153 const el = containerRef . current ;
52- if ( ! el ) return ;
54+ if ( ! el || ! uid ) return ;
55+
56+ const pattern = "[:block/string :block/order {:block/children ...}]" ;
57+ const entityId = `[:block/uid "${ uid } "]` ;
58+ const callback = ( ) => handleChange ( ) ;
59+
60+ const registerPullWatch = ( ) => {
61+ pullWatchArgsRef . current = [ pattern , entityId , callback ] ;
62+ window . roamAlphaAPI . data . addPullWatch ( pattern , entityId , callback ) ;
63+ } ;
5364
5465 if ( ! getFirstChildUidByBlockUid ( uid ) ) {
5566 void createBlock ( { node : { text : " " } , parentUid : uid } ) . then ( ( ) => {
5667 el . innerHTML = "" ;
5768 void window . roamAlphaAPI . ui . components . renderBlock ( { uid, el } ) ;
69+ registerPullWatch ( ) ;
5870 } ) ;
5971 } else {
6072 el . innerHTML = "" ;
6173 void window . roamAlphaAPI . ui . components . renderBlock ( { uid, el } ) ;
74+ registerPullWatch ( ) ;
6275 }
6376
64- const pattern = "[:block/string :block/order {:block/children ...}]" ;
65- const entityId = `[:block/uid "${ uid } "]` ;
66- const callback = ( ) => handleChange ( ) ;
67- pullWatchArgsRef . current = [ pattern , entityId , callback ] ;
68- window . roamAlphaAPI . data . addPullWatch ( pattern , entityId , callback ) ;
69-
7077 return ( ) => {
7178 window . clearTimeout ( debounceRef . current ) ;
7279 if ( pullWatchArgsRef . current ) {
0 commit comments