mirror of
https://github.com/squidfunk/mkdocs-material.git
synced 2024-06-14 11:52:32 +03:00
Refactored navigation observables
This commit is contained in:
parent
ca27f23674
commit
189473867c
@ -22,4 +22,5 @@
|
|||||||
|
|
||||||
export * from "./_"
|
export * from "./_"
|
||||||
export * from "./main"
|
export * from "./main"
|
||||||
|
export * from "./navigation"
|
||||||
export * from "./search"
|
export * from "./search"
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
* IN THE SOFTWARE.
|
* IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { Observable, OperatorFunction, of, pipe } from "rxjs"
|
import { Observable, OperatorFunction, pipe } from "rxjs"
|
||||||
import { map, shareReplay, switchMap } from "rxjs/operators"
|
import { map, shareReplay, switchMap } from "rxjs/operators"
|
||||||
|
|
||||||
import {
|
import {
|
||||||
@ -75,51 +75,6 @@ interface MountOptions {
|
|||||||
screen$: Observable<boolean> /* Screen media observable */
|
screen$: Observable<boolean> /* Screen media observable */
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------------
|
|
||||||
* Helper functions
|
|
||||||
* ------------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Mount navigation below screen from source observable
|
|
||||||
*
|
|
||||||
* @param options - Options
|
|
||||||
*
|
|
||||||
* @return Operator function
|
|
||||||
*/
|
|
||||||
function mountNavigationBelowScreen(
|
|
||||||
_options: MountOptions
|
|
||||||
): OperatorFunction<HTMLElement, NavigationBelowScreen> {
|
|
||||||
return pipe(
|
|
||||||
map(el => getElements("nav", el)),
|
|
||||||
switchMap(els => watchNavigationLayer(els)
|
|
||||||
.pipe(
|
|
||||||
paintNavigationLayer(els),
|
|
||||||
map(layer => ({ layer }))
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Mount navigation above screen from source observable
|
|
||||||
*
|
|
||||||
* @param options - Options
|
|
||||||
*
|
|
||||||
* @return Operator function
|
|
||||||
*/
|
|
||||||
function mountNavigationAboveScreen(
|
|
||||||
options: MountOptions
|
|
||||||
): OperatorFunction<HTMLElement, NavigationAboveScreen> {
|
|
||||||
return pipe(
|
|
||||||
switchMap(el => watchSidebar(el, options)
|
|
||||||
.pipe(
|
|
||||||
paintSidebar(el),
|
|
||||||
map(sidebar => ({ sidebar }))
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------------
|
/* ----------------------------------------------------------------------------
|
||||||
* Functions
|
* Functions
|
||||||
* ------------------------------------------------------------------------- */
|
* ------------------------------------------------------------------------- */
|
||||||
@ -137,10 +92,26 @@ export function mountNavigation(
|
|||||||
return pipe(
|
return pipe(
|
||||||
switchMap(el => options.screen$
|
switchMap(el => options.screen$
|
||||||
.pipe(
|
.pipe(
|
||||||
switchMap(screen => screen
|
switchMap(screen => {
|
||||||
? of(el).pipe(mountNavigationAboveScreen(options))
|
|
||||||
: of(el).pipe(mountNavigationBelowScreen(options))
|
/* Mount sidebar for screen and above */
|
||||||
|
if (screen) {
|
||||||
|
return watchSidebar(el, options)
|
||||||
|
.pipe(
|
||||||
|
paintSidebar(el),
|
||||||
|
map(sidebar => ({ sidebar }))
|
||||||
)
|
)
|
||||||
|
|
||||||
|
/* Mount navigation layer otherwise */
|
||||||
|
} else {
|
||||||
|
const els = getElements("nav", el)
|
||||||
|
return watchNavigationLayer(els)
|
||||||
|
.pipe(
|
||||||
|
paintNavigationLayer(els),
|
||||||
|
map(layer => ({ layer }))
|
||||||
|
)
|
||||||
|
}
|
||||||
|
})
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
shareReplay(1)
|
shareReplay(1)
|
||||||
|
@ -30,24 +30,16 @@ import * as Clipboard from "clipboard"
|
|||||||
import { identity, values } from "ramda"
|
import { identity, values } from "ramda"
|
||||||
import {
|
import {
|
||||||
EMPTY,
|
EMPTY,
|
||||||
Observable,
|
|
||||||
merge,
|
merge,
|
||||||
of,
|
of,
|
||||||
fromEvent,
|
fromEvent
|
||||||
OperatorFunction,
|
|
||||||
pipe
|
|
||||||
} from "rxjs"
|
} from "rxjs"
|
||||||
import {
|
import {
|
||||||
delay,
|
delay,
|
||||||
filter,
|
filter,
|
||||||
map,
|
map,
|
||||||
pluck,
|
|
||||||
switchMap,
|
switchMap,
|
||||||
switchMapTo,
|
tap
|
||||||
tap,
|
|
||||||
distinctUntilKeyChanged,
|
|
||||||
shareReplay,
|
|
||||||
withLatestFrom
|
|
||||||
} from "rxjs/operators"
|
} from "rxjs/operators"
|
||||||
|
|
||||||
import {
|
import {
|
||||||
@ -73,14 +65,15 @@ import { renderSource } from "templates"
|
|||||||
import { not, takeIf } from "utilities"
|
import { not, takeIf } from "utilities"
|
||||||
import { renderClipboard } from "templates/clipboard"
|
import { renderClipboard } from "templates/clipboard"
|
||||||
import { fetchGitHubStats } from "modules/source/github"
|
import { fetchGitHubStats } from "modules/source/github"
|
||||||
import { mountNavigation } from "components2/navigation"
|
|
||||||
import { watchComponentMap, useComponent } from "components2/_"
|
|
||||||
import { renderTable } from "templates/table"
|
import { renderTable } from "templates/table"
|
||||||
import { setToggle } from "actions"
|
import { setToggle } from "actions"
|
||||||
import {
|
import {
|
||||||
Component,
|
Component,
|
||||||
mountMain,
|
mountMain,
|
||||||
mountSearch
|
mountNavigation,
|
||||||
|
mountSearch,
|
||||||
|
useComponent,
|
||||||
|
watchComponentMap
|
||||||
} from "components2"
|
} from "components2"
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------------
|
/* ----------------------------------------------------------------------------
|
||||||
@ -234,8 +227,8 @@ export function initialize(config: unknown) {
|
|||||||
const document$ = watchDocument()
|
const document$ = watchDocument()
|
||||||
const hash$ = watchLocationHash()
|
const hash$ = watchLocationHash()
|
||||||
const viewport$ = watchViewport()
|
const viewport$ = watchViewport()
|
||||||
const screen$ = watchMedia("(min-width: 960px)")
|
const tablet$ = watchMedia("(min-width: 960px)")
|
||||||
const tablet$ = watchMedia("(min-width: 1220px)")
|
const screen$ = watchMedia("(min-width: 1220px)")
|
||||||
const key$ = watchKeyboard()
|
const key$ = watchKeyboard()
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------- */
|
/* ----------------------------------------------------------------------- */
|
||||||
@ -251,7 +244,7 @@ export function initialize(config: unknown) {
|
|||||||
|
|
||||||
const main$ = useComponent("main")
|
const main$ = useComponent("main")
|
||||||
.pipe(
|
.pipe(
|
||||||
mountMain({ header$, viewport$ }),
|
mountMain({ header$, viewport$ })
|
||||||
)
|
)
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------- */
|
/* ----------------------------------------------------------------------- */
|
||||||
|
Loading…
Reference in New Issue
Block a user