@vuepress/theme-default 2.0.0-rc.46 → 2.0.0-rc.47
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/lib/client/components/VPHomeHero.vue +10 -12
- package/lib/client/components/global/index.d.ts +1 -3
- package/lib/client/components/global/index.js +1 -3
- package/lib/client/config.js +1 -5
- package/lib/node/defaultTheme.d.ts +2 -1
- package/lib/node/defaultTheme.js +7 -15
- package/lib/node/index.d.ts +1 -0
- package/lib/node/index.js +1 -0
- package/lib/node/typings.d.ts +58 -0
- package/lib/node/typings.js +1 -0
- package/lib/shared/options.d.ts +0 -57
- package/package.json +17 -17
- package/lib/client/components/global/CodeGroup.d.ts +0 -7
- package/lib/client/components/global/CodeGroup.js +0 -144
- package/lib/client/components/global/CodeGroupItem.vue +0 -29
|
@@ -159,9 +159,12 @@ const HomeHeroImage: FunctionalComponent = () => {
|
|
|
159
159
|
|
|
160
160
|
box-sizing: border-box;
|
|
161
161
|
padding: 0.8rem 1.6rem;
|
|
162
|
-
border: 2px solid var(--vp-c-accent);
|
|
162
|
+
border: 2px solid var(--vp-c-accent-bg);
|
|
163
163
|
border-radius: 4px;
|
|
164
164
|
|
|
165
|
+
background-color: var(--vp-c-bg);
|
|
166
|
+
color: var(--vp-c-accent);
|
|
167
|
+
|
|
165
168
|
font-size: 1.2rem;
|
|
166
169
|
|
|
167
170
|
transition: background-color border-color color var(--vp-t-color);
|
|
@@ -171,23 +174,18 @@ const HomeHeroImage: FunctionalComponent = () => {
|
|
|
171
174
|
font-size: 1rem;
|
|
172
175
|
}
|
|
173
176
|
|
|
174
|
-
|
|
175
|
-
background-color: var(--vp-c-accent);
|
|
177
|
+
&:hover {
|
|
176
178
|
color: var(--vp-c-accent-text);
|
|
177
179
|
}
|
|
178
180
|
|
|
179
|
-
&.
|
|
180
|
-
background-color: var(--vp-c-bg);
|
|
181
|
-
color: var(--vp-c-accent);
|
|
181
|
+
&.primary {
|
|
182
|
+
background-color: var(--vp-c-accent-bg);
|
|
183
|
+
color: var(--vp-c-accent-text);
|
|
182
184
|
|
|
183
185
|
&:hover {
|
|
184
|
-
color: var(--vp-c-accent-
|
|
186
|
+
border-color: var(--vp-c-accent-hover);
|
|
187
|
+
background-color: var(--vp-c-accent-hover);
|
|
185
188
|
}
|
|
186
189
|
}
|
|
187
|
-
|
|
188
|
-
&:hover {
|
|
189
|
-
border-color: var(--vp-c-accent-hover);
|
|
190
|
-
background-color: var(--vp-c-accent-hover);
|
|
191
|
-
}
|
|
192
190
|
}
|
|
193
191
|
</style>
|
package/lib/client/config.js
CHANGED
|
@@ -3,7 +3,7 @@ import { useScrollPromise } from '@theme/useScrollPromise';
|
|
|
3
3
|
import { setupSidebarItems } from '@theme/useSidebarItems';
|
|
4
4
|
import { hasGlobalComponent } from '@vuepress/helper/client';
|
|
5
5
|
import { defineClientConfig } from 'vuepress/client';
|
|
6
|
-
import { Badge
|
|
6
|
+
import { Badge } from './components/global/index.js';
|
|
7
7
|
import Layout from './layouts/Layout.vue';
|
|
8
8
|
import NotFound from './layouts/NotFound.vue';
|
|
9
9
|
import '@vuepress/helper/colors.css';
|
|
@@ -13,10 +13,6 @@ export default defineClientConfig({
|
|
|
13
13
|
enhance({ app, router }) {
|
|
14
14
|
if (!hasGlobalComponent('Badge'))
|
|
15
15
|
app.component('Badge', Badge);
|
|
16
|
-
if (!hasGlobalComponent('CodeGroup'))
|
|
17
|
-
app.component('CodeGroup', CodeGroup);
|
|
18
|
-
if (!hasGlobalComponent('CodeGroupItem'))
|
|
19
|
-
app.component('CodeGroupItem', CodeGroupItem);
|
|
20
16
|
// handle scrollBehavior with transition
|
|
21
17
|
const scrollBehavior = router.options.scrollBehavior;
|
|
22
18
|
router.options.scrollBehavior = async (...args) => {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Theme } from 'vuepress/core';
|
|
2
|
-
import type { DefaultThemeLocaleOptions
|
|
2
|
+
import type { DefaultThemeLocaleOptions } from '../shared/index.js';
|
|
3
|
+
import type { DefaultThemePluginsOptions } from './typings.js';
|
|
3
4
|
export interface DefaultThemeOptions extends DefaultThemeLocaleOptions {
|
|
4
5
|
/**
|
|
5
6
|
* deployed hostname
|
package/lib/node/defaultTheme.js
CHANGED
|
@@ -4,8 +4,8 @@ import { backToTopPlugin } from '@vuepress/plugin-back-to-top';
|
|
|
4
4
|
import { copyCodePlugin } from '@vuepress/plugin-copy-code';
|
|
5
5
|
import { gitPlugin } from '@vuepress/plugin-git';
|
|
6
6
|
import { linksCheckPlugin } from '@vuepress/plugin-links-check';
|
|
7
|
-
import { markdownContainerPlugin } from '@vuepress/plugin-markdown-container';
|
|
8
7
|
import { markdownHintPlugin } from '@vuepress/plugin-markdown-hint';
|
|
8
|
+
import { markdownTabPlugin } from '@vuepress/plugin-markdown-tab';
|
|
9
9
|
import { mediumZoomPlugin } from '@vuepress/plugin-medium-zoom';
|
|
10
10
|
import { nprogressPlugin } from '@vuepress/plugin-nprogress';
|
|
11
11
|
import { palettePlugin } from '@vuepress/plugin-palette';
|
|
@@ -106,20 +106,6 @@ export const defaultTheme = ({ hostname, themePlugins = {}, ...localeOptions } =
|
|
|
106
106
|
...(isPlainObject(themePlugins.hint) ? themePlugins.hint : {}),
|
|
107
107
|
})
|
|
108
108
|
: [],
|
|
109
|
-
themePlugins.container?.codeGroup !== false
|
|
110
|
-
? markdownContainerPlugin({
|
|
111
|
-
type: 'code-group',
|
|
112
|
-
before: () => `<CodeGroup>\n`,
|
|
113
|
-
after: () => '</CodeGroup>\n',
|
|
114
|
-
})
|
|
115
|
-
: [],
|
|
116
|
-
themePlugins.container?.codeGroupItem !== false
|
|
117
|
-
? markdownContainerPlugin({
|
|
118
|
-
type: 'code-group-item',
|
|
119
|
-
before: (info) => `<CodeGroupItem title="${info}">\n`,
|
|
120
|
-
after: () => '</CodeGroupItem>\n',
|
|
121
|
-
})
|
|
122
|
-
: [],
|
|
123
109
|
// @vuepress/plugin-git
|
|
124
110
|
themePlugins.git !== false
|
|
125
111
|
? gitPlugin({
|
|
@@ -165,6 +151,12 @@ export const defaultTheme = ({ hostname, themePlugins = {}, ...localeOptions } =
|
|
|
165
151
|
: {}),
|
|
166
152
|
})
|
|
167
153
|
: [],
|
|
154
|
+
// @vuepress/plugin-markdown-tab
|
|
155
|
+
themePlugins.tab !== false
|
|
156
|
+
? markdownTabPlugin(isPlainObject(themePlugins.tab)
|
|
157
|
+
? themePlugins.tab
|
|
158
|
+
: { codeTabs: true, tabs: true })
|
|
159
|
+
: [],
|
|
168
160
|
// @vuepress/plugin-theme-data
|
|
169
161
|
themeDataPlugin({ themeData: localeOptions }),
|
|
170
162
|
],
|
package/lib/node/index.d.ts
CHANGED
package/lib/node/index.js
CHANGED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { BackToTopPluginOptions } from '@vuepress/plugin-back-to-top';
|
|
2
|
+
import type { CopyCodePluginOptions } from '@vuepress/plugin-copy-code';
|
|
3
|
+
import type { LinksCheckPluginOptions } from '@vuepress/plugin-links-check';
|
|
4
|
+
import type { MarkdownHintPluginOptions } from '@vuepress/plugin-markdown-hint';
|
|
5
|
+
import type { MarkdownTabPluginOptions } from '@vuepress/plugin-markdown-tab';
|
|
6
|
+
import type { PrismjsPluginOptions } from '@vuepress/plugin-prismjs';
|
|
7
|
+
import type { SeoPluginOptions } from '@vuepress/plugin-seo';
|
|
8
|
+
import type { SitemapPluginOptions } from '@vuepress/plugin-sitemap';
|
|
9
|
+
export interface DefaultThemePluginsOptions {
|
|
10
|
+
/**
|
|
11
|
+
* Enable @vuepress/plugin-active-header-links or not
|
|
12
|
+
*/
|
|
13
|
+
activeHeaderLinks?: boolean;
|
|
14
|
+
/**
|
|
15
|
+
* Enable @vuepress/plugin-back-to-top or not
|
|
16
|
+
*/
|
|
17
|
+
backToTop?: BackToTopPluginOptions | boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Enable @vuepress/plugin-copy-code or not
|
|
20
|
+
*/
|
|
21
|
+
copyCode?: CopyCodePluginOptions | boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Enable @vuepress/plugin-git or not
|
|
24
|
+
*/
|
|
25
|
+
git?: boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Enable @vuepress/plugin-markdown-hint or not
|
|
28
|
+
*/
|
|
29
|
+
hint?: MarkdownHintPluginOptions | boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Enable @vuepress/plugin-links-check or not
|
|
32
|
+
*/
|
|
33
|
+
linksCheck?: LinksCheckPluginOptions | boolean;
|
|
34
|
+
/**
|
|
35
|
+
* Enable @vuepress/plugin-medium-zoom or not
|
|
36
|
+
*/
|
|
37
|
+
mediumZoom?: boolean;
|
|
38
|
+
/**
|
|
39
|
+
* Enable @vuepress/plugin-nprogress or not
|
|
40
|
+
*/
|
|
41
|
+
nprogress?: boolean;
|
|
42
|
+
/**
|
|
43
|
+
* Enable @vuepress/plugin-prismjs or not
|
|
44
|
+
*/
|
|
45
|
+
prismjs?: PrismjsPluginOptions | boolean;
|
|
46
|
+
/**
|
|
47
|
+
* Enable @vuepress/plugin-seo or not
|
|
48
|
+
*/
|
|
49
|
+
seo?: Partial<SeoPluginOptions> | boolean;
|
|
50
|
+
/**
|
|
51
|
+
* Enable @vuepress/plugin-sitemap or not
|
|
52
|
+
*/
|
|
53
|
+
sitemap?: Partial<SitemapPluginOptions> | boolean;
|
|
54
|
+
/**
|
|
55
|
+
* Enable @vuepress/plugin-markdown-tab or not
|
|
56
|
+
*/
|
|
57
|
+
tab?: MarkdownTabPluginOptions | boolean;
|
|
58
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/lib/shared/options.d.ts
CHANGED
|
@@ -1,64 +1,7 @@
|
|
|
1
|
-
import type { BackToTopPluginOptions } from '@vuepress/plugin-back-to-top';
|
|
2
|
-
import type { CopyCodePluginOptions } from '@vuepress/plugin-copy-code';
|
|
3
|
-
import type { LinksCheckPluginOptions } from '@vuepress/plugin-links-check';
|
|
4
|
-
import type { MarkdownHintPluginOptions } from '@vuepress/plugin-markdown-hint';
|
|
5
|
-
import type { PrismjsPluginOptions } from '@vuepress/plugin-prismjs';
|
|
6
|
-
import type { SeoPluginOptions } from '@vuepress/plugin-seo';
|
|
7
|
-
import type { SitemapPluginOptions } from '@vuepress/plugin-sitemap';
|
|
8
1
|
import type { ThemeData } from '@vuepress/plugin-theme-data';
|
|
9
2
|
import type { LocaleData } from 'vuepress/shared';
|
|
10
3
|
import type { NavbarOptions } from './navbar.js';
|
|
11
4
|
import type { SidebarOptions } from './sidebar.js';
|
|
12
|
-
export interface DefaultThemePluginsOptions {
|
|
13
|
-
/**
|
|
14
|
-
* Enable @vuepress/plugin-active-header-links or not
|
|
15
|
-
*/
|
|
16
|
-
activeHeaderLinks?: boolean;
|
|
17
|
-
/**
|
|
18
|
-
* Enable @vuepress/plugin-back-to-top or not
|
|
19
|
-
*/
|
|
20
|
-
backToTop?: BackToTopPluginOptions | boolean;
|
|
21
|
-
/**
|
|
22
|
-
* Enable @vuepress/plugin-markdown-container or not
|
|
23
|
-
*/
|
|
24
|
-
container?: {
|
|
25
|
-
codeGroup?: boolean;
|
|
26
|
-
codeGroupItem?: boolean;
|
|
27
|
-
};
|
|
28
|
-
/**
|
|
29
|
-
* Enable @vuepress/plugin-copy-code or not
|
|
30
|
-
*/
|
|
31
|
-
copyCode?: CopyCodePluginOptions | boolean;
|
|
32
|
-
/**
|
|
33
|
-
* Enable @vuepress/plugin-git or not
|
|
34
|
-
*/
|
|
35
|
-
git?: boolean;
|
|
36
|
-
hint?: MarkdownHintPluginOptions | boolean;
|
|
37
|
-
/**
|
|
38
|
-
* Enable @vuepress/plugin-links-check or not
|
|
39
|
-
*/
|
|
40
|
-
linksCheck?: LinksCheckPluginOptions | boolean;
|
|
41
|
-
/**
|
|
42
|
-
* Enable @vuepress/plugin-medium-zoom or not
|
|
43
|
-
*/
|
|
44
|
-
mediumZoom?: boolean;
|
|
45
|
-
/**
|
|
46
|
-
* Enable @vuepress/plugin-nprogress or not
|
|
47
|
-
*/
|
|
48
|
-
nprogress?: boolean;
|
|
49
|
-
/**
|
|
50
|
-
* Enable @vuepress/plugin-prismjs or not
|
|
51
|
-
*/
|
|
52
|
-
prismjs?: PrismjsPluginOptions | boolean;
|
|
53
|
-
/**
|
|
54
|
-
* Enable @vuepress/plugin-seo or not
|
|
55
|
-
*/
|
|
56
|
-
seo?: Partial<SeoPluginOptions> | boolean;
|
|
57
|
-
/**
|
|
58
|
-
* Enable @vuepress/plugin-sitemap or not
|
|
59
|
-
*/
|
|
60
|
-
sitemap?: Partial<SitemapPluginOptions> | boolean;
|
|
61
|
-
}
|
|
62
5
|
export type DefaultThemeLocaleOptions = DefaultThemeData;
|
|
63
6
|
export type DefaultThemeData = ThemeData<DefaultThemeLocaleData>;
|
|
64
7
|
export interface DefaultThemeLocaleData extends LocaleData {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vuepress/theme-default",
|
|
3
|
-
"version": "2.0.0-rc.
|
|
3
|
+
"version": "2.0.0-rc.47",
|
|
4
4
|
"description": "Default theme of VuePress",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"vuepress-theme",
|
|
@@ -37,23 +37,23 @@
|
|
|
37
37
|
"templates"
|
|
38
38
|
],
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@vuepress/helper": "2.0.0-rc.
|
|
41
|
-
"@vuepress/plugin-active-header-links": "2.0.0-rc.
|
|
42
|
-
"@vuepress/plugin-back-to-top": "2.0.0-rc.
|
|
43
|
-
"@vuepress/plugin-copy-code": "2.0.0-rc.
|
|
40
|
+
"@vuepress/helper": "2.0.0-rc.47",
|
|
41
|
+
"@vuepress/plugin-active-header-links": "2.0.0-rc.47",
|
|
42
|
+
"@vuepress/plugin-back-to-top": "2.0.0-rc.47",
|
|
43
|
+
"@vuepress/plugin-copy-code": "2.0.0-rc.47",
|
|
44
44
|
"@vuepress/plugin-git": "2.0.0-rc.44",
|
|
45
|
-
"@vuepress/plugin-links-check": "2.0.0-rc.
|
|
46
|
-
"@vuepress/plugin-markdown-
|
|
47
|
-
"@vuepress/plugin-markdown-
|
|
48
|
-
"@vuepress/plugin-medium-zoom": "2.0.0-rc.
|
|
49
|
-
"@vuepress/plugin-nprogress": "2.0.0-rc.
|
|
50
|
-
"@vuepress/plugin-palette": "2.0.0-rc.
|
|
51
|
-
"@vuepress/plugin-prismjs": "2.0.0-rc.
|
|
52
|
-
"@vuepress/plugin-seo": "2.0.0-rc.
|
|
53
|
-
"@vuepress/plugin-sitemap": "2.0.0-rc.
|
|
54
|
-
"@vuepress/plugin-theme-data": "2.0.0-rc.
|
|
45
|
+
"@vuepress/plugin-links-check": "2.0.0-rc.47",
|
|
46
|
+
"@vuepress/plugin-markdown-hint": "2.0.0-rc.47",
|
|
47
|
+
"@vuepress/plugin-markdown-tab": "2.0.0-rc.47",
|
|
48
|
+
"@vuepress/plugin-medium-zoom": "2.0.0-rc.47",
|
|
49
|
+
"@vuepress/plugin-nprogress": "2.0.0-rc.47",
|
|
50
|
+
"@vuepress/plugin-palette": "2.0.0-rc.47",
|
|
51
|
+
"@vuepress/plugin-prismjs": "2.0.0-rc.47",
|
|
52
|
+
"@vuepress/plugin-seo": "2.0.0-rc.47",
|
|
53
|
+
"@vuepress/plugin-sitemap": "2.0.0-rc.47",
|
|
54
|
+
"@vuepress/plugin-theme-data": "2.0.0-rc.47",
|
|
55
55
|
"@vueuse/core": "^11.1.0",
|
|
56
|
-
"vue": "^3.5.
|
|
56
|
+
"vue": "^3.5.8"
|
|
57
57
|
},
|
|
58
58
|
"peerDependencies": {
|
|
59
59
|
"sass": "^1.79.2",
|
|
@@ -75,5 +75,5 @@
|
|
|
75
75
|
"publishConfig": {
|
|
76
76
|
"access": "public"
|
|
77
77
|
},
|
|
78
|
-
"gitHead": "
|
|
78
|
+
"gitHead": "688b739ad50113f8aad17ab18e868d72698a2a54"
|
|
79
79
|
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import type { SlotsType, VNode } from 'vue';
|
|
2
|
-
import '../../styles/code-group.scss';
|
|
3
|
-
export declare const CodeGroup: import("vue").DefineComponent<{}, () => VNode<import("vue").RendererNode, import("vue").RendererElement, {
|
|
4
|
-
[key: string]: any;
|
|
5
|
-
}> | null, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, SlotsType<{
|
|
6
|
-
default?: () => VNode[];
|
|
7
|
-
}>, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
import { useStorage } from '@vueuse/core';
|
|
2
|
-
import { computed, defineComponent, h, onBeforeUpdate, onMounted, ref, watch, } from 'vue';
|
|
3
|
-
import { useDarkMode } from '../../composables/useDarkMode.js';
|
|
4
|
-
import '../../styles/code-group.scss';
|
|
5
|
-
export const CodeGroup = defineComponent({
|
|
6
|
-
name: 'CodeGroup',
|
|
7
|
-
slots: Object,
|
|
8
|
-
setup(_, { slots }) {
|
|
9
|
-
// refs of the tab buttons
|
|
10
|
-
const tabRefs = ref([]);
|
|
11
|
-
if (__VUEPRESS_DEV__) {
|
|
12
|
-
// in dev mode, we need to clear the tabs ref to avoid HMR issues
|
|
13
|
-
// after removing a code-group-item
|
|
14
|
-
onBeforeUpdate(() => {
|
|
15
|
-
tabRefs.value = [];
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
const isDark = useDarkMode();
|
|
19
|
-
const groupRef = ref();
|
|
20
|
-
// shiki highlighter color & background
|
|
21
|
-
onMounted(() => {
|
|
22
|
-
if (!groupRef.value)
|
|
23
|
-
return;
|
|
24
|
-
const codeBlock = groupRef.value.querySelector('div[class*="language-"]');
|
|
25
|
-
if (codeBlock && codeBlock.dataset.highlighter === 'shiki') {
|
|
26
|
-
const lightColor = codeBlock.style.getPropertyValue('--shiki-light');
|
|
27
|
-
const darkColor = codeBlock.style.getPropertyValue('--shiki-dark');
|
|
28
|
-
const lightBg = codeBlock.style.getPropertyValue('--shiki-light-bg');
|
|
29
|
-
const darkBg = codeBlock.style.getPropertyValue('--shiki-dark-bg');
|
|
30
|
-
watch(isDark, (val) => {
|
|
31
|
-
groupRef.value.style.setProperty('--vp-c-code-tab-bg', val ? darkBg : lightBg);
|
|
32
|
-
groupRef.value.style.setProperty('--vp-c-code-tab-title', val ? darkColor : lightColor);
|
|
33
|
-
}, { immediate: true });
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
// index of current active item
|
|
37
|
-
const activeIndex = ref(-1);
|
|
38
|
-
const codeGroupStorage = useStorage('vuepress-code-group', {});
|
|
39
|
-
const codeGroupKey = computed(() => tabRefs.value.map((tab) => tab.innerText).join(','));
|
|
40
|
-
onMounted(() => {
|
|
41
|
-
watch(() => codeGroupStorage.value[codeGroupKey.value], (val = -1) => {
|
|
42
|
-
if (activeIndex.value !== val) {
|
|
43
|
-
activeIndex.value = val;
|
|
44
|
-
}
|
|
45
|
-
}, { immediate: true });
|
|
46
|
-
watch(activeIndex, (val) => {
|
|
47
|
-
if (codeGroupStorage.value[codeGroupKey.value] !== val) {
|
|
48
|
-
codeGroupStorage.value[codeGroupKey.value] = val;
|
|
49
|
-
}
|
|
50
|
-
});
|
|
51
|
-
});
|
|
52
|
-
// activate next tab
|
|
53
|
-
const activateNext = (i = activeIndex.value) => {
|
|
54
|
-
if (i < tabRefs.value.length - 1) {
|
|
55
|
-
activeIndex.value = i + 1;
|
|
56
|
-
}
|
|
57
|
-
else {
|
|
58
|
-
activeIndex.value = 0;
|
|
59
|
-
}
|
|
60
|
-
tabRefs.value[activeIndex.value].focus();
|
|
61
|
-
};
|
|
62
|
-
// activate previous tab
|
|
63
|
-
const activatePrev = (i = activeIndex.value) => {
|
|
64
|
-
if (i > 0) {
|
|
65
|
-
activeIndex.value = i - 1;
|
|
66
|
-
}
|
|
67
|
-
else {
|
|
68
|
-
activeIndex.value = tabRefs.value.length - 1;
|
|
69
|
-
}
|
|
70
|
-
tabRefs.value[activeIndex.value].focus();
|
|
71
|
-
};
|
|
72
|
-
// handle keyboard event
|
|
73
|
-
const keyboardHandler = (event, i) => {
|
|
74
|
-
if (event.key === ' ' || event.key === 'Enter') {
|
|
75
|
-
event.preventDefault();
|
|
76
|
-
activeIndex.value = i;
|
|
77
|
-
}
|
|
78
|
-
else if (event.key === 'ArrowRight') {
|
|
79
|
-
event.preventDefault();
|
|
80
|
-
activateNext(i);
|
|
81
|
-
}
|
|
82
|
-
else if (event.key === 'ArrowLeft') {
|
|
83
|
-
event.preventDefault();
|
|
84
|
-
activatePrev(i);
|
|
85
|
-
}
|
|
86
|
-
};
|
|
87
|
-
return () => {
|
|
88
|
-
// get children code-group-item from default slots
|
|
89
|
-
const items = (slots.default?.() ?? [])
|
|
90
|
-
.filter((vNode) => vNode.type.name === 'CodeGroupItem')
|
|
91
|
-
.map((vNode) => {
|
|
92
|
-
if (vNode.props === null) {
|
|
93
|
-
vNode.props = {};
|
|
94
|
-
}
|
|
95
|
-
return vNode;
|
|
96
|
-
});
|
|
97
|
-
// do not render anything if there is no code-group-item
|
|
98
|
-
if (items.length === 0) {
|
|
99
|
-
return null;
|
|
100
|
-
}
|
|
101
|
-
// if activeIndex is invalid
|
|
102
|
-
if (activeIndex.value < 0 || activeIndex.value > items.length - 1) {
|
|
103
|
-
// find the index of the code-group-item with `active` props
|
|
104
|
-
activeIndex.value = items.findIndex((vnode) => vnode.props.active === '' || vnode.props.active === true);
|
|
105
|
-
// if there is no `active` props on code-group-item, set the first item active
|
|
106
|
-
if (activeIndex.value === -1) {
|
|
107
|
-
activeIndex.value = 0;
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
// if activeIndex is valid
|
|
111
|
-
else {
|
|
112
|
-
// set the active item
|
|
113
|
-
items.forEach((vnode, i) => {
|
|
114
|
-
vnode.props.active = i === activeIndex.value;
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
return h('div', { class: 'code-group', ref: groupRef }, [
|
|
118
|
-
h('div', { class: 'code-group-nav', role: 'tablist' }, items.map((vnode, i) => {
|
|
119
|
-
const isActive = i === activeIndex.value;
|
|
120
|
-
return h('button', {
|
|
121
|
-
ref: (element) => {
|
|
122
|
-
if (element) {
|
|
123
|
-
tabRefs.value[i] = element;
|
|
124
|
-
}
|
|
125
|
-
},
|
|
126
|
-
class: {
|
|
127
|
-
'code-group-nav-tab': true,
|
|
128
|
-
'active': isActive,
|
|
129
|
-
},
|
|
130
|
-
role: 'tab',
|
|
131
|
-
ariaSelected: isActive,
|
|
132
|
-
onClick: () => {
|
|
133
|
-
activeIndex.value = i;
|
|
134
|
-
},
|
|
135
|
-
onKeydown: (e) => {
|
|
136
|
-
keyboardHandler(e, i);
|
|
137
|
-
},
|
|
138
|
-
}, vnode.props.title);
|
|
139
|
-
})),
|
|
140
|
-
items,
|
|
141
|
-
]);
|
|
142
|
-
};
|
|
143
|
-
},
|
|
144
|
-
});
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
<script setup lang="ts">
|
|
2
|
-
import type { VNode } from 'vue'
|
|
3
|
-
|
|
4
|
-
defineOptions({
|
|
5
|
-
name: 'CodeGroupItem',
|
|
6
|
-
})
|
|
7
|
-
|
|
8
|
-
defineProps<{
|
|
9
|
-
/**
|
|
10
|
-
* The title of the code group item
|
|
11
|
-
*/
|
|
12
|
-
// eslint-disable-next-line vue/no-unused-properties, vue/require-prop-comment
|
|
13
|
-
title: string
|
|
14
|
-
/**
|
|
15
|
-
* Whether the code group item is active
|
|
16
|
-
*/
|
|
17
|
-
active?: boolean
|
|
18
|
-
}>()
|
|
19
|
-
|
|
20
|
-
defineSlots<{
|
|
21
|
-
default?: () => VNode | VNode[] | null
|
|
22
|
-
}>()
|
|
23
|
-
</script>
|
|
24
|
-
|
|
25
|
-
<template>
|
|
26
|
-
<div class="code-group-item" :class="{ active }" role="tabpanel">
|
|
27
|
-
<slot />
|
|
28
|
-
</div>
|
|
29
|
-
</template>
|