mirror of
https://github.com/squidfunk/mkdocs-material.git
synced 2024-06-14 11:52:32 +03:00
Fixed table of contents active element off-by-one on large screens
This commit is contained in:
parent
9aeced0876
commit
a7aa552588
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -213,7 +213,7 @@
|
|||||||
</script>
|
</script>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
{% block scripts %}
|
{% block scripts %}
|
||||||
<script src="{{ 'assets/javascripts/bundle.9f3ca3d1.min.js' | url }}"></script>
|
<script src="{{ 'assets/javascripts/bundle.b88e97c5.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 %}
|
||||||
|
@ -24,7 +24,7 @@ import {
|
|||||||
Observable,
|
Observable,
|
||||||
Subject,
|
Subject,
|
||||||
bufferCount,
|
bufferCount,
|
||||||
combineLatest,
|
combineLatestWith,
|
||||||
debounceTime,
|
debounceTime,
|
||||||
defer,
|
defer,
|
||||||
distinctUntilChanged,
|
distinctUntilChanged,
|
||||||
@ -34,6 +34,7 @@ import {
|
|||||||
of,
|
of,
|
||||||
repeat,
|
repeat,
|
||||||
scan,
|
scan,
|
||||||
|
share,
|
||||||
skip,
|
skip,
|
||||||
startWith,
|
startWith,
|
||||||
switchMap,
|
switchMap,
|
||||||
@ -46,13 +47,17 @@ import {
|
|||||||
import { feature } from "~/_"
|
import { feature } from "~/_"
|
||||||
import {
|
import {
|
||||||
Viewport,
|
Viewport,
|
||||||
|
getElement,
|
||||||
getElements,
|
getElements,
|
||||||
getLocation,
|
getLocation,
|
||||||
getOptionalElement,
|
getOptionalElement,
|
||||||
watchElementSize
|
watchElementSize
|
||||||
} from "~/browser"
|
} from "~/browser"
|
||||||
|
|
||||||
import { Component } from "../_"
|
import {
|
||||||
|
Component,
|
||||||
|
getComponentElement
|
||||||
|
} from "../_"
|
||||||
import { Header } from "../header"
|
import { Header } from "../header"
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------------
|
/* ----------------------------------------------------------------------------
|
||||||
@ -129,7 +134,16 @@ export function watchTableOfContents(
|
|||||||
/* Compute necessary adjustment for header */
|
/* Compute necessary adjustment for header */
|
||||||
const adjust$ = header$
|
const adjust$ = header$
|
||||||
.pipe(
|
.pipe(
|
||||||
map(header => 24 + header.height)
|
distinctUntilKeyChanged("height"),
|
||||||
|
map(({ height }) => {
|
||||||
|
const main = getComponentElement("main")
|
||||||
|
const grid = getElement(":scope > :first-child", main)
|
||||||
|
return height + 0.8 * (
|
||||||
|
grid.offsetTop -
|
||||||
|
main.offsetTop
|
||||||
|
)
|
||||||
|
}),
|
||||||
|
share()
|
||||||
)
|
)
|
||||||
|
|
||||||
/* Compute partition of previous and next anchors */
|
/* Compute partition of previous and next anchors */
|
||||||
@ -168,11 +182,12 @@ export function watchTableOfContents(
|
|||||||
|
|
||||||
/* Sort index by vertical offset (see https://bit.ly/30z6QSO) */
|
/* Sort index by vertical offset (see https://bit.ly/30z6QSO) */
|
||||||
map(index => new Map([...index].sort(([, a], [, b]) => a - b))),
|
map(index => new Map([...index].sort(([, a], [, b]) => a - b))),
|
||||||
|
combineLatestWith(adjust$),
|
||||||
|
|
||||||
/* Re-compute partition when viewport offset changes */
|
/* Re-compute partition when viewport offset changes */
|
||||||
switchMap(index => combineLatest([viewport$, adjust$])
|
switchMap(([index, adjust]) => viewport$
|
||||||
.pipe(
|
.pipe(
|
||||||
scan(([prev, next], [{ offset: { y }, size }, adjust]) => {
|
scan(([prev, next], { offset: { y }, size }) => {
|
||||||
const last = y + size.height >= Math.floor(body.height)
|
const last = y + size.height >= Math.floor(body.height)
|
||||||
|
|
||||||
/* Look forward */
|
/* Look forward */
|
||||||
|
Loading…
Reference in New Issue
Block a user