mirror of
https://github.com/squidfunk/mkdocs-material.git
synced 2026-07-29 01:02:42 -04:00
Refactored header title component
This commit is contained in:
@@ -52,7 +52,7 @@ interface WatchOptions {
|
||||
*
|
||||
* This function returns an observables that fetches a document if the provided
|
||||
* location observable emits a new value (i.e. URL). If the emitted URL points
|
||||
* to the same page, the request is effectively ignored (e.g. when only the
|
||||
* to the same page, the request is effectively ignored (i.e. when only the
|
||||
* fragment identifier changes).
|
||||
*
|
||||
* @param options - Options
|
||||
|
||||
@@ -21,14 +21,7 @@
|
||||
*/
|
||||
|
||||
import { Observable, fromEvent, merge } from "rxjs"
|
||||
import {
|
||||
distinctUntilKeyChanged,
|
||||
map,
|
||||
shareReplay,
|
||||
startWith
|
||||
} from "rxjs/operators"
|
||||
|
||||
import { Viewport } from "../../viewport"
|
||||
import { map, shareReplay, startWith } from "rxjs/operators"
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
* Types
|
||||
@@ -42,17 +35,6 @@ export interface ElementOffset {
|
||||
y: number /* Vertical offset */
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
* Helper types
|
||||
* ------------------------------------------------------------------------- */
|
||||
|
||||
/**
|
||||
* Watch options
|
||||
*/
|
||||
interface WatchOptions {
|
||||
viewport$: Observable<Viewport> /* Viewport observable */
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
* Functions
|
||||
* ------------------------------------------------------------------------- */
|
||||
@@ -77,21 +59,16 @@ export function getElementOffset(el: HTMLElement): ElementOffset {
|
||||
* Watch element offset
|
||||
*
|
||||
* @param el - Element
|
||||
* @param options - Options
|
||||
*
|
||||
* @return Element offset observable
|
||||
*/
|
||||
export function watchElementOffset(
|
||||
el: HTMLElement, { viewport$ }: WatchOptions
|
||||
el: HTMLElement
|
||||
): Observable<ElementOffset> {
|
||||
const scroll$ = fromEvent(el, "scroll")
|
||||
const size$ = viewport$
|
||||
.pipe(
|
||||
distinctUntilKeyChanged("size")
|
||||
)
|
||||
|
||||
/* Merge into a single hot observable */
|
||||
return merge(scroll$, size$)
|
||||
return merge(
|
||||
fromEvent<UIEvent>(el, "scroll"),
|
||||
fromEvent<UIEvent>(window, "resize")
|
||||
)
|
||||
.pipe(
|
||||
map(() => getElementOffset(el)),
|
||||
startWith(getElementOffset(el)),
|
||||
|
||||
@@ -36,8 +36,7 @@ export function watchLocation(): Subject<string> {
|
||||
const location$ = new Subject<string>()
|
||||
fromEvent<PopStateEvent>(window, "popstate")
|
||||
.pipe(
|
||||
map(() => location.href),
|
||||
share()
|
||||
map(() => location.href)
|
||||
)
|
||||
.subscribe(location$)
|
||||
|
||||
|
||||
@@ -85,7 +85,7 @@ export function watchViewport(): Observable<Viewport> {
|
||||
*
|
||||
* @return Viewport observable
|
||||
*/
|
||||
export function watchViewportFrom(
|
||||
export function watchViewportAt(
|
||||
el: HTMLElement, { header$, viewport$ }: WatchRelativeOptions
|
||||
): Observable<Viewport> {
|
||||
return combineLatest([viewport$, header$])
|
||||
|
||||
Reference in New Issue
Block a user