@frontfactory/vitepress-theme 1.7.0 → 1.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +83 -0
- package/README.md +163 -7
- package/config.d.ts +27 -1
- package/config.js +186 -21
- package/dist/style.css +1 -1
- package/node/blog.d.ts +3 -0
- package/node/blog.js +19 -0
- package/node/llms.js +32 -0
- package/node/og.js +158 -0
- package/node/pages.js +162 -0
- package/node/rss.js +78 -0
- package/package.json +42 -28
- package/src/blog/posts.data.ts +47 -0
- package/src/components/FfBackToTop.vue +19 -10
- package/src/components/FfBanner.vue +24 -6
- package/src/components/FfCopyStatus.vue +64 -0
- package/src/components/FfDocMeta.vue +325 -3
- package/src/components/FfFeature.vue +18 -7
- package/src/components/FfFeedback.vue +96 -0
- package/src/components/FfHero.vue +26 -35
- package/src/components/FfHeroActions.vue +44 -0
- package/src/components/FfHeroCommand.vue +22 -35
- package/src/components/FfHomeSponsors.vue +2 -2
- package/src/components/FfNavBarTitle.vue +63 -0
- package/src/components/FfPost.vue +50 -0
- package/src/components/FfProgress.vue +69 -0
- package/src/components/FfVersionSwitcher.vue +20 -0
- package/src/composables/blog.ts +41 -0
- package/src/composables/copy.ts +36 -0
- package/src/composables/options.ts +20 -1
- package/src/composables/tabs.ts +122 -0
- package/src/content/Api.vue +6 -2
- package/src/content/Badge.vue +26 -0
- package/src/content/Callout.vue +27 -0
- package/src/content/FileTree.vue +118 -0
- package/src/content/Tab.vue +11 -0
- package/src/content/Tabs.vue +95 -0
- package/src/content/Timeline.vue +19 -0
- package/src/content/TimelineItem.vue +37 -0
- package/src/content/timeline.ts +4 -0
- package/src/index.ts +37 -1
- package/src/internal.ts +8 -2
- package/src/layout/FfBlog.vue +62 -0
- package/src/layout/FfLayout.vue +20 -4
- package/src/styles/_base.scss +6 -14
- package/src/styles/_blocks.scss +29 -8
- package/src/styles/_blog.scss +130 -0
- package/src/styles/_breakpoints.scss +26 -0
- package/src/styles/_code.scss +11 -17
- package/src/styles/_content.scss +377 -18
- package/src/styles/_doc.scss +32 -29
- package/src/styles/_home.scss +47 -65
- package/src/styles/_mixins.scss +63 -0
- package/src/styles/_motion.scss +24 -13
- package/src/styles/_nav.scss +90 -24
- package/src/styles/_print.scss +77 -0
- package/src/styles/_sidebar.scss +7 -10
- package/src/styles/_tokens.scss +92 -11
- package/src/styles/index.scss +2 -0
- package/src/types.ts +148 -0
- package/types/blog/posts.data.d.ts +14 -0
- package/types/components/FfBackToTop.vue.d.ts +3 -0
- package/types/components/FfBanner.vue.d.ts +3 -0
- package/types/components/FfCopyStatus.vue.d.ts +3 -0
- package/types/components/FfDocMeta.vue.d.ts +3 -0
- package/types/components/FfFeature.vue.d.ts +13 -0
- package/types/components/FfFeedback.vue.d.ts +3 -0
- package/types/components/FfFooter.vue.d.ts +3 -0
- package/types/components/FfHero.vue.d.ts +42 -0
- package/types/components/FfHeroActions.vue.d.ts +19 -0
- package/types/components/FfHeroCommand.vue.d.ts +9 -0
- package/types/components/FfHomeSponsors.vue.d.ts +19 -0
- package/types/components/FfNavBarTitle.vue.d.ts +17 -0
- package/types/components/FfPost.vue.d.ts +3 -0
- package/types/components/FfProgress.vue.d.ts +3 -0
- package/types/components/FfVersionSwitcher.vue.d.ts +3 -0
- package/types/composables/blog.d.ts +10 -0
- package/types/composables/copy.d.ts +6 -0
- package/types/composables/link.d.ts +12 -0
- package/types/composables/options.d.ts +15 -0
- package/types/composables/relativeTime.d.ts +2 -0
- package/types/composables/tabs.d.ts +10 -0
- package/types/content/Api.vue.d.ts +27 -0
- package/types/content/Badge.vue.d.ts +21 -0
- package/types/content/Callout.vue.d.ts +24 -0
- package/types/content/Card.vue.d.ts +23 -0
- package/types/content/CardGrid.vue.d.ts +20 -0
- package/types/content/FileTree.vue.d.ts +6 -0
- package/types/content/Kbd.vue.d.ts +15 -0
- package/types/content/Steps.vue.d.ts +15 -0
- package/types/content/Tab.vue.d.ts +19 -0
- package/types/content/Tabs.vue.d.ts +7 -0
- package/types/content/Timeline.vue.d.ts +21 -0
- package/types/content/TimelineItem.vue.d.ts +21 -0
- package/types/content/timeline.d.ts +3 -0
- package/types/index.d.ts +25 -0
- package/types/internal.d.ts +10 -0
- package/types/layout/FfBlog.vue.d.ts +3 -0
- package/types/layout/FfLayout.vue.d.ts +23 -0
- package/types/types.d.ts +280 -0
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
-
import {
|
|
3
|
-
computed, onUnmounted, ref, watch
|
|
4
|
-
} from 'vue';
|
|
2
|
+
import { computed, useId } from 'vue';
|
|
5
3
|
import { format, useLabels } from '../composables/options';
|
|
4
|
+
import { useCopy } from '../composables/copy';
|
|
5
|
+
import { useTabs } from '../composables/tabs';
|
|
6
6
|
import type { HeroCommandTab } from '../types';
|
|
7
7
|
|
|
8
8
|
// Used from both hero panel positions (inline and beside the headline, see FfHero), which are
|
|
@@ -19,39 +19,15 @@ const tabs = computed<HeroCommandTab[] | undefined>(() =>
|
|
|
19
19
|
Array.isArray(props.command) ? props.command : undefined
|
|
20
20
|
);
|
|
21
21
|
|
|
22
|
-
const activeTab =
|
|
22
|
+
const { active: activeTab, select, onKeydown } = useTabs(() => tabs.value?.map((tab) => tab.label) ?? []);
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
// component (two home pages in the same site), so the index is reset rather than left pointing
|
|
26
|
-
// past the end.
|
|
27
|
-
watch(tabs, () => (activeTab.value = 0));
|
|
24
|
+
const id = useId();
|
|
28
25
|
|
|
29
26
|
const activeCommand = computed<string>(() =>
|
|
30
27
|
tabs.value ? (tabs.value[activeTab.value]?.value ?? '') : (props.command as string)
|
|
31
28
|
);
|
|
32
29
|
|
|
33
|
-
const copied =
|
|
34
|
-
let copiedTimer: ReturnType<typeof setTimeout> | undefined;
|
|
35
|
-
|
|
36
|
-
async function copy() {
|
|
37
|
-
if (!activeCommand.value) {
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
try {
|
|
42
|
-
await navigator.clipboard.writeText(activeCommand.value);
|
|
43
|
-
} catch {
|
|
44
|
-
// Insecure context or denied permission: there is nothing to confirm.
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
copied.value = true;
|
|
49
|
-
|
|
50
|
-
clearTimeout(copiedTimer);
|
|
51
|
-
copiedTimer = setTimeout(() => (copied.value = false), 2000);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
onUnmounted(() => clearTimeout(copiedTimer));
|
|
30
|
+
const { copied, copy } = useCopy(activeCommand);
|
|
55
31
|
</script>
|
|
56
32
|
|
|
57
33
|
<template>
|
|
@@ -66,23 +42,34 @@ onUnmounted(() => clearTimeout(copiedTimer));
|
|
|
66
42
|
<div
|
|
67
43
|
v-if="tabs"
|
|
68
44
|
class="ff-hero-command-tabs"
|
|
69
|
-
role="
|
|
45
|
+
role="tablist"
|
|
70
46
|
:aria-label="labels.heroInstall"
|
|
47
|
+
@keydown="onKeydown"
|
|
71
48
|
>
|
|
72
49
|
<button
|
|
73
50
|
v-for="(tab, index) in tabs"
|
|
74
|
-
:
|
|
51
|
+
:id="`${id}-tab-${index}`"
|
|
52
|
+
:key="index"
|
|
75
53
|
type="button"
|
|
54
|
+
role="tab"
|
|
76
55
|
class="ff-hero-command-tab"
|
|
77
56
|
:class="{ active: index === activeTab }"
|
|
78
|
-
:aria-
|
|
79
|
-
|
|
57
|
+
:aria-selected="index === activeTab"
|
|
58
|
+
:aria-controls="`${id}-panel`"
|
|
59
|
+
:tabindex="index === activeTab ? 0 : -1"
|
|
60
|
+
@click="select(index)"
|
|
80
61
|
>
|
|
81
62
|
{{ tab.label }}
|
|
82
63
|
</button>
|
|
83
64
|
</div>
|
|
84
65
|
|
|
85
|
-
|
|
66
|
+
<!-- One panel whose command follows the active tab, rather than one panel per tab. -->
|
|
67
|
+
<div
|
|
68
|
+
:id="tabs ? `${id}-panel` : undefined"
|
|
69
|
+
class="ff-hero-command"
|
|
70
|
+
:role="tabs ? 'tabpanel' : undefined"
|
|
71
|
+
:aria-labelledby="tabs ? `${id}-tab-${activeTab}` : undefined"
|
|
72
|
+
>
|
|
86
73
|
<code>
|
|
87
74
|
<span
|
|
88
75
|
class="ff-hero-prompt"
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
-
import { VPSponsors } from '../internal';
|
|
2
|
+
import { normalizeLink, VPSponsors } from '../internal';
|
|
3
3
|
import { useLabels } from '../composables/options';
|
|
4
4
|
|
|
5
5
|
export interface SponsorItem {
|
|
@@ -48,7 +48,7 @@ const labels = useLabels();
|
|
|
48
48
|
>
|
|
49
49
|
<a
|
|
50
50
|
class="ff-btn ff-btn-alt no-icon"
|
|
51
|
-
:href="actionLink"
|
|
51
|
+
:href="normalizeLink(actionLink)"
|
|
52
52
|
>{{ actionText ?? labels.sponsorsAction }}</a>
|
|
53
53
|
</div>
|
|
54
54
|
</div>
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
// Replica of the default theme's VPNavBarTitle, with the version switcher rendered beside the
|
|
3
|
+
// title link. Its `nav-bar-title-after` slot sits inside that link, where an interactive menu
|
|
4
|
+
// would be invalid markup and every click would navigate home.
|
|
5
|
+
import { computed } from 'vue';
|
|
6
|
+
import { useData } from 'vitepress';
|
|
7
|
+
import {
|
|
8
|
+
normalizeLink, useLangs, useLayout, VPImage
|
|
9
|
+
} from '../internal';
|
|
10
|
+
import FfVersionSwitcher from './FfVersionSwitcher.vue';
|
|
11
|
+
|
|
12
|
+
const { site, theme } = useData();
|
|
13
|
+
const { hasSidebar } = useLayout();
|
|
14
|
+
const { currentLang } = useLangs();
|
|
15
|
+
|
|
16
|
+
const logoLink = computed(() =>
|
|
17
|
+
typeof theme.value.logoLink === 'string' ? {
|
|
18
|
+
link: theme.value.logoLink
|
|
19
|
+
} : theme.value.logoLink
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
// Plain-text title, surfaced as a native tooltip since the sidebar column truncates it.
|
|
23
|
+
const textTitle = computed(() => {
|
|
24
|
+
if (theme.value.siteTitle === false) {
|
|
25
|
+
return undefined;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const raw: string = theme.value.siteTitle ?? site.value.title;
|
|
29
|
+
|
|
30
|
+
return raw.replace(/<[^>]+>/g, '').trim() || undefined;
|
|
31
|
+
});
|
|
32
|
+
</script>
|
|
33
|
+
|
|
34
|
+
<template>
|
|
35
|
+
<div
|
|
36
|
+
class="VPNavBarTitle"
|
|
37
|
+
:class="{ 'has-sidebar': hasSidebar }"
|
|
38
|
+
>
|
|
39
|
+
<a
|
|
40
|
+
class="title"
|
|
41
|
+
:href="logoLink?.link ?? normalizeLink(currentLang.link)"
|
|
42
|
+
:rel="logoLink?.rel"
|
|
43
|
+
:target="logoLink?.target"
|
|
44
|
+
:title="textTitle"
|
|
45
|
+
>
|
|
46
|
+
<slot name="nav-bar-title-before" />
|
|
47
|
+
<VPImage
|
|
48
|
+
v-if="theme.logo"
|
|
49
|
+
class="logo"
|
|
50
|
+
:image="theme.logo"
|
|
51
|
+
/>
|
|
52
|
+
<span
|
|
53
|
+
v-if="theme.siteTitle"
|
|
54
|
+
dir="auto"
|
|
55
|
+
v-html="theme.siteTitle"
|
|
56
|
+
/>
|
|
57
|
+
<span v-else-if="theme.siteTitle === undefined">{{ site.title }}</span>
|
|
58
|
+
<slot name="nav-bar-title-after" />
|
|
59
|
+
</a>
|
|
60
|
+
|
|
61
|
+
<FfVersionSwitcher />
|
|
62
|
+
</div>
|
|
63
|
+
</template>
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { computed } from 'vue';
|
|
3
|
+
import { useData, withBase } from 'vitepress';
|
|
4
|
+
import {
|
|
5
|
+
formatDate, resolveAuthor, useBlog
|
|
6
|
+
} from '../composables/blog';
|
|
7
|
+
import { format, useLabels } from '../composables/options';
|
|
8
|
+
import { normalizeLink } from '../internal';
|
|
9
|
+
|
|
10
|
+
const { frontmatter, lang } = useData();
|
|
11
|
+
const { isPost, authors } = useBlog();
|
|
12
|
+
const labels = useLabels();
|
|
13
|
+
|
|
14
|
+
const date = computed(() => (isPost.value ? new Date(frontmatter.value.date).toISOString() : ''));
|
|
15
|
+
const author = computed(() => resolveAuthor(authors.value, frontmatter.value.author));
|
|
16
|
+
const tags = computed<string[]>(() => (Array.isArray(frontmatter.value.tags) ? frontmatter.value.tags : []));
|
|
17
|
+
</script>
|
|
18
|
+
|
|
19
|
+
<template>
|
|
20
|
+
<div
|
|
21
|
+
v-if="isPost"
|
|
22
|
+
class="ff-post ff-label"
|
|
23
|
+
>
|
|
24
|
+
<time
|
|
25
|
+
class="ff-post-item"
|
|
26
|
+
:datetime="date"
|
|
27
|
+
>{{ formatDate(date, lang) }}</time>
|
|
28
|
+
<span
|
|
29
|
+
v-if="author"
|
|
30
|
+
class="ff-post-item ff-post-author"
|
|
31
|
+
>
|
|
32
|
+
<img
|
|
33
|
+
v-if="author.avatar"
|
|
34
|
+
:src="withBase(author.avatar)"
|
|
35
|
+
alt=""
|
|
36
|
+
class="ff-post-avatar"
|
|
37
|
+
>
|
|
38
|
+
<a
|
|
39
|
+
v-if="author.link"
|
|
40
|
+
:href="normalizeLink(author.link)"
|
|
41
|
+
>{{ format(labels.blogBy, author.name) }}</a>
|
|
42
|
+
<template v-else>{{ format(labels.blogBy, author.name) }}</template>
|
|
43
|
+
</span>
|
|
44
|
+
<span
|
|
45
|
+
v-for="tag in tags"
|
|
46
|
+
:key="tag"
|
|
47
|
+
class="ff-post-item ff-post-tag"
|
|
48
|
+
>{{ tag }}</span>
|
|
49
|
+
</div>
|
|
50
|
+
</template>
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import {
|
|
3
|
+
computed, onMounted, ref, watchEffect
|
|
4
|
+
} from 'vue';
|
|
5
|
+
import { useData } from 'vitepress';
|
|
6
|
+
import { useThemeOptions } from '../composables/options';
|
|
7
|
+
|
|
8
|
+
const { frontmatter } = useData();
|
|
9
|
+
const options = useThemeOptions();
|
|
10
|
+
|
|
11
|
+
const enabled = computed(() => options.value.progress === true && frontmatter.value.progress !== false);
|
|
12
|
+
|
|
13
|
+
const progress = ref(0);
|
|
14
|
+
|
|
15
|
+
function update() {
|
|
16
|
+
const range = document.documentElement.scrollHeight - window.innerHeight;
|
|
17
|
+
|
|
18
|
+
progress.value = range > 0 ? Math.min(Math.max(window.scrollY / range, 0), 1) : 0;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// At most one state update per frame, however many scroll events fire.
|
|
22
|
+
let frame = 0;
|
|
23
|
+
|
|
24
|
+
function onChange() {
|
|
25
|
+
if (!frame) {
|
|
26
|
+
frame = requestAnimationFrame(() => {
|
|
27
|
+
frame = 0;
|
|
28
|
+
update();
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// Listens only while the bar is enabled, and follows the option if it changes (locale switch,
|
|
34
|
+
// per-page frontmatter). The effect is stopped with the component, which runs its cleanup.
|
|
35
|
+
onMounted(() => {
|
|
36
|
+
watchEffect((onCleanup) => {
|
|
37
|
+
if (!enabled.value) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
update();
|
|
42
|
+
window.addEventListener('scroll', onChange, {
|
|
43
|
+
passive: true
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
window.addEventListener('resize', onChange, {
|
|
47
|
+
passive: true
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
onCleanup(() => {
|
|
51
|
+
cancelAnimationFrame(frame);
|
|
52
|
+
frame = 0;
|
|
53
|
+
window.removeEventListener('scroll', onChange);
|
|
54
|
+
window.removeEventListener('resize', onChange);
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
</script>
|
|
59
|
+
|
|
60
|
+
<template>
|
|
61
|
+
<ClientOnly>
|
|
62
|
+
<div
|
|
63
|
+
v-if="enabled"
|
|
64
|
+
class="ff-progress"
|
|
65
|
+
aria-hidden="true"
|
|
66
|
+
:style="{ transform: `scaleX(${progress})` }"
|
|
67
|
+
/>
|
|
68
|
+
</ClientOnly>
|
|
69
|
+
</template>
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { computed } from 'vue';
|
|
3
|
+
import { VPFlyout } from '../internal';
|
|
4
|
+
import { useLabels, useThemeOptions } from '../composables/options';
|
|
5
|
+
|
|
6
|
+
const options = useThemeOptions();
|
|
7
|
+
const labels = useLabels();
|
|
8
|
+
|
|
9
|
+
const versions = computed(() => options.value.versions);
|
|
10
|
+
</script>
|
|
11
|
+
|
|
12
|
+
<template>
|
|
13
|
+
<VPFlyout
|
|
14
|
+
v-if="versions"
|
|
15
|
+
class="ff-version-switcher"
|
|
16
|
+
:button="versions.current"
|
|
17
|
+
:items="versions.items"
|
|
18
|
+
:label="`${labels.versionSwitcher} ${versions.current}`"
|
|
19
|
+
/>
|
|
20
|
+
</template>
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { computed } from 'vue';
|
|
2
|
+
import { useData } from 'vitepress';
|
|
3
|
+
import { useThemeOptions } from './options';
|
|
4
|
+
import { blogDir, hasValidDate } from '../../node/blog.js';
|
|
5
|
+
import type { BlogAuthor } from '../types';
|
|
6
|
+
|
|
7
|
+
/** Blog options, with the directory normalised (no slash at either end). */
|
|
8
|
+
export function useBlog() {
|
|
9
|
+
const options = useThemeOptions();
|
|
10
|
+
const { page, frontmatter } = useData();
|
|
11
|
+
|
|
12
|
+
const dir = computed(() => blogDir(options.value));
|
|
13
|
+
|
|
14
|
+
// A post is a dated page under the blog directory, the index excluded.
|
|
15
|
+
const isPost = computed(() => {
|
|
16
|
+
const path = page.value.relativePath;
|
|
17
|
+
|
|
18
|
+
return path.startsWith(`${dir.value}/`) && path !== `${dir.value}/index.md` && hasValidDate(frontmatter.value.date);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
return {
|
|
22
|
+
dir,
|
|
23
|
+
isPost,
|
|
24
|
+
authors: computed(() => options.value.blog?.authors ?? {})
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** `author` is a key of `ff.blog.authors`, or a plain name used as is. */
|
|
29
|
+
export function resolveAuthor(authors: Record<string, BlogAuthor>, value?: string): BlogAuthor | null {
|
|
30
|
+
return value ? authors[value] ?? {
|
|
31
|
+
name: value
|
|
32
|
+
} : null;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// UTC, so the server and the browser print the same day whatever their time zone.
|
|
36
|
+
export function formatDate(date: string, lang: string) {
|
|
37
|
+
return new Intl.DateTimeFormat(lang, {
|
|
38
|
+
dateStyle: 'long',
|
|
39
|
+
timeZone: 'UTC'
|
|
40
|
+
}).format(new Date(date));
|
|
41
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import {
|
|
2
|
+
onUnmounted, ref, toValue, type MaybeRefOrGetter
|
|
3
|
+
} from 'vue';
|
|
4
|
+
|
|
5
|
+
/** Copies a string to the clipboard and flags it as copied for two seconds. */
|
|
6
|
+
export function useCopy(text: MaybeRefOrGetter<string>) {
|
|
7
|
+
const copied = ref(false);
|
|
8
|
+
let timer: ReturnType<typeof setTimeout> | undefined;
|
|
9
|
+
|
|
10
|
+
async function copy() {
|
|
11
|
+
const value = toValue(text);
|
|
12
|
+
|
|
13
|
+
if (!value) {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
try {
|
|
18
|
+
await navigator.clipboard.writeText(value);
|
|
19
|
+
} catch {
|
|
20
|
+
// Insecure context or denied permission: there is nothing to confirm.
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
copied.value = true;
|
|
25
|
+
|
|
26
|
+
clearTimeout(timer);
|
|
27
|
+
timer = setTimeout(() => (copied.value = false), 2000);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
onUnmounted(() => clearTimeout(timer));
|
|
31
|
+
|
|
32
|
+
return {
|
|
33
|
+
copied,
|
|
34
|
+
copy
|
|
35
|
+
};
|
|
36
|
+
}
|
|
@@ -24,7 +24,26 @@ export const defaultLabels: Required<ThemeLabels> = {
|
|
|
24
24
|
footerSocial: 'Follow',
|
|
25
25
|
newTab: 'opens in a new tab',
|
|
26
26
|
sponsors: 'Sponsors',
|
|
27
|
-
sponsorsAction: 'Become a sponsor'
|
|
27
|
+
sponsorsAction: 'Become a sponsor',
|
|
28
|
+
apiSince: 'since {0}',
|
|
29
|
+
apiDeprecated: 'deprecated',
|
|
30
|
+
bannerCta: 'Read more',
|
|
31
|
+
feedbackQuestion: 'Was this page helpful?',
|
|
32
|
+
feedbackYes: 'Yes',
|
|
33
|
+
feedbackNo: 'No',
|
|
34
|
+
feedbackThanks: 'Thanks for your feedback',
|
|
35
|
+
copyMarkdown: 'Copy as Markdown',
|
|
36
|
+
copyMarkdownHint: 'Page source',
|
|
37
|
+
pageActions: 'More page actions',
|
|
38
|
+
copyLink: 'Copy link',
|
|
39
|
+
linkCopied: 'Link copied',
|
|
40
|
+
share: 'Share',
|
|
41
|
+
shareOn: 'Share on {0}',
|
|
42
|
+
versionSwitcher: 'Version',
|
|
43
|
+
blogBy: 'By {0}',
|
|
44
|
+
blogEmpty: 'No posts yet',
|
|
45
|
+
returnToTop: 'Return to top',
|
|
46
|
+
codeCopied: 'Copied'
|
|
28
47
|
};
|
|
29
48
|
|
|
30
49
|
/**
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import {
|
|
2
|
+
computed, onMounted, reactive, ref, toValue, watch, type MaybeRefOrGetter
|
|
3
|
+
} from 'vue';
|
|
4
|
+
|
|
5
|
+
const STORAGE_PREFIX = 'ff-tabs:';
|
|
6
|
+
|
|
7
|
+
// Label picked for each sync key. Module-level so every tab group on the page reads the same
|
|
8
|
+
// value; the `storage` event only fires in *other* documents, which is what keeps tabs open
|
|
9
|
+
// side by side in agreement.
|
|
10
|
+
const synced = reactive<Record<string, string>>({});
|
|
11
|
+
let listening = false;
|
|
12
|
+
|
|
13
|
+
function listen() {
|
|
14
|
+
if (listening) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
listening = true;
|
|
19
|
+
|
|
20
|
+
window.addEventListener('storage', (event) => {
|
|
21
|
+
if (event.key?.startsWith(STORAGE_PREFIX) && event.newValue !== null) {
|
|
22
|
+
synced[event.key.slice(STORAGE_PREFIX.length)] = event.newValue;
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Active tab of a group of labels. With a sync key, the choice is shared by label with every
|
|
29
|
+
* group using the same key and remembered across visits.
|
|
30
|
+
*/
|
|
31
|
+
export function useTabs(labels: MaybeRefOrGetter<string[]>, syncKey?: MaybeRefOrGetter<string | undefined>) {
|
|
32
|
+
const local = ref(0);
|
|
33
|
+
|
|
34
|
+
// Client-side navigation can swap the labels without remounting the component (two pages
|
|
35
|
+
// using the same layout), so the index is reset rather than left pointing past the end.
|
|
36
|
+
watch(() => JSON.stringify(toValue(labels)), () => (local.value = 0));
|
|
37
|
+
|
|
38
|
+
const active = computed(() => {
|
|
39
|
+
const list = toValue(labels);
|
|
40
|
+
const key = toValue(syncKey);
|
|
41
|
+
|
|
42
|
+
if (key && synced[key] !== undefined) {
|
|
43
|
+
const index = list.indexOf(synced[key]);
|
|
44
|
+
|
|
45
|
+
if (index !== -1) {
|
|
46
|
+
return index;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return Math.min(local.value, Math.max(list.length - 1, 0));
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
function select(index: number) {
|
|
54
|
+
local.value = index;
|
|
55
|
+
|
|
56
|
+
const key = toValue(syncKey);
|
|
57
|
+
const label = toValue(labels)[index];
|
|
58
|
+
|
|
59
|
+
if (!key || label === undefined) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
synced[key] = label;
|
|
64
|
+
|
|
65
|
+
try {
|
|
66
|
+
localStorage.setItem(STORAGE_PREFIX + key, label);
|
|
67
|
+
} catch {
|
|
68
|
+
// Storage disabled: the choice still holds for this page.
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// Read after mount only, so the server and the hydrating client both render the first tab.
|
|
73
|
+
onMounted(() => {
|
|
74
|
+
const key = toValue(syncKey);
|
|
75
|
+
|
|
76
|
+
if (!key) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
listen();
|
|
81
|
+
|
|
82
|
+
try {
|
|
83
|
+
const stored = localStorage.getItem(STORAGE_PREFIX + key);
|
|
84
|
+
|
|
85
|
+
if (stored !== null && synced[key] === undefined) {
|
|
86
|
+
synced[key] = stored;
|
|
87
|
+
}
|
|
88
|
+
} catch {
|
|
89
|
+
// Storage disabled: fall back to the first tab.
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
// Roving focus across the tab list, as the ARIA tabs pattern expects: arrows wrap around, Home
|
|
94
|
+
// and End jump to the ends, and selection follows focus. Bound on the `role="tablist"` element.
|
|
95
|
+
function onKeydown(event: KeyboardEvent) {
|
|
96
|
+
const count = toValue(labels).length;
|
|
97
|
+
const targets: Record<string, number> = {
|
|
98
|
+
ArrowRight: (active.value + 1) % count,
|
|
99
|
+
ArrowLeft: (active.value - 1 + count) % count,
|
|
100
|
+
Home: 0,
|
|
101
|
+
End: count - 1
|
|
102
|
+
};
|
|
103
|
+
const next = targets[event.key];
|
|
104
|
+
|
|
105
|
+
if (next === undefined) {
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
event.preventDefault();
|
|
110
|
+
select(next);
|
|
111
|
+
|
|
112
|
+
const tabs = (event.currentTarget as HTMLElement).querySelectorAll<HTMLElement>('[role="tab"]');
|
|
113
|
+
|
|
114
|
+
tabs[next]?.focus();
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
return {
|
|
118
|
+
active,
|
|
119
|
+
select,
|
|
120
|
+
onKeydown
|
|
121
|
+
};
|
|
122
|
+
}
|
package/src/content/Api.vue
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
+
import { format, useLabels } from '../composables/options';
|
|
3
|
+
|
|
4
|
+
const labels = useLabels();
|
|
5
|
+
|
|
2
6
|
defineProps<{
|
|
3
7
|
/** Symbol being documented, e.g. `refs()`. */
|
|
4
8
|
name: string
|
|
@@ -28,11 +32,11 @@ defineProps<{
|
|
|
28
32
|
<span
|
|
29
33
|
v-if="since"
|
|
30
34
|
class="ff-api-tag ff-label"
|
|
31
|
-
>
|
|
35
|
+
>{{ format(labels.apiSince, since) }}</span>
|
|
32
36
|
<span
|
|
33
37
|
v-if="deprecated"
|
|
34
38
|
class="ff-api-tag ff-api-deprecated ff-label"
|
|
35
|
-
>
|
|
39
|
+
>{{ labels.apiDeprecated }}</span>
|
|
36
40
|
</header>
|
|
37
41
|
|
|
38
42
|
<p
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { computed } from 'vue';
|
|
3
|
+
import { format, useLabels } from '../composables/options';
|
|
4
|
+
import { VPBadge } from '../internal';
|
|
5
|
+
|
|
6
|
+
const labels = useLabels();
|
|
7
|
+
|
|
8
|
+
const props = defineProps<{
|
|
9
|
+
/** Text of the badge; for `since`, the version, printed through the `apiSince` label. */
|
|
10
|
+
text?: string
|
|
11
|
+
/** `tip`, `info`, `warning` and `danger` come from VitePress; `new`, `beta`, `deprecated` and `since` from the theme. */
|
|
12
|
+
type?: string
|
|
13
|
+
}>();
|
|
14
|
+
|
|
15
|
+
const shown = computed(() => (props.type === 'since' && props.text ? format(labels.value.apiSince, props.text) : props.text));
|
|
16
|
+
</script>
|
|
17
|
+
|
|
18
|
+
<!-- VPBadge types `type` as a closed union but only uses it as a class name, hence the cast. -->
|
|
19
|
+
<template>
|
|
20
|
+
<VPBadge
|
|
21
|
+
:type="(type as 'tip' | undefined)"
|
|
22
|
+
:text="shown"
|
|
23
|
+
>
|
|
24
|
+
<slot />
|
|
25
|
+
</VPBadge>
|
|
26
|
+
</template>
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
// Same markup as a `::: tip` container, so the margin-note styling of _blocks.scss applies as is.
|
|
3
|
+
// It exists for the places a container cannot reach: inside another component, or with a type or
|
|
4
|
+
// title bound to data.
|
|
5
|
+
withDefaults(defineProps<{
|
|
6
|
+
/** One of the container types: `tip`, `info`, `note`, `important`, `warning`, `danger`, `caution`. */
|
|
7
|
+
type?: string
|
|
8
|
+
/** Label printed above the text. Defaults to the type, like a container. */
|
|
9
|
+
title?: string
|
|
10
|
+
}>(), {
|
|
11
|
+
type: 'note',
|
|
12
|
+
title: undefined
|
|
13
|
+
});
|
|
14
|
+
</script>
|
|
15
|
+
|
|
16
|
+
<template>
|
|
17
|
+
<div
|
|
18
|
+
class="custom-block"
|
|
19
|
+
:class="type"
|
|
20
|
+
>
|
|
21
|
+
<p class="custom-block-title">
|
|
22
|
+
{{ title ?? type }}
|
|
23
|
+
</p>
|
|
24
|
+
|
|
25
|
+
<slot />
|
|
26
|
+
</div>
|
|
27
|
+
</template>
|