mirror of
https://github.com/squidfunk/mkdocs-material.git
synced 2024-06-14 11:52:32 +03:00
Fixed search initialization (7.3.2 regression)
This commit is contained in:
parent
24197fafb3
commit
b86281be2e
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -225,7 +225,7 @@
|
|||||||
</script>
|
</script>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
{% block scripts %}
|
{% block scripts %}
|
||||||
<script src="{{ 'assets/javascripts/bundle.f89c2efe.min.js' | url }}"></script>
|
<script src="{{ 'assets/javascripts/bundle.1e84347e.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 %}
|
||||||
|
@ -34,6 +34,8 @@ import {
|
|||||||
filter,
|
filter,
|
||||||
finalize,
|
finalize,
|
||||||
map,
|
map,
|
||||||
|
shareReplay,
|
||||||
|
startWith,
|
||||||
take,
|
take,
|
||||||
takeLast,
|
takeLast,
|
||||||
takeUntil,
|
takeUntil,
|
||||||
@ -92,36 +94,43 @@ export function watchSearchQuery(
|
|||||||
): Observable<SearchQuery> {
|
): Observable<SearchQuery> {
|
||||||
const fn = __search?.transform || defaultTransform
|
const fn = __search?.transform || defaultTransform
|
||||||
|
|
||||||
|
/* Immediately show search dialog */
|
||||||
|
const { searchParams } = getLocation()
|
||||||
|
if (searchParams.has("q"))
|
||||||
|
setToggle("search", true)
|
||||||
|
|
||||||
|
/* Intercept query parameter (deep link) */
|
||||||
|
const param$ = rx$
|
||||||
|
.pipe(
|
||||||
|
filter(isSearchReadyMessage),
|
||||||
|
take(1),
|
||||||
|
map(() => searchParams.get("q") || "")
|
||||||
|
)
|
||||||
|
|
||||||
|
/* Set query from parameter */
|
||||||
|
param$.subscribe(value => { // TODO: not ideal - find a better way
|
||||||
|
if (value)
|
||||||
|
el.value = value
|
||||||
|
})
|
||||||
|
|
||||||
/* Intercept focus and input events */
|
/* Intercept focus and input events */
|
||||||
const focus$ = watchElementFocus(el)
|
const focus$ = watchElementFocus(el)
|
||||||
const value$ = merge(
|
const value$ = merge(
|
||||||
fromEvent(el, "keyup"),
|
fromEvent(el, "keyup"),
|
||||||
fromEvent(el, "focus").pipe(delay(1))
|
fromEvent(el, "focus").pipe(delay(1)),
|
||||||
|
param$
|
||||||
)
|
)
|
||||||
.pipe(
|
.pipe(
|
||||||
map(() => fn(el.value)),
|
map(() => fn(el.value)),
|
||||||
distinctUntilChanged()
|
startWith(""),
|
||||||
|
distinctUntilChanged(),
|
||||||
)
|
)
|
||||||
|
|
||||||
/* Intercept deep links */
|
|
||||||
const location = getLocation()
|
|
||||||
if (location.searchParams.has("q")) {
|
|
||||||
setToggle("search", true)
|
|
||||||
rx$
|
|
||||||
.pipe(
|
|
||||||
filter(isSearchReadyMessage),
|
|
||||||
take(1)
|
|
||||||
)
|
|
||||||
.subscribe(() => {
|
|
||||||
el.value = location.searchParams.get("q")!
|
|
||||||
setElementFocus(el)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Combine into single observable */
|
/* Combine into single observable */
|
||||||
return combineLatest([value$, focus$])
|
return combineLatest([value$, focus$])
|
||||||
.pipe(
|
.pipe(
|
||||||
map(([value, focus]) => ({ value, focus }))
|
map(([value, focus]) => ({ value, focus })),
|
||||||
|
shareReplay(1)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -102,7 +102,7 @@ export function mountSearchResult(
|
|||||||
const meta = getElementOrThrow(":scope > :first-child", el)
|
const meta = getElementOrThrow(":scope > :first-child", el)
|
||||||
const list = getElementOrThrow(":scope > :last-child", el)
|
const list = getElementOrThrow(":scope > :last-child", el)
|
||||||
|
|
||||||
/* Update search result metadata when ready */
|
/* Wait until search is ready */
|
||||||
const ready$ = rx$
|
const ready$ = rx$
|
||||||
.pipe(
|
.pipe(
|
||||||
filter(isSearchReadyMessage),
|
filter(isSearchReadyMessage),
|
||||||
|
@ -24,7 +24,8 @@ import {
|
|||||||
Observable,
|
Observable,
|
||||||
Subject,
|
Subject,
|
||||||
asyncScheduler,
|
asyncScheduler,
|
||||||
fromEvent
|
fromEvent,
|
||||||
|
merge
|
||||||
} from "rxjs"
|
} from "rxjs"
|
||||||
import {
|
import {
|
||||||
combineLatestWith,
|
combineLatestWith,
|
||||||
@ -88,7 +89,10 @@ export function mountSearchSuggest(
|
|||||||
|
|
||||||
/* Retrieve query component and track all changes */
|
/* Retrieve query component and track all changes */
|
||||||
const query = getComponentElement("search-query")
|
const query = getComponentElement("search-query")
|
||||||
const query$ = fromEvent(query, "keydown")
|
const query$ = merge(
|
||||||
|
fromEvent(query, "keydown"),
|
||||||
|
fromEvent(query, "focus")
|
||||||
|
)
|
||||||
.pipe(
|
.pipe(
|
||||||
observeOn(asyncScheduler),
|
observeOn(asyncScheduler),
|
||||||
map(() => query.value),
|
map(() => query.value),
|
||||||
|
Loading…
Reference in New Issue
Block a user