2019-09-29 00:30:56 +02:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2016-2019 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.
|
|
|
|
*/
|
|
|
|
|
2019-12-20 18:03:31 +01:00
|
|
|
// TODO: remove this later on
|
|
|
|
|
|
|
|
// tslint:disable
|
|
|
|
|
2019-11-27 19:12:49 +01:00
|
|
|
import { identity } from "ramda"
|
2019-12-17 09:53:16 +01:00
|
|
|
import {
|
2019-12-20 18:03:31 +01:00
|
|
|
EMPTY,
|
2019-12-17 09:53:16 +01:00
|
|
|
MonoTypeOperatorFunction,
|
2019-12-20 18:03:31 +01:00
|
|
|
NEVER,
|
2019-12-17 09:53:16 +01:00
|
|
|
Observable,
|
2019-12-18 17:14:20 +01:00
|
|
|
Subject,
|
2019-12-20 18:03:31 +01:00
|
|
|
defer,
|
|
|
|
forkJoin,
|
2019-12-17 09:53:16 +01:00
|
|
|
fromEvent,
|
|
|
|
merge,
|
2019-12-20 18:03:31 +01:00
|
|
|
of,
|
2019-12-17 09:53:16 +01:00
|
|
|
pipe,
|
2019-11-27 19:12:49 +01:00
|
|
|
} from "rxjs"
|
2019-12-17 09:53:16 +01:00
|
|
|
import {
|
2019-12-20 18:03:31 +01:00
|
|
|
combineAll,
|
2019-12-17 09:53:16 +01:00
|
|
|
delay,
|
2019-12-18 17:14:20 +01:00
|
|
|
distinctUntilKeyChanged,
|
2019-12-17 09:53:16 +01:00
|
|
|
filter,
|
|
|
|
map,
|
|
|
|
pluck,
|
|
|
|
shareReplay,
|
|
|
|
switchMap,
|
|
|
|
switchMapTo,
|
2019-12-20 18:03:31 +01:00
|
|
|
take,
|
2019-12-17 09:53:16 +01:00
|
|
|
tap,
|
2019-11-27 19:12:49 +01:00
|
|
|
} from "rxjs/operators"
|
2019-11-22 18:42:25 +01:00
|
|
|
|
2019-12-20 18:03:31 +01:00
|
|
|
import {} from "components"
|
|
|
|
import { AjaxResponse, ajax } from "rxjs/ajax"
|
2019-11-18 21:24:56 +01:00
|
|
|
import {
|
2019-11-27 19:12:49 +01:00
|
|
|
Component,
|
2019-12-17 09:53:16 +01:00
|
|
|
paintHeaderShadow,
|
2019-12-20 18:03:31 +01:00
|
|
|
setupHero,
|
|
|
|
setupMain,
|
|
|
|
setupNavigation,
|
|
|
|
setupSearchResult,
|
2019-11-26 17:56:45 +01:00
|
|
|
switchComponent,
|
2019-11-22 18:42:25 +01:00
|
|
|
watchComponentMap,
|
|
|
|
watchHeader,
|
2019-11-27 19:12:49 +01:00
|
|
|
watchSearchReset,
|
2019-12-18 17:14:20 +01:00
|
|
|
} from "./components"
|
2019-12-20 18:03:31 +01:00
|
|
|
import { SearchIndex, SearchResult } from "./modules/search"
|
2019-09-29 00:30:56 +02:00
|
|
|
import {
|
2019-12-18 17:14:20 +01:00
|
|
|
getElement,
|
2019-12-20 18:03:31 +01:00
|
|
|
setupAgent,
|
2019-11-26 17:56:45 +01:00
|
|
|
watchDocument,
|
2019-11-22 18:42:25 +01:00
|
|
|
watchLocation,
|
2019-12-20 18:03:31 +01:00
|
|
|
watchLocationHash,
|
2019-11-18 21:24:56 +01:00
|
|
|
watchMedia,
|
2019-12-18 17:14:20 +01:00
|
|
|
watchToggle,
|
2019-11-18 21:24:56 +01:00
|
|
|
watchViewportOffset,
|
2019-12-18 17:14:20 +01:00
|
|
|
watchViewportSize,
|
|
|
|
watchWorker
|
2019-11-27 19:12:49 +01:00
|
|
|
} from "./utilities"
|
2019-12-20 18:03:31 +01:00
|
|
|
import {
|
|
|
|
SearchMessage,
|
|
|
|
SearchMessageType,
|
|
|
|
SearchSetupMessage,
|
|
|
|
isSearchDumpMessage,
|
|
|
|
isSearchResultMessage
|
|
|
|
} from "./workers"
|
2019-12-18 17:14:20 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Configuration
|
|
|
|
*/
|
|
|
|
export interface Config {
|
|
|
|
base: string /* Base URL */
|
|
|
|
worker: {
|
|
|
|
search: string /* Web worker URL */
|
|
|
|
packer: string /* Web worker URL */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-20 18:03:31 +01:00
|
|
|
import {
|
|
|
|
PackerMessage,
|
|
|
|
PackerMessageType
|
|
|
|
} from "./workers/packer"
|
2019-12-18 17:14:20 +01:00
|
|
|
|
2019-12-20 18:03:31 +01:00
|
|
|
import { setupTabs } from "components/tabs"
|
|
|
|
import { setupTableOfContents } from "components/toc/_"
|
2019-12-18 17:14:20 +01:00
|
|
|
|
|
|
|
/* ----------------------------------------------------------------------------
|
|
|
|
* Functions
|
|
|
|
* ------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Ensure that the given value is a valid configuration
|
|
|
|
*
|
|
|
|
* @param config - Configuration
|
|
|
|
*
|
|
|
|
* @return Test result
|
|
|
|
*/
|
|
|
|
export function isConfig(config: any): config is Config {
|
|
|
|
return typeof config === "object"
|
|
|
|
&& typeof config.base === "string"
|
|
|
|
}
|
2019-09-29 00:30:56 +02:00
|
|
|
|
2019-11-26 17:56:45 +01:00
|
|
|
// TBD
|
|
|
|
|
2019-11-27 19:12:49 +01:00
|
|
|
// TODO: put this somewhere else... (merge with config!) JSON schema!?
|
2019-12-20 18:03:31 +01:00
|
|
|
const names: Component[] = [
|
2019-11-26 17:56:45 +01:00
|
|
|
"header", /* Header */
|
|
|
|
"title", /* Header title */
|
|
|
|
"search", /* Search */
|
|
|
|
"query", /* Search input */
|
|
|
|
"reset", /* Search reset */
|
|
|
|
"result", /* Search results */
|
|
|
|
"container", /* Container */
|
|
|
|
"main", /* Main area */
|
|
|
|
"hero", /* Hero */
|
|
|
|
"tabs", /* Tabs */
|
|
|
|
"navigation", /* Navigation */
|
|
|
|
"toc" /* Table of contents */
|
2019-12-20 18:03:31 +01:00
|
|
|
]
|
2019-11-27 19:12:49 +01:00
|
|
|
|
|
|
|
// modernizr for the poor
|
|
|
|
document.documentElement.classList.remove("no-js")
|
|
|
|
document.documentElement.classList.add("js")
|
2019-11-26 17:56:45 +01:00
|
|
|
|
|
|
|
/* ----------------------------------------------------------------------------
|
|
|
|
* Functions
|
|
|
|
* ------------------------------------------------------------------------- */
|
|
|
|
|
2019-12-20 18:03:31 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* Rogue control characters must be filtered before handing the query to the
|
|
|
|
* search index, as lunr will throw otherwise.
|
|
|
|
*/
|
|
|
|
function prepareQuery(value: string): string {
|
|
|
|
const newvalue = value
|
|
|
|
.replace(/(?:^|\s+)[*+-:^~]+(?=\s+|$)/g, "")
|
|
|
|
.trim()
|
|
|
|
|
|
|
|
return newvalue ? newvalue.replace(/\s+|$/g, "* ") : ""
|
|
|
|
}
|
|
|
|
|
2019-11-26 17:56:45 +01:00
|
|
|
/**
|
|
|
|
* Initialize Material for MkDocs
|
|
|
|
*
|
|
|
|
* @param config - Configuration
|
|
|
|
*/
|
|
|
|
export function initialize(config: unknown) {
|
|
|
|
if (!isConfig(config))
|
|
|
|
throw new SyntaxError(`Invalid configuration: ${JSON.stringify(config)}`)
|
2019-11-22 18:42:25 +01:00
|
|
|
|
2019-12-20 18:03:31 +01:00
|
|
|
const agent = setupAgent()
|
|
|
|
|
2019-12-18 17:14:20 +01:00
|
|
|
const worker = new Worker(config.worker.search)
|
|
|
|
const packer = new Worker(config.worker.packer)
|
|
|
|
|
|
|
|
// const query = message.data.trim().replace(/\s+|$/g, "* ") // TODO: do this outside of the worker
|
|
|
|
|
|
|
|
const packerMessage$ = new Subject<PackerMessage>()
|
2019-12-20 18:03:31 +01:00
|
|
|
const packer$ = watchWorker(packer, { send$: packerMessage$ })
|
2019-12-18 17:14:20 +01:00
|
|
|
|
|
|
|
// send a message, then switchMapTo worker!
|
|
|
|
|
|
|
|
packer$.subscribe(message => {
|
2019-12-20 18:03:31 +01:00
|
|
|
console.log("PACKER.MSG", message.data.length)
|
2019-12-18 17:14:20 +01:00
|
|
|
// is always packed!
|
2019-12-20 18:03:31 +01:00
|
|
|
if (message.type === PackerMessageType.BINARY && message.data[0] !== "{")
|
|
|
|
localStorage.setItem("index", message.data)
|
2019-12-18 17:14:20 +01:00
|
|
|
})
|
|
|
|
|
2019-12-20 18:03:31 +01:00
|
|
|
// storing = experimental feature
|
2019-12-18 17:14:20 +01:00
|
|
|
|
2019-12-20 18:03:31 +01:00
|
|
|
const searchMessage$ = new Subject<SearchMessage>()
|
2019-12-18 17:14:20 +01:00
|
|
|
|
2019-12-20 18:03:31 +01:00
|
|
|
const search$ = watchWorker(worker, { send$: searchMessage$ })
|
2019-12-18 17:14:20 +01:00
|
|
|
|
2019-12-20 18:03:31 +01:00
|
|
|
// paintSearchResult <-- must paint META AND LIST!
|
|
|
|
// list must be painted based on scroll offset...
|
2019-12-18 17:14:20 +01:00
|
|
|
|
2019-12-20 18:03:31 +01:00
|
|
|
/* Render search results */
|
|
|
|
// search$
|
|
|
|
// .pipe(
|
|
|
|
// filter(isSearchResultMessage),
|
|
|
|
// pluck("data")
|
|
|
|
// )
|
|
|
|
// .subscribe(result => {
|
|
|
|
// const list = getElement(".md-search-result__list")!
|
|
|
|
// list.innerHTML = ""
|
|
|
|
// for (const el of result.map(renderSearchResult)) // TODO: perform entire lazy render!!!!
|
|
|
|
// list.appendChild(el)
|
|
|
|
// })
|
2019-12-18 17:14:20 +01:00
|
|
|
|
2019-12-20 18:03:31 +01:00
|
|
|
// scroll!
|
|
|
|
// watchSearchResult
|
2019-12-18 17:14:20 +01:00
|
|
|
|
2019-12-20 18:03:31 +01:00
|
|
|
/* Link search to packer */
|
|
|
|
search$
|
|
|
|
.pipe(
|
|
|
|
filter(isSearchDumpMessage),
|
|
|
|
map(message => ({
|
|
|
|
type: PackerMessageType.STRING,
|
|
|
|
data: message.data
|
|
|
|
})),
|
|
|
|
tap(message => packerMessage$.next(message)) // send message and wait!
|
|
|
|
// switchMapTo(packer$)
|
|
|
|
)
|
|
|
|
.subscribe()
|
2019-12-18 17:14:20 +01:00
|
|
|
|
2019-12-20 18:03:31 +01:00
|
|
|
const data$ = ajax({
|
2019-12-18 17:14:20 +01:00
|
|
|
url: `${config.base}/search/search_index.json`,
|
|
|
|
responseType: "json",
|
|
|
|
withCredentials: true
|
|
|
|
})
|
2019-12-20 18:03:31 +01:00
|
|
|
.pipe<SearchIndex>(
|
|
|
|
pluck("response")
|
|
|
|
// take(1)
|
|
|
|
)
|
|
|
|
|
|
|
|
const fromLocal = localStorage.getItem("index")
|
|
|
|
|
|
|
|
;
|
|
|
|
(fromLocal ? of({
|
|
|
|
type: PackerMessageType.BINARY,
|
|
|
|
data: localStorage.getItem("index")!
|
|
|
|
}) : EMPTY)
|
|
|
|
.subscribe(x => {
|
|
|
|
// console.log("send message to packer")
|
|
|
|
packerMessage$.next(x)
|
|
|
|
})
|
|
|
|
|
|
|
|
const index$ = fromLocal ? packer$.pipe(pluck("data"), take(1)) : of(undefined) // of(localStorage.getItem("index"))
|
|
|
|
|
|
|
|
// index$.subscribe(xx => console.log("INDEX", xx))
|
|
|
|
|
|
|
|
forkJoin([data$, index$])
|
|
|
|
.pipe<SearchSetupMessage>(
|
|
|
|
map(([data, index]) => ({
|
2019-12-18 17:14:20 +01:00
|
|
|
type: SearchMessageType.SETUP,
|
2019-12-20 18:03:31 +01:00
|
|
|
data: { ...data, index }
|
2019-12-18 17:14:20 +01:00
|
|
|
}))
|
|
|
|
)
|
|
|
|
.subscribe(message => {
|
|
|
|
searchMessage$.next(message) // TODO: this shall not complete
|
|
|
|
})
|
|
|
|
|
2019-12-20 18:03:31 +01:00
|
|
|
// filter singular "+" or "-",as it will result in a lunr.js error
|
|
|
|
|
|
|
|
// data$
|
|
|
|
// .pipe(
|
|
|
|
// map<SearchIndex, SearchMessage>(data => ({
|
|
|
|
// type: SearchMessageType.SETUP,
|
|
|
|
// data
|
|
|
|
// }))
|
|
|
|
// )
|
|
|
|
// .subscribe(message => {
|
|
|
|
// searchMessage$.next(message) // TODO: this shall not complete
|
|
|
|
// })
|
|
|
|
|
2019-11-26 17:56:45 +01:00
|
|
|
/* ----------------------------------------------------------------------- */
|
2019-11-22 18:42:25 +01:00
|
|
|
|
2019-11-26 17:56:45 +01:00
|
|
|
/* Create viewport observables */
|
|
|
|
const offset$ = watchViewportOffset()
|
|
|
|
const size$ = watchViewportSize()
|
2019-09-29 00:30:56 +02:00
|
|
|
|
2019-11-26 17:56:45 +01:00
|
|
|
/* Create media observables */
|
|
|
|
const screen$ = watchMedia("(min-width: 1220px)")
|
|
|
|
const tablet$ = watchMedia("(min-width: 960px)")
|
2019-11-18 21:24:56 +01:00
|
|
|
|
2019-11-26 17:56:45 +01:00
|
|
|
/* Create location observables */
|
2019-11-27 19:12:49 +01:00
|
|
|
const location$ = watchLocation()
|
2019-12-20 18:03:31 +01:00
|
|
|
const fragment$ = watchLocationHash()
|
2019-11-22 18:42:25 +01:00
|
|
|
|
2019-11-26 17:56:45 +01:00
|
|
|
/* Create document observables */
|
|
|
|
const load$ = watchDocument()
|
2019-12-20 18:03:31 +01:00
|
|
|
|
|
|
|
// Complete set of AgentObservables...
|
|
|
|
|
|
|
|
// component map!
|
|
|
|
//
|
|
|
|
|
2019-12-17 09:53:16 +01:00
|
|
|
// const switch$ = watchDocumentSwitch({ location$ })
|
2019-11-22 18:42:25 +01:00
|
|
|
|
2019-11-26 17:56:45 +01:00
|
|
|
/* ----------------------------------------------------------------------- */
|
2019-11-22 18:42:25 +01:00
|
|
|
|
2019-11-26 17:56:45 +01:00
|
|
|
/* Create component map observable */
|
2019-12-18 17:14:20 +01:00
|
|
|
const components$ = watchComponentMap(names, { document$: load$ })
|
2019-11-22 18:42:25 +01:00
|
|
|
|
2019-12-20 18:03:31 +01:00
|
|
|
const component = <T extends HTMLElement>(name: Component): Observable<T> => {
|
2019-11-27 19:12:49 +01:00
|
|
|
return components$
|
|
|
|
.pipe(
|
2019-12-20 18:03:31 +01:00
|
|
|
switchComponent<T>(name)
|
2019-11-27 19:12:49 +01:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2019-11-26 17:56:45 +01:00
|
|
|
/* Create header observable */
|
2019-12-20 18:03:31 +01:00
|
|
|
const header$ = component("header") // TODO:!
|
2019-11-26 17:56:45 +01:00
|
|
|
.pipe(
|
|
|
|
switchMap(watchHeader)
|
2019-11-18 21:24:56 +01:00
|
|
|
)
|
2019-09-29 00:30:56 +02:00
|
|
|
|
2019-12-20 18:03:31 +01:00
|
|
|
// DONE
|
2019-11-27 19:12:49 +01:00
|
|
|
const main$ = component("main")
|
2019-11-26 17:56:45 +01:00
|
|
|
.pipe(
|
2019-12-20 18:03:31 +01:00
|
|
|
setupMain(agent, { header$ })
|
2019-11-18 21:24:56 +01:00
|
|
|
)
|
2019-11-22 18:42:25 +01:00
|
|
|
|
2019-12-20 18:03:31 +01:00
|
|
|
// setupHeader(agent) ??
|
|
|
|
|
|
|
|
// setupSearch
|
|
|
|
|
2019-11-27 19:12:49 +01:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2019-12-20 18:03:31 +01:00
|
|
|
|
|
|
|
/* Create header shadow toggle */
|
|
|
|
component("header")
|
|
|
|
.pipe(
|
|
|
|
switchMap(el => main$
|
|
|
|
.pipe(
|
|
|
|
paintHeaderShadow(el)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
.subscribe()
|
|
|
|
|
|
|
|
// watchSearchResult // emit, if at bottom...
|
|
|
|
// receive results as a second observable!? filter stuff, paint
|
|
|
|
|
|
|
|
const result$ = search$
|
|
|
|
.pipe(
|
|
|
|
filter(isSearchResultMessage),
|
|
|
|
pluck("data")
|
|
|
|
)
|
|
|
|
|
|
|
|
const query$ = component<HTMLInputElement>("query")
|
2019-12-18 17:14:20 +01:00
|
|
|
.pipe(
|
2019-12-20 18:03:31 +01:00
|
|
|
switchMap(el => fromEvent(el, "keyup")
|
2019-12-18 17:14:20 +01:00
|
|
|
.pipe(
|
2019-12-20 18:03:31 +01:00
|
|
|
map(() => prepareQuery(el.value))
|
2019-12-18 17:14:20 +01:00
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
2019-12-20 18:03:31 +01:00
|
|
|
|
|
|
|
// DONE
|
|
|
|
component("result")
|
|
|
|
.pipe(
|
|
|
|
setupSearchResult(agent, { result$, query$ })
|
|
|
|
)
|
|
|
|
.subscribe()
|
|
|
|
|
|
|
|
query$
|
|
|
|
.pipe(
|
|
|
|
map(data => ({ // put this into some function...
|
|
|
|
type: SearchMessageType.QUERY,
|
|
|
|
data
|
|
|
|
})), // TODO. ugly...
|
|
|
|
distinctUntilKeyChanged("data")
|
|
|
|
)
|
|
|
|
|
2019-12-18 17:14:20 +01:00
|
|
|
.subscribe(x => {
|
2019-12-20 18:03:31 +01:00
|
|
|
searchMessage$.next(x as any) // TODO
|
2019-12-18 17:14:20 +01:00
|
|
|
})
|
|
|
|
|
2019-12-20 18:03:31 +01:00
|
|
|
// Focus on search input
|
|
|
|
component("query")
|
|
|
|
.pipe(
|
|
|
|
switchMap(el => fromEvent(el, "focus")
|
|
|
|
.pipe(
|
|
|
|
tap(() => {
|
|
|
|
if (!search.checked)
|
|
|
|
search.click() // move this inside the search query stuff? not important...
|
|
|
|
})
|
|
|
|
)
|
|
|
|
) // not super nice...
|
|
|
|
)
|
|
|
|
.subscribe()
|
|
|
|
|
2019-12-17 09:53:16 +01:00
|
|
|
// // WIP: instant loading
|
|
|
|
// load$
|
|
|
|
// .pipe(
|
|
|
|
// switchMap(({ body }) => fromEvent(body, "click")),
|
|
|
|
// switchMap(ev => {
|
|
|
|
// if (ev.target instanceof HTMLElement) {
|
|
|
|
// const el = ev.target.closest("a") || undefined
|
|
|
|
// if (el) {
|
|
|
|
// if (!/^(https?:|#)/.test(el.getAttribute("href")!)) {
|
|
|
|
// ev.preventDefault()
|
|
|
|
// }
|
|
|
|
// const href = el.href
|
|
|
|
// history.pushState({}, "", href) // TODO: reference necessary!?
|
|
|
|
// return of(href)
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// return EMPTY
|
|
|
|
// })
|
|
|
|
|
|
|
|
// // try to reduce the jiggle upon instant page load. ideally, the location
|
|
|
|
// // should directly be resolved and the respective document loaded, but
|
|
|
|
// // we must scroll to the top at first and wait at least 250ms.
|
|
|
|
// //
|
|
|
|
// // Furthermore, this doesn't include the back/next buttons of the browser
|
|
|
|
// // which must be delayed
|
|
|
|
// // tap(url => {
|
|
|
|
// // if (!/#/.test(url))
|
|
|
|
// // scrollTo({ top: 0 })
|
|
|
|
// // }) // only when loading something we havent loaded!
|
|
|
|
// // delay(250)
|
|
|
|
// )
|
|
|
|
// .subscribe(location$)
|
|
|
|
|
|
|
|
// location$.subscribe(x => {
|
|
|
|
// console.log("L", x)
|
|
|
|
// })
|
|
|
|
// switch$.subscribe(x => {
|
|
|
|
// console.log("S", x)
|
|
|
|
// })
|
2019-11-27 19:12:49 +01:00
|
|
|
|
2019-11-26 17:56:45 +01:00
|
|
|
/* ----------------------------------------------------------------------- */
|
2019-11-22 18:42:25 +01:00
|
|
|
|
2019-11-27 19:12:49 +01:00
|
|
|
component("navigation")
|
|
|
|
.pipe(
|
2019-12-20 18:03:31 +01:00
|
|
|
setupNavigation(agent, { main$ })
|
2019-11-27 19:12:49 +01:00
|
|
|
)
|
|
|
|
.subscribe()
|
|
|
|
|
|
|
|
component("toc")
|
|
|
|
.pipe(
|
2019-12-20 18:03:31 +01:00
|
|
|
setupTableOfContents(agent, { header$, main$ })
|
2019-11-27 19:12:49 +01:00
|
|
|
)
|
|
|
|
.subscribe()
|
|
|
|
|
|
|
|
component("tabs")
|
2019-11-22 18:42:25 +01:00
|
|
|
.pipe(
|
2019-12-20 18:03:31 +01:00
|
|
|
setupTabs(agent, { header$ })
|
2019-11-27 19:12:49 +01:00
|
|
|
)
|
|
|
|
.subscribe()
|
|
|
|
|
|
|
|
component("hero")
|
|
|
|
.pipe(
|
2019-12-20 18:03:31 +01:00
|
|
|
setupHero(agent, { header$ })
|
2019-11-27 19:12:49 +01:00
|
|
|
)
|
|
|
|
.subscribe()
|
|
|
|
|
2019-12-17 09:53:16 +01:00
|
|
|
// /* Create header title toggle */
|
|
|
|
// component("main")
|
|
|
|
// .pipe(
|
|
|
|
// delay(1000), // initial delay
|
|
|
|
// switchMap(el => typeof getElement("h1", el) !== "undefined"
|
|
|
|
// ? watchBottomOffset(getElement("h1", el)!, { size$, offset$, header$ })
|
|
|
|
// .pipe(
|
|
|
|
// map(({ y }) => y >= 0),
|
|
|
|
// withLatestFrom(component("title")),
|
|
|
|
// tap(([active, title]) => {
|
|
|
|
// title.dataset.mdState = active ? "active" : ""
|
|
|
|
// })
|
|
|
|
// )
|
|
|
|
// : NEVER
|
|
|
|
// )
|
|
|
|
// )
|
|
|
|
// .subscribe()
|
2019-11-27 19:12:49 +01:00
|
|
|
|
|
|
|
// TODO: replace title as inner text
|
|
|
|
|
|
|
|
/* ----------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
const drawer = getElement<HTMLInputElement>("[data-md-toggle=drawer]")!
|
|
|
|
const search = getElement<HTMLInputElement>("[data-md-toggle=search]")!
|
|
|
|
|
|
|
|
// watchToggle
|
|
|
|
|
|
|
|
// --> watchSearchQuery?
|
|
|
|
|
|
|
|
// watchSearch
|
|
|
|
// watchSearchReset
|
|
|
|
|
|
|
|
// toggles stay the same...
|
2019-11-26 17:56:45 +01:00
|
|
|
|
2019-11-27 19:12:49 +01:00
|
|
|
const a$ = watchToggle(search)
|
|
|
|
.pipe(
|
|
|
|
filter(identity),
|
|
|
|
delay(400)
|
|
|
|
)
|
|
|
|
|
|
|
|
// watchSearchReset()
|
|
|
|
|
|
|
|
const b$ = component("reset")
|
|
|
|
.pipe(
|
|
|
|
switchMap(watchSearchReset)
|
|
|
|
)
|
|
|
|
|
|
|
|
function focusQuery(): MonoTypeOperatorFunction<HTMLElement> {
|
|
|
|
return pipe(
|
|
|
|
tap(el => el.focus())
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
merge(a$, b$)
|
|
|
|
.pipe(
|
|
|
|
switchMapTo(component("query")),
|
|
|
|
focusQuery()
|
|
|
|
)
|
|
|
|
.subscribe()
|
|
|
|
|
2019-12-20 18:03:31 +01:00
|
|
|
/* Wrap all data tables for better overflow scrolling */
|
|
|
|
// const tables = getElements<HTMLTableElement>("table:not([class])")
|
|
|
|
// tables.forEach(table => {
|
|
|
|
// console.log("x", table)
|
|
|
|
// table.parentNode!.insertBefore(renderTable(table), table)
|
|
|
|
// table.replaceWith(renderTable(table) as any)
|
|
|
|
// // table.parentElement!.replaceChild(, table)
|
|
|
|
// })
|
|
|
|
|
|
|
|
return {
|
|
|
|
// agent, // agent.viewport.offset$
|
|
|
|
// component, // component.toc$
|
|
|
|
}
|
|
|
|
|
2019-11-27 19:12:49 +01:00
|
|
|
/* Return observable factories */
|
2019-11-26 17:56:45 +01:00
|
|
|
return {
|
2019-11-27 19:12:49 +01:00
|
|
|
|
|
|
|
/* User interface */
|
|
|
|
watchDocument: () => load$,
|
2019-12-17 09:53:16 +01:00
|
|
|
// watchDocumentSwitch: () => switch$,
|
2019-11-27 19:12:49 +01:00
|
|
|
watchLocation: () => location$,
|
|
|
|
watchLocationFragment: () => fragment$,
|
|
|
|
watchMediaScreen: () => screen$,
|
|
|
|
watchMediaTablet: () => tablet$,
|
|
|
|
watchViewportOffset: () => offset$,
|
|
|
|
watchViewportSize: () => size$
|
2019-11-26 17:56:45 +01:00
|
|
|
}
|
2019-09-29 00:30:56 +02:00
|
|
|
}
|