You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
check what happens if {{[[table]]}} block ALSO has a {{SmartBlock}} button
Notes
I started looking into this, but didn't get a chance to finish. Here were my findings:
If a SmartBlock button is part of roam {{[[table]]}} the observer doesn't catch it because it's parent blockUid is actually the table block, so the match check fails as there is no SmartBlock button in it's textContent.
It doesn't look like there the original uid that holds the SmartBlock button (VeSLtlz0N) is accessible in the DOM
If !match we could check text (which is parentUid text) for {{[[table]]}}
If true
calculate row/column position based on DOM (el is the button element in the roam )
get the tree of parentUid
get original uid based on row/column
something like:
// check if parent is roam {{[[table]]}}constgetMatchFromRoamTable=()=>{constparentText=getTextByBlockUid(parentUid);constroamTablePattern=/\{\{\[\[table\]\]\}\}/;constisInRoamTable=roamTablePattern.exec(parentText);if(!isInRoamTable)returnnull;consttableEl=el.closest("table");if(!tableEl)returnnull;// Get the row and column of the buttonconstrows=Array.from(tableEl.querySelectorAll("tr")).filter((row)=>row.innerHTML.trim()!==""// first row is blank?);letposition={row: 0,column: 0};rows.map((row,rowIndex)=>{constcells=Array.from(row.querySelectorAll("td"));cells.map((cell,colIndex)=>{if(cell.contains(el)){position={row: rowIndex+1,column: colIndex+1};}});});if(!position.row||!position.column)returnnull;// Get UID from tree based positionconsttree=getBasicTreeByParentUid(parentUid);constuid=getUidFromTablePosition()// need to create thisconsttableButtonText=getTextByBlockUid(uid);returnregex.exec(tableButtonText);};if(!match)match=getMatchFromRoamTable();
but the getUidFromTablePosition() gets a little tricky as there are multiple ways to construct a table
It looks like
node with no children = 1 row
node with 1 child = 1 row
node with 1+n children = 1+n rows
I didn't get a chance to finish writing that, but unless I missed something, it seems quite possible.
Oh, also, should consider if the {{[[table]]}} block ALSO has a {{SmartBlock}} button ... check to make sure it gets the data-roamjs-smartblock-button first.
The text was updated successfully, but these errors were encountered:
reported by Mark L via slack.
tl;dr What's left
getUidFromTablePosition()
{{[[table]]}}
block ALSO has a{{SmartBlock}}
buttonNotes
I started looking into this, but didn't get a chance to finish. Here were my findings:
If a SmartBlock button is part of roam
{{[[table]]}}
the observer doesn't catch it because it's parentblockUid
is actually the table block, so thematch
check fails as there is no SmartBlock button in it'stextContent
.It doesn't look like there the original
uid
that holds the SmartBlock button (VeSLtlz0N
) is accessible in the DOMPossible solution:
smartblocks/src/index.ts
Lines 543 to 561 in 170690d
If
!match
we could checktext
(which isparentUid
text) for{{[[table]]}}
If true
el
is the button element in the roam )parentUid
uid
based on row/columnsomething like:
but the
getUidFromTablePosition()
gets a little tricky as there are multiple ways to construct a tableIt looks like
I didn't get a chance to finish writing that, but unless I missed something, it seems quite possible.
Oh, also, should consider if the
{{[[table]]}}
block ALSO has a{{SmartBlock}}
button ... check to make sure it gets thedata-roamjs-smartblock-button
first.The text was updated successfully, but these errors were encountered: