11import { ComponentChildren } from "preact" ;
22import { useNoteContext } from "../../react/hooks" ;
3- import { TabContext , TitleContext } from "../ribbon-interface" ;
3+ import { TabContext } from "../ribbon-interface" ;
44import { useEffect , useMemo , useState } from "preact/hooks" ;
55import { RIBBON_TAB_DEFINITIONS } from "../RibbonDefinition" ;
6+ import { shouldShowTab } from "../Ribbon" ;
67
78interface StandaloneRibbonAdapterProps {
89 component : ( props : TabContext ) => ComponentChildren ;
@@ -16,10 +17,11 @@ export default function StandaloneRibbonAdapter({ component }: StandaloneRibbonA
1617 const Component = component ;
1718 const { note, ntxId, hoistedNoteId, notePath, noteContext, componentId } = useNoteContext ( ) ;
1819 const definition = useMemo ( ( ) => RIBBON_TAB_DEFINITIONS . find ( def => def . content === component ) , [ component ] ) ;
19- const [ shown , setShown ] = useState ( unwrapShown ( definition ?. show , { note } ) ) ;
20+ const [ shown , setShown ] = useState < boolean | null | undefined > ( false ) ;
2021
2122 useEffect ( ( ) => {
22- setShown ( unwrapShown ( definition ?. show , { note } ) ) ;
23+ if ( ! definition ) return ;
24+ shouldShowTab ( definition . show , { note, noteContext } ) . then ( setShown ) ;
2325 } , [ note ] ) ;
2426
2527 return (
@@ -35,9 +37,3 @@ export default function StandaloneRibbonAdapter({ component }: StandaloneRibbonA
3537 />
3638 ) ;
3739}
38-
39- function unwrapShown ( value : boolean | ( ( context : TitleContext ) => boolean | null | undefined ) | undefined , context : TitleContext ) {
40- if ( ! value ) return true ;
41- if ( typeof value === "boolean" ) return value ;
42- return ! ! value ( context ) ;
43- }
0 commit comments