1- import { preserveAnchorNodePosition } from 'scroll-anchoring'
2-
31import { useArticleContext } from '@/frame/components/context/ArticleContext'
42import { InArticlePicker } from './InArticlePicker'
53import { useSelection } from './SelectionContext'
@@ -10,38 +8,6 @@ import { TOOL_PREFERRED_COOKIE_NAME } from '@/frame/lib/constants'
108// Nota bene: tool === application
119// Nota bene: picker === switcher
1210
13- // Imperatively modify article content to show only the selected tool
14- // find all platform-specific *block* elements and hide or show as appropriate
15- // example: {% webui %} block content {% endwebui %}
16- function showToolSpecificContent ( tool : string , supportedTools : Array < string > ) {
17- const markdowns = Array . from ( document . querySelectorAll < HTMLElement > ( '.ghd-tool' ) )
18- const supportedMarkdowns = markdowns . filter ( ( xel ) =>
19- supportedTools . some ( ( toolName ) => xel . classList . contains ( toolName ) ) ,
20- )
21- for ( const el of supportedMarkdowns ) {
22- el . style . display = el . classList . contains ( tool ) ? '' : 'none'
23-
24- // hack: special handling for minitoc links -- we can't pass the tool classes
25- // directly to the Primer NavList.Item generated <li>, it gets passed down
26- // to the child <a>. So if we find an <a> that has the tool class and its
27- // parent is an <li>, we hide/unhide that element as well.
28- if ( el . tagName === 'A' && el . parentElement && el . parentElement . tagName === 'LI' ) {
29- el . parentElement . style . display = el . classList . contains ( tool ) ? '' : 'none'
30- }
31- }
32-
33- // find all tool-specific *inline* elements and hide or show as appropriate
34- // example: <span class="tool-webui">inline content</span>
35- const toolEls = Array . from (
36- document . querySelectorAll < HTMLElement > (
37- supportedTools . map ( ( toolOption ) => `.tool-${ toolOption } ` ) . join ( ', ' ) ,
38- ) ,
39- )
40- for ( const el of toolEls ) {
41- el . style . display = el . classList . contains ( `tool-${ tool } ` ) ? '' : 'none'
42- }
43- }
44-
4511function getDefaultTool ( defaultTool : string | undefined , detectedTools : Array < string > ) : string {
4612 // If there is a default tool and the tool is present on this page
4713 if ( defaultTool && detectedTools . includes ( defaultTool ) ) return defaultTool
@@ -59,7 +25,7 @@ function getDefaultTool(defaultTool: string | undefined, detectedTools: Array<st
5925const toolQueryKey = 'tool'
6026export const ToolPicker = ( ) => {
6127 // allTools comes from the ArticleContext which contains the list of tools available
62- const { defaultTool, detectedTools, allTools, renderedPageHast } = useArticleContext ( )
28+ const { defaultTool, detectedTools, allTools } = useArticleContext ( )
6329 const { setTool } = useSelection ( )
6430
6531 if ( ! detectedTools . length ) return null
@@ -74,14 +40,10 @@ export const ToolPicker = () => {
7440 cookieKey = { TOOL_PREFERRED_COOKIE_NAME }
7541 queryStringKey = { toolQueryKey }
7642 onValue = { ( value : string ) => {
77- // Drive visibility through React state on the hast path (#6619). Only the
78- // string fallback still needs the imperative DOM mutation.
43+ // Visibility is driven by React state via ToggleableContent/MiniTocs
44+ // (#6619); the article body is React-owned on both the hast and string
45+ // paths, so no imperative DOM mutation is needed.
7946 setTool ( value )
80- if ( ! renderedPageHast ) {
81- preserveAnchorNodePosition ( document , ( ) => {
82- showToolSpecificContent ( value , Object . keys ( allTools ) )
83- } )
84- }
8547 } }
8648 preferenceName = "application"
8749 ariaLabel = "Tool"
0 commit comments