Fixed code blocks not selectable via keyboard after content tabs switch

This commit is contained in:
squidfunk 2021-02-15 18:23:39 +01:00
parent c5cbbd9ad8
commit ad27da16dc
7 changed files with 40 additions and 9 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.21e94a31.min.js", "assets/javascripts/bundle.js": "assets/javascripts/bundle.9a5a6e7c.min.js",
"assets/javascripts/bundle.js.map": "assets/javascripts/bundle.21e94a31.min.js.map", "assets/javascripts/bundle.js.map": "assets/javascripts/bundle.9a5a6e7c.min.js.map",
"assets/javascripts/vendor.js": "assets/javascripts/vendor.00ecb175.min.js", "assets/javascripts/vendor.js": "assets/javascripts/vendor.00ecb175.min.js",
"assets/javascripts/vendor.js.map": "assets/javascripts/vendor.00ecb175.min.js.map", "assets/javascripts/vendor.js.map": "assets/javascripts/vendor.00ecb175.min.js.map",
"assets/javascripts/worker/search.js": "assets/javascripts/worker/search.3f4c5856.min.js", "assets/javascripts/worker/search.js": "assets/javascripts/worker/search.3f4c5856.min.js",

View File

@ -217,7 +217,7 @@
{% endblock %} {% endblock %}
{% block scripts %} {% block scripts %}
<script src="{{ 'assets/javascripts/vendor.00ecb175.min.js' | url }}"></script> <script src="{{ 'assets/javascripts/vendor.00ecb175.min.js' | url }}"></script>
<script src="{{ 'assets/javascripts/bundle.21e94a31.min.js' | url }}"></script> <script src="{{ 'assets/javascripts/bundle.9a5a6e7c.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

@ -21,11 +21,20 @@
*/ */
import ClipboardJS from "clipboard" import ClipboardJS from "clipboard"
import { Observable, Subject } from "rxjs" import {
NEVER,
Observable,
Subject,
fromEvent,
merge,
of
} from "rxjs"
import { import {
distinctUntilKeyChanged, distinctUntilKeyChanged,
finalize, finalize,
map, map,
share,
switchMap,
tap, tap,
withLatestFrom withLatestFrom
} from "rxjs/operators" } from "rxjs/operators"
@ -35,6 +44,7 @@ import {
Viewport, Viewport,
getElementContentSize, getElementContentSize,
getElementSize, getElementSize,
getElements,
watchMedia watchMedia
} from "~/browser" } from "~/browser"
import { renderClipboardButton } from "~/templates" import { renderClipboardButton } from "~/templates"
@ -86,6 +96,9 @@ let index = 0
/** /**
* Watch code block * Watch code block
* *
* This function will monitor size changes of the viewport, as well as switches
* of content tabs with embedded code blocks, as both may trigger overflow.
*
* @param el - Code block element * @param el - Code block element
* @param options - Options * @param options - Options
* *
@ -94,9 +107,27 @@ let index = 0
export function watchCodeBlock( export function watchCodeBlock(
el: HTMLElement, { viewport$ }: WatchOptions el: HTMLElement, { viewport$ }: WatchOptions
): Observable<CodeBlock> { ): Observable<CodeBlock> {
return viewport$ const container$ = of(el)
.pipe(
switchMap(child => {
const container = child.closest("[data-tabs]")
if (container instanceof HTMLElement) {
return merge(
...getElements("input", container)
.map(input => fromEvent(input, "change"))
)
}
return NEVER
}),
share()
)
/* Check overflow on resize and tab change */
return merge(
viewport$.pipe(distinctUntilKeyChanged("size")),
container$
)
.pipe( .pipe(
distinctUntilKeyChanged("size"),
map(() => { map(() => {
const visible = getElementSize(el) const visible = getElementSize(el)
const content = getElementContentSize(el) const content = getElementContentSize(el)