@@ -24,7 +24,7 @@ import InfoStyles from '@/styles/info-styles';
24
24
import CustomStyles from '@/styles/custom-styles' ;
25
25
import { expandCollapseNavBarTag } from '@/templates/navbar-template' ;
26
26
import {
27
- pathIsInSearch , invalidCharsRegEx , sleep , rapidocApiKey , advancedSearch , hasValidPathInUrlHash ,
27
+ pathIsInSearch , sleep , rapidocApiKey , advancedSearch , hasValidPathInUrlHash ,
28
28
} from '@/utils/common-utils' ;
29
29
import ProcessSpec from '@/utils/spec-parser' ;
30
30
import mainBodyTemplate from '@/templates/main-body-template' ;
@@ -435,7 +435,7 @@ export default class RapiDoc extends LitElement {
435
435
await this . loadSpec ( newVal ) ;
436
436
// If goto-path is provided then try to scroll there
437
437
if ( this . gotoPath ) {
438
- this . scrollTo ( this . gotoPath . replace ( invalidCharsRegEx , '-' ) . toLowerCase ( ) ) ;
438
+ this . scrollTo ( this . gotoPath ) ;
439
439
}
440
440
} , 0 ) ;
441
441
}
@@ -610,17 +610,13 @@ export default class RapiDoc extends LitElement {
610
610
this . selectedContentId = '' ;
611
611
// If there is hash in url then check if hash belong to any of the path in spec
612
612
if ( window . location . hash ) {
613
- this . selectedContentId = window . location . hash . substring ( 1 ) . startsWith ( 'overview--' )
614
- ? 'overview' : hasValidPathInUrlHash ( this . resolvedSpec . tags )
615
- ? window . location . hash . substring ( 1 ) : '' ;
613
+ if ( 'top, overview, authentication, api-servers' . includes ( window . location . hash . substring ( 1 ) ) || hasValidPathInUrlHash ( this . resolvedSpec . tags ) ) {
614
+ this . selectedContentId = window . location . hash . substring ( 1 ) ;
615
+ }
616
616
}
617
- // If there is no matching hash to path , check if there is sufficient data to display overview otherwise just display first path from first tag
617
+ // If there is no valid location- hash, check if there is sufficient data to display overview otherwise just display first path from first tag
618
618
if ( ! this . selectedContentId ) {
619
- if ( this . showInfo === 'true' && ( this . resolvedSpec . info ?. description || this . resolvedSpec . info ?. title ) ) {
620
- this . selectedContentId = 'overview' ;
621
- } else {
622
- this . selectedContentId = `${ this . resolvedSpec . tags [ 0 ] ?. paths [ 0 ] ?. method } -${ this . resolvedSpec . tags [ 0 ] ?. paths [ 0 ] ?. path } ` ;
623
- }
619
+ this . selectedContentId = 'top' ;
624
620
}
625
621
// Set url back in address bar
626
622
window . location . hash = `${ this . selectedContentId } ` ;
@@ -650,33 +646,37 @@ export default class RapiDoc extends LitElement {
650
646
651
647
// Initiate IntersectionObserver and put it at the end of event loop, to allow loading all the child elements (must for larger specs)
652
648
this . intersectionObserver . disconnect ( ) ;
653
- if ( this . renderStyle === 'read' ) {
654
- await sleep ( 100 ) ;
655
- this . observeExpandedContent ( ) ; // This will auto-highlight the selected nav
656
- } else if ( this . renderStyle === 'focused' ) {
657
- await sleep ( 0 ) ;
658
- const newNavEl = this . shadowRoot . getElementById ( `link-${ this . selectedContentId } ` ) ;
659
- if ( newNavEl ) {
660
- newNavEl . classList . add ( 'active' ) ;
661
- newNavEl . scrollIntoView ( { behavior : 'auto' , block : 'center' } ) ;
649
+ if ( window . location . hash ) {
650
+ if ( this . renderStyle === 'read' ) {
651
+ await sleep ( 100 ) ;
652
+ this . observeExpandedContent ( ) ; // This will auto-highlight the selected nav-item in read-mode
653
+ } else if ( this . renderStyle === 'focused' ) {
654
+ await sleep ( 0 ) ;
655
+ const newNavEl = this . shadowRoot . getElementById ( `link-${ this . selectedContentId } ` ) ;
656
+ if ( newNavEl ) {
657
+ newNavEl . classList . add ( 'active' ) ;
658
+ newNavEl . scrollIntoView ( { behavior : 'auto' , block : 'center' } ) ;
659
+ }
662
660
}
663
661
}
664
662
// On first time Spec load, try to navigate to location hash if provided
665
663
if ( window . location . hash ) {
666
664
if ( ! this . gotoPath ) {
667
- this . expandTreeToPath ( window . location . hash , true , true ) ;
665
+ this . expandAndGotoOperation ( window . location . hash , true , true ) ;
668
666
}
669
667
}
670
668
}
671
669
672
- expandTreeToPath ( pathInput , expandOperation = true , scrollToElement = true ) {
670
+ expandAndGotoOperation ( elementId , expandOperation = true , scrollToElement = true ) {
673
671
// Expand full operation and tag
674
- if ( pathInput . indexOf ( '#' ) === 0 ) pathInput = pathInput . substring ( 1 ) ;
672
+ if ( elementId . indexOf ( '#' ) === 0 ) {
673
+ elementId = elementId . substring ( 1 ) ;
674
+ }
675
675
let path ;
676
676
this . resolvedSpec . tags . map ( ( tag ) => tag . paths . filter ( ( v ) => {
677
- const method = pathInput . match ( new RegExp ( '(.*?)-' ) ) ;
677
+ const method = elementId . match ( new RegExp ( '(.*?)-' ) ) ;
678
678
const methodType = ( method && method . length === 2 ) ? method [ 1 ] : null ;
679
- path = pathInput . match ( new RegExp ( '/.*$' ) ) ;
679
+ path = elementId . match ( new RegExp ( '/.*$' ) ) ;
680
680
const pathValue = ( path && path . length === 1 ) ? path [ 0 ] : null ;
681
681
682
682
if ( methodType && pathValue && methodType === v . method && pathValue === v . path ) {
@@ -689,7 +689,7 @@ export default class RapiDoc extends LitElement {
689
689
if ( scrollToElement ) {
690
690
// delay required, else we cant find element
691
691
window . setTimeout ( ( ) => {
692
- const gotoEl = this . shadowRoot . getElementById ( pathInput ) ;
692
+ const gotoEl = this . shadowRoot . getElementById ( elementId ) ;
693
693
if ( gotoEl ) {
694
694
gotoEl . scrollIntoView ( { behavior : 'auto' , block : 'start' } ) ;
695
695
}
@@ -778,7 +778,7 @@ export default class RapiDoc extends LitElement {
778
778
await sleep ( 0 ) ;
779
779
const gotoEl = this . shadowRoot . getElementById ( path ) ;
780
780
if ( gotoEl ) {
781
- this . expandTreeToPath ( path , expandPath , true ) ;
781
+ this . expandAndGotoOperation ( path , expandPath , true ) ;
782
782
const oldNavEl = this . shadowRoot . querySelector ( '.nav-bar-tag.active, .nav-bar-path.active, .nav-bar-info.active, .nav-bar-h1.active, .nav-bar-h2.active' ) ;
783
783
const newNavEl = this . shadowRoot . getElementById ( `link-${ path } ` ) ;
784
784
if ( oldNavEl ) {
0 commit comments