@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.
@@ -10,9 +10,7 @@ import {
10
10
  useUpdateDeviceStatus,
11
11
  } from '../composables/index.js'
12
12
 
13
- defineEmits<{
14
- (e: 'toggle-sidebar'): void
15
- }>()
13
+ defineEmits<(e: 'toggle-sidebar') => void>()
16
14
 
17
15
  defineSlots<{
18
16
  before?: (props: Record<never, never>) => any
@@ -1,9 +1,7 @@
1
1
  <script setup lang="ts">
2
2
  import { useThemeLocaleData } from '../composables/index.js'
3
3
 
4
- defineEmits<{
5
- (e: 'toggle'): void
6
- }>()
4
+ defineEmits<(e: 'toggle') => void>()
7
5
 
8
6
  const themeLocale = useThemeLocaleData()
9
7
  </script>
@@ -1,19 +1,34 @@
1
- import { defineComponent, h, onBeforeUpdate, ref } from 'vue';
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
- // after removing a code-group-item, we need to clear the ref
12
- // of the removed item to avoid issues caused by HMR
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
- // NOTICE: here we put the `slots.default()` inside the render function to make
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.67",
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.4.1",
40
- "sass": "^1.66.1",
39
+ "@vueuse/core": "^10.6.0",
40
+ "sass": "^1.69.5",
41
41
  "sass-loader": "^13.3.2",
42
- "vue": "^3.3.4",
43
- "vue-router": "^4.2.4",
44
- "@vuepress/client": "2.0.0-beta.67",
45
- "@vuepress/core": "2.0.0-beta.67",
46
- "@vuepress/plugin-active-header-links": "2.0.0-beta.67",
47
- "@vuepress/plugin-external-link-icon": "2.0.0-beta.67",
48
- "@vuepress/plugin-back-to-top": "2.0.0-beta.67",
49
- "@vuepress/plugin-container": "2.0.0-beta.67",
50
- "@vuepress/plugin-git": "2.0.0-beta.67",
51
- "@vuepress/shared": "2.0.0-beta.67",
52
- "@vuepress/utils": "2.0.0-beta.67",
53
- "@vuepress/plugin-palette": "2.0.0-beta.67",
54
- "@vuepress/plugin-nprogress": "2.0.0-beta.67",
55
- "@vuepress/plugin-theme-data": "2.0.0-beta.67",
56
- "@vuepress/plugin-prismjs": "2.0.0-beta.67",
57
- "@vuepress/plugin-medium-zoom": "2.0.0-beta.67"
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"
@@ -24,10 +24,11 @@
24
24
  </script>
25
25
  <!--vuepress-ssr-head-->
26
26
  <!--vuepress-ssr-styles-->
27
- <!--vuepress-ssr-resources-->
27
+ <!--vuepress-ssr-preload-->
28
+ <!--vuepress-ssr-prefetch-->
28
29
  </head>
29
30
  <body>
30
- <div id="app"><!--vuepress-ssr-app--></div>
31
+ <div id="app"><!--vuepress-ssr-content--></div>
31
32
  <!--vuepress-ssr-scripts-->
32
33
  </body>
33
34
  </html>