mirror of
https://github.com/squidfunk/mkdocs-material.git
synced 2024-11-30 18:24:35 +01:00
Squashed commit of the following:
commit 9b5b80380fc81f5a68828e22754f0e7d53b0dea0
Author: squidfunk <martin.donath@squidfunk.com>
Date: Sun Feb 7 16:25:06 2021 +0100
Refactored more stuff
commit 5a2108254f1222db7de08690e13c24e972ea19c0
Author: squidfunk <martin.donath@squidfunk.com>
Date: Sun Feb 7 13:48:16 2021 +0100
Refactored more stuff
commit b3a112f4bddefebcf9dbd1d0ffe240d86fc9aa08
Author: squidfunk <martin.donath@squidfunk.com>
Date: Sun Feb 7 12:02:42 2021 +0100
Refactored more stuff
commit bff323b6b81571021c0ac9be6f637de7728447a5
Author: squidfunk <martin.donath@squidfunk.com>
Date: Sat Feb 6 18:14:52 2021 +0100
Refactored search result list
commit 27b7e7e2da3b725797ad769e4411260ffd35b9f8
Author: squidfunk <martin.donath@squidfunk.com>
Date: Sat Feb 6 17:12:36 2021 +0100
Refactored more components
commit 3747e5ba6d084ed513a2659f48f161449b760076
Author: squidfunk <martin.donath@squidfunk.com>
Date: Sun Jan 24 18:56:26 2021 +0100
Implemented new architecture for several components
commit ea2851ab0f27113b080c2539a94a88dc0332be84
Author: squidfunk <martin.donath@squidfunk.com>
Date: Sun Jan 24 14:53:42 2021 +0100
Removed unnecessary height declaration for sidebars
commit 3c3f83ab4ef392dbabf1a11afba2556e529b1674
Merge: 91d239d8 13024179
Author: squidfunk <martin.donath@squidfunk.com>
Date: Sun Jan 24 13:04:49 2021 +0100
Merge branch 'master' into refactor/observable-architecture
commit 91d239d86649b9571b376011669bc73a7865b186
Author: squidfunk <martin.donath@squidfunk.com>
Date: Sat Jan 9 13:11:04 2021 +0100
Started refactoring observable architecture
This commit is contained in:
parent
130241791d
commit
ae867d484b
2
material/assets/javascripts/bundle.0168bc18.min.js
vendored
Normal file
2
material/assets/javascripts/bundle.0168bc18.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
1
material/assets/javascripts/bundle.0168bc18.min.js.map
Normal file
1
material/assets/javascripts/bundle.0168bc18.min.js.map
Normal file
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
16
material/assets/javascripts/vendor.2c98d838.min.js
vendored
Normal file
16
material/assets/javascripts/vendor.2c98d838.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
1
material/assets/javascripts/vendor.2c98d838.min.js.map
Normal file
1
material/assets/javascripts/vendor.2c98d838.min.js.map
Normal file
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
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -1,14 +1,14 @@
|
|||||||
{
|
{
|
||||||
"assets/javascripts/bundle.js": "assets/javascripts/bundle.e9c9f54f.min.js",
|
"assets/javascripts/bundle.js": "assets/javascripts/bundle.0168bc18.min.js",
|
||||||
"assets/javascripts/bundle.js.map": "assets/javascripts/bundle.e9c9f54f.min.js.map",
|
"assets/javascripts/bundle.js.map": "assets/javascripts/bundle.0168bc18.min.js.map",
|
||||||
"assets/javascripts/vendor.js": "assets/javascripts/vendor.53cc9318.min.js",
|
"assets/javascripts/vendor.js": "assets/javascripts/vendor.2c98d838.min.js",
|
||||||
"assets/javascripts/vendor.js.map": "assets/javascripts/vendor.53cc9318.min.js.map",
|
"assets/javascripts/vendor.js.map": "assets/javascripts/vendor.2c98d838.min.js.map",
|
||||||
"assets/javascripts/worker/search.js": "assets/javascripts/worker/search.9c0e82ba.min.js",
|
"assets/javascripts/worker/search.js": "assets/javascripts/worker/search.cc7c7442.min.js",
|
||||||
"assets/javascripts/worker/search.js.map": "assets/javascripts/worker/search.9c0e82ba.min.js.map",
|
"assets/javascripts/worker/search.js.map": "assets/javascripts/worker/search.cc7c7442.min.js.map",
|
||||||
"assets/stylesheets/main.css": "assets/stylesheets/main.cb6bc1d0.min.css",
|
"assets/stylesheets/main.css": "assets/stylesheets/main.9c987ffa.min.css",
|
||||||
"assets/stylesheets/main.css.map": "assets/stylesheets/main.cb6bc1d0.min.css.map",
|
"assets/stylesheets/main.css.map": "assets/stylesheets/main.9c987ffa.min.css.map",
|
||||||
"assets/stylesheets/overrides.css": "assets/stylesheets/overrides.c462ebf7.min.css",
|
"assets/stylesheets/overrides.css": "assets/stylesheets/overrides.45bf1a32.min.css",
|
||||||
"assets/stylesheets/overrides.css.map": "assets/stylesheets/overrides.c462ebf7.min.css.map",
|
"assets/stylesheets/overrides.css.map": "assets/stylesheets/overrides.45bf1a32.min.css.map",
|
||||||
"assets/stylesheets/palette.css": "assets/stylesheets/palette.39b8e14a.min.css",
|
"assets/stylesheets/palette.css": "assets/stylesheets/palette.00fa6fd5.min.css",
|
||||||
"assets/stylesheets/palette.css.map": "assets/stylesheets/palette.39b8e14a.min.css.map"
|
"assets/stylesheets/palette.css.map": "assets/stylesheets/palette.00fa6fd5.min.css.map"
|
||||||
}
|
}
|
3
material/assets/stylesheets/main.9c987ffa.min.css
vendored
Normal file
3
material/assets/stylesheets/main.9c987ffa.min.css
vendored
Normal file
File diff suppressed because one or more lines are too long
1
material/assets/stylesheets/main.9c987ffa.min.css.map
Normal file
1
material/assets/stylesheets/main.9c987ffa.min.css.map
Normal file
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
@ -1,3 +1,3 @@
|
|||||||
@-webkit-keyframes tx-heart{0%,40%,80%,100%{transform:scale(1)}20%,60%{transform:scale(1.15)}}@keyframes tx-heart{0%,40%,80%,100%{transform:scale(1)}20%,60%{transform:scale(1.15)}}.md-typeset figure>p+figcaption{margin-top:-1.2rem}.md-typeset .twitter{color:#00acee}.md-typeset .tx-video{width:auto}.md-typeset .tx-video__inner{position:relative;width:100%;height:0;padding-bottom:56.138%}.md-typeset .tx-video iframe{position:absolute;top:0;left:0;width:100%;height:100%;overflow:hidden;border:none}.md-typeset .tx-heart{-webkit-animation:tx-heart 1000ms infinite;animation:tx-heart 1000ms infinite}.md-typeset .tx-insiders{color:#e91e63}.md-typeset .tx-insiders-button{font-weight:400}.md-typeset .tx-insiders-count{font-weight:700}.md-typeset .tx-insiders-list{margin:2em 0;overflow:auto}.md-typeset .tx-insiders-list__item{display:block;float:left;width:3rem;height:3rem;margin:.2rem;overflow:hidden;border-radius:100%;transform:scale(1);transition:color 125ms,transform 125ms}.md-typeset .tx-insiders-list__item img{display:block;width:100%;height:auto;-webkit-filter:grayscale(100%);filter:grayscale(100%);transition:-webkit-filter 125ms;transition:filter 125ms;transition:filter 125ms, -webkit-filter 125ms}.md-typeset .tx-insiders-list__item:focus,.md-typeset .tx-insiders-list__item:hover{transform:scale(1.1)}.md-typeset .tx-insiders-list__item:focus img,.md-typeset .tx-insiders-list__item:hover img{-webkit-filter:grayscale(0%);filter:grayscale(0%)}.md-typeset .tx-insiders-list__item--private{color:var(--md-default-fg-color--lighter);font-weight:700;font-size:1.2rem;line-height:3rem;text-align:center;background:var(--md-default-fg-color--lightest)}.md-typeset .tx-switch button{cursor:pointer;transition:opacity 250ms}.md-typeset .tx-switch button:focus,.md-typeset .tx-switch button:hover{opacity:.75}.md-typeset .tx-switch button>code{display:block;color:var(--md-primary-bg-color);background-color:var(--md-primary-fg-color)}.md-typeset .tx-columns ol,.md-typeset .tx-columns ul{-moz-columns:2;columns:2}@media screen and (max-width: 29.9375em){.md-typeset .tx-columns ol,.md-typeset .tx-columns ul{-moz-columns:initial;columns:initial}}.md-typeset .tx-columns li{-moz-column-break-inside:avoid;break-inside:avoid}.md-announce a,.md-announce a:focus,.md-announce a:hover{color:currentColor}.md-announce strong{white-space:nowrap}.md-announce .twitter{margin-left:.2em}.tx-content__footer{margin-top:1rem;text-align:center}.tx-content__footer a{display:inline-block;color:#e91e63;transition:transform 250ms cubic-bezier(0.1, 0.7, 0.1, 1),color 125ms}.tx-content__footer a:focus,.tx-content__footer a:hover{transform:scale(1.2)}.tx-content__footer hr{display:inline-block;width:2rem;margin:1em;vertical-align:middle;background-color:currentColor;border:none}.tx-container{padding-top:1rem;background:url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 1123 258'><path d='M1124,2c0,0 0,256 0,256l-1125,0l0,-48c0,0 16,5 55,5c116,0 197,-92 325,-92c121,0 114,46 254,46c140,0 214,-167 572,-166Z' style='fill: hsla(0, 0%, 100%, 1)' /></svg>") no-repeat bottom,linear-gradient(to bottom, var(--md-primary-fg-color), #a63fd9 99%, var(--md-default-bg-color) 99%)}[data-md-color-scheme=slate] .tx-container{background:url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 1123 258'><path d='M1124,2c0,0 0,256 0,256l-1125,0l0,-48c0,0 16,5 55,5c116,0 197,-92 325,-92c121,0 114,46 254,46c140,0 214,-167 572,-166Z' style='fill: hsla(232, 15%, 21%, 1)' /></svg>") no-repeat bottom,linear-gradient(to bottom, var(--md-primary-fg-color), #a63fd9 99%, var(--md-default-bg-color) 99%)}.tx-hero{margin:0 .8rem;color:var(--md-primary-bg-color)}.tx-hero h1{margin-bottom:1rem;color:currentColor;font-weight:700}@media screen and (max-width: 29.9375em){.tx-hero h1{font-size:1.4rem}}.tx-hero__content{padding-bottom:6rem}@media screen and (min-width: 60em){.tx-hero{display:flex;align-items:stretch}.tx-hero__content{max-width:19rem;margin-top:3.5rem;padding-bottom:14vw}.tx-hero__image{order:1;width:38rem;transform:translateX(4rem)}}@media screen and (min-width: 76.25em){.tx-hero__image{transform:translateX(8rem)}}.tx-hero .md-button{margin-top:.5rem;margin-right:.5rem;color:var(--md-primary-bg-color)}.tx-hero .md-button:focus,.tx-hero .md-button:hover{color:var(--md-default-bg-color);background-color:var(--md-accent-fg-color);border-color:var(--md-accent-fg-color)}.tx-hero .md-button--primary{color:#894da8;background-color:var(--md-primary-bg-color);border-color:var(--md-primary-bg-color)}
|
@-webkit-keyframes tx-heart{0%,40%,80%,100%{transform:scale(1)}20%,60%{transform:scale(1.15)}}@keyframes tx-heart{0%,40%,80%,100%{transform:scale(1)}20%,60%{transform:scale(1.15)}}.md-typeset figure>p+figcaption{margin-top:-1.2rem}.md-typeset .twitter{color:#00acee}.md-typeset .tx-video{width:auto}.md-typeset .tx-video__inner{position:relative;width:100%;height:0;padding-bottom:56.138%}.md-typeset .tx-video iframe{position:absolute;top:0;left:0;width:100%;height:100%;overflow:hidden;border:none}.md-typeset .tx-heart{-webkit-animation:tx-heart 1000ms infinite;animation:tx-heart 1000ms infinite}.md-typeset .tx-insiders{color:#e91e63}.md-typeset .tx-insiders-button{font-weight:400}.md-typeset .tx-insiders-count{font-weight:700}.md-typeset .tx-insiders-list{margin:2em 0;overflow:auto}.md-typeset .tx-insiders-list__item{display:block;float:left;width:3rem;height:3rem;margin:.2rem;overflow:hidden;border-radius:100%;transform:scale(1);transition:color 125ms,transform 125ms}.md-typeset .tx-insiders-list__item img{display:block;width:100%;height:auto;-webkit-filter:grayscale(100%);filter:grayscale(100%);transition:-webkit-filter 125ms;transition:filter 125ms;transition:filter 125ms, -webkit-filter 125ms}.md-typeset .tx-insiders-list__item:focus,.md-typeset .tx-insiders-list__item:hover{transform:scale(1.1)}.md-typeset .tx-insiders-list__item:focus img,.md-typeset .tx-insiders-list__item:hover img{-webkit-filter:grayscale(0%);filter:grayscale(0%)}.md-typeset .tx-insiders-list__item--private{color:var(--md-default-fg-color--lighter);font-weight:700;font-size:1.2rem;line-height:3rem;text-align:center;background:var(--md-default-fg-color--lightest)}.md-typeset .tx-switch button{cursor:pointer;transition:opacity 250ms}.md-typeset .tx-switch button:focus,.md-typeset .tx-switch button:hover{opacity:.75}.md-typeset .tx-switch button>code{display:block;color:var(--md-primary-bg-color);background-color:var(--md-primary-fg-color)}.md-typeset .tx-columns ol,.md-typeset .tx-columns ul{-moz-columns:2;columns:2}@media screen and (max-width: 29.9375em){.md-typeset .tx-columns ol,.md-typeset .tx-columns ul{-moz-columns:initial;columns:initial}}.md-typeset .tx-columns li{-moz-column-break-inside:avoid;break-inside:avoid}.md-announce a,.md-announce a:focus,.md-announce a:hover{color:currentColor}.md-announce strong{white-space:nowrap}.md-announce .twitter{margin-left:.2em}.tx-content__footer{margin-top:1rem;text-align:center}.tx-content__footer a{display:inline-block;color:#e91e63;transition:transform 250ms cubic-bezier(0.1, 0.7, 0.1, 1),color 125ms}.tx-content__footer a:focus,.tx-content__footer a:hover{transform:scale(1.2)}.tx-content__footer hr{display:inline-block;width:2rem;margin:1em;vertical-align:middle;background-color:currentColor;border:none}.tx-container{padding-top:1rem;background:url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 1123 258'><path d='M1124,2c0,0 0,256 0,256l-1125,0l0,-48c0,0 16,5 55,5c116,0 197,-92 325,-92c121,0 114,46 254,46c140,0 214,-167 572,-166Z' style='fill: hsla(0, 0%, 100%, 1)' /></svg>") no-repeat bottom,linear-gradient(to bottom, var(--md-primary-fg-color), #a63fd9 99%, var(--md-default-bg-color) 99%)}[data-md-color-scheme=slate] .tx-container{background:url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 1123 258'><path d='M1124,2c0,0 0,256 0,256l-1125,0l0,-48c0,0 16,5 55,5c116,0 197,-92 325,-92c121,0 114,46 254,46c140,0 214,-167 572,-166Z' style='fill: hsla(232, 15%, 21%, 1)' /></svg>") no-repeat bottom,linear-gradient(to bottom, var(--md-primary-fg-color), #a63fd9 99%, var(--md-default-bg-color) 99%)}.tx-hero{margin:0 .8rem;color:var(--md-primary-bg-color)}.tx-hero h1{margin-bottom:1rem;color:currentColor;font-weight:700}@media screen and (max-width: 29.9375em){.tx-hero h1{font-size:1.4rem}}.tx-hero__content{padding-bottom:6rem}@media screen and (min-width: 60em){.tx-hero{display:flex;align-items:stretch}.tx-hero__content{max-width:19rem;margin-top:3.5rem;padding-bottom:14vw}.tx-hero__image{order:1;width:38rem;transform:translateX(4rem)}}@media screen and (min-width: 76.25em){.tx-hero__image{transform:translateX(8rem)}}.tx-hero .md-button{margin-top:.5rem;margin-right:.5rem;color:var(--md-primary-bg-color)}.tx-hero .md-button:focus,.tx-hero .md-button:hover{color:var(--md-default-bg-color);background-color:var(--md-accent-fg-color);border-color:var(--md-accent-fg-color)}.tx-hero .md-button--primary{color:#894da8;background-color:var(--md-primary-bg-color);border-color:var(--md-primary-bg-color)}
|
||||||
|
|
||||||
/*# sourceMappingURL=overrides.c462ebf7.min.css.map*/
|
/*# sourceMappingURL=overrides.45bf1a32.min.css.map*/
|
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
@ -39,10 +39,10 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
{% block styles %}
|
{% block styles %}
|
||||||
<link rel="stylesheet" href="{{ 'assets/stylesheets/main.cb6bc1d0.min.css' | url }}">
|
<link rel="stylesheet" href="{{ 'assets/stylesheets/main.9c987ffa.min.css' | url }}">
|
||||||
{% if config.theme.palette %}
|
{% if config.theme.palette %}
|
||||||
{% set palette = config.theme.palette %}
|
{% set palette = config.theme.palette %}
|
||||||
<link rel="stylesheet" href="{{ 'assets/stylesheets/palette.39b8e14a.min.css' | url }}">
|
<link rel="stylesheet" href="{{ 'assets/stylesheets/palette.00fa6fd5.min.css' | url }}">
|
||||||
{% if palette.primary %}
|
{% if palette.primary %}
|
||||||
{% import "partials/palette.html" as map %}
|
{% import "partials/palette.html" as map %}
|
||||||
{% set primary = map.primary(
|
{% set primary = map.primary(
|
||||||
@ -131,7 +131,7 @@
|
|||||||
{% if page and page.meta and page.meta.hide %}
|
{% if page and page.meta and page.meta.hide %}
|
||||||
{% set hidden = "hidden" if "navigation" in page.meta.hide %}
|
{% set hidden = "hidden" if "navigation" in page.meta.hide %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<div class="md-sidebar md-sidebar--primary" data-md-component="navigation" {{ hidden }}>
|
<div class="md-sidebar md-sidebar--primary" data-md-component="sidebar" data-md-type="navigation" {{ hidden }}>
|
||||||
<div class="md-sidebar__scrollwrap">
|
<div class="md-sidebar__scrollwrap">
|
||||||
<div class="md-sidebar__inner">
|
<div class="md-sidebar__inner">
|
||||||
{% include "partials/nav.html" %}
|
{% include "partials/nav.html" %}
|
||||||
@ -143,7 +143,7 @@
|
|||||||
{% if page and page.meta and page.meta.hide %}
|
{% if page and page.meta and page.meta.hide %}
|
||||||
{% set hidden = "hidden" if "toc" in page.meta.hide %}
|
{% set hidden = "hidden" if "toc" in page.meta.hide %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<div class="md-sidebar md-sidebar--secondary" data-md-component="toc" {{ hidden }}>
|
<div class="md-sidebar md-sidebar--secondary" data-md-component="sidebar" data-md-type="toc" {{ hidden }}>
|
||||||
<div class="md-sidebar__scrollwrap">
|
<div class="md-sidebar__scrollwrap">
|
||||||
<div class="md-sidebar__inner">
|
<div class="md-sidebar__inner">
|
||||||
{% include "partials/toc.html" %}
|
{% include "partials/toc.html" %}
|
||||||
@ -152,7 +152,7 @@
|
|||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
<div class="md-content">
|
<div class="md-content" data-md-component="content">
|
||||||
<article class="md-content__inner md-typeset">
|
<article class="md-content__inner md-typeset">
|
||||||
{% block content %}
|
{% block content %}
|
||||||
{% if page.edit_url %}
|
{% if page.edit_url %}
|
||||||
@ -182,11 +182,18 @@
|
|||||||
{% block footer %}
|
{% block footer %}
|
||||||
{% include "partials/footer.html" %}
|
{% include "partials/footer.html" %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
<div class="md-dialog" data-md-component="dialog">
|
||||||
|
<div class="md-dialog__inner md-typeset"></div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% block scripts %}
|
{% block config %}
|
||||||
<script src="{{ 'assets/javascripts/vendor.53cc9318.min.js' | url }}"></script>
|
{%- set app = {
|
||||||
<script src="{{ 'assets/javascripts/bundle.e9c9f54f.min.js' | url }}"></script>
|
"base": base_url,
|
||||||
{%- set translations = {} -%}
|
"features": features,
|
||||||
|
"translations": {},
|
||||||
|
"search": "assets/javascripts/worker/search.cc7c7442.min.js" | url,
|
||||||
|
} -%}
|
||||||
|
{%- set translations = app.translations -%}
|
||||||
{%- for key in [
|
{%- for key in [
|
||||||
"clipboard.copy",
|
"clipboard.copy",
|
||||||
"clipboard.copied",
|
"clipboard.copied",
|
||||||
@ -204,19 +211,13 @@
|
|||||||
] -%}
|
] -%}
|
||||||
{%- set _ = translations.update({ key: lang.t(key) }) -%}
|
{%- set _ = translations.update({ key: lang.t(key) }) -%}
|
||||||
{%- endfor -%}
|
{%- endfor -%}
|
||||||
<script id="__lang" type="application/json">
|
<script id="__config" type="application/json">
|
||||||
{{- translations | tojson -}}
|
{{- app | tojson -}}
|
||||||
</script>
|
|
||||||
{% block config %}{% endblock %}
|
|
||||||
<script>
|
|
||||||
app = initialize({
|
|
||||||
base: "{{ base_url }}",
|
|
||||||
features: {{ features or [] | tojson }},
|
|
||||||
search: Object.assign({
|
|
||||||
worker: "{{ 'assets/javascripts/worker/search.9c0e82ba.min.js' | url }}"
|
|
||||||
}, typeof search !== "undefined" && search)
|
|
||||||
})
|
|
||||||
</script>
|
</script>
|
||||||
|
{% endblock %}
|
||||||
|
{% block scripts %}
|
||||||
|
<script src="{{ 'assets/javascripts/vendor.2c98d838.min.js' | url }}"></script>
|
||||||
|
<script src="{{ 'assets/javascripts/bundle.0168bc18.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 %}
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
<meta name="twitter:title" content="{{ title }}">
|
<meta name="twitter:title" content="{{ title }}">
|
||||||
<meta name="twitter:description" content="{{ config.site_description }}">
|
<meta name="twitter:description" content="{{ config.site_description }}">
|
||||||
<meta name="twitter:image" content="{{ image }}">
|
<meta name="twitter:image" content="{{ image }}">
|
||||||
<link rel="stylesheet" href="{{ 'assets/stylesheets/overrides.c462ebf7.min.css' | url }}">
|
<link rel="stylesheet" href="{{ 'assets/stylesheets/overrides.45bf1a32.min.css' | url }}">
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
{% block announce %}
|
{% block announce %}
|
||||||
<a href="https://twitter.com/squidfunk">
|
<a href="https://twitter.com/squidfunk">
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
{% include ".icons/material/magnify.svg" %}
|
{% include ".icons/material/magnify.svg" %}
|
||||||
{% include ".icons/material/arrow-left.svg" %}
|
{% include ".icons/material/arrow-left.svg" %}
|
||||||
</label>
|
</label>
|
||||||
<button type="reset" class="md-search__icon md-icon" aria-label="{{ lang.t('search.reset') }}" data-md-component="search-reset" tabindex="-1">
|
<button type="reset" class="md-search__icon md-icon" aria-label="{{ lang.t('search.reset') }}" tabindex="-1">
|
||||||
{% include ".icons/material/close.svg" %}
|
{% include ".icons/material/close.svg" %}
|
||||||
</button>
|
</button>
|
||||||
</form>
|
</form>
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
This file was automatically generated - do not edit
|
This file was automatically generated - do not edit
|
||||||
-#}
|
-#}
|
||||||
{% import "partials/language.html" as lang with context %}
|
{% import "partials/language.html" as lang with context %}
|
||||||
<a href="{{ config.repo_url }}" title="{{ lang.t('source.link.title') }}" class="md-source">
|
<a href="{{ config.repo_url }}" title="{{ lang.t('source.link.title') }}" class="md-source" data-md-component="source">
|
||||||
<div class="md-source__icon md-icon">
|
<div class="md-source__icon md-icon">
|
||||||
{% set icon = config.theme.icon.repo or "fontawesome/brands/git-alt" %}
|
{% set icon = config.theme.icon.repo or "fontawesome/brands/git-alt" %}
|
||||||
{% include ".icons/" ~ icon ~ ".svg" %}
|
{% include ".icons/" ~ icon ~ ".svg" %}
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
<span class="md-nav__icon md-icon"></span>
|
<span class="md-nav__icon md-icon"></span>
|
||||||
{{ lang.t("toc.title") }}
|
{{ lang.t("toc.title") }}
|
||||||
</label>
|
</label>
|
||||||
<ul class="md-nav__list" data-md-scrollfix>
|
<ul class="md-nav__list" data-md-component="toc" data-md-scrollfix>
|
||||||
{% for toc_item in toc %}
|
{% for toc_item in toc %}
|
||||||
{% include "partials/toc-item.html" %}
|
{% include "partials/toc-item.html" %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
@ -86,8 +86,6 @@
|
|||||||
"ts-node": "^9.1.1",
|
"ts-node": "^9.1.1",
|
||||||
"tsconfig-paths-webpack-plugin": "^3.3.0",
|
"tsconfig-paths-webpack-plugin": "^3.3.0",
|
||||||
"tslib": "^2.1.0",
|
"tslib": "^2.1.0",
|
||||||
"tslint": "^6.1.3",
|
|
||||||
"tslint-sonarts": "^1.9.0",
|
|
||||||
"typescript": "^4.1.3",
|
"typescript": "^4.1.3",
|
||||||
"webpack": "^4.44.2",
|
"webpack": "^4.44.2",
|
||||||
"webpack-assets-manifest": "3.1.1",
|
"webpack-assets-manifest": "3.1.1",
|
||||||
|
127
src/assets/javascripts/_/index.ts
Normal file
127
src/assets/javascripts/_/index.ts
Normal file
@ -0,0 +1,127 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016-2020 Martin Donath <martin.donath@squidfunk.com>
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to
|
||||||
|
* deal in the Software without restriction, including without limitation the
|
||||||
|
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||||
|
* sell copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||||
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||||
|
* IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { getElementOrThrow, getLocation } from "~/browser"
|
||||||
|
|
||||||
|
/* ----------------------------------------------------------------------------
|
||||||
|
* Types
|
||||||
|
* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Feature flag
|
||||||
|
*/
|
||||||
|
export type Feature =
|
||||||
|
| "header.autohide" /* Hide header */
|
||||||
|
| "navigation.tabs" /* Tabs navigation */
|
||||||
|
| "navigation.instant" /* Instant loading */
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Translation
|
||||||
|
*/
|
||||||
|
export type Translation =
|
||||||
|
| "clipboard.copy" /* Copy to clipboard */
|
||||||
|
| "clipboard.copied" /* Copied to clipboard */
|
||||||
|
| "search.config.lang" /* Search language */
|
||||||
|
| "search.config.pipeline" /* Search pipeline */
|
||||||
|
| "search.config.separator" /* Search separator */
|
||||||
|
| "search.placeholder" /* Search */
|
||||||
|
| "search.result.placeholder" /* Type to start searching */
|
||||||
|
| "search.result.none" /* No matching documents */
|
||||||
|
| "search.result.one" /* 1 matching document */
|
||||||
|
| "search.result.other" /* # matching documents */
|
||||||
|
| "search.result.more.one" /* 1 more on this page */
|
||||||
|
| "search.result.more.other" /* # more on this page */
|
||||||
|
| "search.result.term.missing" /* Missing */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Translations
|
||||||
|
*/
|
||||||
|
export type Translations = Record<Translation, string>
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configuration
|
||||||
|
*/
|
||||||
|
export interface Config {
|
||||||
|
base: string /* Base URL */
|
||||||
|
features: Feature[] /* Feature flags */
|
||||||
|
translations: Translations /* Translations */
|
||||||
|
search: string /* Search worker URL */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ----------------------------------------------------------------------------
|
||||||
|
* Data
|
||||||
|
* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve global configuration and make base URL absolute
|
||||||
|
*/
|
||||||
|
let config: Config = JSON.parse(getElementOrThrow("#__config").textContent!)
|
||||||
|
config.base = new URL(config.base, getLocation())
|
||||||
|
.toString()
|
||||||
|
.replace(/\/$/, "")
|
||||||
|
|
||||||
|
/* ----------------------------------------------------------------------------
|
||||||
|
* Functions
|
||||||
|
* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve global configuration
|
||||||
|
*
|
||||||
|
* @return Global configuration
|
||||||
|
*/
|
||||||
|
export function configuration(): Config {
|
||||||
|
return config
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check whether a feature is enabled
|
||||||
|
*
|
||||||
|
* @param feature - Feature
|
||||||
|
*
|
||||||
|
* @returns Test result
|
||||||
|
*/
|
||||||
|
export function flag(feature: Feature): boolean {
|
||||||
|
return config.features.includes(feature)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve the translation for the given key
|
||||||
|
*
|
||||||
|
* @param key - Key to be translated
|
||||||
|
* @param value - Value to be replaced
|
||||||
|
*
|
||||||
|
* @return Translation
|
||||||
|
*/
|
||||||
|
export function translation(
|
||||||
|
key: Translation, value?: string | number
|
||||||
|
): string {
|
||||||
|
if (typeof config.translations[key] === "undefined") {
|
||||||
|
throw new ReferenceError(`Invalid translation: ${key}`)
|
||||||
|
}
|
||||||
|
return typeof value !== "undefined"
|
||||||
|
? config.translations[key].replace("#", value.toString())
|
||||||
|
: config.translations[key]
|
||||||
|
}
|
@ -20,25 +20,29 @@
|
|||||||
* IN THE SOFTWARE.
|
* IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { Observable, fromEvent } from "rxjs"
|
|
||||||
import { mapTo } from "rxjs/operators"
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------------
|
/* ----------------------------------------------------------------------------
|
||||||
* Functions
|
* Functions
|
||||||
* ------------------------------------------------------------------------- */
|
* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Watch search reset
|
* Set focusable property
|
||||||
*
|
*
|
||||||
* @param el - Search reset element
|
* @param el - Element
|
||||||
*
|
* @param value - Tabindex value
|
||||||
* @return Search reset observable
|
|
||||||
*/
|
*/
|
||||||
export function watchSearchReset(
|
export function setFocusable(
|
||||||
el: HTMLElement
|
el: HTMLElement, value = 0
|
||||||
): Observable<void> {
|
): void {
|
||||||
return fromEvent(el, "click")
|
el.setAttribute("tabindex", value.toString())
|
||||||
.pipe(
|
}
|
||||||
mapTo(undefined)
|
|
||||||
)
|
/**
|
||||||
|
* Reset focusable property
|
||||||
|
*
|
||||||
|
* @param el - Element
|
||||||
|
*/
|
||||||
|
export function resetFocusable(
|
||||||
|
el: HTMLElement
|
||||||
|
): void {
|
||||||
|
el.removeAttribute("tabindex")
|
||||||
}
|
}
|
@ -25,23 +25,23 @@
|
|||||||
* ------------------------------------------------------------------------- */
|
* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set anchor blur
|
* Set anchor state
|
||||||
*
|
*
|
||||||
* @param el - Anchor element
|
* @param el - Anchor element
|
||||||
* @param value - Whether the anchor is blurred
|
* @param state - Anchor state
|
||||||
*/
|
*/
|
||||||
export function setAnchorBlur(
|
export function setAnchorState(
|
||||||
el: HTMLElement, value: boolean
|
el: HTMLElement, state: "blur"
|
||||||
): void {
|
): void {
|
||||||
el.setAttribute("data-md-state", value ? "blur" : "")
|
el.setAttribute("data-md-state", state)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reset anchor blur
|
* Reset anchor state
|
||||||
*
|
*
|
||||||
* @param el - Anchor element
|
* @param el - Anchor element
|
||||||
*/
|
*/
|
||||||
export function resetAnchorBlur(
|
export function resetAnchorState(
|
||||||
el: HTMLElement
|
el: HTMLElement
|
||||||
): void {
|
): void {
|
||||||
el.removeAttribute("data-md-state")
|
el.removeAttribute("data-md-state")
|
@ -20,37 +20,43 @@
|
|||||||
* IN THE SOFTWARE.
|
* IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { Observable } from "rxjs"
|
|
||||||
import { map, shareReplay, take } from "rxjs/operators"
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------------
|
/* ----------------------------------------------------------------------------
|
||||||
* Helper types
|
* Functions
|
||||||
* ------------------------------------------------------------------------- */
|
* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Watch options
|
* Set dialog message
|
||||||
|
*
|
||||||
|
* @param el - Dialog element
|
||||||
|
* @param value - Dialog message
|
||||||
*/
|
*/
|
||||||
interface WatchOptions {
|
export function setDialogMessage(
|
||||||
location$: Observable<URL> /* Location observable */
|
el: HTMLElement, value: string
|
||||||
|
): void {
|
||||||
|
el.firstElementChild!.innerHTML = value
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ------------------------------------------------------------------------- */
|
/* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Watch location base
|
* Set dialog state
|
||||||
*
|
*
|
||||||
* @return Location base observable
|
* @param el - Dialog element
|
||||||
|
* @param state - Dialog state
|
||||||
*/
|
*/
|
||||||
export function watchLocationBase(
|
export function setDialogState(
|
||||||
base: string, { location$ }: WatchOptions
|
el: HTMLElement, state: "open"
|
||||||
): Observable<string> {
|
): void {
|
||||||
return location$
|
el.setAttribute("data-md-state", state)
|
||||||
.pipe(
|
}
|
||||||
take(1),
|
|
||||||
map(({ href }) => new URL(base, href)
|
/**
|
||||||
.toString()
|
* Reset dialog state
|
||||||
.replace(/\/$/, "")
|
*
|
||||||
),
|
* @param el - Dialog element
|
||||||
shareReplay({ bufferSize: 1, refCount: true })
|
*/
|
||||||
)
|
export function resetDialogState(
|
||||||
|
el: HTMLElement
|
||||||
|
): void {
|
||||||
|
el.removeAttribute("data-md-state")
|
||||||
}
|
}
|
@ -25,23 +25,23 @@
|
|||||||
* ------------------------------------------------------------------------- */
|
* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set header shadow
|
* Set header state
|
||||||
*
|
*
|
||||||
* @param el - Header element
|
* @param el - Header element
|
||||||
* @param value - Whether the shadow is shown
|
* @param state - Header state
|
||||||
*/
|
*/
|
||||||
export function setHeaderShadow(
|
export function setHeaderState(
|
||||||
el: HTMLElement, value: boolean
|
el: HTMLElement, state: "shadow" | "hidden"
|
||||||
): void {
|
): void {
|
||||||
el.setAttribute("data-md-state", value ? "shadow" : "")
|
el.setAttribute("data-md-state", state)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reset header shadow
|
* Reset header state
|
||||||
*
|
*
|
||||||
* @param el - Header element
|
* @param el - Header element
|
||||||
*/
|
*/
|
||||||
export function resetHeaderShadow(
|
export function resetHeaderState(
|
||||||
el: HTMLElement
|
el: HTMLElement
|
||||||
): void {
|
): void {
|
||||||
el.removeAttribute("data-md-state")
|
el.removeAttribute("data-md-state")
|
@ -21,4 +21,4 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
export * from "./_"
|
export * from "./_"
|
||||||
export * from "./react"
|
export * from "./title"
|
@ -25,23 +25,23 @@
|
|||||||
* ------------------------------------------------------------------------- */
|
* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set header title active
|
* Set header title state
|
||||||
*
|
*
|
||||||
* @param el - Header title element
|
* @param el - Header title element
|
||||||
* @param value - Whether the title is shown
|
* @param state - Header title state
|
||||||
*/
|
*/
|
||||||
export function setHeaderTitleActive(
|
export function setHeaderTitleState(
|
||||||
el: HTMLElement, value: boolean
|
el: HTMLElement, state: "active"
|
||||||
): void {
|
): void {
|
||||||
el.setAttribute("data-md-state", value ? "active" : "")
|
el.setAttribute("data-md-state", state)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reset header title active
|
* Reset header title state
|
||||||
*
|
*
|
||||||
* @param el - Header title element
|
* @param el - Header title element
|
||||||
*/
|
*/
|
||||||
export function resetHeaderTitleActive(
|
export function resetHeaderTitleState(
|
||||||
el: HTMLElement
|
el: HTMLElement
|
||||||
): void {
|
): void {
|
||||||
el.removeAttribute("data-md-state")
|
el.removeAttribute("data-md-state")
|
@ -20,9 +20,11 @@
|
|||||||
* IN THE SOFTWARE.
|
* IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export * from "./code"
|
export * from "./_"
|
||||||
export * from "./details"
|
export * from "./anchor"
|
||||||
export * from "./script"
|
export * from "./dialog"
|
||||||
export * from "./scrollfix"
|
export * from "./header"
|
||||||
|
export * from "./search"
|
||||||
|
export * from "./sidebar"
|
||||||
export * from "./source"
|
export * from "./source"
|
||||||
export * from "./table"
|
export * from "./tabs"
|
24
src/assets/javascripts/actions/search/index.ts
Normal file
24
src/assets/javascripts/actions/search/index.ts
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016-2020 Martin Donath <martin.donath@squidfunk.com>
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to
|
||||||
|
* deal in the Software without restriction, including without limitation the
|
||||||
|
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||||
|
* sell copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||||
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||||
|
* IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
export * from "./query"
|
||||||
|
export * from "./result"
|
@ -20,7 +20,7 @@
|
|||||||
* IN THE SOFTWARE.
|
* IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { translate } from "utilities"
|
import { translation } from "~/_"
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------------
|
/* ----------------------------------------------------------------------------
|
||||||
* Functions
|
* Functions
|
||||||
@ -46,5 +46,5 @@ export function setSearchQueryPlaceholder(
|
|||||||
export function resetSearchQueryPlaceholder(
|
export function resetSearchQueryPlaceholder(
|
||||||
el: HTMLInputElement
|
el: HTMLInputElement
|
||||||
): void {
|
): void {
|
||||||
el.placeholder = translate("search.placeholder")
|
el.placeholder = translation("search.placeholder")
|
||||||
}
|
}
|
@ -20,7 +20,7 @@
|
|||||||
* IN THE SOFTWARE.
|
* IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { translate } from "utilities"
|
import { translation } from "~/_"
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------------
|
/* ----------------------------------------------------------------------------
|
||||||
* Functions
|
* Functions
|
||||||
@ -39,17 +39,17 @@ export function setSearchResultMeta(
|
|||||||
|
|
||||||
/* No results */
|
/* No results */
|
||||||
case 0:
|
case 0:
|
||||||
el.textContent = translate("search.result.none")
|
el.textContent = translation("search.result.none")
|
||||||
break
|
break
|
||||||
|
|
||||||
/* One result */
|
/* One result */
|
||||||
case 1:
|
case 1:
|
||||||
el.textContent = translate("search.result.one")
|
el.textContent = translation("search.result.one")
|
||||||
break
|
break
|
||||||
|
|
||||||
/* Multiple result */
|
/* Multiple result */
|
||||||
default:
|
default:
|
||||||
el.textContent = translate("search.result.other", value)
|
el.textContent = translation("search.result.other", value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -61,7 +61,7 @@ export function setSearchResultMeta(
|
|||||||
export function resetSearchResultMeta(
|
export function resetSearchResultMeta(
|
||||||
el: HTMLElement
|
el: HTMLElement
|
||||||
): void {
|
): void {
|
||||||
el.textContent = translate("search.result.placeholder")
|
el.textContent = translation("search.result.placeholder")
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ------------------------------------------------------------------------- */
|
/* ------------------------------------------------------------------------- */
|
@ -55,17 +55,15 @@ export function resetSidebarOffset(
|
|||||||
* This function doesn't set the height of the actual sidebar, but of its first
|
* This function doesn't set the height of the actual sidebar, but of its first
|
||||||
* child – the `.md-sidebar__scrollwrap` element in order to mitigiate jittery
|
* child – the `.md-sidebar__scrollwrap` element in order to mitigiate jittery
|
||||||
* sidebars when the footer is scrolled into view. At some point we switched
|
* sidebars when the footer is scrolled into view. At some point we switched
|
||||||
* from `absolute` / `fixed` positioning to `sticky` positioning, which greatly
|
* from `absolute` / `fixed` positioning to `sticky` positioning, significantly
|
||||||
* reduced jitter in some browsers (respectively Firefox and Safari) when
|
* reducing jitter in some browsers (respectively Firefox and Safari) when
|
||||||
* scrolling from the top. However, top-aligned sticky positioning means that
|
* scrolling from the top. However, top-aligned sticky positioning means that
|
||||||
* the sidebar snaps to the bottom when the end of the container is reached.
|
* the sidebar snaps to the bottom when the end of the container is reached.
|
||||||
* This is what leads to the mentioned jitter, as the sidebar's height may be
|
* This is what leads to the mentioned jitter, as the sidebar's height may be
|
||||||
* updated to slowly.
|
* updated too slowly.
|
||||||
*
|
*
|
||||||
* By setting the height of the sidebar to zero (while preserving `padding`),
|
* This behaviour can be mitigiated by setting the height of the sidebar to `0`
|
||||||
* and the height on its first element, this behaviour can be mitigiated. We
|
* while preserving the padding, and the height on its first element.
|
||||||
* must assume that the top- and bottom offset (`padding`) are equal, as the
|
|
||||||
* `offsetBottom` value is `undefined`.
|
|
||||||
*
|
*
|
||||||
* @param el - Sidebar element
|
* @param el - Sidebar element
|
||||||
* @param value - Sidebar height
|
* @param value - Sidebar height
|
49
src/assets/javascripts/actions/source/index.ts
Normal file
49
src/assets/javascripts/actions/source/index.ts
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016-2020 Martin Donath <martin.donath@squidfunk.com>
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to
|
||||||
|
* deal in the Software without restriction, including without limitation the
|
||||||
|
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||||
|
* sell copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||||
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||||
|
* IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* ----------------------------------------------------------------------------
|
||||||
|
* Functions
|
||||||
|
* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set repository facts
|
||||||
|
*
|
||||||
|
* @param el - Repository element
|
||||||
|
* @param child - Repository facts element
|
||||||
|
*/
|
||||||
|
export function setSourceFacts(
|
||||||
|
el: HTMLElement, child: Element
|
||||||
|
): void {
|
||||||
|
el.lastElementChild!.appendChild(child)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set repository state
|
||||||
|
*
|
||||||
|
* @param el - Repository element
|
||||||
|
* @param state - Repository state
|
||||||
|
*/
|
||||||
|
export function setSourceState(
|
||||||
|
el: HTMLElement, state: "done"
|
||||||
|
): void {
|
||||||
|
el.lastElementChild!.setAttribute("data-md-state", state)
|
||||||
|
}
|
@ -25,23 +25,23 @@
|
|||||||
* ------------------------------------------------------------------------- */
|
* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set tabs hidden
|
* Set tabs state
|
||||||
*
|
*
|
||||||
* @param el - Tabs element
|
* @param el - Tabs element
|
||||||
* @param value - Whether the element is hidden
|
* @param state - Tabs state
|
||||||
*/
|
*/
|
||||||
export function setTabsHidden(
|
export function setTabsState(
|
||||||
el: HTMLElement, value: boolean
|
el: HTMLElement, state: "hidden"
|
||||||
): void {
|
): void {
|
||||||
el.setAttribute("data-md-state", value ? "hidden" : "")
|
el.setAttribute("data-md-state", state)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reset tabs hidden
|
* Reset tabs state
|
||||||
*
|
*
|
||||||
* @param el - Tabs element
|
* @param el - Tabs element
|
||||||
*/
|
*/
|
||||||
export function resetTabsHidden(
|
export function resetTabsState(
|
||||||
el: HTMLElement
|
el: HTMLElement
|
||||||
): void {
|
): void {
|
||||||
el.removeAttribute("data-md-state")
|
el.removeAttribute("data-md-state")
|
@ -34,6 +34,14 @@
|
|||||||
*
|
*
|
||||||
* @return Element or nothing
|
* @return Element or nothing
|
||||||
*/
|
*/
|
||||||
|
export function getElement<T extends keyof HTMLElementTagNameMap>(
|
||||||
|
selector: T, node?: ParentNode
|
||||||
|
): HTMLElementTagNameMap[T]
|
||||||
|
|
||||||
|
export function getElement<T extends HTMLElement>(
|
||||||
|
selector: string, node?: ParentNode
|
||||||
|
): T
|
||||||
|
|
||||||
export function getElement<T extends HTMLElement>(
|
export function getElement<T extends HTMLElement>(
|
||||||
selector: string, node: ParentNode = document
|
selector: string, node: ParentNode = document
|
||||||
): T | undefined {
|
): T | undefined {
|
||||||
@ -50,6 +58,14 @@ export function getElement<T extends HTMLElement>(
|
|||||||
*
|
*
|
||||||
* @return Element
|
* @return Element
|
||||||
*/
|
*/
|
||||||
|
export function getElementOrThrow<T extends keyof HTMLElementTagNameMap>(
|
||||||
|
selector: T, node?: ParentNode
|
||||||
|
): HTMLElementTagNameMap[T]
|
||||||
|
|
||||||
|
export function getElementOrThrow<T extends HTMLElement>(
|
||||||
|
selector: string, node?: ParentNode
|
||||||
|
): T
|
||||||
|
|
||||||
export function getElementOrThrow<T extends HTMLElement>(
|
export function getElementOrThrow<T extends HTMLElement>(
|
||||||
selector: string, node: ParentNode = document
|
selector: string, node: ParentNode = document
|
||||||
): T {
|
): T {
|
||||||
@ -82,6 +98,14 @@ export function getActiveElement(): HTMLElement | undefined {
|
|||||||
*
|
*
|
||||||
* @return Elements
|
* @return Elements
|
||||||
*/
|
*/
|
||||||
|
export function getElements<T extends keyof HTMLElementTagNameMap>(
|
||||||
|
selector: T, node?: ParentNode
|
||||||
|
): HTMLElementTagNameMap[T][]
|
||||||
|
|
||||||
|
export function getElements<T extends HTMLElement>(
|
||||||
|
selector: string, node?: ParentNode
|
||||||
|
): T[]
|
||||||
|
|
||||||
export function getElements<T extends HTMLElement>(
|
export function getElements<T extends HTMLElement>(
|
||||||
selector: string, node: ParentNode = document
|
selector: string, node: ParentNode = document
|
||||||
): T[] {
|
): T[] {
|
||||||
|
@ -23,5 +23,5 @@
|
|||||||
export * from "./_"
|
export * from "./_"
|
||||||
export * from "./focus"
|
export * from "./focus"
|
||||||
export * from "./offset"
|
export * from "./offset"
|
||||||
export * from "./select"
|
export * from "./selection"
|
||||||
export * from "./size"
|
export * from "./size"
|
||||||
|
@ -80,7 +80,7 @@ const observer$ = defer(() => of(
|
|||||||
finalize(() => resize.disconnect())
|
finalize(() => resize.disconnect())
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
shareReplay({ bufferSize: 1, refCount: true })
|
shareReplay(1)
|
||||||
)
|
)
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------------
|
/* ----------------------------------------------------------------------------
|
||||||
@ -101,6 +101,20 @@ export function getElementSize(el: HTMLElement): ElementSize {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve element content size, i.e. including overflowing content
|
||||||
|
*
|
||||||
|
* @param el - Element
|
||||||
|
*
|
||||||
|
* @return Element size
|
||||||
|
*/
|
||||||
|
export function getElementContentSize(el: HTMLElement): ElementSize {
|
||||||
|
return {
|
||||||
|
width: el.scrollWidth,
|
||||||
|
height: el.scrollHeight
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* ------------------------------------------------------------------------- */
|
/* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -51,40 +51,6 @@ export function setLocation(url: URL): void {
|
|||||||
|
|
||||||
/* ------------------------------------------------------------------------- */
|
/* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
/**
|
|
||||||
* Check whether a URL is a local link or a file (except `.html`)
|
|
||||||
*
|
|
||||||
* @param url - URL or HTML anchor element
|
|
||||||
* @param ref - Reference URL
|
|
||||||
*
|
|
||||||
* @return Test result
|
|
||||||
*/
|
|
||||||
export function isLocalLocation(
|
|
||||||
url: URL | HTMLAnchorElement,
|
|
||||||
ref: URL | Location = location
|
|
||||||
): boolean {
|
|
||||||
return url.host === ref.host
|
|
||||||
&& /^(?:\/[\w-]+)*(?:\/?|\.html)$/i.test(url.pathname)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Check whether a URL is an anchor link on the current page
|
|
||||||
*
|
|
||||||
* @param url - URL or HTML anchor element
|
|
||||||
* @param ref - Reference URL
|
|
||||||
*
|
|
||||||
* @return Test result
|
|
||||||
*/
|
|
||||||
export function isAnchorLocation(
|
|
||||||
url: URL | HTMLAnchorElement,
|
|
||||||
ref: URL | Location = location
|
|
||||||
): boolean {
|
|
||||||
return url.pathname === ref.pathname
|
|
||||||
&& url.hash.length > 0
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ------------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Watch location
|
* Watch location
|
||||||
*
|
*
|
||||||
|
@ -20,10 +20,11 @@
|
|||||||
* IN THE SOFTWARE.
|
* IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { Observable, fromEvent } from "rxjs"
|
import { Observable, fromEvent, of } from "rxjs"
|
||||||
import { filter, map, share, startWith } from "rxjs/operators"
|
import { filter, map, share, startWith, switchMap } from "rxjs/operators"
|
||||||
|
|
||||||
import { createElement } from "browser"
|
import { createElement } from "browser"
|
||||||
|
import { getElement } from "~/browser/element"
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------------
|
/* ----------------------------------------------------------------------------
|
||||||
* Functions
|
* Functions
|
||||||
@ -71,3 +72,15 @@ export function watchLocationHash(): Observable<string> {
|
|||||||
share()
|
share()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Watch location target
|
||||||
|
*
|
||||||
|
* @return Location target observable
|
||||||
|
*/
|
||||||
|
export function watchLocationTarget(): Observable<HTMLElement> {
|
||||||
|
return watchLocationHash()
|
||||||
|
.pipe(
|
||||||
|
switchMap(id => of(getElement(`[id="${id}"]`)!))
|
||||||
|
)
|
||||||
|
}
|
||||||
|
@ -21,5 +21,4 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
export * from "./_"
|
export * from "./_"
|
||||||
export * from "./base"
|
|
||||||
export * from "./hash"
|
export * from "./hash"
|
||||||
|
@ -20,8 +20,8 @@
|
|||||||
* IN THE SOFTWARE.
|
* IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { Observable } from "rxjs"
|
import { Observable, fromEvent, merge } from "rxjs"
|
||||||
import { shareReplay, startWith } from "rxjs/operators"
|
import { filter, map, mapTo, startWith } from "rxjs/operators"
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------------
|
/* ----------------------------------------------------------------------------
|
||||||
* Functions
|
* Functions
|
||||||
@ -36,11 +36,24 @@ import { shareReplay, startWith } from "rxjs/operators"
|
|||||||
*/
|
*/
|
||||||
export function watchMedia(query: string): Observable<boolean> {
|
export function watchMedia(query: string): Observable<boolean> {
|
||||||
const media = matchMedia(query)
|
const media = matchMedia(query)
|
||||||
return new Observable<boolean>(subscriber => {
|
return fromEvent<MediaQueryListEvent>(media, "change")
|
||||||
media.addListener(ev => subscriber.next(ev.matches))
|
|
||||||
})
|
|
||||||
.pipe(
|
.pipe(
|
||||||
startWith(media.matches),
|
map(ev => ev.matches),
|
||||||
shareReplay({ bufferSize: 1, refCount: true })
|
startWith(media.matches)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Watch print mode, cross-browser
|
||||||
|
*
|
||||||
|
* @return Print observable
|
||||||
|
*/
|
||||||
|
export function watchPrint(): Observable<void> {
|
||||||
|
return merge(
|
||||||
|
watchMedia("print").pipe(filter(Boolean)), /* Webkit */
|
||||||
|
fromEvent(window, "beforeprint") /* IE, FF */
|
||||||
|
)
|
||||||
|
.pipe(
|
||||||
|
mapTo(undefined)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,7 @@ import {
|
|||||||
shareReplay
|
shareReplay
|
||||||
} from "rxjs/operators"
|
} from "rxjs/operators"
|
||||||
|
|
||||||
import { Header } from "components"
|
import { Header } from "~/components"
|
||||||
|
|
||||||
import {
|
import {
|
||||||
ViewportOffset,
|
ViewportOffset,
|
||||||
@ -58,8 +58,8 @@ export interface Viewport {
|
|||||||
* Watch at options
|
* Watch at options
|
||||||
*/
|
*/
|
||||||
interface WatchAtOptions {
|
interface WatchAtOptions {
|
||||||
header$: Observable<Header> /* Header observable */
|
|
||||||
viewport$: Observable<Viewport> /* Viewport observable */
|
viewport$: Observable<Viewport> /* Viewport observable */
|
||||||
|
header$: Observable<Header> /* Header observable */
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------------
|
/* ----------------------------------------------------------------------------
|
||||||
@ -78,7 +78,7 @@ export function watchViewport(): Observable<Viewport> {
|
|||||||
])
|
])
|
||||||
.pipe(
|
.pipe(
|
||||||
map(([offset, size]) => ({ offset, size })),
|
map(([offset, size]) => ({ offset, size })),
|
||||||
shareReplay({ bufferSize: 1, refCount: true })
|
shareReplay(1)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -91,7 +91,7 @@ export function watchViewport(): Observable<Viewport> {
|
|||||||
* @return Viewport observable
|
* @return Viewport observable
|
||||||
*/
|
*/
|
||||||
export function watchViewportAt(
|
export function watchViewportAt(
|
||||||
el: HTMLElement, { header$, viewport$ }: WatchAtOptions
|
el: HTMLElement, { viewport$, header$ }: WatchAtOptions
|
||||||
): Observable<Viewport> {
|
): Observable<Viewport> {
|
||||||
const size$ = viewport$
|
const size$ = viewport$
|
||||||
.pipe(
|
.pipe(
|
||||||
|
@ -20,17 +20,6 @@
|
|||||||
* IN THE SOFTWARE.
|
* IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { EMPTY, Observable, of } from "rxjs"
|
|
||||||
import {
|
|
||||||
distinctUntilChanged,
|
|
||||||
map,
|
|
||||||
scan,
|
|
||||||
shareReplay,
|
|
||||||
switchMap
|
|
||||||
} from "rxjs/operators"
|
|
||||||
|
|
||||||
import { getElement, replaceElement } from "browser"
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------------
|
/* ----------------------------------------------------------------------------
|
||||||
* Types
|
* Types
|
||||||
* ------------------------------------------------------------------------- */
|
* ------------------------------------------------------------------------- */
|
||||||
@ -38,130 +27,31 @@ import { getElement, replaceElement } from "browser"
|
|||||||
/**
|
/**
|
||||||
* Component
|
* Component
|
||||||
*/
|
*/
|
||||||
export type Component =
|
export type ComponentType =
|
||||||
| "announce" /* Announcement bar */
|
| "announce" /* Announcement bar */
|
||||||
| "container" /* Container */
|
| "container" /* Container */
|
||||||
|
| "content" /* Content */
|
||||||
| "header" /* Header */
|
| "header" /* Header */
|
||||||
| "header-title" /* Header title */
|
| "header-title" /* Header title */
|
||||||
| "main" /* Main area */
|
| "main" /* Main area */
|
||||||
| "navigation" /* Navigation */
|
|
||||||
| "search" /* Search */
|
| "search" /* Search */
|
||||||
| "search-query" /* Search input */
|
| "search-query" /* Search input */
|
||||||
| "search-reset" /* Search reset */
|
|
||||||
| "search-result" /* Search results */
|
| "search-result" /* Search results */
|
||||||
| "skip" /* Skip link */
|
| "skip" /* Skip link */
|
||||||
| "tabs" /* Tabs */
|
| "source" /* Repository information */
|
||||||
|
| "tabs" /* Navigation tabs */
|
||||||
| "toc" /* Table of contents */
|
| "toc" /* Table of contents */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Component map
|
* A component
|
||||||
|
*
|
||||||
|
* @template T - Component type
|
||||||
|
* @template U - Reference type
|
||||||
*/
|
*/
|
||||||
export type ComponentMap = {
|
export type Component<
|
||||||
[P in Component]?: HTMLElement
|
T extends {} = {},
|
||||||
}
|
U extends HTMLElement = HTMLElement
|
||||||
|
> =
|
||||||
/* ----------------------------------------------------------------------------
|
T & {
|
||||||
* Helper types
|
ref: U /* Component reference */
|
||||||
* ------------------------------------------------------------------------- */
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Watch options
|
|
||||||
*/
|
|
||||||
interface WatchOptions {
|
|
||||||
document$: Observable<Document> /* Document observable */
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------------
|
|
||||||
* Data
|
|
||||||
* ------------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Component map observable
|
|
||||||
*/
|
|
||||||
let components$: Observable<ComponentMap>
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------------
|
|
||||||
* Functions
|
|
||||||
* ------------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set up bindings to components with given names
|
|
||||||
*
|
|
||||||
* This function will maintain bindings to the elements identified by the given
|
|
||||||
* names in-between document switches and update the elements in-place.
|
|
||||||
*
|
|
||||||
* @param names - Component names
|
|
||||||
* @param options - Options
|
|
||||||
*/
|
|
||||||
export function setupComponents(
|
|
||||||
names: Component[], { document$ }: WatchOptions
|
|
||||||
): void {
|
|
||||||
components$ = document$
|
|
||||||
.pipe(
|
|
||||||
|
|
||||||
/* Build component map */
|
|
||||||
map(document => names.reduce<ComponentMap>((components, name) => {
|
|
||||||
const el = getElement(`[data-md-component=${name}]`, document)
|
|
||||||
return {
|
|
||||||
...components,
|
|
||||||
...typeof el !== "undefined" ? { [name]: el } : {}
|
|
||||||
}
|
|
||||||
}, {})),
|
|
||||||
|
|
||||||
/* Re-compute component map on document switch */
|
|
||||||
scan((prev, next) => {
|
|
||||||
for (const name of names) {
|
|
||||||
switch (name) {
|
|
||||||
|
|
||||||
/* Top-level components: update */
|
|
||||||
case "announce":
|
|
||||||
case "header-title":
|
|
||||||
case "container":
|
|
||||||
case "skip":
|
|
||||||
if (name in prev && typeof prev[name] !== "undefined") {
|
|
||||||
replaceElement(prev[name]!, next[name]!)
|
|
||||||
prev[name] = next[name]
|
|
||||||
}
|
|
||||||
break
|
|
||||||
|
|
||||||
/* All other components: rebind */
|
|
||||||
default:
|
|
||||||
if (typeof next[name] !== "undefined")
|
|
||||||
prev[name] = getElement(`[data-md-component=${name}]`)
|
|
||||||
else
|
|
||||||
delete prev[name]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return prev
|
|
||||||
}),
|
|
||||||
|
|
||||||
/* Convert to hot observable */
|
|
||||||
shareReplay({ bufferSize: 1, refCount: true })
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Retrieve a component
|
|
||||||
*
|
|
||||||
* The returned observable will only re-emit if the element changed, i.e. if
|
|
||||||
* it was replaced from a document which was switched to.
|
|
||||||
*
|
|
||||||
* @template T - Element type
|
|
||||||
*
|
|
||||||
* @param name - Component name
|
|
||||||
*
|
|
||||||
* @return Component observable
|
|
||||||
*/
|
|
||||||
export function useComponent<T extends HTMLElement>(
|
|
||||||
name: Component
|
|
||||||
): Observable<T> {
|
|
||||||
return components$
|
|
||||||
.pipe(
|
|
||||||
switchMap(components => (
|
|
||||||
typeof components[name] !== "undefined"
|
|
||||||
? of(components[name] as T)
|
|
||||||
: EMPTY
|
|
||||||
)),
|
|
||||||
distinctUntilChanged()
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
@ -20,28 +20,26 @@
|
|||||||
* IN THE SOFTWARE.
|
* IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { Observable, OperatorFunction, of, pipe } from "rxjs"
|
import { Observable, merge } from "rxjs"
|
||||||
import {
|
|
||||||
distinctUntilKeyChanged,
|
|
||||||
map,
|
|
||||||
switchMap
|
|
||||||
} from "rxjs/operators"
|
|
||||||
|
|
||||||
import { Viewport, watchViewportAt } from "browser"
|
import { getElements, Viewport } from "~/browser"
|
||||||
|
|
||||||
import { Header } from "../../header"
|
import { Component } from "../../_"
|
||||||
import { applyTabs } from "../react"
|
import { CodeBlock, mountCodeBlock } from "../code"
|
||||||
|
import { Details, mountDetails } from "../details"
|
||||||
|
import { DataTable, mountDataTable } from "../table"
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------------
|
/* ----------------------------------------------------------------------------
|
||||||
* Types
|
* Types
|
||||||
* ------------------------------------------------------------------------- */
|
* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tabs
|
* Content
|
||||||
*/
|
*/
|
||||||
export interface Tabs {
|
export type Content =
|
||||||
hidden: boolean /* Whether the tabs are hidden */
|
| CodeBlock
|
||||||
}
|
| DataTable
|
||||||
|
| Details
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------------
|
/* ----------------------------------------------------------------------------
|
||||||
* Helper types
|
* Helper types
|
||||||
@ -51,9 +49,9 @@ export interface Tabs {
|
|||||||
* Mount options
|
* Mount options
|
||||||
*/
|
*/
|
||||||
interface MountOptions {
|
interface MountOptions {
|
||||||
header$: Observable<Header> /* Header observable */
|
target$: Observable<HTMLElement> /* Location target observable */
|
||||||
viewport$: Observable<Viewport> /* Viewport observable */
|
viewport$: Observable<Viewport> /* Viewport observable */
|
||||||
screen$: Observable<boolean> /* Media screen observable */
|
print$: Observable<void> /* Print observable */
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------------
|
/* ----------------------------------------------------------------------------
|
||||||
@ -61,35 +59,28 @@ interface MountOptions {
|
|||||||
* ------------------------------------------------------------------------- */
|
* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mount tabs from source observable
|
* Mount content
|
||||||
*
|
*
|
||||||
|
* @param el - Content element
|
||||||
* @param options - Options
|
* @param options - Options
|
||||||
*
|
*
|
||||||
* @return Operator function
|
* @return Content component observable
|
||||||
*/
|
*/
|
||||||
export function mountTabs(
|
export function mountContent(
|
||||||
{ header$, viewport$, screen$ }: MountOptions
|
el: HTMLElement, { target$, viewport$, print$ }: MountOptions
|
||||||
): OperatorFunction<HTMLElement, Tabs> {
|
): Observable<Component<Content>> {
|
||||||
return pipe(
|
return merge(
|
||||||
switchMap(el => screen$
|
|
||||||
.pipe(
|
|
||||||
switchMap(screen => {
|
|
||||||
|
|
||||||
/* [screen +]: Mount tabs above screen breakpoint */
|
/* Code blocks */
|
||||||
if (screen) {
|
...getElements("pre > code", el)
|
||||||
return watchViewportAt(el, { header$, viewport$ })
|
.map(child => mountCodeBlock(child, { viewport$ })),
|
||||||
.pipe(
|
|
||||||
map(({ offset: { y } }) => ({ hidden: y >= 10 })),
|
|
||||||
distinctUntilKeyChanged("hidden"),
|
|
||||||
applyTabs(el)
|
|
||||||
)
|
|
||||||
|
|
||||||
/* [screen -]: Unmount tabs below screen breakpoint */
|
/* Data tables */
|
||||||
} else {
|
...getElements("table:not([class])", el)
|
||||||
return of({ hidden: true })
|
.map(child => mountDataTable(child)),
|
||||||
}
|
|
||||||
})
|
/* Details */
|
||||||
)
|
...getElements("details", el)
|
||||||
)
|
.map(child => mountDetails(child, { target$, print$ }))
|
||||||
)
|
)
|
||||||
}
|
}
|
154
src/assets/javascripts/components/content/code/index.ts
Normal file
154
src/assets/javascripts/components/content/code/index.ts
Normal file
@ -0,0 +1,154 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016-2020 Martin Donath <martin.donath@squidfunk.com>
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to
|
||||||
|
* deal in the Software without restriction, including without limitation the
|
||||||
|
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||||
|
* sell copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||||
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||||
|
* IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import ClipboardJS from "clipboard"
|
||||||
|
import { Observable, Subject } from "rxjs"
|
||||||
|
import {
|
||||||
|
distinctUntilKeyChanged,
|
||||||
|
finalize,
|
||||||
|
map,
|
||||||
|
tap,
|
||||||
|
withLatestFrom
|
||||||
|
} from "rxjs/operators"
|
||||||
|
|
||||||
|
import { resetFocusable, setFocusable } from "~/actions"
|
||||||
|
import {
|
||||||
|
getElementContentSize,
|
||||||
|
getElementSize,
|
||||||
|
Viewport,
|
||||||
|
watchMedia
|
||||||
|
} from "~/browser"
|
||||||
|
import { renderClipboardButton } from "~/templates"
|
||||||
|
|
||||||
|
import { Component } from "../../_"
|
||||||
|
|
||||||
|
/* ----------------------------------------------------------------------------
|
||||||
|
* Types
|
||||||
|
* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Code block
|
||||||
|
*/
|
||||||
|
export interface CodeBlock {
|
||||||
|
scroll: boolean /* Code block overflows */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ----------------------------------------------------------------------------
|
||||||
|
* Helper types
|
||||||
|
* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Watch options
|
||||||
|
*/
|
||||||
|
interface WatchOptions {
|
||||||
|
viewport$: Observable<Viewport> /* Viewport observable */
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mount options
|
||||||
|
*/
|
||||||
|
interface MountOptions {
|
||||||
|
viewport$: Observable<Viewport> /* Viewport observable */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ----------------------------------------------------------------------------
|
||||||
|
* Data
|
||||||
|
* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Global index for Clipboard.js integration
|
||||||
|
*/
|
||||||
|
let index = 0
|
||||||
|
|
||||||
|
/* ----------------------------------------------------------------------------
|
||||||
|
* Functions
|
||||||
|
* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Watch code block
|
||||||
|
*
|
||||||
|
* @param el - Code block element
|
||||||
|
* @param options - Options
|
||||||
|
*
|
||||||
|
* @return Code block observable
|
||||||
|
*/
|
||||||
|
export function watchCodeBlock(
|
||||||
|
el: HTMLElement, { viewport$ }: WatchOptions
|
||||||
|
): Observable<CodeBlock> {
|
||||||
|
return viewport$
|
||||||
|
.pipe(
|
||||||
|
distinctUntilKeyChanged("size"),
|
||||||
|
map(() => {
|
||||||
|
const visible = getElementSize(el)
|
||||||
|
const content = getElementContentSize(el)
|
||||||
|
return {
|
||||||
|
scroll: content.width > visible.width
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
distinctUntilKeyChanged("scroll")
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mount code block
|
||||||
|
*
|
||||||
|
* This function ensures that overflowing code blocks are focusable by keyboard,
|
||||||
|
* so they can be scrolled without a mouse to improve on accessibility.
|
||||||
|
*
|
||||||
|
* @param el - Code block element
|
||||||
|
* @param options - Options
|
||||||
|
*
|
||||||
|
* @return Code block component observable
|
||||||
|
*/
|
||||||
|
export function mountCodeBlock(
|
||||||
|
el: HTMLElement, options: MountOptions
|
||||||
|
): Observable<Component<CodeBlock>> {
|
||||||
|
const internal$ = new Subject<CodeBlock>()
|
||||||
|
internal$
|
||||||
|
.pipe(
|
||||||
|
withLatestFrom(watchMedia("(hover)"))
|
||||||
|
)
|
||||||
|
.subscribe(([{ scroll }, hover]) => {
|
||||||
|
if (scroll && hover)
|
||||||
|
setFocusable(el)
|
||||||
|
else
|
||||||
|
resetFocusable(el)
|
||||||
|
})
|
||||||
|
|
||||||
|
/* Inject button for Clipboard.js integration */
|
||||||
|
if (ClipboardJS.isSupported()) {
|
||||||
|
const parent = el.closest("pre")!
|
||||||
|
parent.id = `__code_${index++}`
|
||||||
|
parent.insertBefore(
|
||||||
|
renderClipboardButton(parent.id),
|
||||||
|
el
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Create and return component */
|
||||||
|
return watchCodeBlock(el, options)
|
||||||
|
.pipe(
|
||||||
|
tap(internal$),
|
||||||
|
finalize(() => internal$.complete()),
|
||||||
|
map(state => ({ ref: el, ...state }))
|
||||||
|
)
|
||||||
|
}
|
@ -20,47 +20,45 @@
|
|||||||
* IN THE SOFTWARE.
|
* IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { OperatorFunction, pipe } from "rxjs"
|
import { Observable, Subject } from "rxjs"
|
||||||
import {
|
import {
|
||||||
distinctUntilKeyChanged,
|
filter,
|
||||||
|
finalize,
|
||||||
map,
|
map,
|
||||||
switchMap
|
mapTo,
|
||||||
|
mergeWith,
|
||||||
|
tap
|
||||||
} from "rxjs/operators"
|
} from "rxjs/operators"
|
||||||
|
|
||||||
import { WorkerHandler, setToggle } from "browser"
|
import { Component } from "../../_"
|
||||||
import {
|
|
||||||
SearchMessage,
|
|
||||||
SearchMessageType,
|
|
||||||
SearchQueryMessage,
|
|
||||||
SearchTransformFn
|
|
||||||
} from "integrations"
|
|
||||||
|
|
||||||
import {
|
|
||||||
applySearchQuery,
|
|
||||||
watchSearchQuery
|
|
||||||
} from "../react"
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------------
|
/* ----------------------------------------------------------------------------
|
||||||
* Types
|
* Types
|
||||||
* ------------------------------------------------------------------------- */
|
* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Search query
|
* Details
|
||||||
*/
|
*/
|
||||||
export interface SearchQuery {
|
export interface Details {}
|
||||||
value: string /* Query value */
|
|
||||||
focus: boolean /* Query focus */
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------------
|
/* ----------------------------------------------------------------------------
|
||||||
* Helper types
|
* Helper types
|
||||||
* ------------------------------------------------------------------------- */
|
* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Watch options
|
||||||
|
*/
|
||||||
|
interface WatchOptions {
|
||||||
|
target$: Observable<HTMLElement> /* Location target observable */
|
||||||
|
print$: Observable<void> /* Print observable */
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mount options
|
* Mount options
|
||||||
*/
|
*/
|
||||||
interface MountOptions {
|
interface MountOptions {
|
||||||
transform?: SearchTransformFn /* Transformation function */
|
target$: Observable<HTMLElement> /* Location target observable */
|
||||||
|
print$: Observable<void> /* Print observable */
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------------
|
/* ----------------------------------------------------------------------------
|
||||||
@ -68,46 +66,50 @@ interface MountOptions {
|
|||||||
* ------------------------------------------------------------------------- */
|
* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mount search query from source observable
|
* Watch details
|
||||||
*
|
*
|
||||||
* @param handler - Worker handler
|
* @param el - Details element
|
||||||
* @param options - Options
|
* @param options - Options
|
||||||
*
|
*
|
||||||
* @return Operator function
|
* @return Details observable
|
||||||
*/
|
*/
|
||||||
export function mountSearchQuery(
|
export function watchDetails(
|
||||||
{ tx$ }: WorkerHandler<SearchMessage>, options: MountOptions = {}
|
el: HTMLDetailsElement, { target$, print$ }: WatchOptions
|
||||||
): OperatorFunction<HTMLInputElement, SearchQuery> {
|
): Observable<Details> {
|
||||||
return pipe(
|
return target$
|
||||||
switchMap(el => {
|
.pipe(
|
||||||
const query$ = watchSearchQuery(el, options)
|
map(target => target.closest("details:not([open])")!),
|
||||||
|
filter(details => el === details),
|
||||||
/* Subscribe worker to search query */
|
mergeWith(print$),
|
||||||
query$
|
mapTo(el)
|
||||||
.pipe(
|
)
|
||||||
distinctUntilKeyChanged("value"),
|
}
|
||||||
map(({ value }): SearchQueryMessage => ({
|
|
||||||
type: SearchMessageType.QUERY,
|
/**
|
||||||
data: value
|
* Mount details
|
||||||
}))
|
*
|
||||||
)
|
* This function ensures that `details` tags are opened prior to printing, so
|
||||||
.subscribe(tx$.next.bind(tx$))
|
* the whole content of the page is included and on anchor jumps.
|
||||||
|
*
|
||||||
/* Toggle search on focus */
|
* @param el - Details element
|
||||||
query$
|
* @param options - Options
|
||||||
.pipe(
|
*
|
||||||
distinctUntilKeyChanged("focus")
|
* @return Details component observable
|
||||||
)
|
*/
|
||||||
.subscribe(({ focus }) => {
|
export function mountDetails(
|
||||||
if (focus)
|
el: HTMLDetailsElement, options: MountOptions
|
||||||
setToggle("search", focus)
|
): Observable<Component<Details>> {
|
||||||
})
|
const internal$ = new Subject<Details>()
|
||||||
|
internal$.subscribe(() => {
|
||||||
/* Return search query */
|
el.setAttribute("open", "")
|
||||||
return query$
|
el.scrollIntoView()
|
||||||
.pipe(
|
})
|
||||||
applySearchQuery(el)
|
|
||||||
)
|
/* Create and return component */
|
||||||
})
|
return watchDetails(el, options)
|
||||||
)
|
.pipe(
|
||||||
|
tap(internal$),
|
||||||
|
finalize(() => internal$.complete()),
|
||||||
|
mapTo({ ref: el })
|
||||||
|
)
|
||||||
}
|
}
|
@ -21,5 +21,5 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
export * from "./_"
|
export * from "./_"
|
||||||
export * from "./react"
|
export * from "./code"
|
||||||
export * from "./set"
|
export * from "./table"
|
@ -20,51 +20,48 @@
|
|||||||
* IN THE SOFTWARE.
|
* IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { Observable } from "rxjs"
|
import { Observable, of } from "rxjs"
|
||||||
import { map } from "rxjs/operators"
|
|
||||||
|
|
||||||
import {
|
import { createElement, replaceElement } from "~/browser"
|
||||||
createElement,
|
import { renderTable } from "~/templates"
|
||||||
getElements,
|
|
||||||
replaceElement
|
import { Component } from "../../_"
|
||||||
} from "browser"
|
|
||||||
import { renderTable } from "templates"
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------------
|
/* ----------------------------------------------------------------------------
|
||||||
* Helper types
|
* Types
|
||||||
* ------------------------------------------------------------------------- */
|
* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mount options
|
* Data table
|
||||||
*/
|
*/
|
||||||
interface MountOptions {
|
export interface DataTable {}
|
||||||
document$: Observable<Document> /* Document observable */
|
|
||||||
}
|
/* ----------------------------------------------------------------------------
|
||||||
|
* Data
|
||||||
|
* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sentinel for replacement
|
||||||
|
*/
|
||||||
|
const sentinel = createElement("table")
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------------
|
/* ----------------------------------------------------------------------------
|
||||||
* Functions
|
* Functions
|
||||||
* ------------------------------------------------------------------------- */
|
* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Patch all `table` elements
|
* Mount data table
|
||||||
*
|
*
|
||||||
* This function will re-render all tables by wrapping them to improve overflow
|
* @param el - Data table element
|
||||||
* scrolling on smaller screen sizes.
|
|
||||||
*
|
*
|
||||||
* @param options - Options
|
* @return Data table component observable
|
||||||
*/
|
*/
|
||||||
export function patchTables(
|
export function mountDataTable(
|
||||||
{ document$ }: MountOptions
|
el: HTMLElement
|
||||||
): void {
|
): Observable<Component<DataTable>> {
|
||||||
const sentinel = createElement("table")
|
replaceElement(el, sentinel)
|
||||||
document$
|
replaceElement(sentinel, renderTable(el))
|
||||||
.pipe(
|
|
||||||
map(() => getElements<HTMLTableElement>("table:not([class])"))
|
/* Create and return component */
|
||||||
)
|
return of({ ref: el })
|
||||||
.subscribe(els => {
|
|
||||||
for (const el of els) {
|
|
||||||
replaceElement(el, sentinel)
|
|
||||||
replaceElement(sentinel, renderTable(el))
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
@ -22,50 +22,56 @@
|
|||||||
|
|
||||||
import {
|
import {
|
||||||
Observable,
|
Observable,
|
||||||
OperatorFunction,
|
|
||||||
Subject,
|
Subject,
|
||||||
noop,
|
merge,
|
||||||
pipe
|
animationFrameScheduler,
|
||||||
|
of
|
||||||
} from "rxjs"
|
} from "rxjs"
|
||||||
import {
|
import {
|
||||||
distinctUntilKeyChanged,
|
delay,
|
||||||
finalize,
|
finalize,
|
||||||
|
map,
|
||||||
|
observeOn,
|
||||||
switchMap,
|
switchMap,
|
||||||
tap
|
tap
|
||||||
} from "rxjs/operators"
|
} from "rxjs/operators"
|
||||||
|
|
||||||
import { Viewport } from "browser"
|
|
||||||
|
|
||||||
import { useComponent } from "../../_"
|
|
||||||
import { Header } from "../../header"
|
|
||||||
import {
|
import {
|
||||||
applyHeaderShadow,
|
resetDialogState,
|
||||||
watchMain
|
setDialogMessage,
|
||||||
} from "../react"
|
setDialogState
|
||||||
|
} from "~/actions"
|
||||||
|
|
||||||
|
import { Component } from "../_"
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------------
|
/* ----------------------------------------------------------------------------
|
||||||
* Types
|
* Types
|
||||||
* ------------------------------------------------------------------------- */
|
* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Main area
|
* Dialog
|
||||||
*/
|
*/
|
||||||
export interface Main {
|
export interface Dialog {
|
||||||
offset: number /* Main area top offset */
|
message: string /* Dialog message */
|
||||||
height: number /* Main area visible height */
|
open: boolean /* Dialog is visible */
|
||||||
active: boolean /* Scrolled past top offset */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------------
|
/* ----------------------------------------------------------------------------
|
||||||
* Helper types
|
* Helper types
|
||||||
* ------------------------------------------------------------------------- */
|
* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Watch options
|
||||||
|
*/
|
||||||
|
interface WatchOptions {
|
||||||
|
message$: Subject<string> /* Message subject */
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mount options
|
* Mount options
|
||||||
*/
|
*/
|
||||||
interface MountOptions {
|
interface MountOptions {
|
||||||
header$: Observable<Header> /* Header observable */
|
message$: Subject<string> /* Message subject */
|
||||||
viewport$: Observable<Viewport> /* Viewport observable */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------------
|
/* ----------------------------------------------------------------------------
|
||||||
@ -73,38 +79,59 @@ interface MountOptions {
|
|||||||
* ------------------------------------------------------------------------- */
|
* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mount main area from source observable
|
* Watch dialog
|
||||||
*
|
|
||||||
* The header must be connected to the main area observable outside of the
|
|
||||||
* operator function, as the header will persist in-between document switches
|
|
||||||
* while the main area is replaced. However, the header observable must be
|
|
||||||
* passed to this function, so we connect both via a long-living subject.
|
|
||||||
*
|
*
|
||||||
|
* @param el - Dialog element
|
||||||
* @param options - Options
|
* @param options - Options
|
||||||
*
|
*
|
||||||
* @return Operator function
|
* @return Dialog observable
|
||||||
*/
|
*/
|
||||||
export function mountMain(
|
export function watchDialog(
|
||||||
{ header$, viewport$ }: MountOptions
|
_el: HTMLElement, { message$ }: WatchOptions
|
||||||
): OperatorFunction<HTMLElement, Main> {
|
): Observable<Dialog> {
|
||||||
const main$ = new Subject<Main>()
|
return message$
|
||||||
|
|
||||||
/* Connect to main area observable via long-living subject */
|
|
||||||
useComponent("header")
|
|
||||||
.pipe(
|
.pipe(
|
||||||
switchMap(header => main$
|
switchMap(message => merge(
|
||||||
|
of(true),
|
||||||
|
of(false).pipe(delay(2000))
|
||||||
|
)
|
||||||
.pipe(
|
.pipe(
|
||||||
distinctUntilKeyChanged("active"),
|
map(open => ({ message, open }))
|
||||||
applyHeaderShadow(header)
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
.subscribe(noop)
|
}
|
||||||
|
|
||||||
/* Return operator */
|
|
||||||
return pipe(
|
/**
|
||||||
switchMap(el => watchMain(el, { header$, viewport$ })),
|
* Mount dialog
|
||||||
tap(main => main$.next(main)),
|
*
|
||||||
finalize(() => main$.complete())
|
* @param el - Dialog element
|
||||||
)
|
* @param options - Options
|
||||||
|
*
|
||||||
|
* @return Dialog component observable
|
||||||
|
*/
|
||||||
|
export function mountDialog(
|
||||||
|
el: HTMLElement, { message$ }: MountOptions
|
||||||
|
): Observable<Component<Dialog>> {
|
||||||
|
const internal$ = new Subject<Dialog>()
|
||||||
|
internal$
|
||||||
|
.pipe(
|
||||||
|
observeOn(animationFrameScheduler)
|
||||||
|
)
|
||||||
|
.subscribe(({ message, open }) => {
|
||||||
|
setDialogMessage(el, message)
|
||||||
|
if (open)
|
||||||
|
setDialogState(el, "open")
|
||||||
|
else
|
||||||
|
resetDialogState(el)
|
||||||
|
})
|
||||||
|
|
||||||
|
/* Create and return component */
|
||||||
|
return watchDialog(el, { message$ })
|
||||||
|
.pipe(
|
||||||
|
tap(internal$),
|
||||||
|
finalize(() => internal$.complete()),
|
||||||
|
map(state => ({ ref: el, ...state }))
|
||||||
|
)
|
||||||
}
|
}
|
@ -20,46 +20,30 @@
|
|||||||
* IN THE SOFTWARE.
|
* IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { Observable, OperatorFunction, combineLatest, pipe } from "rxjs"
|
import { Observable, defer, of, Subject, animationFrameScheduler } from "rxjs"
|
||||||
import {
|
import {
|
||||||
|
combineLatestWith,
|
||||||
distinctUntilChanged,
|
distinctUntilChanged,
|
||||||
filter,
|
distinctUntilKeyChanged,
|
||||||
map,
|
map,
|
||||||
startWith,
|
observeOn,
|
||||||
switchMap,
|
shareReplay
|
||||||
zipWith
|
|
||||||
} from "rxjs/operators"
|
} from "rxjs/operators"
|
||||||
|
|
||||||
import {
|
import { resetHeaderState, setHeaderState } from "~/actions"
|
||||||
Viewport,
|
import { Viewport, watchElementSize } from "~/browser"
|
||||||
getElement,
|
|
||||||
watchViewportAt
|
|
||||||
} from "browser"
|
|
||||||
|
|
||||||
import { useComponent } from "../../_"
|
import { Component } from "../../_"
|
||||||
import {
|
import { Main } from "../../main"
|
||||||
applyHeaderType,
|
|
||||||
watchHeader
|
|
||||||
} from "../react"
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------------
|
/* ----------------------------------------------------------------------------
|
||||||
* Types
|
* Types
|
||||||
* ------------------------------------------------------------------------- */
|
* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
/**
|
|
||||||
* Header type
|
|
||||||
*/
|
|
||||||
export type HeaderType =
|
|
||||||
| "site" /* Header shows site title */
|
|
||||||
| "page" /* Header shows page title */
|
|
||||||
|
|
||||||
/* ------------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Header
|
* Header
|
||||||
*/
|
*/
|
||||||
export interface Header {
|
export interface Header {
|
||||||
type: HeaderType /* Header type */
|
|
||||||
sticky: boolean /* Header stickyness */
|
sticky: boolean /* Header stickyness */
|
||||||
height: number /* Header visible height */
|
height: number /* Header visible height */
|
||||||
}
|
}
|
||||||
@ -72,8 +56,9 @@ export interface Header {
|
|||||||
* Mount options
|
* Mount options
|
||||||
*/
|
*/
|
||||||
interface MountOptions {
|
interface MountOptions {
|
||||||
document$: Observable<Document> /* Document observable */
|
|
||||||
viewport$: Observable<Viewport> /* Viewport observable */
|
viewport$: Observable<Viewport> /* Viewport observable */
|
||||||
|
header$: Observable<Header> /* Header observable */
|
||||||
|
main$: Observable<Main> /* Main area observable */
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------------
|
/* ----------------------------------------------------------------------------
|
||||||
@ -81,42 +66,69 @@ interface MountOptions {
|
|||||||
* ------------------------------------------------------------------------- */
|
* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mount header from source observable
|
* Watch header
|
||||||
*
|
*
|
||||||
|
* @param el - Header element
|
||||||
|
*
|
||||||
|
* @return Header observable
|
||||||
|
*/
|
||||||
|
export function watchHeader(
|
||||||
|
el: HTMLElement
|
||||||
|
): Observable<Header> {
|
||||||
|
return defer(() => {
|
||||||
|
const styles = getComputedStyle(el)
|
||||||
|
return of(
|
||||||
|
styles.position === "sticky" ||
|
||||||
|
styles.position === "-webkit-sticky"
|
||||||
|
)
|
||||||
|
})
|
||||||
|
.pipe(
|
||||||
|
combineLatestWith(watchElementSize(el)),
|
||||||
|
map(([sticky, { height }]) => ({
|
||||||
|
sticky,
|
||||||
|
height: sticky ? height : 0
|
||||||
|
})),
|
||||||
|
distinctUntilChanged((a, b) => (
|
||||||
|
a.sticky === b.sticky &&
|
||||||
|
a.height === b.height
|
||||||
|
))
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mount header
|
||||||
|
*
|
||||||
|
* The header must be connected to the main area observable outside of the
|
||||||
|
* operator function, as the header will persist in-between document switches
|
||||||
|
* while the main area is replaced. However, the header observable must be
|
||||||
|
* passed to this function, so we connect both via a long-living subject.
|
||||||
|
*
|
||||||
|
* @param el - Header element
|
||||||
* @param options - Options
|
* @param options - Options
|
||||||
*
|
*
|
||||||
* @return Operator function
|
* @return Header component observable
|
||||||
*/
|
*/
|
||||||
export function mountHeader(
|
export function mountHeader(
|
||||||
{ document$, viewport$ }: MountOptions
|
el: HTMLElement, { header$, main$ }: MountOptions
|
||||||
): OperatorFunction<HTMLElement, Header> {
|
): Observable<Component<Header>> {
|
||||||
return pipe(
|
const internal$ = new Subject<Main>()
|
||||||
switchMap(el => {
|
internal$
|
||||||
const header$ = watchHeader(el, { document$ })
|
.pipe(
|
||||||
|
distinctUntilKeyChanged("active"),
|
||||||
|
observeOn(animationFrameScheduler)
|
||||||
|
)
|
||||||
|
.subscribe(({ active }) => {
|
||||||
|
if (active)
|
||||||
|
setHeaderState(el, "shadow")
|
||||||
|
else
|
||||||
|
resetHeaderState(el)
|
||||||
|
})
|
||||||
|
|
||||||
/* Compute whether the header should switch to page header */
|
/* Connect to long-living subject and return component */
|
||||||
const type$ = useComponent("main")
|
main$.subscribe(main => internal$.next(main))
|
||||||
.pipe(
|
return header$
|
||||||
map(main => getElement("h1, h2, h3, h4, h5, h6", main)!),
|
.pipe(
|
||||||
filter(hx => typeof hx !== "undefined"),
|
map(state => ({ ref: el, ...state })),
|
||||||
zipWith(useComponent("header-title")),
|
shareReplay(1)
|
||||||
switchMap(([hx, title]) => watchViewportAt(hx, { header$, viewport$ })
|
)
|
||||||
.pipe(
|
|
||||||
map(({ offset: { y } }) => {
|
|
||||||
return y >= hx.offsetHeight ? "page" : "site"
|
|
||||||
}),
|
|
||||||
distinctUntilChanged(),
|
|
||||||
applyHeaderType(title)
|
|
||||||
)
|
|
||||||
),
|
|
||||||
startWith<HeaderType>("site")
|
|
||||||
)
|
|
||||||
|
|
||||||
/* Combine into single observable */
|
|
||||||
return combineLatest([header$, type$])
|
|
||||||
.pipe(
|
|
||||||
map(([header, type]): Header => ({ type, ...header }))
|
|
||||||
)
|
|
||||||
})
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
@ -21,5 +21,4 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
export * from "./_"
|
export * from "./_"
|
||||||
export * from "./react"
|
export * from "./title"
|
||||||
export * from "./set"
|
|
||||||
|
@ -1,128 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2016-2020 Martin Donath <martin.donath@squidfunk.com>
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to
|
|
||||||
* deal in the Software without restriction, including without limitation the
|
|
||||||
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
|
||||||
* sell copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in
|
|
||||||
* all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
||||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
|
||||||
* IN THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import {
|
|
||||||
MonoTypeOperatorFunction,
|
|
||||||
Observable,
|
|
||||||
animationFrameScheduler,
|
|
||||||
of,
|
|
||||||
pipe
|
|
||||||
} from "rxjs"
|
|
||||||
import {
|
|
||||||
distinctUntilChanged,
|
|
||||||
finalize,
|
|
||||||
map,
|
|
||||||
observeOn,
|
|
||||||
shareReplay,
|
|
||||||
switchMap,
|
|
||||||
tap
|
|
||||||
} from "rxjs/operators"
|
|
||||||
|
|
||||||
import { watchElementSize } from "browser"
|
|
||||||
|
|
||||||
import { Header, HeaderType } from "../_"
|
|
||||||
import {
|
|
||||||
resetHeaderTitleActive,
|
|
||||||
setHeaderTitleActive
|
|
||||||
} from "../set"
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------------
|
|
||||||
* Helper types
|
|
||||||
* ------------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Watch options
|
|
||||||
*/
|
|
||||||
interface WatchOptions {
|
|
||||||
document$: Observable<Document> /* Document observable */
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------------
|
|
||||||
* Functions
|
|
||||||
* ------------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Watch header
|
|
||||||
*
|
|
||||||
* @param el - Header element
|
|
||||||
*
|
|
||||||
* @return Header observable
|
|
||||||
*/
|
|
||||||
export function watchHeader(
|
|
||||||
el: HTMLElement, { document$ }: WatchOptions
|
|
||||||
): Observable<Omit<Header, "type">> {
|
|
||||||
return document$
|
|
||||||
.pipe(
|
|
||||||
map(() => {
|
|
||||||
const styles = getComputedStyle(el)
|
|
||||||
return [
|
|
||||||
"sticky", /* Modern browsers */
|
|
||||||
"-webkit-sticky" /* Safari */
|
|
||||||
].includes(styles.position)
|
|
||||||
}),
|
|
||||||
distinctUntilChanged(),
|
|
||||||
switchMap(sticky => {
|
|
||||||
if (sticky) {
|
|
||||||
return watchElementSize(el)
|
|
||||||
.pipe(
|
|
||||||
map(({ height }) => ({
|
|
||||||
sticky: true,
|
|
||||||
height
|
|
||||||
}))
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
return of({
|
|
||||||
sticky: false,
|
|
||||||
height: 0
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}),
|
|
||||||
shareReplay({ bufferSize: 1, refCount: true })
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ------------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Apply header title type
|
|
||||||
*
|
|
||||||
* @param el - Header title element
|
|
||||||
*
|
|
||||||
* @return Operator function
|
|
||||||
*/
|
|
||||||
export function applyHeaderType(
|
|
||||||
el: HTMLElement
|
|
||||||
): MonoTypeOperatorFunction<HeaderType> {
|
|
||||||
return pipe(
|
|
||||||
|
|
||||||
/* Defer repaint to next animation frame */
|
|
||||||
observeOn(animationFrameScheduler),
|
|
||||||
tap(type => {
|
|
||||||
setHeaderTitleActive(el, type === "page")
|
|
||||||
}),
|
|
||||||
|
|
||||||
/* Reset on complete or error */
|
|
||||||
finalize(() => {
|
|
||||||
resetHeaderTitleActive(el)
|
|
||||||
})
|
|
||||||
)
|
|
||||||
}
|
|
135
src/assets/javascripts/components/header/title/index.ts
Normal file
135
src/assets/javascripts/components/header/title/index.ts
Normal file
@ -0,0 +1,135 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016-2020 Martin Donath <martin.donath@squidfunk.com>
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to
|
||||||
|
* deal in the Software without restriction, including without limitation the
|
||||||
|
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||||
|
* sell copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||||
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||||
|
* IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { Observable, animationFrameScheduler, Subject } from "rxjs"
|
||||||
|
import {
|
||||||
|
distinctUntilKeyChanged,
|
||||||
|
finalize,
|
||||||
|
map,
|
||||||
|
observeOn,
|
||||||
|
tap
|
||||||
|
} from "rxjs/operators"
|
||||||
|
|
||||||
|
import {
|
||||||
|
resetHeaderTitleState,
|
||||||
|
setHeaderTitleState
|
||||||
|
} from "~/actions"
|
||||||
|
import {
|
||||||
|
Viewport,
|
||||||
|
getElementOrThrow,
|
||||||
|
getElementSize,
|
||||||
|
watchViewportAt
|
||||||
|
} from "~/browser"
|
||||||
|
|
||||||
|
import { Component } from "../../_"
|
||||||
|
import { Header } from "../_"
|
||||||
|
|
||||||
|
/* ----------------------------------------------------------------------------
|
||||||
|
* Types
|
||||||
|
* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Header
|
||||||
|
*/
|
||||||
|
export interface HeaderTitle {
|
||||||
|
active: boolean /* User scrolled past first headline */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ----------------------------------------------------------------------------
|
||||||
|
* Helper types
|
||||||
|
* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Watch options
|
||||||
|
*/
|
||||||
|
interface WatchOptions {
|
||||||
|
viewport$: Observable<Viewport> /* Viewport observable */
|
||||||
|
header$: Observable<Header> /* Header observable */
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mount options
|
||||||
|
*/
|
||||||
|
interface MountOptions {
|
||||||
|
viewport$: Observable<Viewport> /* Viewport observable */
|
||||||
|
header$: Observable<Header> /* Header observable */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ----------------------------------------------------------------------------
|
||||||
|
* Functions
|
||||||
|
* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Watch header title
|
||||||
|
*
|
||||||
|
* @param el - Heading element
|
||||||
|
* @param options - Options
|
||||||
|
*
|
||||||
|
* @return Header title observable
|
||||||
|
*/
|
||||||
|
export function watchHeaderTitle(
|
||||||
|
el: HTMLHeadingElement, { viewport$, header$ }: WatchOptions
|
||||||
|
): Observable<HeaderTitle> {
|
||||||
|
return watchViewportAt(el, { header$, viewport$ })
|
||||||
|
.pipe(
|
||||||
|
map(({ offset: { y } }) => {
|
||||||
|
const { height } = getElementSize(el)
|
||||||
|
return {
|
||||||
|
active: y >= height
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
distinctUntilKeyChanged("active")
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mount header title
|
||||||
|
*
|
||||||
|
* @param el - Header title element
|
||||||
|
* @param options - Options
|
||||||
|
*
|
||||||
|
* @return Header title component observable
|
||||||
|
*/
|
||||||
|
export function mountHeaderTitle(
|
||||||
|
el: HTMLElement, options: MountOptions
|
||||||
|
): Observable<Component<HeaderTitle>> {
|
||||||
|
const internal$ = new Subject<HeaderTitle>()
|
||||||
|
internal$
|
||||||
|
.pipe(
|
||||||
|
observeOn(animationFrameScheduler),
|
||||||
|
)
|
||||||
|
.subscribe(({ active }) => {
|
||||||
|
if (active)
|
||||||
|
setHeaderTitleState(el, "active")
|
||||||
|
else
|
||||||
|
resetHeaderTitleState(el)
|
||||||
|
})
|
||||||
|
|
||||||
|
/* Create and return component */
|
||||||
|
const headline = getElementOrThrow<HTMLHeadingElement>("article h1")
|
||||||
|
return watchHeaderTitle(headline, options)
|
||||||
|
.pipe(
|
||||||
|
tap(internal$),
|
||||||
|
finalize(() => internal$.complete()),
|
||||||
|
map(state => ({ ref: el, ...state }))
|
||||||
|
)
|
||||||
|
}
|
@ -21,10 +21,12 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
export * from "./_"
|
export * from "./_"
|
||||||
|
export * from "./content"
|
||||||
|
export * from "./dialog"
|
||||||
export * from "./header"
|
export * from "./header"
|
||||||
export * from "./main"
|
export * from "./main"
|
||||||
export * from "./navigation"
|
|
||||||
export * from "./search"
|
export * from "./search"
|
||||||
export * from "./shared"
|
export * from "./sidebar"
|
||||||
|
export * from "./source"
|
||||||
export * from "./tabs"
|
export * from "./tabs"
|
||||||
export * from "./toc"
|
export * from "./toc"
|
||||||
|
@ -20,6 +20,107 @@
|
|||||||
* IN THE SOFTWARE.
|
* IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export * from "./_"
|
import {
|
||||||
export * from "./react"
|
Observable,
|
||||||
export * from "./set"
|
combineLatest
|
||||||
|
} from "rxjs"
|
||||||
|
import {
|
||||||
|
distinctUntilChanged,
|
||||||
|
distinctUntilKeyChanged,
|
||||||
|
map,
|
||||||
|
shareReplay,
|
||||||
|
switchMap
|
||||||
|
} from "rxjs/operators"
|
||||||
|
|
||||||
|
import { Viewport, watchElementSize } from "~/browser"
|
||||||
|
|
||||||
|
import { Header } from "../header"
|
||||||
|
|
||||||
|
/* ----------------------------------------------------------------------------
|
||||||
|
* Types
|
||||||
|
* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Main area
|
||||||
|
*/
|
||||||
|
export interface Main {
|
||||||
|
offset: number /* Main area top offset */
|
||||||
|
height: number /* Main area visible height */
|
||||||
|
active: boolean /* User scrolled past header */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ----------------------------------------------------------------------------
|
||||||
|
* Helper types
|
||||||
|
* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Watch options
|
||||||
|
*/
|
||||||
|
interface WatchOptions {
|
||||||
|
viewport$: Observable<Viewport> /* Viewport observable */
|
||||||
|
header$: Observable<Header> /* Header observable */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ----------------------------------------------------------------------------
|
||||||
|
* Functions
|
||||||
|
* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Watch main area
|
||||||
|
*
|
||||||
|
* This function returns an observable that computes the visual parameters of
|
||||||
|
* the main area which depends on the viewport vertical offset and height, as
|
||||||
|
* well as the height of the header element, if the header is fixed.
|
||||||
|
*
|
||||||
|
* @param el - Main area element
|
||||||
|
* @param options - Options
|
||||||
|
*
|
||||||
|
* @return Main area observable
|
||||||
|
*/
|
||||||
|
export function watchMain(
|
||||||
|
el: HTMLElement, { viewport$, header$ }: WatchOptions
|
||||||
|
): Observable<Main> {
|
||||||
|
|
||||||
|
/* Compute necessary adjustment for header */
|
||||||
|
const adjust$ = header$
|
||||||
|
.pipe(
|
||||||
|
map(({ height }) => height),
|
||||||
|
distinctUntilChanged()
|
||||||
|
)
|
||||||
|
|
||||||
|
/* Compute the main area's top and bottom borders */
|
||||||
|
const border$ = adjust$
|
||||||
|
.pipe(
|
||||||
|
switchMap(() => watchElementSize(el)
|
||||||
|
.pipe(
|
||||||
|
map(({ height }) => ({
|
||||||
|
top: el.offsetTop,
|
||||||
|
bottom: el.offsetTop + height
|
||||||
|
})),
|
||||||
|
distinctUntilKeyChanged("bottom")
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
/* Compute the main area's offset, visible height and if we scrolled past */
|
||||||
|
return combineLatest([adjust$, border$, viewport$])
|
||||||
|
.pipe(
|
||||||
|
map(([header, { top, bottom }, { offset: { y }, size: { height } }]) => {
|
||||||
|
height = Math.max(0, height
|
||||||
|
- Math.max(0, top - y, header)
|
||||||
|
- Math.max(0, height + y - bottom)
|
||||||
|
)
|
||||||
|
return {
|
||||||
|
offset: top - header,
|
||||||
|
height,
|
||||||
|
active: top - header <= y
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
distinctUntilChanged((a, b) => (
|
||||||
|
a.offset === b.offset &&
|
||||||
|
a.height === b.height &&
|
||||||
|
a.active === b.active
|
||||||
|
)),
|
||||||
|
shareReplay(1)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
@ -1,149 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2016-2020 Martin Donath <martin.donath@squidfunk.com>
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to
|
|
||||||
* deal in the Software without restriction, including without limitation the
|
|
||||||
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
|
||||||
* sell copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in
|
|
||||||
* all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
||||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
|
||||||
* IN THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import {
|
|
||||||
MonoTypeOperatorFunction,
|
|
||||||
Observable,
|
|
||||||
animationFrameScheduler,
|
|
||||||
combineLatest,
|
|
||||||
pipe
|
|
||||||
} from "rxjs"
|
|
||||||
import {
|
|
||||||
distinctUntilChanged,
|
|
||||||
distinctUntilKeyChanged,
|
|
||||||
finalize,
|
|
||||||
map,
|
|
||||||
observeOn,
|
|
||||||
switchMap,
|
|
||||||
tap
|
|
||||||
} from "rxjs/operators"
|
|
||||||
|
|
||||||
import { Viewport, watchElementSize } from "browser"
|
|
||||||
|
|
||||||
import { Header } from "../../header"
|
|
||||||
import { Main } from "../_"
|
|
||||||
import {
|
|
||||||
resetHeaderShadow,
|
|
||||||
setHeaderShadow
|
|
||||||
} from "../set"
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------------
|
|
||||||
* Helper types
|
|
||||||
* ------------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Watch options
|
|
||||||
*/
|
|
||||||
interface WatchOptions {
|
|
||||||
header$: Observable<Header> /* Header observable */
|
|
||||||
viewport$: Observable<Viewport> /* Viewport observable */
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------------
|
|
||||||
* Functions
|
|
||||||
* ------------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Watch main area
|
|
||||||
*
|
|
||||||
* This function returns an observable that computes the visual parameters of
|
|
||||||
* the main area which depends on the viewport vertical offset and height, as
|
|
||||||
* well as the height of the header element, if the header is fixed.
|
|
||||||
*
|
|
||||||
* @param el - Main area element
|
|
||||||
* @param options - Options
|
|
||||||
*
|
|
||||||
* @return Main area observable
|
|
||||||
*/
|
|
||||||
export function watchMain(
|
|
||||||
el: HTMLElement, { header$, viewport$ }: WatchOptions
|
|
||||||
): Observable<Main> {
|
|
||||||
|
|
||||||
/* Compute necessary adjustment for header */
|
|
||||||
const adjust$ = header$
|
|
||||||
.pipe(
|
|
||||||
map(({ height }) => height),
|
|
||||||
distinctUntilChanged()
|
|
||||||
)
|
|
||||||
|
|
||||||
/* Compute the main area's top and bottom borders */
|
|
||||||
const border$ = adjust$
|
|
||||||
.pipe(
|
|
||||||
switchMap(() => watchElementSize(el)
|
|
||||||
.pipe(
|
|
||||||
map(({ height }) => ({
|
|
||||||
top: el.offsetTop,
|
|
||||||
bottom: el.offsetTop + height
|
|
||||||
})),
|
|
||||||
distinctUntilKeyChanged("bottom")
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
/* Compute the main area's offset, visible height and if we scrolled past */
|
|
||||||
return combineLatest([adjust$, border$, viewport$])
|
|
||||||
.pipe(
|
|
||||||
map(([header, { top, bottom }, { offset: { y }, size: { height } }]) => {
|
|
||||||
height = Math.max(0, height
|
|
||||||
- Math.max(0, top - y, header)
|
|
||||||
- Math.max(0, height + y - bottom)
|
|
||||||
)
|
|
||||||
return {
|
|
||||||
offset: top - header,
|
|
||||||
height,
|
|
||||||
active: top - header <= y
|
|
||||||
}
|
|
||||||
}),
|
|
||||||
distinctUntilChanged<Main>((a, b) => {
|
|
||||||
return a.offset === b.offset
|
|
||||||
&& a.height === b.height
|
|
||||||
&& a.active === b.active
|
|
||||||
})
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ------------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Apply header shadow
|
|
||||||
*
|
|
||||||
* @param el - Header element
|
|
||||||
*
|
|
||||||
* @return Operator function
|
|
||||||
*/
|
|
||||||
export function applyHeaderShadow(
|
|
||||||
el: HTMLElement
|
|
||||||
): MonoTypeOperatorFunction<Main> {
|
|
||||||
return pipe(
|
|
||||||
|
|
||||||
/* Defer repaint to next animation frame */
|
|
||||||
observeOn(animationFrameScheduler),
|
|
||||||
tap(({ active }) => {
|
|
||||||
setHeaderShadow(el, active)
|
|
||||||
}),
|
|
||||||
|
|
||||||
/* Reset on complete or error */
|
|
||||||
finalize(() => {
|
|
||||||
resetHeaderShadow(el)
|
|
||||||
})
|
|
||||||
)
|
|
||||||
}
|
|
@ -1,110 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2016-2020 Martin Donath <martin.donath@squidfunk.com>
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to
|
|
||||||
* deal in the Software without restriction, including without limitation the
|
|
||||||
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
|
||||||
* sell copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in
|
|
||||||
* all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
||||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
|
||||||
* IN THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { Observable, OperatorFunction, of, pipe } from "rxjs"
|
|
||||||
import { map, switchMap } from "rxjs/operators"
|
|
||||||
|
|
||||||
import { Viewport } from "browser"
|
|
||||||
|
|
||||||
import { Header } from "../header"
|
|
||||||
import { Main } from "../main"
|
|
||||||
import {
|
|
||||||
Sidebar,
|
|
||||||
applySidebar,
|
|
||||||
watchSidebar
|
|
||||||
} from "../shared"
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------------
|
|
||||||
* Types
|
|
||||||
* ------------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Navigation for [screen -]
|
|
||||||
*/
|
|
||||||
interface NavigationBelowScreen {} // tslint:disable-line
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Navigation for [screen +]
|
|
||||||
*/
|
|
||||||
interface NavigationAboveScreen {
|
|
||||||
sidebar: Sidebar /* Sidebar */
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ------------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Navigation
|
|
||||||
*/
|
|
||||||
export type Navigation =
|
|
||||||
| NavigationBelowScreen
|
|
||||||
| NavigationAboveScreen
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------------
|
|
||||||
* Helper types
|
|
||||||
* ------------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Mount options
|
|
||||||
*/
|
|
||||||
interface MountOptions {
|
|
||||||
header$: Observable<Header> /* Header observable */
|
|
||||||
main$: Observable<Main> /* Main area observable */
|
|
||||||
viewport$: Observable<Viewport> /* Viewport observable */
|
|
||||||
screen$: Observable<boolean> /* Screen media observable */
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------------
|
|
||||||
* Functions
|
|
||||||
* ------------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Mount navigation from source observable
|
|
||||||
*
|
|
||||||
* @param options - Options
|
|
||||||
*
|
|
||||||
* @return Operator function
|
|
||||||
*/
|
|
||||||
export function mountNavigation(
|
|
||||||
{ header$, main$, viewport$, screen$ }: MountOptions
|
|
||||||
): OperatorFunction<HTMLElement, Navigation> {
|
|
||||||
return pipe(
|
|
||||||
switchMap(el => screen$
|
|
||||||
.pipe(
|
|
||||||
switchMap(screen => {
|
|
||||||
|
|
||||||
/* [screen +]: Mount navigation in sidebar */
|
|
||||||
if (screen) {
|
|
||||||
return watchSidebar(el, { main$, viewport$ })
|
|
||||||
.pipe(
|
|
||||||
applySidebar(el, { header$ }),
|
|
||||||
map(sidebar => ({ sidebar }))
|
|
||||||
)
|
|
||||||
|
|
||||||
/* [screen -]: Mount navigation in drawer */
|
|
||||||
} else {
|
|
||||||
return of({})
|
|
||||||
}
|
|
||||||
})
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
@ -20,60 +20,70 @@
|
|||||||
* IN THE SOFTWARE.
|
* IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { Observable, OperatorFunction, combineLatest, pipe } from "rxjs"
|
|
||||||
import {
|
import {
|
||||||
filter,
|
Observable,
|
||||||
|
Subject,
|
||||||
|
combineLatest,
|
||||||
|
fromEvent,
|
||||||
|
merge,
|
||||||
|
defer
|
||||||
|
} from "rxjs"
|
||||||
|
import {
|
||||||
|
delay,
|
||||||
|
distinctUntilChanged,
|
||||||
|
distinctUntilKeyChanged,
|
||||||
|
finalize,
|
||||||
map,
|
map,
|
||||||
mapTo,
|
|
||||||
sample,
|
|
||||||
startWith,
|
startWith,
|
||||||
switchMap,
|
takeLast,
|
||||||
take
|
takeUntil,
|
||||||
|
tap
|
||||||
} from "rxjs/operators"
|
} from "rxjs/operators"
|
||||||
|
|
||||||
import { WorkerHandler } from "browser"
|
|
||||||
import {
|
import {
|
||||||
SearchMessage,
|
resetSearchQueryPlaceholder,
|
||||||
SearchResult,
|
setSearchQueryPlaceholder
|
||||||
isSearchQueryMessage,
|
} from "~/actions"
|
||||||
isSearchReadyMessage
|
import {
|
||||||
} from "integrations/search"
|
getElementOrThrow,
|
||||||
|
setElementFocus,
|
||||||
|
setToggle,
|
||||||
|
watchElementFocus
|
||||||
|
} from "~/browser"
|
||||||
|
import {
|
||||||
|
SearchTransformFn,
|
||||||
|
defaultTransform,
|
||||||
|
SearchWorker,
|
||||||
|
SearchQueryMessage,
|
||||||
|
SearchMessageType,
|
||||||
|
setupSearchWorker,
|
||||||
|
} from "~/integrations"
|
||||||
|
import { configuration } from "~/_"
|
||||||
|
|
||||||
import { SearchQuery } from "../query"
|
import { Component } from "../../_"
|
||||||
|
import { mountSearchQuery, SearchQuery } from "../query"
|
||||||
|
import { mountSearchResult, SearchResult } from "../result"
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------------
|
/* ----------------------------------------------------------------------------
|
||||||
* Types
|
* Types
|
||||||
* ------------------------------------------------------------------------- */
|
* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
/**
|
|
||||||
* Search status
|
|
||||||
*/
|
|
||||||
export type SearchStatus =
|
|
||||||
| "waiting" /* Search waiting for initialization */
|
|
||||||
| "ready" /* Search ready */
|
|
||||||
|
|
||||||
/* ------------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Search
|
* Search
|
||||||
*/
|
*/
|
||||||
export interface Search {
|
export type Search =
|
||||||
status: SearchStatus /* Search status */
|
| SearchQuery
|
||||||
query: SearchQuery /* Search query */
|
| SearchResult
|
||||||
result: SearchResult[] /* Search result list */
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------------
|
/* ----------------------------------------------------------------------------
|
||||||
* Helper types
|
* Helper functions
|
||||||
* ------------------------------------------------------------------------- */
|
* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mount options
|
*
|
||||||
*/
|
*/
|
||||||
interface MountOptions {
|
function fetchSearchIndex() {
|
||||||
query$: Observable<SearchQuery> /* Search query observable */
|
|
||||||
reset$: Observable<void> /* Search reset observable */
|
|
||||||
result$: Observable<SearchResult[]> /* Search result observable */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------------
|
/* ----------------------------------------------------------------------------
|
||||||
@ -81,46 +91,57 @@ interface MountOptions {
|
|||||||
* ------------------------------------------------------------------------- */
|
* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mount search from source observable
|
* Mount search
|
||||||
*
|
*
|
||||||
* @param handler - Worker handler
|
* @param el - Search element
|
||||||
* @param options - Options
|
|
||||||
*
|
*
|
||||||
* @return Operator function
|
* @return Search component observable
|
||||||
*/
|
*/
|
||||||
export function mountSearch(
|
export function mountSearch(
|
||||||
{ rx$, tx$ }: WorkerHandler<SearchMessage>,
|
el: HTMLElement
|
||||||
{ query$, reset$, result$ }: MountOptions
|
): Observable<Component<Search>> {
|
||||||
): OperatorFunction<HTMLElement, Search> {
|
|
||||||
return pipe(
|
|
||||||
switchMap(() => {
|
|
||||||
|
|
||||||
/* Compute search status */
|
const searchQueryEl = getElementOrThrow<HTMLInputElement>("[data-md-component=search-query]", el)
|
||||||
const status$ = rx$
|
const searchResultEl = getElementOrThrow("[data-md-component=search-result]", el)
|
||||||
.pipe(
|
|
||||||
filter(isSearchReadyMessage),
|
|
||||||
mapTo<SearchStatus>("ready"),
|
|
||||||
startWith("waiting")
|
|
||||||
) as Observable<SearchStatus>
|
|
||||||
|
|
||||||
/* Re-emit the latest query when search is ready */
|
const config = configuration()
|
||||||
tx$
|
|
||||||
.pipe(
|
|
||||||
filter(isSearchQueryMessage),
|
|
||||||
sample(status$),
|
|
||||||
take(1)
|
|
||||||
)
|
|
||||||
.subscribe(tx$.next.bind(tx$))
|
|
||||||
|
|
||||||
/* Combine into single observable */
|
// TODO: determine correct BASE URL -> may change on instant loading!
|
||||||
return combineLatest([status$, query$, result$, reset$])
|
const index$ = defer(() => fetch(`${config.base}/search/search_index.json`, {
|
||||||
.pipe(
|
credentials: "same-origin"
|
||||||
map(([status, query, result]) => ({
|
}).then(res => res.json()))
|
||||||
status,
|
|
||||||
query,
|
// TODO: shouldnt be necessary, as it's done from config?
|
||||||
result
|
const worker$ = setupSearchWorker(config.search, {
|
||||||
}))
|
index$
|
||||||
)
|
})
|
||||||
})
|
// TODO: hand transformFn to
|
||||||
|
|
||||||
|
// __search.transform -> search transform
|
||||||
|
// __search.index -> search index
|
||||||
|
|
||||||
|
const query$ = mountSearchQuery(searchQueryEl, worker$)
|
||||||
|
const result$ = mountSearchResult(searchResultEl, worker$, { query$ })
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return merge(
|
||||||
|
query$,
|
||||||
|
result$
|
||||||
|
|
||||||
|
// /* Search query */
|
||||||
|
// ...getElements("[data-md-component=search-query]", el)
|
||||||
|
// .map(child => mountSearchQuery(child, worker$)),
|
||||||
|
|
||||||
|
// /* Search result */
|
||||||
|
// ...getElements("[data-md-component=search-query]", el)
|
||||||
|
// .map(child => mountSearchResult(child, worker$)),
|
||||||
)
|
)
|
||||||
|
// /* Create and return component */
|
||||||
|
// return watchSearchQuery(el, transform)
|
||||||
|
// .pipe(
|
||||||
|
// tap(internal$),
|
||||||
|
// finalize(() => internal$.complete()),
|
||||||
|
// map(state => ({ ref: el, ...state }))
|
||||||
|
// )
|
||||||
}
|
}
|
||||||
|
@ -22,5 +22,4 @@
|
|||||||
|
|
||||||
export * from "./_"
|
export * from "./_"
|
||||||
export * from "./query"
|
export * from "./query"
|
||||||
export * from "./reset"
|
|
||||||
export * from "./result"
|
export * from "./result"
|
||||||
|
@ -20,6 +20,145 @@
|
|||||||
* IN THE SOFTWARE.
|
* IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export * from "./_"
|
import {
|
||||||
export * from "./react"
|
Observable,
|
||||||
export * from "./set"
|
Subject,
|
||||||
|
combineLatest,
|
||||||
|
fromEvent,
|
||||||
|
merge
|
||||||
|
} from "rxjs"
|
||||||
|
import {
|
||||||
|
delay,
|
||||||
|
distinctUntilChanged,
|
||||||
|
distinctUntilKeyChanged,
|
||||||
|
finalize,
|
||||||
|
map,
|
||||||
|
startWith,
|
||||||
|
takeLast,
|
||||||
|
takeUntil,
|
||||||
|
tap
|
||||||
|
} from "rxjs/operators"
|
||||||
|
|
||||||
|
import {
|
||||||
|
resetSearchQueryPlaceholder,
|
||||||
|
setSearchQueryPlaceholder
|
||||||
|
} from "~/actions"
|
||||||
|
import {
|
||||||
|
setElementFocus,
|
||||||
|
setToggle,
|
||||||
|
watchElementFocus
|
||||||
|
} from "~/browser"
|
||||||
|
import {
|
||||||
|
defaultTransform,
|
||||||
|
SearchWorker,
|
||||||
|
SearchQueryMessage,
|
||||||
|
SearchMessageType
|
||||||
|
} from "~/integrations"
|
||||||
|
|
||||||
|
import { Component } from "../../_"
|
||||||
|
|
||||||
|
/* ----------------------------------------------------------------------------
|
||||||
|
* Types
|
||||||
|
* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Search query
|
||||||
|
*/
|
||||||
|
export interface SearchQuery {
|
||||||
|
value: string /* Query value */
|
||||||
|
focus: boolean /* Query focus */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ----------------------------------------------------------------------------
|
||||||
|
* Functions
|
||||||
|
* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Watch search query
|
||||||
|
*
|
||||||
|
* Note that the focus event which triggers re-reading the current query value
|
||||||
|
* is delayed by `1ms` so the input's empty state is allowed to propagate.
|
||||||
|
*
|
||||||
|
* @param el - Search query element
|
||||||
|
* @param transform - Transformation function
|
||||||
|
*
|
||||||
|
* @return Search query observable
|
||||||
|
*/
|
||||||
|
export function watchSearchQuery(
|
||||||
|
el: HTMLInputElement
|
||||||
|
): Observable<SearchQuery> {
|
||||||
|
const fn = __search?.transform || defaultTransform
|
||||||
|
|
||||||
|
/* Intercept focus and input events */
|
||||||
|
const focus$ = watchElementFocus(el)
|
||||||
|
const value$ = merge(
|
||||||
|
fromEvent(el, "keyup"),
|
||||||
|
fromEvent(el, "focus").pipe(delay(1))
|
||||||
|
)
|
||||||
|
.pipe(
|
||||||
|
map(() => fn(el.value)),
|
||||||
|
startWith(fn(el.value)),
|
||||||
|
distinctUntilChanged()
|
||||||
|
)
|
||||||
|
|
||||||
|
/* Combine into single observable */
|
||||||
|
return combineLatest([value$, focus$])
|
||||||
|
.pipe(
|
||||||
|
map(([value, focus]) => ({ value, focus }))
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mount search query
|
||||||
|
*
|
||||||
|
* @param el - Search query element
|
||||||
|
* @param worker - Search worker
|
||||||
|
* @param transform - Transformation function
|
||||||
|
*
|
||||||
|
* @return Search query component observable
|
||||||
|
*/
|
||||||
|
export function mountSearchQuery(
|
||||||
|
el: HTMLInputElement, { tx$ }: SearchWorker
|
||||||
|
): Observable<Component<SearchQuery, HTMLInputElement>> {
|
||||||
|
const internal$ = new Subject<SearchQuery>()
|
||||||
|
|
||||||
|
/* Handle value changes */
|
||||||
|
internal$
|
||||||
|
.pipe(
|
||||||
|
distinctUntilKeyChanged("value"),
|
||||||
|
map(({ value }): SearchQueryMessage => ({
|
||||||
|
type: SearchMessageType.QUERY,
|
||||||
|
data: value
|
||||||
|
}))
|
||||||
|
)
|
||||||
|
.subscribe(tx$.next.bind(tx$))
|
||||||
|
|
||||||
|
/* Handle focus changes */
|
||||||
|
internal$
|
||||||
|
.pipe(
|
||||||
|
distinctUntilKeyChanged("focus")
|
||||||
|
)
|
||||||
|
.subscribe(({ focus }) => {
|
||||||
|
if (focus) {
|
||||||
|
setToggle("search", focus)
|
||||||
|
setSearchQueryPlaceholder(el, "")
|
||||||
|
} else {
|
||||||
|
resetSearchQueryPlaceholder(el)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
/* Handle reset */
|
||||||
|
fromEvent(el.form!, "reset")
|
||||||
|
.pipe(
|
||||||
|
takeUntil(internal$.pipe(takeLast(1)))
|
||||||
|
)
|
||||||
|
.subscribe(() => setElementFocus(el))
|
||||||
|
|
||||||
|
/* Create and return component */
|
||||||
|
return watchSearchQuery(el)
|
||||||
|
.pipe(
|
||||||
|
tap(internal$),
|
||||||
|
finalize(() => internal$.complete()),
|
||||||
|
map(state => ({ ref: el, ...state }))
|
||||||
|
)
|
||||||
|
}
|
||||||
|
@ -1,129 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2016-2020 Martin Donath <martin.donath@squidfunk.com>
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to
|
|
||||||
* deal in the Software without restriction, including without limitation the
|
|
||||||
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
|
||||||
* sell copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in
|
|
||||||
* all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
||||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
|
||||||
* IN THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import {
|
|
||||||
MonoTypeOperatorFunction,
|
|
||||||
Observable,
|
|
||||||
combineLatest,
|
|
||||||
fromEvent,
|
|
||||||
merge,
|
|
||||||
pipe
|
|
||||||
} from "rxjs"
|
|
||||||
import {
|
|
||||||
delay,
|
|
||||||
distinctUntilChanged,
|
|
||||||
finalize,
|
|
||||||
map,
|
|
||||||
startWith,
|
|
||||||
tap
|
|
||||||
} from "rxjs/operators"
|
|
||||||
|
|
||||||
import { watchElementFocus } from "browser"
|
|
||||||
import { SearchTransformFn, defaultTransform } from "integrations"
|
|
||||||
|
|
||||||
import { SearchQuery } from "../_"
|
|
||||||
import {
|
|
||||||
resetSearchQueryPlaceholder,
|
|
||||||
setSearchQueryPlaceholder
|
|
||||||
} from "../set"
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------------
|
|
||||||
* Helper types
|
|
||||||
* ------------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Watch options
|
|
||||||
*/
|
|
||||||
interface WatchOptions {
|
|
||||||
transform?: SearchTransformFn /* Transformation function */
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------------
|
|
||||||
* Functions
|
|
||||||
* ------------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Watch search query
|
|
||||||
*
|
|
||||||
* Note that the focus event which triggers re-reading the current query value
|
|
||||||
* is delayed by `1ms` so the input's empty state is allowed to propagate.
|
|
||||||
*
|
|
||||||
* @param el - Search query element
|
|
||||||
* @param options - Options
|
|
||||||
*
|
|
||||||
* @return Search query observable
|
|
||||||
*/
|
|
||||||
export function watchSearchQuery(
|
|
||||||
el: HTMLInputElement, { transform }: WatchOptions = {}
|
|
||||||
): Observable<SearchQuery> {
|
|
||||||
const fn = transform || defaultTransform
|
|
||||||
|
|
||||||
/* Intercept keyboard events */
|
|
||||||
const value$ = merge(
|
|
||||||
fromEvent(el, "keyup"),
|
|
||||||
fromEvent(el, "focus").pipe(delay(1))
|
|
||||||
)
|
|
||||||
.pipe(
|
|
||||||
map(() => fn(el.value)),
|
|
||||||
startWith(fn(el.value)),
|
|
||||||
distinctUntilChanged()
|
|
||||||
)
|
|
||||||
|
|
||||||
/* Intercept focus events */
|
|
||||||
const focus$ = watchElementFocus(el)
|
|
||||||
|
|
||||||
/* Combine into single observable */
|
|
||||||
return combineLatest([value$, focus$])
|
|
||||||
.pipe(
|
|
||||||
map(([value, focus]) => ({ value, focus }))
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ------------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Apply search query
|
|
||||||
*
|
|
||||||
* @param el - Search query element
|
|
||||||
*
|
|
||||||
* @return Operator function
|
|
||||||
*/
|
|
||||||
export function applySearchQuery(
|
|
||||||
el: HTMLInputElement
|
|
||||||
): MonoTypeOperatorFunction<SearchQuery> {
|
|
||||||
return pipe(
|
|
||||||
|
|
||||||
/* Hide placeholder when search is focused */
|
|
||||||
tap(({ focus }) => {
|
|
||||||
if (focus) {
|
|
||||||
setSearchQueryPlaceholder(el, "")
|
|
||||||
} else {
|
|
||||||
resetSearchQueryPlaceholder(el)
|
|
||||||
}
|
|
||||||
}),
|
|
||||||
|
|
||||||
/* Reset on complete or error */
|
|
||||||
finalize(() => {
|
|
||||||
resetSearchQueryPlaceholder(el)
|
|
||||||
})
|
|
||||||
)
|
|
||||||
}
|
|
@ -1,57 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2016-2020 Martin Donath <martin.donath@squidfunk.com>
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to
|
|
||||||
* deal in the Software without restriction, including without limitation the
|
|
||||||
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
|
||||||
* sell copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in
|
|
||||||
* all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
||||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
|
||||||
* IN THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { OperatorFunction, pipe } from "rxjs"
|
|
||||||
import {
|
|
||||||
mapTo,
|
|
||||||
startWith,
|
|
||||||
switchMap,
|
|
||||||
switchMapTo,
|
|
||||||
tap
|
|
||||||
} from "rxjs/operators"
|
|
||||||
|
|
||||||
import { setElementFocus } from "browser"
|
|
||||||
|
|
||||||
import { useComponent } from "../../../_"
|
|
||||||
import { watchSearchReset } from "../react"
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------------
|
|
||||||
* Functions
|
|
||||||
* ------------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Mount search reset from source observable
|
|
||||||
*
|
|
||||||
* @return Operator function
|
|
||||||
*/
|
|
||||||
export function mountSearchReset(): OperatorFunction<HTMLElement, void> {
|
|
||||||
return pipe(
|
|
||||||
switchMap(el => watchSearchReset(el)
|
|
||||||
.pipe(
|
|
||||||
switchMapTo(useComponent("search-query")),
|
|
||||||
tap(setElementFocus),
|
|
||||||
mapTo(undefined)
|
|
||||||
)
|
|
||||||
),
|
|
||||||
startWith(undefined)
|
|
||||||
)
|
|
||||||
}
|
|
@ -1,101 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2016-2020 Martin Donath <martin.donath@squidfunk.com>
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to
|
|
||||||
* deal in the Software without restriction, including without limitation the
|
|
||||||
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
|
||||||
* sell copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in
|
|
||||||
* all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
||||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
|
||||||
* IN THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { Observable, OperatorFunction, pipe } from "rxjs"
|
|
||||||
import {
|
|
||||||
distinctUntilChanged,
|
|
||||||
filter,
|
|
||||||
map,
|
|
||||||
mapTo,
|
|
||||||
startWith,
|
|
||||||
switchMap
|
|
||||||
} from "rxjs/operators"
|
|
||||||
|
|
||||||
import { WorkerHandler, watchElementOffset } from "browser"
|
|
||||||
import {
|
|
||||||
SearchMessage,
|
|
||||||
SearchResult,
|
|
||||||
isSearchReadyMessage,
|
|
||||||
isSearchResultMessage
|
|
||||||
} from "integrations"
|
|
||||||
|
|
||||||
import { SearchQuery } from "../../query"
|
|
||||||
import { applySearchResult } from "../react"
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------------
|
|
||||||
* Helper types
|
|
||||||
* ------------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Mount options
|
|
||||||
*/
|
|
||||||
interface MountOptions {
|
|
||||||
query$: Observable<SearchQuery> /* Search query observable */
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------------
|
|
||||||
* Functions
|
|
||||||
* ------------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Mount search result from source observable
|
|
||||||
*
|
|
||||||
* @param handler - Worker handler
|
|
||||||
* @param options - Options
|
|
||||||
*
|
|
||||||
* @return Operator function
|
|
||||||
*/
|
|
||||||
export function mountSearchResult(
|
|
||||||
{ rx$ }: WorkerHandler<SearchMessage>, { query$ }: MountOptions
|
|
||||||
): OperatorFunction<HTMLElement, SearchResult[]> {
|
|
||||||
return pipe(
|
|
||||||
switchMap(el => {
|
|
||||||
const container = el.parentElement!
|
|
||||||
|
|
||||||
/* Compute if search is ready */
|
|
||||||
const ready$ = rx$
|
|
||||||
.pipe(
|
|
||||||
filter(isSearchReadyMessage),
|
|
||||||
mapTo(true)
|
|
||||||
)
|
|
||||||
|
|
||||||
/* Compute whether there are more search results to fetch */
|
|
||||||
const fetch$ = watchElementOffset(container)
|
|
||||||
.pipe(
|
|
||||||
map(({ y }) => {
|
|
||||||
return y >= container.scrollHeight - container.offsetHeight - 16
|
|
||||||
}),
|
|
||||||
distinctUntilChanged(),
|
|
||||||
filter(Boolean)
|
|
||||||
)
|
|
||||||
|
|
||||||
/* Apply search results */
|
|
||||||
return rx$
|
|
||||||
.pipe(
|
|
||||||
filter(isSearchResultMessage),
|
|
||||||
map(({ data }) => data),
|
|
||||||
applySearchResult(el, { query$, ready$, fetch$ }),
|
|
||||||
startWith([])
|
|
||||||
)
|
|
||||||
})
|
|
||||||
)
|
|
||||||
}
|
|
@ -20,6 +20,113 @@
|
|||||||
* IN THE SOFTWARE.
|
* IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export * from "./_"
|
import { Observable, Subject } from "rxjs"
|
||||||
export * from "./react"
|
import {
|
||||||
export * from "./set"
|
filter,
|
||||||
|
finalize,
|
||||||
|
map,
|
||||||
|
startWith,
|
||||||
|
tap,
|
||||||
|
withLatestFrom
|
||||||
|
} from "rxjs/operators"
|
||||||
|
|
||||||
|
import {
|
||||||
|
addToSearchResultList,
|
||||||
|
resetSearchResultList,
|
||||||
|
resetSearchResultMeta,
|
||||||
|
setSearchResultMeta
|
||||||
|
} from "~/actions"
|
||||||
|
import { getElementOrThrow } from "~/browser"
|
||||||
|
import {
|
||||||
|
SearchResult as SearchResultData,
|
||||||
|
SearchWorker,
|
||||||
|
isSearchResultMessage
|
||||||
|
} from "~/integrations"
|
||||||
|
import { renderSearchResult } from "~/templates"
|
||||||
|
|
||||||
|
import { Component } from "../../_"
|
||||||
|
import { SearchQuery } from "../query"
|
||||||
|
|
||||||
|
/* ----------------------------------------------------------------------------
|
||||||
|
* Types
|
||||||
|
* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Search result
|
||||||
|
*/
|
||||||
|
export interface SearchResult {
|
||||||
|
data: SearchResultData[] /* Search result data */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ----------------------------------------------------------------------------
|
||||||
|
* Helper types
|
||||||
|
* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mount options
|
||||||
|
*/
|
||||||
|
interface MountOptions {
|
||||||
|
query$: Observable<SearchQuery> /* Search query observable */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ----------------------------------------------------------------------------
|
||||||
|
* Functions
|
||||||
|
* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mount search result list
|
||||||
|
*
|
||||||
|
* @param el - Search result list element
|
||||||
|
* @param worker - Search worker
|
||||||
|
* @param options - Options
|
||||||
|
*
|
||||||
|
* @return Search result list component observable
|
||||||
|
*/
|
||||||
|
export function mountSearchResult(
|
||||||
|
el: HTMLElement, { rx$ }: SearchWorker, { query$ }: MountOptions
|
||||||
|
): Observable<Component<SearchResult>> {
|
||||||
|
const internal$ = new Subject<SearchResult>()
|
||||||
|
|
||||||
|
/* Update search result metadata */
|
||||||
|
const meta = getElementOrThrow(":first-child", el)
|
||||||
|
internal$
|
||||||
|
.pipe(
|
||||||
|
withLatestFrom(query$)
|
||||||
|
)
|
||||||
|
.subscribe(([{ data }, { value }]) => {
|
||||||
|
if (value)
|
||||||
|
setSearchResultMeta(meta, data.length)
|
||||||
|
else
|
||||||
|
resetSearchResultMeta(meta)
|
||||||
|
})
|
||||||
|
|
||||||
|
/* Update search result list */
|
||||||
|
const list = getElementOrThrow(":last-child", el)
|
||||||
|
internal$
|
||||||
|
.subscribe(({ data }) => {
|
||||||
|
resetSearchResultList(list)
|
||||||
|
|
||||||
|
/* Compute thresholds and search results */
|
||||||
|
const thresholds = [...data.map(([best]) => best.score), 0]
|
||||||
|
for (let index = 0; index < data.length; index++)
|
||||||
|
addToSearchResultList(list, renderSearchResult(
|
||||||
|
data[index++], thresholds[index]
|
||||||
|
))
|
||||||
|
})
|
||||||
|
|
||||||
|
/* Filter search result list */
|
||||||
|
const result$ = rx$
|
||||||
|
.pipe(
|
||||||
|
filter(isSearchResultMessage),
|
||||||
|
map(({ data }) => ({ data })),
|
||||||
|
startWith({ data: [] })
|
||||||
|
)
|
||||||
|
|
||||||
|
/* Create and return component */
|
||||||
|
return result$
|
||||||
|
.pipe(
|
||||||
|
tap(internal$),
|
||||||
|
finalize(() => internal$.complete()),
|
||||||
|
map(state => ({ ref: el, ...state }))
|
||||||
|
)
|
||||||
|
}
|
||||||
|
@ -1,129 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2016-2020 Martin Donath <martin.donath@squidfunk.com>
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to
|
|
||||||
* deal in the Software without restriction, including without limitation the
|
|
||||||
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
|
||||||
* sell copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in
|
|
||||||
* all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
||||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
|
||||||
* IN THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import {
|
|
||||||
MonoTypeOperatorFunction,
|
|
||||||
Observable,
|
|
||||||
animationFrameScheduler,
|
|
||||||
pipe
|
|
||||||
} from "rxjs"
|
|
||||||
import {
|
|
||||||
finalize,
|
|
||||||
map,
|
|
||||||
mapTo,
|
|
||||||
observeOn,
|
|
||||||
scan,
|
|
||||||
switchMap,
|
|
||||||
withLatestFrom
|
|
||||||
} from "rxjs/operators"
|
|
||||||
|
|
||||||
import { getElementOrThrow } from "browser"
|
|
||||||
import { SearchResult } from "integrations/search"
|
|
||||||
import { renderSearchResult } from "templates"
|
|
||||||
|
|
||||||
import { SearchQuery } from "../../query"
|
|
||||||
import {
|
|
||||||
addToSearchResultList,
|
|
||||||
resetSearchResultList,
|
|
||||||
resetSearchResultMeta,
|
|
||||||
setSearchResultMeta
|
|
||||||
} from "../set"
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------------
|
|
||||||
* Helper types
|
|
||||||
* ------------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Apply options
|
|
||||||
*/
|
|
||||||
interface ApplyOptions {
|
|
||||||
query$: Observable<SearchQuery> /* Search query observable */
|
|
||||||
ready$: Observable<boolean> /* Search ready observable */
|
|
||||||
fetch$: Observable<boolean> /* Result fetch observable */
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------------
|
|
||||||
* Functions
|
|
||||||
* ------------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Apply search results
|
|
||||||
*
|
|
||||||
* This function will perform a lazy rendering of the search results, depending
|
|
||||||
* on the vertical offset of the search result container. When the scroll offset
|
|
||||||
* reaches the bottom of the element, more results are fetched and rendered.
|
|
||||||
*
|
|
||||||
* @param el - Search result element
|
|
||||||
* @param options - Options
|
|
||||||
*
|
|
||||||
* @return Operator function
|
|
||||||
*/
|
|
||||||
export function applySearchResult(
|
|
||||||
el: HTMLElement, { query$, ready$, fetch$ }: ApplyOptions
|
|
||||||
): MonoTypeOperatorFunction<SearchResult[]> {
|
|
||||||
const list = getElementOrThrow(".md-search-result__list", el)
|
|
||||||
const meta = getElementOrThrow(".md-search-result__meta", el)
|
|
||||||
return pipe(
|
|
||||||
|
|
||||||
/* Apply search result metadata */
|
|
||||||
withLatestFrom(query$, ready$),
|
|
||||||
map(([result, query]) => {
|
|
||||||
if (query.value) {
|
|
||||||
setSearchResultMeta(meta, result.length)
|
|
||||||
} else {
|
|
||||||
resetSearchResultMeta(meta)
|
|
||||||
}
|
|
||||||
return result
|
|
||||||
}),
|
|
||||||
|
|
||||||
/* Apply search result list */
|
|
||||||
switchMap(result => {
|
|
||||||
const thresholds = [...result.map(([best]) => best.score), 0]
|
|
||||||
return fetch$
|
|
||||||
.pipe(
|
|
||||||
|
|
||||||
/* Defer repaint to next animation frame */
|
|
||||||
observeOn(animationFrameScheduler),
|
|
||||||
scan(index => {
|
|
||||||
const container = el.parentElement!
|
|
||||||
while (index < result.length) {
|
|
||||||
addToSearchResultList(list, renderSearchResult(
|
|
||||||
result[index++], thresholds[index]
|
|
||||||
))
|
|
||||||
if (container.scrollHeight - container.offsetHeight > 16)
|
|
||||||
break
|
|
||||||
}
|
|
||||||
return index
|
|
||||||
}, 0),
|
|
||||||
|
|
||||||
/* Re-map to search result */
|
|
||||||
mapTo(result),
|
|
||||||
|
|
||||||
/* Reset on complete or error */
|
|
||||||
finalize(() => {
|
|
||||||
resetSearchResultList(list)
|
|
||||||
})
|
|
||||||
)
|
|
||||||
}
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
@ -1,33 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2016-2020 Martin Donath <martin.donath@squidfunk.com>
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to
|
|
||||||
* deal in the Software without restriction, including without limitation the
|
|
||||||
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
|
||||||
* sell copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in
|
|
||||||
* all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
||||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
|
||||||
* IN THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------------
|
|
||||||
* Types
|
|
||||||
* ------------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sidebar
|
|
||||||
*/
|
|
||||||
export interface Sidebar {
|
|
||||||
height: number /* Sidebar height */
|
|
||||||
lock: boolean /* Sidebar lock */
|
|
||||||
}
|
|
@ -21,11 +21,10 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import {
|
import {
|
||||||
MonoTypeOperatorFunction,
|
|
||||||
Observable,
|
Observable,
|
||||||
|
Subject,
|
||||||
animationFrameScheduler,
|
animationFrameScheduler,
|
||||||
combineLatest,
|
combineLatest
|
||||||
pipe
|
|
||||||
} from "rxjs"
|
} from "rxjs"
|
||||||
import {
|
import {
|
||||||
distinctUntilChanged,
|
distinctUntilChanged,
|
||||||
@ -36,17 +35,29 @@ import {
|
|||||||
withLatestFrom
|
withLatestFrom
|
||||||
} from "rxjs/operators"
|
} from "rxjs/operators"
|
||||||
|
|
||||||
import { Viewport } from "browser"
|
|
||||||
|
|
||||||
import { Header } from "../../../header"
|
|
||||||
import { Main } from "../../../main"
|
|
||||||
import { Sidebar } from "../_"
|
|
||||||
import {
|
import {
|
||||||
resetSidebarHeight,
|
resetSidebarHeight,
|
||||||
resetSidebarOffset,
|
resetSidebarOffset,
|
||||||
setSidebarHeight,
|
setSidebarHeight,
|
||||||
setSidebarOffset
|
setSidebarOffset
|
||||||
} from "../set"
|
} from "~/actions"
|
||||||
|
import { Viewport } from "~/browser"
|
||||||
|
|
||||||
|
import { Component } from "../_"
|
||||||
|
import { Header } from "../header"
|
||||||
|
import { Main } from "../main"
|
||||||
|
|
||||||
|
/* ----------------------------------------------------------------------------
|
||||||
|
* Types
|
||||||
|
* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sidebar
|
||||||
|
*/
|
||||||
|
export interface Sidebar {
|
||||||
|
height: number /* Sidebar height */
|
||||||
|
locked: boolean /* User scrolled past header */
|
||||||
|
}
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------------
|
/* ----------------------------------------------------------------------------
|
||||||
* Helper types
|
* Helper types
|
||||||
@ -56,15 +67,17 @@ import {
|
|||||||
* Watch options
|
* Watch options
|
||||||
*/
|
*/
|
||||||
interface WatchOptions {
|
interface WatchOptions {
|
||||||
main$: Observable<Main> /* Main area observable */
|
|
||||||
viewport$: Observable<Viewport> /* Viewport observable */
|
viewport$: Observable<Viewport> /* Viewport observable */
|
||||||
|
main$: Observable<Main> /* Main area observable */
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Apply options
|
* Mount options
|
||||||
*/
|
*/
|
||||||
interface ApplyOptions {
|
interface MountOptions {
|
||||||
|
viewport$: Observable<Viewport> /* Viewport observable */
|
||||||
header$: Observable<Header> /* Header observable */
|
header$: Observable<Header> /* Header observable */
|
||||||
|
main$: Observable<Main> /* Main area observable */
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------------
|
/* ----------------------------------------------------------------------------
|
||||||
@ -85,10 +98,11 @@ interface ApplyOptions {
|
|||||||
* @return Sidebar observable
|
* @return Sidebar observable
|
||||||
*/
|
*/
|
||||||
export function watchSidebar(
|
export function watchSidebar(
|
||||||
el: HTMLElement, { main$, viewport$ }: WatchOptions
|
el: HTMLElement, { viewport$, main$ }: WatchOptions
|
||||||
): Observable<Sidebar> {
|
): Observable<Sidebar> {
|
||||||
const adjust = el.parentElement!.offsetTop
|
const adjust =
|
||||||
- el.parentElement!.parentElement!.offsetTop
|
el.parentElement!.offsetTop -
|
||||||
|
el.parentElement!.parentElement!.offsetTop
|
||||||
|
|
||||||
/* Compute the sidebar's available height and if it should be locked */
|
/* Compute the sidebar's available height and if it should be locked */
|
||||||
return combineLatest([main$, viewport$])
|
return combineLatest([main$, viewport$])
|
||||||
@ -99,51 +113,53 @@ export function watchSidebar(
|
|||||||
- adjust
|
- adjust
|
||||||
return {
|
return {
|
||||||
height,
|
height,
|
||||||
lock: y >= offset + adjust
|
locked: y >= offset + adjust
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
distinctUntilChanged<Sidebar>((a, b) => {
|
distinctUntilChanged((a, b) => (
|
||||||
return a.height === b.height
|
a.height === b.height &&
|
||||||
&& a.lock === b.lock
|
a.locked === b.locked
|
||||||
})
|
))
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ------------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Apply sidebar
|
* Mount sidebar
|
||||||
*
|
*
|
||||||
* @param el - Sidebar element
|
* @param el - Sidebar element
|
||||||
* @param options - Options
|
* @param options - Options
|
||||||
*
|
*
|
||||||
* @return Operator function
|
* @return Sidebar component observable
|
||||||
*/
|
*/
|
||||||
export function applySidebar(
|
export function mountSidebar(
|
||||||
el: HTMLElement, { header$ }: ApplyOptions
|
el: HTMLElement, { header$, ...options }: MountOptions
|
||||||
): MonoTypeOperatorFunction<Sidebar> {
|
): Observable<Component<Sidebar>> {
|
||||||
return pipe(
|
const internal$ = new Subject<Sidebar>()
|
||||||
|
internal$
|
||||||
|
.pipe(
|
||||||
|
observeOn(animationFrameScheduler),
|
||||||
|
withLatestFrom(header$)
|
||||||
|
)
|
||||||
|
.subscribe({
|
||||||
|
|
||||||
/* Defer repaint to next animation frame */
|
/* Update height and offset */
|
||||||
observeOn(animationFrameScheduler),
|
next([{ height }, { height: offset }]) {
|
||||||
withLatestFrom(header$),
|
setSidebarHeight(el, height)
|
||||||
tap(([{ height, lock }, { height: offset }]) => {
|
setSidebarOffset(el, offset)
|
||||||
setSidebarHeight(el, height)
|
},
|
||||||
|
|
||||||
/* Set offset in locked state depending on header height */
|
/* Reset on complete */
|
||||||
if (lock)
|
complete() {
|
||||||
setSidebarOffset(el, offset)
|
resetSidebarOffset(el)
|
||||||
else
|
resetSidebarHeight(el)
|
||||||
resetSidebarOffset(el)
|
}
|
||||||
}),
|
})
|
||||||
|
|
||||||
/* Re-map to sidebar */
|
/* Create and return component */
|
||||||
map(([sidebar]) => sidebar),
|
return watchSidebar(el, options)
|
||||||
|
.pipe(
|
||||||
/* Reset on complete or error */
|
tap(internal$),
|
||||||
finalize(() => {
|
finalize(() => internal$.complete()),
|
||||||
resetSidebarOffset(el)
|
map(state => ({ ref: el, ...state }))
|
||||||
resetSidebarHeight(el)
|
)
|
||||||
})
|
|
||||||
)
|
|
||||||
}
|
}
|
129
src/assets/javascripts/components/source/_/index.ts
Normal file
129
src/assets/javascripts/components/source/_/index.ts
Normal file
@ -0,0 +1,129 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016-2020 Martin Donath <martin.donath@squidfunk.com>
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to
|
||||||
|
* deal in the Software without restriction, including without limitation the
|
||||||
|
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||||
|
* sell copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||||
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||||
|
* IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { Observable, Subject, defer, of, NEVER } from "rxjs"
|
||||||
|
import {
|
||||||
|
catchError,
|
||||||
|
filter,
|
||||||
|
finalize,
|
||||||
|
map,
|
||||||
|
shareReplay,
|
||||||
|
tap
|
||||||
|
} from "rxjs/operators"
|
||||||
|
|
||||||
|
import { setSourceFacts, setSourceState } from "~/actions"
|
||||||
|
import { renderSourceFacts } from "~/templates"
|
||||||
|
import { hash } from "~/utilities"
|
||||||
|
|
||||||
|
import { Component } from "../../_"
|
||||||
|
import {
|
||||||
|
fetchSourceFacts,
|
||||||
|
SourceFacts
|
||||||
|
} from "../facts"
|
||||||
|
|
||||||
|
/* ----------------------------------------------------------------------------
|
||||||
|
* Types
|
||||||
|
* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Repository information
|
||||||
|
*/
|
||||||
|
export interface Source {
|
||||||
|
facts: SourceFacts /* Repository facts */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ----------------------------------------------------------------------------
|
||||||
|
* Data
|
||||||
|
* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Repository facts observable
|
||||||
|
*/
|
||||||
|
let fetch$: Observable<Source>
|
||||||
|
|
||||||
|
/* ----------------------------------------------------------------------------
|
||||||
|
* Functions
|
||||||
|
* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Watch repository information
|
||||||
|
*
|
||||||
|
* @param el - Repository information element
|
||||||
|
*
|
||||||
|
* @return Repository information observable
|
||||||
|
*/
|
||||||
|
export function watchSource(
|
||||||
|
el: HTMLAnchorElement
|
||||||
|
): Observable<Source> {
|
||||||
|
const digest = hash(el.href).toString()
|
||||||
|
|
||||||
|
/* Fetch repository facts once */
|
||||||
|
return fetch$ ||= defer(() => {
|
||||||
|
const data = sessionStorage.getItem(digest)
|
||||||
|
if (data) {
|
||||||
|
return of(JSON.parse(data))
|
||||||
|
} else {
|
||||||
|
const value$ = fetchSourceFacts(el.href)
|
||||||
|
value$.subscribe(value => {
|
||||||
|
try {
|
||||||
|
sessionStorage.setItem(digest, JSON.stringify(value))
|
||||||
|
} catch (err) {
|
||||||
|
/* Uncritical, just swallow */
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
/* Return value */
|
||||||
|
return value$
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.pipe(
|
||||||
|
catchError(() => NEVER),
|
||||||
|
filter(facts => facts.length > 0),
|
||||||
|
map(facts => ({ facts })),
|
||||||
|
shareReplay(1)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mount repository information
|
||||||
|
*
|
||||||
|
* @param el - Repository information element
|
||||||
|
*
|
||||||
|
* @return Repository information component observable
|
||||||
|
*/
|
||||||
|
export function mountSource(
|
||||||
|
el: HTMLAnchorElement
|
||||||
|
): Observable<Component<Source>> {
|
||||||
|
const internal$ = new Subject<Source>()
|
||||||
|
internal$.subscribe(({ facts }) => {
|
||||||
|
setSourceFacts(el, renderSourceFacts(facts))
|
||||||
|
setSourceState(el, "done")
|
||||||
|
})
|
||||||
|
|
||||||
|
/* Create and return component */
|
||||||
|
return watchSource(el)
|
||||||
|
.pipe(
|
||||||
|
tap(internal$),
|
||||||
|
finalize(() => internal$.complete()),
|
||||||
|
map(state => ({ ref: el, ...state }))
|
||||||
|
)
|
||||||
|
}
|
@ -20,57 +20,49 @@
|
|||||||
* IN THE SOFTWARE.
|
* IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { Observable, combineLatest } from "rxjs"
|
import { NEVER, Observable } from "rxjs"
|
||||||
import { distinctUntilKeyChanged, map } from "rxjs/operators"
|
|
||||||
|
|
||||||
import { Viewport, getElements } from "browser"
|
import { fetchSourceFactsFromGitHub } from "../github"
|
||||||
|
import { fetchSourceFactsFromGitLab } from "../gitlab"
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------------
|
/* ----------------------------------------------------------------------------
|
||||||
* Helper types
|
* Types
|
||||||
* ------------------------------------------------------------------------- */
|
* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mount options
|
* Repository facts
|
||||||
*/
|
*/
|
||||||
interface MountOptions {
|
export type SourceFacts = string[]
|
||||||
document$: Observable<Document> /* Document observable */
|
|
||||||
viewport$: Observable<Viewport> /* Viewport observable */
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------------
|
/* ----------------------------------------------------------------------------
|
||||||
* Functions
|
* Functions
|
||||||
* ------------------------------------------------------------------------- */
|
* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Patch all `code` elements
|
* Fetch repository facts
|
||||||
*
|
*
|
||||||
* This function will make overflowing code blocks focusable via keyboard, so
|
* @param url - Repository URL
|
||||||
* they can be scrolled without a mouse.
|
|
||||||
*
|
*
|
||||||
* @param options - Options
|
* @return Repository facts observable
|
||||||
*/
|
*/
|
||||||
export function patchCodeBlocks(
|
export function fetchSourceFacts(
|
||||||
{ document$, viewport$ }: MountOptions
|
url: string
|
||||||
): void {
|
): Observable<SourceFacts> {
|
||||||
const els$ = document$
|
const [type] = url.match(/(git(?:hub|lab))/i) || []
|
||||||
.pipe(
|
switch (type.toLowerCase()) {
|
||||||
map(() => getElements<HTMLTableElement>("pre > code"))
|
|
||||||
)
|
|
||||||
|
|
||||||
/* Observe viewport size only */
|
/* GitHub repository */
|
||||||
const size$ = viewport$
|
case "github":
|
||||||
.pipe(
|
const [, user, repo] = url.match(/^.+github\.com\/([^\/]+)\/?([^\/]+)?/i)!
|
||||||
distinctUntilKeyChanged("size")
|
return fetchSourceFactsFromGitHub(user, repo)
|
||||||
)
|
|
||||||
|
|
||||||
/* Make overflowing elements focusable */
|
/* GitLab repository */
|
||||||
combineLatest([els$, size$])
|
case "gitlab":
|
||||||
.subscribe(([els]) => {
|
const [, base, slug] = url.match(/^.+?([^\/]*gitlab[^\/]+)\/(.+?)\/?$/i)!
|
||||||
for (const el of els) {
|
return fetchSourceFactsFromGitLab(base, slug)
|
||||||
if (el.scrollWidth > el.clientWidth)
|
|
||||||
el.setAttribute("tabindex", "0")
|
/* Everything else */
|
||||||
else
|
default:
|
||||||
el.removeAttribute("tabindex")
|
return NEVER
|
||||||
}
|
}
|
||||||
})
|
|
||||||
}
|
}
|
@ -26,25 +26,24 @@ import {
|
|||||||
defaultIfEmpty,
|
defaultIfEmpty,
|
||||||
filter,
|
filter,
|
||||||
map,
|
map,
|
||||||
share,
|
|
||||||
switchMap
|
switchMap
|
||||||
} from "rxjs/operators"
|
} from "rxjs/operators"
|
||||||
|
|
||||||
import { round } from "utilities"
|
import { round } from "~/utilities"
|
||||||
|
|
||||||
import { SourceFacts } from ".."
|
import { SourceFacts } from "../_"
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------------
|
/* ----------------------------------------------------------------------------
|
||||||
* Functions
|
* Functions
|
||||||
* ------------------------------------------------------------------------- */
|
* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetch GitHub source facts
|
* Fetch GitHub repository facts
|
||||||
*
|
*
|
||||||
* @param user - GitHub user
|
* @param user - GitHub user
|
||||||
* @param repo - GitHub repository
|
* @param repo - GitHub repository
|
||||||
*
|
*
|
||||||
* @return Source facts observable
|
* @return Repository facts observable
|
||||||
*/
|
*/
|
||||||
export function fetchSourceFactsFromGitHub(
|
export function fetchSourceFactsFromGitHub(
|
||||||
user: string, repo?: string
|
user: string, repo?: string
|
||||||
@ -74,7 +73,6 @@ export function fetchSourceFactsFromGitHub(
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
defaultIfEmpty([]),
|
defaultIfEmpty([])
|
||||||
share()
|
|
||||||
)
|
)
|
||||||
}
|
}
|
@ -26,25 +26,24 @@ import {
|
|||||||
defaultIfEmpty,
|
defaultIfEmpty,
|
||||||
filter,
|
filter,
|
||||||
map,
|
map,
|
||||||
share,
|
|
||||||
switchMap
|
switchMap
|
||||||
} from "rxjs/operators"
|
} from "rxjs/operators"
|
||||||
|
|
||||||
import { round } from "utilities"
|
import { round } from "~/utilities"
|
||||||
|
|
||||||
import { SourceFacts } from ".."
|
import { SourceFacts } from "../_"
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------------
|
/* ----------------------------------------------------------------------------
|
||||||
* Functions
|
* Functions
|
||||||
* ------------------------------------------------------------------------- */
|
* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetch GitLab source facts
|
* Fetch GitLab repository facts
|
||||||
*
|
*
|
||||||
* @param base - GitLab base
|
* @param base - GitLab base
|
||||||
* @param project - GitLab project
|
* @param project - GitLab project
|
||||||
*
|
*
|
||||||
* @return Source facts observable
|
* @return Repository facts observable
|
||||||
*/
|
*/
|
||||||
export function fetchSourceFactsFromGitLab(
|
export function fetchSourceFactsFromGitLab(
|
||||||
base: string, project: string
|
base: string, project: string
|
||||||
@ -58,7 +57,6 @@ export function fetchSourceFactsFromGitLab(
|
|||||||
`${round(star_count)} Stars`,
|
`${round(star_count)} Stars`,
|
||||||
`${round(forks_count)} Forks`
|
`${round(forks_count)} Forks`
|
||||||
])),
|
])),
|
||||||
defaultIfEmpty([]),
|
defaultIfEmpty([])
|
||||||
share()
|
|
||||||
)
|
)
|
||||||
}
|
}
|
@ -21,5 +21,5 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
export * from "./_"
|
export * from "./_"
|
||||||
export * from "./react"
|
export * from "./github"
|
||||||
export * from "./set"
|
export * from "./gitlab"
|
@ -20,4 +20,5 @@
|
|||||||
* IN THE SOFTWARE.
|
* IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export * from "./sidebar"
|
export * from "./_"
|
||||||
|
export * from "./facts"
|
@ -20,6 +20,115 @@
|
|||||||
* IN THE SOFTWARE.
|
* IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export * from "./_"
|
import { Observable, animationFrameScheduler, Subject } from "rxjs"
|
||||||
export * from "./react"
|
import {
|
||||||
export * from "./set"
|
distinctUntilKeyChanged,
|
||||||
|
finalize,
|
||||||
|
map,
|
||||||
|
observeOn,
|
||||||
|
tap
|
||||||
|
} from "rxjs/operators"
|
||||||
|
|
||||||
|
import { resetTabsState, setTabsState } from "~/actions"
|
||||||
|
import { Viewport, watchViewportAt } from "~/browser"
|
||||||
|
|
||||||
|
import { Component } from "../_"
|
||||||
|
import { Header } from "../header"
|
||||||
|
|
||||||
|
/* ----------------------------------------------------------------------------
|
||||||
|
* Types
|
||||||
|
* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Navigation tabs
|
||||||
|
*/
|
||||||
|
export interface Tabs {
|
||||||
|
hidden: boolean /* User scrolled past tabs */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ----------------------------------------------------------------------------
|
||||||
|
* Helper types
|
||||||
|
* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Watch options
|
||||||
|
*/
|
||||||
|
interface WatchOptions {
|
||||||
|
viewport$: Observable<Viewport> /* Viewport observable */
|
||||||
|
header$: Observable<Header> /* Header observable */
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mount options
|
||||||
|
*/
|
||||||
|
interface MountOptions {
|
||||||
|
viewport$: Observable<Viewport> /* Viewport observable */
|
||||||
|
header$: Observable<Header> /* Header observable */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ----------------------------------------------------------------------------
|
||||||
|
* Functions
|
||||||
|
* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Watch navigation tabs
|
||||||
|
*
|
||||||
|
* @param el - Navigation tabs element
|
||||||
|
* @param options - Options
|
||||||
|
*
|
||||||
|
* @return Navigation tabs observable
|
||||||
|
*/
|
||||||
|
export function watchTabs(
|
||||||
|
el: HTMLElement, { viewport$, header$ }: WatchOptions
|
||||||
|
): Observable<Tabs> {
|
||||||
|
return watchViewportAt(el, { header$, viewport$ })
|
||||||
|
.pipe(
|
||||||
|
map(({ offset: { y } }) => {
|
||||||
|
return {
|
||||||
|
hidden: y >= 10
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
distinctUntilKeyChanged("hidden")
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mount navigation tabs
|
||||||
|
*
|
||||||
|
* @param el - Navigation tabs element
|
||||||
|
* @param options - Options
|
||||||
|
*
|
||||||
|
* @return Navigation tabs component observable
|
||||||
|
*/
|
||||||
|
export function mountTabs(
|
||||||
|
el: HTMLElement, options: MountOptions
|
||||||
|
): Observable<Component<Tabs>> {
|
||||||
|
const internal$ = new Subject<Tabs>()
|
||||||
|
internal$
|
||||||
|
.pipe(
|
||||||
|
observeOn(animationFrameScheduler)
|
||||||
|
)
|
||||||
|
.subscribe({
|
||||||
|
|
||||||
|
/* Update state */
|
||||||
|
next({ hidden }) {
|
||||||
|
if (hidden)
|
||||||
|
setTabsState(el, "hidden")
|
||||||
|
else
|
||||||
|
resetTabsState(el)
|
||||||
|
},
|
||||||
|
|
||||||
|
/* Reset on complete */
|
||||||
|
complete() {
|
||||||
|
resetTabsState(el)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
/* Create and return component */
|
||||||
|
return watchTabs(el, options)
|
||||||
|
.pipe(
|
||||||
|
tap(internal$),
|
||||||
|
finalize(() => internal$.complete()),
|
||||||
|
map(state => ({ ref: el, ...state }))
|
||||||
|
)
|
||||||
|
}
|
||||||
|
@ -1,63 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2016-2020 Martin Donath <martin.donath@squidfunk.com>
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to
|
|
||||||
* deal in the Software without restriction, including without limitation the
|
|
||||||
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
|
||||||
* sell copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in
|
|
||||||
* all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
||||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
|
||||||
* IN THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import {
|
|
||||||
MonoTypeOperatorFunction,
|
|
||||||
animationFrameScheduler,
|
|
||||||
pipe
|
|
||||||
} from "rxjs"
|
|
||||||
import { finalize, observeOn, tap } from "rxjs/operators"
|
|
||||||
|
|
||||||
import { Tabs } from "../_"
|
|
||||||
import {
|
|
||||||
resetTabsHidden,
|
|
||||||
setTabsHidden
|
|
||||||
} from "../set"
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------------
|
|
||||||
* Functions
|
|
||||||
* ------------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Apply tabs
|
|
||||||
*
|
|
||||||
* @param el - Tabs element
|
|
||||||
*
|
|
||||||
* @return Operator function
|
|
||||||
*/
|
|
||||||
export function applyTabs(
|
|
||||||
el: HTMLElement
|
|
||||||
): MonoTypeOperatorFunction<Tabs> {
|
|
||||||
return pipe(
|
|
||||||
|
|
||||||
/* Defer repaint to next animation frame */
|
|
||||||
observeOn(animationFrameScheduler),
|
|
||||||
tap(({ hidden }) => {
|
|
||||||
setTabsHidden(el, hidden)
|
|
||||||
}),
|
|
||||||
|
|
||||||
/* Reset on complete or error */
|
|
||||||
finalize(() => {
|
|
||||||
resetTabsHidden(el)
|
|
||||||
})
|
|
||||||
)
|
|
||||||
}
|
|
@ -1,136 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2016-2020 Martin Donath <martin.donath@squidfunk.com>
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to
|
|
||||||
* deal in the Software without restriction, including without limitation the
|
|
||||||
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
|
||||||
* sell copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in
|
|
||||||
* all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
||||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
|
||||||
* IN THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import {
|
|
||||||
Observable,
|
|
||||||
OperatorFunction,
|
|
||||||
combineLatest,
|
|
||||||
of,
|
|
||||||
pipe
|
|
||||||
} from "rxjs"
|
|
||||||
import { map, switchMap } from "rxjs/operators"
|
|
||||||
|
|
||||||
import { Viewport, getElements } from "browser"
|
|
||||||
|
|
||||||
import { Header } from "../../header"
|
|
||||||
import { Main } from "../../main"
|
|
||||||
import {
|
|
||||||
Sidebar,
|
|
||||||
applySidebar,
|
|
||||||
watchSidebar
|
|
||||||
} from "../../shared"
|
|
||||||
import {
|
|
||||||
AnchorList,
|
|
||||||
applyAnchorList,
|
|
||||||
watchAnchorList
|
|
||||||
} from "../anchor"
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------------
|
|
||||||
* Types
|
|
||||||
* ------------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Table of contents for [tablet -]
|
|
||||||
*/
|
|
||||||
interface TableOfContentsBelowTablet {} // tslint:disable-line
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Table of contents for [tablet +]
|
|
||||||
*/
|
|
||||||
interface TableOfContentsAboveTablet {
|
|
||||||
sidebar: Sidebar /* Sidebar */
|
|
||||||
anchors: AnchorList /* Anchor list */
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ------------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Table of contents
|
|
||||||
*/
|
|
||||||
export type TableOfContents =
|
|
||||||
| TableOfContentsBelowTablet
|
|
||||||
| TableOfContentsAboveTablet
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------------
|
|
||||||
* Helper types
|
|
||||||
* ------------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Mount options
|
|
||||||
*/
|
|
||||||
interface MountOptions {
|
|
||||||
header$: Observable<Header> /* Header observable */
|
|
||||||
main$: Observable<Main> /* Main area observable */
|
|
||||||
viewport$: Observable<Viewport> /* Viewport observable */
|
|
||||||
tablet$: Observable<boolean> /* Tablet media observable */
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------------
|
|
||||||
* Functions
|
|
||||||
* ------------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Mount table of contents from source observable
|
|
||||||
*
|
|
||||||
* @param options - Options
|
|
||||||
*
|
|
||||||
* @return Operator function
|
|
||||||
*/
|
|
||||||
export function mountTableOfContents(
|
|
||||||
{ header$, main$, viewport$, tablet$ }: MountOptions
|
|
||||||
): OperatorFunction<HTMLElement, TableOfContents> {
|
|
||||||
return pipe(
|
|
||||||
switchMap(el => tablet$
|
|
||||||
.pipe(
|
|
||||||
switchMap(tablet => {
|
|
||||||
|
|
||||||
/* [tablet +]: Mount table of contents in sidebar */
|
|
||||||
if (tablet) {
|
|
||||||
const els = getElements<HTMLAnchorElement>(".md-nav__link", el)
|
|
||||||
|
|
||||||
/* Watch and apply sidebar */
|
|
||||||
const sidebar$ = watchSidebar(el, { main$, viewport$ })
|
|
||||||
.pipe(
|
|
||||||
applySidebar(el, { header$ })
|
|
||||||
)
|
|
||||||
|
|
||||||
/* Watch and apply anchor list (scroll spy) */
|
|
||||||
const anchors$ = watchAnchorList(els, { header$, viewport$ })
|
|
||||||
.pipe(
|
|
||||||
applyAnchorList(els)
|
|
||||||
)
|
|
||||||
|
|
||||||
/* Combine into single hot observable */
|
|
||||||
return combineLatest([sidebar$, anchors$])
|
|
||||||
.pipe(
|
|
||||||
map(([sidebar, anchors]) => ({ sidebar, anchors }))
|
|
||||||
)
|
|
||||||
|
|
||||||
/* [tablet -]: Unmount table of contents */
|
|
||||||
} else {
|
|
||||||
return of({})
|
|
||||||
}
|
|
||||||
})
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
@ -1,246 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2016-2020 Martin Donath <martin.donath@squidfunk.com>
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to
|
|
||||||
* deal in the Software without restriction, including without limitation the
|
|
||||||
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
|
||||||
* sell copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in
|
|
||||||
* all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
||||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
|
||||||
* IN THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import {
|
|
||||||
MonoTypeOperatorFunction,
|
|
||||||
Observable,
|
|
||||||
animationFrameScheduler,
|
|
||||||
combineLatest,
|
|
||||||
pipe
|
|
||||||
} from "rxjs"
|
|
||||||
import {
|
|
||||||
bufferCount,
|
|
||||||
distinctUntilChanged,
|
|
||||||
distinctUntilKeyChanged,
|
|
||||||
finalize,
|
|
||||||
map,
|
|
||||||
observeOn,
|
|
||||||
scan,
|
|
||||||
startWith,
|
|
||||||
switchMap,
|
|
||||||
tap
|
|
||||||
} from "rxjs/operators"
|
|
||||||
|
|
||||||
import { Viewport, getElement, watchElementSize } from "browser"
|
|
||||||
|
|
||||||
import { Header } from "../../../header"
|
|
||||||
import { AnchorList } from "../_"
|
|
||||||
import {
|
|
||||||
resetAnchorActive,
|
|
||||||
resetAnchorBlur,
|
|
||||||
setAnchorActive,
|
|
||||||
setAnchorBlur
|
|
||||||
} from "../set"
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------------
|
|
||||||
* Helper types
|
|
||||||
* ------------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Watch options
|
|
||||||
*/
|
|
||||||
interface WatchOptions {
|
|
||||||
header$: Observable<Header> /* Header observable */
|
|
||||||
viewport$: Observable<Viewport> /* Viewport observable */
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------------
|
|
||||||
* Functions
|
|
||||||
* ------------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Watch anchor list
|
|
||||||
*
|
|
||||||
* This is effectively a scroll-spy implementation which will account for the
|
|
||||||
* fixed header and automatically re-calculate anchor offsets when the viewport
|
|
||||||
* is resized. The returned observable will only emit if the anchor list needs
|
|
||||||
* to be repainted.
|
|
||||||
*
|
|
||||||
* This implementation tracks an anchor element's entire path starting from its
|
|
||||||
* level up to the top-most anchor element, e.g. `[h3, h2, h1]`. Although the
|
|
||||||
* Material theme currently doesn't make use of this information, it enables
|
|
||||||
* the styling of the entire hierarchy through customization.
|
|
||||||
*
|
|
||||||
* Note that the current anchor is the last item of the `prev` anchor list.
|
|
||||||
*
|
|
||||||
* @param els - Anchor elements
|
|
||||||
* @param options - Options
|
|
||||||
*
|
|
||||||
* @return Anchor list observable
|
|
||||||
*/
|
|
||||||
export function watchAnchorList(
|
|
||||||
els: HTMLAnchorElement[], { header$, viewport$ }: WatchOptions
|
|
||||||
): Observable<AnchorList> {
|
|
||||||
const table = new Map<HTMLAnchorElement, HTMLElement>()
|
|
||||||
for (const el of els) {
|
|
||||||
const id = decodeURIComponent(el.hash.substring(1))
|
|
||||||
const target = getElement(`[id="${id}"]`)
|
|
||||||
if (typeof target !== "undefined")
|
|
||||||
table.set(el, target)
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Compute necessary adjustment for header */
|
|
||||||
const adjust$ = header$
|
|
||||||
.pipe(
|
|
||||||
map(header => 24 + header.height)
|
|
||||||
)
|
|
||||||
|
|
||||||
/* Compute partition of previous and next anchors */
|
|
||||||
const partition$ = watchElementSize(document.body)
|
|
||||||
.pipe(
|
|
||||||
distinctUntilKeyChanged("height"),
|
|
||||||
|
|
||||||
/* Build index to map anchor paths to vertical offsets */
|
|
||||||
map(() => {
|
|
||||||
let path: HTMLAnchorElement[] = []
|
|
||||||
return [...table].reduce((index, [anchor, target]) => {
|
|
||||||
while (path.length) {
|
|
||||||
const last = table.get(path[path.length - 1])!
|
|
||||||
if (last.tagName >= target.tagName) {
|
|
||||||
path.pop()
|
|
||||||
} else {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* If the current anchor is hidden, continue with its parent */
|
|
||||||
let offset = target.offsetTop
|
|
||||||
while (!offset && target.parentElement) {
|
|
||||||
target = target.parentElement
|
|
||||||
offset = target.offsetTop
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Map reversed anchor path to vertical offset */
|
|
||||||
return index.set(
|
|
||||||
[...path = [...path, anchor]].reverse(),
|
|
||||||
offset
|
|
||||||
)
|
|
||||||
}, new Map<HTMLAnchorElement[], number>())
|
|
||||||
}),
|
|
||||||
|
|
||||||
/* Re-compute partition when viewport offset changes */
|
|
||||||
switchMap(index => combineLatest([adjust$, viewport$])
|
|
||||||
.pipe(
|
|
||||||
scan(([prev, next], [adjust, { offset: { y } }]) => {
|
|
||||||
|
|
||||||
/* Look forward */
|
|
||||||
while (next.length) {
|
|
||||||
const [, offset] = next[0]
|
|
||||||
if (offset - adjust < y) {
|
|
||||||
prev = [...prev, next.shift()!]
|
|
||||||
} else {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Look backward */
|
|
||||||
while (prev.length) {
|
|
||||||
const [, offset] = prev[prev.length - 1]
|
|
||||||
if (offset - adjust >= y) {
|
|
||||||
next = [prev.pop()!, ...next]
|
|
||||||
} else {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Return partition */
|
|
||||||
return [prev, next]
|
|
||||||
}, [[], [...index]]),
|
|
||||||
distinctUntilChanged((a, b) => {
|
|
||||||
return a[0] === b[0]
|
|
||||||
&& a[1] === b[1]
|
|
||||||
})
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
/* Compute and return anchor list migrations */
|
|
||||||
return partition$
|
|
||||||
.pipe(
|
|
||||||
map(([prev, next]) => ({
|
|
||||||
prev: prev.map(([path]) => path),
|
|
||||||
next: next.map(([path]) => path)
|
|
||||||
})),
|
|
||||||
|
|
||||||
/* Extract anchor list migrations */
|
|
||||||
startWith({ prev: [], next: [] }),
|
|
||||||
bufferCount(2, 1),
|
|
||||||
map(([a, b]) => {
|
|
||||||
|
|
||||||
/* Moving down */
|
|
||||||
if (a.prev.length < b.prev.length) {
|
|
||||||
return {
|
|
||||||
prev: b.prev.slice(Math.max(0, a.prev.length - 1), b.prev.length),
|
|
||||||
next: []
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Moving up */
|
|
||||||
} else {
|
|
||||||
return {
|
|
||||||
prev: b.prev.slice(-1),
|
|
||||||
next: b.next.slice(0, b.next.length - a.next.length)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ------------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Apply anchor list
|
|
||||||
*
|
|
||||||
* @param els - Anchor elements
|
|
||||||
*
|
|
||||||
* @return Operator function
|
|
||||||
*/
|
|
||||||
export function applyAnchorList(
|
|
||||||
els: HTMLAnchorElement[]
|
|
||||||
): MonoTypeOperatorFunction<AnchorList> {
|
|
||||||
return pipe(
|
|
||||||
|
|
||||||
/* Defer repaint to next animation frame */
|
|
||||||
observeOn(animationFrameScheduler),
|
|
||||||
tap(({ prev, next }) => {
|
|
||||||
|
|
||||||
/* Look forward */
|
|
||||||
for (const [el] of next) {
|
|
||||||
resetAnchorActive(el)
|
|
||||||
resetAnchorBlur(el)
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Look backward */
|
|
||||||
prev.forEach(([el], index) => {
|
|
||||||
setAnchorActive(el, index === prev.length - 1)
|
|
||||||
setAnchorBlur(el, true)
|
|
||||||
})
|
|
||||||
}),
|
|
||||||
|
|
||||||
/* Reset on complete or error */
|
|
||||||
finalize(() => {
|
|
||||||
for (const el of els) {
|
|
||||||
resetAnchorActive(el)
|
|
||||||
resetAnchorBlur(el)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
)
|
|
||||||
}
|
|
@ -20,5 +20,253 @@
|
|||||||
* IN THE SOFTWARE.
|
* IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export * from "./_"
|
import {
|
||||||
export * from "./anchor"
|
Observable,
|
||||||
|
Subject,
|
||||||
|
animationFrameScheduler,
|
||||||
|
combineLatest
|
||||||
|
} from "rxjs"
|
||||||
|
import {
|
||||||
|
bufferCount,
|
||||||
|
distinctUntilChanged,
|
||||||
|
distinctUntilKeyChanged,
|
||||||
|
finalize,
|
||||||
|
map,
|
||||||
|
observeOn,
|
||||||
|
scan,
|
||||||
|
startWith,
|
||||||
|
switchMap,
|
||||||
|
tap
|
||||||
|
} from "rxjs/operators"
|
||||||
|
|
||||||
|
import {
|
||||||
|
resetAnchorActive,
|
||||||
|
resetAnchorState,
|
||||||
|
setAnchorActive,
|
||||||
|
setAnchorState
|
||||||
|
} from "~/actions"
|
||||||
|
import {
|
||||||
|
getElement,
|
||||||
|
getElements,
|
||||||
|
Viewport,
|
||||||
|
watchElementSize
|
||||||
|
} from "~/browser"
|
||||||
|
|
||||||
|
import { Component } from "../_"
|
||||||
|
import { Header } from "../header"
|
||||||
|
|
||||||
|
/* ----------------------------------------------------------------------------
|
||||||
|
* Types
|
||||||
|
* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Table of contents
|
||||||
|
*/
|
||||||
|
export interface TableOfContents {
|
||||||
|
prev: HTMLAnchorElement[][] /* Anchors (previous) */
|
||||||
|
next: HTMLAnchorElement[][] /* Anchors (next) */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ----------------------------------------------------------------------------
|
||||||
|
* Helper types
|
||||||
|
* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Watch options
|
||||||
|
*/
|
||||||
|
interface WatchOptions {
|
||||||
|
viewport$: Observable<Viewport> /* Viewport observable */
|
||||||
|
header$: Observable<Header> /* Header observable */
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mount options
|
||||||
|
*/
|
||||||
|
interface MountOptions {
|
||||||
|
viewport$: Observable<Viewport> /* Viewport observable */
|
||||||
|
header$: Observable<Header> /* Header observable */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ----------------------------------------------------------------------------
|
||||||
|
* Functions
|
||||||
|
* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Watch table of contents
|
||||||
|
*
|
||||||
|
* This is effectively a scroll spy implementation which will account for the
|
||||||
|
* fixed header and automatically re-calculate anchor offsets when the viewport
|
||||||
|
* is resized. The returned observable will only emit if the table of contents
|
||||||
|
* needs to be repainted.
|
||||||
|
*
|
||||||
|
* This implementation tracks an anchor element's entire path starting from its
|
||||||
|
* level up to the top-most anchor element, e.g. `[h3, h2, h1]`. Although the
|
||||||
|
* Material theme currently doesn't make use of this information, it enables
|
||||||
|
* the styling of the entire hierarchy through customization.
|
||||||
|
*
|
||||||
|
* Note that the current anchor is the last item of the `prev` anchor list.
|
||||||
|
*
|
||||||
|
* @param anchors - Anchor elements
|
||||||
|
* @param options - Options
|
||||||
|
*
|
||||||
|
* @return Table of contents observable
|
||||||
|
*/
|
||||||
|
export function watchTableOfContents(
|
||||||
|
anchors: HTMLAnchorElement[], { viewport$, header$ }: WatchOptions
|
||||||
|
): Observable<TableOfContents> {
|
||||||
|
const table = new Map<HTMLAnchorElement, HTMLElement>()
|
||||||
|
for (const anchor of anchors) {
|
||||||
|
const id = decodeURIComponent(anchor.hash.substring(1))
|
||||||
|
const target = getElement(`[id="${id}"]`)
|
||||||
|
if (typeof target !== "undefined")
|
||||||
|
table.set(anchor, target)
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Compute necessary adjustment for header */
|
||||||
|
const adjust$ = header$
|
||||||
|
.pipe(
|
||||||
|
map(header => 24 + header.height)
|
||||||
|
)
|
||||||
|
|
||||||
|
/* Compute partition of previous and next anchors */
|
||||||
|
const partition$ = watchElementSize(document.body)
|
||||||
|
.pipe(
|
||||||
|
distinctUntilKeyChanged("height"),
|
||||||
|
|
||||||
|
/* Build index to map anchor paths to vertical offsets */
|
||||||
|
map(() => {
|
||||||
|
let path: HTMLAnchorElement[] = []
|
||||||
|
return [...table].reduce((index, [anchor, target]) => {
|
||||||
|
while (path.length) {
|
||||||
|
const last = table.get(path[path.length - 1])!
|
||||||
|
if (last.tagName >= target.tagName) {
|
||||||
|
path.pop()
|
||||||
|
} else {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* If the current anchor is hidden, continue with its parent */
|
||||||
|
let offset = target.offsetTop
|
||||||
|
while (!offset && target.parentElement) {
|
||||||
|
target = target.parentElement
|
||||||
|
offset = target.offsetTop
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Map reversed anchor path to vertical offset */
|
||||||
|
return index.set(
|
||||||
|
[...path = [...path, anchor]].reverse(),
|
||||||
|
offset
|
||||||
|
)
|
||||||
|
}, new Map<HTMLAnchorElement[], number>())
|
||||||
|
}),
|
||||||
|
|
||||||
|
/* Re-compute partition when viewport offset changes */
|
||||||
|
switchMap(index => combineLatest([adjust$, viewport$])
|
||||||
|
.pipe(
|
||||||
|
scan(([prev, next], [adjust, { offset: { y } }]) => {
|
||||||
|
|
||||||
|
/* Look forward */
|
||||||
|
while (next.length) {
|
||||||
|
const [, offset] = next[0]
|
||||||
|
if (offset - adjust < y) {
|
||||||
|
prev = [...prev, next.shift()!]
|
||||||
|
} else {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Look backward */
|
||||||
|
while (prev.length) {
|
||||||
|
const [, offset] = prev[prev.length - 1]
|
||||||
|
if (offset - adjust >= y) {
|
||||||
|
next = [prev.pop()!, ...next]
|
||||||
|
} else {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Return partition */
|
||||||
|
return [prev, next]
|
||||||
|
}, [[], [...index]]),
|
||||||
|
distinctUntilChanged((a, b) => (
|
||||||
|
a[0] === b[0] &&
|
||||||
|
a[1] === b[1]
|
||||||
|
))
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
/* Compute and return anchor list migrations */
|
||||||
|
return partition$
|
||||||
|
.pipe(
|
||||||
|
map(([prev, next]) => ({
|
||||||
|
prev: prev.map(([path]) => path),
|
||||||
|
next: next.map(([path]) => path)
|
||||||
|
})),
|
||||||
|
|
||||||
|
/* Extract anchor list migrations */
|
||||||
|
startWith({ prev: [], next: [] }),
|
||||||
|
bufferCount(2, 1),
|
||||||
|
map(([a, b]) => {
|
||||||
|
|
||||||
|
/* Moving down */
|
||||||
|
if (a.prev.length < b.prev.length) {
|
||||||
|
return {
|
||||||
|
prev: b.prev.slice(Math.max(0, a.prev.length - 1), b.prev.length),
|
||||||
|
next: []
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Moving up */
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
prev: b.prev.slice(-1),
|
||||||
|
next: b.next.slice(0, b.next.length - a.next.length)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mount table of contents
|
||||||
|
*
|
||||||
|
* @param el - Anchor list element
|
||||||
|
* @param options - Options
|
||||||
|
*
|
||||||
|
* @return Table of contents component observable
|
||||||
|
*/
|
||||||
|
export function mountTableOfContents(
|
||||||
|
el: HTMLElement, options: MountOptions
|
||||||
|
): Observable<Component<TableOfContents>> {
|
||||||
|
const internal$ = new Subject<TableOfContents>()
|
||||||
|
internal$
|
||||||
|
.pipe(
|
||||||
|
observeOn(animationFrameScheduler),
|
||||||
|
)
|
||||||
|
.subscribe(({ prev, next }) => {
|
||||||
|
|
||||||
|
/* Look forward */
|
||||||
|
for (const [anchor] of next) {
|
||||||
|
resetAnchorActive(anchor)
|
||||||
|
resetAnchorState(anchor)
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Look backward */
|
||||||
|
for (const [index, [anchor]] of prev.entries()) {
|
||||||
|
setAnchorActive(anchor, index === prev.length - 1)
|
||||||
|
setAnchorState(anchor, "blur")
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
/* Create and return component */
|
||||||
|
const anchors = getElements<HTMLAnchorElement>("[href^=\\#]", el)
|
||||||
|
return watchTableOfContents(anchors, options)
|
||||||
|
.pipe(
|
||||||
|
tap(internal$),
|
||||||
|
finalize(() => internal$.complete()),
|
||||||
|
map(state => ({ ref: el, ...state }))
|
||||||
|
)
|
||||||
|
}
|
||||||
|
@ -20,483 +20,121 @@
|
|||||||
* IN THE SOFTWARE.
|
* IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// DISCLAIMER: this file is still WIP. There're some refactoring opportunities
|
|
||||||
// which must be tackled after we gathered some feedback on v5.
|
|
||||||
// tslint:disable
|
|
||||||
|
|
||||||
import "focus-visible"
|
import "focus-visible"
|
||||||
|
import { merge, NEVER, Observable, Subject } from "rxjs"
|
||||||
|
import { switchMap } from "rxjs/operators"
|
||||||
|
|
||||||
import {
|
import {
|
||||||
merge,
|
getElementOrThrow,
|
||||||
combineLatest,
|
|
||||||
animationFrameScheduler,
|
|
||||||
fromEvent,
|
|
||||||
from,
|
|
||||||
defer,
|
|
||||||
of,
|
|
||||||
NEVER
|
|
||||||
} from "rxjs"
|
|
||||||
import {
|
|
||||||
delay,
|
|
||||||
switchMap,
|
|
||||||
tap,
|
|
||||||
filter,
|
|
||||||
withLatestFrom,
|
|
||||||
observeOn,
|
|
||||||
take,
|
|
||||||
shareReplay,
|
|
||||||
catchError,
|
|
||||||
map,
|
|
||||||
bufferCount,
|
|
||||||
distinctUntilKeyChanged,
|
|
||||||
mapTo,
|
|
||||||
startWith,
|
|
||||||
combineLatestWith,
|
|
||||||
distinctUntilChanged
|
|
||||||
} from "rxjs/operators"
|
|
||||||
|
|
||||||
import {
|
|
||||||
watchToggle,
|
|
||||||
setToggle,
|
|
||||||
getElements,
|
getElements,
|
||||||
|
watchLocationTarget,
|
||||||
watchMedia,
|
watchMedia,
|
||||||
watchDocument,
|
watchPrint,
|
||||||
watchLocation,
|
watchViewport
|
||||||
watchLocationHash,
|
} from "./browser"
|
||||||
watchViewport,
|
|
||||||
isLocalLocation,
|
|
||||||
setLocationHash,
|
|
||||||
watchLocationBase,
|
|
||||||
getElement
|
|
||||||
} from "browser"
|
|
||||||
import {
|
import {
|
||||||
|
mountContent,
|
||||||
|
mountDialog,
|
||||||
mountHeader,
|
mountHeader,
|
||||||
mountMain,
|
mountHeaderTitle,
|
||||||
mountNavigation,
|
|
||||||
mountSearch,
|
mountSearch,
|
||||||
|
mountSidebar,
|
||||||
|
mountSource,
|
||||||
mountTableOfContents,
|
mountTableOfContents,
|
||||||
mountTabs,
|
mountTabs,
|
||||||
useComponent,
|
watchHeader,
|
||||||
setupComponents,
|
watchMain
|
||||||
mountSearchQuery,
|
} from "./components"
|
||||||
mountSearchReset,
|
|
||||||
mountSearchResult
|
|
||||||
} from "components"
|
|
||||||
import {
|
import {
|
||||||
setupClipboard,
|
setupClipboardJS
|
||||||
setupDialog,
|
} from "./integrations"
|
||||||
setupKeyboard,
|
import { translation } from "./_"
|
||||||
setupInstantLoading,
|
|
||||||
setupSearchWorker,
|
|
||||||
SearchIndex,
|
|
||||||
SearchIndexPipeline
|
|
||||||
} from "integrations"
|
|
||||||
import {
|
|
||||||
patchCodeBlocks,
|
|
||||||
patchTables,
|
|
||||||
patchDetails,
|
|
||||||
patchScrollfix,
|
|
||||||
patchSource,
|
|
||||||
patchScripts
|
|
||||||
} from "patches"
|
|
||||||
import { isConfig } from "utilities"
|
|
||||||
|
|
||||||
/* ------------------------------------------------------------------------- */
|
/* ----------------------------------------------------------------------------
|
||||||
|
* Program
|
||||||
|
* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
/* Denote that JavaScript is available */
|
/* Yay, JavaScript is available */
|
||||||
document.documentElement.classList.remove("no-js")
|
document.documentElement.classList.remove("no-js")
|
||||||
document.documentElement.classList.add("js")
|
document.documentElement.classList.add("js")
|
||||||
|
|
||||||
/* Test for iOS */
|
/* Set up subjects */
|
||||||
if (navigator.userAgent.match(/(iPad|iPhone|iPod)/g))
|
const target$ = watchLocationTarget()
|
||||||
document.documentElement.classList.add("ios")
|
|
||||||
|
|
||||||
/**
|
/* Set up user interface observables */
|
||||||
* Set scroll lock
|
const viewport$ = watchViewport()
|
||||||
*
|
const tablet$ = watchMedia("(min-width: 960px)")
|
||||||
* @param el - Scrollable element
|
const screen$ = watchMedia("(min-width: 1220px)")
|
||||||
* @param value - Vertical offset
|
const print$ = watchPrint()
|
||||||
*/
|
|
||||||
export function setScrollLock(
|
// these elements MUST be available
|
||||||
el: HTMLElement, value: number
|
const header = getElementOrThrow("[data-md-component=header]")
|
||||||
): void {
|
const main = getElementOrThrow("[data-md-component=main]")
|
||||||
el.setAttribute("data-md-state", "lock")
|
|
||||||
el.style.top = `-${value}px`
|
const header$ = watchHeader(header)
|
||||||
}
|
const main$ = watchMain(main, { header$: header$, viewport$ })
|
||||||
|
|
||||||
/**
|
/* Setup Clipboard.js integration */
|
||||||
* Reset scroll lock
|
const message$ = new Subject<string>()
|
||||||
*
|
setupClipboardJS()
|
||||||
* @param el - Scrollable element
|
.subscribe(() => message$.next(translation("clipboard.copied")))
|
||||||
*/
|
|
||||||
export function resetScrollLock(
|
// TODO: watchElements + general mount function that takes a factory...
|
||||||
el: HTMLElement
|
// + a toggle function (optionally)
|
||||||
): void {
|
|
||||||
const value = -1 * parseInt(el.style.top, 10)
|
const app$ = merge(
|
||||||
el.removeAttribute("data-md-state")
|
|
||||||
el.style.top = ""
|
/* Content */
|
||||||
if (value)
|
...getElements("[data-md-component=content]")
|
||||||
window.scrollTo(0, value)
|
.map(child => mountContent(child, { target$, viewport$, print$ })),
|
||||||
}
|
|
||||||
|
/* Dialog */
|
||||||
/* ----------------------------------------------------------------------------
|
...getElements("[data-md-component=dialog]")
|
||||||
* Functions
|
.map(child => mountDialog(child, { message$ })),
|
||||||
* ------------------------------------------------------------------------- */
|
|
||||||
|
/* Header */
|
||||||
/**
|
...getElements("[data-md-component=header]")
|
||||||
* Initialize Material for MkDocs
|
.map(child => mountHeader(child, { viewport$, header$, main$ })),
|
||||||
*
|
|
||||||
* @param config - Configuration
|
/* Header title */
|
||||||
*/
|
...getElements("[data-md-component=header-title]")
|
||||||
export function initialize(config: unknown) {
|
.map(child => mountHeaderTitle(child, { viewport$, header$ })),
|
||||||
if (!isConfig(config))
|
|
||||||
throw new SyntaxError(`Invalid configuration: ${JSON.stringify(config)}`)
|
/* Search */
|
||||||
|
...getElements("[data-md-component=search]")
|
||||||
/* Set up subjects */
|
.map(child => mountSearch(child)),
|
||||||
const document$ = watchDocument()
|
|
||||||
const location$ = watchLocation()
|
/* Sidebar */
|
||||||
|
...getElements("[data-md-component=sidebar]")
|
||||||
/* Set up user interface observables */
|
.map(child => child.getAttribute("data-md-type") === "navigation"
|
||||||
const base$ = watchLocationBase(config.base, { location$ })
|
? at(screen$, () => mountSidebar(child, { viewport$, header$, main$ }))
|
||||||
const hash$ = watchLocationHash()
|
: at(tablet$, () => mountSidebar(child, { viewport$, header$, main$ }))
|
||||||
const viewport$ = watchViewport()
|
),
|
||||||
const tablet$ = watchMedia("(min-width: 960px)")
|
|
||||||
const screen$ = watchMedia("(min-width: 1220px)")
|
/* Repository information */
|
||||||
|
...getElements("[data-md-component=source]")
|
||||||
/* ----------------------------------------------------------------------- */
|
.map(child => mountSource(child as HTMLAnchorElement)),
|
||||||
|
|
||||||
/* Set up component bindings */
|
/* Navigation tabs */
|
||||||
setupComponents([
|
...getElements("[data-md-component=tabs]")
|
||||||
"announce", /* Announcement bar */
|
.map(child => mountTabs(child, { viewport$, header$ })),
|
||||||
"container", /* Container */
|
|
||||||
"header", /* Header */
|
/* Table of contents */
|
||||||
"header-title", /* Header title */
|
...getElements("[data-md-component=toc]")
|
||||||
"main", /* Main area */
|
.map(child => mountTableOfContents(child, { viewport$, header$ })),
|
||||||
"navigation", /* Navigation */
|
)
|
||||||
"search", /* Search */
|
|
||||||
"search-query", /* Search input */
|
app$.subscribe(console.log)
|
||||||
"search-reset", /* Search reset */
|
|
||||||
"search-result", /* Search results */
|
|
||||||
"skip", /* Skip link */
|
/* ------------------------------------------------------------------------- */
|
||||||
"tabs", /* Tabs */
|
|
||||||
"toc" /* Table of contents */
|
// put this somewhere else
|
||||||
], { document$ })
|
function at<T>(
|
||||||
|
toggle$: Observable<boolean>, factory: () => Observable<T>
|
||||||
const keyboard$ = setupKeyboard()
|
) {
|
||||||
|
return toggle$
|
||||||
// Hack: only make code blocks focusable on non-touch devices
|
.pipe(
|
||||||
if (matchMedia("(hover)").matches)
|
switchMap(active => active ? factory() : NEVER),
|
||||||
patchCodeBlocks({ document$, viewport$ })
|
)
|
||||||
patchDetails({ document$, hash$ })
|
|
||||||
patchScripts({ document$ })
|
|
||||||
patchSource({ document$ })
|
|
||||||
patchTables({ document$ })
|
|
||||||
|
|
||||||
/* Force 1px scroll offset to trigger overflow scrolling */
|
|
||||||
patchScrollfix({ document$ })
|
|
||||||
|
|
||||||
/* Set up clipboard and dialog */
|
|
||||||
const dialog$ = setupDialog()
|
|
||||||
const clipboard$ = setupClipboard({ document$, dialog$ })
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
/* Create header observable */
|
|
||||||
const header$ = useComponent("header")
|
|
||||||
.pipe(
|
|
||||||
mountHeader({ document$, viewport$ }),
|
|
||||||
shareReplay({ bufferSize: 1, refCount: true })
|
|
||||||
)
|
|
||||||
|
|
||||||
const main$ = useComponent("main")
|
|
||||||
.pipe(
|
|
||||||
mountMain({ header$, viewport$ }),
|
|
||||||
shareReplay({ bufferSize: 1, refCount: true })
|
|
||||||
)
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
const navigation$ = useComponent("navigation")
|
|
||||||
.pipe(
|
|
||||||
mountNavigation({ header$, main$, viewport$, screen$ }),
|
|
||||||
shareReplay({ bufferSize: 1, refCount: true }) // shareReplay because there might be late subscribers
|
|
||||||
)
|
|
||||||
|
|
||||||
const toc$ = useComponent("toc")
|
|
||||||
.pipe(
|
|
||||||
mountTableOfContents({ header$, main$, viewport$, tablet$ }),
|
|
||||||
shareReplay({ bufferSize: 1, refCount: true })
|
|
||||||
)
|
|
||||||
|
|
||||||
const tabs$ = useComponent("tabs")
|
|
||||||
.pipe(
|
|
||||||
mountTabs({ header$, viewport$, screen$ }),
|
|
||||||
shareReplay({ bufferSize: 1, refCount: true })
|
|
||||||
)
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
/* Search worker - only if search is present */
|
|
||||||
const worker$ = useComponent("search")
|
|
||||||
.pipe(
|
|
||||||
switchMap(() => defer(() => {
|
|
||||||
const index = config.search && config.search.index
|
|
||||||
? config.search.index
|
|
||||||
: undefined
|
|
||||||
|
|
||||||
/* Fetch index if it wasn't passed explicitly */
|
|
||||||
const index$ = (
|
|
||||||
typeof index !== "undefined"
|
|
||||||
? from(index)
|
|
||||||
: base$
|
|
||||||
.pipe(
|
|
||||||
switchMap(base => fetch(`${base}/search/search_index.json`, {
|
|
||||||
credentials: "same-origin"
|
|
||||||
}).then(res => res.json())) // SearchIndex
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
return of(setupSearchWorker(config.search.worker, {
|
|
||||||
base$, index$
|
|
||||||
}))
|
|
||||||
}))
|
|
||||||
)
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
/* Mount search query */
|
|
||||||
const search$ = worker$
|
|
||||||
.pipe(
|
|
||||||
switchMap(worker => {
|
|
||||||
const query$ = useComponent<HTMLInputElement>("search-query")
|
|
||||||
.pipe(
|
|
||||||
mountSearchQuery(worker, { transform: config.search.transform }),
|
|
||||||
shareReplay({ bufferSize: 1, refCount: true })
|
|
||||||
)
|
|
||||||
|
|
||||||
/* Mount search reset */
|
|
||||||
const reset$ = useComponent("search-reset")
|
|
||||||
.pipe(
|
|
||||||
mountSearchReset(),
|
|
||||||
shareReplay({ bufferSize: 1, refCount: true })
|
|
||||||
)
|
|
||||||
|
|
||||||
/* Mount search result */
|
|
||||||
const result$ = useComponent("search-result")
|
|
||||||
.pipe(
|
|
||||||
mountSearchResult(worker, { query$ }),
|
|
||||||
shareReplay({ bufferSize: 1, refCount: true })
|
|
||||||
)
|
|
||||||
|
|
||||||
return useComponent("search")
|
|
||||||
.pipe(
|
|
||||||
mountSearch(worker, { query$, reset$, result$ }),
|
|
||||||
)
|
|
||||||
}),
|
|
||||||
catchError(() => {
|
|
||||||
useComponent("search")
|
|
||||||
.subscribe(el => el.hidden = true) // TODO: Hack
|
|
||||||
return NEVER
|
|
||||||
}),
|
|
||||||
shareReplay({ bufferSize: 1, refCount: true })
|
|
||||||
)
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
// // put into search...
|
|
||||||
hash$
|
|
||||||
.pipe(
|
|
||||||
tap(() => setToggle("search", false)),
|
|
||||||
delay(125), // ensure that it runs after the body scroll reset...
|
|
||||||
)
|
|
||||||
.subscribe(hash => setLocationHash(`#${hash}`))
|
|
||||||
|
|
||||||
// TODO: scroll restoration must be centralized
|
|
||||||
combineLatest([
|
|
||||||
watchToggle("search"),
|
|
||||||
tablet$,
|
|
||||||
])
|
|
||||||
.pipe(
|
|
||||||
withLatestFrom(viewport$),
|
|
||||||
switchMap(([[toggle, tablet], { offset: { y }}]) => {
|
|
||||||
const active = toggle && !tablet
|
|
||||||
return document$
|
|
||||||
.pipe(
|
|
||||||
delay(active ? 400 : 100),
|
|
||||||
observeOn(animationFrameScheduler),
|
|
||||||
tap(({ body }) => active
|
|
||||||
? setScrollLock(body, y)
|
|
||||||
: resetScrollLock(body)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
})
|
|
||||||
)
|
|
||||||
.subscribe()
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
/* Always close drawer on click */
|
|
||||||
fromEvent<MouseEvent>(document.body, "click")
|
|
||||||
.pipe(
|
|
||||||
filter(ev => !(ev.metaKey || ev.ctrlKey)),
|
|
||||||
filter(ev => {
|
|
||||||
if (ev.target instanceof HTMLElement) {
|
|
||||||
const el = ev.target.closest("a") // TODO: abstract as link click?
|
|
||||||
if (el && isLocalLocation(el)) {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
})
|
|
||||||
)
|
|
||||||
.subscribe(() => {
|
|
||||||
setToggle("drawer", false)
|
|
||||||
})
|
|
||||||
|
|
||||||
/* Enable instant loading, if not on file:// protocol */
|
|
||||||
if (
|
|
||||||
config.features.includes("navigation.instant") &&
|
|
||||||
location.protocol !== "file:"
|
|
||||||
) {
|
|
||||||
const dom = new DOMParser()
|
|
||||||
|
|
||||||
/* Fetch sitemap and extract URL whitelist */
|
|
||||||
base$
|
|
||||||
.pipe(
|
|
||||||
switchMap(base => from(fetch(`${base}/sitemap.xml`)
|
|
||||||
.then(res => res.text())
|
|
||||||
.then(text => dom.parseFromString(text, "text/xml"))
|
|
||||||
)),
|
|
||||||
withLatestFrom(base$),
|
|
||||||
map(([document, base]) => {
|
|
||||||
const urls = getElements("loc", document)
|
|
||||||
.map(node => node.textContent!)
|
|
||||||
|
|
||||||
// Hack: This is a temporary fix to normalize instant loading lookup
|
|
||||||
// on localhost and Netlify previews. If this approach proves to be
|
|
||||||
// suitable, we'll refactor URL whitelisting anyway. We take the two
|
|
||||||
// shortest URLs and determine the common prefix to isolate the
|
|
||||||
// domain. If there're no two domains, we just leave it as-is, as
|
|
||||||
// there isn't anything to be loaded anway.
|
|
||||||
if (urls.length > 1) {
|
|
||||||
const [a, b] = urls.sort((a, b) => a.length - b.length)
|
|
||||||
|
|
||||||
/* Determine common prefix */
|
|
||||||
let index = 0
|
|
||||||
if (a === b)
|
|
||||||
index = a.length
|
|
||||||
else
|
|
||||||
while (a.charAt(index) === b.charAt(index))
|
|
||||||
index++
|
|
||||||
|
|
||||||
/* Replace common prefix (i.e. base) with effective base */
|
|
||||||
for (let i = 0; i < urls.length; i++)
|
|
||||||
urls[i] = urls[i].replace(a.slice(0, index), `${base}/`)
|
|
||||||
}
|
|
||||||
return urls
|
|
||||||
})
|
|
||||||
)
|
|
||||||
.subscribe(urls => {
|
|
||||||
setupInstantLoading(urls, { document$, location$, viewport$ })
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
// Make indeterminate toggles indeterminate to expand navigation on screen
|
|
||||||
document$.subscribe(() => {
|
|
||||||
const toggles = getElements<HTMLInputElement>("[data-md-state=indeterminate]")
|
|
||||||
for (const toggle of toggles) {
|
|
||||||
toggle.dataset.mdState = ""
|
|
||||||
toggle.indeterminate = true
|
|
||||||
toggle.checked = false
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
// Auto hide header - this is still experimental, so there might be some
|
|
||||||
// opportunities for refactoring, but we'll address them when this feature
|
|
||||||
// got some feedback from the community.
|
|
||||||
if (config.features.includes("header.autohide")) {
|
|
||||||
|
|
||||||
// Threshold for header-hiding - always show if scrolled less than 400px.
|
|
||||||
// Also, search is not allowed to be active. Maybe make this dynamic.
|
|
||||||
const threshold$ = viewport$
|
|
||||||
.pipe(
|
|
||||||
map(({ offset }) => offset.y > 400),
|
|
||||||
combineLatestWith(watchToggle("search")),
|
|
||||||
map(([threshold, search]) => threshold && !search),
|
|
||||||
distinctUntilChanged()
|
|
||||||
)
|
|
||||||
|
|
||||||
// Scroll direction (true = down, false = up) + inflection point
|
|
||||||
const direction$ = viewport$
|
|
||||||
.pipe(
|
|
||||||
map(({ offset }) => offset.y),
|
|
||||||
bufferCount(2, 1),
|
|
||||||
map(([a, b]) => [a < b, b] as const),
|
|
||||||
distinctUntilKeyChanged(0)
|
|
||||||
)
|
|
||||||
|
|
||||||
// When the threshold is exceeded, and the search is not active, subscribe
|
|
||||||
// to the direction observable (always do a new subscription), and track
|
|
||||||
// scroll progress.
|
|
||||||
const hide$ = threshold$
|
|
||||||
.pipe(
|
|
||||||
switchMap(active => !active
|
|
||||||
? of(false)
|
|
||||||
: direction$
|
|
||||||
.pipe(
|
|
||||||
combineLatestWith(viewport$),
|
|
||||||
filter(([[, y], { offset }]) => Math.abs(y - offset.y) > 100),
|
|
||||||
map(([[direction]]) => direction)
|
|
||||||
)
|
|
||||||
),
|
|
||||||
distinctUntilChanged()
|
|
||||||
)
|
|
||||||
|
|
||||||
// Set header state depending on main state. There's still some possibility
|
|
||||||
// for improvement, as the page seems to jump when focusing the unfocused
|
|
||||||
// search. This would mean we would need to delay the focus/change event
|
|
||||||
// until the header is focussed, which we need to address in a refactoring.
|
|
||||||
hide$
|
|
||||||
.pipe(
|
|
||||||
combineLatestWith(main$),
|
|
||||||
map(([hide, main]) => main.active
|
|
||||||
? hide ? "hidden" : "shadow"
|
|
||||||
: ""
|
|
||||||
),
|
|
||||||
combineLatestWith(useComponent("header"))
|
|
||||||
)
|
|
||||||
.subscribe(([state, el]) => {
|
|
||||||
el.setAttribute("data-md-state", state)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
const state = {
|
|
||||||
|
|
||||||
/* Browser observables */
|
|
||||||
document$,
|
|
||||||
location$,
|
|
||||||
viewport$,
|
|
||||||
|
|
||||||
/* Component observables */
|
|
||||||
header$,
|
|
||||||
main$,
|
|
||||||
navigation$,
|
|
||||||
search$,
|
|
||||||
tabs$,
|
|
||||||
toc$,
|
|
||||||
|
|
||||||
/* Integration observables */
|
|
||||||
clipboard$,
|
|
||||||
keyboard$,
|
|
||||||
dialog$
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Subscribe to all observables */
|
|
||||||
merge(...Object.values(state))
|
|
||||||
.subscribe()
|
|
||||||
return state
|
|
||||||
}
|
}
|
||||||
|
@ -20,75 +20,29 @@
|
|||||||
* IN THE SOFTWARE.
|
* IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import * as ClipboardJS from "clipboard"
|
import ClipboardJS from "clipboard"
|
||||||
import { NEVER, Observable, Subject } from "rxjs"
|
import { NEVER, Observable } from "rxjs"
|
||||||
import { mapTo, share, tap } from "rxjs/operators"
|
import { share } from "rxjs/operators"
|
||||||
|
|
||||||
import { getElements } from "browser"
|
|
||||||
import { renderClipboardButton } from "templates"
|
|
||||||
import { translate } from "utilities"
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------------
|
|
||||||
* Helper types
|
|
||||||
* ------------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Setup options
|
|
||||||
*/
|
|
||||||
interface SetupOptions {
|
|
||||||
document$: Observable<Document> /* Document observable */
|
|
||||||
dialog$: Subject<string> /* Dialog subject */
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------------
|
/* ----------------------------------------------------------------------------
|
||||||
* Functions
|
* Functions
|
||||||
* ------------------------------------------------------------------------- */
|
* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set up clipboard
|
* Set up Clipboard.js integration
|
||||||
*
|
*
|
||||||
* This function implements the Clipboard.js integration and injects a button
|
* @return Clipboard.js event observable
|
||||||
* into all code blocks when the document changes.
|
|
||||||
*
|
|
||||||
* @param options - Options
|
|
||||||
*
|
|
||||||
* @return Clipboard observable
|
|
||||||
*/
|
*/
|
||||||
export function setupClipboard(
|
export function setupClipboardJS(): Observable<ClipboardJS.Event> {
|
||||||
{ document$, dialog$ }: SetupOptions
|
|
||||||
): Observable<ClipboardJS.Event> {
|
|
||||||
if (!ClipboardJS.isSupported())
|
if (!ClipboardJS.isSupported())
|
||||||
return NEVER
|
return NEVER
|
||||||
|
|
||||||
/* Inject 'copy-to-clipboard' buttons */
|
/* Initialize Clipboard.js */
|
||||||
document$.subscribe(() => {
|
return new Observable<ClipboardJS.Event>(subscriber => {
|
||||||
const blocks = getElements("pre > code")
|
new ClipboardJS("[data-clipboard-target], [data-clipboard-text]")
|
||||||
blocks.forEach((block, index) => {
|
.on("success", ev => subscriber.next(ev))
|
||||||
const parent = block.parentElement!
|
|
||||||
parent.id = `__code_${index}`
|
|
||||||
parent.insertBefore(
|
|
||||||
renderClipboardButton(parent.id),
|
|
||||||
block
|
|
||||||
)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
/* Initialize clipboard */
|
|
||||||
const clipboard$ = new Observable<ClipboardJS.Event>(subscriber => {
|
|
||||||
new ClipboardJS(".md-clipboard").on("success", ev => subscriber.next(ev))
|
|
||||||
})
|
})
|
||||||
.pipe(
|
.pipe(
|
||||||
share()
|
share()
|
||||||
)
|
)
|
||||||
|
|
||||||
/* Display notification for clipboard event */
|
|
||||||
clipboard$
|
|
||||||
.pipe(
|
|
||||||
tap(ev => ev.clearSelection()),
|
|
||||||
mapTo(translate("clipboard.copied"))
|
|
||||||
)
|
|
||||||
.subscribe(dialog$)
|
|
||||||
|
|
||||||
/* Return clipboard */
|
|
||||||
return clipboard$
|
|
||||||
}
|
}
|
||||||
|
@ -1,91 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2016-2020 Martin Donath <martin.donath@squidfunk.com>
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to
|
|
||||||
* deal in the Software without restriction, including without limitation the
|
|
||||||
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
|
||||||
* sell copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in
|
|
||||||
* all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
||||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
|
||||||
* IN THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { Subject, animationFrameScheduler, noop, of } from "rxjs"
|
|
||||||
import {
|
|
||||||
delay,
|
|
||||||
map,
|
|
||||||
observeOn,
|
|
||||||
switchMap,
|
|
||||||
tap
|
|
||||||
} from "rxjs/operators"
|
|
||||||
|
|
||||||
import { createElement } from "browser"
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------------
|
|
||||||
* Types
|
|
||||||
* ------------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Setup options
|
|
||||||
*/
|
|
||||||
interface SetupOptions {
|
|
||||||
duration?: number /* Display duration (default: 2s) */
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------------
|
|
||||||
* Functions
|
|
||||||
* ------------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set up dialog
|
|
||||||
*
|
|
||||||
* @param options - Options
|
|
||||||
*
|
|
||||||
* @return Dialog observable
|
|
||||||
*/
|
|
||||||
export function setupDialog(
|
|
||||||
{ duration }: SetupOptions = {}
|
|
||||||
): Subject<string> {
|
|
||||||
const dialog$ = new Subject<string>()
|
|
||||||
|
|
||||||
/* Create dialog */
|
|
||||||
const dialog = createElement("div") // TODO: improve scoping
|
|
||||||
dialog.classList.add("md-dialog", "md-typeset")
|
|
||||||
|
|
||||||
/* Display dialog */
|
|
||||||
dialog$
|
|
||||||
.pipe(
|
|
||||||
switchMap(text => of(document.body) // useComponent("container")
|
|
||||||
.pipe(
|
|
||||||
map(container => container.appendChild(dialog)),
|
|
||||||
observeOn(animationFrameScheduler),
|
|
||||||
delay(1), // Strangley it doesnt work when we push things to the new animation frame...
|
|
||||||
tap(el => {
|
|
||||||
el.innerHTML = text
|
|
||||||
el.setAttribute("data-md-state", "open")
|
|
||||||
}),
|
|
||||||
delay(duration || 2000),
|
|
||||||
tap(el => el.removeAttribute("data-md-state")),
|
|
||||||
delay(400),
|
|
||||||
tap(el => {
|
|
||||||
el.innerHTML = ""
|
|
||||||
el.remove()
|
|
||||||
})
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
.subscribe(noop)
|
|
||||||
|
|
||||||
/* Return dialog */
|
|
||||||
return dialog$
|
|
||||||
}
|
|
@ -21,7 +21,4 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
export * from "./clipboard"
|
export * from "./clipboard"
|
||||||
export * from "./dialog"
|
|
||||||
export * from "./instant"
|
|
||||||
export * from "./keyboard"
|
|
||||||
export * from "./search"
|
export * from "./search"
|
||||||
|
@ -1,273 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2016-2020 Martin Donath <martin.donath@squidfunk.com>
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to
|
|
||||||
* deal in the Software without restriction, including without limitation the
|
|
||||||
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
|
||||||
* sell copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in
|
|
||||||
* all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
||||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
|
||||||
* IN THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { NEVER, Observable, Subject, from, fromEvent, merge, of } from "rxjs"
|
|
||||||
import {
|
|
||||||
bufferCount,
|
|
||||||
catchError,
|
|
||||||
debounceTime,
|
|
||||||
distinctUntilChanged,
|
|
||||||
distinctUntilKeyChanged,
|
|
||||||
filter,
|
|
||||||
map,
|
|
||||||
sample,
|
|
||||||
share,
|
|
||||||
skip,
|
|
||||||
switchMap
|
|
||||||
} from "rxjs/operators"
|
|
||||||
|
|
||||||
import {
|
|
||||||
Viewport,
|
|
||||||
ViewportOffset,
|
|
||||||
getElement,
|
|
||||||
isAnchorLocation,
|
|
||||||
isLocalLocation,
|
|
||||||
replaceElement,
|
|
||||||
setLocation,
|
|
||||||
setLocationHash,
|
|
||||||
setToggle,
|
|
||||||
setViewportOffset
|
|
||||||
} from "browser"
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------------
|
|
||||||
* Helper types
|
|
||||||
* ------------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* History state
|
|
||||||
*/
|
|
||||||
interface State {
|
|
||||||
url: URL /* State URL */
|
|
||||||
offset?: ViewportOffset /* State viewport offset */
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ------------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Setup options
|
|
||||||
*/
|
|
||||||
interface SetupOptions {
|
|
||||||
document$: Subject<Document> /* Document subject */
|
|
||||||
location$: Subject<URL> /* Location subject */
|
|
||||||
viewport$: Observable<Viewport> /* Viewport observable */
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------------
|
|
||||||
* Functions
|
|
||||||
* ------------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set up instant loading
|
|
||||||
*
|
|
||||||
* When fetching, theoretically, we could use `responseType: "document"`, but
|
|
||||||
* since all MkDocs links are relative, we need to make sure that the current
|
|
||||||
* location matches the document we just loaded. Otherwise any relative links
|
|
||||||
* in the document could use the old location.
|
|
||||||
*
|
|
||||||
* This is the reason why we need to synchronize history events and the process
|
|
||||||
* of fetching the document for navigation changes (except `popstate` events):
|
|
||||||
*
|
|
||||||
* 1. Fetch document via `XMLHTTPRequest`
|
|
||||||
* 2. Set new location via `history.pushState`
|
|
||||||
* 3. Parse and emit fetched document
|
|
||||||
*
|
|
||||||
* For `popstate` events, we must not use `history.pushState`, or the forward
|
|
||||||
* history will be irreversibly overwritten. In case the request fails, the
|
|
||||||
* location change is dispatched regularly.
|
|
||||||
*
|
|
||||||
* @param options - Options
|
|
||||||
*/
|
|
||||||
export function setupInstantLoading(
|
|
||||||
urls: string[], { document$, viewport$, location$ }: SetupOptions
|
|
||||||
): void {
|
|
||||||
|
|
||||||
/* Disable automatic scroll restoration */
|
|
||||||
if ("scrollRestoration" in history)
|
|
||||||
history.scrollRestoration = "manual"
|
|
||||||
|
|
||||||
/* Hack: ensure that reloads restore viewport offset */
|
|
||||||
fromEvent(window, "beforeunload")
|
|
||||||
.subscribe(() => {
|
|
||||||
history.scrollRestoration = "auto"
|
|
||||||
})
|
|
||||||
|
|
||||||
/* Hack: ensure absolute favicon link to omit 404s on document switch */
|
|
||||||
const favicon = getElement<HTMLLinkElement>(`link[rel="shortcut icon"]`)
|
|
||||||
if (typeof favicon !== "undefined")
|
|
||||||
favicon.href = favicon.href // tslint:disable-line no-self-assignment
|
|
||||||
|
|
||||||
/* Intercept link clicks and convert to state change */
|
|
||||||
const state$ = fromEvent<MouseEvent>(document.body, "click")
|
|
||||||
.pipe(
|
|
||||||
filter(ev => !(ev.metaKey || ev.ctrlKey)),
|
|
||||||
switchMap(ev => {
|
|
||||||
if (ev.target instanceof HTMLElement) {
|
|
||||||
const el = ev.target.closest("a")
|
|
||||||
if (
|
|
||||||
el && !el.target &&
|
|
||||||
isLocalLocation(el) &&
|
|
||||||
urls.includes(el.href)
|
|
||||||
) {
|
|
||||||
if (!isAnchorLocation(el))
|
|
||||||
ev.preventDefault()
|
|
||||||
return of(el)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return NEVER
|
|
||||||
}),
|
|
||||||
map(el => ({ url: new URL(el.href) })),
|
|
||||||
share<State>()
|
|
||||||
)
|
|
||||||
|
|
||||||
/* Always close search on link click */
|
|
||||||
state$.subscribe(() => {
|
|
||||||
setToggle("search", false)
|
|
||||||
})
|
|
||||||
|
|
||||||
/* Filter state changes to dispatch */
|
|
||||||
const push$ = state$
|
|
||||||
.pipe(
|
|
||||||
filter(({ url }) => !isAnchorLocation(url)),
|
|
||||||
share()
|
|
||||||
)
|
|
||||||
|
|
||||||
/* Intercept popstate events (history back and forward) */
|
|
||||||
const pop$ = fromEvent<PopStateEvent>(window, "popstate")
|
|
||||||
.pipe(
|
|
||||||
filter(ev => ev.state !== null),
|
|
||||||
map(ev => ({
|
|
||||||
url: new URL(location.href),
|
|
||||||
offset: ev.state
|
|
||||||
})),
|
|
||||||
share<State>()
|
|
||||||
)
|
|
||||||
|
|
||||||
/* Emit location change */
|
|
||||||
merge(push$, pop$)
|
|
||||||
.pipe(
|
|
||||||
distinctUntilChanged((prev, next) => prev.url.href === next.url.href),
|
|
||||||
map(({ url }) => url)
|
|
||||||
)
|
|
||||||
.subscribe(location$)
|
|
||||||
|
|
||||||
/* Fetch document on location change */
|
|
||||||
const ajax$ = location$
|
|
||||||
.pipe(
|
|
||||||
distinctUntilKeyChanged("pathname"),
|
|
||||||
skip(1),
|
|
||||||
switchMap(url => from(fetch(url.href, {
|
|
||||||
credentials: "same-origin"
|
|
||||||
}).then(res => res.text()))
|
|
||||||
.pipe(
|
|
||||||
catchError(() => {
|
|
||||||
setLocation(url)
|
|
||||||
return NEVER
|
|
||||||
})
|
|
||||||
)
|
|
||||||
),
|
|
||||||
share()
|
|
||||||
)
|
|
||||||
|
|
||||||
/* Set new location as soon as the document was fetched */
|
|
||||||
push$
|
|
||||||
.pipe(
|
|
||||||
sample(ajax$)
|
|
||||||
)
|
|
||||||
.subscribe(({ url }) => {
|
|
||||||
history.pushState({}, "", url.toString())
|
|
||||||
})
|
|
||||||
|
|
||||||
/* Parse and emit document */
|
|
||||||
const dom = new DOMParser()
|
|
||||||
ajax$
|
|
||||||
.pipe(
|
|
||||||
map(response => dom.parseFromString(response, "text/html"))
|
|
||||||
)
|
|
||||||
.subscribe(document$)
|
|
||||||
|
|
||||||
/* Intercept instant loading */
|
|
||||||
const instant$ = merge(push$, pop$)
|
|
||||||
.pipe(
|
|
||||||
sample(document$)
|
|
||||||
)
|
|
||||||
|
|
||||||
// TODO: this must be combined with search scroll restoration on mobile
|
|
||||||
instant$.subscribe(({ url, offset }) => {
|
|
||||||
if (url.hash && !offset) {
|
|
||||||
setLocationHash(url.hash)
|
|
||||||
} else {
|
|
||||||
setViewportOffset(offset || { y: 0 })
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
/* Replace document metadata */
|
|
||||||
document$
|
|
||||||
.pipe(
|
|
||||||
skip(1) // Skip initial
|
|
||||||
)
|
|
||||||
.subscribe(({ title, head }) => {
|
|
||||||
document.title = title
|
|
||||||
|
|
||||||
/* Replace meta tags */
|
|
||||||
for (const selector of [
|
|
||||||
`link[rel="canonical"]`,
|
|
||||||
`meta[name="author"]`,
|
|
||||||
`meta[name="description"]`
|
|
||||||
]) {
|
|
||||||
const next = getElement(selector, head)
|
|
||||||
const prev = getElement(selector, document.head)
|
|
||||||
if (
|
|
||||||
typeof next !== "undefined" &&
|
|
||||||
typeof prev !== "undefined"
|
|
||||||
) {
|
|
||||||
replaceElement(prev, next)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Finished, dispatch document switch event */
|
|
||||||
document.dispatchEvent(new CustomEvent("DOMContentSwitch"))
|
|
||||||
})
|
|
||||||
|
|
||||||
/* Debounce update of viewport offset */
|
|
||||||
viewport$
|
|
||||||
.pipe(
|
|
||||||
debounceTime(250),
|
|
||||||
distinctUntilKeyChanged("offset")
|
|
||||||
)
|
|
||||||
.subscribe(({ offset }) => {
|
|
||||||
history.replaceState(offset, "")
|
|
||||||
})
|
|
||||||
|
|
||||||
/* Set viewport offset from history */
|
|
||||||
merge(state$, pop$)
|
|
||||||
.pipe(
|
|
||||||
bufferCount(2, 1),
|
|
||||||
filter(([prev, next]) => {
|
|
||||||
return prev.url.pathname === next.url.pathname
|
|
||||||
&& !isAnchorLocation(next.url)
|
|
||||||
}),
|
|
||||||
map(([, state]) => state)
|
|
||||||
)
|
|
||||||
.subscribe(({ offset }) => {
|
|
||||||
setViewportOffset(offset || { y: 0 })
|
|
||||||
})
|
|
||||||
}
|
|
@ -1,199 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2016-2020 Martin Donath <martin.donath@squidfunk.com>
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to
|
|
||||||
* deal in the Software without restriction, including without limitation the
|
|
||||||
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
|
||||||
* sell copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in
|
|
||||||
* all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
||||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
|
||||||
* IN THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { Observable } from "rxjs"
|
|
||||||
import {
|
|
||||||
filter,
|
|
||||||
map,
|
|
||||||
share,
|
|
||||||
withLatestFrom
|
|
||||||
} from "rxjs/operators"
|
|
||||||
|
|
||||||
import {
|
|
||||||
Key,
|
|
||||||
getActiveElement,
|
|
||||||
getElement,
|
|
||||||
getElements,
|
|
||||||
getToggle,
|
|
||||||
isSusceptibleToKeyboard,
|
|
||||||
setElementFocus,
|
|
||||||
setElementSelection,
|
|
||||||
setToggle,
|
|
||||||
watchKeyboard
|
|
||||||
} from "browser"
|
|
||||||
import { useComponent } from "components"
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------------
|
|
||||||
* Types
|
|
||||||
* ------------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Keyboard mode
|
|
||||||
*/
|
|
||||||
export type KeyboardMode =
|
|
||||||
| "global" /* Global */
|
|
||||||
| "search" /* Search is open */
|
|
||||||
|
|
||||||
/* ------------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Keyboard
|
|
||||||
*/
|
|
||||||
export interface Keyboard extends Key {
|
|
||||||
mode: KeyboardMode /* Keyboard mode */
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------------
|
|
||||||
* Functions
|
|
||||||
* ------------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set up keyboard
|
|
||||||
*
|
|
||||||
* This function will set up the keyboard handlers and ensure that keys are
|
|
||||||
* correctly propagated. Currently there are two modes:
|
|
||||||
*
|
|
||||||
* - `global`: This mode is active when the search is closed. It is intended
|
|
||||||
* to assign hotkeys to specific functions of the site. Currently the search,
|
|
||||||
* previous and next page can be triggered.
|
|
||||||
*
|
|
||||||
* - `search`: This mode is active when the search is open. It maps certain
|
|
||||||
* navigational keys to offer search results that can be entirely navigated
|
|
||||||
* through keyboard input.
|
|
||||||
*
|
|
||||||
* The keyboard observable is returned and can be used to monitor the keyboard
|
|
||||||
* in order toassign further hotkeys to custom functions.
|
|
||||||
*
|
|
||||||
* @return Keyboard observable
|
|
||||||
*/
|
|
||||||
export function setupKeyboard(): Observable<Keyboard> {
|
|
||||||
const keyboard$ = watchKeyboard()
|
|
||||||
.pipe(
|
|
||||||
map<Key, Keyboard>(key => ({
|
|
||||||
mode: getToggle("search") ? "search" : "global",
|
|
||||||
...key
|
|
||||||
})),
|
|
||||||
filter(({ mode }) => {
|
|
||||||
if (mode === "global") {
|
|
||||||
const active = getActiveElement()
|
|
||||||
if (typeof active !== "undefined")
|
|
||||||
return !isSusceptibleToKeyboard(active)
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}),
|
|
||||||
share()
|
|
||||||
)
|
|
||||||
|
|
||||||
/* Set up search keyboard handlers */
|
|
||||||
keyboard$
|
|
||||||
.pipe(
|
|
||||||
filter(({ mode }) => mode === "search"),
|
|
||||||
withLatestFrom(
|
|
||||||
useComponent("search-query"),
|
|
||||||
useComponent("search-result")
|
|
||||||
)
|
|
||||||
)
|
|
||||||
.subscribe(([key, query, result]) => {
|
|
||||||
const active = getActiveElement()
|
|
||||||
switch (key.type) {
|
|
||||||
|
|
||||||
/* Enter: prevent form submission */
|
|
||||||
case "Enter":
|
|
||||||
if (active === query)
|
|
||||||
key.claim()
|
|
||||||
break
|
|
||||||
|
|
||||||
/* Escape or Tab: close search */
|
|
||||||
case "Escape":
|
|
||||||
case "Tab":
|
|
||||||
setToggle("search", false)
|
|
||||||
setElementFocus(query, false)
|
|
||||||
break
|
|
||||||
|
|
||||||
/* Vertical arrows: select previous or next search result */
|
|
||||||
case "ArrowUp":
|
|
||||||
case "ArrowDown":
|
|
||||||
if (typeof active === "undefined") {
|
|
||||||
setElementFocus(query)
|
|
||||||
} else {
|
|
||||||
const els = [query, ...getElements(
|
|
||||||
":not(details) > [href], summary, details[open] [href]",
|
|
||||||
result
|
|
||||||
)]
|
|
||||||
const i = Math.max(0, (
|
|
||||||
Math.max(0, els.indexOf(active)) + els.length + (
|
|
||||||
key.type === "ArrowUp" ? -1 : +1
|
|
||||||
)
|
|
||||||
) % els.length)
|
|
||||||
setElementFocus(els[i])
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Prevent scrolling of page */
|
|
||||||
key.claim()
|
|
||||||
break
|
|
||||||
|
|
||||||
/* All other keys: hand to search query */
|
|
||||||
default:
|
|
||||||
if (query !== getActiveElement())
|
|
||||||
setElementFocus(query)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
/* Set up global keyboard handlers */
|
|
||||||
keyboard$
|
|
||||||
.pipe(
|
|
||||||
filter(({ mode }) => mode === "global"),
|
|
||||||
withLatestFrom(useComponent("search-query"))
|
|
||||||
)
|
|
||||||
.subscribe(([key, query]) => {
|
|
||||||
switch (key.type) {
|
|
||||||
|
|
||||||
/* Open search and select query */
|
|
||||||
case "f":
|
|
||||||
case "s":
|
|
||||||
case "/":
|
|
||||||
setElementFocus(query)
|
|
||||||
setElementSelection(query)
|
|
||||||
key.claim()
|
|
||||||
break
|
|
||||||
|
|
||||||
/* Go to previous page */
|
|
||||||
case "p":
|
|
||||||
case ",":
|
|
||||||
const prev = getElement("[href][rel=prev]")
|
|
||||||
if (typeof prev !== "undefined")
|
|
||||||
prev.click()
|
|
||||||
break
|
|
||||||
|
|
||||||
/* Go to next page */
|
|
||||||
case "n":
|
|
||||||
case ".":
|
|
||||||
const next = getElement("[href][rel=next]")
|
|
||||||
if (typeof next !== "undefined")
|
|
||||||
next.click()
|
|
||||||
break
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
/* Return keyboard */
|
|
||||||
return keyboard$
|
|
||||||
}
|
|
@ -101,9 +101,7 @@ export interface SearchMetadata {
|
|||||||
/**
|
/**
|
||||||
* Search result
|
* Search result
|
||||||
*/
|
*/
|
||||||
export type SearchResult = Array<
|
export type SearchResult = Array<SearchDocument & SearchMetadata>
|
||||||
SearchDocument & SearchMetadata
|
|
||||||
> // tslint:disable-line
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------------
|
/* ----------------------------------------------------------------------------
|
||||||
* Functions
|
* Functions
|
||||||
|
@ -20,8 +20,7 @@
|
|||||||
* IN THE SOFTWARE.
|
* IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// @ts-ignore
|
import escapeHTML from "escape-html"
|
||||||
import * as escapeHTML from "escape-html"
|
|
||||||
|
|
||||||
import { SearchIndexDocument } from "../_"
|
import { SearchIndexDocument } from "../_"
|
||||||
|
|
||||||
|
@ -21,15 +21,10 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { Observable, Subject, asyncScheduler } from "rxjs"
|
import { Observable, Subject, asyncScheduler } from "rxjs"
|
||||||
import {
|
import { map, observeOn, share } from "rxjs/operators"
|
||||||
map,
|
|
||||||
observeOn,
|
|
||||||
share,
|
|
||||||
withLatestFrom
|
|
||||||
} from "rxjs/operators"
|
|
||||||
|
|
||||||
import { WorkerHandler, watchWorker } from "browser"
|
import { configuration, translation } from "~/_"
|
||||||
import { translate } from "utilities"
|
import { WorkerHandler, watchWorker } from "~/browser"
|
||||||
|
|
||||||
import { SearchIndex, SearchIndexPipeline } from "../../_"
|
import { SearchIndex, SearchIndexPipeline } from "../../_"
|
||||||
import {
|
import {
|
||||||
@ -39,6 +34,15 @@ import {
|
|||||||
isSearchResultMessage
|
isSearchResultMessage
|
||||||
} from "../message"
|
} from "../message"
|
||||||
|
|
||||||
|
/* ----------------------------------------------------------------------------
|
||||||
|
* Types
|
||||||
|
* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Search worker
|
||||||
|
*/
|
||||||
|
export type SearchWorker = WorkerHandler<SearchMessage>
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------------
|
/* ----------------------------------------------------------------------------
|
||||||
* Helper types
|
* Helper types
|
||||||
* ------------------------------------------------------------------------- */
|
* ------------------------------------------------------------------------- */
|
||||||
@ -48,11 +52,10 @@ import {
|
|||||||
*/
|
*/
|
||||||
interface SetupOptions {
|
interface SetupOptions {
|
||||||
index$: Observable<SearchIndex> /* Search index observable */
|
index$: Observable<SearchIndex> /* Search index observable */
|
||||||
base$: Observable<string> /* Location base observable */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------------
|
/* ----------------------------------------------------------------------------
|
||||||
* Functions
|
* Helper functions
|
||||||
* ------------------------------------------------------------------------- */
|
* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -68,14 +71,16 @@ function setupSearchIndex(
|
|||||||
|
|
||||||
/* Override default language with value from translation */
|
/* Override default language with value from translation */
|
||||||
if (config.lang.length === 1 && config.lang[0] === "en")
|
if (config.lang.length === 1 && config.lang[0] === "en")
|
||||||
config.lang = [translate("search.config.lang")]
|
config.lang = [
|
||||||
|
translation("search.config.lang")
|
||||||
|
]
|
||||||
|
|
||||||
/* Override default separator with value from translation */
|
/* Override default separator with value from translation */
|
||||||
if (config.separator === "[\\s\\-]+")
|
if (config.separator === "[\\s\\-]+")
|
||||||
config.separator = translate("search.config.separator")
|
config.separator = translation("search.config.separator")
|
||||||
|
|
||||||
/* Set pipeline from translation */
|
/* Set pipeline from translation */
|
||||||
const pipeline = translate("search.config.pipeline")
|
const pipeline = translation("search.config.pipeline")
|
||||||
.split(/\s*,\s*/)
|
.split(/\s*,\s*/)
|
||||||
.filter(Boolean) as SearchIndexPipeline
|
.filter(Boolean) as SearchIndexPipeline
|
||||||
|
|
||||||
@ -84,7 +89,7 @@ function setupSearchIndex(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------------
|
/* ----------------------------------------------------------------------------
|
||||||
* Helper functions
|
* Functions
|
||||||
* ------------------------------------------------------------------------- */
|
* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -97,23 +102,23 @@ function setupSearchIndex(
|
|||||||
* @param url - Worker URL
|
* @param url - Worker URL
|
||||||
* @param options - Options
|
* @param options - Options
|
||||||
*
|
*
|
||||||
* @return Worker handler
|
* @return Search worker
|
||||||
*/
|
*/
|
||||||
export function setupSearchWorker(
|
export function setupSearchWorker(
|
||||||
url: string, { index$, base$ }: SetupOptions
|
url: string, { index$ }: SetupOptions
|
||||||
): WorkerHandler<SearchMessage> {
|
): SearchWorker {
|
||||||
|
const config = configuration()
|
||||||
const worker = new Worker(url)
|
const worker = new Worker(url)
|
||||||
|
|
||||||
/* Create communication channels and resolve relative links */
|
/* Create communication channels and resolve relative links */
|
||||||
const tx$ = new Subject<SearchMessage>()
|
const tx$ = new Subject<SearchMessage>()
|
||||||
const rx$ = watchWorker(worker, { tx$ })
|
const rx$ = watchWorker(worker, { tx$ })
|
||||||
.pipe(
|
.pipe(
|
||||||
withLatestFrom(base$),
|
map(message => {
|
||||||
map(([message, base]) => {
|
|
||||||
if (isSearchResultMessage(message)) {
|
if (isSearchResultMessage(message)) {
|
||||||
for (const result of message.data)
|
for (const result of message.data)
|
||||||
for (const document of result)
|
for (const document of result)
|
||||||
document.location = `${base}/${document.location}`
|
document.location = `${config.base}/${document.location}`
|
||||||
}
|
}
|
||||||
return message
|
return message
|
||||||
}),
|
}),
|
||||||
@ -131,6 +136,6 @@ export function setupSearchWorker(
|
|||||||
)
|
)
|
||||||
.subscribe(tx$.next.bind(tx$))
|
.subscribe(tx$.next.bind(tx$))
|
||||||
|
|
||||||
/* Return worker handler */
|
/* Return search worker */
|
||||||
return { tx$, rx$ }
|
return { tx$, rx$ }
|
||||||
}
|
}
|
||||||
|
@ -1,94 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2016-2020 Martin Donath <martin.donath@squidfunk.com>
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to
|
|
||||||
* deal in the Software without restriction, including without limitation the
|
|
||||||
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
|
||||||
* sell copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in
|
|
||||||
* all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
||||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
|
||||||
* IN THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { Observable, fromEvent, merge } from "rxjs"
|
|
||||||
import {
|
|
||||||
filter,
|
|
||||||
map,
|
|
||||||
switchMapTo,
|
|
||||||
tap
|
|
||||||
} from "rxjs/operators"
|
|
||||||
|
|
||||||
import {
|
|
||||||
getElement,
|
|
||||||
getElements,
|
|
||||||
watchMedia
|
|
||||||
} from "browser"
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------------
|
|
||||||
* Helper types
|
|
||||||
* ------------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Patch options
|
|
||||||
*/
|
|
||||||
interface PatchOptions {
|
|
||||||
document$: Observable<Document> /* Document observable */
|
|
||||||
hash$: Observable<string> /* Location hash observable */
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------------
|
|
||||||
* Functions
|
|
||||||
* ------------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Patch all `details` elements
|
|
||||||
*
|
|
||||||
* This function will ensure that all `details` tags are opened prior to
|
|
||||||
* printing, so the whole content of the page is included, and on anchor jumps.
|
|
||||||
*
|
|
||||||
* @param options - Options
|
|
||||||
*/
|
|
||||||
export function patchDetails(
|
|
||||||
{ document$, hash$ }: PatchOptions
|
|
||||||
): void {
|
|
||||||
const els$ = document$
|
|
||||||
.pipe(
|
|
||||||
map(() => getElements<HTMLDetailsElement>("details"))
|
|
||||||
)
|
|
||||||
|
|
||||||
/* Open all details before printing */
|
|
||||||
merge(
|
|
||||||
watchMedia("print").pipe(filter(Boolean)), /* Webkit */
|
|
||||||
fromEvent(window, "beforeprint") /* IE, FF */
|
|
||||||
)
|
|
||||||
.pipe(
|
|
||||||
switchMapTo(els$)
|
|
||||||
)
|
|
||||||
.subscribe(els => {
|
|
||||||
for (const el of els)
|
|
||||||
el.setAttribute("open", "")
|
|
||||||
})
|
|
||||||
|
|
||||||
/* Open parent details and fix anchor jump */
|
|
||||||
hash$
|
|
||||||
.pipe(
|
|
||||||
map(id => getElement(`[id="${id}"]`)!),
|
|
||||||
filter(el => typeof el !== "undefined"),
|
|
||||||
tap(el => {
|
|
||||||
const details = el.closest("details")
|
|
||||||
if (details && !details.open)
|
|
||||||
details.setAttribute("open", "")
|
|
||||||
})
|
|
||||||
)
|
|
||||||
.subscribe(el => el.scrollIntoView())
|
|
||||||
}
|
|
@ -1,96 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2016-2020 Martin Donath <martin.donath@squidfunk.com>
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to
|
|
||||||
* deal in the Software without restriction, including without limitation the
|
|
||||||
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
|
||||||
* sell copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in
|
|
||||||
* all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
||||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
|
||||||
* IN THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { EMPTY, Observable, noop, of } from "rxjs"
|
|
||||||
import {
|
|
||||||
concatMap,
|
|
||||||
map,
|
|
||||||
skip,
|
|
||||||
switchMap,
|
|
||||||
withLatestFrom
|
|
||||||
} from "rxjs/operators"
|
|
||||||
|
|
||||||
import {
|
|
||||||
createElement,
|
|
||||||
getElements,
|
|
||||||
replaceElement
|
|
||||||
} from "browser"
|
|
||||||
import { useComponent } from "components"
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------------
|
|
||||||
* Helper types
|
|
||||||
* ------------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Patch options
|
|
||||||
*/
|
|
||||||
interface PatchOptions {
|
|
||||||
document$: Observable<Document> /* Document observable */
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------------
|
|
||||||
* Functions
|
|
||||||
* ------------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Patch all `script` elements
|
|
||||||
*
|
|
||||||
* This function must be run after a document switch, which means the first
|
|
||||||
* emission must be ignored.
|
|
||||||
*
|
|
||||||
* @param options - Options
|
|
||||||
*/
|
|
||||||
export function patchScripts(
|
|
||||||
{ document$ }: PatchOptions
|
|
||||||
): void {
|
|
||||||
const els$ = document$
|
|
||||||
.pipe(
|
|
||||||
skip(1),
|
|
||||||
withLatestFrom(useComponent("container")),
|
|
||||||
map(([, el]) => getElements<HTMLScriptElement>("script", el))
|
|
||||||
)
|
|
||||||
|
|
||||||
/* Evaluate all scripts via replacement in order */
|
|
||||||
els$
|
|
||||||
.pipe(
|
|
||||||
switchMap(els => of(...els)),
|
|
||||||
concatMap(el => {
|
|
||||||
const script = createElement("script")
|
|
||||||
if (el.src) {
|
|
||||||
script.src = el.src
|
|
||||||
replaceElement(el, script)
|
|
||||||
|
|
||||||
/* Complete when script is loaded */
|
|
||||||
return new Observable(observer => {
|
|
||||||
script.onload = () => observer.complete()
|
|
||||||
})
|
|
||||||
|
|
||||||
/* Complete immediately */
|
|
||||||
} else {
|
|
||||||
script.textContent = el.textContent!
|
|
||||||
replaceElement(el, script)
|
|
||||||
return EMPTY
|
|
||||||
}
|
|
||||||
})
|
|
||||||
)
|
|
||||||
.subscribe(noop)
|
|
||||||
}
|
|
@ -1,104 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2016-2020 Martin Donath <martin.donath@squidfunk.com>
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to
|
|
||||||
* deal in the Software without restriction, including without limitation the
|
|
||||||
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
|
||||||
* sell copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in
|
|
||||||
* all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
||||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
|
||||||
* IN THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { NEVER, Observable, fromEvent, iif, merge } from "rxjs"
|
|
||||||
import { map, mapTo, shareReplay, switchMap } from "rxjs/operators"
|
|
||||||
|
|
||||||
import { getElements } from "browser"
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------------
|
|
||||||
* Helper types
|
|
||||||
* ------------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Patch options
|
|
||||||
*/
|
|
||||||
interface PatchOptions {
|
|
||||||
document$: Observable<Document> /* Document observable */
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------------
|
|
||||||
* Helper functions
|
|
||||||
* ------------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Check whether the given device is an Apple device
|
|
||||||
*
|
|
||||||
* @return Test result
|
|
||||||
*/
|
|
||||||
function isAppleDevice(): boolean {
|
|
||||||
return /(iPad|iPhone|iPod)/.test(navigator.userAgent)
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------------
|
|
||||||
* Functions
|
|
||||||
* ------------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Patch all elements with `data-md-scrollfix` attributes
|
|
||||||
*
|
|
||||||
* This is a year-old patch which ensures that overflow scrolling works at the
|
|
||||||
* top and bottom of containers on iOS by ensuring a `1px` scroll offset upon
|
|
||||||
* the start of a touch event.
|
|
||||||
*
|
|
||||||
* @see https://bit.ly/2SCtAOO - Original source
|
|
||||||
*
|
|
||||||
* @param options - Options
|
|
||||||
*/
|
|
||||||
export function patchScrollfix(
|
|
||||||
{ document$ }: PatchOptions
|
|
||||||
): void {
|
|
||||||
const els$ = document$
|
|
||||||
.pipe(
|
|
||||||
map(() => getElements("[data-md-scrollfix]")),
|
|
||||||
shareReplay({ bufferSize: 1, refCount: true })
|
|
||||||
)
|
|
||||||
|
|
||||||
/* Remove marker attribute, so we'll only add the fix once */
|
|
||||||
els$.subscribe(els => {
|
|
||||||
for (const el of els)
|
|
||||||
el.removeAttribute("data-md-scrollfix")
|
|
||||||
})
|
|
||||||
|
|
||||||
/* Patch overflow scrolling on touch start */
|
|
||||||
iif(isAppleDevice, els$, NEVER)
|
|
||||||
.pipe(
|
|
||||||
switchMap(els => merge(...els.map(el => (
|
|
||||||
fromEvent(el, "touchstart")
|
|
||||||
.pipe(
|
|
||||||
mapTo(el)
|
|
||||||
)
|
|
||||||
))))
|
|
||||||
)
|
|
||||||
.subscribe(el => {
|
|
||||||
const top = el.scrollTop
|
|
||||||
|
|
||||||
/* We're at the top of the container */
|
|
||||||
if (top === 0) {
|
|
||||||
el.scrollTop = 1
|
|
||||||
|
|
||||||
/* We're at the bottom of the container */
|
|
||||||
} else if (top + el.offsetHeight === el.scrollHeight) {
|
|
||||||
el.scrollTop = top - 1
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
@ -1,118 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2016-2020 Martin Donath <martin.donath@squidfunk.com>
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to
|
|
||||||
* deal in the Software without restriction, including without limitation the
|
|
||||||
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
|
||||||
* sell copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in
|
|
||||||
* all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
||||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
|
||||||
* IN THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { NEVER, Observable } from "rxjs"
|
|
||||||
import { catchError, filter, map, switchMap } from "rxjs/operators"
|
|
||||||
|
|
||||||
import { getElementOrThrow, getElements } from "browser"
|
|
||||||
import { renderSource } from "templates"
|
|
||||||
import { cache, hash } from "utilities"
|
|
||||||
|
|
||||||
import { fetchSourceFactsFromGitHub } from "./github"
|
|
||||||
import { fetchSourceFactsFromGitLab } from "./gitlab"
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------------
|
|
||||||
* Types
|
|
||||||
* ------------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Source facts
|
|
||||||
*/
|
|
||||||
export type SourceFacts = string[]
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------------
|
|
||||||
* Helper types
|
|
||||||
* ------------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Patch options
|
|
||||||
*/
|
|
||||||
interface PatchOptions {
|
|
||||||
document$: Observable<Document> /* Document observable */
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------------
|
|
||||||
* Helper functions
|
|
||||||
* ------------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Fetch source facts
|
|
||||||
*
|
|
||||||
* @param url - Source repository URL
|
|
||||||
*
|
|
||||||
* @return Source facts observable
|
|
||||||
*/
|
|
||||||
function fetchSourceFacts(
|
|
||||||
url: string
|
|
||||||
): Observable<SourceFacts> {
|
|
||||||
const [type] = url.match(/(git(?:hub|lab))/i) || []
|
|
||||||
switch (type.toLowerCase()) {
|
|
||||||
|
|
||||||
/* GitHub repository */
|
|
||||||
case "github":
|
|
||||||
const [, user, repo] = url.match(/^.+github\.com\/([^\/]+)\/?([^\/]+)?/i)!
|
|
||||||
return fetchSourceFactsFromGitHub(user, repo)
|
|
||||||
|
|
||||||
/* GitLab repository */
|
|
||||||
case "gitlab":
|
|
||||||
const [, base, slug] = url.match(/^.+?([^\/]*gitlab[^\/]+)\/(.+?)\/?$/i)!
|
|
||||||
return fetchSourceFactsFromGitLab(base, slug)
|
|
||||||
|
|
||||||
/* Everything else */
|
|
||||||
default:
|
|
||||||
return NEVER
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------------
|
|
||||||
* Functions
|
|
||||||
* ------------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Patch elements containing repository information
|
|
||||||
*
|
|
||||||
* This function will retrieve the URL from the repository link and try to
|
|
||||||
* query data from integrated source code platforms like GitHub or GitLab.
|
|
||||||
*
|
|
||||||
* @param options - Options
|
|
||||||
*/
|
|
||||||
export function patchSource(
|
|
||||||
{ document$ }: PatchOptions
|
|
||||||
): void {
|
|
||||||
document$
|
|
||||||
.pipe(
|
|
||||||
map(() => getElementOrThrow<HTMLAnchorElement>(".md-source[href]")),
|
|
||||||
switchMap(({ href }) => (
|
|
||||||
cache(`${hash(href)}`, () => fetchSourceFacts(href))
|
|
||||||
)),
|
|
||||||
filter(facts => facts.length > 0),
|
|
||||||
catchError(() => NEVER)
|
|
||||||
)
|
|
||||||
.subscribe(facts => {
|
|
||||||
for (const el of getElements(".md-source__repository")) {
|
|
||||||
if (!el.hasAttribute("data-md-state")) {
|
|
||||||
el.setAttribute("data-md-state", "done")
|
|
||||||
el.appendChild(renderSource(facts))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
@ -20,7 +20,8 @@
|
|||||||
* IN THE SOFTWARE.
|
* IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { h, translate } from "utilities"
|
import { translation } from "~/_"
|
||||||
|
import { h } from "~/utilities"
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------------
|
/* ----------------------------------------------------------------------------
|
||||||
* Functions
|
* Functions
|
||||||
@ -37,7 +38,7 @@ export function renderClipboardButton(id: string) {
|
|||||||
return (
|
return (
|
||||||
<button
|
<button
|
||||||
class="md-clipboard md-icon"
|
class="md-clipboard md-icon"
|
||||||
title={translate("clipboard.copy")}
|
title={translation("clipboard.copy")}
|
||||||
data-clipboard-target={`#${id} > code`}
|
data-clipboard-target={`#${id} > code`}
|
||||||
></button>
|
></button>
|
||||||
)
|
)
|
||||||
|
@ -20,12 +20,13 @@
|
|||||||
* IN THE SOFTWARE.
|
* IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import { translation } from "~/_"
|
||||||
import {
|
import {
|
||||||
SearchDocument,
|
SearchDocument,
|
||||||
SearchMetadata,
|
SearchMetadata,
|
||||||
SearchResult
|
SearchResult
|
||||||
} from "integrations/search"
|
} from "~/integrations/search"
|
||||||
import { h, translate, truncate } from "utilities"
|
import { h, truncate } from "~/utilities"
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------------
|
/* ----------------------------------------------------------------------------
|
||||||
* Helper types
|
* Helper types
|
||||||
@ -84,7 +85,7 @@ function renderSearchDocument(
|
|||||||
}
|
}
|
||||||
{teaser > 0 && missing.length > 0 &&
|
{teaser > 0 && missing.length > 0 &&
|
||||||
<p class="md-search-result__terms">
|
<p class="md-search-result__terms">
|
||||||
{translate("search.result.term.missing")}: {...missing}
|
{translation("search.result.term.missing")}: {...missing}
|
||||||
</p>
|
</p>
|
||||||
}
|
}
|
||||||
</article>
|
</article>
|
||||||
@ -130,8 +131,8 @@ export function renderSearchResult(
|
|||||||
<details class="md-search-result__more">
|
<details class="md-search-result__more">
|
||||||
<summary tabIndex={-1}>
|
<summary tabIndex={-1}>
|
||||||
{more.length > 0 && more.length === 1
|
{more.length > 0 && more.length === 1
|
||||||
? translate("search.result.more.one")
|
? translation("search.result.more.one")
|
||||||
: translate("search.result.more.other", more.length)
|
: translation("search.result.more.other", more.length)
|
||||||
}
|
}
|
||||||
</summary>
|
</summary>
|
||||||
{...more.map(section => renderSearchDocument(section, Flag.TEASER))}
|
{...more.map(section => renderSearchDocument(section, Flag.TEASER))}
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user