Migrated tabs and hero and renamed refactored components

This commit is contained in:
squidfunk 2020-02-14 18:48:46 +01:00
parent 32d6df4cc9
commit b094573287
22 changed files with 66 additions and 130 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1,10 +1,10 @@
{ {
"assets/javascripts/bundle.js": "assets/javascripts/bundle.d443780c.min.js", "assets/javascripts/bundle.js": "assets/javascripts/bundle.da70863b.min.js",
"assets/javascripts/bundle.js.map": "assets/javascripts/bundle.d443780c.min.js.map", "assets/javascripts/bundle.js.map": "assets/javascripts/bundle.da70863b.min.js.map",
"assets/javascripts/worker/packer.js": "assets/javascripts/worker/packer.c14659e8.min.js", "assets/javascripts/worker/packer.js": "assets/javascripts/worker/packer.c14659e8.min.js",
"assets/javascripts/worker/packer.js.map": "assets/javascripts/worker/packer.c14659e8.min.js.map", "assets/javascripts/worker/packer.js.map": "assets/javascripts/worker/packer.c14659e8.min.js.map",
"assets/javascripts/worker/search.js": "assets/javascripts/worker/search.07456dbc.min.js", "assets/javascripts/worker/search.js": "assets/javascripts/worker/search.d5bb06df.min.js",
"assets/javascripts/worker/search.js.map": "assets/javascripts/worker/search.07456dbc.min.js.map", "assets/javascripts/worker/search.js.map": "assets/javascripts/worker/search.d5bb06df.min.js.map",
"assets/stylesheets/app-palette.scss": "assets/stylesheets/app-palette.8c25017f.min.css", "assets/stylesheets/app-palette.scss": "assets/stylesheets/app-palette.8c25017f.min.css",
"assets/stylesheets/app.scss": "assets/stylesheets/app.82c13014.min.css" "assets/stylesheets/app.scss": "assets/stylesheets/app.82c13014.min.css"
} }

View File

@ -190,7 +190,7 @@
{% endblock %} {% endblock %}
</div> </div>
{% block scripts %} {% block scripts %}
<script src="{{ 'assets/javascripts/bundle.d443780c.min.js' | url }}"></script> <script src="{{ 'assets/javascripts/bundle.da70863b.min.js' | url }}"></script>
<script id="__lang" type="application/json"> <script id="__lang" type="application/json">
{%- set translations = {} -%} {%- set translations = {} -%}
{%- for key in [ {%- for key in [
@ -209,7 +209,7 @@
{%- endfor -%} {%- endfor -%}
{{ translations | tojson }} {{ translations | tojson }}
</script> </script>
<script>app=initialize({base:"{{ base_url }}",worker:{search:"{{ 'assets/javascripts/worker/search.07456dbc.min.js' | url }}",packer:"{{ 'assets/javascripts/worker/packer.c14659e8.min.js' | url }}"}})</script> <script>app=initialize({base:"{{ base_url }}",worker:{search:"{{ 'assets/javascripts/worker/search.d5bb06df.min.js' | url }}",packer:"{{ 'assets/javascripts/worker/packer.c14659e8.min.js' | url }}"}})</script>
{% for path in config["extra_javascript"] %} {% for path in config["extra_javascript"] %}
<script src="{{ path | url }}"></script> <script src="{{ path | url }}"></script>
{% endfor %} {% endfor %}

View File

@ -35,9 +35,9 @@ import {
* ------------------------------------------------------------------------- */ * ------------------------------------------------------------------------- */
/** /**
* Hero state * Hero
*/ */
export interface HeroState { export interface Hero {
hidden: boolean /* Whether the hero is hidden */ hidden: boolean /* Whether the hero is hidden */
} }
@ -46,59 +46,34 @@ export interface HeroState {
* ------------------------------------------------------------------------- */ * ------------------------------------------------------------------------- */
/** /**
* Options * Mount options
*/ */
interface Options { interface MountOptions {
header$: Observable<Header> /* Header observable */ header$: Observable<Header> /* Header observable */
viewport$: Observable<Viewport> viewport$: Observable<Viewport> /* Viewport observable */
screen$: Observable<boolean> /* Media screen observable */
} }
/* ---------------------------------------------------------------------------- /* ----------------------------------------------------------------------------
* Functions * Functions
* ------------------------------------------------------------------------- */ * ------------------------------------------------------------------------- */
/**
* Watch hero
*
* @param el - Hero element
* @param agent - Agent
* @param options - Options
*
* @return Hero state
*/
export function watchHero(
el: HTMLElement, options: Options
): Observable<HeroState> {
/* Watch and paint visibility */
const hidden$ = watchViewportFrom(el, options)
.pipe(
paintHideable(el, 20)
)
/* Combine into a single hot observable */
return hidden$
.pipe(
map(hidden => ({ hidden }))
)
}
/* ------------------------------------------------------------------------- */
/** /**
* Mount hero from source observable * Mount hero from source observable
* *
* @param agent - Agent
* @param options - Options * @param options - Options
* *
* @return Operator function * @return Hero observable
*/ */
export function mountHero( export function mountHero(
options: Options { header$, viewport$ }: MountOptions
): OperatorFunction<HTMLElement, HeroState> { ): OperatorFunction<HTMLElement, Hero> {
return pipe( return pipe(
switchMap(el => watchHero(el, options)), switchMap(el => watchViewportFrom(el, { header$, viewport$ })
.pipe(
paintHideable(el, 20),
map(hidden => ({ hidden }))
)
),
shareReplay(1) shareReplay(1)
) )
} }

View File

@ -20,5 +20,11 @@
* IN THE SOFTWARE. * IN THE SOFTWARE.
*/ */
export * from "./_"
export * from "./header"
export * from "./hero" export * from "./hero"
export * from "./main"
export * from "./navigation"
export * from "./search"
export * from "./tabs" export * from "./tabs"
export * from "./toc"

View File

@ -20,8 +20,8 @@
* IN THE SOFTWARE. * IN THE SOFTWARE.
*/ */
import { Observable, OperatorFunction, pipe } from "rxjs" import { Observable, OperatorFunction, of, pipe } from "rxjs"
import { map, shareReplay } from "rxjs/operators" import { map, shareReplay, switchMap } from "rxjs/operators"
import { import {
Header, Header,
@ -29,16 +29,15 @@ import {
paintHideable, paintHideable,
watchViewportFrom watchViewportFrom
} from "observables" } from "observables"
import { switchMapIf } from "utilities"
/* ---------------------------------------------------------------------------- /* ----------------------------------------------------------------------------
* Types * Types
* ------------------------------------------------------------------------- */ * ------------------------------------------------------------------------- */
/** /**
* Tabs state * Tabs
*/ */
export interface TabsState { export interface Tabs {
hidden: boolean /* Whether the tabs are hidden */ hidden: boolean /* Whether the tabs are hidden */
} }
@ -47,11 +46,11 @@ export interface TabsState {
* ------------------------------------------------------------------------- */ * ------------------------------------------------------------------------- */
/** /**
* Options * Mount options
*/ */
interface Options { interface MountOptions {
header$: Observable<Header> /* Header state observable */ header$: Observable<Header> /* Header observable */
viewport$: Observable<Viewport> viewport$: Observable<Viewport> /* Viewport observable */
screen$: Observable<boolean> /* Media screen observable */ screen$: Observable<boolean> /* Media screen observable */
} }
@ -59,50 +58,36 @@ interface Options {
* Functions * Functions
* ------------------------------------------------------------------------- */ * ------------------------------------------------------------------------- */
/**
* Watch tabs
*
* This function returns an observable that computes the visual parameters of
* the tabs, currently only denoting whether the tabs are hidden or not.
*
* @param el - Tabs element
* @param options - Options
*
* @return Tabs state
*/
export function watchTabs(
el: HTMLElement, options: Options
): Observable<TabsState> {
/* Watch and paint visibility */
const hidden$ = watchViewportFrom(el, options)
.pipe(
paintHideable(el, 8)
)
/* Combine into a single hot observable */
return hidden$
.pipe(
map(hidden => ({ hidden }))
)
}
// TODO: generalize into watchHideable !!! or mountHideable...
/* ------------------------------------------------------------------------- */
/** /**
* Mount tabs from source observable * Mount tabs from source observable
* *
* @param agent - Agent
* @param options - Options * @param options - Options
* *
* @return Operator function * @return Tabs observable
*/ */
export function mountTabs( export function mountTabs(
options: Options { header$, viewport$, screen$ }: MountOptions
): OperatorFunction<HTMLElement, TabsState> { ): OperatorFunction<HTMLElement, Tabs> {
return pipe( return pipe(
switchMapIf(options.screen$, el => watchTabs(el, options)), switchMap(el => screen$
.pipe(
switchMap(screen => {
/* Mount tabs above screen breakpoint */
if (screen) {
return watchViewportFrom(el, { header$, viewport$ })
.pipe(
paintHideable(el, 20),
map(hidden => ({ hidden }))
)
/* Mount tabs below screen breakpoint */
} else {
return of({ hidden: screen })
}
})
)
),
shareReplay(1) shareReplay(1)
) )
} }

View File

@ -1,28 +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.
*/
export * from "./_"
export * from "./header"
export * from "./main"
export * from "./navigation"
export * from "./search"
export * from "./toc"

View File

@ -45,10 +45,6 @@ import {
pluck pluck
} from "rxjs/operators" } from "rxjs/operators"
import {
mountHero,
mountTabs,
} from "./components"
import { import {
getElement, getElement,
watchToggle, watchToggle,
@ -69,13 +65,15 @@ import { setToggle } from "actions"
import { import {
Component, Component,
mountHeader, mountHeader,
mountHero,
mountMain, mountMain,
mountNavigation, mountNavigation,
mountSearch, mountSearch,
mountTableOfContents, mountTableOfContents,
mountTabs,
useComponent, useComponent,
watchComponentMap watchComponentMap
} from "components2" } from "components"
import { mountClipboard } from "./integrations/clipboard" import { mountClipboard } from "./integrations/clipboard"
import { patchTables, patchDetails } from "patches" import { patchTables, patchDetails } from "patches"
import { takeIf, not, isConfig } from "utilities" import { takeIf, not, isConfig } from "utilities"