Skip to content

Commit

Permalink
Fixed anchor following not bringing last items into view
Browse files Browse the repository at this point in the history
  • Loading branch information
squidfunk committed Feb 2, 2023
1 parent c330a08 commit c5459af
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 18 deletions.
8 changes: 0 additions & 8 deletions material/assets/javascripts/bundle.6bd5f0ae.min.js.map

This file was deleted.

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions material/assets/javascripts/bundle.6df46069.min.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion material/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@
</script>
{% endblock %}
{% block scripts %}
<script src="{{ 'assets/javascripts/bundle.6bd5f0ae.min.js' | url }}"></script>
<script src="{{ 'assets/javascripts/bundle.6df46069.min.js' | url }}"></script>
{% for path in config.extra_javascript %}
<script src="{{ path | url }}"></script>
{% endfor %}
Expand Down
4 changes: 3 additions & 1 deletion src/assets/javascripts/bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,9 @@ const content$ = defer(() => merge(

/* Table of contents */
...getComponentElements("toc")
.map(el => mountTableOfContents(el, { viewport$, header$, target$ })),
.map(el => mountTableOfContents(el, {
viewport$, header$, main$, target$
})),

/* Back-to-top button */
...getComponentElements("top")
Expand Down
11 changes: 8 additions & 3 deletions src/assets/javascripts/components/toc/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import {
Observable,
Subject,
asyncScheduler,
bufferCount,
combineLatestWith,
debounceTime,
Expand All @@ -35,6 +36,7 @@ import {
ignoreElements,
map,
merge,
observeOn,
of,
repeat,
scan,
Expand Down Expand Up @@ -64,6 +66,7 @@ import {
getComponentElement
} from "../_"
import { Header } from "../header"
import { Main } from "../main"

/* ----------------------------------------------------------------------------
* Types
Expand Down Expand Up @@ -95,6 +98,7 @@ interface WatchOptions {
interface MountOptions {
viewport$: Observable<Viewport> /* Viewport observable */
header$: Observable<Header> /* Header observable */
main$: Observable<Main> /* Main area observable */
target$: Observable<HTMLElement> /* Location target observable */
}

Expand Down Expand Up @@ -275,7 +279,7 @@ export function watchTableOfContents(
* @returns Table of contents component observable
*/
export function mountTableOfContents(
el: HTMLElement, { viewport$, header$, target$ }: MountOptions
el: HTMLElement, { viewport$, header$, main$, target$ }: MountOptions
): Observable<Component<TableOfContents>> {
return defer(() => {
const push$ = new Subject<TableOfContents>()
Expand Down Expand Up @@ -307,13 +311,14 @@ export function mountTableOfContents(
viewport$.pipe(debounceTime(250), map(() => "smooth" as const))
)

/* Bring active anchor into view */
/* Bring active anchor into view */ // @todo: refactor
push$
.pipe(
filter(({ prev }) => prev.length > 0),
combineLatestWith(main$.pipe(observeOn(asyncScheduler))),
withLatestFrom(smooth$)
)
.subscribe(([{ prev }, behavior]) => {
.subscribe(([[{ prev }], behavior]) => {
const [anchor] = prev[prev.length - 1]
if (anchor.offsetHeight) {

Expand Down

0 comments on commit c5459af

Please sign in to comment.