Cleaned up main entrypoint

This commit is contained in:
squidfunk 2020-02-14 17:45:32 +01:00
parent aa74dc4d41
commit 0f77194c23
8 changed files with 41 additions and 45 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,6 +1,6 @@
{
"assets/javascripts/bundle.js": "assets/javascripts/bundle.419ace03.min.js",
"assets/javascripts/bundle.js.map": "assets/javascripts/bundle.419ace03.min.js.map",
"assets/javascripts/bundle.js": "assets/javascripts/bundle.d443780c.min.js",
"assets/javascripts/bundle.js.map": "assets/javascripts/bundle.d443780c.min.js.map",
"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/search.js": "assets/javascripts/worker/search.07456dbc.min.js",

View File

@ -190,7 +190,7 @@
{% endblock %}
</div>
{% block scripts %}
<script src="{{ 'assets/javascripts/bundle.419ace03.min.js' | url }}"></script>
<script src="{{ 'assets/javascripts/bundle.d443780c.min.js' | url }}"></script>
<script id="__lang" type="application/json">
{%- set translations = {} -%}
{%- for key in [

View File

@ -80,9 +80,7 @@ import { mountClipboard } from "./integrations/clipboard"
import { patchTables, patchDetails } from "patches"
import { takeIf, not, isConfig } from "utilities"
/* ----------------------------------------------------------------------------
* TODO: where do we put this stuff?
* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */
document.documentElement.classList.remove("no-js")
document.documentElement.classList.add("js")
@ -91,25 +89,7 @@ document.documentElement.classList.add("js")
if (navigator.userAgent.match(/(iPad|iPhone|iPod)/g))
document.documentElement.classList.add("ios")
// add to config? default components to mount...?
const names: Component[] = [
"container", /* Container */
"header", /* Header */
"header-title", /* Header title */
"hero", /* Hero */
"main", /* Main area */
"navigation", /* Navigation */
"search", /* Search */
"search-query", /* Search input */
"search-reset", /* Search reset */
"search-result", /* Search results */
"tabs", /* Tabs */
"toc" /* Table of contents */
]
/* ----------------------------------------------------------------------------
* Helper functions
* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */
/**
* Yes, this is a super hacky implementation. Needs clean up.
@ -191,8 +171,30 @@ export function initialize(config: unknown) {
/* ----------------------------------------------------------------------- */
watchComponentMap(names, { document$ })
watchToggleMap(["drawer", "search"], { document$ })
const worker = setupSearchWorker(config.worker.search, {
base: config.base
})
/* ----------------------------------------------------------------------- */
watchToggleMap([
"drawer", /* Toggle for drawer */
"search" /* Toggle for search */
], { document$ })
watchComponentMap([
"container", /* Container */
"header", /* Header */
"header-title", /* Header title */
"hero", /* Hero */
"main", /* Main area */
"navigation", /* Navigation */
"search", /* Search */
"search-query", /* Search input */
"search-reset", /* Search reset */
"search-result", /* Search results */
"tabs", /* Tabs */
"toc" /* Table of contents */
], { document$ })
/* Create header observable */
const header$ = useComponent("header")
@ -207,17 +209,11 @@ export function initialize(config: unknown) {
/* ----------------------------------------------------------------------- */
const sw = setupSearchWorker(config.worker.search, {
base: config.base
})
const search$ = useComponent("search")
.pipe(
mountSearch(sw, { viewport$, keyboard$ }),
mountSearch(worker, { viewport$, keyboard$ }),
)
/* ----------------------------------------------------------------------- */
const navigation$ = useComponent("navigation")
.pipe(
mountNavigation({ main$, viewport$, screen$ })

View File

@ -71,7 +71,7 @@ export function mayReceiveKeyboardEvents(el: HTMLElement) {
export function watchKeyboard(): Observable<Key> {
return fromEvent<KeyboardEvent>(window, "keydown")
.pipe(
filter(ev => !(ev.shiftKey || ev.metaKey || ev.ctrlKey)),
filter(ev => !(ev.metaKey || ev.ctrlKey)),
map(ev => ({
type: ev.key,
claim() {