mirror of
https://github.com/squidfunk/mkdocs-material.git
synced 2026-08-01 18:28:48 -04:00
Unified components and observable structure
This commit is contained in:
@@ -35,11 +35,13 @@ import {
|
||||
Viewport,
|
||||
getElement,
|
||||
watchViewportAt
|
||||
} from "observables"
|
||||
} from "browser"
|
||||
|
||||
import { useComponent } from "../../_"
|
||||
import { paintHeaderType } from "../paint"
|
||||
import { watchHeader } from "../watch"
|
||||
import {
|
||||
applyHeaderType,
|
||||
watchHeader
|
||||
} from "../react"
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
* Types
|
||||
@@ -104,7 +106,7 @@ export function mountHeader(
|
||||
return y >= hx.offsetHeight ? "page" : "site"
|
||||
}),
|
||||
distinctUntilChanged(),
|
||||
paintHeaderType(title)
|
||||
applyHeaderType(title)
|
||||
)
|
||||
),
|
||||
startWith<HeaderType>("site")
|
||||
|
||||
@@ -21,6 +21,5 @@
|
||||
*/
|
||||
|
||||
export * from "./_"
|
||||
export * from "./apply"
|
||||
export * from "./paint"
|
||||
export * from "./watch"
|
||||
export * from "./react"
|
||||
export * from "./set"
|
||||
|
||||
@@ -1,63 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2016-2020 Martin Donath <martin.donath@squidfunk.com>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to
|
||||
* deal in the Software without restriction, including without limitation the
|
||||
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
* sell copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
* IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
import {
|
||||
MonoTypeOperatorFunction,
|
||||
animationFrameScheduler,
|
||||
pipe
|
||||
} from "rxjs"
|
||||
import { finalize, observeOn, tap } from "rxjs/operators"
|
||||
|
||||
import { HeaderType } from "../_"
|
||||
import {
|
||||
resetHeaderTitleActive,
|
||||
setHeaderTitleActive
|
||||
} from "../apply"
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
* Functions
|
||||
* ------------------------------------------------------------------------- */
|
||||
|
||||
/**
|
||||
* Paint header title type
|
||||
*
|
||||
* @param el - Header title element
|
||||
*
|
||||
* @return Operator function
|
||||
*/
|
||||
export function paintHeaderType(
|
||||
el: HTMLElement
|
||||
): MonoTypeOperatorFunction<HeaderType> {
|
||||
return pipe(
|
||||
|
||||
/* Defer repaint to next animation frame */
|
||||
observeOn(animationFrameScheduler),
|
||||
tap(type => {
|
||||
setHeaderTitleActive(el, type === "page")
|
||||
}),
|
||||
|
||||
/* Reset on complete or error */
|
||||
finalize(() => {
|
||||
resetHeaderTitleActive(el)
|
||||
})
|
||||
)
|
||||
}
|
||||
@@ -20,12 +20,28 @@
|
||||
* IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
import { Observable, of } from "rxjs"
|
||||
import { distinctUntilKeyChanged, switchMap } from "rxjs/operators"
|
||||
import {
|
||||
MonoTypeOperatorFunction,
|
||||
Observable,
|
||||
animationFrameScheduler,
|
||||
of,
|
||||
pipe
|
||||
} from "rxjs"
|
||||
import {
|
||||
distinctUntilKeyChanged,
|
||||
finalize,
|
||||
observeOn,
|
||||
switchMap,
|
||||
tap
|
||||
} from "rxjs/operators"
|
||||
|
||||
import { Viewport } from "observables"
|
||||
import { Viewport } from "browser"
|
||||
|
||||
import { Header } from "../_"
|
||||
import { Header, HeaderType } from "../_"
|
||||
import {
|
||||
resetHeaderTitleActive,
|
||||
setHeaderTitleActive
|
||||
} from "../set"
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
* Helper types
|
||||
@@ -72,3 +88,30 @@ export function watchHeader(
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
/**
|
||||
* Apply header title type
|
||||
*
|
||||
* @param el - Header title element
|
||||
*
|
||||
* @return Operator function
|
||||
*/
|
||||
export function applyHeaderType(
|
||||
el: HTMLElement
|
||||
): MonoTypeOperatorFunction<HeaderType> {
|
||||
return pipe(
|
||||
|
||||
/* Defer repaint to next animation frame */
|
||||
observeOn(animationFrameScheduler),
|
||||
tap(type => {
|
||||
setHeaderTitleActive(el, type === "page")
|
||||
}),
|
||||
|
||||
/* Reset on complete or error */
|
||||
finalize(() => {
|
||||
resetHeaderTitleActive(el)
|
||||
})
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user