@vuepress/theme-default 2.0.0-beta.67 → 2.0.0-beta.68
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.
|
@@ -1,19 +1,34 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useStorage } from '@vueuse/core';
|
|
2
|
+
import { computed, defineComponent, h, onBeforeUpdate, onMounted, ref, watch, } from 'vue';
|
|
2
3
|
export const CodeGroup = defineComponent({
|
|
3
4
|
name: 'CodeGroup',
|
|
4
5
|
slots: Object,
|
|
5
6
|
setup(_, { slots }) {
|
|
6
|
-
// index of current active item
|
|
7
|
-
const activeIndex = ref(-1);
|
|
8
7
|
// refs of the tab buttons
|
|
9
8
|
const tabRefs = ref([]);
|
|
10
9
|
if (__VUEPRESS_DEV__) {
|
|
11
|
-
//
|
|
12
|
-
//
|
|
10
|
+
// in dev mode, we need to clear the tabs ref to avoid HMR issues
|
|
11
|
+
// after removing a code-group-item
|
|
13
12
|
onBeforeUpdate(() => {
|
|
14
13
|
tabRefs.value = [];
|
|
15
14
|
});
|
|
16
15
|
}
|
|
16
|
+
// index of current active item
|
|
17
|
+
const activeIndex = ref(-1);
|
|
18
|
+
const codeGroupStorage = useStorage('vuepress-code-group', {});
|
|
19
|
+
const codeGroupKey = computed(() => tabRefs.value.map((tab) => tab.innerText).join(','));
|
|
20
|
+
onMounted(() => {
|
|
21
|
+
watch(() => codeGroupStorage.value[codeGroupKey.value], (val = -1) => {
|
|
22
|
+
if (activeIndex.value !== val) {
|
|
23
|
+
activeIndex.value = val;
|
|
24
|
+
}
|
|
25
|
+
}, { immediate: true });
|
|
26
|
+
watch(activeIndex, (val) => {
|
|
27
|
+
if (codeGroupStorage.value[codeGroupKey.value] !== val) {
|
|
28
|
+
codeGroupStorage.value[codeGroupKey.value] = val;
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
});
|
|
17
32
|
// activate next tab
|
|
18
33
|
const activateNext = (i = activeIndex.value) => {
|
|
19
34
|
if (i < tabRefs.value.length - 1) {
|
|
@@ -50,10 +65,7 @@ export const CodeGroup = defineComponent({
|
|
|
50
65
|
}
|
|
51
66
|
};
|
|
52
67
|
return () => {
|
|
53
|
-
//
|
|
54
|
-
// the slots reactive, otherwise the slot content won't be changed once the
|
|
55
|
-
// `setup()` function of current component is called
|
|
56
|
-
// get children code-group-item
|
|
68
|
+
// get children code-group-item from default slots
|
|
57
69
|
const items = (slots.default?.() || [])
|
|
58
70
|
.filter((vnode) => vnode.type.name === 'CodeGroupItem')
|
|
59
71
|
.map((vnode) => {
|
|
@@ -66,8 +78,8 @@ export const CodeGroup = defineComponent({
|
|
|
66
78
|
if (items.length === 0) {
|
|
67
79
|
return null;
|
|
68
80
|
}
|
|
81
|
+
// if activeIndex is invalid
|
|
69
82
|
if (activeIndex.value < 0 || activeIndex.value > items.length - 1) {
|
|
70
|
-
// if `activeIndex` is invalid
|
|
71
83
|
// find the index of the code-group-item with `active` props
|
|
72
84
|
activeIndex.value = items.findIndex((vnode) => vnode.props.active === '' || vnode.props.active === true);
|
|
73
85
|
// if there is no `active` props on code-group-item, set the first item active
|
|
@@ -75,6 +87,7 @@ export const CodeGroup = defineComponent({
|
|
|
75
87
|
activeIndex.value = 0;
|
|
76
88
|
}
|
|
77
89
|
}
|
|
90
|
+
// if activeIndex is valid
|
|
78
91
|
else {
|
|
79
92
|
// set the active item
|
|
80
93
|
items.forEach((vnode, i) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vuepress/theme-default",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"version": "2.0.0-beta.68",
|
|
4
4
|
"description": "Default theme of VuePress",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"vuepress-theme",
|
|
@@ -36,25 +36,25 @@
|
|
|
36
36
|
"templates"
|
|
37
37
|
],
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@vueuse/core": "^10.
|
|
40
|
-
"sass": "^1.
|
|
39
|
+
"@vueuse/core": "^10.6.0",
|
|
40
|
+
"sass": "^1.69.5",
|
|
41
41
|
"sass-loader": "^13.3.2",
|
|
42
|
-
"vue": "^3.3.
|
|
43
|
-
"vue-router": "^4.2.
|
|
44
|
-
"@vuepress/client": "2.0.0-beta.
|
|
45
|
-
"@vuepress/
|
|
46
|
-
"@vuepress/plugin-
|
|
47
|
-
"@vuepress/plugin-external-link-icon": "2.0.0-beta.
|
|
48
|
-
"@vuepress/plugin-
|
|
49
|
-
"@vuepress/plugin-
|
|
50
|
-
"@vuepress/plugin-
|
|
51
|
-
"@vuepress/
|
|
52
|
-
"@vuepress/
|
|
53
|
-
"@vuepress/plugin-
|
|
54
|
-
"@vuepress/
|
|
55
|
-
"@vuepress/
|
|
56
|
-
"@vuepress/
|
|
57
|
-
"@vuepress/plugin-
|
|
42
|
+
"vue": "^3.3.8",
|
|
43
|
+
"vue-router": "^4.2.5",
|
|
44
|
+
"@vuepress/client": "2.0.0-beta.68",
|
|
45
|
+
"@vuepress/plugin-active-header-links": "2.0.0-beta.68",
|
|
46
|
+
"@vuepress/plugin-back-to-top": "2.0.0-beta.68",
|
|
47
|
+
"@vuepress/plugin-external-link-icon": "2.0.0-beta.68",
|
|
48
|
+
"@vuepress/plugin-container": "2.0.0-beta.68",
|
|
49
|
+
"@vuepress/plugin-nprogress": "2.0.0-beta.68",
|
|
50
|
+
"@vuepress/plugin-medium-zoom": "2.0.0-beta.68",
|
|
51
|
+
"@vuepress/plugin-git": "2.0.0-beta.68",
|
|
52
|
+
"@vuepress/plugin-palette": "2.0.0-beta.68",
|
|
53
|
+
"@vuepress/plugin-theme-data": "2.0.0-beta.68",
|
|
54
|
+
"@vuepress/utils": "2.0.0-beta.68",
|
|
55
|
+
"@vuepress/core": "2.0.0-beta.68",
|
|
56
|
+
"@vuepress/shared": "2.0.0-beta.68",
|
|
57
|
+
"@vuepress/plugin-prismjs": "2.0.0-beta.68"
|
|
58
58
|
},
|
|
59
59
|
"peerDependencies": {
|
|
60
60
|
"sass-loader": "^13.2.1"
|
package/templates/build.html
CHANGED
|
@@ -24,10 +24,11 @@
|
|
|
24
24
|
</script>
|
|
25
25
|
<!--vuepress-ssr-head-->
|
|
26
26
|
<!--vuepress-ssr-styles-->
|
|
27
|
-
<!--vuepress-ssr-
|
|
27
|
+
<!--vuepress-ssr-preload-->
|
|
28
|
+
<!--vuepress-ssr-prefetch-->
|
|
28
29
|
</head>
|
|
29
30
|
<body>
|
|
30
|
-
<div id="app"><!--vuepress-ssr-
|
|
31
|
+
<div id="app"><!--vuepress-ssr-content--></div>
|
|
31
32
|
<!--vuepress-ssr-scripts-->
|
|
32
33
|
</body>
|
|
33
34
|
</html>
|